akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

type NodeId = usize;

struct Node {
    id: NodeId,
    parent: Option<NodeId>,
    left: Option<NodeId>,
    right: Option<NodeId>,
    value: i64,
}

struct Tree {
    root: Option<NodeId>,
    nodes: Vec<Node>,
}

impl Tree {
    fn new() -> Tree {
        Tree {
            root: None,
            nodes: Vec::new(),
        }
    }

    fn insert(&mut self, value: i64) {
        let mut y: Option<NodeId> = None;
        let mut x: Option<NodeId> = self.root;

        while x != None {
            y = x;
            if value < self.nodes[x.unwrap()].value {
                x = self.nodes[x.unwrap()].left;
            } else {
                x = self.nodes[x.unwrap()].right;
            }
        }

        let node = Node {
            id: self.nodes.len(),
            parent: y,
            value: value,
            left: None,
            right: None,
        };

        if y == None {
            self.root = Some(0);
        } else if node.value < self.nodes[y.unwrap()].value {
            self.nodes[y.unwrap()].left = Some(node.id);
        } else {
            self.nodes[y.unwrap()].right = Some(node.id);
        }

        self.nodes.push(node)
    }

    fn print(&mut self) {
        inorder(0, &self.nodes);
        println!();
        preorder(0, &self.nodes);
        println!();
    }
}

fn preorder(node_id: NodeId, nodes: &Vec<Node>) {
    print!(" {}", nodes[node_id].value);
    if nodes[node_id].left != None {
        preorder(nodes[node_id].left.unwrap(), nodes)
    }
    if nodes[node_id].right != None {
        preorder(nodes[node_id].right.unwrap(), nodes)
    }
}

fn inorder(node_id: NodeId, nodes: &Vec<Node>) {
    if nodes[node_id].left != None {
        inorder(nodes[node_id].left.unwrap(), nodes)
    }
    print!(" {}", nodes[node_id].value);
    if nodes[node_id].right != None {
        inorder(nodes[node_id].right.unwrap(), nodes)
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut tree: Tree = Tree::new();
    for _ in 0..n {
        let command: String = read();
        if command == "insert" {
            let number: i64 = read();
            tree.insert(number);
        } else if command == "print" {
            tree.print();
        }
    }
}



Measured memory_bytes: 36592
#include <bits/stdc++.h>
using namespace std;
vector<int> nxt;

template <typename T>
struct segtree {

  vector<T> seg, lazy;
  segtree(int n = 1e5) {
    n += 5;
    seg.assign(4*n, vector<int>());
  }

  void build(int x, int s, int e) {
    if (s == e) {
      seg[x].push_back(nxt[s]);
      return; 
    }

    int mid = (s + e) >> 1;
    build(2 * x, s, mid);
    build(2 * x + 1, mid + 1, e);

    merge(seg[2*x].begin(), seg[2*x].end(), seg[2*x+1].begin(), seg[2*x+1].end(), back_inserter(seg[x]));
  }

  int query(int x, int s, int e, int l, int r, int val) {
    if (e < l || s > r)  return 0;
    if (s >= l && e <= r){
      int pos = upper_bound(seg[x].begin(), seg[x].end(), val) - seg[x].begin();
      return seg[x].size() - pos;
    }

    int mid = (s + e) >> 1;
    return query(2 * x, s, mid, l, r, val) + query(2 * x + 1, mid + 1, e, l, r, val);
  }
};


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

  int n, q;
  cin >> n >> q;
  
  nxt.resize(n);
  vector<int> c(n), pos(n + 1, n);

  for (int i = 0; i < n; ++i) cin >> c[i];
  for (int i = n - 1; i >= 0; --i) {
    nxt[i] = pos[c[i]];
    pos[c[i]] = i;
  }

  segtree<vector<int>> seg(n);
  seg.build(1, 0, n-1);

  while (q--) {
    int l, r;
    cin >> l >> r;

    cout << seg.query(1, 0, n-1, l-1, r-1, r-1) << '\n';
  }
}


Measured memory_bytes: 121404
import sys
sys.setrecursionlimit(200002)

def dfs(s):
	global x, G
	for t, d in G[s]:
		if x[t] is None:
			x[t] = x[s] + d
			if not dfs(t):
				return False
		else:
			if x[t] != x[s] + d:
				return False
	return True

N,M = map(int,input().split())
x = [None] * N
G = [[] for _ in range(N)]
for _ in range(M):
	L, R, D = map(int,input().split())
	G[L-1].append([R-1,D])
	G[R-1].append([L-1,-D])

res = True
for i in range(N):
	if x[i] is None:
		x[i] = 0
		res &= dfs(i)

print("Yes" if res == True else "No")


Measured memory_bytes: 135196
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP
*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
 cin>>n>>m;
 if(m<=(n*4)&&m>=(n*2)&&m%2==0)
 {
     cout<<"Yes"<<endl;
 }
 else
 {
     cout<<"No"<<endl;
 }
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(ll i=0;i<n;i++)
#define repp(i,a,b) for(ll i=a;i<=b;i++)
#define reff(i,a,b) for(ll i=a;i>=b;i--)
#define ll long long int
#define pll pair<ll,ll>
#define fill(a,x) memset(a,x,sizeof(a))
#define mb make_pair
#define pb push_back
#define F first
#define S second
#define M 1000000007
#define sc(x) scanf("%d",&x)
#define scc(x1,x2) scanf("%d%d",&x1,&x2)
#define sccc(x1,x2,x3) scanf("%d%d%d",&x1,&x2,&x3)
#define pr(x) printf("%lld ",x)
#define dbg(a)          std::cerr<<#a<<"="<<(a)<<"\n"
#define dbg1(a,b)       std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define dbg2(a,b,c)     std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define dbg3(a,b,c,d)   std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define all(v) v.begin(),v.end()
#define PI 3.14159265
#define co cout<<"fuck"<<endl
const int INF = 2034567891;
const ll INF64 = 4234567890123456789ll;
long long nc3(long long v){return (v * (v - 1ll) * (v - 2ll)) / 6ll;}
long long nc2(long long v){return (v * (v - 1ll)) / 2ll;}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
const int N = 10+2e5;
bool isprime(ll n) {
    if (n < 2) return 0;
    if (n == 2) return 1;
    if (n % 2 == 0) return 0;
    for (ll i = 3; i*i <= n; i++) if (n%i == 0) return 0;
    return 1;
}
double dist(pll p1, pll p2)
 {
    return (p1. F - p2.F)*(p1.F - p2.F) +
          (p1.S - p2.S)*(p1.S - p2.S);
 }
ll power(ll x,ll y)
{
    ll ans=1;
    while(y>0){
        if(y&1)
            ans=(ans*x)%M;
        x=(x*x)%M;
        y/=2;
    } 
    return ans;
}
int main()
{
     fast;
     ll k,a,b;
     cin>>k>>a>>b;
     if(a%k==0)
     cout<<"OK";
     else if(b%k==0)
     cout<<"OK";
     else
     {
        ll div = a/k;
        if((div+1)*k<=b)
        cout<<"OK";
        else
        cout<<"NG";
	 }
}   

Measured memory_bytes: 3652
#include <stdio.h>
#include <float.h>

int main()
{
	double n, m, d;

	scanf("%lf %lf %lf", &n, &m, &d);

	if (d != 0) {
		printf("%lf\n", (m - 1) * 2 * (n - d) / (n * n));
	} else {
		printf("%lf\n", (m - 1) / n);
	}

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;

vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
const int N = 1e6 + 5;

ll modexp(ll a, ll b)
{
    a %= mod; // a should not be divisible by mod 
    if(a <= 1)
        return a;
    if(b == 0)
        return 1;
    if(b % 2 == 0)
    {
        ll res = modexp(a, b / 2);
        return (res * res) % mod;
    }
    return (a * modexp(a, b - 1)) % mod;
}

int main()
{
	sync;
    ll n;
    cin >> n;
    ll sum = 0 , ans = 0;
    for(ll i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        ans = (ans + x * sum) % mod;
        sum = (sum + x) % mod;
    }
    cout << ans;
}

Measured memory_bytes: 3524
n, m = map(int, input().split())
mod = 10**9+7
ans = 1
if n == m:
    for i in range(1, n+1):
        ans *= i*i
        ans %= mod
    ans *= 2
    ans %= mod
elif n == m-1:
    for i in range(1, n+1):
        ans *= i*i
        ans %= mod
    ans *= m
    ans %= mod
elif n == m+1:
    for i in range(1, m+1):
        ans *= i*i
        ans %= mod
    ans *= n
    ans %= mod
else:
    ans = 0
print(ans)

Measured memory_bytes: 38896
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define sz(x) (int)(x.size())
#define pii pair<int, int>
#define fi first
#define se second

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    int a[n + 1][m + 1];
    vector<vector<int>> v(n + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
            if (a[i][j] % 2 == 1)
                v[i].push_back(j);
        }
    }
    vector<pair<pii, pii>> ans;
    vector<int> last;
    for (int i = 1; i <= n; i++) {
        if (!sz(v[i])) continue;
        for (int k = 1; k < sz(v[i]); k += 2) {
            for (int j = v[i][k - 1]; j < v[i][k]; j++) {
                ans.push_back({{i, j}, {i, j + 1}});
            }
        }
        if (sz(v[i]) % 2 == 1) {
            for (int j = v[i].back(); j < m ; j++) {
                ans.push_back({{i, j}, {i, j + 1}});
            }
            last.push_back(i);
        }
    }
    for (int k = 1; k < sz(last); k += 2) {
        for (int i = last[k - 1]; i < last[k]; i++) {
            ans.push_back({{i, m}, {i + 1, m}});
        }
    }
    cout << sz(ans) << "\n";
    for (auto &el : ans) {
        cout << el.fi.fi << " " << el.fi.se << " "
            << el.se.fi << " " << el.se.se << "\n";
    }
}

Measured memory_bytes: 10100
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N 300
using namespace std;

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

  int n;
  cin >> n;
  string s[MAX_N];
  for(int i = 0; i < n; i++) cin >> s[i];

  int count = 0;
  for(int b = 0; b < n; b++){
    char m[n][n];
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        m[i][j] = s[i][(j + b) % n];
      }
    }
    bool good = true;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(m[i][j] != m[j][i]){
          good = false;
          break;
        }
      }
    }
    if(good) ++count;
  }

  int ans = count * n;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;

int main()
{
    int w, d;

    while (cin >> w >> d, w || d) {
        vector<int> hw(w), hd(d);
        int ans = 0;

        // Input
        for (int i = 0; i < w; ++i) {
            cin >> hw[i];
            ans += hw[i];
        }
        for (int i = 0; i < d; ++i)
            cin >> hd[i];

        sort(hw.begin(), hw.end(), greater<int>());
        sort(hd.begin(), hd.end(), greater<int>());

        int iw = 0, id = 0;
        while (id < d) {
            if (iw == w)
                ans += hd[id++];
            else if (hw[iw] == hd[id]) {
                ++iw;
                ++id;
            }
            else if (hw[iw] < hd[id])
                ans += hd[id++];
            else if (hw[iw] > hd[id])
                ++iw;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1208
from math import gcd
N=int(input())
A=list(map(int,input().split()))
L=[0]
R=[0]
for i in range(N):
  L.append(gcd(L[i],A[i]))
  R.append(gcd(R[i],A[-i-1]))
R=R[::-1]
P=0
for i in range(N):
  P=max(P,gcd(L[i],R[i+1]))
print(P)

Measured memory_bytes: 97908
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll N,H,W,ANS=0;
	cin>>N>>H>>W;
	rep(i,N){
		ll h,w;
		cin>>h>>w;
		if(h>=H&&w>=W)ANS++;
	}
	cout<<ANS<<endl;
}

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

int main(void)
{
	int n, m, k;
	cin >> n >> m;
	vector<int> a(m + 1, 0);
	for (int i = 0; i < n; ++i) {
		cin >> k;
		for (int j = 0; j < k; ++j) {
			int ii;
			cin >> ii;
			++a[ii];
		}
	}
	int ans = 0;
	for (int i = 0; i < m + 1; ++i) {
		if (a[i] == n) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,k,c;
string s;
Vi mae,usi;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>k>>c;
    cin>>s;
    ll tp = 0;
    rep(i,n){
        if(s[i]=='o'){
            if(mae.empty()){
                mae.pb(i);
            }
            repi(j,i+c+1,n){
                if(s[j]=='o'){
                    mae.pb(j);
                    i = j-1;
                    break;
                }else{
                    continue;
                }
            }
        }
    }
    reverse(all(s));
    rep(i,n){
        if(s[i]=='o'){
            if(usi.empty()){
                usi.pb(n-i-1);
            }
            repi(j,i+c+1,n){
                if(s[j]=='o'){
                    usi.pb(n-1-j);
                    i = j-1;
                    break;
                }else{
                    continue;
                }
            }
        }
    }
    Vi ans;
    rep(i,k){
        if(usi[k-i-1]==mae[i]){
            ans.pb(mae[i]);
        }
    }
    rep(i,ans.size()){
        print(ans[i]+1);
    }
    if(ans.size()==0){
        print("");
    }
    return 0;
}


Measured memory_bytes: 6664
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10000000)

def search(values,hp,vp,item):
	if not (0<=hp<len(values)): return
	if not (0<=vp<len(values[hp])): return
	if item!=values[hp][vp]: return
	values[hp][vp]=True
	search(values,hp-1,vp,item)
	search(values,hp+1,vp,item)
	search(values,hp,vp-1,item)
	search(values,hp,vp+1,item)

def solve(values):
	count=0
	for i in range(len(values)):
		for j in range(len(values[i])):
			if values[i][j] in ['@','#','*']:
				search(values,i,j,values[i][j])
				count+=1
	return count

def main():
	line,values=input().strip(),list()
	while line!='0 0':
		H,W = list(map(int,line.split(' ')))
		value = list()
		for _ in range(H):
			value.append(list(x for x in input().strip()))
		values.append(value)
		line = input().strip()
	for value in values:
		print(solve(value))

if __name__=='__main__':
	main()

Measured memory_bytes: 15784
#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 p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll X;
int main(){
	cin >> X;
	if((X % 100 <= (X / 100) * 5)){
		p(1);
	}else{
		p(0);
	}
	return 0;
}


Measured memory_bytes: 256
import sys
for i in sys.stdin.readlines():
    line = i.split()
    a = int(line[0])
    op = line[1]
    b = int(line[2])
    if op == "?":
        break
    elif op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)

Measured memory_bytes: 7648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


string S;
int main() {
	cin >> S;
	if(S.length() < 4) {
		cout << "No" << endl;
	}
	else{
		if(S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I'){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
}

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

int main(void){

	int n, x, sum = 0;
	cin >> n >> x;

	do{
		for (int i = 1; i <= n; i++){
			for (int j = i+1; j <= n; j++){
				for (int k = j+1; k <= n; k++){
					if (i + j + k == x)	sum++;
				}
			}
		}
		cout << sum << endl;
		sum = 0;
		cin >> n >> x;
	} while (!(n == 0 && x == 0));


	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <iomanip>
#include <math.h>
using namespace std;
typedef long long ll;

int n;
char ans[1010][1010];

void put(int k) {
    for (int i = 0; i < k / 2 - 1; i++) {
        ans[i][i] = ans[i][i + 1] = 'a' + (i % 2);
        ans[k - 1 - i][k - 1 - i] = ans[k - 1 - i][k - 2 - i] = 'c' + (i % 2);
        ans[i][k - 1 - i] = ans[i + 1][k - 1 - i] = 'e' + (i % 2);
        ans[k - 1 - i][i] = ans[k - 2 - i][i] = 'g' + (i % 2);
    }
    ans[k / 2 - 1][k / 2 - 1] = ans[k / 2 - 1][k / 2] = 'y';
    ans[k / 2][k / 2 + 1] = ans[k / 2 + 1][k / 2 + 1] = 'y';
    ans[0][k / 2] = ans[0][k / 2 + 1] = 'v';
    ans[k - 1][k / 2 - 1] = ans[k - 1][k / 2] = 'w';
    ans[k / 2][k - 1] = ans[k / 2 + 1][k - 1] = 'x';
    ans[k / 2][0] = ans[k / 2 - 1][0] = 'z';
}

int main() {
    cin >> n;
    if (n == 2) {
        cout << -1 << endl;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) ans[i][j] = '.';
    }
    if (n % 4 == 0) {
        for (int i = 0; i < n / 2; i++) {
            for (int j = 0; j < n / 2; j++) {
                ans[i][j] = 'a' + (i * 2) % 4 + (j / 2) % 2;
            }
        }
        for (int i = 0; i < n / 2; i++) {
            for (int j = 0; j < n / 2; j++) {
                ans[j][n - 1 - i] = 'e' + (i * 2) % 4 + (j / 2) % 2;
            }
        }
        for (int i = n / 2; i < n; i++) {
            for (int j = 0; j < n; j++) ans[i][j] = ans[n - 1 - i][n - 1 - j];
        }

    }
    else if (n % 2 == 1) {
        put(n);
    }
    else {
        put(n / 2);
        for (int i = 0; i < n / 2; i++) {
            for (int j = 0; j < n / 2; j++) {
                ans[i + n / 2][j] = ans[i][j];
                ans[i][j + n / 2] = ans[i][j];
                ans[i + n / 2][j + n / 2] = ans[i][j];
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) cout << ans[i][j];
        cout << endl;
    }

}

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

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> a = vector<int>(n,0);
    for(int i = 0; i < n; i++){cin >> a[i];}
    vector<int> b = vector<int>(n,0);
    for(int i = 0; i < n; i++){cin >> b[i];}
    ll pa = 0, pb = 0;
    for(int i = 0; i < n; i++){
        if(a[i]>b[i]){pa += a[i]-b[i];}
        else{pb += (b[i]-a[i])/2;}
    }
    if(pa <= pb){cout << "Yes\n";}
    else{cout << "No\n";}
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N,M;
    cin >> N >> M;
    cout << ((N - M) * 100 + M * 1900) * pow(2,M) << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int N;
    cin >> N;

    vector<string> S(N);
    rep(i, N) cin >> S[i];

    map<string, int> mp;
    rep(i, N) mp[ S[i] ]++;

    int count = 0;
    for (auto p : mp) count = max(count, p.second);

    for (auto p : mp) {
        if (p.second == count) cout << p.first << endl;
    }
}

Measured memory_bytes: 26752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int mod = (int) Math.pow(10, 9) + 7;

		long ans = 1;

		if (Math.abs(m-n) > 1) {
			System.out.println(0);
			return;
			}
		else {
			for (int i = 1; i <= n; i++) {
				ans = ans * i % mod;
			}
			for (int j = 1; j <= m; j++) {
				ans = ans * j % mod;
			}
		}

		System.out.println(m==n ? 2 * ans % mod: ans % mod);
	}}

Measured memory_bytes: 22996
#include <iostream>
#include<cstdio>
using namespace std;
int main(void){
    int n,m,sum;
   
    cin>>n>>m;
    int A[n][m],b[m];
    
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
         cin>>A[i][j];
          }
    }
    
    for(int j=0;j<m;j++){
         cin>>b[j];
    }
   for(int i=0;i<n;i++){
            sum=0;
            for(int k=0;k<m;k++){
                sum+=A[i][k]*b[k];
            }
        cout<<sum<<endl;
    }
         
         
}
    


Measured memory_bytes: 3068
import math
from collections import deque
from collections import defaultdict

import time

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq


n = readInt()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def ahaha(x):
	n = (-1+int((1+8*x)**0.5))//2
	return n

f = factorization(n)

if n==1:
	print(0)
	exit()

ans=0

for i in f:
	ans+=ahaha(i[1])

print(ans)

Measured memory_bytes: 9932
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  lint n;
  cin >> n;
  lint x = sqrt(n);
  while (n % x != 0) --x;
  cout << x + (n / x) - 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#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 ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;

//Union Find Tree
class UnionFindTree{
public:
  int treeCnt; //ツリーの数
  vector<int> rank,p;  //rank => 根の高さ, p => 親
  vector<int> num; //木の要素数
  UnionFindTree(){}
  UnionFindTree(int size){
    rank.resize(size,0);
    p.resize(size,0);
    num.assign(size,1);
    treeCnt = 0;
    REP(i,size){
      makeset(i);
    }
  }

  void makeset(int x){
    p[x] = x;
    rank[x] = 0;
    treeCnt++;
  }

  //同じ木に属しているか判定
  bool same(int x, int y){
    return findSet(x) == findSet(y);
  }

  //xとyが属している木をつなぐ
  void unite(int x, int y){
    link(findSet(x),findSet(y));
  }
  
  ///木と木を繋ぐ処理をする。(ついでに木の高さを調整)
  void link(int x, int y){
    if(!same(x,y)){
      if(rank[x] > rank[y]){
	p[y] = x;
	num[x] += num[y];
      }else{
	p[x] = y;
	if(rank[x] == rank[y]){
	  rank[y]++;
	}
	num[y] += num[x];
      }
      treeCnt--;
    }
  }

  //xが属している木の根を探る(ついでに木を操作)
  int findSet(int x){
    if(p[x] == x) return x;
    else return p[x] = findSet(p[x]);
  }

  int countTree(){
    return treeCnt;
  }

  int getNum(int a){
    return num[findSet(a)];
  }
};


int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  while(cin >> a >> b >> c){
    TSTART();
    
    string ans;
    if(a <= c && b >= c)ans = "Yes";
    else ans = "No";
    
    cout << ans << endl;
    TSTOP();
  }
    return 0;
}



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

int main() {
    double N, K;
    cin >> N >> K;

    double res = 0;
    for (int i = 1; i <= N; i++) {
        int score = i;
        double p = 1 / N;
        while (score < K) {
            score *= 2;
            p *= 0.5;
        }
        res += p;
    }
    printf("%.12f", res);
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,s,e) for (int i=s; i<=e; i++)
#define FOD(i,s,e) for (int i=s; i>=e; i--)
#define pb push_back
#define INF INT_MAX
#define SIZE 200000

using namespace std;

int N,K;
int h[SIZE],dp[SIZE];

int main() {
	cin >> N >> K;
	dp[0]=0;
	FOR(i,1,N) {
		cin >> h[i];
		dp[i]=0;
	}
	dp[2]=abs(h[2]-h[1]);
	FOR(i,3,N) {
		dp[i]=INF;
		FOR(j,1,fmin(K,i-1)) {
			dp[i]=fmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout << dp[N];
	
	return 0;
}


Measured memory_bytes: 1024
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 max = 0;
        int prev = 0;		
		for (int i = 0; i < m; i++) {
		    int x = sc.nextInt();
		    max = Math.max((x - prev) / 2, max);
		    prev = x;
		    if (i == 0) {
		        max = Math.max(max, x - 1);
		    } 
		    if(i == m - 1) {
		        max = Math.max(max, n - x);
		    }
		}
	    System.out.println(max);
	}
}



Measured memory_bytes: 63172
#include<iostream>
#include<string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    const std::string bad="Bad";
    const std::string good="Good";

    std::string security_code;

    std::cin >> security_code;
    int readiness = 0;
    rep(i, 3){
        if (security_code[i] == security_code[i+1]){
            readiness = -1;
        }
    }
    if(readiness==0) {
        std::cout << good;
    }else{
        std::cout << bad;
    }

}

Measured memory_bytes: 256
#include "iostream"
using namespace std;

int main(){
  
  int r, D, x;
  int x1;
  cin >> r >> D >> x;
  
  for(int i=1;i<=9;i++){
  	x=r*x-D;

    cout << x << "\n";
  }
  
  	x=r*x-D;
    cout << x ;
  
  return 0;
}

Measured memory_bytes: 256
main = do
  s <- getContents
  putStr . concat . map eachDataSet . dataSets . lines $ s

eachDataSet = showResult 
                . map fst . filter ((>= 1000000) . snd)
                . accumulate
                . map (map read . words)
showResult [] = "NA\n"
showResult is = unlines . map show $ is

-- accumulate [[101,10,3],[102,20,1],[101,30,2]] == [(101,90),(102,20)]
accumulate :: [[Int]] -> [(Int,Int)]
accumulate = foldl accum [] . map amount
  where
    amount [i,p,q] = (i, p * q)
    accum [] t = [t]
    accum (t:ts) (i,a) | fst t == i = (i, snd t + a) : ts
                       | otherwise  = t : accum ts (i,a)

-- dataSets ["2","aa","b","1","cc","0"] == [["aa","b"],["cc"]]
dataSets :: [String] -> [[String]]
dataSets (x:xs)
  | n == 0    = []
  | otherwise = take n xs : dataSets (drop n xs)
  where n = read x

Measured memory_bytes: 6232
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    S = [0] * 5

    march = ['M', 'A', 'R', 'C', 'H']
    for i in range(N):
        ts = in_s()
        fs = ts[0]
        if fs in march:
            S[march.index(fs)] += 1

    comb = itertools.combinations(range(5), 3)

    ans = 0
    for com in comb:
        t = 1
        for c in com:
            t *= S[c]
        ans += t

    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
    int m, n, ans = 0;
    cin >> m >> n;
    for(int i=0;i<m;i++){
        int cnt = 0;
        for(int j=0;j<n;j++){
            int a;
            cin >> a;
            cnt += a;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long int ll;
using namespace std;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,L;
cin>>N>>L;
vector<pair<int,int>> C(N);
rep(i,N) C[i]=mp(abs(L+i),L+i);

sort(C.begin(),C.end());
int total=0;
for(int i=1;i<N;i++){
    total+=C[i].second;
}
cout<<total<<endl;
//system("pause");
return 0;
}

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

int main()
{
	int i, N;
	char s[10001][11];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%s", s[i]);
	
	int j, count[3] = {}, flag[10001][2] = {};
	for (i = 1; i <= N; i++) {
		if (s[i][0] == 'B') {
			count[1]++;
			flag[i][1] = 1;
		}
		for (j = 0; s[i][j] != 0; j++) if (s[i][j] == 'A' && s[i][j+1] == 'B') count[2]++;
		if (s[i][j-1] == 'A') {
			count[0]++;
			flag[i][0] = 1;
		}
	}
	for (i = 1; i <= N; i++) if (flag[i][0] != flag[i][1]) break;
	if (count[0] > 0 && i > N) count[2]--;
	
	printf("%d\n", (count[0] < count[1])? count[2] + count[0]: count[2] + count[1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  ll n;
  cin >> n;
  ll sum = (n+1)*(n)/2;
  sum-=n;
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, ll>;

int main()
{
    string s;
    cin >> s;
    int ans = 1000;
    for (int i = 0; i < s.size() - 2; ++i)
    {
        string sub = s.substr(i, 3);
        int num = std::stoi(sub);
        ans = (min)(ans, abs(753 - num));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ls rt << 1
#define rs rt << 1 | 1
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define eps 1e-9
using namespace std;
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 * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 2e5 + 10;
int n, m;
int a[N], b[N];
set<int> st[2];
int main()
{
	n = read();
	m = read();
	rep(i, 1, m)
	{
		int x, y;
		x = read();
		y = read();
		if(x == 1) st[0].insert(y);
		if(x == n) st[1].insert(y);
		if(y == 1) st[0].insert(x);
		if(y == n) st[1].insert(x);
	}

	rep(i, 2, n)
		if(st[0].count(i) && st[1].count(i))
		{
			puts("POSSIBLE");
			return 0;
		}
	puts("IMPOSSIBLE");

	return 0;
}


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

int main () {
long long int  n,m,sum=0,i;
    cin>>n>>m;
  long long int a[m];
    for(i=1;i<=m;i++){
        cin>>a[i];
        sum=sum+a[i];
    }
    if(sum<=n)cout<<n-sum;
    else cout<<"-1";
}


Measured memory_bytes: 3712
/*
 * 0289.cc: Infinite Express
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int BN = 31;

/* typedef */

/* global variables */

/* subroutines */

int bitnum(int k) {
  int cnt = 0;
  for (int i = 0; i < BN; i++)
    if ((k >> i) & 1) cnt++;
  return cnt;
}

int step(int s, int d) { // 0 < s < d
  int ret = 0, msb = 0;
  //printf("s=%d, d=%d\n", s, d);

  for (int i = 0, bi = 1; i < BN; i++, bi <<= 1)
    if (s & bi) {
      if (s + bi > d) break;
      s += bi;
      msb = i;
      ret++;
    }
  //printf("ret=%d, msb=%d, s=%d, d=%d\n", ret, msb, s, d);

  ret += bitnum(d - s);
  return ret;
}

/* main */

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

  while (n--) {
    int si, di;
    cin >> si >> di;

    int ans = 0;

    if (si > 0)
      ans = step(si, di);
    else if (di < 0)
      ans = step(-di, -si);
    else
      ans = bitnum(-si) + bitnum(di);

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

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

void Main()
{
  int S,W;
  cin >> S >>W;
  if (W>=S) {cout << "unsafe" << endl;}
  else {cout << "safe" << endl;}
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

Measured memory_bytes: 3652
use std::io::prelude::*;

fn main() {
    let scan = std::io::stdin();

    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let v: Vec<&str> = line.split_whitespace().collect();

    let _n: usize = v[0].parse().unwrap_or(0);

    let mut s: [bool; 13] = [true; 13];
    let mut h: [bool; 13] = [true; 13];
    let mut c: [bool; 13] = [true; 13];
    let mut d: [bool; 13] = [true; 13];

    for line in scan.lock().lines() {
        let uline = line.unwrap();
        let vec: Vec<&str> = uline.split_whitespace().collect();
        let suit: &str = vec[0];
        let r: usize     = vec[1].parse().unwrap_or(0);
        if suit == "S" {
            s[r-1] = false;
        } else if suit == "H" {
            h[r-1] = false;
        } else if suit == "C" {
            c[r-1] = false;
        } else if suit == "D" {
            d[r-1] = false;
        }
    }
    for i in 0..13 {
        if s[i] {
            println!("S {}", i+1);
        }
    }
    for i in 0..13 {
        if h[i] {
            println!("H {}", i+1);
        }
    }
    for i in 0..13 {
        if c[i] {
            println!("C {}", i+1);
        }
    }
    for i in 0..13 {
        if d[i] {
            println!("D {}", i+1);
        }
    }
}


Measured memory_bytes: 5028
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main () {
  std::string str;
  std::cin >> str;
  std::sort(str.begin(), str.end());
  if (str == "abc")
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define pb              push_back
#define se              second
#define mp              make_pair
#define fi              first
#define del(a,vec)      vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f,l,v)   binary_search(f,l,v)
#define iter(a,b)       vector<int>::iterator a,b
#define lower(v,num)    lower_bound (v.begin(), v.end(), num);
#define upper(v,num)    upper_bound (v.begin(), v.end(), num); 
#define removecopy(a)   unique(a.begin(), a.end()); 
#define vi              vector<int> 
#define pi              pair<int,int>    
#define vpi             vector<pi>      
#define mlbb            ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)    
int mod =1000000007;
namespace Rahul{
    bool isPrime(int n) 
    {if (n <= 1)  return false; if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; }
    int pow (int x, int n,int mod) {//calculate x^n
    if (n == 0) return 1;

    int res = pow (x, n / 2,mod);

    res = (res * res) % mod;
    if (n % 2) res = (res * x ) % mod;

    return res;
    }
    int _gcd(int a,int b)
    {
        if(a==0)
            return b;
        else    
            return _gcd(b%a,a);
    }
    //s.erase(s.find(2)) where s={1,2,3,3,2}; 
};
using namespace Rahul;
int find(int h){
    
    if(h==1){
        return 1;
    }
    
        return (2*find(h/2) +1);
    
}
int32_t main()
{
    mlbb;
 
 
        int h;
        cin>>h;
        int ans = find(h);
        cout<<ans<<endl;
    
}


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

public class Main {
  static final long MOD = 1000000007;
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int n = Integer.parseInt(line[0]);
    int k = Integer.parseInt(line[1]);
    long[] max_n = new long[n + 2];
    long[] min_n = new long[n + 2];
    for(int i = 1; i <= n; i++){
      max_n[i] = max_n[i - 1] + (n + 1 - i);
      min_n[i] = min_n[i - 1] + (i - 1);
    }
    long answer = 0;
    for(int i = k; i <= n + 1; i++){
      answer += max_n[i] - min_n[i] + 1;
      answer = (answer + MOD) % MOD;
    }
    System.out.println(answer);
  }
}


Measured memory_bytes: 35648
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
          if (S.equals(T.substring(0,T.length()-1))){
              System.out.println("Yes");
          } else {
              System.out.println("No");
          }
    }
}

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

// @author : sam000013

#define int long long
#define PI 3.14159265
#define pb(x) push_back(x)
#define PI 3.14159265
#define all(v) v.begin(), v.end()
#define endl cout<<"\n" 
#define dbg(x) cout<<#x<<" "<<x;endl;
#define bye endl;return
#define uni 1.000000
using namespace std;

const int mod = 1000000007;
// template<typename T>

// void debug(vector<T> x){
//     for(auto e:x){
//         cout<<e<<" ";
//     }
//     cout<<"\n";
// }
/*


*/
int friends;
vector<int> gr[200005];
void dfs(int i, vector<bool>& vis){
    if(!vis[i]){
        vis[i] = true;
        friends++;
    }
    for(auto x: gr[i]){
        if(!vis[x])
            dfs(x, vis);
    }
    return;
}
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=0; i<m; i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        gr[x].push_back(y);
        gr[y].push_back(x);
    }    
    vector<bool> vis(n);
    int ans = 1;
    for(int i=0; i<n; i++){
        friends = 0;
        if(!vis[i] && gr[i].size() > 0){
            dfs(i, vis);
            ans = max(friends, ans);
        }
    }
    cout<<ans;bye;

}

signed main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1;
    // cin>>t;
    for(int i=1; i<=t; i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 23904
#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;
const int MOD = 1000000007;
const int MAXIMAM = 2147480000;

const int MAX = 2001;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCk(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    ll N, K;
    cin >> N >> K;
    ll BLUE = K;
    ll BLUE_BETWEEN = K - 1;
    ll RED = N - K;
    ll RED_SPACES = RED + 1;

    for(ll i=1;i<=K;i++){
      ll ans_l = nCk(RED_SPACES,i);
      ll ans_r = nCk(BLUE_BETWEEN,i-1);
      cout << ans_l * ans_r % MOD << endl;
    }
}

Measured memory_bytes: 256