akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

int main() {
  int N;
  cin >> N;
  vector<string> blues(N);
  rep(i, N){
    cin >> blues.at(i);
  }
  int M;
  cin >> M;
  vector<string> reds(M);
  rep(i, M){
    cin >> reds.at(i);
  }
  
  int max = 0;
  rep(i, N){
    int temp = 1;
    string s = blues.at(blues.size()-1);
    blues.pop_back();
    rep(j, blues.size()){
      if(s == blues.at(j))
        temp++;
    }
    rep(j, reds.size()){
      if(s == reds.at(j))
        temp--;
    }
    max = temp > max ? temp : max;
  }
  cout << max << endl;
}
  

Measured memory_bytes: 256
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)
function main()
	n = readline() |> parseInt
	a = Int[]
	x = 1
	while x<=sqrt(n)
		if n%x==0
			push!(a,x)
		end
		x += 1
	end
	m = 10^18
	for i in a
		k = div(n,i)
		r = 0
		while k>0
			r += 1
			k=div(k,10)
		end
		m = min(r,m)
	end
	println(m)
end

main()

Measured memory_bytes: 110096
while line = gets
  n,x = line.split(" ").map{|val|val.to_i}
  break if 0 == n && 0 == x

  cnt = 0
  ave = x/3
  for i in (1..ave-1)
    ave2 = (x-1)/2
    for j in (i+1..ave2)
      k = x-i-j
      if j <k && k<= n
        cnt += 1
      end
    end
end

puts (cnt)
end

Measured memory_bytes: 8688
from itertools import product

import numpy as np

n, m = list(map(int, input().split(" ")))
if m == 0:
    print(0)
    exit()
xyz_list = []
for _ in range(n):
    xyz_list.append(np.array(list(map(int, input().split(" ")))))
arrs = [np.array(x) for x in product([1, -1], repeat=3)]
ans = max([sum(sorted([sum(arr * xyz) for xyz in xyz_list])[-m:]) for arr in arrs])
print(ans)


Measured memory_bytes: 21556
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,k,p[1005],ans=0;
  cin>>n>>k;
  for(ll i=0;i<n;i++) cin>>p[i];
  sort(p,p+n);
  for(ll i=0;i<k;i++) ans+=p[i];
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;
// ついでに有理数型
using rat = boost::rational<bint>;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()

void solve(long long N, std::vector<std::string> S){
  ll ac = 0,wa = 0,tle = 0 , re = 0;
  for (int i = 0; i < N; i++) {
    if(S[i] == "AC")ac++;
    if(S[i] == "WA")wa++;
    if(S[i] == "TLE")tle++;
    if(S[i] == "RE")re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

int main(){
    long long N;
				scanf("%lld",&N);
				std::vector<std::string> S(N);
				for(int i = 0 ; i < N ; i++){
								std::cin >> S[i];
				}
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 6428
n = input()
a = []
for i in n:
    a.append(int(i))

if a[0]+a[1]+a[2]+a[3] == 7 :
    print('{}+{}+{}+{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]+a[2]-a[3] == 7 :
    print('{}+{}+{}-{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]-a[2]+a[3] == 7 :
    print('{}+{}-{}+{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]+a[1]-a[2]-a[3] == 7 :
    print('{}+{}-{}-{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]+a[2]+a[3] == 7 :
    print('{}-{}+{}+{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]+a[2]-a[3] == 7 :
    print('{}-{}+{}-{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]-a[2]+a[3] == 7 :
    print('{}-{}-{}+{}=7'.format(a[0],a[1],a[2],a[3]))
elif a[0]-a[1]-a[2]-a[3] == 7 :
    print('{}-{}-{}-{}=7'.format(a[0],a[1],a[2],a[3]))


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

int main(){
  double n;
  cin >> n;
  double m = 0;
  for(int i = 1; i <= n; i++){
    if(i % 2) m++;
  }
  cout << m / n << endl;
}

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

const int N = 3005;
int n;
pair<long long, long long> a[N];
long long f[N][N];

long long F(int i, int j)
{
    if (i > j)
    {
        return 0;
    }
    if (f[i][j] != -1)
    {
        return f[i][j];
    }
    int now = j - i + 1;
    long long ans = 0;
    ans = max(F(i, j - 1) + abs(a[now].second - j) * a[now].first,
              F(i + 1, j) + abs(a[now].second - i) * a[now].first);
    return f[i][j] = ans;
}
bool cmp(pair<long long, long long> x, pair<long long, long long> y)
{
    return (x.first != y.first ? x.first < y.first : x.second > y.second);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1, cmp);
    memset(f, -1, sizeof(f));
    long long ans = 0;
    cout << F(1, n);
    return 0;
}


Measured memory_bytes: 74312
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    int N;
    cin >> N;
    string S;
    cin >> S;
    rep(i,2*N){
        if(i%2==0){
            S[i] == 'W'?S[i]='B':S[i]='W';
        }
    }
    ll ans = 1;
    ll R = 0,L = 0;
    rep(i,2*N)if(S[i]=='W')R++;
    if(R!=N)ans = 0;
    R = 0;
    rep(i,2*N){
        if(S[i]=='W')L++;
        else {
            ans *= L;
            L--;
            ans %= mod;
        }
    }
    for(ll i = 0;i<N;i++){
        ans *= i+1;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
/*
 *  Lang    : C++
 *  Author  : little_angel
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int ans = 0;
    string a, b;
    cin >> a >> b;
    for (int i = 0; i < a.length(); ++i) {
        if (a[i] != b[i])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

const double EPS = 1e-8;

int dcmp(double d) {
    if (fabs(d) < EPS) {
        return 0;
    }
    return d < 0? -1 : 1;
}

struct Vector {
    double x, y;
    Vector(double x=0, double y=0): x(x), y(y){
    }
};

typedef Vector Point;

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

double cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x;
}

Vector operator-(const Vector& a, const Vector& b) {
    return Vector(a.x - b.x, a.y - b.y);
}

Vector operator+(const Vector& a, const Vector& b) {
    return Vector(a.x + b.x, a.y + b.y);
}

Vector operator*(const Vector& a, const double p) {
    return Vector(a.x * p, a.y * p);
}

double length(const Vector& v) {
    return sqrt(dot(v, v));
}

bool intersectProp(const Point& a1, const Point& a2, const Point& b1, const Point& b2) {
    double c1 = cross(a2 - a1, b1 - a1);
    double c2 = cross(a2 - a1, b2 - a1);
    double c3 = cross(b2 - b1, a1 - b1);
    double c4 = cross(b2 - b1, a2 - b1);
    
    return dcmp(c1 * c2) == -1 && dcmp(c3 * c4) == -1;
}

bool onSegment(const Point& a, const Point& b, const Point& p) {
    Vector pa = a - p;
    Vector pb = b - p;
    return dcmp(cross(pa, pb)) == 0 && dcmp(dot(pa, pb)) <= 0;
}

bool intersect(const Point& a1, const Point& a2, const Point& b1, const Point& b2) {
    return intersectProp(a1, a2, b1, b2) || onSegment(a1, a2, b1) 
            || onSegment(a1, a2, b2) || onSegment(b1, b2, a1) || onSegment(b1, b2, a2);
}

Point lineIntesection(const Point& p, const Vector& v, const Point& q, const Vector& w) {
    Vector u = p - q;
    return p + v * (cross(w, u) / cross(v, w)); 
}

double distanceToSegment(const Point& a, const Point& b, Point& p) {
    Vector u = b - a;
    Vector v = p - a;
    Vector w = p - b;
    
    if (dot(u, v) < 0) {
        return length(v);
    }
    else if (dot(u, w) > 0) {
        return length(w);
    }
    else {
        return fabs(cross(u, v) / length(u));
    }
}

int main() {
    Point points[4];
    int q;
    cin >> q;
    for (int kase = 0; kase < q; kase++) {
        for (int i = 0; i < 4; i++) {
            cin >> points[i].x >> points[i].y;
        }
        Vector v1 = points[1] - points[0];
        Vector v2 = points[3] - points[2];

        double ans = 0;
        
        if (intersect(points[0], points[1], points[2], points[3])) {
            ans = 0;
        }
        else {
            ans = min(min(distanceToSegment(points[2], points[3], points[0]),
                    distanceToSegment(points[2], points[3], points[1])),
                    min(distanceToSegment(points[0], points[1], points[2]),
                    distanceToSegment(points[0], points[1], points[3])));
        }
        cout << fixed << setprecision(8) << ans << endl;
    }
   
    return 0;
}

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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    string s,t;
    cin >> N >> s >> t;
    int ans;
    rep(i,N+1) {
        string tmp = s.substr(0,i);
        tmp += t;
        if (tmp.substr(0,N)==s) {
            ans = i+N;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(){
  long long A, B, C;
  int ans=0;
  cin >> A >> B >> C;

  if (A == B && B == C && C == A && A%2==0) {
    printf("-1\n");
  }else{
    while (A%2==0 && B%2==0 && C%2==0){
      long long Ah = A/2, Bh = B/2, Ch = C/2;
      A = Bh + Ch;
      B = Ah + Ch;
      C = Ah + Bh;
      ans++;
    }
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int a,b;
  cin>>a>>b;
  cout<<max({a+a-1,a+b,b+b-1})<<endl;  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct point{double x;double y;};
int i,j,k,count1=0,count2=0;

int main(void){
    int d=0,ans=0;
    string s;
    cin>>s;
    for(i=0;i<s.length();i++){
        if(s[i]=='C'){
            d=1;
        }
        if(d==1&&s[i]=='F'){
            ans=1;
        }
    }
    cout<<(ans?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
N, K = list(map(int, input().split()))

trees = {}
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    if a not in trees.keys():
        trees[a] = set()
    if b not in trees.keys():
        trees[b] = set()
    trees[a].add(b)
    trees[b].add(a)

ans = K
if N > 1:
    memo = {1}
    targets = {1}
    while targets:
        next_targets = set()
        for target in targets:
            if target == 1:
                base = K-1
            else:
                base = K-2
            i = 0
            for child in trees[target]:
                if child not in memo:
                    memo.add(child)
                    ans = (ans*(base-i)) % (10**9+7)
                    next_targets.add(child)
                    i += 1
        targets = next_targets
print(ans)

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

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

    std::string S;
    std::string ans;

    cin >> S;
    cin >> K;

    std::string sub = S.substr(K - 1,1);

    for (int i = 0;i < N; i++){
        std::string a = S.substr(i,1);
        if(a == sub){
            ans += a;
        }else{
            ans += "*";
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>


int main(void)
{
	using namespace std;
	
	int n;
	cin >> n;

	int* data = new int[n];
	for(int i=0; i<n; i++)	cin >> data[i];


	for(int i=n-1; i>0; --i) cout << data[i] << " ";
	cout << data[0] << endl;

	return 0;

}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
#define N 16
using namespace std;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}

const int TOP = 0,FRONT = 1,LEFT = 2, RIGHT = 3,BACK = 4,BOTTOM = 5;
class Dice{
public:
  int val[6];
  Dice(){for(int i=0;i<6;i++) val[i] = i;}
  Dice(int val[6]){for(int i=0;i<6;i++) this->val[i] = val[i];}
  Dice(int l,int r,int f,int b,int d,int u){
    val[LEFT] = l, val[RIGHT] = r;
    val[FRONT] = f, val[BACK] = b;
    val[BOTTOM] = d, val[TOP] = u;
  }
  void rot(string s){
    if(s == "N" || s == "B") rotN();
    else if(s == "S" || s == "F") rotS();
    else if(s == "E" || s == "R") rotE();
    else if(s == "W" || s == "L") rotW();
    else if(s == "CW") rotCW();
    else if(s == "CCW") rotCCW();
    else assert(!"rot error");
  }

  //?\\?????¢??????
  void rotN(){
    swap(val[TOP],val[FRONT]);
    swap(val[FRONT],val[BOTTOM]);
    swap(val[BOTTOM],val[BACK]);
  }

  //???????????¢??????
  void rotS(){
    //rotN(),rotN(),rotN();
    swap(val[TOP],val[BACK]);
    swap(val[BACK],val[BOTTOM]);
    swap(val[BOTTOM],val[FRONT]);
  }


  //????????¢??????
  void rotE(){
    swap(val[TOP],val[LEFT]);
    swap(val[LEFT],val[BOTTOM]);
    swap(val[BOTTOM],val[RIGHT]);
  }

  //????????¢??????
  void rotW(){
    //rotE(),rotE(),rotE();
    swap(val[TOP],val[RIGHT]);
    swap(val[RIGHT],val[BOTTOM]);
    swap(val[BOTTOM],val[LEFT]);
  }

  //???????????????????¨????????????????
  void rotCW(){
    swap(val[FRONT],val[RIGHT]);
    swap(val[RIGHT],val[BACK]);
    swap(val[BACK],val[LEFT]);
  }

  //??????????????????????¨???????????????????
  void rotCCW(){
    //rotCW(),rotCW(),rotCW();
    swap(val[FRONT],val[LEFT]);
    swap(val[LEFT],val[BACK]);
    swap(val[BACK],val[RIGHT]);
  }
};


int n;
struct dat{int x,y;Dice d;};
typedef pair<short,short> P;
typedef map<P,int> M;
typedef set<P> S;

M dice[N];
M getMove(int x,int y,Dice d,string rot){
  static int dx[1<<8]={},dy[1<<8]={};
  dx['L'] = -1, dx['R'] = 1,dy['F'] = -1, dy['B'] = 1;
  M res;
  res[P(x,y)] = d.val[BOTTOM];
  for(char ch:rot){
    x += dx[(int)ch], y += dy[(int)ch];
    d.rot(string(1,ch));
    res[P(x,y)] = d.val[BOTTOM];
  }
  return res;
}

int getScore(int idx,S &used){
  int res = 0;
  for(pair<P,int>const &p:dice[idx])
    if(!used.count(p.first))res += p.second;
  return res;
}

S getUsed(int idx,S used){
  for(pair<P,int>const &p:dice[idx]) used.insert(p.first);
  return used;
}


int DP(){
  S used[1<<N];
  int dp[1<<N] = {};
  for(int bit=0;bit<(1<<n);bit++)
    for(int i=0;i<n;i++) {
      if(bit>>i&1)continue;
      int nbit = bit | (1<<i);
      int nscore = dp[bit] + getScore(i,used[bit]);
      Max(dp[nbit],nscore);
      if(used[nbit].empty()) used[nbit] = getUsed(i,used[bit]);

    }
  return dp[(1<<n)-1];
}


signed main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++){
      int x,y;
      int l,r,f,b,d,u;
      string rot;
      cin>>x>>y>>l>>r>>f>>b>>d>>u>>rot;
      dice[i] = getMove(x,y,Dice(l,r,f,b,d,u),rot);
    }
    cout<<DP()<<endl;
  }
  return 0;
}

Measured memory_bytes: 236892
N = int(input())
A = list(map(int, input().split()))
dp = [0] * N
dp[1] = abs(A[1] - A[0])
for i in range(2, N):
  dp[i] = min(
    abs(A[i] - A[i - 1]) + dp[i - 1],
    abs(A[i] - A[i - 2]) + dp[i - 2])
print(dp[-1])


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

int main () {
  int n;
  int a[300000];
  cin >> n;
  for (int i = 0; i < 3*n; i++) cin >> a[i];
  sort(a, a+3*n);
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[3*n - 2 - 2*i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
 
#define int ll
 
typedef int64_t ll;
//static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,0,1,-1}, dy4[4] = {1,-1,0,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) signed((a).size())
#define LEN(a) signed((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end());reverse((c).begin(),(c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
#define YesNo(x) puts((x)?"Yes":"No")
 
signed main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    REP(i,tx-sx) printf("R");
    REP(i,ty-sy) printf("U");
    REP(i,tx-sx) printf("L");
    REP(i,ty-sy) printf("D");
    printf("D");
    REP(i,tx-sx+1) printf("R");
    REP(i,ty-sy+1) printf("U");
    printf("L");
    printf("U");
    REP(i,tx-sx+1) printf("L");
    REP(i,ty-sy+1) printf("D");
    printf("R");

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

ll a[200000+5];

int main(){
		ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i] -= i+1; 
	}	
	sort(a,a+n);
	ll sum=0,minsad=0,presum=0,sum1=0;
	for(int i=0;i<n;i++){
		sum+=a[i];
sum1+=a[i]-a[0];
	}
	minsad = sum1;
	for(ll i=0;i<n;i++){
		ll tans = i*a[i]-presum+(sum-(n-i)*a[i]);
		if(tans<minsad)minsad = tans;
		presum+=a[i];
		sum-=a[i];
	}
	cout<<minsad<<endl;


}


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

using namespace std;

using int64 = long long;

constexpr int64 P = 1000000007;

// Verified: ABC133E, ABC132D, ABC130E
struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 x) : x(x) {}
  FiniteField() : x(0) {}
  int64 Value() { return x; }
  inline FiniteField operator+(FiniteField o) {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

vector<FiniteField> MakeFactorialTable(int n) {
  vector<FiniteField> values(n + 1);
  values[0] = 1;
  for (int i = 1; i <= n; i++) {
    values[i] = values[i - 1] * i;
  }
  return values;
}

vector<vector<FiniteField>> MakePartitionNumberTable(int n, int k) {
  vector<vector<FiniteField>> table(n + 1, vector<FiniteField>(k + 1));
  for (int i = 0; i <= n; i++) {
    table[i][1] = 1;
    for (int j = 2; j <= k; j++) {
      table[i][j] = table[i][j - 1];
      if (i - j >= 0) table[i][j] += table[i - j][j];
    }
  }
  return table;
};

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

  int n, k;
  cin >> n >> k;
  auto p_table = MakePartitionNumberTable(n, k);
  cout << p_table[n][k].Value() << endl;
}



Measured memory_bytes: 10616
// C - Strange Bank
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	int coin[12] = {1,6,36,216,1296, 7776,46656,9,81,729,6561,59049};
	int inf = 1e9;
	int n; cin>>n;
	vi dp(n+1, inf);
	dp[0] = 0;
	// for(int x:dp){cout<<x<<" ";}
	// puts("");
	for(int c:coin){
		// cout<<c<<" ";
		rp(yen,c,n+1){
			dp[yen] = min(dp[yen], dp[yen-c] + 1);
		}
	}
	// puts("");
	cout<< dp[n] <<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(RALL(v));
  ll num = 0;
  for (int i = k; i < n; i++) {
    num += v[i];
  }
  cout << num << endl;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(X: int, A: int):
    print(0 if X < A else 10)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    solve(X, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
N,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(N)]
dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
  w = wv[i][0]
  for j in range(W+1):
    dp[i+1][j]=dp[i][j]
    if j >= w:
      dp[i+1][j] = max(dp[i+1][j], dp[i][j-w] + wv[i][1])
print(max(dp[N]))

Measured memory_bytes: 171656
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)

count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        if l[i]==l[j]:
            continue
        for k in range(j+1,n):
            if l[i]<l[j]+l[k] and l[j]!=l[k]:
                count+=1
print(count)

Measured memory_bytes: 9192
#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
using namespace std;
const int MAXN = (int) 105;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int M,N,Z;
int edgefrom[MAXN],edgeto[MAXN];
vector<pair<int,int> > G[MAXN];

struct Matrix{
    int a[MAXN][MAXN];
}a,mp;

Matrix Matrix_Multiply(const Matrix& L, const Matrix& R,int siz){
    Matrix ret;
    memset(ret.a,0,sizeof(ret.a));
    for(int i=1;i<=siz;i++){
        for(int j=1;j<=siz;j++){
            for(int k=1;k<=siz;k++){
                ret.a[i][k] |= L.a[i][j]&R.a[j][k];
            }
        }
    }
    return ret;
}

void Power(int matrix_size,int X){
    while(X){
        if(X&1) a=Matrix_Multiply(a,mp,matrix_size);
        mp=Matrix_Multiply(mp,mp,matrix_size);
        X>>=1;
    }
}

void work(){
    while(~scanf("%d%d%d",&N,&M,&Z)){
        if(N==0&&M==0&&Z==0) return;
        int edgeid=0;
        for(int i=1;i<=N;i++) G[i].clear();
        for(int i=1;i<=M;i++){
            int u,v; scanf("%d%d",&u,&v);
            G[u].push_back(make_pair(v,++edgeid));
            edgefrom[edgeid]=u;
            edgeto[edgeid]=v;
            G[v].push_back(make_pair(u,++edgeid));
            edgefrom[edgeid]=v;
            edgeto[edgeid]=u;
        }
        memset(a.a,0,sizeof(a.a));
        memset(mp.a,0,sizeof(mp.a));
        for(int i=1;i<=N;i++){
            for(int j=0;j<G[i].size();j++){
                int to=G[i][j].first;
                int now_id=G[i][j].second;
                for(int k=0;k<G[to].size();k++){
                    int to_to=G[to][k].first;
                    int next_id=G[to][k].second;
                    if(to_to!=i){
                        mp.a[now_id][next_id]=1;
//                        printf("%d->%d->%d %d -> %d\n",i,to,to_to,now_id,next_id);
                    }
                }
            }
        }
        for(int i=1;i<=edgeid;i++)if(edgefrom[i]==1)
            for(int j=1;j<=edgeid;j++) a.a[j][i]=1;
        Power(edgeid,Z-1);
        int ok=0;
        for(int i=1;i<=edgeid;i++){
            for(int j=1;j<=edgeid;j++){
                if(a.a[i][j]&&edgeto[j]==N) ok=1;
            }
        }
        if(ok) printf("yes\n");
        else printf("no\n");
    }
}

int main(){
//    freopen("data.in","r",stdin);
    work();
    return 0;
}



/*
8 8 6
1 2
2 3
2 4
3 5
5 6
6 7
7 8
4 8
*/








Measured memory_bytes: 3260
N, M = map(int, input().split())
L, R = (
    zip(*(map(int, input().split()) for _ in range(M))) if M else
    ((), ())
)

x = 1
y = N
for l, r in zip(L, R):
    x = max(l, x)
    y = min(r, y)
ans = max(y - x + 1, 0)
print(ans)


Measured memory_bytes: 57468
import Foundation

let array = [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
]
let input_line=Int(readLine()!)!

print(array[input_line-1])

Measured memory_bytes: 6756
#include <cstdio>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

bool can1[200000+10];
bool can2[200000+10];

int main(void) {
  int n, nEdge;
  scanf("%d%d", &n, &nEdge);
  REP(i, nEdge) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    if(a == 0) {
      can1[b] = true;
    }
    if(b == 0) {
      can1[a] = true;
    }
    if(a == n-1) {
      can2[b] = true;
    }
    if(b == n-1) {
      can2[a] = true;
    }
  }
  bool res = false;
  REP(i, n) {
    if(can1[i] && can2[i]) {
      res = true;
    }
  }
  puts(res ? "POSSIBLE" : "IMPOSSIBLE");
  
  return 0;
}


Measured memory_bytes: 512
import copy
N,K = map(int,input().split())
A = map(int,input().split())

A_sum = [0]
for a in A:
    A_sum.append(A_sum[-1]+a)

score = []
for r in range(1,N+1):
    for l in range(0,r):
        score.append(A_sum[r]-A_sum[l])

ans = 0
for i in range(40,-1,-1):
    count = 0
    score_a = []
    for j in score:
        if (j & (1<<i)):
            count += 1
            score_a.append(j)
    if count >= K:
        ans += (1<<i)
        score = copy.deepcopy(score_a)

print(ans)


Measured memory_bytes: 25240
def resolve():
    n = int(input())
    L = sorted(list(map(int, input().split())))
    cnt = 0
    checker = [[[0 for i in range(n)] for j in range(n)] for k in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if (i < j < k) and (L[i] != L[j] and L[i] != L[k] and L[j] != L[k]) and L[i] + L[j] > L[k]:
                    cnt += 1

    print(cnt)

resolve()

Measured memory_bytes: 18016
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,k;

	int ans=0;
	cin >>n>>k;
	Vi p(n);
	rep(i,n){
		cin>>p[i];
	}
	sort(all(p));
	rep(i,k){
		ans+=p[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3624
import java.io.*;

import java.util.*;

public class Main {

	static Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))) ;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int A = in.nextInt() ;
		int P = in.nextInt() ;
		int sum = A*3+P ;
		if(sum%2!=0){
			sum -= (sum%2) ;
		}
		System.out.println(sum/2);
	}

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> a(n);
  int max_i;
  int max_num = 0,semi_max_num = 0;
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    if(a > max_num){
      max_i = i;
      max_num = a;
    }
    else if(a > semi_max_num)
      semi_max_num = a;
  }
  for(int i = 0; i < n; i++){
    if(i == max_i)
      cout << semi_max_num << endl;
    else
      cout << max_num << endl;
  }
}

Measured memory_bytes: 4032
// Problem : B - Bishop
// Contest : Panasonic Programming Contest 2020
// URL : https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

/*
 * author :Sadik Hassan
 * 
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
/*---------------------------------------------------------------------*/
const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
	ll a,b;
	cin>>a>>b;
	if(a==1||b==1)
	{cout<<1<<nl;}
	else if((a*b)&1)
	{
		cout<<(a*b)/2+1<<nl;
	}
	else
	{
		cout<<(a*b)/2<<nl;
	}
    return 0;
}


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

int n,ans;

void dfs(long long sum, int cnt3, int cnt5, int cnt7) {
	if (sum > n) return;
	if (cnt3 > 0 && cnt5 > 0 && cnt7 > 0) ans++;
	dfs(sum * 10 + 3, cnt3 + 1, cnt5, cnt7);
	dfs(sum * 10 + 5, cnt3, cnt5 + 1, cnt7);
	dfs(sum * 10 + 7, cnt3, cnt5, cnt7 + 1);
}
int main() {
	cin >> n;
	dfs(0, 0, 0, 0);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

ll n;
string ans;
int main() {
	cin >> n;
	while(n>26){
		n--;
		ans += (n%26) + 'a';
		n /= 26;
	}
	ans += n-1+'a';
	reverse(ALL(ans));
	cout <<  ans << endl;
    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <vector>

#define MAXN 100002
#define MAXM 100002

using namespace std;

int N, a, b, c, Q, K, x, y;

struct node {
    int id;
    long long dist;
    node(int i, long long d) : id(i), dist(d) {}
};

vector<vector<node> > sons(MAXN);
int first[MAXN] = {0};
int path[MAXN << 1];
long long deep[MAXN << 1];
int dp[MAXN << 1][19];
int pos = 0;

void dfs(int cur, int fa, long long d) {
    for (auto son : sons[cur]) {
        if (son.id == fa) continue;
        path[pos] = cur;
        deep[pos++]= d;
        dfs(son.id, cur, d + son.dist);
    }
    path[pos] = cur;
    deep[pos++] = d;
}

void make_st() {
    for (int i = 0; i != pos; ++i) {
        if (first[path[i]] == 0)
            first[path[i]] = i;
        dp[i][0] = i;
    }
    for (int j = 1; j != 19; ++j) {
        for (int i = 0; i + (1 << j) - 1 < pos; ++i) {
            int a = dp[i][j - 1];
            int b = dp[i + (1 << j >> 1)][j - 1];
            dp[i][j] = deep[a] < deep[b] ? a : b;
        }
    }
}

int LCA(int a, int b) {
    a = first[a]; b = first[b];
    if (a > b) swap(a, b);
    int j = -1, len = b - a + 1;
    while (len) {
        ++j;
        len /= 2;
    }
    int c = dp[a][j];
    int d = dp[b - (1 << j) + 1][j];
    return deep[c] < deep[d] ? path[c] : path[d];
}

long long dis(int a, int b) {
    int t = LCA(a, b);
    return deep[first[a]] + deep[first[b]] - 2 * deep[first[t]];
}

int main() {
    cin >> N;
    for (int i = 1; i != N; ++i) {
        cin >> a >> b >> c;
        sons[a].push_back(node(b, c));
        sons[b].push_back(node(a, c));
    }
    dfs(1, 0, 0);
    make_st();
    cin >> Q >> K;
    while (Q--) {
        cin >> x >> y;
        cout << dis(x, K) + dis(K, y) << endl;
    }
    return 0;
}

Measured memory_bytes: 31104
=begin
－－－－－－－－－－－－－－
  n = 入力値
  num = nの奇数のみ配列
  cnt = 約数の個数
  ans[] =  奇数かつ約数が"ちょうど8個"ある整数を格納
－－－－－－－－－－－－－－
  1: 1 ~ n までを繰り返す(i)
  2: i が奇数の場合、iの約数を数える
  3: i の約数が"ちょうど8個"の場合のみ ans に代入
  4: ansの要素数を出力
=end

def cnt_divisor(num)
  cnt = 1;
  for i in 2..num do
    cnt += 1 if num % i == 0
  end
  return cnt
end

n = gets.to_i;
ans = [];

for num in 1..n do
  ans << num if cnt_divisor(num) == 8 && num % 2 != 0;
end

puts ans.size;

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
char a[101];
int f=0;
int main()
{
	cin>>a;
	int lena=strlen(a);
	for(int i=0;i<lena;i++)
	{
		if(f==0&&a[i]=='C')
			f=1;
		if(f==1&&a[i]=='F')
		{f++;break;
			}	
	}
	if(f==2)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
f = [0 for i in range(100000 + 10)]
for x in a:
	f[x] = f[x] + 1
mx = f[0] + f[1]
for i in range(1, 100000 + 1):
	mx = max(mx, f[i - 1] + f[i] + f[i + 1])
print(mx)


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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; }

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    n = n % 10;

    string ans = "pon";
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
        ans = "hon";
    } else if (n == 3) {
        ans = "bon";
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        //modをかける場所がわからない
        int N = int.Parse(Console.ReadLine());
        long[] A = new long[N];
        string[] str = Console.ReadLine().Split();
        for (var i = 0; i < N; i++)
        {
            A[i] = long.Parse(str[i]);
        }
        
        long ans = 0;
        int mod = (int)1e9 + 7;

        // bit列60桁分をすべて走査する
        for (int k = 0; k < 60; k++)
        {
            long x0 = 0;
            long x1 = 0;
            for (int i = 0; i < N; i++)
            {
                // k桁目をビット演算で取り出す
                var x = (A[i] >> k) & 1;
                // k桁目が 0, 1 のどちらかを数えておく
                if (x == 0) x0 += 1;
                else x1 += 1;
            }

            long p = 1;
            for (int i = 0; i < k; i++)
            {
                p *= 2;
                p %= mod;
            }
            // x0 * x1 が 0, 1 の組み合わせ数
            var count = (x0 * x1) % mod;
            ans += count * p;
            ans %= mod;
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 50632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
  string s;
  bool gu = true, ki = true;
  cin >> s;
  rep(i, s.size()) {
    if ((i + 1) % 2 == 0) {
      if (s.at(i) == 'R') gu = false;
    } else {
      if (s.at(i) == 'L') ki = false;
    }
  }
  if (gu && ki)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;

	int ans = n;
	for (int i = 0; i < n; ++i){
		if (s[i] == 'x' && (i + 1 < n && s[i + 1] ==  'x')){
			ans = i+1; break;
		} // end if
	} // end for
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3352
def solve():
    N = int(input())
    A = list(map(int, input().split()))

    four_cnt = 0
    two_cnt = 0
    buta = 0
    for a in A:
        if a % 4 == 0:
            four_cnt += 1
        elif a % 2 == 0:
            two_cnt += 1
        else:
            buta += 1
    
    if two_cnt > 0:
        if buta <= four_cnt:
            print('Yes')
        else:
            print('No')
    else:
        if buta <= four_cnt + 1:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    solve()

Measured memory_bytes: 62576
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    while (1)
    {
        cin >> n;
        if (n == 0)
            break;
        vector<int> w(n);
        rep(i, n) cin >> w[i];
        vector<vector<int>> dp(n, vector<int>(n, 0));
        for (int b = 2; b <= n; b++)
        {
            for (int l = 0; l + b <= n; l++)
            {
                int r = l + b - 1;
                if (abs(w[r] - w[l]) <= 1 && dp[l + 1][r - 1] == b - 2)
                    dp[l][r] = b;
                for (int m = l; m < r; m++)
                    dp[l][r] = max(dp[l][r], dp[l][m] + dp[m + 1][r]);
            }
        }
        cout << dp[0][n - 1] << endl;
    }
}


Measured memory_bytes: 3724
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	string S, T;
  	cin >> S >>T;
  	cout << T+S <<endl;

    
  	return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as C
import Data.Vector.Unboxed

main = C.interact $ put . sol . get

get = unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . show

sol v = f 0 (v!0)
  where
  f c 0   = c
  f c 1   = c + if v!1==1 then 1 else 0
  f c i
    | v!i==i && v!(i-1)==i-1  = f (c+1) (i-2)
    | v!i==i                  = f (c+1) (i-1)
    | otherwise               = f c (i-1)

Measured memory_bytes: 8060
i = list(map(int, input().split()))
hp1 = i[0]
hp2 = i[2]
atk1 = i[1]
atk2 = i[3]
while i[0] >= 0 or i[2] >= 0:
    hp2 -= atk1
    if hp2 <= 0:
        break
    hp1 -= atk2
    if hp1 <= 0:
        break
if hp1 <= 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 61904
#include <algorithm>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const int MAX = 200001;
int ti[MAX];
int n, t;

long long solve() {
  sort(ti, ti + n);
  long long res = 0LL;
  res += t; ti[0] += t;
  for (int i = 1; i < n; ++i) {
    if (ti[i] >= ti[i - 1]) {
      res += t;
    } else {
      res += t - (ti[i - 1] - ti[i]);
    }
    ti[i] += t;
  }
  return res;
}

int main() {
  cin >> n >> t;
  for (int i = 0; i < n; ++i) cin >> ti[i];
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 1024
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	if(a*500>=b){
		printf("Yes\n");
	}else printf("No\n");
}

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

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    for (int z = 0; z < q; z++) {
        int k;
        cin >> k;
        lint ans = 0;
        lint m = 0, c = 0, mc = 0;
        //区間を[l,r)で管理
        int l = 0, r = 0;
        while (l != n) {
            if (r >= k) {
                if (s[l] == 'M') {
                    m--;
                    mc -= c;
                }
                if (s[l] == 'C') {
                    c--;
                }
                l++;
            }
            if (r < n) {
                r++;
                if (s[r - 1] == 'C') {
                    c++;
                    mc += m;
                }
                if (s[r - 1] == 'M') {
                    m++;
                }
            }
            if (r >= k && s[l] == 'D') {
                ans += mc;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1412
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
typedef long long ll;

int main()
{
	string S;
	ll K;
	int match1 = -1, match2 = -1;
	ll seq = 0;
	ll pt1 = 0, pt2 = 0, pt3 = 0;
	ll cnt = 0;

	cin >> S >> K;
	
	rep(i, S.length()) {
		if (S[i] == S[S.length() - 1]) {
			match1 = i;
			seq++;
			pt1++;
		}
		else {
			break;
		}
	}
	pt1 /= 2;

	if (seq == S.length()) {
		cout << (seq* K) / 2 << endl;
		return 0;
	}

	rep(i, S.length()) {
		if (S[0] == S[S.length() - 1 - i]) {
			match2 = S.length() - 1 - i;
			seq++;
			pt3++;
		}
		else {
			break;
		}
	}
	pt3 /= 2;

	if (match2 == -1) match2 = S.length() + 1;

	rep1(i, match1 + 1, match2 - 2) {
		if (S[i] == S[i + 1]) {
			cnt++;
			if (i == match2 - 2) {
				pt2 += (cnt + 1) / 2;
			}
		}
		else {
			pt2 += (cnt + 1) / 2;
			cnt = 0;
		}
	}
	cout << pt1 + pt2 * K + pt3 + (seq / 2) * (K - 1) << endl;

	return 0;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<ll>c(1000001);
	for(ll i=1;i<1000001;i++) {
		c.at(i)=i-1+c.at(i-1);
	}
	ll n,ans=0;
	string s;
	cin>>n;
	map<string,int>mp;
	for(int i=0;i<n;i++){
		cin>>s;
		sort(s.begin(),s.end());
		mp[s]++;
	}
	for(auto p:mp){
		auto a=p.first;
		auto b=p.second;
		if(b>=2){
			ans+=c.at(b);
		}
	}
	cout<<ans<<endl;
}


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

using namespace std;

int main()
{
	int D, T, S;
	cin >> D >> T >> S;

	if (T * S >= D) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	
}


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++)  cin >> a.at(i);
  
  set<int> s;
  for(int i=0;i<N;i++){
    if(s.count(a.at(i))){
      cout << "NO" << endl;
      return 0;
    }
    s.insert(a.at(i));
  }
  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 10368