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

int main()
{
    int N ;
    cin >> N ;
    string s[4] = {"AC" , "WA" , "TLE" , "RE"} ;
    int c[4] = {0,0,0,0};
    while(N--)
    {
        string x ;
        cin >> x ;
        if(x == s[1])
            c[1]++ ;
        else if(x == s[0])
            c[0]++ ;
         else if(x == s[2])
            c[2]++ ;
        else if(x == s[3])
            c[3]++ ;
    }
    cout << s[0] << " x " << c[0] << endl;
    cout << s[1] << " x " << c[1] << endl;
    cout << s[2] << " x " << c[2] << endl;
    cout << s[3] << " x " << c[3] << endl;
    return 0 ;
}


Measured memory_bytes: 3616
h, w = map(int, input().split())
n = 10
g = [None] * n
for i in range(n):
    g[i] = list(map(int, input().split()))

def warshall_floyd(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

cost = warshall_floyd(g, n)
ans = 0
for _ in range(h):
    for w in list(map(int, input().split())):
        if w == -1: continue
        ans += cost[w][1]
print(ans)


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

int main(){
    int N;
    cin >> N;
    vector<string> vec(N);
    int count = 0;
    for(int i = 0; i < N; i++){
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    count = (int)vec.size();
    cout << count  << endl;
    return 0;
}

Measured memory_bytes: 9596
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll k;
	cin >> k;
	set <ll> rem;
	ll d = 7 % k;
	ll c = 1;
	while (true) {
		if (d == 0) {
			cout << c << "\n";
			return 0;
		}
		d = (d * 10 + 7) % k;
		if (rem.find(d) != rem.end())
			break;
		rem.insert(d);
		c++;
	}
	cout << "-1\n";

}


Measured memory_bytes: 50388
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        int n  = a.length;

        int ans = Integer.MAX_VALUE;
        int count = 0;
        for (int i = 'a'; i <= 'z'; i++) {
            count = getCount(a, i);
//            System.out.println((char) i + " count: " + count);
            ans = Math.min(ans, count);
        }
        System.out.println(ans);
    }

    static int getCount(char[] a, int i) {
        int maxSpan = 0;
        int lastJ = -1;

        for (int j = 0; j < a.length; j++) {
            if (a[j] == i) {
                maxSpan = Math.max(maxSpan, j - lastJ - 1);
//                System.out.println("j: " + j + ", maxSpan: " + maxSpan + "");
                lastJ = j;
            }
        }

        return Math.max(maxSpan, a.length - lastJ - 1);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <ctype.h>
char ans[101];
void UL(char line[],char type){
    int i=1,t=1;
    ans[0]=type=='U'?toupper(line[0]):tolower(line[0]);
    while(line[i]){
        if(line[i] == '_'){
            ans[t++]=toupper(line[++i]);
            i++;
        }
        else ans[t++]=line[i++];
    }
    ans[t]=0;
}
void D(char line[]){
    int i=1,t=1;
    ans[0]=tolower(line[0]);
    while(line[i]){
        if(isupper(line[i])){
            ans[t++]='_';
            ans[t++]=tolower(line[i++]);
        }
        else ans[t++]=line[i++];
    }
    ans[t]=0;
}

int main(void){
    char line[101],type;
    for(;scanf("%s %s",line,&type),type != 'X';){
        type=='D'?D(line):UL(line,type);
        printf("%s\n",ans);
    }
    return 0;
}

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

int main(void) {
  long long int a,b,a_gcd,b_gcd,r,gcd,lcm,tmp;
  while(scanf("%lld %lld",&a,&b) != EOF) {
    if(b > a) {
      tmp = a;
      a = b;
      b = tmp;
    }
    /* GCD */
    a_gcd = a;
    b_gcd = b;
    while((r = a_gcd % b_gcd) != 0) {
      a_gcd = b_gcd;
      b_gcd = r;
    }
    gcd = b_gcd;
    /* LCM */
    lcm = (a*b)/gcd;
    printf("%lld %lld\n",gcd,lcm);
  }
  return 0;
}

Measured memory_bytes: 596
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define MAX_N 100000000;
#define INF 1000000000;

int main(){
  int n;
  cin >> n;
  int s[n+1];
  for(int i=0;i<n+1;i++){
    s[i] = 0;
  }
  int a = 2;
  int d;
  for(int i=2;i<n+1;i++){
    d = i;
    while(d != 1){
      while(d%a == 0){
        d /= a;
        s[a] += 1;
      }
      a += 1;
    }
    a = 2;
  }
  int e3,e5,e15,e25,e75;
  e3 = 0;
  e5 = 0;
  e15 = 0;
  e25 = 0;
  e75 = 0;
  int ans = 0;
  for(int i=1;i<n+1;i++){
    if(s[i] >= 74) e75 += 1;
    if(s[i] >= 24) e25 += 1;
    if(s[i] >= 14) e15 += 1;
    if(s[i] >= 4) e5 += 1;
    if(s[i] >= 2) e3 += 1;
  }
  ans += e75;
  ans += e25*(e3-1);
  ans += e15*(e5-1);
  ans += (e5-1)*e5*(e3-2)/2;

  cout << ans << endl;



  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

vector<bool> isp;

void sieve(int x=pow(10,6)+10) {
  isp.resize(x,true); 
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=x; i++) {
    if (isp[i]) for(int j=2; i*j<=x; j++) isp[i*j] = false;
  }
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

ll pnk(ll n, ll k) {
  ll pn = n, now = 0, result = 1;
  while (k>=1ll<<now) {
    if (k&1ll<<now) result = result * pn % MOD;
    pn = pn * pn % MOD;
    now++;
  }
  return result;
}

int main() {
  ll N, K; cin >> N >> K;

  // map<string, ll> m;
  // rep(i,1<<N/2) {
  //   string S; rep(j,N/2) S += i&1<<j ? '1' : '0';
  //   rep(j,N/2) S += S[N/2-1-j];
  //   rep(j,N) {
  //     m[S]++;
  //     S = S.substr(1) + S[0];
  //   }
  // }
  // cout << m.size() << endl;

  sieve();
  vector<ll> yaku;
  for (ll i=1; i*i<=N; i++) {
    if (N%i==0) {
      yaku.push_back(i);
      if (i*i!=N) yaku.push_back(N/i);
    }
  }
  sort(all(yaku));
  // debug(all(yaku));

  ll l = yaku.size();
  vector<ll> count(l,0);

  rep(i,l) {
    count[i] = pnk(K,(yaku[i]+1)/2);
    rep(j,i) if (yaku[i]%yaku[j]==0) count[i] = (count[i]-count[j]+MOD) % MOD;
  }
  // debug(all(count));

  ll result = 0; rep(i,l) result = (result+(yaku[i]%2 ? yaku[i] : yaku[i]/2)*count[i]) % MOD;
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N_MAX = 1000000;

int A[N_MAX];

int* partition(int* A, int p, int r){
  int x = A[r];
  int i = p - 1;
  rep(j, p, r){
    if(A[j] <= x){
      i = i + 1;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  // add partition index as the extra element
  A[r+1] = i + 1;
  return A;
}

void swap(int* a, int* b){
  int* tmp = a;
  a = b;
  b = tmp;
}

int main(){
  int n;
  cin >> n;
  rep(i, 0, n) scanf("%d", &A[i]);
  int* sorted_A = partition(A, 0, n-1);
  int part_ix = sorted_A[n];
  rep(i, 0, n){
    if(i == part_ix) cout << "[" << sorted_A[i] << "]";
    else cout << sorted_A[i];
    
    if(i != n-1) cout << " ";
    else cout << endl;

  }

  return 0;
}



Measured memory_bytes: 3508
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){

    string s;
    cin >> s;

    int N = s.size();

    int P = 0;
    REP(i,N) if(s[i] == 'p') P++;

    cout << N/2 - P << endl;

    return 0;
}

Measured memory_bytes: 512
N,M=[int(i) for i in input().split()]
# 二次元配列を得られる
A = []
answer=[-1]*N
for i in range(M):
    A.append(list(map(int,input().split())))
j=0
for i in range(M):
    if answer[int(A[i][0])-1] == -1:
        answer[int(A[i][0])-1] = int(A[i][1])
    elif answer[int(A[i][0])-1] == int(A[i][1]):
        answer[int(A[i][0])-1] = int(A[i][1])
    else:
        print(-1)
        j=j+1
        break
seisu=0
if j==0 and answer[0]==0 and N!=1:
    j=j+1
    print(-1)
if j==0 and (answer[0]==0 or answer[0]==-1) and N == 1:
    j=j+1
    print(0)
if j==0:
    for i in range(N):
        if answer[i]==-1:
            '''
            N = 5 case
            -1,7,-1,9,0
            ?7?90
            5 digits
            17090 
            '''
            if i == 0 :
                answer[0]=1
            else:
                answer[i]=0

        seisu=answer[i]*(10**(N-i-1))+seisu
    print(seisu)


Measured memory_bytes: 3064
A1, A2, A3 = map(int, input().split(" "))
if 1 <= A1 <= 13 and 1 <= A2 <= 13:
	if 1<= A3 <= 13:
		if A1 + A2 + A3 >= 22:
			print("bust")
		else:
			print("win")

Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    D = 1
    LOG = {}
    PATH = []
    for i in range(N):
        PATH.append(D)
        LOG.setdefault(D,i)

        if LOG[D] == i:
            D = A[D-1]
            # print(PATH,LOG, i)
            continue
        else:
            # print("break",D, i)
            break

    # if i-LOG[D] < K:
    if LOG[D] < K:
        K = (K-i)%(i-LOG[D])
        LAST = PATH[LOG[D]+K]
    else:
        LAST = PATH[K]
    print(LAST)

if __name__ == '__main__':
    main()

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

int selection_sort(int A[],int n){
    int m=0;
    for(int i=0;i<n-1;i++){
        int k=i;
        for(int j=i+1;j<n;j++){
            if(A[k]>A[j])k=j;
        }
        if(k!=i){
            int t=A[k];
            A[k]=A[i];
            A[i]=t;
            m++;
        }
    }
    return m;
}

int main(){
    int A[100],n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>A[i];
    int m=selection_sort(A,n);
    for(int i=0;i<n;i++){
        if(i==0)cout<<A[i];
        else cout<<' '<<A[i];
    }
    cout<<endl;
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string S1,S2,S3;
    cin>>S1>>S2>>S3;
    cout<<"A"<<S2[0]<<"C"<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define PRECISION(x) cout << fixed << setprecision(x); 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(i,n) for (int i = 0; i < n; ++i)
#define DO(X) while(X--)
#define DRI(X) int (X); cin >> X
#define DRII(X, Y) int X, Y; cin >> X >> Y
#define DRIII(X, Y, Z) int X, Y, Z; cin >> X >> Y >> Z
#define read(X) for(int &ele : (X)) cin >> ele
#define readI(X) for(int idx = 1; idx < SZ((X)); ++idx) cin >> (X)[idx]
#define debug(x) cerr << '>' << #x << ':' << x << endl
#define MP make_pair
#define PB push_back
#define F first
#define S second

using namespace std;
typedef long long LL;
const int INF = 1<<29;
inline int in() { int x; cin >> x; return x; }
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }

int main(){
	FAST_IO 
	DRI(N);
	string one, two; cin >> one >> two;
	int fIdx = 0, sIdx = 0;
	while(fIdx < N || sIdx < N){
		if(fIdx == sIdx){
			cout << one[fIdx];
			fIdx++;
		}else{
			cout << two[sIdx];
			sIdx++;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int x,a,b;
    cin>>x>>a>>b;
    int A=x-a,B=x-b;
    if(A<0)A*=-1;
    if(B<0)B*=-1;
    if(A>B)cout<<"B"<<endl;
    else cout<<"A"<<endl;
    return 0;
}

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

int  main()
{
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n)
		cin >> a[i];
	sort(a.begin(), a.end());
	cout << abs(a.front() - a.back()) << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
li = list(map(int, input().split()))

def b_s(li):
    num = 0
    for index in range(len(li)):
        for j in range(len(li) - 1, index, -1):
            if li[j] < li[j-1]:
                li[j], li[j-1] = li[j-1], li[j]
                num += 1
    return li, num

li, num = b_s(li)
print(*li)
print(num)



Measured memory_bytes: 5608
//// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
////
//
//#include <iostream>
//#include<vector>
//#include<string>
//using namespace std;
//
//int kumi[100005][26];
//int rui[100005];
//
//void inskumi(string s,int key) {
//    for (int i = 0; i < 10; i++) {
//        kumi[key][s[i] - 'a']++;
//    }
//}
//
//void check(int key) {
//    for (int i = 0; i < key; i++) {
//        bool ok = true;
//        for (int j = 0; j < 26; j++) {
//            if (kumi[i][j] != kumi[key][j]) {
//                ok = false;
//                break;
//            }
//        }
//        if (ok == true) {
//            rui[i]++;
//            break;
//        }
//    }
//}
//int  ruiwa(int x) {
//    int sum = 0;
//    for (int i = x; i > 0; i--) {
//        sum += i;
//    }
//    return sum;
//}
//int main()
//{
//    int n;
//
//    cin >> n;
//
//    for (int i = 0; i < n; i++) {
//        string s;
//        cin >> s;
//        inskumi(s, i);
//        check(i);
//
//    }
//    long long  ans = 0;
//
//    for (int i = 0; i < n; i++) {
//        if (rui[i] != 0) {
//            ans += ruiwa(rui[i]);
//        }
//    }
//    cout << ans << endl;
//
//}
//


#include<iostream>
#include<map>
#include<algorithm>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace  std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	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: 11384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,m;
	cin >> n >> m;
	ll dp[(1<<n)][n];
	ll d[n][n];
	FOR(i,0,n)FOR(j,0,n)d[i][j]=INF;
	FOR(i,0,m){
		ll a,b,c;
		cin >> a >> b >> c;
		d[a][b]  = c;
	}
	FOR(i,0,(1<<n))
		FOR(j,0,n)
			dp[i][j]=INF;
	dp[(1<<n)-1][0] = 0;
	FORR(S,0,(1<<n)-1){
		FOR(v,0,n){
			FOR(u,0,n){
				if(!(S>>u&1))
					dp[S][v] = min(dp[S][v],dp[S|1<<u][u]+d[u][v]);
			}
		}
	}
	if(dp[0][0]<INF)cout << dp[0][0] << endl;
	else cout << "-1" << endl;
}



Measured memory_bytes: 6968
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

long long dp[51][51][3000]={};

int main(){

	int n,a;
	cin>>n>>a;

	int x[50];
	for(int i=0;i<n;i++){
		scanf("%d",&x[i+1]);
	}


	for(int j=0;j<=n;j++){
		for(int k=0;k<=n;k++){
			for(int s=0;s<=2500;s++){
				if(j==0 && k==0 && s==0) dp[j][k][s]=1;
				else if(j>=1 && s<x[j]) dp[j][k][s]=dp[j-1][k][s];
				else if(j>=1 && k>=1 && s>=x[j]) dp[j][k][s]=dp[j-1][k][s]+dp[j-1][k-1][s-x[j]];
				else dp[j][k][s]=0;
			}
		}
	}

	long long res=0;
	for(int i=1;i<=n;i++) res+=dp[n][i][i*a];

	cout<<res<<endl;

}

Measured memory_bytes: 61184
n,m = map(int, input().split())
p = list(map(int, input().split()))

par = [i for i in range(n)]
#rootの計算量は、parが最初の状態に近いほど値は小さくて、高々O(n)
def root(x):
	tmp = par[x]
	if tmp == x:
		return x
	else:
		a = root(tmp)
		par[x] = a
		return a

def merge(x, y):
	x = root(x)
	y = root(y)
	if x != y:
		par[x] = y
		return

for i in range(m):
	x, y = map(int, input().split())
	merge(x-1, y-1)
	#print(par)

ans = 0

for i in range(n):
	if p[i]-1 == i:
		ans += 1
	elif root(p[i]-1) == root(i):
		ans += 1
print(ans)

Measured memory_bytes: 13812
import sys
input=lambda: sys.stdin.readline().rstrip()
D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for _ in range(D)]

result = 0
Last = [0]*26
for i in range(D):
    t = int(input())
    result += S[i][t - 1]
    Last[t-1] = i+1
    for j in range(26):
        result -= C[j] * (i + 1 - Last[j])
    print(result)



Measured memory_bytes: 74764
import sys
read = sys.stdin.buffer.read#全部読み込むやつ
readline = sys.stdin.buffer.readline#1行読み込むやつ
readlines = sys.stdin.buffer.readlines#リストで読み込むらしい

import math
H,A = map(int,read().split())
ans = math.ceil(H/A)
print(ans)

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

int main(){
  string s,t; cin>>s>>t;
  bool ans = false;
  rep(i, s.size()){
    if (s==t){
      cout << "Yes" << endl;
      return 0;
    }
    s = s.back() + s.substr(0, s.size()-1);
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define None cout<<"None"<<endl
typedef long long ll;
using namespace std;

int main() {
	int a,b,c,d; cin >> a >> b >> c >> d;
	if (abs(a-c) <= d) Yes;
	
	else if (abs(a-b) <= d && abs(b-c) <= d) Yes;
	else No;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <limits>
#include <cmath>
#include <iomanip>

using namespace std;

struct bar{
    double x,y,r;
    bar(){};
    bar(double x, double y, double r) : x(x), y(y), r(r){};
};

const int MAX = 1001;
const int WHITE = 1;
const int BLACK = 2;
const int GRAY = 3;
const double INFTY = numeric_limits<double>::max();
vector<pair<int,double> > G[MAX];
int V, gv;

double bfs(int s){
    vector<double> d(V,INFTY);
    vector<int> color(V, WHITE);
    d[s] = 0.0;
    color[s] = GRAY;
    priority_queue<pair<double, int>, vector<pair<double,int> >, greater<pair<double,int> > > Q;
    Q.push(make_pair(d[s],s));

    while(!Q.empty()){
        auto q = Q.top(); Q.pop();
        double c = q.first;
        int u = q.second;
        if(d[u] < c) continue;
        color[u] = BLACK;
        for(auto v : G[u]){
            if(color[v.first] == BLACK) continue;
            if(d[v.first] > d[u] + v.second){
                d[v.first] = d[u] + v.second;
                Q.push(make_pair(d[v.first], v.first));
            }
        }
    }
    return d[gv];
}

double calc(bar &A, bar &B){
    return max(sqrt( (A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y) ) - A.r - B.r, 0.0);
}

int main(){
    double x,y,r;
    bar s,g;
    cin >> x >> y; s = bar(x,y,0.0);
    cin >> x >> y; g = bar(x,y,0.0);
    int N; cin >> N;
    vector<bar> bs(N+2);
    bs[0] = s; bs[N+1] = g;
    gv = N+1;
    V = N+2;
    for(int i=1;i<=N;i++){
        cin >> x >> y >> r;
        bs[i] = bar(x,y,r);
    }

    for(int i=0;i<N+2;i++){
        for(int j=0;j<N+2;j++){
            if(i==j) continue;
            double cost = calc(bs[i], bs[j]);
            G[i].push_back(make_pair(j,cost));
            G[j].push_back(make_pair(i,cost));
        }
    }
    cout << fixed << setprecision(15);
    cout << bfs(0) << endl;
    return 0;
}

Measured memory_bytes: 38000
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main() {
   int N;
   cin >> N;
   
   int ans = 200;
   for (int i = 1; i < N; i++) {
      int A = i;
      int B = N - i;
      string strA = to_string(A);
      string strB = to_string(B);
      int tmp = 0;
      for (int j = 0; j < strA.size(); j++) {
         tmp += ctoi(strA[j]);
      }
      for (int j = 0; j < strB.size(); j++) {
         tmp += ctoi(strB[j]);
      }
      if (tmp < ans) {
         ans = tmp;
      }
   }
   
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <climits> 
#include <map>
using namespace std;

const int MAX_V = 1000;
const int INF = 1000000; 
int v;
int g[MAX_V][MAX_V];
int d[MAX_V]; 
bool used[MAX_V]; 

void dijkstra(int s)
{
  fill(d, d + v, INF);
  fill(used, used + v, false);
  d[s] = 0;
  for(;;){
 
    int i = -1;
    for(int j = 0; j < v; ++j)
      if(!used[j] && (i == -1 || d[i] > d[j]))
	i = j;
    if(i == -1)break;
    used[i] = true;
    for(int j = 0; j < v; ++j)
      d[j] = min(d[j], d[i] + g[i][j]);
  }
}

int main()
{
  for(;;){
    int gv, ge;
    cin >> ge;
    if(ge==0){return 0;}
    set<int> s;

    fill(&g[0][0], &g[MAX_V][0], 100000);
    //for(int i=0;i<5;i++){for(int j=0;j<5;j++){cout << g[i][j] << " ";}cout << endl;}


    for(int i = 0; i < ge; ++i){
      int gs, gt, gd;
      cin >> gs >> gt >> gd;
      g[gs][gt]=gd;
      g[gt][gs]=gd;
      s.insert(gs);
      s.insert(gt);
    }

    gv=s.size();
    v = gv;

    vector<pair<int,int> > p(s.size());
    set<int>::iterator it= s.begin();



    int count=0;
    while(it!=s.end()){
      dijkstra(*it);
      //for(int i=0;i<v;i++)cout << d[i] << endl;

      int sum=0;
      for(int i=0;i<v;i++){sum+=d[i];}
      //cout << sum << ":" << *it << endl;
      p[count].first=sum;
      p[count].second=*it;
      it++;
      count++;
    }

    sort(p.begin(),p.end());
    
    //for(int i=0;i<p.size();i++)
    cout << p[0].second << " " << p[0].first << endl;
  }
  return 0;
}

Measured memory_bytes: 5108
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 12160
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

from collections import defaultdict
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)

ans = defaultdict(int)
for i in range(n):
    ans[uf.find(i)] += 1

print(max(ans.values()))

Measured memory_bytes: 100876
from sys import stdin
H, W = map(int, stdin.readline().split())
C = [list(map(int, stdin.readline().split())) for i in range(H)]
prev = [0] * W
def height(C):
    global prev
    P = []
    for i in range(W):
        if C[-1][i] == 1:
            p = 0
        else:
            p = prev[i] + 1
        P.append(p)
    prev = P[:]
    return P
def square(C):
    P = height(C)
    G = []
    L = []
    for i, v in enumerate(P):
        if not L or v > L[-1][1]:
            L.append((i, v))
        elif v < L[-1][1]:
            k = i - 1
            while L and v < L[-1][1]:
                a = L.pop()
                G.append((k - a[0] + 1) * a[1])
            L.append((a[0], v))
    len_P = len(P)
    while L:
        a = L.pop()
        G.append((len_P - a[0]) * a[1])
    return max(G)
print(max([square(C[:i + 1]) for i in range(H)]))

Measured memory_bytes: 24572
N=int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
t=0
k=-1
for i in A:
  t+=B[i-1]
  if k+1==i:
    t+=C[k-1]
  k=i
print(t)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll H, N;
    cin >> H >> N;
    ll sum = 0;
    rep(i, N){
        ll A;
        cin >> A;
        sum += A;
    }
    if(sum >= H) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            var s = inputLongArray[0];
            var w = inputLongArray[1];

            Console.WriteLine(s > w? "safe": "unsafe");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28224
from itertools import accumulate
n = int(input())
As = list(map(int, input().split()))

if n == 0:
    if As[0] == 1:print(1)
    else:print(-1)
    exit()


if As[0] != 0:
    print(-1)
    exit()

b = 1
ans = 1
acc = list(accumulate(As))
s = acc[-1]
for ac,a in zip(acc[1:], As[1:]):
    # print(s-ac,2*b-a)
    b = min(2*b-a, s-ac)
    if b < 0:
        print(-1)
        exit()
    ans += b+a
print(ans)
    

Measured memory_bytes: 19976
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    long long int n, k;
    cin >> n >> k;

    long long int p, q;
    p = n % k;
    q = k - n % k;
    if(p < q) cout << p << endl;
    else cout << q << endl;
    return 0;
}

Measured memory_bytes: 256
/* 
 * Project: NOMURA Programing Contest B - Postdocs
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/05/30
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstring>
using namespace std;

char t[200000];
int k;

void solve() {

    for (int i=0;i<strlen(t);i++) {
        if (t[i] == '?') {
            t[i] = 'D';
        }
    }
    printf("%s\n", t);

}

int main() {

    scanf("%s", t);

    solve();

}

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

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

  // ここにプログラムを追記
  int x,one,ten,thou,tenthou,sum = 0;
  for(int i = A; i <= B; i++){
    
    x = i;
    one = x % 10;
    x /= 10;
    ten = x % 10;
    x /= 10;
    x /= 10;
    thou = x % 10;
    x /= 10;
    tenthou = x % 10;
   
    if(one == tenthou && ten == thou) sum++;
  }
  
  cout << sum << endl;
 
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
flag = False

for i in reversed(range(1,n)):
    if h[i] - h[i-1] == -1:
        h[i-1] -= 1
    elif h[i] - h[i-1] < -1:
        flag = True
        break
if flag:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 14396
// Branch on Condition - Small, Large, or Equal
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_A
using System;
using System.Linq;

namespace NTL_2_A {
	class Program {
		public Program() {}
		
		public static void Main() {
			new Program().Calc();
		}
		
		void Calc() {
			var n = Input.Split(' ')
                            .Select(i => int.Parse(i))
			                .ToArray();
			Output("a " + judge(n[0], n[1]) + " b");
		}
		
		String Input {
			get {
				return Console.ReadLine();
			}
		}
		
		void Output(String str) {
			Console.WriteLine(str);
		}
		
		String judge(int a, int b) {
            if(a == b) return "==";
            if(a > b) return ">";
            return "<";
		}
	}
}

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

int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; ++i) cin >> A[i];
    int ans = 0, counter = 0, isOK = 0;

    for(int i = 0; i < N; ++i){
        if(isOK == 0 && A[i] == 1) isOK = 1;
        if(A[i] == (counter + 1)){
            counter++;
        }else{
            ans++;
        }
    }

    if(isOK == 1) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
static auto faster_iostream = []() { ios::sync_with_stdio(0); cin.tie(0); return 0; }();
typedef long long ll; typedef long double db;
const int N = 1e6 + 5, M = 1e9 + 7;

// #pragma GCC optimize ("trapv")

int main() {
  ll x, cnt = 1, ans = 0;
  cin >> x;
  while (x > 1) {
    ans += cnt;
    x /= 2, cnt *= 2;
  }
  cout << ans + cnt << endl;
}


Measured memory_bytes: 384
#include <stdio.h>

typedef struct card {
  char suit;
  int value;
} card;

int numberOfCards;
card original[100000];
card sorted[100000];

void printCards(card array[100000]) {
  int i;
  for ( i = 0; i < numberOfCards; i++ )
    printf("%c %d\n", array[i].suit, array[i].value);
}

void swap(card array[100000], int i, int j) {
  int valholder;
  char suitholder;
  valholder = array[i].value;
  suitholder = array[i].suit;
  array[i].value = array[j].value;
  array[i].suit = array[j].suit;
  array[j].value = valholder;
  array[j].suit = suitholder;
}

int partition(card array[100000], int p, int r) {
  int x = array[r].value, i = p-1, j, valholder;
  char suitholder;
  for ( j = p; j < r; j++ )
    if ( array[j].value <= x )
      swap(array, ++i, j);
  swap(array, ++i, r);
  return i;
}

void quicksort(card array[100000], int p, int r) {
  if ( p < r ) {
    int q = partition(array, p, r);
    quicksort(array, p, q-1);
    quicksort(array, q+1, r);
  }
}

int ifstable() {
  int i, j, prevVal = -1;
  for ( i = 0; i < numberOfCards; i++ ) {
    int currVal = sorted[i].value;
    for ( j = (prevVal==currVal ? j+1 : 0); j < numberOfCards; j++ ) {
      if ( (original[j].value == sorted[i].value) &&
	   (original[j].suit == sorted[i].suit) )
	break;
      else if ( j == numberOfCards-1 )
	return 0;
    }
    prevVal = currVal;
  }
  return 1;
}

int main(void) {
  int i;
  scanf(" %d", &numberOfCards);
  for ( i = 0; i < numberOfCards; i++ ) {
    scanf(" %c %d", &original[i].suit, &original[i].value);
    sorted[i].suit = original[i].suit;
    sorted[i].value = original[i].value;
  }
  quicksort(sorted, 0, numberOfCards-1);
  printf("%s\n", ifstable() ? "Stable" : "Not stable");
  printCards(sorted);
  return 0;
}



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

using namespace std;

int marked[110];

int ok[3][3];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  for(int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) cin >> ok[i][j];
  int a, b; cin >> b;
  while (b--) cin >> a, marked[a] = true;

  for(int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) ok[i][j] = marked[ok[i][j]];

  bool result = false;
  
  // rows
  for (int row = 0; row < 3; ++row) {
    int c = 0;
    for (int col = 0; col < 3; ++col) c += ok[row][col];
    if (c == 3)
      result = true;
  }

  // cols
  for (int col = 0; col < 3; ++col) {
    int c = 0;
    for (int row = 0; row < 3; ++row) c += ok[row][col];
    if (c == 3)
      result = true;
  }

  // diags
  int c = 0;
  for (int i = 0; i < 3; ++i) c += ok[i][i];
  if (c == 3)
      result = true;

  c = 0;
  for (int i = 0; i < 3; ++i) c += ok[i][2-i];
  if (c == 3)
      result = true;
  
  cout << (result ? "Yes" : "No") << endl;
}


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

int main()
{
    double a,b,h,m;
    cin >> a >> b >> h >> m;

    double degs = 0.5 * (h * 60 + m);
    double degl = 6 * m;

    double deg = abs(degl - degs);
    if (deg > 180)
        deg = 360 - deg;
    //cout << degs << " " << degl << " :deg=" << deg << endl;

    deg = deg / 180 * pi;
    //cout << deg << " :cos=" << cos(deg) << endl;
    double ans = sqrt(pow(a,2) + pow(b,2) - 2 * a * b * cos(deg));
    cout << setprecision(20) <<ans << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 1e5;

int main()
{
  lli h; int n;
  while (scanf("%lld %d", &h, &n) != EOF)
  {
    lli s = 0;
    for (int i = 0; i < n; i ++)
    {
      lli a; scanf("%lld", &a);
      s += a;
    }
    printf("%s\n", s >= h ? "Yes" : "No");
  }
  return 0;
}

Measured memory_bytes: 256
s = input()
x,ans = len(s),"Yes"
if x%2==1: ans = "No"
else:
  for i in range(x//2):
    if s[i]=="b" and s[x-i-1]!="d": ans = "No"
    elif s[i]=="d" and s[x-i-1]!="b": ans = "No"
    elif s[i]=="p" and s[x-i-1]!="q": ans = "No"
    elif s[i]=="q" and s[x-i-1]!="p": ans = "No"
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  // エラトステネスの篩
  vector<bool> is_prime(55556);
  REP(i, 55556)
  is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i * i <= 55555; ++i)
  {
    if (is_prime[i])
    {
      for (int j = 2; i * j <= 55555; j++)
        is_prime[i * j] = false;
    }
  }
  int count = 0;
  REP(i, 55556)
  {
    if (is_prime[i] && i % 5 == 1)
    {
      cout << (count != 0 ? " " : "") << i;
      count++;
    }
    if (N <= count)
      break;
  }
  cout << "\n";
  return 0;
}

Measured memory_bytes: 256
// 　　＿＿
// 　／　<＠ﾌ
//  ｜(ﾉﾉハ))
//  ﾉ从ﾟヮﾟ从
// 　ﾉ｜ｿﾉГ|つ author:hotarunx
// 〈_ﾉ^^^ヽ|
// 　~~tｧtｧ~
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int N = 3;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // このコードでは座標系は0-based

    int r, c, k;
    cin >> r >> c >> k;

    // grid[i][j]: (i,j)のアイテムの価値（0ならばアイテムは無い）
    vector<vector<int>> grid(r, vector<int>(c, 0));

    for (int i = 0; i < k; i++) {
        int ri, ci, vi;
        cin >> ri >> ci >> vi;
        ri--, ci--;  // 入力した数値を0-basedに変換する
        grid[ri][ci] = vi;
    }

    // スコア：高橋君が拾うことのできるアイテムの価値の合計としてありうる値
    // dp[i][j][k]: (i,j)でi行でアイテムをk回拾ったときの最大スコア
    vector<vector<vector<int>>> dp(
        r, vector<vector<int>>(c, vector<int>(N + 1, 0)));

    // 上から下へdpを更新する
    for (int i = 0; i < r; i++) {
        // 左から右へdpを更新する
        for (int j = 0; j < c; j++) {
            // 左から来るとき
            for (int k = 0; k <= N; k++) {
                const int unpick = j > 0 ? dp[i][j - 1][k] : 0;
                const int pick =
                    j > 0 && k > 0 ? dp[i][j - 1][k - 1] + grid[i][j] : 0;
                dp[i][j][k] = max(pick, unpick);
            }

            // 上から来るとき
            const int unpick_above =
                i > 0 ? *max_element(dp[i - 1][j].begin(), dp[i - 1][j].end())
                      : 0;
            const int pick_above = unpick_above + grid[i][j];

            dp[i][j][0] = max(unpick_above, dp[i][j][0]);
            dp[i][j][1] = max(pick_above, dp[i][j][1]);
        }
    }

    const int ans =
        *max_element(dp[r - 1][c - 1].begin(), dp[r - 1][c - 1].end());

    std::cout << ans << endl;
}


Measured memory_bytes: 706688
import math
A, B, C, D = map(int, input().split())
 
# CでもDでも割り切れない = 全体(a) - Cで割り切れる(b) + Dで割り切れる(c) + CでもDでも割り切れる(d)
lcm = C*D // math.gcd(C, D)
a = B - A + 1
b = B // C - (A-1) // C
c = B // D - (A-1) // D
d = B // lcm - (A-1) // lcm

print(a-b-c+d)

Measured memory_bytes: 8996
// ABC147_B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
	int hug = 0;
	string s;
	cin >> s;
	for (int i = 0; i <= (s.size()-1)/2; i++) {
		//cout << s[i]<<s[s.size() - 1-i] << endl;
		//cout << hug << endl;
		if (s[i] != s[s.size() -1 - i]) hug++;
	}
	cout << hug << endl;
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
n = input()

def sumdigits(num):
  cc = 0
  for c in num:
    cc += int(c)
  return cc

if all([s == '9' for s in n]):
  print(9 * len(n))
else:
  print(max(9 * (len(n) - 1) + int(n[0]) - 1, sumdigits(n)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
	int n,sum=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		mp[x]++;
	}
	map<int,int>::iterator t=mp.begin();
	while(t!=mp.end())
	{
		int x=(*t).first,y=(*t).second;
		if(y<x)
			sum+=y;
		else
			sum+=y-x;
		t++;
	}
	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int n,x,k;
    while (scanf("%d %d",&n,&k)!=EOF) {
        x=0;
        do {
            x++;
            n/=k;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 16;
double dp[N][1<<N];
double nx[N][1<<N];

int main(){
    int m,n;
    scanf(" %d %d", &m, &n);

    double p[16][16]={};
    rep(i,m)rep(j,n) scanf(" %lf", &p[i][j]);

    fill(dp[0], dp[N], 1);
    // i-th enemy
    for(int i=n-1; i>=0; --i){
        double max_p[1<<N];
        rep(mask,1<<m){
            rep(j,m)if(mask>>j&1){
                double win = p[j][i];
                int lmask = mask^(1<<j);
                nx[j][mask] = win*dp[j][mask] + (1-win)*max_p[lmask];
            }

            max_p[mask] = 0;
            rep(j,m)if(mask>>j&1) max_p[mask] = max(max_p[mask], nx[j][mask]);
        }

        rep(j,N)rep(k,1<<N) dp[j][k] = nx[j][k];
    }

    double ans = 0;
    rep(i,m) ans = max(ans, dp[i][(1<<m)-1]);
    printf("%.10f\n", ans);
    return 0;
}



Measured memory_bytes: 18848
mod = 998244353

N = int(input())
D = [int(x) for x in input().split()]

dep = max(D)
dict = [0]*(dep+1)

for d in D:
    dict[d]+=1
if(dict[0]!=1 or D[0]!=0):
    ans = 0
else:
    ans = 1
    for de in range(1,dep+1):
        ans *= (dict[de-1]**dict[de])%mod
        ans %= mod
print(ans)


Measured memory_bytes: 13892
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
		int min = 0, max = 0;
		if(Math.abs(a - b) <= W) System.out.println(0);
		if(a < b) {
			min = a;
			max = b;
		}
		else if(b < a) {
			min = b;
			max = a;
		}
		if(min + W < max) System.out.println(max - (min + W));
	}
}

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

int main() {
	int n,a[30000000],b[3000000],max=-1,count=0,c;
	cin>>n;
	for(int i=0;i<n;i++){
	    cin>>a[i];
	    if(a[i]>max){
	        max=a[i];
	        count=0;
	        c=i;
	    }
	   else if(a[i]==max){
	        count++;
	    }
	}

	sort(a,a+n,greater<int>());
	if(count>=1){
	    for(int i=0;i<n;i++){
	        cout<<a[0]<<'\n';
	    }
	}
	else{
	    for(int i=0;i<n;i++){
	        if(i==c)
	            cout<<a[1]<<'\n';
	       else
	            cout<<a[0]<<'\n';
	    }
	}
	return 0;
}



Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
 
int main()
{
    double cx = 0, cy = 0, r = 0;
    int q = 0;
    double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
 
    cin >> cx >> cy >> r >> q;
 
    for (int i = 0; i < q; i++) {
        cin >> x1 >> y1 >> x2 >> y2;
 
        double a = 0, b = 0, s = 0, t = 0, u = 0,
            v1 = 0, v2 = 0, w1 = 0, w2 = 0;
 
        if (x1 == x2) {
            v1 = x1;
            v2 = x2;
            w1 = cy - sqrt(r * r - (x1 - cx) * (x1 - cx));
            w2 = cy + sqrt(r * r - (x1 - cx) * (x1 - cx));
        }
        else {
            a = (y2 - y1) / (x2 - x1);
            b = (x2 * y1 - x1 * y2) / (x2 - x1);
 
            s = a * a + 1;
            t = a * b - a * cy - cx;
            u = cx * cx + (b - cy) * (b - cy) - r * r;
 
            v1 = (-t - sqrt(t * t - s * u)) / s;
            v2 = (-t + sqrt(t * t - s * u)) / s;
            w1 = a * v1 + b;
            w2 = a * v2 + b;
        }
 
        cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(8)
             << v1 << " " << w1 << " " << v2 << " " << w2 << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3284