akhauriyash/Code-Regression huggingface dataset:
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int j, y;
void dfs(int a, int b, string h) {
	if (a == j && b == y) {
		cout << h << endl;
		return;
	}
	if (a > j || b > y) { return; }
	if (a <= 3 && b >= 5) { return; }
	if (a >= 5 && b <= 3) { return; }
	if (a + b >= 10) return;
	dfs(a + 1, b, h + "A");
	dfs(a, b + 1, h + "B");
}

int main() {
	cin >> j >> y;
	dfs(0, 0, "");
}


Measured memory_bytes: 3212
n = gets.to_i
ary = gets.chomp.split(/ /)
a = ary[0].to_i
b = ary[1].to_i
memo = gets.chomp.split(/ /)
p = Array.new
n.times do |i|
    p[i] = memo[i].to_i
end

c = 0
d=0
e=0

n.times do |i|
    if p[i] <= a
        c += 1
    elsif p[i] <= b
        d += 1
    else
        e += 1
    end
end

min = c;
min = (min > d)? d : min;
min = (min > e)? e : min;

puts(min);



Measured memory_bytes: 1788
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numInt = 0;
        int sumNum = 0;
        while(true){
            String numString = sc.next();
            if(numString.equals("0")){
                break;
            }
            for(int i = 0; i<numString.length(); i++){
                numInt = Integer.parseInt(numString.substring(i,i+1));
                if(i == 0){
                    sumNum = numInt;
                }else{
                    sumNum += numInt;
                }
            }
            System.out.println(sumNum);
        }
    }
}


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

int main(){
  int A,B,K;
  cin>>A>>B>>K;
  int G = __gcd(A,B);
  int cnt = 0;
  for(int i=1;;i++){
    if(G % i == 0){
      cnt++;
    }
    if(cnt == K){
      cout<<G / i<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
//void datalog(int a[],int n);
int BubbleSort(int a[],int n);


int BubbleSort(int a[],int n){
    int s=0;
    for(int i=0;i<n-1 ;i++){
        for(int j=n-1;j>=i+1;j--){
            if(a[j-1]>a[j]){
                swap(a[j],a[j-1]);
                s++;
            }
            
        }   
         
    }
    return s;
}


int main(){

    int a[200],n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    int s=BubbleSort(a,n);
    //cout <<n <<endl;
    for(int i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<a[i];
    }
    cout <<"\n";
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>

int main(void){
     
      double r,l,s,pie = 3.141592653589;
       scanf("%lf",&r);
        l = 2*pie*r;
        s = pie*r*r;
       printf("%lf %lf\n",s,l);
      
        return 0;
 }
        

Measured memory_bytes: 648
#include<stdio.h>

int main(void)
{
	int a, h,ans = 0;
	scanf("%d%d",&h,&a);
	while (h > 0) {
		h = h - a;
		ans++;
		//printf("%d\n",h);
	}
	printf("%d",ans);
	


	return 0;
}


Measured memory_bytes: 128
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 10????????? cout << setprecision(10) << double;
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (???test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// ??\??????push_back(d)???array[d]???????????????1?????§?????????
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN(){T d;cin>>d;return d;}
// ?????§??¬?´???°???Greatest Common Divisor???
LL gcd(LL a, LL b){ return (b > 0) ? gcd(b, a%b) : a; }
// ????°???¬?????°???Least Common Multiple???
LL lcm(LL a, LL b){ return a / gcd(a, b) * b; }

// ------------------- include, typedef, define END. -------------------

void Output(VI personNo){
	int maxValue = -1;
	int ansNo = 0;
	FOR(i,0,10001){
		if(maxValue < personNo[i]){
			maxValue = personNo[i];
			ansNo = i;
		}
	}
	cout << ansNo << " " << maxValue << endl;
}

int main(){
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;
	
	//??????????????????????????????.
	int n=0;
	int p,d1,d2;
	while(cin>>n, n){
		VI personNo(10001,0);
		FOR(i,0,n){
			cin >> p>> d1>> d2;
			personNo[p] = d1 + d2;
		}
		Output(personNo);
	}
	
	return 0;
}

Measured memory_bytes: 1296
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        int[] intArray = new int[100];
        for (int i = 0; i < n1; i++) {
            intArray[i] = sc.nextInt();
        }

        int count = 0;
        for (int i= 0; i < intArray.length; i++) {
            for (int j = i + 1; j < intArray.length && intArray[j] != 0; j++) {
                if (intArray[i] == intArray[j]) {
                   continue;
                }
                for (int k = j + 1; k < intArray.length && intArray[k] != 0; k++) {
                    if ((intArray[i] + intArray[j] > intArray[k]) && (intArray[j] + intArray[k] > intArray[i]) && (intArray[k] + intArray[i] > intArray[j])) {
                        if (intArray[i] != intArray[k] && intArray[j] != intArray[k]) {
                            count++;
                        }
                    }
                }
            }
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 37040
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
using namespace std;
const int N=2017;
typedef long long ll;
ll ans=0x3f3f3f3f3f3f3f3full;
int n,a[N],x,mi[N][N];
void solve(int k){
	ll res=1ll*k*x;
	rep(i,1,n)res+=mi[i][k];
	ans=min(ans,res);
}
int main(){
	scanf("%d%d",&n,&x);
	rep(i,1,n)scanf("%d",&a[i]);
	rep(i,1,n){
		mi[i][0]=a[i];
		
		rep(j,1,n-1)mi[i][j]=min(mi[i][j-1],a[(i-j+n-1)%n+1]);
	}
	rep(i,0,n-1)solve(i);
	printf("%lld\n",ans);
}

Measured memory_bytes: 16000
S = input()
if S[:2] == "00" and S[2:] == "00":
    print('NA')
elif S[:2] == "00" and int(S[2:]) > 12:
    print('NA')
elif int(S[:2]) > 12 and S[2:] == "00":
    print('NA')
elif S[:2] == "00" and int(S[2:]) <= 12:
    print('YYMM')
elif int(S[:2]) <= 12 and S[2:] == "00":
    print('MMYY')
elif int(S[:2]) > 12 and int(S[2:]) > 12:
    print('NA')
elif int(S[:2]) <= 12 and int(S[2:]) <= 12:
    print("AMBIGUOUS")
elif int(S[:2]) <= 12:
    print("MMYY")
else:
    print('YYMM')


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

long long div(int a){
  long long res = 0;
  while(a%2 == 0){
    res++;
    a /= 2;
  }
  
  return res;
}

int main(){
  int n;
  cin >> n;
  long long ans = 0;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    ans += div(a);
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main(void)
{
    while (true) {
        u_int h, w;
        cin >> h >> w;
        if (!h && !w)
            break;
        
        char buf[w+2];
        for (u_int i = 0; i < w; i++)
            buf[i] = '#';
        buf[w] = '\n'; buf[w+1] = '\0';

        for (u_int i = 0; i < h; i++)
            printf("%s", buf);
        puts("");
    }
    
    return 0;
}

Measured memory_bytes: 1140
M=10**9+7
def comb(n,k):
  a=b=1
  for i in range(1,k+1):
    a=a*n%M
    b=b*i%M
    n-=1
  return a*pow(b,M-2,M)
n,a,b=map(int,input().split())
print((pow(2,n,M)-1-comb(n,a)-comb(n,b))%M)

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

#define ALL(v) v.begin(), v.end()
typedef long long ll;



using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int low = max(a, c);
	int up = min(b, d);

	cout << max(0, up - low) << endl;


}

Measured memory_bytes: 256
H, W, A, B = map(int, input().split())
row = [A, W-A]
col = [B, H-B]
ans = ''
for i in [0, 1]:
    for y in range(col[i]):
        for j in [0, 1]:
            for x in range(row[j]):
                ans += str(j^i)
        ans +='\n'
print(ans)

Measured memory_bytes: 6036
/*
首先想到同样例1的构造方式。还是能过三十多个点的。
比如1 4 1 3，会输出无解（会填[1 1 -3 1]）。怎么改呢。对于一个点，它可以覆盖多个h*w的子矩形，只要对每个子矩形满足负权和，它们的和可以尽量大。
将原方案中的所有正数扩大d倍，不得不填负的格子只需恰好大于一个子矩形的和。这样多个格子加起来的和就大了。
如1 4 1 3，可以填[1000 1000 -2001 1000]。
*/
#include <cstdio>
#include <algorithm>
const int N=505;

bool A[N][N];

int main()
{
	int H,W,h,w; scanf("%d%d%d%d",&H,&W,&h,&w);
	if(!(H%h) && !(W%w)) return puts("No"),0;//每个子矩形都是负的，拼一块还是负的 

	int r=h,c=w,tot=0;
	while(1)
	{
		while(1)
		{
			++tot, A[r][c]=1;
			if(c+w>W) break;
			c+=w;//每次只能加w而不是2w-1!
		}
		c=w;
		if(r+h>H) break;
		r+=h;
	}
	int v=-h*w*1000+999;
	if(-1ll*tot*v>=1000*(H*W-tot)) puts("No");
	else
	{
		puts("Yes");
		for(int i=1; i<=H; ++i,putchar('\n'))
			for(int j=1; j<=W; ++j) printf("%d ",A[i][j]?v:1000);
	}

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string n; cin >> n;
    if (n[0] == n[2])
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,i,max=0;
  scanf("%d",&n);
  int A[n],B[n];
  for(i=0;i<n;i++)
  {
    scanf("%d",&A[i]);
    if(A[i]>max) max=A[i];
  }
  int C[max+1];
  //Counting_Sort
  for(i=0;i<=max;i++) C[i]=0;
  for(i=0;i<n;i++) C[A[i]]++;
  //for(i=0;i<=max;i++) printf("%d:%d ",i,C[i]);
  for(i=1;i<=max;i++)
  {
    C[i]=C[i]+C[i-1];
  }
  //for(i=0;i<=max;i++) printf("%d:%d ",i,C[i]);
  //printf("\n");
  for(i=n-1;i>=0;i--)
  {
    B[C[A[i]]]=A[i];
    C[A[i]]--;
  }
  for(i=1;i<=n;i++) 
  {
      if(i==n) printf("%d",B[i]);
      
    else    printf("%d ",B[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 17452
//
// Created by yamunaku on 2019/07/30.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"YES"<<endl
#define CNO cout<<"NO"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    vi p(n);
    rep(i,n) cin >> p[i];
    rep(i,n){
        repl(j,i,n){
            swap(p[i],p[j]);
            rep(k,n-1){
                if(p[k]>p[k+1]){
                    goto next;
                }
            }
            CYES;
            return 0;
            next:;
            swap(p[i],p[j]);
        }
    }
    CNO;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
typedef vector<mint> vec;
typedef vector<vec> mat;

const int M = 1e9 + 7;

// A*Bの計算
mat mul(mat &A, mat &B){
    mat C(A.size(), vec(B[0].size()));
    for(int i = 0; i < A.size(); i++){
        for(int k = 0; k < B.size(); k++){
            for(int j = 0; j < B[0].size(); j++){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]);
            }
        }
    }
    return C;
}

// A^nの計算
mat pow(mat A, ll n){
    mat B(A.size(), vec(A.size()));
    for(int i = 0; i < A.size(); i++){
        B[i][i] = 1;
    }
    while(n > 0){
        if( n & 1 ) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

//入力
ll N, K;
mat G;

int main(){
    cin >> N >> K;
    G.resize(N, vec(N));
    rep(i,N) rep(j, N){
        int t; cin >> t;
        G[i][j] = t;
    }
    G = pow(G, K);
    mint ans = 0;
    rep(i,N) rep(j, N) ans += G[i][j];
    cout << ans << endl;
}

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

typedef struct{
  int pa;
  int le;
  int ri;
} node;

int main(){
  node *ar,*t;
  int a,b,n,id,c,k,z,depth;

  scanf("%d",&n);
  ar=(node *)malloc(sizeof(node)*n);
  t=ar;
  for(a=0;a<n;a++){
    t[a].pa=-1;
    t[a].le=-1;
    t[a].ri=-1;
  }
  
  for(a=0;a<n;a++){
    scanf("%d %d",&id,&k);    
    for(b=0;b<k;b++){
      scanf("%d",&c);
      t[c].pa=id;
      if(b==0)t[id].le=c;
      else t[z].ri=c;
      z=c;
    }
  }
  
  for(a=0;a<n;a++){
    z=t[a].pa;
    depth=0;
    while(z!=-1){
      depth++;
      z=t[z].pa;
    }
    
    printf("node %d: parent = %d, depth = %d, ",a,t[a].pa,depth);
    if(t[a].pa==-1)printf("root, [");
    else if(t[a].le==-1)printf("leaf, [");
    else printf("internal node, [");
    z=t[a].le;
    
    if(z!=-1){
      printf("%d",t[a].le);
      while(t[z].ri!=-1){
	printf(", %d",t[z].ri);
	z=t[z].ri;
      }
    }
    
    printf("]\n");
  }
  
  return 0;
}



Measured memory_bytes: 2936
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=20005,INF=1e18;
struct Node{
	int x,y,w,c;
	Node(int xx=0,int yy=0,int ww=0,int cc=0){
		x=xx;y=yy;w=ww;c=cc;
	}
} Edge[N*8];
int n,v1[N],v2[N],s,t,a[N],root1,root2,x,y,m;
int stot,nxt[N*8],fa1[N],fa2[N],fi1[N],ne1[N],zz1[N],fi2[N],ne2[N],zz2[N],tot1,tot2,head[N];
inline void jb(int x,int y,int w,int c){
	Edge[++stot]=Node(x,y,w,c);
	nxt[stot]=head[x];
	head[x]=stot;
}
inline void jb2(int x,int y,int w,int c){
	jb(x,y,w,c);
	jb(y,x,0,-c);
}
int d[N];
queue<int> q;
bool inq[N];
inline bool spfa(){
	for (int i=1;i<=t;i++) d[i]=INF,inq[i]=0;
	d[s]=0;q.push(s);inq[s]=1;
	while (!q.empty()){
		int x=q.front();q.pop();inq[x]=0;
		for (register int i=head[x];i;i=nxt[i])
		  	if (Edge[i].w>0&&d[x]+Edge[i].c<d[Edge[i].y]){
		  		d[Edge[i].y]=d[x]+Edge[i].c;
		  		if (!inq[Edge[i].y]){
		  			inq[Edge[i].y]=1;
		  			q.push(Edge[i].y);
		  		}
			}
	}
	return d[t]<INF;
}
int hd[N],Flag[N];
inline int anti(int x){
	return (x&1)? x+1:x-1;
}
bool vis[N];
inline int dfs(int now,int flow){
	if (now==t) return flow;
	int usd=0;	
	vis[now]=1;
	for (register int &i=hd[now];i;i=nxt[i])
	  	if (!vis[Edge[i].y]&&Edge[i].w>0&&d[Edge[i].y]==d[now]+Edge[i].c){
	  		int w=dfs(Edge[i].y,min(Edge[i].w,flow-usd));
	  		Edge[i].w-=w;Edge[anti(i)].w+=w;usd+=w;
	  		if (usd==flow) break;
	  	}
	vis[now]=0;
	if (!usd)d[now]=INF;
	return usd;
}
int answ,z,f[N],f1[N],f2[N],ansc;
inline void mcmf(){
	int tmp;
	while (spfa()){
		memcpy(hd,head,sizeof(int)*(t+2));
		tmp=dfs(s,INF),answ+=tmp,ansc+=tmp*d[t];
	}
}
signed main(){
	scanf("%lld",&n);
	s=0;t=n*10+5;
	for (int i=1;i<=n;i++){
		scanf("%lld%lld%lld",&x,&y,&z);
		jb2(s,i,z,0);
		jb2(i,i+n,z,x+y);jb2(i+n,10*n+1,z,0);
		jb2(i,i+2*n,z,x-y);jb2(i+2*n,10*n+2,z,0);
		jb2(i,i+3*n,z,-x+y);jb2(i+3*n,10*n+3,z,0);
		jb2(i,i+4*n,z,-x-y);jb2(i+4*n,10*n+4,z,0);
	}
	for (int i=1;i<=n;i++){
		scanf("%lld%lld%lld",&x,&y,&z);
		jb2(i+5*n,t,z,0);
		jb2(i+6*n,i+5*n,z,-x-y);jb2(10*n+1,i+6*n,z,0);
		jb2(i+7*n,i+5*n,z,-x+y);jb2(10*n+2,i+7*n,z,0);
		jb2(i+8*n,i+5*n,z,x-y);jb2(10*n+3,i+8*n,z,0);
		jb2(i+9*n,i+5*n,z,x+y);jb2(10*n+4,i+9*n,z,0);
	}
	mcmf();
	printf("%lld\n",-ansc);
	return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

int main(){

    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }
    int ans = 0;
    ll t = 0;
    for(int i = 0; i < m; i++){
        t += b[i];
    }
    int j = m;
    for(int i = 0; i < n+1; i++){
        while((j > 0) && (t > k)){
            j--;
            t -= b[j];
        }
        if(t > k) break;
        ans = max(ans, i+j);
        if(i == n) break;
        t += a[i];
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
    int T;
    cin>>T;
    int a,bj=1;
    for(int i=0;i<T;i++)
    {
        cin>>a;
        if(a%2==0)
            if(a%3==0||a%5==0)
                ;
            else
            {
                bj=0;
                break;
            }
    }
    if(bj==1)
        cout<<"APPROVED"<<endl;
    else
        cout<<"DENIED"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#include<vector>



int main(){
	string s;
	cin >> s;
	bool f=true;
	for(int i=0;i<s.size();i+=2){
		if(s[i]=='h'&&s[i+1]=='i');
		else f=false;
	}
	if(f)cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
n=int(input())
d,x=map(int,input().split())
a=[]
for _ in range(n):
	a_=int(input())
	a.append(a_)
for i in range(n):
	for j in range(d+1):
		if a[i]*j+1<=d:
			x += 1
print(x)

Measured memory_bytes: 2940
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int h, w;
	scanf("%d%d", &h, &w);
	vector<vector<char>> r(h, vector<char>(w, '.')), b(h, vector<char>(w, '.')), p(h, vector<char>(w));
	
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			scanf(" %c", &p[i][j]);
		}
	}
	for(int i = 0; i < h; i++){
		r[i][0] = '#';
		b[i][w - 1] = '#';
	}
	for(int i = 0; i < h; i++){
		for(int j = 1; j < w - 1; j++){
			if(i % 2){
				b[i][j] = '#';
			}else{
				r[i][j] = '#';
			}
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(p[i][j] == '#'){
				r[i][j] = '#';
				b[i][j] = '#';
			}
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			printf("%c", r[i][j]);
		}
		printf("\n");
	}
	printf("\n");
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			printf("%c", b[i][j]);
		}
		printf("\n");
	}
	return 0;
}

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

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a%3==0)
    {
        cout << "Possible\n";
        return 0;
    }
    if(b%3==0)
    {
        cout << "Possible\n";
        return 0;
    }
    if((a+b)%3==0)
    {
        cout << "Possible\n";
        return 0;
    }
    cout << "Impossible\n";

    return 0;
}


Measured memory_bytes: 3520
#include <iostream>
#include <map>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int W,H;
bool box_is_in_range(int p, int q){
    // (p,q) is the upper left point of the 3*3 box //
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){  // check all 9 points in the box
            if(p+i < 1 || q+j < 1 || p+i > W || q+j > H) return false;
        }
    }
    return true;
}

int main(){
    int N;
    cin >> H >> W >> N;
    map<pair<long long,long long>,long long> mp;

    for(int i=0;i<N;i++){
        long long a,b;
        cin >> a >> b;
        for(int k=0;k<3;k++){
            for(int l=0;l<3;l++){
                if(a-k >= 1 && a-k <= H-2 && b-l >= 1 && b-l <= W-2){
                    mp[make_pair(a-k,b-l)]++;
                }
            }
        }
    }

    long long ans[10];
    fill(ans, ans+10,0);

    ans[0] = 1ll * (H-2)*(W-2);

    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        ans[itr->second]++;
        ans[0]--;
    }

    for(int i=0;i<10;i++){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 56448
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int sum = 0;
		int[] W = new int[N];
		for(int i = 0; i < N; i++) {
			int x = sc.nextInt();
			W[i] = x;
			sum += x;
		}
		
		int now  = 0;
		int result = 0;
		for(int i = 0; i < N; i++) {
			if((now + W[i]) * 2 > sum) {
				result = Math.min(sum - now * 2, (now + W[i]) * 2 - sum);
				break;
			}
			now += W[i];
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 23764
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (n,q) = scan "%d %d" Tuple2.make
let ls = scan_lines (pred n) "%d %d" Tuple2.make
let ml = scan_lines q "%d %d" Tuple2.make
let arr = Array.make (succ n) 0

let rec dfs tree visited n v =
  arr.(n) <- arr.(n) + v;
  visited.(n) <- true;
  ListL.iter tree.(n) ~f:(fun m ->
      if not visited.(m) then
        dfs tree visited m arr.(n))

let () =
  ListL.iter ml ~f:(fun (p,x) ->
      arr.(p) <- arr.(p) + x);
  let tree = Array.make (succ n) [] in
  ListL.iter ls ~f:(fun (a,b) ->
      tree.(a) <- b::tree.(a);
      tree.(b) <- a::tree.(b));
  let visited = Array.make (succ n)false in
  visited.(1) <- true;
  dfs tree visited 1 0;
  ListL.iter (1++n) ~f:(fun i ->
      if i <> 1 then Printf.printf " ";
      Printf.printf "%d" arr.(i));
  Printf.printf "\n"


Measured memory_bytes: 62464
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int h, n; cin >> h >> n;
  vector<int> a(n), b(n); REP(i, n) cin >> a[i] >> b[i];
  vector<vector<int> > dp(n + 1, vector<int>(h + 1, INF));
  dp[0][h] = 0;
  REP(i, n) for (int j = h; j >= 0; --j) {
    chmin(dp[i + 1][j], dp[i][j]);
    chmin(dp[i + 1][max(j - a[i], 0)], dp[i + 1][j] + b[i]);
  }
  cout << dp[n][0] << '\n';
  return 0;
}


Measured memory_bytes: 39424
def solve():
    N, M = [int(_) for _ in input().split()]
    A = []
    for i in range(N):
        k, *a = map(int, input().split())
        A.append(set(a))
    res = set(range(1, M + 1))
    for i in range(N):
        res &= A[i]
    return len(res)
if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.TreeMap;


public class Main {
//	final static int MOD = 1000000007;

	public static long ans = 0;

	public static void main(String[] args) {

//		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

//		long a = sc.nextLong();

		int n = sc.nextInt();


		//-------------------------------------------------------------------------------------
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for(int i = 0; i <= n; i++) {
			map.put(i, 0);
		}

		for(int i = 1; i <= 100; i++) {
			for(int j = 1; j <= 100; j++) {
				for(int l = 1; l <= 100; l++) {
					int calc = i * i + j * j + l * l + i * l + i * j + j * l;
					if(calc > 0 && calc <= n) {
						int tmp = 1 + map.get(calc);
						map.put(calc, tmp);
					}
				}
			}
		}

		for(int i = 1; i <= n; i++) {
			System.out.println(map.get(i));
		}
		//-------------------------------------------------------------------------------------

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

//		System.out.println(ans);

		sc.close();
	}



}

Measured memory_bytes: 48896
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w,k;
  cin>>h>>w>>k;
  vector<string> tb(h);
  REP(i,h)cin>>tb[i];
  int ans = 0;
  REP(i,1<<h)REP(j,1<<w) {
    int cnt = 0;
    REP(r,h)REP(c,w) {
      if ((i>>r)&1) continue;
      if ((j>>c)&1) continue;
      if (tb[r][c] == '#') ++cnt;
    }
    if (cnt == k) ++ans;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3600
import math
A, B, H, M = map(int, input().split())

degA = 30 * H + 0.5 * M
degB = 6 * M

 

deg = math.radians(abs(degA - degB))


output = math.sqrt(A*A + B*B - 2*A*B*math.cos(deg))
print(output)

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
}

int main()
{
    ll N, R;
    cin >> N >> R;
    double ans = (log2(N)/log2(R));
    if (ans == ceil(ans)) print(ans+1);
    else print(ceil(ans));
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int s[101][101]={0};
    int i,j,r,c;
     
    cin>>r>>c;
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            cin>>s[i][j];
            s[i][c]+=s[i][j];
            s[r][j]+=s[i][j];
        }
        s[r][c]+=s[i][c];
    }
     
    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++){
            cout<<s[i][j];
            if(j!=c){
                cout<<" ";
            }
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3136
#include <stdio.h>

int main(void)
{
  char s[5];
  scanf("%s", s);
  
  if (s[0] == s[1] && s[1] == s[2] && s[2] == s[3])
    puts("No");
  else if (s[0] == s[1] && s[2] == s[3] || s[0] == s[2] && s[1] == s[3] || s[0] == s[3] && s[1] == s[2])
    puts("Yes");
  else
    puts("No");
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;
static const long long INF = 1<<31;

int n;
vector<ll> a, b, c;
ll ans;

int main(void) {
  cin >> n;
  rep (i, 0, n) { ll t; scanf("%lld", &t); a.pb(t);}
  rep (i, 0, n) { ll t; scanf("%lld", &t); b.pb(t);}
  rep (i, 0, n) { ll t; scanf("%lld", &t); c.pb(t);}
  a.pb(-INF); a.pb(INF);
  c.pb(-INF); c.pb(INF);
  sort(all(a));
  sort(all(b));
  sort(all(c));

 //自分で実装二分探索
    for (ll v : b) {
      int aa, cc;
      int l = 0, r = sz(a)-1;
      while (r-l>1) {
        int m = (l+r)/2;
        if (a[m]<v) l = m;
        else r = m;
      }
      aa = l;
      l = 0, r = sz(c)-1;
      while (r-l>1) {
        int m = (l+r)/2;
        if (c[m]<=v) l = m;
        else r = m;
      }
      cc = sz(c) - 1 - r;
      
      ans += 1LL * aa * cc;
    }
    
    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		for (;;) {
			int n = s.nextInt(), m = s.nextInt(), p = s.nextInt();
			if (n < 1) {
				break;
			}

			int a = 0, c = 0;
			for (int i = 0; i < n; ++i) {
				int b = s.nextInt();
				a += b;
				if (i + 1 == m) {
					c = b;
				}
			}
			System.out.println(c < 1 ? 0 : 100 * a * (100 - p) / 100 / c);

		}
	}
}

Measured memory_bytes: 27896
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

int main()
{
	int n;
	string s, t;
	long long d[100000];
	memset(d, 0, sizeof(d));

	cin >> n >> s >> t;

	d[0] = 1;

	for (int i = 1; i < n; i++) {
		int j = i - 1; 
		
		while(j > 0 && t[j] != t[i])
			j--;

		if (j > 0)
			d[i] = d[j];

		for (int k = j; k < i; k++) {
			if (s[k] == t[i])
				d[i] = (d[i] + d[k]) % 1000000007;
		}
	}

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

	return 0;
}


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

long long d_n(long long a) {
  int n = 0;
  while (a != 0) {
    a /= 10;
    n++;
  }
  return n;
}

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

  vector<int> t(n);
  vector<int> x(n);
  vector<int> y(n);

  for (int i = 0; i < n; i++) {
    cin >> t.at(i);
    cin >> x.at(i);
    cin >> y.at(i);
  }
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (t.at(i) >= x.at(i) + y.at(i)) {
      if ((t.at(i) - x.at(i) + y.at(i)) % 2 == 0) {
        flag = 1;
      } else {
        cout << "No";
        return 0;
      }

    } else {
      cout << "No";
      return 0;
    }
  }
  if (flag) cout << "Yes";
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main() {
  bool f;
  int n, b, c, p;
  cin >> n;
  while (n--) {
    b = c = 0;
    f = true;
    for (int i = 0; i < 10; i++) {
      cin >> p;
      if (p < b && p < c) f = false;
      else if (p > b) b = p;
      else if (p > c) c = p;
      else f = false;
    }
    cout << (f ? "YES" : "NO") << endl;
  }
}

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

int main(){
    int N;
    cin >> N;
    vector<int> h(100000);
    for(int i = 0; i < N; i++){
        cin >> h.at(i);
    }
    int dp[100000];
    dp[0] = 0;
    dp[1] = abs(h.at(1) - h.at(0));
    for(int i = 2; i < N; i++){
        dp[i] = min(dp[i - 1] + abs(h.at(i) - h.at(i - 1)), dp[i - 2] + abs(h.at(i) - h.at(i - 2)));
    }
    cout << dp[N - 1] << endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e3+23;

long long x[N], y[N], z[N];
int ind[N];

void solve() {
  int n, m; scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    ind[i] = i;
    scanf("%lld%lld%lld", x+i, y+i, z+i);
  }
  long long ans = 0;
  for (int i = 0; i < 8; ++i) {
    sort(ind, ind+n, [i](int a, int b) {
      int f = 1, s = 1, t = 1;
      if (i&1) f = -1;
      if (i&2) s = -1;
      if (i&4) t = -1;
      return f*x[a]+s*y[a]+t*z[a] > f*x[b]+s*y[b]+t*z[b];
    });
    long long b = 0, t = 0, p = 0;
    for (int j = n-1; j >= n-m; --j) {
      b += x[ind[j]]; t += y[ind[j]]; p += z[ind[j]];
    }
    ans = max(ans, abs(b)+abs(t)+abs(p));
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3848
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

istream& operator>>(istream& is, P& p){
    int x, y;
    is >> x >> y;
    p = P(x, y);
    return is;
}

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<P> input(m);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    for(int i = 0; i < m; ++i)  cin >> input[i];
    sort(a.begin(), a.end());
    sort(input.begin(), input.end(), [](const P& p1, const P& p2){
        if(p1.second == p2.second){
            return p1.first > p2.first;
        }
        return p1.second > p2.second;
    });
    vector<tuple<int, int, int>> table;
    for(int i = 0; i < m; ++i){
        int len = input[i].first, val = input[i].second;
        int p = lower_bound(a.begin(), a.end(), val) - a.begin();
        table.emplace_back(len, val, p);
    }
    ll ans = 0;
    int cur = 0;
    for(int i = 0; i < m; ++i){
        int len, val, p;
        tie(len, val, p) = table[i];
        if(cur >= p)    continue;
        if(len > p - cur){
            ans += (ll)val * (p - cur);
            cur = p;
        }
        else{
            ans += (ll)val * len;
            cur += len;
        }
    }
    for(int i = cur; i < n; ++i)    ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <numeric>
#include <cmath>

using namespace std;

template<class T>
class Input {
public:
    auto operator()() const {
        T v;
        cin >> v;
        return v;
    }
};

template<class L, class R>
class Input<pair<L, R>> {
public:
    auto operator()() const {
        L l;
        R r;
        cin >> l >> r;
        return make_pair(l, r);
    }
};

template<class U>
class Input<vector<U>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        return (*this)(n);
    }
    auto operator()(size_t n) const {
        vector<U> v;
        v.reserve(n);
        Input<U> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in();
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class U>
class Input<vector<vector<U>>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        auto m = in();
        return (*this)(n, m);
    }
    auto operator()(size_t n, size_t m) const {
        vector<vector<U>> v;
        v.reserve(n);
        Input<vector<U>> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in(m);
            v.emplace_back(move(u));
        }
        return v;
    }
};

class InputType
{
public:
    template<class T>
    operator T() const {
        Input<T> i{};
        return i();
    }
};

class InputType2
{
public:
    InputType2(size_t n)
        : n_(n)
    {}
    template<class T>
    operator T() const {
        Input<T> i{};
        return i(n_);
    }
private:
    size_t n_;
};

auto input() {
    return InputType();
}

template<class... Args>
auto input(Args&&... args) {
    return InputType2(std::forward<Args>(args)...);
}

size_t bitcount(size_t n) {
    size_t c = 0;
    while (n) {
        if (n & 1ull)
            ++c;
        n >>= 1;
    }
    return c;
}

auto make_order(size_t n) {
    vector<size_t> a(n, 0);
    iota(begin(a), end(a), 0);
    return a;
}

template<class T>
auto next_permutation(T&& x) {
    using std::begin;
    using std::end;
    return next_permutation(begin(x), end(x));
}

using ll = long long;
using ull = unsigned long long;

int main() {
    size_t n = input();
    size_t m = input();
    vector<size_t> a = input(n);
    sort(rbegin(a), rend(a));
    size_t c = 0;
    for (size_t i = 0; i < n; ++i)
        c += a[i];
    bool b = m <= n;
    for (size_t i = 0; i < m; ++i) {
        if (4 * m * a[i] < c) {
            b = false;
            break;
        }
    }
    if (b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

double dis(int a,int b,vector<vector<int>> xy){
    double ret;
    ret = pow((pow(xy.at(a).at(0)-xy.at(b).at(0),2) + pow(xy.at(a).at(1)-xy.at(b).at(1),2)),0.5);
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> xy (n);
    cout << fixed << setprecision(10);
    vector<int> p;
    for(int i=0; i<n; i++){
        int x,y;
        cin >> x >> y;
        xy.at(i).push_back(x);
        xy.at(i).push_back(y);
        p.push_back(i);
    }
    double sum = 0.0;
    int count = 0;
    do{
        for(int i=0; i<n-1; i++){
            sum += dis(p.at(i),p.at(i+1),xy);
        }
        count++;
    } while(next_permutation(p.begin(),p.end()));
    cout << sum / count << endl;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"strings"
)

func main() {
	var a string
	fmt.Scan(&a)
	b := ""
	arr := strings.Split(a, b)
	i := 0
	counter1 := 0
	if arr[i] == arr[i+1] {
		counter1++
	}
	if arr[i] == arr[i+2] {
		counter1++
	}
	if arr[i] == arr[i+3] {
		counter1++
	}
	if counter1 != 1 {
		fmt.Println("No")
		return
	}
	counter2 := 0
	if arr[i] == arr[i+1] {
		counter2++
	}
	if arr[i+1] == arr[i+2] {
		counter2++
	}
	if arr[i+1] == arr[i+3] {
		counter2++
	}
	if counter2 != 1 {
		fmt.Println("No")
		return
	}
	counter3 := 0
	if arr[i] == arr[i+2] {
		counter3++
	}
	if arr[i+1] == arr[i+2] {
		counter3++
	}
	if arr[i+2] == arr[i+3] {
		counter3++
	}
	if counter3 != 1 {
		fmt.Println("No")
		return
	}
	counter4 := 0
	if arr[i] == arr[i+3] {
		counter4++
	}
	if arr[i+1] == arr[i+3] {
		counter4++
	}
	if arr[i+2] == arr[i+3] {
		counter4++
	}
	if counter4 != 1 {
		fmt.Println("No")
		return
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

vector<ll> dist(ll start, ll n, vector<vector<ll> > &g){
	vector<ll> ret(n, INF);
	ret[start] = 0;
	queue<ll> q;
	q.push(start);

	while(!q.empty()){
		ll node = q.front();q.pop();
		REP(i, g[node].size()){
			ll aite = g[node][i];
			if(ret[node] + 1 >= ret[aite])continue;
			ret[aite] = ret[node] + 1;
			q.push(aite);
		}
	}

	return ret;
}

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

	ll n, a, b;cin >> n >> a >> b;
	a--;b--;
	vector<vector<ll> > g(n);
	REP(i, n-1){
		ll u, v;cin >> u >> v;
		u--;v--;
		g[u].PB(v);
		g[v].PB(u);
	}

	auto distA = dist(a, n, g);
	auto distB = dist(b, n, g);

	ll ans = 0;
	REP(i, n){
		if(distA[i] >= distB[i])continue;
		ans = max(ans, distB[i] - 1);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 8064
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    map<int,int> mp;

    for(int i = 0; i < n; i++){
        mp[a[i]]++;
    }

    int ans = 0;

    for(auto i : mp){
        if(i.second > 0){
            ans++;
        }
    }

    if(ans % 2 == 0){
        cout << ans - 1 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int H,N,sum=0;
    cin>>H>>N;
    int a[N];
    for(int i=0;i<N;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(H>sum)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<pair<int,int>> a(N), c(N);
	for(int i = 0; i < N; ++i) {
		cin >> a[i].first >> a[i].second;
	}
	for(int i = 0; i < N; ++i){
		cin >> c[i].first >> c[i].second;
	}
	sort(ALL(a));
	sort(ALL(c));
	c.push_back(make_pair(3 * N, 3 * N));
	vector<int> used(N);
	int res = 0;
	for(int i = N -1; i >=0; --i){
		int p = N;
		for(int j = 0; j < N; ++j) {
			if(used[j]) continue;
			if(a[i].first >= c[j].first || a[i].second >= c[j].second)
				continue;
			if(c[j].second < c[p].second) {
				p = j;
			}
		}
		if(p < N) {
			++res;
			used[p] = true;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc156/tasks/abc156_c
// brute force
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int n = readln.chomp.to!int;
    int[] x = readln.split.map!(to!int).array;

    long minima = 1<<30;
    foreach(p; 1..101) {
        long dist = 0;
        foreach(person; x) {
            dist += (person-p)^^2;
        }
        minima = min(minima, dist);
    }
    minima.writeln;
}



Measured memory_bytes: 256