akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations_with_replacement, compress
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)


def main():
    N, M, Q = LI()
    abcd = [LI() for _ in range(Q)]
    ans = 0

    for A in combinations_with_replacement(range(1, M + 1), N):
        tmp = 0
        for (a, b, c, d) in abcd:
            tmp += d if (A[b-1] - A[a-1] == c) else 0
        ans = max(ans, tmp)
    print(ans)


main()


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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 998244353; 


signed main(void)
{
	IOS;
	string s = "ACL";
	int k; cin>>k;
	for(int i = 0; i < k; i++)
		cout<<s;
	cout<<endl;
	return 0;
}

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

int main(int argc, char *argv[])
{
  int x, y;

  scanf("%x %x", &x, &y);
  if (x > y) {
    printf(">");
    }
  else if (x == y) {
      printf("=");
    }
  else {
    printf("<");
  }
  printf("\n");
}


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

#define NMAX 20000

ll dp1[100][NMAX], dp2[100][NMAX];
ll a[100][100], b[100][100];

void init() {
    rep(i, 0, 100) {
        rep(j, 0, NMAX) {
            dp1[i][j] = 0;
            dp2[i][j] = 0;
        }
    }
}

void my_swap() {
    rep(i, 0, 100) {
        rep(j, 0, NMAX) {
            dp1[i][j] = dp2[i][j];
            dp2[i][j] = 0;
        }
    }
}

int main(){
    init();
    ll h, w;
    cin >> h >> w;
    rep(i, 0, h) rep(j, 0, w) cin >> a[i][j];
    rep(i, 0, h) rep(j, 0, w) cin >> b[i][j];
    ll base = NMAX / 2;
    dp1[0][base] = 1;
    rep(i, 0, h) {
        rep(j, 0, w) {
            rep(k, 0, NMAX) {
                if(dp1[j][k]) {
                    ll p = a[i][j] - b[i][j];
                    dp1[j+1][k+p] = 1;
                    dp1[j+1][k-p] = 1;
                    dp2[j][k+p] = 1;
                    dp2[j][k-p] = 1; 
                }
            }
        }
        my_swap();
    }
    ll ans = 1e18;
    rep(i, 0, NMAX) {
        if(dp1[w-1][i]){
            ans = min(ans, abs(i - base));
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	int n[3];
	for(int i = 0;i<3;i++)n[i]= s[i].size();
	int now = 0;
	int m[3] = {};
	while(1)
	{

		if(m[now]==n[now])
		{
			cout<<(char)('A'+now)<<endl;
			return 0;
		}
		int next = s[now][m[now]]-'a';
		m[now]++;
		
		now = next;
		
	}
}


Measured memory_bytes: 3612
#include <stdio.h>

int main(void){
    int n, rank[3];
    scanf("%d", &n);

    rank[0] = n / 100;
    rank[1] = (n % 100) / 10;
    rank[2] = (n % 10);

    if(rank[0] == 7){
        printf("Yes\n");
        return 0;
    }
    else if(rank[1] == 7){
        printf("Yes\n");
        return 0;
    }
    else if(rank[2] == 7){
        printf("Yes\n");
        return 0;
    }
    else{
        printf("No\n");
        return 0;
    }
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
#define int long long
using namespace std;

int k,n,maxv=-1;
int a[200006];

bool cmp(int a,int b)
{
	return a<b;
}

signed main()
{
	cin>>k>>n;
	for (int i=1;i<=n;i++)  cin>>a[i];
	
	sort(a+1,a+n+1,cmp);
	a[n+1]=a[1]+k;
	
	for (int i=1;i<=n;i++)  maxv=max(maxv,a[i+1]-a[i]);
	cout<<k-maxv<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
package main

import (
  "fmt"
)

func main() {
  var (
    a,b,sum int
  )

  fmt.Scan(&a,&b)

  if a>b {
    sum = a * 2 - 1
  } else if a == b {
    sum = a * 2
  } else {
    sum = b * 2 -1
  }
  fmt.Println(sum)
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int X,t;
  cin>>X>>t;
  cout<<max(0,X-t)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	cout<<((n/(a+b)*a)+(min(n%(a+b),a)));
}



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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<4;i++){
    int count=0;
    for(int j=0;j<4;j++){
      if(s.at(i)==s.at(j)) count++;
    }
    if(count!=2){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
n = int(input())
# S = [None] * n
d = {}
m = 0
T = []
for i in range(n):
    s = input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
    m = max(m, d[s])

for key in d:
    if d[key] == m:
        T.append(key)

T.sort()
for i in range(len(T)):
    print(T[i])


Measured memory_bytes: 32124
def solve():
  n,k = map(int,input().split())
  t = []
  hl = []
  mi = 1000000000
  for i in range(n):
    hl.append(int(input()))
  hl.sort(reverse=True)
  for i in range(n):
    h = hl[i]
    if i + 1 > k:
       t.pop(0)
    t.append(h)
    if len(t) == k:
      sm = t[0] - t[k - 1]
      if mi > sm:
        mi = sm
  print(mi)

if __name__ == '__main__':
  solve()


Measured memory_bytes: 7884
n = int(input())
a = [int(input()) for i in range(n)]
flg = 0
num = 1
cnt = 0
for i in range(n):
	cnt += 1
	num = a[num-1]
	if num == 2:
		flg = 1
		break
if flg == 1:
	print (cnt)
else:
	print (-1)

Measured memory_bytes: 7084
n=gets.to_i
b=gets.split.map &:to_i

a=[]
m=n
m.times{|i|
    b.reverse.each_with_index{|e,j|
        if e==n-j
            a<<e
            b.delete_at(n-j-1)
            n-=1
            break
        end
    }
}

if a.size!=m
    p -1
else
    a.reverse_each{|e|p e}
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define PI 3.1415926535897932384626
#define mod 1000000007
#define fo(i,n) for(i=0;i<n;i++)
#define endl "\n"
#define mset(m,v) memset(m,v,sizeof(m))
typedef vector<int>	vi;

void solve()
{
	int n,k,i,x=0,a,b;
	cin >> n >> k;
	k*=k;
	for(i=0;i<n;i++){
	    cin >> a >> b;
	    if(a*a+b*b<=k)x++;
	}
	cout << x;
	cout << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}

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

#define STRING(str) #str

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

int main() {
	int N;
	cin >> N;
	// x+y
	long long val1 = 3e18;
	long long val2 = -3e18;
	// x-y
	long long val3 = 3e18;
	long long val4 = -3e18;
	// -x+y
	long long val5 = 3e18;
	long long val6 = -3e18;
	// -x-y
	long long val7 = 3e18;
	long long val8 = -3e18;
	for (int i=0;i<N;i++) {
		long long x, y;
		cin >> x >> y;
		val1 = min(val1, x+y);
		val2 = max(val2, x+y);
		val3 = min(val3, x-y);
		val4 = max(val4, x-y);
		val5 = min(val5, -x+y);
		val6 = max(val6, -x+y);
		val7 = min(val7, -x-y);
		val8 = max(val8, -x-y);
	}

	long long ans = -3e18;
	ans = max(ans, abs(val1-val2));
	ans = max(ans, abs(val3-val4));
	ans = max(ans, abs(val5-val6));
	ans = max(ans, abs(val7-val8));
	cout << ans << endl;
}

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

int main() {
  int n;
  int h;
  cin >> n;
  int m = -1;
  int res = 0;
  for (int i = 0; i < n; i++) {
    cin >> h;
    if (m <= h) {
      res++;
    }
    m = max(m, h);
  }
  cout << res << endl;
}


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

int main(){
    string ta,ha;
    int tap = 0 ,hap = 0,n;
    
    cin >> n;
    while(n--){
        cin >> ta >> ha;
        
        if(ta > ha) tap += 3;
        else if(ta < ha) hap += 3;
        else{
            tap++;
            hap++;
        }
    }
    cout << tap << ' ' << hap << endl;

    return 0;
}


Measured memory_bytes: 3148
import sys

N,M=map(int, sys.stdin.readline().split())
S=[None]+map(int, sys.stdin.readline().split())
T=[None]+map(int, sys.stdin.readline().split())

dp=[ [ 0 for m in range(M+1) ] for n in range(N+1) ]

for m in range(M+1): dp[0][m]=1	
for n in range(n+1): dp[n][0]=1	

mod=10**9+7
for i in range(1,N+1):
	for j in range(1,M+1):
		if S[i]==T[j]:
			dp[i][j]+=dp[i][j-1]+dp[i-1][j]
		else:
			dp[i][j]+=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]
		dp[i][j]%=mod
		

print dp[-1][-1]%mod
			

Measured memory_bytes: 60700
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;
 
#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
 
const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);
 
template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
const ll dx[4] = {0, 1, 0, -1};
const ll dy[4] = {1, 0, -1, 0};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h, w; cin >> h >> w;
    vector<string> m(h); cin >> m;
    vector<vector<ll>> dist(h, vector<ll>(w, linf));
    queue<P> Q;
    Q.push({0, 0});
    dist[0][0] = 0;
    auto inRange = [&](ll x, ll y) {
        return 0 <= x && x < w && 0 <= y && y < h;
    };
    while ( !Q.empty() ) {
        P p = Q.front(); Q.pop();
        ll x, y; tie(x, y) = p;
        rep(d, 4) {
            ll nx = x + dx[d];
            ll ny = y + dy[d];
            if (inRange(nx, ny) && m[y][x] == '.' && dist[y][x] + 1 < dist[ny][nx]) {
                dist[ny][nx] = dist[y][x] + 1;
                Q.push({nx, ny});
            }
        }
    }
    if (dist[h-1][w-1] == linf) {
        cout << -1 << endl;
    }
    else {
        ll cnt = 0;
        rep(y, h) rep(x, w) if (m[y][x] == '.') ++cnt;
        cout << cnt - dist[h-1][w-1]-1 << endl;
    }
}

Measured memory_bytes: 256
def abc_exp(a,b,c):
	print(str(a) + ' ' + str(b) + ' ' + str(c) )
	
def exchange(a,b,remain):
	while True:
		if remain >= 4 and a - 4 >= 0:
			b = b + 8
			a = a - 4
			remain = remain - 4
		else: 
			break
	return a,b
	

N,Y = map(int,input().split())

a = int(Y/10000)
b = int((Y - a * 10000)/5000)
c = int((Y - a * 10000 - b * 5000)/1000)

max_bills = int(Y/1000)

if (max_bills < N) or (N < a + b + c):
	print('-1 -1 -1')
	
elif (N == max_bills):
	print('0 0 ' + str(max_bills))
	
else:
	remain = N - a - b - c
	a = a - (remain % 4)
	b = b + 2 * (remain % 4)
	
	a , b = exchange(a,b,remain)
	remain = N - a - b - c
	if b - remain/4 >= 0:
		b = b - int(remain / 4)
		c = c + int(remain / 4) * 5
		abc_exp(a,b,c)
	
	else:
		print('-1 -1 -1')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const double pi = 3.141592653589793;

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

  int n; cin >> n;
  string s; cin >> s;
  vector<int> cnt(26, 0);
  rep(i, n) {
    ++cnt[s[i]-'a'];
  }

  long long ans = 1;
  rep(i, 26) {
    if(cnt[i] > 0) {
      ans *= cnt[i] + 1;
      ans %= MOD;
    }
  }

  ans -= 1;

  cout << ans << endl;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int A[310];
double dp[310][310][310];
bool used[310][310][310];

double dfs(int x, int y, int z)
{
	if (!x && !y && !z)return 0.0;
	if (used[x][y][z])return dp[x][y][z];

	double res = (double)N / (x + y + z);
	if (x > 0)res += dfs(x - 1, y, z)*(double)x / (x+y+z);
	if (y > 0)res += dfs(x + 1, y - 1, z)*(double)y / (x + y + z);
	if (z > 0)res += dfs(x, y + 1, z - 1)*(double)z / (x + y + z);
	used[x][y][z] = true;
	dp[x][y][z] = res;
	return res;
}

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

	int C[3] = { 0 };
	cin >> N;
	rep(i, 0, N)
	{
		cin >> A[i];
		C[A[i] - 1]++;
	}

	printf("%.15lf\n", dfs(C[0], C[1], C[2]));

	return 0;
}

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

using ll = long long;

int solve(vector<ll> values)
{
    auto S = *max_element(begin(values), end(values));
    auto small_primes = vector<ll>();
    auto small_prime_limit = static_cast<int>(cbrt(S)) + 1;
    auto large_prime_squares = map<ll, ll>();
    auto large_prime_limit = static_cast<int>(sqrt(S)) + 1;
    auto is_prime = vector<bool>(large_prime_limit+1, true);
    for (auto p = 2LL; p <= large_prime_limit; p++) if (is_prime[p])
    {
        if (p <= small_prime_limit) small_primes.push_back(p);
        else large_prime_squares[p*p] = p;
        for (auto k = 2*p; k <= large_prime_limit; k += p)
            is_prime[k] = false;
    }

    auto normalize = [&](ll x)
    {
        for (auto p : small_primes)
        {
            auto cube = p*p*p;
            while (x % cube == 0) x /= cube;
        }
        return x;
    };

    auto counts = map<ll, int>();
    for (auto x : values)
        counts[normalize(x)]++;

    auto dual = [&](ll x)
    {
        auto y = 1LL;
        for (auto p : small_primes)
        {
            if (x % (p*p) == 0) y *= p;
            else if (x % p == 0) y *= p*p;
            while (x % p == 0) x /= p;
        }
        auto kv = large_prime_squares.find(x);
        if (kv != end(large_prime_squares)) y *= kv->second;
        else y *= x*x;
        return y;
    };

    auto result = 0;
    for (auto kv : counts)
    {
        auto x = kv.first, y = dual(x);
        if (counts.count(y) == 0) result += counts[x];
        else if (x < y) result += max(counts[x], counts[y]);
    }
    if (counts[1]) result++;
    return result;
}

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

    auto values = vector<ll>(N);
    for (auto& x : values) cin >> x;

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


Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    cout << (n-1) * (m-1) << endl;
}

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

int main (){

    //data_set : a and b
    std::array<int, 4> data_a;
    std::array<int, 4> data_b;

    while(std::cin >> data_a[0] >> data_a[1] >> data_a[2] >> data_a[3]){
        std::cin >> data_b[0] >> data_b[1] >> data_b[2] >> data_b[3];
        int hit = 0;
        int blow = 0;
        for(int i = 0; i < 4; ++i){
            //if same digit and same num
            if(data_b[i] == data_a[i]) {
                hit++;
            } else {
                //if different digit and same num
                for (int j = 0; j < 4; ++j) {
                    if (data_b[i] == data_a[j]) {
                        blow++;
                    }
                }
            }
        }
        std::cout << hit << " " << blow << std::endl;

    }
}

Measured memory_bytes: 3060
s = input()

mod = [0]*2019
mod[0] = 1
t, a, n = 0 , 1, len(s)
s = s[::-1]
for i in range(n):
    t = (t + int(s[i])*a) % 2019
    a = a * 10 % 2019
    mod[t] += 1
ans = 0
for i in range(2019):
    ans += mod[i]*(mod[i]-1)//2
print(ans)

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

int main() {
    long long x, y;
    cin >> x >> y;

    int length = 0;
    long long value = x;
    while (value <= y) {
        value *= 2;
        length++;
    }

    cout << length << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n;
int a[10010],l,ans=0,p[100000];

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

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


ll power(ll a,ll x,ll mod){
  if (x==0) return 1;
  if (x==1) return a;
  if (x%2==0) return power(a*a%mod,x/2,mod);
  else return power(a*a%mod,x/2,mod)*a%mod;
}

template<typename T> 
unordered_map<T,int> factorize(T x){
    unordered_map<T,int> res;
    for(int i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            res[i]++;
        }
    }
    if(x!=1) res[x]++;
    return res;
}



void solve(){
  unordered_map<int,int> L;
  cin >> n;
  rep(i,n){
    cin >> a[i];
    int x=a[i];
    unordered_map<int,int> res;
    for(int k=2;k*k<=x;k++){
        while(x%k==0){
            x/=k;
            res[k]++;
        }
    }
    if(x!=1) res[x]++;
    for(auto k:res){
      L[k.first]=max(L[k.first],k.second);
    }
  }
  ll ans=0;
  rep(i,n){
    ans+=power(a[i],mod-2,mod);
    ans%=mod;
  }
  for(auto k:L){
    ans*=power(k.first,k.second,mod);
    ans%=mod;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 768
package main

import (
	"fmt"
	"sort"
)


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

func main() {
	var n int
	fmt.Scan(&n)
	point := make([]int, n+1)
	fmt.Scan(&point[0])
	for i := 1; i < n+1; i++ {
		fmt.Scan(&point[i])
	}
	sort.Ints(point)
	sa := make([]int,n)

	for i := 0;i < n; i++ {
		sa[i] = point[i+1] - point[i]
	}
	z := sa[0]
	for _,n := range sa {
		z = gcd(n, z)
	}
	fmt.Println(z)
}


Measured memory_bytes: 5504
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import functools 
import sys
import bisect
import string
import math
import time
import random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

N=10**6+2
m=[0]*(N)

n,k=LI()
a=LI()
N=1<<n
ans=inf
for i in range(N):
    c=0
    t=[]
    for j in range(n):
        if (i>>j)&1:
            c+=1
            t+=[j]
    if c!=k:
        continue
    
    alt=0
    ti=0
    M=-1
    for j in range(n):
        
        if j==t[ti]:
            alt+=max(0,M+1-a[j])
            M=max(a[j],M+1)
            ti+=1
        #show(j,M,alt,ti)
        if ti==k:
            break
        M=max(M,a[j])
        
    #show(alt,t,a)
    if alt<ans:
        ans=alt
print(ans)


Measured memory_bytes: 52840
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ちゃんとユニークな配列にする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int Q;
  cin >> Q;
  vector<int> l;
  vector<int> r;
  rep(i, Q) {
    int li, ri;
    cin >> li >> ri;
    l.pb(li);
    r.pb(ri);
  }

  // 全部作ってしまえ
  vector<int> primes;
  set<int> setPrime;
  vector<int> like2017s;

  primes.pb(2);
  setPrime.insert(2);
  for(int i = 3; i < 100001; i++)
  {
    bool prime = true;
    for(int j=0; j<primes.size() && primes[j]*primes[j] <= i ; j++)
    {
      if(i % primes[j] == 0)
      {
        prime = false;
        break;
      }
    }
    if(prime) 
    {
      primes.pb(i);
      setPrime.insert(i);

      if(setPrime.count((i + 1) / 2) > 0) {
        like2017s.pb(i);
      }
    }
  }

  // 数え上げるだけ
  rep(i, Q) {
    int count = 0;
    for(int like2017 : like2017s) {
      if(l[i] <= like2017 && like2017 <= r[i]) count++;
    }
    cout << count << endl;
  }

}


Measured memory_bytes: 2036
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;



int cnta[1000001] = {0};
int cntb[1000001] = {0};

signed main(){
    
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(m);
    rep(i,n){
        cin >> a[i];
        cnta[a[i]]++;
        if(cnta[a[i]] >= 2){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i,m){
        cin >> b[i];
        cntb[b[i]]++;
        if(cntb[b[i]] >= 2){
            cout << 0 << endl;
            return 0;
        }
    }
    SORT(a);
    SORT(b);
    int ans = 1;
    for(int i = n*m;i >= 1;i--){
        if(cnta[i] == 1 && cntb[i] == 1){
            //no
        }else if(cnta[i] == 1){
            auto itr = upper_bound(b.begin(),b.end(),i);
            int x = b.end() - itr;
            if(x <= 0){
                cout << 0 << endl;
                return 0;
            }
            ans *= x;
            ans %= MOD;
        }else if(cntb[i] == 1){
            auto itr = upper_bound(a.begin(),a.end(),i);
            int x = a.end() - itr;
            if(x <= 0){
                cout << 0 << endl;
                return 0;
            }
            ans *= x;
            ans %= MOD;
        }else{
            auto itr = upper_bound(a.begin(),a.end(),i);
            int x = a.end() - itr;
            auto itr1 = upper_bound(b.begin(),b.end(),i);
            int y = b.end() - itr1;
            if(x <= 0 || y <= 0 || x*y-(n*m-i) <= 0){
                cout << 0 << endl;
                return 0;
            }
            ans *= x*y-(n*m-i);
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 
// rm -r -f test;oj dl http://arc074.contest.atcoder.jp/tasks/arc074_b

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

int val(char a){
  if(a=='T')return 10;
  if(a=='J')return 11;
  if(a=='Q')return 12;
  if(a=='K')return 13;
  if(a=='A')return 14;
  return (int)(a-'0');
}

int main(){
  char t;
  string c[4][13];
  
  while(cin >> t,t!='#'){
    for(int i=0;i<4;i++)for(int j=0;j<13;j++)cin >> c[i][j];
    
    int ns=0,ew=0,prv = 0;
    for(int i=0;i<13;i++){
      int tr=0,ma=0,tid,mid,v;
      for(int j=0;j<4;j++){
	if(c[j][i][1] == t){
	  v = val(c[j][i][0]);
	  if(tr<v){
	    tr = v; tid = j;
	  }
	}
	if(c[j][i][1] == c[prv][i][1]){
	  v = val(c[j][i][0]);
	  if(ma<v){
	    ma = v; mid= j;
	  }
	}
      }      if(tr){
	prv = tid;
	if(tid&1)ew++;else ns++;
      }else{
	prv = mid;
	if(mid&1)ew++;else ns++;
      }
    }
    if(ns>ew)cout << "NS " << ns-6 << endl;
    else cout << "EW " << ew-6 << endl;
  }
}

Measured memory_bytes: 1192
/*
*/

#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-6
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 350

using namespace std;

const int INF = 1e9;
const int N = 300000;

int n, k, s;
int a[N];
int mx;

int ans;

int main(){
	//freopen("fabro.in","r",stdin);
	//freopen("fabro.out","w",stdout);
	//freopen("F:/in.txt", "r", stdin);
	//freopen("F:/output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin >> k >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		s += a[i];
		mx = max(mx, a[i]);
	}

	for (int start_block = 1; start_block <= 100; start_block++)
	{
		int rem = s - start_block;
		int rem_bad = mx - start_block;
		//--rem;
		if (rem_bad * 2 > rem)
			continue;
		cout << start_block - 1 << endl;
		return 0;
	}
	cin.get(); cin.get();
	return 0;
}

Measured memory_bytes: 384
import java.math.BigInteger
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val t1 = BigInteger(sc.next())
  val t2 = BigInteger(sc.next())
  val a1 = BigInteger(sc.next())
  val a2 = BigInteger(sc.next())
  val b1 = BigInteger(sc.next())
  val b2 = BigInteger(sc.next())

  var d1 = (a1 - b1) * t1 // 最初のt1分間での増分
  var d2 = (a2 - b2) * t2 // 次のt2分間での増分
  //println("P = $d1, Q = $d2")

  if (d1 > BigInteger.ZERO) {
    d1 *= -BigInteger.ONE
    d2 *= -BigInteger.ONE
  }

  if (d1 + d2 < BigInteger.ZERO) {
    // 1サイクルが終わった時に正の向きなので、0の位置に戻ることはない
    println(0)
  } else if (d1 + d2 == BigInteger.ZERO) {
    // 1サイクルが終わると0の位置に戻るので、無限に繰り返す
    println("infinity")
  } else {
    val s = -d1 / (d1 + d2)
    val t = -d1 % (d1 + d2)
    //println("S = $s, T = $t")
    if (t == BigInteger.ZERO) {
      println(s * BigInteger("2"))
    } else {
      println(s * BigInteger("2") + BigInteger.ONE)
    }
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 100 * 1000 + 10;
const ll MOD = 1000 * 1000 * 1000 + 7;

struct Bit {
    vector<ll> t;

    Bit(int n): t(n) {}

    ll get(int i) const {
        ll res = 0;
        for (; i >= 0; i = (i & (i + 1)) - 1)
            res += t[i];
        return res % MOD;    
    }

    ll get(int l, int r) const {
        if (l > r)
            return 0;
        ll res = get(r) - get(l - 1);
        return (res + MOD) % MOD;    
    }

    void upd(int i, ll d) {
        for (; i < t.size(); i = (i | (i + 1)))
            t[i] = (t[i] + d) % MOD;    
    }
};

ll badX[N];
ll badY[N];

ll get(ll* p, int l, int r) {
    if (l > r)
        return 0;
    ll res = p[r];
    if (l)
        res -= p[l - 1];
    return res; 
}


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

    int n;
    cin >> n;
    ll a, b;
    cin >> a >> b;
    vector<ll> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];
    Bit dp0(n + 1);
    Bit dp1(n + 1);
    for (int i = 1; i < n; i++) {
        if (s[i] - s[i - 1] < a)
            badX[i - 1]++;
        if (s[i] - s[i - 1] < b)
            badY[i - 1]++;    
        badX[i] = badX[i - 1];
        badY[i] = badY[i - 1];
    }
    for (int i = 0; i < n; i++) {
        if (!i || badX[i - 1] == 0) 
            dp1.upd(i + 1, 1);
        if (!i || badY[i - 1] == 0)
            dp0.upd(i + 1, 1);   
    }
    for (int cur = 1; cur < n; cur++) {
        {
            int r = cur;
            if (cur != n - 1) 
                r = min(r, int(upper_bound(s.begin(), s.end(), s[cur + 1] - b) - s.begin()));
            int low = -1;
            int high = cur;
            while (high - low > 1) {
                int mid = (low + high) / 2;
                if (get(badX, mid, cur - 1) == 0)
                    high = mid;
                else
                    low = mid;        
            } 
            //cerr << 0 << endl;
            //cerr << cur << " " << high << " " << r << endl;
            int l = high;
            ll ways = dp0.get(l, r);
            //cerr << ways << endl << endl;
            dp1.upd(cur + 1, ways); 
        }  
        {
            int r = cur;
            if (cur != n - 1) 
                r = min(r, int(upper_bound(s.begin(), s.end(), s[cur + 1] - a) - s.begin()));
            int low = -1;
            int high = cur;
            while (high - low > 1) {
                int mid = (low + high) / 2;
                if (get(badY, mid, cur - 1) == 0)
                    high = mid;
                else
                    low = mid;        
            } 
            //cerr << 1 << endl;
            //cerr << cur << " " << high << " " << r << endl;
            int l = high;
            ll ways = dp1.get(l, r);
            //cerr << ways << endl << endl;
            dp0.upd(cur + 1, ways); 
        }  
    }
    cout << (dp0.get(n, n) + dp1.get(n, n)) % MOD << endl;
}   

Measured memory_bytes: 4352
function main()
  
  N = parse(Int, readline())
  a = map(x -> parse(Int, x), split(readline()))
  
  sum = 0
  
  for i in 1:N
    
    sum += a[i]
    
  end
  
  for i in 1:N
    
    a[i] = abs(sum - (a[i] * N))
    
  end
  
  (c, ans) = findmin(a)
  
  println(ans-1)
  
end

main()

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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

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

const ll SIZE = 1e5+10;

ll k,x;

int main(){
    cin >> k >> x;
    if(k*500 >= x)  cout << "Yes\n";
    else{
        cout << "No\n";
    }
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
$H = array_map('intval', explode(" ", trim(fgets(STDIN))));

$ans = 'Yes';
$mmax = $H[0];

for ($i = 1; $i < $N; $i++) {
    $mmax = max($mmax, $H[$i]);
    if ($mmax - 2 >= $H[$i]) {
        $ans = 'No';
    }
}

echo $ans;


Measured memory_bytes: 16884
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	int W, a, b;
	cin >> W >> a >> b;
	if (a > b) swap(a, b);
	if (b <= a + W) cout << 0 << endl;
	else cout << b - (a + W) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    string s;
    cin >> n;
    cin >> s;

    int A[2 * n];
    REP(i,2 * n){
        if(s[i] == 'B'){
            A[i] = 1;
        }
        else{
            A[i] = 0;
        }
    }

    int kake = 1;
    FOR(i,1, n + 1){
        kake *= i;
        kake %= MOD;
    }
    int migi = 0;
    int ans = 1;
    int i = 0;
    bool migiflag = true;
    bool hajime = true;
    while(i < 2 * n ){

        if(migi == 0 and hajime){
            if(A[i] %2  == 1 and A[i+ 1]%2 == 1){
                i += 2;
            }
            else if(A[i]%2 == 1 and A[i + 1]%2 == 0){
                migi = 2;
                i += 2;
                migiflag = true;
                hajime = false;
            }
            else{
                cout << 0 << endl;
                return 0;
            }


        }
        else{
            if(A[i] %2 == A[i-1]%2){
                if(migiflag){
                    migiflag = false;
                    ans *= migi;
                    ans %= MOD;
                    migi --;
                }
                else{
                    migiflag = true;
                    migi ++;
                }
            }
            else{
                if(migiflag){
                    migi ++;
                }
                else{
                    ans *= migi;
                    ans %= MOD;
                    migi --;
                }
            }
            i+= 1;
            if(migi < 0){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    if(migi != 0){
        cout << 0 << endl;
        return 0;
    }



    cout << ans * kake % MOD << endl;


}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
ll n, c[3][100005], dp[3][100005];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (ll i = 1; i <= n; i++){
		for (ll j = 0; j <= 2; j++){
			cin >> c[j][i];
			dp[j][i] = c[j][i];
		}
	}
	//dp[0][1] = c[0][1], dp[1][1] = c[1][1], dp[2][1] = c[2][1];
	
	for (ll i = 2; i <= n; i++){
		for (ll j = 0; j <= 2; j++){
			for (ll k = 0; k <= 2; k++){
				if (j == k)continue;
				dp[j][i] = max(dp[k][i-1]+c[j][i], dp[j][i]);
			}
		}
	}
	cout << max(max(dp[0][n], dp[1][n]), dp[2][n]);
}


Measured memory_bytes: 4992
//C
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e6+10;
ll raw[maxn];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,k;
	cin >> n >> k;
	ll lst = 1;
	for(int i = 1;i <= n;i++){
		cin >> raw[i];
	}
	ll mul = 1;
//	for(int i = 1;i <= k;i++)mul *= raw[i];
	for(int i = k+1;i <= n;i++){
		if(raw[i] > raw[i-k])cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 5144
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int tmp1=Euclid(a,b);
        int tmp2=0;
        int k=sc.nextInt();
        for(int i=a;i>0;i--){
            if(tmp1%i==0){
                tmp2++;
                if(tmp2==k){
                    System.out.println(i);
                    return;
                }
            }
        }
    }
        private static int Euclid(int n, int m) {
        int tmp;
        while (true) {
            if (n == 0) {
                return m;
            } else if (m == 0) {
                return n;
            }
            tmp = n;
            n = m;
            m = tmp;
            n = n % m;

        }
        }
}

Measured memory_bytes: 22996
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  set<int,greater<int>>大到小
#include <vector>// ::iterator it;
#include <stack>
#include <cmath> // auto &Name : STLName  Name.
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;
const db eps=1e-10;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=2e5+8;
inline ll read(){ll s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
using namespace std;

int t,n,m,k=0;
int a,b,c,ans=0;
string s,e;
int main(){
    scanf("%d%d",&n,&k);
    scanf("%d%d%d",&a,&b,&c);
    cin>>s;
    for(int i=0;i<n;i++){
        char cc;
        if(s[i]=='r') cc='p',ans+=c;
        if(s[i]=='s') cc='r',ans+=a;
        if(s[i]=='p') cc='s',ans+=b;
        e.insert(e.end(),cc);
    }
    for(int i=0;i<n-k;i++){
        char cc;
        if(s[i]=='r'&&s[i]==s[i+k]) s[i+k]='a',ans-=c;
        if(s[i]=='s'&&s[i]==s[i+k]) s[i+k]='a',ans-=a;
        if(s[i]=='p'&&s[i]==s[i+k]) s[i+k]='a',ans-=b;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
	ll h,w,m;
	cin>>h>>w>>m;
	vector<ll>x(m),y(m);
	rep(i,m){
		cin>>x[i]>>y[i];
		x[i]--;y[i]--;
	}
	vector<int>cnt(h);
	rep(i,m){
		cnt[x[i]]++;
	}
	int maxv=0,val=-1;
	rep(i,h){
		if(chmax(maxv,cnt[i]))val=i;
	}
	int ans=maxv;
	cnt=vector<int>(w);
	rep(i,m){
		if(x[i]!=val){
			cnt[y[i]]++;
		}
	}
	maxv=0;
	rep(i,w){
		chmax(maxv,cnt[i]);
	}
	ans+=maxv;
	rep(i,m)swap(x[i],y[i]);
	int ans2=ans;
	ans=0;
	cnt=vector<int>(w);
	rep(i,m){
		cnt[x[i]]++;
	}
	maxv=0,val=-1;
	rep(i,w){
		if(chmax(maxv,cnt[i]))val=i;
	}
	ans=maxv;
	cnt=vector<int>(h);
	rep(i,m){
		if(x[i]!=val){
			cnt[y[i]]++;
		}
	}
	maxv=0;
	rep(i,h){
		chmax(maxv,cnt[i]);
	}
	ans+=maxv;
	chmax(ans,ans2);
	cout<<ans;
}

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


Measured memory_bytes: 10328
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        C_Alchemist();
    }

    private static void C_Alchemist() {

        final Scanner sc = new Scanner(System.in);
        final int numberOfMaterials = sc.nextInt();
        final List<Integer> valueListOfMaterials = new ArrayList<>();
        for (int i = 0; i < numberOfMaterials; i++) {
            valueListOfMaterials.add(sc.nextInt());
        }

        final List<Double> valueListByDouble = valueListOfMaterials.stream()
                .sorted()
                .map(Integer::doubleValue)
                .collect(Collectors.toList());

        Double answer = null;
        for (Double d : valueListByDouble) {
            if (answer == null) {
                answer = d;
            } else {
                answer = (answer + d) / 2;
            }
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 27348
n,k = map(int, input().split())
ab = []
for i in range(n):
    a,b = map(int, input().split())
    ab.append((a,b))
ab.sort()
num = 0
for h in range(n):
    num += ab[h][1]
    if k <= num:
        print(ab[h][0])
        break

Measured memory_bytes: 22752
import java.util.Scanner


object Main {


  def read() = {
    val sc = new Scanner(System.in)
    val n, a, b, c, d = sc.nextInt()
    val s = sc.next() + "####"
    (n, a - 1, b - 1, c - 1, d - 1, s)
  }

  def solve(n: Int, a: Int, b: Int, c: Int, d: Int, s: String): Boolean = {
    //テストケースにない怖い
    def exists2Black(begin: Int, end: Int): Boolean = {
      (begin until end - 1).exists(i => s(i) == '#' && s(i + 1) == '#')
    }

    def exists3White(begin: Int, end: Int): Boolean = {
      (begin until end - 2).exists(i => s(i) == '.' && s(i + 1) == '.' && s(i + 2) == '.')
    }

    if (c < d) {
      !exists2Black(a, c + 1) && !exists2Black(b, d + 1)
    } else {
      !exists2Black(a, c + 1) && !exists2Black(b, d + 1) && exists3White(b-1, d + 2)
    }
  }

  def main(args: Array[String]): Unit = {
    val (n, a, b, c, d, s) = read()
    val able = solve(n, a, b, c, d, s)
    val result = if (able) "Yes" else "No"
    println(result)
  }
}

Measured memory_bytes: 36336
#include<iostream>
#include<vector>

using namespace std;

int main()
{int N , K ;
 cin >> N >> K;
 vector<int> A(N);
 for(int i = 0; i < N; i++)
 {cin >> A[i];}
 
 cout << (N + K - 3) / ( K - 1 ) << endl;
 
 return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define N 55
using namespace std;
const int mo=1e9+7;
int n,f[N][2*N][2*N],a[2*N],ans;
void inc(int &x,int y){ x=x+y>=mo ? x+y-mo : x+y;}
int main()
{
	int i,j,k,l,p,u,v;
	scanf("%d",&n);
	for(i=1;i<2*n;i++) scanf("%d",&a[i]);
	sort(a+1,a+2*n);
	f[n][1][1]=1,p=1;
	for(i=n;i>1;i--){
		u=(a[i]!=a[i-1]);
		v=(a[2*n-i]!=a[2*n-i+1]);
		for(j=1;j<=p;j++)
			for(k=1;k<=j;k++){
				if(!f[i][j][k]) continue;
				for(l=1;l<k+u;l++)
					inc(f[i-1][j+u+v-(k+u-l-1)][l],f[i][j][k]);
				for(l=j+u+v;l>k+u;l--)
					inc(f[i-1][j+u+v-(l-k-u-1)][k+u+1],f[i][j][k]);
				inc(f[i-1][j+u+v][k+u],f[i][j][k]);
			  }
		p+=u+v;
	  }
	for(i=1;i<=p;i++)
		for(j=1;j<=i;j++)
			inc(ans,f[1][i][j]);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1408