akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

//辞書順順列はiota(1,N),nextPermituionを使う


void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
    import core.stdc.stdlib;
    writeln(v);
    exit(0);
}

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}


void main()
{
  scanString;writeln("A"~scanString[0].to!string~"C");
}


Measured memory_bytes: 256
n = int(input())
list_res = []
for i in range(0, n):
    s, p = input().split()
    list_res.append([s, int(p), i + 1])
list_res_point = sorted(list_res, key=lambda x: (x[1]), reverse=True)
list_ans = sorted(list_res_point, key=lambda x: (x[0]))
for i in range(0, n):
    print(list_ans[i][2])

Measured memory_bytes: 9076
N = int(input())
D = sorted(list(map(int, input().split())))
check = []
half = int(len(D)/2)
D_lead = D[:half]
D_tail = D[half:]
if max(D_lead) != min(D_tail):
    check = [num for num in range(max(D_lead), min(D_tail))]
    print(len(check))
else:
    print(0)

Measured memory_bytes: 14396
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
typedef long long llong;

#define MAXIM 200010


int main() {

	char seq[MAXIM];
	bool init = false;
	int subcount = 0;
	llong countresult = 0;

	cin >> seq;


	for (int i = 0; seq[i] != '\0'; i++) {
		if (!init) {
			if (seq[i] == 'W') {
				subcount++;
				continue;
			}
			else {
				init = true;
			}
		}
		else {
			if (seq[i] == 'W') {
				countresult += i - subcount;
				subcount++;
			}
		}

	}
	cout << countresult << endl;
	
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 標準入力からデータを読み込む準備
        try (Scanner sc = new Scanner(System.in)) {
            String line = sc.nextLine();
            String answer = "";
            int length = line.length();
            for (int i = 0; i < length; i++) {
                char ch = line.charAt(i); // 文字列(line)からi番目の文字を取り出す
                // Character.isLowerCase で小文字かどうか判断可能
                // Character.toUpperCase, Character.toLowerCase で変換
                // 記号は上記メソッドで変換にかけても変化しない
                if (Character.isLowerCase(ch)) {
                    // 小文字なら
                    ch = Character.toUpperCase(ch);
                } else {
                    // 大文字
                    ch = Character.toLowerCase(ch);
                }
                answer = answer.concat(String.valueOf(ch));
            }

            System.out.println(answer);
            sc.close();
        }
    }
}



Measured memory_bytes: 27564
import collections


def solve(sa, sb, sc):
    next_turn = sa.popleft()
    while True:
        if next_turn == 'a':
            if len(sa) == 0:
                return 'A'
            next_turn = sa.popleft()
        elif next_turn == 'b':
            if len(sb) == 0:
                return 'B'
            next_turn = sb.popleft()
        else:
            if len(sc) == 0:
                return 'C'
            next_turn = sc.popleft()


sa = raw_input()
sa = collections.deque(sa)
sb = raw_input()
sb = collections.deque(sb)
sc = raw_input()
sc = collections.deque(sc)
ans = solve(sa, sb, sc)
print ans


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

const int mod = 1000000007;
bool ok[1010];
long long a[1010];

void f(int x)
{
	int n, i;
	n = x;
	i = 0;
	while(n > i)
	{
		i++;
		if (ok[i])
		{
			while (x % i == 0)
			{
				x /= i;
				a[i]++;
			}
		}
	}
}

signed main(void)
{
	int n;
	long long ans;

	cin >> n;
	rep(i, 1010) {ok[i] = true; a[i] = 0;}
	ok[0] = ok [1] = false;
	for (int i = 2; i < sqrt(n); i++) 
	{
		if (ok[i])
		{
			for (int j = 0; i * (j + 2) < n; j++)
			{	
				ok[i * (j + 2)] = false;
			}
		}
	}
	for (int i = n; i > 0; i--) f(i);
	ans = 1;
	rep(i, n + 1)
	{
		if (a[i])
		{
			ans *= a[i] + 1;
			ans %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
from decimal import Decimal
'''
N = ii()
A = li()
ans = 1
for num in A:
    ans *= num
    if ans > 10**18:
        if 0 in A:
            print(0)
        else:
            print(-1)
        exit()

print(ans)
'''

'''
N = ii()
A = li()
ans = 1
inf = Decimal('1000000000000000000')
for num in A:
    if ans <= inf / Decimal(str(num)):
        ans *= num
    else:
        if 0 in A:
            print(0)
        else:
            print(-1)
        exit()
print(ans)
'''


N = ii()
A = li()
if 0 in A:
    print(0)
    exit()
ans = 1
for num in A:
    #print(ans, 10**18 / num, 10**18//num)
    #if ans < (10**18+1) / num or ans == 10**18//num:
    if ans <= 10**18//num:
        ans *= num
    else:
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 23456
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int n,a[MAXN],Ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),Ans=Ans^a[i];
	if(Ans)printf("No\n");
	else printf("Yes\n");
}

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

using namespace std;

string s;

int main()
{
    cin>>s;
    if(s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi") cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int main() {
	string S;
	ll s=0,c=0;
	cin >> S;

	rep(i,S.size())
		if(S.at(i) == 'W') {
			s += i-c;
			++c;
		}

	cout << s << endl;
}

Measured memory_bytes: 644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

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

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;
#define NIL -INF

typedef struct Node_t {
  ll key;
  Node_t *parent;
  Node_t *left;
  Node_t *right;
} Node;

// Node T[500500]; // ??????????¶???????????????§?????????????????????
Node *root = NULL;

void insert(Node *z) {
  Node *y = NULL;
  Node *x = root;
  while(x != NULL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;

  if (y == NULL) {
    root = z;
  } else if (z->key < y->key) {
    y->left = z;
  } else {
    y->right = z;
  }
}

void inorder(Node *n) {
  if (n == NULL) return;

  inorder(n->left);
  cout << " " << n->key;
  inorder(n->right);
}

void preorder(Node *n) {
  if (n == NULL) return;

  cout << " " << n->key;
  preorder(n->left);
  preorder(n->right);
}

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

  // REP(i, 500500) {
  //   Node n = {NIL, NIL, NIL, NIL};
  //   T[i] = n;
  // }

  REP(i, n) {
    string cmd;
    cin >> cmd;

    if (cmd == "insert") {
      ll key;
      cin >> key;
      Node *child = (Node*)malloc(sizeof(Node));
      child->key = key;
      child->parent = NULL;
      child->left = NULL;
      child->right = NULL;
      insert(child);
    } else {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 26476
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(a + b == c + d)
		cout << "Balanced" << endl;
	else if(a + b > c + d)
		cout << "Left" << endl;
	else
		cout << "Right" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n,m,a,b,ans;
vector < ll > graph[N];
ll dp[N];

ll longest(ll cur)
{
    if(dp[cur] != -1)
        return dp[cur];

    ll res = 0;

    rep(i,0,graph[cur].size())
        res = max(res,longest(graph[cur][i])+1);

    return dp[cur] = res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    memset(dp,-1,sizeof dp);
    cin >> n >> m;

    rep(i,0,m)
    {
        cin >> a >> b;
        graph[a].push_back(b);
    }

    rep(i,1,n+1)
        ans = max(ans,longest(i));

    cout << ans;

    return 0;
}



Measured memory_bytes: 14848
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    char s[120],c[27]="abcdefghijklmnopqrstuvwxyz";
    scanf("%s",s);
    int tmp,count,ans=1e9;
    for (int i=0; i<26; i++){
        count=0;
        tmp=0;
        for (int j=0; j<strlen(s); j++){
            if (s[strlen(s)-1-j]==c[i]){
                if(tmp<count){
                    tmp=count;
                }
                count=0;
            } else {
                count++;
            }
        }
        if(tmp<count){
            tmp=count;
        }
        if(tmp<ans){
            ans=tmp;
        }
    }
    printf("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S;
  cin >> S;
  int a=S/100;
  int b=S%100;
  bool A,B;
  if(1<=a && a<=12){A=true;}
  else{A=false;}
  if(1<=b && b<=12){B=true;}
  else{B=false;}
  if(A && B){cout << "AMBIGUOUS" << endl;}
  else if(A){cout << "MMYY" << endl;}
  else if(B){cout << "YYMM" << endl;}
  else {cout << "NA" << endl;}
}

Measured memory_bytes: 256
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import itertools
import bisect
import copy
import fractions
import math
import random
import sys
import time
import queue
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def warshall_floyd(n):
    # 隣接行列graphを使う
    for i in range(n):  # 経由する頂点
        for j in range(n):  # 開始頂点
            for k in range(n):  # 終端
                graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k])


N, M, R = MI()
r = LI()
road = [LI() for _ in range(M)]
graph = [[INF] * N for _ in range(N)]
# pprint(graph, width=30)
distance = [[INF] * N for _ in range(N)]
for a, b, c in road:
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c
for i in range(N):
    graph[i][i] = 0

q = queue.PriorityQueue()

# distance = [INF] * N
# while not q.empty():
#     cost, v = q.get()
#     if distance[v] < cost:
#         continue
#     distance[v] = cost
# 
#     for next_v in range(N):
#         if graph[v][next_v] == 0:  # 繋がっていない
#             continue
#         q.put((distance[v] + graph[v][next_v], next_v))

# for begin in range(N):
for begin in r:
    begin -= 1
    q.put((0, begin))  # begin~beginのコストは0, begin番目の頂点始点
    while not q.empty():
        cost, v = q.get()
        if distance[begin][v] < cost:
            continue
        distance[begin][v] = cost

        for next_v in range(N):
            if graph[v][next_v] == 0:
                continue
            q.put((distance[begin][v] + graph[v][next_v], next_v))

mini = INF
for permutation in itertools.permutations(r):
    tmp = 0
    # print(permutation)
    for i in range(R-1):
        tmp += distance[permutation[i]-1][permutation[i+1]-1]
    mini = min(mini, tmp)

print(mini)


Measured memory_bytes: 107220
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
res = 0

def checkValidity(a, b, c):   
    if (a + b <= c) or (a + c <= b) or (b + c <= a) : 
        return False
    else: 
        return True 

for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if (L[i] != L[j] != L[k]) and checkValidity(L[i], L[j],L[k]):
                res += 1
 
print(res)


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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int A[100005];
int pos[100005];

int main(void) {
    COMinit();
    int N; cin >> N;
    N++;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int dup;
    int dup_dist;
    for (int i = 0; i < N; i++) {
        if (pos[A[i]] != 0) {
            dup = A[i];
            dup_dist = i + 1 - pos[A[i]];
        }
        pos[A[i]] = i+1;
    }
    
    for (int i = 1; i <= N; i++) {
        long long ans = 0;
        ans += COM(N-2, i);
        ans %= MOD;
        ans += COM(N-2, i-1);
        ans %= MOD;
        ans += COM(N-2, i-1); 
        ans %= MOD;
        ans += COM(N-2, i-2);
        ans %= MOD;
        ans -= COM(N-dup_dist-1, i-1);
        ans += MOD;
        ans %= MOD;
        cout << ans << endl;
    }
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define REP(i, n) FOR(i, 1, ll(n) + 1)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> inline bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> inline bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

int n, m;
vector<int> E[700];
bool ee[700][700];

int color[700];

pair<int, int> dfs(int x, int c) {
    color[x] = c;
    int a = 1, b = 0;
    for(int y : E[x]) {
        if(color[y] == c) {
            cout << -1 << endl;
            exit(0);
        }
        if(color[y] == 0) {
            pair<int, int> p = dfs(y, -c);
            a += p.second;
            b += p.first;
        }
    }
    return make_pair(a, b);
}

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

    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        ee[a - 1][b - 1] = ee[b - 1][a - 1] = true;
    }

    rep(i, n) rep(j, n) if(ee[i][j] == false && i != j) E[i].push_back(j);

    vector<pair<int, int>> p;

    rep(i, n) if(!color[i]) p.push_back(dfs(i, 1));

    bitset<701> dp(1);
    for(auto x : p)
        dp = dp << x.first | dp << x.second;

    int ans = 1 << 30;
    rep(i, n + 1) if(dp[i])
        chmin<int>(ans, i * (i - 1) + (n - i) * (n - i - 1) >> 1);

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

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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	REP(i, w + 2) {
		cout << '#';
	}
	cout << endl;
	REP(i, h) {
		string s;
		cout << '#';
		cin >> s;
		cout << s << '#' << endl;
	}
	REP(i, w + 2) {
		cout << '#';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
H = [int(i)  for i in input().split()]

temp = 10 ** 5
for i in range(n):
    diff = abs(a - (t - H[i] * 0.006))
    if diff < temp:
        temp = diff
        ans = i + 1
        
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    ll cnt=0;
    ll ans=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='A' || s[i]=='C' || s[i]=='T' || s[i]=='G')
        {
            cnt++;
        }
        else
        {
            ans=max(ans,cnt);
            cnt=0;
        }
    }
    cout<<max(ans,cnt)<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int INF =1e9+5;
int main()
{
   int n,k;
  cin>>n>>k;
  int h[n];
  vector<int>dp(n,INF);
  dp[0]=0;
  for(int i=0;i<n;i++)
    cin>>h[i];
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<=i+k;j++)
    {
       if(j<n)
       {
         dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
       }
    }
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    cin >> N;
    pair<int,int> A[100000];
    for(int i=0; i<N; i++){
       cin>> A[i].first;
        A[i].second=i;
    }
    sort(A,A+N);
    for(int i=0; i<N; i++){
        cout<<A[i].second+1<<" ";
    }
    cout<<endl;
    return 0;
    
}


Measured memory_bytes: 1536
import java.util.*;
import java.io.*;
public class Main {
    public static int dp[][] ;
    public static int mod = 1000000007;
    public static int solve(int arr[] , int n , int k){
        
        for(int j = 0; j <= k ; j++){
            dp[1][j] = (j > arr[1]) ? 0 : 1;
        }

        for(int i = 2 ; i <= n ; i++){
            for( int j = 0 ; j <= k ; j++){
                if(j == 0) 
                    dp[i][j] = dp[i-1][j];
                else 
                    dp[i][j] = (mod + (dp[i-1][j] + dp[i][j-1] - (j-1-arr[i] >=0 ? dp[i-1][j-1-arr[i]] : 0))%mod ) % mod;
            }
        }
        return dp[n][k];
    }
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        int arr[] = new int[n+1];
        dp = new int[n+1][k+1];

        for(int i = 1 ; i <= n ; i++){
            arr[i] = s.nextInt();
        }
        System.out.println(solve(arr , n , k));
    }
}

Measured memory_bytes: 85132
require "prime"
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans = Float::INFINITY
a.each do |i|
    if i.prime_division.sort[0][0] == 2
        ni = i.prime_division.sort[0][1]
    else
        ni = 0
    end
    ans = [ans,ni].min
end
puts ans

Measured memory_bytes: 14344
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur = nil->next;
    while (cur != nil && cur->key != key ) {
        cur = cur->next;
    }
    return cur;
}

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while(1) {
        if (cur == nil) break;
        if (isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    } 
    printf("\n");
}

void deleteNode(Node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void insert (int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    
    cin >> n;
    init();
    for (i = 0; i < n; i++) {
        scanf("%s%d", com, &key);
        if (com[0] == 'i') {
            insert(key);
            np++;
            size++;
        }
        else if (com[0] == 'd') {
            if (strlen(com) > 6) {
                if (com[6] == 'F') deleteFirst();
                else if (com[6] == 'L') deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size --;
        }
    }
    printList();
    
    return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  cout << ((n + 110)/111) * 111 << endl;
  return 0;
}


Measured memory_bytes: 256
//  Copyright 2020 Nikita Golikov

#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;
using ui64 = uint64_t;

template <class A, class B>
bool smin(A &x, B &&y) {
  if (y < x) {
    x = y;
    return true;
  }
  return false;
}

template <class A, class B>
bool smax(A &x, B &&y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

int main() {
#ifdef GOLIKOV
  assert(freopen("in", "rt", stdin));
  auto _clock_start = chrono::high_resolution_clock::now();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (auto& x : p) {
    cin >> x;
    --x;
  }
  vector<int> c(n);
  for (auto& x : c) {
    cin >> x;
  }
  i64 ans = *max_element(c.begin(), c.end());
  vector<bool> used(n);
  for (int i = 0; i < n; ++i) {
    if (used[i]) continue;
    int cur_k = k;
    int cur = i;
    vector<int> guys;
    i64 tot = 0;
    do {
      guys.push_back(c[cur]);
      tot += c[cur];
      used[cur] = true;
      cur = p[cur];
    } while (cur != i);
    i64 res = 0;
    int len = (int) guys.size();
    int full = k / len;
    smax(--full, 0);
    if (tot >= 0) {
      res += tot * full;
      cur_k -= full * len;
      if (full) {
        smax(ans, res);
      }
    } else {
      smin(cur_k, len);
    }
    for (int st = 0; st < len; ++st) {
      auto cres = res;
      for (int it = 0; it < cur_k; ++it) {
        res += guys[(st + it) % len];
        smax(ans, res);
      }
      res = cres;
    }
  }
  cout << ans << '\n';

#ifdef GOLIKOV
  cerr << "Executed in " << chrono::duration_cast<chrono::milliseconds>(
      chrono::high_resolution_clock::now()
          - _clock_start).count() << "ms." << endl;
#endif
  return 0;
}


Measured memory_bytes: 3696
#include <complex>
#include <cmath>
#include <iostream>
#include <cstdio>
using namespace std;
typedef complex<double> xy_t;

double X1,Y1,X2,Y2,XQ,YQ;

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }

int main() {
  while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf",&X1, &Y1, &X2, &Y2, &XQ, &YQ)) {
    xy_t P1(X1,Y1), P2(X2,Y2), Q(XQ,YQ);
    double t = dot_product(P2-P1, Q-P1)/norm(P2-P1);
    xy_t M = P1 + t * (P2 - P1);
    xy_t R = Q + 2.0 * (M - Q);

    printf("%.6f %.6f\n", real(R), imag(R));
  }
}


Measured memory_bytes: 3256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

void dfs(vector<vector<int>>&t, vector<int>&depth, int k, int dp, pair<int, int>&p){
  depth[k] = dp;
  if(dp%2) p.second++;
  else p.first++;
  for(auto i : t[k]){
    if(depth[i] != -1) continue;
    dfs(t, depth, i, dp+1, p);
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  vector<vector<int>> t(n);
  int rem0 = n/3, rem1 = n/3 + (n%3 != 0), rem2 = n/3 + (n%3 == 2);
  for(int i = 0; i < n-1; i++){
    int a, b; cin >> a >> b;
    a--; b--;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  vector<int> depth(n, -1);
  pair<int, int> p = {0, 0};
  dfs(t, depth, 0, 0, p);
  vector<int> ans(n);
  if(p.first < rem1){
    for(int i = 0; i < n; i++){
      if(depth[i]%2 == 0) ans[i] = (--rem0)*3 + 3;
      else{
        if(rem1) ans[i] = (--rem1)*3 + 1;
        else if(rem2) ans[i] = (--rem2)*3 + 2;
        else ans[i] = (--rem0)*3 + 3;
      }
    }
  }
  else if(p.second < rem2){
    for(int i = 0; i < n; i++){
      if(depth[i]%2 == 1) ans[i] = (--rem0)*3 + 3;
      else{
        if(rem1) ans[i] = (--rem1)*3 + 1;
        else if(rem2) ans[i] = (--rem2)*3 + 2;
        else ans[i] = (--rem0)*3 + 3;
      }
    }
  }
  else{
    for(int i = 0; i < n; i++){
      if(depth[i]%2 == 0){
        if(rem1) ans[i] = (--rem1)*3 + 1;
        else ans[i] = (--rem0)*3 + 3;
      }
      else if(depth[i]%2 == 1){
        if(rem2) ans[i] = (--rem2)*3 + 2;
        else ans[i] = (--rem0)*3 + 3;
      }
    }
  }
  for(int i = 0; i < n; i++){
    cout << ans[i] << ' ';
  }
  cout << endl;
  // end-----------------------------------------------
  cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 20352
#include<iostream>

using namespace std;

int main()
{
	int n, k;
	int data[1000][2];
	int center, color;
	bool hosei =false;
	
	cin >> n >> k;
	
	for(int i = 0; i < k; i++){
		cin >> data[i][0];
		cin >> data[i][1];
		
		//0x[XÉ¼·
		data[i][0] -= 1;
		data[i][1] -= 1;
	}
	
	//êÓÌ·³N©ç¢ë¢ëí©é
	//êÓÌ·³ªïÈçâ³
	
	if(n % 2 != 0){
		hosei = true;
		n++;
	}
	
	/*
	//^Cf[^©çlðZo
	cout << "lF" <<flush;
	if(n % 3 == 0){
		cout << "Y" << endl;
		center = 0;
	}
	else if(n % 3 == 1){
		cout << "B" << endl;
		center = 1;
	}
	else{
		cout << "R" << endl;
		center = 2;
	}
	*/
	
	//©ç£êÄ¢élÉæÁÄFðè
	for(int i = 0; i < k; i++){
		//¶ãÌÀWÉÏ·
		int x, y;
		if(data[i][0] > (n/2)-1){
			x = n - data[i][0];
			if(hosei){
				x++;
			}
			else{
				x--;
			}
		}
		else{
			x = data[i][0];
		}
		
		if(data[i][1] > (n/2)-1){
			y = n - data[i][1];
			if(hosei){
				y++;
			}
			else{
				y--;
			}
		}
		else{
			y = data[i][1];
		}
		
		//»ê¼êÌÀWª¬³·¬½ç3ð«µÄ²®
		x += 3;
		y += 3;
		
		if(y > x){
			color = x%3;
		}
		else{
			color = y%3;
		}
		
		switch(color){
			case 0:
				cout << "1" << endl;
				break;
			case 1:
				cout << "2" << endl;
				break;
			case 2:
				cout << "3" << endl;
				break;
		}
	}
}
	

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

int main() {
    string s;
    cin >> s;
    int current = 0;
    int mmaxus = 0;
    for(int i = 0; i < s.size();i++){
        if(s[i] == 'R'){
            current++;
        }else {
            mmaxus = max(current,mmaxus);
            current = 0;
        }
    }
    mmaxus = max(current,mmaxus);
    cout << mmaxus;
    
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int a[3];
	for(int i = 0;i<3;i++){
		cin >> a[i];
	}
	for(int i = 0;i<3;i++){
		for(int j = 0;j<3;j++){
			if(a[i] < a[j]){
			swap(a[i],a[j]);
			}
		}
	}
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
	return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

int main(int argc, char const *argv[])
{
    string S;
    cin >> S;
    vector<long long> a(S.size() + 1);
    vector<long long> b(S.size() + 1);
    vector<long long> c(S.size() + 1);

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

    for (int i = S.size() - 1; i >= 0; i--)
    {
        if (S[i] == '>') b[i] = b[i + 1] + 1;
    }
    
    long long ans = 0;
    for (int i = 0; i < c.size(); i++)
    {
        c[i] = max(a[i], b[i]);
        ans += c[i];
    }
    
    cout << (long long)accumulate(c.begin(), c.end(), 0LL) << endl;
    
    return 0;
}

Measured memory_bytes: 12664
#include <stdio.h>
#include <stdlib.h>

int H, W;

int g(int id) {
	return (id - 1) / W;
}

int cmp(const void* x, const void* y) {
	int a = *(const int*)x;
	int b = *(const int*)y;
	if (a < b) return -1;
	return a > b;
}

int A[128][128];
int B[128][128];
int C[128][128];

int main(void) {
	int i, j, k;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (scanf("%d", &A[i][j]) != 1) return 1;
		}
	}

	/* コピー */
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			B[i][j] = A[i][j];
		}
	}
	/* 順番に構築する */
	for (j = 0; j < W; j++) {
		int thisCount[128] = {0};
		int ttl = H * 10;
		for (i = 0; i < H; i++) {
			thisCount[g(B[i][j])]++;
		}
		for (;;) {
			int found = 0;
			int proceed = 0;
			for (i = 0; i < H; i++) {
				if (thisCount[g(B[i][j])] > 1) {
					found = 1;
					for (k = j + 1; k < W; k++) {
						if (thisCount[g(B[i][k])] == 0) {
							int t = B[i][j];
							B[i][j] = B[i][k];
							B[i][k] = t;
							thisCount[g(B[i][j])]++;
							thisCount[g(B[i][k])]--;
							proceed = 1;
							break;
						}
					}
				}
			}
			if (!found) break;
			if (!proceed) {
				for (i = 0; i < H; i++) {
					for (k = j + 1; k < W; k++) {
						if (thisCount[g(B[i][k])] == 0) {
							int t = B[i][j];
							B[i][j] = B[i][k];
							B[i][k] = t;
							thisCount[g(B[i][j])]++;
							thisCount[g(B[i][k])]--;
							proceed = 1;
							break;
						}
					}
				}
			}
			if (!proceed || --ttl <= 0) {
				if (ttl > 0) {
					puts("error! (not found)");
				} else {
					puts("error! (TTL expired)");
				}
				if (W <= 26) {
					for (i = 0; i < H; i++) {
						printf("%c", 'A' + g(B[i][0]));
						for (j = 1; j < W; j++) {
							printf(" %c", 'A' + g(B[i][j]));
						}
						putchar('\n');
					}
				}
				return 1;
			}
		}
	}

	/* コピー */
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			C[j][i] = B[i][j];
		}
	}
	/* ソート */
	for (j = 0; j < W; j++) {
		qsort(C[j], H, sizeof(int), cmp);
	}

	/* 出力 */
	for (i = 0; i < H; i++) {
		printf("%d", B[i][0]);
		for (j = 1; j < W; j++) {
			printf(" %d", B[i][j]);
		}
		putchar('\n');
	}
	for (i = 0; i < H; i++) {
		printf("%d", C[0][i]);
		for (j = 1; j < W; j++) {
			printf(" %d", C[j][i]);
		}
		putchar('\n');
	}

	return 0;
}

/*
上で同じ行に入っている数字が、下で同じ列に入ってしまうと負け
同じ数字が、上で複数行に入っていることは無い

上と下で、同じ数字は同じ行に入れる
上の配置を決めれば、自動的に下の配置も決まる

1を引いてWで割った商が同じ数字は、別の列に入れる

 1  4  7  10
 5 11  2   8
 9  6 12   3

A A B C    A A B C
A B B C -> B B C A
A B C C    C C A B

A A B C
A B B C
A B C C

A A B C
B A B C
A B C C

A A B C
B A B C
C B A C

A A B C
B C B A
C B A C

A A C B
B A B C
C B A C

1. 複数あるやつを探す
2. 複数あるやつのところの右から、無いやつを探す
3. 入れ替える

A A B C
A B B C
A B C C

C A B A
A B B C
A B C C

C A B A
B A B C
A B C C

C A B A
B C B A
A B C C

C A A B
B C B A
A B C C

*/


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

int main()
{
    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 998244353
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; 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;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	string s;
	cin >> s;
	if (s[0] == s[1] && s[0] == s[2])cout << "No" << endl;
	else cout << "Yes" << endl;
}
int main() {
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

constexpr auto M = 998244353;

int64_t calc(const string& s, vector<int64_t>& uu, int64_t g) {
    int64_t n = s.size();

    auto ss = s.substr(0, g);
    int64_t u = 0;
    int64_t dd = 1;
    for (auto i : irange(0uL, ss.size())) {
        u += dd * (ss[ss.size() - i - 1] - '0');
        u %= M;
        dd *= 2;
        dd %= M;
    }

    auto rr = ss;
    for (auto&& c : rr) {
        if (c == '1') {
            c = '0';
        } else {
            c = '1';
        }
    }

    string r;
    r.reserve(n);
    for (auto i : irange(0L, n / g)) {
        if (i % 2 == 0) {
            r += ss;
        } else {
            r += rr;
        }
    }

    if (r <= s) {
        ++u;
    }
    u %= M;

    for (int64_t i = 1; i * i <= g; ++i) {
        if (g % i > 0) {
            continue;
        }

        if (g != i) {
            u += M - uu[i];
        }
        if (g != g / i && i * i != g) {
            u += M - uu[g / i];
        }

        u %= M;
    }

    uu[g] = u;

    int64_t ans = u * 2 * g;
    ans %= M;

    return ans;
}

main() {
    int64_t n;
    cin >> n;

    string s;
    cin >> s;

    int64_t num = 0;
    int64_t ans = 0;
    vector<int64_t> uu(n + 1);
    int64_t i = 1;
    for (; i * i <= n; ++i) {
        if (n % i > 0) {
            continue;
        }

        if ((n / i) % 2 == 1) {
            ans += calc(s, uu, i);
            ans %= M;
            cerr << i << ":" << ans << endl;
        }
    }
    for (--i; i >= 1; --i) {
        if (n % i > 0) {
            continue;
        }

        if (i * i == n) {
            continue;
        }

        if (i % 2 == 1) {
            ans += calc(s, uu, n / i);
            ans %= M;
            cerr << n / i << ":" << ans << endl;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

int main(int argc, char* argv[]) {
  string s, t;
  cin >> s >> t;

  for (int i = 0; i < t.size(); ++i) {
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    char tmp = t[0];
    for (int j = 0; j < t.size(); ++j) {
      if (j == t.size() - 1) {
        t[0] = tmp;
      } else {
        char tmp2 = t[j + 1];
        t[j + 1] = tmp;
        tmp = tmp2;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[50];
  rep(i,n) cin>>a[i];
  int ans=0;
  while(1){
    bool f=true;
    sort(a,a+n,greater<int>() );
    if(a[0]>=n){
      f=false;
      int num=a[0]/n;
      a[0]%=n;
      ans+=num;
      //cout<<a[0]<<endl;
      repi(j,1,n) a[j]+=num;
    }
    if(f) break; 
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

void Sequence() {
	int n,x;
	cin >> n >> x;
	int bef = 0;
	ll res = 0;
	for (size_t i = 0; i < n; i++)
	{
		ll a;
		cin >> a;
		if (i > 0) {
			if (bef + a > x) {
				ll su = (bef + a) - x;
				a -= su;
				res += su;
			}
		}
		
		bef = max(0ll,a);
	}
	cout << res << endl;
	
}
int main() {
	Sequence();
	return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod;
assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
const int N=1e5+10;
ll n,k;
ll dp[N];
void add(ll &x,ll y)
{
    x=(x+y)%mod;
}
int main()
{

    cin>>n>>k;

    ll ans=0;
    for(ll gc=k;gc;--gc)
    {
        ll di=k/gc;
        ll num=powmod(di,n)%mod;
        ll t=0;
        for(ll j=gc+gc;j<=k;j+=gc) add(t,dp[j]);
    
        dp[gc]=(num-t+mod)%mod;
    }

    for(int i=1;i<=k;++i){
        add(ans,dp[i]*i%mod);
    }
    cout<<ans<<endl;
}
/*
3 200
*/


Measured memory_bytes: 4388
#include <iostream>
#include <utility>
using namespace std;

int main() {
  int n;
  cin >> n;
  long a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }

  long sub = 0;  //操作回数
  for (int i = 0; i < n; i++) {
    sub += b[i] - a[i];
  }

  long subreach = 0;
  for (int i = 0; i < n; i++) {
    subreach += (max(b[i] - a[i], 0l) + 1) / 2;
  }

  cout << (subreach <= sub ? "Yes" : "No") << endl;
}

Measured memory_bytes: 384
#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>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
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;}

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x = 0):x((x % mod + mod) % mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};
// combination c(max);
// mint c(n, k)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w, a, b;
    cin >> h >> w >> a >>b;

    combination c(1000000);
    mint ans = 0;
    rep(i, h-a) {
        ans += c(b-1+i, i) * c(w-b+h-i-2, h-1-i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 16000
N = int(input())
fizz = N // 3
buzz = N // 5
fzbz = N // 15
ans = (N+1)*N // 2
ans -= buzz * (5 * buzz + 5) // 2
ans -= fizz * (3 * fizz + 3) // 2
ans += fzbz * (15 * fzbz + 15) // 2
print(ans)


Measured memory_bytes: 9040
MOD = 2019
L, R = map(int, input().split())

if R - L > 2019:
    print(0)
    exit()

ans = float('inf')
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,(i*j)%MOD)
print(ans)

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

long long N, A, B, C, D;
priority_queue<pair<long long, long long> > pq;
set<long long> s;

void it(long long i, long long v) {
    if (s.find(i) != s.end()) return;
    s.insert(i);
    if (i % 2 == 0) pq.emplace(-v - A, i / 2);
    else {pq.emplace(-v - A - D, i / 2); pq.emplace(-v - A - D, i / 2 + 1);}
    if (i % 3 == 0) pq.emplace(-v - B, i / 3);
    else if (i % 3 == 1) pq.emplace(-v - B - D, i / 3);
    else pq.emplace(-v - B - D, i / 3 + 1);
    if (i % 5 == 0) pq.emplace(-v - C, i / 5);
    else if (i % 5 == 1) pq.emplace(-v - C - D, i / 5);
    else if (i % 5 == 2) pq.emplace(-v - C - D * 2, i / 5);
    else if (i % 5 == 3) pq.emplace(-v - C - D * 2, i / 5 + 1);
    else pq.emplace(-v - C - D, i / 5 + 1);
    if (i < (1000000000000000000 - v) / D) pq.emplace(-v - D * i, 0);
}

int main() {
    long long T, i, j;
    scanf("%lld", &T);
    while (T--) {
        scanf("%lld %lld %lld %lld %lld", &N, &A, &B, &C, &D);
        it(N, 0);
        while (pq.top().second) it(pq.top().second, -pq.top().first), pq.pop();
        printf("%lld\n", -pq.top().first);
        while (!pq.empty()) pq.pop();
        s.clear();
    }
    return 0;
}


Measured memory_bytes: 4236
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int cnt=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(i*500+j*100+k*50==x){
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    Int h;
    cin >> h;

    h = ceil(log2(h + 1));

    int n = 43;
    Int co[n] = {};
    co[0] = 1;
    for (Int i = 1; i < n; i++) {
        co[i] = 2 * co[i - 1] + 1;
        // cout << i << ':' << co[i] << endl;
    }

    cout << co[h - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    mod=1000000007
    n=int(input())
    A=list(map(int,input().split()))
    RGB=[0]*3
    ans=1
    for a in A:
        tmp=0
        for k in RGB:
            if a==k:
                tmp+=1
        ans*=tmp
        ans%=mod
        for i,k in enumerate(RGB):
            if a==k:
                RGB[i]+=1
                break
        else:
            return 0
    return ans
    
if __name__=='__main__':
    print(main())

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

int main() {
  long long n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> a;
  while(n){
    a.push_back(n%k);
    n /= k;
  }
  int ans = a.size();
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

 

int main() {
	int N; vector<string> w;
	cin >> N;
	bool ok = true;
	for (int i = 0; i < N; i++) {
		string ipts;
		cin >> ipts;
		w.push_back(ipts);
	}
	for (int i = 1; i < N; i++) {
		if (w[i].front() != w[i - 1].back())ok = false;
	}
	sort(w.begin(), w.end());
	for (int i = 1; i < N; i++) {
		if (w[i] == w[i - 1])ok = false;
	}
	if (ok)print("Yes"); else print("No");


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 510000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A=INF,B=0,C=INF,D=INF,E,F,N,M,K,sum=0,num=0,cnt=1,next=0;
  cin >> N >> M;
  Vec(P,lli,N,0);
  rep(i,0,N)cin >> P[i];
  Vecpr(Q,lli,lli,M);
  rep(i,0,M)cin >> Q[i].second >> Q[i].first;
  Sort(P);Sort(Q);Rev(Q);
  cnt=0;
  rep(i,0,N){
    if(Q[cnt].first>P[i]&&Q[cnt].second>0){
      P[i]=Q[cnt].first;
      Q[cnt].second--;
    }
    if(Q[cnt].second==0)cnt++;
  }
  rep(i,0,N)sum+=P[i];
  Out(sum);
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
void dfs(int,int);
int a[52][52]={};

int main(){
  while(1){
    int count=0,w,h;
    cin>>w>>h;
    if(w+h==0)break;
    
    for(int i=1;i<=h;i++)
      for(int j=1;j<=w;j++)
	cin>>a[i][j];

    for(int i=1;i<=h;i++)
      for(int j=1;j<=w;j++)
	if(a[i][j]==1){
	  dfs(j,i);
	  count++;
	}
    cout<<count<<endl;  
  }
  return 0;
}

  void dfs(int x,int y){
    a[y][x]=0;
    int nx,ny;
    int dx[8]={1,1,1,0,-1,-1,-1,0};
    int dy[8]={1,0,-1,-1,-1,0,1,1};
    for(int k=0;k<8;k++){
	nx=x+dx[k];
	ny=y+dy[k];
	if(a[ny][nx]==1){
	  dfs(nx,ny);
	}
    }
  }

Measured memory_bytes: 1384