akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

const int MAX_N = 3e3 + 5;

int can_sug [MAX_N];
int can_wat [MAX_N];

int ceil (int p, int q) {
  return (p + q - 1) / q;
}

int main () {
  ios::sync_with_stdio(false);

  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  for (int i = 0; i <= f; i += c) {
    can_sug[i] = 1;
  }

  for (int i = 0; i + d <= f; i++) {
    if (can_sug[i]) {
      can_sug[i + d] = 1;
    }
  }

  for (int i = 0; i <= f; i += 100 * a) {
    can_wat[i] = i;
  }

  for (int i = 0; i + 100 * b <= f; i++) {
    if (can_wat[i]) {
      can_wat[i + 100 * b] = i + 100 * b;
    }
  }

  can_wat[f + 1] = f + 1;
  for (int i = f; i >= 0; i--) {
    if (!can_wat[i]) {
      can_wat[i] = can_wat[i + 1];
    }
  }
  
  int cur_sug = 0, cur_tot = 100 * a;
  for (int i = 1; i <= f; i++) {
    if (can_sug[i]) {
      int need_wat = ceil(100 * i, e);
      if (need_wat <= f) {
        need_wat = can_wat[need_wat];
        if (i + need_wat <= f) {
          int sug = i;
          int tot = i + need_wat;
          if (sug * (cur_tot) >= cur_sug * tot) {
            cur_sug = sug;
            cur_tot = tot;
          }
        }
      }
    }
  }

  cout << cur_tot << " " << cur_sug << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <numeric>

using namespace std;

const int MAXN = 1e6;
int minDivisor[MAXN + 1];
bitset<MAXN + 1> usedPrime;

int main() {
    for (int i = 2; i <= 1e6; ++i) {
        if (minDivisor[i]) continue;
        for (long long j = i*(long long)i; j <= 1e6; j += i) {
            if (!minDivisor[j]) minDivisor[j] = i;
        }
    }

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<int> a(n);
    for (int &x : a) cin >> x;
    bool pairwiseCoprime = true;
    for (int x : a) {
        while (x > 1) {
            int prime = minDivisor[x];
            if (!prime) prime = x;
            if (usedPrime[prime]) {
                pairwiseCoprime = false;
                break;
            }
            usedPrime[prime] = true;
            while (x % prime == 0) x /= prime;
        }
        if (!pairwiseCoprime) break;
    }

    if (pairwiseCoprime) cout << "pairwise coprime" << endl;
    else {
        int gcdAll = a[0];
        for (int i = 1; i < n && gcdAll > 1; ++i) gcdAll = gcd(gcdAll, a[i]);
        if (gcdAll == 1) cout << "setwise coprime" << endl;
        else cout << "not coprime" << endl;
    }
    return 0;
}


Measured memory_bytes: 11160
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf (ll)2e18
#define EPS 1e-12
#define MOD (ll)(1e9 + 7)
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;

inline void solve()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	bool h = 0;
	while (a > 0 & c > 0) {
		if (!h)
			c -= b;
		else
			a -= d;
		h = !h;
	}
	if (a <= 0)
		cout << "No";
	else
		cout << "Yes";
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	fore(t, 0, q)
	{
		solve();
		cout << '\n';
	}
}

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

int main() {
  vector<int64_t> buf(87);
  int N;
  cin >> N;

  buf.at(0) = 2;
  buf.at(1) = 1;

  for (int i = 2; i <= N; i++)
  {
    buf.at(i) = buf.at(i - 1) + buf.at(i - 2);
  }

  cout << buf.at(N) << endl;
}



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

//main関数
int main() {
    //入力
    long A,B;
    cin>>A>>B;
    
    //計算
    long ans=0;
    if(A>5) ans+=B/2;
    if(A>12) ans+=B/2;
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#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 all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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 (b < a) { a = b; return true; } return false; }

// ??????????????? ????°?
using Value = int;
static const int MAX_N = 2000010;
static Value heap[MAX_N];
static int sz = 0;
void push(Value x) {
	int v = sz++;
	while (v > 0) {
		int p = (v - 1) / 2;
		if (heap[p] >= x)break;
		heap[v] = heap[p];
		v = p;
	}
	heap[v] = x;
}
const Value pop() {
	Value ret = heap[0];
	Value back = heap[--sz];
	int v = 0;
	while (v * 2 + 1 < sz) {
		// l ??¨ r ??????????°???????????????¨???????????????
		int l = v * 2 + 1, r = v * 2 + 2;
		int u = (r >= sz || heap[l] > heap[r]) ? l : r;
		// ???????????¢???????????????
		if (heap[u] <= back)break;
		heap[v] = heap[u];
		v = u;
	}
	heap[v] = back;
	return ret;
}
const Value top() {
	return heap[0];
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	char s[10];
	while (~scanf("%s", &s)) {
		if (s[0] == 'i') {
			int a; scanf("%d", &a);
			push(a);
		}
		else if (s[1] == 'x') {
			printf("%d\n", pop());
		}
		else {
			break;
		}
	}
	return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int64_t> a(N+1);
  a[0]=2; a[1]=1;
  for (int i=2; i<=N; i++) a[i]=a[i-1]+a[i-2];
  cout << a[N] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
bool prime[51001];
using namespace std;
int main(){
	int i,j,n;

	for (i = 3; i <= 51000; i += 2){
		prime[i] = true;
	}
	prime[2] = true;

	for (i = 3; i <= (int)sqrt(51000.); i += 2){
		if (prime[i] == 1){
			for (j = 3; j <= 51000 / i; j += 2){
				prime[i * j] = false;
			}
		}
	}
	while(cin >> n && n){
		for(i=n-1;i>1;i--){
			if(prime[i]){
				cout << i << " ";
				break;
			}
		}
		for(i=n+1;i<51001;i++){
			if(prime[i]){
			cout << i << endl;
			break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
void fast(){
cin.tie(0);
cin.sync_with_stdio(0);
}
int main()
{
    fast();
 int a,b;
 cin>>a>>b;
for(int i=1;i<=3;i++)
{
   if((i*a*b)%2!=0)
    {cout<<"Yes";return 0;}
}
cout<<"No";
}


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

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

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        ArrayDeque<Integer> list = new ArrayDeque<Integer>(2000000);
        
        try {
        int n = input.nextInt();
        while (n-- > 0) {
            String s = input.next();
            if ("insert".equals(s)) {
                int x = input.nextInt();
                list.addFirst(x);
            } else if ("delete".equals(s)) {
                int x = input.nextInt();
                list.remove(x);
            } else if ("deleteFirst".equals(s)) {
                list.pollFirst();
            } else if ("deleteLast".equals(s)) {
                list.pollLast();
            }
        }
        } catch (IOException e) {}
        print(list.toArray());
    }
    
    private void print(Object[] xs) {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    }
    
    private static class Scanner {
        BufferedReader r;
        StreamTokenizer st;
        
        public Scanner(InputStream in) {
            r = new BufferedReader(new InputStreamReader(in));
            st = new StreamTokenizer(r);
        }
        
        public String next() throws IOException {
            st.nextToken();
            return st.sval;
        }
        
        public Integer nextInt() throws IOException {
            st.nextToken();
            return (int)st.nval;
        }
    }
}

Measured memory_bytes: 122604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int MAX = 1000005;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    vector<int> d(MAX, -1);
    for (int i = 2; i*i < MAX;) {
        while (d[i] != -1) i++;
        for (int j = i; j + i < MAX; j += i) {
            if (d[j] == -1)
                d[j] = i;
        }
    }
    for (int i = 0; i < MAX; i++)
        if (d[i] == -1)
            d[i] = i;
    vector<int> c(MAX, 0);
    bool flag = true;
    for (int i = 0; flag && i < n; i++) {
        int m = a[i];
        while (m > 1) {
            int p = d[m];
            c[p]++;
            if (c[p] > 1) {
                flag = false;
                break;;
            }
            while (m % p == 0) m /= p;
        }
    }
    if (flag) {
        cout << "pairwise coprime" << endl;
        return 0;
    }
    
    queue<int> q;
    for (int i = 0; i < n; i++)
        q.push(a[i]);
    while (q.size() >= 2) {
        int u = q.front();
        q.pop();
        int v = q.front();
        q.pop();
        q.push(gcd(u, v));
    }
    if (q.front() == 1)
        cout << "setwise coprime" << endl;
    else
        cout << "not coprime" << endl;

    return 0;
}


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

count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

for i in range(n):
    b, f, r, v = map(int, input().split())
    count[b - 1][f - 1][r - 1] += v

flag = False
for b in count:
    if flag:
        print("####################")
    else:
        flag = True
    for f in b:
        for r in f:
            print(" " + str(r), end = "")
        print()


Measured memory_bytes: 5624
package main
import(
  "fmt"
)
func main() {
  var(
    a,n,m,c,count,counter int
  )
  fmt.Scan(&n,&m,&c)
  b:=make([]int,m)
  for i:=0;i<m;i++{
    fmt.Scan(&b[i])
  }
  for i:=0;i<n;i++{
    count=c
    for j:=0;j<m;j++{
      fmt.Scan(&a)
      a*=b[j]
      count+=a
    }
    if count>0{
      counter+=1
    }
  }
  fmt.Println(counter)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string a, b, c;
  cin >> a >> b >> c;
  char dif = 'A' - 'a';
  printf ("%c%c%c\n" , a[0] + dif, b[0] + dif, c[0] + dif);
}

Measured memory_bytes: 256
//k_tourist
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define mx 500005
#define non __builtin_popcount
#define ml map<ll, ll> 
#define uml unordered_map<ll, ll>
#define ms map<string , ll> 
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define pl pair<ll, ll>
#define vl vector<ll>
#define vll vector<pl>
#define tpl pair<ll, pl>
#define vlll vector<tpl>
#define vs vector<string>
#define pb push_back
#define mk make_pair
#define M_PI 3.14159265358979323846
#define endl '\n'
#define fst ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%I64d",&x)
#define inf ((ll)1e18 + 1)
#define bs binary_search
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define pow powr
#define rep(i,a,b)  for (i=(a);i<(b);i++)
#define nrep(i,a,b) for (i=(a);i>(b);i--)
using namespace std;
 
bool isp[mx];
 
void sv(){
 
	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}
 
ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

void bta_de_yarr(){
    
	ll  i, j,n, a[mx], m, od=0;
	cin>>n>>m;
	rep(i, 1, n+1)
	{
        cin>>a[i];
        a[i]/=2;

        if(a[i] & 1)
        od = 1;
    }

    ll l= a[1], fl=0;
    rep(i, 2, n+1){


        l= (a[i]/__gcd(a[i], l))*l;

        if(l > m)
        {
            fl = 1;
            break;
        }
/*
        //l= (a[i]/__gcd(a[i], l))*l;//(l/__gcd(a[i], l));
         ll x= a[i]/__gcd(a[i], l);
        // ll y= l/__gcd(a[i], l);


       // if(l > m)
       if(x > m/l)
        {
            fl = 1;
            break;
        }

        l= x*l;

        //l = x*y;
        */
    }

    ll ans=0;
    if(!fl){

        // // ans= m/l;// - m/(2*l);
        // // ll an= ans/2;
        // // if(ans %2)
        // // an++;

        // // ans= an;
        // // if(l&1 || (!od))
        // // ans= m/l - m/(2*l);

        // ll l1= (l/__gcd(l, 2LL)) *2;

        // ans= m/l - m/l1;

        // // else if(!od)
        // // ans= m/l;
        // // else
        // // {
        // //     ans= 
        // // }


        ll kr=1 , fg=0;//(l/a[1])%2

        rep(i, 1, n+1)
        if((l/a[i])%2 != kr)
        {
            fg= 1;
            break;
        }

        if(!fg){

           // ans= m/l;
            // if(kr){
            //     ans= m/(2*l);
            // }
            // else
            // {
                ans= m/l - m/(2*l);
            //}
            
        }

        

    }

    cout<<ans;
	
	cout<<endl;
}

int main(){
    fst
	ll t;
    t= 1;
	//cin>>t;
    while(t--){
        bta_de_yarr();
    }
    return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 3072
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <limits>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int solve()
{
    int len;
    std::cin >> len;

    std::string s;
    std::cin >> s;

    vector<vector<int>> subs(len, vector<int>(len, 0));

    for (int i = 1; i < len; ++i)
    {
        if (s[0] == s[i])
        {
            subs[0][i] = 1;
            subs[i][0] = 1;
        }
    }

    int maxLen = 0;
    for (int left = 1; left < len; ++left)
    {
        for (int right = left + 1; right < len; ++right)
        {
            if (s[left] != s[right])
                continue;

            if (right - subs[left-1][right-1] > left)
                subs[left][right] = subs[left - 1][right - 1] + 1;
            else
                subs[left][right] = subs[left - 1][right - 1];

            maxLen = std::max(maxLen, subs[left][right]);
        }
    }

    return maxLen;
}

int main()
{
    std::cout << solve() << std::endl;

    return 0;
}


Measured memory_bytes: 98176
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;
std::vector<ll> v;

void solve()
{
// string s;
  ll n,m,k,x=0,y=0,q,z,ans=0;
  cin>>x>>y>>z>>k;
  ll a[x],b[y],c[z];
  for (ll i = 0; i < x; ++i)
  {
  cin>>a[i];
  }
  sort(a,a+x,greater<ll>());
  
  for (ll i = 0; i < y; ++i)
  {
  cin>>b[i];
  }
sort(b,b+y,greater<ll>());
  for (ll i = 0; i < z; ++i)
  {
  cin>>c[i];
  }
  sort(c,c+z,greater<ll>());
  fr(i,0,x)fr(j,0,y)fr(l,0,z)
  {
    if((i+1)*(j+1)*(l+1)<=min(3000LL,x*y*z))
    {
      v.pb(a[i]+b[j]+c[l]);
    }
    else break;
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < k; ++i)
  {
    cout<<v[i]<<"\n";
  }
}

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


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

int main() {
  int k;
  string s;
  cin >> k >> s;
  if(s.size() <= k){cout << s <<endl;}
  else{
    for(int i=0; i<k ; i++){
    cout << s.at(i);
    }
  
  cout <<"..."<<endl;
  }
  
}


Measured memory_bytes: 3632
#include <stdio.h>
int main(void) {

	int a, b, z;

	scanf("%d %d", &a, &b);
	while (1) {
		if (a == 0 && b == 0) break;
		if(a > b) {
			z = a;
			a = b;
			b = z;
		}
		printf("%d %d\n", a, b);
		scanf("%d %d", &a, &b);
	}
	return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    int n; cin >> n;
    V<int> p(n);
    for(int i = 0; i < n; i++){
        int t; cin >> t;
        t--;
        p[i] = t;
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(p[i] != i) continue;
        if(p[i] == i && p[i + 1] != i){
            swap(p[i], p[i + 1]);
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>

int main() {

   int x, y, z, d, f;
   int w = 1;
   int e = 0;

   scanf("%d %d", &x, &y);

   if(x < y) {
      z = x;
      x = y;
      y = z;
   }

   while(x % 10 == 0 && y % 10 == 0) {
      x /= 10;
      y /= 10;
      e++;
   }
      

   while(y > 0) {
	  w = x % y;
	  x = y;
	  y = w;
   }

   for(f = e; f > 0; f--) {
      x *= 10;
   }

   printf("%d\n", x);
   return 0;
}



Measured memory_bytes: 2080
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int mod = 100000;
int dp[1 << 20][3], dp_prev[1 << 20][3];
int x[409], H, W; string S;
int power[20];
int main() {
	power[0] = 1; for (int i = 1; i < 20; i++)power[i] = power[i - 1] * 2;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S;
		for (int j = 0; j < W; j++) {
			if (S[j] == 'J')x[i * W + j] = 1;
			if (S[j] == 'O')x[i * W + j] = 2;
			if (S[j] == 'I')x[i * W + j] = 3;
			if (S[j] == '?')x[i * W + j] = 0;
		}
	}
	if (x[0] == 0 || x[0] == 1)dp_prev[0][1] += 1;
	if (x[0] == 0 || x[0] == 2)dp_prev[0][0] += 1;
	if (x[0] == 0 || x[0] == 3)dp_prev[0][0] += 1;
	for (int i = 1; i < H * W; i++) {
		int mass = i % W;
		for (int j = 0; j < power[W - 1]; j++) {
			int L = 0, R = 0;
			if ((j / power[mass]) % 2 == 1) {
				L = j - power[mass];
				R = L + power[mass - 1];
				if (x[i] == 0 || x[i] == 1) {
					if (mass != W - 1) { dp[L][1] += dp_prev[j][0] + dp_prev[j][1]; dp[L][1] %= mod; }
					if (mass == W - 1) { dp[L][0] += dp_prev[j][0] + dp_prev[j][1]; dp[L][0] %= mod; }
				}
				if (x[i] == 0 || x[i] == 2) {
					dp[L][0] += dp_prev[j][0]; dp[L][0] %= mod;
					dp[R][0] += dp_prev[j][1]; dp[R][0] %= mod;
				}
			}
			else {
				L = j;
				R = j + power[mass - 1];
				if (x[i] == 0 || x[i] == 1) {
					if (mass != W - 1) { dp[L][1] += dp_prev[j][0] + dp_prev[j][1]; dp[L][1] %= mod; }
					if (mass == W - 1) { dp[L][0] += dp_prev[j][0] + dp_prev[j][1]; dp[L][0] %= mod; }
				}
				if (x[i] == 0 || x[i] == 2) {
					dp[L][0] += dp_prev[j][0]; dp[L][0] %= mod;
					dp[R][0] += dp_prev[j][1]; dp[R][0] %= mod;
				}
				if (x[i] == 0 || x[i] == 3) { dp[L][0] += dp_prev[j][0] + dp_prev[j][1]; dp[L][0] %= mod; }
			}
		}
		for (int j = 0; j < power[W - 1]; j++) {
			dp_prev[j][0] = dp[j][0]; dp_prev[j][1] = dp[j][1];
			dp[j][0] = 0; dp[j][1] = 0;
		}
	}
	int C = 1; for (int i = 0; i < H*W; i++) if (x[i] == 0) C = C * 3 % mod;
	int sum = 0; for (int i = 0; i < power[W - 1]; i++) { sum += dp_prev[i][0] + dp_prev[i][1]; sum %= mod; }
	cout << (C + mod - sum) % mod << endl;
	return 0;
}

Measured memory_bytes: 18500
s = input()
k = int(input())
arr =[]
for i in range(len(s)):
    for j in range(i,i+5):
        if s[i:j+1] != '' and s[i:j+1] not in arr:
            arr.append(s[i:j+1])
arr = sorted(arr)
def print_arr(arr):
    for i in range(len(arr)):
        print(arr[i],sep="",end="/")
    print()   
print(arr[k-1])

Measured memory_bytes: 4060
<?php
fscanf(STDIN, "%d %d", $max, $target);

$cnt=0;
for($i = 0; $i <= $max; $i++){
  for($j = 0; $j <= $max; $j++){
    $k = $target - $i - $j;
    if($k >= 0 && $k <= $max){
      $cnt++;
    }
  }
}
echo $cnt."\n";
?>

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,K,C;
string S;
int sum[200010];
int pre[200010];
int sum2[200010];
int pre2[200010];

int main(){
	cin>>N>>K>>C;
	cin>>S;
	if(N==1){
		if(K==1&&S[0]=='o'){
			cout<<1<<endl;
		}else{
			//cout<<0<<endl;
		}
		return 0;
	}
	REP(i,N){
		sum[i]=0;
		pre[i]=-3000000;
		sum2[i]=0;
		pre2[i]=6000000;
	}
	REP(i,N){
		if(i==0){
			if(S[i]=='o'){
				sum[i]=1;
				pre[i]=0;
			}else{
				sum[i]=0;
			}
		}else{
			if(S[i]=='o'){
				if(pre[i-1]+C<i){
					pre[i]=i;
					sum[i]=sum[i-1]+1;
				}else{
					pre[i]=pre[i-1];
					sum[i]=sum[i-1];
				}
			}else{
				pre[i]=pre[i-1];
				sum[i]=sum[i-1];
			}
		}
	}
	for (int i=N-1;i>=0;i--){
		if(i==N-1){
			if(S[i]=='o'){
				sum2[i]=1;
				pre2[i]=i;
			}else{
				sum2[i]=0;
			}
		}else{
			if(S[i]=='o'){
				if(pre2[i+1]>i+C){
					pre2[i]=i;
					sum2[i]=sum2[i+1]+1;
				}else{
					pre2[i]=pre2[i+1];
					sum2[i]=sum2[i+1];
				}
			}else{
				pre2[i]=pre2[i+1];
				sum2[i]=sum2[i+1];
			}
		}
	}
	/*REP(i,N){
		cout<<sum[i]<<" "<<pre[i]<<" "<<sum2[i]<<" "<<pre2[i]<<endl;
	}*/
	int ans=0;
	REP(i,N){
		if(i==0){
			if(sum2[i+1]!=K-1)continue;
			if(S[i]=='o'&&(pre2[i+1]>C)){
				cout<<(i+1)<<endl;
				//ans++;
			}
		}else if(i==N-1){
			if(sum[i-1]!=K-1)continue;
			if(S[i]=='o'&&(pre[i+1]+C)<N-1){
				cout<<(i+1)<<endl;
				//ans++;
			}
		}else{
			if(sum2[i+1]+sum[i-1]!=K-1)continue;
			if(S[i]=='o'&&(pre2[i+1]>i+C)&&(pre[i-1]+C<i)){
				cout<<(i+1)<<endl;
				//ans++;
			}
		}
	}
	//cout<<ans<<endl;
}

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

const ll MOD=1e9+7;

int main(){
  ll n,m;
  cin>>n>>m;
  ll ans;
  if(abs(n-m)>1){
    ans=0;
  }else{
    ll p=1, q=1;
    for(int i=1; i<=n; i++){
      p*=i; 
      p%=MOD;
    }
    for(int i=1; i<=m; i++){
      q*=i; 
      q%=MOD;
    }
    ans=p*q%MOD;
    if(n==m) ans*=2;
  }
  ans%=MOD;
  cout<<ans<<endl;
}



Measured memory_bytes: 3588
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		double x=0, y=0;
		int deg=90;
		for(;;){
			String[] s=sc.nextLine().split(",");
			int r=Integer.parseInt(s[0]);
			int d=Integer.parseInt(s[1]);
			if(r==0&&d==0)
				break;
			x+=r*cos(toRadians(deg));
			y+=r*sin(toRadians(deg));
			deg-=d;
		}
		println((int)x+"");
		println((int)y+"");
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N,A,B;
    int j=0;
    int a=0;
    string S;
    cin >>N>>A>>B;
    cin >>S;
    for(int i=0;i<N;i++){
        if(S[i]=='a'){
            if(a<A+B){
                printf("Yes\n");
                a++;
            }else{
                printf("No\n");
            }
        }
        else if(S[i]=='b'){
            j++;
            if(a<A+B&&j<=B){
                printf("Yes\n");
                a++;
            }else{
                printf("No\n");
            }
        }
        else{
            printf("No\n");
        }
        }
    return 0;
}


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

int main(void){
  int N;
  cin >> N;
  if (N % 2 == 0) {
	  cout << N << endl;
  }
  else {
	  cout << 2 * N << endl;
  }
}

Measured memory_bytes: 256
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)
	writer := bufio.NewWriter(os.Stdout)

	var r, d, x int
	fmt.Sscan(getNextLine(scanner), &r, &d, &x)

	for i := 1; i <= 10; i++ {
		x = r*x - d
		fmt.Fprintln(writer, x)
	}
	writer.Flush()

}


Measured memory_bytes: 640
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  ll N;
  cin >> N;
  vector<ll> P(N);
  for(int i=0;i<N;i++) cin >> P.at(i);

  ll min_P=P.at(0);
  ll ans=0;
  for(int i=0;i<N;i++){
    if(P.at(i)<=min_P){
      ++ans;
      min_P=P.at(i);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll a[200005];
ll s,x;
ll ans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll l=0,r=0;
    s=a[0]; x=a[0];
    for(;;){
        while(r<n&&s==x){
            ans+=(r-l+1);
            r++;
            x=x^a[r];
            s=s+a[r];
        }
        if(s==x||r>=n){
            break;
        }
        //cout<<r<<" "<<s<<" "<<x<<endl;
        while(s!=x){
            s=s-a[l];
            x=x^a[l];
            l++;
            /*cout<<l<<endl;
            if(l==2){
                cout<<l<<" "<<s<<" "<<x<<endl;
                return 0;
            }*/
        }
        //cout<<l<<" "<<r<<" "<<s<<" "<<x<<" "<<ans<<endl;
    }

    cout<<ans<<endl;

}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = (ull)1e9 + 7;

int main(void)
{
	ll n,m;
	cin >> n >> m;
	vector<t3> as(n);
	rep(i, n) {
		ll a, b, c;
		cin >> a >> b >> c;
		as[i] = tie(a, b, c);
	}
	vector<vector<vector<ll>>> dp(8, vector<vector<ll>>(n + 1, vector<ll>(m + 1, -1e15)));
	rep(i, 2) {
		rep(j, 2) {
			rep(k, 2) {
				vector<vector<ll>>& d = dp[i * 4 + j * 2 + k];
				d[0][0] = 0;
			}
		}
	}
	rep(i, 2) {
		rep(j, 2) {
			rep(k, 2) {
				vector<vector<ll>>& d = dp[i * 4 + j * 2 + k];
				rep(t, n) {
					ll a, b, c;
					tie(a, b, c) = as[t];
					ll add = a * (i % 2 == 0 ? 1 : -1);
					add += b * (j % 2 == 0 ? 1 : -1);
					add += c * (k % 2 == 0 ? 1 : -1);
					rep(mm, m+1) {
						d[t + 1][mm] = d[t][mm];
					}
					repi(mm, 1, m+1) {
						d[t + 1][mm] = max(d[t + 1][mm], d[t][mm - 1] + add);
					}
				}
			}
		}
	}
	ll upper = 0;
	rep(i, 2) {
		rep(j, 2) {
			rep(k, 2) {
				vector<vector<ll>>& d = dp[i * 4 + j * 2 + k];
				upper = max(upper, d[n][m]);
			}
		}
	}
	cout << upper << endl;
	return 0;
}


Measured memory_bytes: 71040
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int main(){
  int n;
  cin >> n;
  vi v(n + n);
  rep(i,0,n+n) cin >> v[i];
  sort(all(v));
  int ans = 0;
  rep(i,0,n) ans+=v[i<<1];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main(){
  long long n,k,i,j,ans = 1000000000000;cin >> n >> k;
  long long x[n];
  for(i=0;i<n;i++) cin >> x[i];
  for(i=0;i<=n-k;i++){
    j=i+k-1;
    if(x[i]<=0 && 0<=x[j]) ans = min(ans,min(-x[i],x[j])*2+max(-x[i],x[j]));
    else ans = min(ans,max(abs(x[i]),abs(x[j])));
  }
  cout << ans << endl;
}

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

int main()
{
    char s[20];
    int sum=0;
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++){
        if(s[i]=='x')
            sum++;
    }
    if(sum<8)
        printf("YES\n");
    else
        printf("NO\n");
}


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

int main(){
  int n;
  cin>>n;
  unordered_map<string,int>mp;
  rep(i,n){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  ll ans=0;
  for(auto& p:mp){
    int s=p.second;
    ans+=(ll)s*(s-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >>n;
    int a[200010];
    int ans=0;
    int count=1;
    bool one=false;
    for(int i=0;i<n;i++){
        cin >>a[i];
    }
    for (int i = 0; i < n; i++)
    {
        if(a[i]==count){
            count++;
            if(a[i]==1){
                one =true;
            }
        }else{
            ans++;
        }
    }
    if(one){
    cout <<ans<<endl;
    }else{
        cout <<-1<<endl;
    }
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int p,q,r,t;
    scanf("%d%d%d",&p,&q,&r);
    if(p>q)
    {
        t=p;
        p=q;
        q=t;
    }
    if(q>r)
    {
        t=q;
        q=r;
        r=t;
    }
    printf("%d\n",p+q);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
                 // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define pb(v,x) v.push_back(x)
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Sort(v) sort(v.begin(),v.end())
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#include <set>
#include <map>

int dp[100005];
const int inf=100000000;
int main()
{
    int h,n;
    cin>>h>>n;
    int a[n][2];
    f0(i,n)
    cin>>a[i][0]>>a[i][1];
    f1(i,h)
    dp[i]=inf;
    f1(i,h)
    {
        f0(j,n)
        {
            dp[i]=min(dp[i],dp[max(0,i-a[j][0])]+a[j][1]);
        }
    }
    cout<<dp[h];
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7

def modcmb(n, r, mod):
    x = 1
    y = n
    for i in range(2,r+1):
        x *= i
        x %= MOD
        y *= n-i+1
        y %= MOD
    
    return y * pow(x, mod-2, mod) % mod


def main():
    n,a,b = map(int, readline().split())

    if n == 2:
        print(0)
        exit()

    ans = pow(2, n, MOD) - 1 - modcmb(n, b, MOD) - modcmb(n, a, MOD)
    print(ans % MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  char s[100002];
  int len, i, j, ans01=0, ans10=0;
  cin >> s;
  len=strlen(s);
  for(i=0; i<len; i++){
    if((s[i]-'0'-i)%2==0) ans10++;
    else ans01++;
  }
  cout <<min(ans10, ans01);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
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;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////




int main() {
	int N,K; cin >> N >> K;
	vector<int> A(200001);
	rep(i,N)
	{
		int a; cin >> a; A.at(a)++;
	}
	sort(ALL(A));
	reverse(ALL(A));

	ll ans = 0;
	FOR(i,K,200001)
	{
		ans += A.at(i);
	}

	cout << ans << endl;


}

Measured memory_bytes: 1024
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

j = m - 1
cost = sum(b)
cnt = m
ans = 0
for i in range(n + 1):
    if i != 0:
        cost += a[i - 1]
        cnt += 1
    while cost > k and j >= 0:
        cost -= b[j]
        cnt -= 1
        j -= 1
    if cost <= k:
        ans = max(cnt, ans)
print(ans)

Measured memory_bytes: 40480
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int K = sc.nextInt();
    Integer[] l = new Integer[N];

    for (int i = 0; i < N; i++) {
      l[i] = sc.nextInt();
    }

    sc.close();

    Arrays.sort(l, Comparator.reverseOrder());

    Integer length = 0;

    for (int i = 0; i < K; i++) {
      length += l[i];
    }

    System.out.println(length);

  }

}

Measured memory_bytes: 23124
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n;cin >> n;
	vector<ll> v;
	
	vector<pair<ll,ll> > ans;
	
	ll ma = -1000000000,mi = 1000000000;
	int A,B;
	
	REP(i,n)
	{
		ll tmp;cin >> tmp;
		v.PB(tmp);
		if(ma <= tmp)
		{
			ma = tmp;A = i;
		}
		if(mi >= tmp)
		{
			mi = tmp;B = i;
		}
	}
	
	//cout << ma << ' ' << mi << endl;
	//SHOW1d(v,v.size()); 
	
	if(abs(ma) > abs(mi))
	{
		//cout << "!!!" << endl;
		REP(i,n)
		{
			//if(i == A)continue;
			ans.PB(MP(i,A));
			v[i] += v[A];
		}
		//SHOW1d(v,v.size());
		REP(i,n-1)
		{
			ans.PB(MP(i+1,i));
			v[i+1] += v[i];
		}
	}
	else
	{
		//cout << "!!!!!" << endl;
		REP(i,n)
		{
			//if(i == B)continue;
			ans.PB(MP(i,B));
			v[i] += v[B];
		}
		//SHOW1d(v,v.size());
		for(int i = n-1;i > 0;i--)
		{
			ans.PB(MP(i-1,i));
			v[i-1] += v[i];
		}
	}
	
	cout << ans.size() << endl;
	
	REP(i,ans.size())
	{
		cout << ans[i].SE+1 << ' ' << ans[i].FI+1 << endl;
	}
	
//	SHOW1d(v,v.size());
	
	return 0;
}

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


void solve(long long K, long long A, long long B){
    for(int i=A; i<=B; i++){
        if(i%K == 0){
            cout << "OK" << endl;
            return;
        }
    }
    cout << "NG" << endl;
    return;
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(K, A, B);
    return 0;
}


Measured memory_bytes: 3764
s = input().lower()
n = len(s)

dp_a = 0
dp_ab = 0
dp_abc = 0
hatena = 1

mod = 10**9 + 7

for i in range(n):
    if s[i]=="a":
        dp_a = (dp_a + hatena) % mod
    elif s[i]=="b":
        dp_ab = (dp_a + dp_ab) % mod
    elif s[i]=="c":
        dp_abc = (dp_ab + dp_abc) % mod
    else:
        dp_abc = (dp_ab + 3 * dp_abc) % mod
        dp_ab = (3 * dp_ab + dp_a) % mod
        dp_a = (3 * dp_a + hatena) % mod
        hatena = (hatena * 3) % mod

print(dp_abc)


Measured memory_bytes: 67580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<vector<ll>> a(n,vector<ll>(n));
	vector<vector<ll>> dp(n,vector<ll>(n));
	rep(i,n)rep(j,n){
		cin>>a[i][j];
		dp[i][j]=a[i][j];
	}
	rep(k,n)rep(i,n)rep(j,n) chmin(dp[i][j],dp[i][k]+dp[k][j]);
	bool flag=true;
	rep(i,n)rep(j,n){
		if(a[i][j]!=dp[i][j]) flag=false;
	}
	if(!flag){
		cout<<-1<<endl;
		return 0;
	}
	ll ans=0;
	rep(i,n)FOR(j,i+1,n){
		bool f=true;
		rep(k,n){
			if(k==i || k==j) continue;
			if(dp[i][k]+dp[k][j]==dp[i][j]){
				f=false;
				break;
			}
		}
		if(f){
			ans+=dp[i][j];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1664
d,g=map(int,input().split())
l=[0]+[list(map(int,input().split())) for i in range(d)]

def fnc(a,b):#点の大きいものから解いていく
    if a==0:#全部試したらおわり
        return 10**9
    s=min(l[a][0],b//(a*100))#全部か部分か
    t=100*a*s#基本スコア
    if s==l[a][0]:
        t+=l[a][1]#ボーナス
    if t<b:#達してないなら
        s+=fnc(a-1,b-t)#次の問題
    return(min(s,fnc(a-1,b)))#a-1問目から解く
print(fnc(d,g))

Measured memory_bytes: 3064
def get_all_index(a, value)
  index = []
  _a = a.dup
  while _a.include?(value)
    next_i = _a.index(value)
    index << next_i
    _a[next_i] = nil
  end
  index
end

n = gets.to_i
virgin = true

n.times do
  puzzle = []
  errata = []
  
  puts "" unless virgin

  9.times do
    puzzle << gets.split.map(&:to_i)
    errata << Array.new(9, true)
  end

  0.upto(8) do |i|
    0.upto(8) do |j|
      j.upto(8) do |k|
        if puzzle[i][j] == puzzle[i][k] && j != k
          errata[i][j] = false
          errata[i][k] = false
        end
        if puzzle[j][i] == puzzle[k][i] && j != k
          errata[j][i] = false
          errata[k][i] = false
        end
      end
    end
  end
  
  current_box = []
  box_index = []
  -1.upto(1) do |i|
    -1.upto(1) do |j|
      box_index << [i, j]
    end
  end
  [1,4,7].each do |i|
    [1,4,7].each do |j|
      current_box = []
      current_box_index = []
      box_index.each do |b|
        current_box_index << [b[0] + i, b[1] + j]
        current_box << puzzle[b[0] + i][b[1] + j]
      end
      if (temp = current_box.uniq.select{ |x| current_box.index(x) != current_box.rindex(x) }).any?
        temp.each do |m|
          get_all_index(current_box, m).each do |i|
            x, y = current_box_index[i]
            errata[x][y] = false
          end
        end
      end
    end
  end

  0.upto(8) do |i|
    0.upto(8) do |j|
      if errata[i][j]
        print " #{puzzle[i][j]}"
      else
        print "*#{puzzle[i][j]}"
      end
      puts "" if j == 8
    end
  end

  virgin = false if virgin
end

Measured memory_bytes: 6132
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long int n,sum=0; 
    cin>>n;
    for(int i=1;i<=n;i++)
    {
      if(i%3!=0&&i%5!=0)
      sum+=i;
    }
    cout<<sum<<endl;

    return 0;
}

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

typedef long long int ll;
#define PI 3.141592653

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll a,b,h,m;
  cin>>a>>b>>h>>m;
  double thetah=((60*h)+m)/2.000000000;
  double thetam=m*6;
  //cout<<thetah<<" "<<thetam<<endl;
  double theta=min(abs(thetah-thetam),360-abs(thetah-thetam));
  //cout<<theta<<" "<<cos(theta);
  double ans=(a*a)+(b*b)-(2*a*b*cos((theta*PI)/180));
  ans=sqrt(ans);
  printf("%0.9lf\n",ans);
  return 0;
}


Measured memory_bytes: 4212
#include <iostream>

using namespace std;

bool func(int i, int d)
{
	int x = 0;

	while (i)
	{
		int y = i % 100;
		if (y == 0)
		{
			x++;
			i /= 100;
		}
		else
		{
			break;
		}
	}

	return x == d;
}

int main(void)
{
	int d, n;

	cin >> d >> n;

	int x = 0;

	int i = 1;

	for (; x < n;i++)
	{
		if (func(i, d))
		{
			x++;
		}
		
	}

	cout << i - 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int pw(int a,int t=mod-2){
	int x=1;
	while(t){
		if(t&1)x=x*a%mod;
		a=a*a%mod,t/=2;
	}
	return x;
}
int32_t main(){
	if(fopen("input.txt", "r"))
		freopen("input.txt", "r", stdin),
		freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,sum=0;
	cin >> n;
	int a[n],v[n]={0},f=1;
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=1;i<n;i++)
		v[i]=(v[i-1]+pw(i))%mod,
		f=(f*i)%mod;
	for(int i=1;i<n;i++)
		sum=(sum+(v[i]*(a[i]-a[i-1]))%mod)%mod;
	cout << (f*sum)%mod;
}


Measured memory_bytes: 1792
# C - Half and Half

A, B, C, X, Y = map(int, input().split())

# 条件を満たすときのA, B, ABの買い方を全列挙したい
# A, Bの枚数は、ABの値が決まれば、一意に定まるため、
# ABのみループする。

ans = 10**18
for i in range(0, max(X, Y)*2+1, 2):
    x = max(X-i//2, 0)
    y = max(Y-i//2, 0)
    ans = min(ans, x*A + y*B + i*C)
    
print(ans)

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

using namespace std;

int N,M,K,L,R,H,W;

const long long int MOD=1000000007;

class UnionFind{
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num){
		num++;
		parent.resize(num);
		rank.resize(num);
		for(int i=0;i<num;i++){
			parent[i]=i;
			rank[i]=0;
		}
	}
	int Find(int node){
		if(parent[node]==node)return node;
		else return parent[node]=Find(parent[node]);
	}
	void Unite(int u,int v){
		u=Find(u);
		v=Find(v);
		if(u==v)return ;
		if(rank[u]<rank[v])parent[u]=v;
		else{
			parent[v]=u;
			if(rank[u]==rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u,int v){
		return Find(u)==Find(v);
	}
};

int main(){
	int N,M,K;
	cin>>N>>M>>K;
	UnionFind uf(N);
	vector<int>v(N,-1);
	for(int i=1;i<=K;i++){
		int a;
		cin>>a;
		if(a==1){
			int b,c;
			cin>>b>>c;
			b--,c--;
			if(v[uf.Find(b)]!=v[uf.Find(c)]&&min(v[uf.Find(b)],v[uf.Find(c)])!=-1){
				cout<<i<<endl;
				return 0;
			}
			int club=0;
			if(v[uf.Find(b)]==-1)club=v[uf.Find(c)];
			else club=v[uf.Find(b)];
			uf.Unite(b,c);
			v[uf.Find(b)]=v[uf.Find(c)]=club;
		}
		else{
			int b,c;
			cin>>b>>c;
			b--,c--;
			if(v[uf.Find(b)]==-1)v[uf.Find(b)]=c;
			else if(v[uf.Find(b)]!=c){
				cout<<i<<endl;
				return 0;
			}
		}
	}
	cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 3900