akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using namespace std;
ll power(ll a,ll n)
{
          ll result=1;
          while(n>0)
          {
               if(n&1)
                    result=result*a;
               a=a*a;
               n=n>>1;
          }
          return result;
}
ll lcm(ll a,ll b)
{
          return ((a*b)/__gcd(a,b));
}
bool ispow2(ll n)
{
          return (ceil(log2(n))==floor(log2(n)));
}
bool isprime(ll n)
{
          if(n==1)
               return false;
          else if(n==2)
               return true;
          else
          {
               for(ll i=2;i*i<=n;++i)
               {
                    if(n%i==0)
                         return false;
               }
               return true;
          }
}

ll ncr(ll n,ll r)
{
    if(r > n - r)
          r = n - r;
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++)
     {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
int main()
{
          ios_base::sync_with_stdio(0);
          cin.tie(0);

          int t=1;
          //cin>>t;
          while(t--)
          {
                    string s;
                    cin>>s;
                    int c=0;int ans=0;
                    int j;
                    for(int i=0;i<s.size();++i)
                    {
                         c=0;
                         if(s[i]=='R')
                         {
                              for( j=i;j<s.size();++j)
                              {
                                   if(s[j]=='R')
                                        c++;
                                   else
                                        break;
                              }
                              ans = max(ans,c);
                              i=j-1;
                         }
                    }
                    cout<<ans;
          }
          return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct pp{
	char name[10];
	int time;
};

int head=0, tail=0;
struct pp que[10000000];


void enqueue(struct pp *x){
	tail++;
	que[tail] = *x;
}


struct pp dequeue(){
	head++;
	return que[head];
}


int main(){
	int n, q, cnt=0, i, flag=0;
	struct pp temp;

	scanf("%d %d", &n, &q);
	tail = n;
	for(i=1; i<n+1; i++){
		scanf("%s %d", que[i].name, &que[i].time);
	}

	while(flag<n){
		temp = dequeue();
		if(temp.time>q){
			temp.time -= q;
			cnt += q;
			enqueue(&temp);
		}else{
			cnt += temp.time;
			printf("%s %d\n", temp.name, cnt);
			flag++;
		}
	}

	return 0;
}

Measured memory_bytes: 4688
#!/usr/bin/env pypy3

#import numpy as np
#import scipy, scipy.special

# Python 3 modules: https://docs.python.org/3/library/

import math, itertools, operator
from math import *
from math import factorial as fact
from operator import itemgetter, attrgetter
from itertools import permutations, combinations
from functools import reduce
# Use scipy for stats: https://docs.scipy.org/doc/scipy/reference/stats.html
# Before Python 3.5
from fractions import gcd

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(inp = input, sep = ' ', conv = int):
    return list(map(conv, inp().split(sep = sep)))

################################################################################

N, M = input_ints()
Smask = []
for i in range(M):
    l = input_ints()
    m = 0
    for j in l[1:]:
        m |= (1 << (j - 1))
    Smask.append(m)
P = input_ints()

def popcount(x):
    return bin(x).count('1')

cnt = 0
for i in range(1 << N):
    flag = True
    for j in range(M):
        mask = Smask[j]
        if popcount(i & mask) % 2 != P[j]:
            flag = False
            break
    if flag:
        cnt += 1
print(cnt)


Measured memory_bytes: 5760
N, M = map(int,input().split())

myAC = [0 for n in range(N+1)]
myWA = [0 for n in range(N+1)]

ansAC = 0
ansWA = 0


for m in range(M):
    a,  b = map(str, input().split())
    a = int(a)
    if b == 'WA' and myAC[a] != 1:
        myWA[a] += 1
        
    if b == 'AC' and myAC[a] != 1:
        myAC[a] = 1
        ansWA += myWA[a]
        ansAC += 1

#print(myAC)
#print(myWA)
print(ansAC,ansWA)


Measured memory_bytes: 4760
function Main(s) {
  var s = s.split("\n")[0].split(" ").map(e => e*1);
  var backet = new Array(101).fill(0);
  var cnt = 0;
  for(var i = s[0]; i <= s[1]; i++) backet[i]++;
  for(var i = s[2]; i <= s[3]; i++) backet[i]++;
  for(var i of backet) if(i === 2) cnt++;
  console.log(Math.max(cnt - 1, 0));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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


int main() {
    int a,b;
    cin >> a >> b;
    if(b%a == 0)cout << a+b << endl;
    else cout << b-a << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int f[55][55];

int main(){
  int H,W;
  cin >> H >> W;
  rep(i,0,H - 1){
    string s;
    cin >> s;
    rep(j,0,W - 1){
      f[i + 1][j + 1] = s[j] == '#';
    }
  }

  rep(i,1,H) rep(j,1,W){
    if(!f[i][j]) continue;
    int cnt = 0;
    cnt += f[i + 1][j];
    cnt += f[i - 1][j];
    cnt += f[i][j + 1];
    cnt += f[i][j - 1];
    if(cnt == 0){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" <<endl;


}


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

int main(void) {
  int X, A, B;
  cin >> X >> A >> B;
  if (A - B >= 0)
    cout << "delicious" << endl;
  else if (B - A <= X)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
void CountingSort(int *,int *,int);
int C[2000000],max=0;
int main(void){
  int n,A[2000000],B[2000000],i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(max<A[i])max=A[i];
  }
  CountingSort(A,B,n);
  for(i=0;i<n;i++){
    printf("%d",B[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n");
  return 0;
}
void CountingSort(int *A,int *B,int k){
  int i;
  for(i=0;i<=k;i++)
    C[i]=0;
 
  /* C[i] に i の出現数を記録する */
  for(i=0;i<k;i++)
    C[A[i]]++;
 
  /* C[i] に i 以下の数の出現数を記録する*/
  for(i=1;i<=max;i++)
    C[i]=C[i]+C[i-1];
 
  for(i=k-1;i>=0;i--){
    B[C[A[i]]-1]=A[i];
    C[A[i]]--;
  }
}


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

#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))

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


int main(){
int N;
cin>>N;
int cou=0;
int nn=N-1;
for(int i=1;i<=N;i++){
 cou=cou+nn/i;
}

cout<<cou<<endl;    
}

Measured memory_bytes: 3604
//**KEEP IT SHORT AND SIMPLE**
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a)* (b)).imag()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
typedef tuple<ll, ll, ll> line;
typedef complex<double> point;
const double pi = 2 * acos(0.0);
const int OO = 0x3f3f3f3f;
ll n, c[25], v[25];
ll solve(ll i)
{
    if(i == n)  return 0;
    return max(solve(i + 1) + c[i] - v[i], solve(i + 1));
}
int main()
{
    IO
    cin >> n;
    REP(i, 0, n)    cin >> c[i];
    REP(i, 0, n)    cin >> v[i];
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
	static BufferedReader br;

	public static void main(String[] args) {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			char[][] player = new char[3][];

			for (int i = 0; i < 3; i++) {
				player[i] = br.readLine().toCharArray();
			}
			System.out.println(play(player));
		} catch (Exception e) {
			System.err.println("Error : " + e.getMessage());
		}
	}

	private static char play(char[][] player) {
		int i = 0, j = 0;
		try {
			int a = 0, b = 0, c = 0;
			while (true) {
				switch (player[i][j]) {
				case 'a':
					i = 0;
					j = a++;
					break;
				case 'b':
					i = 1;
					j = b++;
					break;
				case 'c':
					i = 2;
					j = c++;
					break;
				default:
					break;
				}
			}
		} catch (Exception e) {
			char p = ' ';
			switch (i) {
			case 0:
				p = 'A';
				break;
			case 1:
				p = 'B';
				break;
			case 2:
				p = 'C';
				break;
			default:
				break;
			}
			return p;
		}
	}

}


Measured memory_bytes: 8020
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		Point[] P = new Point[N];
		for(int i = 0;i < N;i++) {
			P[i] = new Point(scn.nextLong(), scn.nextLong());
		}
		boolean chokudai = true;
		P = mergeSort(P);
		long ans = 0;
		for(int i = N-1;i > -1;i--) {
			if(chokudai) {
				ans += P[i].A;
			}else {
				ans -= P[i].B;
			}
			chokudai = !chokudai;
		}
		System.out.println(ans);

	}

	public static Point[] mergeSort(Point[] input) {
		// 分割の配列
		Point[] array = input;
		// 並び替えた数値を格納する配列。最終的にこの配列を返す。
		Point[] b = new Point[array.length];

		// 分割する添え字
		int middle = (0 + array.length - 1) / 2;
		// 分割した配列の前半分を格納する配列
		Point[] array1 = new Point[middle + 1];

		// 分割した配列の後ろ半分を格納する配列
		Point[] array2;
		// arrayの要素数が1以上のとき
		if (0 < array.length) {
			array2 = new Point[array.length - middle - 1];
			// arrayの要素数が0以下のとき
		} else {
			array2 = new Point[0];
		}

		// 要素数が1以下のときは、何もせず返却する
		if (array.length < 2) {
			return array;
		}
		// 前半部分をarray1にコピー
		System.arraycopy(array, 0, array1, 0, middle + 1);

		// 後半部分をarray1にコピー
		System.arraycopy(array, middle + 1, array2, 0, array.length - middle - 1);

		// 前半部分を並び替え（再帰的に）
		array1 = mergeSort(array1);

		// 後半部分を並び替え（再帰的に）
		array2 = mergeSort(array2);

		int bindex = 0;
		int array1index = 0;
		int array2index = 0;

		for (int i = 0; i < array.length - 1; i++) {
			if (array1index < array1.length && array2index < array2.length) {
				if (array1[array1index].C < array2[array2index].C) {
					b[bindex] = array1[array1index];
					array1index++;
				} else {
					b[bindex] = array2[array2index];
					array2index++;
				}
				bindex++;
			}
		}
		if (array1index > array2index) {
			for (int j = array2index; j < array2.length; j++, bindex++) {
				b[bindex] = array2[j];
			}
		} else {
			for (int j = array1index; j < array1.length; j++, bindex++) {
				b[bindex] = array1[j];
			}
		}
		return b;
	}

}

class Point{
	long A,B,C;
	Point(long A, long B){
		this.A = A;
		this.B = B;
		C = A+B;
	}
}


Measured memory_bytes: 96116
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
# sys.setrecursionlimit(int(pow(10,6)))
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    sys.stdin = open("input.txt", "r")
except:
    pass


# @lru_cache(None)
l,r,d=L()
ans=(r//d)-(l//d)+(l%d==0)
print(ans)

Measured memory_bytes: 10468
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#define fir first
#define sec second
using namespace std;
typedef long long ll;
const int maxn = 2e5+7;

int n;
int a[maxn];
vector<int> v[maxn];
ll ans[maxn];
ll res[maxn];

int main() {
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        scanf("%d",&a[i]);
        v[a[i]].push_back(i);
    }
    ll sum = 0;
    for(int i=1;i<=n;i++) {
        ll d = v[i].size();
        if(d == 0) continue;
        res[i] = d*(d-1)/2;
        sum += res[i];
        ans[i] = (d-1)*(d-2)/2;
        ans[i] -= res[i];
    }
    for(int i=0;i<n;i++) {
        printf("%lld\n",sum+ans[a[i]]);
    }
    return 0;
}

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

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


Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int Mod=998244353;
int n,m;
#define Maxn 305
int num[Maxn][Maxn];
bool vis[Maxn];
int val[Maxn][Maxn];
inline int Fast_Pow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1ll*ans*a%Mod;
		a=1ll*a*a%Mod;
		b>>=1;
	}
	return ans;
}

inline void rd(int &x){
	x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
}

int main(){
	rd(n);rd(m);
	for(register int i=1;i<=n;++i)
	    for(register int j=1;j<=m;++j)rd(num[i][j]);
	int res=Fast_Pow(2,n);
	int T=0;
	for(register int i=1;i<=n;++i)
	    for(register int j=m;j>=1;--j)
	        if(num[i][j]){
				if(!vis[j]){
					for(register int k=1;k<=m;++k)val[j][k]=num[i][k];
					vis[j]=true;
					T++;
					break;
				}else{
					for(register int k=1;k<=m;++k)num[i][k]^=val[j][k];
				}
	        }
	res=(res-Fast_Pow(2,n-T)+Mod)%Mod;
	printf("%d\n",1ll*res*Fast_Pow(2,m-1)%Mod);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
     cin>>n;
       int a[n][3];
      for(int i=0;i<n;i++)
      {
         cin>>a[i][0]>>a[i][1]>>a[i][2];
      }

      for(int i=1;i<n;i++)
      {
          a[i][0]+=max(a[i-1][1],a[i-1][2]);
            a[i][1]+=max(a[i-1][0],a[i-1][2]);
            a[i][2]+=max(a[i-1][0],a[i-1][1]);

      }


     cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]));
}


Measured memory_bytes: 1408
#include<stdio.h>
int n;
struct EDGE{
	int to,next;
}edge[200010];
int head[100010],tot=0;
inline void AddEdge(int a,int b){
	edge[++tot].to=b;
	edge[tot].next=head[a];
	head[a]=tot;
}
#define ty (edge[x].to)
int sta[100010],siz;
bool flag[100010];
bool Dfs(int u,int v){
	sta[++siz]=u;
	flag[u]=true;
	if(u==n) return true;
	for(int x=head[u];x;x=edge[x].next){
		if(ty==v) continue;
		if(Dfs(ty,u)) return true;
	}
	--siz;
	flag[u]=false;
	return false;
}
int Dfs2(int u,int v){
	int p=1;
	for(int x=head[u];x;x=edge[x].next){
		if(ty==v) continue;
		if(!flag[ty]) p+=Dfs2(ty,u);
	}
	return p;
}
int main(){
	scanf("%d",&n);
	int a,b;
	for(int i=1;i<n;++i){
		scanf("%d%d",&a,&b);
		AddEdge(a,b);
		AddEdge(b,a);
	}
	Dfs(1,0);
	int ans1=0,ans2=0;
	for(int i=1;i<=siz;++i){
		if(i<=((siz+1)>>1)) ans1+=Dfs2(sta[i],0);
		else ans2+=Dfs2(sta[i],0);
	}
	if(ans1>ans2) puts("Fennec");
	else puts("Snuke");
	return 0;
}
	

Measured memory_bytes: 7296
package main

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

func solve() {
	n := getInt()
	as := getIntSlice(n)

	ans := 0
	sum := 0
	r := 0
	for l := 0; l < n; l++ {
		r = max(r, l)
		for r < n {
			if (sum + as[r]) != (sum ^ as[r]) {
				break
			}
			sum += as[r]
			r++
		}
		ans += r - l

		sum -= as[l]
	}

	fmt.Fprintln(wr, ans)
}

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

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

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

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


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

void prime_factorize(int64_t N, set<int64_t> &pf)
{
  vector<pair<int64_t, int64_t>> res;
  for (int64_t a = 2; a * a <= N; a++)
  {
    if (N % a != 0)
      continue;
    int64_t ex = 0;
    while (N % a == 0)
    {
      ex++;
      N /= a;
    }
    pf.insert(a);
  }
  if (N != 1)
    pf.insert(N);
}

int main()
{
  int64_t A, B, ans = 1;
  set<int64_t> pfa, pfb;
  cin >> A >> B;
  prime_factorize(A, pfa);
  prime_factorize(B, pfb);
  for (auto n : pfa)
  {
    if (pfb.count(n))
      ans++;
  }
  cout << ans << endl;
}


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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int cntR = 0, cntB = 0;
    for(int i=0; i<N; ++i) {
        if(S[i] == 'R') ++cntR;
        else ++cntB;
    }
    
    if(cntR > cntB) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Array
import Data.Array.ST

main = do
    [n,w]<-map read.words<$>getLine::IO [Int]
    wvs<-replicateM n $ unfoldr (B.readInt.B.dropWhile(<'!'))<$>B.getLine::IO[[Int]]
    print $ f n w wvs

f n w wvs = runST $ do
    dp <- newArray ((0,0),(n,w)) 0 :: ST s (STUArray s (Int,Int) Int)
    forM_ [(i,wi,vi,j)|(i,[wi,vi])<-zip [1..] wvs,j<-[0..w]] $ \(i,wi,vi,j) ->
        writeArray dp (i,j) =<<
        if j< wi then readArray dp (i-1,j)
                 else max.(+vi) <$> readArray dp (i-1,j-wi) <*> readArray dp (i-1,j)
    readArray dp (n,w)

Measured memory_bytes: 80892
from collections import deque
k = int(input())
ans = 0
num = ["0","1","2","3","4","5","6","7","8","9"]
dq = deque(["1","2","3","4","5","6","7","8","9"])
# print(num[k:k+2])
if k<=12:
    print(k)
else:
    while 1:
        ans += 1
        a = dq.popleft()
        if ans == k:
            print(int(a))
            exit()
        for i in num[max(0,int(a[-1])-1):min(10,int(a[-1])+2)]:
            dq.append(a+i)

Measured memory_bytes: 17012
// -*- compile-command: "g++ -g -Wno-return-type -Wall -Wextra -DLOCAL -std=c++11 -D_GLIBCXX_DEBUG d.cpp -od && ./d " -*-
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#define int LL
#define vc vector
#define pb push_back
#define pr pair
#define fi first
#define se second
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define f(i,n) for(int i=0;i<(n);i++)
#define fr(i,n) for(int i=(n);i--;)
#define fv(i,v) f(i,sz(v))

int n,z,w;
int b[2000],d[2000][2];

int solve(int i,int x){
	if(~d[i][x]) return d[i][x];
	if(x){
		int r=b[i];
		for(int k=i+1;k<n;k++){
			r=max(r,solve(k,0));
		}
		return d[i][x]=r;
	}else{
		int r=b[i];
		for(int k=i+1;k<n;k++){
			r=min(r,solve(k,1));
		}
		return d[i][x]=r;
	}
}

main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>z>>w;
	vc<int> a(n);
	f(i,n) cin>>a[i];
	b[0]=abs(a[n-1]-w);
	f(i,n-1) b[i+1]=abs(a[i]-a[n-1]);
	memset(d,-1,sizeof(d));
	cout<<solve(0,1)<<'\n';
}


Measured memory_bytes: 384
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        mut x: usize,
    }

    let mut ans = 0;

    if 500 <= x {
        ans += x / 500 * 1000;
        x = x % 500;
    }

    if 5 <= x {
        ans += x / 5 * 5;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2200
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

count = 0

for i in range(n):
    count += min(a[i] + a[i+1], b[i])
    a[i+1] = max(a[i+1] + min(a[i] - b[i], 0), 0)

print(count)

Measured memory_bytes: 18468
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;


int main(){
int n,k,x,y;cin>>n>>k>>x>>y;
if(n<=k){cout<<n*x;return 0;}
    cout<<(n-k)*y+k*x;


}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<vector<int>> a(3,vector<int>(3));
for(int i = 0; i< 3; i++){
  for(int j = 0; j<3; j++){
    cin >> a.at(i).at(j);
  }
}
int N ;
cin >> N;
vector<vector<int>> b(N,vector<int>(1));
for(int i = 0; i< N; i++){
  cin >> b.at(i).at(0);
}
for(int i = 0;i< 3; i++){
  for(int j = 0; j<3; j++){
    for(int k = 0; k<N; k++){
      if(a.at(i).at(j)==b.at(k).at(0)){
        a.at(i).at(j) = 0;
      }
    }
    
  }
}
  for(int j = 0; j<3; j++){
    if(a.at(0).at(j)==0 && a.at(1).at(j)==0 && a.at(2).at(j)==0){
      cout << "Yes" << endl;
      return 0;
    }
    else if(a.at(j).at(0)==0 && a.at(j).at(2)==0 && a.at(j).at(1)==0){
      cout << "Yes" << endl;
      return 0;
    }
    else if(a.at(0).at(0)==0&&a.at(1).at(1)==0&a.at(2).at(2)==0){
      cout << "Yes" << endl;
      return 0;
    }
    else if(a.at(0).at(2)==0&&a.at(1).at(1)==0&a.at(2).at(0)==0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>


using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;


void fill(vvi&f, int x, int y, int is_black, int&k, int &w)
{
	static const int vx[]={ 1, 0,-1, 0};
	static const int vy[]={ 0, 1, 0,-1};

	if(is_black) k++;
	else w++;

	f[y][x]='*';
	for(int i=0;i<4;i++)
	{
		int nx=x+vx[i];
		int ny=y+vy[i];
		if(is_black && f[ny][nx]=='.') fill(f, nx, ny, 0, k, w);
		if(!is_black && f[ny][nx]=='#') fill(f, nx, ny, 1, k, w);
	}
}


int main(void)
{
	int h, w;

	while(scanf("%d%d\n", &h, &w)==2)
	{
		vvi f(h+2);
		for(auto&mf:f) mf.assign(w+2, -1);

		for(int y=1;y<=h;y++)
		{
			char s[w+10];
			scanf("%[.#]\n", s+1);
			for(int x=1;x<=w;x++)
			{
				f[y][x]=s[x];
			}
		}

		ll ans=0;
		for(int y=1;y<=h;y++)
		{
			for(int x=1;x<=w;x++)
			{
				if(f[y][x]=='#')
				{
					int k=0, w=0;
					fill(f, x, y, 1, k, w);
					ans+=(ll)k*w;
				}
			}
		}
		printf("%lld\n", ans);
	}

	return 0;
}



Measured memory_bytes: 13312
n,x=map(int,input().split())
l=list(map(int,input().split()))
list=[0]
cnt=0
for i in l:
  i=i+list[cnt]
  list.append(i)
  cnt+=1
ans=0
for i in list:
  if i<=x:
    ans+=1
print(ans)
  
  
  

Measured memory_bytes: 9076
#include<bits/stdc++.h>
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN      
using namespace std;
const ll mod=1e9+7;
const int N=2e5+4;

int n,k; 

int a[N];

bool check(int mid)
{
	ll total=0;

	rep(i,0,n)
	{
		int temp=a[i];

		temp=(temp+mid-1)/mid;

		temp--; total+=temp;
	}

	return total<=k;
}
 
int main()                  
{
    scn(n); scn(k);

    int mx=0;

    rep(i,0,n)
    scn(a[i]),mx=max(mx,a[i]);

    int ans=-1,low=1,high=mx;

    //cout<<check(2)<<endl;

    while(low<=high)
    {
    	int mid=(low+high)/2;

    	if(check(mid))
    	ans=mid,high=mid-1;
    	else
    	low=mid+1;
    }

    pri(low);

    return 0;
}

Measured memory_bytes: 4412
#include<iostream>
using namespace std;
int main() {
	int s,a,b,c,d; cin >> s;
	a = s / 1000;
	b = (s % 1000) / 100;
	c = (s % 100) / 10;
	d = s % 10;
	if (a == b || b == c || c == d)cout << "Bad" << endl;
	else cout << "Good" << endl;
}

Measured memory_bytes: 256
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) (*find_by_order(i))
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
using cd = complex<double>;
const double pi = acos(-1);
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
#define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/


void solve(){
    int n;
    cin >> n;
    n--;
    int sum = 0;
    int i = 1;
    while(sum + pow(26, i) <= n)sum += pow(26, i), i++;
    n -= sum;
    vi v(i, 0);
    rep(j, 0, i){
        v[j] = n%26;
        n /= 26;
    }
    reverse(all(v));
    for(auto j : v)cout << (char)(j+'a');
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 4056
n, m = map(int, input().split())
d = [[] for i in range(n)]    


for _ in range(m):
    p, s = input().split()
    p = int(p) - 1
    d[p].append(s)

ac_cnt, w_cnt = 0, 0
for l in d:
    if len(l) != 0 and "AC" in l:
        w_cnt += l.index("AC")

    if "AC" in l:
        ac_cnt += 1

print(ac_cnt, w_cnt)


Measured memory_bytes: 20376
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashSet<Integer> hs = new HashSet<>();
		for(int i = 0; i < n; i++) {
			hs.add(sc.nextInt());
		}
		System.out.println(hs.size());
	}
}


Measured memory_bytes: 21840
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <list>
#include <functional>
#include <algorithm>

using namespace std;

unsigned long long ns[35];

int main(int, char**){
    ns[0] = 1;
    ns[1] = 2;
    ns[2] = 4;
    for(int i(3);i<31;++i)
	ns[i]=ns[i-1]+ns[i-2]+ns[i-3];
    int n;
    while(cin >> n){
	if (n ==0) break;
	int tmp = ns[n-1] / (365*10) + (ns[n-1] % 3650 != 0);
	cout << tmp <<endl;
    }
    return 0;
}

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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int h, a;
  cin >> h >> a;
  if (h % a == 0)
    cout << h / a << endl;
  else
    cout << h / a + 1 << endl;
}


Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
alias invmod=(long x,long n,long m=10^^9+7)=>powmod(x,m-2,m);alias powmod=(long x,long n,long m=10^^9+7)=>
std.math.powmod(cast(ulong) x,cast(ulong) n,cast(ulong) m);
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    auto cnt1 = new long[](N);
    auto cnt2 = new long[](N);
    foreach (i; 0 .. N)
    {
        cnt1[abs(i - (N - 1 - i))]++;
        cnt2[A[i]]++;
    }
    if (zip(cnt1, cnt2).any!"a[0] != a[1]"())
    {
        writeln(0);
        return;
    }
    writeln(Mod(2) ^^ Mod(N / 2));

}

struct Mod
{
    alias T = long;
    T data, m;
    alias data this;
    this(T x, T m = 10 ^^ 9 + 7)
    {
        this.data = x;
        this.m = m;
    }

    Mod opBinary(string op, R)(R rhs)
    {
        static if (op == "-")
            return Mod((m + data - rhs) % m, m);
        static if (op == "^^")
            return Mod(std.math.powmod(cast(ulong) data, cast(ulong) rhs, cast(ulong) m), m);
        static if (op == "/")
            return Mod(data * std.math.powmod(cast(ulong) rhs, cast(ulong) m - 2, cast(ulong) m) % m,
                    m);
        return Mod(mixin("data " ~ op ~ " rhs") % m, m);
    }

    Mod opUnary(string op)()
    {
        static if (op == "-")
            return Mod((m + data - 1) % m, m);
        return Mod(mixin(op ~ "data") % m, m);
    }
}


Measured memory_bytes: 8104
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

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

typedef struct point2d{
  int64 x,y;
} point;

typedef struct line2d{
  point s,t;
} line;

void swap(int64 *a,int64 *b){
  int64 tmp=*a;
  *a=*b;
  *b=tmp;
}

int func(const line *a,const point *b){
  int64 p=a->s.x;
  int64 q=a->s.y;
  int64 r=a->t.x;
  int64 s=a->t.y;
  int64 t=(s-q)*(b->x-p)-(r-p)*(b->y-q);
  return t==0?0:(t>0?1:-1);
}

int isIntersect(const line *a,const line *b){
  int p=func(a,&(b->s));
  int q=func(a,&(b->t));
  int r=func(b,&(a->s));
  int s=func(b,&(a->t));
  if(p==0 && q==0 && r==0 && s==0){//同一直線上に2つの線分有り
    if(a->s.x!=a->t.x){
      int64 p=a->s.x;
      int64 q=a->t.x;
      int64 r=b->s.x;
      int64 s=b->t.x;
      if(p>q) swap(&p,&q);
      if(r>s) swap(&r,&s);
      return !(p>s || r>q);
    } else {
      int64 p=a->s.y;
      int64 q=a->t.y;
      int64 r=b->s.y;
      int64 s=b->t.y;
      if(p>q) swap(&p,&q);
      if(r>s) swap(&r,&s);
      return !(p>s || r>q);
    }
  }
  return p*q<=0 && r*s<=0;
}

void scanfLine(line *a){
  scanf("%lld%lld%lld%lld",&(a->s.x),&(a->s.y),&(a->t.x),&(a->t.y));
  return;
}

double calcPointDistance(const point *a,const point *b){
  int64 p=a->x;
  int64 q=a->y;
  int64 r=b->x;
  int64 s=b->y;
  double l= sqrt((p-r)*(p-r)+(q-s)*(q-s));
  return l;
}

int64 calcLinePointDistanceInnerFunction(const line *x,const point *y){
  int64 a=x->s.x;
  int64 b=x->s.y;
  int64 c=x->t.x;
  int64 d=x->t.y;
  int64 s=y->x;
  int64 t=y->y;
  int64 pq=ABS((s-a)*(s-a)+(t-b)*(t-b)-((s-c)*(s-c)+(t-d)*(t-d)));
  int64 ll=(a-c)*(a-c)+(b-d)*(b-d);
  return pq<=ll;;
}

double calcLinePointDistance(const line *a,const point *b){
  double p=calcPointDistance(&(a->s),b);
  double min=p;
  double q=calcPointDistance(&(a->t),b);
  min=MIN(min,q);
  double l=calcPointDistance(&(a->s),&(a->t));
  if(calcLinePointDistanceInnerFunction(a,b)){
    int64 p=a->s.x-b->x;
    int64 q=a->s.y-b->y;
    int64 r=a->t.x-b->x;
    int64 s=a->t.y-b->y;
    double area=ABS(p*s-q*r);
    min=MIN(min,area/l);
  }
  return min;
}

double calcLineDistance(const line *a,const line *b){
  if(isIntersect(a,b)) return 0;

  //2点間の距離の計算
  double min=calcLinePointDistance(a,&(b->s));
  min=MIN(min,calcLinePointDistance(a,&(b->t)));
  min=MIN(min,calcLinePointDistance(b,&(a->s)));
  min=MIN(min,calcLinePointDistance(b,&(a->t)));
  return min; 
}

void run(void){
  int q;
  scanf("%d",&q);
  while(q--){
    line a,b;
    scanfLine(&a);
    scanfLine(&b);
    double ans=calcLineDistance(&a,&b);
    printf("%.9lf\n",ans);
  }
  return;
}

int main(void){
  run();
  return 0;
}



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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A.at(i);
  }

  int sum = 0;
  for (int i=0; i<N; i++) {
    sum += A.at(i);
  }
  
  int count = 0;
  for (int i=0; i<N; i++) {
    if (A.at(i)*4*M >= sum) {
      count++;
    }
  }
  
  if (count < M) {
    cout << "No" << endl;
  }
  
  else {
    cout << "Yes" << endl;
  }
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

using namespace std;
const int inf=1000000010;

set<int> dp[200][200];
string in;

set<int> rec(int s,int t){
	if(dp[s][t].count(inf))return dp[s][t];
	
	dp[s][t].insert(inf);
	int i=s,d=0,found=0;
	
	for(;i<t;i++){
		if(in[i]=='(')d++;
		if(in[i]==')')d--;
		
		if(d==0&&(in[i]=='+'||in[i]=='-'||in[i]=='*'||in[i]=='/')){
			found=1;
			
			set<int> l=rec(s,i-1), r=rec(i+1,t);
			fr(ii,l)fr(jj,r){
				if(*ii==inf||*jj==inf)continue;
				
				if(in[i]=='+')dp[s][t].insert(*ii + *jj);
				if(in[i]=='-')dp[s][t].insert(*ii - *jj);
				if(in[i]=='*')dp[s][t].insert(*ii * *jj);
				if(in[i]=='/'&&*jj!=0)dp[s][t].insert(*ii / *jj);
			}
		}
	}
	if(!found){
		if(in[s]=='(')return dp[s][t]=rec(s+1,t-1);
		
		stringstream ss(in.substr(s,t-s+1));
		int n; ss>>n;
		dp[s][t].insert(n);
	}
	return dp[s][t];
}
int main()
{
	while(cin>>in,in!="#"){
		rep(i,200)rep(j,200)dp[i][j].clear();
		
		rec(0,in.size()-1);
		cout<<dp[0][in.size()-1].size()-1<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	string s ,t;
	cin>>s;
	cin>>t;
	string ans = "No";
	for(int i =0; i< t.size(); i++){
		rotate(t.begin(),t.begin()+1,t.end());
		if(t==s){
			ans = "Yes";
			break;
			}
		
			
				
		}
	cout<<ans;
	
	return 0;
	}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

int main(){
  int n;
  cin>>n;
  std::cout << (n-2)*180 << std::endl;
    
  return 0;
}


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

using namespace std;

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

#define INF 2<<29
#define F first
#define S second

int main(){
  int n;
  int k[10005];
  int cnt;
  int cnt0;

  while(1){
    scanf("%d",&n);
    if(n==0) break;
    
    cnt=0;
    cnt0=0;
    for(int i=0;i<n;i++){
      scanf("%d",&k[i]);
      cnt=max(k[i],cnt);
      if(k[i]==0) cnt0++;
    }
    
    if(cnt<2){
      printf("NA\n");
    }else{
      printf("%d\n",n+1-cnt0);
    }
  }
  
  return (0);
}



Measured memory_bytes: 3224
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

constexpr int MAX = 1000000000;

struct data {
	int id, len;
	data(int id_ = 0, int len_ = 0):id(id_), len(len_) {}
};

vector<data> disk;

inline void Write() {
	int id, size;
	cin >> id >> size;

	for(auto it = begin(disk); it != end(disk); ++it) {
		if(it->id == -1) {
			if(size <= it->len) {
				it->len -= size;
				disk.insert(it, data(id, size));
				return;
			}
			else {
				it->id = id;
				size -= it->len;
			}
		}
	}
}

inline void Delete() {
	int id;
	cin >> id;

	for(auto &e : disk) {
		if(e.id == id) e.id = -1;
	}
}

inline void Read() {
	int pos;
	cin >> pos;

	for(const auto &e : disk) {
		if(pos < e.len) {
			cout << e.id << '\n';
			return;
		}
		pos -= e.len;
	}
	assert(false);
}

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

	void (*func[128])();
	func['W'] = &Write;
	func['D'] = &Delete;
	func['R'] = &Read;

	for(int n; cin >> n && n;) {
		disk.assign(1, data(-1, MAX + 1));

		for(int i = 0; i < n; ++i) {
			char c;
			cin >> c;
			func[c]();
		}

		cout << '\n';
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1320
# -*- coding: utf-8 -*-
N=input()

#約数列挙
def make_divisors(n):
    divisors=[]
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n/i:
                divisors.append(n/i)
    return divisors

#整数N-1の約数は全て答えにカウントして良い
ans=set(make_divisors(N-1))
wrong_ans=set(make_divisors(N-1))

K=make_divisors(N)  #Nの約数の集合
#整数Nの約数について条件にマッチングするかを1つ1つ調べる
for k in K:
    if k==1: continue
    n=N
    while n%k==0:
        n/=k
    else:
        if n==1 or n%k==1:
            ans.add(k)
print len(ans)-1


Measured memory_bytes: 29932
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second 
//#define int   long long
#define ll   long long
#define pii pair<int, int>
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vl vector<long long>
#define vii vector< vector<int> >  
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
#define cd complex<double>
#define PI 4*atan(1)
#define pi 3.14159265358979323846//20 decimals
#define ld long double

const ll mod = 1000000007;
//const ll mod = 998244353;

ll powmod(ll a,ll p){
	ll ans=1;
	while(p){
		if(p&1) ans*=a;
		p/=2;a*=a; ans%=mod;a%=mod;
	}
	return ans;
}
ll mdinv(ll a){return powmod(a,mod-2); }

double func(int a, int b, int c, vector<vector<vector<double> > > &dp, int n){
    if(dp[a][b][c] >= -0.5)return dp[a][b][c];
    double tot = a + b + c;
    double val = 1;
    if(a > 0)val += ((double)a/n)*(func(a-1, b+1, c, dp, n));
    if(b > 0)val+=((double)b/n)*(func(a, b-1, c+1,dp, n));
    if(c > 0)val+= ((double)c/n)*(func(a,b,c-1,dp, n));
    val*=((double)n/(a+b+c));
    return dp[a][b][c] = val;
}

int main(){
    FAST
    int n;
    cin>>n;
    vector<vector<vector<double> >  > dp(n+1, vector<vector<double> >(n+1, vector<double>(n+1, -1)));
    int a = 0, b=0, c=0;
    for(int i =0; i<n; i++){
        int u;
        cin>>u;
        if(u == 3)a++;
        else if(u == 2)b++;
        else c++;
    }
    dp[0][0][0] = 0;
    double ans = func( a, b,  c,  dp, n);
    cout<<setprecision(18)<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 216960
s = input()
s = s[::-1]
check = ('dream', 'dreamer', 'erase', 'eraser', '')

ns = ''
len_ns = 0
for i in s:
    ns = i + ns
    len_ns += 1
    if len_ns < 5:continue
    if 5 <= len_ns <= 7:
        if ns in check:
            ns = ''
            len_ns = 0
    else:
        print('NO')
        exit()
else:
    if ns not in check:
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 3316
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

const int MOD = 1e9 + 7;
int power(int n, int p)
{
    if (p == 0)
        return 1;
    long long res = 1;
    long long add = n;
    while (p > 0)
    {
        if (p & 1)
            res = (res * add) % MOD;
        p >>= 1;
        add = add*add%MOD;
    }
    return res;
}

      


int getinv(int n) {
    static int invtable[100005];
    if (invtable[n])
        return invtable[n];
    return invtable[n] = power(n, MOD - 2);
}

int comb(int n, int r) {
    long long res = 1;
    for (int i = n - r + 1; i <= n; i++)
        res = (res * i) % MOD;
    for (int i = 1; i <= r; i++)
        res = (res * getinv(i)) % MOD;

    return res;
}
      
int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    ll invtable[100005] = {};
    REP(i, 100005)
        invtable[i] = power(i, MOD-2);


    vector<ll> accum(100005, 0);
    accum[0] = 1;
    IFOR(i, 1, 100004){
        ll newval = ((accum[i-1] * (i+k-1))%MOD * invtable[i]) % MOD;
        accum[i] = newval % MOD;
    }


    ll ans = 0;
    IFOR(i, 1, n){
        if(i<=n-k+1)
            ans = (ans + MOD - a[i-1]*accum[n-i-k+1]) % MOD;
        if(i>=k)
            ans = (ans + a[i-1]*accum[i-k]) % MOD;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 3003

using namespace std;

const int mod = 1e9 + 7, inv = (mod + 1) / 2;

int n, m;
int a[N], f[N][N], x[N][2], y[N][2];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			if(a[i] > a[j]) f[i][j] = 1;
	int sum = 1;
	while(m--){
		int X, Y; (sum *= 2) %= mod;
		scanf("%d%d", &X, &Y);
		for(int i = 1; i <= n; ++i){
			x[i][0] = f[X][i], x[i][1] = f[i][X];
			y[i][0] = f[Y][i], y[i][1] = f[i][Y];
		}
		for(int i = 1; i <= n; ++i){
			f[X][i] = 1ll * inv * (x[i][0] + y[i][0]) % mod;
			f[i][X] = 1ll * inv * (x[i][1] + y[i][1]) % mod;
			f[Y][i] = 1ll * inv * (y[i][0] + x[i][0]) % mod;
			f[i][Y] = 1ll * inv * (y[i][1] + x[i][1]) % mod;
		}
		f[X][Y] = f[Y][X] = 1ll * inv * (x[Y][0] + y[X][0]) % mod;
	}
	int ans = 0;
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			(ans += f[i][j]) %= mod;
	ans = 1ll * ans * sum % mod;
	cout << ans << endl;
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int W, H;
int p[100010], q[100010];
ll sp, sq;
ll ret;

int main() {
	cin >> W >> H;

	rep(i, W) {
		cin >> p[i];
		sp += p[i];
	}

	rep(i, H) {
		cin >> q[i];
		sq += q[i];
	}

	sort(p, p + W);
	sort(q, q + H);

	ll t = sp + sq;
	ret = min(t + sp * H, t + sq * W);

	int a=0,b=0;

	while (a<W || b<H) {
		if (a<W && (b==H || p[a] <= q[b])) {
			t += (ll)p[a]*(H-b);
			++a;
		} else {
			t += (ll)q[b]*(W-a);
			++b;
		}
	}

	cout << t << endl;

	return 0;
}

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

int main(){
	long long n,m;
	cin>>n>>m;
	long long inf=1e9+7;

	if(abs(n-m)>1){
		cout<<0<<endl;
		return 0;
	}

	long long ans=1;

	for(long long i=1;i<=n;i++){
		ans=(ans*i)%inf;
	}

	for(long long i=1;i<=m;i++){
		ans=(ans*i)%inf;
	}

	cout<<(n==m ? (ans*2)%inf : ans)<<endl;//(条件)?真の処理:偽の処理; //:ansのansってどのans?
	return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

int COUNT[100010];
long long SUM[100011];

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

    vector<pair<int, int>> pairs(M);
    vector<long long> ids(M);
    int P, Y;
    rep(i, M) {
        cin >> P >> Y;
        pairs[i] = (make_pair(P, Y));
        COUNT[P]++;
        ids[i] = (P * pow(10, 10) + Y);
    }

    rep(i, 100010) SUM[i + 1] = COUNT[i] + SUM[i];

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

    rep(i, M) {
//        cout << ids[i] << endl;
        long long idx = lower_bound(ids.begin(), ids.end(), pairs[i].first * pow(10, 10) + pairs[i].second) - ids.begin();
        idx -= SUM[pairs[i].first];
        printf("%06d%06d\n", pairs[i].first, idx + 1);
    }
}

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

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;

  if (U == S) {
    A--;
  } else {
    B--;
  }
  printf("%d %d\n", A, B);

  return 0;
}


Measured memory_bytes: 256