akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    string s;
    int Q;
    cin >> s >> Q;
    vector<pair<int, int>> A(Q);
    rep(i, Q) cin >> A[i].first >> A[i].second;
    // next[l][0]: s[l, r)が空となる最小のr
    // next[l]['#']: s[l, r)が"#"となる最小のr
    vector<vector<int>> next(s.size() + 1, vector<int>(27, inf));// "", a, b, c, ...
    
    for(int i = (int)s.size() - 1; i >= 0; i--){
        int ind = s[i] - 'a' + 1;
        // next[i][s[i]] = s[i] + 1
        next[i][ind] = i + 1;
        for(int j = (ind + 1) % 27; j != ind; j = (j + 1) % 27){
            if(j == 1) continue;
            int prev = (j + 26) % 27;
            if(next[i][prev] != inf){
                next[i][j] = min(next[i][j], next[next[i][prev]][prev]);
            }
        }
        if(next[i][0] != inf){
            rep(j, 1, 27){
                next[i][j] = min(next[i][j], next[next[i][0]][j]);
            }
        }
    }
    
    vector<vector<int>> D(20, vector<int> (s.size() + 1, inf));
    rep(i, s.size() + 1){
        D[0][i] = next[i][0];
    }
    rep(i, 19){
        rep(j, s.size() + 1){
            if(D[i][j] != inf){
                D[i + 1][j] = D[i][D[i][j]];
            }
        }
    }
    
    rep(i, Q){
        int l = A[i].first - 1, r = A[i].second;
        for(int j = 19; j >= 0; j--){
            if(D[j][l] <= r) l = D[j][l];
//            cout << l << ", " << j << ":" << D[j][l] << endl;
        }
//        cout << i << ":" << l << "," << r << endl;
        if(l == r){
            output("Yes");
        }
        else output("No");
    }
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 116892
/**
    Submitting by the name of Maa Sarashwati and Maaa Bishwakarma.
 **/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int k,n;
    cin>>k>>n;
    if(k*500>=n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define N 100010
#define D 18
ll n,q;
struct edge{
  ll to,cost,col;  
};
edge edges(ll to,ll cost,ll col){
    edge gen;gen.to=to,gen.cost=cost,gen.col=col;
    return gen;
}
vector<edge> g[N];
unordered_map<ll,ll> ddd[N],dddd[N];

ll dep[N],p[N];

namespace lca{
  ll t[N][D];
  void init(){
      for(int i=1;i<=n;i++)t[i][0]=p[i];
      for(int d=1;d<D;d++){
      for(int i=1;i<=n;i++){
          t[i][d]=t[t[i][d-1]][d-1];
      }
      }
  }
  ll ad(ll a,ll k){
      for(ll d=0;k!=0;d++){
      if(k&1)a=t[a][d];
      k>>=1;
      }
      return a;
  }
  ll qry(ll a,ll b){
      if(dep[a]<dep[b])swap(a,b);
      a=ad(a,dep[a]-dep[b]);
      if(a==b)return a;
      for(ll d=D-1;d>=0;d--){
      if(t[a][d]!=t[b][d]){
          a=t[a][d],b=t[b][d];
      }
      }
      return p[a];
  }
};

class rrr{
    public:
    ll len[N],rui[N];
  void dfs(ll x,ll from,ll sum,ll d){
    rui[x]=sum; dep[x]=d;
    for(auto y:g[x])if(y.to!=from){
	ll ccc=ddd[x][y.to];
    p[y.to]=x,len[y.to]=ccc;
    dfs(y.to,x,sum+ccc,d+1);
    }
  }
    void init(){
	dfs(1,0,0,0);
    }
    ll dist(ll a,ll b){
      ll c=lca::qry(a,b);
      return rui[a]+rui[b]-2*rui[c];
  }
};rrr lcaa,dat[510];

bool tochu(ll a,ll b,ll c,ll d){
    ll d1=lcaa.dist(a,b);
    ll d2=min(lcaa.dist(a,c),lcaa.dist(a,d));
    ll d3=min(lcaa.dist(d,b),lcaa.dist(c,b));
    ll d4=lcaa.dist(c,d);
    if(d1+d4==d2+d3||d1-d4==d2+d3)return 1;
    return 0;
}

#define B 300
vector<edge> e[N];
int main(){
  cin>>n>>q;
  for(int i=0;i<n-1;i++){
      ll a,b,c,d;cin>>a>>b>>c>>d;
      g[a].push_back(edges(b,d,c));
      g[b].push_back(edges(a,d,c));
      e[c].push_back(edges(a,b,d));
      ddd[a][b]=ddd[b][a]=d;
      dddd[a][b]=dddd[b][a]=d;
  }
  lcaa.init();
  lca::init();
  
  unordered_map<ll,ll> mas;
  ll p=0;
  for(int i=1;i<=n;i++){
      if(e[i].size()<B)continue;
      mas[i]=p;
      for(auto t:e[i]){
	  ddd[t.to][t.cost]=ddd[t.cost][t.to]=1e9;
      }
      dat[p].init();
      for(auto t:e[i]){
	  ddd[t.to][t.cost]=ddd[t.cost][t.to]=dddd[t.to][t.cost];
      }
      p++;
  }
  while(q--){
      ll a,b,c,d;cin>>a>>b>>c>>d;
      if(e[a].size()<B){
	  ll ans=lcaa.dist(c,d);
	  for(auto t:e[a]){
	      if(tochu(c,d,t.to,t.cost)==0)continue;
	      ans+=b;
	      ans-=dddd[t.to][t.cost];
	  }
	  cout<<ans<<endl;
      }
      else{
	  ll cur=dat[mas[a]].dist(c,d);//cout<<cur<<endl;
	  ll addi=cur/(ll)1e9*b;
	  cur%=(ll)1e9;
	  cout<<cur+addi<<endl;
      }
  }
  return 0;
}


Measured memory_bytes: 74216
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);
 
 
 
 
 
int main() 
{
  ll X,Y; cin>>X>>Y;
  rep(i,X+1)
  {
    ll t=X-i;
    if(2*i+4*t==Y)
    {
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define mp make_pair
#define pb push_back
void solve(){
	ll n;
	cin>>n;
	int i=0,j,f=0;
	for(;i<150;i++){
		j=-149;
		for(;j<=i;j++){
			if((ll)pow(i,5)-(ll)pow(j,5)==n){
				f=1;
				break;
				
			}
		}
		if(f)
			break;
	}
	cout<<i<<" "<<j<<endl;
	
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int T=1;
	//cin>>T;
	while(T--)
		solve();
}



Measured memory_bytes: 3996
from collections import deque
from bisect import bisect_left
import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]
nums = deque()
for i in range(N):
    j = bisect_left(nums, A[i])
    if j == 0:
        nums.appendleft(A[i])
    else:
        nums[j-1] = A[i]
print(len(nums))


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int [] a = new int[3];
        for (int i = 0; i < 3 ; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[0]*a[1]/2);
    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define s size
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0)
#define ll long long
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;

int main()
{IOS;
int t;
t=1;
while(t--)
{ll a[5],i;
for(i=0;i<5;i++)
{
    cin>>a[i];
   
}
for(i=0;i<5;i++)
{
    
    if(a[i]==0)
   { cout<<i+1;
   break;
   }
}
}
return 0;}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll q;
    cin >> q;
    vector<ll> b(q);
    vector<ll> c(q);
    rep(i,q){
        cin >> b[i] >> c[i];
    }
    ll total = 0;
    vector<ll> cnt(100001);
    rep(i,n){
        total += a[i];
        cnt[a[i]]++;
    }
    rep(i,q){
        total += cnt[b[i]]*(c[i]-b[i]);
        cnt[c[i]] += cnt[b[i]];
        cnt[b[i]] = 0;
        cout << total << endl;

    }

    return 0;
}

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

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

		if (n == 0) {
			break;
		}

		int count = 0;

		for (int i = 1; i <= n / 2; i++) {
			int sum = 0;
			int cur = i;
			while (sum < n) {
				sum += cur;
				cur++;
				if (sum == n) {
					count++;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 3080
import java.util.*;

public class Main {
	
	public static void main(String[] args) {

		// argumentの取得
		Scanner s = new Scanner(System.in);

		int x = s.nextInt();
        int y = s.nextInt();
        int z = s.nextInt();
      
        if (x + y == z || x == y + z || x + z == y) {
          System.out.println("Yes");
        } else {
          System.out.println("No");
        }
 
      
		// 戻り値の返却
		//System.out.println(x + y + z);
	
	} 
}

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

int main(void){
    
    string S;
    cin >> S;
    
    int count = 0;
    int ans = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'R') count++;
        else{
          ans = max(ans, count);
          count = 0;
        } 
    }
    ans = max(ans, count);
    cout << ans << endl;
}


Measured memory_bytes: 3144
#include<stdio.h>
#define N 100

int main()
{
  int i,j,n,p,q,r,A[N][N];
  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      A[i][j] = 0;
    }
  }
  for(i=0; i<n; i++){
    scanf("%d%d",&p,&q);
    for(j=0; j<q; j++){
      scanf("%d",&r);
      A[p-1][r-1] = 1;
    }
  }
   for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      if(j)printf(" ");
      printf("%d",A[i][j]);
    }
    printf("\n");
   }
   return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int N,M;
vector<int>G[10];
long long dp[10000];
long long dfs(int v,long long x){
     //cout<<"v"<<v<<x<<endl;
     //if(dp[x]!=-1)return dp[x];
     if(x==((1<<N)-1))return 1;
     long long ans=0;
     REP(i,G[v].size()){
         int t=G[v][i];
         if(((x>>t)&1)==0){
            ans+=dfs(t,x|(1<<t));
         }
     }
     dp[x]=ans;
     return ans;
}

int main(){
        cin>>N>>M;
        REP(i,M){
            int a,b;
            cin>>a>>b;
            a--;
            b--;
            G[a].push_back(b);
            G[b].push_back(a);
        }
        REP(i,10000){
            dp[i]=-1;
        }
        
        cout<<dfs(0,1)<<endl;
	return(0);
}

Measured memory_bytes: 384
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

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


int main(){
	FIO
	
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < 3; i++)if(s[i] == '1')ans++;
	cout << ans << '\n'; 	
	return 0; 
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] dp = new int[100010];
		for(int i = 0 ; i <= 100000 ; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		for(int i = 1 ; i <= 100000 ; i++) {
			int pow6 = 1;
			while(pow6 <= i) {
				dp[i] = Math.min(dp[i], dp[i - pow6] + 1) ;
				pow6 *= 6;
			}
			int pow9 = 1;
			while(pow9 <= i) {
				dp[i] = Math.min(dp[i], dp[i - pow9] + 1);
				pow9 *= 9;
			}
		}
		System.out.println(dp[n]);
	}
}


Measured memory_bytes: 23252
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(x,y,z)for((x)=(y);(x)<(z);(x)++)

int w, h, n, x, y, ans=0;

int input() {
	int i;
	cin >> w >> h >> n;
	cin >> x >> y;
	return 0;
}

int main() {
	int i, X, Y;
	input();
	rep(i, 0, n-1) {
		cin >> X >> Y;
		if ((X - x) * (Y - y) < 0) {
			ans += abs(X - x) + abs(Y - y);
		}
		else {
			ans += abs(X - x) + abs(Y - y) - min(abs(X - x), abs(Y - y));
		}
		x = X;
		y = Y;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  
  int n;
  cin >> n;
  double point[2][n];
  
  double wa = 0;
  double ans;
  
  for(int i=0; i<n; i++){
    cin >> point[0][i] >> point[1][i];
  }
  
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      wa += sqrt((point[0][i]-point[0][j])*(point[0][i]-point[0][j])
                +(point[1][i]-point[1][j])*(point[1][i]-point[1][j]));
     //各ポイントの距離を入れる
    }
  }
  
  ans = wa*2/n;
  cout << std::setprecision(10) << ans << endl;

}
  
      

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    int n;
    scanf("%d",&n);
    for(int j=0;j<n;j++){
        char pro[1000];
        scanf(" %s",pro);
        int num;
        num=strlen(pro);
        int a[1000]={};
        for(int i=0;pro[i]!='\0';i++){
            a[i]=pro[i]-'0';
        }
        int ans=0,count=0;
        for(int i=0;i<num;i++)ans+=a[i];
        while(ans>9){
            ans-=9;
            count++;
        }
        if((num-1+count)%2==0)printf("Audrey wins.\n");
        else printf("Fabre wins.\n");
    }
    return 0;
}

Measured memory_bytes: 2516
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	n, x, y := readInt(), readInt()-1, readInt()-1

	mat := make([][]int, n)
	for i := range mat {
		mat[i] = make([]int, 0)
		if i-1 >= 0 {
			mat[i] = append(mat[i], i-1)
		}
		if i+1 < n {
			mat[i] = append(mat[i], i+1)
		}
	}
	if x != y {
		mat[x] = append(mat[x], y)
		mat[y] = append(mat[y], x)
	}

	dist := make([][]int, n)
	for i := range dist {
		dist[i] = make([]int, n)
	}

	for i := range mat {
		visited := map[int]bool{i: true}
		tos := mat[i]
		cnt := 0
		for len(visited) < n {
			cnt++
			nexts := make([]int, 0)
			for _, to := range tos {
				if visited[to] {
					continue
				}
				visited[to] = true
				dist[i][to] = cnt
				nexts = append(nexts, mat[to]...)
			}
			tos = nexts
		}
	}

	// for i := range dist {
	// 	fmt.Println(i, dist[i])
	// }

	ans := make(map[int]int)
	for i := range dist {
		for j := i + 1; j < n; j++ {
			ans[dist[i][j]]++
		}
	}

	for i := 1; i < n; i++ {
		if v, ok := ans[i]; ok {
			fmt.Println(v)
		} else {
			fmt.Println(0)
		}
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 66324
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

int main(){
    
    ll n,cnt = 1;
    cin >> n;
    map<string,ll> map;
    string s;
    rep(i,0,n){
        cin >> s;
        if(map.count(s)){
            map[s]++;
            cnt = max(cnt,map[s]);
        }
        else map[s] = 1;
    }

    vector<string> vec;
    for(auto i = map.begin();i != map.end();++i){
        if(i->second == cnt) vec.push_back(i->first);
    }

    sort(vec.begin(),vec.end());

    rep(i,0,vec.size()) cout << vec[i] << endl;
    return 0;
}

Measured memory_bytes: 26992
#include <cstdio>
#include <cstdint>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <utility>
#include <tuple>

using interval = std::pair<size_t, size_t>;
using disk_type = std::list<std::pair<interval, size_t>>;

void write(disk_type& disk, size_t id, size_t size) {
  size_t last = 0;
  auto it = disk.begin();
  while (size > 0) {
    size_t s, e;
    std::tie(s, e) = it->first;
    if (last < s) {
      size_t s0 = last;
      size_t e0 = std::min(s0+size, s);
      interval p(s0, e0);
      disk.emplace(it, p, id);
      size -= e0-s0;
    }
    last = e;
    ++it;
  }
}

void delete_(disk_type& disk, size_t id, size_t size) {
  for (auto it = disk.begin(); it != disk.end();) {
    if (size == 0) break;
    if (it->second == id) {
      it = disk.erase(it);
    } else {
      ++it;
    }
  }
}

size_t read(const disk_type& disk, size_t id) {
  for (auto it = disk.begin(); it != disk.end(); ++it) {
    size_t s, e;
    std::tie(s, e) = it->first;
    if (s <= id && id < e) return it->second;
    if (id < s) return -1;
  }
  return -1;
}

void inspect(const disk_type& disk) {
  for (auto it = disk.begin(); it != disk.end(); ++it) {
    fprintf(stderr, "[%zu:%zu): %zu\n",
            it->first.first, it->first.second, it->second);
  }
  fprintf(stderr, "===\n");
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::map<size_t, size_t> sizes;
  disk_type disk;
  size_t inf = 2e9;
  disk.emplace_back(std::make_pair(inf, inf), -1);
  for (size_t i = 0; i < n; ++i) {
    char cmd;
    scanf(" %c", &cmd);

    if (cmd == 'W') {
      size_t id, size;
      scanf("%zu %zu", &id, &size);
      write(disk, id, size);
      sizes[id] = size;
    } else if (cmd == 'D') {
      size_t id;
      scanf("%zu", &id);
      delete_(disk, id, sizes.at(id));
      sizes.erase(id);
    } else if (cmd == 'R') {
      size_t index;
      scanf("%zu", &index);
      size_t res = read(disk, index);
      if (res+1 == 0) {
        puts("-1");
      } else {
        printf("%zu\n", res);
      }
    }
  }

  puts("");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 3164
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#define MP make_pair
using namespace std;
long long int sc[1001][1001],ssc[1001][1001];
char c[1001];
int main()
{
	int h, w, cnt = 0, ans = 0, n,kfc=0;
	int x, y;
	pair<int, int> p;
	queue< pair<int, int> > que;
	queue< pair<int, int> > que1;
	scanf("%d%d", &h, &w);
	for (int i = 0; i < h; i++)
	{
		scanf("%s", c);
		for (int j = 0; j < w; j++)
		{

			if (c[j] == '.')
				sc[i][j] = -1;
			else
				sc[i][j] = c[j] - 48;
		}
	}
	for (int i = 1; i < h; i++)
	{
		for (int j = 1; j < w; j++)
		{
			if (sc[i][j] != -1)
			{
				for (int a = i - 1; a < i + 2; a++)
				{
					for (int b = j - 1; b < j + 2; b++)
					{
						if (sc[a][b] == -1)ssc[i][j] ++;
					}
				}
				if (sc[i][j] <= ssc[i][j])
				{
					que.push(MP(i, j)); que1.push(MP(i, j));  kfc++;
				}
			}
		}
	}
	for (int i = 0; i < kfc; i++) {
		x = que.front().first;
		y = que.front().second;
		que.pop();
		que1.pop();
		sc[x][y] = -1; que.push(MP(x, y)); que1.push(MP(x, y));
	}
	while (!que.empty())
	{
		while (!que.empty())
		{
			x = que.front().first;
			y = que.front().second;
			que.pop();
			for (int a = -1; a < 2; a++)
			{
				ssc[x - 1][y + a]++;
				ssc[x + 1][y + a]++;
			}
			ssc[x][y - 1]++;
			ssc[x][y + 1]++;
		}
		n = que1.size();
		for (int i = 0; i < n; i++)
		{
			x = que1.front().first;
			y = que1.front().second;
			que1.pop();
			for (int a = -1; a < 2; a++)
			{
				if (sc[x - 1][y + a] <= ssc[x - 1][y + a] && sc[x - 1][y + a] != -1) {
					que.push(MP(x - 1, y + a)); que1.push(MP(x - 1, y + a)); sc[x - 1][y + a] = -1;
				}
				if (sc[x + 1][y + a] <= ssc[x + 1][y + a] && sc[x + 1][y + a] != -1) {
					que.push(MP(x + 1, y + a)); que1.push(MP(x + 1, y + a)); sc[x + 1][y + a] = -1;
				}
			}
			if (sc[x][y - 1] <= ssc[x][y - 1] && sc[x][y - 1] != -1) {
			que.push(MP(x, y - 1)); que1.push(MP(x, y - 1)); sc[x][y - 1] = -1;
			}
			if (sc[x][y + 1] <= ssc[x][y + 1] && sc[x][y + 1] != -1) {
				que.push(MP(x, y + 1)); que1.push(MP(x, y + 1)); sc[x][y + 1] = -1;
			}
		}
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 18912
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		boolean flg = false;
		for (int i = 0; i < n; i++) {
			if (scan.next().equals("Y")) {
				flg = true;
				break;
			}
		}

		if (flg) {
			System.out.println("Four");
		} else {
			System.out.println("Three");
		}
		scan.close();
	}

}


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

#define reint register int
#define coint const int

using namespace std;

struct Vector {
    double x, y;

    inline Vector operator+(const Vector &v) const {
        return (Vector){ x + v.x, y + v.y };
    }

    inline double dot(const Vector &v) const { return x * v.x + y * v.y; }
    inline double cross(const Vector &v) const { return x * v.y - y * v.x; }
    inline double length(void) const { return sqrt(x * x + y * y); }

    inline Vector operator*(const double a) const {
        return (Vector){ x * a, y * a };
    }
};

struct Point {
    double x, y;

    inline Vector operator-(const Point &p) const {
        return (Vector){ x - p.x, y - p.y };
    }

    inline Point operator+(const Vector &v) const {
        return (Point){ x + v.x, y + v.y };
    }
};

int main(void) {
    Point p1, p2;
    scanf("%lf%lf%lf%lf", &p1.x, &p1.y, &p2.x, &p2.y);
    const Vector vecP1P2 = p2 - p1;
    const double lenP1P2 = vecP1P2.length();
    int q;
    scanf("%d", &q);
    for (reint i = 1; i <= q; ++i) {
        Point p;
        scanf("%lf%lf", &p.x, &p.y);
        const Vector vecP1P = p - p1;
        const double lenP1H = vecP1P.dot(vecP1P2) / lenP1P2;
        const Vector vecP1H = vecP1P2 * (lenP1H / lenP1P2);
        const Point h = p1 + vecP1H;
        const Point x = (Point){ h.x * 2 - p.x, h.y * 2 - p.y };
        printf("%.12f %.12f\n", x.x, x.y);
    }

    return 0;
}



Measured memory_bytes: 3236
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;

int k;
ll q[N],hh=1,tt=0;

int main() {
    ios::sync_with_stdio(false);
    cin>>k;
    if(k<=12){
        printf("%d\n",k);
        return 0;
    }

    for(int i=1;i<=9;++i) q[++tt]=i;

    int cnt=0;
    ll ans;
    while(cnt!=k){
        ll now=q[hh];
        hh++;
        ll res=now%10;

        if(res!=0) q[++tt]=now*10+res-1,cnt++;
        if(cnt==k-10+1){
           ans=q[tt];
           break;
        }
        q[++tt]=now*10+res,cnt++;
        if(cnt==k-10+1){
            ans=q[tt];
            break;
        }
        if(res!=9) q[++tt]=now*10+res+1,cnt++;
        if(cnt==k-10+1){
            ans=q[tt];
            break;
        }
    }
   printf("%lld\n",ans);


    return 0;
}

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

#define int long long
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define endl "\n"
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;

int power(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int ncr(int n,int r){int res=1;if(r>n-r)r=n-r;for(int i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}
int max(int a,int b){int ans=a>b?a:b;return ans;}
int min(int a,int b){int ans=a<b?a:b;return ans;}
//cout<<fixed<<setprecision(8)<<x<<endl;
clock_t time_p=clock();
void rtime(){time_p=clock()-time_p;cerr<<"******************\nTime taken : "<<(double)(time_p)/CLOCKS_PER_SEC<<"\n";}

signed main()
{
	//fast;
    //int t=1; cin>>t; while(t--)
    {
    	int n,w,x;
    	cin>>n>>w;
    	vector<int> aw,av;
    	aw.pb(0),av.pb(0);
    	for(int i=0;i<2*n;i++)
    	{
    		cin>>x;
    		aw.pb(x);
    		cin>>x;
    		av.pb(x);
    	}
    	int dp[n+5][w+5];
    	memset(dp,0,sizeof(dp));

    	for(int i=1;i<=n;i++)
    	{
    		for(int j=1;j<=w;j++)
    		{
    			dp[i][j]=dp[i-1][j]; 
    			if (aw[i]<=j) 
	                 dp[i][j]=max(av[i]+dp[i-1][j-aw[i]], dp[i-1][j]); 
    		}
    	}
    	cout<<dp[n][w];
    }
    rtime();
    return 0;
}

Measured memory_bytes: 82304
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int c=-1,f=-1;
	for (int i=0;i<s.size();i++)
		if (s[i]=='C')
		{
			c=i;
			break;
		}
	for (int i=s.size()-1;i>=0;i--)
		if (s[i]=='F')
		{
			f=i;
			break;
		}
	if (c!=-1&&f!=-1&&c<f)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  cin >> n;
  vector<pii> v;
  REP(i,n){
      int tmp;
      cin >> tmp;
      v.pb(MP(tmp, i+1));
  }

  SORTV(v);
  REPI(itr, v){
    cout << itr->second << " ";
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 1780
using System;
using System.Linq;

namespace ALDS1_9A{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var H = sr.Next<int>();
            var A = new[] {0}.Concat(sr.Next<int>(H)).ToArray();

            for(var i = 1; i <= H; i++){
                Console.Write("node {0}: ", i);
                Console.Write("key = {0}, ", A[i]);
                if(i / 2 >= 1)     Console.Write("parent key = {0}, ", A[i / 2]);
                if(i * 2 <= H)     Console.Write("left key = {0}, ", A[i * 2]);
                if(i * 2 + 1 <= H) Console.Write("right key = {0}, ", A[i * 2 + 1]);
                Console.WriteLine();
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  vi pack(3); rep(i, 3) std::cin >> pack[i];
  sort(rng(pack));
  std::cout << (pack[0]+pack[1] == pack[2] ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	long long a,b;
	cin>>a>>b;
	if(abs(a-b)<=1)
	{
		
		cout<<"Brown";
	}
	else cout<<"Alice";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
const ll INF=1e11+7;
void input(ll *a,ll n){
    for(ll i=0;i<n;i++)cin>>a[i];
}
ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
bool isprime(ll n){
    if(n==1)return false;
    if(n==2 || n==3)return true;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0)
            return false;
    }
    return true;
}

//ll x[100001]={0};
ll a[200001]={0};
//ll b[200001]={0};
//bool c[10000001]={0};
//vector<pair<ll,ll> > adj[100001];
//ll dist[100001]={0};

ll binary_expon(ll a,ll b){
    ll res=1;
    while(b){
        if(b%2)res*=a;
        a*=a;
        b/=2;
    }
    return res;
}

void sieve(ll n,bool *a)
{
    for (ll p=2; p*p<=n; p++){
        if (!a[p]){
            for (ll i=p*p;i<=n;i+=p)
                a[i]=true;
        }
    }
}

ll fact(ll n){
    ll res=1;
    for(ll i=1;i<=n;i++)
        res*=i;
    return res;
}

double distance(ll x1,ll y1,ll x2,ll y2){
    return (sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}

/*void dfs(ll curr,ll prev,ll d){

    for(u:adj[curr]){
        if(u.first!=prev){
            dfs(u.first,curr,d+1);
        }
    }
    depth.push_back({d,curr});
}*/

/*void dfs(ll x,ll y){
    if(x<0 || y<0 || x>=n || y>=m)return;
    if(visited[x][y])return;
    visited[x][y]=true;
    dfs(x+1,y);dfs(x-1,y);dfs(x,y+1);dfs(x,y-1);
}*/

/*bool isVowel(char c){
    return(c=='a'||c=='e'||c=='i'||c=='o'||c=='u');
}*/

void solve(){
    ll a,b;
    cin>>a>>b;
    cout<<a*b;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //sieve(10000001,c);
    ll t=1;
   // cin>>t;
    for(ll i=0;i<t;i++){
        solve();
    }
}


Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<climits>
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<cstring>

using namespace std;

#define DEBUGMODE 0
#define int long long
#define MOD (1000000007l)
#define EPS ((double)0.000000001)
#define rep(i,s,n) for(int (i)=(s);i<(int)(n);(i)++)
#define rrep(i,s,n) for(int (i)=(int)(n)-1;(i)>=(s);(i)--)

signed main(){
    int ans=1;
    int N;
    cin>>N;
    string s[2];

    cin>>s[0];
    cin>>s[1];

    int bef=0;
    rep(i,0,s[0].size()){
        if(s[0][i]==s[1][i]){
            if(bef==0){
                ans*=3;
            }
            if(bef==1){
                ans*=2;
            }
            if(bef==2){
                ans*=1;
            }
            bef=1;
        }
        else{
            if(bef==0){
                ans*=3;
                ans*=2;
            }
            if(bef==1){
                ans*=2;
                ans*=1;
            }
            if(bef==2){
                ans*=3;
            }
            bef=2;
            i++;
        }
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
wa, ac = [0]*(N+1), [0]*(N+1)
wa_ac = 0
for i in range(1, M+1):
  pi, Si = input().split()
  pi = int(pi)
  if Si == 'WA' and ac[pi] == 0: 
    wa[pi] += 1
  elif Si == 'AC' and ac[pi] == 0:
    ac[pi] += 1

for i in range(1, N+1):
  if ac[i] == 1:
    wa_ac += wa[i]

print('{} {}'.format(sum(ac), wa_ac))


Measured memory_bytes: 46624
#include<stdio.h>

int main(){
    int r,D,x2000;
    int i;
    int x_out;
    scanf("%d %d %d",&r,&D,&x2000);
    x_out=x2000;
    for(i=0;i<10;i++){
        x_out=r*x_out-D;
        printf("%d\n",x_out);
    }
    return 0;
}

Measured memory_bytes: 128
<?php
fscanf(STDIN, "%d %d %d %d %d", $a, $b, $c, $x, $y);
$c2 = $c * 2;
if ($a + $b <= $c2) {
	echo $a * $x + $b * $y;
} elseif ($a >= $c2 && $b >= $c2) {
	echo $c2 * max($x, $y);
} else {
	if ($x > $y) {
		$r = $x - $y;
		$p = min($a * $r, $c2 * $r);
	} else {
		$r = $y - $x;
		$p = min($b * $r, $c2 * $r);
	}
	echo $c2 * min($x, $y) + $p;
}

Measured memory_bytes: 4604
#! /usr/bin/env python3

def f(a, b, c, d):
    n = max(1,a//c, b//d)
    while a > c * n or b > d * n : n += 1
    return c * n, d * n
    
def main():
    a, b = 0, 0
    for i in range(int(input())):
        c, d = map(int, input().split())
        a, b = f(a, b, c, d)
    print(a+b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40176
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
string S, T;
signed main(){
  bool x; cin >> x;
  cout << !x << endl;
  return 0;
}
  
  

Measured memory_bytes: 3668
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int a[100005];
int main()
{
	int n;
   int sum;
     while(scanf("%d",&n)!=EOF)
     {
     	sum=0;
     	for(int i=0;i<n;i++)
     	{
     		scanf("%d",&a[i]);
     		sum+=a[i];
		 }
		 printf("%d\n",sum-n);
	 }
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
  	cin>>n;
  cout<<n/2+(n%2==1);
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int q,x,i,k,l[N],r[N],j,n;
long long ans;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		for(j=1;i*j<n;++j)
			++ans;
	cout<<ans;
}


Measured memory_bytes: 3804
import java.io.InputStream;
import java.io.IOException;
import java.util.NoSuchElementException;

public class Main {
    public static void main(final String[] args) {
        final MyScanner sc = new MyScanner();
        final int n = sc.nextInt();
        final int[] w = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
            sum += w[i];
        }

        int minimum = sum;
        int temp = 0;
        for (int i = 0; i < n; i++) {
            temp += w[i];
            minimum = Math.min(minimum, Math.abs(temp - (sum - temp)));
        }
        System.out.println(minimum);
    }
}

class MyScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int pointer = 0;
    private int bufLength = 0;

    private boolean hasNextByte() {
        if (pointer < bufLength) {
            return true;
        } else {
            pointer = 0;
            try {
                bufLength = in.read(buffer);
            } catch (final IOException e) {
                e.printStackTrace();
            }
            if (bufLength <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[pointer++];
        } else {
            return -1;
        }
    }

    private static boolean isNumberChar(final int c) {
        return '0' <= c && c <= '9';
    }

    private static boolean isPrintableChar(final int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[pointer])) {
            pointer++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        final StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long num = 0;
        boolean isNegative = false;
        int b = readByte();
        if (b == '-') {
            isNegative = true;
            b = readByte();
        }
        if (!isNumberChar(b)) {
            throw new NumberFormatException();
        }
        while (true) {
            if (isNumberChar(b)) {
                num *= 10;
                num += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return isNegative ? -num : num;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        final long temp = nextLong();
        if (temp < Integer.MIN_VALUE || Integer.MAX_VALUE < temp) {
            throw new NumberFormatException();
        }
        return (int) temp;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

int main(){
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if(A + B >= K){
        if(A >= K) cout << K << endl;
        else cout << A << endl;
    }
    else  cout << 2*A + B - K << endl;;
}

Measured memory_bytes: 3640
#include <stdio.h>

#define MAX 100000
#define SENTINEL 2000000000
 
struct Card{
  char suit;
  int value;
};
 
struct Card L[MAX/2+2], R[MAX/2+2];


int partition(struct Card A[],int p,int r){
  int i, j;
  struct Card t,x;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].value <= x.value){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}
 
void merge(struct Card A[],int left,int mid,int right){
  int i,j,k,n1,n2;
   
  n1 = mid - left;
  n2 = right - mid;
  for(i=0;i<n1;i++){
    L[i] = A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i] = A[mid+i];
  }

  L[n1].value = R[n2].value = SENTINEL;

  i = j = 0;

  for(k=left;k<right;k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    }else {
      A[k] = R[j++];
    }
  }
 
}
 
void mergeSort(struct Card A[],int left,int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A,left,mid,right);
  }
}
 


 
void quickSort(struct Card A[],int p,int r){
  int q;
  if(p < r){
    q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}
 
int main(){
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;
 
  scanf("%d", &n);
 
  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }
 
  mergeSort(A, 0, n);
  quickSort(B, 0, n-1);
 
  for(i=0;i<n;i++){
    if(A[i].suit != B[i].suit){
      stable = 0;
    }
  }
 
  if(stable == 1){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }
  for( i = 0 ; i < n ; i++ ){
    printf("%c %d\n", B[i].suit, B[i].value);
  }
 
  return 0;
}




Measured memory_bytes: 4056
void main() {
	auto ip = readAs!(int[]), N = ip[0], M = ip[1], X = ip[2];
	auto A = readAs!(int[]);
	auto c = A.count!(a => a > X);
	min(c, A.length - c).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int n;
    cin>>n;
    if(n<1000)cout<<"ABC"<<endl;
    else cout<<"ABD"<<endl;
}


Measured memory_bytes: 256
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let h: usize = it.next().unwrap().parse().unwrap();
    let w: usize = it.next().unwrap().parse().unwrap();
    let m: usize = it.next().unwrap().parse().unwrap();
    let s: Vec<Vec<usize>> = (0..h).map(|_| it.next().unwrap().chars().map(|c| c.to_digit(10).unwrap() as usize).collect()).collect();
    let mut ans = h - 1 + w - 1;
    for i in 0..(1 << (h - 1)) {
        let mut id = vec![0; h];
        let mut k = 0;
        let mut res = 0;
        for j in 0..h {
            id[j] = k;
            if (i >> j) & 1 == 1 {
                k += 1;
                res += 1;
            }
        }
        k += 1;
        let mut cnt = vec![0; k];
        let mut c = vec![0; k];
        for j in 0..w {
            c.clear();
            c.resize(k, 0);
            for x in 0..h {
                c[id[x]] += s[x][j];
            }
            if !c.iter().all(|c| *c <= m) {
                res = h + w;
                break;
            } else {
                for (a, b) in cnt.iter_mut().zip(c.iter()) {
                    *a += *b;
                }
                if !cnt.iter().all(|c| *c <= m) {
                    res += 1;
                    cnt.clone_from(&c);
                }
            }
        }
        ans = std::cmp::min(ans, res);
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int D;
int H;
LL BIT[1145141];
LL fact[1145141];
LL fsum[1145141];

void ADD(LL &v, LL t) {
  v += t;
  while (v >= MOD) v -= MOD;
}

void Add(int k, LL x) {
  k++;
  while (k < 1145141) {
    ADD(BIT[k], x);
    k += k&-k;
  }
}

LL Get(int k) {
  k++;
  LL ret = 0;
  while (k > 0) {
    ADD(ret, BIT[k]);
    k -= k&-k;
  }
  return ret;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  cin >> N >> H >> D;

  fact[0] = 1;
  reps(i, 1, N+2) {
    fact[i] = fact[i-1]*i% MOD;
  }

  //fsum[0] = 1;
  reps(i, 1, N+2) {
    fsum[i] = (fsum[i-1] + fact[i]) % MOD;
  }

  Add(0, 1);
  LL ans = -1;
  reps(i, 1, H+1) {
    LL dpi = Get(i-1);
    if (i >= D+1) ADD(dpi, MOD-Get(i-D-1));
    if (i <= D) {
      ADD(dpi, MOD-1);
      dpi *= fsum[N];
      dpi %= MOD;
      ADD(dpi, 1);
    } else {
      dpi *= fsum[N];
      dpi %= MOD;
    }

    Add(i, dpi);
    if (i == H) ans = dpi;
  }
  assert(ans >= 0);

  //ans *= fsum[N];
  //ans %= MOD;
  ans *= fact[N];
  ans %= MOD;
  cout << ans << endl;
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  bool ans=true;
  sort(a,a+n);
  if(n%3==0){
    int x,y,z;
    for(int i=0;i<n/3-1;i++){
      if(a[i]!=a[i+1]) ans=false;
    }
    for(int i=n/3;i<2*n/3-1;i++){
      if(a[i]!=a[i+1]) ans=false;
    }
    for(int i=2*n/3;i<n-1;i++){
      if(a[i]!=a[i+1]) ans=false;
    }
    if((a[0]^a[n/3])!=a[2*n/3]) ans=false;
  }
  else{
    for(int i=0;i<n-1;i++){
      if(a[i]!=a[i+1]) ans=false;
    }
  }
  cout << (ans?"Yes":"No") << endl;
}

Measured memory_bytes: 640