akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

struct Node{
	Node *right;
	Node *left;
	Node *parent;
	int key;
};

Node *root,*NIL;

void insert(int k){
	Node *x=root,*y=NIL,*z;
	
	z=(Node *)malloc(sizeof(Node));
	z->key=k;
	z->left=NIL;
	z->right=NIL;
	
	while(x!=NIL){
		y=x;
		if(z->key<x->key){
			x=x->left;
		}else{
			x=x->right;
		}
	}
	
	z->parent=y;
	if(y==NIL){
		root=z;
	}else{
		if(z->key<y->key){
			y->left=z;
		}else{
			y->right=z;
		}
	} 
}

void preParse(Node *u){
	if(u==NIL) return;
	cout<<" "<<u->key;
	preParse(u->left);
	preParse(u->right);
}

void inParse(Node *u){
	if(u==NIL) return;
	inParse(u->left);
	cout<<" "<<u->key;
	inParse(u->right);
}

int main(){
	int n,x;
	string com;
	
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>com;
		if(com=="insert"){
			cin>>x;
			insert(x);
		}
		if(com=="print"){
			inParse(root);
			cout<<endl;
			preParse(root);
			cout<<endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 26560
#include <iostream>
using namespace std;
int main(void){
    int a;
    int b;
    cin >>a>>b;
    if(a > b){
        cout << "a"<<" > "<<"b"<<endl;
    }
    else if(a == b){
        cout << "a"<<" == "<<"b"<<endl;
    }
    else{
        cout << "a"<<" < "<<"b"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    sort(all(s));
    sort(all(t));
    reverse(all(t));
    cout << (s < t ? "Yes" : "No") << endl;
}

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

namespace AtCoder_Tutorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            string unit = "";
            switch (N%10)
            {
                case 2:
                case 4:
                case 5:
                case 7:
                case 9:
                    unit = "hon";
                    break;
                case 0:
                case 1:
                case 6:
                case 8:
                    unit = "pon";
                    break;
                case 3:
                    unit = "bon";
                    break;
                default: unit = "";
                    break;
            }
            Console.WriteLine(unit);
        }
    }
}


Measured memory_bytes: 27176
#include <iostream>
#include <string>

using namespace std;
int main(void) {
    int count_5 = 0;
    int count_7 = 0;

    for (size_t i = 0; i < 3; i++)
    {
        int in;
        const int FIVE = 5;
        const int SEVEN = 7;

        cin >> in;
        if (in == FIVE)
            count_5++;
        if (in == SEVEN)
            count_7++;
    }
    {
    const string YES("YES");
    const string NO("NO");
    const int crect_5 = 2;
    const int crect_7 = 1;
    if (count_5 == crect_5 && count_7 == crect_7)
        cout << YES << endl;
    else
        cout << NO << endl;
    }
}

Measured memory_bytes: 256
import sys            
input = sys.stdin.readline

def main():                      
    N,M = map(int,input().split())
    S = [[int(s)-1 for s in input().split()[1:]] for _ in range(M)]
    P = [int(p) for p in input().split()]  
    
    ans = 0
    
    for i in range(2**N):
        state = [(i>>j)%2 for j in range(N)]
        ans += sum([sum([state[s] for s in S[j]])%2==P[j] for j in range(M)])==M
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 42588
#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN = (int) 5e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

LL N,P,Q;
LL C[MAXN];

void work(){
    scanf("%lld%lld%lld",&N,&P,&Q);
    for(int i=0;i<N;i++) scanf("%lld",&C[i]);
    LL ans=(LL)P*(N*(2*Q+N-1)/2);
//    printf("ans = %lld\n",ans);
    for(int i=0;i<N;i++) C[i]=C[i]-P*(Q+i)-2*P*(N-1-i);
//    for(int i=0;i<N;i++) printf("%lld ",C[i]);
//    printf("\n");
    sort(C,C+N);
//    for(int i=0;i<N;i++) printf("%lld ",C[i]);
    LL ret=ans;
    for(int i=0;i<N;i++){
        ans+=C[N-1-i]+P*i*2;
        ret=max(ret,ans);
    }
    printf("%lld\n",ret);
}

int main(){
#ifdef NNever
    freopen("data.in","r",stdin);
//    freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}



Measured memory_bytes: 7208
N, M = map(int, input().split())
AC = set()
wa = [0] * (N+1)

for _ in range(M):
    p, s = input().split()
    p = int(p)
    if not p in AC:
        if s == 'AC':
            AC.add(p)
        if s == 'WA':
            wa[p] += 1

wa_ans = 0
for i in AC:
    wa_ans += wa[i]

print(len(AC), wa_ans)

Measured memory_bytes: 12652
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type data struct {
	a, i int
}

// Datas :
type Datas []data

func (p Datas) Len() int {
	return len(p)
}

func (p Datas) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Datas) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].i > p[j].i
	}
	return p[i].a > p[j].a
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make(Datas, N)
	for i := 0; i < N; i++ {
		x := getInt()
		a[i] = data{x, i}
	}
	sort.Sort(a)
	a = append(a, data{0, 0})
	b := make([]int, N)
	b[0] = a[0].i
	for i := 1; i < N; i++ {
		b[i] = min(a[i].i, b[i-1])
	}
	// out(a)
	// out(b)
	s := make([]int, N)
	for i := 0; i < N; i++ {
		n := a[i].a - a[i+1].a
		m := b[i]
		// out(n, n*(i+1), m)
		s[m] += n * (i + 1)
		// out(s)
	}

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for _, v := range s {
		fmt.Fprintln(w, v)
	}
}


Measured memory_bytes: 8576
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	long long ans = 1, i, j, k, l, m, n, N, M, cnt = 0;
	string A[50], B[50];

	cin >> N >> M;
	for (i = 0; i < N; i++)
		cin >> A[i];
	for (i = 0; i < M; i++)
		cin >> B[i];

	int al, bl;
	al = A[0].length(); bl = B[0].length();

	for (i = 0; i < N - M + 1; i++) {
		for (j = 0; j < al - bl + 1; j++) {
			if (A[i][j] == B[0][0]) {
				cnt = 0;
				for (k = 0; k < bl; k++) {
					for (l = 0; l < M; l++) {
						if (A[i + l][j + k] == B[l][k])
							cnt++;
					}
				}
				if (cnt == bl * M) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}

	cout << "No" << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;


int cost[6] = {100, 101, 102, 103, 104, 105};


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int x;
    cin >> x;
    rep (i, x / 105 + 1) {
        int a = i * 105;
        if (a == x) {
            cout << 1 << endl;
            return 0;
        }
        if (a > x) break;
        rep (j, (x - a) / 104 + 1) {
            int b = a + j * 104;
            if (b == x) {
                cout << 1 << endl;
                return 0;
            }
            if (b > x) break;
            rep (k, (x - b) / 103 + 1) {
                int c = b + k * 103;
                if (c == x) {
                    cout << 1 << endl;
                    return 0;
                }
                if (c > x) break;
                rep (l, (x - c) / 102 + 1) {
                    int d = c + l * 102;
                    if (d == x) {
                        cout << 1 << endl;
                        return 0;
                    }
                    if (d > x) break;
                    rep (m, (x - d) / 101 + 1) {
                        int e = d + m * 101;
                        if (e == x) {
                            cout << 1 << endl;
                            return 0;
                        }
                        if (e > x) break;
                        rep (n, (x - e) / 100 + 1) {
                            int f = e + n * 100;
                            if (f == x) {
                                cout << 1 << endl;
                                return 0;
                            }
                            if (f > x) break;
                        }
                    }
                }
            }
        }
    }
    cout << 0 << endl;
    
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// 窓の長さ
		int b = sc.nextInt();
		// カーテンの長さ
      if((a - 2*b) >= 0){
		System.out.println(a - 2*b);
      }
      if((a - 2*b) < 0){
		System.out.println(0);
      }
	}
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  double ans;
  for(int i=n;i>=1;i--){
    ans=i;
    if(sqrt(ans)-(int)sqrt(ans)==0) break;
  }
  cout<<(int)ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long int  a[100500];
int flag[100500];
bool cmp(int a,int b){
    return a>b;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
    }
    memset(flag,0,sizeof(flag));
    sort(a,a+n,cmp);
    long long int  x,y;
    x=y=0;
    int fg=0;
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]&&!flag[i]){
            if(!x) x=a[i];
            else{
                y=a[i];
                break;
            }
            flag[i]=1;
            flag[i+1]=1;
        }
    }
    long long int  sum;
    sum=x*y;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include <cstdio>

using namespace std;

int main() {

	int no[30] = {0};
	int N,m,a,b;
	char connma;

	cin >> N;
	cin >> m;

	for (int i = 0; i < N; i++) {
		no[i] = i+1;
	}
	
	for (int i = 0; i < m; i++) {
		cin >> a >> connma >> b;
		swap(no[a - 1], no[b - 1]);
	}

	for (int i = 0; i < N; i++) {
		cout << no[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
def main():
  n, m = (int(x) for x in input().split())
  a_list = list(map(int, input().split()))
  sum_num = 0
  sum_num = sum(a_list)
  count = 0
  for i in a_list:
    if(i >= sum_num/(4 * m)):
      count += 1

  if(count >= m):
    print('Yes')
  else:
    print('No')

if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

//デバッグ
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/


int main(){
  ll N;
  cin >> N;
  vector <pair<ll, ll>> A(N);
  rep(i, N){
    cin >> A[i].f;
    A[i].f--;
    A[i].s = i;
  }
  sort(A.begin(), A.end());
  rep(i, N){
    cout << A[i].s + 1;
    if(i == N-1) cout << endl;
    else cout << " ";
  }

}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<ld> a(n);
  rep(i,n){
    cin >> a[i];
  }
  vector<vector<ld>> dp(3010, vector<ld>(3010,0));
  dp[0][0]=1;
  REP(i,1,n+1){ //coin
    rep(j,i+1){ //j:ura
      int k = i-j;
      if(k>0) dp[k][j] += dp[k-1][j] * a[i-1];
      if(j>0) dp[k][j] += dp[k][j-1]*(1-a[i-1]);
    }
  }
  ld ans = 0.0;
  rep(i,(n+1)/2){
    ans += dp[n-i][i];
  }
  cout << fixed << setprecision(10) << ans << ln;
  return 0;
}

Measured memory_bytes: 142080
MOD = 10 ** 9 + 7
h, w = map(int, input().split())
grid = '#' * (w + 2)
for _ in range(h):
    grid += '#' + input() + '#'
grid += '#' * (w + 2)
D = [0] * len(grid)
start = w + 3
goal = -(w + 4)
D[start] = 1
for i in range(start + 1, len(grid)):
    if grid[i] == '#':
        continue
    D[i] = (D[i - 1] + D[i - (w + 2)]) % MOD
print(D[goal])

Measured memory_bytes: 43632
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <map>
 
 
using namespace std;
 
 
int main()
{
  long N, M;
  cin >> N ;
  vector<long> a(N);
 
  for(int i=0;i<N;i++)
    {
      cin >>a[i];
     a[i] -= i +1;
     }
  sort(a.begin(),a.end());
  
  long c=0;
  for(int i=0;i<N;i++){
    c+= abs( a[i] - a[N/2]);
  }
  
  
 
  cout << c << endl;
 
  return 0;
}

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

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans=0;
  int c2 = c*2;
  
  if (a > c2 && b > c2) {
    ans = max(x,y) * c2;
  }
  else {
    if (a+b > c2) { 
      ans += c2 * min(x,y);
      if (x<y) ans+=(y-x) * min(b,c2);
      else     ans+=(x-y) * min(a,c2);
    }
    else ans = a*x + b*y;
  }
  cout << ans << endl;
  return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	double ans=0;
	for(int i=0;i<n;i++){
		ans+=(double)(1.0/a[i]);
	}
    ans=1.0/ans;
	printf("%.8f\n",ans);
}

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

using namespace std;

int main() {
    set<int> s;
    int a;
    cin >> a;   s.insert(a);
    cin >> a;   s.insert(a);
    cin >> a;   s.insert(a);

    if (s.size() == 2)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def era(n): #n以下の素数を列挙
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        
        for j in range(2*i, n+1, i):
            is_prime[j] = False
    
    return [i for i in range(n+1) if is_prime[i]]

p = era(10**5+100)
s = set(p)
is_like = [0]*(10**5+100)

for i in range(len(is_like)):
    if i in s and (i+1)//2 in s:
        is_like[i] = 1

acc = [0]

for i in range(len(is_like)):
    acc.append(acc[-1]+is_like[i])

Q = int(input())

for _ in range(Q):
    l, r = map(int, input().split())
    print(acc[r+1]-acc[l])

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

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

int main(){
    ll N;
    cin >> N;
    if(N % 2 == 1){ 
        cout << 0 << endl;
        return 0;
    }else{
        ll ans = 0;
        for(ll i = 10; i <= N; i*=5){
            ans += N/i;
        }
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int k;
    cin>>s>>k;
    vector<string> sub;
    for(int i=0;i<s.size();i++){
        for(int j=1;j<=k;j++){
            string tmp=s.substr(i,j);
            sub.push_back(tmp);
        }
    }
    sort(sub.begin(),sub.end());
    sub.erase(unique(sub.begin(),sub.end()),sub.end());
    //for(int i=0;i<sub.size();i++)cout<<sub[i]<<endl;
    cout<<sub[k-1]<<endl;
    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        int v=n%1000;
        v=1000-v;
        v%=1000;
        cout<<v<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n) cin >> a[i];
  int ans = 1;
  vector<int>num(100010);
  rep(i,n){
    num[a[i]]++;
    num[a[i]+1]++;
    num[a[i]+2]++;
  }
  rep(i,(int)num.size()){
    chmax(ans,num[i]);
  }
  cout << ans << endl;
    
  return 0;
}


Measured memory_bytes: 3972
N,C=map(int, raw_input().split())
X=[ tuple( map(int, raw_input().split()) ) for i in range(N)]
T=[]
R=[]

a=[]

v_sum=0
for x,v in X:
	v_sum+=v
	T.append(v_sum-x)

a+=T

v_sum=0
for x,v in X[::-1]:
	v_sum+=v
	R.append(v_sum-(C-x))

a+=R



T_MAX=[]
val=float("-inf")
for i in T:
	val=max(val,i)
	T_MAX.append(val)


R_MAX=[]
val=float("-inf")
for i in R:
	val=max(val,i)
	R_MAX.append(val)


for i in range(N):
	extra_x=X[i][0]
	if N-i-2>=0:
		val=T[i]+R_MAX[N-i-2]-extra_x
		a.append(val)


for i in range(N):
	extra_x=C-X[N-i-1][0]
	if N-i-2>=0:
		val=R[i]+T_MAX[N-i-2]-extra_x
		a.append(val)


print max(0,max(a))

Measured memory_bytes: 76700
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
const ll DEP = (1LL << 50);
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T x,T y){
    return y ? GCD(y,x%y) : x;
}
ll N,M;
int main(){
    cin >> N;
    ll d[N];
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    sort(d,d+N);
    cout << d[N/2] - d[N/2-1] << endl;
}


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

int main()
{
  char b;
  cin >> b;

  switch (b)
  {
    case 'A':
      cout << 'T' << endl;
      break;
    case 'C':
      cout << 'G' << endl;
      break;
    case 'G':
      cout << 'C' << endl;
      break;
    case 'T':
      cout << 'A' << endl;
      break;
    default:
    ;
  };
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;


int main()
{
	IOS;
	cin>>n>>k;
	int arr[n];
	forn(i,n){
		cin>>arr[i];
	}
	sort(arr,arr+n);
	int diff=1e9;
	for(int i=0;i<=n-k;i++)
	{
		//dbg(diff);
		diff=min(diff,arr[i+k-1]-arr[i]);
	}
	cout<<diff;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(ll i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

const ll max_n = 1e5 + 9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}

ll n , k;
ll a[max_n];
ll dp[max_n] , dp1[max_n];

ll add(ll a , ll b){
    a = (a + b);
    if(a >= mod){
        a -= mod;
    }
    return a;
}
int main()
{
    cin >> n >> k;

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

    for(ll i = 0 ; i <= min(k , a[0]) ; i++){
        dp[i] = 1;
    }

    for(ll i = 1 ; i < n ; i++){
        ll pref[k+1] = {0};
        pref[0] = dp[0];
        for(ll j = 1 ; j <= k ; j++){
            pref[j] = add(pref[j-1] , dp[j]);
        }
        for(ll j = 0 ; j <= k ; j++){
            // for(ll w = 0 ; w <= a[i] ; w++){
            //     if(j >= w){
            //         dp1[j] += dp[j-w];
            //     }
            // }

            ll num = max(0ll , j - a[i]);
            dp1[j] = (pref[j] - (num > 0 ? pref[num-1] : 0) + mod)%mod;
        }

        for(ll j = 0 ; j <= k ; j++){
            dp[j] = dp1[j];
        }
    }

    cout << dp[k] << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for(int i = 0; i < 3; i++){
		char c = cin.get();
		if(c == '1') cout << '9';
		else if(c == '9') cout << '1';
		else cout << c;
	}
	cout << "\n";
	return 0;
}

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

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var dic = new Dictionary<string, long>()
            {
                {"AC",0 },
                {"WA",0 },
                {"TLE",0 },
                {"RE",0 },
            };
            for(var i = 0; i < N; i++)
            {
                var S = ReadText();
                dic[S] = dic[S] + 1;
            }
            var sb = new StringBuilder();
            foreach(var d in dic)
            {
                sb.AppendLine($"{d.Key} x {d.Value}");
            }
            return sb.ToString().Trim();
        }
        

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 31248
package main

import (
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(stdin io.Reader, stdout io.Writer) {
	var n, k int

	var s []string
	fmt.Fscanf(stdin, "%d%d", &k, &n)
	for i := n - k + 1; i <= n+k-1; i++ {
		s = append(s, string(strconv.Itoa(i)))
	}
	fmt.Fprintln(stdout, strings.Join(s, " "))

}



Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
  long long a,b;
  cin >> a >> b;
  long long i = a+1;
  long long ans = a;
  if (a > 0 && b > 0)
    cout << "Positive" << endl;
  if (a < 0 && b < 0)
  {
    if ((b - a + 1) % 2 ==0)
      cout << "Positive" << endl;
    else
      cout << " Negative" << endl;
  }
  if (a <= 0 && b >= 0)
    cout << "Zero" << endl;
  return 0;
 }
    


Measured memory_bytes: 256
n ,k = map(int, input().split())
s = input()
ret = ""
for i in range(n):
    if i==k-1:
        if s[k-1]=="A":
            ret += "a"
        elif s[k-1]=="B":
            ret += "b"
        elif s[k-1]=="C":
            ret += "c"
    else:
        ret += s[i]
print(ret)

Measured memory_bytes: 3060
#include <stdio.h>
#define MAX 1000
int main(){
  int i,j,N,A[MAX][MAX]={0},n,value,max,roop;
  scanf("%d",&N);
  for(i=0;i<N;i++){
	scanf("%d",&n);
	max=n;
	scanf("%d",&roop);
	  for(j=0;j<roop;j++){
		scanf("%d",&value);
		if(value==0) break;
		A[n][value]=1;
	  }
  }
  for(i=1;i<=N;i++){
	for(j=1;j<=max;j++){
	  printf("%d",A[i][j]);
	  if(j==max){
		printf("\n");
		break;
	  }
	  printf(" ");
	}
  }
  return 0;
}



Measured memory_bytes: 5704
#include <bits/stdc++.h>
using namespace std ;
int main(){
    int N;
    cin >> N;
    int X[N];
    int S=0,SS=0;
    for(int i=0;i<N;i++){
        cin >> X[i];
        S+=X[i];
        SS+=X[i]*X[i];
    }
    int mini;
    for(int i=0;i<=100;i++){
        if(i<1){
            mini=N*i*i-2*S*i;
        }else{
            int c=N*i*i-2*S*i;
            mini = min(mini,c);
        }
    }
    int Ans=mini+SS;
    cout << Ans << endl;
}

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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29

int main(){
int n,d;
cin >> n >> d;
if(n%(2*d+1)==0){
cout << n/(2*d+1);
}else{
cout << n/(2*d+1)+1;
}

}


Measured memory_bytes: 256
#include <cstdio>

const int MAXN = 1E5 + 10;

int n, m, Q;
int a[MAXN];
int b[MAXN], id[MAXN];
bool vis[MAXN];
int cnt[MAXN];

int main(){
	scanf("%d%d", &n, &m);
	scanf("%d", &Q);
	for (int i = 1; i <= Q; ++i)
		scanf("%d", &a[i]);
	for (int k = 0, j = Q; j > 0; --j)
		if (!vis[a[j]])
			b[++k] = a[j], vis[a[j]] = true;
	for (int j = m, i = m; i > 0; --i)
		if (!vis[i])
			b[j--] = i;
	for (int i = 1; i <= m; ++i)
		id[b[i]] = i;

	bool flag = true;
	cnt[0] = n;
	for (int i = Q; i > 0; --i){
		int t = id[a[i]];
		if (cnt[t - 1] > 0){
			--cnt[t - 1];
			++cnt[t];
			vis[t] = true;
		}
		else if (!vis[t]){
			flag = false;
			break;
		}
	}

	int l;
	for (l = 0; cnt[l] == 0; ++l);
	for (int i = l + 1; i < m; ++i)
		flag &= b[i] < b[i + 1];
	puts(flag ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define SANKOU(n, a, b) cout << ((n) ? (#a) : (#b)) << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>

void solve()
{
}

signed main()
{
    string s;
    cin >> s;
    int a = 0, n = 0, l;
    l = (int)s.size();
    for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == 'o')
            a++;
    }
    if (8 - a <= 15 - l) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    solve();
    return 0;
}


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

typedef struct{
  char name[128];
  unsigned int minprice;
  short fr_oth;
} item;

typedef struct{
  char to[128];
  unsigned int num;
  char from[100][128];
} gosei;

item list[100];
gosei makelist[100];
unsigned int m,n;

unsigned int makeans(int var);

int main(void){
  unsigned int i,j,k,ans;
  char tmpstr[128];
  unsigned int inputs;
  while(scanf("%u%*c",&n) &&n){
    for(i=0;i<n;i++)
      scanf("%s %u%*c",list[i].name,&(list[i].minprice));

    scanf("%u%*c",&m);
    for(i=0;i<m;i++){
      scanf("%s %u%*c",tmpstr,&inputs);
      for(j=0;j<n;j++){
	if(strcmp(list[j].name,tmpstr))continue;
	list[j].fr_oth=1;
	break;
      }
      strcpy(makelist[i].to,tmpstr);
      makelist[i].num=inputs;
      for(j=0;j<makelist[i].num;j++)
	scanf("%s%*c",makelist[i].from[j]);
    }
    scanf("%s%*c",tmpstr);
    for(i=0;i<n;i++){
      if(strcmp(list[i].name,tmpstr)) continue;
      k=i;
      break;
    }
    
    ans=makeans(k);
    printf("%u\n",ans);
  }
  return 0;
}

unsigned int makeans(int var){
  unsigned int i,j,k,tmp;
  if(list[var].fr_oth==1){
    tmp=0;
    for(i=0;i<m;i++){
      if(strcmp(makelist[i].to,list[var].name)) continue;
      k=i;
      break;
    }
    for(i=0;i<makelist[k].num;i++){
      for(j=0;j<n;j++){
	if(strcmp(makelist[k].from[i],list[j].name)) continue;
	break;
      }
      tmp+=makeans(j);
    }
    if(list[var].minprice>tmp) list[var].minprice=tmp;
    list[var].fr_oth=0;
  }
  return list[var].minprice;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  queue<string> q;
  FOR(i, 1, 10) {
    string t;
    t = i + '0';
    q.push(t);
  }

  string ans;
  REP(i, n) {
    ans = q.front();
    if (i == n - 1) break;
    int last_int = ans[ans.length() - 1] - '0';
    FOR(j, max(0, last_int - 1), min(9, last_int + 1) + 1) {
      string last_str;
      last_str = j + '0';
      q.push(ans + last_str);
    }
    q.pop();
  }
  ll tmp = stol(ans);
  cout << tmp << endl;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 3010;

int n, a[N];

vector<int> edge[N];

bool dfs(int u, int fa)
{
	bool ret = 0;
	for (auto v : edge[u])
	{
		if (v == fa) continue;
		if (a[u] > a[v]) ret |= dfs(v, u) ^ 1;
	}
	return ret;
}

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i]);
	for (int i = 1; i < n; ++i)
	{
		int u, v;
		gii(u, v);
		edge[u].pb(v);
		edge[v].pb(u);
	}
	for (int i = 1; i <= n; ++i) if (dfs(i, 0)) printf("%d ", i);
	return 0;
}

Measured memory_bytes: 384
/*
    2014.07.04 1313~1326
    2014.07.04 1451~1551
    C language Lecture week 4
*/

#include <stdio.h>
#include <string.h>

#define ES_max 32 // Era string max length
    // heisei_2014_12_31
    //     *    1    *    2    *    3    *    4

typedef struct Date {
    int year;
    int month;
    int date;
} Date;

void Year2EraTranslate ( char* out, Date In );
int DateCmp ( Date In1, Date In2 );

// 変えないので高速化の意味でもグローバルで定義しておく
Date Meiji  = { 1868,  9,  8 };
Date Taisho = { 1912,  7, 30 };
Date Showa  = { 1926, 12, 25 };
Date Heisei = { 1989,  1,  8 };

int main (void) {
    
    char erastr[ES_max];
    Date Input;
    
    while (1) {
        
        if ( scanf ( "%d", &Input.year ) == EOF ) {
            break;
        }
        scanf ( "%d", &Input.month );
        scanf ( "%d", &Input.date );
        Year2EraTranslate ( (char *) erastr, Input );
        printf ( "%s", erastr );
        fflush ( stdout );
        
    }
    
    return 0;
    
}

void Year2EraTranslate ( char* out, Date In ) {
    
    if ( DateCmp ( In, Meiji ) == -1 ) {
        sprintf ( (char*) out, "pre-meiji\n" );    // 明治以前
    } else if ( DateCmp ( In, Taisho ) == -1 ) {
        sprintf ( (char*) out, "meiji %d %d %d\n",  ( In.year -  Meiji.year + 1 ), In.month, In.date );    // 明治
    } else if ( DateCmp ( In, Showa ) == -1 ) {
        sprintf ( (char*) out, "taisho %d %d %d\n", ( In.year - Taisho.year + 1 ), In.month, In.date );    // 大正
    } else if ( DateCmp ( In, Heisei ) == -1 ) {
        sprintf ( (char*) out, "showa %d %d %d\n",  ( In.year -  Showa.year + 1 ), In.month, In.date );    // 昭和
    } else {
        sprintf ( (char*) out, "heisei %d %d %d\n", ( In.year - Heisei.year + 1 ), In.month, In.date );    // 平成
    }
    
    return;
    
}

int DateCmp ( Date In1, Date In2 ){
    // Compare Date In1 and In2
    // If In1 < In2 then return -1
    // If In1 = In2 then return 0
    // if In1 > In2 then return 1
    
    if ( In1.year == In2.year ) {
        if ( In1.month == In2.month ) {
            if ( In1.date == In2.date ) {
                return 0;
            } else {
                if ( In1.date < In2.date ) {
                    return -1;
                } else {
                    return 1;
                }
            }
        } else {
            if ( In1.month < In2.month ) {
                return -1;
            } else {
                return 1;
            }
        }
    } else {
        if ( In1.year < In2.year ) {
            return -1;
        } else {
            return 1;
        }
    }
    
}

Measured memory_bytes: 1044
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

long long gcd(long long a, long long b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int A, B;
    cin >> A >> B;
    if (A == B) {
        cout << "Draw" << endl;
    } else if ((B < A && B != 1) || (A == 1)) {
        cout << "Alice" << endl;
    } else {
        cout << "Bob" << endl;
    }
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define all(a) a.begin(), a.end()

typedef long long lint;

const int MAXN = (int)1e5 + 9;

int N, M;

priority_queue<lint> jobs[MAXN];

int main() {
    scanf("%d%d", &N, &M);
    rep(i, N) {
        int A, B;
        scanf("%d%d", &A, &B);
        if (A > M)
            continue;
        jobs[M - A].push(B);
    }
    priority_queue<lint> pq;
    lint ans = 0LL;
    rep(i, M + 1) {
        if (pq.empty() && jobs[M - i].empty()) continue;
        lint tmp1 = 0LL, tmp2 = 0LL;
        if (!pq.empty()) tmp1 = pq.top();
        if (!jobs[M - i].empty()) tmp2 = 1LL * jobs[M - i].top();
        if (tmp1 <= tmp2) jobs[M - i].pop();
        else pq.pop();
        while (!jobs[M - i].empty()) {
            pq.push(jobs[M - i].top());
            jobs[M - i].pop();
        }
        ans += max(tmp1, tmp2);
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

// int main() {
//     ios::sync_with_stdio(false);
//     cin.tie(0);
    
//     ll n, k;
//     cin >> n >> k;
//     vi a(n);
//     rep(i, n) cin >> a[i];
//     set<int> st;
//     vi ans;
//     int now = 1;
//     while (1) {
//         now = a[now-1];
//         if (st.count(now)) {
//             ans.pb(now);
//             break;
//         } else {
//             st.insert(now);
//             ans.pb(now);
//         }
//     }
//     int s = 0;
//     rep(i, n) {
//         if (ans[i] == ans.back()) {
//             s = i;
//             break;
//         }
//     }
//     vi repeat;
//     for (int i = s; i < sz(ans) - 1; ++i) {
//         repeat.pb(ans[i]);
//     }
//     int len = sz(ans) - s - 1;
//     if (k <= s) {
//         cout << ans[k-1] << endl;
//     } else {
//         k -= s;
//         k %= len;
//         if (k == 0) cout << repeat.back() << endl;
//         else cout << repeat[k-1] << endl;
//     }
// }

int main() {
    int n; ll k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];

    vi s;
    vi ord(n+1, -1);
    int c = 0, l = 0;
    {
        int v = 1;
        while (ord[v] == -1) {
            ord[v] = sz(s);
            s.pb(v);
            v = a[v-1];
        }
        c = sz(s) - ord[v];
        l = ord[v];
    }
    if (k < l) {
        cout << s[k] << endl;
    } else {
        k -= l;
        k %= c;
        cout << s[l+k] << endl;
    }
}

Measured memory_bytes: 5900
/*
    Stay motivated and keep working hard
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll N, W;
ll w[107], v[107];
ll dp[107][100007];
// ll rec(ll N, ll W){
//     if(N == 0 || W == 0){
//         return 0;
//     }
//     if(dp[N][W]){
//         return dp[N][W];
//     }
//     if(W >= w[N-1]){
//         return dp[N][W] = max(dp[N][W], max(rec(N-1, W), v[N-1] + rec(N-1, W-w[N-1])));
//     }
//     else{
//         return dp[N][W] = max(dp[N][W], rec(N-1, W));
//     }
// }
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    cin >> N >> W;
    for(ll i=0;i<N;i++){
        cin >> w[i] >> v[i];
    }
    // rec(N, W);
    // cout << dp[N][W] << "\n";
    for(ll i=1;i<=N;i++){
        for(ll j=1;j<=W;j++){
            if(j >= w[i-1]){
                dp[i][j] = max(dp[i][j], max(v[i-1] + dp[i-1][j-w[i-1]], dp[i-1][j]));
            }
            else{
                dp[i][j] = max(dp[i][j], dp[i-1][j]);
            }
        }
    }
    cout << dp[N][W] << "\n";


    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
char s[100005];
int a[100005], b[100005];

int main() {
    scanf("%d%s", &n, s);
    forn(i, n) {
        a[i] = s[i] == 'x';
    }
    for (b[0] = 0; b[0] < 2; ++b[0]) {
        for (b[1] = 0; b[1] < 2; ++b[1]) {
            for (int i = 1; i < n - 1; ++i) {
                int x = a[i] ^ b[i] ^ b[i - 1];
                b[i + 1] = x;
            }
            bool ok = true;
            if (a[0] ^ b[0] ^ b[1] ^ b[n - 1]) {
                ok = false;
            }
            if (a[n - 1] ^ b[n - 1] ^ b[n - 2] ^ b[0]) {
                ok = false;
            }
            if (ok) {
                forn(i, n) if (b[i] == 0) {
                    printf("S");
                } else {
                    printf("W");
                }
                puts("");
                return 0;
            }
        }
    }
    printf("-1\n");
    return 0;
}


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

void solve(std::string S) 
{
  long mod = 1000000007;
  int n = 13;
  std::vector<int> dp(n, 0);
  dp[0] = 1;
  long mul = 1;
  for (int s = S.size()-1; s >= 0; s--)
  {
    std::vector<int> next_dp(n, 0);
    if(S[s] == '?')
    {
      for (size_t i = 0; i < 13; i++)
      {
        for (size_t j = 0; j < 10; j++)
        {
          next_dp[(j*mul+i)%n] += dp[i]; 
          next_dp[(j*mul+i)%n] %= mod; 
        }
      }
    }
    else
    {
      int j = (int)(S[s]-'0');
      for (size_t i = 0; i < 13; i++)
      {
        next_dp[(j*mul+i)%n] += dp[i]; 
        next_dp[(j*mul+i)%n] %= mod; 
      }
    }
    dp = next_dp;
    mul*=10;
    mul%=n;
  }
  std::cout << dp[5] << std::endl;
}

int main(void) 
{
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 512