akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



signed main() {

	int M, D;
	cin >> M >> D;

	int ans = 0;
	for (int m = 1; m <= M; m++) {
		for (int d = 1; d <= D; d++) {
			int d1 = d % 10;
			int d2 = d / 10;
			if (d1 >= 2 && d2 >= 2 && d1 * d2 == m) ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 58;
const int MOD = 1000000007;
const int MAX_N = 200100;

int li[1000010][2];
signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    REP(idx, N)
    {
        string S;
        cin >> S;
        stack<bool> sta;
        REP(i, S.size())
        {
            if (S[i] == '(')
            {
                sta.push(1);
            }
            else
            {
                if (!sta.empty())
                {
                    if (sta.top() != 0)
                        sta.pop();
                    else
                        sta.push(0);
                }
                else
                    sta.push(0);
            }
        }
        int a = 0;
        int b = 0;
        while (!sta.empty())
        {
            if (sta.top())
            {
                a++;
            }
            else
            {
                b++;
            }
            sta.pop();
        }
        li[idx][0] = a;
        li[idx][1] = b;
    }

    int sum = 0;
    int numa = 0;
    int numaa = INF;
    int numb = 0;
    int numbb = INF;
    REP(i, N)
    {
        int a = li[i][0];
        int b = li[i][1];
        sum = sum + a - b;
        if (a == 0)
        {
            numb += b;
        }
        else if (b == 0)
        {
            numa += a;
        }
        else
        {
            numaa = min(a, numaa);
            numbb = min(b, numbb);
        }
    }
    if (numaa == INF)
    {
        numaa = 0;
    }
    if (numbb == INF)
    {
        numbb = 0;
    }
    if (sum != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    if (numaa > numb)
    {
        cout << "No" << endl;
        return 0;
    }
    if (numbb > numa)
    {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 19228
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif




#define int long long
#define rng(i,l,r) for(size_t i=(l);i<(r);++i)
#define rep(i,n) rng(i,0,n)
#define gnr(i,l,r) for(size_t i=(r)-1;i>=(l);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()   //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend()//...,3,2,1

using namespace std;
//using ll = long long;


const int MOD = 1000000007;
const int INF = 1e18;

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

const double pi = acos(-1);



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


using Graph = vector<vector<int>>;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//*max_element(ALL(vector))
//count(ALL(vector),num) -> n




void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

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

    double w,h,x,y; cin >> w >> h >> x >> y;
    
    double halfs = w*h/2;
    double cx = w/2;
    double cy = h/2;
    bool isPcenter = (cx==x && cy==y);
    
    int num = 0;
    if(isPcenter) num = 1;
    
    cout << setprecision(10) << halfs << " " << num << endl;
    
    
    
    
    
    
    
    
    
}



signed main() {
    solve();
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	long long int i,h[3],m[3],s[3],h1[3],m1[3],s1[3];
	for(i=0;i<3;i++){
		scanf("%lld %lld %lld %lld %lld %lld",&h[i],&m[i],&s[i],&h1[i],&m1[i],&s1[i]);
	}
	long long int a[3],b[3];
	for(i=0;i<3;i++){
		a[i]=h[i]*3600+m[i]*60+s[i];
		b[i]=h1[i]*3600+m1[i]*60+s1[i];
	}
	long long int c[3];
	for(i=0;i<3;i++){
		c[i]=b[i]-a[i];
	}
	long long int h2[3],m2[3],s2[3],h3[3];
	for(i=0;i<3;i++){
		h2[i]=c[i]/3600;
		h3[i]=c[i]%3600;
		m2[i]=h3[i]/60;
		s2[i]=h3[i]%60;
	}
	for(i=0;i<3;i++){
		printf("%lld %lld %lld\n",h2[i],m2[i],s2[i]);
	}
	return 0;
}


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

const int MAX = 2000000;
const int MOD = 1000000007;

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


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

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


int main(){
  ll x,y;
  cin >> x >> y;
  ll n,m;
  COMinit();
  if((x+y)%3!=0){
    cout << '0' << endl;
    return 0;
  }

  m=(2*x-y)/3;
  n=(2*y-x)/3;
  if(n<0 || m<0){
    cout << '0' << endl;
    return 0;
  }
  ll ans=COM(n+m,n)%MOD;
  cout << ans << endl;
  return 0;

}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

ll n, k;

ll ans;

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

  cin>>n>>k;

  if (k==0) {
    ans=n*n;
    out(ans);
  }
  
  for (ll b=k+1; b<=n; b++) {
    ll cur = 0;
    for (ll a=k; a<=n; a+=b) {
      ll ub = min(n, ((a+b-1)/b)*b - 1);
      cur += (ub-a+1);
    }
    ans += cur;
  }

  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int in, h, m, s;
	while(scanf("%d", &in) != EOF )

	h = in / 3600;
	m = (in - h * 3600) / 60;
	s = (in - h * 3600 - m * 60);

	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 592
#include <stdio.h>
#include <string.h>

int main(void){
    char weatherPreview[4];
    char weatherReport[4];
    int corrects = 0;

    scanf("%s %s", &weatherPreview, &weatherReport);

    for (int i = 0; i < 3; i++) {
        if (weatherPreview[i] == weatherReport[i]) {
            corrects++;
        }
    }

    printf("%d\n", corrects);

    return 0;
}


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

using namespace std;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    int co=0;
    if(a==b)co++; 
    if(a==c)co++;
    if(b==c)co++;
    if(a==b&&b==c){
        co=2;
    }
    cout << 3-co<< endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 922337203685477580;//7;
constexpr auto mod = 1000000007;

int main() {

	string s;
	cin >> s;
	int a = stoi(s.substr(0, 2));
	int b = stoi(s.substr(2, 2));
	if (a > 12) {
		if (b > 12)cout << "NA" << endl;
		else if (b > 0)cout << "YYMM" << endl;
		else cout << "NA" << endl;
	}
	else if(a>0){
		if (b > 12)cout << "MMYY" << endl;
		else if (b > 0)cout << "AMBIGUOUS" << endl;
		else cout << "MMYY" << endl;
	}
	else {
		if (b > 12)cout << "NA" << endl;
		else if (b > 0)cout << "YYMM" << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 256
n  = int(input())
A = list(map(int,input().split()))
ans = []
A_even = [i for i in A if i % 2 == 0]
for i in A_even:
  if i % 3 == 0 or i % 5 == 0:
    ans.append(i)
if len(ans) == len(A_even):
  print("APPROVED")
else:
  print("DENIED")

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){ 
  while(x->left != NIL) x = x->left;
  return x;
} 

Node treeSearch(Node u, int k){ 
  while(u != NIL && k != u->key){
  if(k < (u->key)) u = u->left;
  else u = u->right;
  }
  return u;
} 

Node treeSuccessor(Node x){
  Node y;
  //if(x->right != NIL) return treeSuccessor(x->right);
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
} 

void treeDelete(Node z){ 
  Node y; // node to be deleted 
  Node x; // child of y 
  
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;

  free(y);

} 

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if((z->key) < (x->key)) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  
  if(y == NIL) root = z;
  else if((z->key) < (y->key)) y->left = z;
  else y->right = z;
  
}

void inorder(Node u){
  if(u != NIL){
    if((u->left) != NIL) inorder(u->left);
    printf(" %d",u->key);
    if((u->right) != NIL) inorder(u->right);
  }
}

void preorder(Node u){

  if(u != NIL){
    printf(" %d",u->key);
    if(u->left != NIL) preorder(u->left);
    if(u->right != NIL) preorder(u->right);
  }
}

int main(){
  int n, i, x;
  char command[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", command);
    if ( command[0] == 'f' ){ 
      scanf("%d", &x); 
      Node t = treeSearch(root, x); 
      if ( t != NIL ) printf("yes\n"); 
      else printf("no\n"); 
    }  
    else if ( command[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( command[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
    else if ( command[0] == 'd' ){ 
      scanf("%d", &x); 
      treeDelete(treeSearch(root, x)); 
    } 
  }
  
  return 0;
}

Measured memory_bytes: 19364
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for sum_w in range(W + 1):
        if sum_w - items[i][0] >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w],
                                   dp[i][sum_w - items[i][0]] + items[i][1])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])

res = dp[N][W]
print(res)


Measured memory_bytes: 121068
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
double dp[3000][3000];
int main()
{
    fastio;
    int n;
    cin>>n;
    double a[n+1];
    for(int i=0;i<n;i++)cin>>a[i];
    dp[0][1] = a[0];
    dp[0][0] = 1.0 - a[0];

    for(int i=1;i<n;i++)
    {
        for(int h=0;h<=i;h++)
        {
            dp[i][h+1]+=  dp[i-1][h]*a[i];
            dp[i][h]+= dp[i-1][h]*(1.0-a[i]);
        }
    }
    double ans = 0;
    for(int i=n;i>n/2;i--)
    {
        ans+=dp[n-1][i];
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 68864
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parent = [-1 for i in range(n)]
    
    def root(self, x):
        if self.parent[x] <0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
    
    def same(self, x, y):
        return (self.root(x) == self.root(y))

    def union(self, x, y):
        p = self.root(x)
        q = self.root(y)
        
        if not p==q :
            if self.parent[p] > self.parent[q]:
                p,q = q,p
            self.parent[p] += self.parent[q]
            self.parent[q] = p
    
    def size(self, x):
        return -self.parent[self.root(x)]



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

uf = UnionFind(N)
for i in range(M):
    A,B  = list(map(int, input().split()))
    uf.union(A-1,B-1)

ans = -1
for i in range(N):
    s = uf.size(i)
    if s > ans:
        ans = s

print(ans)











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

int main(){
	int N, i;
	scanf("%d", &N);
	string S;
	cin >> S;
	int ans = 1;
	for(i = 1; i < N; i++){
		if(S[i] != S[i - 1]){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){

  int n,r;
  int p,c;
  int tmp[50];
  int i,j;
  int card[50];

  for(;;){

    scanf("%d %d",&n,&r);
    if(n==0&&r==0)break;

    for(i=0;i<n;i++)card[i]=n-i;
    
    for(i=0;i<r;i++)
      {
        scanf("%d %d",&p,&c);
        for(j=0;j<p-1+c;j++)
          tmp[j]=card[j];
        
        for(j=0;j<c;j++)
          card[j]=tmp[p-1+j];

        for(j=0;j<p-1;j++)
          card[c+j]=tmp[j];
      }

    printf("%d\n",card[0]);
 
  }

  return 0;
}

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

const int mod = 1e9 + 7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n < 600) cout << 8;
    else if (n < 800) cout << 7;
    else if (n < 1000) cout << 6;
    else if (n < 1200) cout << 5;
    else if (n < 1400) cout << 4;
    else if (n < 1600) cout << 3;
    else if (n < 1800) cout << 2;
    else if (n < 2000) cout << 1;
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n,q;
    cin >> n >> q;
    int ind = 0;
    rep(_,q){
        int a,b;
        cin >> a >> b;
        if(a){//swap
            ind = (ind+b)%n;
        }else{//cout
            b--;
            cout << (ind+b)%n+1 << endl;
        }
    }
}



Measured memory_bytes: 3100
inpl = lambda: list(map(int,input().split()))
R,G,B,N = inpl()
(R,G,B) = sorted([R,G,B])
ans = 0
for b in range(N//B+1):
    N1 = N - b*B
    for g in range(N1//G+1):
        N2 = N1 - g*G
        if N2 % R == 0:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int a, b;
  cin>>a>>b;
  if(a+b>=10){
    cout<<"error"<<endl;
  }else{
    cout<<a+b<<endl;
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        List<Integer> numsListA = new ArrayList<Integer>();
        List<Integer> numsListB = new ArrayList<Integer>();
        List<Integer> numsListC = new ArrayList<Integer>();
        int score = 0;

        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();                     //N品の料理を食べる
        for(int i = 0; i < n; i++) {                //N回scanします ListA
            numsListA.add(scan.nextInt());
        }
        for(int i = 0; i < n; i++) {                //N回scanします ListB
            numsListB.add(scan.nextInt());
        }
        for(int i = 0; i < n - 1; i++) {            //N-1回scanします ListC
            numsListC.add(scan.nextInt());
        }

        for (int i = 0; i < n; i++) {               //ListB満足度をscoreにSUM
            score += numsListB.get(numsListA.get(i) - 1);
        }

        for (int i = 0; i < n - 1; i++) {           //ListCボーナスをscoreにSUM
            if(numsListA.get(i + 1) - numsListA.get(i) == 1) {
                score += numsListC.get(numsListA.get(i)- 1);
            }
        }

        System.out.println(score);
    }
}

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

typedef long long ll;
typedef unsigned long long ull;

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void)
{
	int n, k;
	cin >> n >> k;
	n -= 2;

	int ans = 0;
	Rep(i, 77){
		Rep(j, 5){
			int sum = 0;
			sum += (i * 7 + j + 1);
			sum += (i * 7 + j + 2);
			sum += (i * 7 + j + 3);
			sum += ((i + 1) * 7 + j + 1);
			sum += ((i + 1) * 7 + j + 2);
			sum += ((i + 1) * 7 + j + 3);
			sum += ((i + 2) * 7 + j + 1);
			sum += ((i + 2) * 7 + j + 2);
			sum += ((i + 2) * 7 + j + 3);
			if(sum % 11 == k){
				ans++;
			}
		}
	}
	ans *= n / 77;

	Rep(i, n % 77){
		Rep(j, 5){
			int sum = 0;
			sum += (i * 7 + j + 1);
			sum += (i * 7 + j + 2);
			sum += (i * 7 + j + 3);
			sum += ((i + 1) * 7 + j + 1);
			sum += ((i + 1) * 7 + j + 2);
			sum += ((i + 1) * 7 + j + 3);
			sum += ((i + 2) * 7 + j + 1);
			sum += ((i + 2) * 7 + j + 2);
			sum += ((i + 2) * 7 + j + 3);
			if(sum % 11 == k){
				ans++;
			}
		}
	}
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define ull unsigned long long
#define inf 0x3f3f3f3f
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn];
ull sum[maxn];
int n,m;
int main()
{
	n=read(); m=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	sum[0]=0;
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+a[i];
	ull ans=5*sum[n]+(ull)n*m;
	for(int i=1;i<n;i++){
		// printf("%d ***\n",i);
		ull cur=5*(sum[n]-sum[n-i])+(ull)m*i;
		for(int j=n-i,k=5;j>0;j-=i,k+=2){
			int l=std::max(1,j-i+1);
			// printf("%d %d : %d\n",l,j,k);
			cur+=(ull)k*(sum[j]-sum[l-1]);
		}
		// printf("%lld\n",cur);
		ans=std::min(ans,cur);
	}
	writeln(ans+(ull)n*m);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
    COMinit();
    int N, K; cin >> N >> K;
    for (int i = 1; i <= K; i++) {
        cout << COM(K-1, i-1) * COM(N-K+1, i) % MOD << '\n';
    }
    return 0;
}

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

int number(int n){
  int ans = 0;
  while(n%2 == 0){
    ++ans;
    n /= 2;
  }
  return ans;
}

int main(){
  int N; cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  int ans = 0;
  for(int i = 0; i < N; i++){
    ans += number(a[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
A,B=map(int,input().split())
ans=0
if A > B:
        ans += A
        A = A - 1
else:   
        ans += B
        B = B - 1
if A > B:
        ans += A
        A = A - 1
else:
        ans += B
        B = B - 1
print(ans)

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

int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;

  int ans = abs(A2 - A1) + abs(A2 - A3);
  ans = min(ans, abs(A3 - A1) + abs(A3 - A2));
  ans = min(ans, abs(A3 - A2) + abs(A3 - A1));
  ans = min(ans, abs(A1 - A2) + abs(A1 - A3));
  ans = min(ans, abs(A1 - A3) + abs(A1 - A2));
  ans = min(ans, abs(A2 - A3) + abs(A2 - A1));
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        long[] A = new long[N];
        int[] B = new int[N];
        
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }
        HashMap<Long, Integer> map = new HashMap<>();
        for(int i = 0; i < N; i++){
            if(map.containsKey(A[i])){
                map.put(A[i], map.get(A[i]) + B[i]);
            } else{
                map.put(A[i], B[i]);
            }
        }
        Arrays.sort(A);
        for(int i = 0; i < N-1; i++){
            if(A[i] == A[i+1]){
                A[i] = 0;
            }
        }
        int sum = 0;
        long charge = 0;
        int i = 0;
        while(sum < M) {
            if(A[i] != 0) {
                if(M - sum >= map.get(A[i])){
                    sum += map.get(A[i]);
                    charge += map.get(A[i])*A[i];
                } else {
                    charge += (M-sum)*A[i];
                    sum = M;                    
                }
            }
            i++;    
        }
        sc.close();
        System.out.println(charge);
    }
}


Measured memory_bytes: 90940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, m, k, l;
string s;

struct union_find {//1-origin
	vector<int> rnk, par;
	union_find(int n) {
		rnk.resize(n+1);
		par.resize(n+1);
		for(int i = 1; i <= n; i++){
			par[i] = i;
			rnk[i] = 0;
		}
	}
	
	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}
 
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rnk[x] < rnk[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rnk[x] == rnk[y])rnk[x]++;
		}
	}
	
	bool same(int x, int y) {
		return (find(x) == find(y));
	}
};

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> m;
	
	union_find u(n+m);
	rep(i, 1, n){
		cin >> k;
		rep(j, 1, k){
			cin >> l;
			u.unite(i, n+l);
		}
	}
	
	ll p1 = u.find(1);
	string ans = "YES";
	rep(i, 2, n){
		if(u.find(i) != p1){
			ans = "NO";
		}
	}
	
	print(ans)
	return 0;
}

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;

	if ((A < C && C < B) || (B < C && C < A)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define why 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  string s,a,b,c;; cin>>s;
  ll n=s.size();
  a=s;
  reverse(bc(s));
  if(a==s){
    b="";
    rep(i,(n-1)/2) b+=s[i];
    string x=b;
    reverse(bc(b));
    if(b==x){
      c="";
      haha(i,(n+3)/2-1,n) c+=s[i];
      string z=c;
      reverse(bc(c));
      if(c==z){
        cout<<"Yes"; return ;
      }
    }
  }
  cout<<"No";
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

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

typedef long long ll;

int main () {
	int N;
	int b[200000] = {0};
	cin >> N;
	for (int i=1; i<N; i++) {
		int tmp;
		cin >> tmp;
		b[tmp-1] ++;
	}
	for (int i=0; i<N; i++)
		cout << b[i] << endl;
	return 0;
}

Measured memory_bytes: 4392
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


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

  map<char,ll> name;

  std::vector<string> s(n);
  string a;
  rep(i,n){
    cin >> s.at(i);
    a=s.at(i);
    name[a.at(0)]+=1;
  }

  ll mar,mac,mah,mrc,mrh,mch,arc,arh,ach,rch;

  mar=name['M']*name['A']*name['R'];
  mac=name['M']*name['A']*name['C'];
  mah=name['M']*name['A']*name['H'];
  mrc=name['M']*name['R']*name['C'];
  mrh=name['M']*name['R']*name['H'];
  mch=name['M']*name['C']*name['H'];
  arc=name['A']*name['R']*name['C'];
  arh=name['A']*name['R']*name['H'];
  ach=name['A']*name['C']*name['H'];
  rch=name['R']*name['C']*name['H'];

  ll sum=mar+mac+mah+mrc+mrh+mch+arc+arh+ach+rch;


  cout << sum << endl;


  }


Measured memory_bytes: 6324
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] x = new int[5];
		int ans = 0;
		
		for(int i = 0; i < 5; i++) {
			x[i]	 = sc.nextInt();
		}
		for(int i = 0; i < 5; i++) {
			if(x[i] == 0 && i != 0) {
				ans = x[i-1] + 1;
				break;
			}else if(x[i] == 0){
				ans = x[i+1] -1;
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 27080
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep(i, n-2) {
        if (p[i] < p[i+1] && p[i+1] < p[i+2]) {
            ans += 1;
        } else if (p[i] > p[i+1] && p[i+1] > p[i+2]) {
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m;
string str;

int main(){
	cin >> n >> m;
	ll ans = 0;
	if(n >= 6){
		ans = m/2;
	}
	if(n >= 13){
		ans = m;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll pow(ll x, ll y, ll mod) {
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        return pow(x * x % mod, y / 2, mod) % mod;
    } else {
        return x * pow(x, y - 1, mod) % mod;
    }
}

const int MAX = 510000;

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


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

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll f(ll n, ll k) {
    ll res = 1;
    rep2(i, 1, k + 1) {
        res *= (n - i + 1);
        res %= MOD;
        res *= inv[i];
        res %= MOD;
    }
    return res;
}


void Main() {
    ll N, A, B;
    cin >> N >> A >> B;
    COMinit();
    ll ans = pow(2, N, MOD);
    ans %= MOD;
    ans -= 1;
    if (ans < 0) ans += MOD;
    ans -= f(N, A);
    ans %= MOD;
    if (ans < 0) ans += MOD;
    ans -= f(N, B);
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans % MOD << '\n';
}

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


Measured memory_bytes: 12160
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long llint;
llint min2(llint a,llint b){
    return a>=b?b:a;
}

int main(void){
    llint block=0,count=0,n,i;
    char s[200000];
    scanf("%s",s);
    n = strlen(s);
    for(i=0;i<n;i++){
        if(s[i]=='1') count++;
    }
    block = 2*min2(count,n-count);


    printf("%lld\n",block);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <string>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (auto &e : v)
    cin >> e.first >> e.second;
  sort(v.begin(), v.end());
  map<pair<int, int>, int> mp;

  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      if (i == j)
        continue;
      mp[make_pair(v[i].first - v[j].first, v[i].second - v[j].second)]++;
    }
  }
  int cnt = 0;
  int p = 0, q = 0;
  for (auto e : mp)
  {
    if (cnt < e.second)
    {
      cnt = e.second;
      p = e.first.first, q = e.first.second;
    }
  }

  cout << n-cnt << endl;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;


const int W = 12345;
int dp[2][114][W];
const int N = 123;
int a[N], b[N], c[N];

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, cc;
  cin >> n >> cc;
  REP(i, 0, n) {
    cin >> a[i] >> b[i] >> c[i];
  }
  REP(i, 0, cc + 1) {
    REP(j, 0, W) {
      dp[0][i][j] = -1;
    }
  }
  dp[0][0][0] = 0;
  REP(i, 0, n) {
    int t = i % 2;
    REP(i, 0, cc + 1) {
      REP(j, 0, W) {
	dp[1 - t][i][j] = -1;
      }
    }
    REP(j, c[i], cc + 1) {
      REP(k, 0, W) {
	int &ret = dp[1 - t][j][k];
	if (k >= a[i]) {
	  if (dp[t][j - c[i]][k - a[i]] >= 0) {
	    ret = max(ret, dp[t][j - c[i]][k - a[i]] + b[i]);
	  }
	}
	if (k >= b[i]) {
	  if (dp[t][j - c[i]][k - b[i]] >= 0) {
	    ret = max(ret, dp[t][j - c[i]][k - b[i]] + a[i]);
	  }
	}
      }
    }
    REP(j, 0, cc + 1) {
      REP(k, 0, W) {
	dp[1 - t][j][k] = max(dp[1 - t][j][k], dp[t][j][k]);
      }
    }
  }
  int ma = 0;
  REP(i, 0, cc + 1) {
    REP(j, 0, W) {
      ma = max(ma, min(dp[n % 2][i][j], j));
    }
  }
  cout << ma << "\n";
}

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

long long int MOD = 1e9 + 7;

long long int modPow(long long int x, long long int a) {
  if (a == 1) return x;
  if (a % 2) return (x * modPow(x, a - 1)) % MOD;
  long long int t = modPow(x, a / 2);
  return (t * t) % MOD;
}

long long int  modInv(long long int x) {
  return modPow(x, MOD - 2);
}

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

    std::vector<long long int> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    long long int sum = 0;
    long long int sqs = 0;
    for (int i = 0; i < N; i++) {
        sum = (sum + A[i]) % MOD;
        sqs = (sqs + A[i] * A[i]) % MOD;
    }
    long long int mod = ((sum * sum % MOD - sqs) * modInv(2)) % MOD;
    if (mod < 0) {
        mod += MOD;
    }
    std::cout << mod << std::endl;
}


Measured memory_bytes: 4780
#include<stdio.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lf", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
#define pi 3.14159265359
int main(){
	double r;
	while(~getI(r)){
		printf("%.6lf\n",pi*2*r);
	}
}


Measured memory_bytes: 1752
#include <iostream>

using namespace std;

int main(void){
  bool exist = false;

  int num;
  double w, h;

  while(cin >> num){
	cin.ignore();
	cin >> w;
	cin.ignore();
	cin >> h;
	if(w / (h*h) >= 25){
	  exist = true;
	  cout << num << endl;
	}
  }
  if(!exist){
	cout << "ツ該ツ督鳴づ按つオ" << endl;
  }
}

Measured memory_bytes: 0
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

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

    string s; cin>>s;
    int n = s.size();

    vector<vector<ll>> dp(n+1, vector<ll>(4, 0));
    dp[0][0] = 1;
    for(int i=0; i<n; i++){
        // 使わない
        for(int j=0; j<4; j++){
            if(s[i] == '?') dp[i+1][j] += dp[i][j] * 3;
            else dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= MOD;
        }

        // 使う
        if(s[i] == 'A' || s[i] == '?'){
            dp[i+1][1] += dp[i][0];
            dp[i+1][1] %= MOD;
        }
        if(s[i] == 'B' || s[i] == '?'){
            dp[i+1][2] += dp[i][1];
            dp[i+1][2] %= MOD;
        }
        if(s[i] == 'C' || s[i] == '?'){
            dp[i+1][3] += dp[i][2];
            dp[i+1][3] %= MOD;
        }
    }

    cout << dp[n][3] << endl;

    return 0;
}

Measured memory_bytes: 7376
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long S = 0;
  for (int i = 0; i < N; i++) {
    S += A[i];
  }
  long m;
  m = S;
  long Sr = 0;
  for (int i = 0; i < N - 1; i++) {
    Sr += A[i];
    if (abs(S - Sr * 2) < m) {
      m = abs(S - Sr * 2);
    }
  }
  cout << m << endl;
  return 0;
}


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

int main() {
	string s;
	cin >> s;
	int ans = 0;
	int j;
	for (int i = 0; i < s.length(); i++) {
		j = s.at(i);
		if (j == '+') {
			ans++;
		} else if (j == '-') {
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string x,y;
  cin>>x>>y;
  if(x=="A"){
    if(y=="A"){
      cout<<'=';
    }
    else if(y=="B"||y=="C"||y=="D"||y=="E"||y=="F"){
      cout<<'<';
    }
  }
  else if(x=="B"){
    if(y=="A"){
      cout<<'>';
    }
    else if(y=="B"){
      cout<<'=';
    }
    else if(y=="C"||y=="D"||y=="E"||y=="F"){
      cout<<'<';
    }
  }
  else if(x=="C"){
    if(y=="A"||y=="B"){
      cout<<'>';
    }
    else if(y=="C"){
      cout<<'=';
    }
    else if(y=="D"||y=="E"||y=="F"){
      cout<<'<';
    }
  }
  else if(x=="D"){
    if(y=="A"||y=="B"||y=="C"){
     cout<<'>';
    }
    else if(y=="D"){
      cout<<'=';
    }
    else if(y=="E"||y=="F"){
      cout<<'<';
    }
  }
  else if(x=="E"){
    if(y=="C"||y=="D"||y=="A"||y=="B"){
      cout<<'>';
    }
    else if(y=="E"){
      cout<<'=';
    }
    else if(y=="F"){
      cout<<'<';
    }
  }
  else if(x=="F"){
    if(y=="B"||y=="C"||y=="D"||y=="E"||y=="A"){
      cout<<'>';
    }
    else if(y=="F"){
      cout<<'=';
    }
  }
}

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

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


bool my_cp(pair<int, int> a, pair<int, int> b){
  return (double)b.first / (double)(b.second+1) < (double)a.first / (double)(a.second+1);
}


ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}

int N;

void dfs(string s, char m, int N){
  size_t len = s.length();
  if(len == N){
    cout << s << endl;
  }else{
    for(char c = 'a'; c <= m; c++){
      dfs(s + c, ((c == m)? (m + 1) : m), N);
    }
  }
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}





// substr(start, len)

int main(){

  int N, M;
  cin >> N >> M;

  vector<int> a(M, 0);

  rep(i, 0, M){
    cin >> a[i];
  }

  ll sum = accumulate(all(a), 0);

  ll resi = N >= sum ? N - sum : -1;

  cout << resi << endl;


  
  // cout << setprecision(8) << ans << endl;  // For double
  // CHECK if it's possible to overflow!!
}

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

int n, W;
int w[155], v[155];
long long dp[100055];

int main() {
	cin >> n >> W;
	
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &w[i], &v[i]);
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = W; j >= w[i]; j--) {
			dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
		}
	}
	
	cout << dp[W];
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

class Vector3{
public:
	double x;
	double y;
	double z;
	Vector3(double x_, double y_, double z_):x(x_), y(y_), z(z_){}
	Vector3(){}
};

class sphere{
public:
	Vector3 p;
	double r;
	sphere(Vector3 p_, double r_):p(p_), r(r_){}
	sphere(){}
};

Vector3 operator+(Vector3 a, Vector3 b){
	return Vector3(a.x+b.x, a.y+b.y, a.z+b.z);
}
Vector3 operator-(Vector3 a, Vector3 b){
	return Vector3(a.x-b.x, a.y-b.y, a.z-b.z);
}
Vector3 operator*(Vector3 a, double k){
	return Vector3(a.x*k, a.y*k, a.z*k);
}
double abs(Vector3 a){
	return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
}
double cul_distance(sphere a, sphere b){
	return abs(a.p-b.p) - a.r - b.r;
}
bool is_connect_distance(sphere a, sphere b){
	return cul_distance(a, b) <= 0.0001;
}

double func(int n){
	vector<sphere> spheres(n);
	foreach(i, spheres)cin>>i.p.x>>i.p.y>>i.p.z>>i.r;
	double res = 0;
	using pdi = pair<double, int>;
	priority_queuer<pdi> pq;
	vector<double> fast(n, INF);
	fast[0] = 0;
	pq.emplace(0, 0);
	while(pq.size()){
		pdi d = pq.top();
		pq.pop();
		if(d.first != fast[d.second])continue;
		res += d.first;
		rep(i, n){
			double dis = cul_distance(spheres[d.second], spheres[i]);
			chmax(dis, 0);
			if(dis < fast[i]){
				fast[i] = dis;
				pq.emplace(dis, i);
			}
		}
	}
	return res;
}

int main(){
	int n;
	while(cin>>n&&n){
		printf("%.3lf\n", func(n));
	}




		return 0;
}



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

using namespace std;
#define N_MAX 200000
#define input(d) cin >> d;
#define inputs(n,d) for(int i=0;i<n;i++) {cin >> d[i];}
#define inputxy(n,x,y) for(int i=0;i<n;i++) {cin >> x[i] >> y[i];}
#define output(d) cout << d << endl;
#define outputs(n,d) for(int i=0;i<n;i++) {cout << d[i] << endl;}
#define outputxy(n,x,y) for(int i=0;i<n;i++) {cout << x[i] << y[i] << endl;}
#define f0(n) for(int i=0;i<n;i++)
#define f(a,b) for(int i=a;i<b;i++)
#define l long
#define ll long long
#define s string

int main(){
    ll n,d,x,y,ans=0;
    input(n);
    input(d);

    f0(n){
        input(x);
        input(y);
        if(d*d >= x*x+y*y){
            ans++;
        }
    }

    output(ans);
    return 0;
}

Measured memory_bytes: 3620
from collections import Counter
N, M = map(int, input().split())
A = list(map(int, input().split()))

X = Counter(A)
for i in range(M):
    B, C = map(int, input().split())
    X[C] += B

Z = []
for key, value in X.items():
    Z.append((key, value))

Z.sort(key=lambda x: x[0], reverse=True)

ans = 0
cnt = 0

for value, key in Z:
    if cnt + key <= N:
        ans += key * value
        cnt += key
    else:
        ans += (N - cnt) * value
        break

print(ans)


Measured memory_bytes: 43296