akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ac = 0, wa = 0, tle = 0, re = 0;
		for (int i = 0; i < N;i++) {
			String S = sc.next();
			if (S.equals("AC")) {
				ac++;
			}
			else if (S.equals("WA")) {
				wa++;
			}
			else if (S.equals("TLE")) {
				tle++;
			}
			else {
				re++;
			}
		}
		System.out.println("AC x " + ac);
		System.out.println("WA x " + wa);
		System.out.println("TLE x " + tle);
		System.out.println("RE x " + re);
	}
}

Measured memory_bytes: 58340
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

struct task {
  string name;
  int time;
};

#define MAX_N (100100)
task tq[MAX_N];
int head, tail;

int size() {
  if (tail >= head) return tail - head;
  else return MAX_N - (head - tail);
}

bool empty() {
  return size() == 0;
}

bool full() {
  return size() == MAX_N - 1;
}

void push(const task& t) {
  if (full()) {
    cerr << "Stack is full" << endl;
    exit(1);
  }
  tq[tail] = t;
  tail = (tail+1)%MAX_N;
}

task pop() {
  if (empty()) {
    cerr << "Stack is empty" << endl;
    exit(1);
  }
  task& res = tq[head];
  head = (head+1)%MAX_N;
  return res;
}

int main(int argc, char **argv)
{
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    task t;
    cin >> t.name >> t.time;
    push(t);
  }

  int elapsed = 0;
  while (!empty()) {
    task t = pop();
    if (t.time <= q) {
      elapsed += t.time;
      cout << t.name << " " << elapsed << endl;
    } else {
      elapsed += q;
      t.time -= q;
      push(t);
    }
  }

  return 0;
}

Measured memory_bytes: 7112
import Foundation
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
let n=Int(readLine()!)!
var aa=readInts()
var bb=readInts()
var cc=readInts()
var before=40000
var ans=0
for a in aa{
  ans+=bb[a-1]
  if before==a-1{
    ans+=cc[a-2]
  }
  before=a
}
print(ans)

Measured memory_bytes: 13188
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

class Node
{
public:
  int location;
  int p, l, r;
  Node() {}
};

class Point
{
public:
  int id, x, y;
  Point() {}
  Point(int id, int x, int y) : id(id), x(x), y(y) {}
  bool operator<(const Point &p) const
  {
    return id < p.id;
  }

  void print()
  {
    printf("%d\n", id);
  }
};

static const int MAX = 1000000;
static const int NIL = -1;

int n;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2)
{
  return p1.x < p2.x;
}
bool lessY(const Point &p1, const Point &p2)
{
  return p1.y < p2.y;
}

int makeKDTree(int l, int r, int depth)
{
  if (!(l < r))
  {
    return NIL;
  }

  int mid = (l + r) / 2;
  int t = np++;
  if (depth % 2 == 0)
  {
    sort(P + l, P + r, lessX);
  }
  else
  {
    sort(P + l, P + r, lessY);
  }
  T[t].location = mid;
  T[t].l = makeKDTree(l, mid, depth + 1);
  T[t].r = makeKDTree(mid + 1, r, depth + 1);

  return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans)
{
  int x = P[T[v].location].x;
  int y = P[T[v].location].y;

  if (sx <= x && x <= tx && sy <= y && y <= ty)
  {
    ans.push_back(P[T[v].location]);
  }

  if (depth % 2 == 0)
  {
    if (T[v].l != NIL)
    {
      if (sx <= x)
      {
        find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
      }
    }
    if (T[v].r != NIL)
    {
      if (x <= tx)
      {
        find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
      }
    }
  }
  else
  {
    if (T[v].l != NIL)
    {
      if (sy <= y)
      {
        find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
      }
    }
    if (T[v].r != NIL)
    {
      if (y <= ty)
      {
        find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
      }
    }
  }
}

int main()
{
  int x, y;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d %d", &x, &y);
    P[i] = Point(i, x, y);
    T[i].l = T[i].r = T[i].p = NIL;
  }

  np = 0;

  int root = makeKDTree(0, n, 0);

  int q;
  scanf("%d", &q);
  int sx, tx, sy, ty;
  vector<Point> ans;
  for (int i = 0; i < q; i++)
  {
    scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
    ans.clear();
    find(root, sx, tx, sy, ty, 0, ans);
    sort(ans.begin(), ans.end());
    for (int j = 0; j < ans.size(); j++)
    {
      ans[j].print();
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 15960
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (1 << 10)

vector<vector<int> > v;
vector<int> rows;

int ans[MAXN][MAXN];
int f[MAXN][MAXN];

int h, w, k;


void myfill(int x, int y, int color, int dx, int dy) {
	x += dx;
	y += dy;
	while ((x >= 1) && (y >= 1) && (x <= h) && (y <= w) && (!ans[x][y])) {
		ans[x][y] = color;
		x += dx;
		y += dy;
	}
}

void print() {
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
}

int main() {
	cin >> h >> w >> k;
	for (int i = 1; i <= h; i++) {
		string s;
		cin >> s;
		for (int j = 1; j <= w; j++) {
			if (s[j - 1] == '#') {
				f[i][j] = 1;
			}
		}
	}

	int color = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (f[i][j]) {
				color++;
				ans[i][j] = color;
			}
		}
	}

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (ans[i][j]) {
				myfill(i, j, ans[i][j], -1, 0);
				myfill(i, j, ans[i][j], 1, 0);
			}
		}
	}


	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (ans[i][j]) {
				myfill(i, j, ans[i][j], 0, -1);
				myfill(i, j, ans[i][j], 0, 1);
			}
		}
	}

	print();
	return 0;
}


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

using namespace std;

void solve()
{
    string s, t;
    cin >> s >> t;
    vector<int> pos[26];
    s += s;
    int n = s.size();
    for (int i = 0; i < n; i++)
    {
        pos[s[i]-'a'].push_back(i);
    }
    long ans = 0, now = -1;
    for (char c : t)
    {
        int x = c - 'a';
        if (pos[x].empty())
        {
            cout << -1 << endl;
            return;
        }
        int nxt = *lower_bound(pos[x].begin(), pos[x].end(), now+1);
        ans += nxt - now;
        if (nxt >= n/2) 
        {
            nxt -= n/2;
        }
        now = nxt;
    }
    cout << ans << endl;
}

int main()
{
    solve();
    cerr << "努力不足ですね！" << endl;
    return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<pair<int, int>, int>> v1(m);  // 左端の位置でソート
  vector<pair<pair<int, int>, int>> v2(m);  // 右端の位置でソート
  for (int i = 0; i < m; i++) {
    v1[i].second = v2[i].second = i;
    cin >> v1[i].first.first >> v1[i].first.second;
    v2[i].first.first = v1[i].first.second;  // 逆にして突っ込む
    v2[i].first.second = v1[i].first.first;
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());

  vector<bool> ok(m);  // i番目の要求が満たされたか
  int ans = 0, iti = 0;
  for (int i = 0; i < m; i++) {
    if (ok[v2[i].second] == false) {
      ans++;
      while (iti < m && v1[iti].first.first < v2[i].first.first) {
        ok[v1[iti].second] = true;
        iti++;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 2560
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
const int INF = 1001001001;

int main()
{
    int n,a,b;
    in n>>a>>b;
    int tmp=0;
    for(int i=1;i<=n;i++)
    {
        int c=0,t=i;
        for(int j=0;j<5;j++)c+=t%10,t/=10;
        if(a<=c&&c<=b)tmp+=i;
    }
    cout<<tmp<<endl;
}


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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define iter(it,c) for(auto it=c.begin(); it!=c.end(); it++)

typedef vector<int> vi;

pair<vi,int> solve(int n, int x, int m, vi const& l, vi const& r, vi const& s){
    vi ans;
    int ans_sum = -1;
    int end = x + 1;
    rep(i, n - 1) end *= x + 1;
    rep(q, end){
        int mask = q;
        vi v(n);
        rep(i, n){
            v[i] = mask % (x + 1);
            mask /= (x + 1);
        }
        vi sum(n);
        sum[0] = v[0];
        loop(i, 1, n) sum[i] = sum[i - 1] + v[i];

        bool ok = true;
        rep(i, m){
            int a = sum[r[i]];
            if (l[i] != 0) a -= sum[l[i] - 1];
            if (a == s[i]) continue;
            ok = false;
            break;
        }
        if (ok && sum.back() > ans_sum) {
            ans_sum = sum.back();
            swap(ans, v);
        }
    }
    return make_pair(ans,ans_sum);
}

int main(){
    int n, x, m;
    while (cin >> n >> x >> m){
        vi l(m), r(m), s(m);
        rep(i, m){
            cin >> l[i] >> r[i] >> s[i];
            l[i]--; r[i]--;
        }
        auto t = solve(n, x, m, l, r, s);
        if (t.second != -1){
            rep(i, t.first.size() - 1) cout << t.first[i] << " ";
            cout << t.first.back() << endl;
        }
        else{
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 1208
from collections import Counter
n = int(input())
a = Counter(map(int,input().split()))
a = a.items()
a = sorted(a,key=lambda x: x[1],reverse=1)
if len(a) > 3:
  f = 1
elif len(a) == 3:
  b,c,d = a[0][0],a[1][0],a[2][0]
  if b^d != c or c^b != d or d^c != b:
    f = 1
  elif a[0][1] == a[1][1] == a[2][1]:
    f = 0
  else:
    f = 1
elif len(a) == 2:
  b,c,d = a[0][0],a[0][0],a[1][0]
  if b^d != c or c^b != d:
    f = 1
  elif a[0][1] == 2*a[1][1]:
    f = 0
  else:
    f = 1
else:
  b,c,d = a[0][0],a[0][0],a[0][0]
  if b^d != c:
    f = 1
  else:
    f = 0
print('YNeos'[f::2])

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int X; cin >> X;
  if(X >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int n;

int main(){
    cin >> n;
    int A[n];
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    sort(A,A+n);
    int sum=0;
    int max = A[n-1];
    for (int i=0;i<n-1;i++){
        sum+=A[i];
    }
    if(sum>max){
        cout <<"Yes"<<endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
pair<int,int> pii;
vector<int> vec;
int main()
{
  int n,k,q,a;
  int ans[100005],fl[100005]={};
  cin>>n>>k>>q;

  for(int i=0; i<q; i++){
    cin>>a;
    fl[a]++;
  }
  for(int i=1; i<=n; i++){ 
    ans[i]=k-q;
  }

  for(int i=1; i<=n; i++){ 
    ans[i]+=fl[i];
    if(ans[i]>0)cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
  }
  return 0;
}


Measured memory_bytes: 1408
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;


int n, a[101010] , b[101010] , c=1, ans;
multiset<int> s;

int res(){

rep(i, 1, n){
s.insert(b[i]);
}

int k = n/2  + 1;
auto it = s.end();
it--;
a[k]=*it;
s.erase(it);

int l, r;
l=k;r=k;
c=0;
while(l>1 || r<n){
    l--;
    r++;
//cout << l << " " << r << " " << c << " " << s.size()  << endl;
    if(c){
        auto it = s.end();;

        if(l>0){
        it--;
        a[l]=*it;
        s.erase(it);
        }
        if(r<n+1){
            it = s.end();
            it--;
            a[r]=*it;
            s.erase(it);
        }
        c^=1;
    }
    else {
        if(l>0){
            auto it = s.begin();
            a[l]=*it;
            s.erase(it);
        }
        if(r<n+1){
            auto it = s.begin();
            a[r]=*it;
            s.erase(it);
        }
        c^=1;

    }
}

int ret=0;
rep(i, 1 , n-1){
ret+= abs(a[i+1]-a[i]);
}
return ret;

}

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


cin >> n;
rep(i, 1, n){
    cin >> a[i];
    b[i]=a[i];
    s.insert(a[i]);
}

int k = n/2  + 1;
auto it = s.begin();
a[k]=*it;
s.erase(it);

int l, r;
l=k;r=k;

while(l>1 || r<n){
    l--;
    r++;
//cout << l << " " << r << " " << c << " " << s.size()  << endl;
    if(c){
        auto it = s.end();;

        if(l>0){
        it--;
        a[l]=*it;
        s.erase(it);
        }
        if(r<n+1){
            it = s.end();
            it--;
            a[r]=*it;
            s.erase(it);
        }
        c^=1;
    }
    else {
        if(l>0){
            auto it = s.begin();
            a[l]=*it;
            s.erase(it);
        }
        if(r<n+1){
            auto it = s.begin();
            a[r]=*it;
            s.erase(it);
        }
        c^=1;

    }
}


rep(i, 1 , n-1){
ans+= abs(a[i+1]-a[i]);
}
ans = max(ans, res());
cout << ans << endl;



return 0;}
///....


Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include<iomanip>
 
using namespace std;
 
 
int main() {
	vector<int> load;
 
	int n, m;
	int s, e;
 
	cin >> n >> m;
 
	load.resize(n);
	for (int& v : load) {
		v = 0;
	}
 
	while (cin >> s >> e) {
		load[s - 1]++;
		load[e - 1]++;
	}
 
	for (int i = 0; i < n; i++) {
		cout << load[i] << endl;
	}
 
	
 
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define int long long
using namespace std;
const int MOD = 1e9 + 7;

int N, x, a[200];

signed main()
{
    cin >> N >> x;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a, a + N);
    for (int i = 0; i < N; i++) {
        if (x >= 0) {
            x -= a[i];
        }
        if (x < 0) {
            cout << i << endl;
            return 0;
        }
    }
    if (x != 0) {
        cout << N - 1 << endl;
    } else {
        cout << N << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 1e5+10;

int N;
ll A[MAX];

ll GCD(ll x, ll y) {
    if (x > y) swap(x, y);
    while (x) {
        ll z = x;
        x = y%x;
        y = z;
    }
    return y;
}

int main() {

    cin >> N;
    REP (i, N) cin >> A[i];
    ll g = A[0];
    REP (i, N) g = GCD(g, A[i]);
    ll ans = g;
    REP (i, N) if (A[i]%g != 0) ans = min(ans, A[i]%g);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

struct SS{
  string S;
  int score;
  int num;

  bool operator<(const SS& another) const {
  if (S != another.S)
    return S < another.S;
  if (score != another.score)
    return score > another.score; // 同様に比較演算子を反転
  return S < another.S;
  }
};

int main() {

  int N;
  cin >> N;
  vector<SS> V(N);
  REP(i, N)
  {
    cin >> V[i].S >> V[i].score;
    V[i].num = i + 1;
  }

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

  REP(i, N) cout << V[i].num << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define rep11(i, n) for(int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct { int x; int y; } Pos;
using namespace std;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) {
        par = vector<int>(n);
        rep(i, n) par[i] = -1;
    }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int x_ = root(x);
        int y_ = root(y);
        if (x_ == y_) return;
        par[y_] += par[root(x_)];
        par[x_] = root(y_);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return -par[root(x)];
    }
};

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

    UnionFind uf(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        uf.unite(a - 1, b - 1);
    }

    int ans = 0;
    rep(i, n) {
        ans = max(ans, uf.size(i));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10308
#include <bits/stdc++.h>
#define int long long
#define all(c) (c).begin(),(c).end()
#define pii pair<long long,long long>
#define endl '\n'

using namespace std;

signed main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector <int> A(n+1,0);
    int temp;
    for(int i=0;i<n-1;i++){
        //int temp;
        cin >> temp;
        A[temp]++;
    }
    for(int i=1;i<=n;i++){
        cout << A[i] << endl;
    }
    
}

Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back

int main()
{

    int i,j;
    int q;
    cin>>q;
    while(q--)
    {

        ll a,b;
        cin>>a>>b;
        ll a1,b1;
        a1=min(a,b);
        b1=max(a,b);

        if(a1==b1)
        {
            ll x=2*a1-2;
            cout<<x<<endl;
        }
        else
        {

            ll pr=(ll)a1*b1;
            ll q=(ll)sqrt(pr);

            ll w=q*q;
            if(w==pr)
                q--;

            int fl=0;
            ll ans=2*q-1;
            ll p=(q)*(q+1);
            if(p>=pr)
                fl=1;
            ans=ans-fl;
            cout<<ans<<endl;




        }





    }














    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <list>
using namespace std;

int main() {
    int m;
    list<int> mountain = list<int>();
    for (int i = 0; i < 10; i++) {
        scanf("%d", &m);
        mountain.push_back(m);
    }
    mountain.sort();
    for (int i = 0; i < 3; i++) {
        printf("%d\n", mountain.back());
        mountain.pop_back();
    }
    return 0;
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a;
  int b;
  
  cin >> a;
  cin >> b;
  
  if((a+b)%2==0){
    cout << (a+b)/2 << endl;
  }
   else{
     
    cout << "IMPOSSIBLE" << endl;
}
}


Measured memory_bytes: 256
import collections
n,m=map(int,input().split())
A=[]
for i in range(n):
  A.append([int(_) for _ in input().split()])
D=dict()
for i in range(m):
  D[i+1]=1
ans=n
for _ in range(m):
  p=[]
  for i in range(n):
    for j in range(m):
      if D[A[i][j]]==1:
        p.append(A[i][j])
        break
  pp=collections.Counter(p).most_common()
  a,b=pp[0]
  ans=min(ans,b)
  D[a]=0
print(ans)


Measured memory_bytes: 47068
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    そう甘くはないんだな〜w
*/

// from std...
use std::cmp::{
    max, min, Ordering,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::convert::TryInto;
use std::mem::swap;
use std::num::{NonZeroU32, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Index, IndexMut, Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,
    SubAssign,
};
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, multinomial, Integer};
use num_rational::Rational;
use num_traits::{clamp, one, pow, zero, Num, NumAssignOps, NumOps, One, Pow, Zero};
use permutohedron::Heap;
use proconio::{
    fastout, input, is_stdin_empty,
    marker::{Bytes, Chars, Isize1, Usize1},
};
use rand::random;

pub const MOD10E9_7: usize = 1000000007;
pub const MOD99_: usize = 998244353;
pub const MAX: usize = std::usize::MAX;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 65;

// code...
// #[fastout]
fn main() {
    input! {
        n: usize,
        s: [String; n]
    }

    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for d in s {
        if d == "AC".to_string() {
            ac += 1;
        } else if d == "WA".to_string() {
            wa += 1;
        } else if d == "TLE".to_string() {
            tle += 1;
        } else {
            re += 1;
        }
    }

    println!("AC x {}\nWA x {}\nTLE x {}\nRE x {}", ac, wa, tle, re);
}


Measured memory_bytes: 7820
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> P(N);
    for(int i = 0; i < N; i++) cin >> P[i];
    vector<int> ind(N);
    for(int i = 0; i < N; i++) ind[i] = i;
    sort(ind.begin(), ind.end(), [&](int x, int y){
        return P[x] > P[y];
    });
    multiset<int> s;
    long long ans = 0;
    s.insert(-1), s.insert(-1), s.insert(N), s.insert(N);
    s.insert(ind[0]);
    long long a, b, c, d;
    for(int i = 1; i < N; i++){
        s.insert(ind[i]);
        auto ite = s.find(ind[i]);
        a = *next(ite, 1);
        b = *next(ite, 2);
        c = *prev(ite, 1);
        d = *prev(ite, 2);
        long long temp = (a - ind[i]) * (c - d) + (ind[i] - c) * (b - a);
        ans += P[ind[i]] * temp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vector<int> R(n);
    rep(i, n) cin >> R[i];

    int maxv = -1e9;
    int minv = R[0];

    for(int i = 1; i < n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    COUT(maxv);
}


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

int main(){
    int N; cin >> N;
    int count = 0;
    double ans = 0;
    if(N%2 == 0){
        ans = (N)/2;
    }else {
        ans = (N+1)/2;
    }
    cout << ans/N << endl;
}

Measured memory_bytes: 256
import bisect
import sys
input = sys.stdin.readline
def solve():
  N, Q = map(int, input().split())
  Qs = []
  for _ in range(Q):
    i, q = map(int, input().split())
    Qs.append((i - 1, q))
  #print(Qs)
  M = (N-2) ** 2
  #print(M)

  current_mins = [[(-N, N)], [(-N, N)]]
  for i, q in Qs:
    other_min = -current_mins[not i][-1][0]
    j = bisect.bisect(current_mins[i], (-q, other_min))
    #print(i, q, j, current_mins)
    if j == 0:
      m = other_min - 2
    else:
      m = current_mins[i][j-1][1] - 2
    if j == len(current_mins[i]):
      current_mins[i].append((-q, other_min))
      current_mins[not i][-1] = (current_mins[not i][-1][0], q)

    M -= m
    #print(m)
  print(M)
  
solve()
  
  
  
  

Measured memory_bytes: 99012
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();

    int[] t = new int[n + 1];
    int[] x = new int[n + 1];
    int[] y = new int[n + 1];

    t[0] = 0;
    x[0] = 0;
    y[0] = 0;

    for (int i = 1; i < n + 1; i++) {
      t[i] = scan.nextInt();
      x[i] = scan.nextInt();
      y[i] = scan.nextInt();

      if ((Math.abs(x[i] - x[i - 1]) + Math.abs(y[i] - y[i - 1]) > t[i] - t[i - 1])
          || (((Math.abs(x[i] - x[i - 1]) + Math.abs(y[i] - y[i - 1])) % 2) != ((t[i] - t[i - 1]) % 2))) {
        System.out.println("No");
        return;
      }

    }

    System.out.println("Yes");

  }

}


Measured memory_bytes: 59620
s=str(input())
k=int(input())

l=len(s)
chars=set()
chars1=set()
sub1=['']*l

for j in range(l):
    chars1.add(s[j])
    min_c=sorted(chars1)[0]

def subset(st,m):
    substring=set()
    if m==0:
        lst=len(st)
    else:
        lst=m
    for i in range(lst):
        n=i+1 #length = n
        for j in range(lst-i):
            substring.add(st[j:j+n])
    return substring
    
chars=chars|subset(s[max(l-10,0):],0)
for i in range(l):
    if s[i]==min_c:
        chars=chars|subset(s[i:i+5],0)

#print(min_c,chars)

'''
for i in range(l):
    n=i+1 #length = n
    for j in range(l-i):
        chars.add(s[j:j+n])
        #print('i,j,sub',i,j,s[j:j+n])
'''

print(sorted(chars)[k-1])


Measured memory_bytes: 41712
import { readFileSync } from 'fs'
 
function main(input: string) {
  const list = input.trim().split('')
 
  const result = list.every(char =>
    list.filter(c => c === char).length === 2
  )
 
  console.log(result ? 'Yes' : 'No')
}
 
main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 7372
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
#define mod  1000000007
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define endl '\n'
#define cnl cout<<endl;
#define pi  3.141592653589793238
#define ms(x,v) ((x), v, sizeof((x)))
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
ll i, j, k;
void solve(){
    ll n , m; cin >> n >> m;
    if(n == m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
           

     return ; 
} 
    signed main(){
   
    //CASET
    solve();
    
   
    return 0;
  }

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

using namespace std;

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

  int previous_x, previous_y;
  int previous_t;
  previous_x = previous_y = 0;
  previous_t = 0;

  bool can = true;
  for(int i = 0; i < point_num; i++)  {
    int x, y;
    int t;
    cin >> t >> x >> y;

    int diff_x = abs(x - previous_x);
    int diff_y = abs(y - previous_y);
    int diff_t = t - previous_t;

    int left_t = diff_t - (diff_x + diff_y);

    if(left_t < 0 || left_t % 2 != 0) {
      can = false;
      break;
    }

    previous_x = x;
    previous_y = y;
    previous_t = t;
  }

  if(can) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3584
// In the name of god
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
long long int n,m,x,ac[maxn],wa[maxn],p,ans;
string s;
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>x>>s;
		if(s=="AC"){
			if(ac[x]==0){
				ans++;
				p+=wa[x];
			}
			ac[x]=1;
		}
		else{
			wa[x]++;
		}
	}
	cout<<ans<<' '<<p;
}


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

int main() {
    int n;
    cin >> n;
    int64_t total = 1;
    bool zero = 0;

    vector<int64_t> vec(100010);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
        if (vec.at(i) == 0) {
            zero = 1;
        }
    }

    if (zero) {
        cout << 0 << endl;
        return 0;
    }
    
    for (int i = 0; i < n; i++) {
        if (total <= 1000000000000000000 / vec.at(i)) {
            total *= vec.at(i);
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << total << endl;
}

Measured memory_bytes: 4028
#include <iostream>
#include <cmath>
#include <utility>
#include <functional>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#include <deque>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int m, nMin, nMax;
	cin >> m >> nMin >> nMax;

	while (m != 0) {
		vector<int> point(m);
		rep(i, 0, m) cin >> point[i];

		vector<int> gap(m - 1);
		// ギャップの配列
		rep(i, 0, m - 1) {
			gap[i] = point[i] - point[i + 1];
		}
		// 最大のギャップで最大の合格者数
		int mx = 0, ans = nMin;
		rep(i, nMin - 1, nMax) {
			if (mx <= gap[i]) ans = max(ans, i + 1);
			mx = max(mx, gap[i]);
		}

		cout << ans << endl;

		cin >> m >> nMin >> nMax;
	}

	return 0;
}


Measured memory_bytes: 3088
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n;
vi t,a,det;
int ret;

signed main(){
    I(n);
    t.resize(n);
    a.resize(n);
    REP(i,n) I(t[i]);
    REP(i,n) I(a[i]);

    det.resize(n);
    det[0] = t[0];
    FOR(i,1,n){
        if (t[i] != t[i-1]) det[i] = t[i];
    }
    if ( (det[n-1] != 0 && det[n-1] != a[n-1]) || t[n-1] < a[n-1]){
        cout << 0 << endl;
        return 0;
    }
    det[n-1] = a[n-1];
    REPN(i,n-1){
        if (a[i] != a[i+1]){
            if (det[i] != 0 && det[i] != a[i]){
                cout << 0 << endl;
                return 0;
            }
            det[i] = a[i];
        }
        if (det[i] > a[i]) {
            cout << 0 << endl;
            return 0;
        }
    }
    ret = 1;
    REP(i,n){
        if(!det[i]){
            ret *= min(a[i],t[i]);
            ret %= mod;
        }
        // cerr << det[i] << " " << t[i] << " " << a[i] << endl;
    }
    cout << ret << endl;
}

Measured memory_bytes: 2560
s = raw_input()

while len(s) > 0:
	if s[-5:] == 'erase' :
		s = s[:-5]

	elif s[-5:] == 'dream' :
		s = s[:-5]

	elif s[-7:] == 'dreamer' :
		s = s[:-7]

	elif s[-6:] == 'eraser' :
		s = s[:-6]

	else :
		print 'NO'
		break

if len(s) == 0 :
	print 'YES'



Measured memory_bytes: 2820
/*author: hyperion_1724
  date: 
*/

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

	READV(K);
	READV(N);
	FORI(i,N-K+1,N+K)
	{
		cout<<i<<" ";
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 256
S = input()
S_len = len(S)

X1 = "10" * ((S_len // 2)+1)
X2 = "01" * ((S_len // 2)+1)

ans = 0
if S[0] == "0":
    for i in range(S_len):
        if X2[i] != S[i]:
            ans += 1
elif S[0] == "1":
    for i in range(S_len):
        if X1[i] != S[i]:
            ans += 1
    
print(ans)   

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

using namespace std;

int Count(vector<string> A,string str,int n){
  int count=0;
  for(int i=0;i<A.size();i++)
    if(A.at(i)==str) count++;
  return n*count;
}

int main(){

  int N,M,best=0,count;
  
  cin >> N;
  vector<string> Nvec(N);
  for(int i=0;i<Nvec.size();i++) cin >> Nvec.at(i);
  cin >> M;
  vector<string> Mvec(M);
  for(int i=0;i<Mvec.size();i++) cin >> Mvec.at(i);
  
  for(int i=0;i<Nvec.size();i++){
    count = Count(Nvec,Nvec.at(i),1)+Count(Mvec,Nvec.at(i),-1);
    if(count > best) best=count;
  }
  
  cout << best << endl;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define DBG(a) cout<<#a<<" ->->->-> "<<a<<endl
#define EN cout<<"\n"
#define fi first
#define se second
#define PI (acos(-1))
#define fastread ios::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 1000005
template<class T> ostream& operator<<(ostream &s,pair<T,ll> a)
{
    s<<a.fi<<' '<<a.se;
    return s;
}
ll fastpow(ll val,ll pwr,ll md=0)
{
    if(pwr==0)return 1;
    if(md){
    if(pwr%2)return (val*fastpow((val*val)%md,pwr/2,md))%md;
    return fastpow((val*val)%md,pwr/2,md);
    }
    else
    {
        if(pwr%2)return val*fastpow(val*val,pwr/2);
        return fastpow(val*val,pwr/2);
    }
}
ll nck(ll n,ll k)
{
    ll x=1;
    for(int i=0;i<k;i++)x=(x*(n-i))%mod;
    ll y=1;
    for(int i=2;i<=k;i++)y=(y*i)%mod;
    x*=fastpow(y,mod-2,mod);
    return x%mod;
}
int main()
{
    fastread;
    ll T=1;
//    cin>>T;
    for(ll qq=1;qq<=T;qq++)
    {
        ll n,a,b;
        cin>>n>>a>>b;
        ll ans=fastpow(2,n,mod);
        ans-=nck(n,a);
        ans-=nck(n,b);
        ans--;
        while(ans<0)ans+=mod;
        cout<<ans<<endl;
    }
    return 0;
}



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

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

    if (s.front() != 'A') {
        puts("WA");
        return 0;
    }

    int pos;
    int cnt = 0;
    for (int i = 2; i < s.size() - 1; i++) {
        if (s[i] == 'C') {
            pos = i;
            cnt++;
        }
    }
    if (cnt != 1) {
        puts("WA");
        return 0;
    }

    for (int i = 1; i < s.size(); i++) {
        if (i == pos) continue;
        if (isupper(s[i])) {
            puts("WA");
            return 0;
        }
    }
    puts("AC");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 101
vector<int> G[MAX];
bool used[MAX];
bool cycle;

// 各頂点から, 深さ優先探索(depth-first search) を行い, 閉路が存在するかチェックする.
// https://ja.wikipedia.org/wiki/深さ優先探索
// @param s: 探索開始地点となる頂点.
// @param c: 今回探索する頂点.
// @return : 特に無し.
void dfs(int s, int c){
    used[c] = 1;
    for(int i = 0; i < G[c].size(); i++){
        // 閉路が見つかったら, 終了.
        if(G[c][i] == s){
            cycle = true;
            return;
        }
        if(!used[G[c][i]]) dfs(s, G[c][i]);
    }
}

int main(){
    
    // 1. 入力情報.
    int V, E;
    scanf("%d %d", &V, &E);
    for(int i = 0; i < E; i++){
        int s, t;
        scanf("%d %d", &s, &t);
        G[s].push_back(t);
    }
    
    // 2. 閉路チェック.
    for(int i = 0; i < V; i++){
        if(!cycle){
            memset(used, 0, sizeof(used));
            dfs(i, i);
        }
    }
    
    // 3. 出力 ～ 後処理.
    if(cycle) printf("%d\n", 1);
    else      printf("%d\n", 0);
    return 0;

}


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

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

inline int Pow(int a, int k) {
  int s = 1; 
  for(; k; k >>= 1) {
    k & 1 ? s = 1LL * s * a % MOD : 0;
    a = 1LL * a * a % MOD;
  }
  return s;
}

const int N = 1e6 + 7;

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);
}

void preprocess() {
}

void debug() {
  //  44gg
  if (true) {
  
  }
}



void solve() {
  preprocess();
  // 50gg
  int W, H; cin >> W >> H;
  int w, h; cin >> w >> h;
  cout << (W - w) * (H - h) << endl;
  //debug();
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

void output() {

}

#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(false);
	cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  //int t; cin >> t;
  //while (t--) 
  {
    input();
    solve();
    output();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using ll = long long;
int main(){ 
    ll a,b;
    cin>>a>>b;
    if(a==1&&b==2){
        cout<<3;
    }else if(a==1&&b==3){
        cout<<2;
    }else if(a==2&&b==3){
        cout<<1;
    }else if(a==3&&b==2){
        cout<<1;
    }else if(a==2&&b==1){
        cout<<3;
    }else if(a==3&&b==1){
        cout<<2;
    }
    
    return 0;
}


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

using namespace std;

int main() {
  long long x, ans;
  scanf("%lld", &x);

  ans = 1;
  for (long long b = 1; b <= x; b++) {
      for (long long p = 2; p <= x; p++) {
          long long tmp = 1, q = p;
          while (0 < q) {
              tmp *= b;
              q--;
          }
          if (x < tmp) {
              break;
          }
          ans = max(ans, tmp);
      }
  }
  
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  	cin>>n;
  	vector<int>a(n);
  	int count=0;
  	for(int i=0;i<n;i++){
    	cin>>a.at(i);
      	if(a.at(i)%2==0){
        	count++;
        }
    }
  	
  	for(int i=0;i<n;i++){
      if(a[i]%2==0){
    	if(a[i]%3==0||a[i]%5==0){
        	count--;
        }
      }
    }
  	
  	if(count==0){
    	cout<<"APPROVED"<<endl;
    }
  	else{
    	cout<<"DENIED"<<endl;
    }
  	

}

Measured memory_bytes: 256
#![allow(unused_mut, non_snake_case,unused_imports)]
use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::{swap};
use std::collections::{HashMap,BTreeMap,HashSet,BTreeSet,BinaryHeap,VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn main(){
    input!(N:i32,M:usize,X:i32,Y:i32,x:[i32;N],y:[i32;M]);
    let x:Vec<i32> = x;
    let y:Vec<i32> = y;
    let &maxx = x.iter().max().unwrap();
    let &miny = y.iter().min().unwrap();

    let L = max(maxx,X);
    let R = min(miny,Y);
    println!("{}",if L < R {"No War"}else{"War"});
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

/*
 * dijkstra 法 O(Elog(V))
 * グラフ g において, 始点 start から各頂点への最短経路を返す
*/
struct Edge {
public:
  int to, cost;

  Edge() {}
  Edge(int to, int cost) : to(to), cost(cost) {}
};

std::vector<int> dijkstra(std::vector<std::vector<Edge> >& graph, int start) {
  std::vector<int> d(graph.size(), int(1e9));
  // (x, y) ... x : the minimum distance from start to y, y : now vertex 
  std::priority_queue<std::pair<int, int> > que;

  que.push({0, start});
  d[start] = 0;

  while(!que.empty()) {
    auto p = que.top();
    que.pop();

    for (auto e : graph[p.second]) {
      if (d[e.to] <= p.first + e.cost) continue;

      d[e.to] = p.first + e.cost;
      que.push({d[e.to], e.to});
    }
  }

  return d;
}


int main() {
  int n, u, k, v, c;
  std::vector<std::vector<Edge> > g;

  cin >> n;
  g.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      cin >> v >> c;
      g[u].push_back({v, c});
    }
  }

  auto d = dijkstra(g, 0);

  for (int i = 0; i < n; ++i) {
    cout << i << " " << d[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3084