akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C, long long D){
  bool isWin = false;
  while(1) {
    C -= B;
    if (C <= 0){
      isWin = true;
      break;
    }
    A -= D;
    if (A <= 0){
      isWin = false;
      break;
    }
  }
  cout << (isWin ? YES : NO) << endl;
}

signed main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long C;
  scanf("%lld",&C);
  long long D;
  scanf("%lld",&D);
  solve(A, B, C, D);
}


Measured memory_bytes: 3776
import sys

readline = sys.stdin.readline
MOD = 998244353
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, s = map(int, readline().split())
    a = list(map(int, readline().split()))
    dp = [[0] * (s + 1) for _ in range(n + 1)]
    dp[0][0] = 1

    for i in range(n):
        cur = a[i]
        dp[i + 1][0] += 1
        for j in range(s + 1):
            dp[i + 1][j] += dp[i][j]
            dp[i + 1][j] %= MOD
            nx = cur + j
            if nx <= s:
                dp[i + 1][nx] += dp[i][j]
                dp[i + 1][nx] %= MOD
    ans = 0

    for i in range(1, n + 1):
        ans += dp[i][s]
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	long long d = (c - a - b);
	if (d > 0 && d * d > 4LL * a * b)
		puts("Yes");
	else 
		puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
//#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
	int N, M;
	cin >> N >> M;
	map<int, int>m;
	rep(i, N)
	{
		int K;
		cin >> K;
		rep(i, K)
		{
			int num;
			cin >> num;
			m[num]++;
		}
	}
	int cnt = 0;
	for (auto i : m)
	{
		if (i.second == N)cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vec vector

typedef long long ll;

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

using namespace std;

/* Input variables. */
ll n;
ll a, b, c, d, e;

/* Solve! */
void solve() {
  ll ans = 0;
  ll x = min({a, b, c, d, e});
  ans = (n + x - 1) / x + 4;
  cout << ans << endl;
}

int main() {
  /* Input handling. */
  cin >> n;
  cin >> a >> b >> c >> d >> e;

  solve();
  return 0;
}

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


signed main() {
    //my-code
    int x, y, z; cin >> x >> y >> z;
    int tmp;
    tmp = y;
    y = x;
    x = tmp;
    tmp = z;
    z = x;
    x = tmp;
    cout << x << " " << y << " " << z << endl;

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

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

int main()
{
  int N, sum;
  sum = 0;
  string collor;
  cin >> N;
  for (int i = 0; i < N ; i++)
  {

    cin >> collor;
    if (collor == "P"||collor == "W"||collor =="G")
    {
      sum += 1;
    }
    else if (collor == "Y")
    {
      sum += 999;
    }

  }
  if (sum >= 1 && sum < 999)
    {
      cout << "Three" << endl;
    }
    else if (sum >= 1 && sum >= 999)
    {
      cout << "Four" << endl;
    }
}


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

int main(){
  int n,a,x;
  cin>> n;
  vector<vector<int>> v(n,vector<int>(n,-1));
  for (int i=0; i<n; i++){
    cin>>a;
    for (int j=0; j<a; j++){
      cin>>x;
      cin>>v[i][x-1];
    }
  }
  
  int ans=0;
  for (int i=0; i<(1<<n); i++){
    bitset<15> bs(i);
    bool ok=true;
    for (int j=0; ok && j<n; j++){
      if (bs.test(j)){
        for (int k=0; k<n; k++){
          if (v[j][k]!=-1 && v[j][k]!=bs[k]){
            ok=false;
            break;
          }
        }
      }
    }
    if (ok) {
      ans=max(ans,(int)bs.count());
    }
  }
  
  cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main() {

  char ch[1200];
  int i,n;
  n=0;
  char a[1200];

  while(1) {
    scanf("%c",&a[n]);
    if(a[n] == '\n') {
      break;
    }
    ch[n] = a[n];
    if('A' <= a[n] && a[n] <= 'Z') {
      ch[n] = a[n] + 32;
    } else if(a[n] >= 'a' && a[n] <= 'z') {
      ch[n] = a[n] - 32;

    }
    
    
    n = n +1;
    
  }
  
  for(i=0; i<n ; i++) {
    printf("%c" ,ch[i]);
  }
  printf("\n"); 
  return 0;
  
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    vector<ll> a(n),b(n),c(n),d(m),e(m),f(m);
    set<ll> st;
    st.insert(0);
    ll lim = 1e+10;
    st.insert(lim);
    st.insert(-lim);
    rep(i,n) {
        cin>>a[i]>>b[i]>>c[i];
        st.insert(a[i]);
        st.insert(b[i]);
        st.insert(c[i]);
    }
    rep(i,m) {
        cin>>d[i]>>e[i]>>f[i];
        st.insert(d[i]);
        st.insert(e[i]);
        st.insert(f[i]);
    }
    map<ll,ll> comp;
    vector<ll> compinv(st.size(),0);
    ll num = 0;
    for(auto x:st) {
        comp[x] = num;
        compinv[num++] = x;
    }
    ll c_size = comp.size();

    bool mat[c_size][c_size][2] = {};
    // vector<vector<vector<bool>>> mat(c_size,vector<vector<bool>>(c_size,vector<bool>(2,false)));
    rep(i,n) {
        ll y = comp[c[i]];
        repr(j,comp[a[i]],comp[b[i]]) {
            mat[j][y][0] = true;
        }
    }
    rep(i,m) {
        ll x = comp[d[i]];
        repr(j,comp[e[i]],comp[f[i]]) {
            mat[x][j][1] = true;
        }
    }
    queue<pair<ll,ll>> que;
    que.emplace(comp[0],comp[0]);
    ll res = 0;
    vector<vector<bool>> chk(c_size,vector<bool>(c_size,true));
    chk[comp[0]][comp[0]] = false;
    while(!que.empty()) {
        ll x = que.front().first;
        ll y = que.front().second;
        que.pop();
        res += (compinv[x+1]-compinv[x]) * (compinv[y+1]-compinv[y]);
        if (x==0||y==0||x==c_size-2||y==c_size-2) {
            cout << "INF" << endl;
            return 0;
        }
        if (!mat[x][y][0]&&chk[x][y-1]) {
            que.emplace(x,y-1);
            chk[x][y-1] = false;
        }
        if (!mat[x][y][1]&&chk[x-1][y]) {
            que.emplace(x-1,y);
            chk[x-1][y] = false;
        }
        if (!mat[x][y+1][0]&&chk[x][y+1]) {
            que.emplace(x,y+1);
            chk[x][y+1] = false;
        }
        if (!mat[x+1][y][1]&&chk[x+1][y]) {
            que.emplace(x+1,y);
            chk[x+1][y] = false;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 79244
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int cnt = 0;

void insertion_sort(vector<int> &a,int n,int g){
	FOR(i,g,n){
		int v = a[i];
		int j = i - g;
		while(j >= 0 && a[j] > v){
			a[j+g] = a[j];
			j -= g;
			cnt++;
		}
		a[j+g] = v;
	}
}

vector<int> make_g(int n){
	vector<int> res;
	int num = 1;
	res.push_back(1);
	while(1){
		num = 3*num+1;
		if(num >= n)break;
		res.push_back(num);
	}
	reverse(ALL(res));
	return res;
}

void shellsort(vector<int> &a,int n){
	vector<int> G = make_g(n);
	rep(i,G.size())insertion_sort(a,a.size(),G[i]);
	cout << G.size() << endl;
	rep(i,G.size()){
		if(i == 0)cout << G[i];
		else cout << " " << G[i];
	}
	cout << endl;
}

int n;

int main(){
	cin >> n;
	vector<int> A(n);
	rep(i,n)cin >> A[i];
	shellsort(A,n);
	cout << cnt << endl;
	rep(i,n)cout << A[i] << endl;
}


Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#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 = 1LL << 60;

ll mpow(ll x, ll n, ll mod){//繰り返し二乗法 計算量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 main(){
    int N;
    cin >> N;
    vector<char> C(N);
    rep(i, N) cin >> C[i];
    int left = 0, right = N - 1;
    int ans = 0;
    while(left<right){
        if(C[left] == 'W' && C[right] == 'R'){
            ans++;
            left++;
            right--;
        }else{
            if(C[left] == 'R')left++;
            if(C[right] == 'W')right--;
        }
        // cout << left << " " << right << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>

int main(){
  int H,i,j,k,l,A[250],left = 0,right = 0,parent = 0;
  
  scanf("%d",&H);
  
  for(i = 1;i <= H ;i++){
    scanf("%d",&A[i]);
  }
  
  for(i = 1;i <= H;i++){
    j = 2*i;
    k = 2*i+1;
    l = i/2;
    left = A[j];
    right = A[k];
    parent = A[l];
    if(j > H){
      left = 0;
    }
    if(k > H){
      right = 0;
    }
    if(l < 1){
      parent = 0;
    }
    printf("node %d: key = %d, ",i,A[i]);
    if(parent != 0){
      printf("parent key = %d, ",parent);
    }
    if(left != 0){
      printf("left key = %d, ",left);
    }
    if(right != 0){
      printf("right key = %d, ",right);
    }
    printf("\n");
  }
      return 0;
}
  



Measured memory_bytes: 2104
N = int(input())
hs = [int(i) for i in input().split()]

ans = 0
while True:
    is_segment = False
    segment_count = 0
    for h in hs:
        if h > 0:
            if not is_segment:
                segment_count += 1
            is_segment = True
        else:
            is_segment = False
    if segment_count == 0:
        break
    else:
        ans += segment_count
        hs = [max(0, h-1) for h in hs]
print(ans)


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

int s,i,l,ans;
string f;
int main()
{
	cin>>l;
	cin>>f;
	for(int i=0;i<l;i++)
	{
		if(f[i]=='I')s++;
		if(f[i]=='D')s--;
		if(s>ans)ans=s;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
S = int(input())
dp = [0 for i in range(S+1)]
dp[0] = 1

#dp[i] = dp[i-3] + dp[i-4] + .... + dp[0] = dp[i-3] + dp[i-2]

for i in range(3, S+1):
  t = 0
  for j in range(0, i-2):
    t += dp[j]
    t %= 10**9 + 7
  dp[i] = t
  #print(i , dp[i])

print(dp[S])

Measured memory_bytes: 9184
let (n, p) = Scanf.sscanf (read_line ()) "%d %d" @@ fun n p -> (n, p)

let rec prime_fact acc i n =
  if n = 0 then acc
  else if n < i * i then n :: acc
  else if n mod i = 0 then prime_fact (i :: acc) i (n / i)
  else prime_fact acc (i + 1) n

let prime_fact n =
  List.fold_left (fun acc i ->
    match acc with
      | [] -> [(i, 1)]
      | (v, cnt) :: xs -> if v = i then (v, cnt + 1) :: xs else (i, 1) :: (v, cnt) :: xs
  ) [] @@ prime_fact [] 2 n

let ps = prime_fact p

let rec pow n = function
  | 0 -> 1
  | i -> n * pow n (i - 1)


let () = 
  let ans = List.fold_left (fun ans (v, cnt) ->
    ans * (pow v (cnt / n))
  ) 1 ps in
  Printf.printf "%d\n" ans

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

typedef struct {
	double x, y, z, r;
} Coord;

typedef struct {
	int from, to;
	double weight;
} Edge;

Coord coord[ 100 ];
int node[ 100 ];
Edge edge[ 4950 ];

int compare( const void *a, const void *b ) {
	double at = (*(Edge *)a).weight, bt = (*(Edge *)b).weight;

	if ( at < bt )
		return -1;
	if ( at > bt )
		return 1;
	return 0;
}

int find( int x ) {
	if ( node[ x ] == x )
		return x;
	else
		return node[ x ] = find( node[ x ] );
}

int main( void ) {
	int i, j;
	int n;

	while ( scanf( "%d", &n ), n ) {
		int cnt;
		double sum;

		for ( i = 0; i < n; i++ )
			scanf( "%lf %lf %lf %lf", &coord[ i ].x, &coord[ i ].y, &coord[ i ].z, &coord[ i ].r );

		cnt = 0;
		for ( i = 0; i < n; i++ )
			for ( j = i + 1; j < n; j++ ) {
				edge[ cnt ].from = i;
				edge[ cnt ].to = j;
				edge[ cnt ].weight = fmax( sqrt( ( coord[ i ].x - coord[ j ].x ) * ( coord[ i ].x - coord[ j ].x ) + ( coord[ i ].y - coord[ j ].y ) * ( coord[ i ].y - coord[ j ].y ) + ( coord[ i ].z - coord[ j ].z ) * ( coord[ i ].z - coord[ j ].z ) ) - coord[ i ].r - coord[ j ].r, 0.0 );
				cnt++;
			}
		qsort( edge, cnt, sizeof(Edge), &compare );

		for ( i = 0; i < n; i++ )
			node[ i ] = i;

		sum = 0.0;
		for ( i = 0; n && i < cnt; i++ ) {
			int set1 = find( edge[ i ].from ), set2 = find( edge[ i ].to );

			if ( set1 != set2 ) {
				node[ set2 ] = set1;
				sum += edge[ i ].weight;
				n--;
			}
		}

		printf( "%.3f\n", sum );
	}

	return 0;
}

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

int H, W;

std::vector< std::string > Map;
std::vector< std::vector< long long int > > Route;
const long long int Mod = 1000000000 + 7;

void input() {
    std::cin >> H >> W;
    Map.resize(H);
    for (int i = 0; i < Map.size(); i++)
        std::cin >> Map[i];

    Route = std::vector< std::vector< long long int > >(H, std::vector<long long int >(W, 0));
}

void compute() {
    Route[0][0] = 1;
    for (int r = 1; r < H; r++)
        Route[r][0] = (Map[r][0] == '#')?0:Route[r-1][0];
    for (int c = 1; c < W; c++)
        Route[0][c] = (Map[0][c] == '#')?0:Route[0][c-1];
    for (int r = 1; r < H; r++) {
        for (int c = 1; c < W; c++)
            Route[r][c] = (Map[r][c] == '#')?0:((Route[r-1][c] + Route[r][c-1]) % Mod);
    }
    std::cout << Route[H-1][W-1];
}

int main() {
    input();
    compute();
    return 0;
}


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

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    double g = -1;
    int w = 0, s = 0;
    for(int i = 0; 100 * A * i <= F; ++i) {
        for(int j = 0; 100 * (A * i + B * j) <= F; ++j) {
            for(int k = 0; 100 * (A * i + B * j) + C * k <= F; ++k) {
                for(int l = 0; 100 * (A * i + B * j) + C * k + D * l <= F; ++l) {
                    if(E * (A * i + B * j) < C * k + D * l || i + j == 0) {
                        continue;
                    }
                    double t = (C * k + D * l) / (100.0 * (A * i + B * j) + C * k + D * l);
                    if(t >= g) {
                        g = t;
                        w = 100 * (A * i + B * j);
                        s = C * k + D * l;
                    }
                }
            }
        }
    }
    cout << w + s << ' ' << s << endl;
}


Measured memory_bytes: 256
def solve(X, Y, Z, V, E, A):
    dp = [[0.0] * 6001 for _ in range(Y + max(V) + 1)]
    dp[0][0] = 1.0
    for i in range(Y):
        for j in range(5001):
            if dp[i][j] <= 0.0:
                continue
            for k in V:
                t = i + k
                if t > Y:
                    dp[Y][j] += dp[i][j]/X
                elif E[t] == 1:
                    dp[min(Y, t+A[t])][j] += dp[i][j]/X
                else:
                    dp[t][max(0, j+A[t])] += dp[i][j]/X

    s = 0
    for i in range(5001):
        if dp[Y][i] <= 0.0:
            continue
        s += i * dp[Y][i]
    print(int(s))

if __name__ == "__main__":
    import sys

    while True:
        X, Y, Z = map(int, raw_input().split())
        if X | Y | Z == 0:
            sys.exit()
        V = map(int, raw_input().split())
        E = [0] * 100
        A = [0] * 100
        for _ in range(Z):
            n, e, a = map(int, raw_input().split())
            E[n] = e
            if e == 3:
                A[n] = -a
            else:
                A[n] = a
        solve(X, Y, Z, V, E, A)

Measured memory_bytes: 9596
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, 0, n)cin >> a[i];
	ll sum = 0;
	rep(i, 0, n) {
		sum += a[i] - 1;
	}
	cout << sum;
	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1LL<<61
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge {
	int from,to;
	ll cost;

	edge(int t,ll c) : to(t),cost(c) {}
	edge(int f,int t,ll c) : from(f),to(t),cost(c) {}

	bool operator<(const edge &e) const {
		return cost < e.cost;
	}
};

vector<edge> G[100005];
ll d[100005], d2[100005];

void dijkstra(int s, int n) {
	priority_queue<pair<ll, ll> , vector<pair<ll, ll> >, greater<pair<ll, ll> > > que;
	fill(d, d+n, INF);

	d[s] = 0;
	que.push(P(0,s));

	while(que.size()) {
		P p = que.top();
		que.pop();

		int v = p.second;
		if(d[v] < p.first) continue;

		rep(i, G[v].size()) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

struct BIT {
	vector<int> bit;

	BIT(int n) : bit(n+1) {}

	int sum(int i) {
		int s = 0;
		while(i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}

	void add(int i,int x) {
		while(i <= bit.size()) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

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

	rep(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;

		G[a].push_back(edge(b, c));
		G[b].push_back(edge(a, c));
	}

	dijkstra(n-1, n);
	memset(d2, 0, sizeof(d2));
	rep(i, n) {
		d2[i] = d[i];
	}

	dijkstra(0, n);

	vector<ll> d3(n);
	vector<pair<ll, int> > D, D2;
	rep(i, n) {
		d3[i] = d[i];
		D.push_back(mp(d[i], i));
		D2.push_back(mp(d2[i], i));
	}

	sort(d3.begin(), d3.end());
	sort(D.begin(), D.end());
	sort(D2.begin(), D2.end());

	map<int, int> ma;
	rep(i, n) {
		ma[ D[i].second ] = i;
	}

	int q;
	cin >> q;

	vector<pair<pair<ll, ll> , int> > query(q);

	rep(i, q) {
		ll s, g;
		cin >> s >> g;

		query[i] = mp(mp(g, s), i);
	}

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

	BIT bit(n + 5);
	vector<P> ans;
	int start = 0;
	rep(i, q) {
		ll s = query[i].first.second;
		ll g = query[i].first.first;
		int id = query[i].second;

		for(; start < n; start++) {
			if(g > D2[start].first) {
				int k = ma[ D2[start].second ];
				bit.add(k + 1, 1);
				continue;
			} else break;
		}

		vector<ll>::iterator ite = upper_bound(d3.begin(), d3.end(), s);
		int k = ite - d3.begin() - 1;
		if(k < 0) {
			ans.push_back(mp( id, 0));
		} else {
			int res = k + 1;
			res -= bit.sum(k + 1);
			ans.push_back(mp( id, res));
		}
	}

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

	rep(i, ans.size()) {
		cout << ans[i].second << endl;
	}

	return 0;
}

Measured memory_bytes: 23380
/******************************************************************************
 
рассвет. 
 
*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (int i = a; i < (n); ++i)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
 
const lli MOD=1e9+7;
const lli MAXN=2e6;
const ld PI=acos(-1);

int main(){
    rapgame
    //freopen("brokeday.in", "r", stdin);
    //freopen("richday.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        read(n);
        vlli a(n);
        fr(i,n) cin >> a[i];
        srt(a);
        rev(a);
        lli ans=a[0];
        int ind=1;
        bool used=0;
        fra(i,2,n){
            ans+=a[ind];
            if(used){ ind++; used=0;}
            else used=1;
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 4780
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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


int main(){
    int N,K;
    cin >> N ;
    bool f = false;
    FOR(i,0,26){
        FOR(j,0,16){
            if (N == 4*i + 7*j) f = true;
        }}
    if(f) cout << "Yes" << endl;
    else  cout << "No" << endl;
    
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    int a[N];
    rep(i, N) {
        cin >> a[i];
    }
    int v[201];
    rep(i, 201) {
        v[i] = 0;
    }

    for(int x = -100; x <= 100; x++) {
        rep(i, N) {
            v[x+100] += (a[i] - x)*(a[i] - x);
        }
    }
    
    sort(v, v+201);

    cout << v[0];
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll mod = 1e9+7;
 
int main(){
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  rep(i,n-1) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
 
  vector<vector<ll>> dp(n, vector<ll>(2,0));
  vector<int> visited(n,0);
 
  auto dfs = [&](auto& f, int p, int u, int c)-> ll {
    if (visited[u]) {
      if (c) return dp[u][0];
      return (dp[u][0] + dp[u][1]) % mod;
    }
 
    dp[u][0] = 1; 
    dp[u][1] = 1;
 
    for (auto v : g[u]) {
      if (v == p) continue;
      (dp[u][0] *= f(f, u, v, 0)) %= mod;
      (dp[u][1] *= f(f, u, v, 1)) %= mod;
    }
 
    visited[u] = 1;
    if (c) return dp[u][0];
    return (dp[u][1] + dp[u][0]) % mod; 
  };
  
  cout << dfs(dfs,-1,0,0) << endl;
  return 0;
} 

Measured memory_bytes: 39424
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=2e5+5;
typedef long long ll;
int n,k,h[MAXN];
ll sum;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1; i<=n; i++)
		scanf("%d",h+i);
	sort(h+1,h+n+1);
	for(int i=1; i<=n-k; i++)
		sum+=h[i];
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 896
h, w, n = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=lambda x: (x[1], x[0]))
t = 0
a = [h + 1]
for x, y in l:
    if x > y + t:
        a.append(x)
    elif x == y + t:
        t += 1
print(min(a) - 1)


Measured memory_bytes: 67924
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,h,m=0,c=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>h;
		if(h>=m)
		{
			m=h;
			c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int i=0;
		for(i=1;X > 0; i++){
			X -= i;
		}
		Console.WriteLine(i- 1);
	}
	long X;
	public Sol(){
		X = rl();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

void solve() {
    int n;
    cin >> n;

    const int MAX_VAL = (int) 1e6;
    vector<int> cnt(MAX_VAL + 1, 0);

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }

    vector<int> multiple_cnt(MAX_VAL + 1, 0);

    for (int i = 2; i <= MAX_VAL; i++) {
        for (int j = i; j <= MAX_VAL; j += i) {
            multiple_cnt[i] += cnt[j];
        }
    }

    bool pairwise_coprime = true;

    for (int i = 2; i <= MAX_VAL; i++) {
        if (multiple_cnt[i] > 1) {
            pairwise_coprime = false;
            break;
        }
    }

    if (pairwise_coprime) {
        cout << "pairwise coprime" << endl;
        return;
    }

    int all_gcd = 0;

    for (int i = 1; i <= MAX_VAL; i++) {
        if (cnt[i]) {
            all_gcd = gcd(all_gcd, i);
        }
    }

    if (all_gcd == 1) {
        cout << "setwise coprime" << endl;
        return;
    }

    cout << "not coprime" << endl;
}

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



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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> ans(n+1);
    for(int i = 2; i <= n; ++i){
        cin >> a[i];
        ++ans[a[i]];
    }
    for(int i = 1; i <= n; ++i) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4848
#include <stdio.h>
 
int main(void){
	int a,b,c,i,count = 0;
	scanf("%d%d%d",&a,&b,&c);
	for(i = a;i<=b;i++){
		if(c % i == 0) count++;
	}
	printf("%d\n",count);
}

Measured memory_bytes: 1836
from decimal import *
#exp = Decimal(10**23)
#rint((Decimal(11)*exp)/Decimal(10))

## coding: UTF-8
s = input().split()
t = [int(p) for p in s]
#print(t)

a = t[0]
b = t[1]
x = t[2]

'''
start = a
goal = b
while True:
    if(start % x == 0):
        break
    else:
        start += 1
#print(start)
while True:
    if(goal % x == 0):
        break
    else:
        goal -= 1
#start = Decimal(3)
#goal = Decimal(999999999999999999)

#print(Decimal(goal))
print(Decimal(Decimal(Decimal(goal) - Decimal(start)) / Decimal(x)) + Decimal(1)  ) 
#answer = ((goal - start) / x ) + 1
#print('{}'.format(int(answer)))
'''

def count_even(t, x):
    return int( Decimal(t)/ Decimal(x) )

if( a == 0):
    answer = count_even(b, x) + 1
else:
    answer = count_even(b, x) - count_even(a-1, x)
print(answer)

Measured memory_bytes: 5204
//情報オリンピック2011予選3「最高のピザ」
#include<stdio.h>

int main(void)
{
	int n, a, b, c, *ml, f1, f2, goukei, temp, max;
	
	scanf("%d",&n);
	
	scanf("%d %d",&a, &b);

	ml = new int [n];
		
	scanf("%d",&c);
	
	for(f1 = 0; f1 < n; f1++)
		scanf("%d",&ml[f1]);
	//トッピング降順に並べ替え	
	for(f1 = 0; f1 < n-1; f1++){
		for(f2 = f1+1; f2 < n; f2++){
			if(ml[f1] < ml[f2]){
				temp = ml[f1];
				ml[f1] = ml[f2];
				ml[f2] = temp;
			}
		}
	}
	//トッピングを何も載せない時の1ドル当たりのカロリー数
	max = c / a;

	for(f1 = 1; f1 <= n; f1++){
		goukei = 0;
		//上からf1までのトッピングを抜き出す
		for(f2 = 0; f2 < f1; f2++)
			goukei += ml[f2];
		//1ドル当たりのカロリー数を計算	
		goukei = (goukei + c) / (a + f1 * b);
		
		if(max < goukei)
			max = goukei;
			
	}
	
	printf("%d\n",max);
	return 0;
}

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

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int A, B;
  cin>>A>>B;
  int ans = B;
  if(A <= 12) {
    if(A <= 5) ans = 0;
    else ans /=	2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
int deg[200005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int a;
        scanf("%d",&a);
        deg[a]++;
    }
    for(int i=1;i<=n;i++)
        printf("%d\n",deg[i]);
}


Measured memory_bytes: 4540
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

const double pi = 3.14159265359;

void
solve() {
  int a, b, h, m;
  cin>>a>>b>>h>>m;

  double v = m * 6 * 2 * pi / 360;
  double y1 = sin(v) * a;
  double x1 = cos(v) * a;

  v = (360 / 12. * h + 360 / 720. * m) * 2 * pi / 360;
  double y2 = sin(v) * b;
  double x2 = cos(v) * b;

  double ans = (y1-y2)*(y1-y2) + (x1-x2)*(x1-x2);
  ans = sqrt(ans);
  printf("%.20lf\n", ans);
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 4084
#include <stdio.h>
 
int main () {
  int Top, South, East, tmp, sum;
  int i, j, n;
  char direction[6] = "NEWSRL";

  while (1) {
    Top = 1;
    South = 2;
    East = 3;
    sum = 1;
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      scanf("%s", direction);
             
      switch (direction[0]) {

      case 'N':
	tmp = Top;
	sum += Top = South;
	South = 7 - tmp;
	break;
                 
      case 'E':
	tmp = East;
	East = Top;
	sum += Top = 7 - tmp;
	break;
                     
      case 'W':
	tmp = Top;
	sum += Top = East;
	East = 7 - tmp;
	break;
                     
      case 'S':
	tmp = South;
	South = Top;
	sum += Top = 7 - tmp;
	break;
                     
      case 'R':
	tmp = South;
	South = East;
	East = 7 - tmp;
       	sum += Top;
	break;
                     
      case 'L':
	tmp = East;
	East = South;
	South = 7 - tmp;
	sum += Top;
                     
      default:
	break;
      }
    }
      printf("%d\n", sum);
  }
  return 0;
}

Measured memory_bytes: 600
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15


def main():
    n = getN()
    # n, m = getlist()
    # nums = getlist()
    s = input().strip()
    dic = dict(Counter(s))
    for i in range(n-1):
        s = input().strip()
        cnt = dict(Counter(s))
        for k in dic.keys():
            if k not in cnt:
                dic[k] = 0
        for k,v in cnt.items():
            if k in dic:
                dic[k] = min(dic[k], v)

    # print(sorted(dic.items()))
    ans = ""

    for k,v in sorted(dic.items(), key=lambda x: x[0]):
        # print(k, v)
        for _ in range(v):
            ans += k

    print(ans)

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    if(s[s.length()-1]=='s'){
        s+="e";
    }
    s+="s";
    cout<<s;

    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
long long n,m,ans=1e13;
int main(){
	cin>>n>>m;
	for (long long i=0;i<=2e10;i+=2019)
		if (n<=i&&i<=m){
			cout<<0<<endl;
			return 0;
		}
	n%=2019;m%=2019;
	for (long long i=n;i<=m;i++)
		for (long long j=i+1;j<=m;j++)
			ans=min(ans,(i*j)%2019);
	if (ans==1e13) ans=0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
from collections import defaultdict
sc = defaultdict(set)
for _ in range(M):
    s,c = map(int,input().split())
    sc[s].add(c)


if N == 1:
    if len(sc[1]) > 1:
        print(-1)
    elif len(sc[1]) == 1:
        print(sc[1].pop())
    else:
        print(0)
    exit()

ans = ""
for i in range(1,N+1):
    if len(sc[i]) > 1:
        print(-1)
        exit()

    if i == 1:
        if len(sc[i]) == 1:
            tmp = sc[i].pop()
            if tmp == 0:
                print(-1)
                exit()
            else:
                ans += str(tmp)
        else:
            ans += "1"
    else:
        if len(sc[i]) == 1:
            ans += str(sc[i].pop())
        else:
            ans += "0"

print(ans)

Measured memory_bytes: 3444
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_078_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(20).
    01 X      PIC 9(6).
    01 Y      PIC 9(6).
    01 Z      PIC 9(6).
    01 D      PIC 9(6).
    01 R      PIC 9(6).
    01 ans    PIC X(18).

    01 ZS     PIC Z(6)9.
    01 DUMMY  PIC X(1).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO X Y Z.

*>  A * Y + (A + 1) * Z <= X
*>  A <= (X - Z) / (Y + Z)

    SUBTRACT Z FROM X.
    ADD Y TO Z.
    DIVIDE Z INTO X GIVING D REMAINDER R.

    MOVE D TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 384
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long mod = 998244353;
		long answer = 1;
    long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    if(nums[0] != 0) answer = 0;
    Array.Sort(nums);

    int vertexMemo = 0;
    long lastlastCount = 1;
    long lastCount = 1;
    long countMemo = 0;

    for(int i = 1; i < n; i++)
    {
      if(nums[1] != 1) answer = 0;
    
      if(vertexMemo+1 == nums[i])
      {
        vertexMemo++;
        answer *= DivideMod(lastlastCount, lastCount, mod);
        answer %= mod;
        
        lastlastCount = lastCount;
        lastCount = 1;
        
      }else if(vertexMemo == nums[i])
      {
        lastCount++;
      }else answer = 0;

      //Console.WriteLine(lastlastCount+" "+lastCount+" "+answer);
    }

    answer *= DivideMod(lastlastCount, lastCount, mod);
    answer %= mod;

		Console.WriteLine(answer);
	}

  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x%p;
    
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
        answer %= p;
      }
    memo *= memo;
    memo %= p;
    num *= 2;
    }
    return answer;
  }
  
}

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

const int N = 200005;
int a[N], b[N], aa[N], bb[N], n;

int low_binary(int pos, int value){
	int lo = 0, hi = n - 1, mid, res = -1;
	while(lo <= hi){
		mid = (lo + hi) >> 1;
		if(aa[pos] + bb[mid] >= value){
			res = mid;
			hi = mid - 1;
		}
		else{
			lo = mid + 1;
		}
	}
	return res;
}

int high_binary(int pos, int value){
	int lo = 0, hi = n - 1, mid, res = -1;
	while(lo <= hi){
		mid = (lo + hi) >> 1;
		if(aa[pos] + bb[mid] >= value){
			hi = mid - 1;
		}
		else{
			res = mid;
			lo = mid + 1;
		}
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  	int i, bit;
	int ans = 0;
	cin >> n;
	for(i = 0; i < n; ++i)cin >> a[i];
	for(i = 0; i < n; ++i)cin >> b[i];
	for(bit = 0; bit < 29; ++bit){
		int T = (1 << bit);
		for(i = 0; i < n; ++i){
			aa[i] = a[i] % (2*T);
			bb[i] = b[i] % (2*T);
		}

		sort(bb, bb + n);

		int ct = 0, lower_bound, upper_bound;

		for(i = 0; i < n; ++i){
			lower_bound = low_binary(i, T);
			upper_bound = high_binary(i, 2*T);
			if(lower_bound != -1)
				ct = ct + (upper_bound - lower_bound + 1);
			lower_bound = low_binary(i, 3*T);
			upper_bound = high_binary(i, 4*T);
			if(lower_bound != -1)
				ct = ct + (upper_bound - lower_bound + 1);	
		}


		if(ct & 1)
			ans = ans + T;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	int i,j,n;
	cin>>n;
	int arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];
	int dp[n];
	dp[n-1] = 0;
	int ans = 0;
	for(i=n-2;i>=0;i--)
	{
		if(arr[i]>=arr[i+1])
			dp[i] = dp[i+1]+1;
		else
			dp[i] = 0;
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
 template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  int a[n];
  int b[m];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  sort(a,a+n);sort(b,b+m);
  bool ok=false;
  int ans;
  ans=a[n-1]+1;
  if(x<ans and ans<=y and ans<=b[0])
    ok=true;
  if(ok)
    cout<<"No War"<<endl;
  else
    cout<<"War"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<random>
#include<algorithm>
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
using namespace std;
 
 
int main(){
  int N,R;
  cin >> N >> R;
  if(N>9) cout<< R<< endl;
  else cout<< R + 100*(10-N) <<endl;
 
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.Queue;
import java.text.DecimalFormat;

public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        long a = input.nextLong();
        long b = input.nextLong();
        long  fatiga = 0;

        input.nextLine();
        long pueblos[] = new long[n];
        for (int i = 0; i < n; i++) {
            pueblos[i] = input.nextLong();
        }
        input.nextLine();

        for (int i = 0; i <n-1 ; i++) {
            if((pueblos[i+1]-pueblos[i])*a < b)
                fatiga += (pueblos[i+1]-pueblos[i])*a;
            else
                fatiga += b;

        }
        System.out.println(fatiga);

        }
}

Measured memory_bytes: 62824
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

int main()
{
  string S;
  cin >> S;
  int length = SZ(S);
  int first = 0;

  ll sum = 0;
  int cnt=0;

  for(int i=0;i<length;i++){
    if(S[i]=='W'){
      sum+=i-cnt;
      // cout << i-cnt << endl;
      cnt++;
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 640