akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for(int i = 0; i < (int)c; i++)
const int inf = 1000000000; // 10^9

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    rep(i, N) cin >> X[i];
    int ans = inf;
    for(int i = 1; i <= 100; i++) { // L やR の計算が不要
        int cost = 0;
        rep(j, N) cost += (X[j] - i) * (X[j] - i);
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int n,m; cin>>n>>m;
	vector<string> A(n);
	vector<string> B(m);

	for (int i=0; i<n; i++)
		cin>>A[i];
	for (int i=0; i<m; i++)
		cin>>B[i];

	bool yes=false;
	for (int i=0; i<=n-m; i++) {
		for (int j=0; j<=n-m; j++) {
			bool possible=true;
			for (int k=0; k<m; k++) {
				for (int l=0; l<m; l++) {
					if (A[i+k][j+l] != B[k][l]) {
						possible=false;	
						break;
					}
				}
			}
			if (possible)
				yes=true;
		}
	}

	if (yes) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main() {
	int n;
	cin>>n;
	int cnt=0,a[n];
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	for(int i=0;i<n-2;i++)
	{
	    for(int j=i+1;j<n-1;j++)
	    {
	        if(a[i]!=a[j])
	        {
	        for(int k=j+1;k<n;k++)
	        {
	            if(a[j]!=a[k]&&a[i]!=a[k])
	            {
	            if((a[i]+a[j]>a[k])&& (a[i]+a[k]>a[j])&&(a[j]+a[k]>a[i]))
	            {
	            cnt++;
	            }
	            }
	        }
	        }
	    }
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 3544
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	x := make([]float64, n)
	y := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i], &y[i])
	}

	ans := 0.0
	for i := 0; i < n; i++ {
		sum := 0.0
		for j := 0; j < n; j++ {
			if j == i {
				continue
			}
			sum += math.Sqrt(math.Pow(x[i]-x[j], 2) + math.Pow(y[i]-y[j], 2))
		}
		ans += sum / float64(n)
	}
	fmt.Println(ans)
}


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

void chmax(long long int* former_number,long long int* x) {//xよりもyが大きければ更新
    if (*former_number < *x) { long long int a = *former_number; *former_number = *x; *x = a; } else { /*no action*/ }
}
void chmin(long long int* former_number,long long int* x) {//xよりもyが大きければ更新
    if (*former_number > *x) { long long int a = *former_number; *former_number = *x; *x = a; } else {/* no action */}
}
const int INF = 100000000;
using ll = long long int;
using ul = unsigned long long int;
using vi = vector<int>;
#define all(v) v.begin(),v.end()
#define pb push_back


int main(){
    ll n;
    cin>>n;
    vi v;
    ll m[200000] = {};
    for(int i=0;i<n;i++){cin>>m[i];v.pb(m[i]);}
    sort(all(v));
    int k = v[n/2],l = v[n/2 -1];
    for(int i=0;i<n;i++){
        if(l>=m[i]){
            cout<<k<<endl;
        }else{
            cout<<l<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4724
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int ans = 0;
	int n, p[22];
	int i;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> p[i];
	}

	for (i = 1; i < n - 1; i++) {
		if (p[i - 1] < p[i] && p[i] < p[i + 1]) {
			ans++;
		}
		else if (p[i - 1] > p[i] && p[i] > p[i + 1]) {
			ans++;
		}
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
typedef long long lint;
const int N=1e5+5;
int n,m,val[N],fa[N];
std::vector <int> buk[N];

namespace utils{
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int find_rt(const int x){
	return fa[x]?fa[x]=find_rt(fa[x]):x;
}

int main(){
	n=nxi(),m=nxi();
	for(int i=1; i<=n; ++i){
		val[i]=nxi();
	}
	for(int i=1; i<=m; ++i){
		int x=find_rt(nxi()),y=find_rt(nxi());
		if(x!=y) fa[x]=y;
	}
	for(int i=1; i<=n; ++i){
		buk[find_rt(i)].push_back(i);
	}
	int ans=0;
	for(int i=1; i<=n; ++i){
		static bool vis[N];
		if(buk[i].empty()) continue;
		for(std::vector <int> ::iterator it=buk[i].begin(); it!=buk[i].end(); ++it){
			vis[*it]=1;
		}
		for(std::vector <int> ::iterator it=buk[i].begin(); it!=buk[i].end(); ++it){
			ans+=vis[val[*it]];
		}
		for(std::vector <int> ::iterator it=buk[i].begin(); it!=buk[i].end(); ++it){
			vis[*it]=0;
		}
	}
	printf("%d\n",ans);
	return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N;
char S[10101], mk[30];
ll i, j;
int main(){
    scanf("%lld%s", &N, S);
    fornum(i,0,26){
        mk[i] = 'A' + i;
    }
    for (i = 0; S[i];i++)
    {
        S[i] = mk[((S[i] - 'A') + N) % 26];
    }
    printf("%s", S);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int M,K;

int main(void) {
    cin>>M>>K;

    vector<int> A;

    if(K >=  pow(2,M))
    {
        cout<<-1<<endl;

        return 0;
    }
    if(M == 1 && K == 0) {
        cout<<0<<" "<<0<<" "<<1<<" "<<1<<endl;

        return 0;
    }
    if(M == 1 && K != 0) {
        cout<<-1<<endl;

        return 0;
    }

    for(int i = 0;i < pow(2,M);i++) {
        if(i == K)
            continue;
        A.push_back(i);
    }

    sort(A.begin(),A.end());
    for(int i = 0;i < A.size();i++) {
        cout<<A[i]<<" ";
    }

    cout<<K<<" ";
    sort(A.begin(),A.end(),greater<int>());
    for(int i = 0;i < A.size();i++) {
        cout<<A[i]<<" ";
    }
    cout<<K<<endl;

    return 0;
}


Measured memory_bytes: 2424
#include <iostream>
#include <cmath>
int n;
int a[1000];
int min = 1000000;

int main(){
  while(true){
    std::cin >> n;
    if(n == 0){
      break;
    }
    else{
      for(int i = 0; i < n; i++){
        std::cin >> a[i];
      }
      for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
           if(std::abs(a[i] - a[j]) < min){
             min = std::abs(a[i] - a[j]);
           }
        }
      }
      std::cout << min << std::endl;
      min = 1000000;
    }
  }
  return 0;
}


Measured memory_bytes: 3100
module Input
	def numread()
		s = gets().split()
		p = Array.new()
		for i in 0...s.size()
			p[i] = s[i].to_i()
		end
		return p
	end
	
	module_function:numread
end

include Input

def gcd(x,y)
	w = y % x
	if(w == 0)
		return x
	else
		return gcd(w,x)
	end
end

loop{
	if(STDIN.eof())
		break
	end
	w = numread()
	w.sort!()
	s = gcd(w[0],w[1])
	l = w[0] * w[1] / s
	print(s," ",l,"\n")
}

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

int main() {
  int a;
  cin>>a;
  for(int i=0;i<=a/7;i++){
    if((a-7*i)%4==0){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define mp make_pair;

const ll prime = 1000000000 + 7;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

int main() {

	ll x, y;
	cin >> x >> y;
	ll sum = 0;
	if (x <= 3) {
		sum += 4-x;
	}
	if (y <= 3) {
		sum += 4-y;
	}
	if (x + y == 2) {
		sum += 4;
	}

	cout << sum * 100000 << endl;



	return 0;
}


Measured memory_bytes: 888
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


def solve(S):
    dp = np.zeros(2019, np.int64)
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % 2019
        dp = np.roll(dp, x)
        answer += dp[0]
        pow10 *= 10
        pow10 %= 2019
    return answer


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i4[:],)')(solve)
    cc.compile()


try:
    from my_module import solve
except:
    cc_export()
    exit()

S = np.array(list(read().rstrip()), dtype=np.int32) - ord('0')
print(solve(S))


Measured memory_bytes: 29156
#include<stdio.h>
#define G_MAX 100

int main()
{
  int i,j;
  int n;
  int v,c,c1,v1;
  int G[G_MAX+1][G_MAX+1];
  int color[G_MAX+1],d[G_MAX+1],pi[G_MAX+1];
  int min,ii;
  
  for(i=0;i<G_MAX+1;i++){
    for(j=0;j<G_MAX+1;j++) G[i][j]=-1;
  }
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&c);
    for(j=0;j<c;j++){
      scanf("%d%d",&v1,&c1);
      G[v][v1]=c1;
    }
  }

  for(i=0;i<n;i++){
    color[i]=0;
    pi[i]=-1;
    d[i]=10000001;
  }
  d[0]=0;

  while(1){
    min=10000001;
    for(i=0;i<n;i++){
      if(color[i]!=2 && d[i]<min){
        min=d[i];
        ii=i;
      }
    }
    if(min==10000001)break;
    color[ii]=2;
    for(i=0;i<n;i++){
      if(G[ii][i]!=-1 && color[i]!=2 && (G[ii][i]+d[ii])<d[i]){
	pi[i]=ii;
	d[i]=G[ii][i]+d[ii];
	color[i]=1;
      }
    }
  }
  for(i=0;i<n;i++)
    printf("%d %d\n",i,d[i]);
  return 0;
}



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

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

int main(){
  int n;
  cin>>n;
  rep(i,100){
    rep(j,100){
      if(4*i+7*j==n){
	cout<<"Yes"<<endl;
	return 0;
      }
    }
  }

  cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Point{

	double x,y;
};

Point small,large;

Point roll(Point point,double degree){

	Point ret;
	double rad = degree*(M_PI/180.0);

	ret.x = point.x*cos(rad)-point.y*sin(rad);
	ret.y = point.x*sin(rad)+point.y*cos(rad);

	return ret;
}

int main(){

	int A,B,H,M;
	scanf("%d %d %d %d",&A,&B,&H,&M);

	small.x = 0;
	small.y = A;

	large.x = 0;
	large.y = B;

	double deg_s = 30*H+M/2.0;
	double deg_l = 6.0*M;

	small = roll(small,deg_s);
	large= roll(large,deg_l);

	printf("%.15lf\n",sqrt((small.x-large.x)*(small.x-large.x)+(small.y-large.y)*(small.y-large.y)));

	return 0;
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  string s;
  string ans;
  cin >> s;
  for (auto a : s) {
    if (a == '0')
      ans.push_back('0');
    else if (a == '1')
      ans.push_back('1');
    else {
      if (!ans.empty()) ans.pop_back();
    }
  }
  cout << ans << endl;
}

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


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(10)<<fixed;
	
	int n;
	cin>>n;
	set<string> s;
	string t;
	for(int i=0;i<n;i++)
	{
		cin>>t;
		s.insert(t);
	}
	cout<<s.size()<<endl;
	return 0;
}

Measured memory_bytes: 19288
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

int label_num = 0,N;

enum DIST{
	now_U_next_right,
	now_U_next_hidarishita,
	now_L_next_down,
	now_L_next_migiue,
	now_R_next_down,
	now_R_next_hidarishita,
	now_D_next_right,
	now_D_next_migiue,
	hidarishita_moving,
	migiue_moving,
};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= N-1 && col >= 0 && col <= N-1)return true;
	else{
		return false;
	}
}

void func(){

	if(N <= 2){
		printf("Case %d:\n",label_num);
		if(N == 0){
			printf("  0\n");
		}else if(N == 1){
			printf("  1\n");
		}else if(N == 2){
			printf("  1  2\n  3  4\n");
		}
		return;
	}

	int table[N][N],number = 1,limit,row = 0,col = 0;
	limit = N*N;

	DIST current = now_U_next_right;
	table[0][0] = number;

	number++;

	while(number <= limit){
		switch(current){
		case now_U_next_right:
			if(rangeCheck(row,col+1) == true){
				table[row][col+1] = number;
				col++;
				current = now_U_next_hidarishita;
			}else{
				table[row+1][col] = number;
				row++;
				current = now_R_next_hidarishita;
			}
			break;
		case now_U_next_hidarishita:
			table[row+1][col-1] = number;
			row++;
			col--;
			current = hidarishita_moving;
			break;
		case now_L_next_down:
			if(rangeCheck(row+1,col) == true){
				table[row+1][col] = number;
				row++;
				current = now_L_next_migiue;
			}else{
				table[row][col+1] = number;
				col++;
				current = now_D_next_migiue;
			}
			break;
		case now_L_next_migiue:
			table[row-1][col+1] = number;
			row--;
			col++;
			current = migiue_moving;
			break;
		case now_R_next_down:
			if(rangeCheck(row+1,col)){
				table[row+1][col] = number;
				row++;
				current = now_R_next_hidarishita;
			}else{
				//Do nothing
			}
			break;
		case now_R_next_hidarishita:
			if(rangeCheck(row+1,col-1)){
				table[row+1][col-1] = number;
				row++;
				col--;
				current = hidarishita_moving;
			}else{
				//Do nothing
			}
			break;
		case now_D_next_right:
			if(rangeCheck(row,col+1)){
				table[row][col+1] = number;
				col++;
				current = now_D_next_migiue;
			}else{
				//Do nothing
			}
			break;
		case now_D_next_migiue:
			if(rangeCheck(row-1,col+1)){
				table[row-1][col+1] = number;
				row--;
				col++;
				current = migiue_moving;
			}else{
				//Do nothing;
			}
			break;
		case hidarishita_moving:
			if(rangeCheck(row+1,col-1)){
				table[row+1][col-1] = number;
				row++;
				col--;
			}else{
				number--;
				if(row == N-1){
					current = now_D_next_right;
				}else{
					current = now_L_next_down;
				}
			}
			break;
		case migiue_moving:

			if(rangeCheck(row-1,col+1)){
				table[row-1][col+1] = number;
				row--;
				col++;
			}else{
				number--;
				if(col == N-1){
					current = now_R_next_down;
				}else{
					current = now_U_next_right;
				}
			}
			break;
		}
		number++;
	}

	printf("Case %d:\n",label_num);

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){
			printf("%3d",table[i][k]);
		}
		printf("\n");
	}

}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		label_num++;

		func();

	}

    return 0;
}

Measured memory_bytes: 2584
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define ggr getchar();getchar();return 0
using namespace std;
int n,q;
string s;
char t[200010],d[200010];
bool func(int x,bool b){
	int now=x;
	if(!b){
		rep(i,q){
			if(t[i]==s[now]&&d[i]=='L')now--;
			if(t[i]==s[now]&&d[i]=='R')now++;
			if(now==-1)break;
		}
		if(now==-1)return true;
		return false;
	}
	else{
		rep(i,q){
			if(t[i]==s[now]&&d[i]=='R')now++;
			if(t[i]==s[now]&&d[i]=='L')now--;
			if(now==n)break;
		}
		if(now==n)return true;
		else return false;
	}
}
signed main(){
	cin>>n>>q>>s;
	rep(i,q)cin>>t[i]>>d[i];
	int mi=0,ma=n-1;
	while(ma-mi>1){
		int md=(mi+ma)/2;
		if(func(md,false))mi=md;
		else ma=md;
	}
	int ans;
	if(func(mi,false)){
		if(func(ma,false))mi++;
		ans=mi+1;
	}
	mi=0,ma=n-1;
	while(ma-mi>1){
		int md=(mi+ma)/2;
		if(func(md,true))ma=md;
		else mi=md;
	}
	if(func(ma,true)){
		if(func(mi,true))ma--;
		ans+=n-ma;
	}
	cout<<n-min(n,ans)<<endl;
	ggr;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a)  a.begin(),a.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;

void a(){
    ll x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x<< ' ' << y<< ' ' << z;
}

void b(){
    ll n,m; cin >> n >> m;
    auto a = v<>(n,0);
    rep(i,n) cin >> a[i];
    ll sum = accumulate(all(a),0);
    sort(all(a));
    ll check = ceil((double)sum/(4*m));
    ll ans = n - (lower_bound(all(a),check)-a.begin());
    if(ans>=m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

void c(){

}

void d(){

}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
const int mod=1000000007;
const int INF=1e18;
int a[200005];
map <int,int> mp;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,ans=0;
    cin>>n;
    f(i,0,n)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    for(auto i: mp)
    {
        ans+=(i.ss*(i.ss-1))/2;
    }
    f(i,0,n)
    {
        cout<<ans-(mp[a[i]]-1)<<'\n';
    }
    return 0;
}

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

using namespace std;

int main() {
  int n,x[200];
  cin >> n;
  for(int i = 0; i < n; i++) 
    cin >> x[i];
  
  sort(x,x+n);
  
  int mi = 10000000;
  for(int i = x[0]; i <= x[n-1]; i++) {
    int sum = 0;
    for(int j = 0; j < n; j++) {
      sum += (x[j] - i) * (x[j] - i);
    }
    mi = min(mi, sum);
  }  
  cout << mi << endl;
  return 0;
}

Measured memory_bytes: 3552
import math


a, b = list(map(int, input().split()))

ans = -1

for i in range(0, 1251):
    tax_a = int(i * 0.08)
    tax_b = int(i * 0.1)

    if tax_a == a and tax_b == b:
        ans = i
        break

print(ans)


Measured memory_bytes: 9096
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define INF 100000000
int main(void){
    int n;
    string s;
    cin >> n;
    string ret;
    map<char, int> buf;
    for(char c='a'; c<='z'; c++){
        buf[c] = INF;
    }
    for(int i=0; i<n; i++){
        cin >> s;
        for(char c='a'; c<='z'; c++){
            buf[c] = min(buf[c], int(count(s.begin(), s.end(), c)));
        }
    }
    for(char c='a'; c<='z'; c++){
        for(int i=0; i<buf[c]; i++){
            ret += c;
        }
    }
    cout << ret;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main() {
  int N;
  cin >> N;
  int sum = 0;
  int M = 0;
  rep(i,N){
    int a;
    cin >> a;
    sum += a;
    M = max(M,a);
  }
  bool f=false;
  if(sum - M > M) f = true;
  cans(f);
  return 0;
}










Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int a[4];
int main(){
    int i;
    for(i=0;i<4;i++) cin >> a[i];
    sort(a,a + 4);
    cout << max(a[0] + a[3] - a[1] - a[2],a[1] + a[2] - a[0] - a[3]) << endl;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m; cin >> n >> m;
	vector<int> at(m, -1), cnt(m + 1, 0), stk;
	cnt[0] = n;
	int q; cin >> q;
	vector<int> op(q);
	for(int & v : op) cin >> v;
	reverse(op.begin(), op.end());
	for(int & v : op){
		v--;
		if(at[v] == -1){
			stk.push_back(v);
			at[v] = stk.size();
			cnt[at[v]] = 1;
		} else {
			if(cnt[at[v] - 1] > cnt[at[v]]){
				cnt[at[v]]++;
			}
		}
	}
	int len = stk.size() + 1;
	vector<int> res;
	for(int i = 0, j = 0; i < len; i = j){
		while(j < len && cnt[j] == cnt[i]) j++;
		vector<int> holm;
		for(int k = 1; k < j; k++) holm.push_back(stk[k - 1]);
		for(int k = 0; k < m; k++) if(at[k] == -1 || at[k] >= j) holm.push_back(k);
		if(res.empty()) res = holm;
		else if(res != holm){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3184
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
void pr(vector<int> output,int n, int sum,int m){
  if(sum==n){
    bool f = false;
    REP(i,output.size()){
      if(f) cout<<" ";
      f = true;
      cout<<output[i];
    }
    cout<<endl;
  }
  for(int i=min(n-sum,m); i>0; i--){
    vector<int> tmp;
    tmp = output;
    tmp.push_back(i);
    pr(tmp,n,sum+i,i);
  }
}
int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<int> emp;
    pr(emp,n,0,n);
  }   
  return 0;
}

Measured memory_bytes: 916
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        Pair ur = null; Pair ul = null; Pair ll = null; Pair lr = null;
        long urb = Long.MIN_VALUE; long ulb = Long.MIN_VALUE; long llb = Long.MIN_VALUE; long lrb = Long.MIN_VALUE;
        ArrayList<Pair> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            long x = sc.nextInt();
            long y = sc.nextInt();
            Pair p = new Pair(x, y);
            a.add(p);
            if (x + y > urb) {
                ur = p;
                urb = x + y;
            }
            if (-x + y > ulb) {
                ul = p;
                ulb = -x + y;
            }
            if (x - y > lrb) {
                lr = p;
                lrb = x - y;
            }
            if (-x - y > llb) {
                ll = p;
                llb = -x - y;
            }
        }
        long res = Long.MIN_VALUE;
        for (Pair i: a) {
            res = Math.max(res, dist(i, ll));
            res = Math.max(res, dist(i, lr));
            res = Math.max(res, dist(i, ul));
            res = Math.max(res, dist(i, ur));
        }
        out.println(res);
        out.close();
    }

    static long dist(Pair i, Pair j) {
        return Math.abs(i.x - j.x) + Math.abs(i.y - j.y);
    }

    static class Pair {
        long x; long y;
        Pair(long x, long y) {
            this.x = x; this.y = y;
        }
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


    }

}

Measured memory_bytes: 61724
#include<bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>

#define IO std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);

#define MOD 1000000007
#define ll long long int
#define MAX 100005

using namespace std;

int main() {

    IO

    string a;

    cin >> a;

    if(a[3]==a[2] && a[4]==a[5])
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int x, y;
  cin >> x >> y;

  int a[7] = {1,3,5,7,8,10,12}, b[4] = {4,6,9,11}, c = 2;
  int xg, yg;
  for (size_t i = 0; i < 7; i++) {
    if (x==a[i]) xg = 0;
    if (y==a[i]) yg = 0;
  }
  for (size_t i = 0; i < 4; i++) {
    if (x==b[i]) xg = 1;
    if (y==b[i]) yg = 1;
  }
  if (x==c) xg = 2;
  if (y==c) yg = 2;
  if (xg == yg) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;



int main() {
	while (1) {
		int n; cin >> n;
		int ans=0;
		if (!n)break;

		int amin = -1000000010;
		int amax =  1000000010;
		
		vector<int>nums;
		for (int i = 0; i < n; ++i) {
			string c; cin >> c;
			if (c!="x") {
				nums.push_back(stoi(c));
			}
			else {
				nums.push_back(1000000001);
			}
		}
		for (int i = 0; i < n; ++i) {
			if (nums[i] == 1000000001) {
				if (i != n - 1) {
					if (nums[i + 1] == 1000000001) {
						ans = 1000000001;
						break;
					}
					else {
						if (i % 2) {
							amin = max(amin, nums[i + 1] + 1);
						}
						else {
							amax = min(amax, nums[i + 1] - 1);
						}
					}
				}
				
				if (i) {
					if (nums[i - 1] == 1000000001) {
						ans = 1000000001;
						break;
					}
					else {
						if (i % 2) {
							amin = max(amin, nums[i - 1] + 1);
						}
						else {
							amax = min(amax, nums[i - 1] - 1);
						}
					}
				}
			}
		}
		for (int i = 0; i < n-1; ++i) {
			if (nums[i] != 1000000001 && nums[i + 1] != 1000000001) {
				if (i % 2) {
					if (nums[i] <= nums[i + 1])ans = 1000000001;
				}
				else {

					if (nums[i] >= nums[i + 1])ans = 1000000001;
				}
			}
		}
		if (ans == 1000000001||amax<amin) {
			cout << "none" << endl;
		}
		else if (amax == amin) {
			cout << amax << endl;
		}
		else {
			cout << "ambiguous" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end());
    int num = a.size();
    a.erase(unique(a.begin(), a.end()), a.end());
    if(a.size() == num) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define IOS                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define ll long long
using namespace std;

int maxHappines(vector<vector<int> >& hapiness, int n, int cur, int prev, vector<vector<int>>& dp)
{
    if(cur == n){
        return 0;
    }
    if(dp[cur][prev] != -1){
        // cout << "MIRACLE" << endl;
        return dp[cur][prev];
    }
    int hap1 = INT_MIN, hap2 = INT_MIN, hap3 = INT_MIN;
    if (prev != 1)
    {
        hap1 = hapiness[cur][0] + maxHappines(hapiness, n, cur + 1, 1,dp);
    }
    if(prev != 2){
        hap2 = hapiness[cur][1] + maxHappines(hapiness, n, cur + 1, 2,dp);
    }
    if(prev != 3){
        hap3 = hapiness[cur][2] + maxHappines(hapiness, n, cur + 1, 3,dp);
    }
    dp[cur][prev] = max(hap1, max(hap2,hap3));
    return dp[cur][prev];
}

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> v(n);
    vector<vector<int>> dp(n, vector<int>(4, -1));
    int data;
    for (int i = 0; i < n; i++)
    {
        cin >> data;
        v[i].push_back(data);
        cin >> data;
        v[i].push_back(data);
        cin >> data;
        v[i].push_back(data);
    }

    cout << maxHappines(v, n, 0, 0, dp);
}
int main()
{
    IOS;
    // int t;
    // cin>>t;
    // while(t>0)
    // {
    solve();
    //     t--;
    // }
    return 0;
}

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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

template <typename T> class graph {
public:
    graph(T n): n_(n), adj_(n) {
    }
    void add(T u, T v, T weight) {
        adj_[u].push_back(make_pair(weight, v));
    }
    vector<T> dijkstra(int start) {
        vector<T> d(n_, INF);
        vector<bool> visited(n_, false);
        priority_queue<ptt, vector<ptt>, greater<ptt>> q;
        d[start] = 0;
        q.push(make_pair(0, start));
        while(!q.empty()) {
            auto uw = q.top().first;
            auto u = q.top().second;
            q.pop();
            visited[u] = true;
            if (d[u] < uw) continue;
            for (auto pav : adj_[u]) {
                auto v = pav.second;
                auto w = pav.first;
                if (visited[v]) continue;
                if(d[u] + w < d[v]) {
                    d[v] = d[u] + w;
                    q.push(make_pair(d[v], v));
                }
            }
        }
        return d;
    }
private:
    using ptt = pair<T, T>;
    T n_;
    vector<vector<ptt>> adj_;
};

signed main(){
    ll n, m, s, t;
    cin >> n >> m >> s >> t;
    --s, --t;
    graph<ll> yen(n), snuuk(n);
    rep(i, m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        --u, --v;
        yen.add(u, v, a);
        yen.add(v, u, a);
        snuuk.add(u, v, b);
        snuuk.add(v, u, b);
    }
    auto dyen = yen.dijkstra(s);
    auto dsnuuk = snuuk.dijkstra(t);

    ll maxsnk = 0;
    vector<ll> ans(n);
    dec(i, n-1, -1) {
        ll a = 1e15 - (dyen[i] + dsnuuk[i]);
        maxsnk = max(maxsnk, a);
        ans[i] = maxsnk;
    }
    rep(i, n) {
        cout << ans[i] << nl;
    }
}


Measured memory_bytes: 19012
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main()
{
    FAST_IO;
    int a[6];
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    int last = 0;
    for (int i = 1; i < 5; i++)
        last = a[i]%10 != 0 && a[i]%10 < a[last]%10 ? i : last;

    int ans = a[last];
    for (int i = 0; i < 5; i++) {
        if (i == last) continue;
        if (a[i]%10 != 0)
            ans += a[i] + (10 - a[i]%10);
        else
            ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  int n,m; cin >> n >> m;
  vector<string> a(n),b(m);
  for(int i=0; i<n; ++i) cin >> a.at(i);
  for(int i=0; i<m; ++i) cin >> b.at(i);

  for(int i=0; i<n-m+1; ++i) {
    for(int j=0; j<n-m+1; ++j) {
    //  if(a[i][j]==b[0][0]) {
      if(i+m-1>=n || j+m-1>=n) continue;
        int ok=1;
        bool match = true;
        for(int k=0; k<m; ++k) {
          for(int l=0; l<m; ++l) {
            if(a[i+k][j+l]!=b[k][l]) {
              ok=0; match=false;
            }
          }
        }
        if(ok) drop("Yes");
    }
  }
  cout << "No" << endl;

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3644
N = int(input())
t = []
pos = []
pos.append((0, 0))
t.append(0)
for i in range(N):
    t_i, x_i, y_i = map(int, input().split())
    t.append(t_i)
    pos.append((x_i, y_i))

def isReachable(cur, dst, t):
    dist = abs(cur[0] - dst[0]) + abs(cur[1] - dst[1])
    if dist > t:
        return False
    if dist % 2 != t % 2:
        return False
    return True

reachable = True
for i in range(1, N + 1):
    cur = (pos[i - 1][0], pos[i - 1][1])
    dst = (pos[i][0], pos[i][1])
    t_i = t[i] - t[i - 1]
    if not isReachable(cur, dst, t_i):
        reachable = False
        break

if reachable:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 17400
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      for(int k=0; k<10; k++){
        int num = i * 10001 + j * 1010 + k * 100;
        if(A <= num && num <= B) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  integer :: n, i
  character(1) :: s(100)
  logical :: yellow
  read(*, *) n
  read(*, *) s(1:n)
  yellow = .false.
  do i = 1, n
    if (s(i) == "Y") then
      yellow = .true.
      exit
    end if
  end do
  if (yellow) then
    write(*, "(a)") "Four"
  else
    write(*, "(a)") "Three"
  end if
end program main


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const double pi=acos(-1);
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
//cout << fixed << setprecision(12);
ll n;
cin>>n;
ll a[n]={};
rep(i,n){
cin>>a[i];}
sort(a,a+n);
reverse(a,a+n);
ll k=n;
ll ca=a[0];
if(k%2==0){
for(ll i=1; i<k/2; i++){
ca+=a[i]*2;}
cout << ca << endl;}
else{
for(ll i=1; i<k/2; i++){
ca+=a[i]*2;}
ca+=a[(k-1)/2];
cout << ca << endl;}}

Measured memory_bytes: 5188
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lp(i,n)   for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b) for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define F          first
#define S          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
const ll M  = 1e9+7 ;
//const int N = 111;
const int inf = 1<<30;
const double EPS = 1e-9;
//////////////////////    Hi    ^_^  hack me if you can :P
string ys = "YES\n";
string no = "NO\n" ;

int n, k,q, a, b , c ;
int x, y;
vector < int > v[100100];
map < pair<int,int>, ll > mp;
ll cst[100100];
void dfs(int u,int p, ll tot) {
    cst[u] = tot;
    for(auto x : v[u]) {
        if (x == p ) continue;
        dfs(x,u,tot+mp[{u,x}]);
    }
    return ;
}
int main()
{
    speed;
    cin >> n;
    ff(i,2,n)
    {
        cin >> a >> b >> c;
        v[a].pb(b);
        v[b].pb(a);
        mp[ {a,b}] = c;
        mp[ {b,a}] = c;
    }
    cin >> q >> k;
    dfs(k,-1,0);
    while(q--){
        cin >> x >> y;
        cout << cst[x] + cst[y] <<endl;
    }
    return 0;
}

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

int main(){
    int n, m;
    cin >> n;
    cin >> m;
    int s[m];
    int c[m];
    int num[3] = {-1, -1, -1};
    for(int ii1=0; ii1<m; ii1++){
       cin >> s[ii1];
       cin >> c[ii1];
    }
    for(int ii1=0; ii1<m; ii1++){
        if(s[ii1] == 1){
          if(c[ii1] == 0 && n != 1){
              cout << -1;
              return 0;
          }
        }
        if(num[s[ii1]-1] != -1){
          if(c[ii1] != num[s[ii1]-1]){
            cout << -1;
            return 0;
          }
        }
        num[s[ii1]-1] = c[ii1];
    }
    if( m==0&&n==1 ){
      cout << 0;
      return 0;
    }

    if(num[0] == -1) num[0] = 1;
    for(int ii1=0; ii1<n; ii1++){
        if(num[ii1] == -1)
           num[ii1] = 0;
    }
    for(int ii1=0; ii1<n; ii1++){
            cout << num[ii1];
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

ll f(int n, ll x){
    if(n==0) return 1;
    else{
        if(x>=pow(2, n+1)) return pow(2,n)+f(n-1, x-pow(2, n+1)+1);
        if(x==pow(2, n+1)-1) return f(n-1,x-2)+1;
        if(x==1) return 0;
        else return f(n-1,x-1);
    }
}

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

    int N;
    ll X;
    cin>> N>>X;
    cout << f(N,X)<<"\n";
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
map <string,int> cost;
multimap <string,string>  rule;
set <string> his;

void update(string a){
  multimap<string,string>::iterator it=rule.find(a);
  while(it != rule.end() && it->first == a) {
    if(cost[it->second]>cost[a])cost[it->second]=cost[a], update(it->second);
    it++;
  }
}
int mk_rule(string a){
  if(his.count(a) == 0){
    his.insert(a);    
    multimap<string,string>::iterator it=rule.find(a);
    while(it != rule.end() && it->first == a) cost[a]= min(cost[a],mk_rule(it->second)),it++;
    //    update(a);
  }
  return cost[a];
}

int main(){
  int n,m,b;
  cin >> n;
  string a,c,ls[5002];
  for(int i=0;i<n;i++) cin >> ls[i] >> b, cost[ls[i]] = b;
  
  cin >> m;
  for(int i=0;i<m;i++){
    cin >> a >> c;
    rule.insert(pair<string,string>(a,c));
    rule.insert(pair<string,string>(c,a));
  }
  int ans=0;
  for(int i=0;i<n;i++)his.clear(), ans += mk_rule(ls[i]);
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 2004
from heapq import*
N,M,*t=map(int,open(0).read().split())
v=[[]for _ in'_'*M]
z=i=0
for a in t[::2]:a>M or v[a-1].append(t[i+1]);i+=2
q=[0]*M
for i in v:
	for j in i:heappush(q,-j)
	z-=heappop(q)
print(z)

Measured memory_bytes: 25124
def min_dist(i, j, X, Y):
    return min(abs(j-i), abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j))

N, X, Y = list(map(int, input().split()))
dists = [min_dist(i, j, X, Y) for i in range(N-1) for j in range(i+1, N)]
dist_dic = { i: 0 for i in range(1,N)}
for dist in dists:
    dist_dic[dist] += 1
for K in range(1,N):
    print(dist_dic[K])

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

typedef struct {
	double x;
	double y;
}vector;

bool ex_product(double x0,double y0,double x1,double y1,double xp,double yp ){
	vector a={x1-x0,y1-y0};
	vector b={xp-x0,yp-y0};

	return (a.x*b.y-a.y*b.x)>=0;
}

int main(int argc, char *argv[]){
    
	double x1,y1,x2,y2,x3,y3,xp,yp;
	while(cin >> x1>>y1>>x2>>y2>>x3>>y3>>xp>>yp){
	
		bool a=ex_product(x1,y1,x2,y2,xp,yp); 
		bool b= ex_product(x2,y2,x3,y3,xp,yp) ;
		bool c=ex_product(x3,y3,x1,y1,xp,yp) ;
	
		if((a && b && c) || ((!a) && (!b) && (!c)))cout <<"YES"<<endl;
		else cout <<"NO"<<endl;
	}
	
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

string s;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -Wall #-}

import Control.Monad
import Data.Array

readInt :: String -> Int
readInt = read

calcDp :: Int -> Array Int Int -> Array Int Int -> Array (Int,Int) Int
calcDp n hs ws = dp
    where
        dp = array ((0,0),(n-1,n-1)) $ concat $ map gen [1..n]
        gen 1 = [((i,i),0) | i<-[0..n-1]]
        gen k = [((i,i+k-1),f i k) | i<-[0..n-k]]
        f i k = minimum $ [g i k l | l<-[1..k-1]]
        g i k l = h1*w2*w1 + dp!(i,i+l-1) + dp!(i+l,i+k-1)
            where
                h1 = hs!i
                w1 = ws!(i+l-1)
                w2 = ws!(i+k-1)

main :: IO ()
main = do
    n  <- fmap readInt getLine
    ms <- replicateM n $ do
        [h,w] <- fmap (map readInt . words) getLine
        return (h,w)
    let (hs,ws) = (listArray (0,n-1) $ map fst ms, listArray (0,n-1) $ map snd ms)

    let dp  = calcDp n hs ws
    let ans = dp!(0,n-1)

    print $ ans



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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int priority;
    double value;
}data;

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    long N,M;
    scanf("%ld%ld",&N,&M);

    long ans;
    if(N==1){
        if(M==1) ans=1;
        else ans=M-2;
    }
    else if(N==2) ans=0;
    else{
        if(M==1) ans=N-2;
        else ans=(N-2)*(M-2);
    }
    printf("%ld\n",ans);

    return 0;
}

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

int main(){
  int A, B, C, X, Y;
  cin>>A>>B>>C>>X>>Y;

  // AとBのみ or  ABをmaxまでかで比較すればOK
  int ans = X*A + Y*B;
  if(X>Y){
    ans = min(ans, Y*2*C + (X-Y) * A);
    ans = min(ans,X*2*C);
  }
  else{
    ans = min(ans, X*2*C + (Y-X)*B);
    ans = min(ans,Y*2*C);
  }
  cout<<ans<<endl;

}


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

int main() {
  int n;
  cin >> n;
  
  int i, ans = 0, mxm = 0;
  vector<int> p(n);
  for(i = 0; i < n; i++){
    cin >> p.at(i);
    ans += p.at(i);
    mxm = max(mxm, p.at(i));
  }
  
  cout << ans - mxm / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

long long GCD(long long a, long long b) {
    return b != 0 ? GCD(b, a % b) : a;
}

long long lmax(long long a, long long b) {
    if (a > b) return a;
    else return b;
}

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    if (N == 2) {
        cout << lmax(A[0], A[1]) << endl;
    }
    else {
        vector<ll> L(N, 0), R(N, 0);
        rep(i, N - 1) {
            L[i + 1] = GCD(L[i], A[i]);
            R[i + 1] = GCD(R[i], A[N - 1 - i]);
        }
        vector<ll> M(N);

        ll ans = 1;

        rep(i, N) {
            M[i] = GCD(L[i], R[N - 1 - i]);
            ans = lmax(ans, M[i]);
        }

        cout << ans << endl;
    }

}


Measured memory_bytes: 3456
s = input()
n = len(s)
s1 = s[0:len(s)//2]
s2 = s[len(s)//2+1:len(s)]

def reverse(s): 
    return s[::-1]

def isPalindrome(s): 
    rev = reverse(s) 
  
    if (s == rev): 
        return True
    return False

if isPalindrome(s):
    if n % 2 == 0:
        print("No")
    elif isPalindrome(s1) and isPalindrome(s2):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t r, d, x;
    cin >> r >> d >> x;
    for(int i=0; i<10; i++){
        x = r * x - d;
        cout << x << endl;
    }
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  int A,Z,X;
  cin>>A>>Z>>X;
  if(A+Z>=X) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int K = sc.nextInt();
      String S = sc.next();
      
      // 切り出し
      String result = "";
      int len = S.length();
      if(len <= K){
        result = S;
      }else{
        result = S.substring(0,K) + "...";
      }
      
      // 出力
      System.out.println(result);
    }
    
}

Measured memory_bytes: 38708