akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

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

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

        System.out.println(solve(a));

        sc.close();
    }

    static int solve(int[] a) {
        return IntStream.rangeClosed(Arrays.stream(a).min().getAsInt(), Arrays.stream(a).max().getAsInt())
                .map(x -> Arrays.stream(a).map(ai -> (ai - x) * (ai - x)).sum()).min().getAsInt();
    }
}

Measured memory_bytes: 27092
h,w=map(int,input().split())
s=[input() for i in range(h)]
c=[[0 for i in range(w)] for i in range(h)]
t=0
for H in range(h):
    for W in range(w):
        if(s[H][W]=="#"):
            for l in range(1,t+1):
                c[H][W-l]=t
            t=0
        else:
            t+=1
    for l in range(1,t+1):
        c[H][-l]=t
    t=0
ans=0
for W in range(w):
    for H in range(h):
        if(s[H][W]=="#"):
            for l in range(1,t+1):
                ans=max(c[H-l][W]+t,ans)
            t=0
        else:
            t+=1
    for l in range(1,t+1):
        ans=max(c[-l][W]+t,ans)
    t=0
print(max(ans-1,0))

Measured memory_bytes: 100184
#include <stdio.h>


int main(void){
  char S[4];
  scanf("%s", S);

  int month_f, month_r;

  month_f = 10*(S[0]-'0')+(S[1]-'0');
  month_r = 10*(S[2]-'0')+(S[3]-'0');

  int m_flag_f, m_flag_r;

  m_flag_f = 0<month_f && month_f<13;
  m_flag_r = 0<month_r && month_r<13;

  if(m_flag_f == 1)   //前半が月になる
    if(m_flag_r == 1) //後半が月になる
      printf("AMBIGUOUS\n");
    else              //後半が月にならない
      printf("MMYY\n");
  else                //前半が月にならない
    if(m_flag_r == 1) //後半が月になる
      printf("YYMM\n");
    else              //後半が月にならない
      printf("NA\n");
  return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
    	String X = ns();
    	StringBuffer sb = new StringBuffer();
    	int N = X.length();

    	int Scnt = 0;
    	for (int i=0; i<N; i++) {
			if (X.charAt(i) == 'S') {
				Scnt++;
			} else {
				if (Scnt == 0) {
					sb.append("T");
				} else {
					Scnt--;
				}
			}
		}
    	for (int i=0; i<Scnt; i++) {
    		sb.append("S");
    	}
    	out.println(sb.length());
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}


Measured memory_bytes: 12876
require "prime"

n = gets.to_s.to_i

ans = 0
1.step(n,2) do |k|
  # p k.prime_division.to_h
  ans += 1 if 8 == k.prime_division.map{|t|t.last}.reduce(1){|cnt, t| cnt * (t+1) } 
  # p k if 8 == k.prime_division.to_h.values.reduce(1){|cnt, t| cnt * (t+1) } 
end

puts ans

Measured memory_bytes: 1916
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque
import heapq
from itertools import combinations
import bisect

n,m=map(int,input().split())
g=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
q=deque([0])
ans=[-1]*n
ans[0]=0
while q:
    p=q.popleft()
    for i in g[p]:
        if ans[i]==-1:
            ans[i]=p+1
            q.append(i)
ans=ans[1:]
print('Yes')
for i in ans:
    print(i)


Measured memory_bytes: 37628
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end() 

#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
 
using namespace std;

/**************************************************************************/
int main()
{
	fastIO;
	ll n,i;
    cin>>n;
    if(n<=111) cout<<"111"<<endl;
    else if(n<=222) cout<<"222"<<endl;
    else if(n<=333) cout<<"333"<<endl;
    else if(n<=444) cout<<"444"<<endl;
    else if(n<=555) cout<<"555"<<endl;
    else if(n<=666) cout<<"666"<<endl;
    else if(n<=777) cout<<"777"<<endl;
    else if(n<=888) cout<<"888"<<endl;
    else if(n<=999) cout<<"999"<<endl;
}
/*************************************************************************/ 

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (chunk) {
	var a = chunk.split(' ');
	var b = parseInt(a[0],10);
	var c = parseInt(a[1],10);
	var d = parseInt(a[2],10);
	if(b<c && c<d)
		console.log("Yes");
	else 
		console.log("No");
});

Measured memory_bytes: 15540
#include<bits/stdc++.h>
using namespace std;   //author: madmin2619/mintu_agarwal
     
#define nfs() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define pf push_front
#define forin(i, n) for(int i=0;i<n;i++)
#define tr(c, it) for(auto it=c.begin();it!=c.end();it++)
#define sz(c) c.size()
#define all(c) c.begin(),c.end()
#define ff first
#define ss second
#define m_p(x, y) make_pair(x, y)
     
const int M = 1e9 + 7;
     
int32_t main(){
    //nfs()
    int n, i, j, k, m;
    string s, t;
    cin >> s;
    cin >> t;
    n = sz(s);
    m = sz(t);
    int lcs[n+1][m+1];
    pair<int, int> ind[n+1][m+1];
    forin(i, n+1){
    	forin(j, m+1)
    		lcs[i][j]=0;
    }
    ind[0][0] = {-1, -1};
    for(i=0;i<n+1;i++)
    	ind[i][0]={-1, -1};
    for(i=0;i<m+1;i++)
    	ind[0][i] = {-1, -1};
    for(i=1;i<=n;i++){
    	for(j=1;j<=m;j++){
    		ind[i][j] = {-1, -1};
    		if(s[i-1]==t[j-1]){
    			lcs[i][j] = lcs[i-1][j-1] + 1;
    			ind[i][j] = {i-1, j-1};
    		}
    		if(lcs[i-1][j] > lcs[i][j]){
    			lcs[i][j] = lcs[i-1][j];
    			ind[i][j] = ind[i-1][j];
    		}
    		if(lcs[i][j-1] > lcs[i][j]){
    			lcs[i][j] = lcs[i][j-1];
    			ind[i][j] = ind[i][j-1];
    		}
    	}
    }
    string res = "";
    int x = (ind[n][m]).ff;
    int y = (ind[n][m]).ss;
    //cout << x << '\n';
    while(x>=0 && y>=0){
    	res.pb(s[x]);
    	int tx = x;
    	int ty = y;
    	x = ind[tx][ty].ff;
    	y = ind[tx][ty].ss;
    }
    reverse(all(res));
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 211328
#include <stdio.h>
int main(void){
    int H,W,i,j,g;
    for(;;){
        scanf("%d %d\n",&H,&W);
        if(H==0&&W==0)break;
        for(j=1;j<=W;j++){
            putchar('#');
        }
        putchar('\n');
        for(g=1;g<=H-2;g++){
            putchar('#');
            for(i=1;i<=W-2;i++){
            putchar('.');
            }
            putchar('#');
            putchar('\n');
        }
        for(j=1;j<=W;j++){
            putchar('#');
        }
        putchar('\n');
        putchar('\n');
    }    
    
    return 0;
    
}


Measured memory_bytes: 2036
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(c<=b&&c>=a||(c<=a&&c>=b))
		cout<<"Yes";
	else cout<<"No";
	
	return 0;
} 

Measured memory_bytes: 256
def main():
    n = int(input())
    al = []
    bl = []
    for _ in range(n):
        a, b = map(int, input().split())
        al.append(a)
        bl.append(b)
    al.sort()
    bl.sort()
    if n%2:
        print(bl[n//2]-al[n//2]+1)
    else:
        print(bl[n//2]+bl[n//2-1]-al[n//2]-al[n//2-1]+1)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 25336
//file_name:ABC99_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    if(n<=999){
        puts("ABC");
    }else{
        puts("ABD");
    }
    return 0;


    ll ans = 0;

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



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        while (!(line = br.readLine()).equals("0 0")) {
            int w = Integer.parseInt(line.substring(0, line.indexOf(' ')));
            int h = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
            char[][] map = new char[h + 2][w + 2];

            ArrayDeque<int[]> queue = new ArrayDeque<int[]>();
            int count = 0;

            for (int i = 1; i < h + 1; i++) {
                line = br.readLine();
                for (int j = 1; j < w + 1; j++) {
                    map[i][j] = line.charAt(j - 1);
                    if (map[i][j] == '@') {
                        queue.offer(new int[]{i, j});
                        map[i][j] = '#';
                        count++;
                    }
                }
            }

            int[][] dir = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
            int[] curr;
            int ni, nj;
            while (queue.size() > 0) {

                curr = queue.poll();
                for (int i = 0; i < dir.length; i++) {
                    ni = curr[0] + dir[i][0];
                    nj = curr[1] + dir[i][1];
                    if (map[ni][nj] == '.') {
                        queue.offer(new int[]{ni, nj});
                        map[ni][nj] = '#';
                        count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 26452
#include<iostream>
	#include<stdlib.h>
	#include<math.h>
	#include<algorithm>
	#include<string.h>
	using namespace std;


int main()

{
	std::ios_base::sync_with_stdio(0);
		cin.tie(NULL);
		int n, m; cin >> n >> m;
		int averge = m * 2 - n;
		cout << averge << endl;
	return 0;

}

	

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
long long dp[100001],v[101],w[101];
int main()
{
    int n,W;
    cin>>n>>W;
    for(int i=0;i<n;i++)
        cin>>w[i]>>v[i];
    for(int i=0;i<n;i++)
    {
        for(int j=W;j>=0;j--)
        {
            if(w[i]>j)
                break;
            dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
        }
    }
    cout<<dp[W]<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double W = sc.nextDouble();
		double H= sc.nextDouble();
		int x = sc.nextInt();
		int y = sc.nextInt();

		double ans = W*H/2;

		if (x==W/2 && y==H/2) {
			System.out.println(ans + " 1" );
		}else {
			System.out.println(ans + " 0");
		}
	}
}


Measured memory_bytes: 24276
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF  = 1<<30;


struct item {
  int v, w;
  bool operator<(const item &r) const { return w < r.w; }
  void operator+=(const item &r) { w += r.w, v += r.v; }
};


vector<item> enum_powerset(const vector<item> &is) {
  vector<item> a = {{0, 0}};
  vector<item> c;
  c.reserve(1<<sz(is));
  for (auto &i : is) {
    auto b = a;
    for (auto &e : b) e += i;
    merge(all(a), all(b), back_inserter(c));
    swap(a, c);
    c.clear();
  }
  return a;
}


int solve(const vector<item> &a, const vector<item> &b, int W) {
  int ans = 0;
  int vbmax = -INF;
  auto itr = b.begin();
  for (auto &[va, wa] : a) {
    while (itr != b.end() && wa + itr->w <= W) {
      chmax(vbmax, itr->v);
      ++itr;
    }
    chmax(ans, va + vbmax);
  }
  return ans;
}


int main() {
  int n; cin >> n;
  vector<item> is(n);
  for (auto &[v, w] : is) cin >> v >> w;
  is.insert(is.begin(), {0, 0});

  const int m = 12;
  int M = 1<<m;
  chmin(M, n+1);
  vector<vector<item>> pre(M);
  pre[0] = {{0, 0}};
  rep2(i, 1, M) {
    auto a = pre[i/2];
    for (auto &e : a) e += is[i];
    merge(all(pre[i/2]), all(a), back_inserter(pre[i]));
  }
  rep(i, M) reverse(all(pre[i]));

  int q; cin >> q;
  rep(_, q) {
    int v, l; cin >> v >> l;
    vector<item> qi;
    while (v >= M) {
      qi.push_back(is[v]);
      v /= 2;
    }
    cout << solve(pre[v], enum_powerset(qi), l) << '\n';
  }
}


Measured memory_bytes: 92796
////////////////////////////////////////////////////
                    //                                                //
                    //  For her who keeps the fire kindling in me...  //
                    //                                                //
                    ////////////////////////////////////////////////////


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException; 
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
// import java.util.Scanner;
// import java.util.Arrays;
// import java.util.ArrayList;
// import java.util.Collections; 
// import java.util.StringTokenizer;
import java.util.*;
import java.lang.Math;
import java.awt.Point;                            

import java.awt.geom.*;

public class Main{

    // static class Pair{
    //     int x;
    //     int y;
    // }

    public static void main(String args[]){
        try{
            FastReader s = new FastReader();
            BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
            int i, j, k, x, y, t,  count, key, size, Pairer, minglob, minloc, beg, end, begl, endr, ld, up, down, maxele, minele;
            long ans, sqrt, q, r, sum, maxup, maxdown, n, m, X, Y, Q, MOD;//, sum2;
            boolean flag, flag2;

            double avg;

            // t = s.nextInt();

            // for(; t>0; t--){

                X = s.nextLong();
                //Y = s.nextLong();


                
                if( X%2 == 0){
                    w.write(((X/2))+"\n");
    
                }else
                    w.write(((X/2) + 1)+"\n");

            // }
            w.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
                
                
//========================================### FAST IO ###=========================================//
class FastReader 
{ 
    BufferedReader br; 
    StringTokenizer st; 

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

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

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

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

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

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

Measured memory_bytes: 20436
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n>=28)cout<<"Yes";
    else {
    	for(int i=0;i<=n/4;i++){
    		if((n-i*4)%7==0){
    			cout<<"Yes";
    			return 0;
			}
		}
		cout<<"No";
	}
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

ll power(ll a, ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}

ll dp[100001];

int main()
{
    IOS;
    ll n,k;
    cin>>n>>k;
    ll a[n];
    repf(i,0,n) cin>>a[i];
    dp[0]=0;
    repf(i,1,k+1)
    {
        dp[i]=0;
        repf(j,0,n)
        {
            if(a[j]<=i && dp[i-a[j]]==0) 
            {
                dp[i]=1;
                break;
            }
        }
    }
    if(dp[k]) cout<<"First\n";
    else cout<<"Second\n";
    return 0;  
}

Measured memory_bytes: 1024
import math
def make_divisors(n):
    divisors = []
    for i in range(2, int(math.sqrt(n))+1):
        if n % i == 0:
            divisors.append(i)

    divisors.sort()
    return divisors

def main():
    N=int(input())
    di=make_divisors(N)
    if di==[]:
        print(N-1)
    else:
        M=N//di[-1]
        print(di[-1]-1+M-1)

if __name__=="__main__":
    main()

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        
        int h = n / 3600;
        int m = (n % 3600) / 60;
        int s = n % 60;


        System.out.println(h + ":" + m + ":" + s);

    }

}



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

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

void add_self(int& a, int b) {
    a += b;
    if(a > MOD) {
        a -= MOD;
    }
}

void sub_self(int& a, int b) {
    a -= b;
    if(a < 0) {
        a += MOD;
    }
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int& x : a) {
        cin >> x;
    }
    vector<vector<int>> dp(n+1, vector<int>(k+1));
    dp[0][k] = 1;
    //dp[n][k] -> dp[n+1][k-a[i]]
    for(int i = 0; i < n; i++) {
        vector<int> prefix(k+1);
        for(int j = k; j >= 0; j--) {
            /*for(int x = 0; x <= a[i]; x++) {
                if(j-x >= 0) {
                    add_self(dp[i+1][j-x], dp[i][j]);
                }
            }*/
            add_self(prefix[max(0, j-a[i])], dp[i][j]);
            if(j < k)
                sub_self(prefix[j+1], dp[i][j]);
        }
        for(int j = 0; j <= k; j++) {
            dp[i+1][j] += prefix[j] + (j > 0 ? dp[i+1][j-1] : 0);
            if(dp[i+1][j] > MOD) {
                dp[i+1][j] -= MOD;
            }
        }
    }
    cout << dp[n][0] << endl;
}


Measured memory_bytes: 40192
I=input().split( )
n=int(I[0])
m=int(I[1])

C=input().split( )
c=[int(C[i]) for i in range(m)]

T=[50001 for i in range(n+1)]#50000が上限
T[0]=0

for i in range(m):
    for j in range(n+1):
        if c[i]+j<=n:
            T[j+c[i]]=min(T[j+c[i]],T[j]+1)

print(T[n])



Measured memory_bytes: 7640
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
int main(){
  int n,d, x;
  vector< int > ai(102);
  cin >> n >> d >> x;
  int sum=x;
  for(int i=0; i<n; i++){
    cin >> ai[i];
    sum+= (d/ai[i])+1;
    if( (d%ai[i]) == 0 ) sum-=1;
  }
  printf("%d\n", sum);
  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
vector<pair<int,int> > e[maxn];
int ans[maxn];
void dfs(int u, int p){
	for(auto ee : e[u]){
		int to = ee.first;
		if(to == p) continue;
		int k = ee.second % 2;
		ans[to] = ans[u] ^ k;
		dfs(to, u);
	}
}
int main(){
	int n; cin >> n;
	for(int i = 0; i < n - 1; i++){
		int u, v, w;
		cin >> u >> v >> w;
		w %= 2;
		e[u].push_back({v, w});
		e[v].push_back({u, w});
	}
	dfs(1, 0);
	for(int i = 1; i <= n; i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 8320
n = int(input())
ue = input()
sita = input()
narabe = []
flag = False
mod = 10**9 + 7
for i in range(n):
    if ue[i] == sita[i]:
        narabe.append(0)
    elif ue[i] != sita[i]:
        if not flag:
            flag = True
            narabe.append(1)
        elif flag:
            flag = False

dp = [0 for i in range(len(narabe))]
if narabe[0] == 0:
    dp[0] = 3
elif narabe[0] == 1:
    dp[0] = 6
for i in range(1,len(narabe)):
    if narabe[i-1] == 1 and narabe[i] == 1:
        dp[i] = (dp[i-1]*3)%mod
    elif narabe[i-1] == 1 and narabe[i] == 0:
        dp[i] = dp[i-1]
    elif narabe[i-1] == 0 and narabe[i] == 0:
        dp[i] = (dp[i-1]*2)%mod
    elif narabe[i-1] == 0 and narabe[i] == 1:
        dp[i] = (dp[i-1]*2)%mod
        
print(dp[-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n,m;
  cin>>n>>m;
  n--;m--;
  cout<<n*m<<endl;
  return(0);
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(a, n) sort(a, a+n)
#define VSORT(v) sort(v.begin(), v.end())

using namespace std;

int main()
{
    int k, n;

    cin >> k >> n;

    int a[n], d[n];
    
    cin >> a[0];
    FOR(i, 1, n) {
        cin >> a[i];
        d[i-1] = abs(a[i] - a[i-1]);
    }
    d[n-1] = a[0] + abs(k - a[n-1]);

    SORT(d, n);

    cout << k-d[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
int main(){
	string s;
	cin>>s;
	int ans=0,b=0;
	for(int i=0;i!=s.size();++i){
		if(b){
			if(s[i]=='g')
				++ans;
			--b;
		}
		else{
			if(s[i]=='p')
				--ans;
			++b;
		}
	}
	cout<<ans;
}


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

import sys

def calc_prime(n):
  p_list = [True]*n
  p_list[0] = p_list[1] = False
  for i in xrange(2,int(n**0.5)+1):
    if p_list[i]:
      for j in xrange(i*i,n,i):
        p_list[j] = False
  return [ i for i in xrange(2,n) if p_list[i] ]

prime_list = calc_prime(999999)
for s in sys.stdin:
  d = int(s)
  print len([prime_list[i] for i in range(len(prime_list)) if prime_list[i] <= d ])

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

int main()
{
	long long n,k;
	cin>>n>>k;
	vector<int> A(n+1);
	for(int i=1;i<=n;i++) cin>>A[i];

	vector<vector<int>> T(n+1,vector<int>(61));
	
	for(int i=1;i<=n;i++) T[i][0]=A[i];
	
	for(int i=1;i<=60;i++)
	{
		for(int j=1;j<=n;j++)
		{
			T[j][i]=T[T[j][i-1]][i-1];
		}
	}
	int curr=1;
	for(int bit=0;bit<61;bit++)
	{
		if((k>>bit)&1) curr=T[curr][bit];
	}
	cout<<curr<<endl;
}

Measured memory_bytes: 58676
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			Map<Integer, Integer> numberCountMap = new HashMap<>();
			IntStream.range(0, n).forEach(i -> {
				int number = scanner.nextInt();
				numberCountMap.put(number, numberCountMap.getOrDefault(number, 0) + 1);
			});
			int size = numberCountMap.size();
			if (size <= k) {
				System.out.println(0);
			} else {
				System.out.println(
						numberCountMap.entrySet().stream().mapToInt(x -> x.getValue()).sorted().limit(size - k).sum());
			}
		}
	}
}


Measured memory_bytes: 69536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		String s1 = sc.next().substring(0, 1);
		String s2 = sc.next().substring(0, 1);
		String s3 = sc.next().substring(0, 1);
		
		System.out.println((s1 + s2 + s3).toUpperCase());
	}
}


Measured memory_bytes: 39164
N = int(input())
H = list(map(int,input().split()))
ans = "Yes"
for i in range(1,N):
    if H[-i] < H[-i-1]:
        if H[-i]+1 == H[-i-1]:
            H[-i-1] += -1
        else:
            ans = "No"
            break
print(ans)

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

using namespace std;

vector <int> nr[12];

int ok(int x, int y, int z)
{
	int pos1 = nr[x][0];
	int pos2 = 0;
	
	int l = 0;
	int r = nr[y].size() - 1;
	
	if(nr[y][r] <= pos1)
		return 0;
		
	while(l <= r)
	{
		int mid = (l + r) / 2;
		
		if(nr[y][mid] <= pos1)
			l = mid + 1;
		else
		{
			pos2 = nr[y][mid];
			r = mid - 1;
		}
	}
	
	l = 0;
	r = nr[z].size() - 1;
	
	if(nr[z][r] <= pos2)
		return 0;
	
	return 1;
}

main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	cin >> n;
	
	string s;
	cin >> s;
	
	for(int i = 0; i < s.size(); i++)
		nr[s[i] - '0'].push_back(i);
	
	int res = 0;
	
	for(int i = 0; i <= 9; i++)
		if(nr[i].size() > 0)
		{
			for(int j = 0; j <= 9; j++)
				if(nr[j].size() > 0)
				{
					for(int k = 0; k <= 9; k++)
						if(nr[k].size() > 0)
						{
							res += ok(i, j, k);
						}
				}
		}
	
	cout << res;
}

Measured memory_bytes: 512
#include <stdio.h>

struct Card{
  char suit;
  int value;
};

void bubble(struct Card A[],int n){
  int i,j;
  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(A[j].value<A[j-1].value){
	struct Card t=A[j];
	A[j]=A[j-1];
	A[j-1]=t;
      }
    }
  }
}

void selection(struct Card A[],int n){
  int i,j;
  for(i=0;i<n;i++){
    int min=i;
    for(j=i;j<n;j++){
      if(A[j].value<A[min].value) min=j;
    }

    struct Card t=A[i];
    A[i]=A[min];
    A[min]=t;
  }
}

void print(struct Card A[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%c%d",A[i].suit,A[i].value);
  }
  printf("\n");
}


int isStable(struct Card C1[],struct Card C2[],int n){
  int i;
  for(i=0;i<n;i++){
    if(C1[i].suit!=C2[i].suit) return 0;
  }
  return 1;
}

int main(){
  struct Card C1[100],C2[100];

  int n,i;
  char ch;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&C1[i].suit,&C1[i].value);
  }

  for(i=0;i<n;i++) C2[i]=C1[i];

  bubble(C1,n);
  selection(C2,n);
  
  print(C1,n);
  printf("Stable\n");
  print(C2,n);
  if(isStable(C1,C2,n)){
    printf("Stable\n");
  }
  else printf("Not stable\n");

  return 0;
}



Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,T;
  cin >> N >> T;
  vector<pair<int,int>> AB(N);
  for(int i=0;i<N;i++)  cin >> AB.at(i).fi >> AB.at(i).se;

  sort(all(AB));
  vector<vector<int>> dp(N+1,vector<int>(T+1,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<T+1;j++){
      chmax(dp.at(i+1).at(j),dp.at(i).at(j));
      if(j>=T)  continue;
      int tmp=min(T,j+AB.at(i).fi);
      chmax(dp.at(i+1).at(tmp),dp.at(i).at(j)+AB.at(i).se);
    }
  }
  cout << dp.at(N).at(T) << endl;

  return 0;
}

Measured memory_bytes: 38512
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    // ここで入力を処理する
    lines.push(line);
});
var sub_fn = (ary)=>{
  
}
reader.on('close', () => {
  var x = lines[0].split(' ')[0]
  var y = lines[0].split(' ')[1]
  var xx = "";
  var yy = "";
  for(var i=0;i<y;i++){
    xx += x
  }
    for(var j=0;j<x;j++){
    yy += y
  }
  //console.log(yy)
  if(("" + xx) < ("" + yy)){
    console.log(xx)
  }else{    
    console.log(yy)
  }
  var cnt = [];


  
});


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

int sum(const vector<vector<int>>& p, int t, int l, int b, int r) {
  return p[b][r] - p[b][l - 1] - p[t - 1][r] + p[t - 1][l - 1];
}

int frame(const vector<vector<int>>& p, int t, int l, int b, int r) {
  int result = sum(p, t, l, b, r);
  if(b - t > 1 && r - l > 1) result -= sum(p, t + 1, l + 1, b - 1, r - 1);
  return result;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> p(N, vector<int>(N));
  for(auto& i: p) for(auto& j: i) cin >> j;
  for(auto& i: p) i.insert(begin(i), 0);
  p.insert(begin(p), vector<int>(N + 1, 0));

  for(int i = 1; i <= N; ++i) for(int j = 2; j <= N; ++j) p[i][j] += p[i][j - 1];
  for(int i = 2; i <= N; ++i) for(int j = 1; j <= N; ++j) p[i][j] += p[i - 1][j];

  int answer = -1000;
  for(int top = 1; top <= N; ++top) for(int bottom = top; bottom <= N; ++bottom) {
    int left = 1;
    for(int right = 1; right <= N; ++right) {
      int tlbr = frame(p, top, left, bottom, right);
      answer = max(answer, tlbr);
      int r = frame(p, top, right, bottom, right);
      int tlb = tlbr - r + frame(p, top, right, top, right) + frame(p, bottom, right, bottom, right);
      if(top == bottom) tlb -= frame(p, bottom, right, bottom, right);
      if(r > tlb) left = right;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 1788
#include <stdio.h>

int count = 0;

void dfs(int a[], int b[], int n){
  if(b[0] == n){
    int check = 1;
    for(int i=1; i<=b[0]; i++)
      check = check * b[i];
    if(check%2 == 0)
      count++;
    return;
  }
  
  for(int i=-1; i<=1; i++){
    b[0]++;
    b[b[0]] = a[b[0]] + i;
    dfs(a, b, n);
    b[0]--;
  }
}
  

int main(){
  int n;  scanf("%d", &n);
  int a[13];
  for(int i=1; i<=n; i++)  scanf("%d", a+i);
  int b[14] = {0};
  dfs(a, b, n);
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import numpy as np


N = int(input())
a = np.array([int(n) for n in input().split()])

total = 0

while a.max() >= N:
    add = (a//N).sum() - (a//N)
    total += (a//N).sum()
    a = a%N
    a += add

print(total)

Measured memory_bytes: 21668
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

int main()
{
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	if (a < 0) {
		cout << a * c * (-1) + d + b * e << endl;
	}
	else if (a == 0) {
		cout << d + b * e << endl;
	}
	else {
		cout << (b - a) * e << endl;
	}
}


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

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

Node root;

Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

}

void inorder(Node u){
  if(u->left != NIL) inorder(u->left);
  printf(" %d", u->key);
  if(u->right != NIL) inorder(u->right);
}
void preorder(Node u){ 
  printf(" %d", u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

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

  return 0;
}

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int h,w;cin>>h>>w;
  int n;cin>>n;
  int a[n]; rep(i, n){ cin>>a[i]; }
  rep(i, 1, n){ a[i] += a[i-1]; }

  int res[h][w]={};
  int cnt=0;
  rep(i, h){
    if (i%2==0) {
      rep(j, w){
        res[i][j] = lower_bound(a,a+n,cnt+1)-a+1;
        cnt++;
      }
    }
    else{
      rrep(j, w){
        res[i][j] = lower_bound(a,a+n,cnt+1)-a+1;
        cnt++;
      }
    }
  }
  dump_2d(res, h, w);
  rep(i, h){
    rep(j, w){
      cout << res[i][j] << (j==w-1 ? "\n" : " ");
    }
  }

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


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

#define rep(i, n) for (int i = 0; i < (n); i++)

int N;
double D[8][8];
double result = 0;

int factorial(int n){
    if(n == 1) return 1;
    return n * factorial(n-1);
}

double dfs(int n,vector<int> res,double dis){
    if(res.size()){
        int i = 0;
        for(auto r : res){
            double d = dis;
            d += D[n][r];
            vector<int> v;
            copy(res.begin(), res.end(), back_inserter(v));
            v.erase(v.begin()+i);
            dfs(r,v,d);
            i++;
        }
    }else{
        result += dis;
    }
}

int main() {
    //input
    int N;
    cin >> N;
    int C[N][2];
    rep(i,N){
        cin >> C[i][0] >> C[i][1];
    }
    rep(i,N){
        rep(j,N){
            D[i][j] = sqrt(pow(abs(C[i][0]-C[j][0]),2) +pow(abs(C[i][1]-C[j][1]),2));
        }
    }
    vector<int> A;
    rep(i,N) A.emplace_back(i);
    rep(i,N){
        vector<int> v;
        copy(A.begin(), A.end(), back_inserter(v));
        v.erase(v.begin()+i);
        dfs(i,v,0);
    }

    cout << setprecision(16) << result / factorial(N)  << endl;

    return 0;
}

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

using namespace std;

vector<int> get_primes(int n) {
    vector<bool> is_prime(n + 1, true);
    vector<int> primes;
    for (int i = 2; i <= n; ++i) {
        if (is_prime[i]) {
            primes.push_back(i);
            for (int j = 2*i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return primes;
}

vector<pair<int, int>> fact_fac(int n) {
    vector<int> primes = get_primes(n);
    vector<pair<int, int>> fact;
    for (int prime : primes) {
        int count = 0;
        for (int i = 1; i <= n; ++i) {
            int j = i;
            while (j % prime == 0) {
                ++count;
                j /= prime;
            }
        }
        fact.push_back(make_pair(prime, count));
    }
    return fact;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int total = 0;
    vector<pair<int, int>> fact = fact_fac(n);
    {
        // 75 = 74+1
        int c = 0;
        for (auto p : fact) {
            c += p.second >= 74;
        }
        total += c;
    }
    {
        // 3 * 25 = (2+1) * (24+1)
        int c = 0, d = 0;
        for (auto p : fact) {
            c += p.second >= 24;
            d += p.second >= 2;
        }
        total += c * (d-1);
    }
    {
        // 5 * 15 = (4+1) * (14+1)
        int c = 0, d = 0;
        for (auto p : fact) {
            c += p.second >= 14;
            d += p.second >= 4;
        }
        total += c * (d-1);
    }
    {
        // 3 * 5 * 5 = (2+1) * (4+1) * (4+1)
        int c = 0, d = 0;
        for (auto p : fact) {
            c += p.second >= 4;
            d += p.second >= 2;
        }
        total += (c * (c-1)/2) * (d-2);
    }
    cout << total << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  // ここにプログラムを追記


  int i = 0;
  string color;
  bool has_yellow = false;

  while (i < N) {
    cin >> color;

    if (color == "Y") {
        has_yellow = true;
        break;
    }

    i++;
  }

  if (has_yellow) {
      cout << "Four";
  } else {
      cout << "Three";
  }

  cout << endl;
}


Measured memory_bytes: 256
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n;
    cin>>n;
    ll now=1;
    ll cnt=0;
    V vec(n+1);
    rep(i,n+1)cin>>vec[i];
    V ruiseki(n+1);
    ruiseki[n]=vec[n];
    for(int i=n-1;i>=0;i--){
        ruiseki[i]+=vec[i]+ruiseki[i+1];
    }
    /*for(auto i:ruiseki){
        cout<<i<<" ";
    }
    cout<<endl;*/
    rep(i,n+1){
        ll x=vec[i];
      //  cout<<now<<" ";
        if(now<=0){
            cout<<-1<<endl;
            return 0;
        }
        cnt+=now;
        now-=x;
        if(i==n){
            if(now!=0){
                cout<<-1<<endl;
                return 0;
            }
            continue;
        }
        if(now*2>ruiseki[i+1]){
            now=ruiseki[i+1];
        }else{
            now*=2;
        }
    }
    //cout<<endl;
    cout<<cnt<<endl;
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >>s;
    bool dif=false;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]==s[i+1]) dif=true;
    }
    if(dif) cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(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 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q, T;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vll flag, D; vector<vpll> path; vs S;

int main() {
	string S, T;
	cin >> S >> T;
	ll N = S.length();
	ll M = T.length();
	ll ans = INF;
	for (i = 0; i <= N-M; i++) {
		ll pre = 0;
		for (j = i; j < i+M; j++) {
			if (S[j] != T[j - i]) pre++;
		}
		//debug(pre);
		ans = min(ans, pre);
	}
	co(ans);
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define N	    100001
#define rep(i,a,b)  for(int i=a;i<b;i++)
typedef long long ll;

void solve(){
	int a, b;
	cin>>a>>b;
	int ans = a * 3 + b;
	cout<<ans / 2<<endl;
}
int main() {
	int t;
	//cin>>t;
	t = 1;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
using ll = long long;
using namespace std;

int N,x;
vector<int> a;

int main() {
	cin >> N >> x;
	for (int i = 0; i < N; i++)
	{
		int tmpa;
		cin >> tmpa;
		a.push_back(tmpa);
	}
	ll ans=0;
	if (a[0] > x) {
		int change0 = a[0] - x;
		a[0] -= change0;
		ans += change0;
	}
	for (int i = 1; i < N; i++)
	{
		int change = max(0, a[i - 1] + a[i] - x);
		a[i] -= change;
		ans += change;
	}
	cout << ans << endl;
}

Measured memory_bytes: 892