akhauriyash/Code-Regression huggingface dataset:
N, Y = map(int, input().split())

man = gosen= sen = -1

for i in range(N+1):
    for j in range(N+1-i):
        k=N-i-j
        if i*10000+j*5000+k*1000==Y:
            man=i
            gosen=j
            sen=k

print(man, gosen, sen)
            

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    int n,a[20],b[20],c[19],g=0,i;
    scanf("%d", &n);
    for(i=0; i<n; i++)
    scanf("%d", &a[i]);
    for(i=0; i<n; i++)
    scanf("%d", &b[i]);
    for(i=0; i<n-1; i++)
    scanf("%d", &c[i]);
    for(i=0; i<n; i++)
    {
        g+=b[i];
        if(i>0&&a[i-1]+1==a[i])
        g+=c[a[i-1]-1];
    }
    printf("%d\n", g);
    
    return 0;
}

Measured memory_bytes: 128
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

result = min(a)+min(b)

for _ in range(M):
    x, y, c = map(int, input().split())
    result = min(result, a[x-1]+b[y-1]-c)

print(result)

Measured memory_bytes: 18736
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;

import java.util.Scanner;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            switch(s) {
            case "insert":
                map.put(sc.next(), "");
                break;
            case "find":
                if (map.containsKey(sc.next())) {
                    System.out.println("yes");
                } else {
                    System.out.println("no");
                }
                break;
            }
        }
    }
}

Measured memory_bytes: 260624
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,K;
  cin >> N >> K;
  vi cnt(N,0);
  rep(i,K) {
    int d;
    cin >> d;
    rep(j,d) {
      int x;
      cin >> x;
      x--;
      cnt[x]++;
    }
  }
  int ans = 0;
  rep(i,N) {
    if(cnt[i]==0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int a,b,x,y,z,cnt;
	scanf("%d %d",&a,&b);
	while(a!=0 && b!=0) {
		cnt=0;
		if(a>=b) {
			x=a;
			y=b;
		}
		else {
			x=b;
			y=a;
		}
		while(y!=0) {
			z=x%y;
			x=y;
			y=z;
			cnt++;
		}
		printf("%d %d\n",x,cnt);
	scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
int main(){
    ll n; cin >> n;
    vector<ll> a(3), b(3);
    rep(i,3)cin >> a[i];
    rep(i,3)cin >> b[i];
    vector<ll> dp(n+1,0);
    rep(i,3){
        rep(j,n+1){
            if(j >= a[i])chmax(dp[j], dp[j - a[i]] + b[i] - a[i]);
        }
    }
    ll m = dp[n] + n;
    vector<ll> dp2(m+1,0);
    rep(i,3){
        rep(j,m+1){
            if(j >= b[i])chmax(dp2[j], dp2[j - b[i]] + a[i] - b[i]);
        }
    }

    cout << m + dp2[m] << endl;
}

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

using namespace std;
 
int main() {

	long long int a,b,c,d;
	cin>>a>>b>>c>>d;

	long long int ans;

	ans = max(a*c, max(a*d, max(b*c, b*d)));

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

// http://drken1215.hatenablog.com/entry/2018/06/08/210000

const int MAX = 2123456;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll sum(int x, int y)
{
    if ((ll)x * y == 0)
        return 0;
    ll res = 0;
    for (int i = 1; i <= y; i++)
    {
        res += COM(i + 1 + x, x);
        res += MOD - COM(i, 0);
        res %= MOD;
    }
    return res;
}

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

    COMinit();

    int r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    ll res = sum(r2, c2);
    res += MOD - sum(r1 - 1, c2);
    res += MOD - sum(r2, c1 - 1);
    res += sum(r1 - 1, c1 - 1);
    res %= MOD;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 50048
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m,q;
	cin>>n>>m>>q;
	vs in(n+1);
	in[0]=string(m+1,'0');
	rep(i,n){
		cin>>in[i+1];
		in[i+1]='0'+in[i+1];
	}
	vvi dp(n+1,vi(m+1));
	vvi dph(n+1,vi(m+1));
	vvi dpw(n+1,vi(m+1));
	rep(i,n)rep(j,m){
		if(in[i+1][j+1]=='1')dp[i+1][j+1]=1;
		if(in[i+1][j+1]=='1'&&in[i][j+1]=='1')dph[i+1][j+1]++;
		if(in[i+1][j+1]=='1'&&in[i+1][j]=='1')dpw[i+1][j+1]++;
	}
	rep(i,n)rep(j,m){
		dp[i+1][j+1]+=dp[i][j+1]+dp[i+1][j]-dp[i][j];
		dph[i+1][j+1]+=dph[i][j+1]+dph[i+1][j]-dph[i][j];
		dpw[i+1][j+1]+=dpw[i][j+1]+dpw[i+1][j]-dpw[i][j];
	}
	while(q--){
		int a,b,c,d;cin>>a>>b>>c>>d;a--;b--;
		int s=dp[c][d]-dp[a][d]-dp[c][b]+dp[a][b];
		int t=dph[c][d]-dph[a+1][d]-dph[c][b]+dph[a+1][b];
		int r=dpw[c][d]-dpw[a][d]-dpw[c][b+1]+dpw[a][b+1];
		cout<<s-t-r<<endl;
	}
}










Measured memory_bytes: 52992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int H, W;
string s[55];
int b[55][55];
int dy[] = {1, 0, -1, 0}, dx[] = {0, 1, 0, -1};

int main() {
	cin >> H >> W;
	rep(i, H) cin >> s[i];
	rep(i, 55)rep(j, 55) b[i][j] = -1;
	b[0][0] = 0;
	queue<tuple<int, int, int>> q;
	q.push(make_tuple(0, 0, 0));
	while(!q.empty()) {
		int y, x, d;
		tie(y, x, d) = q.front(); q.pop();
		rep(k, 4) {
			int ny = y + dy[k], nx = x + dx[k];
			if(!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue;
			if(s[ny][nx] == '#') continue;
			if(b[ny][nx] != -1) continue;
			b[ny][nx] = d + 1;
			q.push(make_tuple(ny, nx, d + 1));
		}
	}

	if(b[H - 1][W - 1] == -1) {
		printf("-1\n");
		return 0;
	}

	ll cnt = 0;
	rep(i, H)rep(j, W) {
		if(s[i][j] == '.') cnt++;
	}

	printf("%lld\n", cnt - b[H - 1][W - 1] - 1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n;
    while(cin >> n && n){
        int cubic = n*n*n;
        int ret= 1 << 29;
        int ub = 1111,lb=1;
        int maxi = 1111;

        for(int i=1;i<=maxi;i++){
            ub = 1111;
            lb = 1;
            while(ub - lb > 1){
                int mid = (ub + lb) / 2;
                if(i*i*i + mid*mid*mid <= cubic){
                    lb = mid;
                }else{
                    ub = mid;
                }
            }
            maxi = lb;
            ret = min(ret, cubic - i*i*i - lb*lb*lb);
        }
        cout << ret << endl;
    }
}

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

int n,k;
vector<long long> x;
int main(){
  cin >> n >> k;
  x.resize(n);
  for(auto &i:x) cin >> i;
  long long res = 1LL<<60;
  for(int i=0;i+k-1<n;i++){
    long long left = x[i],right = x[i+k-1];
    res = min(res,min(abs(left),abs(right))+right-left);
  }
  cout << res << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;

#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

const int MAX_N = 100'000;
int N, M;
int Q;
int dp[MAX_N][11];

int main(void) {
	cin >> N >> M;
	struct Edge {
		int a, b;
	};
	vector<Edge> edges(M);
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		edges[i] = { a , b };
	}

	const int MAX_DP = 1'000'000;
	REP(i, N) REP(j, 11) {
		dp[i][j] = 1'000'000;
	}
	cin >> Q;
	struct Query {
		int v, d, c;
	};
	vector<Query> queries(Q);
	REP(i, Q) {
		int v, d, c;
		cin >> v >> d >> c;
		v--;
		queries[Q - 1 - i] = { v, d, c };

		for(int td = d; td >= 0; td--) {
			dp[v][td] = Q - 1 - i;
		}
	}
	for (int d = 10; d > 0; d--) {
		for (int i = 0; i < M; i++) {
			dp[edges[i].a][d - 1] = min(dp[edges[i].a][d - 1], dp[edges[i].b][d]);
			dp[edges[i].b][d - 1] = min(dp[edges[i].b][d - 1], dp[edges[i].a][d]);
		}
	}
	REP(i, N) {
		if (dp[i][0] == MAX_DP) {
			cout << 0 << endl;
		}
		else {
			cout << queries[dp[i][0]].c << endl;
		}
	}
	return 0;
}

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(m);
  int i=0;
  rep(i,m)cin>>a[i];
  int s1=0;
  rep(i,m)s1+=a[i];
  if(n-s1>=0)cout<<n-s1;
  else cout<<-1;
  return 0;
}

Measured memory_bytes: 3664
import math
N, D = (int(i) for i in input().split())
protList = []
intCounter = 0
for i in range(N):
    oneProt = list(int(i) for i in input().split())
    protList.append(oneProt)

for i in range(len(protList)):
    for j in range(i + 1, len(protList)):
        sqSum = 0
        for k in range(len(protList[i])):
            sqSum += (protList[i][k] - protList[j][k]) ** 2 
        if math.sqrt(sqSum).is_integer():
            intCounter += 1
            
print(intCounter)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

ll NcR(ll n, ll r) 
{ 
	ll p = 1, k = 1; 
	if (n - r < r) 
		r = n - r; 

	if (r != 0) { 
		while (r) { 
			p *= n; 
			k *= r; 
			ll m = __gcd(p, k); 
			p /= m; 
			k /= m; 

			n--; 
			r--; 
		}
	} 

	else
		p = 1; 

	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,a,b;
	cin>>n>>a>>b;
	ll v[n];
	long double h=0.0,g;
	for(int i = 0;i<n; i++)
		cin>>v[i];
	sort(v,v+n, greater<ll>());
	ll ans = 0,ways=1,aw = 0;
	vector<ll> c;
	set<ll>s;
	for(int i= 0; i<b; i++)
	{
		c.push_back(v[i]);
		s.insert(v[i]);
		if(i<a-1)
			ans += v[i];
		else
		{
			ans += v[i];
			g = ((long double)ans)/(i+1);
			ways = 1;
			for(auto it:s)
			{
				ll g2 = count(c.begin(),c.end(),it);
				ll y = count(v,v+n,it);
				// cout<<g2<<" "<<y<<" ";
				if(g2!=y)
					ways *= NcR(y,g2);
				// cout<<ways<<endl;
			}
			if(g==h) aw = aw+ways;
			if(g>h)
			{
				aw = ways;
				h = g;
			}
		}
	}
	cout<<fixed<<setprecision(6)<<h<<endl;
	cout<<aw<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define debug(x) {cerr<<#x<<" = "<<(x)<<endl;}
#define M(x) memset(x,0,sizeof(x))
#define dalao main
using namespace std;
int same(string x,string y)
{
    int sum=0;
    for(int i=0;i<x.size();i++)
        sum+=(x[i]==y[i]);
    return sum;
}
int dalao()
{
    string s,t;//let t be substring of s
    cin>>s>>t;
    int ls=s.size(),lt=t.size();
    int ans=lt;
    for(int i=0;i+lt<=ls;i++)
    {
        string sub=s.substr(i,lt);
        ans=min(ans,lt-same(sub,t));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for i in range(Q)]
ans = 0

for x in combinations_with_replacement(range(M), N):
    temp = 0
    for i in range(Q):
        if x[ABCD[i][1]-1]+1 == x[ABCD[i][0]-1]+1 + ABCD[i][2]:
            temp += ABCD[i][3]
    if temp > ans:
        ans = temp
print(ans)

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

using namespace std;

vector<bool> isPrime;
vector<int> primes;

void SieveOfEratosthenes(int n) {
  isPrime = vector<bool>(n, true);
  isPrime[0] = false;
  isPrime[1] = false;

  for (int i = 2; i < n; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j < n; j += i) {
        isPrime[j] = false;
      }
      primes.push_back(i);
    }
  }
}

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

  SieveOfEratosthenes(100100);
  for (int i = X; i < 100100; i++) {
    if (isPrime[i]) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 384
#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<vector<int> > Graph;
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; }

ll con[210000];
int main() {
    int n;
    while (cin >> n) {
        memset(con, 0, sizeof(con));
        for (int i = 0;i < n; ++i) {
            int a;
            cin >> a;
            con[a+1]++;
        }
        
        long long res = 0;
        for (int i = 1; i <= 100000; ++i) {
            res = max(res, con[i-1] + con[i] + con[i+1]);
        }
        
        cout << res << endl;
    }
}
 

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define nl "\n"
#define fat 1000000007

int main()
{
    boost
    int n, x, y;
    cin >> n >> x >> y;

    vi d(n, 0);

    for(int j = 1; j <= n; j++)
    {
        ll ans = 0;
        for(int i = j + 1; i <= n; i++)
        {
            int dist = i - j;
            int dist2 = abs(j - x) + 1 + abs(y - i);
            
            d[min(dist, dist2)]++;
        }
    }

    for(int i = 1; i < n; i++) cout << d[i] << nl;

    return 0;
}

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

using namespace std;

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

	if(n == 1) {
		cout << "No" << '\n';
		exit(0);
	}

	int t = 1;
	while(t * 2 <= n + 1) {
		t = t * 2;
	}

	int Xor = 0;
	for(int i = t; i <= n; ++i) {
		Xor ^= i;
	}

	int cnt = 0;
	for(int i = t; i <= n; ++i) {
		if(i & t) {
			cnt += 1;
		}
	}

	if(cnt % 2 == 0) {
		cout << "Yes" << '\n';
		for(int i = 1; i < t - 1; ++i) {
			cout << i << ' ' << i + 1 << '\n';
		}

		cout << t - 1 << ' ' << 1 + n << '\n';
	
		for(int i = 1; i < t - 1; ++i) {
			cout << i + n << ' ' << i + n + 1 << '\n';
		}

		for(int i = t; i < n; ++i) {
			cout << i << ' ' << i + 1 << '\n';
		}

		if(Xor != 0) {
			cout << n << ' ' << Xor << '\n';
			cout << Xor << ' ' << t + n << '\n';
		} else if(n > t) {
			cout << n << ' ' << 1 << '\n';
			cout << n << ' ' << t + n << '\n';
		}
	
		for(int i = t; i < n; ++i) {
			cout << i + n << ' ' << i + n + 1 << '\n';
		}
	} else {
		if(cnt == 1) {
			cout << "No" << '\n';
		} else {
			cout << "Yes" << '\n';
			int Xor = 0;
			for(int i = t; i < n; ++i) {
				Xor ^= i;
			}
			if(Xor == 0) {
				for(int i = t; i < n - 1; ++i) {
					cout << i << ' ' << i + 1 << '\n';
					cout << i + n << ' ' << i + 1 + n << '\n';
				}
				cout << n - 1 << ' ' << t + n << '\n';
				for(int i = 1; i < t - 1; ++i) {
					cout << i << ' ' << i + 1 << '\n';
					cout << i + n << ' ' << i + 1 + n << '\n';
				}
				cout << t - 1 << ' ' << 1 + n << '\n';
				int v = n ^ t;
				cout << n << ' ' << t << '\n';
				cout << t << ' ' << v << '\n';
				cout << v << ' ' << n + n << '\n';
			} else {
				for(int i = t; i < n - 1; ++i) {
					cout << i << ' ' << i + 1 << '\n';
					cout << i + n << ' ' << i + 1 + n << '\n';
				}	
				cout << n - 1 << ' ' << Xor << '\n';
				cout << Xor << ' ' << t + n << '\n';
				int v = n ^ t ^ Xor;
				cout << n << ' ' << t + n << '\n';
				cout << v << ' ' << n + n << '\n';
				vector<int> node;
				node.emplace_back(Xor);
				node.emplace_back(v);
				for(int i = 1; i < t; ++i) {
					if(i != Xor && i != v) {
						node.emplace_back(i);
					}	
				}
				for(int i = 0; i + 1 < node.size(); ++i) {
					cout << node[i] << ' ' << node[i + 1] << '\n';
					cout << node[i] + n << ' ' << node[i + 1] + n << '\n';
				}
				cout << node.back() << ' ' << node[0] + n << '\n';
			}
		}
	}

	return 0;
}


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

int main()
{
    int n, pt, px, py;
    cin >> n;
    pt = px = py= 0;
    while(n--){
        int t, x, y;
        cin >> t >> x >> y;
        int d = abs(x-px) + abs(y-py);
        if(t-pt < d || (t-pt-d)%2 ==1){
            cout << "No" << endl;
            return 0;
        }
        pt = t;
        px = x;
        py = y;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define exists(s,x) (s).find(x)!=(s).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define fi first
#define se second
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}
inline ll modpow(ll x, ll y) {
    ll res = 1;
    while(y) {
        if(y&1) res = mul(res,x);
        y >>= 1;
        x = mul(x,x);
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A, B; cin >> A >> B;
    int ans = 0;
    REP(i,10000) {
        if (i*8/100==A && i/10==B) { ans = i; break;}
    }
    cout << (ans == 0 ? -1 : ans) << endl;
    return 0;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    // 後ろから解くかわりにすべての文字列を「左右反転」する
    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for(int i=0; i<S.size();){
    	bool can2 = false;
    	for(int j=0;j<4; j++){
    		string d = divide[j];
    		if(S.substr(i,d.size()) == d){
    			can2 = true;
    			i += d.size();
    		}
    	}
    	if(!can2){
    		can = false;
    		break;
    	}
    }

	if(can)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

class bit {
public :
    vector<int> data;
    int n;

    bit( int _n ){
        built( _n );
    }
    void built( int _n ){
        n = 1;
        while( _n >= n ) n *= 2;
        data.assign( n,0 );
    }
    int sum( int i ){
        int sumval = 0;
        while( i > 0 ){
            sumval += data[i];
            i -= i & -i;
        }
        return sumval;
    }
    void upd( int a, int i ){
        while( i < n ){
            data[i] += a;
            i += i & -i;
        }
    }
};

int main() {

    static char s[200003];
    static int n[200003];
    Scs(s);
    static stack<int> sta[256];

    int N = strlen(s);
    int cnt[256] = {};
    Rep(i,N){
        cnt[s[i]]++;
    }
    char odd = false;
    Rep(i,256){
        if( odd && cnt[i]%2 ) {
            printf("-1");
            return 0;
        }
        if( cnt[i]%2 ) odd = i;
    }


    int cc = 1;
    Rep(i,N){
        // printf ("%d", cnt[s[i]]);
        if( cnt[s[i]] == 1 ){
            n[i] = (N+1)/2;
            cnt[s[i]] = 0;
        }else
        if( cnt[s[i]] > 0 ){
            sta[s[i]].push(cc);
            n[i] = cc++;
            cnt[s[i]] -= 2;
            if( N%2 && (N+1)/2 == cc ) cc++;
        }
    }
    // // printf ("\n");

    Rep(i,N){
        if( n[i] == 0 ){
            n[i] = N+1-sta[s[i]].top();
            sta[s[i]].pop();
        }
    }
    // Rep(i,N) printf ("%d", n[i]);
    // printf ("\n");

    bit B(N);
    ll ans = 0;
    Rep(i,N){
        ans += i - B.sum(n[i]);
        B.upd(1,n[i]);
    }
    printf ("%llu\n", ans);

    return 0;
}



Measured memory_bytes: 2816
n = int(input())
List = list(map(int,input().split()))
List = sorted(List)
a_j = List[-1]
checker = a_j
a_i = a_j
for item in List:
  temp = abs(a_j/2 - item)
  if temp < checker:
    checker = temp
    a_i = item
Answer = [a_j, a_i]
print(*Answer)

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

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

#define maxn 110

int n;
int x[maxn],y[maxn],h[maxn];

void read(){
  cin >> n;
  REP(i,n)cin >> x[i] >> y[i] >> h[i];
}

int get_cand(int cx,int cy){
  REP(i,n){
    if(h[i] > 0){
      return h[i] + abs(x[i] - cx) + abs(y[i] - cy);
    }
  }
}

bool valid(int cx,int cy,int H,int i){
  return max(H - abs(cx - x[i]) - abs(cy - y[i]),0) == h[i];
}

bool solve(int cx,int cy){
  int H = get_cand(cx,cy);
  REP(i,n) if(!valid(cx,cy,H,i)) return false;
  cout << cx << ' ' << cy << ' ' << H << '\n';
  return true;
}

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

  for(int cx = 0;cx <= 100;cx++){
    for(int cy = 0;cy <= 100;cy++){
      if(solve(cx,cy)) return 0;
    }
  }

}


Measured memory_bytes: 3656
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // min, max, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;

int main() {
	ll n, m, a;
	cin >> n >> m;
	vector<ll> dp(n+10);
	for (ll i = 0; i < m; i++) {
		cin >> a;
		dp[a] = -1;
	}
	dp[0] = 1;
	if (dp[1] == -1)dp[1] = 0;
	else dp[1] = 1;
	for (int i = 2; i < n+1; i++) {
		if (dp[i] == -1)dp[i] = 0;
		else dp[i] = (dp[i - 1] + dp[i - 2])%mod;
	}
	cout << dp[n] << endl;
}

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

int main(void){
    int K;

    cin >> K;
    
    if(K % 5 == 0 || K % 2 == 0){
        cout << -1 << endl;
    } else{
        int mod;
        int ans = 0;
        int value = 1;
        if(K % 7 == 0) mod = K * 9 / 7;
        else mod = K * 9;

        while(true){
            value = (10*value) % mod;
            ++ans;
            if(value == 1){
                cout << ans << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3608
def FactorialMod(N,Mod):
    if N>=Mod:
        return 0
    else:
        FactM = 1
        for TF in range(1,N+1):
            FactM = (FactM*TF)%Mod
        return FactM
print(FactorialMod(int(input()),10**9+7))

Measured memory_bytes: 9168
#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

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

  ll n; cin >> n;
  int ans = 1e9;
  for(ll i = 1; i*i <= n; ++i) {
    if(n%i == 0) {
      ll tmp = max(i, n/i);
      int cnt = 0;
      while(tmp > 0) {
        tmp /= 10;
        ++cnt;
      }
      ans = min(ans, cnt);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
n = int(input())
M = 10**9+7
L = []
for _ in range(n):
  a = int(input())
  L.append((a, 1))
for _ in range(n):
  b = int(input())
  L.append((b, 0))
L.sort()
C = [0, 0]
ans = 1
for d, f in L:
  if C[f^1]:
    ans *= C[f^1]
    ans %= M
    C[f^1] -= 1
  else:
    C[f] += 1
print(ans)

Measured memory_bytes: 30336
/*input
2
10 -10
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

int main(){
	ios_base::sync_with_stdio(0);
	long long q,m,k,h,ans=1e15,sum=0,p,x=0,y;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=0;i<n-1;++i){
		x+=a[i];
		ans=min(ans, abs(x-(sum-x)) );
	}
	cout<<ans;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Graph vector<vector<ll>>
constexpr ll INF=(1ll<<60);
constexpr ll mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

	if(n==1 && m==1) cout<<1<<endl;
	else if(n==1 || m==1) cout<<max(n-2,m-2)<<endl;
	else cout<<(n-2)*(m-2)<<endl;

    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main() {
    int a,b;cin>>a>>b;
    if(a<10&&b<10)cout<<a*b<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 256
N = input()
v = [int(i) for i in input().strip().split()]

while True:
    v.sort(reverse=True)
    x1 = v.pop()
    x2 = v.pop()
    x = (x1 + x2) / 2
    v.append(x)

    if len(v) == 1:
        break

print(v[0])


Measured memory_bytes: 3060
#include <iostream> 
#include <cassert>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

#define whole(xs) (xs).begin(),(xs).end()

namespace {
    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }

    typedef long double real;

    real EPS = 1e-9;

    real R;
    int S;
    vector<int> W;
    void input() {
        cin >> R >> S;
        W.clear(); W.resize(S);
        for (int i = 0; i < S; i++) {
            cin >> W[i];
        }
    }

    real solve();

    vector<int> pat;
    void init() {
        real ans = -1;
        pat.clear();
        for (int k = 0; k < S - 1; k++) pat.push_back(0);
        for (int i = 0; i < S; i++) pat.push_back(W[i]);
        ans = max(ans, solve());
        if (ans < 0) {
            cout << -1 << endl;
        } else {
            printf("%.18Lf\n", ans);
        }
    }

    struct State {
        int w;
        real left, right;
        State(int w, real left, real right) : w(w), left(left), right(right) {}
    };

    real parse() {
        vector<State> stack;
        real ans = 0;
        for (int i = 0; i < pat.size(); i++) {
            if (pat[i] == 0) { // 結合
                if (stack.size() < 2) return -1.0;
                assert(stack.size() >= 2);
                State a = stack.back(); stack.pop_back();
                State b = stack.back(); stack.pop_back();
                int w = a.w + b.w;
                real L = 1.0 / w * b.w, R = 1.0 / w * a.w;
                real nleft = max(L + a.left, b.left - R);
                real nright = max(R + b.right, a.right - L);
                stack.push_back(State(a.w + b.w, nleft, nright));
                ans = max(ans, nleft + nright);
            } else {
                assert(pat[i] >= 1); // 石
                stack.push_back(State(pat[i], 0, 0));
            }
        }
        assert(stack.size() == 1);
        return ans;
    }

    real solve() {
        real ans = -1.0;
        sort(whole(pat));
        do {
            real c = parse();
            //printf("c: %.18Lf  ", c); cout << pat << endl;
            if (c > R + EPS) continue;
            ans = max(c, ans);
        } while (next_permutation(whole(pat)));
        return ans;
    }
}

int main() {
    int T; cin >> T;
    for (int i = 0; i < T; i++) {
        input(); init();
    }
    return 0;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (1e9)
ll N, M;
vector<ll> A;
ll sum[105000];

ll f(ll x) {
    ll ret = 0;
    int j = N - 1;
    for(int i = 0; i < N; i++) {
        while( j >= 0 && A[i] + A[j] >= x) j--;
        ret += N - j - 1;
    }
    return ret;
}


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    A.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    for(int i = 0; i < N; i++) {
        sum[i+1] = sum[i] + A[i];
    }
    ll ok = 0;
    ll ng = 2e5 + 1;
    while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if(f(mid) >= M) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ll ans = 0;
    cerr << ok << endl;
    for(int i = 0; i < N; i++) {
        auto itr = lower_bound(A.begin(), A.end(), ok - A[i]);
        int index = distance(A.begin(), itr);
        ans += distance(itr, A.end()) * A[i];
        ans += sum[N] - sum[index];
    }
    ans -= (f(ok) - M) * ok;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  cout << a[n-1] << " ";
  ll minv = abs(a[n-1] - a[0] -  a[0]);
  ll minidx = 0;
  rep(i,n-1){
    if(minv > abs(a[n-1] - a[i] -  a[i])){
      minv = abs(a[n-1] - a[i] -  a[i]);
      minidx = i;
    }
  }
  cout << a[minidx] << endl;

  
  return 0;
    

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
int aa[10000];
string ss[10000];
char cc[10000];
pair<int,string>pp[1000];
int a,b=0,c;
string sa,sb,sc;
signed main()
{
	cin>>a>>sa>>sb>>sc;
	rep(i,a){
		if(sa[i]==sb[i]&&sb[i]==sc[i]){
			b=b;
		}elif(sa[i]==sb[i]||sb[i]==sc[i]||sc[i]==sa[i]){
			b++;
		}else{
			b=b+2;
		}
	}
	cout<<b;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>


#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;


int main(void) {
	int num = 0;
	string pair_str[52];
	int pair_num[52];
	bool S_set[13] = {};
	bool H_set[13] = {};
	bool C_set[13] = {};
	bool D_set[13] = {};

	CI num;

	for (int i = 0; i < num; ++i) {
		CI pair_str[i];
		CI pair_num[i];
		if (pair_str[i] == "S") {
			S_set[pair_num[i] - 1] = 1;
		}
		if (pair_str[i] == "H") {
			H_set[pair_num[i] - 1] = 1;
		}
		if (pair_str[i] == "C") {
			C_set[pair_num[i] - 1] = 1;
		}
		if (pair_str[i] == "D") {
			D_set[pair_num[i] - 1] = 1;
		}
	}
	for (int i = 0; i < 13; ++i) {
		if (S_set[i] == 0) {
			CO "S" << " " << i + 1 E
		}
	}
	for (int i = 0; i < 13; ++i) {
		if (H_set[i] == 0) {
			CO "H" << " " << i + 1 E
		}
	}
	for (int i = 0; i < 13; ++i) {
		if (C_set[i] == 0) {
			CO "C" << " " << i + 1 E
		}
	}
	for (int i = 0; i < 13; ++i) {
		if (D_set[i] == 0) {
			CO "D" << " " << i + 1 E
		}
	}
	
}

Measured memory_bytes: 1208
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#include<cmath>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll K,a,b;
int main(){
    cin >> K >> a >> b;
    if(a+2 >= b || K+1 <= a){
        cout << K+1 << endl;
        return 0;
    }
    ll bisket = 0;
    for(int i = 0; i < K; i++){
        if(bisket < a){
            bisket = a;
            i = a-2;
        }
        else {
            if((K-i)%2 == 0){
                bisket += ((K-i)/2*(b-a));
                break;
            } else {
                bisket += ((K-i)/2)*(b-a) + 1;
                break;
            }
        }
    }
    cout << bisket << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define N 200000
using namespace std;
int n,i;
char s[N];
int main()
{
    scanf("%s",s);
    n = strlen(s);
    if (n % 2 == 1) {cout<<"No"<<endl; return 0;}
    fo(i,0,n-1)
    {
        if (i % 2 == 0 && s[i] !='h') {cout<<"No"<<endl; return 0;}
        if (i % 2 == 1 && s[i] !='i') {cout<<"No"<<endl; return 0;}
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, M, Q = MAP()
LR = [LIST() for _ in range(M)]
pq = [LIST() for _ in range(Q)]

x = [[0]*(N+1) for _ in range(N+1)]

for L, R in LR:
	x[L][R] += 1

for l in range(N+1):
	x[l] = list(accumulate(x[l]))

for l in range(1, N+1):
	for r in range(N+1):
		x[l][r] += x[l-1][r]
		
for p, q in pq:
	print(x[q][q] - x[q][p-1] - x[p-1][q] + x[p-1][p-1])




Measured memory_bytes: 65256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <chrono>
//#include <intrin.h>

using namespace std;

typedef long long ll;

inline void solve() {
	string s;
	cin >> s;
	int n = s.size();

	for (int i = 0; i < n; i++)
		if (s[i] == '?')
			s[i] = 'D';
	cout << s;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3740
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N;
string s;

int powMod(int n, int p) {
  int res = 1;
  while (p) {
    if (p & 1) (res *= n) %= MOD;
    (n *= n) %= MOD;
    p >>= 1;
  }
  return res;
}
int invMod(int n) {
  return powMod(n, MOD - 2);
}

int memo[100010][2];
int dfs(int i, int less){
  if(i == N){
    return 1;
  }

  if(less) return powMod(3, N-i);
  if(s[i] == '0') return dfs(i+1, less);
  int ret = 0;
  ret += dfs(i+1, less)*2;
  ret += dfs(i+1, true);

  return ret%MOD;
}

signed main() {
  cin >> s;
  N = s.size();

  cout << dfs(0, false) << "\n";

  return 0;
}

Measured memory_bytes: 3664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class Main {
    public static void main(String[] args) {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        int n = 0;
        String aInput = "";

        try {
            n = Integer.parseInt(bufferedReader.readLine());
            aInput = bufferedReader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }

        String[] aArray = aInput.split(" ");
        List<Integer> aList = new ArrayList<>();
        for (String aString : aArray) {
            aList.add(Integer.parseInt(aString));
        }
        int alice = 0;
        int bob = 0;
        int i = 0;
        while (aList.size() > 0) {
            int max =  getMaxValue(aList);
            if (i % 2 == 0) {
                alice += max;
            } else {
                bob += max;
            }
            aList.remove(Integer.valueOf(max));
            i++;
        }

        System.out.println(alice - bob);
    }

    private static int getMaxValue(List<Integer> list) {
        Optional<Integer> max = list.stream().max(Integer::compareTo);
        return max.get();
    }
}

Measured memory_bytes: 26836
N = int(input())
now = [0,0]
tnow = 0
ans = 'Yes'
for i in range(N):
    t,x,y = map(int,input().split())
    dis = abs(x-now[0]) + abs(y-now[1])
    if t-tnow >= dis and (t-tnow)%2 == dis%2:
        tnow = t
        now = [x,y]
    else:
        ans = 'No'
        break
print(ans)

Measured memory_bytes: 3064
from heapq import heappush, heappop

INF = 10 ** 18

sum_B = 0
L, R = [INF], [INF]
sum_L = sum_R = 0
L_size = R_size = 0

A = map(int, open(0).read().split())

Q = next(A)
for _ in range(Q):
    q = next(A)
    if q == 1:
        a, b = next(A), next(A)

        sum_B += b

        max_L = -heappop(L)
        min_R = heappop(R)

        sum_L -= max_L
        sum_R -= min_R

        l, m, r = sorted((max_L, a, min_R))

        heappush(L, -l)
        heappush(R, r)
        sum_L += l
        sum_R += r

        if L_size == R_size:
            heappush(L, -m)
            L_size += 1
            sum_L += m
        else:
            heappush(R, m)
            R_size += 1
            sum_R += m

    else:
        median = -L[0]
        min_value = sum_B + sum_R - sum_L
        if L_size != R_size:
            min_value += median
        print(median, min_value)


Measured memory_bytes: 42352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		
		int count=0;
		char[] tenki = new char[3];
		char temp = 'R';
		
		for(int i=0; i < 3; i++) {
			tenki[i] = s.charAt(i);
		}
		
		if(tenki[0] == 'R') {
			count++;
			if(tenki[1] == 'R') {
				count++;
				if(tenki[2] == 'R') {
					count++;
				}
			}
		}else {
			if(tenki[1] == 'R') {
				count++;
				if(tenki[2] == 'R') {
					count++;
				}
			}else {
				if(tenki[2] == 'R') {
					count++;
				}
			}
		}
		
		
		
		
		
		System.out.println(count);
		
		
		
	}

}


Measured memory_bytes: 35768
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scanf("%d %d", &h, &w)

	ss := make([]string, h)

	type Bomb struct {
		X int
		Y int
	}
	bomb := []Bomb{}

	for i := 0; i < h; i++ {
		var s string
		fmt.Scanf("%s", &s)
		ss[i] = s
		for k, v := range s {
			if v == 35 {
				bomb = append(bomb, Bomb{X: i, Y: k})
			}
		}
	}

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			s := ss[i][j]
			if s == 35 {
				fmt.Printf("%s", "#")
				continue
			}
			cnt := 0
			for m := -1; m < 2; m++ {
				for n := -1; n < 2; n++ {
					tx := i + m
					ty := j + n
					if tx < 0 || ty < 0 {
						continue
					}
					for _, b := range bomb {
						if b.X == tx && b.Y == ty {
							cnt = cnt + 1
						}
					}
				}
			}
			fmt.Printf("%d", cnt)
		}
		fmt.Printf("\n")
	}
}

Measured memory_bytes: 1960
N = int(input())
s = []
for i in range(N):
    s.append(int(input()))
s.sort()
ssum = sum(s)
c = 0
for i in s:
    if ssum%10 != 0:
        print(ssum)
        c = 1
        break
    if i%10 != 0:
        ssum -= i
if c == 0:
    print(0)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
    
    int arlong;
    cin >> arlong;
    int ar[arlong];
    for (int i=0; i<arlong; i++) {
        cin >>ar[i];
    }
    int maxv = 0;
    int minv = 1000;
    for(int i = 0; i < arlong; ++i) {
        if( ar[i] > maxv )
            maxv = ar[i];
        if( ar[i] < minv )
            minv = ar[i];
    }
    cout << (maxv-minv) <<endl;
    return 0;
}

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

int main(){
  	long n;
  	cin >> n;
  	vector<long> a(n);
  	for(int i=0;i<n;i++){
    	cin >> a[i];
    }
  	auto m=max_element(a.begin(),a.end());
  	*m=*m/2;
  	long sum=0;
  	for(auto i:a){
    	sum+=i;
    }
  	cout << sum;
}


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

int main(void){
  string A, B, C;
  int cnt = 0;
  cin >> A;
  cin >> B;
  cin >> C;
  if(A[A.size() - 1] == B[0])
    cnt++;
  if(B[B.size() - 1] == C[0])
    cnt++;
  if(cnt == 2) cout << "YES" << "\n";
  else cout << "NO" << "\n";
  return 0;
}


Measured memory_bytes: 3608
#include<iostream>
using namespace std;
typedef long long int LL;
const int INF=1e9+7;
int main(){
	int n;
	LL a,b,c;
	int i,j,k;
	LL s=0;
	cin>>n;
	for(c=INF,i=0;i<n;i++){
		cin>>a>>b;
		if(a>b && c>b)c=b;
		s+=a;
	}
	if(c==INF)cout<<0<<endl;
	else cout<<s-c<<endl;
}
	


Measured memory_bytes: 256
import math

N = int(input())

ans = 100

# 桁数を計算する関数
def cal_digits(n):
    digits = 0
    while True:
        if n // 10 < 1:
            digits += 1
            break
        n //= 10
        digits += 1
    return digits

for i in range(1, int(math.sqrt(N))+1):
    if N % i == 0:
        ans = min(ans, max(cal_digits(i), cal_digits(N//i)))

print(ans)

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

int main(){
  int k;
  cin >> k;
  rep(i,k) cout << "ACL";
  cout << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <algorithm>

int main(void)
{
	int data[101];
	int n;
	int sum;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		for (int i = 0; i < n; i++){
			scanf("%d", data + i);
		}
		std::sort(data, data + n);
		sum = 0;
		for (int i = 1; i < n - 1; i++){
			sum += data[i];
		}
		printf("%d\n", sum / (n - 2));
	}
	return (0);
}

Measured memory_bytes: 1044
#include <stdio.h>

int main(void) {
    int n,a,b,c,d,count;
    while(1){
        scanf("%d%d",&n,&d);
        if(n==0&&d==0)break;
        count=0;
        for(a=1;a<n+1;a++){
            for(b=1;b<n+1;b++){
                for(c=1;c<n+1;c++){
                    if((a+b+c)==d&&(a!=b)&&(b!=c)&&(c!=a)){
                        count++;
                    }
                }
            }
        }
        printf("%d\n",(count/6));
    }
    return 0;
}

Measured memory_bytes: 600