akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);


int main(){
    int n;
    cin>>n;
    int res=0;
    int t=n/500;
    res+=t*1000;
    n-=t*500;
    res+=n/5*5;
    cout<<res<<endl;
    getchar();
    return 0;
}

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

#define inf 0x3f3f3f3f
#define endl '\n'
typedef long long ll;

int n, k;
int h[100005], dp[100005];

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

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

  for(int i=1; i<=n; i++){
    cin >> h[i];
    dp[i]=-1;
  }

  cout << frog(1) << endl;
}

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

typedef long long ll;
typedef long double ld;

int main(){
	int n,k;
	cin >> n >> k;
	ld ret = 0.0;
	for(int i = 1 ; i <= n ; i ++){
		ld r = 1.0;
		int x = i;
		while(x < k){
			r /= 2.0;
			x *= 2.0;
		}
		ret += r;
	}
	cout.precision(20);
	cout << ret/(ld)n << endl;
}

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

#define long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i);
#define for(i, a, b) for(int i = (a); i < (b); ++i)

int main(){

    int x, a;  cin >> x >> a;
    if(x < a)   cout << 0 << endl;
    else    cout << 10 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{int D, N; cin >> D >> N;
 
 if( N <= 99){
 if(D == 0){ cout << N << endl;}
 else if(D == 1){cout << N * 100 << endl;}
 else{cout << N * 10000 << endl;}}
else{
  if(D == 0){cout << "101" << endl;}
  else if( D == 1){cout << "10100" << endl;}
 else if( D == 2){cout << "1010000" << endl;}}
 return 0;
}

Measured memory_bytes: 256
import queue

def proceess(start_x,start_y):
    #print("start_x : " + str(start_x) + ", start_y : " + str(start_y))
    #insland = []
    #insland.append([start_x,start_y])
    new_island = queue.Queue()
    map[start_x][start_y] = 0
    new_island.put([start_x,start_y])
    while True:
        ob = new_island.get()
        x = ob[0]
        y = ob[1]
        #print("x : " + str(x) + ", y : " + str(y))

        for i in [-1,0,1]:
            for j in [-1,0,1]:
                nx = x + i
                ny = y + j

                if nx >= 0 and ny >= 0 and nx < h and ny < w:
                    if map[nx][ny] == 1:
                        #insland.append([nx,ny])
                        #print("ny : " + str(ny) + ", nx : " + str(nx))
                        new_island.put([nx,ny])
                        map[nx][ny] = 0

        #print("end 8 count.")
        if new_island.empty():
            break

while True:
    map = []

    tmp = input().split(" ")
    w = int(tmp[0])
    h = int(tmp[1])

    if w == 0 and h == 0:
        break


    for j in range(h):
        nova = []
        arm = input()
        for k in arm.split(" "):
            #k.rstrip('\n')
            nova.append(int(k))
        map.append(nova)

    #print(map)

    count = 0
    for i in range(h):
        for j in range(w):
            if map[i][j] == 1:
                #print("i : " + str(i) + ", j : " + str(j))
                proceess(i,j)
                count += 1

    print(count)



Measured memory_bytes: 6840
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a, b, k;
    cin >> a >> b >> k;
    if (a >= k) {
        a -= k;
        k = 0;
    }
    else {
        k -= a;
        a = 0;
    }
    if (b >= k) {
        b -= k;
        k = 0;
    }
    else {
        k -= b;
        b = 0;
    }
    cout << a << ' ' << b << '\n';

}


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

int main() {
    int n, co = 0, a, b;
    cin >> n;
    vector<int> per(n);
    vector<vector<int>> p(2, vector<int>(n));
    bool f = true;
    rep(i, 2) {
        rep(j, n) {
            cin >> p[i][j];
        }
    }
    int idx = 0;
    rep(i, n) per[i] = i + 1;
    do {
        co++;
        f = true;
        rep(i, n) {
            if (per[i] != p[0][i]) {
                f = false;
                break;
            }
        }
        if (f) {
            a = co;
            break;
        }
    } while (next_permutation(per.begin(), per.end()));
    sort(per.begin(), per.end());
    co = 0;
    do {
        co++;
        f = true;
        rep(i, n) {
            if (per[i] != p[1][i]) {
                f = false;
                break;
            }
        }
        if (f) {
            b = co;
            break;
        }
    } while (next_permutation(per.begin(), per.end()));
    cout << abs(a - b) << endl;
}

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

int main() {
  int a, b, c, d;
  std::string l, ba, r;
  l = "Left\n";
  ba = "Balanced\n";
  r = "Right\n";
  
  std::cin >> a >> b >> c >> d;
  if (a + b > c + d) {
	std::cout << l;
  } else if (a + b == c + d) {
    std::cout << ba;
  } else {
    std::cout << r;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include<climits>

#define ll long long
using namespace std;
int main()
{
   ll n;cin>>n;
   ll k=n%10;
   if((k==2)||(k==4)||(k==5)||(k==7)||(k==9))
   {
       cout<<"hon"<<endl;
   }
   else if((k==0)||(k==1)||(k==6)||(k==8))
   {
       cout<<"pon"<<endl;
   }
   else if(k==3)
   {
       cout<<"bon"<<endl;
   }
    return 0;
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  // 解答
  cout << (a + b == c + d ? "Balanced" : (a + b < c + d ? "Right" : "Left")) << endl;

  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let o: String = sc.read();
    let o: Vec<char> = o.chars().collect();
    let e: String = sc.read();
    let e: Vec<char> = e.chars().collect();
    let mut ans: String = String::new();
    for i in 0..o.len() {
        ans.push(o[i]);
        if i < e.len() {
            ans.push(e[i]);
        }
    }
    println!("{}", ans);
}

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

void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}

int main(int argc, char const *argv[])
{
	#define int long long
	// fastio();
	int n, w;
	cin >> n >> w;
	vector<int> weights(n), values(n);
	for (int i = 0; i < n; ++i) {
		cin >> weights[i] >> values[i];
	}
	vector<vector<int> > dp(n, vector<int>(w + 1, 0LL));
	for (int i = 0; i < n; ++i) {
		for (int j = 1; j <= w; ++j) {
			if (weights[i] <= j) {
				// take ith item
				dp[i][j] = values[i];
				if (i > 0) dp[i][j] += dp[i-1][j-weights[i]];
			}
			// don't take
			if (i > 0) {
				dp[i][j] = max(dp[i][j], dp[i-1][j]);
			}
		}
	}
	cout << dp[n-1][w] << endl;
	return 0;
}

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N, M, A;
    cin >> N >> M;
    while (M--){
        cin >> A;
        N -= A;
    }
    N < 0 ? cout << -1 : cout << N;
}

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

int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<char>> ans(H+2, vector<char>(W+2, '#'));
    for (int i = 1; i < H + 1; i++){
        for (int j = 1; j < W + 1; j++){
            cin >> ans.at(i).at(j);
        }
    }
    for (int i = 0; i < H + 2; i++){
        for (int j = 0; j < W + 2; j++){
            cout << ans.at(i).at(j);
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  val xs = List.fill(n)(sc.nextInt)

  var minHp = Int.MaxValue
  for (p <- xs.min to xs.max) {
    val hp = xs.foldLeft(0)((z, x) => z + Math.pow(x - p, 2).toInt)
    if (hp < minHp) {
      minHp = hp
    }
  }
  println(minHp)
}


Measured memory_bytes: 25656
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		if(i%3==0 || i%5==0)
			continue;
		ans+=i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

class Vec;
Vec operator/(const Vec& v, const double& divisor);
Vec operator*(const double& scale, const Vec& v);

class Vec {
  using F = double;
  vector<F> container;

 public:
  Vec(size_t size) : container(size) {}
  Vec(initializer_list<F> elements)
      : container(elements.begin(), elements.end()) {}
  size_t dim() const { return container.size(); }
  F& operator[](const size_t size) { return container.at(size); }
  const F& operator[](const size_t size) const { return container.at(size); }
  Vec operator+(const Vec& other) const {
    Vec ret(*this);
    for (size_t i = 0; i < dim(); i++) ret[i] += other[i];
    return ret;
  }
  Vec operator-(const Vec& other) const { return (*this) + (-other); }
  Vec operator-() const { return -1.0 * (*this); }
  F inner(const Vec& other) const {
    F acc = 0;
    for (size_t i = 0; i < dim(); i++) {
      acc += (*this)[i] * other[i];
    }
    return acc;
  }
  F norm() const { return sqrt(inner(*this)); }
  Vec unit() const { return (*this) / this->norm(); }
  F ccw(const Vec& other) const {
    return (*this)[0] * other[1] - other[0] * (*this)[1];
  }
};
Vec operator/(const Vec& v, const double& divisor) { return 1.0 / divisor * v; }
Vec operator*(const double& scale, const Vec& v) {
  Vec ret(v);
  for (size_t i = 0; i < ret.dim(); i++) ret[i] *= scale;
  return ret;
}

class Line {
  Vec m_grad;
  double m_bias;

 public:
  Line(const Vec& grad, double bias) : m_grad(grad), m_bias(bias) {}
  static Line fromPoints(const Vec& p0, const Vec& p1) {
    Vec d = p0 - p1;
    Vec g({-d[1], d[0]});
    return Line(g, g.inner(p0));
  }
  const Vec& grad() const { return m_grad; }
  double bias() const { return m_bias; }
  double dist(const Vec& p) const {
    return abs(m_grad.inner(p) - m_bias) / m_grad.norm();
  }
  Vec projection(const Vec& p) const {
    const Vec g = m_grad.unit();
    const Vec h({-g[1], g[0]});
    return m_bias / m_grad.norm() * g + h.inner(p) * h;
  }
};

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

  rep(i, q) {
    double x0, y0, x1, y1, x2, y2, x3, y3;
    cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    const Vec v0({x1 - x0, y1 - y0}), v1({x3 - x2, y3 - y2});
    const double a = v0.unit().inner(v1.unit());
    const double EPS = 1e-10;
    if (abs(a) < EPS) {
      cout << 1 << endl;
    } else if (abs(abs(a) - 1) < EPS) {
      cout << 2 << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3288
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		out.println(2 * Math.PI * ni());
	}
		
	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 33300
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main() {
	int n; cin >> n;
	int flag = 0;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == n) {
				flag = 1;
				break;
			}
		}
	}
	if (flag == 1) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	ll n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s;
	bool flag;
	if (c == d) {
		flag = false;
	}
	else if (c > d) {
		flag = false;
		for (ll i = b-2; i <= d-2; i++) {
			if (s[i] == '.'&&s[i + 1] == '.'&&s[i + 2] == '.') {
				flag = true;
			}
		}
		for (ll i = a - 1; i <= c - 2; i++) {
			if (s[i] == '#'&&s[i + 1] == '#') {
				flag = false;
			}
		}
	}
	else {
		flag = true;
		for (ll i = a - 1; i <= d - 2;i++) {
			if (s[i] == '#'&&s[i + 1] == '#') {
				flag = false;
			}
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3592
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

#include <atcoder/twosat>
using namespace atcoder;

int main() {
  int n, d; cin >> n >> d;
  vector<int> x(n), y(n); REP(i, n) cin >> x[i] >> y[i];
  two_sat ts(n);
  REP(i, n) FOR(j, i + 1, n) {
    if (abs(x[i] - x[j]) < d) ts.add_clause(i, false, j, false);
    if (abs(x[i] - y[j]) < d) ts.add_clause(i, false, j, true);
    if (abs(y[i] - x[j]) < d) ts.add_clause(i, true, j, false);
    if (abs(y[i] - y[j]) < d) ts.add_clause(i, true, j, true);
  }
  if (!ts.satisfiable()) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  vector<bool> ans = ts.answer();
  REP(i, n) cout << (ans[i] ? x[i] : y[i]) << '\n';
  return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
ll A[200100],B[200100];
int main(){
	scanf("%d",&N);
	bool flag = true;
	for(int i=0;i<N;i++){
		scanf("%lld %lld",&A[i],&B[i]);
		if(A[i]!=B[i])flag = false;
	}
	if(flag){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	vector<ll> vec;
	for(int i=0;i<N;i++){
		ans += A[i];
		if(A[i]>B[i])vec.pb(B[i]);
	}
	sort(all(vec));
	ans -= vec[0];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main(){
  long long n;
  cin >>n;
  long long c[n];
  for(int i=0;i<n;i++){
    cin>>c[i];
    }
  long long ans=0;
  for(int i=0;i<n-1;i++){
    ans+=c[i]/2;
    if(c[i]%2==1&&c[i+1]>0){
      c[i+1]--;
      ans++;
    }
  
    }
  ans+=c[n-1]/2;
  cout <<ans<<endl;
  return 0;
  }

    

Measured memory_bytes: 1024
from collections import deque

def fast_bellman_ford(n, s, graph, edge_n, init_val): #どう？
    d = [init_val] * n
    d[s] = 0
    q = deque([s])
    checker = [-1] * n
    for i in range(n):
        m = len(q)
        for _ in range(m):
            vf = q.popleft()
            for vt, w in graph[vf]:
                if d[vt] > d[vf] + w:
                    d[vt] = d[vf] + w
                    if checker[vt] < i:
                        q.append(vt)
                        checker[vt] = i
        if not q:
            break
    if q: #閉路の存在
        minus_inf = -float('inf')
        i += 1
        while q:
            m = len(q)
            for _ in range(m):
                vf = q.popleft()
                for vt, w in graph[vf]:
                    if d[vt] > d[vf] + w:
                        d[vt] = minus_inf
                        if checker[vt] < i:
                            q.append(vt)
                            checker[vt] = i
            i += 1
    return d

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    a, b, w = map(int, input().split())
    graph[a-1].append((b-1, -w))
d = fast_bellman_ford(n, 0, graph, 2 * m, float('inf'))
print(-d[-1] if d[-1] != -float('inf') else 'inf')






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

const int N_MAX = 100000;
int dat[N_MAX * 4];

int n;
int n_add;

void init() {
	int k = 0;
	while ((n - 1) >> k) k++;
	n_add = (1 << k) - 1;
	for (int i = 0; i < n_add * 2; ++i) {
		dat[i] = 0;
	}
}

void add(int x, int y) {
	x += n_add;
	while (x > 0) {
		dat[x] += y;
		x = x / 2;
	}
}

int getSum(int x, int y) {
	x = x + n_add;
	y = y + n_add;

	int sum = 0;
	while (true) {
		if (x > y)
			return sum;
		else if (x == y)
			return sum + dat[x];

		bool xodd = x % 2;
		bool yodd = y % 2;
		if (xodd && yodd) {
			sum += dat[x];
			x = x / 2 + 1;
			y = y / 2;
		} else if (xodd && !yodd) {
			sum += dat[x] + dat[y];
			x = x / 2 + 1;
			y = y / 2 - 1;
		} else if (!xodd && yodd) {
			x = x / 2;
			y = y / 2;
		} else {
			sum += dat[y];
			x = x / 2;
			y = y / 2 - 1;
		}
	}
}

int main() {
	int q;
	cin >> n >> q;
	init();
	for (int i = 0; i < q; ++i) {
		int c, x, y;
		cin >> c >> x >> y;
		if (c == 0)
			add(x, y);
		else
			cout << getSum(x, y) << endl;
	}
}

Measured memory_bytes: 2184
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void primeNumber(int N, vector<bool>& prime)
{
    prime.assign(N+1, true);
    prime [0] = prime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(prime[i]){
            for(int j=i; i*j<=N; j++){
                prime[i*j] = false;
            }
        }
    }
}

int main()
{
    vector<bool> prime;
    primeNumber(10000, prime);

    for(;;){
        int n;
        if(!(cin >> n))
            return 0;

        int ret = 0;
        for(int i=1; i<=n; ++i){
            if(prime[i] && prime[n+1-i])
                ++ ret;
        }

        cout << ret << endl;
    }
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll x;
    double dy;
    cin >> x >> dy;
    ll y = (100 * dy + 1e-5);
    ll ans = (x * y) / 100;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3724
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
answer=0
for i in range(n):
  if a[i]>=b[i]:
    answer+=b[i]
    a[i]=0
    b[i]=0
  elif a[i]<b[i] and a[i]+a[i+1]>=b[i]:
    answer+=b[i]
    b[i]-=a[i]
    a[i+1]-=b[i]
  elif a[i]<b[i] and a[i]+a[i+1]<b[i]:
    answer+=(a[i]+a[i+1])
    b[i]-=(a[i]+a[i+1])
    a[i]=0
    a[i+1]=0
print(answer)

Measured memory_bytes: 19004
while True:

    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if (i+k)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print()


Measured memory_bytes: 7000
n=int(input())
b=list(map(int,input().split()))
a=[]
ans=0
for i in range(n-1):
    if i!=0:
        if b[i]<=b[i-1]:
            ans+=b[i]
            a+=[b[i]]
        else:
            ans+=b[i-1]
            a+=[b[i-1]]
print(b[0]+ans+b[n-2])

Measured memory_bytes: 3060
import Control.Applicative
import Control.Monad
import Data.Char (digitToInt)

main :: IO ()
main = solve <$> getLine >>= putStrLn

solve :: String -> String
solve [sa, sb, sc, sd] = head $ do
  op1 <- "+-"
  op2 <- "+-"
  op3 <- "+-"
  guard $ f op3 (f op2 (f op1 a b) c) d == 7
  return [sa, op1, sb, op2, sc, op3, sd, '=', '7']
  where
    
    [a, b, c, d] = map digitToInt [sa, sb, sc, sd]
    f '+' x y = x + y
    f '-' x y = x - y


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

int d[3][4]={{0,4,5,1},{0,2,5,3},{4,2,1,3}};//d,u,l,r

void dice(int a[6], int n){
	int tmp = a[d[n][0]];
	a[d[n][0]] = a[d[n][1]];
	a[d[n][1]] = a[d[n][2]];
	a[d[n][2]] = a[d[n][3]];
	a[d[n][3]] = tmp;
}

int check(int a[6], int b[6]){
	for(int i = 0;i < 6;i++)if(a[i] != b[i])return 0;
	return 1;
}

int func(int a[6], int b[6]){
	for(int i = 0;i < 6;i++){
		for(int j = 0;j < 4;j++){
			dice(b, 0);
			if(check(a, b))return 1;
		}
		if(i%2 == 0)dice(b, 1);
		else dice(b, 2);
	}
	return 0;
}

int calc(int a[100][6], int n){
	for(int i = 0;i < n-1;i++){
		int b[6], c[6];
		for(int j = 0;j < 6;j++)b[j] = a[i][j];
		for(int j = i+1;j < n;j++){
			for(int k = 0;k < 6;k++)c[k] = a[j][k];
			if(func(b, c))return 1;
		}
	}
	return 0;
}

int main(){
	int a[100][6];
	int n;cin >> n;
	for(int j = 0;j < n;j++)
	for(int i = 0;i < 6;i++)cin >> a[j][i];
	
	if(calc(a, n))cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}




Measured memory_bytes: 3100
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    use std::collections::HashSet;
    let h = get!(usize);
    let w = get!(usize);
    let mut f = vec![vec![false; w]; h];
    let mut es = HashSet::new();
    for y in 0..h as usize {
    	let s = get().as_bytes();
        for x in 0..w as usize {
        	if s[x] == b'#' {
            	f[y][x] = true;
                es.insert(y * w + x);
            }
        }
    }
    let mut ans = 0;
    let dt = vec![0, 1, 0, -1, 0];
    while es.len() > 0 {
    	let mut rs = HashSet::new();
        for &e in es.iter() {
        	let y = e / w;
            let x = e  % w;
        	for i in 0..4 {
            	let x = x as i32 + dt[i];
                let y = y as i32 + dt[i+1];
                if y < 0 || y >= h as i32 || x < 0 || x >= w as i32 {
                	continue;
                }
                let y = y as usize;
                let x = x as usize;
                if f[y][x] {
                	continue;
                }
                f[y][x] = true;
                rs.insert(y * w + x);
            }
        }
        if rs.len() > 0 {
        	ans += 1;
        }
        es = rs;
    }
    
    println!("{}", ans);
}

Measured memory_bytes: 55592
import fractions
from functools import reduce
n=int(input())
t=[int(input()) for i in range(n)]
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)

def lcm_list(num):
    return reduce(lcm_base,num,1)
print(lcm_list(t))

Measured memory_bytes: 5048
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int ctoi(char);

int main()
{
    int H, W;
    cin >> H >> W;

    vector<vector<char>> sq(H, vector<char>(W));
    rep(i, H)
    {
        rep(j, W)
        {
            char x;
            cin >> x;
            sq.at(i).at(j) = x;
        }
    }
    // cout << "sec1" << endl;
    vector<int> delete_list_1;
    rep(i, sq.size())
    {
        rep(j, sq.at(i).size())
        {
            if (sq.at(i).at(j) == '#')
            {
                break;
            }
            if (j == sq.at(i).size() - 1)
            {
                delete_list_1.push_back(i);
            }
        }
    }
    for (int i = delete_list_1.size() - 1; i >= 0; i--)
    {
        sq.erase(sq.begin() + delete_list_1.at(i));
    }
    // cout << "sec2" << endl;
    vector<int> delete_list_2;
    rep(j, sq.at(0).size())
    {
        rep(i, sq.size())
        {
            if (sq.at(i).at(j) == '#')
            {
                break;
            }
            if (i == sq.size() - 1)
            {
                delete_list_2.push_back(j);
            }
        }
    }
    for (int j = delete_list_2.size() - 1; j >= 0; j--)
    {
        rep(i, sq.size())
        {
            sq.at(i).erase(sq.at(i).begin() + delete_list_2.at(j));
        }
    }
    // cout << "sec3" << endl;
    for (vector<char> cs : sq)
    {
        for (char c : cs)
        {
            cout << c;
        }
        cout << endl;
    }
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}


Measured memory_bytes: 256
s = gets.chop.split("")
t = gets.chop.split("")
match_flg = false

(0..s.length-t.length).to_a.reverse.each do |si|
  t.each_with_index do |tv,ti|
    break if s[si + ti].nil?
    break unless s[si + ti] == tv or s[si + ti] == "?"
    match_flg = true if ti == t.length-1
  end

  if match_flg
    for i in 0..t.length-1 do
      s[si+i] = t[i]
    end
    print s.join.gsub(/\?/, "a")
    exit
  end
end

print "UNRESTORABLE"

Measured memory_bytes: 1788
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    static List<int[]> QUERY = new ArrayList<>();
    static List<Double> sqrts = new ArrayList<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] xy = new int[2][n];
        for (int i = 0; i < n; i++) {
            xy[0][i] = sc.nextInt();
            xy[1][i] = sc.nextInt();
        }

        // X
        List<Double> d1 = new ArrayList<>();
        permutation(xy[0]);
        d1.addAll(sqrts);
        sqrts.clear();

        // Y
        permutation(xy[1]);
        List<Double> d2 = new ArrayList<>();
        d2.addAll(sqrts);

        double ans = 0;
        for (int i = 0; i < d1.size(); i++) {
            ans += Math.sqrt(d1.get(i) + d2.get(i));
        }
        System.out.println(ans / prime(n));
    }

    private static int prime(int n) {
        int ans = 1;
        for (int i = 1; i <= n; i++) {
            ans *= i;
        }
        return ans;
    }

    private static void calc(int[] q) {
        for (int j = 0; j < q.length - 1; j++) {
            double t = Math.pow(q[j] - q[j + 1], 2);
            sqrts.add(t);
        }
    }

    private static void permutation(int[] seed) {
        int[] perm = new int[seed.length];
        boolean[] used = new boolean[seed.length];
        buildPerm(seed, perm, used, 0);
    }

    private static void buildPerm(int[] seed, int[] perm, boolean[] used, int index) {
        if (index == seed.length) {
            calc(perm);
            QUERY.add(perm);
            return;
        }

        for (int i = 0; i < seed.length; ++i) {
            if (used[i])
                continue;
            perm[index] = seed[i];
            used[i] = true;
            buildPerm(seed, perm, used, index + 1);
            used[i] = false;
        }
    }
}



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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2) ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
//#define MULTIPLE_TEST_CASE
void solution() {
  int d, l, r;
  cin >> l >> r >> d;
  cout << r / d - (l - 1) / d << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


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

int main(){
  int a, b;
  cin >> a >> b;

  if(a > b) cout << "a > b" << endl;
  if(a < b) cout << "a < b" << endl;
  if(a == b) cout << "a == b" << endl;

  return 0;
}


Measured memory_bytes: 3084
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(len(a)):
        for j in range(i, len(a)):
            for k in range(j,len(a)):            
                if i == j or j == k:
                    pass
                else:
                    if (a[i] <(a[j]+a[k])) and (a[j] <(a[i]+a[k])) and (a[k] <(a[j]+a[i])) and (a[i] != a[j]) and a[j] != a[k] and a[k] != a[i]:
                        ans += 1
                    else:
                        pass

print(ans)

Measured memory_bytes: 9240
def role(s:str):
    s0, s1 = s[:len(s)-1], s[len(s)-1]
    return s1 + s0

def main():
    s = input()
    t = input()
    for _ in range(len(t)):
        if s == t:
            print('Yes')
            return
        s = role(s)
    print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
#define M 200005
int a[M],b[M];
int main(){
	int n,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=n;i>=1;--i){
		int v=0;
		for(int j=i+i;j<=n;j+=i)v^=b[j];
		b[i]=v^a[i];
		if(b[i])++ans;
	}
	printf("%d\n",ans);
	for(int i=1;i<=n;++i)if(b[i])printf("%d ",i);
}

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

class ABC123B{
    public static void Main(){
        var a = int.Parse(Console.ReadLine());
        Console.ReadLine();
        Console.ReadLine();
        Console.ReadLine();
        var e = int.Parse(Console.ReadLine());
        var k = int.Parse(Console.ReadLine());
        if(e-a > k)Console.WriteLine(":(");
        else Console.WriteLine("Yay!");   
    }
}

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

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

int main() {
    char a;
    cin >> a;

    if (isupper(a)) {
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }

    return 0;
}


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

using namespace std;
 
//#define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)
#define PI 3.14159265358979323846264338327950L

ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
 
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ios_base::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    cout << 6 - a - b << endl;
    return 0;
}


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

using namespace std;

#define int long long int
//#define lint long long int
#define test int t; cin>>t; while(t--)
#define mod 1000000007    
#define pb push_back

int32_t main()
{	
	int n;
	cin>>n;
	cout<<n +(n*n)+(n*n*n);
	
	return 0;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		int x = Integer.parseInt(in.readLine());

		int x3 = (int)Math.pow(x, 3);

		System.out.println(x3);

	}

}

Measured memory_bytes: 24108
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k;
ll a[500],b[500],c=0;
ll n,m,q;
ll ans;
 
int main(){
 
	cin>>q;
 
	for(i=0;i<q;i++){
		cin>>a[i]>>b[i];
	}
	for(i=0;i<q;i++){
		ans=0;
		if(a[i]>b[i])swap(a[i],b[i]);
		ll r=sqrt((b[i]*a[i]-1)*1.0000000);
		c=r;
		for(j=c-2;j<=c+2;j++){
			if(j*j<b[i]*a[i])r=j;
		}
		if(r*r+r>b[i]*a[i]-1){
			ans=2*r-2;
		}else{
			ans=2*r-1;
		}
		if(b[i]==a[i])ans=2*a[i]-2;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repbit(bit,n) for (int bit = 0; bit < (1<<n); bit++)
using namespace std;
typedef long long ll;

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

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

	if (k % 2 == 0 or k % 5 == 0) {
		cout << -1 << endl;
		return 0;
	}
	int ans;
	vector<int> s;
	s.push_back(0);
	int id = 0;
	ll term = 7 % k;
	while (true) {
		int& ref = s.back();
		if (id != 0 and ref == 0) {
			ans = id;
			break;
		}
		s.push_back((ref + term) % k);
		id++;
		term *= 10;
		term %= k;
	}
	cout << ans << endl;
	return 0;
}


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

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,ans;
	cin>>n;
	ans=0;
	for (int i=1;i<=min(9,n);++i)
	{
		++ans;
		//cout<<i<<" ";
	}
	for (int i=100;i<=min(999,n);++i)
	{
		++ans;
		//cout<<i<<" ";
	}
	for (int i=10000;i<=min(99999,n);++i)
	{
		++ans;
		//cout<<i<<" ";
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
h,w,n=map(int,input().split())
y,x=map(int,input().split())
ul=y-1
dl=h-y
ll=x-1
rl=w-x
s=input()
t=input()
#U
for i in range(n):
  if s[i]=="U":ul-=1
  if ul<0:exit(print("NO"))
  if t[i]=="D":ul=min(ul+1,h-1)
#D
for i in range(n):
  if s[i]=="D":dl-=1
  if dl<0:exit(print("NO"))
  if t[i]=="U":dl=min(dl+1,h-1)
#L
for i in range(n):
  if s[i]=="L":ll-=1
  if ll<0:exit(print("NO"))
  if t[i]=="R":ll=min(ll+1,w-1)
#R
for i in range(n):
  if s[i]=="R":rl-=1
  if rl<0:exit(print("NO"))
  if t[i]=="L":rl=min(rl+1,w-1)
print("YES")

Measured memory_bytes: 3888
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
using namespace std;

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
    int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
		return false;
	}
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

signed main(){
    char c;
    int ans=0;
    while(cin>>c){
        ans+=c-'0';
    }
    
    if(ans%9==0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;
const int nmax=101234;

int n,m,x,y,len[nmax],flg[nmax],flg2[nmax],flg3[nmax],flg4[nmax],res;
vector<vector<int> > vt(nmax),v2(nmax);
stack<int> st1;
queue<int> q2;

void solve2(int pos)
{
    for(int i=0; i<(int)v2[pos].size(); ++i)
    {
        if(flg4[v2[pos][i]]==0)
            solve2(v2[pos][i]);
        if(len[pos]<len[v2[pos][i]]+1)
            len[pos]=len[v2[pos][i]]+1;
    }
    flg4[pos]=1;
}




void solve(int st)
{
    q2.push(st);
    while(!q2.empty())
    {
        int pos=q2.front();
        q2.pop();
        if(flg2[pos]==0)
        {
            for(int i=0; i<(int)vt[pos].size(); ++i)
            {
                if(flg3[vt[pos][i]]==1)
                {
                    if(len[pos]<len[vt[pos][i]]+1)
                        len[pos]=len[vt[pos][i]]+1;
                }
                else
                {
                    if(flg2[vt[pos][i]]==0)
                        q2.push(vt[pos][i]);
                    v2[pos].pb(vt[pos][i]);
                }
            }
            st1.push(pos);
            flg2[pos]=1;
        }
    }
    while(!st1.empty())
    {
        if(flg4[st1.top()]==0)
            solve2(st1.top());
        flg4[st1.top()]=1;
        st1.pop();
    }
}

int main()
{
    scanf("%d %d",&n,&m);
    for(int i=0; i<m; ++i)
    {
        scanf("%d %d",&x,&y);
        vt[x].pb(y);
        flg[y]=1;
    }
    for(int i=1; i<=n; ++i)
    {
        if(flg[i]==0)
            solve(i);
    }
    for(int i=1; i<=n; ++i)
    {
        if(res<len[i])
            res=len[i];
    }
    printf("%d",res);
    return 0;
}


Measured memory_bytes: 13312
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int main() {


	char c;
	cin >> c;
	if (c == 'A')
	{
		cout << 'T' << endl;
	}
	else if (c == 'T')
	{
		cout << 'A' << endl;
	}
	else if (c == 'G') {
		cout << 'C' << endl;
	}
	else if (c == 'C')
	{
		cout << 'G' << endl;
	}


	return 0;
}

Measured memory_bytes: 256
N, M, Q = [int(i) for i in input().split(" ")]
ans = 0
que = [1 for i in range(1, N+1)]
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = [int(j) for j in input().split(" ")]

while True:
    if len(que) == N:
        s=0
        for i in range(Q):
            if que[b[i]-1] - que[a[i]-1] == c[i]:
                s += d[i]
        ans = max(ans, s)
    n = que.pop()
    if n < M:
        for i in range(N):
            que.append(n+1)
            if len(que) == N:
                break
    if len(que) == 0:
        break

print(ans)

Measured memory_bytes: 9228
#include <iostream>

using namespace std;

int main()
{
	int  h, w;

	while (true)
	{
		cin >> h >> w;

		if (h == 0 && w == 0)
		{
			break;
		}

		for (int i = 0; i < h; i++)
		{
				for (int j = 0; j < w; j++)
				{
					if ((((i + 1) % 2 != 0) && ((j + 1) % 2 != 0)) || (((i + 1 )% 2 == 0) && ((j + 1) % 2 == 0)))
					{
						cout << "#";
					}
					else
					{
						cout << ".";
					}
				}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3104