akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision
vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(vector<vector<int>> &G, int v, int &ptr){
    first_order[v]=ptr++;
    seen[v]=true;
    for(auto nv:G[v]){
        if(seen[nv]) continue;
        dfs(G, nv, ptr);
    }
    last_order[v]=ptr++;
}

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> G(n);
    rep(i,n){
        int a,b;
        cin >> a;
        cin >> b;
        a--;
        rep(i,b){
            int c;
            cin >> c; 
            c--;
            G[a].push_back(c);
        }
    }
    seen.assign(n, false);
    first_order.resize(n);
    last_order.resize(n);
    int ptr=1;
    rep(i,n){
        if(seen[i]==false){
            dfs(G, i, ptr);
        }
    }
    for(int i=0; i<n; i++){
       cout << i+1 << " " << first_order[i] << " " << last_order[i] << endl;
    }
}


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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main()
{
    int64_t N, ans = 0;
    cin >> N;
    for (int A = 1; A < N; A++)
        ans += (N - 1) / A;
    cout << ans;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    int b = 0, w = 0;

    vi black(n, 0), white(n, 0);

    rep(i, n) {
        if (s[i] == '#') {
            b++;
        } else {
            white[i] = b;
            w++;
        }
    }
    //all b or all w
    int num = min(b, w);

    b = 0;
    w = 0;

    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == '#') {
            b++;
            black[i] = w;
        } else {
            w++;
        }
    }

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '.') {
            int t = 0;

            t += white[i];

            while (s[i] != '#') {
                i++;

                if(i==s.size()){
                    break;
                }
            }

            t += black[i];

            num = min(num, t);

            i++;
        }
    }

    cout << num << endl;
}

Measured memory_bytes: 2196
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, t, b;
    cin >>a >>b >>t;
    cout <<(t / a) * b;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
blu_list = [str(input()) for _ in range(n)]
m = int(input())
red_list = [str(input()) for _ in range(m)]

blu_set_list = list(set(blu_list))
red_set_list = list(set(red_list))
set_list = blu_set_list + red_set_list

blu_cnt = []
red_cnt = []
ans = []

for i in set_list:
    blu_cnt.append(blu_list.count(i))
    red_cnt.append(red_list.count(i))

for i in range(len(set_list)):
    ans.append(blu_cnt[i] - red_cnt[i])

print(max(ans) if max(ans) > 0 else 0)

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

int main(){
  long long int X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  vector<long long int> A(X),B(Y),C(Z);
  vector<long long int> M(K);
  vector<long long int> saa(X-1),sab(Y-1),sac(Z-1);
  for(int i=0;i<X;i++){
    cin>>A.at(i);
  }
  for(int i=0;i<Y;i++){
    cin>>B.at(i);
  }
  for(int i=0;i<Z;i++){
    cin>>C.at(i);
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  reverse(A.begin(),A.end());
  reverse(B.begin(),B.end());
  reverse(C.begin(),C.end());
  vector<long long int> D(Y*Z);
  for(int i=0;i<Y;i++){
    for(int j=0;j<Z;j++){
      D.at(i*Z+j)=B.at(i)+C.at(j);
    }
  }
  sort(D.begin(),D.end());
  reverse(D.begin(),D.end());
  vector<long long int> ma(X*min(K,Y*Z));
  for(int i=0;i<X;i++){
    for(int j=0;j<min(K,Y*Z);j++){
      ma.at(j*X+i)=A.at(i)+D.at(j);
    }
  }
  sort(ma.begin(),ma.end());
  reverse(ma.begin(),ma.end());
  for(int i=0;i<K;i++){
    cout<<ma.at(i)<<endl;
  }
  
  
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=len(s);
    rep(i,n){
      if(i+1<=n-1 && s[i]==s[i+1]){
        cout<<i+1<<' '<<i+2<<endl;
        return 0;
      }
      else if(i+2<=n-1 && s[i]==s[i+2]){
        cout<<i+1<<' '<<i+3<<endl;
        return 0;
      }
    }
    cout<<-1<<' '<<-1<<endl;
}

Measured memory_bytes: 512
def yakusu(n):
  a=[]
  for i in range(1,n+1):
    if n%i==0:a.append(i)
  return a
a=0;n=int(input())
for i in range(1,n+1):a+=(1if len(yakusu(i))==8and i%2==1else 0)
print(a)

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

 

#define pb push_back

#define mp make_pair

#define fs first

#define sc second

#define rep(i, from, to) for (int i = from; i < (to); ++i)

#define all(x) x.begin(), x.end()

#define sz(x) (int) (x).size()

#define FOR(i, to) for (int i = 0; i < (to); ++i)

 

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pii;

typedef pair<double,double> pdd;

typedef vector<ll> vll;

typedef vector<pair<int,int>> vpi;

typedef pair<ll,ll> pll;

typedef vector<string> vs;

#define MOD 1000000007

#define INF 1000000000LL * 100000000LL

#define Nmax 2020201



ll N,T;

ll A[3333], B[3333];

ll best[3333];

ll ret;
vector<pll> v;

int main() {

  cin >> N >> T;

  FOR(i, N) {
    ll x,y;
    cin >> x >> y;
    v.pb(mp(x,y));

  }
  sort(all(v));

  best[0] = 1;

  FOR(i, N) {

    for(ll j=T-1;j>=0;--j) {

      if(best[j]) {
        int fs = min(j+v[i].fs,T);

        best[fs] = max(best[fs], best[j] + v[i].sc);
      }

    }

  }

  FOR(i, T+1) {

    ret = max(ret, best[i]);

  }

  cout << ret - 1 << endl;

}

 

Measured memory_bytes: 384
// In the name of god
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define use_file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
using namespace std;
using ll = long long;
const ll N = 1e5 + 5, inf = 4e18, mod = 1e9 + 7;
ll n, m, ans;
vector <ll> adj[N];
bool mark[N];
void dfs(ll u){
	mark[u]=1;
	for(int j : adj[u]){
		if(!mark[j])
			dfs(j);
	}
}
int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >>  n >> m;
	for(int i =  0; i < m; i++){
		ll u, v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	for(int i = 1; i <= n; i++){
		if(!mark[i]){
			dfs(i);
			ans++;
		}
	}
	cout << ans - 1;
	cout << endl;
}


Measured memory_bytes: 10340
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

int main(){
	int	n;
	long long a[200000] = { 0 };
	long long total = 0;
	long long temp=0,min =LLONG_MAX ;
	long long y;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		total += a[i];
	}
	
	for (int i = 0; i < n - 1; i++) {
		temp += a[i];
		y = temp - (total - temp);
		if (y < 0)y = -y;
		if (min > y)
			min = y;
	}
	/*
	if (min > abs(a[n - 1] - (total - a[n - 1])))
		min = abs(a[n - 1] - (total - a[n - 1]));
		*/
	printf("%lld",min);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <atcoder/all>

typedef long long ll;
using namespace std;
using namespace atcoder;

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define _repi(i, s, n) for(ll i = (ll)(s); i < (ll)n; i++)
#define REP(...) _overload(__VA_ARGS__, _repi, _rep,)(__VA_ARGS__)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

int main(){
	ll n, q;	cin >> n >> q;
	dsu g(n);
	ll t, u, v;
	REP(i, q){
		cin >> t >> u >> v;
		if( t == 0 ){
			g.merge(u, v);
		}else{
			if( g.same(u, v) )	cout << 1 << endl;
			else				cout << 0 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 4004
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}
//xとyのビットごとの排他的論理和
template<class T> T XOR(T x, T y)
{
	T n = 0;
	while (max(x, y) > pow(2, n)) n++;
	T ans=0;
	for (int i = 0; i <= n; i++)
	{
		T x1 = (x % (T)pow(2, i + 1)) / (T)pow(2, i);
		T y1 = (y % (T)pow(2, i + 1)) / (T)pow(2, i);
		if (x1 != y1) ans += (T)pow(2, i);
	}
	return ans;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



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

	int a = max(H, W);

	if (N%a == 0)
		cout << N / a << endl;
	else
		cout << N / a + 1 << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    PrintWriter out = new PrintWriter(System.out);

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

    void run() {

        int n = sc.nextInt();
        int y = sc.nextInt();

        int c10000 = 2000;
        int c5000 = 2000;
        int c1000 = 0;

        label:
        for (int i=0; i<=n; i++) {
            for (int j=0; j<=n; j++) {
                if ((9000*i+4000*j)==(y-1000*n)) {
                    c10000 = i;
                    c5000 = j;
                    if (c10000+c5000<=n) break label;
                }
            }
        }

        c1000 = n-c10000-c5000;

//        out.print(c10000+" ");
//        out.print(c5000+" ");
//        out.print(c1000+" ");

        if (c1000>=0) {
            out.print(c10000+" ");
            out.print(c5000+" ");
            out.print(c1000+" ");
            out.flush();
        } else {
            out.print(-1+" ");
            out.print(-1+" ");
            out.print(-1+" ");
            out.flush();
        }



    }

}


Measured memory_bytes: 21844
#include <stdio.h>
#include <ctype.h>
#define MAX 1200

int main(void) {
    char ary[MAX], *ptr = ary;
    for(fgets(ary, sizeof(ary), stdin); *ptr; ptr++) {
        printf("%c", isupper(*ptr) ? tolower(*ptr) : toupper(*ptr));
    }
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;

class Solver {
public:
};

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		vector<tuple<int, int>> pos;
		pos.emplace_back(make_tuple(0, 0));
		int left = 0;
		int right = 0;
		int up = 0;
		int down = 0;
		for (int i = 1; i < n; i++) {
			int base, dire;
			cin >> base >> dire;
			if (dire == 0) {
				pos.emplace_back(
					make_tuple(get<0>(pos[base]) - 1, get<1>(pos[base])));
				left = min(left, get<0>(pos[i]));
			}
			if (dire == 1) {
				pos.emplace_back(
					make_tuple(get<0>(pos[base]), get<1>(pos[base]) + 1));
				down = max(down, get<1>(pos[i]));
			}
			if (dire == 2) {
				pos.emplace_back(
					make_tuple(get<0>(pos[base]) + 1, get<1>(pos[base])));
				right = max(right, get<0>(pos[i]));
			}
			if (dire == 3) {
				pos.emplace_back(
					make_tuple(get<0>(pos[base]), get<1>(pos[base]) - 1));
				up = min(up, get<1>(pos[i]));
			}
		}
		cout << (right - left + 1)<<' ' << (down - up + 1) << endl;
	}
}


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

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

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    println!("{}", {
        input!{ s: String, }
        let rl = ['R', 'L'];
        if s.chars().enumerate().filter(|&(_, c)| c == 'R' || c == 'L').all(|(i, c)| rl[i % 2] == c) { "Yes" } else { "No" }
    });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
	ll n,m;
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2<<endl;
	return 0;
}

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

#define sz(x) (int)x.size()

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    string x; cin >> x;


        if (x[sz(x)-1] == '3') {
            cout << "bon\n";
        } else if (x[sz(x)-1] == '0' || x[sz(x)-1] == '1' || x[sz(x)-1] == '6' || x[sz(x)-1] == '8') {
            cout << "pon\n";
        } else cout << "hon\n";

}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        String S = scanner.next();

        scanner.close();

        if (N % 2 == 1) {
            System.out.println("No");
            return;
        }

        String firstHalf = S.substring(0, N / 2);
        String lastHalf = S.substring(N / 2, N);

        System.out.println(firstHalf.equals(lastHalf) ? "Yes" : "No");
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define ld double
using namespace std;
const int N = 1005;
const int mod = 1e9+7;
int ans[N][N];
int main() {
    int h , w;
    cin>>h>>w;
    char grid[h][w];
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            cin>>grid[i][j];
//            if(j == 0 || i == 0){
//                if(grid[i][j] == '#')
//                    continue;
//                ans[i][j] = 1;
//            }
        }
    }
    ans[0][0] = 1;
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            if(grid[i][j] == '#')
                continue;
            if(i){
                ans[i][j] += ans[i-1][j];
            }
            if(j){
                ans[i][j] += ans[i][j-1];
            }
            ans[i][j]%=mod;
        }
    }
    printf("%d",ans[h-1][w-1]);
    return 0;
}


Measured memory_bytes: 5120
#include <iostream>

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

using namespace std;

int main(){
	int h,w,d;
	cin >> h >> w >> d;
	
	int a[90005][2];
	int input;
	
	REP(i,h){
		REP(k,w){
			cin >> input;
			//cout << input << endl;
			a[input-1][0] = i;
			a[input-1][1] = k;
		}
	}
	
	int q;
	cin >> q;
	
	int l,r;
	long long int m[90005];
	REP(i,h*w){
		m[i] = 0;
	}
	
	for (int i=d; i<h*w; i++){
		m[i] = m[i-d] + abs(a[i][0]-a[i-d][0]) + abs(a[i][1]-a[i-d][1]);
	}
		
	
	REP(i,q){
		cin >> l >> r;
		cout << m[r-1]-m[l-1] << endl;
	}
}



Measured memory_bytes: 2688
from math import gcd
n = int(input())
C = {}
z = 0
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        z += 1
        continue
    g = gcd(x, y)
    x, y = x // g, y // g
    if y < 0:
        x, y = -x, -y
    try:
        C[(x, y)] += 1
    except KeyError:
        C[(x, y)] = 1
ans = 1
p = 10**9 + 7
for x, y in C:
    if C[(x, y)] == 0:
        continue
    a = C[(x, y)]
    if x > 0:
        x0, y0 = -y, x
    else:
        x0, y0 = y, -x
    try:
        b = C[(x0, y0)]
        C[(x0, y0)] = 0
    except KeyError:
        b = 0
    ans *= pow(2, a, p) + pow(2, b, p) - 1
    ans %= p
    C[(x, y)] = 0
print((ans + z - 1) % p)


Measured memory_bytes: 46440
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

const char *button[10] = {
  " ",
  "',.!?", "abcABC", "defDEF",
  "ghiGHI"  , "jklJKL", "mnoMNO",
  "pqrsPQRS" , "tuvTUV", "wxyzWXYZ"
};


int main(){
  string str;
  while(cin >> str){
    int b = 0;
    int c = 0;

    FOR(it, str){
      int a = *it - '0';

      if(a == 0){
	if(b == 0){
	  cout << " ";
	}else{
	  cout << button[b][c % strlen(button[b])];
	  b = a;
	  c = 0;
	}
      }else{
	if(a == b){
	  c++;
	}else{
	  if(b != 0) cout << button[b][c % strlen(button[b])];
	  b = a;
	  c = 0;
	}
      }
    }
    if(b != 0) cout << button[b][c % strlen(button[b])];
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); 
        int L = sc.nextInt();
        String[] s = new String[N];
        String[] S = new String[N];
      
        for(int i=0; i<N; i++){
          s[i] = sc.next();
          S[i] = s[i];
        }
      
        Arrays.sort(S);

        String X = S[0];
        for(int i=1; i<N; i++){
          X = X + S[i];
        }
        System.out.println(X);
    }
}

Measured memory_bytes: 24148
x,y,_,_,_ = map(int,raw_input().split(' '))

a,b,c = map(int, raw_input().split(' ')),map(int, raw_input().split(' ')),map(int, raw_input().split(' '))
a.sort(key = lambda x:-x)
b.sort(key = lambda x:-x)
c.sort(key = lambda x:-x)
r = a[:x] + b[:y]
r.sort()

i,j = 0,0
while(j < len(c) and i < len(r)):
	if c[j] > r[i]:
		r[i] = c[j]
		i +=1
	else:
		break
	j +=1

print sum(r)

Measured memory_bytes: 79192
#include<iostream>
using namespace std;
int main(){
  int n,minj,count=0;
  int a[101]={};
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
 
  for(int i=0;i<n;i++){
    minj=i;
    for(int j=i;j<n;j++)if(a[j]<a[minj])minj=j;
    if(i!=minj){
      swap(a[i],a[minj]);// 関数をかく。
      count++;
    }
  }
  for(int i=0;i<n-1;i++)cout<<a[i]<<' ';
  cout<<a[n-1]<<endl<<count<<endl;
  return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main(void){

    long long n, k;
    cin >> n >> k;
    
    long long result = n%k;
    long long temp = result - k;
    if(temp<0) temp *= -1;

    if(result > temp) cout << temp << endl;
    else cout << result << endl;

    return 0;    
}


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

long long l, n = 1, m = 0, now = 1, bf, nown, nowl,
             plus = 0;
long long ans[60][3] = {0};
long long store[20] = {0};

long long mypow(long long x, long long y) {
  long long ans = 1;
  for(long long i = 0; i < y; ++i) ans *= x;
  return ans;
}

int main() {
  long long i;
  cin >> l;
  while(now * 2 <= l) {
    ans[m][0] = n;
    ans[m][1] = n + 1;
    ans[m][2] = 0;
    ans[m + 1][0] = n;
    ans[m + 1][1] = ++n;
    ans[m + 1][2] = now;
    m += 2;
    bf = now;
    now *= 2;
  }
  if(now == l)
    nowl = 0;
  else
    nowl = l - now;
  nown = n - 1;
  while(nowl) {
    if(nowl >= bf) {
      ans[m][0] = nown;
      ans[m][1] = n;
      if(nown == 1)
        ans[m][2] = l - 1;
      else
        ans[m][2] = now;
      now += mypow(2, nown - 1);
      ++m;
      nowl -= bf;
    }
    bf /= 2;
    --nown;
  }
  cout << n << " " << m << endl;
  for(i = 0; i < m; ++i)
    cout << ans[i][0] << " " << ans[i][1] << " "
         << ans[i][2] << endl;
  return 0;
}


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

int main() {
    ios :: sync_with_stdio(false);
    cin.tie(0);
    vector<int> s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    cout << s[n - 1];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
template<typename T> T gcd(T a,T b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n, m, p[100009];
vi v[100009];
si s, s2, s3;
void search(int a){
  s.emplace(a);
  s2.emplace(a);
  s3.emplace(p[a]-1);
  each(itr, v[a]){
    if(s2.find(*itr) != s2.end()) continue;
    search(*itr);
  }
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, n) cin >> p[i];
  FOR(i, 0, m){
    int x, y;
    cin >> x >> y;
    x--; y--;
    v[x].pb(y);
    v[y].pb(x);
  }
  int ans = 0;
  FOR(i, 0, n){
    if(s.find(i) != s.end()) continue;
    search(i);
    each(itr, s3) if(s2.find(*itr) != s2.end()) ans++;
    s2.clear();
    s3.clear();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 23168
N , M = map(int,input().split())

X = list(map(int,input().split()))

X.sort()

# 隣接点の間の距離が長い順で分割する
# おけるコマの個数-1だけ辺を取り除ける

maxDist = X[-1] - X[0]

dist = [0] * (M-1)

# 間の距離を計算
for i in range(M-1) :
    dist[i] = X[i+1] - X[i]

dist.sort(reverse=True)

for i in range(min(N-1,M-1)) :
    maxDist -= dist[i]

print(maxDist)

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

int main(){
	int n;
	long long np, nq, tmp, cnt, cnt_small;
	int dp[8] = {0, 0, 0, 0, 0, 0, 0, 0};
	cin >> n;
	vector<int> p(n), q(n);
	for(int i=0; i<n; i++){
		cin >> p[i];
	}
	for(int i=0; i<n; i++){
		cin >> q[i];
	}

	np = 1;
	tmp = 1;
	cnt = 1;
	dp[p[n-1]-1] = 1;
	for(int i=n-2; i>=0; i--){
		dp[p[i]-1] = 1;
		cnt_small = 0;
		for(int j=0; j<p[i]-1; j++){
			cnt_small += dp[j];
		}
		np += cnt_small*tmp;
		cnt++;
		tmp *= cnt;
	}
	for(int i=0; i<8; i++){
		dp[i] = 0;
	}
	nq = 1;
	tmp = 1;
	cnt = 1;
	dp[q[n-1]-1] = 1;
	for(int i=n-2; i>=0; i--){
		dp[q[i]-1] = 1;
		cnt_small = 0;
		for(int j=0; j<q[i]-1; j++){
			cnt_small += dp[j];
		}
		nq += cnt_small*tmp;
		cnt++;
		tmp *= cnt;
	}
	//cout << np << endl;
	//cout << nq << endl;
	//cout << np << "," << nq << endl;
	cout << abs(np-nq) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) ((int)x.size())

const int mod = 1000*1000*1000+7;
char grid[1005][1005];
int dp[1005][1005] = {{0}};

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++)
            cin >> grid[i][j];
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++)
            if(i == 1 && j == 1)
                dp[i][j] = 1;
            else if(grid[i][j] == '.')
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
    cout << dp[h][w] << endl;
}

Measured memory_bytes: 12372
require("fs").readFileSync("/dev/stdin","utf8").trim().split('\n').some(function(i){j=i.split(' ');if(j[1])a=j[0],b=j[1],c=j[2],d=j[3],e=j[4],f=j[5],g=a*a,h=b*b,k=c*c,l=d*d,m=e*e,n=f*f,o=a-c,r=b-d,s=b-f,t=a-e,p=(s*(h-l+g-k)-r*(h-n+g-m))/(2*s*o-2*r*t),q=(t*(g-k+h-l)-o*(g-m+h-n))/(2*t*r-2*o*s),console.log(p.toFixed(3),q.toFixed(3),Math.sqrt((a-p)*(a-p)+(b-q)*(b-q)).toFixed(3))})

Measured memory_bytes: 7912
# exp = [1]
# b = 2
# while b ** 2 <= 1000:
#     p = 2
#     while b ** p <= 1000:
#         exp.append(b ** p)
#         p += 1
#     b += 1
# exp.sort()
# print(exp)
from bisect import bisect

exp = [1, 4, 8, 9, 16, 16, 25, 27, 32, 36, 49, 64, 64, 64, 81, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243,
       256, 256, 256, 289, 324, 343, 361, 400, 441, 484, 512, 512, 529, 576, 625, 625, 676, 729, 729, 729, 784, 841,
       900, 961, 1000]

x = int(input())
print(exp[bisect(exp, x) - 1])


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <algorithm>    
#include <vector>       
#include <set>
#include <utility>  
#include <cstring>
#include <stdio.h>
#include <limits.h>
#include <queue>
#include <algorithm> 
#define MAX_DOUBLE  40000000000.0 
#include <math.h> 
#include <unistd.h>

using namespace std;

int max(int a, int b){
	if(a > b) return a;
	return b;
}

map<int, vector<int> > graph; 
int res[100010];

void dfs(int a){
	if(res[a] != -1 ) return;
	
	res[a] = 0;
	
	for(int i = 0; i < graph[a].size(); i++){
//		cout<<graph[a][i]<<endl;
		dfs(graph[a][i]);
		res[a] = max(res[a], res[graph[a][i]] + 1);
	}	
}


int main(){
	int n,m;
	
	cin>>n>>m;
	
	for(int i = 0; i < m; i++){
		int a, b;
		cin>>a>>b;
		graph[a].push_back(b);
	}
	
	for(int i = 1; i <= n; i++){
		res[i] = -1;
	}
	
	for(int i = 1; i <= n; i++){
		dfs(i);
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		ans = max(ans, res[i]);
	}
	
	cout<<ans;
}


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

int main() {
  int s;
  cin >> s;
  int s1 = s / 100;
  int s2 = (s - s1 * 100) / 10;
  int s3 = s - s1 * 100 - s2 * 10;
  cout << s1 + s2 + s3 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if((a<b&&b<c)||(c<a&&a<b)||(b<a&&a<c)||(c<b&&b<a)) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


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

int main(int argc, char *argv[])
{
        char s[100000];
        cin >> s;
        int i=0;
        while(1){
            if(s[i]==NULL){
                break;
            }
            i++;
        }

        if(i==0){
            cout << 0 << endl;
            return 0;
        }

        

        int size = i;
        int counter1=0;
        

        for(int z=0;z<size;z++){
            if(z%2==0){
                if(s[z]=='1'){
                    counter1++;
                }
            }else{
                if(s[z]=='0'){
                    counter1++;
                }
            }
        }


        int counter2=0;
        for(int z=0;z<size;z++){
            if(z%2==0){
                if(s[z]=='0'){
                    counter2++;
                }
            }else{
                if(s[z]=='1'){
                    counter2++;
                }
            }
        }

        if(counter1<counter2){
            cout << counter1 << endl;
        }else{
            cout << counter2 << endl;
        }

        return 0;
}

Measured memory_bytes: 888
# diverta 2019 Programming Contest
# https://atcoder.jp/contests/diverta2019
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    R, G, B, N = i2nn()
    c = 0
    for r in range(N+1):
        rr = r * R
        if rr > N:
            break
        for g in range(N+1):
            gg = g * G
            if rr + gg > N:
                break
            n2 = N - rr - gg
            if n2 % B == 0:
                c += 1
    print(c)

main()


Measured memory_bytes: 40560
#include <iostream>
#include <fstream>
#include <string>


using namespace std;

int main(){
#ifdef CIN
	ifstream cin("input.txt");
	ofstream cout("output.txt");

#endif

	int n;
	int max, min;
 long long sum;

	cin >> n;
	int a[10000];

	max = -1000000;
	min = 1000000;
	sum = 0;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (max < a[i]) max = a[i];
		if (min > a[i]) min = a[i];

		sum += a[i];

	}

	


	cout << min << " " << max << " " << sum << endl;






}

Measured memory_bytes: 1204
l=[1,9,30,76,141,267,400,624,885,1249,1590,2208,2689,3411,4248,5248,6081,7485,8530,10248,11889,13687,15228,17988,20053,22569,25242,28588,31053,35463,38284,42540,46581,50893,55362,61824,65857,71247,76884,84388,89349,97881,103342,111528,120141,128047,134580,146316,154177,164817,174438,185836,194157,207927,218812,233268,245277,257857,268182,288216,299257,313635,330204,347836,362973,383709,397042,416448,434025,456967,471948,499740,515581,536073,559758,583960,604833,633651,652216,683712,709065,734233,754734,793188,818917,846603,874512,909496,933081,977145,1006126,1041504,1073385,1106467,1138536,1187112,1215145,1255101,1295142,1342852,1373253,1422195,1453816,1502376,1553361,1595437,1629570,1691292,1726717,1782111,1827492,1887772,1925853,1986837,2033674,2089776,2145333,2197483,2246640,2332104,2379085,2434833,2490534,2554600,2609625,2693919,2742052,2813988,2875245,2952085,3003306,3096024,3157249,3224511,3306240,3388576,3444609,3533637,3591322,3693924,3767085,3842623,3912324,4027884,4102093,4181949,4270422,4361548,4427853,4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692]
print(l[int(input())-1])


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

int dp[MAX_N][MAX_L];

int main() {
    int n,s,l,p,mn,w;
    map<int,int> m;
    vector<int> a,b;
    cin >> n;

    rep(i,n) {
        cin >> s >> l >> p;
        rep(j,l-s+1) {
            if(!m.count(j+s))
                m[j+s] = p;
            else
                m.at(j+s) = max(m.at(j+s), p);
        }
    }

    for(auto p : m) {
        a.push_back(p.first);
        b.push_back(p.second);
    }

    rep(i,MAX_N)
        rep(j,MAX_L)
            dp[i][j] = 0;

    rep(i,a.size())
        rep(j,MAX_L) {
            if(a.at(i) > j)
                dp[i+1][j] = dp[i][j];
            else
                dp[i+1][j] = max(dp[i][j], dp[i+1][j-a.at(i)]+b.at(i));
        }
    
    cin >> mn;
    vector<int> r(mn);
    rep(i,mn) {
        cin >> w;
        if(dp[a.size()][w] == 0) {
            cout << -1 << endl;
            return 0;
        }
        r.at(i) = dp[a.size()][w];
    }

    rep(i,mn)
        cout << r.at(i) << endl;
}


Measured memory_bytes: 3820
// Problem : S - Digit Sum
// Contest : Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_s
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define maxm 1e18
#define minm -1e18
#define pr pair<ll,ll>
#define mod 1000000007

void add_self(ll &a,ll b)
{
	a=(a+b)%mod;
}
 
void solve()
{
	ll d,i,digit,sm_already;
	string k;
	cin>>k>>d;
	ll len=k.length(),sum;
	vector< vector<ll> > dp(d,vector<ll> (2));
	//dp[sum][smaller_already] -> the number of ways
	//to choose digits so far such that sum of digits
	//modulo d is 'sum' and 'smaller_already' says whether
	//we already chosen some digit smaller than in k
	dp[0][0]=1;
	for(i=0;i<len;i++)
	{
		vector< vector<ll> > new_dp(d,vector<ll> (2));
		for(sum=0;sum<d;sum++)
		{
			for(sm_already=0;sm_already<2;sm_already++)
			{
				for(digit=0;digit<10;digit++)
				{
					if(!sm_already && (digit>k[i]-'0'))
						break;
					add_self(new_dp[(sum+digit)%d][sm_already || (digit<k[i]-'0')],dp[sum][sm_already]);
				}
			}
		}
		dp=new_dp;
	}
	ll ans=(dp[0][0]+dp[0][1]-1+mod)%mod;
	cout<<ans<<endl;
}
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
    	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
import math

c = [0, 0, 0, 0]
for i in range(3):
    a, b = [int(x) for x in input().split()]
    c[a-1] += 1
    c[b-1] += 1

c.sort()
# print(c)

if c == [1,1,2,2]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
def main():
    n = int(input())
    a = [int(v) for v in input().split()]
    b = [a[i] for i in range(n + 1)]
    for i in reversed(range(0, n)):
        b[i] += b[i + 1]
    pow2 = [1 for _ in range(n + 1)]
    for i in range(1, n + 1):
        pow2[i] = 2 * pow2[i - 1]
    result = a[n]
    d = 0
    for i in range(n):
        d = 2 * d + a[i]
        if pow2[i] - d < 0:
            print(-1)
            return
        result += min(pow2[i] - d, b[i + 1]) + a[i]
    d = 2 * d + a[n]
    if pow2[n] - d < 0:
        print(-1)
        return
    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 674640
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    
	    Queue <Long> OVER = new LinkedList<Long>(); 
	    PriorityQueue <Long> A = new PriorityQueue<Long>(); 
	    
        for(int i = 0; i < N; i++) {
        	Long temp = sc.nextLong();
        	if (temp<=Math.pow(10, 5))
        		A.add(temp);
        	else
        		OVER.add(temp);
        }
        sc.close();
        
        if (A.isEmpty())
        	System.out.println(OVER.size());
	    
        else {
        int size = A.size();
        long count = 0;
        int ans = 0;
        
        while (A.isEmpty()!=true){
        	count = 1;
        	long temp = A.poll();
        	
        	while (A.isEmpty()!=true && A.peek()==temp){
        		A.poll();
        		count++;
        	}
        	
        	if (temp>count)
        		ans += count; 
        	
        	else if (temp<count)
        		ans += (count-temp);
        	
        }
        System.out.println(OVER.size()+ans);
        
        }

	}

}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int l, r;
	cin >> l >> r;
	if (r - l > 2020)
	{
		cout << 0;
		return 0;
	}
	
	int ans = INF;
	FOR(i, l, r) FOR(j, i + 1, r + 1) setmin(ans, (int)(i * (LL) j % 2019));
	cout << ans;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



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

int main() {
	//input
	string S;
	cin >> S;

	int Q;
	cin >> Q;

	vector<int> T(Q);
	vector<int> F(Q);
	vector<char> C(Q);

	for (int i = 0; i < Q; i++) {
		cin >> T[i];
		if (T[i] == 2) {
			cin >> F[i] >> C[i];
		}
	}

	//code
	int reverse_flag = 1;
	for (int i = 0; i < Q; i++) {
		if (T[i] == 1) {
			reverse_flag *= -1;
		} else {
			if (F[i] == 1) {
				if (reverse_flag == 1) {
					S.insert(S.begin(), char(C[i]));
				} else {
					S.push_back(char(C[i]));
				}
			} else {
				if (reverse_flag == 1) {
					S.push_back(char(C[i]));
				} else {
					S.insert(S.begin(), char(C[i]));
				}
			}
		}
	}

	//output
	if (reverse_flag == -1) {
		reverse(S.begin(), S.end());
	}
	cout << S << endl;

	return 0;
}


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
int D;
int c[27], s[400][27];
int L[27];
int last[27];
long long ANS = 0;
long long ans = 0;
int main(){
    scanf("%d",&D);
    for (int i = 1; i <= 26; i++) scanf("%d",&c[i]);
    for (int i = 1; i <= D; i++){
        for (int j = 1; j <= 26; j++) scanf("%d",&s[i][j]);
    }
    for (int i = 1; i <= D; i++){
        int b1 = -1;
        long long ok = 0;
        for (int t = 1; t <= 26; t++){
            for (int x = 1; x <= 26; x++){
                ans = ANS;
                for (int j = 1; j <= 26; j++){
                    last[j] = L[j];
                }
                ans += s[i][t];
                last[t] = i;
                for (int j = 1; j <= 26; j++){
                    ans -= c[j]*(i-last[j]);
                }
                if (i != D){
                    ans += s[i+1][x];
                    last[x] = i+1;
                    for (int j = 1; j <= 26; j++){
                        ans -= c[j]*(i-last[j]);
                    }
                }
                if (b1 == -1 || ans > ok){
                    b1 = t;
                    ok = ans;
                }
            }
            //printf("for %d: %lld\n",t,ans);
        }
        ANS += s[i][b1];
        L[b1] = i;
        for (int j = 1; j <= 26; j++){
            ANS -= c[j]*(i-L[j]);
        }
        printf("%d\n",b1);
        //printf("score %lld\n",ANS);
    }
}


Measured memory_bytes: 3864
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
using namespace std;


int main() {
	long long int a = 0, b = 0, c = 0, memo = 0, s[50] = {};
	string str,res="2222222222222";
	cin >> str;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == 'B'&&memo > 0) { memo--; }
		if (str[i] == '0') { res[memo] = '0'; memo++; }
		if (str[i] == '1') { res[memo] = '1'; memo++; }

	}
	for (int i = 0; i < memo; i++) {
		cout << res[i];

	}
}


Measured memory_bytes: 256
from fractions import gcd

A, B, C, D = map(int, input().split())
L = C * D // gcd(C, D)
a = (A - 1) - (A - 1) // C - (A - 1) // D + (A - 1) // L
b = B - B // C - B // D + B // L
print(b - a)


Measured memory_bytes: 5048
S = input()
N = len(S)
end = int((N-1)/2)
start = int( (N+3)/2)-1

ans  = 'No'
if S == S[::-1]:
    if S[:end] == S[:end][::-1]:
        if S[start:] == S[start:][::-1]:
            ans = 'Yes'
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

        int minimum;
        cin >> minimum;

        int ans = 1;
        for(int i = 1; i < n; i++) {
                int pi;
                cin >> pi;

                if(pi <= minimum) {
                        ans++;
                        minimum = pi;
                }
        }

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


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep2(i,a,n) for(ll i=a;i<(n);++i)
#define repr(i,n) for(ll i=n;i>=0; --i)
#define repr2(i,a,n) for(ll i=n;i>=a; --i)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define VEC(v) vector<v >

#define INT(...) int __VA_ARGS__;IN(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;IN(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;IN(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;IN(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;IN(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;IN(__VA_ARGS__)

int scan(){ return getchar(); }
void scan(int& a){ cin>>a; }
void scan(long long& a){ cin>>a; }
void scan(char &a){cin>>a;}
void scan(double &a){ cin>>a; }
void scan(long double& a){ cin>>a; }
void scan(char a[]){ scanf("%s", a); }
void scan(string& a){ cin >> a; }
template<class T> void scan(vector<T>&);
template<class T, size_t size> void scan(array<T, size>&);
template<class T, class L> void scan(pair<T, L>&);
template<class T, size_t size> void scan(T(&)[size]);
template<class T> void scan(vector<T>& a){ for(auto& i : a) scan(i); }
template<class T> void scan(deque<T>& a){ for(auto& i : a) scan(i); }
template<class T, size_t size> void scan(array<T, size>& a){ for(auto& i : a) scan(i); }
template<class T, class L> void scan(pair<T, L>& p){ scan(p.first); scan(p.second); }
template<class T, size_t size> void scan(T (&a)[size]){ for(auto& i : a) scan(i); }
template<class T> void scan(T& a){ cin >> a; }

void IN(){}
template <class Head, class... Tail> void IN(Head& head, Tail&... tail){ scan(head); IN(tail...); }

int in() {int x;cin>>x;return x;}
ll llin() {unsigned long long x;cin>>x;return x;}

#define ios cin.tie(NULL), ios_base::sync_with_stdio(false)
#define cfs(n) cout<<fixed<<setprecision((n))
#define endl '\n'
#define ret return 0

constexpr ll mod=998244353;
constexpr ll mod2=10e9+7;
const double PI = 3.1415926535897932384626433832795028841971; //acos(-1)

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

int main(){
  ios; cfs(15);
  INT(d,t,s);
  cout<<((t*s>=d) ? "Yes" : "No")<<endl;
  ret;
}


Measured memory_bytes: 3640