akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int MOD=1000*1000*1000+7,N=50,M=17;
using namespace std;
typedef long long ll;
ll n,x,y,z,ans=1;
ll C[N][1<<M];//sum of n elements is m
int main()
{cin>>n>>x>>y>>z;
    C[0][0]=1;
    for(int i=1;i<=n;i++)ans=(ans*10)%MOD;
    int S=(1<<x+y+z)-1;
    int B=(1<<x-1)|(1<<x+y-1)|(1<<x+y+z-1);
    for(int i=1;i<=n;i++){
        for(int j=0;j<=S;j++){
            for(int k=1;k<=10;k++){
                int E=(j<<k)|(1<<k-1);
                E&=S;
                if((E&B)!=B)C[i][E]=(C[i][E]+C[i-1][j])%MOD;
            }
        }
    }
    for(int i=0;i<=S;i++){
        ans=(ans-C[n][i])%MOD;
        ans=(ans+MOD)%MOD;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 44472
//  RAKSHIT KADAM

 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 3
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning check the size of arrays!!!
// NUMERIC DEFINITIONS :
    #define INF 100000000000000005
    #define inf 1000000004
    #define MOD  1000000007
    #define mod 998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll ter; cin>> ter; while(ter--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
 
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}

int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn = 500003;
//ll fact[10005];
//ll modIN[1000005];
//void facto()
//{
//    ll lim =1000005;fact[0]=1;
//    for(ll i=1;i<lim;i++)
//    {
//        fact[i]=(fact[i-1]*i)%MOD;
//    }
//    modIN[n]=modInverse(fact[n],MOD);
//    for(ll i=n-1;i>=1;i--)
//    {
//        modIN[i] = (modIN[i+1]*(i+1))%MOD;
//    }
//}
//ll ncr(ll a,ll b)
//{
//    ll ret = 0;
//    ret = fact[a]*(modIN[b]);
//    ret%=MOD;
//    ret*=modIN[a-b];
//    ret%=MOD;
//    return ret;
//}

void solve()
{
    
}
signed main(){
   Need_for_speed(activated);
//
//    satisfy
//    {
// solve();
//    }
    ll x;cin>>x;
    cout<<(x^1)<<endl;
//    solve();

    
    
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define for(i,a,b)      for(int i=a; i<b; i++)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()  {

	FIO;
    int n,k; cin>>n>>k;
    n++ ;

    int h[n] ;
    h[0] = 0;

    for(i,1,n) cin>>h[i] ; 

    int dp[n] ;

    for(i,0,n) dp[i] = INT_MAX ;

    dp[0] = 0, dp[1]= 0 ;

    for(i,1,n) {

        for(j,i+1,min(n,i+k+1)) {

            dp[j] = min(dp[j],dp[i] + abs(h[j]-h[i])) ;
        }

    }

    cout<<dp[n-1] ;

    return 0; 
}

Measured memory_bytes: 5172
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int l,r,d;
    cin >> l >> r >> d;
    
    int cnt = 0;
    for(int i=1; i<=n; i++){
        if(i%2==1 && a[i-1]%2==1) cnt++;
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(void)
{
    int N;
    int money = 1000;
    int m_num;
    int sa;

    scanf("%d", &N);

    m_num = N % money;

    if (m_num == 0) {
        printf("0\n");
    } else {
        sa = money - m_num;
        printf("%d\n", sa); 
    }
    

    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if( A == B && B != C){
        cout << "Yes" << endl;
    }
    else if ( B == C && C != A) {
        cout << "Yes" << endl;
    }
    else if ( C == A && A != B) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

const int MAXN = 1e5 + 10;

int u, v;
long long n, r = -1;
vector<int> adj[MAXN];
long long dp[MAXN][2];

void dfs(int root, int par = -1){
    long long s = 0, mx = 0;
    for(auto y: adj[root])
        if(y != par){
            dfs(y, root);
            s += dp[y][1];
            mx = max(mx, dp[y][1] - dp[y][0]);
        }
    dp[root][1] = s - mx;
    dp[root][0] = s - mx;
    if(s - mx == 0)
        dp[root][1] = 1;
    return;
}

int main(){
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    for(int i = 0; i < n; i++)
        if(adj[i].size() >= 3)
            r = i;
    
    if(!(r ^ -1))
        return cout << 1 << '\n', 0;
    
    dfs(r);
    cout << dp[r][1] << '\n';
    return 0;
}


Measured memory_bytes: 11648
N = int(input())
A = list(map(int, input().split()))
if N%2:
    a, b, c = 0, 0, 0
    for i in range(0,N-2,2):
        c=max(a+A[i+2],b+A[i+2],c+A[i+2])
        b=max(a+A[i+1],b+A[i+1])
        a+=A[i]
    print(max(a,b,c))
else:
    a, b = 0, 0
    for i in range(0,N-1,2):
        b=max(a+A[i+1],b+A[i+1])
        a+=A[i]
    print(max(a,b))

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

using namespace std;

struct data{
	int weight;
	int value;
	double vperp;
} listdata[100010];

bool compare(struct data a,struct data b){
	return a.vperp > b.vperp;
}

int main(){
	int jumlah,berattas;
	scanf ("%d %d",&jumlah,&berattas);
	for (int a=0;a<jumlah;a++){
		scanf ("%d %d",&listdata[a].value,&listdata[a].weight);
		double x = (double) listdata[a].weight;
		double y = (double) listdata[a].value;
		listdata[a].vperp = y/x;
	}
	
	sort(listdata,listdata+jumlah,compare);
	
//	for (int a=0;a<jumlah;a++){
//		printf ("%d %d %.2f\n",listdata[a].value,listdata[a].weight,listdata[a].vperp);
//	}	

	int totaltas = berattas;
	int idx=0;
	double hasil =0;
	for (int a=0;a<jumlah;a++){
		if (totaltas<=0){
			break;
		}
		else{
			if (totaltas>listdata[a].weight){
				hasil+=(listdata[a].weight*listdata[a].vperp);
				totaltas-=listdata[a].weight;
			}else{
				hasil+=listdata[a].vperp *totaltas;
				totaltas-=totaltas;
			}
		}
	}
	
	printf ("%lf\n",hasil);
	return 0;
}


Measured memory_bytes: 4268
#include <cstdio>
#include <map>
#include <algorithm>

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

  std::map<int, size_t> rate;
  rate[8] = 0;
  for (int i=0; i<N; ++i) {
    int a;
    scanf("%d", &a);
    if (a >= 3200) a = 3200;
    ++rate[a/400];
  }

  size_t min=std::max<size_t>(1, rate.size()-1);
  size_t max=rate.size()-1+rate[8];
  printf("%zu %zu\n", min, max);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(long long i = 0;i < (n);i++)
typedef long long ll;
typedef vector<long long> vl;
const ll mod = 1000000007;

int main(){
	ll n,m; cin >> n >> m;
	vl s(m); vl c(m);
	rep(i,m){
		cin >> s[i] >> c[i];
		s[i]--;
	}
	vl d(n); rep(i,n)d[i] = 0;
	if(n > 1)d[0] = 1;
	vector<bool> check(n,false);
	rep(i,m){
		if(check[s[i]] && d[s[i]] != c[i]){
			cout << -1 << endl;
			return 0;
		}
        else if(s[i] == 0 &&c[i] == 0 && n != 1){
          cout << -1 << endl;
          return 0;
        } 
		else{
			d[s[i]] = c[i];
			check[s[i]] = true;
        }
	}
    rep(i,n)cout << d[i];
    cout << endl;
}


Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import itertools

N,P = map(int, sys.stdin.readline().rstrip().split())
As = list(map(int, sys.stdin.readline().rstrip().split()))

odds = sum(item % 2 == 1 for item in As)
evens = N - odds

def comb(n, i):
    return math.factorial(n) / math.factorial(n-i) / math.factorial(i)

count = 0
for j in range(P, odds+1, 2): # 奇数を何個とるか
    for k in range(evens+1): # 偶数を何個とるか
        count += comb(odds, j) * comb(evens, k)
print(int(count))

exit(0)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        long N = long.Parse(input[0])+1;
        long M = long.Parse(input[1]);
        int[] ng = new int[N];
        for (int i = 0; i < N; i++)
        {
            ng[i] = 0;
        }
        for (int i = 0; i < M; i++)
        {
            ng[long.Parse(Console.ReadLine())] = 1;
        }
        long[] num = new long[N];
        num[0] = 1;
        for(int i = 0; i < N; i++)
        {
            if (ng[i] == 0)
            {
                if (i + 1 < N)
                {
                    num[i + 1] += num[i];
                    num[i + 1] %= 1000000007;
                }
                if (i + 2 < N)
                {
                    num[i + 2] += num[i];
                    num[i + 2] %= 1000000007;
                }
            }
        }
        Console.WriteLine(num[num.Length-1]);
    }
}


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


int N,M;
pair<int,int> a[100000];
int main(){
  while(cin >> N >> M){
    if(N==0 && M==0){
      return 0;
    }
    else{
      for(int i=0; i<N; i++){
	int d,p;
	cin >> d >> p;
	a[i] = make_pair(p,d);
      }
      
      sort(a, a+N);
      reverse(a, a+N);
      
      int S = 0;
      for(int k=0; k<N; k++){
	S += a[k].first*a[k].second;
      }
      for(int l=0; l<N; l++){
	if(M<=0)break;
	int guarded = min(M, a[l].second);
	S -= a[l].first*guarded;
	M -= guarded;
      }
      cout << S << endl;
    }
    }
    }

Measured memory_bytes: 1944
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	var n int
	var p []int
	for n = 40; n > 0; n-- {
		if N >= (1<<uint(n))-1 {
			break
		}
	}
	for i := 1; i <= n; i++ {
		p = append(p, i)
	}
	N -= (1 << uint(n)) - 1

	for i := n - 1; i >= 0; i-- {
		if N < 1<<uint(i) {
			continue
		}
		n++
		p = append(p[:i], append([]int{n}, p[i:]...)...)
		N -= 1 << uint(i)
	}

	fmt.Println(len(p) * 2)
	for i := 0; i < len(p); i++ {
		fmt.Printf("%d ", i+1)
	}

	for _, v := range p {
		fmt.Printf("%d ", v)
	}

	fmt.Println()
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	if x < y {
		return x
	}

	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}

	return y
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

// ---------- Util.


Measured memory_bytes: 768
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    int[] c = new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
      b[i]=sc.nextInt();
      c[i]=sc.nextInt();
    }
    long[][] dp = new long[3][n];
    dp[0][0]=a[0];
    dp[1][0]=b[0];
    dp[2][0]=c[0];
    for(int i=1;i<n;i++){
      dp[0][i]=Math.max(dp[1][i-1]+a[i],dp[2][i-1]+a[i]);
      dp[1][i]=Math.max(dp[2][i-1]+b[i],dp[0][i-1]+b[i]);
      dp[2][i]=Math.max(dp[0][i-1]+c[i],dp[1][i-1]+c[i]);
    }
    
    System.out.println(Math.max(dp[0][n-1],Math.max(dp[1][n-1],dp[2][n-1])));
  }
}

Measured memory_bytes: 94416
//In the name of GOD
//SMani24
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5 + 10;
int n, a[N];

void read_input() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}
void write_output(int cnt) {
	int sum = 0;
	int tf = 0, f = -1;
	for (int i = 0; i < n; i++) {
		sum += a[i];
		if (a[i] % 2) {
			tf++;
			f = a[i];
		}
	}
	if ((sum - n) % 2) {
		if (cnt % 2)
			cout << "Second" << endl;
		else
			cout << "First" << endl;
		exit(0);
	}
	else if (tf == 1 && f != 1) {
		int gcd = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] % 2)
				a[i]--;
			gcd = __gcd(gcd, a[i]);
		}
		for (int i = 0; i < n; i++)
			a[i] /= gcd;
		write_output(cnt + 1);
	}
	if (cnt % 2)
		cout << "First\n";
	else
		cout << "Second\n";
	exit(0);
}

int32_t main() {
	read_input(), write_output(0);
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}

const int N = 1e6 + 10;

int fre[N];
int sieve[N];

void solve()
{
   int n;
    cin >> n;
    
   int a[n];
    f(i,n) cin >> a[i];
    
   f(i,n) fre[a[i]]++;
    
   for(int i=1;i<N;i++)
   {
       for(int j=i;j<N;j+=i) sieve[j]+=fre[i];
   }
    
   int res = 0;
    
   for(int i=0;i<n;i++) if(sieve[a[i]] == 1) res++;
       
   cout <<res;
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 20768
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>

#define MAX(a,b) ((a)<(b) ? (a) : (b))
#define MIN(a,b) ((a)>(b) ? (a) : (b))


using namespace std;

int main(){
	string a;
	cin>>a;
	int b,e,ans;
	ans = 0;

	for (int i = 1; i <= a.length(); i++) {
		if (a[i-1]=='A') {
			b=i;
			break;
		}
	}
	
	for (int i = a.length(); i >= 1; i--) {
		if (a[i-1]=='Z') {
			e=i;
			break;
		}
	}
	ans = e - b + 1;
	
	cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> choco(h);
    for (int i=0; i<h; ++i) {
        cin >> choco.at(i);
    }

    int res = INF;
    for (int bits=0; bits<(1<<(h-1)); ++bits) {
        vector<int> g(h);
        int divH = 0;
        for (int i=0; i<h; ++i) {
            g.at(i) = divH;
            if (bits & (1<<i)) ++divH;
        }
        vector<int> cnt(divH+1);
        int divW = 0, len = 0;
        for (int i=0; i<w; ++i) {
            for (int j=0; j<h; ++j) {
                if (choco.at(j).at(i) == '1') cnt.at(g.at(j))++;
            }
            bool ok = true;
            for (int x : cnt) {
                if (x > k) {
                    ok = false;
                    break;
                }
            }
            if (!ok) {
                if (len == 0) {
                    divW = 1e8;
                    break;
                } else {
                    for (int &x : cnt) x = 0;
                    len = 0;
                    ++divW;
                    --i;
                }
            } else {
                ++len;
            }
        }
        chmin(res, divH + divW);
    }

    cout << res << '\n';
}

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

    solve();

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin>>s;
  ll n=s.size();
  REP(i,n){
    if(s[i]=='?')
      cout<<'D';
    else
      cout<<s[i];
  }
  cout<<endl;

}



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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	int k=1;
	string p = "",c = "";
	p += s[0];
	for(int i=1;i<s.size();i++){
		c += s[i];
		if(p.size() == c.size() && p == c){
		
		}
		else{
			p = c;
			c = "";
			k++;
		}
	}
	cout<<k;
	return 0;
}


Measured memory_bytes: 720
#include <iostream>
using namespace std;
int main(){
	const int ERA[4][3]={{1868,9,8},{1912,7,30},{1926,12,25},{1989,1,8}};
	const string ERA_N[]={"meiji","taisho","showa","heisei"};
	int y,m,d;
	while(cin>>y>>m>>d){
		if(ERA[0][0]>y||(ERA[0][0]==y&&ERA[0][1]>m)||(ERA[0][0]==y&&ERA[0][1]==m&&ERA[0][2]>d))cout<<"pre-meiji\n";
		else for(int i=3;i>=0;--i){
			if(ERA[i][0]<y||(ERA[i][0]==y&&ERA[i][1]<m)||(ERA[i][0]==y&&ERA[i][1]==m&&ERA[i][2]<=d)){
				int ly=y-ERA[i][0]+1;
				cout<<ERA_N[i]<<" "<<ly<<" "<<m<<" "<<d<<"\n";
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define MAX 50

int main()
{
	int n;
	int k;
	int l[MAX];
	int i;
	int total=0;
	cin >> n >> k;

	for (i = 0; i < n; i++)
	{
		cin >> l[i];
	}

	sort(l, l + n);

	for (i = 0; i <k; i++)
	{
		total = total + l[n-1-i];
	}

	cout << total;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a, b, h, x;
        a = input.nextInt();
        b = input.nextInt();
        h = input.nextInt();
        x = ((a+b)*h)/2;
        System.out.println(x);
    }
    
}


Measured memory_bytes: 27080
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
int n;
int arr[250005];
int grid[505][505];
int dist[505][505];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
queue<pi> q;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	REP(i, 0, n*n){
		cin >> arr[i];
		arr[i]--;
		dist[i/n][i%n] = min(min(i/n, i%n), min(n - 1 - (i/n), n - 1 - (i%n)));
		grid[i/n][i%n] = 1;
	}
	ll answer = 0;
	REP(i, 0, n*n){
		answer += dist[arr[i]/n][arr[i]%n];
		grid[arr[i]/n][arr[i]%n] = 0;
		q.push(MP(arr[i]/n, arr[i]%n));
		while (!q.empty()){
			pi cur = q.front();
			q.pop();
			int xx = cur.first;
			int yy = cur.second;
			REP(j, 0, 4){
				int newx = xx + dx[j];
				int newy = yy + dy[j];
				if (newx < 0 || newx >= n) continue;
				if (newy < 0 || newy >= n) continue;
				if (dist[newx][newy] > dist[xx][yy] + grid[xx][yy]){
					dist[newx][newy] = dist[xx][yy] + grid[xx][yy];
					q.push(MP(newx, newy));
				}
			}
		}
	}
	cout << answer << "\n";
	
}

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

int main(){
  long long a,ib;
  long double b;
  cin >> a >> b;
  
  ib = (b*100)+0.5;
  a *= ib;
  a /= 100;
  
  cout << a << endl;
  
  return 0;
}


Measured memory_bytes: 3684
n, x, y = list(map(int, input().split()))

ans = [0] * n
for i in range(1, n):
    for j in range(i + 1, n + 1):
        if i < x:
            if j < x:
                d = j - i
            elif x <= j <= y:
                d = min(j - i, y - j + x - i + 1)
            else:
                d = j - y + x - i + 1
        elif x <= i <= y:
            if j <= y:
                d = min(j - i, y - j + i - x + 1)
            else:
                d = min(j - i, j - y + i - x + 1)
        else:
            d = j - i
        ans[d] += 1

print('\n'.join(map(str, ans[1:])))


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

using namespace std;
int n,i,ans,nrr;
char ch;
int a[200005];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>ch;
        if(ch=='W')
            a[i]=1;
        else
            nrr++;
    }

    for(i=1;i<=nrr;i++)
    {
        if(a[i])
            ans++;
    }

    cout<<ans;
    return 0;
}


Measured memory_bytes: 4372
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	a = LIST()
	if sum(a) > 21:
		print('bust')
	else:
		print('win')

if __name__=='__main__':
	main()


Measured memory_bytes: 5716
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <queue>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){


    ll N, x;
    cin >> N >> x;

    vector<ll> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];

    ll ans = 0;
    if(v[0] > x){
        ans += v[0] - x;
        v[0] = x;
    } 
    for(int i = 1; i < N; i++){
        if(v[i] + v[i-1] > x){
            ans += v[i] + v[i-1] - x;
            v[i] = x - v[i-1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
S = input()
odd_flag = True
even_flag = True

for i, s in enumerate(S):
    if i % 2 == 0 and s == "L":
        odd_flag = False
    elif i % 2 == 1 and s  == "R":
        even_flag = False
if odd_flag and even_flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


n = int(input())
li = make_divisors(n)

ans = 10 ** 12
for i in li:
    j = n // i
    tmp_ans = (i-1)+(j-1)
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)

Measured memory_bytes: 3268
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 2001 * 2001;

bitset<MAX> can;

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

  can.set(0);
  int sum = 0;
  REP(i, N) {
    int x;
    scanf("%d", &x);
    can |= (can << x);
    sum += x;
  }

  int ans = (sum + 1) / 2;
  while (!can.test(ans)) ans++;

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


Measured memory_bytes: 1664
#include<cstdio>
#include<algorithm>

using namespace std;

#define N 100001

const int mod=1e9+7;

int a[N],inv[N];

int Pow(int p,int q)
{
    int s=1;
    for(;q;q>>=1,p=1LL*p*p%mod)
        if(q&1) s=1LL*s*p%mod;
    return s;
}

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i) inv[i]=Pow(i,mod-2); 
    long long p=1,ans=a[k];
    for(int i=k+1;i<=n;++i)
    {
         p=p*(i-1)%mod;
         p=p*inv[i-k]%mod;
         ans=(ans+a[i]*p%mod)%mod;
    }
    ans-=a[n-k+1];
    p=1;
    for(int i=k+1;i<=n;++i)
    {
         p=p*(i-1)%mod;
         p=p*inv[i-k]%mod;
         ans=(ans-a[n-i+1]*p%mod)%mod;
    }
    if(ans<0) ans+=mod;
    printf("%d",ans);
}

Measured memory_bytes: 2492
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const int INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(int m,int n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(int x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(int x,int y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}

int main(){
  int X,Y;
  cin >> X >> Y;
  double x,y;
  x = (-1/3.0)*(X - 2*Y);
  y = (-1/3.0)*(-2*X + Y);
  if(abs(x-int(x)) > 0.01 || abs(y-int(y)) > 0.01 || x < 0 || y < 0){
    cout << 0 << endl;
  }
  else{
    cout << comb(int(x+y),int(x)) << endl;
  }
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
 
int main(){
  int  n;
  cin >> n;
  vector<ll> a(n+1);
  vector<ll> b(n);
  rep(i,n+1){
    cin >> a.at(i);
  }
  rep(i,n){
    cin >> b.at(i);
  }
  ll sum=0;
  rep(i,n){
    if(i!=n-1){
   if(a.at(i)>=b.at(i)) sum+=b.at(i);
    else if(a.at(i)< b.at(i) && (a.at(i)+a.at(i+1))>=b.at(i)){
      sum+=b.at(i);
      a.at(i+1)-=(b.at(i)-a.at(i));
    }
    else{
      sum+=a.at(i)+a.at(i+1);
      a.at(i+1)=0;
    }
    }
    else{
      if(b.at(i)<=a.at(i)+a.at(i+1)){
        sum+=b.at(i) ;
      }
      else{
        sum+=a.at(i)+a.at(i+1);
      }
    }
  }
    cout << sum << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int digitSum(int n){
  int sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int n,a,b,num,sum=0;
  cin >> n >> a >> b;
  for(int i=1;i<=n;i++){
    num = digitSum(i);
    if(num >= a && num <= b){
      sum += i;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
 string s,t;
 cin>>s;
 int count=0;
 cin>>t;
 for(int i=0;i<3;i++)
   if(s[i]==t[i])
     count++;
cout<<count<<endl;
return 0;  
}  

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	d=~~input[0]
	n=~~input[1]
	bai = 1
	if(d==0){
		if(n<100){
			console.log('%d',n)
		}else{
			console.log('%d','101')
		}
	}else if(d==1){
		if(n<100){
			console.log('%d',n*100)
		}else{
			console.log('%d','10100')
		}
	}else{
		if(n<100){
			console.log('%d',n*10000)
		}else{
			console.log('%d','1010000')
		}
	}
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
const int INF=0x3f3f3f3f;
const int MAXN=100010;
set<int>s[MAXN];
struct Edge
{
    int v,cost;
    Edge(int _v=0,int _cost=0):v(_v),cost(_cost) {}
};
vector<Edge>E[MAXN];
bool vis[MAXN];
int dist[MAXN];
void Dijkstra(int n,int start)//点的编号从1开始
{
    memset(vis,false,sizeof(vis));
    for(int i=1; i<=n; i++) dist[i]=INF;
    priority_queue<PII>que;
    while(!que.empty())que.pop();
    dist[start]=0;
    que.push({0,start});
    PII tmp;
    while(!que.empty())
    {
        tmp=que.top();
        que.pop();
        int u=tmp.se;
        int c=-tmp.fi;
        if(vis[u])continue;
        vis[u]=true;
        for(int i=0; i<E[u].size(); i++)
        {
            int v=E[u][i].v;
            int com=E[u][i].cost;
            int cost=c+(!s[u].count(com));
            if(!vis[v])
            {
                if(dist[v]>cost){
                    dist[v]=cost;
                    que.push({-cost,v});
                    s[v].clear();
                    s[v].insert(com);
                }
                else if(dist[v]==cost){
                    s[v].insert(com);
                }
            }
        }
    }
}
void addedge(int u,int v,int w)
{
    E[u].push_back(Edge(v,w));
}
int main()
{
    int n,m;
    cin>>n>>m;
    while(m--){
        int a,b,c;
        cin>>a>>b>>c;
        addedge(a,b,c);
        addedge(b,a,c);
    }
    Dijkstra(n,1);
    printf("%d\n",dist[n]==inf?-1:dist[n]);
    return 0;
}


Measured memory_bytes: 23540
#include <stdio.h>
int main() {
    long long n, a, b;
    scanf("%lld %lld %lld", &n, &a, &b);
    if (n > 1 && b >= a || n == 1 && a == b) printf("%lld", (n - 2) * (b - a) + 1);
    else printf("0"); 
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
private static Scanner s = new Scanner(System.in);

public static void main(String[] args) {
	 int n = s.nextInt();
     Node[] nodes = new Node[n];
     for (int i = 0; i < n; i++) {
         nodes[i] = new Node(i);
     }
     for (int i = 0; i < n; i++) {
         Node node = nodes[s.nextInt()];
         int left = s.nextInt();
         if (left != -1) node.setL(nodes[left]);
         int right = s.nextInt();
         if (right != -1) node.setR(nodes[right]);
         node.setSib();
     }
     Node root = null;
     for (int i = 0; i < n; i++) {
         if (nodes[i].parent == null) {
             root = nodes[i];
             break;
         }
     }
     root.setDep(0);
     for (int i = 0; i < n; i++) {
         nodes[i].setHei(0);
     }
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < n; i++) {
         sb.append("node ");
         sb.append(nodes[i].id);
         sb.append(": parent = ");
         if(nodes[i].parent == null) {
        	 sb.append(-1);
         }else {
        	 sb.append(nodes[i].parent.id);
         }
         sb.append(", sibling = ");
         if(nodes[i].sibling ==null) {
        	 sb.append(-1);
         }else {
        	 sb.append(nodes[i].sibling.id);
         }
         sb.append(", degree = ");
         sb.append(nodes[i].deg);
         sb.append(", depth = ");
         sb.append(nodes[i].dep);
         sb.append(", height = ");
         sb.append(nodes[i].hei);
         sb.append(", ");
         if (nodes[i].parent == null) {
             sb.append("root");
         } else {
             if (nodes[i].l == null && nodes[i].r == null) {
                 sb.append("leaf");
             } else {
                 sb.append("internal node");
             }
         }
         sb.append("\n");
     }
     System.out.print(sb);
 }
}


class Node{
	int id,deg,dep,hei;
	Node parent,sibling,l,r;

	Node(int id){
		this.id = id;
		this.deg = 0;
		this.dep = 0;
		this.hei = 0;
		}

	void setL(Node node) {
		l = node;
		l.parent = this;
		deg++;
	}

	void setR(Node node) {
		r = node;
		r.parent = this;
		deg++;
	}

	void setSib() {
		if(l != null && r != null) {
			l.sibling = r;
			r.sibling = l;
		}
	}

	void setDep(int dep){
		this.dep = dep;
		if(l != null)l.setDep(dep + 1);
		if(r != null)r.setDep(dep + 1);
	}

	void setHei(int hei) {
		if(hei >= this.hei) this.hei = hei;
		if(parent != null)parent.setHei(this.hei + 1);
	}

	}



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

int main() {
  vector<int> A(9);
  rep(i, 9) cin >> A.at(i);
  int N;
  cin >> N;
  vector<int> B(N);
  rep(i, N){
    cin >> B.at(i);
    rep(j, 9){
      if(B.at(i)==A.at(j)) A.at(j)=0;
    }
  }
  if(A.at(0)==0 && A.at(1)==0 && A.at(2)==0) cout << "Yes" << endl;
  else if(A.at(3)==0 && A.at(4)==0 && A.at(5)==0) cout << "Yes" << endl;
  else if(A.at(6)==0 && A.at(7)==0 && A.at(8)==0) cout << "Yes" << endl;
  else if(A.at(0)==0 && A.at(3)==0 && A.at(6)==0) cout << "Yes" << endl;
  else if(A.at(1)==0 && A.at(4)==0 && A.at(7)==0) cout << "Yes" << endl;
  else if(A.at(2)==0 && A.at(5)==0 && A.at(8)==0) cout << "Yes" << endl;
  else if(A.at(0)==0 && A.at(4)==0 && A.at(8)==0) cout << "Yes" << endl;
  else if(A.at(2)==0 && A.at(4)==0 && A.at(6)==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())
s = 0
for i in range(N):
    s = A[i] - s
x = s//2
B = [0]*N
s = x
for i in range(N):
    B[i] = s*2
    s = A[i] - s
print(*B)


Measured memory_bytes: 14092
// Ki
// 所要時間 25分 (1WA)
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()

int main() {

    int n;
    cin >> n;
    vector<vector<int> > graph(n);
    rep(i, n){
        int u, k;
        cin >> u >> k;
        --u;
        rep(j, k){
            int v;
            cin >> v;
            graph[u].push_back(--v);
        }
    }

    queue<int> q;
    vector<int> dis(n, -1);
    q.push(0);
    dis[0] = 0;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        rep(i, graph[v].size()){
            int u = graph[v][i];
            if(dis[u] == -1){
                dis[u] = dis[v] + 1;
                q.push(u);
            }
        }
    }

    rep(i, n){
        cout << i+1 << " " << dis[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3152
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define T3I tuple<int, int, int>
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

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

    string N;
    cin >> N;
    int n = N.size();
    ll res = 0;
    ll pre = 0;
    for(int i = n-1; i >= 0; --i) {
        ll cur = N[i]-'0'+pre;
        if(cur < 5) {
            res += cur;
            pre = 0;
        }else if(cur > 5) {
            pre = 1;
            res += 10-cur;
        }else {
            if(pre == 0) {
                if(i > 0 && N[i-1]-'0' >= 5) {
                    pre = 1;
                    res += 5;
                }else {
                    res += 5;
                }
            }else {
                if(i > 0 && N[i-1]-'0' >= 5) {
                    pre = 1;
                    res += 5;
                }else {
                    pre = 0;
                    res += 5;
                }
            }
        }
    }
    res += pre;
    cout << res << endl;
}


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

using namespace std;

int main() {
  long long n;
  scanf("%lld", &n);
  for (int a = 1; a <= 3500; ++a) {
    for (int b = 1; b <= 3500; ++b) {
      long double da = (long double)n / a;
      long double db = (long double)n / b;
      long double v = 4 - da - db;
      if (v < 1e-11) {
        continue;
      }
      long double d = n / v;
      long long x = (long long)d;
      if (x == 0 || fabs(x - d) > 1e-11) {
        continue;
      }
      printf("%d %d %lld\n", a, b, x);
      return 0;
    }
  }
  assert(false);
}

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

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

using namespace std;

int main(){
	int a[5];
	rep(i,5) cin>>a[i];

	sort(a,a+5);

	int ans=700;
	do{
		int tmp=0;
		rep(i,4) tmp+=(a[i]%10==0?a[i]:(a[i]/10+1)*10);
		tmp+=a[4];
		ans=min(ans,tmp);
	}while(next_permutation(a,a+5));
	cout<<ans<<endl;

	return 0;
}


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

int main(){
    ll x,y,total=0;
    cin >> x >> y;
    if(x==1&&y==1){
        total=1000000;
    }else{
        if(x==3){
            total+=100000;
        }
        if(x==2){
            total+=200000;
        }
        if(x==1){
            total+=300000;
        }
        if(y==3){
            total+=100000;
        }
        if(y==2){
            total+=200000;
        }
        if(y==1){
            total+=300000;
        }
    }
    
    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
//from Kuugo
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
 
int nn,mm,n,l[N],r[N],f[N],g[N],ans;
 
struct node{int x,y;}a[N];
vector<node> ql,qr;
bool cmp(node a,node b){return a.y<b.y;}

int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}

void build(int t,int x,int y){
	l[t]=x;r[t]=y;f[t]=0;g[t]=0;
	if (x==y){f[t]=nn-a[x].y;return;}
	build(2*t,x,(x+y)/2);
	build(2*t+1,(x+y)/2+1,y);
	f[t]=max(f[2*t],f[2*t+1]);
}
 
void modify(int t,int x,int y,int z){
	if (x<=l[t]&&y>=r[t]) {f[t]+=z;g[t]+=z;return;};
	if (x<=r[2*t]) modify(2*t,x,y,z);
	if (y>=l[2*t+1]) modify(2*t+1,x,y,z);
	f[t]=max(f[2*t],f[2*t+1])+g[t];
}
 
void solve(){
	sort(a+1,a+n+1,cmp);
	build(1,0,n);
	ql.clear();ql.push_back((node){0,-1});ql.push_back((node){0,0});
	qr.clear();qr.push_back((node){nn,-1});qr.push_back((node){nn,0});
	for (int i=1;i<=n;i++){
		ans=max(ans,(f[1]+a[i].y)*2);
		if (a[i].x<=nn/2){
			for (int j=ql.size()-1;j&&ql[j].x<=a[i].x;ql.pop_back(),j--)
				modify(1,ql[j-1].y+1,ql[j].y,ql[j].x-a[i].x);
			ql.push_back((node){a[i].x,i-1});
		}
		else {
			for (int j=qr.size()-1;j&&qr[j].x>=a[i].x;qr.pop_back(),j--)
				modify(1,qr[j-1].y+1,qr[j].y,a[i].x-qr[j].x);
			qr.push_back((node){a[i].x,i-1});
		}
		ql.push_back((node){0,i});
		qr.push_back((node){nn,i});
	}
	ans=max(ans,(f[1]+mm)*2);
}
int main(){
	nn=read();mm=read();n=read();
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	solve();
	for (int i=1;i<=n;i++) swap(a[i].x,a[i].y);
	swap(mm,nn);solve();
	printf("%d\n",ans);
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  } //N個の数字を配列vecとして取得
  
  sort(vec.begin(), vec.end()); // vecを小さい順に並べる
  reverse(vec.begin(), vec.end()); // vecを大きい順に並べる
  
   vector<int> vec1(N-1);
  
  for (int i = 0; i < N-1; i++) {
   vec1.at(i) = vec.at(i+1) - vec.at(i);
  } //N-1個の差を取得する
  
  int S;
  S = 0;
  
  for (int i = 0; i < N-1; i++) {
   if (vec1.at(i) == 0) {
    S = S + 1;
   }
   else { 
   }
  } 
    
  cout << N - S << endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll n;
vl a;
vl b;
ll ans = 0;
ll cnt;

void error(){
  cout << -1 << endl;
  exit(0);
}

int main(){
  cin >> n;
  a = vl(n);
  b = vl(n);
  for(ll i = 0;i < n;i++) cin >> a[i];
  for(ll i = 0;i < n;i++) cin >> b[i];
  for(ll i = 0;;i = (i+1)%n){
    ll prv = (i-1+n)%n;
    ll nxt = (i+1)%n;
    if(b[i] > b[prv] && b[i] > b[nxt] && b[i] > a[i]){
      ll ope = (b[i]-a[i])/(b[prv]+b[nxt]);
      if(ope > 0) cnt = 0;
      ans += ope;
      b[i] = (b[i]-a[i])%(b[prv]+b[nxt])+a[i];
    }
    if(cnt >= n+1) break;
    cnt++;
  }
  // for(ll i = 0;i < n;i++){
  //   cerr << b[i] << " ";
  // }
  // cerr << endl;
  for(ll i = 0;i < n;i++){
    if(a[i] != b[i]) error();
  }
  cout << ans << endl;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string S; cin >> S;
    string T; cin >> T;

    int i = S.length()-T.length(), j = 0;
    while(i >= 0 && j < T.length())
    {
        if(S[i+j] == '?' || S[i+j] == T[j])
        {
            j++;
        }
        else
        {
            i--;
            j = 0;
        }
        if(j == T.length())
        {
            S.replace(i, T.length(), T);
            REP(i, S.length()) if(S[i] == '?') S[i] = 'a';
            cout << S << endl;
            return;
        }
    }
    cout << "UNRESTORABLE" << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll solve(vector<ll>&arr,ll s,ll e,vector<vector<ll>>&dp){
    if(s>e)
        return 0;
    
    if(dp[s][e]!=-1)
        return dp[s][e];
    dp[s][e] = max(arr[s]+min(solve(arr,s+2,e,dp),solve(arr,s+1,e-1,dp)),arr[e]+min(solve(arr,s+1,e-1,dp),solve(arr,s,e-2,dp)));
    
    return dp[s][e];
}
int main() {
	// your code goes here
	ll n;
	cin>>n;
	vector<ll> arr(n);
	ll sum1=0;
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	    sum1+=arr[i];
	}
	vector<vector<ll>>dp(n+1,vector<ll>(n+1,-1));
	ll p1 = solve(arr,0,n-1,dp);
	ll p2 = sum1-p1;
	cout<<p1-p2<<endl;
	return 0;
}


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

const int N = 1e6 + 100;

int to[N][26];
int pre[N][26];
int tot = 1;
long long ans;

void add(string s) {
//    cout << "s: " << s << endl;
    int cur = 1;
    vector<int> nodes;
    for(int i = 0; i < s.size(); i++) {
        int c = s[i] - 'a';
        nodes.push_back(cur);
        if(!to[cur][c]) to[cur][c] = ++tot;
        cur = to[cur][c];
    }
    int add = pre[nodes.back()][s.back()-'a'];
    ans += add;
//    cout << "add: " << add << endl;
    vector<bool> F(26);
    for(int i = (int)s.size()-1, j = (int)nodes.size()-1; j >= 0; i--, j--) {
        int c = s[i]-'a';
        F[c] = true;
        for(int k = 0; k < 26; k++) {
            if(F[k]) pre[nodes[j]][k]++;
        }
    }
}

bool cmp(string &s1, string &s2) {
    return s1.size() > s2.size();
}

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<string> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end(), cmp);
    for(int i = 0; i < n; i++) {
        reverse(v[i].begin(), v[i].end());
        add(v[i]);
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 207512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=100010;
int d[N],n,m,vis[N];
multiset<int>se[N];
int main()
{
	n=gi();m=gi();
	for(int i=1;i<=m;i++)
	{
		int u=gi(),v=gi();
		d[u]++;d[v]++;
		se[u].insert(v);
		se[v].insert(u);
	}
	for(int i=1;i<=n;i++)if(d[i]&1)return puts("No"),0;
	int huan=0;
	for(int i=1;i<=n;i++)
	{
		if(se[i].size()!=2)continue;
		vis[i]=1;
		multiset<int>::iterator id;
		id=se[i].begin();
		int v1=*id;id++;int v2=*id;
		se[v1].erase(se[v1].find(i));
		se[v2].erase(se[v2].find(i));
		if(v1==v2)huan++;
		else se[v1].insert(v2),se[v2].insert(v1);
		se[i].clear();
	}
	int Del=0,Max=0;
	for(int i=1;i<=n;i++)
		if(!vis[i])Del++,Max=max(Max,(int)se[i].size());
	huan+=Max/2;
	if(huan>=3 || Del>=3)return puts("Yes"),0;
	puts("No");
	return 0;
}


Measured memory_bytes: 15104
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<ll, ll> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 2010;
const int MAXM = 10010;
const int MAXK = 110;
const int MAXQ = 200010;
const int MAX = 1000000000;
const int oo = 0x3c3c3c3c;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    if (a > 9 || b > 9) cout << -1;
    else cout << a * b;
    return 0;
}


Measured memory_bytes: 256