akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int deg[110000];
int UF[110000];
int FIND(int a){
    if(UF[a]<0)return a;
    return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
    a=FIND(a);b=FIND(b);if(a==b)return;
    UF[a]+=UF[b];UF[b]=a;
}
int main(){
    int a,b;
    while(scanf("%d%d",&a,&b),a){
        for(int i=0;i<a;i++)UF[i]=-1;
        for(int i=0;i<a;i++)deg[i]=0;
        for(int i=0;i<b;i++){
            int p,q;
            scanf("%d%d",&p,&q);
            p--;q--;
            UNION(p,q);
            deg[p]++;
            deg[q]++;
        }
        bool ok=true;
        for(int i=0;i<a;i++)if(deg[i]>2)ok=false;

        int rk=0;
        for(int i=0;i<a;i++)if(UF[i]<0)rk++;
        if(rk!=a-b)ok=false;
        if(ok)printf("yes\n");
        else printf("no\n");
    }
}

Measured memory_bytes: 3928
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll a,b;
    cin >> a >> b;
    cout << a*b << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define endl '\n'
#define fast_in ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp  make_pair
#define pb  push_back
#define  sz(x)   (int)x.size()
#define  all(x)  x.begin(), x.end()
#define	 allr(x)  x.rbegin(), x.rend()
#define  bit(x)  __builtin_popcountll(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
const int inf = (int) 1e9+99999, mod = (int)1e9+7;
const ll linf = (ll) 2e18+99999;
int mul (int x, int y) { return ((ll)x * y) % mod; } 
int sub (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int add (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }
 
const int maxn = (int) 3e5;
 
int a[maxn];
pii p[maxn];

void solve () {
	int n, q;
	cin >> n >> q;
	multiset <int> s;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		s.insert (a[i]);
	} 	

	for (int i = 1; i <= q; i ++) {
		cin >> p[i].second >> p[i].first;
	}

	sort (p + 1, p + q + 1);
	reverse (p + 1, p + q + 1);


	for (int i = 1; i <= q; i ++) {
		int cnt = p[i].second;
		int x = p[i].first;

		while (cnt --) {
			if (*s.begin () < x) {
				s.erase (s.begin());
				s.insert (x);
			} else {
				break;
			}
		}
	}

	ll res = 0;
	for (auto to : s) {
		res += to;	
	}

	cout << res;
}

main () { fast_in;
    int t = 1; //cin >> t;
    while (t --) {
    	solve ();    
    }
	return 0;
}

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, Q;
	cin >> N >> Q;
	int p = 0;
	while (Q--) {
		int t, k;
		cin >> t >> k;
		if (t == 0) {
			printf("%d\n", (p + --k) % N + 1);
		}
		else {
			p = (p + k) % N;
		}
	}
	return 0;
}



Measured memory_bytes: 3240
#提出 #8086687

import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for b in range(n):
  for a in range(b):
    ans += bisect.bisect_left(l,l[a]+l[b])-(b+1)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
vector<int> g[2001];
int d[2001];
int cnt,k,td;
void dfs2(int s,int par,int dt){
    if(dt>td) ++cnt;
    rep(i,g[s].size()){
        if(g[s][i]!=par){
            dfs2(g[s][i],s,dt+1);
        }
    }
}
int main(){
    int n,sr,ds;
    cin>>n>>k;
    rep(i,n-1){
        cin>>sr>>ds;
        --sr,--ds;
        g[sr].pb(ds);
        g[ds].pb(sr);
    }
    int mn=2048;
    if(k%2==1){
        td=(k-1)/2;
        rep(i,n){
            rep(j,g[i].size()){
                cnt=0;
                dfs2(i,g[i][j],0);
                dfs2(g[i][j],i,0);
                mn=min(mn,cnt);
            }
        }
    }
    else{
        td=k/2;
        rep(i,n){
            cnt=0;
            dfs2(i,-1,0);
            mn=min(mn,cnt);
        }
    }
    cout<<mn<<endl;
    return 0;
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

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

    ll D, T, S; cin >> D >> T >> S;
    if(D <= S*T) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a,b,n;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	if (n==1&&a!=b||a>b){
		puts("0");return 0;
	}
	printf("%lld\n",(n-2)*(b-a)+1);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
//	Table is the complete reverse of dp
//	Always think of the pattern (LCM, GCD)
//	Be careful of unsigned
//	double epsilon = FLT_EPSILON;
//	Think of a solution that gets TLE and optimize it

int main()
{
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int *x = new int[n];
    double mul = 1;
    for(int i = 0; i < n; i++)
    {
    	cin >> x[i];
    	if(i < k)
    		mul += log(x[i]);
    }
    for(int i = k; i < n; i++)
    {
    	cout << (mul + log(x[i]) - log(x[i - k]) > mul? "Yes": "No") << endl;
    	mul += log(x[i]) - log(x[i - k]);
    }
}


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

int main(){
  int s;
  cin >> s;
  int answer = 0;
  for(int i = 1; ; i++){
    if(s == 1 || s == 2 || s == 4){
      i += 3;
      answer = i;
      break;
    }
    if(s % 2 == 0){
      s /= 2;
    }
    else{
      s = s * 3 + 1;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
    int a,b;
    double c,d;
    scanf("%d %d",&a,&b);
    c = (double)a*2-(double)b/2;
    d = floor(c);
    if(c == d && 0<=c && a-c>=0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1656
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>T operator()(T&& lhs, T&& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>T operator()(T&& lhs, T&& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min(); 
}

void Main()
{
	std::size_t N, K;
	std::cin >> N >> K;
	std::set<int> set;
	for (auto i : boost::irange(K))
	{
		std::size_t d;
		std::cin >> d;
		for (auto j : boost::irange(d))
		{
			int a;
			std::cin >> a;
			set.emplace(a);
		}
	}
	std::cout << N - set.size() << std::endl;
}

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

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

ll fun(ll x) {
	if (x < 0) return 0;
	int m = x % 4;
	switch (m) {
	case 0:
		return x;
		break;
	case 1:
		return 1;
		break;
	case 2:
		return 1 ^ x;
		break;
	case 3:
		return 0;
		break;
	}
	return 0;
}

int main()
{
	ll A, B;
	cin >> A >> B;
	ll ans = 0;
	cout << (fun(A-1) ^ fun(B)) << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    char ch[n+1];
    int a[n+1], b[n+1], c[n+1], s1=0, s2=0, s3=0;
    long long t=0;
    for (register int i=1; i<=n; i++)
    {
        cin >> ch[i];
        if (ch[i]=='R')
        {
            s1++;
            a[s1]=i;
        }
        if (ch[i]=='G')
        {
            s2++;
            b[s2]=i;
        }
        if (ch[i]=='B')
        {
            s3++;
            c[s3]=i;
        }
    }
    for (register int i=1; i<=s1; i++)
        for (register int j=1; j<=s2; j++)
        {
            int maxx=max(a[i], b[j]), minn=min(a[i], b[j]);
            int dif=maxx-minn;
            t+=s3;
            if (minn-dif>=1)
                if (ch[minn-dif]=='B') t--;
            if (maxx+dif<=n)
                if (ch[maxx+dif]=='B') t--;
            if (dif%2==0)
                if (ch[minn+dif/2]=='B') t--;
        } 
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ini(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long

int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//ll tt;	cin>>tt;	while(tt--)
	{
		ll n,i,minicost;
		cin>>n;
		ll arr[n+1];
		ll dp[n+1];
		ini(dp,0);

		for(i=0;i<n;i++)	cin>>arr[i];
			minicost=0;
		dp[1]=abs(arr[1]-arr[0]);
		for(i=2;i<n;i++)
		{
			dp[i]=min((dp[i-1]+abs(arr[i]-arr[i-1])) , (dp[i-2]+abs(arr[i]-arr[i-2])));
		}

		cout<<dp[n-1];
 	
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  ll n;
  cin>>n;
  int ans=810;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      string s=to_string(i);
      string t=to_string(n/i);
      int a=s.size();
      int b=t.size();
      ans=min(ans,max(a,b));
    }
  }
  cout<<ans<<endl;
}

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

int main(){
	long long int r,d,x;
	cin >>r>>d>>x;
	long long int  ans = x;
	rep(i,10){
		ans = r*ans-d;
		cout <<ans<<endl;
	}
}

Measured memory_bytes: 256
import collections
n = int(input())
a = []
for i in range(n):
    s = input()
    a.append(s)
t = collections.Counter(a)

b = list(set(a))
b.sort()
most_n = max(t.values())
for i in b:
    if t[i] == most_n:
        print(i)

Measured memory_bytes: 44272
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

long func(long long X, int d){
    long long f = 1LL<<(d+1);
    long long g = X%f;
    long long ret = max(0LL, g-(1LL<<d)+1LL);
    X -= g;
    ret += (X/f)*(1LL<<d);
    return ret;
}

int main(){
    long long A, B;
    cin >> A >> B;
    long long ans = 0;
    for(int i=0; i<44; i++){
        long long cnt = func(B, i) - func(max(0LL, A-1), i);
        if(cnt%2)
            ans |= (1LL<<i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  string s; cin >> s;
  if(s.size() == 2){
    cout << s << endl;
  }else{
    swap(s[0], s[2]);
    cout << s << endl;
  }

  return 0;
}


///


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

int main()
{
  int n,x;
  cin >> n >> x;
  
  int a[n+1];
  rep(i,n) cin >> a[i];
  a[n] = x;
  sort(a,a+(n+1));
  
  int dist[n];
  rep(i,n)
  {
    dist[i] = a[i+1] - a[i];
  }
  
  int gc = 0;
  rep(i,n)
  {
    gc = gcd(gc,dist[i]);
  }
  
  cout << gc << endl;
}


Measured memory_bytes: 4292
#include<stdio.h>

int ab(int x){
	if(x<0)return -x;
	return x;
}


int main(){
	int N,M,i,j;
	scanf("%d%d",&N,&M);
	int a[N],b[N],c[M],d[M];
	for(i=0;i<N;i++)scanf("%d%d",&a[i],&b[i]);
	for(i=0;i<M;i++)scanf("%d%d",&c[i],&d[i]);
	for(i=0;i<N;i++){
		int dist;
		int min=1000000000;
		int minj;
		for(j=0;j<M;j++){
			dist=ab(a[i]-c[j])+ab(b[i]-d[j]);
			if(dist<min){
				min=dist;
				minj=j;
			}
		}
		printf("%d\n",minj+1);
	}	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

constexpr double eps = 1e-8;

int main() {
    double d;
    cin >> d;
    double res = 0;
    double y = d;
    while(std::abs(y) > eps) {
        double x = sqrt(d*d - y*y);
        if(y + eps < x) {
            break;
        }
        double tmp = y+x;
        if(x < 1 - eps) {
            for(int i=1; i<=d; ++i) {
                if(abs(y-i) < eps) {
                    tmp = y+1;
                    break;
                }
            }
        }
        res = max(res, tmp);
        y -= 0.00001;
    }
    cout << fixed << setprecision(10) << res << endl;
}


Measured memory_bytes: 3280
def solve():
    from sys import stdin
    f_i = stdin
    n = f_i.readline()
    A = tuple(map(int, f_i.readline().split()))
    m = f_i.readline()
    B = tuple(map(int, f_i.readline().split()))
    if A < B:
        print(1)
    else:
        print(0)

solve()


Measured memory_bytes: 5624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		Long a[] = new Long[n];

		String str[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		Arrays.sort(a, Comparator.reverseOrder());

		long ans = a[0];
		int index = 1;

		for (int i = 1; i < n - 1; i++) {
			ans += a[index];
			//System.out.println(ans + " " + a[index]);
			if (i % 2 == 0)
				index++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 62792
using System;

class Coin{
    static void Main(){
        short a,b,c;
        string[] str=Console.ReadLine().Split(' ');
        a=short.Parse(str[0]);
        b=short.Parse(str[1]);
        c=short.Parse(str[2]);
        if(a+b>=c){
            Console.WriteLine("Yes");
        }else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
import string
digs = string.digits + string.ascii_letters

def int2base(x, base):
    if x < 0:
        sign = -1
    elif x == 0:
        return digs[0]
    else:
        sign = 1
    x *= sign
    digits = []
    while x:
        digits.append(digs[int(x % base)])
        x = int(x / base)
    if sign < 0:
        digits.append('-')
    digits.reverse()
    return ''.join(digits)
a,b = map(int,input().split())

print(len(int2base(a, b)))

Measured memory_bytes: 4084
#include<stdio.h>
#include<string.h>

int main(){
	char ss[2000],out[2000],temp[2000];
	int i,j,k;
	
	while(NULL!=fgets(ss,1999,stdin)){
		j=0;
		for(i=0;i<1800;i++){
			if(ss[i]=='a' && ss[i+1]=='p' && ss[i+2]=='p' && ss[i+3]=='l' && ss[i+4]=='e'){
				out[j]='p';
				out[j+1]='e';
				out[j+2]='a';
				out[j+3]='c';
				out[j+4]='h';
				out[j+5]='@';
				j+=6;
				i+=4;
				continue;
			}
			out[j]=ss[i];
			++j;
		}
		j=0;
		for(i=0;i<1800;i++){
			if(out[i]=='p' && out[i+1]=='e' && out[i+2]=='a' && out[i+3]=='c' && out[i+4]=='h' && out[i+5]!='@'){
				ss[j]='a';
				ss[j+1]='p';
				ss[j+2]='p';
				ss[j+3]='l';
				ss[j+4]='e';
				j+=5;
				i+=4;
				continue;
			}
			ss[j]=out[i];
			++j;
		}
		j=0;
		
		while(0!=ss[j]){
			if(ss[j]=='@'){
				++j;
				continue;
			}
			if(ss[j]=='\n')break;
			printf("%c",ss[j]);
			++j;
		}
		printf("\n");
	}
	return 0;
}

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

using ll = long long;

constexpr ll mod = 998244353;

ll modpow(ll x, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) (res *= x) %= mod;
        (x *= x) %= mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int n; cin >> n;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }

    ll ans = (modpow(2, n) - n - 1 + mod) % mod;
    set<vector<int>> vss;
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j < n; ++j) {
            vector<int> vs;
            for(int k = 0; k < n; ++k) {
                const int dx1 = x[j] - x[i], dx2 = x[k] - x[i];
                const int dy1 = y[j] - y[i], dy2 = y[k] - y[i];
                if(dx1 * dy2 - dx2 * dy1 == 0) {
                    vs.push_back(k);
                }
            }
            if(vss.count(vs)) continue;
            ans = (ans - modpow(2, vs.size()) + vs.size() + 1 + mod) % mod;
            vss.insert(move(vs));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2048
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	cnt := 0
	for i := 0; i <= n; i++ {
		if int(math.Log10(float64(i))+1)%2 == 1 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

ll solve(ll n){
  ll x = ((n+1)/2)%2;
  if(n%2==0) x = x^n;
  return x;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    cout<<(solve(max(a-1,(ll)0)) ^ solve(b))<<endl;
}


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

using namespace std;

typedef long long ll;

#define MOD 1000000007
#define MAXN 2000200

vector<ll> primes;

void mount_sieve(vector<bool>& sieve) {
	sieve[0] = sieve[1] = false;
	for (ll i = 2; i < MAXN; i++) {
		if (sieve[i]) {
			primes.push_back(i);
			ll x = i * i;
			while (x < MAXN) {
				sieve[x] = false;
				x += i;
			}
		}
	}
}

ll mod_pow(ll num, ll pot) {
	if (pot == 0) return 1;
	if (pot % 2 == 0) {
		ll x = mod_pow(num, pot / 2);
		x *= x;
		x %= MOD;
		return x;
	} else {
		ll x = mod_pow(num, pot - 1);
		x *= num;
		x %= MOD;
		return x;
	}
}

ll calc(ll a, ll b) {
	vector<int> factors(primes.size(), 0);
	ll target = a + b;
	for (int i = 0; i < primes.size(); i++) {
		ll prime = primes[i];
		while (prime <= target) {
			factors[i] += target / prime;
			prime *= primes[i];
		}
	}
	target = a;
	for (int i = 0; i < primes.size(); i++) {
		ll prime = primes[i];
		while (prime <= target) {
			factors[i] -= target / prime;
			prime *= primes[i];
		}
	}
	target = b;
	for (int i = 0; i < primes.size(); i++) {
		ll prime = primes[i];
		while (prime <= target) {
			factors[i] -= target / prime;
			prime *= primes[i];
		}
	}
	ll ret = 1;
	for (int i = 0; i < (int)factors.size(); i++) {
		ret *= mod_pow(primes[i], factors[i]);
		ret %= MOD;
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	vector<bool> sieve(MAXN, true);
	mount_sieve(sieve);
	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	ll a = calc(r2 + 1, c2 + 1);
	ll b = calc(r1, c1);
	ll c = calc(r2+1, c1);
	ll d = calc(r1, c2+1);
	ll ans = (a + b) % MOD - (c + d) % MOD;
	ans += MOD;
	ans %= MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2676
n, k = map(int, input().split())
a = [i-1 for i in map(int, input().split())]

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    if middle==0:
        left=1
        break
    count = 0
    for i in a:
        count += i//middle
    
    if count <= k:
        right = middle
    else:
        left = middle + 1

print(left)

Measured memory_bytes: 104524
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = stdIn.nextInt();
        }
        stdIn.close();

        Set<Integer> H = new HashSet<>();
        for (int i = 0; i < N; i++) {
            H.add(A[i]);
        }

        if (H.size() == A.length) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 71900
from collections import deque
S = input()
d = deque()
for s in S:
  if len(d) == 0:
    d.append(s)
  elif s == "T":
    d.pop() if d[-1] == "S" else d.append(s)
  elif s == "S":
    d.append(s)
print(len(d))

Measured memory_bytes: 5092
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    long long int a,b,c,n,ans;
    ans = 0;
    cin >> n;
    int d[n];
    for(int i=0;i<n;i++)cin >> d[i];
    sort(d,d+n);
    int l = n/2 - 1;
    int r = n/2;
    ans = d[r] - d[l];

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


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd


string solve(int k, int n)
{
    if (!n) return "0";
    string ret = "";
    int mod = abs(k);
    while (n) {
        int m = (n % mod + mod) % mod;
        //cout << n << " " << m << endl;
        ret += m+'0';
        n = (n - m) / k;
    }
    reverse(all(ret));
    return ret;
}

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

    Int(n);

    cout << solve(-2, n) << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e18;

int main(){
    vector<ll> a(3);
    rep(i,3){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    vector<bool> b(3);
    rep(i,3){
        if((a[i]-a[(i+1)%3])%2==0){
            b[i]=true;
        }
    }
    if(b[0] && b[1] && b[2]){
        cout << (2*a[2]-a[0]-a[1])/2 << endl;
        return 0;
    }
    if(b[0]){
        cout << (2*a[2]-a[0]-a[1]-2)/2+1 << endl;
        return 0;
    }
    cout << (2*a[2]-a[0]-a[1]+1)/2+1 << endl;
} 

Measured memory_bytes: 256
let HWM = readLine()!.split(separator: " ").compactMap { Int($0) }
let H = HWM[0]
let W = HWM[1]
let M = HWM[2]
let list: [(Int, Int)] = (1...M)
    .map { _ in
        let tmp = readLine()!.split(separator: " ").compactMap { Int($0) }
        return (tmp[0]-1, tmp[1]-1)
    }

var hCounts = Array(repeating: 0, count: H)
var wCounts = Array(repeating: 0, count: W)
var indexes = [String: Bool]()
list.forEach {
    hCounts[$0.0] += 1
    wCounts[$0.1] += 1
    indexes["\($0.0),\($0.1)"] = true
}
let hMax = hCounts.max()!
let wMax = wCounts.max()!

var hMaxIndexes = [Int]()
for i in 0..<hCounts.count {
    if hCounts[i] == hMax {
        hMaxIndexes.append(i)
    }
}
var wMaxIndexes = [Int]()
for i in 0..<wCounts.count {
    if wCounts[i] == wMax {
        wMaxIndexes.append(i)
    }
}

var isExist = false
for i in hMaxIndexes {
    for j in wMaxIndexes {
        if indexes["\(i),\(j)"] != true {
            isExist = true
            break
        }
    }
}

print(isExist ? hMax+wMax : hMax+wMax-1)


Measured memory_bytes: 35364
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a+b>=a-b&&a+b>=a*b)
    cout << a+b << endl;
  else if (a-b>=a+b&&a-b>=a*b)
    cout << a-b << endl;
  else if (a*b>=a+b&&a*b>=a-b)
    cout << a*b << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = pow(10, 5) + 1;//+1しないとREになる(out of rangeになるんかな?? )

int main(void) {
	int N, M;
	cin >> N >> M;
	VVI node(N, vector<int>());
	//↑node[i][j]はノードiとつながっているノード
	//つまり存在するjの個数(node[i].size()が
	//ノードiがと繋がっているノードの個数となる

	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		node[a].push_back(b);
		node[b].push_back(a);
	}

	vector<int> perm(N);//0からはじまり 2番目の数字以降は1~N-1の順列
	perm[0] = 0; //必ずノード0から開始するので最初は0
	for (int i = 1; i < N; i++) perm[i] = i;
	
	
	int ans = 0;
	do {
		//for (int i = 0; i < N; i++) cout << perm[i] << " ";
		//cout << endl;
		
		bool is_goal = true;
		for (int i = 0; i < N-1; i++) {
			int now_node = perm[i];
			int next_node = perm[i + 1];
			for (int j = 0; j < node[now_node].size(); j++) {
				if (node[now_node][j] == next_node) break;
				if (j == node[now_node].size() - 1) {
					is_goal = false; //now_nodeとnext_nodeがつながっていない
				}
			}
		}
		if (is_goal == true) ans++;
	} while (next_permutation(perm.begin()+1, perm.end()));
	//↑最初の数字は0からはじまり，　2番目以降を順列に並べる

	cout << ans << endl;
}	


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b&&b==c){
        cout << 1 << endl;
    }else if(a==b&&b!=c || a==c&&c!=b || b==c&&c!=a){
        cout << 2 << endl;
    }else{
        cout << 3 << endl;
    }
}

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

const int INF = 1<<21;
map<string, int> value;
map<string, vector<string> > R;

int rec(string s) {
  int res = INF;
  if(value.find(s) != value.end()) res = min(res, value[s]);
  if(R.find(s) != R.end()) {
    int sum = 0;
    for(vector<string>::iterator it = R[s].begin(); it != R[s].end(); it++) {
      sum += rec(*it);
    }
    res = min(res, sum);
  }
  return res;
}

main() {
  int n;
  while((cin >> n) && n) {
    value.clear();
    R.clear();
    while(n--) {
      string s;
      int a;
      cin >> s >> a;
      value[s] = a;
    }
    cin >> n;
    while(n--) {
      string s;
      int m;
      cin >> s >> m;
      while(m--) {
	string t;
	cin >> t;
	R[s].push_back(t);
      }
    }
    string s;
    cin >> s;
    cout << rec(s) << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    // 単語ベクトルを形成する
    // 26文字で表現できるので強いかもしれない
    map<string, ll> ans;
    rep(i,n){
        string s;
        cin >> s;
        vector<int> v(30);
        for(auto i:s){
            v[i-'a']++;
        }
        string t = "";
        for(auto i:v)
        {
            if(i==10){
                t+="a";
            }
            else{
                t+=to_string(i);
            }
        }
        ans[t]++;
    }
    ll res = 0;
    for(auto i:ans){
        res += ((i.second-1)*i.second)/2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 14336
// 1_6_B
#include<stdio.h>

int main(void)
{
	int foundCards[4][13] = {};
	int n, i, rank, j;
	char suit;

	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%s %d", &suit, &rank);
		if(suit == 'S'){
			foundCards[0][rank-1] = 1;
		}else if(suit == 'H'){
			foundCards[1][rank-1] = 1;
		}else if(suit == 'C'){
			foundCards[2][rank-1] = 1;
		}else if(suit == 'D'){
			foundCards[3][rank-1] = 1;
		}
	}

	for(i = 0; i < 4; i++){
		for(j = 0; j < 13; j++){
			if(!foundCards[i][j]){
				printf("%c %d\n", "SHCD"[i],j+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    H, W, M = map(int, input().split())
    h = [0] * H
    w = [0] * W
    hw = set()
    for i in range(M):
        tmph, tmpw = map(lambda x: int(x)-1, input().split())
        h[tmph] += 1
        w[tmpw] += 1
        hw.add((tmph,tmpw))
    # 最大値より1だけ小さくなる物が候補
    HMAX = max(h)
    h0 = []
    for i in range(H):
        if h[i] == HMAX:
            h0.append(i)

    WMAX = max(w)
    w0 = []
    for i in range(W):
        if w[i] == WMAX:
            w0.append(i)

    ans = 0
    for i in h0:
        for j in w0:
            if (i,j) not in hw:
                print(HMAX+WMAX)
                exit()
    print(HMAX+WMAX-1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 166428
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <math.h>
#define rep(i, start, end) for (int i = start; i < end; ++i)
using namespace std;
typedef long long ll;

string S;

int main() {
   cin >> S;

   if (S == "Sunny") cout << "Cloudy" << endl;
   if (S == "Cloudy") cout << "Rainy" << endl;
   if (S == "Rainy") cout << "Sunny" << endl;

   return 0;
}

Measured memory_bytes: 256
/**
  *  Author: dhruv_gheewala
  *  Problem: E - Dist Max
  *  Date:   19.09.2020
  *  Time:   10:48:19
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;
    
    #define fundri 108
    #define debug(...) 1729
#endif

#define int int64_t
typedef pair<int, int> pii;
typedef vector<int> vi;

const bool testcases = false;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(), s.end()

// if vector isn't soted then it will remove consecutive same elements
#define make_unique(vec) vec.erase(unique(all(vec)), vec.end())
#define test int TC = 1;if(testcases)cin >> TC;for(int tc = 1 ; tc <= TC ; tc++)solve(), fundri
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})
// clears stdin
#define flush(ch) cin.ignore(std::numeric_limits<std::streamsize>::max(), ch) // default, EOF

int seed; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);}

inline bool in_range(int a, int l, int r) {return (a >= l && a <= r);}
template<typename H, typename ...T>void inp(H &head) {cin >> head;}
template<typename H, typename ...T>void inp(H &head, T &...tail) {cin >> head;inp(tail...);}
template<typename T>bool isPrime(T n) {for(T i = 2; i * i <= n; i++)if(n % i == 0)return false; return n >= 2;}
template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(T &x : a)in >> x; return in;}
template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.ff >> a.ss; return in;}

void solve();
void fast_io();

int32_t main(int32_t argc, char **argv)
{
    fast_io();
    test;
    return 0;
}

void solve()
{
    int n;
    cin >> n;
    vector<pii> a(n);
    cin >> a;

    vi plus, minus;
    for(int i = 0 ; i < n ; i++) {
    	plus.emplace_back(a[i].ff + a[i].ss);
    	minus.emplace_back(a[i].ff - a[i].ss);
    }

    sort(all(plus));
    sort(all(minus));

    int ans = plus.back() - plus[0];  // xj + yj - xi - yi
    ans = max(ans, minus.back() - minus[0]);  // xj - yj - xi + yi
    cout << ans << endl;
}

void fast_io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef DHRUV_GHEEWALA
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
}

Measured memory_bytes: 9860
import kotlin.math.sqrt

fun solver(a: String, b: String): String {
    val num = (a + b).toInt()

    val value = sqrt(num.toDouble())

    return if (value - value.toInt().toDouble() == 0.0) {
        "Yes"
    } else {
        "No"
    }
}

fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ")

    //val (a, b) = Pair("1", "21")

    val result = solver(a = a, b = b)

    println(result)
}


Measured memory_bytes: 35568
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}

#define REP(i,s,n) for(int i=s; (n-i)*sign(n-s)>0; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1'000'000'000+7)

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

ll dp[100001][101];

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N+1);
    REP(i, 0, N) {
        cin >> a[i+1];
    }

    int suma = 0;
    REP(j, 1, N+1) {
        suma += a[j];
        dp[0][j] = 1;
        REP(i, 1, min(suma+1, K+1)) {
            dp[i][j] = (dp[i-1][j] + (i-a[j]-1>=0?MOD-dp[i-a[j]-1][j-1]:0) + dp[i][j-1])%MOD;
        }
    }
    
    cout << dp[K][N] << endl;
}


Measured memory_bytes: 79104
import sys
input = sys.stdin.readline

p = int(input())
a = [int(i) for i in input().split()]

ans = [0]*p

for i,j in enumerate(a):
    if j == 0:
        continue
    ans[0] -= p-1
    m = 1
    for k in range(p):
        ans[p-1-k] -= m
        ans[p-1-k] %= p
        m *= i
        m %= p

print(*ans)


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

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;
	int count = 0;

	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i])count++;
	}
	cout << count << endl;

    return 0;
}

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

using namespace std;

const int INF = 1e9 + 1;
int n, a, dp[100001];

int main() {    
    ios::sync_with_stdio(false);
    
    cin >> n;
    for (int i=0; i<n; ++i) dp[i] = INF;

    for (int i=0; i<n; ++i) {
        cin >> a;
        *lower_bound(dp, dp+n, a) = a;
    }

    cout << lower_bound(dp, dp+n, INF) - dp << endl;
    
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

// 柵にも幅を1持たせる
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
    int n, m;
    cin >> n >> m;
    int a[n], b[n], c[n], d[m], e[m], f[m];
    vector<int> u,v;
    rep(i,n){
        cin >> a[i] >> b[i] >> c[i];
        a[i] *= 2; b[i] *= 2; c[i] *= 2;
        u.push_back(a[i]);
        u.push_back(b[i]);
        v.push_back(c[i]);
    }
    rep(i,m){
        cin >> d[i] >> e[i] >> f[i];
        d[i] *= 2; e[i] *= 2; f[i] *= 2;
        u.push_back(d[i]);
        v.push_back(e[i]);
        v.push_back(f[i]);
    }

    sort(u.begin(), u.end());
    u.erase(unique(u.begin(), u.end()), u.end());
    int num = u.size();
    u.push_back(u[0]-1);
    rep(i,num){
        u.push_back(u[i]+1);
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    num = v.size();
    v.push_back(v[0]-1);
    rep(i,num){
        v.push_back(v[i]+1);
    }

    sort(u.begin(), u.end());
    sort(v.begin(), v.end());

    int h = u.size();
    int w = v.size();
    int g[h][w];
    rep(i,h)rep(j,w)g[i][j] = 0;
    
    rep(i,n){
        int x1 = lower_bound(u.begin(),u.end(),a[i]) - u.begin();
        int x2 = lower_bound(u.begin(), u.end(), b[i]) - u.begin();
        int y = lower_bound(v.begin(), v.end(), c[i]) - v.begin();
        srep(j,x1,x2+1) g[j][y] = 1;
    }
    rep(i,m){
        int x = lower_bound(u.begin(),u.end(),d[i]) - u.begin();
        int y1 = lower_bound(v.begin(), v.end(), e[i]) - v.begin();
        int y2 = lower_bound(v.begin(), v.end(), f[i]) - v.begin();
        srep(j,y1,y2+1) g[x][j] = 1;
    }

    int sx = lower_bound(u.begin(), u.end(), 0) - u.begin();
    if(u[sx]%2==0)sx--;
    int sy = lower_bound(v.begin(),v.end(),0) - v.begin();
    if(v[sy]%2==0)sy--;

    g[sx][sy] = 2;
    if(sx == 0 || sx == h-1 || sy == 0 || sy == w-1){
        cout << "INF" << endl;
        return 0;
    }

    queue<P> que;
    que.push(P(sx, sy));
    while(que.size()>0){
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        rep(i,4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx == 0 || nx == h-1 || ny == 0 || ny == w-1){
                cout << "INF" << endl;
                return 0;
            }
            if(g[nx][ny] == 0){
                g[nx][ny] = 2;
                que.push(P(nx,ny));
            }
        }
    }

    ll ans = 0;
    rep(i,h){
        rep(j,w){
            // cout << g[i][j];
            if(g[i][j] == 2 && i % 2 == 0 && j % 2 == 0){
                ll x1 = u[i-1], x2 = u[i+1];
                ll y1 = v[j-1], y2 = v[j+1];
                ans += (x2-x1)/2 * (y2-y1)/2;
            }
        }
        // cout << endl;
    }

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




Measured memory_bytes: 144328
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int[] x = new int[m];
		int[] y = new int[m];

		int[] c = new int[n];
		boolean[] p = new boolean[n];
		Arrays.fill(c, 1);
		p[0] = true;
		for( int i=0 ; i<m ; i++ ) {
			int f = sc.nextInt()-1;
			int t = sc.nextInt()-1;
			x[i] = f;
			y[i] = t;
			
			p[t] |= p[f];
			if ( c[f] == 1 ) {
				p[f] = false;
			}
			c[f]--;
			c[t]++;
		}
		
		int r =0;
		for( int i=0 ; i<n ;i++ ) {
			if(p[i])r++;
		}
		
		System.out.println(r);
		
		
	}

}


Measured memory_bytes: 69068
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let n: usize = buf.trim().parse().unwrap();

    let mut sum: f64 = 0.0;
    for _ in 0..n {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        let x: f64 = iter.next().unwrap().parse().unwrap();
        let u = iter.next().unwrap().trim();

        sum += if u == "JPY" {
            x
        }
        else {
            x * 380000.0
        }
    }

    println!("{}", sum);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using number = int;
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 




number A, B; string op;
//---------------------------------------------------------------------------------------------------
void _main() {
    int a, b; cin >> a >> op >> b;
    A = a;
    B = b;
    number ans;
    if (op == "+") ans = A + B;
    else ans = A - B;
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n,m,R = myinput()
r = list(myinput())
abc = mylistinput(m)

d = [[float("inf")]*n for i in range(n)] 
# d[u][v]: 辺uvのコスト(存在しないときはinf)

for i in range(m):
    a = abc[i][0] - 1
    b = abc[i][1] - 1
    c = abc[i][2]
    d[a][b] = c
    d[b][a] = c

#自身のところに行くコストは０
for i in range(n):
    d[i][i] = 0 

# ワーシャルフロイド（warshall_floyd）法
# d[u][v]: 辺uvのコスト(存在しないときはinf)
def warshall_floyd(n,d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

d = warshall_floyd(n,d)
# print(d)

rp = list(permutations(r))
# print(rp)

ls_count = []
for i in rp:
    count = 0
    for j in range(len(i)-1):
        s = i[j] - 1
        t = i[j+1] - 1
        count += d[s][t]
    ls_count.append(count)
# print(ls_count)

ans = min(ls_count)
print(ans)

Measured memory_bytes: 65880
#include <iostream>

int main()
{
  char ch;
  std::cin >> ch;
  char result;
  switch (ch) {
    case 'A':
      result = 'T';
      break;
    case 'C':
      result = 'G';
      break;
    case 'G':
      result = 'C';
      break;
    case 'T':
      result = 'A';
      break;
  }
  std::cout << result << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[1002][1002];
long long dp[1002][1002];
long long mod= 1000000007;
int m,n;
long long c=0;
long long solve(int x,int y)
{
    if(x==m && y==n)
    return 1;
    if(x>m || y>n)
    return 0;
    if(dp[x][y]!=-1)
    return dp[x][y];
    long long right=0;
    long long down=0;
    if(a[x][y]=='#')
    return 0;
    else
    {
    right = solve(x,y+1);
    down = solve(x+1,y);
    return dp[x][y]=(right+down)%mod;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>m>>n;
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            cin>>a[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
    cout<<solve(1,1)%mod;
}

Measured memory_bytes: 9216
/*input
5
1 2 3 4 5
*/
fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_
}

fn main() {
    read_line();
    let mut v: Vec<u16> = read_line()
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    v.reverse();
    for i in 0..v.len() {
        print!("{}", v[i]);
        if i != v.len() - 1 {
            print!(" ");
        }
    }
    print!("\n");
}



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

int main(){
  int a, b, c, d;
  cin>>a>>b>>c>>d;
//  cout<<a<<" "<<b<<" "<<c<<" ";
  if( abs(c-a) <= d ){
    cout<<"Yes";
  }else if( abs(b-a) <= d && abs(c-b) <= d){
    cout<<"Yes";
  }else{
    cout<<"No";
  }

}


Measured memory_bytes: 256
N = int(input())
S = str(input())
S = list(S)
R = S.count("R")
G = S.count("G")
B = S.count("B")
count = R*G*B
double = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        k = 2*j-i
        if k < N:
            s = set([S[i],S[j],S[k]])
            if len(s) == 3:
                count -= 1
print(count)

Measured memory_bytes: 68548
import heapq as hq
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

def main():
    n,q = nm()
    tl = []
    ins = list()
    dlt = list()
    vv = [tuple(nm()) for _ in range(n)]
    tl = [(s-x, 1, x) for s, _, x in vv]
    tl.extend([(t-x, 0, x) for _, t, x in vv])
    ww = [ni() for _ in range(q)]
    tl.extend([(t, 2) for t in ww])
    tl.sort()

    for x in tl:
        if x[1] == 1:
            hq.heappush(ins, x[2])
        elif x[1] == 0:
            hq.heappush(dlt, x[2])
            while dlt and ins[0] == dlt[0]:
                hq.heappop(ins)
                hq.heappop(dlt)
        else:
            print(-1 if not ins else ins[0])
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 109140