akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    vector<char> last;
    string S;

    cin >> S;

    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'B'){
            if(last.size() > 0){
                last.pop_back();
            }
        }else{
            last.push_back(S[i]);
        }
    }

    for(auto i:last){
        cout << i;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
  def __init__(self,size):
    self.table=[-1]*size
  def root(self,x):
    while self.table[x]>=0:
      x=self.table[x]
    return x
  def unite(self,x,y):
    s1=self.root(x)
    s2=self.root(y)
    if s1!=s2:
      if self.table[s1]>self.table[s2]:
        s1,s2=s2,s1
      self.table[s1]+=self.table[s2]
      self.table[s2]=s1
    return
  def same(self,x,y):
    return self.root(x)==self.root(y)
  def size(self,x):
    return -self.table[self.root(x)]
(n,m),_,*e=[map(int,t.split())for t in open(0).readlines()]
u=UnionFind(n)
a=[n*~-n//2]
for x,y in e[::-1]:
  x,y=x-1,y-1
  t=a[-1]
  if not u.same(x,y):
    t-=u.size(x)*u.size(y)
  a.append(t)
  u.unite(x,y)
print(*a[::-1],sep='\n')

Measured memory_bytes: 55916
class ModComb
  def initialize(max, mod)
    @mod = mod
    @fac = Array.new(max + 1)
    @finv = Array.new(max + 1)
    @inv = Array.new(max + 1)
    @fac[0] = @fac[1] = 1
    @finv[0] = @finv[1] = 1
    @inv[1] = 1
    (2..max).each do |i|
      @fac[i] = @fac[i - 1] * i % @mod
      @inv[i] = @mod - @inv[@mod % i] * (@mod / i) % @mod
      @finv[i] = @finv[i - 1] * @inv[i] % @mod
    end
  end

  def comb(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0
    @fac[n] * (@finv[k] * @finv[n - k] % @mod) % @mod
  end
end

X, Y = gets.split.map(&:to_i)

if (X + Y) % 3 != 0
  puts 0
  exit 0
end

diff = (X - Y).abs
min = [X, Y].min

if diff > min
  puts 0
  exit 0
end

MOD = 10 ** 9 + 7
count1 = (min - diff) / 3
count2 = (min - diff) / 3 + diff
count = count1 + count2
comb = ModComb.new(count, MOD)
ans = comb.comb(count, count1)
puts ans

Measured memory_bytes: 19452
#include<iostream>
#include<stdio.h>
using namespace std;
main(){
  double a,b,c,d,e,f;
  double x=0,y=0;
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF){
	y=(c*d-a*f)/(b*d-a*e);
	x=(c-b*y)/a;
	printf("%.3f %.3f\n",x,y);
  }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  //1 <= N <= 10000
  //0 <= A <=1000

  int N = 0, A = 0;
  cin >> N >> A;

  if(N <= A) {
    cout << "Yes" << endl;
    return 0;
  }
  
  if (N % 500 <= A) {
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 256
/*************************************************************************
 *                                                                       *
 *                    XI Olimpiada Informatyczna                         *
 *                                                                       *
 *   Rozwi±zanie zadania: Jaskinia                                       *
 *   Plik:                jas.cpp                                        *
 *   Autor:               Arkadiusz Paterek                              *
 *************************************************************************/

#include <iostream>
#include <vector>

using namespace std;

#define VAR(a, b) __typeof(b) a = (b)
#define FOREACH(it, c) for(VAR(it, (c).begin()); it != (c).end(); ++it)

struct Node {
  vector<int> neigh; // s±siedzi wezla w drzewie
  int f; // funkcja f z dowodu (minimalna liczba pytañ)
  vector<int> S; // zbiór S z dowodu (warto¶ci f, które "widaæ" "patrz±c" od ojca wierzcho³ka)
  
  Node() : S(25, 0) { // inicjujemy S na 25 elementow, bo K = max_f nie moze byæ wiêksze niz log(rozmiar drzewa)
    f = 0;
  }
};

struct Tree {
  vector<Node> nodes; // wierzcho³ki tworz±ce drzewo
  
  friend istream &operator>>(istream &is, Tree &tree) { // wczytanie drzewa z wej¶æia
    vector<Node> &nodes = tree.nodes;
    nodes.clear();
    
    int size;
    is >> size;
    nodes.resize(size);

    int a, b;
    for (int i = 0; i < size - 1; ++i) {
      is >> a >> b;
      --a;
      --b;
      nodes[a].neigh.push_back(b);
      nodes[b].neigh.push_back(a);
    }
    
    return is;
  }
  
  void computeF(int n, int father) { // DFS w drzewie - obliczenie warto¶ci f w wêŒle n
    Node &node = nodes[n];
    
    FOREACH(child_i, node.neigh)
      if (*child_i != father) { // dla wszystkich s±siadów w drzewie oprócz poprzednika
        Node &child = nodes[*child_i];
        computeF(*child_i, n);
        
        for (int i = 0; i < (int)child.S.size(); ++i)
          if (child.S[i] > 0)
            ++node.S[i];
      }


    int m = node.S.size();
    do
      --m;
    while (m >= 0 && node.S[m] < 2);

    node.f = m + 1;
    while (node.S[node.f] > 0)
      ++node.f;
    
    for (int i = 0; i < node.f; ++i)
      node.S[i] = 0;

    node.S[node.f] = 1;
    
/*    cerr << "computeF " << n << " " << father << endl;
    cerr << " m = " << m << endl;
    cerr << " f = " << node.f << endl;
    cerr << " S = ";
    copy(node.S.begin(), node.S.end(), ostream_iterator<int>(cerr, " "));
    cerr << endl;*/
  }
  
  int computeAnswer() {
    computeF(0, -1);
    
    int max_f = -1;
    FOREACH(node, nodes) {
      if (node->f > max_f)
        max_f = node->f;
    }
    return max_f;
  }
};

int main() {
  Tree tree;
  cin >> tree;
  cout << tree.computeAnswer() << endl;
  return 0;
}


Measured memory_bytes: 21760
#include<cstdio>
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
const int MOD=1e9+7;
struct mint{int x;mint(int x=0):x(x){}};
inline mint operator+  (mint a,mint b){return a.x+b.x<MOD?a.x+b.x:a.x+b.x-MOD;}
inline mint operator-  (mint a){return MOD-a.x;}
inline mint operator-  (mint a,mint b){return a+-b;}
inline mint operator*  (mint a,mint b){return 1LL*a.x*b.x%MOD;}
inline mint operator<< (mint x,int y){mint r=1;for(;y;y>>=1,x=x*x)if(y&1)r=r*x;return r;}
inline mint operator~  (mint x){return x<<MOD-2;}
inline mint operator/  (mint a,mint b){return a*~b;}
inline mint&operator+= (mint&a,mint b){return a=a+b;}
inline mint&operator-= (mint&a,mint b){return a=a-b;}
inline mint&operator*= (mint&a,mint b){return a=a*b;}
inline mint&operator<<=(mint&x,int y){return x=x<<y;}
inline mint&operator/= (mint&a,mint b){return a=a/b;}
#define MN 50
#define MM 100
struct edge{int nx,t;}e[MM*2+5];
int k,h[MN+5],en,d[MN+5],l[MN+5],cnt,qx[MM+5],qy[MM+5],qn;
mint f[MM*2+5],rf[MM*2+5],ans=1;
inline mint C(int n,int m){return f[n]*rf[n-m]*rf[m];}
inline void ins(int x,int y)
{
	e[++en]=(edge){h[x],y};h[x]=en;
	e[++en]=(edge){h[y],x};h[y]=en;
}
int gcd(int x,int y){return y?gcd(y,x%y):x;}
void solve(int l,int r)
{
	int i;
	for(i=l;i<r;++i)if(qy[i]!=qx[i+1])break;
	if(i==r&&qy[r]==qx[l])
	{
		mint s=0;
		for(int i=1;i<=r-l+1;++i)s+=mint(k)<<gcd(i,r-l+1);
		ans*=s/(r-l+1);
		return;
	}
	ans*=C(r-l+k,k-1);
}
void dfs(int x,int fa)
{
	d[x]=l[x]=++cnt;
	for(int i=h[x];i;i=e[i].nx)if(e[i].t!=fa)
	{
		if(!d[e[i].t])
		{
			qx[++qn]=x;qy[qn]=e[i].t;
			dfs(e[i].t,x);
			if(l[e[i].t]>=d[x])
			{
				int z=qn;
				while(qx[qn]!=x||qy[qn]!=e[i].t)--qn;
				solve(qn--,z);
			}
			if(l[e[i].t]<l[x])l[x]=l[e[i].t];
		}
		else
		{
			if(d[e[i].t]<d[x])qx[++qn]=x,qy[qn]=e[i].t;
			if(d[e[i].t]<l[x])l[x]=d[e[i].t];
		}
	}
}
int main()
{
	int n,m,i;
	n=read();m=read();k=read();
	for(f[0]=i=1;i<=m+k;++i)f[i]=f[i-1]*i;
	for(rf[i=m+k]=~f[m+k];i--;)rf[i]=rf[i+1]*(i+1);
	while(m--)ins(read(),read());
	for(i=1;i<=n;++i)if(!d[i])dfs(i,0);
	printf("%d",ans); 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int>P;
 
int main() {
  ll a,b,c;
  cin>>a>>b>>c;
  for(int i=0;i<b;i++){
    cout<<c<<" ";
  }
 for(int j=0;j<a-b;j++){
     if(c>2){
     cout<<c-1<<" ";
     }
     else{
       cout<<c+1<<" ";
     }
 }
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string s;
    vector<char> v(3);
    cin>>s;
    int i,j,p,ctr;
    for (i=0;i<8;i++)
    {
        p=i;
        ctr=2;
        while (ctr>=0)
        {
            if (p&1)
                v[ctr]='+';
            else
                v[ctr]='-';
            ctr--;
            p>>=1;
        }
        int tp=s[0]-'0';
        for (j=0;j<3;j++)
        {
            if (v[j]=='+')
                tp+=(s[j+1]-'0');
            else
                tp-=(s[j+1]-'0');
        }
        if (tp==7)
        {
            cout<<s[0];
            for (j=0;j<3;j++)
                cout<<v[j]<<s[j+1];
            cout<<"=7\n";
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    int b[20];
    for (int i = 0; i < m; i++) cin >> b[i];
    int a[20];
    int ans, count = 0;
    for (int i = 0; i < n; i++)
    {
        ans = 0;
        for (int j = 0; j < m; j++)
        {
            cin >> a[j];
            ans += a[j] * b[j];
        }
        ans += c;
        if (ans > 0) count++;
    }
    cout << count << endl;
    return (0);
}

Measured memory_bytes: 256
N, M = map(int, input().split())
sclist = [[]]*M
number = ['0']*N
judge = True
written = ['0']*N
for m in range(M):
  sclist[m] = list(map(int, input().split()))
  if written[sclist[m][0]-1] == '0':
    number[sclist[m][0]-1] = str(sclist[m][1])
    written[sclist[m][0]-1] = '1'
  elif written[sclist[m][0]-1] == '1' and number[sclist[m][0]-1] != str(sclist[m][1]):
    judge = False
  if sclist[m][0] == 1 and sclist[m][1] == 0 and N != 1:
    judge = False
if judge:
  if number[0] == '0' and N != 1:
    number[0] = '1'
  print(''.join(number))
else:
  print('-1')

Measured memory_bytes: 3064
function main(input) {
  var temp = input.split('\n');
  for (var i=0; i < temp.length; i++) {
    var data = temp[i].split(' ').map(Number);
    var height = data[0];
    var width = data[1];
    if(height == 0 && width == 0)
      break;
    var line = "";
    for (var k = 0; k<width; k++) {
      line += '#'
    }
    for (var j = 0; j < height; j++) {
      console.log(line);
    }
    console.log('');
  }
}

var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
main(x);


Measured memory_bytes: 17668
package main
import (
  "fmt"
  "bufio"
  "os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Scan()
  
  var (
    strScan string
    strAns string
  )
  strScan = sc.Text()
  
  switch strScan {
    case "Sunny":
      strAns = "Cloudy"
    case "Cloudy":
      strAns = "Rainy"
    case "Rainy":
      strAns = "Sunny"
  }
  
  fmt.Println(strAns)
  
}
  
  

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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;


template <typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

bool dfs(int idx, int col, int* colors, const int size, const VVI s) {
    bool result = true;
    colors[idx] = col;
    rep(i, size) {
        if(s[idx][i] == 0) continue;
        if(colors[i] == 0 && !dfs(i, col == 1 ? 2 : 1, colors, size, s)){
            return false;
        } else if(colors[i] == colors[idx]) {
            return false;
        }
    }
    return true;
}

int main() {
    int N;
    VVI S;

    cin >> N;
    rep(i, N) {
        string val;
        cin >> val;
        vector<char> chars(all(val));
        VI row;
        for(char ch: chars) row.pb(ch - '0');
        S.pb(row);
    }
    int colors[200] = {0};
    rep(i, N) if(colors[i] == 0 && !dfs(i, 1, colors, N, S)) {
        out(-1);
        return 0;
    }

    int d[200][200];
    rep(i, N) rep(j, N) d[i][j] = i == j ? 0 : S[i][j] == 1 ? 1 : INT_MAX / 2;
    rep(k, N) rep(i, N) rep(j, N) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
    int ans = 0;
    rep(i, N) ans = max(ans, *max_element(d[i], d[i] + N));
    out(ans + 1);
    return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1, 0));
  for(int i = 0; i < s.size(); i++) {
    for(int j = 0; j < t.size(); j++) {
      if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
      else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    }
  }
  // cout << dp[s.size()][t.size()] << endl;
  string ans = "";
  int i = s.size(), j = t.size();
  while(i > 0 && j > 0) {
    if(dp[i][j] == dp[i-1][j]) i--;
    else if(dp[i][j] == dp[i][j-1]) j--;
    else {
      ans = s[i-1] + ans;
      i--, j--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 38780
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    string s;
    cin >> s;
    int mn = INT_MAX;
    REP(i, s.length()-2){
        int n = atoi(s.substr(i, 3).c_str());
        chmin(mn, abs(753-n));
    }
    cout << mn << el;
}



Measured memory_bytes: 256
#include <iostream>  
#include <cstdio>  
#include <cstdlib>  
#include <cstring>  
#include <cmath>  
#include <stack>  
#include <bitset>  
#include <queue>  
#include <set>  
#include <map>  
#include <string>  
#include <algorithm>  
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define pb(a) push_back(a)
#define fir first
#define se second
#define LL long long
typedef pair<int, int> pii;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
const int maxn = 1e6 + 5;
const LL inf = 0x3f3f3f3f3f3f3f3f;
LL mod = 1e9 + 7;
double eps = 0.00000001;
double PI = acos(-1);

vector<int> g[1005];
int n,m, low[1005], dfn[1005], dfs_clock, iscut[1005];
vector<pii> ans;
//dfn[i]为点i在dfs遍历中的次序
//low[i]为点i能通过非树边回到的遍历序号最小的点
//dfs_clock用来计数,iscut用来表示是否是割点。
//ans用pair来存桥

void init() {  //初始化
	for (int i = 0; i <= n; i++) g[i].clear();
	ans.clear();
	dfs_clock = 0;
	clr(dfn, 0);
	clr(iscut, 0);
	clr(low, 0);
}

int dfs(int u, int fa) {  //dfs求每个点的dfn和low
	low[u] = dfn[u] = ++dfs_clock;
	int child = 0;
	for (int i = 0; i < g[u].size(); i++) {
		int v = g[u][i];
		if (!dfn[v]) {
			child++;
			low[v] = dfs(v, u);
			low[u] = min(low[u], low[v]);
			if (low[v] >= dfn[u]) {   //判断割点
				iscut[u] = true;
			}
			if (low[v] > dfn[u]) {  //判断桥
				int a = u, b = v;
				if (a > b) swap(a, b);
				ans.pb(make_pair(a, b));
			}
		}
		else if (dfn[v] < dfn[u] && v != fa) {
			low[u] = min(low[u], dfn[v]);
		}
	}
	if (fa < 0 && child == 1) iscut[u] = false;  //特判树根是不是割点
	return low[u];
}

void input() {  //输入
	int u, v;
	for (int i = 1; i <= m; i++) {
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
}

int main() {
	while (scanf("%d%d", &n,&m) != EOF) {
		int u, v;
		init();
		input();
		for (int i = 1; i <= n; i++)
			if (!dfn[i]) dfs(i, -1);
		printf("%d\n", ans.size());  //输出桥
		
	}
}

Measured memory_bytes: 256
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

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

func main() {
  NM := NextIntVec()
  N, M := NM[0], NM[1]
  S := NextLine()
  D := make([]int, N + 1)
  for i := range D {
    D[i] = -1
  }
  now := N
  for 0 < now {
    next := now
    for i := 1; i <= M; i++ {
      if now < i { break }
      if S[now - i] == '1' { continue }
      D[now - i] = i
      next = now - i
    }
    if now == next { break }
    now = next
  }
  if D[0] < 0 {
    Write(-1)
  } else {
    A := make([]int, 0)
    pos := 0
    for pos < N {
      A = append(A, D[pos])
      pos += D[pos]
    }
    WriteIntVec(A)
  }
  Output()
}

Measured memory_bytes: 7424
N , K = (map(int , input().split()))
ans_list = []
for i in range(1,N+1):
    ss = i
    count = 0
    while ss < K:
        ss = ss * 2
        count += 1
    ans_list.append((1/N)*((1/2)**count))
print(float(sum(ans_list)))

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  if (a==b){
    cout << c << endl;
  } else if (b==c){
    cout << a << endl;
  } else {
    cout << b << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    int N,K; cin>>N>>K;
    string S; cin>>S;

    int a=0;
    for (int i = 0; i < N-1; ++i) {
        if(S[i]==S[i+1]) a++;
    }

    cout<<min(N-1, K*2+a)<<endl;


    return 0;
}

Measured memory_bytes: 512
import numpy as np
N, C = map(int, input().split())
dic = []
L = 0
for i in range(N):
  s, t, c = map(int, input().split())
  dic += [(c-1,s,t)]
  if 2*t+1>L:
    L = 2*t+1

sm = np.zeros(L)
for c in range(C):
  tt = np.zeros(L)
  for i in range(N):
    if dic[i][0]==c:
      tt[dic[i][1]*2-1] += 1
      tt[dic[i][2]*2] -= 1
  tt = tt.cumsum()
  sm[tt>0] += 1
print(int(sm.max()))

Measured memory_bytes: 32552
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] nums = new int[n], dp = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = in.nextInt();
		}
		dp[1] = Math.abs(nums[0] - nums[1]);
		for (int i = 2; i < n; i++) {
			dp[i] = Math.min(dp[i-2] + Math.abs(nums[i] - nums[i-2]), dp[i-1] + Math.abs(nums[i] - nums[i-1]));
		}
		System.out.println(dp[n - 1]);
	}
}

Measured memory_bytes: 61168
#include <iostream>

#define rep(i, s, n) for(int (i) = (s); (i) < (n); ++(i))
#define print(x) cout << (x) << endl 
#define min2(a, b) ((a) < (b)) ? (a) : (b)
#define max2(a, b) ((a) > (b)) ? (a) : (b)

using namespace std;

int main(){
    int N, Y;
    bool valid;
    cin >> N >> Y;
    rep(x, 0, min2(N + 1, Y / 10000 + 1)){
        rep(y, 0, min2(N + 1, Y / 5000 + 1)){
            if(0 <= N - x - y && N - x - y <= N && 10000 * x + 5000 * y + 1000 * (N - x - y) == Y){
                cout << x << " " << y << " " << N - x - y << endl;
                return 0;
            }
        }
    }
    print("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
/*-*/

int main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<int> > g(n);
	rep(i,n-1) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	auto dfs = [&] (auto f, int i, int par) -> int {
		// -1 is win otherwise return parity
		int p=1;
		for(auto to:g[i]) {
			if(to==par) continue;
			int o=f(f,to,i);
			if(o==-1) return -1;
			if(o==1) p++;
		}
		if(p>2) return -1;
		return p%2;
	};
	int ans=dfs(dfs,0,-1);
	if(ans==1||ans==-1) print("First");
	else print("Second");
}


Measured memory_bytes: 5760
#include <stdio.h>
#define NIL -1
struct Node{
  int parent,left,right;
};
struct Node R[10000];
int n;
void preorder(int);
void inorder(int);
void postorder(int);

void preorder(int x){
  if(x==NIL)
    return;
  printf(" %d",x);
  preorder(R[x].left);
  preorder(R[x].right);
}
void inorder(int x){
  if(x==NIL)
    return;
  inorder(R[x].left);
  printf(" %d",x);
  inorder(R[x].right);
}
void postorder(int x){
  if(x==NIL)
    return;
  postorder(R[x].left);
  postorder(R[x].right);
  printf(" %d",x);
}

int main(){
  int i,a,b,c,root;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    R[i].parent=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&a,&b,&c);
    R[a].left=b;
    R[a].right=c;
    if(b!=NIL)R[b].parent=a;
    if(c!=NIL)R[c].parent=a;
  }
  for(i=0;i<n;i++){
    if(R[i].parent==NIL)
      root=i;
  }
  printf("Preorder\n");
  preorder(root);
  printf("\n");
  printf("Inorder\n");
  inorder(root);
  printf("\n");
  printf("Postorder\n");
  postorder(root);
  printf("\n");
  return 0;
}

  



Measured memory_bytes: 2056
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = Console.ReadLine().Split(' ');
            var A = int.Parse((K[0]));
            var B = int.Parse((K[1]));

            var ret = 0;
            if (A <= 5)
            {
                
            }else if (A <= 12)
            {
                ret = B / 2;
            }else
            {
                ret = B;
            }
            Console.Write(ret);
            

        }

    }

    //var N = int.Parse(Console.ReadLine());
    //var S = Console.ReadLine();
    //var K = Console.ReadLine().Split(' ');
}


Measured memory_bytes: 11092
N = int(input())
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
#print(A)
#print(B)

defeated_num = 0
for i in reversed(range(0, N)):
    if A[i + 1] <= B[i]:
        defeated_num += A[i + 1]
        B[i] -= A[i + 1]
        A[i + 1] = 0
        if A[i] <= B[i]:
            defeated_num += A[i]
            B[i] -= A[i]
            A[i] = 0
        else:
            defeated_num += B[i]
            A[i] -= B[i]
            B[i] = 0
    else:
        defeated_num += B[i]
        A[i + 1] -= B[i]
        B[i] = 0

#print(A)
#print(B)
print(defeated_num)

Measured memory_bytes: 18752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner (System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		sc.close();
		
		if(a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
	}

}

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

int main() {
    int N; cin >> N;
    vector<vector<pair<int, bool>>> T(N);
    rep(i, N) {
        int A; cin >> A;
        while(A--) {
            int x, y;
            cin >> x >> y;
            T[i].emplace_back(--x, y);
        }
    }
    int ans = 0;
    rep(mask, (1 << N)) {
        bool ok = true;
        rep(i, N) {
            if(mask & (1 << i)) {
                for(auto &t : T[i]) {
                    bool s = mask & (1 << t.first);
                    if(t.second ^ s) ok = false;
                }
            }
        }
        if(ok) ans = max(ans, __builtin_popcount(mask));
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>


using namespace std;


using ll = long long;


class node {
    public:
        node();
        ll k;
        node *l, *r, *p;
};


node::node()
    : l{nullptr}, r{nullptr}, p{nullptr}
{
}



node *root = nullptr;


void insert(node *n)
{
    node *parent, *now;
    now = root;
    while (now != nullptr) {
        parent = now;
        if (now->k <= n->k)
            now = now->r;
        else
            now = now->l;
    }

    if (root == nullptr)
        root = n;
    else if (parent->k <= n->k)
        parent->r = n;
    else
        parent->l = n;
}


void inorder(node *now, vector<ll> &log)
{
    if (now->l != nullptr)
        inorder(now->l, log);

    log.push_back(now->k);

    if (now->r != nullptr)
        inorder(now->r, log);
}


void preorder(node *now, vector<ll> &log)
{
    log.push_back(now->k);

    if (now->l != nullptr)
        preorder(now->l, log);

    if (now->r != nullptr)
        preorder(now->r, log);
}


void print_log(vector<ll> &log)
{
    for (auto it = log.begin(); it != log.end(); ++it) {
        cout << " " << *it;
    }
    cout << endl;
}


int main()
{
    ll N;
    cin >> N;
    for (ll i = 0; i < N; i++) {
        vector<ll> log;
        vector<node *> nodes;
        string cmd;
        node *n;
        ll k;

        cin >> cmd;
        switch(cmd[0]) {
            case 'i':
                cin >> k;
                n = new node;
                n->k = k;
                insert(n);
                break;
            case 'p':
                inorder(root, log);
                print_log(log);
                log.clear();

                preorder(root, log);
                print_log(log);
                log.clear();
                break;
        }
    }
}



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



int main() {
   int n;
   cin >> n;
   vector<string> s(n);
   for (int i=0; i<n; i++) {
      cin >> s[i];
   }
   sort(s.begin(), s.end());
   vector<string> ss;
   ss.push_back(s[0]);
   for (int i=0; i<n-1; i++) {
      if (s[i] != s[i+1]) {
         ss.push_back(s[i+1]);
      }
   }
   vector<int> cnt((int) distance(ss.begin(), ss.end()));
   int j = 0;
   for (int i=0; i<n-1; i++) {
      if (s[i] == s[i+1]) {
         cnt[j]++;
      }
      else j++;
   }
   int cntmax = *max_element(cnt.begin(), cnt.end());
   for (int i=0; i<(int) distance(ss.begin(), ss.end()); i++) {
      if (cnt[i] == cntmax) {
         cout << ss[i] << endl;
      }
   }
   return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

ll Modpow(ll a, int n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = Modpow(a, n/2);
    return res * res % mod;
  }
  return a * Modpow(a, n-1) % mod;
}


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

  int n;
  cin >> n;
  vl a(n);
  rep(i,n) cin >> a[i];
  vi cnt(60);
  rep(i,n) {
    bitset<60> b(a[i]);
    rep(j,60) {
      if(b[j]) cnt[j]++;
    }
  }
  ll ans = 0;
  rep(i,60) {
    ll cur = Modpow(2,i) * cnt[i] % mod;
    cur *= (n-cnt[i]);
    cur %= mod;
    ans += cur;
    ans %= mod;
  }
  cout << ans << endl;
}

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

int main() {
	ll n, m;
	cin >> n >> m;
	ll ans;
	if (n > m / 2) ans = m / 2;
	else ans = n + (m - 2 * n) / 4;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int a, b; scanf("%d%d", &a, &b);
	if(b == 1) {
		printf("0\n");
		return 0;
	}
	b = std::max(0, b - a);
	
	printf("%d\n", (b + a - 2) / (a - 1) + 1);
	return 0;
}


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

int
main(int argc, char** argv) {
    int n;
    std::cin >> n;

    std::multiset<int> mst;
    for (int i = 0; i < n; i++) {
        int d;
        std::cin >> d;
        mst.insert(d);
    }

    int ans = 0;
    int i = 0;
    int len = mst.size();
    int tmp;
    for (auto v: mst) {
        i++;
        if (i == (len/2)) {
            tmp = v;
        } else if (i == (len/2) + 1) {
            ans = v - tmp;
            break;
        }
    }
    std::printf("%d\n", ans);
    return 0;
}

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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF (1 << 29)

using namespace std;

/*class Point{
	public:
		double x, y;

		Point(double x = 0, double y = 0): x(x), y(y) {}

		Point operator + (Point p){ return Point(x + p.x, y + p.y); }
		Point operator - (Point p){ return Point(x - p.x, y - p.y); }
		Point operator * (double a){ return Point(a * x, a * y); }
		Point operator / (double a){ return Point (x / a, y / a); }

		double abs(){ return sqrt(norm()); }
		double norm(){ return x * x + y * y; }

		bool operator < (const Point &p) const{
			return x != p.x ? x < p.x : y < p.y;
		}

		bool operator == (const Point &p) const{
			return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
		}
};

class Segment{
	public:
		Point p1, p2;
		Segment(Point p1 = Point(), Point p2 = Point()): 
			p1(p1), p2(p2) {}
};

class Circle{
	public:
		Point c;
		double r;
		Circle(Point c = Point(), double r = 0.0): c(c) , r(r) {}
};

typedef Segment Line;
typedef vector<Point> Polygon;
typedef Point Vector;

double dot(Vector a, Vector b){
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
	return a.x * b.y - a.y * b.x;
}
*/

int n;
vector<int> v;

int func(){
	int cnt = 0;
	while(1){
		for(auto i : v){
			if(i % 2 == 1) return cnt;
		}
		for(auto &i : v) i /= 2;
		cnt++;
	}
}
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		int a; cin >> a;
		v.pb(a);
	}
	cout << func() << endl;
	return 0;
}


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

int main(){
  string S,T,U;
  int A,B;
  cin>>S>>T;
  cin>>A>>B;
  cin>>U;
  if(U==S) cout<<A-1<<" "<<B<<endl;
  else cout<<A<<" "<<B-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = a; i < (b + a); i++)
#define W1 while (1)
#define COUT(x) cout << x << endl
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define mod 1000000007
#define PB push_back
#define F first
#define S second

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int count = 0;
  while (a >= b) {
    count++;
    b *= 2;
  }
  while (b >= c) {
    count++;
    c *= 2;
  }
  if (count <= k) COUT("Yes");
  else COUT("No");

  return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}

//小文字=大文字+32

int main() {
	int n;
	cin >> n;
	pair<pair<string, int>,int>p[110];
	string s; 
	int a;
	rep(i, n){
		cin >> s >> a;
		p[i] = make_pair(make_pair(s, -a), i+1);
	}
	sort(p,p+n);
	rep(i, n) {
		cout<<p[i].second<<endl;
	}

}
	



Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

struct P {
  int dis;
  vector<int> ba, aki, mp;
  P() {
    dis = 0;
    ba.resize(32);
    mp.resize(32);
  }
  P(int dis, vector<int> ba, vector<int> aki, vector<int> mp) :
    dis(dis), ba(ba), aki(aki), mp(mp) {}
  bool goal() {
    REP(i, 32) {
      if (i%8 != 7 && ba[i] != i) return 0;
    }
    return 1;
  }
};


int main() {
  int n;
  cin >> n;
  while(n--) {
    P ini;
    REP(i, 4) {
      REP(j, 7) {
        int a;
        cin >> a;
        int suit = a/10-1;
        int val = a%10-1;
        if (val == 0) {
          ini.ba[suit*8+val] = suit*8+val;
          ini.aki.push_back(i*8+j+1);
          ini.ba[i*8+j+1] = -1;
        } else {
          ini.ba[i*8+j+1] = suit*8 + val;
          ini.mp[suit*8+val] = i*8+j+1;
        }
      }
    }
    queue<P> Q;
    Q.push(ini);
    int res = -1;
    map<vector<int>, bool> visited;
    while(!Q.empty()) {
      P now = Q.front();
      Q.pop();
      if (visited[now.ba]) continue;
      visited[now.ba] = 1;

      // REP(i, 32) {
      //   printf("%2d ", now.ba[i]);
      //   if (i%8==7) cout << endl;
      // }
      // cout << endl;
      
      if (now.goal()) {
        res = now.dis;
        break;
      }
      
      REP(i,4) {
        P next = now;
        int hoge = next.ba[next.aki[i]-1]+1;
        if (hoge%8 == 7 || hoge == 0) continue;
        swap(next.ba[next.aki[i]], next.ba[next.mp[hoge]]);
        swap(next.aki[i], next.mp[hoge]);
        if (visited[next.ba]) continue;
        next.dis++;
        Q.push(next);
      }
    }
    cout << res << endl;
  }
}

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

int main() {
	int N, ans;
	cin >> N;

	vector<int> L(N);
	for(int i = 0; i < N; i++)
	{
		cin >> L.at(i);
	}

	int sum = 0;
	for(int i = 0; i < L.size(); i++)
	{
		sum += L.at(i);
	}
	
	int max = *max_element(L.begin(), L.end());
	if (max < sum - max) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
const ll M=1e9+7;
const int MAXN=2e5+1;

ll tree[4*MAXN];

ll query(int node,int start,int end,int l,int r){
	if(start>r || end<l){
	
		return 0;
	}
	if(start>=l && end<=r){
		return tree[node];
	}
 
	int mid=(start+end)/2;
 
	ll prt1=query(2*node,start,mid,l,r);
	ll prt2=query(2*node+1,mid+1,end,l,r);
 
	
 
	return max(prt2,prt1);
}
 
void update(int node,int start,int end,int ind,ll val1){
	if(start==end){
		tree[node]=max(tree[node],val1);
		return ;
	}
	int mid=(start+end)/2;
 
	if(ind<=mid)
		update(2*node,start,mid,ind,val1);
	else
		update(2*node+1,mid+1,end,ind,val1);
 
	tree[node]=max(tree[2*node],tree[2*node+1]);

}



int main(){

	int n;
	sfi(n)

	map<int,int> mp;

	int arr[n];

	ll val[n];

	int k=1;

	f(i,0,n){ 
		sfi(arr[i])
		mp[arr[i]]=0;
	}

	for(auto it=mp.begin();it!=mp.end();++it){
		it->second=k;
		k++;
		
	}

	k--;

	f(i,0,n) sfl(val[i])


	ll ans[n];

	for(int i=0;i<n;i++){
		int x=mp[arr[i]];
		ans[i]=query(1,0,k,0,x-1);
		ans[i]+=val[i];
		update(1,0,k,x,ans[i]);
	}

	

	ll fin=*max_element(ans,ans+n);

	pfln(fin)


	return 0;	
}

Measured memory_bytes: 19712
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def get_block(X1, Y1, X2, Y2):
    # x1 から x2 の間にある、y方向の両端が y1 と y2 より大きいブロック
    if X1 > X2:
        X1, X2 = X2, X1
    if Y1 > Y2:
        Y1, Y2 = Y2, Y1
    size = pow(3, 30)
    for level in reversed(range(31)):
        x1 = X1 // size
        x2 = X2 // size
        y1 = Y1 // size
        y2 = Y2 // size
        if y1 == y2 and y1 % 3 == y2 % 3 == 1:
            # x1 と x2 の間に 1, 4, 7, ... があればそれ
            if x2 - x1 >= 2:
                while x1 % 3 != 1:
                    x1 += 1
                return x1 * size, y1 * size, size
        if x1 == x2 and x1 % 3 == x2 % 3 == 1:
            if y2 - y1 >= 2:
                while y1 % 3 != 1:
                    y1 += 1
                return x1 * size, y1 * size, size
        size //= 3
    return None


def dist(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)


def solve(X1, Y1, X2, Y2):
    # 一番大きい障害物を知りたい
    block = get_block(X1, Y1, X2, Y2)
    ret = INF
    if block:
        x, y, size = block
        for x, y in itertools.product((x - 1, x + size), (y - 1, y + size)):
            ret = min(ret, dist(X1, Y1, x, y) + dist(X2, Y2, x, y))
    else:
        ret = min(ret, dist(X1, Y1, X2, Y2))
    return ret


Q = int(sys.stdin.buffer.readline())
ABCD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]
for a, b, c, d in ABCD:
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    ans = solve(a, b, c, d)
    print(ans)


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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }


    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};


int main() {

    int n;
    cin >> n;
    vector<ll> frogs(n);
    rep(i, n) cin >> frogs[i];

    mint ans = 1;

    stack<ll> s;
    rep(i, n) {
        s.push(frogs[i]);
        if (frogs[i] < 2 * s.size() - 1) {
            ans *= s.size();
            s.pop();
        }
    }

    while(!s.empty()) {
        ans *= s.size();
        s.pop();
    }

    cout << ans << endl;
}


Measured memory_bytes: 1920
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 2*10^^9 + 7;

void main() {
    int n, k; scan(n, k);
    auto a = new int[](n);
    auto b = new int[](n);
    foreach (i ; 0 .. n) {
        int ai, bi; scan(ai, bi);
        a[i] = ai, b[i] = bi;
    }

    long ans;

    foreach (j ; 0 .. n) {
        if ((~k & a[j]) == 0) {
            ans += b[j];
        }
    }

    foreach (i ; 0 .. 32) {
        if (k & (1 << i)) {
            long tmp;
            int ks = k ^ (1 << i) | ((1<<i) - 1);
            debug {
                writefln("%16b", ks);
            }
            foreach (j ; 0 .. n) {
                if ((~ks & a[j]) == 0) {
                    tmp += b[j];
                }
            }
            ans = max(ans, tmp);
        }
    }

    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

bool comp(pii a, pii b){
  return a.first < b.first;
}

void Main() {
  int N; cin >> N;
  vector<pii> A(N);
  rep(i, 0, N){
    int tmp; cin >> tmp;
    A[i] = make_pair(tmp, i + 1);
  }
  sort(all(A), comp);
  rep(i, 0, N){
    cout << A[i].second;
    if(i != N - 1) cout << " ";
    else cout << endl;
  }
}

/////////////////////////////////////////////////////////

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

  Main();
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pair<int, int>, int> ppi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = 1000000005;
const int MAX = 300000;
const int MOD = 1000000007;
struct Graph{int to,coin; ll cost;};
struct Edge{int from,to,coin; ll cost;};
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------
int main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int ans = 0;
    int n;cin>>n;
    for(int i = 1; i <= n; i+=2) {
        int cnt = 0;
        for(int j = 1; j <= n; j++) {
            if(i%j==0) cnt++;
        }
        if(cnt==8) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3608
def find_max(n, grid):
    def helper(idx, cur_max, down):
        if n > (idx + 1):
            if down:
                return helper(idx + 1, cur_max + grid[1][idx], down)
            else:
                return max(helper(idx + 1, cur_max + grid[1][idx], True), helper(idx + 1, cur_max + grid[0][idx + 1], False))
        else:
            return cur_max + grid[1][idx]

    return helper(0, grid[0][0], False)

n = int(input())
candie_matrix = []
for i in range(2):
    row = list(map(int, input().split()))
    if len(row) != n:
        print("wrong inputs")

    candie_matrix.append(row)

print(find_max(n,candie_matrix))


Measured memory_bytes: 3064
from functools import reduce
a, b = map(int, input().split() )
aa = reduce(lambda y,x: y*x%1000000007, [i for i in range(1,a+1) ] )
bb = reduce(lambda y,x: y*x%1000000007, [i for i in range(1,b+1) ] )
if a == b :
  print(2*aa*bb%1000000007)
elif a+1 == b or a == b+1:
  print(aa*bb%1000000007)
else:
  print(0)

Measured memory_bytes: 7560