akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque
stdin = sys.stdin

def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
N = ii()
infos = [ tuple(li()) for i in range(N) ]
infos.sort(key=lambda x:x[1])
def do(infos):
    works = deque()
    time = 0
    used = 0
    for t, e in infos:
        time += t
        works.append( (t, e) )
        while works and time >= works[0][1]:
            deadline = works[-1][1]
            lt, le = works.popleft()
            if deadline < time:
                return "No"

    return "Yes"
print(do(infos))



Measured memory_bytes: 41604
#include<bits/stdc++.h>
namespace lib
{
	#define ll long long
	#define ull unsigned long long
	#define rgi register int
	#define rgl register long long
	#define rgc register char
	const double pi=acos(-1); 
	using namespace std;
	class fastio
	{
		private:
			#define _NUMLEN 112
			char _num[_NUMLEN],_ch; int _f,_head; bool _useSTD;
		public:
			fastio() {_f=0,_head=0,_useSTD=0,SUF=_ch=' ';}
			char SUF;
			inline void ioSTD() {_useSTD=1; ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); }
			inline void gc(char & _c) {if(_useSTD)cin>>_c; else _c=getchar(); }
			inline void pc(char _c) {if(_useSTD)cout<<_c; else putchar(_c); }
			template<typename _T> inline fastio & operator - (_T & _x)
			{
				if(_useSTD)cin>>_x; else{
					_x=0; 
					while(!isdigit(_ch)) _f|=_ch=='-',gc(_ch); 
					while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),gc(_ch); 
					_f&&(_x=-_x,_f=0); 
				}return *this; 
			}
			template<typename _T> inline fastio & operator + (_T _x)
			{
				if(_useSTD)cout<<_x<<SUF; else{
					_T _k; 
					if(_x==0) {pc('0'),pc(SUF);return *this;} if(_x<0) pc('-'),_x=-_x;
					while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k; while(_head>0) pc(_num[_head]),--_head;
					pc(SUF);
				}return *this; 
			}
			template<typename _T> inline fastio & operator >> (_T & _x) {cin>>_x;return *this;}
			template<typename _T> inline fastio & operator << (_T _x) {cout<<_x;return *this;}
			#define edn pc('\n')
	}io;
	inline void fileio(string _r,string _w) {if(_r[0]!='-')freopen(_r.c_str(),"r",stdin); if(_w[0]!='-')freopen(_w.c_str(),"w",stdout); }
	#define mem(_x,_set) memset(_x,_set,sizeof(_x))
}
using namespace lib;
// ----------------------------

// #define int ll
const int maxn=104;
const int mod=998244353,inf=1000000007;

int a[maxn];
signed main()
{
	// fileio("tt.in","tt.out");
	// io.ioSTD();
	// io.SUF='\n';
	int n;
	io-n;
	for(rgi i=1;i<=n;++i) io-a[i];
	ll ans=inf,nsum;
	for(rgi i=1;i<=100;++i)
	{
		nsum=0;
		for(rgi j=1;j<=n;++j) nsum+=(i-a[j])*(i-a[j]);
		ans=min(ans,nsum);
	}
	io+ans;
	return 0;
}
// ----------------------------
// by imzzy


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
#define inf 0x3f3f3f3f
#define ull unsigned long long  
using namespace std;
const int mod=1e9+7;
const int MAX=2e5+7;
const double pi=6.28318530717958623200;
//ll a[MAX];
int main()
{
 	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	double r;
 	cin>>r;
 	cout<<fixed<<setprecision(20)<<r*pi;
 	
}

Measured memory_bytes: 3800
import java.util.Comparator;
import java.util.Scanner;

class Main{


	static int[][] map ;
	static long INF =Long.MAX_VALUE/2;
	static int n,m ;
	static	long[] dis;

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int T = sc.nextInt();
		int[] t = new int[n+1];
		
		for(int i = 1;i <= n;i++){
			t[i] = sc.nextInt();

		}
		
		long ans = 0;
		for(int i = 1;i < n;i++){
			if(t[i+1] - t[i] <= T){
				ans += t[i+1] - t[i];
			}else{
				ans += T;
			}
		}
		
		ans += T;
		
		
		




		System.out.println(ans);




	}
}





class MyComparator implements Comparator {

	public int compare(Object obj1, Object obj2) {

		int num1 = (int)obj1;
		int num2 = (int)obj2;

		if(num1 < num2) {
			return 1;
		} else if(num1 > num2) {
			return -1;
		} else{
			return 0;
		}
	}
}




Measured memory_bytes: 64972
import math

(A, B, C) = list(map(int, input().split()))
cnt = 0
coin = 0

if A*7 < C:
    if A*7+B >= C:
        cnt = 7
    else:
        week_num = math.floor(C / (A*7+B))
        cnt = week_num * 7
        coin = week_num * (A*7+B)

        if A*7 < C - coin:
            cnt += 7
        else:
            cnt += math.ceil((C - coin) / A)
else:
    cnt += math.ceil((C - coin) / A)
    
print(cnt)



Measured memory_bytes: 5660
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int 
#define pb push_back
#define vv vector<ll>
#define MAX 105000
#define fr(i,x) for(int i=0;i<x;i++)
int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    
    if(a.first == b.first) return a.second<b.second;
    return (a.first < b.first); 
}
ll ar[MAX];
void divisor(){
    for (int i = 1; i <= MAX; i++)
    {
        for (int j = i; j <= MAX;j+=i)
        {
            ar[j]++;
            
        }
        
        
    }
    
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll h,n,k,x,c = 0,a[4][4] = {0};
    map<ll,pair<ll,ll>>m;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> x;
            m[x] = make_pair(i+1,j+1);
        } 
    }
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        pair<ll,ll>p = m[x];
        a[p.first][p.second] = 1;
    }
    if((a[1][1]&&a[1][2]&&a[1][3]) ||(a[2][1]&&a[2][2]&&a[2][3]) ||(a[3][1]&&a[3][2]&&a[3][3])){
        cout << "Yes" << endl;
        return 0;
    }
    if((a[1][1]&&a[2][1]&&a[3][1]) ||(a[1][2]&&a[2][2]&&a[3][2]) ||(a[1][3]&&a[2][3]&&a[3][3])){
        cout << "Yes" << endl;
        return 0;
    }
    if((a[1][1]&&a[2][2]&&a[3][3]) || (a[1][3]&&a[2][2] && a[3][1])){
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;

}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define model l,mid,num<<1
#define moder mid+1,r,num<<1|1
#define bug(k)  cout<<"text :"<<t<<endl
#define lowbit(k) k&-k
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
const int M=1e5+5;
map <string,int> ma;
int n;
int main()
{
    bool flag;
    string str;
    char c;
    while(cin>>n)
    {
        flag=1;
        ma.clear();
        cin>>str;
        ma[str]=1;
        c=str[str.size()-1];
        for(int i=2;i<=n;++i)
        {
            cin>>str;
            if(!flag)continue;
            if(ma[str]==0)ma[str]=1;
            else flag=0;
            if(str[0]!=c)flag=0;
            else c=str[str.size()-1];
        }
        if(flag)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{

  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;

    int in_K;

    int odd;
    int even;
    int ans;

    try
    {
      in_stream = new BufferedReader(new InputStreamReader(System.in));

      /*----------------
       * 引数
       *----------------*/
      in_str = new String(in_stream.readLine());
      in_K   = Integer.parseInt(in_str);

      /*----------------
       * 計算
       *----------------*/
      if(in_K % 2 == 0)
      {
        odd  = (in_K / 2);
        even = (in_K / 2);
      }
      else
      {
        odd  = (in_K / 2);
        even = (in_K / 2) + 1;
      }

      ans = odd * even;


      System.out.println(String.valueOf(ans));
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 22356
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

vector<vector<int>> v(100010);
ll N;
int M,a,b;
int color[100010] = {0};

bool dfs(int n,int c){
	color[n] = c;
	bool j = true;
	for(int i=0;i<v[n].size();i++){
		if(color[v[n][i]] == c) j = false;
		else if(color[v[n][i]] == 0 && !dfs(v[n][i],-c)) j = false;
	}
	return j;
}

int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	ll nibu = 0,notnibu = 0,koritsu = 0;
	for(int i=1;i<=N;i++){
		if(color[i]==0){
			if(v[i].size()==0) koritsu++;
			else if(dfs(i,1)) nibu++;
			else notnibu++;
		}
	}
	cout << 2*koritsu*N-koritsu*koritsu + notnibu*notnibu + 2*notnibu*nibu + 2*nibu*nibu << endl;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

bool AtoZ(char a) {
	if('a' <= a && a <= 'z') return false;
	else return true;
}


int main() {
	string s; cin >> s;
	bool flag1 = false;
	bool flag2 = false;
	bool flag3 = true;
	/////////////flag1///////////////
	if(s[0]=='A') flag1 = true;
	////////////flag2////////////////
	int count = 0;
	for (int i = 2; i < (int)s.size() - 1; ++i)
	{
		if(s[i]=='C') ++count;
	}
	if (count==1) flag2 = true;
	////////////flag3///////////////
	for (int i = 0; i < (int)s.size(); ++i)
	{ 
		if(s[i]!='A' && s[i]!='C') {
			if(AtoZ(s[i])) flag3 = false;
		}
	}

	if(flag1 && flag2 && flag3) cout << "AC" << endl;
	else cout << "WA" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define FALSE 1
#define TRUE 0

typedef struct {
    char pic;
    int num;
} Card;

void print(Card C[],int N){
    int i;
    for(i=0;i<N;i++){
        printf("%c%d",C[i].pic,C[i].num);
        if(i!=N-1){
            printf(" ");
        }
        else{
            printf("\n");
        }
    }
}

void BubbleSort(Card C[],int N){
    int i,j;
    Card tmp;
    
    for(i=0;i<N;i++){
        for(j=N-1;j>i;j--){
            if(C[j].num<C[j-1].num){
                tmp=C[j];
                C[j]=C[j-1];
                C[j-1]=tmp;
            }
        }
    }
    print(C,N);
    printf("Stable\n");
}

void SelectionSort(Card C[],int N){
    int i,j;
    int minj;
    Card temp;
    
    for(i=0;i<N;i++){
        minj=i;
        for(j=i;j<N;j++){
            if(C[j].num<C[minj].num)minj=j;
        }
        temp=C[i];
        C[i]=C[minj];
        C[minj]=temp;
    }
    print(C,N);
}

int isStable(Card C1[],Card C2[],int N){
    int i;
    for(i=0;i<N;i++){
        if(C1[i].pic!=C2[i].pic){
            return FALSE;
        }
    }
    return TRUE;
}

int main(){
    int N;
    int i;
    Card C1[36],C2[36];//1はバブルソートで、2が選択ソート

    scanf("%d",&N);
    
    for(i=0;i<N;i++){
        scanf(" %c%d",&C1[i].pic,&C1[i].num);
        C2[i]=C1[i];
        }
    
    BubbleSort(C1,N);
    SelectionSort(C2,N);
    
    for(i=0;i<N;i++){
     if(C1[i].pic!=C2[i].pic){
         break;
     }   
    }
    
    if(isStable(C1,C2,N)==TRUE)
        printf("Stable\n");
    else
        printf("Not stable\n");    
    return 0;
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	ULL gcd(ULL a, ULL b) { return b ? gcd(b, a % b) : a; }

	void Loop() {
		ULL A, B, C, D; cin >> A >> B >> C >> D;
		if (D < B || A < B) { cout << "No" << endl; return; }
		{
			ULL G = gcd(B, D);
			B /= G; D /= G;
			if (A % G <= C % G) {
				A /= G; C /= G;
			}
			else {
				A /= G; C /= G;
				if (C == 0) { cout << "No" << endl; return; }
				C--;
			}
			A /= G;
		}
		if (C + 1 < B) { cout << "No" << endl; return; }
		cout << "Yes" << endl;
	}

	void Solve(){
		UL t; cin >> t; rep(i, t) Loop();
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 256
N = int(input())
S = [i for i in range(1, 14)]
H = [i for i in range(1, 14)]
C = [i for i in range(1, 14)]
D = [i for i in range(1, 14)]

for n in range(N):
    suit, num = input().split()
    num = int(num)
    if suit == 'S': S.remove(num)
    if suit == 'H': H.remove(num)
    if suit == 'C': C.remove(num)
    if suit == 'D': D.remove(num)

for s in S: print('S', s)
for h in H: print('H', h)
for c in C: print('C', c)
for d in D: print('D', d)


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

int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> x(n);
    int w;
    for(int i=0;i<2*m;i++){
        cin>>w;
        x.at(w-1)++;
    }
    for(int i=0;i<n;i++){
        cout<<x.at(i)<<endl;
    }
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

using ll = long long;
using namespace std;

int main(){
    int cnt = 0,ans=0;
    string S;
    cin >> S;

    rep(i,S.length()){
        if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
            cnt++;
        }else{
            cnt = 0;
        }
        ans = max(ans, cnt);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

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

    int count = 0;

    for(int i = 0; i < M; i++) {
        int A;
        cin >> A;
        count += A;
    }

    if(count > N) {
        cout << -1 << endl;
    } else {
        cout << N - count << endl;
    }
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
#define fprint(NUM,X) cout << fixed << setprecision(NUM) << (X) << endl
#define fprints(NUM,X,Y) cout << fixed << setprecision(NUM) << (X) << " " << (Y) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];

class Dijkstra{
private:
  struct edge{int to,cost;};
  typedef pair<int,int> P;
  vector<edge> graph[100000];
  int ans[100000];

public:
  int vertces,edges;
  int start;
  Dijkstra(){
    cin >> vertces >> edges >> start;
    for(int i = 0;i < edges;i++){
      int a,b,c;
      cin >> a >> b >> c;
      // a--;b--;
      graph[a].push_back(edge{b,c});
      //graph[b].push_back(edge{a,c});
    }
  }

  void goal(int goal){
    if(ans[goal] == 1e+9+7)puts("INF");
    else printf("%d\n",ans[goal]);
  }

  void process(int s = 0){
    s = start;
    priority_queue<P,vector<P>,greater<P> > que;
    fill(ans,ans+vertces,1e+9+7);
    ans[s] = 0;
    que.push(P(0,s));

    while(!que.empty()){
      P p = que.top();que.pop();
      int v = p.second;
      if(ans[v] < p.first)continue;

      rep(i,0,graph[v].sz){
        edge e = graph[v][i];
        if(ans[e.to] > ans[v]+e.cost){
          ans[e.to] = ans[v] + e.cost;
          que.push(P(ans[e.to],e.to));
        }
      }
    }
  }
};

int main(){
  Dijkstra dij;
  dij.process();
  for(int i = 0;i < dij.vertces;i++)dij.goal(i);
  return 0;
}


Measured memory_bytes: 13052
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef pair<string, string> S;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int h, w, k;
string a[800];

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

bool used[820][820];

int solve() {
    int sy, sx;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a[i][j] == 'S') {
                sy = i;
                sx = j;
            }
        }
    }

    int miny = sy, maxy = sy, minx = sx, maxx = sx;
    queue<T> que;
    que.push(make_tuple(sy, sx, 0));
    used[sy][sx] = true;
    while (!que.empty()) {
        T t = que.front(); que.pop();
        int y = get<0>(t), x = get<1>(t), d = get<2>(t);
        miny = min(miny, y);
        maxy = max(maxy, y);
        minx = min(minx, x);
        maxx = max(maxx, x);
        if (y <= 0 || y >= h-1 || x <= 0 || x >= w-1) return 1;
        if (d >= k) continue;
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i], nx = x + dx[i];
            if (!used[ny][nx] && a[ny][nx] == '.') {
                que.push(make_tuple(ny, nx, d+1));
                used[ny][nx] = true;
            }
        }
    }

    return min(min((miny+k-1)/k, (minx+k-1)/k), min((h-1-maxy+k-1)/k, (w-1-maxx+k-1)/k))+1;
}

void input() {
    cin >> h >>  w >> k;
    for (int i = 0; i < h; i++) cin >> a[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 4548
import java.util.*;

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

        HashSet<Integer> set = new HashSet<Integer>();
//        int AStart = 0;
//        if ((A%0.08) == 0){
//            AStart = (int) (A/0.08);
//        } else {
//            AStart = (int) (A/0.08) + 1;
//        }
//        int BStart = 0;
//        if ((B%0.1) == 0){
//            BStart = (int) (B/0.1);
//        } else {
//            BStart = (int) (B/0.1) + 1;
//        }
        for (int i = (int) (Math.ceil(A/0.08)); i < (int) (Math.ceil((A+1)/0.08)); i++){
//            System.out.println(i);
            set.add(i);
        }

        for (int i = (int) (Math.ceil(B/0.1)); i < (int) (Math.ceil((B+1)/0.1)); i++){
//            System.out.println(i);
            if (set.contains(i)){
                System.out.println(i);
                System.exit(0);
            }
        }

        System.out.println("-1");

    }
}

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

int N;
std::vector<std::vector<int>> Child;

int Height(int n)
{
    int len = Child[n].size();
    if(len == 0)return 0;

    std::vector<int> ar;
    ar.resize(len);
    for(int i = 0;i<len;i++)
    {
        ar[i] = Height(Child[n][i]);
    }

    std::sort(ar.begin(),ar.end());

    int result = -1;

    for (int j = 0; j < len; ++j) {
        result = std::max(result, ar[j] + len-j);
    }

    return result;
}

int main() {
    std::cin >> N;
    Child.resize(N);
    for (int i = 1; i <N; ++i) {
        int a;
        std::cin >> a;
        Child[a-1].push_back(i);
    }
    std::cout << Height(0) << std::endl;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  string s;
  cin >> s;
  Yes(s != "AAA" && s != "BBB");
  return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=12010,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,mod,tot,f[N][N];ll inv[N],jc;//f[i][j]表示i个数,j表示1的个数-2的个数 
void upd(int &x) {x+=x>>31&mod;}
void upd(ll &x)  {x+=x>>63&mod;}

int main() {
	qr(n); qr(mod); tot=3*n+1; 
	f[0][tot]=1;
	inv[1]=jc=1; for(int i=2;i<tot;i++) inv[i]=inv[mod%i]*(mod-mod/i)%mod,jc=jc*i%mod;
	for(int i=1;i<tot;i++) 
		for(int j=-i+tot;j<=i+tot;j++) {
			f[i][j]=f[i-1][j-1]*inv[i]%mod;
			if(i>=2)upd(f[i][j]+=f[i-2][j+1]*inv[i]%mod-mod);
			if(i>=3)upd(f[i][j]+=f[i-3][j  ]*inv[i]%mod-mod);
		}
	ll ans=0; 
	for(int i=tot;i<=tot*2;i++) ans+=f[tot-1][i];
	ans%=mod; pr2(ans*jc%mod);
	return 0;
}


Measured memory_bytes: 281088
package main

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

var (
	BufferSize = 10 * 10 * 10 * 10 * 10 * 10 * 10
)

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}

	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}

	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	a := make([]int, n+1, n+1)
	b := make([]int, n+1, n+1)

	for i := 0; i < n+1; i++ {
		a[i] = scanInt(sc)
	}

	for i := 0; i < n; i++ {
		b[i] = scanInt(sc)
	}

	add := 0
	sum := 0
	for i := 0; i < n+1; i++ {
		if a[i] < add {
			sum += a[i]
			add = b[i]
		} else if a[i] < add+b[i] {
			sum += a[i]
			add = add + b[i] - a[i]
		} else {
			sum += add + b[i]
			add = 0
		}
	}

	fmt.Printf("%d\n", sum)
}


Measured memory_bytes: 11520
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

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

using namespace std;

int main(){
	int n;cin>>n;
	long long a[100000]={};
	REP(i,n) cin>>a[i];

	sort(a,a+n);
	int ans=n;
	REP(i,n-1){
		if(a[i]==a[i+1]){
			ans-=2;
			i++;
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
ll mod = 1e9+7;

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

ll lcm(ll a, ll b){
  return (a/gcd(a,b))*b;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = (tx-sx); int dy = (ty-sy);
  rep(i, dy) cout << 'U';
  rep(i, dx) cout << 'R';
  rep(i, dy) cout << 'D';
  rep(i, dx) cout << 'L';
  cout << 'L';
  rep(i, dy+1) cout << 'U';
  rep(i, dx+1) cout << 'R';
  cout << 'D';
  cout << 'R';
  rep(i, dy+1) cout << 'D';
  rep(i, dx+1) cout << 'L';
  cout << 'U';
  return 0;
} 

Measured memory_bytes: 256
module vector_int32_mod
    use,intrinsic :: iso_fortran_env
    type vector
        integer(int64),allocatable:: array(:)
        integer(int64):: l
    contains
        procedure :: push_back => vector_regist
    end type

    interface vector
        module procedure vector_init
    end interface
    private
    public:: vector
contains
    function vector_init() result(vec)
        type(vector):: vec
        allocate(vec%array(1))
        vec%l = 0
    end function

    subroutine vector_regist(vec, v)
        class(vector):: vec
        integer(int64):: v

        if (vec%l+1 > size(vec%array)) call add_(vec)
        vec%l=vec%l+1
        vec%array(vec%l) = v
    end subroutine


    subroutine add_(vec)
        type(vector):: vec
        integer(int64),allocatable:: tmp(:)
        integer(int64):: l

        l = size(vec%array)
        allocate(tmp(l))
        tmp(:) = vec%array(:)
        deallocate(vec%array)
        allocate(vec%array(l*2))
        vec%array(1:l) = tmp(:)
        deallocate(tmp)
    end subroutine
end module

program main
    use,intrinsic :: iso_fortran_env
    use vector_int32_mod
    implicit none
    integer(int64):: n,q,k,i
    integer(int64), allocatable:: a(:), b(:), c(:), x(:), y(:)
    integer(int64), allocatable:: k_dist(:)
    type(vector), allocatable:: to(:), d(:)
    
    read*, n
    allocate(a(n-1), b(n-1), c(n-1))
    allocate(to(n), d(n))
    allocate(k_dist(0:n))

    do i=1,n
        to(i) = vector()
        d(i) = vector()
    end do
    
    do i=1,n-1
        read*, a(i), b(i), c(i)
        call to(a(i))%push_back(b(i))
        call to(b(i))%push_back(a(i))
        call d(a(i))%push_back(c(i))
        call d(b(i))%push_back(c(i))
    end do

    read*, q,k
    allocate(x(q), y(q))
    k_dist(0)=0_8
    call dfs(k,0_8,0_8)

    do i=1,q
        read*, x(i), y(i)
    end do

    do i=1,q
        print'(i0)', k_dist(x(i)) + k_dist(y(i))
    end do
contains
    recursive subroutine dfs(self, from, distance)
        integer(int64), intent(in):: self, from, distance
        integer(int64):: i, next, next_d

        k_dist(self) = k_dist(from)+distance

        do i=1,to(self)%l
            next = to(self)%array(i)
            next_d = d(self)%array(i)
            if (next == from) cycle
            call dfs(next, self,next_d)
        end do
    end subroutine
end program main

Measured memory_bytes: 37152
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <cctype>
#include <climits> // INT_MAX ...
#include <cstring> // 

using namespace std;
using ll = long long;

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

    int n, k;
    cin >> n >> k;
    vector<ll> H(n);
    for (auto &x : H) cin >> x;
    if (n <= k) cout << "0" << endl;
    else {
        ll sum = 0;
        sort(H.begin(), H.end(), greater<ll>());
        for (int i = k; i < n; ++i) {
            sum += H[i];
        }
        cout << sum << endl;
    }

	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            var min = 999;
            for (var i = 0; i <= s.Length - 3; i++)
            {
                var tmp = int.Parse(s.Substring(i, 3));
                min = Math.Min(min, Math.Abs(753 - tmp));
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 11220
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int leftb[4040][2020];
int leftw[4040][2020];
int dp[2020][2020];
int ballnum[4040];
bool ballcolor[4040];
int bplace[2020];
int wplace[2020];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < 2 * N; i++) {
        string s;
        cin >> s;
        cin >> ballnum[i];
        if (s == "B") {
            ballcolor[i] = true;
            bplace[ballnum[i]] = i;
        } else {
            ballcolor[i] = false;
            wplace[ballnum[i]] = i;
        }
    }
    for (int i = 0; i < 4040; i++) {
        fill(leftb[i], leftb[i] + 2020, 0);
        fill(leftw[i], leftw[i] + 2020, 0);
    }
    for (int i = 0; i < 2020; i++) {
        fill(dp[i], dp[i] + 2020, 0);
    }
    for (int i = 1; i < 2 * N + 1; i++) {
        for (int j = 1; j < N + 1; j++) {
            if (ballnum[i - 1] <= j) {
                if (ballcolor[i - 1]) {
                    leftb[i][j] = leftb[i - 1][j] + 1;
                    leftw[i][j] = leftw[i - 1][j];
                } else {
                    leftb[i][j] = leftb[i - 1][j];
                    leftw[i][j] = leftw[i - 1][j] + 1;
                }
            } else {
                leftb[i][j] = leftb[i - 1][j];
                leftw[i][j] = leftw[i - 1][j];
            }
        }
    }
    for (int i = 1; i < N + 1; i++) {
        int costb = i - 1 - leftb[bplace[i]][i - 1];
        int costw = i - 1 - leftw[wplace[i]][i - 1];
        dp[i][0] = dp[i - 1][0] + costb;
        dp[0][i] = dp[0][i - 1] + costw;
    }
    for (int i = 1; i < N + 1; i++) {
        for (int j = 1; j < N + 1; j++) {
            int costb = i - 1 - leftb[bplace[i]][i - 1] + j - leftw[bplace[i]][j];
            int costw = i - leftb[wplace[j]][i] + j - 1 - leftw[wplace[j]][j - 1];
            dp[i][j] = min(dp[i - 1][j] + costb, dp[i][j - 1] + costw);
        }
    }
    cout << dp[N][N] << endl;
}


Measured memory_bytes: 80000
input_word=input()
input_word+="E"
atcg_list=["A","T","C","G"]
OK_list=[]
tmp=[]
for i,inp in enumerate(input_word):

    if inp in atcg_list:
        tmp.append(inp)
    else:
        OK_list.append(tmp)
        tmp=[]

print(max([len(ok) for ok in OK_list]))

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int primeCnt = 0;
		for (int i = 0; i < n; i++) {
			if (checkPrimeNumber(Integer.parseInt(br.readLine()))) primeCnt++;
		}
		System.out.println(primeCnt);
	}

	public static boolean checkPrimeNumber(int target) {
		if (target < 2) return false;
		if (target == 2) return true;
		if (target % 2 == 0) return false;

		for (int i = 3; i * i<= target; i += 2) {
			if (target % i == 0) return false;
		}
		return true;
	}
}

Measured memory_bytes: 30468
/*
* @Author: _dp95
* @Date:   2019-02-10 23:34:11
*/
/*
* @Author: _dp95
* @Date:   2019-02-10 23:31:40
*/
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

const int MAX = 2*1000*100 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

ll a[ MAX ], b[ MAX ] ;
ll dp[ 105 ][ MAX ] ;

int main( ){
  timesaver ;
  int n, w ;
  cin >> n >> w ;
  for( int i = 1 ; i <= n ; i++ ){
    cin >> a[ i ] >> b[ i ] ;
  }
  for( int i = 0 ; i <= n ; i++ ){
    for( int j = 0 ; j <= w ; j++ ){
      if( i == 0 or j == 0 )
        dp[ i ][ j ] = 0 ;
      else if( a[ i ] <= j )
        dp[ i ][ j ] = max( dp[ i - 1 ][ j - a[ i ] ] + b[ i ], dp[ i - 1 ][ j ] ) ;
      else
        dp[ i ][ j ] = dp[ i - 1 ][ j ] ;
    }
  }
  //*/
  cout << dp[ n ][ w ] << nl ;
}

Measured memory_bytes: 159232
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;

int main()
{
    int a;
    cin>>a;
    cout<<a*a*a<<endl;
    return 0;
}




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

void Main()
{
  ll N,A,B,C,D,E;
  cin >> N;  cin >> A;  cin >> B;  cin >> C; cin >> D; cin >> E;
  if (min({N, A, B, C, D, E}) == N) {cout << 5 << endl; return;}
  ll minutes = 0;
  minutes += N / A + min(N % A, (ll)1); //最後の1人がAで移動しきる時間
  ll restPeople = N - (minutes-1) * min(A,B);
  minutes += restPeople / B + min(restPeople % B, (ll)1);
  restPeople = N - (minutes-2) * min({A,B,C});
  minutes += restPeople / C + min(restPeople % C, (ll)1);
  restPeople = N - (minutes-3) * min({A,B,C,D});
  minutes += restPeople / D + min(restPeople % D, (ll)1);
  restPeople = N - (minutes-4) * min({A,B,C,D,E});
  minutes += restPeople / E + min(restPeople % E, (ll)1);
  cout << minutes << endl;
}

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

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N, M;
    cin >> N >> M;
    vec A(M);
    REP(i,0,M) cin >> A[i];

    vec dp(N+1, 0);
    dp[0] = 1; dp[1] = 1;
    if(M == 0) {
        REP(i,2,N+1) dp[i] = (dp[i-1] + dp[i-2]) % MOD; 
    }
    else {
        ll j = 0;
        REP(i,1,N+1) {
            if(i == A[j]) {
                dp[i] = 0;
                ++j;
            }
            else if(i > 1) dp[i] = (dp[i-1] + dp[i-2]) % MOD;
        }
    }
    _PR(dp[N]);

    return 0;
}

/*



*/

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ls x<<1
#define rs x<<1|1
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=3e5+100;
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
ll qpow(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1)ret*=a;
		b>>=1;
		a*=a;
	}
	return ret;
}
ll get(ll x){
	return x*(x+1)/2;
}
struct node{
	ll val;
	int num;
	bool operator < (const node&z)const {
		return val<z.val;
	}
}a[maxn];
void solve()
{
    int a,b,k,ans;
    scddd(a,b,k);
    int now=min(a,b);
    while(k){
    	//cout<<now<<' '<<ans<<endl;
    	if(a%now==0&&b%now==0){
    		k--;
    		ans=now;
		}now--;
	}
	ac;
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("D://out.txt","w",stdout);
    //IOS;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;
const int INF=1001001001;

int n;
int x[10],y[10];

double dist(int i,int j){
   double dx=x[i]-x[j];
   double dy=y[i]-y[j];
   return pow(dx*dx+dy*dy,0.5);
}

void solve(){
   cin>>n;
   for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
   double sum=0.0;
   vector<int> v(n);
   rep(i,n) v[i]=i+1;
   do{
      //一つ一つの組み合わせごとに距離を計算してsumにたしていく
      for(int i=0;i<n-1;i++) sum+=dist(v[i],v[i+1]);
   }while(next_permutation(v.begin(),v.end()));
   //何通りあるか
   int ave=1;
   for(int i=2;i<=n;i++) ave*=i;
   printf("%.8f",sum/ave);
}

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


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

int main() {
    int N;
    int d[110];
    int num[110] = {0};
    
    cin >> N;
    
    for (int i = 0; i < N; ++i) cin >> d[i];

    for (int i = 0; i < N; ++i) {
        num[d[i]] = 1;
    } 

    int total = 0;
    for (int i = 1; i <= 100; ++i) {
        total += num[i];
    }

    cout << total << endl;
}

Measured memory_bytes: 256
// ※※※ 解答不能 ※※※
// SheepRanger氏.
// https://atcoder.jp/contests/tenka1-2019-beginner/submissions/5124700
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 305;
const int MAXC = MAXN * 305;
const int INF = (LL)1e9 + 5;
const LL MOD = 998244353;
LL ans = 0, sum = 0, dp[MAXC], dp2[MAXC];

LL qpow(LL a, LL pw){
    LL res = 1;
    while(pw){
        if(pw & 1) res = res * a % MOD;
        a = a * a % MOD;
        pw >>= 1;
    }
    return res;
}

int main(){
    int N;
    scanf("%d", &N);
    dp[0] = dp2[0] = 1;
    for(int i = 0; i < N; i++){
        int a;
        scanf("%d", &a);
        sum += a;
        for(int j = sum; j >= 0; j--){
            dp2[j] = (dp2[j] * 2) % MOD;
            if(j >= a){
                dp[j] = (dp[j] + dp[j - a]) % MOD;
                dp2[j] = (dp2[j] + dp2[j - a]) % MOD;
            }
        }
    }
    ans = (qpow(3, N) - qpow(2, N) * 3 + 3) % MOD;
    LL minus = 0;
    for(int i = sum / 2 + sum % 2; i <= sum; i++){
        minus = minus + dp2[i] - 2 * dp[i];
        if(i == sum) minus++;
    }
    printf("%d\n", ((ans - minus * 3) % MOD + MOD) % MOD);
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int
main(void){  
  ios_base::sync_with_stdio(false);

  ll n, k;
  cin >> n >> k;
  //倍数を考える問題 --> modを考える

  ll ans = 0LL;
  ans += (n/k)*(n/k)*(n/k);
  //偶数かつ2n>=kの場合、 (a, b, c) % k = (k/2, k/2, k/2)が存在
  
  if(k%2 == 0){
    ans += ((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k);
  }
  
  cout << ans << endl;
    
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ls (o << 1)
#define rs (o << 1 | 1)
using namespace std;

int a[100005];

int p[100005];

long long ans[100005];

int data[100005], cc = 0;

inline int hs(int x) {
    return lower_bound(data, data + cc, x) - data + 1;
}

pair <int, long long> operator + (pair <int, long long> a, pair <int, long long> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

struct Seg {
    int l, r, c, lz;
    long long s;
} T[400005];

inline void push_up(int o) {
    T[o].c = T[ls].c + T[rs].c;
    T[o].s = T[ls].s + T[rs].s;
}

inline void clr(int o) {
    T[o].c = T[o].s = 0;
    T[o].lz = 1;
}

inline void push_down(int o) {
    if(!T[o].lz) return;
    clr(ls); clr(rs);
    T[o].lz = 0;
}

void build(int o, int l, int r) {
    T[o].l = l; T[o].r = r;
    T[o].c = T[o].s = T[o].lz = 0;
    if(l == r) return;
    int m = (l + r) >> 1;
    build(ls, l, m);
    build(rs, m + 1, r);
}

void update(int o, int x, int c, long long v) {
    if(T[o].l == T[o].r) {
        T[o].c += c;
        T[o].s += v;
        return;
    }
    push_down(o);
    int m = (T[o].l + T[o].r) >> 1;
    update(x <= m ? ls : rs, x, c, v);
    push_up(o);
}

void modify(int o, int l, int r) {
    if(T[o].l == l && T[o].r == r) {
        clr(o);
        return;
    }
    push_down(o);
    int m = (T[o].l + T[o].r) >> 1;
    if(r <= m) modify(ls, l, r);
    else if(l > m) modify(rs, l, r);
    else {
        modify(ls, l, m);
        modify(rs, m + 1, r);
    }
    push_up(o);
}

pair <int, long long> query(int o, int l, int r) {
    if(T[o].l == l && T[o].r == r) return make_pair(T[o].c, T[o].s);
    push_down(o);
    int m = (T[o].l + T[o].r) >> 1;
    if(r <= m) return query(ls, l, r);
    if(l > m) return query(rs, l, r);
    return query(ls, l, m) + query(rs, m + 1, r);
}

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++ i)
        scanf("%d", a + i);
    p[1] = 1;
    for(int i = 2; i <= n; ++ i) {
        p[i] = p[i - 1];
        if(a[i] > a[p[i]])
            p[i] = i;
    }
    for(int i = 1; i <= n; ++ i)
        data[cc ++] = a[i];
    sort(data, data + cc);
    cc = unique(data, data + cc) - data;
    build(1, 1, cc);
    for(int i = 1; i <= n; ++ i)
        update(1, hs(a[i]), 1, a[i]);
    int cur = p[n];
    while(true) {
        if(cur == 1) {
            pair <int, long long> t = query(1, 1, cc);
            ans[1] += t.second;
            break;
        }
        int nc = p[cur - 1];
        int x = hs(a[nc]);
        pair <int, long long> t = query(1, x + 1, cc);
        ans[cur] += t.second - 1ll * t.first * a[nc];
        modify(1, x + 1, cc);
        update(1, x, t.first, 1ll * t.first * a[nc]);
        cur = nc;
    }
    for(int i = 1; i <= n; ++ i)
        printf("%lld\n", ans[i]);
    return 0;
}


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

int main() {
 string s,t;
 cin >> s >> t;
  int ans = t.size();
  int size = s.size();
  int tsize = t.size();
 for(int i = 0; i <= size-tsize; i++){
  int a = 0;
   for(int k = 0; k < tsize; k++){
     if(t[k] != s[k+i]) a++;
   }
   ans = min(ans,a);
 }
  cout << ans << endl;
}

Measured memory_bytes: 3612
l = raw_input().split()
N = int(l[0])
S = [0]*N
for i in range(N):
    l = raw_input().split()
    S[i] = l[0]

#print(N, S)

count = 0
for s in S:
    count += s.count('AB')
#print(count)

numA = 0
numB = 0
numAB = 0
for s in S:
    if s[0] != 'B' and s[-1] == 'A':
        numA += 1
    if s[0] == 'B' and s[-1] != 'A':
        numB += 1
    if s[0] == 'B' and s[-1] == 'A':
        numAB += 1

count += min(numA, numB)
if numAB > 0:
    count += numAB - 1
if (numA > 0 or numB > 0) and numAB > 0:
    count += 1
print(count)


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

int main() {
	vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << a[k-1] << endl;

	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE CPP #-}
module Main where

import qualified Data.Vector as V 
import qualified Data.Map.Strict as M
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

dump :: (Show a) => a -> IO()
#if __GLASGOW_HASKELL__ >= 800
dump x = print x
#else
dump _ = pure ()
#endif

-- "101010" -> [1,0,1,0,1,0]
readToList :: String -> [Int]
readToList [] = []
readToList (x:xs) = read [x] : readToList xs

-- "10 10 10" -> [10, 10, 10]
readvec :: IO [Int]
readvec = (fmap (read . BS.unpack) . BS.words) <$> BS.getLine

newtype UF a = UF (M.Map a a) deriving (Show) -- Map node parent

makeuf :: Int -> UF Int
makeuf n = let m = M.fromList $ zip [0..n] [0..n]
                in UF m

union :: (Eq a, Ord a) => a -> a -> UF a -> UF a
union l r uf@(UF m) = let lp = find l uf
                          rp = find r uf
                      in if lp == rp
                         then uf
                         else if size l uf < size r uf
                              then UF $ M.update (const $ Just rp) lp m
                              else UF $ M.update (const $ Just lp) rp m

find :: (Eq a, Ord a) => a -> UF a -> a
find x uf@(UF m) = let px = m M.! x
                in if px == x
                   then px
                   else find px uf -- TODO 貼り直し

size :: (Eq a, Ord a) => a -> UF a -> Int
size x (UF m) = M.size $ M.filter (\par -> par==x) m

main :: IO()
main = do
  s <- getLine
  let s'= take (length s `div` 2) s
  let t = take (length s `div` 2) $ reverse s
  dump s'
  dump t
  print $ length $ filter (\(x, y) -> x /= y) $ zip s' t


Measured memory_bytes: 508