akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 310;
	
int n, k, mod;
int comb[N][N], f[N][N][2], dp[N][N];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k >> mod;

	comb[0][0] = 1;
	for (int i=1; i<N; i++)
	{
		comb[i][i] = comb[i][0] = 1;
		for (int j=1; j<i; j++)
			comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod;
	}

	for (int t=0; t<N; t++) dp[0][t] = f[0][t][0] = f[0][t][1] = 1;

	for (int len=1; len<=n; len++)
		for (int t=1; t<=k; t++)
		{
			for (int i=1; i<=len; i++)
				f[len][t][0] += f[len - i][t][1], f[len][t][0] %= mod;
			
			for (int i=1; i<=len; i++)
			{
				ll ways = comb[len][i];
				ways *= dp[i][t - 1], ways %= mod;
				f[len][t][1] += (1LL * ways * f[len - i][t][0]) % mod;
				f[len][t][1] %= mod;
			}
			
			dp[len][t] = (f[len][t][0] + f[len][t][1]) % mod;

		}

	cout << dp[n][k] << endl;

}


Measured memory_bytes: 1792
S = input()
a = S.split("/")
y = int(a[0])
m = int(a[1])
d = int(a[2])

if y<=2018:
	print("Heisei")
elif y==2019 and m<=3:
	print("Heisei")
elif y==2019 and m==4 and d<=30:
	print("Heisei")
else:
	print("TBD")

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

int main(){
    long long N, Q;
    scanf("%lld%lld", &N, &Q);

    vector<long long> A(N), AS(N + 2), S(N + 1), X((N - 1) / 2), a((N + 1) / 2);
    for(int i = 0; i < N; ++i){
        scanf("%lld", &A[i]);
        AS[i + 2] = A[i] + AS[i];
        S[i + 1] = A[i] + S[i];
    }

    reverse(A.begin(), A.end());
    reverse(S.begin(), S.end());
    reverse(AS.begin(), AS.end());
    
    for(int i = 1; i <= (N + 1) / 2; ++i){
        a[i - 1] = S[0] - S[i] + AS[i * 2];
    }

    for(int i = 1; i <= (N - 1) / 2; ++i){
        X[i - 1] = A[i] + A[i * 2];
    }

    reverse(a.begin(), a.end());
    reverse(X.begin(), X.end());

    for(long long i = 0, x = 0; i < Q; ++i){
        scanf("%lld", &x);
        printf("%lld\n", a[lower_bound(X.begin(), X.end(), x * 2) - X.begin()]);
    }
    return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
    FOR(i,2,p) {
      if (p%i==0) return false;
    }
  return true;
}

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << min(a,b)+min(c,d);
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int r;
  cin >> r;
  if(r >= 2800){
    cout << "AGC" << endl;
  }else if(r >= 1200){
    cout << "ARC" << endl;
  }else{
    cout << "ABC" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;

int n, k, ans, tot, x, y, S[2010][2010];
char s[10];

inline int find(int x1, int y1, int x2, int y2)
{
    if (x1 > x2 || y1 > y2) return 0;
    return S[x2][y2] - S[x2][y1 - 1] - S[x1 - 1][y2] + S[x1 - 1][y1 - 1];
}

int check1(int x, int y)
{
    int tmp = 0;
    tmp += find(x, y, x + k - 1, y + k - 1);
    tmp += find(1, 1, x - 1, y - 1);
    tmp += find(1, y + k, x - 1, 2 * k);
    tmp += find(x + k, 1, 2 * k, y - 1);
    tmp += find(x + k, y + k, 2 * k, 2 * k);
    return tmp;
}

int check2(int x, int y)
{
    int tmp = 0;
    tmp += find(1, y, x - 1, y + k - 1);
    tmp += find(x, 1, x + k - 1, y - 1);
    tmp += find(x + k, y, 2 * k, y + k - 1);
    tmp += find(x, y + k, x + k - 1, 2 * k);
    return tmp;
}

int main()
{
    scanf("%d%d", &n, &k); ans = -n;
    FOR(i, 1, n)
    {
        scanf("%d%d%s", &x, &y, s);
        if (s[0] == 'W') ++tot, --S[x % (2 * k) + 1][y % (2 * k) + 1];
            else ++S[x % (2 * k) + 1][y % (2 * k) + 1];
    }
    FOR(i, 1, 2 * k) FOR(j, 1, 2 * k) S[i][j] += S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1];
    FOR(i, 1, k + 1) FOR(j, 1, k + 1)
    {
        ans = max(ans, check1(i, j));
        ans = max(ans, check2(i, j));
    }
    printf("%d\n", ans + tot);
    return 0;
}


Measured memory_bytes: 15872
L, R = map(int, input().split())
mod = 2019
modlist = [(L + i)%mod for i in range(min(2019,R-L+1))]
length = len(modlist)
ans = 2019
for i in range(length):
    for j in range(i+1,length):
        ans = min(ans, modlist[i]*modlist[j]%mod)

print(ans)

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int a[5][mx2];

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

    for(int i = 1; i <= n; i++)
        cin >> a[1][i], a[1][i] += a[1][i - 1];

    for(int i = 1; i <= n; i++)
        cin >> a[2][i];

    for(int i = n; i; i--)
        a[2][i] += a[2][i + 1];

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

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a,b;
  	cin>>a>>b;
  	if(a-'0'>b-'0'){
		cout<<'>'<<endl;
    }else if(a-'0'<b-'0'){
		cout<<'<'<<endl;
    }else{
		cout<<'='<<endl;
    }
}


Measured memory_bytes: 256
import itertools
N = int(input())
L = list(map(int, input().split()))

count = 0
for i in itertools.combinations(range(N), 3):
    Lx = sorted([L[i[0]], L[i[1]], L[i[2]]])
    if not (Lx[0] == Lx[1] or Lx[1] == Lx[2] or Lx[2] == Lx[0]):
        if Lx[0] + Lx[1] > Lx[2] :
            count += 1
    # print(Lx)
print(count)

Measured memory_bytes: 9204
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	h := getNextInt(scanner)
	n := getNextInt(scanner)

	// dp[減らす体力] = 使用する魔力の最小値
	dp := make([]int, h+1)
	for i := 0; i < h; i++ {
		dp[i+1] = math.MaxInt32
	}
	for i := 0; i < n; i++ {
		a := getNextInt(scanner)
		b := getNextInt(scanner)
		for j := 1; j <= h; j++ {
			mi := maxint(j-a, 0)
			if dp[mi] == math.MaxInt32 {
				continue
			}
			if dp[j] > dp[mi]+b {
				dp[j] = dp[mi] + b
			}
		}
	}

	fmt.Fprintln(writer, dp[h])
}

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


Measured memory_bytes: 768
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int a,b,c,k;
    cin>>a>>b>>c>>k;

    ll sum=0;
    if(k<=a){
        sum += k;
        cout<<sum<<endl;
        return 0;
    }
    sum += a;
    k -=a;
    if(k<=b){
        cout<<sum<<endl;
        return 0;
    }
    k -= b;
    if(k<=c){
        sum -= k;
        cout<<sum<<endl;
        return 0;
    }
    sum -= c;
    k -= c;
    cout<<sum<<endl;
    return 0;
}



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

int main(void){
    int n, i;
    long long int p, q;
    map<int, long long int> emp;
    vector<int> seq;
    while(cin >> n && n) {
        bool isExist = false;
        emp.clear();
        seq.clear();
        rep(l, n) {
            cin >> i >> p >> q;
            if(!emp[i]) seq.push_back(i);
            emp[i]+=p*q;
        }
        rep(i, seq.size()) {
            if(emp[seq[i]] >= 1000000) {
                cout << seq[i] << endl;
                isExist = true;
            }
        }
        if(!isExist) cout << "NA" << endl;
    }
}

Measured memory_bytes: 3120
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] card=new int[n+1];
    int kari=0;
    int cnt1=0;
    int cnt2=0;
    for(int i=1;i<=n;i++)
      card[i]=sc.nextInt();
    for(int i=1;i<=n;i++)
      for(int j=n;j>=i+1;j--)
        if(card[j]>card[j-1]){
          kari=card[j-1];
          card[j-1]=card[j];
          card[j]=kari;
        }
    for(int i=1;i<=n;i++){
      if(i%2==1) cnt1+=card[i];
      else cnt2+=card[i];
    }
    System.out.println(cnt1-cnt2);
  }
}

Measured memory_bytes: 21972
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt() - (i + 1);
		}
		Arrays.sort(a);
		
		// 計算
		long result = 0;
		long b = a[(n-1)/2];
		for(int i = 0; i < n; i++){
		    result += abs(a[i] - b);
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 65324
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>

using namespace std;

int main()
{
	string s;
	cin >> s;
	sort(begin(s), end(s));
	if (s == "abc")
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
N, M, C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]

cnt = 0
for a in A:
  tmp = C
  for i in range(M):
    tmp += a[i]*B[i]
  if(tmp > 0):
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

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



int main(){
    int N, M;
    cin >> N >> M;
    ll ans = 0;
    rep(i, M){
        int num;
        cin >> num;
        ans += num;
    }
    if(N - ans < 0)cout << -1 << endl;
    else cout << N - ans << endl;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, string> P;
typedef tuple<int, string, string> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

char a;

char solve() {
    if ('a' <= a && a <= 'z') return 'a';
    return 'A';
}

void input() {
    cin >> a;
}

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

    input();
    cout << solve() << endl;
}


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

using namespace std;

typedef long long ll;

int main()
{
	ll n, a, b, c, d;
	scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d), n--;
	for(int i = 0; i <= n; i++) {
		ll tmp = a + i * c - (n - i) * d;
		if(b - tmp >= 0 && b - tmp <= n * (d - c)) return puts("YES"), 0;
	}
	return puts("NO"), 0;
}

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

void fnInput(int& rnMonster, int& rnFinCnt, vector<int>& rvnLifePnt)
{
  cin >> rnMonster >> rnFinCnt;
  rvnLifePnt.resize(rnMonster);

  for(int& rnLifePnt : rvnLifePnt)
    cin >> rnLifePnt;
}
  
int64_t fnGameOverCnt(int nFinCnt, vector<int>& rvnLifePnt)
{
  sort(begin(rvnLifePnt), end(rvnLifePnt), greater<int>());

  int64_t nGameOverCnt = 0;
  for (int n = nFinCnt; n < rvnLifePnt.size(); n++)
    nGameOverCnt += rvnLifePnt[n];

  return nGameOverCnt;
}
  
int main()
{
  int nMonstr, nFinCnt;
  vector<int> vnLifePnt;

  fnInput(nMonstr, nFinCnt, vnLifePnt);
  cout << fnGameOverCnt(nFinCnt, vnLifePnt) << endl;

  return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>

int A[11]={0,1,2,3,4,5,6,7,8,9,0};
int cnt=0;

void dfs(int i,int rest,int d,int n){

 if(i<11){
    if(d==n){
      if(rest==0){cnt++;return;}
      else return;
    }

    if(rest<0)return;/*sを超える*/

    dfs(i+1,rest-A[i],d+1,n);/*A[i]を選ぶ*/
    dfs(i+1,rest,d,n);/*A[i]を選ばない*/

 }

return;
}




int main(){
 int n,s;

 while(1){

      scanf("%d %d",&n,&s);
      if(n==0 && s==0)break;
      if(s > 55)printf("0\n");
      else {
            cnt=0;
            dfs(0,s,0,n);
            printf("%d\n",cnt);

      }
 }

 return 0;
}


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

#define fore(i,ii,iii) for(int i=ii;i<iii;i++)

const int N=1e5+15,INF=1e9;
int n,dp[N][3],p[N][3];

int f(int x,int y){
if(x==0){return p[0][y];}
if(dp[x][y]>=0){return dp[x][y];}
dp[x][y]=max(f(x-1,(y+1)%3)+p[x][y],f(x-1,(y+2)%3)+p[x][y]);
return dp[x][y];
}

int main() {
cin>>n;
fore(i,0,n)fore(ii,0,3)cin>>p[i][ii];
memset(dp,-1,sizeof dp);
cout<<max(max(f(n-1,0),f(n-1,1)),f(n-1,2));
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n; scanf("%d",&n);
	int mx = 0, sm = 0;
	for(int i=0;i<n;i++){
		int x; scanf("%d",&x);
		if(mx<x) mx=x;
		sm += x;
	}
	if(sm-2*mx<=0) printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef unsigned long long int ull;
    const int MOD = (int)1e9+7;
    const int MAX = 1e6;
    ll arr[120];
    ll nCr(ll n, ll r)
    {
        ll C[r+1];
        memset(C, 0, sizeof(C));
        C[0] = 1;
        for (ll i = 1; i <= n; i++)
        {
            for (ll j = min(i, r); j > 0; j--)
                C[j] = (C[j] + C[j-1]);
        }
        return C[r];
    }
    int main()
    {
        ll tot=0;
        long double ans=0,sum=0,cnt=0;
        map<ll,int>N,R;
        int n,a,b;
        cin>>n>>a>>b;
        for(int i=0; i<n; i++){
        	cin>>arr[i];
			N[arr[i]]++;
		}
        sort(arr,arr+n);
        ll last ;
        for(int i=n-1; i>=0; i--)
        {
            sum+=arr[i];
            R[arr[i]]++;
            cnt++;
            if(cnt>b)
                break;
            if(cnt==a)
            {
                last = arr[n-1];
                ans=sum/cnt;
            }
            if(cnt>=a)
            {
                long double cur=(sum/cnt);
                if(cnt==a)
                    {tot+=nCr(N[arr[i]],R[arr[i]]);
                    }
                else if(arr[i]==last)
                {
                 tot+=nCr(N[arr[i]],R[arr[i]]);
                }
            }
        }
        cout<<setprecision(18)<<fixed<<ans<<endl;
        cout<<tot<<endl;
        return 0;
    }


Measured memory_bytes: 3804
import sys
sys.setrecursionlimit(10 ** 6)


def dfs(n, rest):
    global C, N
    rst = 0
    if maxR[n] > 0:
        rst = maxR[n]
    elif rest >= C and S[n] == 'o':
        rst += 1
        if n + (C + 1) < N:
            rst += dfs(n + C + 1, C)
    else:
        if n + 1 < N:
            rst += dfs(n + 1, rest + 1)
    maxR[n] = rst
    return rst


def dfs2(n, rest):
    global C, N
    rst = 0
    if maxL[n] > 0:
        rst = maxL[n]
    elif rest >= C and S[n] == 'o':
        rst += 1
        if n - (C + 1) >= 0:
            rst += dfs2(n - (C + 1), C)
    else:
        if n - 1 >= 0:
            rst += dfs2(n - 1, rest + 1)
    maxL[n] = rst
    return rst


N, K, C = map(int, input().split())
S = input()
maxR = [-1] * N
for i in range(N):
    if maxR[i] == -1:
        maxR[i] = dfs(i, C)

# if maxR[-1] == -1:
#     maxR[-1] = 0
# for i in range(N - 2, -1, -1):
#     if maxR[i] == -1:
#         maxR[i] = maxR[i + 1]

maxL = [-1] * N
for i in range(N - 1, -1, -1):
    if maxL[i] == -1:
        maxL[i] = dfs2(i, C)

# if maxL[0] == -1:
#     maxL[0] = 0
# for i in range(1, N):
#     if maxL[i] == -1:
#         maxL[i] = maxL[i - 1]

ans = []
for i in range(N):
    r = maxR[i + 1] if i + 1 < N else 0
    l = maxL[i - 1] if i - 1 >= 0 else 0
    if r + l < K:
        ans.append(i + 1)

print(*ans, sep='\n')


Measured memory_bytes: 191072
import sys

# import re
import math
import collections
# import decimal
import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()

    ans = []
    while len(a) > 0:
        flg = True
        for i in range(len(a) - 1, -1, -1):
            if i + 1 == a[i]:
                ans.append(i + 1)
                del a[i]
                flg = False
                break
        if flg:
            print(-1)
            exit(0)

    for i in range(n-1,-1,-1) :
        print(ans[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 5092
#include<iostream>
#include<algorithm>
#include<math.h>
#include <iterator>
#include <map>
#include<cmath>
using namespace std;


int main (){
   int x,n;
   cin>>x>>n;
   int start=0,endi=n,mid=0;
   while(start<=endi-1){
    mid=(start+endi)/2;
    if(mid*x-mid+1>=n)endi=mid;
    else start =mid+1;

    }
    cout<<endi<<endl;


	return 0;
}











Measured memory_bytes: 256
using System;
using System.Linq;
namespace ABC156
{
    class B
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long K = input[1];

            long res = 0;

            long index = 0;
            while (Math.Pow(K, index) <= N)
            {
                index++;
            }

            res = index;

            Console.WriteLine(res);

        }
    }
}


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

template <typename T> class BIT {
  public:
    int n;
    vector<T> nodes;
    BIT(int _n) : n(_n), nodes(_n + 1, 0) {}
    void add(int i, T v) {
        for (++i; i <= n; i += i & (-i)) nodes[i] += v;
    }
    T sum(int i) {
        T res = 0;
        for (++i; i > 0; i -= i & (-i)) res += nodes[i];
        return res;
    }
};

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

    int N, Q;
    cin >> N >> Q;
    vector<int> c(N);
    for (int i = 0; i < N; ++i) cin >> c[i];
    vector<tuple<int, int, int, int>> lr;  // (l, r, index, answer)
    for (int i = 0; i < Q; ++i) {
        int l, r;
        cin >> l >> r;
        lr.emplace_back(l, r, i, 0);
    }

    sort(lr.begin(), lr.end(), [](auto a, auto b) { return get<1>(a) < get<1>(b); });

    vector<int> last(N + 1, -1);  // last[color] = index
    BIT<int> indices(N + 10);

    int k = 0;
    for (int i = 0; i < Q; ++i) {
        while (k < get<1>(lr[i])) {
            if (last[c[k]] != -1) { indices.add(last[c[k]], -1); }
            last[c[k]] = k + 1;
            indices.add(last[c[k]], 1);
            k++;
        }
        get<3>(lr[i]) = indices.sum(get<1>(lr[i])) - indices.sum(get<0>(lr[i]) - 1);
    }

    sort(lr.begin(), lr.end(), [](auto a, auto b) { return get<2>(a) < get<2>(b); });

    for (int i = 0; i < Q; ++i) { cout << get<3>(lr[i]) << endl; }

    return 0;
}

Measured memory_bytes: 17368
N = int(input())
from collections import defaultdict as dd
a = list(map(int,input().split()))
Q = int(input())
bc = [tuple(map(int,input().split())) for _ in range(Q)]
dic=dd(int)
for val in a:
    dic[val] += 1
s = sum(a)
for b,c in bc:
    tmp = dic[b]
    dic[b] = 0
    dic[c] += tmp
    s += (c-b)*tmp
    print(s)


Measured memory_bytes: 35512
#include<stdio.h>
#include<stdlib.h>
 
#define MAX 10000

void countSort(short *,short *,int);
 
int main(){

  unsigned short *A, *B;
  int i,n;
 
  scanf("%d",&n);
   
  A = malloc(sizeof(int) * n + 1);
  B = malloc(sizeof(int) * n + 1);
 
  for(i = 1;i <= n;i ++)scanf("%hd",&A[i]);
   
  countSort(A,B,n);
 
  for(i = 1;i < n;i ++)
    {
    printf("%hd ",B[i]);
    }
  
  printf("%hd\n",B[n]);
  
  free(A);
  free(B);
  
  return 0;
}
     
void countSort(short *A,short *B,int n){

  int i,j;
  int C[MAX+1];
 
  for(i = 0;i <= MAX;i ++)
    {
      C[i] = 0;
    }
  
  for(j = 1;j <= n;j ++)
    {
      C[A[j]]++;
    }
  
  for(i = 1;i <= MAX;i ++)
    {
	C[i] = C[i] + C[i-1];
    }
  
  for(j = n;j >= 1;j --)
    {
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }
}

Measured memory_bytes: 11704
//ALDS1_2_A Sort I - Bubble Sort
#include <iostream>
using namespace std;

void swap(int& n1, int& n2)
{
    int temp;
    temp = n1;
    n1 = n2;
    n2 = temp;
}

void printArray(int* a, int n)
{
    for(int i=0; i<n; i++ ) {
        cout << *(a+i);
        if(i<n-1) cout << " ";
    }
    cout << endl;
}

int main()
{
    int l;
    int a[100];
    cin >> l;
    for(int i=0; i<l; i++) {
        cin >> a[i];
    }
    int count = 0;
    for(int i = 0; i < l-1; i++) {
        for(int j = (l-1); j >= (i+1); j--) {
            if (a[j] < a[j-1]) {
                swap(a[j],a[j-1]);
                count++;
            }
            //cout << "i:" << i << " j:" << j << " count:" << count << " Array: ";
            //printArray(a,l); 
        }        
    }
    printArray(a,l);
    cout << count << endl;
}


Measured memory_bytes: 3080
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        String str = N == M ? "Yes" : "No";
        System.out.println(str);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <list>
using namespace std;

int main() {
    int n,i,x;
    string com;
    list<int> L;
    list<int>::iterator it;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>com;
        if(com=="insert"){
            cin>>x;
            L.push_front(x);
        }else if(com=="delete"){
            cin>>x;
            for(it=L.begin();it!=L.end();it++){
                if((*it)==x){L.erase(it);break;}
            }
        }else if(com=="deleteFirst"){
            L.pop_front();
        }else if(com=="deleteLast"){
            L.pop_back();
        }
    }
    if(!L.empty()){
        it=L.begin();
        cout<<(*it);
        for(it++;it!=L.end();it++) cout<<" "<<(*it);
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 34400
n, m = map(int, input().split())
ps = []
for i in range(m):
    ps.append(list(map(str, input().split())))

res = [0, 0]
stat = ['WA' for i in range(n)]
for i in range(m):
    if ps[i][1] == 'AC':
        stat[int(ps[i][0]) - 1] = 'P'
for i in range(m):
    if ps[i][1] == 'AC':
        if stat[int(ps[i][0]) - 1] == 'P':
            res[0] += 1
            stat[int(ps[i][0]) - 1] = 'AC'
    if ps[i][1] == 'WA':
        if stat[int(ps[i][0]) - 1] == 'P':
            res[1] += 1
print('{} {}'.format(res[0], res[1]))

Measured memory_bytes: 73944
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"

vector<int>prime_number;
 
void prime(int n){
    int r = sqrt(n);
    for(int i=2;i<r+1;i++){
        while(n%i==0){
            n /= i;
            prime_number.push_back(i);
        }
    }
    if(n>1)prime_number.push_back(n);
}

int main(){
    int x;
    cin >> x;
    cout << x << ':';
    prime(x);
    for(int i=0;i<prime_number.size();i++){
        if(i!=prime_number.size())cout << " ";
        cout << prime_number[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3168
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int a=in();int b=in();int k=in();
	int ans;
	for(int i=100;i>=1 and k>0;i--)
	{
		if(a%i==0 and b%i==0){k--;ans=i;}
	}
	cout<<ans;
	
}

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
using namespace std;

int main() {
	

	long long int N, M, R;
	cin >> N >> M >> R;
	long long int G[205][205] = {};
	for (int i = 0; i < 205; i++) {
		for (int k = 0; k < 205; k++) {
			G[i][k] = 1000000000;
		}
	}
	long long int r[9];
	for (long long int i = 0; i < R; i++) {
		cin >> r[i];
	}
	long long int a, b, c;
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		G[a][b] = c;
		G[b][a] = c;
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			for (int k = 1; k <= N; k++) {
				G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
			}
		}
	}
	
	

	sort(r, r + R);
	vector<long long int> vec(R);
	for (int i = 0; i < R; i++) {
		vec[i] = r[i];
	}
	long long int X;
	long long int Y = 1000000000;
	
	do {
		X = 0;
		
		for (int i = 0; i < R - 1; i++) {
			X += G[vec[i]][vec[i + 1]];
			
		 }

		Y = min(Y, X);
	} while (next_permutation(vec.begin(), vec.end()));     // 次の順列を生成

	cout << Y << endl;
	return 0;
}



Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import numpy

# スペース区切りの整数の入力
N,M = map(int, input().split())
AB_list = []

for i in range(N):
  AB_list.append([int(e) for e in input().split()])

AB_list.sort(reverse=False) 

#print(AB_list)

sum = 0
i = 0
ans=0

while(sum!=M):
  #print(AB_list[i][0],AB_list[i][1])
  if sum + AB_list[i][1] <=M: #全部買っても合計に達しないなら
    #print("全部買う")
    sum = sum + AB_list[i][1] #全部買う
    ans = ans + AB_list[i][1]*AB_list[i][0] #全部買った分、金額増加
    #print(sum,ans)
  else: #買い占めると合計超すので抑える
    #print("一部買う")
    ans = ans + AB_list[i][0]*(M-sum) #買った分金額増加
    #print(M-sum,ans)
    sum=M #これで止める
  i=i+1
  
print(ans)

Measured memory_bytes: 30720
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a <= 0 && 0 <= b) {
        cout << "Zero" << endl;
        return 0;
    }
    int negative = 0;
    if (a < 0) {
        negative = -a - min(0, b) + 1;
    }
    if (negative % 2 == 1) {
        cout << "Negative" << endl;
    } else {
        cout << "Positive" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
typedef pair<int,int> pii;
int main() {
	int n=read(),a=read(),b=read();
	puts(a+b&1?"Borys":"Alice");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

template <class T>
T mult(T n,T m){
	if(m<=0) return 1;
	if(m==1){
		return n%mod;
	}else if(m%2==0){
		T t=mult(n,m/2);
		return (t*t)%mod;
	}else{
		T t=mult(n,m-1);
		return (t*n)%mod;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> c(n+1);
	rep(i,n){
		cin>>c[i];
	}
	c[n]=-1;
	sort(begin(c),end(c));
	ll ans=0;
	FOR(i,1,n+1){
		ll ret=(n-i)*mult(2ll,n-i-1ll);
		ret%=mod;
		ret+=mult(2ll,n-i);
		ret%=mod;
		ret*=mult(4ll,i-1);
		ret%=mod;
		ret*=mult(2ll,n-i+1);
		ret%=mod;
		ret*=c[i];
		ret%=mod;
		ans+=ret;
		ans%=mod;
	}
	ans%=mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
int main(){
    fastio;
    file();
    int n,x;
  cin>>n>>x;
  vv v(n);
  fors(i,n){
    cin>>v[i];
  }
  sortv(v);
  int cnt = 0;
  fors(i,n){
    if(x>=v[i]){
      ++cnt;
      x=x-v[i];
    }
    else{
      x=0;
    }
  }
  if(x){
    --cnt;
  }
  test(cnt);
  return 0;
}

Measured memory_bytes: 256
N,Q=list(map(int,input().strip().split(' ')))
gr=[[] for _ in range(N)]
val=[0]*N
for _ in range(N-1):
    a,b=list(map(int,input().strip().split(' ')))
    a-=1
    b-=1
    gr[a]+=[b]
    gr[b]+=[a]
for _ in range(Q):
    p,x=list(map(int,input().strip().split(' ')))
    p-=1
    val[p]+=x
ans=[0]*N
stack=[0]
checked=[0]*N
checked[0]=1
ans[0]=val[0]
while stack:
    x=stack.pop()
    for v in gr[x]:
        if checked[v]==0:
            stack+=[v]
            checked[v]=1
            ans[v]=ans[x]+val[v]
ans=[str(x) for x in ans]

print(" ".join(ans))

Measured memory_bytes: 122112
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    count = 0
    for i in range(N):
        if h[i] >= K:
            count += 1
        else:
            pass
    print(count)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12024
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define vi vector<int>
#define pb push_back
#define SZ(x) (int) x.size()
using namespace std;
const int MAXN = 1e6 + 10;
const ll INF = numeric_limits<ll>::max();
ll dis[MAXN][3];
bool vis[MAXN][3];
int n, m, s, t;
struct Node {
  int u, d;
};
vi e[MAXN];
void dij(int s) {
  queue<Node> q;
  for(reg int i = 1 ; i <= n + 100; ++i) for(reg int j = 0; j < 3; ++j) dis[i][j] = INF, vis[i][j] = 0;
  dis[s][0] = 0, q.push((Node) { s, 0 });
  while(!q.empty()) {
    Node x = q.front();
    q.pop();
    int u = x.u, d = x.d;
    if(vis[u][d]) continue;
    vis[u][d] = 1;
    for(auto i : e[u]) {
      int now = (d + 1) % 3;
      if(dis[i][now] > dis[u][d] + 1) dis[i][now] = dis[u][d] + 1, q.push((Node) { i, now });
    }
  }
}
void work() {
  scanf("%d%d", &n, &m);
  for(reg int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v), e[u].pb(v);
  }
  scanf("%d%d", &s, &t), dij(s);
  if(dis[t][0] == INF) puts("-1");
  else printf("%lld\n", dis[t][0] / 3);
}
int main() {
  int _ = 1;
  // scanf("%d", &_);
  while(_--) work();
  return 0;
}


Measured memory_bytes: 34048
while True:
    table = input().split()

    a = int(table[0])
    op = table[1]
    b = int(table[2])
    if op == '?':
        break

    if op == '+':
        print("%d"%(a+b))
    elif op == '-':
        print("%d"%(a-b))
    elif op == '/':
        print("%d"%(a/b))
    else:
        print("%d"%(a*b))



Measured memory_bytes: 5592
N, M = map(int, input().strip().split())
graph = [[False for _ in range(N)] for _ in range(N)]
visited = [False for _ in range(N)]
aa, bb = [], []
ans = 0
for _ in range(M):
  a, b = map(int, input().strip().split())
  aa.append(a)
  bb.append(b)
  graph[a-1][b-1] = graph[b-1][a-1] = True

def dfs(x):
  visited[x] = True
  for i, y in enumerate(graph[x]):
    if y and not visited[i]:
      dfs(i)

for a, b in zip(aa, bb):
  graph[a-1][b-1] = graph[b-1][a-1] = False
  for _v in range(len(visited)):
    visited[_v] = False
  dfs(0)
  if all(v for v in visited):
    ans += 1
  graph[a-1][b-1] = graph[b-1][a-1] = True

print(M - ans)


Measured memory_bytes: 3064
s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
m[0] = 1
m[int(s[l - 1])] = 1
ten = 10
ans = 0

for i in range(l - 1, 0, -1):
    t[i - 1] = (t[i] + int(s[i - 1]) * ten) % 2019
    ten = ten * 10 % 2019
    m[t[i - 1]] += 1

for i in m:
    ans += i * (i - 1) // 2

print(ans)

Measured memory_bytes: 16180
#include<bits/stdc++.h>
    #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    using namespace std;
    #define watch(x) cout<<(#x)<<" is "<<x<<endl;
    #define ll long long int
    #define pb push_back
    #define in insert
    #define mp make_pair
    #define F first
    #define S second
    #define N 1000000
    #define MOD 1000000007
    #define PI acos(-1)
   
    int main()
    {
    	IOS
    	ll a,b,n;
    	cin>>a>>b>>n;
    	ll ans;
    	ll x=min(b-1,n);
    	ans=(a*x)/b;
    	ans=max(ans,(a*n)/b-a*(n/b));
    	cout<<ans;
    }
    

Measured memory_bytes: 3648
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            List<TaskC.Point> pointA = new ArrayList<>();
            List<TaskC.Point> pointB = new ArrayList<>();
            Comparator<TaskC.Point> min = Comparator.comparing(TaskC.Point::getMin);
            Comparator<TaskC.Point> max = Comparator.comparing(TaskC.Point::getMax);

            for (int i = 0; i < n; i++) {
                pointA.add(new TaskC.Point(in.nextInt(), in.nextInt()));
            }
            for (int i = 0; i < n; i++) {
                pointB.add(new TaskC.Point(in.nextInt(), in.nextInt()));
            }

            pointA.sort(max);
            pointB.sort(min);
            int ans = 0;
            for (int index = pointA.size() - 1; index >= 0 ; index--) {
                TaskC.Point ca = pointA.get(index);
                for (int i = 0; i < pointB.size(); i++) {
                    TaskC.Point cb = pointB.get(i);
                    if (ca.getX() < cb.getX() && ca.getY() < cb.getY()) {
                        pointA.remove(ca);
                        pointB.remove(cb);
                        ans++;
                        break;
                    } 
                }
            }
            out.println(ans);
        }

        static class Point {
            private int x;
            private int y;

            public Point(int x, int y) {
                this.x = x;
                this.y = y;
            }

            public int getX() {
                return this.x;
            }

            public int getY() {
                return this.y;
            }

            public int getMax() {
                return Math.max(x, y);
            }

            public int getMin() {
                return Math.min(x, y);
            }

        }

    }
}


Measured memory_bytes: 27348
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B;
    cin >> A >> B;
    ll ans = max(A+B, max(A-B, A*B));
    print(ans);
    
    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, D;
    cin >> N >> D;
    if(N%(2*D+1)==0){
        std::cout << N/(2*D+1) << std::endl;
    }
    else{
        std::cout << N/(2*D+1)+1 << std::endl;
    }
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {

            int a, b, A, B, C, max;

            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            A = a + b;
            B = a - b;
            C = a * b;

            if (A >= B && A >= C)
                max = A;
            else if (B > A && B > C)
                max = B;
            else
                max = C;


            Console.WriteLine(max);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long lol;
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
int n,f[505][505],px[250005],py[250005],vis[505][505];
lol ans;
void bfs(int x,int y)
{int X,Y,xx,yy;
	queue<int>Q;
	for (int i=0;i<4;i++)
		{
			X=x+dx[i];Y=y+dy[i];
			if (X<=0||X>n||Y<=0||Y>n) continue;
			if (f[X][Y]>f[x][y]+(vis[x][y]==0)) 
			{
				Q.push((X-1)*n+Y);
				f[X][Y]=f[x][y]+(vis[x][y]==0);
			}
		}
	while (!Q.empty())
	{
		int xx=px[Q.front()],yy=py[Q.front()];
		Q.pop();
		for (int i=0;i<4;i++)
		{
			X=xx+dx[i];Y=yy+dy[i];
			if (X<=0||X>n||Y<=0||Y>n) continue;
			if (f[X][Y]>f[xx][yy]+(vis[xx][yy]==0))
			{
				Q.push((X-1)*n+Y);
				f[X][Y]=f[xx][yy]+(vis[xx][yy]==0);
			}
		}
	}
}
int main()
{int i,j,x;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
			{
				f[i][j]=min(i-1,min(j-1,min(n-i,n-j)));
				px[(i-1)*n+j]=i;py[(i-1)*n+j]=j;
			}
	}
	for (i=1;i<=n*n;i++)
	{
		scanf("%d",&x);
		ans+=f[px[x]][py[x]];
		vis[px[x]][py[x]]=1;
		//printf("%d %d %d\n",px[x],py[x],f[px[x]][py[x]]);
		bfs(px[x],py[x]);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 7696
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#define ll long long
#define ull unsigned long long
using namespace std;

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

	ll n, k;
	cin >> n >> k;
	vector<ll> V(n);
	for (ll &v : V) cin >> v;
	vector<ll> DP(n, INT32_MAX);
	DP.at(0) = 0;
	DP.at(1) = abs(V.at(1) - V.at(0));

	for (ll i = 2; i < n; i++){
		for (ll j = i - 1; j >= 0 && j >= (i - k); j--){
			DP.at(i) = min(DP.at(i), DP.at(j) + abs(V.at(i) - V.at(j)));
		}
	}

	cout << DP.back();
	return 0;
}


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


def shortest_path(s):
    #s→iの最短距離
    # s:始点, n:頂点数, w:辺の数, es[i]: [辺の始点,辺の終点,辺のコスト]
    d = [float("inf")] * n
    #d[i] : s→iの最短距離
    d[s] = 0
    for j in range(n):
        updata = False
        for i in range(w):
            e = es[i]
            # e: 辺iについて [from,to,cost]
            if d[e[0]] != float("inf") and d[e[1]] > d[e[0]] + e[2]:
                d[e[1]] = d[e[0]] + e[2]
                updata = True
        if not updata:
            break
    tmp = d[-1]
    for j in range(n):
        updata = False
        for i in range(w):
            e = es[i]
            # e: 辺iについて [from,to,cost]
            if d[e[0]] != float("inf") and d[e[1]] > d[e[0]] + e[2]:
                d[e[1]] = d[e[0]] + e[2]
                updata = True
        if not updata:
            break
    if tmp == d[-1]:
        return d[-1]
    return float("inf")

n,w = map(int,input().split()) #n:頂点数　w:辺の数

es = []

for i in range(w):
    x,y,z = map(int,input().split())
    es.append([x-1,y-1,-z])
dj = shortest_path(0)
if dj == float("inf"):
    print('inf')
else:
    print(-dj)

Measured memory_bytes: 43356
roll = {"North":("152304"), 
    "South":("402351"), 
    "East":("310542"), 
    "West":("215043"),
    "Right":("024135"),
    "Left":("031425")}
while True:
    n = int(input())
    if n == 0:
        break
    cnt = 1
    _dice = [i for i in range(1,7)]
    for i in range(n):
        _dice = [_dice[int(j)] for j in roll[input().strip()]]
        cnt+=_dice[0]
    print(cnt)


Measured memory_bytes: 5620