akhauriyash/Code-Regression huggingface dataset:
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pf push_front
#define pb push_back
using namespace std;
using ll = long long; using ld = long double;
using pii = pair<int,int>; using pil = pair<int,ll>;
using pli = pair<ll,int>; using pll = pair<ll,ll>;
const int MOD = 1000000007, MOD2 = 998244353;
const int INF = 0x3f3f3f3f, INF2 = 0x3f3f3f37;
const ll LINF = 0x3f3f3f3f3f3f3f3f, LINF2 = 0x3f3f3f3f3f3f3f3d;

string s;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> s;
    if (s == "Sunny") cout << "Cloudy\n";
    if (s == "Cloudy") cout << "Rainy\n";
    if (s == "Rainy") cout << "Sunny\n";
}

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

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;


const int N = 2e5+5;

int h[N], a[N], BIT[N];
int n;

void update(int i, int v){
	while(i < N){
		BIT[i] = max(BIT[i],v);
		i += i&-i;
	}
}

int query(int i){
	int ans = 0;
	while(i){
		ans = max(ans,BIT[i]);
		i -= i&-i;
	}
	return ans;
}

signed main(){
	fastio
	cin >> n;
	for(int i = 0;i < n;i++) cin >> h[i];
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++){
		update(h[i],query(h[i])+a[i]);
	}
	cout << query(n) << "\n";
}

Measured memory_bytes: 8316
#include<stdio.h>

int n,A[50];

int solve(int i, int m){

  if(m==0)return 1;

  if(i>=n)return 0;

  int res =solve(i+1,m)||solve(i+1,m-A[i]);

  return res;
}

int main(){
 
  int q,M,i;

  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&A[i]);

  scanf("%d",&q);

  for(i=0;i<q;i++){

    scanf("%d",&M);

    if(solve(0,M))printf("yes\n");
    else printf("no\n");
    

  }

  return 0;

} 

Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
 
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
 
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
 
#define infi INT_MAX
#define infl LONG_LONG_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
#define pll pair<ll,ll> 
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;

const ll N=2e5+5;
ll cnt[N];

void func()
{
  ll n;
  cin>>n;
  ll arr[n];
  vll v;
  f(i,0,n)
  {
  	cin>>arr[i];
  	cnt[arr[i]]++;
  	if(cnt[arr[i]]==1) v.pb(arr[i]);
  }
  ll ans=0;
  for(auto i:v)
  {
  	//cout<<i<<" "<<cnt[i]<<"\t";
  	ll x=cnt[i];
  	ans+=((x*(x-1))/2);
  }
  //cout<<endl;
  //cout<<ans<<endl;
  f(i,0,n)
  {
  	ll x=cnt[arr[i]];
  	ll ans1=ans-((x*(x-1))/2);
  	x--;
  	ans1+=((x*(x-1))/2);
  	cout<<ans1<<endl;
  }
}

int main() 
{
    fast
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    
    ll ntc=1;
    //cin>>ntc;

    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<":";
      func();
    }
 
    return 0;
}

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

using namespace std;

typedef long long int ll;

int main(){
    int N;
    cin >> N;
    vector<int> d;
    for(int i=0;i<N;i++){
        int di;
        cin >> di;
        d.emplace_back(di);
    }

    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            ans+=d[i]*d[j];
        }
    }

    cout << ans <<endl;
}

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

#define f(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=a;i<b;i++)
#define gcd(x,y)         __gcd(x,y)
#define lcm(x,y)        (x/gcd(x,y))*y
#define mod             1000000007
#define all(a)           a.begin(),a.end()
// for lightoj cin cout #define CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif



void solve(){

    int n,m;cin>>n>>m;
    if(n==m) cout << "Yes\n"; else cout << "No";


}

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


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 28 13:30:11 2020

@author: NEC-PCuser
"""

N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

a_li = [0, A[0]]

for i in range(1, len(A)):
    if (a_li[len(a_li) - 1] + A[i] > K):
        break
    
    a_li.append(a_li[len(a_li) - 1] + A[i])
    
    
j = len(a_li)
ans = -1
count = 0
b_sum = 0
for i in range(-1, len(B)):
    if (i != -1):
        b_sum += B[i]
        if b_sum > K:
            break
    while (b_sum + a_li[j - 1] > K):
        j -= 1
    count = j + i
    if (ans < count):
        ans = count
    
print(ans)

Measured memory_bytes: 40632
#include<stdio.h>
static const int N = 100;

int main(){
  int M[N][N];
  int i,j,n,u,k,v;

  scanf("%d",&n);

  for(i =0; i<n; i++){
    for(j = 0; j < n; j++) M[i][j] = 0;
  }

  for(i = 0; i<n; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>

using namespace std;

int main(){
    int K,S,count=0;
    cin >>K>>S;
    for(int X=0;X<=K;X++){
        for(int Y=0;Y<=K;Y++){
            int Z=S-X-Y;
            if(Z<=K&&0<=Z){
                count++;
            }
        }
    }
    cout <<count<<endl;
}

Measured memory_bytes: 256
{$R-,S-,Q-,I-,O+}
const NN=28;
var a,b,seq:array[0..200009] of int64;
    bits:array[0..NN] of int64;
    n,i,k:longint;
    m,t,ans,bit_count:int64;

procedure quicksort(l,r:longint);
var v,t:int64;i,j:longint;
begin
  if l<r then begin
    v:=seq[r];i:=l-1;j:=r;
    repeat
      repeat inc(i) until v<=seq[i];
      repeat dec(j) until seq[j]<=v;
      t:=seq[i];seq[i]:=seq[j];seq[j]:=t;
    until j<=i;
    seq[j]:=seq[i];seq[i]:=seq[r];seq[r]:=t;
    quicksort(l,i-1);
    quicksort(i+1,r);
  end;
end;

function count(p,q:int64):int64;
var p_idx,q_idx,l,r,m:longint;
begin
  l:=1;r:=n;
  p_idx:=-1;
  while l<=r do begin
    m:=(l+r) div 2;
    if p>seq[m] then
      l:=m+1
    else begin
      p_idx:=m;
      r:=m-1;
    end;
  end;
  if p_idx=-1 then
  begin
    count:=0;
    exit;
  end;

  l:=1;r:=n;
  q_idx:=-1;
  while l<=r do begin
    m:=(l+r) div 2;
    if q>=seq[m] then
      l:=m+1
    else begin
      q_idx:=m;
      r:=m-1;
    end;
  end;
  
  //writeln('DEBUG');
  //writeln('q_idx= ',q_idx);

  if q_idx=-1 then q_idx:=n else dec(q_idx);
  count:=q_idx-p_idx+1;
  
  //write('SEQ ');
  //for i:=1 to n do write(seq[i],',');
  //writeln;
  //writeln(p,'..',q,' = ',count,'--',p_idx,':',q_idx);
  //writeln;
end;

begin
  read(n);
  for i:=1 to n do read(a[i]);
  for i:=1 to n do read(b[i]);
  FillCHar(bits,sizeof(bits),0);
  for k:= 0 to NN do begin
    bit_count:=0;
    m:=1 shl (k+1);
    for i:=1 to n do seq[i]:=b[i] mod m;
    quicksort(1,n);
    for i:=1 to n do begin
      t:=a[i] mod m;
      inc(bit_count,count((1 shl k)-t,(2 shl k)-1-t));
      inc(bit_count,count((1 shl k)-t+(2 shl k),(2 shl k)-1-t+(2 shl k)));
    end;
    bits[k]:=bit_count mod 2;
  end;

  ans:=0;
  for k:=0 to NN do inc(ans,(1 shl k)*bits[k]);
  writeln(ans);
end.


Measured memory_bytes: 4736
def func(num,arr):
  dp=[1]*(n+1)
  dp[0]=(1-arr[0])
  dp[1]=arr[0]
  for i in range(1,n):
    p0=arr[i]
    p1=1-arr[i]
    dp[i+1]=dp[i]*p0
    for j in range(1,i+1):
      dp[i+1-j]=dp[i-j]*p0+dp[i+1-j]*p1
    dp[0]=dp[0]*p1
  return dp

n=int(input())
arr=[float(s) for s in input().split()]
dp=func(n,arr)
ans=0
for i in range(int(n/2)+1,n+1):
  ans+=dp[i]
print(ans)


Measured memory_bytes: 3316
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();

		char[][] arr = new char[n*2][n*2];
		for(int i = 0; i < n; i++) {
			char[] input = scan.next().toCharArray();
			for(int j = 0; j < n; j++) {
				arr[i][j] = input[j];
				arr[i+n][j] = input[j];
				arr[i][j+n] = input[j];
				arr[i+n][j+n] = input[j];
			}
		}

		long ans = 0;

		for(int offset = 0; offset < n; offset++) {
			boolean flag = true;
			for(int x = 1; x < n; x++) {
				for(int y = 0; y < x; y++) {
					flag &= (arr[x+offset][y] == arr[y+offset][x]);
				}
			}
			ans += (flag)?n:0;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 29280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		int div = 0;
		int Hig = H - h;
		int Wid = W - w;
		
		div = Hig * Wid;
		
		System.out.println(div);
	}

}

Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LLI;
int main()
{
  	int n;
  	cin >> n;
  	LLI arr[n], ans = 0;
  	for(int i = 0; i < n; i++)
      	cin >> arr[i];
  	sort(arr,arr+n);
  	for(int i = 0; i < n-1; i++)
      	ans += (arr[i+1] - arr[i]);
  	cout << ans;
	return 0;
}

Measured memory_bytes: 3640
#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,m,X,Y;
  cin>>n>>m>>X>>Y;
  int a[n+1],b[m+1];
  rep(i,0,n) cin>>a[i];
  rep(i,0,m) cin>>b[i];
  a[n]=X;
  b[m]=Y;
  int z=*min_element(b,b+m+1);
  int y=*max_element(a,a+n+1);
  if(z>y){
    cout<<"No War\n";
  }
  else cout<<"War\n";
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3656
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int x, a;
	cin >> x >> a;

	cout << (x < a ? "0" : "10") << endl;



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main() {
  int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
  int ans1 = 0, ans2 = 0;double node = 0;
  rep(i,31){
    rep(j,31){
      int water = (a*i + b*j)*100,
          sg = (a*i+b*j)*e;
      rep(k,3001){
        if(c*k+water <= f && c*k <= sg){
          int l = (min(f-water, sg)-c*k)/d;
          double sd = c*k+d*l, all = c*k+d*l+water;
          if(sd/all >= node){
            node = sd/all;ans1 = c*k+d*l+water;ans2 = c*k+d*l;
          }
        }
      }
    }
  }
  cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 256
import heapq as hp
N,M=map(int,input().split())
price_list=sorted([-1*int(item) for item in input().split()])
total_m=0
def discount(price_list,tickets_num):
    total_ticket =0
    hp.heapify(price_list)

    while total_ticket < tickets_num:
        temp = hp.heappop(price_list)
        hp.heappush(price_list,-1*(-1*temp//2))
        total_ticket+=1
    return price_list

res = discount(price_list,M)
print(-1*sum(res))


Measured memory_bytes: 14180
items = [int(input()) for _ in range(5)]
items = sorted(items, key=lambda x:x%10)
flag = False
for i in range(len(items)):
    if items[i] % 10 == 0:
        continue
    elif flag is False:
        flag = True
        continue
    tmp = items[i] // 10
    items[i] = tmp * 10 + 10


print(sum(items))


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()

# (鍵の購入コスト, 開けられる宝箱)
keys = [None] * M
for i in range(M):
    c, _ = MAP()
    # どの宝箱を開けられるのかをbitで持っておく
    s = 0
    for a in [a-1 for a in LIST()]:
        s += 1 << a
    keys[i] = (c, s)

# dp[i][j] := i個目の鍵まで考えて、集合jの宝箱を開けるための最小コスト
dp = list2d(M+1, 1<<N, INF)
dp[0][0] = 0
for i in range(M):
    # 今回の鍵で開けられる宝箱の集合s
    s = keys[i][1]
    c = keys[i][0]
    for j in range(1<<N):
        # 今回の鍵を買わない遷移
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        # 買う遷移：遷移元の開けられる宝箱の集合j | 今回の鍵で開けられる宝箱の集合s
        dp[i+1][j|s] = min(dp[i+1][j|s], dp[i][j]+c)
ans = dp[M][-1]

if ans != INF:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 135560
main :: IO ()
main = interact $ unlines . map (unwords . map show) . calc . map (map read . words) . tail . lines

calc :: [[Int]] -> [[Int]]
calc = addVSum . map addHSum
    where addHSum xs  = xs ++ [sum xs]
          addVSum xss = xss ++ [foldr1 (zipWith (+)) xss]


Measured memory_bytes: 5532
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
vector<P> g[100000];
int d[100000];
int p[17][100000];
bool used[100000];
void dfs0(int x){
	used[x]=1;
	for(auto pr:g[x]){
        int y=pr.first;
		if(!used[y]){
			d[y]=d[x]+1;
			p[0][y]=x;
			dfs0(y);
		}
	}
}
void init_lca(){
    dfs0(0);
	for(int i=1; i<17; i++){
        for(int x=0; x<n; x++){
            p[i][x]=p[i-1][p[i-1][x]];
        }
    }
}
int lca(int a, int b){
    if(d[a]>d[b]) swap(a, b);
    int a1=a, b1=b;
    int dd=d[b]-d[a], i=0;
    while(dd>0){
        if(dd%2==1){
            b1=p[i][b1];
        }
        dd/=2;
        i++;
    }
    if(a1==b1) return a1;
    for(int i=16; i>=0; i--){
        if(p[i][a1]!=p[i][b1]){
            a1=p[i][a1], b1=p[i][b1];
        }
    }
    return p[0][a1];
}
vector<int> v[100010];
vector<int> vm[100010];
int c[100010]; ll dist[100010];
int cx[100010]; ll y[100010];
ll cnt[100010], dc[100010], ds;
ll ans[100010];
void dfs(int x){
    used[x]=1;
    for(auto i:v[x]){
        ans[i]+=(ds-dc[cx[i]]+cnt[cx[i]]*y[i]);
    }
    for(auto i:vm[x]){
        ans[i]-=2*(ds-dc[cx[i]]+cnt[cx[i]]*y[i]);
    }
    for(auto pr:g[x]){
        int y=pr.first;
        if(used[y]) continue;
        int i=pr.second;
        cnt[c[i]]++;
        dc[c[i]]+=dist[i];
        ds+=dist[i];
        dfs(y);
        cnt[c[i]]--;
        dc[c[i]]-=dist[i];
        ds-=dist[i];
    }
}
int main()
{
    int q;
    cin>>n>>q;
    for(int i=0; i<n-1; i++){
      int a, b;
        cin>>a>>b>>c[i]>>dist[i];
        a--; b--;
        g[a].push_back({b, i});
        g[b].push_back({a, i});
    }
    init_lca();
    for(int i=0; i<q; i++){
        int ui, vi; cin>>cx[i]>>y[i]>>ui>>vi;
        ui--; vi--;
        v[ui].push_back(i);
        v[vi].push_back(i);
        vm[lca(ui, vi)].push_back(i);
    }
    fill(used, used+n, 0);
    dfs(0);
    for(int i=0; i<q; i++) cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 30588
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using ll = long long;

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}

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

    std::vector<ll> x(N * 2), y(N * 2);
    std::vector<ll> x1(N), y1(N), x2(N), y2(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        x[i * 2] = x1[i], x[i * 2 + 1] = x2[i];
        y[i * 2] = y1[i], y[i * 2 + 1] = y2[i];
    }

    std::sort(x.begin(), x.end());
    x.erase(std::unique(x.begin(), x.end()), x.end());
    std::sort(y.begin(), y.end());
    y.erase(std::unique(y.begin(), y.end()), y.end());
    std::map<ll, int> revx, revy;
    for (int i = 0; i < x.size(); ++i) revx[x[i]] = i;
    for (int i = 0; i < y.size(); ++i) revy[y[i]] = i;

    auto imos = Vec<int>(x.size(), y.size(), 0);
    for (int i = 0; i < N; ++i) {
        ++imos[revx[x1[i]]][revy[y1[i]]];
        --imos[revx[x1[i]]][revy[y2[i]]];
        --imos[revx[x2[i]]][revy[y1[i]]];
        ++imos[revx[x2[i]]][revy[y2[i]]];
    }

    for (int i = 0; i < x.size(); ++i) {
        for (int j = 1; j < y.size(); ++j) {
            imos[i][j] += imos[i][j - 1];
        }
    }

    for (int j = 0; j < y.size(); ++j) {
        for (int i = 1; i < x.size(); ++i) {
            imos[i][j] += imos[i - 1][j];
        }
    }

    ll ans = 0;
    for (int i = 0; i < x.size() - 1; ++i) {
        for (int j = 0; j < y.size() - 1; ++j) {
            if (imos[i][j] > 0) ans += (x[i + 1] - x[i]) * (y[j + 1] - y[j]);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 66148
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << p.first << " " << p.second;
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < (int)v.size(); i++)
        os << v[i] << (i + 1 != v.size() ? " " : "");
    return os;
}

void solve()
{
    int s, w;
    cin >> s >> w;
    if (s > w)
    {
        cout << "safe" << endl;
    }
    else
        cout << "unsafe" << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
const int N=2e3+9;
using namespace std;
int g[N][N],l[N],r[N],n,m,a[N][N],ans,stk[N];
char s[N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	 {
	 	scanf("%s",&s);
	 	for(int j=0;j<m;++j)  a[i][j+1]=(s[j]=='.');
     }
/*for(int i=1;i<=n;++i)
 {
 	for(int j=1;j<=m;++j)
 	 printf("%d",a[i][j]);
 	cout<<endl;
 }*/
    for(int i=2;i<=m;++i) g[1][i]=1;
	for(int i=2;i<=n;++i)
	 for(int j=2;j<=m;++j)
	  g[i][j]=((a[i][j]==a[i-1][j]&&a[i][j-1]==a[i-1][j-1])
	          ||(a[i][j]==(a[i-1][j]^1))&&(a[i][j-1]==(a[i-1][j-1])^1))?
			  g[i-1][j]+1:1;
//for(int i=1;i<=n;++i)
// {
//    for(int j=1;j<=m;++j)
//	 printf("%d ",g[i][j]);
//	cout<<endl;	
// }	
	for(int i=2;i<=n;++i)
	{
	   int k[N];
	   memset(k,0,sizeof(k));memset(stk,0,sizeof(stk));r[0]=0;
	   for(int j=2;j<=m;++j) k[j]=g[i][j];
	   int tot=0;
	   for(int j=2;j<=m;++j)
	   {
	      r[j]=j;l[j]=j;
	   	  while(tot>0&&k[stk[tot]]>=k[j]) l[j]=l[stk[tot]],r[stk[tot]]=max(r[stk[tot]],r[stk[tot+1]]),tot--;
	      stk[++tot]=j;
	   }
	   if(tot>1) tot--;
       while(tot>0) r[stk[tot]]=max(r[stk[tot]],r[stk[tot+1]]),tot--;

//for(int i=2;i<=m;++i)
// printf("%d: l:%d r:%d\n",i,l[i],r[i]);
//cout<<endl;

	   for(int j=2;j<=m;++j) 
	     ans=max(ans,(r[j]-l[j]+2)*k[j]);
	} 
	cout<<max(ans,max(n,m))<<endl;
	return 0;
}
/*
2 3
.##
#..
*/

Measured memory_bytes: 31744
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    ll a[n][2];
    for(int i = 0; i < n; i++){
        ll x , y;
        cin>>x>>y;
        a[i][0] = x;
        a[i][1] = y;
    }
    bool flag = 0;
    for(int i = 0; i <= n - 3; i++){
        if(a[i][0] == a[i][1] && a[i + 1][0] == a[i + 1][1] && a[i + 2][0] == a[i + 2][1]){
            flag = 1;
        }
    }   
    if(flag){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
}

Measured memory_bytes: 3644
import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int K = sc.nextInt();
      int S = sc.nextInt();
            
      int count = 0;
      
      for(int x=0; x<=K; x++){
        for(int y=0; y<=K; y++){         
          if(0 <=S-x-y && S-x-y <=K){
           count ++; 
          }
        }
      }
            
      System.out.println(count);
    }  
}  

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

using namespace std;

int main(){
	long long int a, b;
	cin >> a >> b;
	long long int ans = a*b;
	for (int i = 50000; i > 1; i--){
		if (a%i == 0 && b%i == 0){
			ans /= i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define F first
#define S second
using namespace std;
typedef pair<int,int> PR;
int n, m, k, ans;
PR a[100005];
int main() {
	scanf("%d%d", &n, &m);
	for(int i=0; i<m; i++) scanf("%d%d", &a[i].S, &a[i].F);
	sort(a, a+m);
	for(PR x:a) if(x.S>=k) ans++, k = x.F;
	printf("%d", ans);
	return 0;
}

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



int32_t main()
{


	string s;


	int T = 1;


	//cin >> T;


	while (T--)
	{

		cin >> s;

		int ans = 0;


		if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
			ans = 3;
		else if (s[0] == 'R' && s[1] == 'R' || s[1] == 'R' && s[2] == 'R')
			ans = 2;
		else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
			ans = 1;

		cout << ans << endl;

	}


}

Measured memory_bytes: 3592
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
vector<int> g[200020];
int d[200020];
bool used[200020];
void dfs(int x){
    used[x]=1;
    for(auto y:g[x]){
        if(!used[y]){
            d[y]=d[x]+1;
             dfs(y);
        }
    }
}
int main()
{
	cin>>n;
    for(int i=0; i<n-1; i++){
        int x, y; cin>>x>>y; x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0);
    int r=0;
    for(int i=1; i<n; i++){
        if(d[r]<d[i]) r=i;
    }
    fill(used, used+n, 0);
    d[r]=0;
    dfs(r);
    if(*max_element(d, d+n)%3==1) cout<<"Second"<<endl;
    else cout<<"First"<<endl;
	return 0;
}

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

typedef long long ll;

int main(){
    ll N, M; cin >> N >> M;
    
    ll ans=0;
    if((N-2)<0 || (M-2)<0){
        if(N==1&&M==1) ans = 1;
        else if(N==1 || M==1){
            ans = max(N,M)-2;
        }
    }
    else
        ans = (N-2)*(M-2);
    
    cout << ans << endl;
}


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

int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	bool f=true;
	for(char c = 'a';c <= 'z';c++){
		int a = count(s.begin(),s.end(),c);
		if(!a){
			cout << c << endl;
			f = false;
			break;
		}
	}
	if(f) cout << "None" << endl;
	
	return 0;
}

Measured memory_bytes: 512
import javax.swing.*;
import java.util.*;
import java.io.*;


public class Main {
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }


    }
    public class pair {
        int a;
        int b;

        pair(int p, int q) {
            a = p;
            b = q;
        }
        public int hashCode() {
            return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
        }
    }

    public static int gcd(int a, int b) {
        if (a == 1 || b == 1)
            return 1;
        if (a == 0)
            return b;
        if (b == 0)
            return a;
        return gcd(b % a, a);
    }






    public static void main(String[] args) {
        FastReader s = new FastReader();
        String str=s.next();
        String str1=s.next();
        int n1=s.nextInt();
        int n2=s.nextInt();
        String str2 = s.next();
        if(str2.equals(str))
        {
            System.out.println(n1-1+" "+n2);
        }
        else {
            System.out.println(n1 + " "+ (n2-1));
        }

    }


}









Measured memory_bytes: 21076
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int n;
int w;
int line[31][2];
int perm[31];

int main() {
	cin >> n;
	cin >> w;
	for (int i = 0; i < w; i++) {
		scanf("%d,%d", &line[i][0], &line[i][1]);
	}

	for (int i = 1; i <= n; i++) {
		int pt = i;
		for (int j = 0; j < w; j++) {
			if (line[j][0] == pt) pt = line[j][1];
			else if (line[j][1] == pt) pt = line[j][0];
		}
		perm[pt] = i;
	}

	for (int i = 1; i <= n; i++) {
		cout << perm[i] << endl;
	}

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

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

int temp[1048577]={};
int x[4]={0,3,5,7};
int tempnum= 0;
void puttotemp(int k){
	temp[tempnum] = k;
	tempnum++;
}
void maketemp(int a,int n,int k){
	//現在の値kに3と5と7を足す
	//nは加算後の桁数
	if(n > a){
		return;
	}
	puttotemp(k*10+3);
	maketemp(a,n+1,k*10+3);
	puttotemp(k*10+5);
	maketemp(a,n+1,k*10+5);
	puttotemp(k*10+7);   
	maketemp(a,n+1,k*10+7);
}

int main(void){
	int N;
	scanf("%d",&N);
	int i,j,x;
	int flag,threeflag,fiveflag,sevenflag;
	char s[11];
	snprintf(s,11,"%d",N);//sにはNが入る
	int n = strlen(s);//nにはNの桁数が入る
	int ans = 0;
	maketemp(n,1,0);
	//printf("n = %d\n",n);
	for(i=0;i<1048576;i++){
		if( N >= temp[i]){
		}else{
			continue;
		}
		//sの0行目から753かどうか調べる
		snprintf(s,11,"%d",temp[i]);//
		flag = 0;threeflag=0;fiveflag=0;sevenflag=0;
		for(j=0;j<strlen(s);j++){
			if(s[j]=='7'){
				sevenflag=1;
			}else if(s[j]=='5'){
				fiveflag = 1;
			}else if(s[j]=='3'){
				threeflag= 1;
			}else{
				flag = -1;
			}
		}
		if(flag == 0 && sevenflag==1 && fiveflag ==1 && threeflag ==1){
			ans++;
		}
		
	}
	printf("%d",ans);
	return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

vector<int> x,a;
vector<list<int>> child;

bool dfs(int n){
  int ruiseki=0;
  int si=child[n].size();
  bool ans=true;
  vector<int> wei(si);
  int count=0,weitotal=0;
  for(auto i:child[n]){
    ans&=dfs(i);
    ruiseki+=min(x[i],a[i]);
    wei[count]=max(x[i],a[i])-min(x[i],a[i]);
    weitotal+=wei[count];
    count++;
  }
  if(ruiseki>x[n]){
    return false;
  }
  vector<vector<bool>> dp(si+1,vector<bool>(x[n]-ruiseki+1,false));
  for(int i=0;i<=si;i++) dp[i][0]=true;
  for(int i=1;i<=si;i++){
    for(int j=1;j<=x[n]-ruiseki;j++){
      dp[i][j]=dp[i-1][j];
      if(j>=wei[i-1]) dp[i][j]=dp[i][j]|dp[i-1][j-wei[i-1]];
    }
  }
  int ma=0;
  for(int i=0;i<=x[n]-ruiseki;i++) if(dp[si][i]) ma=i;
  a[n]=weitotal-ma;
  return ans;
}

int main(){
  int n;
  cin >> n;
  x=vector<int>(n);
  a=vector<int>(n,0);
  child=vector<list<int>>(n,list<int>());
  int p;
  for(int i=1;i<n;i++){
    cin >> p;
    child[p-1].push_back(i);
  }
  for(int i=0;i<n;i++) cin >> x[i];
  cout << (dfs(0)?"POSSIBLE":"IMPOSSIBLE") << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

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


Measured memory_bytes: 256
n = int(input())

e = [[] for _ in range(n)]

for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        x -= 1
        e[i].append((x, y))

ret = 0
for mask in range(1 << n):
    t = [(mask >> i) & 1 for i in range(n)]
    flg = True
    for i in range(n):
        if t[i]:
            for x, y in e[i]:
                if t[x] != y:
                    flg = False
                    break
            if not flg:
                break
    if flg:
        ret = max(ret, sum(t))

print(ret)

Measured memory_bytes: 3064
import sys


fin = sys.stdin.readline
MOD = 10**9 + 7
N = int(fin())
C_list = tuple(int(fin()) for _ in range(N))

dp = [0] * N
dp[0] = 1
past_idx = {C_list[0]: 0}
for i, C in enumerate(C_list[1:], start=1):
    if C in past_idx:
        dp[i] = dp[i - 1] + dp[past_idx[C]] if i - past_idx[C] > 1 else dp[i - 1]

    else:
        dp[i] = dp[i - 1]
    past_idx[C] = i
    dp[i] %= MOD
# print(dp)
print(dp[-1])


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

using namespace std;

int main()
{
        string s,sc;
        cin >> s;
        sc=s;
        reverse(s.begin(), s.end());
        for(int i=0;i<s.length();i++){
            if(s.at(i)=='b'){
                s.at(i)='d';
            }else if(s.at(i)=='d'){
                s.at(i)='b';
            }else if(s.at(i)=='p'){
                s.at(i)='q';
            }else if(s.at(i)=='q'){
                s.at(i)='p';
            }
        }
        if(s==sc){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        return 0;
}


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

int main() {
	string s;
	cin >> s;
	char c;
	int jud;
	for(int i=0; i<26; i++){
		c='a'+i;
		jud=0;
		for(int j=0; j<s.size(); j++){
			if(s[j]==c) jud++;
		}
		if(jud==0){
			cout << c; return 0;
		}
	}
	cout << "None";
}

Measured memory_bytes: 512
/*
author : seryu
title : AGC037A_"Dividing a String"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	string s;
	cin >> s;
	int n = sz(s);
	int ans = n;
	rep(i, n-1)
	{
		if(s[i] == s[i+1])
		{
			ans--;
			i += 2;
		}
	}
	cout << ans << endl;
	return;	
}

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


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

signed main(){
  int t,tt,a,aa,b,bb;cin>>t>>tt>>a>>aa>>b>>bb;
  if(a > b){
    a -= b;aa -= bb;
  }else{
    a = b - a, aa = bb - aa;
  }
  int p = t*a, q = tt*aa;
  if(p+q == 0){
    cout << "infinity" << endl;return 0;
  }else if(p+q > 0){
    cout << 0 << endl;return 0;
  }else if(q % (p+q) == 0){
    cout << (q/(p+q)-1)*2 << endl;
  }else{
    cout << (q/(p+q)-1)*2+1 << endl;
  }
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int N;
	cin >> N;

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

	bool ok = true;
	for (int i = 0; i < N; i++) {
		if ((A[i] & 1) == 0 && A[i] % 3 != 0 && A[i] % 5 != 0)ok = false;
	}

	if (ok) cout << "APPROVED" << "\n";
	else cout << "DENIED" << "\n";

	return 0;
}

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

int main() {
  int N;
  vector<ll> D(5, 0);
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) cin >> S[i];
  
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    char f = S[i][0];
    if (f == 'M') D[0]++;
    if (f == 'A') D[1]++;
    if (f == 'R') D[2]++;
    if (f == 'C') D[3]++;
    if (f == 'H') D[4]++;
  }
  
  ll ans = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 4; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += D[i] * D[j] * D[k];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6424
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <deque>
using namespace std;

typedef long long ll;

deque<pair<ll, ll> > v;
ll dp[2222][2222], n;

int main(void)
{
	ll a, i, j;

	scanf("%lld", &n);
	for (i = 1; i <= n; i++)
	{
		scanf("%lld", &a);
		v.push_back(make_pair(a, i));
	}

	sort(v.begin(), v.end(), greater<>());

	for (i = 1; i <= n; i++)
		for (j = i; j >= 1; j--)
		{
			ll cnt = j - 1 + n - i;

			if (i == j)
				dp[j][i] = v[cnt].first * abs(j - v[cnt].second);
			dp[j][i] = max(dp[j + 1][i] + v[cnt].first * abs(v[cnt].second - j), dp[j][i - 1] + v[cnt].first * abs(v[cnt].second - i));
		}

	printf("%lld", dp[1][n]);
	return 0;
}

Measured memory_bytes: 26560
#include <cstdio>
#include <vector>
#include <cassert>
using namespace std;

int calc(const long long start, const vector<int> &a) {
        if (start < 0) return 0;
        int n = a.size();
        long long val = start;
        for (int i = 0; i < n; i ++) {
                val = (long long) (val / a[i]) * a[i];
        }
        if (val < 2) return 0;
        else if (val == 2) return 1;
        else return 2;
}

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        for (int i = 0; i < n; i ++) {
                scanf("%d", &a[i]);
        }
        long long lb = 0, ub = 1e18;
        long long ok = -1;
        int cnt = 100;
        while (cnt --) {
                long long mid = (lb + ub) / 2;
                int get = calc(mid, a);
                if (get == 0) {
                        lb = mid;
                } else if (get == 2) {
                        ub = mid;
                } else {
                        ok = mid;
                        break;
                }
        }
        if (!~ok) {
                return !printf("-1\n");
        }
        long long milb = 0, miub = ok + 1;
        while (miub - milb > 1) {
                long long mid = (milb + miub) / 2;
                int get = calc(mid, a);
                assert(get != 2);
                if (get == 0) {
                        milb = mid;
                } else {
                        miub = mid;
                }
        }
        long long malb = ok, maub = 1e18 + 10;
        while (maub - malb > 1) {
                long long mid = (malb + maub) / 2;
                int get = calc(mid, a);
                assert(get != 0);
                if (get == 1) {
                        malb = mid;
                } else {
                        maub = mid;
                }
        }
        printf("%lld %lld\n", miub, malb);
        //for (long long mi = miub - 5; mi <= miub + 5; mi ++) {
        //        if (calc(mi, a) == 1) {
        //                printf("%d ", mi);
        //                break;
        //        }
        //}
        //for (long long ma = malb + 5; ma >= malb - 5; ma --) {
        //        if (calc(ma, a) == 1) {
        //                printf("%d\n", ma);
        //                break;
        //        }
        //}
        return 0;
}


Measured memory_bytes: 640
package main

import "fmt"

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

	res := 9999999999
	for i := 1; i <= 100; i++ {
		tmp := 0

		for j := 0; j < n; j++ {
			run := x[j] - i
			tmp += run * run
		}
		if tmp < res {
			res = tmp
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{
    int W,a,b,t;
    cin>>W>>a>>b;
    if(a<b)
    {
        t=a;
        a=b;
        b=t;
    }
    if(a-b<=W)
        cout<<"0"<<endl;
    else
        cout<<a-b-W<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>

using namespace std;

int main(void){

    long long int n;
    cin>>n;
    long long int sum = 0;

    //sum = ((1+n-1)*(n-1))/2.0;

    for(int i=1;i<n;i++) sum += i;
    cout<<sum<<endl;
}


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

using namespace std;

using ll = long long;

const int INF = 1e9;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector< vector<int> > a(2, vector<int>(n));
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }

    int ans = INF;
    vector< vector< deque<int> > > ids(2, vector< deque<int> >(51));
    for (int i = 0; i < (1 << n); ++i) {
        if (__builtin_popcount(i) % 2 == 1) continue;

        vector<int> v(n);
        for (int j = 0; j < n; ++j) {
            v[j] = a[i >> j & 1][j];
        }
        sort(v.begin(), v.end());
 
        int rest = n;
        for (int j = 0; j < n; ++j) {
            ids[j % 2][v[j]].push_back(j);
        }
 
        int memo = 0;
        vector<int> nex(n, -1);
        for (int j = 0; j < n; ++j) {
            int hoge = i >> j & 1;
            deque<int>& d = ids[abs(j % 2 - hoge)][a[hoge][j]];
            if (d.empty()) {
                memo = INF;
                break;
            }
            nex[j] = d.front();
            d.pop_front();
            rest--;
        }
 
        for (int j = 0; j < n; ++j) {
            ids[j % 2][v[j]].clear();
        }
 
        if (memo >= INF || rest > 0) continue;
        memo = 0;
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < j; ++k) {
                if (nex[k] > nex[j]) memo++;
            }
        }
        ans = min(ans, memo);
    }
    cout << (ans >= INF ? -1 : ans) << "\n";
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#define MAX 10000
#define BMAX 1000
int max(int a,int b){
 if(a > b)return a;
 return b;
}

int min(int a,int b){
 if(a > b)return b;
 return a;
}

int main(){
 int n,q;
 int i,j,k;
 int an,vn,x;
 int maxi;
 int *A;
 int B[BMAX];
 int b,L,R;
 int idx;

 scanf("%d %d",&n,&q);
 b=max(floor(sqrt(n)),4);
 A=(int *)malloc(sizeof(int) * 1000001);

 for(i=0;i<n;i++){
  A[i]=0;
 }
 for(i=0;i<BMAX;i++){
  B[i]=0;
 }

 for(i=0;i<q;i++){

  /*update*/
   scanf("%d %d",&an,&vn);
   x=an-1;
   A[x]+=vn;
   maxi=A[(x/b)*b];
   R=min((x/b+1)*b-1,n-1);
   for(j=(x/b)*b+1;j<=R;j++)maxi=max(maxi,A[j]);
   B[x/b]=maxi;

  /*find*/
   maxi=-1;
   for(j=0;j<=(n-1)/b;j++){
     if(B[j] > maxi){
       maxi=B[j];
       idx=j;
     }
    }

   for(k=b*idx;k<b*(idx+1);k++){
     if(A[k]==maxi){
       printf("%d %d\n",k+1,maxi);
       break;
     }
   }

 }

return 0;
}
    


Measured memory_bytes: 5708
//Author: Lixiang
#include<stdio.h>
inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int _read(){
    char ch=nc();int sum=0;
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum;
}
inline char __read(){
	char ch=nc();
	while(ch<'a'||ch>'z')ch=nc();
	return ch;
}
inline int max(int a,int b){
	return a>b?a:b;
}
struct C{
	int cnt[27];
	int N,M;
	void init(){
		N=_read();M=_read();
		for(int i=1;i<=N;i++)
			for(int j=1;j<=M;j++)
				cnt[__read()-'a']++;
	}
	void work(){
		int cnt1=0,cnt2=0;
		bool ans;
		if(N%2==1){
			if(M%2==1){
				for(int i=0;i<26;i++)
					if(cnt[i]%2!=0)cnt1++;
					else if(cnt[i]%4!=0)cnt2++;
				if(cnt1>1)ans=0;
				else
					if(cnt2>N/2+M/2)ans=0;
					else ans=1;
			}
			else{
				for(int i=0;i<26;i++)
					if(cnt[i]%2!=0)cnt1++;
					else if(cnt[i]%4!=0)cnt2++;
				if(cnt1>0)ans=0;
				else
					if(cnt2>M/2)ans=0;
					else ans=1;
				
			}
		}
		else{
			if(M%2==1){
				for(int i=0;i<26;i++)
					if(cnt[i]%2!=0)cnt1++;
					else if(cnt[i]%4!=0)cnt2++;
				if(cnt1>0)ans=0;
				else
					if(cnt2>N/2)ans=0;
					else ans=1;
			}
			else{
				for(int i=0;i<26;i++)
					if(cnt[i]%2!=0)cnt1++;
					else if(cnt[i]%4!=0)cnt2++;
				if(cnt1>0||cnt2>0)ans=0;
				else ans=1;
			}
		}
		puts(ans?"Yes":"No");
	}
}sol;
int main(){
	sol.init();
	sol.work();
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    if(n<=k)cout << n*x << endl;
    else cout << ((k*x)+(n-k)*y) << endl;
    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;

    int ans = 0;
    if (a >= 13) ans = b;
    else if (a >= 6) ans = b/2;

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


Measured memory_bytes: 256