akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) puts("error")
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=993244853;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;GG(e<0);
        while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}
        return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e5+10;

    ll bs[N],base=13331,pp[N];ll gg(int l,int r){return (pp[r]-pp[l-1]*bs[r-l+1]%MOD+MOD)%MOD;}
    char str[N];int n;
    bool check(int ln)
    {
        for(int l=1;l+ln-1<=n;l++) for(int r=l+ln;r+ln-1<=n;r++)
            if(gg(l,l+ln-1)==gg(r,r+ln-1))
                return 1;
        return 0;
    }
    void main()
    {
        bs[0]=1;for(int i=1;i<N;i++) bs[i]=bs[i-1]*base%MOD;

        n=qread();scanf("%s",str+1);
        for(int i=1;i<=n;i++) pp[i]=(pp[i-1]*base+(str[i]-'a'+1))%MOD;
        int fl=0,fr=n,ans=0;
        while(fl<=fr)
        {
            int mid=(fl+fr)>>1;
            if(check(mid)) ans=mid,fl=mid+1; else fr=mid-1;
        }
        write(ans);
    }//(ans+MOD)%MOD
};
int main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 1024
#include <iostream>

int main(int argc, char const *argv[])
{
    int a, b, c;
    int count = 0;
    std::cin >> a >> b >> c;

    for (int i = a; i <= b; i++)
    {
        if (c % i == 0)
        {
            count++;
        }
    }

    std::cout << count << std::endl;
    return 0;
}



Measured memory_bytes: 3104
k = gets.split(" ")[1].to_i
s = gets.chomp
 
a = s.split(/(0+)/).map{|item| item.length}
if s[-1]=="0" then a.push(0) end
 
t = a[0, 2*k+1].inject(:+)
m = t
i = 2
while i+2*k < a.count
  t = t - a[i-1] - a[i-2] + a[i+2*k-1] + a[i+2*k]
  if t >= m
    m = t
  end
  i += 2
end
 
puts m

Measured memory_bytes: 8188
import java.util.Arrays;
import java.util.Scanner;

/*
問題文


*/

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

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        long A[] = new long[a];
        long B[] = new long[b];
        long C[] = new long[x+y+c];

        for (int i = 0; i < a; i ++) {
            A[i] = -sc.nextInt();
        }
        for (int i = 0; i < b; i ++) {
            B[i] = -sc.nextInt();
        }
        for (int i = 0; i < c; i ++) {
            C[i] = -sc.nextInt();
        }

        Arrays.sort(A);
        Arrays.sort(B);

        int temp = 0;

        for (int i= 0; i < x; i++) {
            C[c+i] = A[i];
        }
        for (int i= 0; i < y; i++) {
        	C[x+c+i] = B[i];
        }

        long ans = 0;
        Arrays.sort(C);

        for (int i = 0; i < x + y; i++) {
            ans -= C[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 98000
using System;

class test
{
static void Main(){
	int D = Int32.Parse(Console.ReadLine());
	string Eves = "";
	if(D <= 24) Eves += " Eve";
	if(D <= 23) Eves += " Eve";
	if(D <= 22) Eves += " Eve";
	Console.WriteLine("Christmas" + Eves);
}
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <tuple>
#include <unordered_set>
#include <unordered_map>

class uftree{
  std::vector<int> parent;
  std::vector<int> rank;
  std::vector<long long> ufsize;
  public:
  uftree(int n) : parent(n), rank(n), ufsize(n, 1) {
    for(int i = 0; i < n; i++){
      parent[i] = i;
    }
  }
  int root(int x){
    std::vector<int> update_node_arr;
    while(parent[x] != x){
      update_node_arr.push_back(x);
      x = parent[x];
    }
    for(const auto& it: update_node_arr) parent[it] = x;
    return x;
  }

  bool same(int x, int y){
    return root(x)==root(y);
  }

  long long size(int x){
    return ufsize[root(x)];
  }

  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x==y) return;
    long long xsize = size(x);
    long long ysize = size(y);
    if(rank[x]<rank[y]){
      parent[x] = y;
      ufsize[y] += xsize;
    }else{
      parent[y] = x;
      ufsize[x] += ysize;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }
};

int main(){
  int N,M;
  std::cin >> N >> M;

  std::vector<int> p_arr(N);
  for(int i = 0; i < N; i++) std::cin >> p_arr[i];

  uftree uf(N);
  std::unordered_map<int, std::unordered_set<int>> uf_map;

  for(int i = 0; i < M; i++){
    int x,y;
    std::cin >> x >> y;
    uf.unite(x-1, y-1);
  }
  for(int i = 0; i < N; i++){
    uf_map[uf.root(i)].insert(i);
  }

  int ans = 0;
  for(auto&& it: uf_map){
    auto group = it.second;
    for(auto&& it2: group){
      if(group.count(p_arr[it2]-1)) ans++;
    }
  }

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

  return 0;
}



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

int main(){
    string s,t;
    cin >> s >> t;
    int n = s.length(),m = t.length();
    int minm = INT_MAX;
    for(int i = 0;i < n;i++){
        if(i + m <= n){
            int ans =0;
            for(int j = i;j < i+m;j++){
                if(s[j] != t[j-i]) ans++;
            }
            minm = min(minm,ans);
        }
    }
    cout<<minm<<"\n";
}

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

vector<int> v;
int n;

int main() {
#ifdef HOME
	freopen("agc13a.in", "r", stdin);
	freopen("agc13a.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int ant(0);

	cin >> n;
	v.resize(n);
	for (auto &i: v)
		cin >> i;

	v.erase(unique(begin(v), end(v)), end(v)); n = v.size();
	for (int i = 0; i < n;) {
		ant+= 1;
		if (i + 1 >= n)
			break;

		if (v[i] < v[i + 1]) {
			do {
				i+= 1;
				if (v[i - 1] > v[i])
					break; }
			while (i + 1 < n);
			if (v[i - 1] < v[i])
				break; }
		else {
			do {
				i+= 1;
				if (v[i - 1] < v[i])
					break; }
			while (i + 1 < n);
			if (v[i - 1] > v[i])
				break; } }

	cout << ant << endl;

	return 0; }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
bool ok(int a) {
	return a >= 0 and a <= 9;
}
int main() {
	int a, b;
	cin >> a >> b;
	if (ok(a) and ok(b)) {
		cout << a * b;
	}
	else {
		cout << -1;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
num_A = [0] * N

for i in A:
    num_A[i-1] += 1

ans = 0
for i in num_A:
    ans += 0.5 * (i - 1) * i
        
for i in range(N):
    print(int(ans - (num_A[A[i]-1] - 1)))

Measured memory_bytes: 26140
import numpy as np

n, m = map(int, input().split())

arr = []
for _ in range(m):
    a, b = map(int, input().split())
    arr.append(a)
    arr.append(b)

arr = np.array(arr)

print("YES" if np.where(np.bincount(arr) % 2 != 0)[0].shape[0] == 0 else "NO")

Measured memory_bytes: 36548
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <list>
using namespace std;

int main()
{
    string N;
    cin >> N;
    int fX = 0, X = stoi(N);
    for (int i = 0; i < N.size(); i++)
    {
        fX += (N[i] - '0');
    }
    int ans = X % fX;
    if (ans)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200200;
int i,j,k,n,m,x,y,En,ch,ff;
ll ans;
char s[N];
int fg[N],h[N],dp[N];
struct edge { int s,n;} E[N<<1];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void E_add(int x,int y) {
	E[++En].s=y;E[En].n=h[x];h[x]=En;
	E[++En].s=x;E[En].n=h[y];h[y]=En;
}
void dfs1(int x,int F) {
	for (int k=h[x];k;k=E[k].n) if (E[k].s!=F) {
		dfs1(E[k].s,x);
		fg[x]+=fg[E[k].s];
		dp[x]=max(dp[x],dp[E[k].s]+1);
	}
}
void dfs2(int x,int F,int Dp) {
	int i,k,ma1=Dp,ma2=-1,mi=n;
	if (fg[1]-fg[x]) mi=Dp;
	if (s[x]=='1') mi=-1;
	for (k=h[x];k;k=E[k].n) if (E[k].s!=F) {
		if (fg[E[k].s]) mi=min(mi,dp[E[k].s]);
		if (dp[E[k].s]>ma1) ma2=ma1,ma1=dp[E[k].s];
		else ma2=max(ma2,dp[E[k].s]);
	}
	ans+=max(0,min(ma2+1,ma1-1)-mi+1);
	vector<int> pre,suf;
	for (k=h[x];k;k=E[k].n) if (E[k].s!=F) {
		pre.push_back(dp[E[k].s]);
		suf.push_back(dp[E[k].s]);
	}
	for (k=1;k<pre.size();k++) pre[k]=max(pre[k],pre[k-1]);
	for (k=suf.size()-2;k>=0;k--) suf[k]=max(suf[k],suf[k+1]);
	i=-1;
	for (k=h[x];k;k=E[k].n) if (E[k].s!=F) {
		i++;
		int ma=Dp;
		if (i-1>=0) ma=max(ma,pre[i-1]);
		if (i+1<suf.size()) ma=max(ma,suf[i+1]);
		dfs2(E[k].s,x,ma+1);
	}
}
int main() {
	R(n);
	for (i=1;i<n;i++) {
		R(x);R(y);
		E_add(x,y);
	}
	scanf("%s",s+1);
	for (i=1;i<=n;i++) if (s[i]=='1') fg[i]=1;
	dfs1(1,0);
	dfs2(1,0,-1);
	printf("%lld\n",ans+1);
}

Measured memory_bytes: 34432
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef struct pair<int,int> P;
typedef long long ll;

ll n,k,l;

int dp1[16002][3]={};
int dp2[16002][3]={};
ll c[200001]={};
int main() {
	ll x,y;
	cin>>x>>y;

	int i=0;
	while(x<=y){
		x=x*2;
		++i;
	}
	cout<<i<<endl;
	return 0;
}


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

using namespace std;

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

template<typename Container>
bool include(const Container& c, const typename Container::value_type& v) {
  return ( c.end() != std::find(c.begin(),c.end(),v) );
}

template<class T>
vector<T> unique_vec(const vector<T> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  return v;
}

int main() {
  int R;
  cin >> R;
  cout << 2 * M_PI * R << endl;

  return 0;
}


Measured memory_bytes: 3736
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n){
		string s;
		string t;
		cin >> s >> t;
		int ans = 2*n;
		REP(i,n){
			DEBUG(s.substr(i,SZ(s)-i)); DEBUG(t.substr(0,SZ(s)-i));
			if(s.substr(i,SZ(s)-i) == t.substr(0,SZ(s)-i)){
				// DEBUG(2*n-(i+1));
				ans = 2*n-(n-(i));
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;

bool possible (string &s, string &t) {
    int n = s.length();
    for (int i = 0; i < n; i++) {
        if (s == t) return true;
        char ap = s[n - 1];
        s.erase(n - 1);
        s = ap + s;
    }

    return false;
}

int main() {
    string s, t; cin >> s >> t;
    if (possible(s, t)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0&&c>0)
	{
		c-=b;
		if(c<=0){
			break;
		}
		a-=d;
		// cout<<c<<a<<endl;
	}
	if(a>0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


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

using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 
int main()
{
 
 char a;cin>>a;

 if(a<='Z'&&a>='A')cout<<"A\n";
 else cout<<"a\n";
 
 
 
 
 
return 0;
   
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
map< long long, int > prime_factor(long long n) {
  map< long long, int > ret;  // 宣言
        for(long long i = 2; i * i <= n; i++) {//素因数分解
            while(n % i == 0) {
                ret[i]++;
                n /= i;
            }
        }
        if(n != 1) ret[n] = 1; //素数が残った
    return ret;
}
int main() {
  ll t,b;
  cin>>t>>b;
  /////
  ll n=__gcd(t,b);
  //nを素因数分解して素因数の数＋1が答え
  //cout<<n<<endl;
  ll ans=1;
  for(auto v:prime_factor(n)){
    //cout<<v.first<<endl;
   ans++; 
  }
  cout<<ans<<endl;
}

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

int main()
{
    int n,c,k=0;
    cin >>n>>c;
    n++;
    for(int i=0;i<c;i++)
    {
        int p;
        cin >>p;
        k += p;
    }
    cout <<(k%n==0 ? k/n : k/n+1)<<endl;


    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const double INF = 1e18;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool eq(double x, double y){ return abs(x - y) < EPS; }
struct Point{
  double x, y;
  Point() {}
  Point(double x, double y) : x(x), y(y) {}
  Point operator+(const Point& b) const { return Point(x + b.x, y + b.y); }
  Point operator-(const Point& b) const { return Point(x - b.x, y - b.y); }
  Point operator*(const double b) const { return Point(x * b, y * b); }
  Point operator*(const Point& b) const { return Point(x * b.x - y * b.y, x * b.y + y * b.x); }
  Point operator/(const double b) const { return Point(x / b, y / b); }
  bool operator< (const Point& b) const { return x != b.x ? x < b.x : y < b.y; }
  bool operator==(const Point& b) const { return eq(x, b.x) && eq(y, b.y); }
  double norm(){ return x * x + y * y; }
  double arg(){ return atan2(x, y); }
  double abs(){ return sqrt(norm()); }
  Point rotate(double theta){ return Point(cos(theta) * x - sin(theta) * y, sin(theta) * x + cos(theta) * y); }
  Point rotate90(){ return Point(-y, x); }
};

bool compare_y(const Point& a, const Point& b){
  return a.y < b.y;
}

double closest_pair(vector<Point>::iterator begin, vector<Point>::iterator end){
  int N = end - begin;
  if(N == 1) return INF;
  int M = N / 2;
  double mx = (begin + M)->x; //テ、ツクツュテ・ツソツε」ツ?ョxテ・ツコツァテヲツィツ?
  double d = min(closest_pair(begin, begin + M), closest_pair(begin + M, end));
  inplace_merge(begin, begin + M, end, compare_y); //yテ・ツコツァテヲツィツ凖」ツ?ァテ」ツつステ」ツδシテ」ツδ?

  vector<Point> b;
  for(vector<Point>::iterator it1 = begin; it1 != end; it1++){
    if(abs(it1->x - mx) >= d) continue;
    for(vector<Point>::reverse_iterator it2 = b.rbegin(); it2 != b.rend(); it2++){
      Point dfp = *it1 - *it2;
      if(dfp.y >= d) break;
      d = min(d, dfp.norm());
    }
    b.push_back(*it1);
  }

  return d;
}

int main(){
  int N;
  while(cin >> N && N){
    vector<Point> ps(N);
    REP(i, N){
      scanf("%lf %lf", &ps[i].x, &ps[i].y);
    }
    sort(ps.begin(), ps.end());
    cout << (int)closest_pair(ps.begin(), ps.end()) << endl;
  }
  return 0;
}

Measured memory_bytes: 20552
/***** TheAnshul *****/

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  405
ll dp[N][N];
ll a[N];
ll n;
ll fun(ll l,ll r)
{
	if(r==l)
	{
		return 0;
	}
	if(r-l==1)
	{
		return (a[l]+a[r]);
	}
	if(dp[l][r]!=-1)
		return dp[l][r];
	ll sum=0;
	rep(i,l,r+1)
	{
		sum+=a[i];
	}
	ll mn=LLONG_MAX;
	rep(i,l,r)
	{
		mn=min(sum+fun(l,i)+fun(i+1,r),mn);
	}
	dp[l][r]=mn;
	return mn;
}
void solve()
{
	cin>>n;
	rep(i,1,n+1)
	{
		cin>>a[i];
	}
	rep(i,1,n+1)
	{
		rep(j,1,n+1)
		{
			dp[i][j]=-1;
		}
	}
	cout<<fun(1,n);
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

bool vis[60];

void func(vector<vector<lli>> &g,lli now){
	if(vis[now])return;
	vis[now]=true;

	for(auto e:g[now]){
		func(g,e);
	}
}

signed main(){

	lli n,m;
	cin>>n>>m;
	vector<lli> a(m),b(m);
	REP(i,0,m){
		lli tmpA,tmpB;
		cin>>tmpA>>tmpB;
		tmpA--,tmpB--;
		a[i]=tmpA;
		b[i]=tmpB;
	}

	lli ans=0;
	REP(i,0,m){
		vector<vector<lli>> G(n);
		REP(j,0,m){
			if(i==j)continue;
			G[a[j]].push_back(b[j]);
			G[b[j]].push_back(a[j]);
		}
		REP(j,0,n)vis[j]=false;
		func(G,0);

		REP(j,0,n){
			if(!vis[j]){
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int lcm( int m, int n );
int gcd( int m, int n );
main(){
  int a,b,A,B;
  while(scanf("%d %d",&a,&b)!=EOF){
    A=gcd(a,b);
    B=lcm(a,b);
    printf("%d %d\n",A,B);
  }
  return 0;
}
  int gcd( int m, int n ){
    if ( ( 0 == m ) || ( 0 == n ) )
      return 0;
    while( m != n ){
	if ( m > n ) m = m - n;
	else         n = n - m;
      }
    return m;
  }


  int lcm( int m, int n ){
    if ( ( 0 == m ) || ( 0 == n ) )
      return 0;
    return ((m / gcd(m, n)) * n);
  }

Measured memory_bytes: 0
#include <bits/stdc++.h>
//#include<fstream>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

/*ofstream fout("bcount.out");
ifstream fin("bcount.in");*/

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
    ll n,x,t;
    cin>>n>>x>>t;
    ll ans;
    if(n%x == 0)
    	ans = (n/x)*t;
    else
    	ans = (n/x + 1)*t;
    cout<<ans<<endl;
    return 0;
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;

int main() {
    int in;

    cin >> in;
    cout << (in / 3600) << ":" << ((in % 3600) / 60) << ":" << (in % 60) << endl;

    return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
/**CLICK ss---> ctrl+j**/
#define PI 2.0*acos(0.0)
#define ll              long long int
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define MOD             1000000007
#define mx              123456789
using namespace std;
void solve()
{
  ll n, m;
  cin>>n>>m;
  cout<<n*m<<endl;
}
int main()
{
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <iostream>
using namespace std;
int find(int a, int b)
{
    if(a==0)
        return b;
    return find(b%a,a);
}
int main(void) 
{
    long long a,b;
    cin>>a>>b;
    long gcd=find(a,b);
    cout<<gcd<<endl;
    return 0;
}

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

#define N 101
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1<<21)

int n, M[N][N], color[N], d[N], p[N];

int prim(){
    int mincost, u, sum = 0;
    for (int i = 1; i <= n; i++){
        color[i] = WHITE;
        d[i] = INFTY;
    }
    d[1] = 0;
    p[1] = -1;
    
    while(1){
        mincost = INFTY;
        for (int i = 1; i <= n; i++){ 
            if ( color[i] != BLACK && d[i] < mincost ){
                mincost = d[i];
                u = i;
            }
        }
        
        if ( mincost == INFTY ) break;
        
        color[u] = BLACK;
        
        for (int v = 1; v <= n; v++){
            if ( color[v] != BLACK && M[u][v] != -1 ){
                if ( M[u][v] < d[v] ){
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    
    for (int i = 1; i <= n; i++){
        if ( p[i] != -1 ) sum += M[i][p[i]];
    }
    return sum;
}

int main(){
    cin >> n;
    for (int i = 1; i <= n; i++){ //隣接行列の生成
        for (int j = 1; j <= n; j++){
            cin >> M[i][j];
            M[j][i] = M[i][j];
        }
    }
    
    cout << prim() << endl;
    
    return 0;
}



Measured memory_bytes: 3136
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#define Maxn 1000008 
using namespace std;
typedef long long ll;

int n,cnt,tot;
ll imp;
int U[Maxn],V[Maxn];
ll d;
bool vis[Maxn];
int son[Maxn],head[Maxn];
map <ll,int> M;

struct node{
	int num;
	ll val;
}N[Maxn];

struct edge{
	int to,next;
}E[Maxn];

void adde(int u,int v)
{
	E[tot].to = v;
	E[tot].next = head[u];
	head[u] = tot++;
}

void dfs(int u,ll val)
{
	imp += val,vis[u] = 1;
	for(int i = head[u];~i;i = E[i].next)
	{
		int v = E[i].to;
		if(vis[v]) continue;
		dfs(v,val+1);
	}
}

bool cmp(node a,node b){	return a.val > b.val;}

int main()
{
	memset(vis,0,sizeof(vis));
	memset(head,-1,sizeof(head));
	memset(son,0,sizeof(son));
	scanf("%d",&n);
	for(int i = 1;i <= n;i ++)
	{
		scanf("%lld",&d);
		M[d] = i;
		N[i].num = i,N[i].val = d;
	}
	sort(N+1,N+1+n,cmp);
	map<ll,int>::iterator iter;;
	for(int i = 1;i < n;i ++)
	{
		int u = N[i].num;
		iter = M.find(N[i].val - n + 2 + (son[u] << 1));
		if(iter == M.end())
		{
			printf("-1\n");
			return 0;
		}
		int v = iter->second;
		son[v] += son[u]+1;
		adde(u,v);adde(v,u);
		U[cnt] = u,V[cnt++] = v;
	}
	dfs(N[n].num,0);
	if(N[n].val != imp){	printf("-1\n");return 0;}
	for(int i = 0;i < cnt;i ++) printf("%d %d\n",U[i],V[i]);
	return 0;
}


Measured memory_bytes: 27136
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; i++) {
        if (s.substr(i, s.size() - i) == t.substr(0, s.size() - i)) {
            cout << n + n - s.substr(i, s.size() - i).size() << endl;
            return 0;
        }
    }
    cout << n + n << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
nums = [list(map(int,input().split())) for i in range(N)]

nums.sort(key=lambda x: x[0])

cost = 0
count = M
i = 0
while count > 0:
    if count >= nums[i][1]:
        count -= nums[i][1]
        cost += nums[i][1] * nums[i][0]
        i += 1
    else:
        cost += nums[i][0] * count
        count == 0
        break

print(cost)

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

long long int kansu( long long int x, long long int y ) {

  if ( x < y ) swap( x, y );

  while( y != 0 ) {

    x = x % y;
    swap( x, y );

  }

  return x;

}

int main() {

  long long int input;

  long long int n;

  while( true ) {

    cin >> n;

    if ( n == 0 ) break;

    vector< long long int > x;
    vector< long long int > y;

    for ( int i = 0; i < n * ( n + 1 ) / 2; i++ ) {

      cin >> input;

      if ( input % 2 == 0 ) {

	x.push_back( input );

      }else {

	y.push_back( input );

      }

    }

    sort( x.begin(), x.end() );
    sort( y.begin(), y.end() );

    long long int k = kansu( x[0], y[0] );

    long long int g = (long long int) sqrt( x[0] / k * ( x[1] / ( y[0] / k ) ) );

    cout << g << endl;

    for ( int i = 0; i < n; i++ ) {

      if ( i != 0 ) cout << " ";

      cout << x[i] / g;

    }

    cout << endl;

  }

  return 0;

}

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

int s[10004];
int cnt,n;

void find(int s[], int num) {
	for(int i=0;i<n;i++) {
		if(s[i]==num) {
			cnt++;
			break;
		}
	}
}

int main() {
	cin >> n;
	for (int k=0;k<n;k++) {
		cin >> s[k];
	}
	int q;
	cin >> q;
	while(q--) {
		int nn;
		cin >> nn;
		find(s,nn);
	}
	cout << cnt << endl;
	return 0;
}



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

int main(void){
  int n; cin >> n;
  int h[n];
  int mx = 0;
  rep(i,n){
    cin >> h[i];
    mx = max(mx,h[i]);
  }
  ll ans = 0;
  while(mx != 0){
    for(int i = 0; i < n; i++){
      if(h[i] == mx && i == 0){
        ans++;
      }
      else if(h[i] == mx && h[i-1] != mx){
        ans++;
      }
    }
    for(int i = 0; i < n; i++){
      if(h[i] == mx) h[i]--;
    }
    mx--;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n,k; cin >> n >> k;
  vector<int> s(n,0), d(k);
  for(int i = 0; i < k; i++){
    cin >> d.at(i);
    for(int j = 0; j < d.at(i); j++) {
      int tmp;
      cin >> tmp;
      tmp--;
      s.at(tmp)++;
    }
  }
  int out = 0;
  for(int i = 0; i < n; i++){
    if(s.at(i) == 0) out++;
  }
  cout << out; 
}


Measured memory_bytes: 3600
#include <iostream>
using namespace std;
const int MAX = 105;
const int NIL = -1;

int pre[MAX];
int in[MAX];
int post[MAX];
int pre_i = 0;
int post_i = 0;


int n;

void build_tree(int, int);

int main()
{

	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> pre[i];
	for (int i = 0; i < n; i++)
		cin >> in[i];

	build_tree(0, n);
	for (int i = 0; i < n - 1; i++)
		cout << post[i] << " ";
	cout << post[n - 1] << endl;

// 	cin.get();
// 	cin.get();
	return 0;
}

void build_tree(int l, int r)
{
	if (l >= r)
		return;

	int root = pre[pre_i++];
	int mark = 0;
	for (int i = l; i < r; i++)
	{
		if (in[i] == root)
		{
			mark = i;
			break;
		}
	}

	//post-order
	build_tree(l, mark);
	build_tree(mark + 1, r);
	post[post_i++] = root;

	return;
}

Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

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

		String str[] = br.readLine().split(" ");

		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);

		int gcd = gcd(a, b);

		if (c % gcd == 0) {
			System.out.println("YES");
		} else
			System.out.println("NO");
	}

	static int gcd(int m, int n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}
}

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

using namespace std;

typedef long long llint;

int main() {
  llint s;
  cin >> s;
  const llint MAX = 1e9;
  llint x1 = 0, y1 = 0, x2 = MAX, y2 = 1, x3, y3;
  x3 = (MAX - s % MAX) % MAX;
  y3 = (s + x3) / MAX;
  printf("%lld %lld %lld %lld %lld %lld\n", x1, y1, x2, y2, x3, y3);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a, b, temp, i;
    for(i=1; i<=3000; i++)
  { 
     cin >> a >> b;
    
    
    if(a==0 && b==0)
       break;
    
    
    if(a > b)
    {
    temp = a;
    a = b;
    b = temp;
    }
    
    cout << a << " " << b << endl;
  }
}




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

using namespace std;

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

template <typename T> inline void print(T val) { cout << val << '\n'; }

template <typename Iterator> inline void print(Iterator begin, Iterator end) {
  for (auto it = begin; it != end; it = next(it)) {
    cout << *it << ' ';
  }
  cout << '\n';
}

template <class T> inline T square(T x) {
  T result;
  result = x * x;
  return result;
};

#ifdef LOCAL
#define DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) 0
#endif

const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

  auto start = chrono::steady_clock::now();
#endif

  int n;
  cin >> n;

  vector<int> a(n);

  for (auto &i : a) {
    cin >> i;
  }

  vector<int> dp(n, INF);
  dp[0] = 0;

  for (auto i = 0; i < n; ++i) {
    if (i + 1 < n) {
      dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
    }

    if (i + 2 < n) {
      dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i] - a[i + 2]));
    }
  }

  print(dp.back());

#ifdef LOCAL
  auto end = chrono::steady_clock::now();
  auto diff = end - start;

  cout << "Duration: " << chrono::duration<double, milli>(diff).count() << " ms"
       << '\n';
#endif

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<cinttypes>
#include<algorithm>

using sl = std::int64_t;

struct pos
{
	sl x, y, id_;
	pos() = default;
	pos( sl x, sl y )
		:x{ x }, y{ y }, id_{ x + y * 10'000'000'000 }
	{}

	auto id()const{
		return id_;
	}
	auto operator<( const pos& other )const{
		return this->id() < other.id();
	}

	auto operator-( const pos& other )const{
		return
			pos{ x - other.x, y - other.y };
	}

	friend
		auto operator<<( std::ostream&os, const pos&p )->std::ostream&{
		return os << "(" << p.x << "," << p.y << ")";
	}
};

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

	std::vector<pos> data( n );

	for( auto&e : data )
		std::cin >> e.x >> e.y;

	// vector, c
	std::map<pos, sl> mp;

	for( int i{}; i < n; ++i )
		for( int j{ }; j < n; ++j )
			if(i!=j )
				mp[ data[i] - data[j] ] += 1;

	/*
	for( auto&e : mp )
		std::cout << e.first << " " << e.second << "\n";
	*/

	sl mx{};
	for( const auto&e : mp )
		mx = std::max( e.second, mx );

	std::cout << ( n <= 2 ? sl{ 1 } : n - mx ) << "\n";

	return 0;
}


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

int main()
{
    /* ------- 宣言と入力 ------- */

    string S;

    cin >> S;

    /* ------- 計算 ------- */

    if(S=="AAA"||S=="BBB"){
    cout << "No" << endl;

    }else{
            cout << "Yes"<< endl;

    }
    


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
bool solve(int n, vector<int> & a, vector<vector<int> > & g) {
    vector<int> dp(n);
    auto is_leaf = [&](int i) { return g[i].size() == 1; };
    function<bool (int, int)> go = [&](int i, int parent) {
        if (is_leaf(i)) {
            dp[i] = a[i];
        } else {
            ll sum_dp = 0;
            for (int j : g[i]) if (j != parent) {
                if (not go(j, i)) return false;
                sum_dp += dp[j];
            }
            if (sum_dp < a[i]) return false;
            ll b = sum_dp - a[i];
            ll c = a[i] - b;
            if (b < 0 or c < 0) return false;
            int argmax_dp = *whole(max_element, g[i], [&](int j, int k) { return make_pair(j != i, dp[j]) < make_pair(k != i, dp[k]); });
            ll max_dp = dp[argmax_dp];
            if (max_dp > sum_dp / 2) {
                if (sum_dp - max_dp < b) return false;
            } else {
                if (sum_dp / 2 < b) return false;
            }
            dp[i] = c;
        }
        return true;
    };
    assert (n >= 2);
    if (n == 2) {
        return a[0] == a[1];
    } else {
        int i = 0;
        while (is_leaf(i)) ++ i;
        if (not go(i, -1)) return false;
        return dp[i] == 0;
    }
}
int main() {
    int n; cin >> n;
    vector<int> a(n); repeat (i,n) cin >> a[i];
    vector<vector<int> > g(n);
    repeat (i,n-1) {
        int x, y; cin >> x >> y; -- x; -- y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    cout << (solve(n, a, g) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 14464
n = input()
a = len(n) % 2

b = []
c = []

res = 0

s = n[0:len(n) // 2]
for i in range(len(n) // 2):
  b.append(n[len(n) - i - 1])
  c.append(n[i])

for i, j in zip(b, c):
  if i != j:
    res += 1
print(res)

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

using namespace std;

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

int cell[101], n;
double mem[101][101];

double solve(int k, int t) {
  if (mem[k][t] > -0.5) return mem[k][t];
  if (k == n) return 1;
  if (t <= 0) return 0;
  double res = 0;
  rep (i, 6) {
    int next = k + i + 1;
    if (next > n) next = 2 * n - next;
    if (cell[next] == 2) next = 0;
    res += solve(next, t - 1 - (cell[next] == 1 ? 1 : 0));
  }
  return mem[k][t] = res /= 6;
}

int main() {
  int t, l, b, c;
  while (cin >> n >> t >> l >> b, n) {
    rep (i, n + 1) rep (j, t + 1) mem[i][j] = -1;
    rep (i, n + 1) cell[i] = 0;
    rep (i, l) {
      cin >> c;
      cell[c] = 1;
    }
    rep (i, b) {
      cin >> c;
      cell[c] = 2;
    }
    printf("%.12lf\n", solve(0, t));
  }
  return 0;
}

Measured memory_bytes: 1272
#include<iostream>
using namespace std;
string a="qwertasdfgzxcvb";
main(){
  string in;while(cin>>in && in != "#"){
    int ans=-1,now=-1;
    for(int i=0;i<in.size();i++){
      int next=1;
      for(int j=0;j<a.size();j++)if (a[j] == in[i]){next=0;break;}
      if (now != next)ans++;
      now=next;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # 総和がx以上になる位置のindex をbinary search
    def bsearch(self,x):
        le = 0
        ri = 1<<(self.size.bit_length()-1)
        while ri > 0:
            if le+ri <= self.size and self.tree[le+ri]<x:
                x -= self.tree[le+ri]
                le += ri
            ri >>= 1
        return le+1

n = int(input())
a = [[int(x),i] for i,x in enumerate(input().split())]
a.sort()
bit = BIT(n)

ans = 0

for i in range(n):
    x,ind = a[i]
    s = bit.sum(ind)
    if s == 0:
        l = 0
    else:
        l = bit.bsearch(s)
    s2 = s+1
    if s2 > i:
        r = n
    else:
        r = bit.bsearch(s2)-1
    ans += x*(r-ind)*(ind-l+1)
    bit.add(ind,1)
    
print(ans)

Measured memory_bytes: 110580
import java.util.Arrays;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int[] d = new int[n];

		for (int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}
		Arrays.sort(d);

		System.out.println((d[n / 2]) - (d[n / 2 - 1]));
	}

}

Measured memory_bytes: 50824
import java.util.Scanner;

public class Main {
    static int c0=0;
    static int c1=0;
    static int c2=0;
    static int c3=0;


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

        while(testCases-- >= 0){
            String input = sc.nextLine();

            if(input.equals("AC"))
                c0++;
            else if(input.equals("WA"))
                c1++;
            else if(input.equals("TLE"))
                c2++;
            else if(input.equals("RE"))
                c3++;
        }

        System.out.println("AC x " + c0);
        System.out.println("WA x " + c1);
        System.out.println("TLE x "+ c2);
        System.out.println("RE x "+ c3);
    }
}


Measured memory_bytes: 51336
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 4
#define M 46

int A[N][N]={
  {1,2,3,4},
  {5,6,7,8},
  {9,10,11,12},
  {13,14,15,0}};
  
int P[N*N]={3,0,1,2,
	    3,0,1,2,
	    3,0,1,2,
	    3,0,1,2},Q[N*N]={3,0,0,0,
	    0,1,1,1,
	    1,2,2,2,
	    2,3,3,3};

int min=M;

void res(int X[N][N], int Xj[N][N], int n)
{
  int i,j,i0,j0,d=0,f=0,tmp[N][N];
      
  for(i=0;i<N;i++) {
    for(j=0;j<N;j++) {
      if(A[i][j]!=X[i][j]) f++;
      if(X[i][j]==0) {
    i0=i;
    j0=j;
      }
      else
    d+=abs(j-P[X[i][j]])+abs(i-Q[X[i][j]]);
  
    }
  }
      
  if(f==0) {
    if(min>n) {
      min=n;
    }
    return;
  }
  if(d+n>min) return;
      
      
  if(i0>0 && i0<N) {
    memcpy(tmp,X,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0-1][j0];
    tmp[i0-1][j0]=f;
    if(memcmp(tmp,Xj,sizeof(int)*N*N)!=0)
      res(tmp, X, n+1);
  }
  if(j0>0 && j0<N) {
    memcpy(tmp,X,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0][j0-1];
    tmp[i0][j0-1]=f;
    if(memcmp(tmp,Xj,sizeof(int)*N*N)!=0)
      res(tmp, X, n+1);
  }
      
  if(i0>=0 && i0<N-1) {
    memcpy(tmp,X,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0+1][j0];
    tmp[i0+1][j0]=f;
    if(memcmp(tmp,Xj,sizeof(int)*N*N)!=0)
      res(tmp, X, n+1);
  }
  if(j0>=0 && j0<N-1) {
    memcpy(tmp,X,sizeof(int)*N*N);
    f=tmp[i0][j0];
    tmp[i0][j0]=tmp[i0][j0+1];
    tmp[i0][j0+1]=f;
    if(memcmp(tmp,Xj,sizeof(int)*N*N)!=0)
      res(tmp, X, n+1);
  }
      
}

int main()
{
  int i,j,X[N][N];

  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      scanf("%d",&X[i][j]);
    }
  }
  res(X,X,0);

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




Measured memory_bytes: 2036
class ReRooting:
    """
    0-indexed
    """
    def __init__(self, size, root=0, identDp=1, identCum=1):
        """
        identDp: 木DP用 lift(a, identDp) = a
        identCum: 累積用 merge(a, identCum) = a
        """
        self.size = size
        self.edges = [[] for _ in range(self.size + 1)]
        self.root = root
        self.identDp = identDp
        self.identCum = identCum

    def addEdge(self, fr, to):
        self.edges[fr].append(to)
        self.edges[to].append(fr)

    # 根を固定したときの木DP(貰うDP)
    def lift(self, top, bottom):
        return top * (bottom + 1) % M

    # 親の左右の累積から子を根としたときの値を求める
    def merge(self, left, right):
        return left * right % M

    def sol(self):
        N = self.size
        edges = self.edges

        st = [self.root]
        parent = [-1] * (N + 1)
        child = [[] for _ in range(N + 1)]
        order = []
        while st:
            v = st.pop()
            order.append(v)
            for to in edges[v]:
                if parent[v] == to:
                    continue
                parent[to] = v
                child[v].append(to)
                st.append(to)

        dp = [self.identDp] * (N + 1)
        left = [self.identCum] * (N + 1)
        right = [self.identCum] * (N + 1)
        for v in order[::-1]:  # 貰うDPしつつ，累積をとる
            tmp = self.identCum
            for ch in child[v]:
                left[ch] = tmp
                tmp = self.lift(tmp, dp[ch])
            tmp = self.identCum
            for ch in reversed(child[v]):
                right[ch] = tmp
                tmp = self.lift(tmp, dp[ch])
            dp[v] = tmp

        fromParent = [0] * (N + 1)
        for v in order:
            if v == self.root:
                continue
            fromParent[v] = self.lift(self.merge(left[v], right[v]), fromParent[parent[v]])
            dp[v] = self.lift(dp[v], fromParent[v])  # 最後に親からの貰うDP

        return dp[:N]

N, M = map(int, input().split())
tree = ReRooting(N, 0, 1, 1)

for _ in range(N - 1):
    fr, to = map(int, input().split())
    tree.addEdge(fr - 1, to - 1)

ans = tree.sol()
print(*ans, sep='\n')


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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N+1);
  vector<ll> B(N);
  for (ll &e : A) cin >> e;
  for (ll &e : B) cin >> e;
  
  ll ov = 0;
  ll sum = 0;
  for (ll i = 0; i < N; i++) {
    A[i] = max(A[i] - ov, 0LL);
    if (A[i] >= B[i]) {
      sum += B[i];
      ov = 0;
    }
    if (A[i] < B[i] && B[i] < A[i] + A[i+1]) {
      sum += B[i];
      ov = B[i] - A[i];
    }
    if (B[i] >= A[i] + A[i+1]) {
      sum += A[i] + A[i+1];
      ov = A[i+1];
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define X_MAX 100001

int memo[X_MAX];

bool func(int val)
{
	if (val < 0){
		return false;
	}
	if (0 == val){
		return true;
	}
	if (-1 != memo[val]){
		return false;
	}

	for (int i = 100; i <= 105; i++){
		if (func(val - i)){
			return true;
		}
	}

	memo[val] = 0;
	return false;
}

void solv()
{
	int X; scanf("%d", &X);

	fill(memo, memo + X + 1 , -1);
	if (func(X)){
		printf("1");
	}
	else{
		printf("0");
	}

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i=0 ; i<N ; i++)
    cin >> V.at(i);
  int answer=0;
  for (int i=0 ; i<N ;i++){
    for (int j=i+1 ; j<N ; j++){
    answer+=V.at(i)*V.at(j);
    }
  }
 cout << answer << endl;
}


Measured memory_bytes: 256