akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<set>
#include<stack>
#include<queue>
#include<sstream>
#include<iomanip>

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}

template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", ";
	return out << "}" << endl;
}
int c[50][50];
int gcd(int x, int y){
	if(!y) return x;
	return gcd(y, x%y);
}
#define N 1000
vi g[N];
int used[N];
int match[N];
void add_edge(int i, int j){
	g[i].pb(j);
	g[j].pb(i);
}
bool dfs(int v){
	used[v] = 1;
	rep(i,g[v].size()){
		int u = g[v][i], w = match[u];
		if(w < 0 || (!used[w] && dfs(w))){
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int main(){
	int n,m;
	while(cin >> m >> n, n){
		vi r(n), b(m);
		rep(i,m) cin >> b[i];
		rep(i,n) cin >> r[i];
		int t = n + m;
		fill(match, match+N, -1);
		fill(used, used + N, 0);
		rep(i,t) g[i].clear();
		rep(i,m){
			rep(j,n){
				if(gcd(b[i], r[j]) > 1){
					add_edge(i,m+j);
				}
			}
		}
		int ans = 0;
		rep(v, t){
			if(match[v]<0){
				fill(used, used + N, 0);
				if(dfs(v)){
					ans ++;
				}
			}
		}
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 4916
N = int(input())
A = sorted(list(map(int, input().split())))
#check
v = 1
idx = 0
if N%2 == 1:
    if A[0] != 0:
        print(0)
        exit()
    idx = 1
    v = 2
for i in range(N//2):
    for j in range(2):
        if A[idx+2*i+j] != v:
            print(0)
            exit()
    v += 2
print((2**(N//2))%(10**9+7))


Measured memory_bytes: 14008
import math
N=int(input())
ans=[]
for i in range(1,int(math.sqrt(N))+1):
    if N%i==0:
        num1=i
        num2=N//i
        if (num1-1)>num2:
            ans.append(num1-1)
        if (num2-1)>num1:
            ans.append(num2-1)
#print(ans)
ans=list(set(ans))
print(sum(ans))

Measured memory_bytes: 40300
#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[])
{	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	int i,j,t;
	if(a>b)  {t=a;a=b;b=t;}
	if(a>c) {t=a;a=c;c=t;}
	if(b>c){t=b;b=c;c=t;}
	int m,n;
	m=b-a;n=c-b;
	printf("%d\n",m+n);
	return 0;
}

Measured memory_bytes: 128
n=int(input())
S = [input() for _ in range(n)]
c={}
c["AC"] = 0
c["WA"] = 0
c["TLE"] = 0
c["RE"] = 0
for s in S:
    c[s]+=1
print("AC x",c["AC"])
print("WA x",c["WA"])
print("TLE x",c["TLE"])
print("RE x",c["RE"])

Measured memory_bytes: 16180
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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() {
  int N;
  cin >> N;

  typedef pair<int, int> P;

  vector<P> ab(N);
  rep(i, N) cin >> ab[i].fi >> ab[i].se;
  vector<P> cd(N);
  rep(i, N) cin >> cd[i].fi >> cd[i].se;

  sort(all(cd));

  vector<bool> used_ab(N, false);

  int ans = 0;
  rep(i, N) {
    int ymax = -1;
    int ymax_ind = -1;

    rep(j, N) {
      if (ab[j].fi < cd[i].fi && ab[j].se < cd[i].se && used_ab[j] == false) {
        if (chmax(ymax, ab[j].se)) ymax_ind = j;
      }
    }

    if (ymax_ind != -1) {
      used_ab[ymax_ind] = true;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = inp()
a = inpl()
b = inpl()
pp = 0
qq = 0
for i in range(n):
    if a[i] > b[i]:
        pp += a[i] - b[i]
    elif a[i] < b[i]:
        qq += (b[i] - a[i]) // 2
if qq >= pp:
    print('Yes')
else:
    print('No')


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG
#include "cpp-pyprint/pyprint.h"
#endif

void Main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    for (auto &v : a) {
        cin >> v;
    }

    vector<ll> ans(N, 0);
    ll tmp = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0){
            tmp += a[i];
        }else{
            tmp -= a[i];
        }
    }
    ans[0] = tmp;
    for (int j = 1; j < N; ++j) {
        ans[j] = 2 * (a[j-1] - ans[j - 1] / 2 );
    }
    for (auto v : ans ) {
        cout << v << " ";
    }
    cout << endl;

}

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


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

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

	if (s[0] == s[1] && s[1] == s[2] && s[2] == s[0]) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n, a, b, k = map(int, input().split())

mod = 998244353
factorial = [1]
inverse = [1]
for i in range(1, n+1):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod - 2, mod))

def comb(n, r, mod):
    if n < r or r < 0: return 0
    elif r == 0: return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod

ans = 0
for i in range(n+1):
    if a*i > k: break
    sum_b = k - a*i
    if sum_b % b != 0: continue
    j = sum_b // b
    if j > n: continue
    ans = (ans + comb(n, i, mod)*comb(n, j, mod)) % mod
print(ans)

Measured memory_bytes: 26864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=5e6;
int tot=0;
ll n,s;
ll fac[N];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
	{
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
	{
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
bool check(ll a,ll b)
{
	ll ans=0;
	while(a)
	{
		ans+=a%b;
		a/=b;
	}
	return ans==s;
}
bool cmp(int x,int y){return x>y;}
int main()
{
//    freopen("test.in","r",stdin);
//    freopen("test.ans","w",stdout);
    scanf("%lld%lld",&n,&s);
    if(s>=n)
    {
    	if(s>n) puts("-1");
    	else printf("%lld",n+1);
    	return 0;
    }
	for(int i=2;i<=sqrt(n)+1;i++)
	{
		if(check(n,i))
		{
			printf("%d",i);
			return 0;
		}
	}
	ll temp=n-s;
	ll sq=sqrt(n);
	for(int i=temp/sq+1;i;i--)
	{
		if(temp%i) continue;
		if(s>=i&&s-i<=temp/i&&i<=temp/i)//i为B,则ans=(n-s)/B+1且ans>sqrt(n); 
		{//A+B=S,A+ans*B=n得==>(ans-1)*B=n-s;
			printf("%lld",temp/i+1);
			return 0;
		}
	}
	puts("-1");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int x, a, b, c;
    int ans=0;

    scanf("%d%d%d%d", &a, &b, &c, &x);

    for(int i=c;0<=i;i--) {
        for(int j=0;b>=j;j++) {
            for(int k=0;a>=k;k++) {
                int tmp = 500 * k + 100 * j + 50 * i;
                if(x == tmp) {
                    ans++;
                }
            }
        }
    }

    printf("%d", ans);
    return 0;
}

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

// 文字列の長さ: s.size()
// 文字列の i 文字目: s[i]　(char 型です、値の取得も書き換えもできます)
// 文字列の連結: s + t　(例: s = "AtCoder", t = "Jobs" -> s + t = "AtCoderJobs")
// 文字列の大小関係: <　(辞書式順序で比較します)

int main(){
string s;
int y = 700;
cin >> s;

if (s[0] =='o' ) y += 100;
if (s[1] =='o' ) y += 100;
if (s[2] =='o' ) y += 100;

cout << y << endl; 

}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n);
    for(auto&& i : a){
        cin >> i;
    }
    for(auto&& i : b){
        cin >> i;
    }
    long long ans = 0;
    for(int i = 0; i < n; i++){
        ans += min(a[i], b[i]);
        b[i] -= min(a[i], b[i]);
        ans += min(a[i + 1], b[i]);
        a[i + 1] -= min(a[i + 1], b[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
import copy
n = int(input())
a = list(map(int, input().split()))
b = [0]*n
for i in range(n, 0, -1):
  c = 0
  for j in range(i - 1, n, i):
    c += b[j]
  if c%2 != a[i - 1]:
    b[i - 1] = 1

if sum(b) == 0:
  print(0)
else:
  print(sum(b))
  for i in range(n):
    if b[i] == 1:
      print(str(i + 1), end=" ")

Measured memory_bytes: 13072
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn is_prime(x: u64) -> bool {
    if x == 2 { return true }
    if x < 2 || x % 2 == 0 {
        return false;
    }
    let mut i = 3;
    while i*i <= x {
        if x % i == 0 { return false }
        i += 2;
    }
    true
}


fn main() {
    input! {
        n: usize,
        a: [u64;n]
    }
    let mut cnt = 0;
    for x in a {
        if is_prime(x) { cnt += 1 }
    }
    println!("{}", cnt);
}
/* vim:set foldmethod=marker: */



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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  string o, e;
  cin >> o;
  cin >> e;

  for (int i = 0; i < o.length(); ++i) {
    cout << o[i];
    if (i < e.length()) {
      cout << e[i];
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define int long long

signed main(){
int n,m;cin>>n>>m;
  int ans;
  if(n==1 && m==1)ans=1;
  else if(n==1)ans=m-2;
  else if(m==1)ans=n-2;
  else ans=(m-2)*(n-2);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=998244353;
const ll inf=1e17;
const ll ms=(2e5)+5;


int ar[ms][3];

int peil(int n,int k)
{
    if(n%k)return n/k+1;
    return n/k;
}

int main()
{
    idfc;
    int n;
    cin>>n;
    int i;
    for(i=1;i<n;i++)
    {
        cin>>ar[i][0]>>ar[i][1]>>ar[i][2];
    }
    int j;
    int t;
    int d;
    int k;
    for(i=1;i<=n;i++)
    {
        t=0;
        for(j=i;j<n;j++)
        {
          d=max(0,t-ar[j][1]);
          k=peil(d,ar[j][2]);
          t=ar[j][1]+(k*ar[j][2])+ar[j][0];
        }
        cout<<t<<"\n";
    }


    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using vs = vector<string>;
const int MOD = 1000000007;

int main(){
    string s;
    char c;
    rep(i,4){
        cin>>c;
        s += c;
    }
    sort(all(s));
    puts(s=="1479"?"YES":"NO");
    
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);
#define endl "\n"
#define MAXN 100123
#define ll long long
#define INF INT_MAX
#define SZ(v) (int)v.size()
#define FORE(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,n) FORE(i,0,n)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define pb(v) push_back(v)
#define ms(v,x) memset(v,x,sizeof(v)) 
#define PI M_PI
using namespace std;

// cout << fixed << setprecision(4);

int n,t;
int k,a,b;
bool possivel = false;
    
int main(){_
    cin >> k;
    cin >> a >> b;

    FORE(i,a,b+1){
        if(i%k==0){
            possivel = true;
            break;
        }
    } 
    cout << (possivel? "OK":"NG") << endl;
    return 0;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define FOR(i, l, r) for(int i = (int)l; i <= (int)r; ++i)

using namespace std;
typedef long long ll;
const int Nmax = 102;
const int Wmax = 1e5 + 11;
const ll inf = 1e18 + 112;

int n, w[Nmax], v[Nmax], W;
ll f[Nmax][Wmax], ans;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> W;
    FOR(i, 1, n) {
        cin >> w[i] >> v[i];
    }
    FOR(i, 0, n) FOR(j, 0, W) {
        f[i][j] = -inf;
    }
    f[0][0] = 0;
    FOR(i, 1, n) FOR(j, 0, W) {
        f[i][j] = f[i - 1][j];
        if (j - w[i] >= 0) {
            f[i][j] = max(f[i][j], f[i - 1][j - w[i]] + v[i]);
        }
        if (i == n) ans = max(ans, f[i][j]);
    }
    cout << ans;
}


Measured memory_bytes: 79232
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    reverse(all(s));
    
    ll total=0, cnt=0;
    for(auto c:s){
        if(c=='B'){
            total+=cnt;
        }else{
            cnt++;
        }
    }
    cout1(total)
}

Measured memory_bytes: 720
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int n, k;
int main(){
  cin >> n >> k;
  if(2*k-1<=n){
    cout << "YES" <<endl;
  }else{
    cout << "NO" <<endl;
  }
  return 0;
}
  
    
  
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int n;
  cin >> n;
  int not24 = 0;
  int by2 = 0;
  int by4 = 0;
  rep(i,n){
    int x;
    cin >> x;
    if(x%4 == 0){
      by4 ++;
    }else if(x%2 == 0){
      by2 ++;
    }else{
      not24 ++;
    }
  }//i
  if(not24 == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(by4 >= not24-1){
    if(by4 == not24-1 && by2 > 0){
      cout << "No" << endl;
    }else{
      cout << "Yes" << endl;
    }
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
using System;

public class BubbleSort {

    const int MIN_N = 1;
    const int MAX_N = 100;
    const int MIN_A = 0;
    const int MAX_A = 100;

    int N = 0;
    
    BubbleSort() {
	// ?????????????????°???????????????????????????
	N = int.Parse(Console.ReadLine());

	// ?????????????????§??????
	N = Math.Min(N, MAX_N);
	N = Math.Max(N, MIN_N);

	// ?????????????????°??????????????????
	string[] buf = Console.ReadLine().Split(' ');
	int[] input  = new int[N];
	for (int i = 0; i < N; i++) {
	    input[i] = int.Parse(buf[i]);
	}

	// ???????????????????????¢?????´?????????
	bool flag = true; // ????????£??\????´?????????¨??????
	int change = 0; // ???????????°
	while (flag) {
	    flag = false;
	    for (int j = N - 1; 1 <= j; j--) {
		if (input[j] < input[j - 1]) {
		    // ????????????
		    int tmp = input[j];
		    input[j] = input[j - 1];
		    input[j - 1] = tmp;
		    change++;
		    flag = true;
		}
	    }
	}

	// ??????
	for (int i = 0; i < N; i++) {
	    if (i == N - 1) {
		Console.WriteLine(input[i]);
		Console.WriteLine(change); // ???????????°
		continue;
	    }
	    Console.Write(input[i] + " ");
	}	
    }

    public static void Main() {
	//BubbleSort sort = new BubbleSort();
	new BubbleSort();
    }
}

Measured memory_bytes: 9160
#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;
int main(){
    int n;
    int k=1;
    while(cin>>n,n){
        vector<pair<int,int> >v;
        int x,y;
        while(n--){
            cin>>x>>y;
            v.push_back(make_pair(x,y));
        }
        double s=0;
        for(int i=0;i<v.size();i++){
            pair<int,int>ne=v[(i+1)%v.size()];
            s+=0.5*(ne.first-v[i].first)*(v[i].second+ne.second);
        }
        printf("%d %.1f\n",k++,s);
    }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long Q,H,S,D,N,ans=0; cin>>Q>>H>>S>>D>>N;
  Q*=4, H*=4, S*=4, D*=4, N*=4;
  vector<long long>a4={Q*8,H*4,S*2,D}, a3={Q*4,H*2,S}, a2={Q*2,H};
  sort(a4.begin(), a4.end()), sort(a3.begin(), a3.end()), sort(a2.begin(), a2.end());
  ans+=N/8*a4[0];
  N%=8;
  ans+=N/4*a3[0];
  N%=4;
  ans+=N/2*a2[0];
  N%=2;
  ans+=N*Q;
  cout<<ans/4<<endl;
}


Measured memory_bytes: 256
#include <tuple>
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
namespace loquat {
class disjoint_set {
public:
	using value_type = size_t;
private:
	std::vector<value_type> m_parents;
	std::vector<value_type> m_ranks;
public:
	explicit disjoint_set(size_t n)
		: m_parents(n)
		, m_ranks(n)
	{
		for(size_t i = 0; i < n; ++i){
			m_parents[i] = i;
		}
	}
	value_type find(size_t x){
		if(m_parents[x] == x){ return x; }
		m_parents[x] = find(m_parents[x]);
		return m_parents[x];
	}
	value_type unite(size_t x, size_t y){
		x = find(x);
		y = find(y);
		if(x == y){ return x; }
		if(m_ranks[x] < m_ranks[y]){
			m_parents[x] = y;
			return y;
		}else if(m_ranks[x] > m_ranks[y]){
			m_parents[y] = x;
			return x;
		}else{
			m_parents[y] = x;
			++m_ranks[x];
			return x;
		}
	}
	bool same(size_t x, size_t y){
		return find(x) == find(y);
	}
};
}
using namespace std;
using ll = long long;
using tlii = tuple<ll, int, int>;
int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> x(n);
	for(int i = 0; i < n; ++i){ cin >> x[i]; }
	vector<tlii> edges;
	for(int i = 0; i < m; ++i){
		int a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		edges.emplace_back(c, a, b);
	}
	sort(edges.begin(), edges.end());
	loquat::disjoint_set ds(n);
	vector<int> prev_a(m, -1), prev_b(m, -1), last(n, -1);
	vector<ll> sizes(m, 0);
	for(int i = 0; i < m; ++i){
		const int a = get<1>(edges[i]);
		const int b = get<2>(edges[i]);
		if(ds.same(a, b)){
			const int t = last[ds.find(a)];
			prev_a[i] = prev_b[i] = t;
		}else{
			prev_a[i] = last[ds.find(a)];
			prev_b[i] = last[ds.find(b)];
			const ll new_c = x[ds.find(a)] + x[ds.find(b)];
			const int k = ds.unite(a, b);
			x[k] = new_c;
		}
		last[ds.find(a)] = i;
		sizes[i] = x[ds.find(a)];
	}
	int answer = 0;
	vector<int> marker(m, 0);
	if(m > 0){ marker[m - 1] = 1; }
	for(int i = m - 1; i >= 0; --i){
		if(!marker[i]){ continue; }
		const ll c = get<0>(edges[i]);
		if(c > sizes[i]){
			++answer;
			if(prev_a[i] >= 0){ marker[prev_a[i]] = 1; }
			if(prev_b[i] >= 0){ marker[prev_b[i]] = 1; }
		}
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 6512
#include<stdio.h>
#include<stdlib.h>

int main(void){
 	int N;
  	char line[101];
  
  	scanf("%d",&N);
  	scanf("%s",line);
  
  	if(N < strlen(line)){
     	for(int i = 0;i < N;i ++){
         	printf("%c",line[i]); 
        }
      	printf("...\n");
    }else{
     		printf("%s",line); 
    }
  
  return 0;
}


Measured memory_bytes: 1728
n = int(input())
a_list = list(map(int, input().split()))

ans = 0

_break = False

while _break == False:
    
    for i in range(n):

        # print("i : {0}".format(i))

        # 対象が偶数
        if a_list[i] % 2 == 0 :

            a_list[i] = a_list[i] / 2

            # 最後まで回りきったら+1
            if i == n - 1 :
                ans += 1
        # 対象が奇数　→ 終了
        else :
            _break = True
            break

print(ans)

Measured memory_bytes: 9088
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

#define MAX 2000007
long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long comb(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    fact();
    ll r1;
    cin >> r1;
    ll c1;
    cin >> c1;
    ll r2;
    cin >> r2;
    ll c2;
    cin >> c2;
    ll ans=0;
    ans+=comb(r1+c1,r1);
    for(ll i=r1+1;i<=r2;++i){
        ans+=comb(c2+i,i);
        ans%=MOD;
    }
    for(ll i=c1+1;i<=c2;++i){
        ans+=comb(r2+i,i);
        ans%=MOD;
    }
    prt(ans);
    return 0;
}



Measured memory_bytes: 50468
#include<iostream>
#include<string>
#include <vector>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

bool cmp(pii x, pii y) {
	return x.second < y.second;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<pii> d(m);
	rep(i, m) cin >> d[i].first >> d[i].second;
	sort(d.begin(), d.end(), cmp);
	int ans = 0;
	int end = 0;
	for (int i = 0; i < m; i++) {
		if (d[i].first >= end) {
			end = d[i].second;
			ans++;
		}
	}
	cout << ans << endl;
}

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

char s;
int k = 0,q = 0,new1 = 1,old;
int ans = -1, temp = 0, total = 0;

//N文字の数列の初めに１をつけて簡略化
int main() {
  int N, K;
  cin >> N >> K;
  queue<int> que, que2;
  for(int i = 0; i < N + 1 ; i++ ){
    cin >> s;
    old = new1;
    new1 = s - '0';
    q++;
    if(old != new1 || i == N)que.push(q),q = 0;
  }

  int K2 = K*2;
  while(total != N + 1) {
    temp += que.front();
    k++;
    que2.push(que.front());
    if(k > K2 && (k & 1) == 1) {
      if(ans == -1) ans = temp - 1;
      else ans = max(ans,temp);
      temp -= que2.front();
      que2.pop();
      temp -= que2.front();
      que2.pop();
    }
    total += que.front();
    que.pop();
  }
  if(ans == -1) ans = temp - 1;
  else ans = max(ans,temp);

  cout << ans << endl;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
// }}} End Header


int main() {
	ll n, ans = 0;
	cin >> n;
	vector<ll> sieve(n);
	loop(i, 2, n){
		for(ll j=i; j<n; j+=i){
			if(sieve[j] == 0) sieve[j]=i;
		}
	}
	
	for(ll c=1; c<n; c++){
		ll x = n-c;
		ll subans=1;
		map<ll, ll> tmp;

		while(x > 1){
			tmp[sieve[x]]++;
			x/=sieve[x];
		}
		for(auto x : tmp){
			//cout << x.first << " " << x.second << endl;
			subans*=(x.second+1);
		}
		ans+=subans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11064
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

n,k = mii()
arr = limii()
if k >= len(arr):
    print(0)
    exit()
arr.sort(reverse=True)

print(sum(arr[k:]))

Measured memory_bytes: 107596
main = do
    [k_, s_] <- return . map read . words =<< getLine
    let pairs = [(x,y) | x <- [0..k_], y <- [0..k_]]
	check (x,y) =	let z = s_ - x - y
			in 0 <= z && z <= k_
    print . length $ filter check pairs

Measured memory_bytes: 1148
K, A, B = map(int, input().split())

if B - A <= 2:
    print(K + 1)
else:
    ans = 0
    # 初回のA枚→B枚まで A-1 回かかる
    rest = K - A + 1
    # このときにはA枚持っている
    ans += A
    # 残りをすべてA枚→B枚
    ans += rest // 2 * (B - A)
    if rest % 2 != 0:
        ans += 1
    print(ans)



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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int a,p;
  cin >> a >> p;
  p+=a*3;
  cout << p/2 << endl;
  return 0;
}


Measured memory_bytes: 764
N = int(input())
H = list(map(int, input().split()))
f = 0
maxtmp = H[0]
shave = 0
for i in range(N-1):
  if H[i]-1>H[i+1] or (H[i]-1==H[i+1] and shave==1):
    f = 1
    break
  elif H[i]-1==H[i+1] and shave==0:
    maxtmp = H[i+1]
    shave = 1
  elif H[i]==H[i+1]:
    pass
  else:
    maxtmp = H[i+1]
    shave = 0
if f == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 85344
import sys


def main():
    n = int(input())
    a = [0] * n
    for i in range(n):
        a[i] = int(sys.stdin.readline()) - 1
    sw = [False for _ in range(n)]
    nextsw = 0
    while True:
        if nextsw == 1:
            print(sw.count(True))
            return
        if sw[nextsw]:
            print(-1)
            return
        sw[nextsw] = True
        nextsw = a[nextsw]


if __name__ == '__main__':
    main()


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

int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int ans = 0;
  for(int a = 0; a <= A; a++){
    for(int b = 0; b <= B; b++){
      for(int c = 0; c <= C; c++){
        if(a * 500 + b * 100 + c * 50 == X){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

          


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    rep(i, 5) {
        int a;
        cin >> a;
        if (a == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, b, n) for (int i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve(ll A, ll B, ll C, ll K) {
  ll ans = 0;
  if (K < A) {
    cout << K << endl;
    return;
  }
  ans += A;
  K -= A;

  if (B < K)
    ans -= (K - B);

  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  ll K;
  cin >> K;

  solve(A, B, C, K);

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;

#define M 100005
#define mod 1000000007
int n;
int f[M];
char a[M];
inline void inc(int &x,int y) {x+=y,x-=x>=mod?mod:0;}

int main () {
	//freopen("a.in","r",stdin);
	scanf("%s",a+1);
	n=strlen(a+1);
	bool t=0;
	for1(1,n-1,i) if(a[i]==a[i+1]) {t=1;break;}
	if(!t) return puts("1"),0;
	int ans=0;
	int s=0,pre[3]={0,-1,-1};
	f[0]=1;
	for1(1,n,i) {
		s=(s+2-(a[i]=='a'))%3;
		if(!s&&i<n) f[i]=1;
		++s,s%=3;
		if(pre[s]!=-1) inc(f[i],f[pre[s]]);
		++s,s%=3;
		if(pre[s]!=-1) inc(f[i],f[pre[s]]);
		++s,s%=3;
		pre[s]=i;
	}
	cout<<f[n]<<endl;
}

Measured memory_bytes: 768
//written by libra9z
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for (int i=0;i<(n);i++)
#define repit(it,a) for (__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define RET(p,x) return p<<x<<endl,0
#define all(a) (a).begin(),(a).end()
#define reunique(v) v.erase(unique(all(v)),v.end())
#define sz(a) (int)a.size()
#define sqr(x) ((x)*(x))
const int inf=1e9;
const ll lnf=1e18;
const int mod=1e9+7;
int h,w;
char s[13][13];
string ss[13];
int a[13];
int b[13];
void dfs1(int x,bool f)
{
	if (x==w)
	{
		puts("YES");
		exit(0);
	}
	else if (b[x]!=-1) dfs1(x+1,f);
	else
	{
		for (int i=x+1;i<w;++i)
		{
			if (b[i]!=-1) continue;
			int j;
			for (j=0;j<h;++j) if (s[j][x]!=s[a[j]][i]) break;
			if (j==h)
			{
				b[x]=i;
				b[i]=x;
				dfs1(x+1,f);
				b[x]=b[i]=-1;
			}
		}
		if (!f)
		{
			int j;
			for (j=0;j<h;++j) if (s[j][x]!=s[a[j]][x]) break;
			if (j==h)
			{
				b[x]=x;
				dfs1(x+1,true);
				b[x]=-1;
			}
		}
	}
}
void dfs2(int x,bool f)
{
	if (x==h) dfs1(0,!(w&1));
	else if (a[x]!=-1) dfs2(x+1,f);
	else
	{
		for (int i=x+1;i<h;++i)
		{
			if (a[i]!=-1) continue;
			if (ss[x]!=ss[i]) continue;
			a[x]=i;
			a[i]=x;
			dfs2(x+1,f);
			a[x]=a[i]=-1;
		}
		if (!f)
		{
			a[x]=x;
			dfs2(x+1,true);
			a[x]=-1;
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cout<<setprecision(15);
	cin>>h>>w;
	for (int i=0;i<h;++i) cin>>s[i],ss[i]=s[i],sort(ss[i].begin(),ss[i].end());
	int ui;
	for (int i=0;i<1000000000;++i)ui+=i;
	for (int i=0;i<h;++i) a[i]=-1;
	for (int i=0;i<w;++i) b[i]=-1;
	dfs2(0,!(h&1));
	cout<<"NO\n";
	return 0;
}

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

int main()
{
  int N,D;
  cin >> N >> D;
  if( N % (D * 2 +1) == 0){
    cout << N / (D * 2 + 1) << endl;
  }
  else{
    cout << N / (D * 2 + 1) + 1 << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int[][] ss = new int[n][2];
		int [][] cps  = new int[m][2];
		
		for(int[] s:ss) {
			s[0] = sc.nextInt();
			s[1] = sc.nextInt();
		}
		for(int[] cp:cps) {
			cp[0] = sc.nextInt();
			cp[1] = sc.nextInt();
		}
		
		for(int i = 0; i<n; i++) {
			int number = 1;
			int d;
			int fd = Math.abs(ss[i][0]-cps[0][0]) + Math.abs(ss[i][1]-cps[0][1]);
			for(int j = 1; j<m; j++) {
				d = Math.abs(ss[i][0]-cps[j][0]) + Math.abs(ss[i][1]-cps[j][1]);
				if(d<fd) {
					fd = d;
					number = j+1;
				}
			}
			System.out.println(number);
		}

	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int maxf[100005];
int h[100005];

int main() {
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) {
		cin>>h[i];
	}
	for(int i=1;i<=m;i++) {
		int a,b;
		cin>>a>>b;
		maxf[a]=max(maxf[a],h[b]);
		maxf[b]=max(maxf[b],h[a]);
	}
	int ans=0;
	for(int i=1;i<=n;i++) {
		if(h[i]>maxf[i]) {
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4408
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        h: usize,
        w: usize,
        q: usize,
        s: [chars; h],
        ask: [(usize1, usize1, usize, usize); q],
    }
    let mut s: Vec<Vec<bool>> = s.into_iter().map(|s| s.into_iter().map(|c| c == '1').collect()).collect();
    for s in s.iter_mut() {
        s.push(false);
    }
    s.push(vec![false; w + 1]);
    let mut cnt = vec![vec![0u32; w + 1]; h + 1];
    let mut row = vec![vec![0u32; w + 1]; h + 1];
    let mut col = vec![vec![0u32; w + 1]; h + 1];
    for i in (0..h).rev() {
        for j in (0..w).rev() {
            for a in [&mut cnt, &mut row, &mut col].iter_mut() {
                a[i][j] = a[i + 1][j] + a[i][j + 1] - a[i + 1][j + 1];
            }
            if s[i][j] {
                cnt[i][j] += 1;
            }
            if s[i][j] && s[i][j + 1] {
                row[i][j] += 1;
            }
            if s[i][j] && s[i + 1][j] {
                col[i][j] += 1;
            }
        }
    }
    let func = |sum: &Vec<Vec<u32>>, a: usize, b: usize, c: usize, d: usize| -> u32 {
        sum[a][b] - sum[a][d] - sum[c][b] + sum[c][d]
    };
    for (a, b, c, d) in ask {
        let mut ans = func(&cnt, a, b, c, d);
        ans -= func(&row, a, b, c, d - 1);
        ans -= func(&col, a, b, c - 1, d);
        writeln!(out, "{}", ans).ok();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 79472
#define DBG 1 //submit 0
#define ll long long
#if DBG
    #include <algorithm>
    #include <array>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <unordered_map>
    #include <iostream>
    #include <cmath>
    #include <queue>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif

using namespace std;


int main(){
    int N,a;
    bool flag = false;
    cin >> N >> a;

    if(N%500 <= a) flag = true;
    cout << (flag ? "Yes" : "No") << endl;
    //cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

vector<vector<array<ll, 4>>> dp;
vector<vector<ll>> table;
int R, C, K;

int main() {
	cin >> R >> C >> K;
	dp.resize(R);
	table.resize(R);
	REP(i, 0, R) {
		dp[i].resize(C, { 0,0,0,0 });
		table[i].resize(C, 0);
	}
	REP(i, 0, K) {
		int r, c, v;
		cin >> r >> c >> v;
		r--;
		c--;
		table[r][c] = v;
	}
	dp[0][0][1] = table[0][0];
	REP(j, 1, C) {
		REP(k, 1, 4) dp[0][j][k] = max(dp[0][j - 1][k], dp[0][j - 1][k - 1] + table[0][j]);
	}
	REP(i, 1, R) {
		dp[i][0][0] = dp[i - 1][0][1];
		dp[i][0][1] = dp[i - 1][0][1] + table[i][0];
		REP(j, 1, C) {
			dp[i][j][0] = max(dp[i][j - 1][0], *max_element(dp[i - 1][j].begin(), dp[i - 1][j].end()));
			if (table[i][j] <= 0) REP(k, 1, 4) dp[i][j][k] = dp[i][j - 1][k];
			else {
				dp[i][j][1] = max(dp[i][j - 1][1], table[i][j] + max(dp[i][j - 1][0], *max_element(dp[i - 1][j].begin(), dp[i - 1][j].end())));
				dp[i][j][2] = max(dp[i][j - 1][2], dp[i][j - 1][1] + table[i][j]);
				dp[i][j][3] = max(dp[i][j - 1][3], dp[i][j - 1][2] + table[i][j]);
			}
		}
	}
	PRI(*max_element(dp[R - 1][C - 1].begin(), dp[R - 1][C - 1].end()));
	return 0;
}




Measured memory_bytes: 355396
#include <cstdio>

int main()
{
    char c;
    scanf("%c", &c);
    
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    {
        printf("vowel");
    }
    else
    {
        printf("consonant");
    }
    
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
string s;
regex reg(".*AC.*");
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s;
	puts(regex_match(s,reg) ? "Yes" : "No");
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var L1 = new string('#', w + 2);
        Console.WriteLine(L1);
        for (int i = 0; i < h; i++)
            Console.WriteLine("#" + Console.ReadLine().Trim() + "#");
        Console.WriteLine(L1);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long r, d, x;

  cin >> r >> d >> x;

  for(int i = 0;i < 10;i++){
    x = r * x - d;
    cout << x << endl;
  } 
  return 0;
}



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

int main(){
  int s,w;
  cin>>s>>w;
  if(s>w) cout<<"safe"<<endl;
  if(s<=w) cout<<"unsafe"<<endl;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, K;
vector<int> h;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  h.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (h[i] >= K) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> r(n,0);
  for(int i=0;i<m;i++){
    int s,t;
    cin>>s>>t;
    r.at(s-1)+=1;
    r.at(t-1)+=1;
  }
  for(int i=0;i<n;i++)
    cout<<r.at(i)<<endl;
}

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


int main(){
	int x=0;
	char s[10];
	scanf("%s",s);
	for(int i=0;s[i];++i)
		if(s[i]=='+') ++x; else --x;
	printf("%d\n",x);
	
	return 0;
}


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

using namespace std;

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

int main() {
	string str;
	int k;
	
	cin >> str >> k;
	
	REP(i, str.size()) {
		if (str[i] == 'a') continue;
		
		int cnt = 'z' - str[i] + 1;
		
		if (cnt <= k) {
			str[i] = 'a';
			k -= cnt;
		}
	}
	str[str.size() - 1] = (char)((str[str.size() - 1] - 'a' + (k % 26)) % 26 + 'a');
	
	cout << str << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int n,i,j,temp,sum=0;
	int array[105];
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&array[i]);
	}
	
	
	for (i = 0;i < n - 1;i++) {
		for (j = 0;j < n - 1;j++) {
			if (array[j + 1] < array[j]) {
				temp = array[j];array[j] = array[j + 1];array[j + 1] = temp;
			}
		}
	}
	
	
	for(i=0;i<n-1;i++){
		sum+=array[i+1];
		sum-=array[i];
	}
	
	printf("%d\n",sum);
	return 0;
}

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

ll solve() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N), B(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i] >> B[i];
    }
    ll ans = 0;
    ll k = K;
    bool f = true;
    while ( f || k > 0 ) {
        ll mask = f ? k : k-1;
        ll tmp = 0;
        for ( int i = 0; i < N; i++ ) {
            if ( (mask | A[i]) == mask ) {
                tmp += B[i];
           }
        }
        ans = max(ans, tmp);
        if ( !f ) {
            k = k & (k-1);
        } else {
            f = false;
        }
    }

    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair



using namespace std;
typedef unsigned long long ull;
typedef vector<int>vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef set<int> si;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,i;
	cin >> n >> i;
	cout << n - i + 1  << endl;	
	return 0;
}


Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)

inf = 10 ** 15
mod = 10 ** 9 + 7
n = int(input())
v = list(map(int, input().split()))

# 偶数番目の要素において、iの数が何個あったか
even = [0 for i in range(100001)]
# 奇数番目の要素において、iの数が何個あったか
odd = [0 for i in range(100001)]

# 偶数番目、奇数番目の要素、それぞれ数える
for i in range(0, n-1, 2):
    even[v[i]] += 1
    odd[v[i+1]] += 1

# 偶数番目の要素のうち最も多かった数値
maxeveni = -1
# 偶数番目の要素のうち最も多かった数値の個数
maxeven = 0
# 偶数番目の要素のうち2番目に多かった数値の個数
preeven = 0

# 奇数番目の要素のうち最も多かった数値
maxoddi = -1
# 奇数番目の要素のうち最も多かった数値の個数
maxodd = 0
# 奇数番目の要素のうち2番目に多かった数値の個数
preodd = 0

# 偶数番目の要素を走査
for i in range(1, 100001):
    num = even[i]
    if maxeven <= num:
        maxeveni = i
        preeven = maxeven
        maxeven = num
    elif preeven <= num:
        preeven = num

# 奇数番目の要素を走査
for i in range(1, 100001):
    num = odd[i]
    if maxodd <= num:
        maxoddi = i
        preodd = maxodd
        maxodd = num
    elif preodd <= num:
        preodd = num

ans = 0

# 要素のうち最も多かった数値が偶数番目と奇数番目で一致していなかった場合
if maxeveni != maxoddi:
    ans = n - maxeven - maxodd
# 要素のうち最も多かった数値が偶数番目と奇数番目で一致していた場合
else:
    ans = min(n - preeven - maxodd, n - maxeven - preodd)
print(ans)

Measured memory_bytes: 57324
#include <bits/stdc++.h>
using namespace std;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define watch(x) cout<<"->"<<#x<<": "<<x<<endl;
#define int long long
const int INF = 1000000000;
const int MOD = 1000000007;
const double PI = 2*acos(0.0);
int solve(int n)
{
	int end = (n+1)%4;
	int res = 0;
	while(end--)
		res^=n--;
	return res;
}
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a,b;
	cin>>a>>b;
	int x = solve(a-1);
	int y = solve(b);
	cout<<(x^y)<<endl;
	return 0;	
}

Measured memory_bytes: 256