akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
typedef long long LL;
const int maxn = 505;
const LL mod = 1e9 + 7;

char a[maxn][maxn], b[maxn][maxn], c[maxn][maxn];

int up = maxn, down, lef = maxn, righ, n, m;

bool check(int x, int y) {
	if(up <= x && x <= down && lef <= y && y <= righ) return 0;
	return 1;
}

int main() {
	cin>>n>>m;
	rep(i, 1, n)
	    rep(j, 1, m) {
	    	cin>>a[i][j];
	    	if(a[i][j] == '#') b[i][j] = c[i][j] = '#';
	    	else b[i][j] = c[i][j] = '.';
	    }
	rep(i, 1, n) b[i][1] = '#', c[i][m] = '#';
	rep(i, 1, n) {
		if(i&1)
			rep(j, 2, m - 1) b[i][j] = '#';
		else 
			rep(j, 2, m - 1) c[i][j] = '#';
	}
	rep(i, 1, n) {
		rep(j, 1, m)
		    cout<<b[i][j];
		cout<<endl;
	}
	cout<<endl;
	rep(i, 1, n) {
		rep(j, 1, m)
		    cout<<c[i][j];
		cout<<endl;
	}
}

Measured memory_bytes: 4384
from bisect import bisect_left, bisect_right

def count(x, li1, li2, p):
    cnt = 0
    now = len(li2)-1 if p else 0
    for ind, i in enumerate(li1):
        rng = range(now, -1, -1) if p else range(now, len(li2))
        for j in rng:
            if p and ind==j:
                continue
            if i*li2[j]<x:
                # print(cnt, ind, j)
                cnt += j+1 if p else len(li2)-j
                cnt -= 1 if p and ind<j else 0
                now = j
                break
        else:
            break
    return cnt//2 if p else cnt

def bisect(ok, ng, solve):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if solve(mid):
            ok = mid
        else:
            ng = mid
    return ok

def p_solve(x):
    tmp = count(x, posi, posi, True)
    tmp += count(x, nega[::-1], nega[::-1], True)
    # print(x, tmp)
    return np*nn+nn*nz+nz*np+nz*(nz-1)//2+tmp < k

def n_solve(x):
    return count(x, nega, posi, False) < k


n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
nega = a[:bisect_left(a, 0)]
posi = a[bisect_right(a, 0):]
np = len(posi)
nn = len(nega)
nz = n - np - nn
if k <= np*nn:
    ans = bisect(-10**18-1, 0, n_solve)
elif k <= np*nn+nn*nz+nz*np+nz*(nz-1)//2:
    ans = 0
else:
    ma = 0
    if len(nega)>1:
        ma = nega[-1]*nega[-2]
    if len(posi)>1 and ma<posi[-1]*posi[-2]:
        ma = posi[-1]*posi[-2]
    ans = bisect(1, 10**18+1, p_solve)
print(ans)


Measured memory_bytes: 140072
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef double dd;
typedef pair <int, int> pii;
#define pb push_back
#define pf push_front
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
//#define mp make_pair
const int mx = 1000 * 100 + 5;
map < char , char > mp;
map < char , int > val;
int j[mx];
int32_t main(){		
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	int n, k, r, s, p;
	string t;
	cin >> n >> k >> r >> s >> p >> t;
	int ans = 0;
	mp['r'] = 'p';
	mp['p'] = 's';
	mp['s'] = 'r';
	val['r'] = r;
	val['p'] = p;
	val['s'] = s;
	for(int i = 0; i < k; i++){
		ans += val[mp[t[i]]];
		j[i] = mp[t[i]];
	}
	for(int i = k; i < n; i++){
		if(mp[t[i]] != j[i - k]){
			j[i] = mp[t[i]];
			ans += val[mp[t[i]]];
		}
		else{
			j[i] = 'e';
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main(){
    int L, R, d;
    cin >> L >> R >> d;

    int a = L/d, b = R/d, ans = b - a;

    if(L%d == 0) ans++;
    cout << ans << endl;
}


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

using Lint=long long;
using P=pair<int,int>;

int main()
{
   int N; cin>>N;
   vector<int> x(N),l(N);
   for(int i=0;i<N;i++) cin>>x[i]>>l[i];

   vector<P> p(N);
   for(int i=0;i<N;i++){
      p[i]=make_pair(x[i]+l[i],x[i]-l[i]);
   }
   sort(p.begin(),p.end());

   int ans=1,cur=p[0].first;
   for(int i=1;i<N;i++){
      if(cur<=p[i].second){
         ans++; cur=p[i].first;
      }
   }
   cout<<ans<<endl;
   return 0;
}



Measured memory_bytes: 1792
//सत्यान्न प्रमदितव्यम्  ||

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
// #define mp make_pair
#define nt _int128
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define inf 0x3f3f3f3f

const ll mod = 1000000007;
#define mx 1000005
const ll mxi = 4e4+5;
// ll ar[mx][mx] = {0};

ll sol(ll x)
{
	while(x/10 > 0)
	{
		x /= 10;
	}
	return x;
}

int main()
{
    fast_as_levi;
    ll i,j,n;
    cin>>n;
    ll ar[10][10];
    memset(ar,0,sizeof(ar));
    for(i=1;i<=n;i++)
    {
        ll z = sol(i);
        ll y = i%10;
        ar[z][y]++;
    }
    ll ans = 0;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
        {
            ans+= ar[i][j] * ar[j][i];
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int x;
  cin >> x;
  int n = 1;
  while(1){
    if((n*(n+1))/2 >= x){
      break;
    }
    n++;
  }

  cout << n << endl;
  
  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void)
{
	int mhp;
	int sat;
	char str[12];
	int num;
	
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d %d", &mhp, &sat);
	
	for(num = 0;mhp > 0; num++)
	{
		mhp -= sat;
		//printf("%d %d\n", mhp, sat);
	}
	
	printf("%d\n", num);
	
	return (0);
}

Measured memory_bytes: 128
s=[]
lis=[]
N,M=map(int, input().split())
wacount=0
account=0
count=0
zero=0
flag=1
cur=0
changeflag=1
#s=[list(input()) for i in range(2)] 
#for range(M):
#print(N,M)
 
for i in range(M):
     lis=input().split()
     #print(lis)
     lis[0]=int(lis[0])
     lis.append(i)
     #print(lis)
     s.append(lis)
 
s2=sorted(s,key=lambda x:x[0])
sorted(s2,key=lambda x:x[2])
j=1
for i in range(len(s2)):
    if s2[i][0]>j:
        j=s2[i][0]
        flag=1
        count=0
    if (s2[i][0]==j)and(flag==1):
        if s2[i][1]=="WA":
            count=count+1
        elif s2[i][1]=="AC":
            account=account+1
            wacount=wacount+count
            flag=0
            count=0
                
print(account,wacount)

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

LL func(LL x, LL y, LL z) {
    return (x + y + z)*(x + y + z) - x*y - y*z - x*z;
}

int main() {
    LL N;
    cin >> N;
    vector<LL> f(N + 1, 0);
    FOR(i, 1, N + 1) {
        for(LL x = 1;x*x < i;x++) {
            for(LL y = 1;x*x + y*y < i;y++) {
                LL l = 1;
                LL r = i;
                for(;1 < r - l;) {
                    LL mid = (l + r)/2;
                    if(func(x, y, mid) <= i) {
                        l = mid;
                    }else{
                        r = mid;
                    }
                }
                if(func(x, y, l) == i) {
                    f[i]++;
                }
            }
        }
    }
    FOR(i, 1, N + 1) {
        cout << f[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3460
s=input()
p=input()
sl = [i for i in s]
pl = [i for i in p]
lenp=len(p)
pp=pl[-1]
el=[i for i,x in enumerate(sl) if x==pp]
check=0
for i in el:
    pcheck=-1
    while True:
        if sl[i]==pl[pcheck]:
            i-=1
            pcheck-=1
        else:
            break
        if pcheck+lenp<=0:
            check+=1
            break
    if check==1:
        break
if check==0:
    print("No")
else:
    print("Yes")



Measured memory_bytes: 5568
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 100000000

using namespace std;

int main() {
   string s;
   cin >> s;
   int n = s.size();
   cout << s[0] << n-2 << s[n-1] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Map<Integer, List<Path>> map;
    static int n;
    static long[] memo;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        map = new HashMap<>();
        memo = new long[n+1];
        for (int i = 0; i < n - 1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            List<Path> tmp = map.get(a);
            if(tmp != null) {
                tmp.add(new Path(b, c));
            }
            else {
                List<Path> tmp1 = new ArrayList<>();
                tmp1.add(new Path(b, c));
                map.put(a, tmp1);
            }
            tmp = map.get(b);
            if(tmp != null) {
                tmp.add(new Path(a, c));
            }
            else {
                List<Path> tmp1 = new ArrayList<>();
                tmp1.add(new Path(a, c));
                map.put(b, tmp1);
            }
        }
        int Q = sc.nextInt();
        int k = sc.nextInt();
        Deque<Integer> q = new ArrayDeque<>();
        q.add(k);
        while (!q.isEmpty()) {
            int c = q.poll();
            for(Path next : map.get(c)){
                if(memo[next.a] != 0) {
                    continue;
                }
                memo[next.a] = memo[c] + next.b;
                q.add(next.a);
            }
        }
        for (int i = 0; i < Q; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(memo[a] + memo[b]);
        }
    }

    static class Path{
        int a;
        long b;

        public Path(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Path path = (Path) o;
            return a == path.a &&
                    b == path.b;
        }

        @Override
        public int hashCode() {
            return Objects.hash(a, b);
        }
    }
}


Measured memory_bytes: 184736
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>

#define size 100005

int main()
{
    int i, n, x, arr[size], least=0, sum, ans, min;
    scanf("%d%d", &n, &x);

    min = 1001;
    for(i=1; i<=n; i++)
    {
        scanf("%d", &arr[i]);
        least = least + arr[i];
        if(arr[i]<min)
            min = arr[i];
    }
    sum = x - least;
    ans = n + sum/min;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1728
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout << (1000-n%1000)%1000 << endl;
}

Measured memory_bytes: 3648
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
ans = 0
l = [a,b,c,d,e]
ld = [(a+9)%10,(b+9)%10,(c+9)%10,(d+9)%10,(e+9)%10]
i = ld.index(min(ld))
last = l[i]
l.remove(l[i])
for j in l:
  ans += ((j+9)//10)*10
print(ans+last)

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

int sum_digit(int n)
{
  int sum_n;

  while (n != 0)
  {
    sum_n += n % 10;
    n /= 10;
  }
  return (sum_n);
}

int main()
{
  int N;
  string s = "No";

  cin >> N;
  if (N % sum_digit(N) == 0)
    s = "Yes";
  cout << s << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;
struct Edge {
  int to;
  Edge(int _to) : to(_to) {
  }
};
using Graph = vector<vector<Edge>>;

int cycle_node = -1;

vb seen;     // 探索済みフラグ
vb finished; // これ以上何を見ても絶対にサイクルがないノード

vi history;

void dfs(const Graph& g, int idx) {
  if (finished[idx]) {
    return;
  }

  history.push_back(idx);

  if (seen[idx]) {
    cycle_node = idx;
    return;
  }

  seen[idx] = true;

  for (const auto& e : g[idx]) {
    if (finished[e.to])
      continue;

    dfs(g, e.to);

    if (cycle_node != -1)
      return;
  }

  finished[idx] = true;
  history.pop_back();
}

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

  ll n, m;
  cin >> n >> m;

  seen.assign(n, false);
  finished.assign(n, false);
  Graph g(n);

  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].emplace_back(b);
  }

  rep(i, n) {
    dfs(g, i);
    if (cycle_node != -1) {
      break;
    }
  }

  if (cycle_node == -1) {
    cout << -1 << endl;
    return 0;
  }

  // historyの始めにあるサイクルと無関係なデータを削除
  vi cycle;
  cycle.push_back(cycle_node);
  for (auto it = history.rbegin() + 1; it != history.rend(); it++) {
    if (*it == cycle[0]) {
      break;
    }
    cycle.push_back(*it);
  }
  reverse(all(cycle));

  // 検出した閉路に弦が存在するかを確認
find_smaller_cycle:

  ll cn = cycle.size();
  rep(i, cn) {
    for (auto e : g[cycle[i]]) {
      if (e.to == cycle[(i + 1) % cn]) {
        continue;
      }
      auto gen = find(all(cycle), e.to);
      if (gen == cycle.end()) {
        continue;
      }

      vi smaller_cycle;
      smaller_cycle.push_back(cycle[i]);

      vi cc = cycle;
      cc.insert(cc.end(), cycle.begin(), cycle.end());
      auto it = find(all(cc), e.to);

      while (*it != smaller_cycle[0]) {
        smaller_cycle.push_back(*it);
        it++;
      }

      cycle = smaller_cycle;
      goto find_smaller_cycle;
    }
  }

  cout << cycle.size() << endl;
  for (auto it : cycle) {
    cout << it + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 384
def counting_sort(a,b,k):
  c = [0 for _ in range(k+1)]
  for i in range(len(a)):
    c[a[i]] += 1
  for i in range(1, len(c)):
    c[i] += c[i-1]
  for i in range(len(a) - 1, -1, -1):
    b[c[a[i]]- 1] = a[i]
    c[a[i]] -= 1

n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(len(a))]
counting_sort(a, b, max(a))
print(*b)



Measured memory_bytes: 224392
#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define MAX 100

int calc(char,int,int);
int ctoi(char*);

int main() {
  char s[MAX];
  int array[MAX] , pos = 0 , a , b , res;

  memset(array,-1,sizeof(array));

  while ( scanf("%s" ,s) != EOF ) {
    if (!isdigit(s[0])) {
      a = array[pos-2]; array[pos-2] = -1;
      b = array[pos-1]; array[pos-1] = -1;
      pos -= 2;

      res = calc(s[0],a,b);
      array[pos++] = res;
    } else {
      array[pos++] = ctoi(s);
    }
  }
  printf("%d\n" ,array[0]);

  return 0;
}

int calc (char op , int a , int b){
  int res;

  switch (op) {
  case '+':
    res = a + b;
    break;
  case '-':
    res = a - b;
    break;
  case '*':
    res = a * b;
    break;
  }

  return res;
}

int ctoi(char str[]){
  int res = 0 , i , power = 1;

  for(i = strlen(str)-1 ; i >= 0 ; i--){
    res += (str[i]-'0')*power;
    power *= 10;
  }

  return res;
}

Measured memory_bytes: 548
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
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;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int H,W,c;

void solve() {
    cin>>W>>H;
    priority_queue<pair<int,int>> que;
    REP1(i,W) {
        cin>>c;
        que.push({-c,i});
    }
    REP1(i,H) {
        cin>>c;
        que.push({-c,-i});
    }
    int ans = 0;
    int C[2] = {};
    while(que.size()) {
        auto [c, i] = que.top();
        que.pop();
        c = -c;
        if (i<0) {
            ans += (W+1-C[0])*c;
            C[1]++;
        } else {
            ans += (H+1-C[1])*c;
            C[0]++;
        }
    }
    _PN(ans);
}



Measured memory_bytes: 7388
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
 int n,coun=0,temp=0;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++)
   cin>>a[i];

 for(int i=1;i<n-1;i++)
 {
     if(max(a[i],a[i-1])==min(a[i],a[i+1])||min(a[i],a[i-1])==max(a[i],a[i+1]))
         coun++;
 }
 cout<<coun<<endl;


    return 0;}

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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

int dp[1 << 12][1005];
signed main() {
    int N, M;
    cin >> N >> M;

    vi a(M), b(M);
    vi c[M];
    REP(i, M) {
        cin >> a[i] >> b[i];
        REP(j, b[i]) {
            int tmp; cin >> tmp;
            c[i].pb(--tmp);
        }
    }

    int big = 1LL << 30;
    REP(i, 1 << 12) {
        REP(j, 1005) {
            dp[i][j] = big;
        }
    }
    dp[0][0] = 0;

    REP(i, M) {
        int x = 0;
        REP(j, c[i].size()) {
            x |= (1 << c[i][j]);
        }
        REP(j, 1 << N) {
            dp[j][i + 1] = min(dp[j][i], dp[j][i + 1]);
            dp[j | x][i + 1] = min(dp[j][i] + a[i], dp[j | x][i + 1]);
        }
    }

    int ans = dp[(1 << N) - 1][M];
    if (ans == big) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 32640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<"LBWNB    "<<x<<"---\n"
#define pb push_back
#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mp make_pair
#define p() puts("")
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
using namespace std;
typedef long long ll;
typedef double db;
const int mod=998244353;
//const int mod=1e9+7;
const int inf=1e9+7;
const int maxn=5e5+10;
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}

int t,n,m,k;
int main(){
    scanf("%d",&n);
    ll s=0;
    rep(i,1,n){
        if(i%3&&i%5) s+=i;
    }
    printf("%lld\n",s);
    return 0;
}




//const int M=1<<20;
//ll t1[M*2+5],t2[M*2+5],ans,ca[M],cb[M];
//inline void upd(int i){t1[i]=t1[i<<1]+t1[i<<1|1];t2[i]=max(t2[i<<1],t1[i<<1]+t2[i<<1|1]);}
//inline void add(int i,int v){for(t1[i+=M]+=v;i>>=1;upd(i));}
//int n,m,p,x,y,i,j;
//struct mons{int x,y,z;}a[M];
//int main(){
//	for(i=0;i<M;++i)ca[i]=cb[i]=1ll<<60;ans=-(1ll<<60);
//	scanf("%d%d%d",&n,&m,&p);
//	for(i=1;i<=n;++i)scanf("%d%d",&x,&y),ca[x]=min(ca[x],(ll)y);
//	for(i=1;i<=m;++i)scanf("%d%d",&x,&y),cb[x]=min(cb[x],(ll)y);
//	for(i=0;i<M;++i)t2[i+M]=-cb[i];for(i=M-1;i;--i)upd(i);
//	for(i=1;i<=p;++i)scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
//	sort(a+1,a+p+1,[&](const mons&a,const mons&b){return a.x<b.x;});
//	for(i=0,j=1;i<M;++i){
//		for(;j<=p && a[j].x<i;++j)add(a[j].y,a[j].z);
//		ans=max(ans,t2[1]-ca[i]);
//	}
//	printf("%lld\n",ans);
//	return 0;
//}


Measured memory_bytes: 3812
// Shinchan Loves Coding :)))
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<stack>

using namespace std;

#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define double long double
#define en "\n"
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define toUpper(x) transform(x.begin(), x.end(), x.begin(),::toupper);
#define toLower(x) transform(x.begin(), x.end(), x.begin(),::tolower);
#define rep(i,x,y) for(int i=x ; i<y ; i++)
#define erep(i,x,y) for(int i=x ; i<=y ; i++)
#define erepr(i,x,y) for(int i=x ; i>=y ; i--)
#define repr(i,x,y) for(int i=x ; i>y ; i--)
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> pii;
bool secdes(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi>b.fi;}else{return a.se>b.se;}}//second descending !
bool sir(const pair<int,int>&a , const pair<int,int>&b){if(a.fi==b.fi){return a.se>b.se;}else{return a.first>b.first;}}//first descending !
bool bysec(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi<b.fi;} else{return a.se<b.se;}}//second ascending !

//--------------------------------------------------------------------------------------------------------------------------------------------------------------

const int no=3e6+5;
const int modulo=1e9+7;
const int inf=1e18;
const int N=2001;
int ar[no],br[no],mat[N][N];
int dx[]={-1 , 0 , 1 , 0};
int dy[]={0 , 1 , 0 , -1};
char dc[]={'L', 'D' , 'R' ,'U'};

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
int mul(int x , int y , int mod) {
	return ((x%mod)*(y%mod))%mod;
}

int powwmod(int x, int y , int mod) { int res=1; while (y) { if (y & 1){ y--; res=mul(res,x,mod); res%=mod; } else { y/=2; x=mul(x,x,mod); x%=mod; } } return res%mod; }

int poww(int x , int y) { int res=1; while(y) { if(y%2) { y--; res=res*x; } else { y/=2; x=x*x; } } return res; }

int div(int x , int y , int mod) {
	return x*poww(y,mod-2)%mod ;
}

bool comp(int x, int y) {
	return (x < y);   // MINIMUM
	return (x > y);   // MAXIMUM
}

int gcd(int x, int y) { if(y==0) return x; else return gcd(y,x%y); }

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

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
vi adj[no];
int used[no];

void solve (){
	int n,m,a,b,x,y;
	cin>>n>>m>>a>>b;
	x=max(m*a,m*b);
	cout<<max(n*a,max(n*b,x));
}

inline void runn(){
	#ifndef ONLINE JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

signed main()
{
	night_rider
	//runn();
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 73964
data = [[[0 for r in range(10)] for  f in range(3)] for b in range(4)]

n = int(input())
for nc in range(n):
  (b, f, r, v) = [int(i) for i in input().split()]
  data[b - 1][f - 1][r - 1] +=  v


for b in range(4):
  for f in range(3):
    for r in range(10):
      print(' {0}'.format(data[b][f][r]), end='')
    print()
  print('#' * 20) if b < 4 - 1 else print(end='')

Measured memory_bytes: 6724
#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;
ll dp[110][2][4];
int main(){ 
  string s;
  cin >> s;
  int K;
  cin >> K;
  int n = sz(s);
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    int d = s[i] - '0';
    for (int f = 0; f < 2; f++) {
      for (int c = 0; c <= (f ? 9 : d); c++) {
        if (c == 0) {
          dp[i+1][f | (c < d)][0] += dp[i][f][0];
          dp[i+1][f | (c < d)][1] += dp[i][f][1];
          dp[i+1][f | (c < d)][2] += dp[i][f][2];
          dp[i+1][f | (c < d)][3] += dp[i][f][3];
        } else {
          dp[i+1][f | (c < d)][1] += dp[i][f][0];
          dp[i+1][f | (c < d)][2] += dp[i][f][1];
          dp[i+1][f | (c < d)][3] += dp[i][f][2];
        }
     }
   }
  }
  cout << dp[n][0][K] + dp[n][1][K] << endl;
  return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include <string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main(void){
int i,A1,A2,A3;
scanf("%d",&A1);
scanf("%d",&A2);
scanf("%d",&A3);
if(A1+A2+A3>=22){
	printf("bust");
}
else {

printf("win");
}
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;

#define MOD 1000000007

int b;
int w;

class Combination {
public:
	long long int ppow(long long int i, long long int j) {
		long long int res = 1LL;
		while (j) {
			if ((j & 1LL)) {
				res *= i;
				if (res >= MOD) {
					res %= MOD;
				}
			}
			j >>= 1;
			i *= i;
			if (i >= MOD) {
				i %= MOD;
			}
		}
		return res;
	}
public:
	vector<long long int> k;
	vector<long long int> r;
	void resize(int N) {
		k.resize(N + 2);
		r.resize(N + 2);
		k[0] = 1;
		for (int i = 1; i < N + 2; i++) {
			k[i] = k[i - 1];
			k[i] *= i;
			if (k[i] >= MOD)k[i] %= MOD;
		}
		long long int al = k[k.size() - 1];
		long long int iv = ppow(k[k.size() - 1], MOD - 2);
		r[k.size() - 1] = iv;
		for (int i = (int)(r.size()) - 2; i >= 0; i--) {
			r[i] = r[i + 1] * (i + 1);
			if (r[i] >= MOD) {
				r[i] %= MOD;
			}
		}
	}
	long long int C(int a, int b) {
		if (a < b)return 0;
		long long int up = k[a];
		long long int dw = r[b] * r[a - b];
		dw %= MOD;
		up *= dw;
		up %= MOD;
		return up;
	}
	long long int H(int a, int b) {
		return C(a + b - 1, b);
	}
	long long int catalan_number(int n) {
		return (C(2 * n, n) + MOD - C(2 * n, n - 1)) % MOD;
	}
};

Combination C;


//Lucas theorem とか
int main() {
	C.resize(400005);
	cin >> b >> w;
	long long int way = 0;
	long long int bla = 0;
	long long int ALL = 1LL;
	for (int i = 1; i <= b + w; i++) {
		way *= 2LL;
		bla *= 2LL;
		long long int luc = ALL + way;
		long long int mooow = way + bla + ALL*2LL;
		mooow %= MOD;
		luc %= MOD;
		luc *= C.ppow(mooow, MOD - 2);
		luc %= MOD;
		printf("%lld\n", luc);
		ALL *= 2LL;
		ALL %= MOD;
		if (w <= i) {  //we end up with eating w at this moment
			int black = i - w;
			int white = w-1;
			long long int f = C.C(black + white, black);
			ALL += MOD - f;
			ALL %= MOD;
			way+=f;
			way %= MOD;
		}
		if (b <= i) {
			int black =b-1;
			int white = i - b;
			long long int f = C.C(black + white, black);
			ALL += MOD - f;
			ALL %= MOD;
			bla += f;
			bla %= MOD;
		}
	}
	return 0;
}

Measured memory_bytes: 8448
N = int(input())
S = input()

w = S.count('.')
b = S.count('#')

if w == 0 or b == 0:
    print(0)
    exit()

nw = w
nb = 0
ans = nw
for i in range(N):
    if S[i] == '.':
        nw -= 1
    else:
        nb += 1
    ans = min(ans, nb + nw)

print(ans)


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

typedef long long ll;

int main() {
  string S; cin >>S;
  reverse(S.begin(),S.end());
  string moji[4]={"dream","dreamer","erase","eraser"};
  rep(i,0,4) reverse(moji[i].begin(),moji[i].end());
  int cur_pos=0;
  while (cur_pos<(int)S.size()) {
    bool flag=false;
    rep(i,0,4) {
      int find_index=S.find(moji[i],cur_pos);
      if (find_index==cur_pos) {
        cur_pos=find_index+moji[i].size();
        flag=true;
        break;
      }
    }
    if (!flag) {
      cout <<"NO" <<endl;
      return 0;
    }
  }
  cout <<"YES" <<endl;
  return 0;
}


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

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<int, int>> X_with_idx;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        X_with_idx.emplace_back(tmp, i);
    }
    sort(X_with_idx.begin(), X_with_idx.end());
    vector<int> org_idx_to_sorted(N, 0);
    for (int i = 0; i < N; i++) {
        int org_i = X_with_idx.at(i).second;
        org_idx_to_sorted.at(org_i) = i;
    }
    int left_mid = X_with_idx.at(N / 2 - 1).first;
    int right_mid = X_with_idx.at(N / 2).first;
    for (int i = 0; i < N; i++) {
        int sorted_pos = org_idx_to_sorted.at(i);
        int mid = (sorted_pos >= N / 2) ? left_mid : right_mid;
        cout << mid << "\n";
    }
}


Measured memory_bytes: 4592
from sys import stdin

N = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(2)]

profit = [0] * N
sum_profit = 0

for i in range(N):
    profit[i] = int(data[0][i]) - int(data[1][i])
    if profit[i] > 0:
        sum_profit += profit[i]

print(sum_profit)

Measured memory_bytes: 3064
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(){
		
		bool sleep = false;
		long tot = 0;
		for(int i=0;i<N;i++){
			if(Ss[i] == T){
				sleep = true;
				continue;
			}
			if(sleep){
				tot += Ts[i];
			}
		}
		
		Console.WriteLine(tot);
		
		
		
		
	}
	int N;
	String[] Ss;
	long[] Ts;
	String T;
	public Sol(){
		N = ri();
		Ss = new String[N];
		Ts = new long[N];
		for(int i=0;i<N;i++){
			var ss = rsa();
			Ss[i] = ss[0];
			Ts[i] = long.Parse(ss[1]);
		}
		T = rs();
	}

	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: 13140
#include <iostream>
using namespace std;

int main(){
	int n, x;
	cin >> n >> x;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	long long ans = 0;
	{
		int diff = max(0, a[0] + a[1] - x);
		ans += diff;
		if(diff > a[1]){
			a[0] -= diff - a[1];
			a[1] = 0;
		}else a[1] -= diff;
	}
	for(int i = 1; i < n; i++){
		ans += max(0, a[i - 1] + a[i] - x);
		a[i] -= max(0, a[i - 1] + a[i] - x);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string s;
    cin >> s;
    set<char> kind;
    for (auto elem : s) {
        kind.insert(elem);
    }
    if (kind.size() != 2) {
        cout << "No" << endl;
        return 0;
    } else {
        for(set<char>::iterator it = kind.begin(); it!=kind.end(); ++it) {
            if (count(ALL(s), *it) != 2) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N, A, B = map(int, input().split())
mx = min(A, B)
mn = max(A + B - N, 0)
print(mx, mn)
 


Measured memory_bytes: 7880
def partition(a,p,r):
    x = a[r]
    i = p
    for j in range(p,r):
        if x>=a[j]:
            a[i],a[j] = a[j],a[i]
            i+=1
    a[r],a[i] = a[i],a[r]
    return i

n = int(input())
a = list(map(int,input().split()))

m = partition(a,0,n-1)
print(' '.join(map(str,a[0:m]))+' ['+str(a[m])+'] ' +' '.join(map(str,a[m+1:])))


Measured memory_bytes: 16388
n,m=map(int,input().split())
dic={}
doll=0
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
for k,v in AB:
  if v<m:
    doll+=k*v
    m-=v
  else:
    doll+=k*m
    print(doll)
    exit()

Measured memory_bytes: 27364
#include <iostream>
	#include <vector>
	#include <cmath>
	#include <map>
	#include <string>
	#include <algorithm>
	#include <climits>
	#include <set>
	#include <queue>
	#include <unordered_set>
	using namespace std;

	#define ll long long

	class Solver
	{
	private:
		ll n;
		vector<ll> a;
	public:
		Solver(){
			cin >> n;
			for (ll i = 0; i < n; ++i)
			{
				ll tmp;
				cin >> tmp;
				a.push_back(tmp);
			}
		}
		void exec(){
			ll ans = 0;
			bool up = true;
			if(a.size() == 1){
				cout << 1 << endl;
				return;
			}
			bool first_flag = true;
			for (ll i = 1; i < n; ++i)
			{
				if(first_flag){
					if(a[i] == a[i-1]) continue;
					if(a[i] > a[i-1]){
						first_flag = false;
						up = true;
					}else{
						first_flag = false;
						up = false;
					}
				}else{
					if(a[i] == a[i-1]) continue;
					if(a[i] > a[i-1]){
						if(up == false){
							ans++;
							first_flag = true;
							// i++;
						}
						up = true;
					}else{
						if(up == true){
							ans++;
							first_flag = true;
							// i++;
						}
						up = false;
					}
				}
			}
			cout << ans + 1<< endl;
		}
	};

	int main(){
		Solver solution = Solver();
		solution.exec();
	}


Measured memory_bytes: 1400
#include <stdio.h>

int main()
{
	int N;
	int num[1000];
	int i;
	int approvedFlag = 0;

	scanf("%d\n", &N);

	for (i = 0; i < N; i++) {
		scanf("%d", &num[i]);
	}

	for (i = 0; i < N; i++) {
		if (num[i] & 1) {
			continue;
		}
		else {
			if ((num[i] % 3 == 0) || (num[i] % 5 == 0)) {
				continue;
			}
			else {
				approvedFlag = 1;
			}
		}
	}

	if (approvedFlag) {
		printf("DENIED\n");
	}
	else {
		printf("APPROVED\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct state{
  int a,b,o;
  state(int a=0, int b=0, int o=0):a(a),b(b),o(o){}
};

int r,c,n;
state s[50000];

void solve(){
  int numr = 0, numc = 0, ans = 0;
  bool f[2][50000];
  vector<state> v;
  fill(f[0],f[2],false);
  for(int i=n-1;i>=0;i--){
    if(!f[s[i].a][s[i].b]){
      f[s[i].a][s[i].b] = true;
      v.push_back(s[i]);
    }
  }
  reverse(v.begin(),v.end());

  fill(f[0],f[2],false);
  //cout << endl;
  for(int i=0;i<v.size();i++){
    //    cout << numr << ' ' << numc << endl;
    if(v[i].a == 0){
      if(v[i].o == 1){
        if(!f[v[i].a][v[i].b]){
          f[v[i].a][v[i].b] = true;
          numr++;
        }
        ans += max(0, c - numc);
      } else {
        if(f[v[i].a][v[i].b]){
          f[v[i].a][v[i].b] = false;
          numr = max(0, numr-1);
        }
        ans = max(0, ans-numc);
      }
    } else {
      if(v[i].o == 1){
        if(!f[v[i].a][v[i].b]){
          f[v[i].a][v[i].b] = true;
          numc++;
        }
        ans += max(0, r - numr);
      } else {
        if(f[v[i].a][v[i].b]){
          f[v[i].a][v[i].b] = false;
          numc = max(0, numc-1);
        }
        ans = max(0, ans-numr);
      }
    }
  }
  cout << ans << endl;
}

int main(){
  while(cin >> r >> c >> n && (r|c|n)){
    for(int i=0;i<n;i++)
      cin >> s[i].a >> s[i].b >> s[i].o;
    solve();
  }
}

Measured memory_bytes: 3052
N, A, B, C = map(int, input().split())  # 複数数値入力
L = [0] * N
for i in range(N):
    L[i] = int(input())


def dfs(depth, a, b, c):    # 深さは何本目の竹まで場合分けしたかを示す  a,b,cにはA,B,Cに割り当てられている竹の長さの和が入っている　戻り値はMP
    if depth == N:
        # ABCのどれかが1本も割り当てられていない場合はだめなのでINFを返す
        return abs(a-A)+abs(b-B)+abs(c-C) - 30 if min(a, b, c) > 0 else 1000000000

    ret0 = dfs(depth + 1, a, b, c)  # depth本目の竹を使わない
    # depth本目の竹をAを作るのに使用する    コストを足して、長さには使用する竹の長さを足してやる
    ret1 = dfs(depth + 1, a + L[depth], b, c) + 10
    ret2 = dfs(depth + 1, a, b + L[depth], c) + 10  # depth本目の竹をBを作るのに使用する
    ret3 = dfs(depth + 1, a, b, c + L[depth]) + 10  # depth本目の竹をCを作るのに使用する

    return min(ret0, ret1, ret2, ret3)  # 一番小さいMPを返す


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
using namespace std;
const int tINF = (int)INT_MAX;
const long long lINF = (long long)LLONG_MAX;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef DEBUG
			assert(freopen("inp", "r", stdin));
			assert(freopen("out", "w",stdout));
	#else
			#define cerr if(false)cerr
	#endif
    int n;
    cin >> n;
    int sum = 0;
    vector <int> ar(n);
    for(auto &i : ar){
        cin >> i;
        sum += i;
    }
    sum = round(sum / (double)n);
    ll ans = 0;
    for(auto i : ar){
        ll num = sum - i;
        ans += num * num;
    }
    cout << ans << '\n';
   cerr << "Time execute: " << (double)clock() / (double)CLOCKS_PER_SEC 
    << " sec" << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

struct Cost {
  ull cost;
  int cnt;
};
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<Cost> A(N);
  rep(i, N) cin >> A[i].cost >> A[i].cnt;
  std::sort(A.begin(), A.end(), [](auto& l, auto& r){return l.cost<r.cost;});

  int cnt {};
  ull money {};
  rep(i, N) {
    if (cnt + A[i].cnt > M) {
      money += A[i].cost*(M-cnt);
      break;
    } else {
      cnt += A[i].cnt;
      money += A[i].cnt*A[i].cost;
    }
  }
  cout << money << '\n';
}


Measured memory_bytes: 1792
l, r = [ int(v) for v in input().split() ]

if l % 2019 == 0:
    ans = 0
elif r % 2019 == 0:
    ans = 0
elif l // 2019 == r // 2019:
    ans = 10**6
    l, r = l % 2019, r % 2019
    for i in range(l,r):
        for j in range(i+1,r+1):
            ans = min( ans, (i*j) % 2019 )


elif l // 2019 != r // 2019:
    ans = 0
print(ans)

Measured memory_bytes: 40812
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    int W = Integer.parseInt(sc.next());
    int H = Integer.parseInt(sc.next());
    int x = Integer.parseInt(sc.next());
    int y = Integer.parseInt(sc.next());
    
    double s = (double)W * (double)H / 2;
    int a = (W == x*2 && H == y*2) ? 1 : 0;
    System.out.println(s+" "+a);
  }
}

Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=200010;
int L[N],R[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,m=1e5;
    long long ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) ++L[gi()+m],++R[gi()+m];
    for(int i=1;i<=m+m;i++) R[i]+=R[i-1];
    for(int i=m+m;~i;i--) L[i]+=L[i+1];
    for(int i=1;i<=m;i++) ans+=min(R[i-1],L[i]+1);
    for(int i=m+1;i<=m+m;i++) ans+=min(R[i-1]+1,L[i]);
    cout<<ans*2;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
const int sz = 1e5 + 10;
ll n, a, b;
ll h[sz];
ll ans;
void solve()
{
    ll sa = a - b;
    ll mi = 0, ma = 1e9, mid;
    while (ma - mi > 1)
    {
        mid = (mi + ma) / 2;
        ll cnt = 0;
        rep(i, n)
        {
            if (h[i] > b * mid)
            {
                cnt += (h[i] - b * mid - 1) / sa + 1;
            }
        }
        if (cnt > mid)
            mi = mid;
        else
            ma = mid;
    }
    ans = ma;
    return;
}
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> n >> a >> b;
    rep(i, n) cin >> h[i];
    solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 20:41:16 2020

@author: Kanaru Sato
"""

n = int(input())
a = list(map(int, input().split()))
d = {}

for i in range(n-1):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1

for i in range(n):
    if i+1 in d:
        print(d[i+1])
    else:
        print(0)

Measured memory_bytes: 33528
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n, m;
    cin >> n >> m;
    vector<int> dp(n + 1, INF);
    dp[0] = 0;
    for(int i = 0; i < m; ++i){
        int c;
        cin >> c;
        for(int j = 0; j <= n - c; ++j){
            if(dp[j] == -1) continue;
            chmin(dp[j + c], dp[j] + 1);
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    vector<int>v(n);int c = 0;
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=1;i<n-1;i++){
        if(v[i] >= v[i-1] && v[i]<=v[i+1]){
            c++;
        }
        else if(v[i] <= v[i-1] && v[i]>=v[i+1]){
            c++;
        }
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    int h,m,s;
    for(int j=0;j<3;j++){
        cin>>h>>m>>s;
        long sum=0;
        sum-=h*60*60+m*60+s;
        cin>>h>>m>>s;
        sum+=h*60*60+m*60+s;
        int oh=0,om=0,os=0;
        if(sum>=3600){
            oh=sum/3600;
            sum=sum%3600;
        }
        if(sum>=60){
            om=sum/60;
            sum=sum%60;
        }
        os=sum;
        cout<<oh<<" "<<om<<" "<<os<<endl;
    }
    return 0;
}

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

const int INF=1e9;

int main(){
  int n,m,R;
  cin>>n>>m>>R;
  vector<int> r(R);
  rep(i,R){
    cin>>r[i];
    r[i]--;
  }
  
  vector<vector<int>>  d(n,vector<int>(n,INF));
  rep(i,n) d[i][i]=0;
  
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--; b--;
    d[a][b]=min(c,d[a][b]);
    d[b][a]=min(c,d[b][a]);
  }
  
  rep(k,n)rep(i,n)rep(j,n){
    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  }
  
  int ans=INF;
  sort(r.begin(),r.end());
  do{
    int res=0;
    rep(i,R-1){
      res+=d[r[i]][r[i+1]];
    }
    ans=min(ans,res);
  }while(next_permutation(r.begin(),r.end()));
  cout<<ans<<endl;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;

int main() {
    ll num;
    scanll(num);
    int tmp;
    ll counter = 1;
    vector<char> name;
    while (num != 0) {
        num -= 1; 
        tmp = num % 26;
        num = (num-tmp) / 26;
        name.push_back("abcdefghijklmnopqrstuvwxyz"[tmp]);
        counter++;
    }   
    for (int i = name.size(); i > 0; i--) {
        printf("%c", name[i - 1]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3700