akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

if sum(A)>=sum(B):
    neg = []
    pos = []
    for i in range(N):
        d = A[i]-B[i]
        if d<0:
            neg.append(-d)
        elif d>0:
            pos.append(d)
    negsum = sum(neg)
    pos.sort(reverse=True)
    possum = 0
    for i in range(len(pos)+1):
        if possum >= negsum:
            print(i+len(neg))
            break
        possum += pos[i]
else:
    print(-1)

Measured memory_bytes: 83504
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int A, ans = 0;
	for (int i = 0; i < 3; i++) {
		cin >> A;
		ans += A;
	}
	if (ans >= 22) cout << "bust" << endl;
	else cout << "win" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

int main(){
	int n=read();
	printf("%d\n",(n-2)*180);
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(){
	int N;
	scanf("%d",&N);

	if(N/100==7 || (N/10)%10 == 7 || N%10 == 7 ){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

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

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        StringBuffer p = new StringBuffer();
        for (int i = 0; i < N; i++) {
            p.append(sc.next());
        }

        StringBuffer q = new StringBuffer();
        for (int i = 0; i < N; i++) {
            q.append(sc.next());
        }

        final List<String> candidate = IntStream.rangeClosed(1, N).boxed().map(String::valueOf).collect(Collectors.toList());
        final List<List<String>> perms = new ArrayList<>();

        perm(candidate, new ArrayList<>(), perms);

        final List<String> sPerms = perms.stream()
                .map(e -> e.stream().collect(Collectors.joining("")))
                .collect(Collectors.toList());

        int a = 0;
        int b = 0;

        for (int i = 0; i < sPerms.size(); i++) {
            if (sPerms.get(i).equals(p.toString())) {
                a = i;
            }
            if (sPerms.get(i).equals(q.toString())) {
                b = i;
            }
        }

        System.out.println(Math.abs(a-b));
    }

    private static<T> void perm(List<T> candidate, List<T> perm, List<List<T>> perms) {
        if (candidate.size() == 0) {
            perms.add(perm);
        }
        for (int i = 0; i < candidate.size(); i++) {
            final List<T> c = new ArrayList<>(candidate);
            final List<T> p = new ArrayList<>(perm);
            p.add(c.get(i));
            c.remove(i);
            perm(c, p, perms);
        }
    }
}


Measured memory_bytes: 54444
use itertools::Itertools;
use whiteread::parse_line;

fn main() {
    let mut c: Vec<Vec<u32>> = Vec::new();
    let mut ans = true;

    for _ in 0..3 {
        c.push(parse_line().unwrap());
    }
    let sum = c[0][0] + c[1][1] + c[2][2];
    for p in (0..3).permutations(3) {
        let mut s = 0;
        for (i, k) in (0..3).zip(p) {
            s += c[i][k];
        }
        if s != sum {
            ans = false;
            break;
        }
    }
    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>arr[i][j];
        }
    }
    int dp[n+1][3];
    memset(dp,0,sizeof(dp));
    dp[1][0]=arr[0][0];
    dp[1][1]=arr[0][1];
    dp[1][2]=arr[0][2];
    for(int i=2;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            dp[i][j]=max(dp[i-1][(j+1)%3]+arr[i-1][j],dp[i-1][(j+2)%3]+arr[i-1][j]);
        }
    }
    cout<<max(max(dp[n][0],dp[n][1]),dp[n][2]);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    ll int A[X], B[Y], C[Z];
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];
    sort(A, A + X);
    sort(B, B + Y);
    sort(C, C + Z);
    reverse(A, A + X);
    reverse(B, B + Y);
    reverse(C, C + Z);
    //ll int t[1000500];
    priority_queue<ll int> Q;
    priority_queue<ll int> Q_1;
    //memset(t, 0, sizeof(t));
    int g = 0;
    rep(i, X){
        rep(j, Y){
            Q.push(A[i] + B[j]);
            // t[g] = A[i] + B[j];
           // g ++;
        }
    }
    //sort(t, t + 1000500);
    //reverse(t, t + 1000500);
    //ll int ee[3000100];
    //memset(ee, 0, sizeof(ee));
    ll int gb = 0;
    ll int ii = 0;
    ll int jj = 0;
    ll int yy = 0;
    size_t hh = Q.size();
    int qqq = hh;
    int aaaa = min(3000, qqq);
    rep(i, aaaa){
        ll int ff = Q.top();
        Q.pop();
        rep(j, Z){
            Q_1.push(ff + C[j]);
            //yy++;
        }
    }
    //sort(ee, ee + 3000100);
    rep(i, K){
        ll int jjj = Q_1.top();
        Q_1.pop();
        cout << jjj << endl;
    }


}


Measured memory_bytes: 43236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main() {
    int n,a,b;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    int c1=0,c2=0;
    for(int i=0;i<n;i++){
        if(s[i]=='a'&&c1<a+b){
            cout<<"Yes"<<endl;
            c1++;continue;
        }
        if(s[i]=='b'&&c2<b&&c1<a+b){
            c1++,c2++;
            cout<<"Yes"<<endl;
            continue;
        }
        cout<<"No"<<endl;
    }
}



Measured memory_bytes: 3768
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

def solve():
    l, r = MI()
    mod = 2019

    r = min(r, l+673)
    ans = 2018
    for i in range(l, r):
        for j in range(i+1, r+1):
            ans = min(ans, i * j % mod)

    print(ans)
if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
using namespace std;

int main(void) {
    int N,M;cin>>N>>M;
    vector<int> H(N+1);
    H[0] = 0;
    vector<bool> result(N+1,true);
    result[0] = false;
    for (int i = 1; i <= N; i++) cin>>H[i];
    for (int i = 1; i <= M; i++) {
        int A,B;cin>>A>>B;
        if (H[A] < H[B]) result[A] = false;
        else if (H[A] > H[B]) result[B] = false;
        else {
            result[A] = false;
            result[B] = false;
        }
    }
    cout << count(all(result), true) << endl;
    return 0;
}

Measured memory_bytes: 3356
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
    
int main(){
    string S,T,U;
    int A,B;
    cin >> S >> T >> A >> B >> U;
    if(S==U && T== U) cout << A-1 <<" " << B-1 << endl;
    else if(S==U && T!=U) cout << A-1 <<" " << B << endl;
    else if(S!=U && T==U) cout << A <<" "<< B-1 << endl;
    else if(S!=U && T!=U) cout << A << " " << B << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  char a;cin>>a;
  char ans;
  if(a=='A')ans='T';
  if(a=='G')ans='C';
  if(a=='C')ans='G';
  if(a=='T')ans='A';
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
const double eps=1e-6,pi=acos(-1);
const int N=1e5+5,M=1e9+7,SEGM=4*N,OO=0x3f3f3f3f;
int n,m,w[105],v[105],c[N];
ll mem[105][N];

ll solve(int i=0,int remW=m){
    if(i==n) return 0;
    ll &ret=mem[i][remW];
    if(~ret) return ret;
    ret=max(solve(i+1,remW),remW-w[i]>=0?solve(i+1,remW-w[i])+v[i]:(int)-1e9);
    return ret;
}

int main(){
    //freopen("myfile.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;++i)
        scanf("%d%d",w+i,v+i);
    memset(mem,-1,sizeof mem);
    printf("%lld",solve());
    return 0;
}


Measured memory_bytes: 85792
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    odd = 0
    even = 0
    for a in A:
        if a % 2:
            odd+=1
        else:
            even+=1
    if odd % 2 == 1:
        print('NO')
    else:
        print('YES')




Measured memory_bytes: 14108
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

typedef struct range {
  i32 l, r;
} range;

void add (i32 *bit, i32 x, i32 v) {
  i32 n = bit[0];
  for (i32 i = x; i <= n; i += i & -i) {
    bit[i] += v;
  }
}

i32 find (i32 *bit, i32 x) {
  i32 sum = 0;
  for (i32 i = x; i > 0; i -= i & -i) {
    sum += bit[i];
  }
  return sum;
}

void run (void) {
  i32 n = read_int();
  i32 m = read_int();
  range **p = (range **) calloc (m + 1, sizeof (range *));
  i32 *len = (i32 *) calloc (2 * (m + 1), sizeof (i32));
  i32 *max_len = len + m + 1;
  for (i32 i = 0; i < n; ++i) {
    i32 l = read_int();
    i32 r = read_int() + 1;
    i32 d = r - l;
    if (len[d] == max_len[d]) {
      max_len[d] = 2 * max_len[d] + 1;
      p[d] = realloc (p[d], sizeof (range) * max_len[d]);
    }
    p[d][len[d]++] = (range) {l, r};
  }
  i32 *bit = (i32 *) calloc (m + 2, sizeof (i32));
  bit[0] = m + 1;
  for (i32 d = 1, c = 0; d <= m; ++d) {
    for (i32 i = 0; i < len[d - 1]; ++i) {
      c++;
      add (bit, p[d - 1][i].l, 1);
      add (bit, p[d - 1][i].r, -1);
    }
    i32 ans = n - c;
    for (i32 j = d; j <= m; j += d) {
      ans += find (bit, j);
    }
    print_int (ans);
    putchar ('\n');
  }
}

int main (void) {
  run();
  return 0;
}


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

int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    int ans = t.size();
    int diff;
    for (int i = 0; i <= s.size() - t.size(); i++)
    {
        diff = 0;
        for (int j = 0; j < t.size(); j++)
        {
            if (s.at(i + j) != t.at(j))
                diff++;
        }
        ans = min(ans, diff);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int x1=0,x2,y1=0,y2,n;
    cin>>x2>>y2>>n;
    rep(i,n){
        int x,y,a;
        cin>>x>>y>>a;
        //cout<<"Yes"<<endl;
        if(a==1){
            x1 = max(x1,x);
        }
        else if(a==2) {
            x2 = min(x2,x);
        }
        else if(a==3) {
            //cout<<"a==3"<<y2<<" "<<y<<endl;
            y1 = max(y1,y);
        }
        else y2 = min(y2,y);
        //cout<<x1<<" "<<x2<<" "<<y1<<" "<<y2<<endl;
    }
    if(x1<x2 && y1<y2) cout<<(x2-x1)*(y2-y1)<<endl;
    else cout<<"0"<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int len;
  scanf("%d", &len);
  map<ii, int> cnt;
  while (len--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    for (int u = max(0, x - 2); u <= x && u + 3 <= n; ++u) {
      for (int v = max(0, y - 2); v <= y && v + 3 <= m; ++v) {
        cnt[{u, v}]++;
      }
    }
  }
  vector<int64> ret(10);
  for (auto& it : cnt) {
    ret[it.second]++;
  }
  ret[0] = (int64)(n - 2) * (m - 2) - accumulate(ret.begin() + 1,
                                                 ret.end(), 0);
  for (int i = 0; i < 10; ++i) {
    printf("%lld\n", ret[i]);
  }
  return 0;
}


Measured memory_bytes: 56448
st = input().split(" ")
ab = input().split(" ")
ab[0] = int(ab[0])
ab[1] = int(ab[1])
u = input()

if st[0] == u:
    ab[0] -= 1
else:
    ab[1] -= 1

print(str(ab[0]) + " " + str(ab[1]))


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cnt = 0;

void merge(int A[], int left, int mid, int right) {
    int i = 0;
    int j = 0;
    int k;
    int n1 = mid - left;
    int n2 = right - mid;
    int *L = (int *)malloc((n1 + 1) * sizeof(int));
    int *R = (int *)malloc((n2 + 1) * sizeof(int));
    memcpy(L, A + left, (n1 + 1) * sizeof(int));
    memcpy(R, A + mid, (n2 + 1) * sizeof(int));
    L[n1] = 2000000000;
    R[n2] = 2000000000;
    for (k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
        cnt++;
    }
    free(R);
    free(L);
}

void mergeSort(int A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

void printarray(int A[], int n) {
    int i;
    for (i = 0; i < n; i++) {
        if (i) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

int main(void) {
    int n, i;
    int S[500000];
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &S[i]);
    mergeSort(S, 0, n);
    printarray(S, n);
    printf("%d\n", cnt);
    return 0;
}



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

int main(){
    string S;
    cin>>S;
    int b=0,r=0;
    for(auto s:S){
        if(s=='0'){
            b++;
        }else{
            r++;
        }
    }
    cout<<S.size()-abs(b-r)<<endl;
    return 0;
}

Measured memory_bytes: 1144
#include <iostream>
using namespace std;
int main()
{
 int H, W;
 for(;;)
 {
  cin >> H >> W;
  if (H == 0 && W == 0) break;
  
  for(int i = 0; i<H; ++i)
  {
    for(int j=0; j<W; ++j)
      cout << "#";
    cout << endl;
  }
  cout << endl;
 }
 return 0;
}

Measured memory_bytes: 3060
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  st S;
  ci(S);
  map<char, int> A;
  for(char i = 'a'; i <= 'z'; i++){
    A[i] = 0;
  }
  rep(i, sz(S)){
    A[S.at(i)]++;
  }
  each(i, A){
    if(i.sc == 0){
      co(i.ft);
      rt;
    }
  }
  co("None");
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
     
    static char[] k = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
     
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        String s = stdIn.next();
        String p = stdIn.next();
         
        boolean ans = false;
         
        IN:for(int i = 0; i < s.length(); i++) {
            for(int j = 0; j < p.length(); j++) {
                if(s.charAt((i + j) % s.length()) != p.charAt(j)) {
                    continue IN;
                }
            }
            ans = true;
            break;
        }
         
        System.out.println((ans)?"Yes":"No");
         
    }
}


Measured memory_bytes: 26260
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cstring>
#define rg register
#define LL long long
using namespace std;
const int MAXN=500;
int H,W;
LL ans,hei,bai;
char mp[MAXN][MAXN];
int heng[5]={0,1,-1,0,0},shu[5]={0,0,0,1,-1};
int vis[MAXN][MAXN];

template <typename T> inline void in(T &a) {
	T ch = getchar(), f = 1;
	for(a = 0; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
	for( ; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + ch - '0';
	a *= f;
}

template <typename T> inline void print(T x) {
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + '0');
}

inline void find_(int x,int y){
	vis[x][y]=1;
	if(mp[x][y]=='.') hei++;
	else bai++;
	for(rg int i=1;i<=4;i++){
		int tox=x+heng[i],toy=y+shu[i];
		if(tox>=0&&tox<H&&toy>=0&&toy<W&&!vis[tox][toy]&&mp[tox][toy]!=mp[x][y])
			find_(tox,toy);
	}
	return ;
}

int main(){
	in(H),in(W);
	
	for(rg int i=0;i<H;i++){
		for(rg int j=0;j<W;j++)
			cin>>mp[i][j];
	} 
	
	for(rg int i=0;i<H;i++){
		for(rg int j=0;j<W;j++){
			if(!vis[i][j]){
				find_(i,j);
				ans+=hei*bai;
				hei=bai=0LL;
			}	
		}
	}
	
	print(ans),puts("");
	
    return 0;
}
/*
4 3
###
###
...
###
*/

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, c = 0, d = 0;
  cin >> N;
  int x;
  
  for (int i = 0;  i < N; i++) {
    cin >> x;
    c = 0;
    while (x % 2 == 0) {
      x /= 2;
      c++;
    }
    if (d > c) d = c;
    if (i == 0 && d == 0) d = c;
  }
  cout << d << endl;
}

Measured memory_bytes: 256
#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 pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(b-a<=0) cout<<"delicious"<<endl;
    else if(b-a<x+1) cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 0;i < n;i++){
        for (int j = 0;j < n;j++){
            for (int k = 0;k < n;k++){
                cnt++;
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

long gcd(long m, long n)
{
	if ((0 == m) || (0 == n))
		return 0;

	while (m != n)
	{
		if (m > n) m = m - n;
		else         n = n - m;
	}
	return m;
}

long lcm(long m, long n)
{

	if ((0 == m) || (0 == n))
		return 0;

	return ((m / gcd(m, n)) * n);
}

int main() {
	long N,M;
	string S, T;
	cin >> N >> M;
	cin >> S >> T;

	long lcmVal = lcm(M, N);

	long ans = lcmVal;
	for (long i = 0; i / M<N; i += lcmVal) {
		if (S[i / M] != T[i / N]) {
			ans = -1;
			break;
		}
	}

	cout << ans;
	return 0;
}

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

Measured memory_bytes: 596
import java.util.Scanner;

/**
 * @author munkhbat
 * AOJ 033 ball
 */
public class Main {
	public static int[] balls = new int[10];
	private static int n;
	
	public static void main(String[] a) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 10; j++) {
				balls[j] = sc.nextInt();
			}
			
			System.out.println(dfs(0, 0, 0) == true ? "YES" : "NO");
		}
		sc.close();
	}
	
	/**
	 * @param a last number in A box
	 * @param b last number in B box
	 * @param num
	 * @return
	 */
	private static boolean dfs(int a, int b, int num) {
		if (num >= 10) {
			return true;
		}
		
		if (a < balls[num]) {
			return dfs(balls[num], b, ++num);
		}
		
		if (b < balls[num]) {
			return dfs(a, balls[num], ++num);
		}
		
		return false;
	}
}

Measured memory_bytes: 18140
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

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

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<int> > g(n);
	rep(i,n) {
		if(i==0) continue;
		int a;
		std::cin >> a;
		a--;
		g[a].emplace_back(i);
	}
	rep(i,n) std::cout << g[i].size() << EL;
	return 0;
}


Measured memory_bytes: 13956
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n, m;
    while(cin>>n>>m){
        ll ans=n*(n-1)/2+m*(m-1)/2;
        cout<<ans<<endl;

    }
  return 0;
}




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

int main() {
  int l, n, t, i=0, j;
  cin >> n;
  int* a = new int[n];
  int* ans = new int[n];
  while(cin>>l){
  	a[i++] = l;
  }
  for (i = 0; i < n; i++) {
    ans[a[i]-1] = i+1;
  }
  for(i=0; i<n;i++){
  	cout << ans[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1536
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;
vector<vector<pair<ll,ll>>> v(100010);
vector<ll> dist(100010);
void dfs(ll cur, ll par,ll point=0){
    dist[cur] = point;
    // cout<<"cur:"<<cur<<", par:"<<par<<endl;
    for(ll i=0;i<v[cur].size();i++){
        ll next = v[cur][i].first;
        ll next_point = v[cur][i].second+point;
        // cout<<"next:"<<next<<endl;
        if(next!=par){
            dfs(next,cur,next_point);
        }
    }
    return;
}

int main(){
    long N;
    cin>>N;
    
    for(ll i=0;i<N-1;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        v[a].push_back(make_pair(b,c));
        v[b].push_back(make_pair(a,c));
    }
    
    ll Q,K;
    cin>>Q>>K;
    K--;
    ll x[Q],y[Q];
    for(ll i=0;i<Q;i++){
        ll _x,_y;
        cin>>_x>>_y;
        _x--;_y--;
        x[i] = _x;
        y[i] = _y;
    }
    dfs(K,-1,0);
    for(ll i=0;i<Q;i++){
        cout<<dist[x[i]]+dist[y[i]]<<"\n";
    }




}


Measured memory_bytes: 15872
#include <iostream>
#include<string.h>

using namespace std;
typedef long long ll;


int main()
{

    int h,w,n;
    cin>>h>>w>>n;
    if(n%max(h,w)==0)
        cout<<n/max(h,w);
    else cout<<n/max(h,w)+1;
    return 0;
}


Measured memory_bytes: 256
def soi(n): #?´??????°????§£?????¢?????´?????????
    i=2
    while True:
        if i*i>n:
            return n
        
        if n%i==0:
            return i
        i+=1


a=int(input())
ans=a
count=1
i=2 # ??????????????°
while True:
    temp=soi(a)
    if a==1: #?´??????°??????????????°
        break
    while a%temp==0: #?´??????°??§???????¶???????
        a/=temp
     #   print (a)

    ans*=(1-1/temp)
    #print (ans)

print(int(ans))


                
       

def gcd(a,b): #?????§??¬?´???°???????????°??????
    r=0
    while True:
       r=a%b
       if r==0:
           break
       a=b
       b=r
    return b

Measured memory_bytes: 7732
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 998244353
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	ll n, m;
	cin >> n >> m;
	if(n == 1 && m == 1) {
		cout << 1;
		return 0;
	}
	if(n == 1) {
		cout << m - 2;
		return 0;
	}
	if(m == 1) {
		cout << n - 2;
		return 0;
	}
	cout << (n - 2) * (m - 2);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
using namespace std;
signed  main(){
	int n,cun=0;
  	char s[100000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  for(int i=0;i<n;i++){
	if(s[i]=='Y'){
	cun++;
    }
  }
  if(cun>0){
    cout<<"Four\n";
  }else{
    cout<<"Three\n";
  }
	return(0);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		boolean[] has = new boolean[n];
		for(int i = 0; i < k; i++)
		{
			int jn = sc.nextInt();
			for(int j = 0; j < jn; j++)
			{
				int sn = sc.nextInt()-1;
				has[sn] = true;
			}
		}
		
		int c = 0;
		for(int i = 0; i < n; i++)
		{
			if(!has[i])c++;
		}
		System.out.println(c);
	}

}


Measured memory_bytes: 37332
//羊肉串问题 
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
int num[1005];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
		scanf("%d",&num[i]);
	int ans=-100000000;
	for(int a=0;a<=k;a++)
	{
		for(int b=0;b<=k;b++)
		{
			for(int c=0;c<=k;c++)
			{
				if((a+b+c)<=k&&(a+b)>=c&&(a+b)<=n)
				{
					priority_queue<int>q;
					for(int i=0;i<a;i++)
						q.push(num[i]);
					for(int i=0;i<b;i++)
						q.push(num[n-i-1]);
					int sum=0;
					for(int i=0;i<a+b-c;i++)
					{
						sum+=q.top();
						q.pop();
					}
					ans=max(ans,sum);
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
 } 

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

int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r ;
	if (0 <= x - r&&x + r <= W && 0 <= y - r&&y + r <= H) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
return		0;
}

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

using namespace std;

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

  vector<int> A(N);

  for(int i = 0; i < N; i++)
    cin >> A[i];

  int dp[N][2];

  for(int i = 0; i < N; i++) {
    dp[i][0] = dp[i][1] = 100000;
  }

  dp[0][0] = dp[0][1] = 1;

  for(int i = 1; i < N; i++) {
    if(A[i] - A[i - 1] == 0) {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = dp[i - 1][1];
    }else if(A[i] - A[i - 1] > 0) {
      dp[i][0] = min(dp[i - 1][0], dp[i - 1][1] + 1);
      dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + 1;
    }else {
      dp[i][1] = min(dp[i - 1][1], dp[i - 1][0] + 1);
      dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + 1;
    }
  }

  cout << min(dp[N - 1][0], dp[N - 1][1]) << endl;


}


Measured memory_bytes: 1408
//151 C - Welcome to AtCoder 2020/01/12

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

bool ac[100000]={false};
int wa[100000]={0};


int main(){
    int n , m; cin >> n >> m;
    int counter_AC = 0; int counter_WA = 0;
 
    for(int i=1 ; i <= m ; ++i){
            int p; string s;
            cin >> p >> s;
            if(ac[p]) continue;
            if(s == "AC"){
                ac[p] = true;
                ++counter_AC;
                counter_WA+=wa[p];
            } else if (s == "WA"){
                ++wa[p];
            }
        }

    cout << counter_AC << " " << counter_WA << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001

int main(void) {
	int n; cin >> n;
	vi h(n); rep(i,n) cin >> h[i];
	int ans = 1;
	int mxh = h[0];	
	rep2(i,1,n){
		if(h[i]>=mxh) ans++;
		mxh = max(mxh,h[i]);
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        Card[] a1 = new Card[N];
        Card[] a2 = new Card[N];
        for (int i = 0; i < N; i++) {
            Card c = new Card(scanner.next());
            a1[i] = c;
            a2[i] = c;
        }
        bubbleSort(a1);
        selectionSort(a2);
        String s1 = result(a1);
        String s2 = result(a2);
        System.out.println(s1);
        System.out.println("Stable");
        System.out.println(s2);
        System.out.println(s1.equals(s2) ? "Stable" : "Not stable");
    }

    private static void bubbleSort(Card[] a) {
        for (int i = 0; i < a.length; i++) {
            for (int j = a.length - 1; j > i; j--) {
                if (a[j].n < a[j - 1].n) {
                    Card t = a[j - 1];
                    a[j - 1] = a[j];
                    a[j] = t;
                }
            }
        }
    }

    private static void selectionSort(Card[] a) {
        for (int i = 0; i < a.length; i++) {
            int mi = i;
            for (int j = i + 1; j < a.length; j++) {
                if (a[j].n < a[mi].n) {
                    mi = j;
                }
            }
            if (i != mi) {
                Card t = a[i];
                a[i] = a[mi];
                a[mi] = t;
            }
        }
    }

    private static String result(Card[] a) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < a.length; i++) {
            sb.append(a[i].toString());
            if (i != a.length - 1) {
                sb.append(" ");
            }
        }
        return sb.toString();
    }

    private static class Card {
        String m;
        int n;

        private Card(String s) {
            this.m = String.valueOf(s.charAt(0));
            this.n = Character.getNumericValue(s.charAt(1));
        }

        public String toString() {
            return m + String.valueOf(n);
        }
    }
}

Measured memory_bytes: 26360
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    string str;
    cin >> str;

    if (str[0] == 'R' && str[1] == 'R' && str[2] == 'R')
    {
        cout << 3;
        return 0;
    }
    if (str[0] == 'R' && str[1] == 'R' || str[1] == 'R' && str[2] == 'R')
    {
        cout << 2;
        return 0;
    }
    if (str[0] == 'R' || str[1] == 'R' || str[2] == 'R')
        cout << 1;
    else cout << 0;
}

Measured memory_bytes: 3620
//2*10^9
//9*10^18
// __int128_t 
#include<bits/stdc++.h>
using namespace std;

#define ull unsigned long long int
#define ll long long int

const ll M=998244353;

//to handle when remainder is -neg we add + M
//but when rem is +pos that time also we add so use %M
//so it will work for both
ll mod(ll n){
    return (n%M + M)%M; 
}
ll modAdd(ll a, ll b){
    return mod(mod(a)+mod(b));
}
ll modMul(ll a, ll b){
    return mod(mod(a)*mod(b));
}
ll modMinus(ll a, ll b){
    return mod(mod(a)-mod(b));
}
ll modpow(ll x, ll n) 
{ 
    if (n == 0) 
        return 1%M;
    if (n == 1)
        return x%M; 
    ll u = modpow(x,n/2); 
    u = modMul(u,u); 
    if (n%2) 
        u = modMul(u,x); 
    return u; 
}
ll gcd(ll a,ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}
bool isPrime(ll n){
    int end = sqrt(n);
    for(int i=2;i<=end;i++)
        if(n%i==0)
            return false;
    return true;
}

int factors(int n){
    int count=0;
    int end=sqrt(n)-1;

    for(int i=1;i<=end;i++){
        if(n%i==0)
           count+=2;
    }
    if(n%(end+1)==0){
        if(n/(end+1)!=(end+1))
            count+=1;
        count+=1;
    }

    return count;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    
    
    int t=1;
    //cin>>t;

    while(t--){
        int n;
        cin>>n;

        vector<int> dp(n+1);
        vector<int> suffix(n+1);
        int k;
        cin>>k;

        vector<vector<int>> segment(k,vector<int>(2));
        for(int i=0;i<k;i++)
            cin>>segment[i][0]>>segment[i][1];
        sort(segment.begin(),segment.end());


        dp[n]=1;
        suffix[n]=1;
        for(int i=n-1;i>=1;i--){
            for(int j=0;j<k;j++){
                int start=i+segment[j][0];
                int end=i+segment[j][1];

                if(start<=n){
                    if(end<n)
                        dp[i]=modAdd(dp[i],suffix[start]-suffix[end+1]);
                    else
                        dp[i]=modAdd(dp[i],suffix[start]);
                }
            }
            suffix[i]=modAdd(dp[i],suffix[i+1]);
        }
        cout<<dp[1]<<endl;
    }
    return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int x) { return (x > 0) - (x < 0); }
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int cdiv(int a, int b) { return (a - 1 + b) / b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int N, M;
    cin >> N >> M;
    scc_graph g(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        g.add_edge(a, b);
    }
    auto ans = g.scc();
    cout << ans.size() << endl;
    for (auto v:ans) {
        cout << v.size();
        for (int x:v) { cout << " " << x; }
        cout << endl;
    }
}

Measured memory_bytes: 40060
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int ans;
    int a, b;

    cin >> a >> b;

    int tower_height = 0;
    int diff = b - a;
    for(int i = 1; i <= 999; i++) {
        tower_height += i;
        if(i == diff) {
            ans = tower_height - b;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;

int N = 0, M = 0;
int D[1000] = {0};
int C[1000] = {0};

int memo[1001][1001];

long dp(int i, int j){

    if(memo[i][j] != -1){
        return memo[i][j];
    }

    if(j > M){
        return memo[i][j] = INT_MAX;
    }
    if(i == N){
        return memo[i][j] = 0;
    }

    long x = dp(i, j+1);
    long y = dp(i+1, j+1);

    if(x == INT_MAX && y == INT_MAX){
        return memo[i][j] = INT_MAX;
    }else if(x == INT_MAX){
        return memo[i][j] = C[j] * D[i] + y;
    }else if(y == INT_MAX){
        return memo[i][j] = x;
    }else{
        return memo[i][j] = min(x, C[j] * D[i] + y);
    }

}

int main(void){

    fill(memo[0],memo[1000], -1);

    cin >> N >> M;
    for(int i=0; i<N; ++i){
        cin >> D[i];
    }
    for(int j=0; j<M; ++j){
        cin >> C[j];
    }
    cout << dp(0, 0) << endl;
}

Measured memory_bytes: 7056
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<list>
#include<vector>
#include<stdio.h>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
	string s;
	cin >> s;
	string t = s;


	if(s=="zyxwvutsrqponmlkjihgfedcba"){
		cout << "-1" << endl;
		return 0;
	}

	map<char,bool> m;
	int cnt =0;
	for(int i=0;i<s.size();i++){
		m[s[i]] = true;
	}
	for(char c = 'a'; c <='z';c++){
		if(!m[c]){
			t = t + c;
			cout << t << endl;;
			return 0;
		}
	}

	next_permutation(s.begin(),s.end());
	if(t<s){
		for(int i=0;i<s.size();i++){
			if(t[i]<s[i]){
				cout << s.substr(0,i+1) << endl;;
				return 0;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 256
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int n;
  string com;
  priority_queue<int>  pq;
  while (1) {
    cin >> com;
    if (com == "end") break;
    else if (com == "insert") {
      cin >> n;
      pq.push(n);
    }
    else if (com == "extract") {
      cout << pq.top() << endl;
      pq.pop();
    }
  }

  
  return 0;
}


Measured memory_bytes: 7024
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int N,res = 0;
    cin >> N;
    
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        if(a%2==1)res++;
    }
    
    if(res % 2 == 1){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    
    
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;

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

const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
int w[maxn],v[maxn],W;
ll ans=0;
vector<ll> ve[4];
void dfs(int pos,ll sum,ll wsum)
{
    if(pos==4)
    {
        ans=max(ans,sum);
        return ;
    }
    dfs(pos+1,sum,wsum);
    for(int i=0;i<ve[pos].size();i++)
    {
        if(wsum+1LL*(i+1)*(w[1]+pos)>W) continue;
        dfs(pos+1,sum+ve[pos][i],wsum+1LL*(i+1)*(w[1]+pos));
    }
}
int main() {
    //freopen(".in", "r", stdin);

    int n;scanf("%d%d",&n,&W);
    for(int i=1;i<=n;i++) scanf("%d%d",&w[i],&v[i]);
    for(int i=1;i<=n;i++) ve[w[i]-w[1]].push_back(v[i]);
    for(int i=0;i<4;i++) sort(ve[i].begin(),ve[i].end(),greater<ll>());
    for(int i=0;i<4;i++) for(int j=1;j<ve[i].size();j++) ve[i][j]=ve[i][j]+ve[i][j-1];
    dfs(0,0,0);
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type point struct {
	x, y, h int
}

func height(c point, x, y int) int {
	h := float64(c.h) - math.Abs(float64(c.x-x)) - math.Abs(float64(c.y-y))
	return int(math.Max(h, 0))
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	L := make([]point, N)
	for i := 0; i < N; i++ {
		L[i].x, L[i].y, L[i].h = scanInt(), scanInt(), scanInt()
	}

	for Cx := 0; Cx <= 100; Cx++ {
		for Cy := 0; Cy <= 100; Cy++ {
			H := 0
			for _, l := range L {
				if l.h > 0 {
					H = int(float64(l.h) + math.Abs(float64(l.x-Cx)) + math.Abs(float64(l.y-Cy)))
					break
				}
			}

			flg := true
			for _, l := range L {
				if l.h != height(point{Cx, Cy, H}, l.x, l.y) {
					flg = false
					break
				}
			}

			if flg {
				fmt.Printf("%d %d %d\n", Cx, Cy, H)
				return
			}
		}
	}

}


Measured memory_bytes: 1780
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int dx[8] = { 1,-1,0,0,-1,-1,1,1 };
int dy[8] = { 0,0,1,-1,-1,1,-1,1 };
int dif[55][55];
char c[55][55];
int h, w;
void dfs(P p) {
	queue<P>que;
	que.push(p);
	while (!que.empty()) {
		int nowy = que.front().first;
		int nowx = que.front().second;
		que.pop();
		for (int i = 0; i < 8; i++) {
			int newy = nowy + dy[i];
			int newx = nowx + dx[i];
			if (newy >= 0 && newy < h && newx >= 0 && newx < w && dif[newy][newx] == inf && c[newy][newx] == '1') {
				dif[newy][newx] = 1;
				que.push(make_pair(newy, newx));
			}
		}

	}
	
}

int main() {
	vector<ll>ans;
	while (1) {
		
		ll count = 0;
		cin >> w >> h;
		if (h == 0 && w == 0) {
			break;
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> c[i][j];
				dif[i][j] = inf;
			}
		}
		
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (dif[i][j] == inf&&c[i][j]=='1') {
					count++;
					dif[i][j] = 1;
					dfs(make_pair(i, j));
				}
			}
		}
		ans.push_back(count);
	}
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <deque>

using namespace std;

int main() {
  deque<char> d;
  char c;
  int ans{}, x;
  cin >> x;
  while(cin >> c) d.push_back(c);
  while(!d.empty()) {
    while(!d.empty() && d.front()=='R') d.pop_front();
    while(!d.empty() && d.back()=='W') d.pop_back();
    if (d.empty()) break;
    if (!d.empty()) d.pop_front();
    if (!d.empty()) d.pop_back();
    ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3832
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
long long n,i,a[200001],prefix[200001]={},answer,j;
bool comp (int a,int b)
{
	return max(a,-a)<max(b,-b);
}
int main ()
{
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	for (i=1;i<=n;i++)
	prefix[i]=a[i]+prefix[i-1];
	sort(prefix+1,prefix+n+1,comp);
	for (answer=0;answer<n&&prefix[answer+1]==0;answer++);
	sort(prefix+1,prefix+n+1);
	for (i=1;i<=n;i=j)
	{
		for (j=i;j<=n&&prefix[i]==prefix[j];j++);
		answer+=(j-i-1)*(j-i)/2;
	}
	printf("%lld",answer);
	return 0;
}

Measured memory_bytes: 3328