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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

const int N = 1e2+2;
int x, n;
int freq[N];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> x >> n;
    memset(freq,0,sizeof(freq));
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        freq[x] = 1;
    }
    int ans = 0;
    int l, r;
    for (l = x; l >= 1 && freq[l]; l--);
    for (r = x; r <= 100 && freq[r]; r++);
    // cout << l << ' ' << r << '\n';
    if (abs(l-x) < abs(ans-x))
        ans = l;
    if (abs(r-x) < abs(ans-x))
        ans = r;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3644
from queue import Queue

H, W =  list(map(int, input().split()))
s = [input() for _ in range(H)]
 
y = "."
n = "#"

D = [[0] * W for _ in range(H)]
num = 0
for i in range(H):
  for j in range(W):
    if s[i][j] == y:
      num += 1
    else:
      D[i][j] = -1

def setWall(D, x):
  H = len(D)
  W = len(D[0]) + 2
  D = [[x] * W] + [[x] + [i for i in j] + [x] for j in D] + [[x] * W] 
  return D

D = setWall(D, -1)

D[1][1] = 1
Q = Queue()
Q.put([1, 1])
while Q.empty() != True:
  x, y = Q.get()
  t = D[x][y]
  for i in (-1, 1):
    for j in (0, 1):
      a = j * i
      b = (1 - j) * i
      if D[x + a][y + b] > t + 1 or D[x + a][y + b] == 0:
        D[x + a][y + b] = t + 1
        Q.put([x + a, y + b])

if D[H][W] == 0:
  print(-1)
else:
  print(num - D[H][W])



Measured memory_bytes: 3952
n = int(input())
V = [int(x) for x in input().split(" ")]

# print(n)
# print(V)

dict0 = {}
dict1 = {}

for i in range(0, n, 2):
    v = V[i]
    if v in dict0:
        dict0[v] += 1
    else:
        dict0[v] = 1

for i in range(1, n, 2):
    v = V[i]
    if v in dict1:
        dict1[v] += 1
    else:
        dict1[v] = 1

# 多い順にソート(タプルに変えた後、dictの値部分(x[1])でソート)
d0 = sorted(dict0.items(), key=lambda x: x[1], reverse=True)
d1 = sorted(dict1.items(), key=lambda x: x[1], reverse=True)

# print(d0)
# print(d1)


n = int(n/2)
if (d0[0][0] != d1[0][0]):
    ret = (n - d0[0][1]) + (n - d1[0][1])
else:
    d1_1_1 = 0
    if len(d1) > 1:
        d1_1_1 = d1[1][1]
    r1 = (n - d0[0][1]) + (n - d1_1_1)

    d0_1_1 = 0
    if len(d0) > 1:
        d0_1_1 = d0[1][1]
    r2 = (n - d0_1_1) + (n - d1[0][1])
    ret = min(r1, r2)

print(ret)


Measured memory_bytes: 22752
from itertools import permutations
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
m = [set() for _ in range(27)]
for a, b in AB:
    m[a].add(b)
    m[b].add(a)

def main():
    ans = []
    def traverse(n, visits):
        visits = visits | set([n])
        if len(visits) == N:
            ans.append(1)
            return
        for c in m[n] - visits:
            traverse(c, visits)
    traverse(1, set())
    return len(ans)

print(main())

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
int N, M, D[100010]; 
int INF = 1145141919; 
pair<int, int> A[100010]; 
vector<int> E[100010]; 
map<pair<int, int>, int> mp;
vector<int> ans;  
bool seen[100010];
void dfs(int i, int p){
	if(seen[i]) return; 
	seen[i] = true; 
	for(int j = 0; j < E[i].size(); j++){
		if(seen[E[i].at(j)]) continue; 
		dfs(E[i].at(j), i); 
	}
	if(D[i] % 2){
		D[i] ++; D[p] ++; 
		ans.push_back(mp[make_pair(i, p)]); 
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> M; 	
	for(int i = 0; i < N; i++){
		cin >> A[i].first >> A[i].second; 
	}
	A[N].first = -INF; A[N].second = 0; 
	A[N+1].first = INF; A[N+1].second = 0; 
	sort(A, A+N+2); 
	for(int i = 0; i < N+1; i++){
		D[i] = (A[i+1].second ^ A[i].second); 
	}
	for(int i = 0; i < M; i++){
		int L, R; cin >> L >> R; 
		int a = lower_bound(A, A+N+2, make_pair(L, 0)) - A - 1; 
		int b = upper_bound(A, A+N+2, make_pair(R, 2)) - A - 1; 
		if(a == b) continue; 
		E[a].push_back(b); E[b].push_back(a);
		mp[make_pair(a, b)] = i + 1; 
		mp[make_pair(b, a)] = i + 1;  
	}
	for(int i = 0; i < N+1; i++) dfs(i, 100008);
	if(D[100008]){
		cout << -1 << endl; return 0; 
	}
	sort(ans.begin(), ans.end()); 
	cout << ans.size() << endl; 
	for(int i = 0; i < ans.size(); i++){
		cout << ans.at(i) << " "; 
	}
	cout << endl; 
}

Measured memory_bytes: 41596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,h,maxh=0,r=0;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>h;
    if(maxh<=h){
      r++;
      maxh=h;
    }
  }
  cout<<r<<endl;
  return 0;
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  ll r,D,x;
  cin >> r >> D >> x;
  rep(i,10){
    x = r*x-D;
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
  {
int n,k;
cin>>n>>k;
long long ans=0;
long long a;
for(int i=0;i<n;i++) {
    cin>>a;
    if(a>=k) ans++;
}
cout<<ans<<endl;
   }









Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;

int n, a, b, c;
vector<int> l;
int dfs(int d, int la, int lb, int lc) {
  if(d == n) {
    if(la == 0 || lb == 0 || lc == 0) return INF; 
    return abs(la - a) + abs(lb - b) + abs(lc - c) - 30;
  }
  int res = INF;
  chmin(res, dfs(d + 1, la, lb, lc));
  chmin(res, dfs(d + 1, la + l[d], lb, lc) + 10);
  chmin(res, dfs(d + 1, la, lb + l[d], lc) + 10);
  chmin(res, dfs(d + 1, la, lb, lc + l[d]) + 10);
  return res;
}

int main() {
  cin >> n >> a >> b >> c;
  l.resize(n);
  rep(i, n) {
    cin >> l[i];
  }
  int ans = dfs(0, 0, 0, 0);
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int partition(vector<int> &A, int p, int r) {
    int x = A[r];
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }

    int a = partition(A, 0, N - 1);
    for (int i = 0; i < a; i++) {
        cout << A[i] << " ";
    }
    cout << "[" << A[a] << "]"
         << " ";
    for (int i = a + 1; i < N - 1; i++) {
        cout << A[i] << " ";
    }
    cout << A[N - 1] << endl;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int S(int n){
  int ret=0;
  while(n){
    ret+=n%10;
    n/=10;
  }
  return ret;
}
signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N; cin >> N;

  Yes(N%S(N)==0);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    int N,M;
    cin >> N >> M;
    vector<string> A(N),B(M);
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];
    bool same = false;
    
    for (int i = 0; i+M-1 < N; i++) {
        for (int j = 0; j+M-1 < N; j++) {
            same = true;
            rep(k,M) rep(l,M){
                if(A[i+k][j+l] != B[k][l]) same = false;;
            }
            if(same){
                cout << "Yes" << endl;
                return 0;
            }
            
        }
    }
    
    cout << "No" << endl;
    return 0;
    
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<set>
using namespace std;
int main(){
    int N;
    int d[N];
    cin>>N;
    for(int i=0; i<N; i++){
        cin>>d[i];
    }    
        set<int>values;
        for(int j=0; j<N; j++){
            values.insert(d[j]);
        }
        cout<<values.size()<<endl;
    
    
}


Measured memory_bytes: 256
#include "iostream"

using namespace std;

int main(){
    int n,x;
    cin >> n >> x;
    int l;
    int L=0;
    int cnt=1;
    for(int i=0;i<n;i++){
        cin >> l;
        L += l;
        if (L <= x){
            //cout << L << endl;
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

int n,p[20],ans=0;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){cin>>p[i];}
    for(int i=1;i<n-1;i++){
        if(p[i]<max(p[i-1],p[i+1]) && p[i]>min(p[i-1],p[i+1])){ans++;}
    }
    cout<<ans<<endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string zentai = "";

  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    zentai += s;
  }

  for (int i = 0; i < H * W; i++){
    if (zentai.at(i) == '#') {
      cout << '#';
    } else if (zentai.at(i) == '.'){
      	int count = 0;
      	int x = i % W;
      	int y = i / W;

//////// xが0より大きくyも0より大きく、iの（左隣 + 1段上）が # だったら
//////// ↓
//////// iが一番左ではなく一番上でもなく、iの左上が # だったら

      	if (x - 1 >= 0 && y - 1 >= 0 && zentai.at(x - 1 + (y - 1) * W) == '#'){
        	count++;
      	}

//////// yが0より大きく、iの（1段上）が # だったら
//////// ↓
//////// iが一番上ではなく、iの上が # だったら

      	if (y - 1 >= 0 && zentai.at(x + (y - 1) * W) == '#'){
        	count++;
      	}

//////// xがW - 1より小さくyが0より大きく、iの（右隣 + 1段上）が # だったら
//////// ↓
//////// iが一番右ではなく一番上でもなく、iの右上が # だったら

      	if (x + 1 < W && y - 1 >= 0 && zentai.at(x + 1 + (y - 1) * W) == '#'){
        	count++;
      	}

//////// xが0より大きく、iの（左隣）が # だったら
//////// ↓
//////// iが一番左ではなく、iの左が # だったら

      	if (x - 1 >= 0 && zentai.at(x - 1 + y * W) == '#'){
        	count++;
      	}

//////// xがW - 1より小さく、iの（右隣）が # だったら
//////// ↓
//////// iが一番右ではなく、iの右が # だったら

      	if (x + 1 < W && zentai.at(x + 1 + y * W) == '#'){
        	count++;
      	}

//////// xが0より大きくyがH - 1より小さく、iの（左隣 + 1段下）が # だったら
//////// ↓
//////// iが一番左ではなく一番下でもなく、iの左下が # だったら

      	if (x - 1 >= 0 && y + 1 < H && zentai.at(x - 1 + (y + 1) * W) == '#'){
        	count++;
      	}

//////// yがH - 1より小さく、iの（1段下）が # だったら
//////// ↓
//////// iが一番下ではなく、iの下が # だったら

      	if (y + 1 < H && zentai.at(x + (y + 1) * W) == '#'){
        	count++;
      	}

//////// xがW - 1より小さくyがH - 1より小さく、iの（右隣 + 1段下）が # だったら
//////// ↓
//////// iが一番右ではなく一番下でもなく、iの右下が # だったら

      	if (x + 1 < W && y + 1 < H && zentai.at(x + 1 + (y + 1) * W) == '#'){
        	count++;
      	}

      cout << count;
    }

    if ((i + 1) % W == 0){
      cout << endl;
    }
  }
}

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

int h,w;
bool a[110][110];
int main()
{
	cin >> h >> w;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			char tmp;
			cin >> tmp;
			a[i][j] = (tmp == '#') ? true : false;
		}
	}

	bool hf[110],wf[110];
	for(int i = 0;i < 110;i++){
		hf[i] = false;
		wf[i] = false;
	}
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			hf[i] |= a[i][j];
		}
	}

	for (int i = 0; i < w; i++)
	{
		for (int j = 0; j < h; j++)
		{
			wf[i] |= a[j][i];
		}
	}

	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if(hf[i] && wf[j]){
				cout << ((a[i][j])? "#" : ".");
			}
		}
		if(hf[i] || i == h-1)cout << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int K=stdIn.nextInt();
		boolean sunuke[]=new boolean[N];
		int ans=N;
		for(int i=0;i<K;i++){
			int a=stdIn.nextInt();
			for(int j=0;j<a;j++){
				int b=stdIn.nextInt()-1;
				if(sunuke[b]==false)
					ans--;
				sunuke[b]=true;
			}
		}
		System.out.println(ans);
	}
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int N,M,X;
int C[12];
int A[12][12];

int solve() {
    cin >> N >> M >> X;
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        for (int j = 0; j < M; j++) cin >> A[i][j];
    }
    int minc = INT_MAX;
    for (int i = 0; i < (1<<N); i++) {
        vector<int> Mv(M);
        int cost = 0;
        for (int j = 0; j < N; j++) {
            if (i&(1<<j)) {
                cost += C[j];
                for (int k = 0; k < M; k++) {
                    Mv[k] += A[j][k];
                }
            }
        }
        bool valid = true;
        for (int j = 0; j < M; j++) {
            if (Mv[j] < X) {
                valid = false;
                break;
            }
        }
        if (valid) {
            minc = min(minc, cost);
        }
    }

    if (minc == INT_MAX) {
        return -1;
    }
    
    return minc;
}

int main() {
    int T = 1; 
    // cin >> T;
    for (int t = 1; t <= T; t++)
        // cout << "Case #" << t << ": " << solve() << "\n";
        cout << solve() << "\n";
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back
#define FOR(x, n) for(int i=x; i<=n; ++i)

int main() {

    string s, t;
    cin>>s>>t;

    int len1 = (int) s.length();
    int len2 = (int) t.length();

    int ans = INT_MAX;

    for(int i=0; i<=len1-len2; ++i) {

        int c = 0;

        for(int j=0, k=i; j<len2; ++j, ++k) {
            if(s[k] != t[j]) {
                c++;
            }
        }
        ans = min(ans, c);
    }

    printf("%d\n", ans);
}



Measured memory_bytes: 3688
import java.util.Scanner;

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

		int pre = Integer.parseInt(S.substring(0, 2));
		int post = Integer.parseInt(S.substring(2));

		if((0 < pre && pre < 13) && (0 < post && post < 13)) {
			System.out.println("AMBIGUOUS");
		} else if (0 < pre && pre < 13) {
			System.out.println("MMYY");
		} else if (0 < post && post < 13) {
			System.out.println("YYMM");
		} else {
			System.out.println("NA");
		}
	}
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int64_t> A(n);
    copy_n(istream_iterator<int64_t>(cin), n, A.begin());
    vector<vector<int>> B(n + 1, vector<int>(62)), C(n + 1, vector<int>(62));
    const int64_t p = 1e9 + 7;
    sort(A.begin(), A.end());

    for (int i = 0; i < n; i++){
        for (int j = 0; j <= 61; j++){
            if (A[i] >> j == 0)
                break;
            B[i + 1][j] = B[i][j];
            C[i + 1][j] = C[i][j];
            if ((A[i] >> j) & 1)
                B[i + 1][j]++;
            else
                C[i + 1][j]++;
        }
    }

    int64_t ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= 61; j++){
            ans += (1LL << j) % p * (((A[i] >> j) & 1) ? (C[n][j] - C[i + 1][j]) : (B[n][j] - B[i + 1][j]));
            ans %= p;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 166656
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int n;cin>>n;
	if(n%1000==0){
		cout<<0;return 0;
	}
	cout<<(1000-n%1000);
}

Measured memory_bytes: 3632
n,m=map(int,input().split())
l=list(map(int,input().split()))
if n>=m:
  print(0)
else:
  l.sort()
  k=[]
  for i in range(m-1):
    x=l[i+1]-l[i]
    k.append(x)
  k.sort()
  sum=0
  for i in range(m-n):
    sum+=k[i]
  print(sum)


Measured memory_bytes: 13968
import sys
input = sys.stdin.readline

n, k = [int(x) for x in input().split()]
flag = [0]*n
for _ in range(k):
    d = int(input())
    a = [int(x) for x in input().split()]
    for i in a:
        flag[i - 1] = 1
ans = 0
for i in flag:
    if not i:
        ans += 1
print(ans)






Measured memory_bytes: 67528
n,m,k=map(int,input().split())
mod=10**9+7
A=n*m-2
from math import factorial
def Comb(N, K):
    a = factorial(N) % mod
    b = factorial(K) % mod
    c = factorial(N-K) % mod
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
v=Comb(A,k-2)
t=0
y=0
for i in range(1,n):
  t+=i*(n-i)*m*m%mod
for i in range(1,m):
  y+=i*(m-i)*n*n%mod

ans=v*(t+y)
print(ans%mod)

Measured memory_bytes: 72924
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(void) {
  ll n;
  cin >> n;
  char ori = 'a' - 1;
  vector<int> a(0);
  for (; n > 0; n /= 26) {
    if (n % 26 == 0) {
      a.push_back(26);
      n -= 26;
    } else {
      a.push_back(n % 26);
    }
  } 
  for (int i = a.size() - 1; i >= 0; i--) {
    cout << char(ori + a[i]);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    int N;

    cin >> N;

    double X[N];

    for(int i=0;i<N;i++){
        cin >> X[i];
    }

    double sum[100];

    for(int i=0;i<100;i++){
        sum[i] = 0;
        for(int j=0;j<N;j++){
            sum[i] += pow(X[j]-(i+1),2);
        }
    }

    double min = sum[0];
    for(int i=0;i<100;i++){
        if(min >= sum[i]){
            min = sum[i];
        }
    }

    cout << min << endl;

    return 0;



}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
string s;
bool jadge(char a) {
	char b[11] = { 'y','h','n','u','j','m','i','k','o','l','p' };
	for (int i = 0; i < 11; i++) {
		if (a == b[i])return 1;
	}
	return 0;
}


int main() {
	while (cin >> s) {
		if (s == "#")return 0;
		int m = s.length();
		bool b[33];
		for (int i = 0; i < m; i++) {
			if (jadge(s[i])) {
				b[i] = 1;
			}
			else {
				b[i] = 0;
			}
		}
		int cont = 0;
		for (int i = 1; i < m; i++) {
			if (b[i] != b[i - 1]) {
				cont++;
			}
		}
		cout << cont << endl;
	}
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

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

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
LL ave(LL, LL);

int main() {
	int a, b; cin >> a >> b;
	if (isEven(a + b)) {
		cout << ave(a, b);
	}
	else {
		cout << "IMPOSSIBLE";
	}
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}
LL ave(LL a, LL b) {
	return (a + b) / 2;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
deque<int> Era(int n) {
    deque<int> arr(n+1,1);
    deque<int> prime;
    arr[0]=0;
    arr[1]=0;
    for (int i=2;i*i<n;i++) {
        if (arr[i]==1) {
            for (int j=i*i;j<n;j+=i) {
                arr[j]=0;
            }
        }
    }
    for (int k=2;k<=n;k++) {
        if (arr[k]==1) {
            prime.emplace_back(k);
        }
    }
    return prime;
}
int main(void){
    std::deque<int> deq;
    deq=Era(110000);
    int x;
    cin>>x;
    auto itr=lower_bound(deq.begin(),deq.end(),x);
    cout<<*itr<<endl;
}

Measured memory_bytes: 768
S = input().split()

count1 = 0
count2 = 0

for s in S: 
  if s == "5":
    count1 += 1
  elif s == "7":
    count2 += 1
  
if count1 == 2 and count2 == 1:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 2940
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 303;
const int mod = 1e9 + 7;

inline int add(int a, int b) {
  return a+b >= mod ? a+b-mod : a+b;
}

inline int sub(int a, int b) {
  return a >= b ? a-b : a-b+mod;
}

inline int mul(int a, int b) {
  return llint(a)*b % mod;
}

int c[MAX][MAX];
int f[MAX][MAX][MAX];
int pw[MAX*MAX];

int main(void) {
  int N;
  scanf("%d", &N);
  REP(i, N) REP(j, N) scanf("%d", &c[i][j]);


  int r = 0;
  REP(i, N) {
    int k = -1;
    FOR(j, r, N)
      if (c[j][i]) { k = j; break; }
    if (k == -1) continue;
      
    REP(j, N) swap(c[r][j], c[k][j]);
    REP(j, N)
      if (j != r && c[j][i])
        REP(k, N) c[j][k] ^= c[r][k];
    r++;
  }

  pw[0] = 1;
  FOR(i, 1, MAX*MAX) pw[i] = mul(pw[i-1], 2);
  
  f[0][0][0] = 1;
  REP(i, N) REP(rc, min(i+1, r+1)) REP(rn, min(i+1-rc, N-r+1)) {
    f[i+1][rc][rn] = add(f[i+1][rc][rn], mul(pw[rc+rn], f[i][rc][rn]));
    if (rc < r) {
      f[i+1][rc+1][rn] = add(f[i+1][rc+1][rn], mul(sub(pw[r+rn], pw[rc+rn]), f[i][rc][rn]));
    }
    if (rn < N-r) {
      f[i+1][rc][rn+1] = add(f[i+1][rc][rn+1], mul(sub(pw[N], pw[r+rn]), f[i][rc][rn]));
    }
  }

  int ans = 0;
  REP(rn, N-r+1) ans = add(ans, mul(pw[N*(N-rn-r)], f[N][r][rn]));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 55552
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
         Scanner scan = new Scanner(System.in);
         int a = scan.nextInt();
         int b = scan.nextInt();
         int c = scan.nextInt();
      
         if (a < b && b < c) {
             System.out.println("Yes");
         }
         else {
             System.out.println("No");
         }
     }
 }

Measured memory_bytes: 26124
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)
int p[100010];
int main(){
    int n, k, q;
    cin >> n >> k >> q;
    rep(i,1,n+1){
        p[i] = k - q;
    }
    rep(i,0,q){
        int a;
        cin >> a;
        p[a]++;
    }
    rep(i,1,n+1){
        if(0 < p[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

#define black 1
#define white 0
#define gray 2

void dfs(void);
void visit(int);

int fi[110];
int di[110];
int color[110];
int time;
int num;
int a[110][110];

int main(){
  int sum,elem,in;
  int i,j;

  scanf("%d",&num);

  for(i=1;i<=num;i++){
    for(j=1;j<=num;j++) a[i][j]=white;
  }
  
  for(i=1;i<=num;i++){
    scanf("%d%d",&elem,&sum);

    if(sum==0) continue;

    for(j=1;j<=sum;j++){
      scanf("%d",&in);
      a[elem][in]=black;
    }
  }
  
  dfs();

  for(i=1;i<=num;i++){
    printf("%d %d %d\n",i,di[i],fi[i]);
  }
  
  return 0;
}

void dfs(void){
  int i;
  for(i=1;i<=num;i++) color[i]=white;//syokika
  time=0;
  
  for(i=1;i<=num;i++){//black ni narumade
    if(color[i]==white) {
      visit(i);
    }
  }
}

void visit(int k){
  int i;
  color[k]=gray;//tootta
  di[k]=++time;
  
  for(i=1;i<=num;i++){
    if(a[k][i]==black){//tooreru
      if(color[i]==white) visit(i);//mada tootteinai
    }
  }
  
  color[k]=black;
  fi[k]=++time;
  
}




Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
typedef long long ll;
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

const int MAXk = 61;
const ll MOD = 1e9 + 7;

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    mint ans = 0;
    rep(i, 0, N) cin >> A[i];

    rep(i, 0, MAXk){
        mint t = 0, f = 0;
        rep(j, 0, N){
            if((1LL << i) & A[j]) t = t + 1;
            else f = f + 1;
        }
        //cout << i << " "<< t << " " << f << endl;
        ans = (ans + t * f * (1LL << i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define ld long double
#define el '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < int(n); i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vli vector<pair<ll,int>>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

vector<ll> parent, rak;

void make_set(int f){
    fo(i,f+1)parent.pb(i);
    rak.assign(f+1,1);
}

ll find_set(ll v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

ll union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rak[a]+=rak[b];
        return (rak[a]-rak[b])*(rak[b]);
    }
    return 0;
}

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

/*const int N = 1000001;
int lp[N+1];
vector<int> pr;
void s(){
for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}*/


ld kv;
ll t,n,x,y,h,k,z,p,q,w;
string s,s1,s2;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    cin>>n>>k;
    fo(i,n){
        x=ceil(log2((ld)k/(i+1)));
        if(x<1)x=0;
        kv+=powl(0.5,x);
    }
    cout<<fixed<<setprecision(16)<<kv/n;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
constexpr long N = 300000;
constexpr long mod = 998244353;

long mpow(long a, long p){
    long x=a;
    long y=1;
    while(p>0){
        if((p&1)==1){
            y=x*y%mod;
        }
        x=x*x%mod;
        p>>=1;
    }
    return y;
}

long minv(long a){
    return mpow(a, mod-2);
}

long fact[N+1];
void init_fact(){
    long t=1;
    fact[0]=1;
    for(long i=1; i<=N; i++){
        t=t*i%mod;
        fact[i]=t;
    }
}

long mcomb(long n, long r){
    return fact[n]*minv(fact[n-r]*fact[r]%mod)%mod;
}

int main(void){
    long n, a, b, k;
    scanf("%ld %ld %ld %ld", &n, &a, &b, &k);
    init_fact();
    long sum = 0;
    long s = max(0l, (k-n*b)/a);
    long e = min(n, k/a);
    for(long i=s; i<=e; i++){
        long q=(k-a*i)/b;
        long m=(k-a*i)%b;
        if(m==0){
            sum = (sum+mcomb(n,i)*mcomb(n,q))%mod;
        }
    }
    if(sum==0)sum++;
    printf("%ld\n", sum);
    return 0;
}


Measured memory_bytes: 2560
n, k, q = map(int, input().split())
aq = []
for i in range(0, q):
    aq.append(input())

scores = {}
for i in range(1, n + 1):
    scores[str(i)] = 0

for ok_num in aq:
    scores[ok_num] = scores[ok_num] + 1

for i in range(1, n + 1):
    score = scores[str(i)]
    if score + k - q > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 23464
#include <stdio.h>


void maxheapify(int a[], int i,int n){
    int l = 2*i;
    int r = 2*i+1;
    int largest = 0;
    //select
    if(l<=n && a[l]>a[i])
        largest = l;
    else largest = i;
    
    if(r<=n && a[r]>a[largest])
        largest = r;
    if(largest != i){
        int temp = a[i];
        a[i] = a[largest];
        a[largest] = temp;
        maxheapify(a,largest, n);
    }
}

void build_maxheap(int a[], int n){
    for(int i = n/2; i>=1; i--){
        maxheapify(a,i,n);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    int a[n+1];
    for(int i = 1; i<=n; i++){
        scanf("%d",&a[i]);
    }
    build_maxheap(a, n);
    for(int i = 1; i<=n; i++){
        printf(" %d",a[i]);
    }printf("\n");
    return 0;
}


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

int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    // reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());

    int min_size = min(s.size(), t.size());
    for (int i = 0; i < min_size; i++)
    {
        if (t[i] > s[i])
        {
            cout << "Yes" << endl;
            return 0;
        }
        else if (t[i] < s[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }

    if (s.size() < t.size())
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,K,S = MI()
if S == 10**9:
    ANS = [10**9]*K + [1]*(N-K)
else:
    ANS = [S]*K + [10**9]*(N-K)

print(*ANS)


Measured memory_bytes: 80016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <functional>
#include <array>
#include <cmath>
#include <set>

using namespace std;

int N, d[100]{};

set<int> s;

int main(){
	
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> d[i];
		s.insert(d[i]);
	}


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

	return 0;
}



Measured memory_bytes: 256
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;
const int MYINF = 1e9+7;

typedef struct {
	int top;
	int north;
	int south;
	int east;
	int west;
	int bottom;
} dice;

void dice_init(dice *d, int v1, int v2, int v3, int v4, int v5, int v6) {
	d->top = v1;
	d->north = v5;
	d->south = v2;
	d->east = v3;
	d->west = v4;
	d->bottom = v6;
}

enum direction {
	DIR_N,
	DIR_S,
	DIR_E,
	DIR_W,
};

void rotate(dice *d, int dir) {
	int tmp;
	switch (dir) {
	case DIR_N:
		tmp = d->top;
		d->top = d->south;
		d->south = d->bottom;
		d->bottom = d->north;
		d->north = tmp;
		break;
	case DIR_S:
		tmp = d->top;
		d->top = d->north;
		d->north = d->bottom;
		d->bottom = d->south;
		d->south = tmp;
		break;
	case DIR_E:
		tmp = d->top;
		d->top = d->west;
		d->west = d->bottom;
		d->bottom = d->east;
		d->east = tmp;
		break;
	case DIR_W:
		tmp = d->top;
		d->top = d->east;
		d->east = d->bottom;
		d->bottom = d->west;
		d->west = tmp;
		break;
	default:
		fprintf(stderr, "Unspported direction: %d\n", dir);
		exit(1);
	}
	return;
}

int main(int argc, char **argv)
{
	int i, v[6], dir;
	dice d;
	char s[128];
	
	for (i = 0; i < 6; i++) {
		scanf("%d", &v[i]);
	}
	dice_init(&d, v[0], v[1], v[2], v[3], v[4], v[5]);
	scanf("%s", s);

	for (i = 0; i < strlen(s); i++) {
		dir = -1;
		switch (s[i]) {
		case 'N':
			dir = DIR_N;
			break;
		case 'S':
			dir = DIR_S;
			break;
		case 'E':
			dir = DIR_E;
			break;
		case 'W':
			dir = DIR_W;
			break;
		}
		rotate(&d, dir);
	}
	printf("%d\n", d.top);

	return 0;
}

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

char kaitenx(int j) {
  if (j == 0)
    j = 2;
  else if (j == 2)
    j = 0;
  else
    j = 1;
  
  return j;
}

char kaiteny(int i) {
  if (i == 0)
    i = 1;
  else if (i == 1)
    i = 0;
  
  return i;
}

int main () {
  vector<vector<char>> c(2, vector<char>(3));
  bool judg = 1;
  
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);
    }
  }
  
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 3; j++) {
      if (c.at(i).at(j) != c.at(kaiteny(i)).at(kaitenx(j))) {
        judg = 0;
      }
    }
  }
  
  if (judg)
    cout << "YES" << endl;
  else 
    cout << "NO" << endl;
}
  


      

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

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

    long long cnt[10] = {0};
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s[0] == 'M') cnt[0]++;
        else if (s[0] == 'A') cnt[1]++;
        else if (s[0] == 'R') cnt[2]++;
        else if (s[0] == 'C') cnt[3]++;
        else if (s[0] == 'H') cnt[4]++;
    }

    long long 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 += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }

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

Measured memory_bytes: 256
// Jalpaiguri Government Engineering college //


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

ll power(ll a,ll N)
{
	if(N==0)
	{
		return 1;
	}
	else
	{
		ll r=power(a,N/2);
		if(N%2==0)
		{
			return r*r;
		}
		else
		{
			return r*r*a;
		}
	}
}

ll powerMod(ll a,ll N,ll MOD)
{
	if(N==0)
	{
		return 1;
	}
	else
	{
		ll r=powerMod(a,N/2,MOD);
		if(N%2==0)
		{
			return (r*r)%MOD;
		}
		else
		{
			return (r*r*a)%MOD;
		}
	}
}


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


void solve()
{
	ll i,n,W;
	cin>>n>>W;
	ll v[1000],w[1000];
	ll p[100005]={0};
	for(i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
	}
	ll j;
	for(i=1;i<=n;i++)
	{
		for(j=W;j>=w[i];j--)
		{
			p[j]=max(p[j],p[j-w[i]]+v[i]);
		}
	}
	cout<<p[W]<<'\n';


}


int main()
{
    aso;
	
	// cout<<"hello\n";
	bool x=0;
	ll t=1;
	if(x)
	{
		cin>>t;
	}
	while(t--)
	{
		solve();
	}
	return 0;
	
}

Measured memory_bytes: 1024
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

import math

s = ii()

a = 0

for n in range(0, s//3):
 k = s - 3*(n+1) + n
 a += math.factorial(k)//math.factorial(k-n)//math.factorial(n)

print(a%1000000007)

Measured memory_bytes: 9116
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

fn main() {
    let (r, w, e) = (stdin(), stdout(), stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    // =============================================== //
    let (h, w): (usize, usize) = (io.read(), io.read());

    let mut s: Vec<Vec<char>> = Vec::new();
    for _ in 0..h {
        let a = io.chars();
        s.push(a);
    }
    let inf = 1 << 30;
    let mut mem = vec![vec![inf; w]; h];
    mem[0][0] = if s[0][0] == '.' { 0 } else { 1 };
    for i in 0..h {
        for j in 0..w {
            if i + 1 < h {
                if s[i][j] != s[i + 1][j] {
                    mem[i + 1][j] = min(mem[i + 1][j], mem[i][j] + 1);
                } else {
                    mem[i + 1][j] = min(mem[i + 1][j], mem[i][j]);
                }
            }

            if j + 1 < w {
                if s[i][j] != s[i][j + 1] {
                    mem[i][j + 1] = min(mem[i][j + 1], mem[i][j] + 1);
                } else {
                    mem[i][j + 1] = min(mem[i][j + 1], mem[i][j]);
                }
            }
        }
    }
    io.writeln((1 + mem[h - 1][w - 1]) / 2);
}

// IO
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug ) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug>(&mut self, val1: S, val2: S) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
#define MAX  1000
#define VMAX 10000

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

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

int partition(int A[],int p,int r){
  int i,j;
  int t,x;
  x = A[r];
  i = p - 1;

  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }

  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;

  return i+1;
}
void quickSort(int A[],int p,int r){
  int q;
  if(p<r){
    q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}


int solve(){
  int ans=0,i,cur,S,m,an,v;

  int V[MAX];
  for(i=0;i<n;i++){
    B[i] = A[i];
    V[i] = 0;
  }
  quickSort(B,0,n-1);
  for(i=0;i<n;i++) T[B[i]] = i;
  for(i=0;i<n;i++){
    if(V[i]) continue;
    cur = i;
    S = 0;
    m = VMAX;
    an = 0;
    while(1){
      V[cur] = 1;
      an++;
      v = A[cur];
      m = min(m,v);
      S += v;
      cur = T[v];
      if(V[cur]) break;
    }
    ans += min(S+(an-2)*m,m+S+(an+1)*s);
  }
  return ans;
}



int main(){
  int i;

  scanf("%d", &n);
  
  s = VMAX;
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    s = min(s,A[i]);
  }

  int ans = solve();
  printf("%d\n",ans);

  return 0;
}



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


int search(int arr[], int n, int x);
void mergeSort(int arr[], int l, int r);
void merge(int arr[], int l, int m, int r);

int main(void){
	int n;
	scanf("%i", &n);

	int count = 0;
	int same = 0;
	for(int i=1; i<n; i++){
	    if(n%i==0){
	        count--;
	    }
        count += n/i;
	}
    printf("%i", count);
}
int search(int arr[], int n, int x)
{
    int i;
    for (i = 0; i < n; i++)
        if (arr[i] == x)
            return i;
    return -1;
}

void merge(int arr[], int l, int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 = r - m;

    /* create temp arrays */
    int L[n1], R[n2];

    /* Copy data to temp arrays L[] and R[] */
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1 + j];

    /* Merge the temp arrays back into arr[l..r]*/
    i = 0; // Initial index of first subarray
    j = 0; // Initial index of second subarray
    k = l; // Initial index of merged subarray
    while (i < n1 && j < n2) {
        if (L[i] <= R[j]) {
            arr[k] = L[i];
            i++;
        }
        else {
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    /* Copy the remaining elements of L[], if there
       are any */
    while (i < n1) {
        arr[k] = L[i];
        i++;
        k++;
    }

    /* Copy the remaining elements of R[], if there
       are any */
    while (j < n2) {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(int arr[], int l, int r)
{
    if (l < r) {
        // Same as (l+r)/2, but avoids overflow for
        // large l and h
        int m = l + (r - l) / 2;

        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m + 1, r);

        merge(arr, l, m, r);
    }
}

Measured memory_bytes: 1732
#include<iostream>

using namespace std;

int main(){

  string s;
  cin>>s;

  int n;
  int i=0;
  while(s[i]!=0){
    if(s[i+1]==0){ n=i;}
    i++;
  }
  
  cout<<s[0]<<(n-1)<<s[n]<<endl;
  
  return 0;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  int N;
  bool f = false;
  cin >> N;
  for (int i= 0; i < N; ++i) {
    char c; cin >> c;
    if (c == 'Y') {
      f = true;
    }
  }

  puts(f ? "Four" : "Three");

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main() {
  ll N,M,X,cntN=0,cnt0=0;
  cin>>N>>M>>X;
  vector<ll> A(M);
  rep0(i,M){cin>>A[i];}
  rep0(i,M){
    if(A[i]>X){cntN++;}
    else {cnt0++;}
  }
  cout<<min(cnt0,cntN)<<endl;
}



Measured memory_bytes: 256