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

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

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N),C(N);
  REP(i,N)cin >> A[i];
  REP(i,N)cin >> B[i];
  REP(i,N)cin >> C[i];

  sort(ALL(A));
  sort(ALL(B));
  sort(ALL(C));

  ll ans=0;
  for(auto &v: B){
    ans += (lower_bound(ALL(A),v) - A.begin()) *(C.end() - upper_bound(ALL(C),v)); 
  }

  cout << ans << endl;
}



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

#define N 100005

int n, K, h[N], f[N];

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n >> K;
    for (int i = 1; i <= n; ++i)
        scanf("%d", h + i);
    f[1] = 0;
    for (int i = 2; i <= n; ++i) {
        f[i] = 0x3f3f3f3f;
        for (int j = max(1, i - K); j < i; ++j)
            f[i] = min(f[i], f[j] + abs(h[i] - h[j]));
    }
    cout << f[n] << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define lli long long int
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define deb3(x, y, z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define fastio 	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
	fastio;

    int n;
    cin >> n;

    vector<lli> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    lli ans = 0;
    lli x = a[0];

    for (int i = 0; i < n; i++) {
        x = max(x, a[i]);
        ans += x - a[i];
        // deb2(x, x - a[i]);
    }

    cout << ans << endl;

	return 0;
}




Measured memory_bytes: 4756
#include<stdio.h>
#include<stdlib.h>
#define ll long long
int cmp(const void *a,const void *b){return *(long long*)a-*(long long*)b;}
int main(){
  int n,k,i;
  scanf("%d%d",&n,&k);
  ll h[n],ans=0;
  for(i=0;i<n;i++)
    scanf("%lld",&h[i]);
  qsort(h,n,sizeof(long long),cmp);
  for(i=0;i<n-k;i++)
    ans+=h[i];
  printf("%lld\n",ans);
  return 0;}


Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long N,K;
  long N1, N2;
  cin >> N >> K;
  N1=abs(N%K);
  N2=abs(K-N1);
  if(N<K)
  {
    N1=N;
    N2=abs(N-K);
  }
  cout << min(N1,N2)<<endl;
}


Measured memory_bytes: 256
#if 0

#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int W, H;
int x[4] = {1,0,-1,0};
int y[4] = {0,-1,0,1};

bool in_map(int h, int w) {
  return (1 <= h && h <= H && 1 <= w && w <= W);
}

char M[25][25];
int cnt;
void dfs(int h, int w) {
  cnt += 1;
  M[h][w] = '#';
  for (int i = 0; i < 4; i++) {
    int nh = h+y[i]; int nw = w+x[i];
    if (in_map(nh, nw) && M[nh][nw] != '#') {
      dfs(nh, nw);
    }
  }
}

int main() {
  int sh,sw;
  while(cin >> W >> H && W > 0) {
    cnt = 0;
    for (int h = 1; h <= H; h++) {
      for (int w = 1; w <= W; w++) {
        cin >> M[h][w];
        if (M[h][w] == '@') {
          sh = h; sw = w;
        }
      }
    }
    dfs(sh, sw);
    cout << cnt << endl;
  }
}



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

int do_win(char a, char b, int point)
{
    if ((a == 'r' && b == 's') || (a == 's' && b == 'p') || (a == 'p' && b == 'r'))
    {
        return point;
    }
    return 0;
}

int main()
{
    int n, k, R, S, P, ans = 0;
    string t;
    cin >> n >> k >> R >> S >> P >> t;
    vector<int> point = {R, S, P};
    vector<char> my = {'r', 's', 'p'};
    for (int lane = 0; lane < k; lane++)
    {
        // cout << "r s p\n";
        int size = (n - lane - 1) / k + 1;
        vector<vector<int>> dp(size, vector<int>(3, 0));
        for (int gen = 0; gen < size; gen++)
        {
            for (int j = 0; j < 3; j++)
            { //0:r 1:s 2:p
                if (gen == 0)
                {
                    dp[gen][j] += do_win(my[j], t[lane + gen * k], point[j]);
                    continue;
                }
                dp[gen][j] += do_win(my[j], t[lane + gen * k], point[j]) + max(dp[gen - 1][(j + 1) % 3], dp[gen - 1][(j + 2) % 3]);
            }
            // cout << dp[gen][0] << ' ' << dp[gen][1] << ' ' << dp[gen][2] << endl;
        }
        ans += max({dp[size - 1][0], dp[size - 1][1], dp[size - 1][2]});
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
N = int(input())
ans = 0
for i in range(1, N+1):
    ans += i*(N-i+1)

for _ in range(N-1):
    u, v = map(int, input().split())
    l, r = min(u, v), max(u, v)
    dec = l*(N-r+1)
    ans -= dec

print(ans)

Measured memory_bytes: 74376
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10

struct Info{
    Info(ll arg_to,ll arg_cost){
        to = arg_to;
        cost = arg_cost;
    }
    bool operator<(const struct Info &arg) const{
            return cost > arg.cost;
    };
    ll to,cost;
};

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

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



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll v,e,r;
    cin>>v>>e>>r;
    
    ll mincost[v];
    rep(i,v) mincost[i]=INF;
    mincost[r]=0;
    
    vector<Info> edges[v];
    
    rep(i,e){
        ll s,t,d;
        cin>>s>>t>>d;
        edges[s].pb(Info(t,d));
    }
    
    priority_queue<Info> q;
    
    rep(i,edges[r].size()){
        if(mincost[edges[r][i].to]>edges[r][i].cost){
            mincost[edges[r][i].to]=edges[r][i].cost;
            q.push(Info(edges[r][i].to,edges[r][i].cost));
        }
    }
    ll minindex = 0;
    while(!q.empty()){
        if(q.top().cost>mincost[q.top().to]) q.pop();
        else{
            minindex=q.top().to;
            q.pop();
        }
        rep(i,edges[minindex].size()){
            if(mincost[edges[minindex][i].to]>mincost[minindex] + edges[minindex][i].cost){
                mincost[edges[minindex][i].to]=mincost[minindex] + edges[minindex][i].cost;
                q.push(Info(edges[minindex][i].to,mincost[edges[minindex][i].to]));
            }
        }
    }
    rep(i,v){
        if(mincost[i]==INF) cout<<"INF"<<endl;
        else cout<<mincost[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 19372
#include<stdio.h>

int main()
{
  int a,b,c,k;
  scanf("%d %d %d %d",&a,&b,&c,&k);
  int d=a+b;
  int e=k-d;
  if (k <= a) printf("%d",k);
  else if (d >= k) printf("%d",a);
  else printf("%d",a-e);
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  int ans;
  for (int i = 1; i < 10; i++) {
    if (i * 111 >= a){
      cout << i * 111 << endl;
      return 0;
    }
  }
}

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


int main() {
	vector<int> a(3);
  	cin>>a.at(0)>>a.at(1)>>a.at(2);
  
  	sort(a.begin(),a.end());
  	cout<<a.at(0)+a.at(1)<<endl;
}



Measured memory_bytes: 256
# /user/bin/python
# -*- coding: utf-8 -*-
import sys


def solve(sn,h,w):
  for i in range(1,h+1):
    for j in range(1,w+1):
      if sn[i][j] > 0:
        if sn[i-1][j] + sn[i+1][j] + sn[i][j-1] + sn[i][j+1] == 0:
          return False
  return True



H,W = map(int, input().split())
Sn = []
Sn.append([0]*(W+2))
for _ in range(H):
  s_in = str(input())
  lst = [0] * (W+2)
  for i in range(len(s_in)):
    if s_in[i] == '#':
      lst[i+1] = 1
  Sn.append(lst)
Sn.append([0]*(W+2))

if solve(Sn,H,W):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
from functools import singledispatch
import math

EPS = 1e-10

COUNTER_CLOCKWISE = 1
CLOCKWISE = -1
ONLINE_BACK = 2
ONLINE_FRONT = -2
ON_SEGMENT = 0

class Segment():
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2

class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, point):
        # + 演算子での挙動を指定
        return Point(self.x+point.x, self.y+point.y)

    def __sub__(self, point):
        # - 演算子での挙動を指定
        return Point(self.x-point.x, self.y-point.y)

    def __mul__(self, a):
        # * 演算子での挙動を指定
        return Point(a*self.x, a*self.y)

    def __truediv__(self, a):
        # / 演算子での挙動を指定
        return Point(self.x/a, self.y/a)

    def __abs__(self):
        # abs関数での挙動を指定
        return math.sqrt(self.norm())

    def norm(self):
        return self.x**2+self.y**2

    def __eq__(self, point):
        # == 演算子での挙動を指定
        return abs(self.x-point.x) < EPS and abs(self.y-point.y) <EPS

def dot(a, b):
    return a.x*b.x+a.y*b.y

def cross(a, b):
    return a.x*b.y - a.y*b.x

def isOrthogonal(a, b):
    return dot(a, b) == 0

def isParallel(a, b):
    return cross(a, b) == 0

def project(s, p):
    #s: Segment(), p: Point()
    base = s.p2 - s.p1
    r = dot(p-s.p1, base)/base.norm()
    return s.p1+base*r

def reflect(s, p):
    return p+(project(s, p)-p)*2

@singledispatch
def get_distance(a, b):
    return abs(a-b)

def get_distance_lp(l, p):
    return abs(cross(l.p2-l.p1, p-l.p1)/abs(l.p2-l.p1))

def get_distance_sp(s, p):
    if dot(s.p2-s.p1, p-s.p1) < 0:
        return abs(p-s.p1)
    if dot(s.p1-s.p2, p-s.p2) < 0:
        return abs(p-s.p2)
    return get_distance_lp(s, p)
    
@get_distance.register(Segment)
def _(s1, s2):
    if intersect(s1, s2):
        return 0
    return min([get_distance_sp(s1, s2.p1), get_distance_sp(s1, s2.p2),
                get_distance_sp(s2, s1.p1), get_distance_sp(s2, s1.p2)])

def ccw(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    if cross(a, b) > EPS:
        return COUNTER_CLOCKWISE
    if cross(a, b) < -EPS:
        return CLOCKWISE
    if dot(a, b) < -EPS:
        return ONLINE_BACK
    if a.norm() < b.norm():
        return ONLINE_FRONT
    return ON_SEGMENT

@singledispatch
def intersect(p1, p2, p3, p4):
    return (ccw(p1, p2, p3)*ccw(p1, p2, p4) <= 0
            and ccw(p3, p4, p1)*ccw(p3, p4, p2) <= 0)

@intersect.register(Segment)
def _(s1, s2):
    return intersect(s1.p1, s1.p2, s2.p1, s2.p2)

def get_cross_point(s1, s2):
    base = s2.p2 - s2.p1
    d1 = abs(cross(base, s1.p1-s2.p1))
    d2 = abs(cross(base, s1.p2-s2.p1))
    t = d1/(d1+d2)
    return s1.p1 + (s1.p2-s1.p1)*t

if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    q = int(input())
    for _ in range(q):
        x0, y0, x1, y1, x2, y2, x3, y3 = map(int, input().split())
        p0 = Point(x0, y0)
        p1 = Point(x1, y1)
        p2 = Point(x2, y2)
        p3 = Point(x3, y3)
        s1 = Segment(p0, p1)
        s2 = Segment(p2, p3)
        p = get_cross_point(s1, s2)
        print(p.x, p.y)


Measured memory_bytes: 6456
#include <stdio.h>
#define LENGTH 4

int main(){
    int i,j;
    char S[4];
    int cnt = 0;
    scanf("%s",S);
    for(i=0;i<LENGTH - 1;i++){
        for(j=i+1;j<LENGTH;j++){
            if(S[i]==S[j]) cnt++;
        }
    }
    if(cnt == 2){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

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


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

    odd = (N + 1) / 2;

    double ans = (double)odd / N;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)

r = Array.new(N, 0)
r[N - 1] = A[-1]
(N - 2).downto(1){|i|
  r[i] = A[i].gcd(r[i + 1])
}
ans = Array.new(N, 0)
ans[0] = r[1]
wk = A[0]
1.upto(N - 2){|i|
  ans[i] = wk.gcd(r[i+1])
  wk = wk.gcd(A[i])
}
ans[N - 1] = wk

puts ans.max


Measured memory_bytes: 11276
a, b, c = map(int, input().split())
x = max(a,b,c)
# a=b=cにするために足さないといけない数y
y = (x-a) + (x-b) + (x-c)

if y&1:
    # yが奇数なら+3して偶数にする
    y += 3
ans = y//2
print(ans)

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

const ll INF = 1001001001001001001;

int main() {
    int v, e;
    cin >> v >> e;
    vector<vector<ll>> dist(v, vector<ll>(v, INF));
    for (int i = 0; i < v; ++i) {
        for (int j = 0; j < v; ++j) {
            if (i == j) dist[i][j] = 0;
        }
    }
    for (int i = 0; i < e; ++i) {
        ll s, t, d;
        cin >> s >> t >> d;
        dist[s][t] = min(dist[s][t], d);
    }
    for (int k = 0; k < v; k++) {
        for (int i = 0; i < v; i++) {
            for (int j = 0; j < v; j++) {
                if (dist[i][k] == INF or dist[k][j] == INF) continue;
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    for (int i = 0; i < v; ++i) {
        if (dist[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    for (int i = 0; i < v; ++i) {
        for (int j = 0; j < v; ++j) {
            if (dist[i][j] >= INF) {
                if (j == 0) cout << "INF";
                else cout << " " << "INF";
            } else {
                if (j == 0) cout << dist[i][j];
                else cout << " " << dist[i][j];
            }
        }
        cout << endl;
    }
}



Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int g[3][110];
int main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<=2;i++){
        for(int j=1;j<=n;j++){
            scanf("%d",&g[i][j]);
            g[i][j]+=max(g[i-1][j],g[i][j-1]);
        }
    }
    cout<<g[2][n]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  
  int num[10] = {0,2,5,5,4,5,6,3,7,6};
  vector < pair<int, int> > candidate;
  int N, M; cin >> N >> M;
  for (int i = 0; i < M; i++){
    int A; cin >> A;
    candidate.push_back(make_pair(A, num[A]));
  }
  sort(candidate.begin(), candidate.end(), greater< pair<int, int> >());
  
  map <int, int> DP;
  for (int i = 0; i < candidate.size(); i++){
    DP[candidate[i].second] = 1;
  }
  
  for (int i = 2; i < N + 1; i++){
    if (DP[i] > 0){
      for (int j = 0; j < candidate.size(); j++){
        int num = candidate[j].second;
        DP[i + num] = max(DP[i + num], DP[i] + 1);
      }
    }
  }
  
  int dig = DP[N], sum = N;
  while (dig > 0){    
    for (int i = 0; i < candidate.size(); i++){
      int now = candidate[i].second;
      if (DP[sum - now] + 1 == DP[sum] && DP[sum] > 1){
        cout << candidate[i].first;
        sum -= now;
        break;
      }else if(DP[sum] == 1 && sum == now){
        cout << candidate[i].first;
        sum -= now;
        break;
      }
    }
    dig--;
  }
  cout << endl;

  return 0;
}


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

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

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

int main() {
    COMinit();

    int jp,kt;
    cin>>jp>>kt;
    for (int i=1;i<kt+1;i++) {
      cout<<COM(kt-1,i-1)*COM(jp-kt+1,i) % 1000000007<<endl;
    }
}

Measured memory_bytes: 12160
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var ret = new List<int>();
        var ad = true;
        for (int i = 0; i < n; i++)
        {
            if (ad) { ret.Add(a[i]); ad = false; }
            else { ret.Insert(0, a[i]); ad = true; }
        }
        if (!ad) { ret.Reverse(); }
        Console.WriteLine(string.Join(" ", ret));
    }
}


Measured memory_bytes: 51128
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    sc.close();
    
    int result = 0;
    
     for(int i = 0; i < D; i++){
       if (A > 0){
         result += 1;
         A -= 1;
       } else if ( B > 0){
         B -= 1;
       } else {
         result -= 1;
         C -= 1;
       }
     }
    System.out.println(result);
  } 
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
#include <math.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,ans=0;
    cin >> n;
    vector<int> v(n);
    rep(i,n){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if(!(v.at(i) == v.at(j) || v.at(j) == v.at(k) || v.at(k) == v.at(i))){
                    int len = v.at(i)+v.at(j)+v.at(k);
                    int rest = len - v.at(k);
                    if(v.at(k) < rest){
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include"bits/stdc++.h"

using namespace std;

typedef long long ll;

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){

    ll n,m;

    cin>>n>>m;

    set<ll>s;

    while(m--){

        ll k;

        cin>>k;

        while(k--){

            ll t;

            cin>>t;

            s.insert(t);

        }

    }

    cout<<n-s.size()<<endl;

}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
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(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

int dp[11][11];

signed main() {

	string s;
	cin >> s;
	reverse(all(s));

	mclr(dp);
	function<int(int, int)> solve = [&](int i, int j) {
		if (i == s.size())return 0ll;
		if (dp[i][j] != -1)return dp[i][j];
		int t = (s[i] - '0');
		rep(_, j) {
			t *= 10;
		}
		return dp[i][j] = t * mypow(2, s.size() - i - 1) + solve(i + 1, j + 1) + solve(i + 1, 0);
	};
	cout << solve(0, 0) << endl;

	return 0;
}

Measured memory_bytes: 256
from itertools import product

N, K = map(int, input().split())
D = list(map(int, input().split()))
L = []
for i in range(10):
	if not i in D:
		L.append(i)
keta = len(str(N))
flg = 0

# 与えられた桁と同じ桁数で終わるとき
for num in product(L, repeat = keta):
	num = list(num)
	num.reverse()
	# print(num)
	val = 0
	for i in range(keta):
		val += num[i] * (10 ** i)
	if val >= N:
		flg = 1
		break
		
if flg:
	print(val)
# 与えられた桁で終わらないとき
else:
	for l in L:
		if l != 0:
			a = l
			break
	val = a * (10 ** (keta))
	for i in range(keta):
		val += min(L) * (10 ** i)
	print(val)

Measured memory_bytes: 39664
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 1
if K == N:
    for a in A:
        ans *= a
        ans %= MOD
    print(ans)
    exit()

P = []
M = []
zero = 0
for a in A:
    if a >= 0:
        P.append(a)
    elif a < 0:
        M.append(a)


ans = 1
if len(P) == 0 and K % 2 == 1:
    M.sort(reverse=True)
    for k in range(K):
        ans *= M[k]
        ans %= MOD
    print(ans)
    exit()

P.sort(reverse=True)
M.sort()
S = 1
LP = len(P)
LM = len(M)
cur_p = 0
cur_m = 0
cnt = 0
ans = 1
while cnt < K:
    if K - cnt == 1 or LM - cur_m <= 1:
        flag = 'p'
    elif LP - cur_p == 1:
        if (K - cnt) % 2 == 1:
            flag = 'p'
        else:
            flag = 'm'
    elif LP - cur_p == 0:
        flag = 'm'
    else:
        p1 = P[cur_p]
        p2 = P[cur_p + 1]
        m1 = M[cur_m]
        m2 = M[cur_m + 1]
        if p1 * p2 >= m1 * m2:
            flag = 'p'
        else:
            flag = 'm'
    
    if flag == 'p':
        ans *= P[cur_p]
        ans %= MOD
        cur_p += 1
        cnt += 1
    else:
        ans *= M[cur_m] * M[cur_m + 1]
        ans %= MOD
        cur_m += 2
        cnt += 2

print(ans)


Measured memory_bytes: 104672
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [n, _x] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const [, ...m] = stdin.split('\n').map(Number)

const ans = () => {
  const ms = m.sort((a, b) => a - b)

  let x = _x

  let count = 0

  for (let i = 0; i < n; i++) {
    x -= ms[i]

    if (x >= 0) {
      count++
    } else {
      return count
    }
  }

  return count + Math.floor(x / ms[0])
}

console.log(ans())


Measured memory_bytes: 7500
n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
    m=input()
    if m=='AC': ac+=1
    elif m=='WA': wa+=1
    elif m=='TLE': tle+=1
    elif m=='RE': re+=1
print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))

Measured memory_bytes: 69876
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void solve(){
  int n = 100, m = 100;
  		int x, y;
  		cin >> x >> y;
  		char a[n][m];
  		x--, y--;
  		rep(i,0, n) {
  				rep(j, 0,m){
  					if(i < n / 2) a[i][j] = '.';
  					else a[i][j] = '#';
  				}
  		}
  		swap(x, y);
  		rep(i,0, n){
  			rep(j,0, m){
  				if((i + j) % 2 == 0 && i % 2 == 0){
  						if(x) x--, a[i][j] = '#';
  				}
  				if((i + j) % 2 == 0 && i % 2 == 0 && y && i >= n / 2 + 2) a[i][j] = '.', y--;
  			}
  		}
  		cout << "100 100\n";
  		rep(i, 0,100) {rep(j, 0,100) cout << a[i][j]; cout << "\n"; }
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int MAXN = 1000001;
string extractStringAtKey(string str, int key){
    char *s = strtok((char *)str.c_str(), " ");
    while(key > 1){
        s = strtok(NULL, " ");
        key--;
    }
    return (string)s;
}
int32_t main(){
    SPEED;
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    int odd = 0, even = 0;
    for(int i = 0; i < 3; ++i){
        if(a[i] & 1) odd++;
        else even++;
    }
    if(odd == 3 || even == 3){
        sort(a, a + 3);
        if(a[0] == a[1] && a[1] == a[2]){
            cout << 0;
            return 0;
        }
        if(odd == 3){
            cout << (a[2] - a[0])/2 + (a[2] - a[1])/2;
        }
        else cout << (a[2] - a[0])/2 + (a[2] - a[1])/2;
    }
    else{
        if(odd > even){
            int ans = 1;
            for(int i = 0; i < 3; ++i){
                if(a[i] & 1) a[i]++;
            }
            if(a[0] == a[1] && a[1] == a[2]){
                cout << 1;
                return 0;
            }
            sort(a, a + 3);
            cout << ans + (a[2] - a[0])/2 + (a[2] - a[1])/2;
        }
        else{
            int ans = 1;
            for(int i = 0; i < 3; ++i){
                if(a[i] % 2 == 0) a[i]++;
            }
            sort(a, a + 3);
            if(a[0] == a[1] && a[1] == a[2]){
                cout << 1;
                return 0;
            }
            cout << ans + (a[2] - a[0])/2 + (a[2] - a[1])/2;
        }
    }
}

Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

ll fast_pow(ll x, ll n) {
  ll res = 1;
  while(n > 0) {
    if (n & 1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

ll ComputeCharLength(ll turn_count){
  int upper_digit = 0;

  ll tmp = turn_count;
  while(tmp > 0){
    tmp /= 10LL;
    upper_digit++;
  }

  ll res = 0;
  for(int digit=1;digit <= upper_digit; digit++){
    ll remaining_nums = 0;
    ll current_max = 0;
    if(digit == upper_digit){
      current_max = turn_count;
      //ex... 132 - 100 + 1
      remaining_nums = turn_count - fast_pow(10,digit-1)+1;
    }
    else{
      //ex... 100 - 1 -> 99
      current_max = fast_pow(10,digit) - 1;

      //ex... ((100-1) - 10) + 1
      remaining_nums = (fast_pow(10,digit)-1) - fast_pow(10,digit-1)+1;
    }
    
    //ex... 133/3 - (100 - 1)/3
    ll fizz_count = current_max / 3 - (fast_pow(10,digit-1)-1) / 3;

    //ex... 133/5 - (100 - 1)/5
    ll buzz_count = current_max / 5 - (fast_pow(10,digit-1)-1) / 5; 

    //ex... 133/15 - (100 - 1)/15
    ll fizzbuzz_count = current_max / 15 - (fast_pow(10,digit-1)-1) / 15;

    ll current_total = (fizz_count+buzz_count-2*fizzbuzz_count)*4
      + fizzbuzz_count*8
      + (remaining_nums - (fizz_count+buzz_count-fizzbuzz_count)) * digit;
    res += current_total;
  }

  return res;
}

int main(){
  ll num;
  while(~scanf("%ld",&num)){

    ll lhs = 0;
    ll rhs = fast_pow(10,18);

    for(int i=0;i<100;i++){
      ll mid = (lhs + rhs)/2LL;
      if(ComputeCharLength(mid) < num){
	lhs = mid;
      }
      else if(ComputeCharLength(mid) >= num){
	rhs = mid;
      }
    }

    string res = "";
    for(ll turn=rhs;turn<=lhs+20;turn++){
      if(turn % 15 == 0){
	res += "FizzBuzz";
      }
      else if(turn % 5 == 0){
	res += "Buzz";
      }
      else if(turn % 3 == 0){
	res += "Fizz";
      }
      else{
	char buf[32];
	sprintf(buf,"%ld",turn);
	res += buf;
      }
    }
    
    printf("%s\n",res.substr(num-ComputeCharLength(lhs)-1,20).c_str());
  }
}

Measured memory_bytes: 1240
#include<iostream>
#include<vector>
#include<set>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using P = pair<int,int>;

int main(){
    int h,w,n;
    cin >> h >> w >> n;
    vector<int> hs(h), ws(w);
    set<P> s;
    rep(i,n){
        int r,c;
        cin >> r >> c;
        r--;c--;
        hs[r]++;
        ws[c]++;
        s.emplace(r,c);
    }

    int mh = 0,mw = 0;
    rep(i,h)mh = max(mh,hs[i]);
    rep(j,w)mw = max(mw,ws[j]);
    vector<int> is,js;
    rep(i,h)if(mh == hs[i])is.push_back(i);
    rep(j,w) if(mw == ws[j])js.push_back(j);
    int ans = mh + mw;

    for(int i :is){
        for(int j :js){
            if(s.count(P(i,j)))continue;
            cout << ans << endl;
            return 0;
        }
    }
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl 	"\n"

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;

#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define present(c,x) 	((c).find(x) != (c).end())
#define rep(i,n)        for(ll i=0LL; i<(n); i++)

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

//Maths functions
ll Digit(ll N){ll res=0;while(N) res++, N/=10;return res;}
ll Gcd(ll a,ll b){ return b?Gcd(b,a%b):abs(a); }


int main()
{	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	
	string s;
	cin>>s;
	set<char> sp;
	for(ll i=0; i<3; i++)
		sp.insert(s.at(i));
	if(sp.size()==1)
		cout<<"No";
	else cout<<"Yes";
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  long long mod = 1000000007;
  
  vector<long long> a(N+1);
  vector<long long> b(N+1);
  vector<long long> c(N+1);
  
  a.at(1) = 8;
  b.at(1) = 2;
  
  for(int i = 1; i < N; i++){
    a.at(i+1) = (a.at(i) * 8) % mod;
    b.at(i+1) = (a.at(i) * 2 + b.at(i) * 9) % mod;
    c.at(i+1) = (b.at(i) * 1 + c.at(i) * 10) % mod;
  }
  
  cout << c.at(N) << endl;
}


Measured memory_bytes: 26592
n,m=map(int,input().split())
a = [[int(x) for x in input().split()] for _ in range(n)]
b = [int(input()) for _ in range(m)]
for i in range(n):
  s = 0
  for j in range(m):
    s += a[i][j] * b[j]
  print(s)


Measured memory_bytes: 6016
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>
#include <bitset>
 
using namespace std;
typedef long long ll;

template <int N>
struct UnionFind {
    int ig[N];
    vector<int> gi[N];
    int gn;
    /// UnionFind???????????°n??§???????????????
    void init(int n = N) {
        for (int i = 0; i < n; ++i) {
            ig[i] = i;
            gi[i] = {i};
        }
        gn = n;
    }

    /// ??????a??¨??????b????????????
    void merge(int a, int b) {
        if (same(a, b)) return;
        gn--;
        int x = ig[a], y = ig[b];
        if (gi[x].size() < gi[y].size()) swap(x, y);
        for (int j: gi[y]) {
            ig[j] = x;
        }
        gi[x].insert(gi[x].end(), gi[y].begin(), gi[y].end());
        gi[y].clear();
    }
    /// ??????a??¨??????b???????????°????????????????±?????????????????????????
    bool same(int a, int b) {
        return ig[a] == ig[b];
    }
    /// ??°??????????????°
    int group_num() {
        return gn;
    }
};

const int MN = 550;
UnionFind<MN> uf;

bool solve() {
    int n, m;
    if (scanf("%d %d", &n, &m) != 2) return false;
    uf.init(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b); a--; b--;
        uf.merge(a, b);
    }
    printf("%d\n", m-n+uf.group_num());
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}

Measured memory_bytes: 1240
#include<stdio.h>

int main()
{
	while (1)
	{
		int n, x;
		scanf("%d %d", &n, &x);
		if (n == 0 && x == 0) break;
		int i, j, k, total, ways=0;
		for (i = 1; i <= n - 2; i++)
		{
			for (j = i + 1; j <= n - 1; j++)
			{
				for (k = j + 1; k <= n; k++)
				{
					total = i + j + k;
					if (total == x) ways += 1;
				}
			}
		}
		printf("%d\n", ways);
	}
	return 0;
}

Measured memory_bytes: 1028
Taka, Aoki, K = map(int, input().split())
dif = Taka - K
if dif >= 0:
    Taka -= K
else:
    dif = abs(dif)
    Taka = 0
    dif = Aoki - dif
    if dif >= 0:
        Aoki = dif
    else:
        Aoki = 0
print(Taka, Aoki)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
#define MOD1 1000000007
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    char s;
}frequent;
// 小大
int compare(const void *a, const void *b){return *(ll *)a - *(ll *)b;}

int main(void){
    ll n,m,i,j;
    scanf("%lld%lld",&n,&m);
    char s[n][52],t[m][52];
    for(i=0;i<n;i++){
        scanf("%s",s[i]);
    }
    for(i=0;i<m;i++){
        scanf("%s",t[i]);
    }
    for(i=0;i<n-m+1;i++){
        for(j=0;j<n-m+1;j++){
            ll p,q;
            if(s[j][i]==t[0][0]){
                for(p=0;p<m;p++){
                    for(q=0;q<m;q++){
                        if(s[j+p][i+q]!=t[p][q]) break;
                    }
                    if(q!=m) break;
                }
                if(p==m){
                    printf("Yes\n");
                    return 0;
                }
            }
        }
    }
    printf("No\n");
    return 0;
}


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

int main(){
  ll h,w; cin>>h>>w;
  ll s = h*w;
  if(h==1 || w==1) cout<<1;
  else if(s%2==0) cout<<s/2;
  else cout<<s/2 + 1;
}

Measured memory_bytes: 256
S = input()
d1 = int(S[:2])
d2 = int(S[2:])

m = lambda d:d>0 and d<13

if m(d1):
    if m(d2):
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if m(d2):
        print("YYMM")
    else:
        print("NA")



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

using namespace std;

int main(){
	string a;
	int ans=0;
	cin>>a;
	for(int i=0;i<a.length();++i){
		if(a[i]=='C' && ans==0){
			ans++;
		}
		if(a[i]=='F' && ans==1){
			ans++;
		}
	}
	if(ans==2)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int q,n,alpha_n,x;
  q=b-a;
  n=q-1;
  alpha_n=n*(n+1)/2;
  x=alpha_n-a;
  printf("%d\n",x);
  
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  private final Scanner sc = new Scanner(System.in);

  public void run() {
    int n = sc.nextInt();

    int[][] list = new int[n][];

    for (int i = 0; i < n; i++) {
      int u = sc.nextInt() - 1;
      int k = sc.nextInt();

      list[u] = new int[k];

      for (int j = 0; j < k; j++) {
        list[u][j] = sc.nextInt() - 1;
      }

      Arrays.sort(list[u]);
    }

    int time = 1;

    int[] ds = new int[n];
    int[] fs = new int[n];

    for (int i = 0; i < n; i++) {
      ds[i] = 0;
      fs[i] = 0;
    }

    Deque<Integer> stack = new ArrayDeque<Integer>();
    stack.push(0);
    while(true) {
      if (stack.size() == 0) {
        boolean flag = true;
        for (int i = 0; i < n; i++) {
          if (ds[i] == 0) {
            stack.push(i);
            flag = false;
            break;
          }
        }
        if(flag) break;
      }

      int p = stack.peek();

      if (fs[p] != 0) {
        stack.pop();
      }
      else if (ds[p] != 0) {
        fs[p] = time;
        time++;
        stack.pop();
      }
      else {
        ds[p] = time;
        time++;
        for(int i = list[p].length - 1; i >= 0; i--) {
          if (ds[list[p][i]] == 0) stack.push(list[p][i]);
        }
      }
    }

    for (int i = 0; i < n; i++) {
      System.out.println((i + 1) + " " + ds[i] + " " + fs[i]);
    }
  }

  public static void main(String[] args) {
    new Main().run();
  }
}

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

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}

int main(){
	string s;
	cin>>s;
	puts(s[1]=='B'?"ARC":"ABC");
	return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,enable_if_t<iterable<T>::value,int> =0>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}
template<class T,enable_if_t<is_integral<T>::value,int> =0>T mod(T a, T b){if(a>0)return a%b;return b-(-a%b);}
template<class T,enable_if_t<is_floating_point<T>::value,int> =0>T mod(T a, T b){if(a>0)return a%b;return b-fmod(-a,b);}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int n;
    cin>>n;
    vi c(60);
    ll a;
    ll ans=0;
    REP(i,n){
        cin>>a;
        for(ll j=1ll<<59,x=59; j; j>>=1,--x){
            if(a&j)ans+=j%MOD*(i-(c[x]++));
            else ans+=j%MOD*c[x];
            ans%=MOD;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

long long a[100000];
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    bool first = false;
    for(int i = 0; i < N; i++){
        if(a[i] % 2 == 1){
            first = true;
        }
    }
    if(first){
        cout << "first" << endl;
    } else {
        cout << "second" << endl;
    }
    return 0;
}


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

using namespace std;

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

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

    cout << a[n - 1];
    for (int i = n - 3, d = -2; i < n; i += d) {
        if (i < 0) {
            i = (i == -2 ? -1 : -2);
            d = 2;
            continue;
        }

        cout << " " << a[i];
    }
    cout << endl;
}


Measured memory_bytes: 2944
n=int(input())
l=sorted([int(i) for i in input().split()])
if(n<3):
  print(0)
else:
  c=0
  for i in range(n-2):
    for j in range(i+1,n-1):
      for k in range(j+1,n):
        if(l[i]+l[j]>l[k] and len(set([l[i],l[j],l[k]]))==3):
          c+=1
  print(c)

Measured memory_bytes: 9144
n = gets.to_i
a, b = gets.split.map{|i|i.to_i}
p = gets.split.map{|i|i.to_i}

first, second, third = 0, 0, 0

p.each do |score|
  if score <= a
    first+=1
  elsif score <= b
    second+=1
  else
    third+=1
  end
end

puts [first, second, third].min

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
string item[110];
int cost[110][110];
int solve(int x, int n) {
	int ans = 0;
	bool f = 1;
	rep(i,n) {
		if(i==x) continue;
		if(cost[x][i]!=-1) {
			f=0;
			ans += solve(i,n);
		}
	}
	if(f) return cost[x][x];
	return min(cost[x][x], ans);

}
int main(){
	int n, k, m;
	string s;
	while(cin >> n, n) {
		rep(i,110) {
			rep(j,110) {
				cost[i][j] = -1;
			}
		}
		rep(i,n) {
			cin >> item[i] >> cost[i][i];
		}
		cin >> k;
		rep(i,k) {
			cin >> s >> m;
			rep(j,100) {
				if(item[j] == s) {
					rep(p,m) {
						cin >> s;
						rep(q,100) {
							if(item[q] == s) {
								cost[j][q] = cost[q][q];
								break;
							}
							
						}
					}
					break;
				}
			}
		}
		cin >> s;
		rep(i,100) {
			if(item[i] == s) {
				cout << solve(i,n) << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1260
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main
{
	public static void main(String[] args)throws IOException
	{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sRem = br.readLine().split(" ");
		//int[] chip = new int[n];
		int temp;
		int min = 1000, max = 0 ;
		for(int i = 0 ; i< n ; i++)
		{
			temp = Integer.parseInt(sRem[i]) ; 
			if(temp < min) min = temp;
			if(temp > max) max =temp;
		}
		System.out.println(max-min);
	}
}

Measured memory_bytes: 21204
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
class union_find{
    public:
        int n;
        vector<T> p;

        union_find(int n)
            : n(n), p(n+1, -1){}

        int find(int v){
            if(p[v] == -1){
                return v;
            }
            p[v] = find(p[v]);
            return p[v];
        }

        void unite(int u, int v){
            int u_root = find(u);
            int v_root = find(v);

            if(u_root == v_root){
                return;
            }
            p[u_root] = v_root;
        }
};

signed main(){
    int n, q;
    cin >> n >> q;

    vector<int> p(n, -1);

    union_find<int> uf(n);
    rep(i, q){
        int com, x, y;
        cin >> com >> x >> y;

        if(com == 0){
            uf.unite(x, y);
        }

        if(com == 1){
            int px = uf.find(x);
            int py = uf.find(y);

            cout << (px == py ? 1 : 0) << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3300
n=int(input())
s=input()
cnt=s[1:].count('E')
res=cnt
for i in range(len(s)-1):
    if s[i]=='W' and s[i+1]=='W':
        cnt+=1
    if s[i]=='E' and s[i+1]=='E':
        cnt-=1
    
    if res>cnt:
        res=cnt
print(res)

Measured memory_bytes: 3672
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

i = 0
j = 0
k = 0
p = []
while i < n and j < n:
    if a[i] < b[j]:
        i += 1
    else:
        p.append(i + k)
        k = p[-1]
        j += 1
else:
    while j < n:
        p.append(n + k)
        k = p[-1]
        j += 1
       
i = 0
j = 0
k = 0
s = []
while i < n and j < n:
    if b[i] < c[j]:
        i += 1
    else:
        if i == 0:
            s.append(0)
        else:
            s.append(p[i-1] + k)
        k = s[-1]
        j += 1
else:
    while j < n:
        s.append(p[-1] + k)
        k = s[-1]
        j += 1

print(s[-1])

Measured memory_bytes: 24768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
#define all(x) x.begin(),x.end()
const int inf=0x3f3f3f3f;

int N,M,X,C[15],A[15][15],curr[15];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>N>>M>>X;
	for(int i=0;i<N;i++){
		cin>>C[i];
		for(int j=0;j<M;j++) cin>>A[i][j];
	}
	int ans=inf;
	for(int i=1;i<(1<<N);i++){
		int cost=0;
		for(int j=0;j<N;j++) if(i&(1<<j)){
			cost+=C[j];
			for(int k=0;k<M;k++) curr[k]+=A[j][k];
		}
		bool flag=1;
		for(int j=0;j<M;j++){
			flag&=(curr[j]>=X);
			curr[j]=0;
		}
		if(!flag) continue;
		ans=min(ans,cost);
	}
	if(ans==inf) cout<<-1;
	else cout<<ans;
	return 0;
}

Measured memory_bytes: 3652