akhauriyash/Code-Regression huggingface dataset:
// ProblemURL : https://atcoder.jp/contests/abc120/tasks/abc120_c
// ---------------------------------------------
package main

import "fmt"

func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var s string
	fmt.Scan(&s)

	ct0, ct1 := 0, 0
	for i := range s {
		if s[i] == '0' {
			ct0++
		} else {
			ct1++
		}
	}

	fmt.Println(smaller(ct0, ct1) * 2)
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int R,C;
	int field[10000];
	
	while(cin>>R>>C,R|C){
		memset(field,0,sizeof(field));
		for(int i=0; i<R; i++){
			for(int j=0; j<C; j++){
				int a; cin>>a;
				field[j] = (field[j]<<1) | a;
			}
		}
		
		int ans = 0;
		
		for(int k=1; k<(1<<R); k++){
			int sum = 0;
			for(int i=0; i<C; i++){
				int t1 = field[i];
				int t2 = ~field[i];
				int sum1 = 0;
				int sum2 = 0;
				for(int j=1; j<(1<<R); j<<=1){
					if( k&j ){
						sum1 += ( ((~t1)&j)==j ? 1 : 0 );
						sum2 += ( ((~t2)&j)==j ? 1 : 0 );
					}else{
						sum1 += ( (t1&j)==j ? 1 : 0 );
						sum2 += ( (t2&j)==j ? 1 : 0 );
					}
				}
				sum += max(sum1,sum2);
			}
			ans = max(ans,sum);
		}
		
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 916
#include<stdio.h>

int main(void){int i,n;int number;long long int sum = 0;int min =0;int max = 0;
scanf("%d",&n);
for(i=0;i<n;i++){scanf("%d",&number);if(i==0){min =number;max = number;}if(number<min) min = number;if(number>max) max = number;
sum += number;}
printf("%d %d %lld\n",min,max,sum);
return 0;}

Measured memory_bytes: 1028
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String s  = "YES";
		Set<Integer> a = new HashSet<>();
		for(int i=0; i<N; i++) {
			int num = sc.nextInt();
			if(a.contains(num)){
				s = "NO";
				break;
			} else {
				a.add(num);
			}
		}
		sc.close();
		System.out.println(s);
	}

}

Measured memory_bytes: 100676
let s = Int(readLine()!)!
let devider = 1000_000_000 + 7
var dpTable: [Int] = .init(repeating: 0, count: s+1)

dpTable[0] = 1
dpTable[1] = 0
dpTable[2] = 0

if s >= 3 {
    for i in 3...s {
        dpTable[i] = dpTable[i-3]+dpTable[i-1]
        dpTable[i] %= devider
    }
}

print(dpTable[s])



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

#define ff first
#define ss second
#define pb push_back

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

const int N = 1000005;

void solve(int v[], int n){
  if(n == 1){
    printf("%d\n", v[0]);
    return;
  }
  int v2[n];
  for(int i = 0; i < n-1; i++){
    printf("%d ", v[i]);
    v2[i] = abs(v[i] - v[i+1]);
  }
  printf("%d\n", v[n-1]);
  return solve(v2, n-1);
}

int n;
int v[N];
int dp[N];

int main() {
  bool f1 = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%1d", v+i);
    v[i]--;
    f1 |= v[i] == 1;
  }
  if(f1){
    for(int i = 0; i < n; i++){
      v[i] %= 2;
    }
  }
  else{
    for(int i = 0; i < n; i++){
      if(v[i] == 2) v[i] = 1;
    }
  }
  for(int i = 0; i < n; i++){
		dp[i] = v[i];
	}
	for(int b = 0; b <= 22; b++){
		for(int i = 0; i < n; i++){
			if(i & (1 << b)){
				dp[i] ^= dp[i ^ (1 << b)];
			}
		}
	}
  printf("%d\n", f1 ? dp[n-1] : 2*dp[n-1]);
  return 0;
}


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



int H, W;
string A[10];
//-----------------------------------------------------------------
string ans = "Possible";
int dx[2] = { 0, 1 };
int dy[2] = { 1, 0 };
void dfs(int x, int y) {
	if (x == W - 1 && y == H - 1) return;

	int a = -1, b = -1;
	rep(i, 0, 2) {
		int xx = x + dx[i];
		int yy = y + dy[i];
		if (W <= xx) continue;
		if (H <= yy) continue;

		if (A[yy][xx] == '#') {
			A[yy][xx] = '.';
			if (0 <= a) {
				ans = "Impossible";
				return;
			}
			a = xx;
			b = yy;
		}
	}

	if(a < 0) {
		ans = "Impossible";
		return;
	}

	dfs(a, b);
}
//-----------------------------------------------------------------
int main() {
	cin >> H >> W;
	rep(y, 0, H) cin >> A[y];

	A[0][0] = '.';
	dfs(0, 0);

	rep(y, 0, H) rep(x, 0, W) if (A[y][x] == '#') ans = "Impossible";
	cout << ans << endl;
}

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

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

  vector<int> d(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &d.at(i));
  }

  int ans = 0;
  for (int x = 0; x < N; x++) {
    for (int y = x + 1; y < N; y++) {
      ans += d.at(x) * d.at(y);
    }
  }

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> type(Q), A(Q), B(Q);
    rep(i, Q) {
        cin >> type[i];
        if (type[i] == 1) {
            char c;
            cin >> A[i] >> c;
            B[i] = c;
        }
        else {
            cin >> A[i] >> B[i];
        }
    }

    vector<int> ans(Q);
    set<int> cidx;
    for (char c = 'a'; c <= 'z'; ++c) {
        cidx.clear();
        rep(i, N) {
            if (S[i] == c) cidx.insert(i);
        }
        rep(i, Q) {
            if (type[i] == 1) {
                if (cidx.find(A[i] - 1) != cidx.end()) {
                    if (B[i] != c) cidx.erase(A[i] - 1);
                }
                else {
                    if (B[i] == c) cidx.insert(A[i] - 1);
                }
            }
            else {
                if (cidx.lower_bound(A[i] - 1) != cidx.lower_bound(B[i])) {
                    ans[i]++;
                }
            }
        }
    }
    rep(i, Q) if (type[i] == 2) write(ans[i]);
}

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

ll X;
ll happy;
int main(){
    cin>>X;
    ll n500 = X/500;
    ll n5   = (X-500*n500)/5;
    happy =1000*n500+5*n5;
    cout<<happy;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<numeric>
#include<stack>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1e18+1;
const ll mod = 1e9+7;
const double PI = acos(-1);  // PI = 3.141593...

struct puddle {
    int from;
    int s;
    puddle(int from, int s):
        from(from), s(s) {};
};

int main() {
    string str;
    cin >> str;
    vector<puddle> p;
    deque<int> pos;
    int ssum=0;
    for(int i=0; i<str.size(); ++i) {
        if(str[i] == '\\') {
            pos.push_back(i);
        }
        else if(str[i] == '/' && pos.size() > 0) {
            // 対応する行の面積 = 距離 - 1
            int j = pos.back(); pos.pop_back();
            int s = i - j;
            ssum += s;
            // 過去の水たまりを含む場合の処理
            while(p.size() > 0 && p.back().from > j) {
                s += p.back().s; p.pop_back();
            }
            p.push_back(puddle(j, s));
        }
    }
    cout << ssum << endl;
    cout << p.size();
    rep(i, p.size()) cout << " " << p[i].s;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
 
typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout<<i<<endl;
#define AS(i) cout<<i<<" ";
 
const int INF = 1001001001;
 
using namespace std;
 
int main() {

    int n;
    cin >> n;

    string a[n];

    rep(i, n) {
        cin >> a[i];
    }

    sort(a, a+n);

    vector<string> ans;

    int cut = 1;
    int maxCut = 1;
    string now = a[0];
    for (int i = 1; i < n; i++) {

        if (a[i] == now) {
            cut++;

        } else {


            if (maxCut <= cut) {
                if (maxCut < cut)
                    ans.clear();

                ans.push_back(now);
                maxCut = cut;
            }

            now = a[i];
            cut = 1;
        }
    }
    if (maxCut <= cut) {
        if (maxCut < cut)
            ans.clear();

        ans.push_back(now);
        maxCut = cut;
    }

    rep(i, ans.size()) {
        AA(ans[i]);
    }
}



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

int main(void){
  int n,count;
  count=0;
  vector<int> v;
  cin>>n;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    if(count%2==0){
      auto it=v.begin();
      v.insert(it,tmp);
      count++;

    }else{
      v.push_back(tmp);
      count++;
    }
  }
  if(n%2==0){
  	reverse(v.begin(),v.end());
  }else{
  }  
  for(int i=0;i<n;i++){
  	cout<<v[i]<<" ";
  }
  cout<<endl;

}


Measured memory_bytes: 3060
#include<iostream>

using LL = long long;
using namespace std;

int main() {
	LL N;
	cin >> N;
	LL ans = 0;
	for (int i = 1; i < N; i++) {
		int num = N / i;
		int amari = N % i;
		if (amari == 0) {
			num--;
		}
		ans += num;


	}



	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3672
N,D = map(int,input().split())
X = []
Y = []
for i in range(N):
    x, y = input().split()
    X.append(int(x))
    Y.append(int(y))
count = 0

for i in range(N):
        if((X[i]) ** 2 + (Y[i]) ** 2 <= D ** 2 ):
            count += 1

print(count)

Measured memory_bytes: 24920
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<ll> A(N);
    for (ll& x : A) cin >> x;
    sort(A.begin(), A.end());
    vector<ll> L, R;
    ll M = A.back() - A.front();
    for (int i = 1; i < N - 1; i++) {
      if (A[i] < 0) {
        L.push_back(A[i]);
      } else {
        R.push_back(A[i]);
      }
      M += abs(A[i]);
    }
    cout << M << endl;
    ll lsum = A.back(), rsum = A.front();
    for (ll x : L) {
      cout << lsum << " " << x << endl;
      lsum -= x;
    }
    for (ll x : R) {
      cout << rsum << " " << x << endl;
      rsum -= x;
    }
    cout << lsum << " " << rsum << endl;
  }
  return 0;
}


Measured memory_bytes: 3572
//============================================================================
// Name        : DPTest.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int N,M,K;
int A[20001]={};
const long long INF=100000000000000;
long long dp[20001]={};
int maxdp[20001][1001]={};
int mindp[20001][1001]={};

int maxD(int n2,int n3){
	int ans2=A[n2+n3];
	if(maxdp[n2][n3]>0)return maxdp[n2][n3];
	if(n3>1)ans2=max(maxD(n2,n3-1),A[n2+n3]);
	maxdp[n2][n3]=ans2;
	return ans2;
}
int minD(int n2,int n3){
	int ans2=A[n2+n3];
	if(mindp[n2][n3]>0)return mindp[n2][n3];
	if(n3>1)ans2=min(minD(n2,n3-1),A[n2+n3]);
	mindp[n2][n3]=ans2;
	return ans2;
}

long long calc(int n1){
	long long ans=INF;
	if(dp[n1]>-1)return dp[n1];
	for(int i=1;i<M+1&&i<n1+1;i++){
		ans=min(ans,calc(n1-i)+(long long)K+(long long)i*(long long)(maxD(n1-i,i)-minD(n1-i,i)));
	}
	dp[n1]=ans;
	return ans;
}
int main() {
	cin>>N>>M>>K;
	for(int i=1;i<N+1;i++)cin>>A[i];
	fill(dp,dp+20001,-1);
	dp[0]=0;
	cout<<calc(N)<<endl;
	return 0;
}

Measured memory_bytes: 160980
#include<iostream>
int _abs(int x)
{
    if(x>0)
    {
        return x;
    }
    else
    {
        return (-1)*x;
    }
}
int gcd_euclid(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r; /* swap */
  }
  return u;
}
int main()
{
    int N,X;
    unsigned int x[100000];
    unsigned int D=0;

    std::cin>>N>>X;
    for(int i=0;i<N;i++)
    {
        scanf("%d ",&x[i]);
    }
    D=_abs(x[0]-X);
    for(int j=0;j<N;j++)
    {
        if(D>_abs(x[j]-X))
        {
            D=_abs(x[j]-X);
        }
        if(_abs(x[j]-X) % D!=0)
        {
            D=gcd_euclid(D,_abs(x[j]-X));
        }

    }
    std::cout<<D<<std::endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  ll l, r;
  cin >> l >> r;
  if (r - l >= 2019) {
    cout << 0 << endl;
    return;
  }
  ll ans = INF;
  rep3(i, l, r + 1) rep3(j, i + 1, r + 1) {
    chmin(ans, (1LL * i * j) % 2019);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  vll d(3);
  vpr q(n+1);
  rep(i,3) cin >> d[i];
  rep(i,n) {
    string s;
    cin >> s;
    if(s == "AB") q[i] = make_pair(0, 1);
    else if(s == "BC") q[i] = make_pair(1, 2);
    else if(s == "AC") q[i] = make_pair(0, 2);
  }
  string ans = "";
  auto add = [&](ll l, ll r) {
    d[l]++;
    d[r]--;
    ans += 'A' + l;
  };
  q[n] = make_pair(0, 1);
  rep(i,n) {
    ll l = q[i].first;
    ll r = q[i].second;
    if(!d[l] && !d[r]) {
      cout << "No\n";
      return;
    } else if(!d[l]) {
      add(l, r);
    } else if(!d[r]) {
      add(r, l);
    } else if(q[i+1].first == l || q[i+1].second == l) {
      add(l, r);
    } else {
      add(r, l);
    }
  }
  cout << "Yes\n";
  rep(i,n) cout << ans[i] << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 5120
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().split()]
import collections
c = collections.Counter(A)
d = c.items()
e = []
for i in d:
    if i[1] >= 4:
        e.append(i[0])
        e.append(i[0])
    elif i[1] >= 2:
        e.append(i[0])
if len(e) < 2:
    print(0)
    sys.exit()
e = sorted(e,reverse=True)
print(e[0] * e[1])

Measured memory_bytes: 18116
#include <bits/stdc++.h>
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};

// 最大公約数（a > b）
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  // 入力
  int N, M;
  cin >> N >> M;

  int ans = 0;
  for (int i = 1; i * i <= M; i++) {
    if (M % i == 0) {
      if (i >= N) {
        ans = max(ans, M / i);
      }
      if (M / i >= N) {
        ans = max(ans, i);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimize("Os")
#pragma GCC target("avx2,fma")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("Os")
*/
#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld; 

#define X first
#define Y second
#define MP make_pair

using namespace std;
    
const int N = 3e3 + 123;
const ll mod = 1e9 + 7;
const ll INF = 1e18;

int n, k, a[N];
bool dp[N * 100];

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

	cin >> n >> k;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}

	for(int i = 1;i <= k;i++){
		for(int j = 1;j <= n;j++){
			if(i - a[j] < 0)
				continue;
			dp[i] |= !dp[i - a[j]];
		}
	}

	if(dp[k] == 1){
		cout << "First";
	}
	else{
		cout << "Second";
	}

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007


int main()
{
	int h, w;
	cin >> h >> w;
	vector<vector<int> > count(h, vector<int>(w, -1));
	queue<pair<int, int> > qu;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			char a;
			cin >> a;
			if(a == '#'){
				count[i][j] = 0;
				qu.push(make_pair(i, j));
			}
		}
	}

	int dx[4] = {1, 0, -1, 0};
	int dy[4] = {0, 1, 0, -1};

	while(!qu.empty()){
		int x = (qu.front()).first;
		int y = (qu.front()).second;
		qu.pop();
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(nx < 0 || nx >= h || ny < 0 || ny >= w || count[nx][ny] >= 0) continue;
			count[nx][ny] = count[x][y] + 1;
			qu.push(make_pair(nx, ny));
		}
	}
	int ans = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			ans = max(ans, count[i][j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 12432
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 1e5+100, inf = 2e9;
typedef long long LL;

LL dp[110][N];  //dp[i][j] 表示在前i个物品中选，总价值是j的最小容量
int n,m;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m;
    int M = n*1000;
    for(int i = 1; i<=N; i++){
        dp[0][i] = inf;
    }
    for(int i = 1; i<=n; i++){
        int w,v;
        cin>>w>>v;
        for(int j = 0; j<=M; j++){
            //不选第i个物品
            dp[i][j] = dp[i-1][j];
            //选第i个物品
            if(j >= v) dp[i][j] = min(dp[i-1][j], dp[i-1][j-v] + w);
        }
    }
    
    int ans = 0;
    for(int i = 0; i<=M; i++){
        if(dp[n][i] <= m) ans = i;
    }
    
    cout<<ans;
    return 0;
}

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

#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a<=5){
        cout << "0" <<"\n";
    }
    else if (a >=6 && a <=12){
        cout << b/2 <<"\n";
    }
    else{
        cout << b << "\n";
    }


}






Measured memory_bytes: 3568
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_099
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            var patterns = new List<int>();
            patterns.Add(1);
            patterns.AddRange(new int[6]
                {6,36,216,1296,7776,46656});
            patterns.AddRange(new int[5]
            { 9,81,729,6561,59049});
            patterns.Sort();
            int cnt = n;
            for (int i = 0; i <= n; i++)//6^pで表すものをiとし, 最小回数を全探索
            {
                int a = n - i;
                int p = 0;
                while (a > 0)
                {
                    p += a % 6;
                    a /= 6;
                }

                int b = i;
                int q = 0;
                while (b > 0)
                {
                    q += b % 9;
                    b /= 9;
                }

                cnt = Math.Min(p + q, cnt);
            }
            Console.WriteLine(cnt);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(multiple: int, min_value: int, max_value: int) -> bool:
    return max_value - (max_value % multiple) >= min_value


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    K = int(input())
    A, B = map(int, input().split())
    # values = []
    # for _ in range(N):
    #     values.append(input().split())
    result = solve(K, A, B)
    print("OK" if result else "NG")


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result))


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)


Measured memory_bytes: 82600
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String s = sc.next();
		
		// 計算
		int result = 0;
		for(int i = 1; i < n; i++){
		    int tmp = 0;
		    HashSet<Character> hs = new HashSet<Character>();
		    for(int j = 0; j < i; j++){
		        hs.add(s.charAt(j));
		    }
		    for(Character c : hs){
		        if(s.substring(i).contains(Character.toString(c))){
		            tmp++;
		        }
		    }
		    result = max(result, tmp);
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 24020
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef string str;

ll log2(ll n){
  ll i = 0;
  while(n%2==0){
    n=n/2;
    i++;
  }
  return i;
}

int main(){
  ll n;
  cin >> n;
  ll ans = INF;
  REP(i,n){
    ll a;
    cin >> a;
    if(ans>log2(a)) ans = log2(a);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    int ans = 0;
    for(int i=1; i<N; i++) if(A[i] > A[i-1]) ans++;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3100
integer N,N_6,N_9
integer ans,preans
read*,N

ans=huge(ans)
do i =0,N
  preans=0
  N_6=i
  do while(N_6/=0)
    preans=preans+mod(N_6,6)
    N_6=N_6/6
  end do
  N_9=N-i
  do while(N_9/=0)
    preans=preans+mod(N_9,9)
    N_9=N_9/9
  end do
  ans=min(ans,preans)
end do

print"(I0)",ans
end

Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


k = int(input())
sum = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        if gcd(a,b) == 1:
            sum += 1 * k
            continue
        for c in range(1,k+1):
            sum += gcd(a,b,c)

print(sum)


Measured memory_bytes: 9620
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  int n; cin >> n;
  vector<pair<int,int>> d(n);
  rep(i,n) cin >> d[i].first >> d[i].second;

  int count = 0;
  rep(i,n) {
    if(d[i].first == d[i].second) count++;
    else count = 0;
    if(count >=3 ) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main(void){
  char a[10],b[10];
  scanf("%s %s",a,b);
  strcat(a,b);
  int ab=atoi(a);
  for(int i=1;i<400;i++){
    if(i*i==ab) {printf("Yes");return 0;}
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 128
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int N;
ll A, B, C;

vll h;

ll rec(int n, ll a, ll b, ll c)
{
    if (n == N)
    {
        if (a == 0 || b == 0 || c == 0) return INF;

        return abs(a - A) + abs(b - B) + abs(c - C) - 30;
    }

    ll ans = rec(n + 1, a, b, c);
    chmin(ans, rec(n + 1, a + h[n], b       , c       ) + 10);
    chmin(ans, rec(n + 1, a       , b + h[n], c       ) + 10);
    chmin(ans, rec(n + 1, a       , b       , c + h[n]) + 10);

    return ans;
}

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    in1(N);
    in3(A, B, C);

    h.resize(N);
    inN(h, N);

    outl(rec(0, 0, 0, 0));

    return 0;
}


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

const long MAX_N = 1e5;

bool option(pair<long, long> p1, pair<long, long> p2) {
	if (p1.second < p2.second) {
		return true;
	} else if (p1.second > p2.second) {
		return false;
	} else {
		if (p1.first < p2.first)
			return true;
		else 
			return false;
	}
}

int main() {
	long N, M;
	long sum = 0;
	pair<long, long> p[MAX_N];

	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		cin >> p[i].first >> p[i].second;
		p[i].second--;
	}
	sort(p, p+M, option);
	long end = 0;
	for (int i = 0; i < M; i++) {
		if (!end) {
			end = p[i].second;
			sum++;
		} else if (end < p[i].first) {
			end = p[i].second;
			sum++;
		} 
	}
	cout << sum << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

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

  int ans = 0;
  
  if(a>=13) ans=b;
  else if (a>=6) ans=b/2;
  
  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <algorithm>

using namespace std;

int box[100005];
int cand[100005];

int N, M;

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

    cand[0] = 1;

    fill(box, box + N, 1);

    for (int i = 0; i < M; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;

        box[x]--;
        box[y]++;

        if (cand[x] == 1)
        {
            cand[y] = 1;
        }

        if (box[x] == 0)
        {
            cand[x] = 0;
        }
    }

    cout << accumulate(cand, cand + N, 0) << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main(){
	int N, T;
	int i, j;
	int c[1001];
	int t[1001];
	int cmin = 9999999;
	int flag = 0;
	cin >> N >> T;

	for (i = 0; i < N; ++i) {
		cin >> c[i] >> t[i];
	}

	for (i = 0; i < N; ++i) {
		if (t[i] <= T) {
			if (cmin > c[i]) {
				cmin = c[i];
				++flag;
			}
		}
	}

	if (flag > 0) {
		cout << cmin << endl;
	}
	else {
		cout << "TLE" << endl;
	}
 }



Measured memory_bytes: 256
n,m=map(int,input().split())
A=[]
B=[]
for _ in range(m):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
one=[]
des=[]
for i in range(m):
    if A[i]==1:
        one.append(B[i])
    if B[i]==1:
        one.append(A[i])
for j in range(m):
    if A[j]==n:
        des.append(B[j])
    if B[j]==n:
        des.append(A[j])
one=set(one)
des=set(des)
ans=one & des
if len(ans)>0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


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

using namespace std;

const int N = 2e5 + 5, mod = 998244353;

long long powmod(long long b, long long p) {
  long long r = 1;
  for (; p; p >>= 1, b = b * b % mod)
    if (p & 1)
      r = r * b % mod;
  return r;
}

struct Fenwick {
  int bit[N];
  Fenwick() {
    memset(bit, 0, sizeof bit);
  }

  void upd(int x, int v) {
    for (++x; x < N; x += x&-x)
      bit[x] = (bit[x] + v) % mod;
  }

  int get(int x) {
    int ret = 0;
    for (++x; x; x -= x&-x)
      ret = (ret + bit[x]) % mod;
    return ret;
  }
};

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> p(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &p[i]);
  long long ans = 1LL * k * (k - 1) / 2;
  ans %= mod;
  long long prob = powmod(k, mod - 2), q = (mod + 1 - prob) % mod;
  Fenwick sum, cnt;
  for (int i = 0; i < k; ++i) {
    sum.upd(p[i], powmod(q, mod - 1 - (k-1)));
    cnt.upd(p[i], +1);
  }
  ans = ans * powmod(2, mod - 2) % mod;
  for (int i = k; i < n; ++i) {
    long long now = powmod(q, i)* powmod(2, mod - 2) % mod;
    long long down = sum.get(p[i]), up = sum.get(N-2) - down;
    int cdown = cnt.get(p[i]), cup = cnt.get(N-2) - cdown;
    down = down * now % mod;
    up = up * now % mod;
    ans = (ans + up  + cdown - down) % mod;
    sum.upd(p[i], powmod(q, mod - 1 - i));
    cnt.upd(p[i], +1);
  }
  long long tot = 1LL * n * (n - 1) / 2;
  tot %= mod;
  ans = (tot - ans) % mod;
  ans %= mod;
  if (ans < 0)
    ans += mod;
  printf("%lld\n", ans);
  return 0;
}


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

int main(){
  vector<int> A(5);
  int k;
  for(int i=0;i<5;i++){
    cin >> A.at(i);
  }
  cin >> k;
  if(A.at(4)-A.at(0)>k){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
}


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    C = iss()
    cnt = collections.Counter(C)
    red = cnt['R']
    print(red - collections.Counter(C[:red])['R'])


if __name__ == '__main__':
    main()


Measured memory_bytes: 10188
#include <stdio.h>
int main(void){
   int a, b, d, r;
   double f;
   scanf("%d %d", &a, &b);
   d = a/b;
   r = a%b;
   f = (double)a / b;
   printf("%d %d %f\n", d, r, f);
   return 0;
}


Measured memory_bytes: 2124
#include<stdio.h>
int main(void){
	int a,b,ans;
	char op;
		while(1){
			scanf("%d %c %d",&a,&op,&b);
			if(op=='?')break;
			else if(op=='+')ans=a+b;
			else if(op=='-') ans=a-b;
            else if(op=='*') ans=a*b;
            else if(op=='/') ans=a/b;
			printf("%d\n",ans);
		}
	return 0;
}


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

int main()
{
    int d;
    scanf("%d",&d);
    switch (d)
    {
        case 22: printf("Christmas Eve Eve Eve\n"); break;
        case 23: printf("Christmas Eve Eve\n"); break;
        case 24: printf("Christmas Eve\n"); break;
        case 25: printf("Christmas \n"); break;
    }
    //system("PAUSE");
    return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>


int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (((a < c) && (c < b))||((a > c) && (c > b))) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

typedef struct {
	int key, id, s;
} data;

typedef struct {
	data obj[400001];
	int size;
} min_heap;

void push(data x, min_heap* h)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key < h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(min_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key < h->obj[j].key) j ^= 1;
		if (h->obj[j].key < h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}

void add_BIT(int N, int BIT[], int i, int k)
{
	while (i <= N) {
		BIT[i] += k;
		i += (i & -i);
	}
}

int sum_BIT(int BIT[], int r)
{
	int sum = r;
	while (r > 0) {
		sum -= BIT[r];
		r -= (r & -r);
	}
	return sum;
}

int main()
{
	int i, H, W, A, B;
	scanf("%d %d", &H, &W);
	
	int j, k, s[200002], left[200002], right[200002], BIT[200001] = {}, L, R, M, tmp;
	data d;
	min_heap h;
	h.size = 0;
	for (i = 0; i <= W + 1; i++) {
		s[i] = i;
		left[i] = i - 1;
		right[i] = i + 1;
	}
	for (i = 1, d.key = 0; i <= W; i++) {
		d.id = i;
		d.s = i;
		push(d, &h);
	}
	for (i = 1; i <= H; i++) {
		scanf("%d %d", &A, &B);
		tmp = sum_BIT(BIT, B);
		if (sum_BIT(BIT, A - 1) == tmp) {
			printf("%d\n", h.obj[1].key + i);
			continue;
		}
		
		if (s[B+1] < 0) {
			L = A;
			R = B;
			while (L != R) {
				M = (L + R) / 2;
				if (sum_BIT(BIT, M) != tmp) L = M + 1;
				else R = M;
			}
			s[B+1] = s[L];
			right[B+1] = right[L];
			left[right[L]] = B + 1;
			
			d.key = B + 1 - s[B+1];
			d.id = B + 1;
			d.s = s[B+1];
			push(d, &h);
			add_BIT(W, BIT, B + 1, -1);
		} else L = left[B+1];
		
		for (j = L; j >= A; j = left[j]) {
			s[j] = -1;
			add_BIT(W, BIT, j, 1);
		}
		left[B+1] = j;
		right[j] = B + 1;
		
		while (h.size > 0 && h.obj[1].s != s[h.obj[1].id]) pop(&h);
		if (h.size > 0) printf("%d\n", h.obj[1].key + i);
		else break;
	}
	for (; i <= H; i++) printf("-1\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 7356
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
int main(){
  ll k;
  ll a,b;
  cin >> k;
  cin >> a >> b;
  t1 = a / k;
  t2 = b / k;
  bool can = false;
  REP(i,a,b+1){
    if(i % k == 0){
      can = true;
    }

  }
  if(can){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
}

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

static const int MAX =100;
static const int INF=(1<<21);
static const int WHITE =0;
static const int GRAY =1;
static const int BRACK =2;

int n,A[MAX][MAX];

void dij(){
  int minv,d[MAX],c[MAX];

  for(int i=0;i<n;i++){
    d[i]=INF;
   
    c[i]=WHITE;
  }

  d[0]=0;
  c[0]=GRAY;
  
  while(1){
    minv=INF;
    int x=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i] && c[i]!=BRACK){
	x=i;
	minv=d[i];
      }
    }
    if(x==-1)break;
    c[x]=BRACK;
    for(int v=0;v<n;v++){
      if(c[v]!=BRACK && A[x][v]!=INF){
	if(d[v]>d[x]+A[x][v]){
	  d[v]=d[x]+A[x][v];
	 
	  c[v]=GRAY;
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==INF ? -1: d[i])<<endl;
  }
}
 

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      A[i][j]=INF;
    }
  }
  int k,c,u,v;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin >> v >> c;
      A[u][v]=c;
    }
  }
  dij();
  return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define swap(a,b)\
do{\
  a = a^b;\
  b = a^b;\
  a = a^b;\
}while(0)
 
int gcd(int a,int b){
  if(a<b){
  	swap(a,b);
  }
  int r=a%b;
  if(r==0)return b;
  return gcd(r,b);
}
 
int main(){
  int k,sum=0;cin>>k;
  rep(x,k){
  	rep(y,k){
  	  rep(z,k){
  	  	sum+=gcd(gcd(x+1,y+1),z+1);
  	  }
  	}
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3632
n, m, l = map(int, input().split())

A = []
B = []

for _ in range(n):
    A.append(list(map(int, input().split())))

for _ in range(m):
    B.append(list(map(int, input().split())))

C = []

for i in range(n):
    row = []
    for j in range(l):
        s = 0
        for k in range(m):
            s += A[i][k] * B[k][j]
        row.append(s)
    C.append(row)

for row in C:
    print(" ".join(map(str, row)))


Measured memory_bytes: 6908
#include<stdio.h>

#define ll long long int

int main() {
  ll i;
  ll a, b, c, d;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &d);

  ll tmp;
  if(c < d) {
    tmp = c;
    c = d;
    d = tmp;
  }

  // printf("%lld %lld\n", c, d);
  ll tmp1 = c, tmp2 = d, q, r;
  while(1) {
    q = tmp1 / tmp2;
    r = tmp1 % tmp2;
    // printf("q %lld  r %lld\n", q, r);
    tmp1 = tmp2;
    if(r == 0) break;
    tmp2 = r;
  }

  ll lcm_c_d = c * d / tmp2;
  // printf("%lld\n", lcm_c_d);

  ll less_a_num = (a - 1) - ((a - 1) / c + (a - 1) / d - (a - 1) / lcm_c_d);
  ll less_b_num = b - (b / c + b / d - b / lcm_c_d);

  printf("%lld\n", less_b_num - less_a_num);

  return 0;
}


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

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

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

  int r, g;
  cin >> r >> g;

  int ans;
  ans = g * 2 - r;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256