akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
using namespace std;
int P=1000000007;
int main(){
	int n, k;
	long long int res=1;
	cin >> n >> k;
	vector<long long int> posi, nega;
	for(int i=0;i<n;++i)
	{
		int a;
		cin >> a;
		if(a>=0) posi.push_back(a);
		else nega.push_back(a);
	}
	sort(posi.begin(), posi.end(), greater<long long int>());
	sort(nega.begin(), nega.end());
	int ip=0, in=0, np=posi.size(), nn=nega.size();
	if(np==0 && k%2) {
		for(int i=nn-1;i>nn-k;i-=2)
		{
//			cout << nega[i] * nega[i-1] << '\n';
			res = ((nega[i] * nega[i-1]) % P * res)%P;
		}
		res = (res * (nega[nn-k] + P))%P;
		cout << res;
		return 0;
	}
	if(k==n)
	{
		for(int i=0;i<np;++i) res= (res*posi[i])%P;
		for(int i=0;i<nn;++i) res= (res*(nega[i]+P))%P;
		cout << res;
		return 0;
	}
	while(k>1)
	{
		long long int pv=0, nv=0;
		if(ip+2 < np || (ip+2==np && k%2==0))
			pv = posi[ip] * posi[ip+1];
		if(in+1 < nn) {
			nv = nega[in] * nega[in+1];
		}
		if(pv > nv)
		{
			res = (res * (pv%P))%P;
			ip+=2;
		}
		else
		{
			res = (res * (nv%P))%P;
			in+=2;
		}
//		printf("k=%d, pv=%d, nv=%d, res=%d\n", k, int(pv), int(nv), int(res));
		k-=2;
	}
	if(k==1) res = (res * posi[ip]) % P;
	cout << res;
	return 0;
}

Measured memory_bytes: 5384
import sys
input = sys.stdin.readline


N, M = map(int,input().split())
X = list(map(int, input().split()))
X.sort()
dis = []
for i in range(1,M):
    dis.append(X[i]-X[i-1])
dis.sort()
ans = 0
if M-N>=0:
    ans=sum(dis[:M-N])
print(ans)

Measured memory_bytes: 13188
#include <bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
long long n,m;
long long a[200005];
bool cmp(int x,int y)
{
	return abs(x)<abs(y);
 } 
 int main()
 {
 	int pn=0,nn=0;
 	cin>>n>>m;
 	for(int i=1;i<=n;i++)
 	{
 		cin>>a[i];
 		if(a[i]>=0)
 			pn++;
 		else 
 			nn++;
	 }
	 int l=1,r=n;
	 long long ans=1;
	 if(!pn&&m%2==1)
	 {
	 	sort(a+1,a+1+n,cmp);
	 	for(int i=1;i<=m;i++)
	 		ans=a[i]*ans%mod;
	 }
	 else 
	 {
	 	sort(a+1,a+1+n,greater< int >());
	 	while(m)
	 	{
	 		if(m%2==1)
	 		{
	 			ans=ans*a[l]%mod;
	 			l++;
	 			m--;
			 }
			 else 
			 {
			 	if(a[l]*a[l+1]>=a[r]*a[r-1])
			 	{
			 		ans=ans*a[l]%mod*a[l+1]%mod;
			 		l+=2;
			 		m-=2;
				 }
				 else 
				{
					ans=ans*a[r]%mod*a[r-1]%mod;
					r-=2;
					m-=2;
				}
			 }
		 }
	 }
	cout << (ans % mod + mod) % mod << endl;
 }

Measured memory_bytes: 5156
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        String a = scanner.next();
        String b = scanner.next();
        System.out.println(a.charAt(0) == b.charAt(2) && a.charAt(1) == b.charAt(1) && a.charAt(2) == b.charAt(0) ? "YES" : "NO");
    }
}

Measured memory_bytes: 23764
/*
                                                                                                                                               
8b        d8                           888888888888                                             88b           d88                  ad88888ba   
 Y8,    ,8P                                 88                                        ,d        888b         d888                 d8"     "8b  
  Y8,  ,8P                                  88                                        88        88`8b       d8'88                 ""      a8P  
   "8aa8"  ,adPPYba,   88       88          88  8b,dPPYba,  88       88  ,adPPYba,  MM88MMM     88 `8b     d8' 88   ,adPPYba,          ,a8P"   
    `88'  a8"     "8a  88       88          88  88P'   "Y8  88       88  I8[    ""    88        88  `8b   d8'  88  a8P_____88         d8"      
     88   8b       d8  88       88          88  88          88       88   `"Y8ba,     88        88   `8b d8'   88  8PP"""""""         ""       
     88   "8a,   ,a8"  "8a,   ,a88          88  88          "8a,   ,a88  aa    ]8I    88,       88    `888'    88  "8b,   ,aa         aa       
     88    `"YbbdP"'    `"YbbdP'Y8          88  88           `"YbbdP'Y8  `"YbbdP"'    "Y888     88     `8'     88   `"Ybbd8"'         88       
                                                                                                                                               
*/
#include <bits/stdc++.h>
using namespace std;

int n, a[25];

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

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

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

	int ans = 0;
	for (int i = 1; i < n - 1; i++) if ((a[i - 1] < a[i] && a[i] < a[i + 1]) || (a[i - 1] > a[i] && a[i] > a[i + 1])) ans++;

	cout << ans << '\n';

	return 0;
} 

Measured memory_bytes: 256
/*
Read the question and constraints carefully .Take pen and paper and start solving.
write it down
*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define pi acos(-1.0)/*
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second*/
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{

    int n,i,j,o,c,tot=0,k;

    cin>>n;

    string s;
    pair<int,string> p[n];

    rep(i,0,n)
    {
        cin>>s;
        p[i].second = s;

        tot += s.size();

        for(j=o=c=0;j<s.size();++j)
        {
            if(s[j]=='(')
                ++o;
            else
                ++c;
        }

        
        if(o==0)
            p[i].first = INT_MIN;
        else if(c==0)
            p[i].first = INT_MAX;
        else if(o>c)
            p[i].first = INT_MAX-c;
        else if(o<c)
            p[i].first = INT_MIN+o;
        else
            p[i].first = 0;



    }

    sort(p,p+n,greater<pair<int,string>>());

     string ans(tot,'a');



    k=0;
    for(i=0;i<n;++i)
    {
        s = p[i].second;

        for(j=0;j<s.size();++j,++k)
        {
            ans[k] = s[j];
        }
    }


    //cout<<ans<<"\n";

    for(i=o=c=0;i<tot;++i)
    {
        if(ans[i]=='(')
            ++o;
        else
            --o;

        if(o<0)
        {
            cout<<"No";
            return 0;
        }
    }


    if(o==0)
        cout<<"Yes";
    else
        cout<<"No";


    return 0;
}

Measured memory_bytes: 43320
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

vector<char> solve(int n,int A, int B, int C, vector<string> &op){
	int a[3]= {A,B,C};
	int zcnt = 0;
	rep(i,0,3)zcnt += a[i] == 0;
	vector<char> res;

	if(A + B + C == 1){
		rep(i,0,n){
			string s = op[i];
			int i1 = s[0] - 'A';
			int i2 = s[1] - 'A';
			if(a[i1] < a[i2]){
				res.push_back(s[0]);
				++a[i1];
				--a[i2];
				if(a[i2] < 0)return vector<char>();
			}
			else{
				res.push_back(s[1]);
				++a[i2];
				--a[i1];
				if(a[i1] < 0)return vector<char>();
			}
		}
		return res;
	}

	if(zcnt == 3){
		return res;
	}
	else if(zcnt == 2){
		string s = op[0];
		int i1 = s[0] - 'A';
		int i2 = s[1] - 'A';
		if(a[i1] < a[i2]){
			res.push_back(s[0]);
			++a[i1];
			--a[i2];
			if(a[i2] < 0)return vector<char>();
		}
		else{
			res.push_back(s[1]);
			++a[i2];
			--a[i1];
			if(a[i1] < 0)return vector<char>();
		}
		op.erase(op.begin());
		vector<char> temp = solve(n-1,a[0],a[1],a[2], op);
		res.insert(res.end(), all(temp));
		return res;
	}
	else if(zcnt == 1){
		int nxtind = -1;
		char c;
		int pref = 0;
		rep(i,0,3)if(a[i]==0)c = i + 'A';
		rep(i,0,n){
			string s = op[i];
			if(nxtind == -1 && s.find(c) != -1){
				pref = (c == s[0]?s[1]-'A':s[0]-'A');
				nxtind = i;	
			}
		}
		rep(i,0,n){
			string s = op[i];
			int i1 = s[0] - 'A';
			int i2 = s[1] - 'A';
			if(a[i1] < a[i2] || (a[i2] == a[i1] && i1 == pref)){
				res.push_back(s[0]);
				++a[i1];
				--a[i2];
			}
			else{
				res.push_back(s[1]);
				++a[i2];
				--a[i1];
			}
			if(nxtind == i){
				rep(i,0,3)if(a[i]==0)c = i + 'A';
				rep(i,nxtind+1,n){
					string s = op[i];
					if(s.find(c) != -1){
						pref = (c == s[0]?s[1]-'A':s[0]-'A');
						nxtind = i;	
						break;
					}
				}
			}
		}
		return res;
	}
	else{
		rep(i,0,n){
			string s = op[i];
			int i1 = s[0] - 'A';
			int i2 = s[1] - 'A';
			if(a[i1] < a[i2]){
				res.push_back(s[0]);
				++a[i1];
				--a[i2];
			}
			else{
				res.push_back(s[1]);
				++a[i2];
				--a[i1];
			}
		}
		return res;
	}
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,a,b,c;
	cin >> n >> a >> b >> c; 
	vector<string> op(n);
	rep(i,0,n)cin >> op[i];
	auto ans = solve(n,a,b,c,op);
	if(ans.size()){
		cout << "Yes" << '\n';
		for(char c:ans){
			cout << c << '\n';
		}
	}
	else{
		cout << "No\n";
	}
}


Measured memory_bytes: 6732
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0){
				break;
			}
			int[] s=new int[n];
			for(int i=0;i<n;i++){
				s[i]=sc.nextInt();
			}
			int[] answer=calc(s,0);
			System.out.println(answer[answer.length-1]);
			for(int i=0;i<n-1;i++){
				System.out.print(answer[i]+" ");
			}
			System.out.println(answer[answer.length-2]);
		}
	}
	static int[] calc(int[] s,int count){
		int[] check=new int[s.length];
		for(int i=0;i<check.length;i++){
			for(int j=0;j<check.length;j++){
				if(s[i]==s[j]){
					check[i]++;
				}
			}
		}
		boolean flag=true;
		for(int i=0;i<check.length;i++){
			if(s[i]!=check[i]){
				flag=false;
				break;
			}
		}
		if(flag){
			int[] answer=new int[check.length+1];
			for(int i=0;i<answer.length-1;i++){
				answer[i]=check[i];
			}
			answer[answer.length-1]=count;
			return answer;
		}else{
			return calc(check,count+1);
		}
	}
}

Measured memory_bytes: 23528
n,m = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
arr = Array.new(n)
mod = Hash.new(0)
arr[0] = a[0] % m
mod[arr[0]] += 1
for i in 1..n-1
  arr[i] = arr[i-1] + a[i]
  arr[i] %= m
  mod[arr[i]] += 1
end
cnt = 0
mod.each do |k,v|
  if k==0
    cnt += (v+1)*v/2
  else
    cnt += v*(v-1)/2
  end
end
puts cnt

Measured memory_bytes: 23872
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define int long long
#define endl "\n";
using namespace std;

void solve(){
	int n;
	cin >> n;
	if (n % 10 == 3) cout << "bon";
	else if (n % 10 == 0 or n % 10 == 1 or n % 10 == 6 or n % 10 == 8)cout << "pon";
	else cout << "hon";
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(15);
	int t = 1;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll long long
#define N 100009
#define M 200009
using namespace std;

int n,m,sz,eg,tot,num[3],fst[N],pnt[M],len[M],nxt[M],vis[N];
bool flag;
void add(int x,int y,int z){
	pnt[++tot]=y; len[tot]=z; nxt[tot]=fst[x]; fst[x]=tot;
}
void dfs(int x,int t){
	if (vis[x]!=-1){
		if (vis[x]!=t) flag=1;
		return;
	}
	sz++; vis[x]=t; num[t]++;
	int i,y;
	for (i=fst[x]; i; i=nxt[i]){
		y=pnt[i];
		if (len[i]==1) eg++;
		dfs(y,(t+len[i])%3);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	int i,x,y;
	for (i=1; i<=m; i++){
		scanf("%d%d",&x,&y);
		add(x,y,1); add(y,x,2);
	}
	memset(vis,-1,sizeof(vis));
	ll ans=0;
	for (i=1; i<=n; i++) if (vis[i]==-1){
		sz=eg=0; flag=0;
		memset(num,0,sizeof(num));
		dfs(i,0);
		if (flag) ans+=(ll)sz*sz; else
		if (!num[0] || !num[1] || !num[2]) ans+=eg; else
		ans+=(ll)num[0]*num[1]+(ll)num[1]*num[2]+(ll)num[2]*num[0];
	}
	printf("%lld\n",ans);
	return 0;
}


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

int sg(int x , int y) {
	if(x < y) return 0;
	if(x % y == 0) return x / y;
	int tmp = (x - x / y * y) / (x / y + 1);
	if(tmp) return sg(x - tmp * (x / y + 1), y);
	else return sg(x - x / y - 1 , y);
}

const int N = 1111111;

int n , A[N] , K[N];

main(void) {
	cin >> n;
	int a , b;
	int ans = 0;
	for(int i = 1;i <= n;++ i) {
		cin >> a >> b;
		ans = ans ^ sg(a , b);
	}
	if(!ans) {
		puts("Aoki");
	}
	else puts("Takahashi");
}

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


int main() 
{

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);


    string s; cin >> s;
    // cout << s;

    if (s[0] == s[1] || (s[1] == s[2]) || (s[2] == s[3])) puts("Bad");

    else puts("Good");
    

}

Measured memory_bytes: 3620
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int N;
int A[200010];
long B[200010];

long calc(int b) {

	long res = 0;
	for (int i = 0; i < N; i++) {
		res += abs(A[i] - (b + i+1));
	}

	return res;
}

int main() {
	
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[i] = A[i] - (i+1);
	}

	sort(B, B + N, greater<>());

	int b = N % 2 == 0 ? (B[N / 2] + B[N / 2 - 1])/ 2 : B[N / 2];
	long res[3] = {calc(b), calc(b+1), calc(b-1)};

	cout << min(min(res[0], res[1]), res[2]) << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  long long sum = 0;
  for (int i = 0; i < N; i++) 
  {
    long long A;
    cin >> A;
    sum += A;
    a.at(i) = A;
  }
  
  long long sum0 = 0;
  long long ans = INF;
  for (int i = 0; i < N - 1; i++)
  {
    sum0 += a.at(i);
    chmin(ans, abs(sum0 - (sum - sum0)));
  }
  
  cout << ans << endl;
}

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

int main() {
	int n,m;
	cin>>n;//>>m;
	int x[n], y[n];
	for(int i=0;i<n;++i)
	cin>>x[i];//>>y[i];
	/*string s;
	cin>>s;*/
	int p=0, ne=0;
	for(int i=0;i<n;++i) {
		if(x[i]>0) {
			p++;
		} else if(x[i]<0) {
			ne++;
		}
	}
	sort(x, x+n);
	int sum = 0;
	if(p == 0) {
		for(int i=0;i<n-1;++i) {
			sum += abs(x[i]);
		}
		sum += x[n-1];
		cout<<sum<<"\n";
		int c = x[n-1];
		for(int i=n-2;i>=0;--i) {
			cout<<c<<" "<<x[i]<<"\n";
			c = c-x[i];
		}
	} else if(p==1) {
		for(int i=0;i<n;++i) {
			sum += abs(x[i]);
		}
		cout<<sum<<"\n";
		int c = x[n-1];
		for(int i=n-2;i>=0;--i) {
			cout<<c<<" "<<x[i]<<"\n";
			c -= x[i];
		}
	} else {
		if(ne == 0) {
			for(int i=1;i<n;++i) {
				sum += abs(x[i]);
			}
			sum -= x[0];
			cout<<sum<<"\n";
			int c = x[0];
			for(int i=1;i<n-1;++i) {
				cout<<c<<" "<<x[i]<<"\n";
				c -= x[i];
			}
			cout<<x[n-1]<<" "<<c;
		} else if(ne==1) {
			for(int i=0;i<n;++i) {
				sum += abs(x[i]);
			}
			cout<<sum<<"\n";
			int c = x[0];
			for(int i=1;i<n-1;++i) {
				cout<<c<<" "<<x[i]<<"\n";
				c -= x[i];
			}
			cout<<x[n-1]<<" "<<c<<"\n";
		} else {
			for(int i=0;i<n;++i)
			sum += abs(x[i]);
			cout<<sum<<"\n";
			int c = x[0], play;
			for(int i=0;i<n;++i)
			if(x[i] > 0) {
				play = i;
				break;
			}
			for(int i=play;i<n-1;++i) {
				cout<<c<<" "<<x[i]<<"\n";
				c -= x[i];
			}
			cout<<x[n-1]<<" "<<c<<"\n";
			c = x[n-1]-c;
			for(int i=1;i<play;++i) {
				cout<<c<<" "<<x[i]<<"\n";
				c -= x[i];
			}
		}
	}
	return 0;
}

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

typedef long long ll;
#define pii pair<ll ,ll>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

ll x , y , a , b , c , k;
ll p[MAXX];
ll q[MAXX];
ll r[MAXX];

int main()
{
    _FastIO;
    cin >> x >> y >> a >> b >> c;
    for(ll i = 0; i < a; i++){
        cin >> p[i];
    }
    for(ll i = 0; i < b; i++){
        cin >> q[i];
    }
    for(ll i = 0; i < c; i++){
        cin >> r[i];
    }
    sort(p , p + a);
    sort(q , q + b);
    sort(r , r + c);
    reverse(p , p + a);
    reverse(q , q + b);
    reverse(r , r + c);
    ll ans = 0;
    multiset<ll> ms;
    for(ll i = 0; i < x; i++){
        ms.insert(p[i]);
    }
    for(ll i = 0; i < y; i++){
        ms.insert(q[i]);
    }
    for(ll i = 0; i < c; i++){
        if(*(ms.begin()) > r[i])
            break;
        ms.insert(r[i]);
        ms.erase(ms.begin());
    }
    for(ll i : ms){
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


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

const int M = 1e9+7;

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

    int n , k;
    cin >> n;
    k = n/2;
    int a[n+1];
    for(int i = 1; i <= n; i++) cin >> a[i];
    int dp[n+1][2];
    dp[1][0] = dp[0][0] = dp[0][1] = 0;
    dp[1][1] = a[1];
    for(int i = 2; i <= n; i++) {
        if(i & 1) {
            dp[i][0] = max(a[i] + dp[i-2][0] , max(a[i] + dp[i-3][0] , dp[i-1][0]));
            dp[i][1] = a[i] + dp[i-2][1];
        }
        else {
            dp[i][0] = max(a[i] + dp[i-2][0] , dp[i-1][1]);
        }
    }
    cout << dp[n][0] << "\n";

    return 0;
}


Measured memory_bytes: 8284
l = [int(input()) for _ in range(4)]
ans = 0
for i in range(l[0] + 1):
  for j in range(l[1] + 1):
    for k in range(l[2] + 1):
      if 500 * i + 100 * j + 50 * k == l[3]:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, N, damage = 0;
  cin >> H >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++)
    cin >> A.at(i);
  for (int i=0; i<N; i++){
    damage += A.at(i);
  }
  if (damage >= H)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>

const double PI = acos(-1.0);

struct Point
{
    double x;
    double y;
};

void Koch(int n,Point a,Point b)
{
    if(n==0) return;
        Point s,t,u;
        double th=PI*60.0/180.0;

        s.x=(2.0*a.x+1.0*b.x)/3.0;
        s.y=(2.0*a.y+1.0*b.y)/3.0;
        t.x=(1.0*a.x+2.0*b.x)/3.0;
        t.y=(1.0*a.y+2.0*b.y)/3.0;
        u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
        u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

        Koch(n-1,a,s);
        printf("%.8f %.8f\n",s.x,s.y);
        Koch(n-1,s,u);
        printf("%.8f %.8f\n",u.x,u.y);
        Koch(n-1,u,t);
        printf("%.8f %.8f\n",t.x,t.y);
        Koch(n-1,t,b);
}

using namespace std;

int main()
{
    Point a,b;
    int n;

    scanf("%d",&n);
    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;

    printf("%.8f %.8f\n",a.x,a.y);
    Koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
    return 0;
}



Measured memory_bytes: 3184
/*
luogu AT4809
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define mid (l+r>>1)

int n,q;
int ee,h[100005],nex[100005<<1],to[100005<<1],val[100005<<1],col[100005<<1];
int dis[100005],v[100005],c[100005];
int dfn,mark[100005],fa[100005],son[100005],dep[100005],top[100005],siz[100005];
int cnt,root[100005];
struct segtree{
	int l,r;
	int num,sum;
	void init()
	{
		num = sum = 0;
	}
	segtree operator + (segtree b)
	{
		segtree res;
		res.num = num+b.num;
		res.sum = sum+b.sum;
		return res;
	}
}dat[100005<<5];

void addedge(int x,int y,int z,int w)
{
	nex[++ee] = h[x];
	to[ee] = y;
	val[ee] = z;
	col[ee] = w;
	h[x] = ee;
}

void dfs1(int x,int pre)
{
	siz[x] = 1;
	fa[x] = pre;
	dep[x] = dep[pre]+1;
	for(int i=h[x];i;i=nex[i])
		if(to[i]!=pre)
		{
			v[to[i]] = val[i], c[to[i]] = col[i];
			dis[to[i]] = dis[x]+val[i];
			dfs1(to[i],x);
			if(siz[to[i]]>siz[son[x]])
				son[x] = to[i];
			siz[x] += siz[to[i]];
		}
}

void dfs2(int x,int tp)
{
	mark[x] = ++dfn;
	top[x] = tp;
	if(!son[x])
		return;
	dfs2(son[x],tp);
	for(int i=h[x];i;i=nex[i])
		if(to[i]!=fa[x] && to[i]!=son[x])
			dfs2(to[i],to[i]);
}

void modify(int &o,int l,int r,int x,int v)
{
	if(!o)
		o = ++cnt;
	dat[o].num++;
	dat[o].sum += v;
	if(l==x && r==x)
		return;
	if(x<=mid)
		modify(dat[o].l,l,mid,x,v);
	else
		modify(dat[o].r,mid+1,r,x,v);
}

segtree query(int o,int l,int r,int ql,int qr)
{
	if(l>=ql && r<=qr)
		return dat[o];
	segtree res;
	res.init();
	if(ql<=mid)
		res = res+query(dat[o].l,l,mid,ql,qr);
	if(qr>mid)
		res = res+query(dat[o].r,mid+1,r,ql,qr);
	return res;
}

int query_(int c,int x,int y,int d)
{
	int l=dis[x]+dis[y];
	segtree res;
	res.init();
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
			swap(x,y);
		res = res+query(root[c],1,n,mark[top[x]],mark[x]);
		x = fa[top[x]];
	}
	if(dep[x]<dep[y])
		swap(x,y);
	if(x!=y)
		res = res+query(root[c],1,n,mark[y]+1,mark[x]);
	return l-2*dis[y]-res.sum+res.num*d;
}

signed main()
{
	cin>>n>>q;
	for(int i=1,x,y,z,w;i<n&&scanf("%lld %lld %lld %lld",&x,&y,&z,&w);i++)
		addedge(x,y,w,z), addedge(y,x,w,z);
	dfs1(1,0), dfs2(1,1);
	for(int i=2;i<=n;i++)
		modify(root[c[i]],1,n,mark[i],v[i]);
	while(q--)
	{
		int c,d,x,y;
		scanf("%lld %lld %lld %lld",&c,&d,&x,&y);
		printf("%lld\n",query_(c,x,y,d));
	}
	
	return 0;
}

Measured memory_bytes: 58112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll k,a,b; cin>>k>>a>>b;
  if (b-a <= 2) {
    cout << k+1 << endl;
    return 0;
  }

  ll t = k-a+1;
  ll ans = a + (b-a)*(t/2);
  if (t%2) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
from collections import deque
N=int(input())
numbers=[[] for _ in range(N)]
for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    numbers[u].append((v,w%2))
    numbers[v].append((u,w%2))
inf=pow(10,9)
visited_point=[inf for _ in range(N)]
visited_point[0]=0
stack=deque([0])
while len(stack)>0:
    n=stack.pop()
    for v,w in numbers[n]:
        if visited_point[v]==inf:
            stack.appendleft(v)
            if w%2==0:
                visited_point[v]=visited_point[n]
            else:
                visited_point[v]=visited_point[n]^1
for a in visited_point:
    print(a)
    

Measured memory_bytes: 35940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n;
	string str;
	cin>>n>>str;
	for(ll i=0;i<str.size();++i){
		cout<<(char)(65+(str[i]+n-'A')%26);
	}
	cout<<endl;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
queue = Array.new
n.times do
  order = gets.split(" ")
  case order[0]
    when "insert"
      queue.unshift(order[1].to_i)
    when "delete" 
      queue.index(order[1].to_i) == nil ? (next): (queue.delete_at(queue.index(order[1].to_i)))
    when "deleteFirst"
    queue.shift
    when "deleteLast"
    queue.pop
  end
end
(queue.size).times do |num|
  print queue[num]
  num+1 == (queue.size) ? (print "\n") : (print " ")
end

Measured memory_bytes: 20696
N = input()
H = input().split()
count = 0

if not(1 <= int(N) and int(N) <= 10**5):
    exit()
for h in H:
    if not(1 <= int(h) and int(h) <= 10**9):
        exit()

tmp = []

for i in range(int(N)-1):
    if int(H[i]) >= int(H[i+1]):
        tmp.append(1)
    else:
        tmp.append(0)

# print(tmp)
count = 0
c = 0
for i in tmp:
    if i == 1:
        c += 1
    else:
        # print(c)
        if c >= count:
            count = c
        c = 0
if c > count:
    print(c)
else:
    print(count)

Measured memory_bytes: 11508
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#define MIN 1<<31-1
#define HMAX 1000000000000000000
#define MOD 1000000007
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RSET(s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
typedef long long int ll;
using namespace std;
bool visit[600000+100000];  
int prime[600000],n,num; ///prime的大小大概估计一下再开数组。大概是（x/lnx）
int flag[600000];
 void getprime()  
 {  
     memset(visit, false, sizeof(visit));  
     num=0;
     for (int i = 2; i <= n; ++i)  
     {  
         if ( !visit[i] )  prime[++num] = i;  
         for (int j = 1; j <= num && i * prime[j] <= n ;  j++)  
         {  
             visit[ i  *  prime[j] ]  =  true;  
             if (i % prime[j] == 0) break; ///此处是重点，避免了很多的重复判断，比如i=9,现在素数是2,3,5,7,进入二重循环，visit[2*9]=1;visit[3*9]=1；这个时候9%3==0，要跳出。因为5*9可以用3*15来代替，如果这个时候计算了，i=15的时候又会被重复计算一次，所以这里大量避免了重复运算。  
         }  
     }  
 } 

int main()
{
	n=600000;
	getprime();
	vector<int> ans;
	for(int i=0;i<num;i++)
	{
		flag[prime[i]]=1;
		if(prime[i]%10==1)
		ans.push_back(prime[i]);
	}
	int ne;cin>>ne;
	for(int i=0;i<ne;i++)
	cout<<ans[i]<<" ";
}

Measured memory_bytes: 5120
N, L = map(int, input().split())

taste       = 0
total_taste = 0
tastes = []
for i in range(1, N+1):
    taste = (L + i - 1) 
    total_taste += taste
    tastes.append(taste)

diff_tastes      = {}
for i in range(0, len(tastes)):
    diff_total_taste = 0
    for j in range(0, len(tastes)):
        if(i != j):
            diff_total_taste += tastes[j]
    diff = abs(total_taste - diff_total_taste)
    diff_tastes[diff_total_taste] = diff

print(min(diff_tastes, key=diff_tastes.get))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#define inf 99999999
using namespace std;
typedef long long ll;
const int MAXN=2000+7;
const int MAX=100+10;
int main(){
   #ifdef SIYU
   //freopen("in.txt","r",stdin);
   #endif // SIYU
   string s1,s2;
   cin>>s1>>s2;
   int len1=s1.size();
   int len2=s2.size();
   if(len1>len2)
      cout<<"GREATER"<<endl;
   else if(len1<len2)
      cout<<"LESS"<<endl;
   else{
      if(s1>s2)
         cout<<"GREATER"<<endl;
      else if(s1<s2)
         cout<<"LESS"<<endl;
      else
         cout<<"EQUAL"<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+7;
int n,ans,cnt,c[N],s[N];
vector<int>G[N];
void dfs(int u,int fa)
{
	s[u]=c[++cnt];
	for(int i=0;i<G[u].size();i++)if(G[u][i]!=fa)dfs(G[u][i],u);
}
int main()
{
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),G[x].push_back(y),G[y].push_back(x);
	for(int i=1;i<=n;i++)scanf("%d",&c[i]);
	sort(c+1,c+n+1),reverse(c+1,c+n+1);
	for(int i=2;i<=n;i++)ans+=c[i];
	printf("%d\n",ans);
	dfs(1,0);
	for(int i=1;i<=n;i++)printf("%d ",s[i]);
}

Measured memory_bytes: 1408
/* author:hellojim */
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
ll n,x,t; 
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n>>x>>t;
	cout<<(n+x-1)/x*t<<endl;
	return 0;
}



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

int sum_dig(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;

  for (int i = 1; i <= N; i++) {
    int sum = sum_dig(i);
    if (sum >= A && sum <= B) total += i;
  }
  cout << total << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
	int n=0;
	cin>>n;
	int*data=new int[n];
	int ans=0;
	bool check=true;
	for(int i=0;i<n;i++){
		cin>>data[i];
	}
	for(;;){
		for(int i=0;i<n;i++){
			if((data[i]%2)==1){
				check=false;
				break;
			}
			data[i]/=2;
		}
		if(!check){
			break;
		}
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

int main() {
	ios_base::sync_with_stdio(0);
	int t, i, j, k, p, q, r, x, y, u, v, n, m;
	cin>>n;
	int c=0;
	for(i=0;i<n;i++){
		cin>>a[i];
		if(i%2==0 and a[i]%2){
			c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % mod;
		base = ((ll)base * base) % mod;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}




Measured memory_bytes: 10608
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	ll n,i,j,k,l,m,z;
	cin>>n;
	ll arr[n];
	l=0;
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
		l+=arr[i];
	}
	k=0;
	m=l-arr[0];
	for(i=0;i<n-1;i++)
	{
		k+=arr[i];
		z=l-k;
		if(m>abs(z-k))
			m=abs(z-k);
	}
	cout<<m<<"\n";
	return 0;
}
	


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;
int N,T;
ll dp[3001][3001];
vector<pair<ll,ll>> d;
ll napsack(int x){
    for(int i=0;i<=N;i++){
        for(int j=0;j<=T;j++) dp[i][j]=0;
    }

    for(int i=0;i<N;i++){
        for(int j=0;j<=T;j++){
            ll B=d.at(i).first, A=d.at(i).second;
            if(j>=A && i!=x) dp[i+1][j]=max(dp[i][j],dp[i][j-A]+B);
            else dp[i+1][j]=dp[i][j];
        }
    }
    ll ret=0;
    for(int i=0;i<T;i++) ret=max(dp[N][i],ret);
    return ret+d.at(x).first;
}
int main(){
    cin>>N>>T;
    
    for(int i=0;i<N;i++){
        ll A,B; cin>>A>>B;
        d.push_back(make_pair(B,A));
    }
    sort(d.begin(),d.end());
    reverse(d.begin(),d.end());
    //for(int i=0;i<N;i++) cout<<"**"<<d.at(i).first<<' '<<d.at(i).second<<endl;
    priority_queue<ll> Q;
    ll ans=0;
    Q.push(0);

    for(int i=0;i<N;i++){
        if(Q.top()<d.at(i).second){
            Q.push(d.at(i).second);
            ans=max(ans,napsack(i));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100],b[100];
int main()
{
	cin>>n;
	int k=0;
	bool t=false;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		if(a[i]==b[i])
			k++;
		else
		{
			if(k>=3)
				t=true;
			k=0;
		}
	}
	if(k>=3)
		t=true;
	if(t==true)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

int const MaxSize = 3e5 + 10;
string s;

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);
	cin >> s;

	if (s.size() < 4)
		cout << "No";
	else {
		string tar = "YAKI";

		LP(i, 0, 4)
		{
			if (tar[i] != s[i]) {

				cout << "No";
				return 0;
			}

		}

		cout << "Yes";

	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 200000000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

#define MAX 100005
int m,n,c;
vector<P> G[MAX];
int sum=0;
int distances[MAX];
int r[MAX];
int road[MAX];

signed main(){
	cin>>n>>m>>c;
	for(int i=0; i<m; i++){
		int a,b,c; cin>>a>>b>>c;
		G[a].push_back(mk(b,c));
		G[b].push_back(mk(a,c));
		sum+=c;
	}
	for(int i=0; i<=n; i++){
		distances[i]=INF;
	}
	
	priority_queue<P,vector<P>, greater<P> > que;
	que.push(mk(0,1));
	distances[1]=0;
	while(!que.empty()){
		int now=que.top().second, dis=que.top().first; que.pop();
		if(distances[now]<dis) continue;
		for(int i=0; i<G[now].size(); i++){
			int d=G[now][i].second, to=G[now][i].first;
			if(dis+d<distances[to]){
				distances[to]=dis+d;
				que.push(mk(distances[to], to));
			}
		}
	}
	
	vector<P> rank;
	for(int i=1; i<=n; i++){
		rank.push_back(mk(distances[i],i));
	}
	sort(rank.begin(), rank.end());
	P a; a.first=0,a.second=0;
	for(int i=0; i<rank.size(); i++){
//		if(rank[i].first>a.second) a.first++;
		r[rank[i].second]=i;		
//		a.second=rank[i].first;
	}
	
	for(int i=1; i<=n; i++){
		for(int j=0; j<G[i].size(); j++){
			int to=G[i][j].first,dis=G[i][j].second;
			if(r[i]>r[to]) road[i]+=dis;
		}
	}
	
	int ans=INF;
	int s=0;
	int l=0;
	for(int i=0; i<rank.size(); i++){
		int v=rank[i].second, x=rank[i].first;
//		if(l<x)
		s+=road[v];
		ans=min(ans, c*x+sum-s);
//		l=x;
	}
	cout<<ans<<en;
}





Measured memory_bytes: 20292
/////////////////////    答案    /////////////// 
/*
注意点：
1. 
*/
//----------------------自打1------------------ 

//---------------------标准答案--------------------

//////////////////////////      一      //////////////
/*
注意点：
1. 
*/
//------------------1z-------------- 

//-----------------------------------------分界线----------------------------------------------- 
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
	char suit;
	int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge( struct Card A[],int n,int left,int mid,int right){
	int i,j,k;
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;++i) L[i]=A[left+i];
	for(int i=0;i<n2;++i) R[i]=A[mid+i];
	L[n1].value=R[n2].value=SENTINEL;
	i=j=0;
	for(k=left;k<right;k++){
		if(L[i].value<=R[j].value){
			A[k]=L[i++];
		}else{
			A[k]=R[j++];
		}
	}
}

void mergeSort(struct Card A[],int n,int left,int right){
	int mid;
	if(left+1<right){
		mid=(left+right)/2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}

int partition(struct Card A[],int n,int p,int r){
	int i,j;
	struct Card t,x;
	x=A[r];
	i=p-1;
	for(int j=p;j<r;++j){
		if(A[j].value<=x.value){
			++i;
			t=A[i];A[i]=A[j];A[j]=t;
		}
	}
	t=A[i+1];A[i+1]=A[r];A[r]=t;
	return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){
	int q;
	if(p<r){
		q=partition(A,n,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}

int main(){
	int n,i,v;
	struct Card A[MAX],B[MAX];
	char S[10];
	int stable=1;
	
	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		scanf("%s %d",S,&v);
		A[i].suit=B[i].suit=S[0];
		A[i].value=B[i].value=v;
	}
	
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);
	
	for(i=0;i<n;i++){
		//比较归并排序与快速排序的结果 
		if(A[i].suit!=B[i].suit) stable=0;
	}
	
	if(stable==1) printf("Stable\n");
	else printf("Not stable\n");
	for(int i=0;i<n;++i){
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	
	return 0;
} 


Measured memory_bytes: 4960
#include <iostream>
using namespace std;
 
int main(){
  int a = 0,b = 0,c = 0,d = 0;
  cin >> a >> b >> c >> d;
  while(a > 0){
    c = c - b;
    if(c <= 0){
      break;
    }
    a =  a - d;
  }
  if(a <= 0)
    cout << "No\n";
  else
    cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N,M; cin >> N >> M;
  if(N%2==0){
    int l1=1, l2=1+N/2;
    bool t = true;
    int cnt = 0;
    for(int d=N/2-1; cnt<M; cnt++){
      if(t){
        cout << l1 << " " << l1+d << endl;
        l1++;
      }
      else{
        cout << l2 << " " << l2+d << endl;
        l2++;
      }
      t = !t;
      d--;
    }
  }
  else{
    int l = N/2;
    int r = l+1;
    rep(i,M){
      cout << l << " " << r << endl;
      l--;
      r++;
    }
  }
  return 0;
}


Measured memory_bytes: 3636
n=int(input())
a=list(map(int,input().split()))
cnt=0
ans=0
now=False
for i in range(n):
    if a[i]==1:
        cnt+=1
        now=True
    elif now:
        ans=max(ans,cnt)
        cnt=0
        now=False
ans=max(cnt,ans)
print(ans+1)


Measured memory_bytes: 5596
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define  all(v)            v.begin(), v.end()
#define  sz(x)             (int)x.size()
#define  debug(x)         cout << '>' << #x << ':' << x << endl;
#define  rep(i,n)         for(int i = 0; i < n; i++)
#define  reps(i,n)        for(int i = 1; i<=n ; i++)
#define  unq(v)           sort(all(v));v.erase(unique(all(v)), v.end());
#define  rot(v)           rotate(v.begin(), v.begin() + k, v.end());
#define  rmv(v,a)         v.erase(remove(v.begin(),v.end(), a), v.end());
#define  pb               push_back
#define  eb               emplace_back
#define  mp               make_pair
#define  endl             '\n'
#define  fi               first
#define  se               second
using namespace std;
typedef long long          ll;
// use count() instead of find() in sets.
const ll MOD = 1e9 + 9;
const double PI  = acos(-1.0);
const double EPS = (1e-10);
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = { -1, 0, 1, 0};
const int dx8[8] = { -1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = { -1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int X, int Y) {return X > Y;}
int dcp(double A, double B){return fabs(A-B)<=EPS ? 0 : A<B ? -1:1;}


ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m ){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}




int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;cin>>n;
ll a[n];
rep(i,n){cin>>a[i];}
sort(a,a+n,cmp);

ll ans = a[0];
if(n%2 == 0){
    for(ll i = 1;i<=(n-2)/2; i++ ){
        ans=ans+ 2*a[i];
    }
}else{
    for(ll i = 1;i<(n-1)/2 ; i++){
        ans=ans+2*a[i];
    }
    ans+=a[(n-1)/2];

}
cout<<ans<<endl;


}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
ll ds[11];
  
int main(){
while(true){
scanf("%d%d", &n, &m);
if(n+m==0)return 0;
for(int i=0;i<=10;i++)ds[i]=0;
while(n--){
ll d;
int x;
scanf("%lld%d",&d,&x);
ds[x] += d;
}
ll ans = 0;
for(int i=10;i>=0;i--){
ll use = min((ll)m, ds[i]);
ds[i] -= use;
m -= use;
ans += i * ds[i];
}
printf("%lld\n", ans);
  
}
}



Measured memory_bytes: 3184
#include<stdio.h>

int main(void)
{
	int x,y,i;
	for(i=0;i<3000;i++){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0){
			break;
		}
		if(x>y){
			printf("%d %d\n",y,x);
		}else{
			printf("%d %d\n",x,y);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct M{ ll a, b; };


int main()
{
    int n;
	cin >> n;
	
	vector<M> v(n);
	vector<vector<ll> > dp(n, vector<ll>(n, 1 << 30LL));
	
	rep(i, n) cin >> v[i].a >> v[i].b;
	rep(i, n) dp[i][i] = 0;
	
	REP(i, 1, n) rep(j, n - i) rep(k, i + j) 
	{
		chmin(dp[j][i + j], dp[j][k] + dp[k + 1][i + j] + v[j].a * v[k].b * v[k + 1].a * v[i + j].b);
	}
	
	cout << dp[0][n - 1] << endl;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <complex>

using namespace std;
using pii = pair<int, int>;
using ll = long long;

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

	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n - 1);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n - 1; i++) cin >> c[i];
	int answer = b[a[0] - 1];
	for (int i = 1; i < n; i++) {
		answer += b[a[i] - 1];
		if (a[i - 1] + 1 == a[i]) answer += c[a[i - 1] - 1];
	}
	cout << answer;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,q;cin >> n >> m >> q;
    vector<int> a(q),b(q),c(q),d(q);
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--,b[i]--;
    }
    stack<pair<int,string>> st;
    vector<string> v;
    st.push({0,""});
    while(!st.empty()){
        int x=st.top().first;
        string y=st.top().second;
        st.pop();
        if(x==0){
            rep(i,n){
                st.push({x+1,y+char(i)});
            }
        }
        else if(x==n){
            v.push_back(y);
        }
        else{
            for(int i=y[y.size()-1];i<m;i++){
                st.push({x+1,y+char(i)});
            }
        }
    }
    int ans=0;
    for(string x:v){
        int res=0;
        rep(i,q){
            if(x[b[i]]-x[a[i]]==c[i]){
                res+=d[i];
            }
        }
        chmax(ans,res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 7392
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  V<> x(n); for (int i = 0; i < n; ++i) cin >> x[i];
  int res = 0;
  for (int i = 0; i < n; ++i) {
    res += min(x[i], k - x[i]);
  }
  cout << 2 * res << '\n';
}

Measured memory_bytes: 256