akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		executeA();
	}

	private static void executeA() {

		Scanner sc = new Scanner(System.in);

		String s1 = sc.nextLine();
		String[] s1Array = s1.split(" ");

		try {
			int n = Integer.parseInt(s1Array[0]);
			int m = Integer.parseInt(s1Array[1]);

			int count = (n*(n-1) + m*(m-1))/2;
			PrintWriter pw = new PrintWriter(System.out);
			pw.println(count);
			pw.flush();
			pw.close();
		} catch (NumberFormatException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define debug(a,b) cerr << #a<<" = "<<a<<"   |   "<<#b<<" = "<<b<<'\n'
#define endl '\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const int MX = 1e4+7;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	string s,t;
	cin>>s>>t;
	int cnt=0;
	for(int i=0;i<SZ(s);i++){
		if(s[i]!=t[i])cnt++;
	}
	cout<<cnt<<endl;
	
	return 0;
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000

int main(){
  string S, s;
  getline(cin,s);
  stringstream SS(s);
  stack<int> A;
  int a,b;

  while (getline(SS,S,' ')){
    if (S=="+"){
      b = A.top(); A.pop();
      a = A.top(); A.pop();
      A.push(a+b);
    }
    else if (S=="-"){
      b = A.top(); A.pop();
      a = A.top(); A.pop();
      A.push(a-b);
    }
    else if (S=="*"){
      b = A.top(); A.pop();
      a = A.top(); A.pop();
      A.push(a*b);
}
    else{
      A.push(stoi(S));
    }
  }
  cout << A.top() << endl;

  return 0;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 998244353
#define inf 1e18 
 
using namespace std;

signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n;
    cin>>n;
    n=n%10;
    if(n==3) cout<<"bon";
    else if(n==0||n==1||n==6||n==8) cout<<"pon";
    else cout<<"hon";
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll H, W, K;
    cin >> H >> W >> K;
    vector<string> grid(H);
    rep(i, H) cin >> grid[i];
    ll ans = 0;
    rep(i, 1 << H) {
        rep(j, 1 << W) {
            vector<ll> h, w;
            rep(k, H) {
                if (i & (1 << k)) {
                    h.push_back(k);
                }
            }
            rep(k, W) {
                if (j & (1 << k)) {
                    w.push_back(k);
                }
            }
            vector<string> red = grid;
            for (ll x: h) {
                rep(j2, W) {
                    red[x][j2] = 'X';
                }
            }
            for (ll y: w) {
                rep(i2, H) {
                    red[i2][y] = 'X';
                }
            }
            ll cnt = 0;
            rep(a, H) {
                rep(b, W) {
                    if (red[a][b] == '#') cnt++;
                }
            }
            if (cnt == K) {
                ans++;
            }
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3656
/* ?  ?        ????????????????         ? ? ?            ????????????????               ??     ??        ? ? ?           ???????        
		?             ??              ?       ?                 ??                      ??   ??        ?       ?        ??    ??     
   		 ?            ??             ?         ?                ??                      ?? ??         ?         ?      ??     ??         
  ?????????           ??             ?         ?                ??                      ??            ?         ?     ??      ??         
		 ?            ??             ?         ?                ??                      ?? ??         ?         ?   ??????????????                    
		?             ??              ?       ?                 ??                      ??   ??        ?       ?    ??          ??         
   ?  ?               ??                ? ? ?                   ??                      ??     ??        ? ? ?     ??           ??          
 
 
    ??     ?        ??    ?   ?   ?  ?   ??          ?  ?      ??     ?    ?    ????????  ?    ?                       
   ?      ? ?      ?  ?    ???    ????  ?  ?         ????     ?  ?    ?  ? ?       ??     ?  ? ?                       
   ?     ?   ?     ?  ?    ???    ?  ?  ?  ?         ?  ?    ??????   ? ?  ?       ??     ? ?  ?                 
    ??  ?     ?     ??    ?   ?   ?  ?   ??          ?  ?   ?      ?  ?    ?       ??     ?    ?                                      
                                                                                       
     ?      ?????    ??????    ?  ?    ???           ???????     ???     ????????    ???????       ?? ??      ?? ??     ??????????    ??                                                                               
    ? ?     ?        ??        ? ?   ?     ?         ??   ??   ?     ?      ??       ??            ??  ??    ??  ??         ??        ?? 
   ?   ?    ?????    ??        ??    ?     ?         ??   ??   ?     ?      ??       ???????       ?? ??      ?? ??         ??        ?? ??                                                           
  ?     ?   ?        ??        ? ?   ?     ?         ??   ??   ?     ?      ??       ??            ??        ??  ??         ??        ??  ?? 
 ?       ?  ?????    ??        ?  ?    ???           ??   ??     ???        ??       ????????      ??       ??   ??         ??        ?? ??                         
 
 
 
 
 
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef double dou;
typedef string str;

 
#define pb push_back
#define F first
#define S second
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end() 
 
int n,m,y,cnt = 1,l,r;
int sum;
int a[1000005];
vector <int> v;
str s,c;

 
 
int main () {
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++){
		if (a[i] == cnt){
			cnt++;
			sum++;
		}
	}
	if (sum > 0){
		cout << n - sum;
	}
	else {
		cout << -1;	
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r;
ll x[500005],y[500005],z[500005];
ll dp[30][4005];
//bool check[5005];
char s[500005],t[500005];
bool flag,dame;

ll  fact[400005];
ll rfact[400005];
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<200000; i++){
        fact[i] = (fact[i-1]*i) % mod;
        rfact[i] = rui(fact[i],mod - 2);
    }
}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;
}

int main(){
	cin >> a >> b >> c;
	p(b*(c/a));
	return 0;
}

Measured memory_bytes: 25724
#include<iostream>
using namespace std;
int main()
{
	int h,w,x=0,y=0;
	cin>>h>>w;
	char array[h][w];
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>array[i][j];
		}
	}
	char array1[h+2][w+2];
	for(int i=0;i<w+2;i++)
	{
		array1[0][i]='#';
		array1[h+1][i]='#';
	}
	for(int i=1;i<h+1;i++)
	{
		array1[i][0]='#';
		array1[i][w+1]='#';
	}
	for(int i=1;i<h+1;i++)
	{
		for(int j=1;j<w+1;j++)
		{
			array1[i][j]=array[x][y];
			y++;
			
		}
		x++;
		y=0;
	}
	for(int i=0;i<h+2;i++)
	{
		for(int j=0;j<w+2;j++)
		{
			cout<<array1[i][j];
		}
		cout<<endl;
	}
}

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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> inline constexpr auto sqr(T x) { return (x) * (x); }
void printd(double x) { printf("%.10lf\n", x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const int INF = INT_MAX;

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

	int odd = 1;
	rbf(s, S) {
		if (odd > 0) {
			if (s == 'L') {
				COL("No");
				return 0;
			}
		}
		else {
			if (s == 'R') {
				COL("No");
				return 0;
			}
		}
		odd *= -1;
	}

	COL("Yes");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#define pb push_back
using namespace std;

long long n;

long long a,b,c;

long long gcd(long long x,long long y)
{
    long long q,temp;
    long long r,oldr;

    oldr=x;
    r=y;

    while(r!=0)
    {
        q=oldr/r;

        temp=r;
        r=oldr-q*r;
        oldr=temp;
    }

    return oldr;
}

int main()
{
   long long _gcd;
   long long nok;
   long long i,j;

   long long curn;

   cin>>n;

   for(i=1;i<=3500;i++)
   {
       for(j=i;j<=3500;j++)
       {
           _gcd=gcd(i,j);

           nok=(i*j)/_gcd;

           _gcd=gcd(nok,n);

           nok=(nok*n)/_gcd;

           curn=4LL*(nok/n);

           a=i;
           b=j;

           if(nok/a + nok/b >= curn)
            continue;

           c=curn - (nok/a + nok/b);

           if(nok % c == 0)
           {

               c=nok/c;

               cout<<a<<" "<<b<<" "<<c<<endl;


               return 0;
           }
       }
   }



   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
typedef long long ll;
bool vis[N];
int n,k;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++)
    {
        int x;scanf("%d",&x);
        while(x--)
        {
            int y;scanf("%d",&y);vis[y]=true;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        if(!vis[i]) ans++;
    printf("%d\n",ans);
}


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

int main(){
    int n, m;cin>>n>>m;
    vector<int> points(m); for (int i=0;i<m;i++){cin>>points[i];}
    sort(points.begin(), points.end());
    if (n >= m){
        cout << 0 << endl;
        return 0;
    }

    vector<int> diff;
    for (int i=1;i<m;i++){
        diff.push_back(points[i] - points[i-1]);
    }
    sort(diff.rbegin(), diff.rend());

    long long acc=0;
    for (int i=0;i<n-1;i++){
        acc += diff[i];
    }
    cout << (points.back() - points[0]) - acc <<endl;
    return 0;

}

Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long power = 1;

		for (int i = 1; i < n + 1; i++) {
			power *= i;
			power %= 1000000007;
		}
		System.out.println(power);
	}
}

Measured memory_bytes: 21844
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC122.B
{
    class Program
    {
        static void Main()
        {
            var sc = new Scanner();
            var S = sc.Next();
            var count = 0;
            var maxCount = 0;
            foreach (var ch in S)
            {
                if ("ACGT".Contains(ch))
                {
                    count++;
                    maxCount = Math.Max(maxCount, count);
                }
                else
                {
                    count = 0;
                }
            }
            Console.WriteLine(maxCount);
        }
    }

    class Scanner
    {
        string[] s;
        long i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public int Nextint()
        {
            return int.Parse(Next());
        }
        public int[] Arrayint(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Nextint() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }

        public double[] ArrayDouble(long N, double add = 0)
        {
            double[] Array = new double[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }

        public decimal NextDecimal()
        {
            return decimal.Parse(Next());
        }

        public decimal[] ArrayDecimal(long N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDecimal();
            }
            return Array;
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using vi = vector<int>;

int main() {
	int n;
	cin >> n;
	vi a(n);
	int sup = -1 << 20;
	int inf = 1 << 20;
	for (int & x : a) {
		cin >> x;
		sup = max(sup, x);
		inf = min(inf, x);
	}
	int si;
	int ii;
	for (int i = 0; i < n; i++) {
		if (a[i] == inf) {
			ii = i+1;
		}
		if (a[i] == sup) {
			si = i+1;
		}
	}
	if (-inf < sup) {
		cout << 2 * n - 2 << endl;
		for (int i = 1; i <= n;i++) {
			if (i != si) {
				cout <<si<<" "<< i << endl;
			}
		}
		for (int i = 1; i <= n - 1; i++) {
			cout << i << " " << i + 1 << endl;
		}
	}
	else {
		cout << 2 * n - 2 << endl;
		for (int i = 1; i <= n;i++) {
			if (i != ii) {
				cout <<ii<<" "<< i << endl;
			}
		}
		for (int i = n; i > 1; i--) {
			cout << i << " " << i - 1 << endl;
		}
	}
}

Measured memory_bytes: 256
//94 B - Toll Gates 2018/04/14

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n , m , x;
    cin >> n >> m >> x;
    vector<int> a(m,0);
    rep(i ,m) cin >> a[i];
    //0に向かうかN-1に向かうか　2通りを考えて小さいほうが答え

    a.push_back(x);
    sort(a.begin(),a.end());
    int i=0;int fee_to_zero=0;
    while(a[i]!=x){
        ++fee_to_zero; ++i;  
    }
    i=m;int fee_to_n=0;
    while(a[i]!=x){
        ++fee_to_n; --i;
    }
    cout << min(fee_to_zero,fee_to_n) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll field[305][305]={0};
int main(){
  ll h,w,k;
  cin>>h>>w>>k;
  ll cnt=1;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      char c;
      cin>>c;
      if(c=='#'){
        field[i][j]=cnt;
        cnt++;
      }
    }
  }

  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(field[i][j]==0) field[i][j]=field[i-1][j];
    }
  }

  for(int i=h;i>=1;i--){
    for(int j=1;j<=w;j++){
      if(field[i][j]==0) field[i][j]=field[i+1][j];
    }
  }

  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(field[i][j]==0) field[i][j]=field[i][j-1];
    }
  }

  for(int i=1;i<=h;i++){
    for(int j=w;j>=1;j--){
      if(field[i][j]==0) field[i][j]=field[i][j+1];
    }
  }

  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cout<<field[i][j]<<" ";
    }
    cout<<endl;
  }

}


Measured memory_bytes: 1536
//intのオーバーフローに気をつけろ,AGCはだいたいlongにしておけ
//毎回余りを求めることでオーバーフローしなくなる
//nextLineよりnextだ
//charは''で囲うんだぞ
//読み込みは先に全部やっておけ
//for文を回す回数に気をつけろ
	//for文は10^3の三重はTLE,10^5の二重はTLE,10^9のforはTLE
//貪欲は使えるか？？試した？？

import java.util.Scanner;

public class Main {

	public static void main(String args[]) throws InterruptedException {
		    Scanner sc = new Scanner(System.in);

		    int n = sc.nextInt(); //都市
		    int m = sc.nextInt(); //道
		    int[] road = new int[2*m];
		    int[] counter = new int[n];
		    for(int i = 0; i < 2 * m; i++) {
		    	road[i] = sc.nextInt();
		    }
		    for(int i = 0; i < n; i++) {
		    	counter[i] = 0;
		    }
		    //入力
		    
		    for(int i = 0; i < 2*m; i++) {
		    	counter[road[i]-1]++;
		    }
		    //シミュレート
		    
		    for(int i = 0; i < n; i++) {
		    	System.out.println(counter[i]);
		    }
		    //出力
		    sc.close(); }

	public static void saiki(int a, String b) {
		//再帰コーディングのお手本

		if(a == 0) {
			System.out.println(b);
		}else {
			for(char ch = 'a'; ch <= 'c'; ch++) {
				saiki(a-1,b + ch);
			}
		}
	}

	public static  int gcd(int a, int b) {
	    if (a < b) {
	        int tmp = a;
	        a = b;
	        b = tmp;
	    }

	    int r = -1;
	    while (r != 0) {
	        r = a % b;
	        a = b;
	        b = r;
	    }

	    return a;
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,n;
  string s;
  cin>>k>>n>>s;
  if(s.at(n-1)=='A'){
    s.at(n-1)='a';
  }
  if(s.at(n-1)=='C'){
    s.at(n-1)='c';
  }
  if(s.at(n-1)=='B'){
    s.at(n-1)='b';
  }
  cout<<s<<endl;
}

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

signed main() {
	int n;
	cin >> n;
	vector<tuple<string, int, int>> a(n);
	for (int i = 0; i < n; ++i) {
		string s;
		int p;
		cin >> s >> p;
		a[i] = make_tuple(s, p, i);
	}

	sort(a.begin(), a.end());
	vector<pair<int, int>> r(n);

	int curN = 0;

	for (int i = 1; i < n; ++i) {
		if (get<0>(a[i - 1]) != get<0>(a[i])) {
			reverse(a.begin() + curN, a.begin() + i);
			curN = i;
		}
	}

	reverse(a.begin() + curN, a.end());



	for (int i = 0; i < n; ++i) {
		cout << get<2>(a[i]) + 1 << endl;
	}

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
using namespace std;
using ll = long long;

signed main() {
    IO;
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll xor_val = 0, and_val;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        if(i > 1) xor_val ^= a[i];
    }
    if((a[0] + a[1] - xor_val < 0) || (a[0] + a[1] - xor_val) % 2 == 1) {cout << -1; return 0;}
    and_val = (a[0] + a[1] - xor_val) / 2;
    if((and_val & xor_val) != 0) {cout << -1; return 0;}
    
    ll a0 = 0, a1 = 0;
    bool pos = true;
    for(ll i = 45; i >= 0; --i) {
        ll two = 1ll << i;
        if(and_val & two) {
            a0 |= two; a1 |= two;
        }
    }
    for(ll i = 45; i >= 0; --i) {
        ll two = 1ll << i;
        if(xor_val & two) {
            ll new_a0 = a0 | two;
            if(new_a0 < a[0]) a0 = new_a0;
            else a1 |= two;
        }
    }
    DB(a0); DB(a1);

    if(a0 == 0) pos = false;
    if(a0 > a[0]) pos = false;
    if((a0 + a1) != (a[0] + a[1])) pos = false;
    if((a0 ^ a1) != xor_val) pos = false;
    if((a0 & a1) != and_val) pos = false;

    if(!pos) cout << -1;
    else cout << a[0] - a0;
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
#include <vector>

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

using namespace std;

vector<vector<long> > a;
long gp[100001];

long calc( long i )
{
    if( gp[i] >= 0 ) {
        return gp[i];
    }

    long max = 0;
    long size = a[i].size();
    long k;
    for(k=0; k<size; k++) {
        long tmp = calc( a[i][k] ) + 1;
        if(max < tmp)
            max = tmp;
    }

    return gp[i]=max;
}

int main(int argc, char* argv[])
{
    long n, m;
    scanf("%ld %ld", &n, &m);

    a.resize(n);
    long i;
    for(i=0; i<n; i++) {
        gp[i] = -1;
    }

    for(i=0; i<m; i++) {
        long x, y;
        scanf("%ld %ld", &x, &y);
        a[x-1].push_back(y-1);
    }

    long max = 0;
    for(i=0; i<n; i++) {
        long len = calc( i );
        if(max<len)
            max=len;
    }

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


Measured memory_bytes: 8576
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    int[] b = new int[number-1];
    int sum = 0;
      
    for(int i = 0; i < number-1; i++){
    	b[i] = sc.nextInt();
    }
    sum += b[0];
    for(int j = 0; j < number-2; j++){
       if(b[j] >= b[j+1]){
       	sum += b[j+1];
       }else{
       	sum += b[j];
       }
    }
      
    sum += b[number-2];
    System.out.println(sum);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(){
    int a, b;
    char op;
    while(1){
        scanf("%d %c %d", &a, &op, &b);
        if(op=='?'){
            break;
    	}else if(op=='+'){
    	    printf("%d\n", a+b);
    	}else if(op=='-'){
    	    printf("%d\n", a-b);
    	}else if(op=='*'){
    	    printf("%d\n", a*b);
    	}else if(op=='/'){
    	    printf("%d\n", a/b);
        }
    }
    return 0;
}

Measured memory_bytes: 2712
#ifndef CLASS_DISJOINT_SET
#define CLASS_DISJOINT_SET

#include <vector>
#include <cstdint>
#include <cstring>
#include <algorithm>

class disjoint_set {
private:
	typedef std::int32_t value_type;
	std::vector<value_type> val;
public:
	explicit disjoint_set() : val() {};
	explicit disjoint_set(std::size_t n) : val(n, -1) {};
	std::size_t size() const { return val.size(); }
	std::size_t size(std::size_t elem) { return std::size_t(-val[root(elem)]); }
	std::size_t root(std::size_t elem) {
		// path halving
		while (val[elem] >= 0 && val[val[elem]] >= 0) {
			val[elem] = val[val[elem]];
			elem = val[elem];
		}
		return std::size_t(val[elem] >= 0 ? val[elem] : elem);
	}
	void link(std::size_t elemx, std::size_t elemy) {
		elemx = root(elemx);
		elemy = root(elemy);
		if (elemx == elemy) return;
		if (val[elemx] > val[elemy]) {
			std::swap(elemx, elemy);
		}
		val[elemx] += val[elemy];
		val[elemy] = elemx;
	}
	bool connected(std::size_t elemx, std::size_t elemy) {
		return root(elemx) == root(elemy);
	}
};

#endif // CLASS_DISJOINT_SET

#include <iostream>
int main() {
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	int N, Q;
	std::cin >> N >> Q;
	disjoint_set ds(N);
	for (int i = 0; i < Q; ++i) {
		int tp, va, vb;
		std::cin >> tp >> va >> vb;
		if (tp == 0) {
			ds.link(va, vb);
		}
		else {
			std::cout << ds.connected(va, vb) << '\n';
		}
	}
	return 0;
}


Measured memory_bytes: 3220
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		while (n-- > 0) {
			Point2D.Double[] points = new Point2D.Double[5];
			for (int i = 0; i < 5; i++) {
				points[i] = new Point2D.Double(scanner.nextDouble(),
						scanner.nextDouble());
			}
			Path2D.Double path = new Path2D.Double();
			path.moveTo(points[0].x, points[0].y);
			path.lineTo(points[1].x, points[1].y);
			path.lineTo(points[2].x, points[2].y);
			if ((path.contains(points[3]) && path.contains(points[4]))
					|| !path.contains(points[3]) && !path.contains(points[4])) {
				System.out.println("NG");
			} else {
				System.out.println("OK");
			}
		}
	}
}

Measured memory_bytes: 104932
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        //大きいやつは捨てる
        List<int>[] neighbors = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < n - 1; i++)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            neighbors[ab[0]].Add(ab[1]);
            neighbors[ab[1]].Add(ab[0]);
        }
        var c = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
        var res = c.Take(n - 1).Sum();
        Stack<int> numbers = new Stack<int>(c);
        int[] values = new int[n];
        Stack<int> stack = new Stack<int>();
        stack.Push(0);
        values[0] = numbers.Pop();
        while (stack.Count > 0)
        {
            var elem = stack.Pop();
            foreach (var neighbor in neighbors[elem])
            {
                if (values[neighbor] != 0) continue;
                values[neighbor] = numbers.Pop();
                stack.Push(neighbor);
            }
        }
        Console.WriteLine(res);
        Console.WriteLine(string.Join(" ", values));
    }
}


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

int main(){
    string s;
    cin >> s;
    if(s=="SUN") cout << 7 << endl;
    if(s=="MON") cout << 6 << endl;
    if(s=="TUE") cout << 5 << endl;
    if(s=="WED") cout << 4 << endl;
    if(s=="THU") cout << 3 << endl;
    if(s=="FRI") cout << 2 << endl;
    if(s=="SAT") cout << 1 << endl; 
}

Measured memory_bytes: 256
/* include */
#include <bits/stdc++.h>
#include <boost/algorithm/string/trim.hpp>
#include <boost/range/algorithm.hpp>

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x)  \
    boost::sort(x); \
    (x).erase(unique(all(x)), (x).end())
#define mp make_pair

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int n;
    cin >> n;
    int vmid;
    int amid;
    int cnt = 0;
    vector<int> v(n);
    vector<int> av(3);
    rep(i, n)
    {
        cin >> v[i];
    }
    rep(i, n - 2)
    {
        for (int j = 0; j <= 2; ++j)
        {
            av[j] = v[i + j];
        }
        amid = av[1];
        sort(all(av));
        vmid = av[1];
        if (amid == vmid)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string.h>

int main()
{
    int a, b, c ,d, e, k;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);
    scanf("%d", &e);
    scanf("%d", &k);

    if (b-a <= k && c-a <= k && d-a <= k && e-a <= k &&
        c-b <= k && d-b <= k && e-b <= k && 
        d-c <= k && e-c <= k &&
        e-d <= k){

            printf("Yay!\n");
            return 0;
        }
        else{
            printf(":(\n");
            return 0;
        }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<string.h>
#include<functional>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<limits.h>
using namespace std;

int dp[100001][2];
int b[100000];
signed main() {
	memset(dp, 0x3f, sizeof(dp));//増加　減少
	dp[0][0] = dp[0][1] = 1;
	int a; scanf("%d", &a);
	for (int c = 0; c < a; c++) {
		scanf("%d", &b[c]);
	}
	for (int i = 0; i < a-1; i++) {
		dp[i + 1][0] = dp[i + 1][1] = min(dp[i][0], dp[i][1]) + 1;
		if (b[i] <= b[i + 1])dp[i + 1][0] = dp[i][0];
		if (b[i] >= b[i + 1])dp[i + 1][1] = dp[i][1];
	}
	cout << min(dp[a-1][0], dp[a-1][1]) << endl;
}

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

using namespace std;

int main(){
    int sum=0;
    int n,m;cin>>n>>m;
    while(m--){
        int a;
        cin>>a;
        sum+=a;
    }
    if(sum==n) cout<<0;
    else if(sum<n) cout<<n-sum;
    else cout<<-1;


return 0;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    stack<int> s1;
    stack<pair<int, int>> s2;
    char ch;
    int sum = 0;
    for(int i = 0; cin >> ch; i++) {
        if(ch == '\\') s1.push(i); // '\' ならばスタック位置情報iを積む
        else if(ch == '/' && s1.size() > 0) {
            int j = s1.top(); s1.pop();
            sum += i - j;
            int a = i - j;
            while(s2.size() > 0 && s2.top().first > j) {
                a += s2.top().second; s2.pop();
            }
            s2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    int t = 0;
    while(s2.size() > 0) {ans.push_back(s2.top().second); s2.pop(); }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i = 0; i < ans.size(); i++) {
        cout << " ";
        t += ans[i];
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3172
def solve():
  N = int(input())
  P = list(map(float, input().split()))
  dp = [[0]*(N+1) for _ in range(N+1)]
  dp[0][0] = 1
  for i in range(1,N+1):
    for j in range(i+1):
      dp[i][j] = dp[i-1][j-1]*P[i-1]+dp[i-1][j]*(1-P[i-1])
  ans = sum(dp[-1][N//2+1:])
  return ans
print(solve())

Measured memory_bytes: 204124
<?php
fscanf(STDIN,"%d%d%d",$h,$w,$k);
for($i=0;$i<$h;$i++){
  $gyo[] = str_split(trim(fgets(STDIN)));
}

function dfs(&$patern,$c,$n){
  if(strlen($c)==$n){
    $patern[] = $c;
    return;
  }
  for($i=0;$i<2;$i++){
    $c .= $i;
    dfs($patern,$c,$n);
    $c  = substr($c, 0, -1);
  }
  
}

$gyoretu = $h+$w;

$array = array();
dfs($array,"",$gyoretu);

//print_r($gyo);
$re = 0;

$black_c = 0;
foreach($array as $p){
  for($i=0;$i<$h;$i++){
    //echo $p."\n";
    if($p[$i]==1){
     // echo "hoge1";
      continue;
    }
    for($j=0;$j<$w;$j++){
      if($p[$h+$j]==1){
              //echo "hoge2";
        continue;
      }
            //echo $i."\n";

      if($gyo[$i][$j]=='#'){
        $black_c++;
      }
    }
    
  }
  if($black_c==$k){
      $re++;
   }
  //echo "blackc".$black_c."\n";
  $black_c = 0;

}
  echo $re;



Measured memory_bytes: 16328
from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]


g = Graph()
N, M = [int(i) for i in input().split()]
magic = [1 for i in range(N)]

for i in range(M):
    u, v, w = [int(i) for i in input().split()]
    g.add_edge(u-1, v-1, w)
    g.add_edge(v-1, u-1, w)
    magic[u-1] = 0
    magic[v-1] = 0
ans = sum(magic)

d = Dijkstra(g, 0)

for i in range(N):
    if magic[i] == 0:
        d = Dijkstra(g, i)
        ans += 1
        for j in d.dist.keys():
            #print(j)
            magic[j] = 1

print(ans)

Measured memory_bytes: 85804
#include <stdio.h>
int main () {
long long int M,N,b,c;
scanf("%lld %lld", &M, &N);
b=((2*M+N)-(2*M+N)%4)/4;
c=(N-N%2)/2;
if (N>=2*b) printf("%lld\n",b);
if (N<2*b) {
printf("%lld\n",c);
}
return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> V(N);
  vector<int> C(N);
  
  for (int i=0; i<N; i++){
    cin>>V.at(i);
  }
  
  for (int i=0; i<N; i++){
    cin>>C.at(i);
  }
  
  int total=0;
  for (int i=0; i<N; i++){
    if ((V.at(i)-C.at(i))>0){
      total+=V.at(i)-C.at(i);
    }
  }
  cout<<total<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int n, i, p;
	int flag = 0;

	scanf("%d", &n);

	//1,2,3...Nの並びと、与えられた数列Pで一致しない箇所があれば flag を 1 増やす
	for (i = 0; i < n; i++) {
		scanf("%d", &p);
		if (p != i + 1) {
			flag++;
		}
	}

	//flagが2以上のとき、昇順にできない
	if (flag > 2) {
		printf("NO\n");
	}
	else {
		printf("YES\n");
	}

	return 0;
}

Measured memory_bytes: 128
import bisect
Q = int(input())
lsQ = []
for i in range(Q):
    l,r = map(int,input().split())
    lsQ.append([l,r])
def prime(N):
    lsprime = [0,0]+[1 for i in range(N-1)]
    lsprime2 = []
    for i in range(N+1):
        if lsprime[i] == 0:
            continue
        lsprime2.append(i)
        k = i
        while i <= N:
            lsprime[i] = 0
            i += k
    return lsprime2

primels = prime(10**5)
primeset = set(primels)
lssim = []
for i in primels:
    x = (i+1)//2
    if x in primeset:
        lssim.append(i)
for i in range(Q):
    ans = bisect.bisect(lssim,lsQ[i][1])-bisect.bisect_left(lssim,lsQ[i][0])
    print(ans)

Measured memory_bytes: 25340
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pi 3.14159265358979323846264
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
int n, a[100005];
map <int, int> m;
int main() {
    scanf("%d", &n);
    for (int i=0;i<n;i++) scanf("%d", &a[i]), m[a[i]]++;
    sort (a, a+n);
    bool found = false;
    int x = 0;
    for (int i=n-1;i>=0;i--) {
        if (a[i]==a[i-1]) continue;
        if (!found) {
            if (m[a[i]]>=4) {
                printf("%lld\n", 1LL * a[i] * a[i]);
                return 0;
            } else if (m[a[i]]>=2) {
                x = a[i];
                found = true;
            }
        } else {
            if (m[a[i]]>=2) {
                printf("%lld\n", 1LL * x * a[i]);
                return 0;
            }
        }
    }
    printf("0\n");
    return 0;
}

Measured memory_bytes: 5376
from bisect import bisect_left
from operator import itemgetter

N, Q = map(int, input().split(" "))
check_points = [tuple(map(int, input().split(" "))) for _ in range(N)]
querys = [int(input()) for _ in range(Q)]
time = [-1] * Q
jump = [-1] * Q
check_points = sorted(check_points, key=itemgetter(2))
b_left = bisect_left

for line in check_points:
    s, f, x = line
    start = s-x
    end = f-x
    left = b_left(querys, start)
    right = b_left(querys, end)
    while left < right:
        if time[left] == -1:
            time[left] = x
            jump[left] = right
            left += 1
        else:
            left = jump[left]

for t in time:
    print(t)


Measured memory_bytes: 54024
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> dp(n+1,INF);
    dp[0] = 0;
    Rep(i, 1, n+1){
        //1円
        chmin(dp[i], dp[i-1] + 1);
        //6円の乗数
        ll yen = 6;
        while(i - yen >= 0){
            chmin(dp[i], dp[i-yen] + 1);
            yen *= 6;
        }
        yen = 9;
        while(i - yen >= 0){
            chmin(dp[i], dp[i-yen] + 1);
            yen *= 9;
        }
    }
    pr(dp[n]);
}

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

#define MOD 1000000007

using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long g(int r, int c){
    long ans = 0;
    long a = c+1;
    for(long i=0; i<r+1; i++){
        ans += a;
        ans %= MOD;
        a *= (c + i + 2);
        a %= MOD;
        a *= modinv(i+2, MOD);
        a %= MOD;
    }
    return ans;
}


int main(){
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    long ans = 0;
    cout << (g(r2, c2) - g(r1-1, c2) - g(r2, c1-1) + g(r1-1, c1-1) + MOD) % MOD << endl;
    return 0;
}

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

#define rep(i,end)          rep2(i,0,(end))
#define rep2(i,beg,end)   for (int i=(beg);i<(end);i++)
#define all(cont)           begin(cont), end(cont)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);
vi get_n_array(int n);


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a = get_n_array(n+1);
    vi b = get_n_array(n);
    b.push_back(0);
    ll kill = 0;
    ll rest = 0;
    rep(i, a.size())
    {
        ll enemy = max(a[i] - rest, 0LL);
        rest = max(b[i] - enemy, 0LL);
        enemy = max(enemy - b[i], 0LL);
        kill += a[i] - enemy;
    }
    cout << kill << endl;
    return 0;
}

string gets(bool skipToNextline)
{
    if (skipToNextline) gets(false);
    const int LINE_MAX = 1024;
    char buf[LINE_MAX];
    cin.getline(buf, sizeof(buf));
    return buf;
}

vi get_n_array(int n)
{
    vi v;
    while (n-- > 0) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    return v;
}

Measured memory_bytes: 2676
#include <stdio.h>

//関数のプロトタイプ宣言
void swap(int *a, int *b);

//メイン関数
int main(void){
  int x, y;
  int i = 1;
  while(1){
    scanf("%d %d", &x, &y);
    if(x == 0 && y == 0) {
      break;
    }
    if(x > y){
      swap(&x, &y);
    }
    printf("%d %d\n", x, y);
    i++;
  }
  return 0;
}

//swap関数
void swap(int *a,int *b){
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
  return;
}


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

const int N = 15;
int n,d;
int a[N][N];

int issqr(int x) {
	int t = sqrt(x);
	for(int i = t-2; i <= t + 2; i++) if(i * i == x) return 1;
	return 0;
}
int dis(int i, int j) {
	int ans = 0;
	for(int k = 1; k <= d; k++)
		ans += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
	return ans;
} 
int main(){
	scanf("%d%d", &n, &d);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= d; j++) scanf("%d", &a[i][j]);
	
	int cnt = 0;
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			if(issqr(dis(i, j))) ++cnt;
	cout << cnt << endl;
	return 0;
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var s = Input().ToInt();
		foreach(var c in new int[]{s[0], s[1], s[0]+s[1]})
		{
			if(c%3==0)
			{
				Console.WriteLine("Possible");
				return;
			}
		}
		Console.WriteLine("Impossible");
		
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define ri register int
using namespace std;
const int rlen=1<<18|1;
inline char gc(){
	static char buf[rlen],*ib,*ob;
	(ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin));
	return ib==ob?-1:*ib++;
}
inline int read(){
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return ans;
}
const int mod=998244353;
typedef pair<int,int> pii;
typedef long long ll;
inline int add(int a,int b){return (a+=b)<mod?a:a-mod;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline int mul(int a,int b){return (ll)a*b%mod;}
inline void Add(int&a,int b){(a+=b)<mod?a:(a-=mod);}
inline void Dec(int&a,int b){(a-=b)<0?(a+=mod):a;} 
inline void Mul(int&a,int b){a=(ll)a*b%mod;}
inline int ksm(int a,int p){int ret=1;for(;p;p>>=1,Mul(a,a))if(p&1)Mul(ret,a);return ret;}
const int N=250005;
int main(){
	#ifdef ldxcaicai
	freopen("lx.in","r",stdin);
	#endif
	int a=read(),b=read(),cnt=0;
	for(ri i=2;i<10;++i)for(ri j=2;j<10;++j){
		if(i*10+j>b)continue;
		if(i*j<=a)++cnt;
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{

    ll i,j,c=0,n,a,b;
    //vector<ll>v;
   // double x;
    cin>>a>>b;
    if(2*b<a)
    {
        cout<<a-2*b;
    }
    else
        cout<<0<<endl;

    return 0;
}


Measured memory_bytes: 256