akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vi vec(n);
    cin>>vec;
    int a=0,b=0;
    REP(i,n){
        if(vec[i]>a){
            b=a;
            a=vec[i];
        }else if(vec[i]>b){
            b=vec[i];
        }
    }
    REP(i,n){
        if(a==vec[i]){
            cout<<b<<endl;
        }else{
            cout<<a<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2432
#include"bits/stdc++.h"
using namespace std;

using ll = long long;

void Main()
{
    string s;
    ll Q;
    std::cin >> s;
    std::cin >> Q;

    bool reverse = false;

    for (ll i = 0; i < Q; i++)
    {
        ll t, f;
        string c;
        std::cin >> t;

        if (t == 1)
        {
            reverse = !reverse;
        }
        else
        {
            std::cin >> f >> c;
            if (f == 1)
            {
                if (!reverse)
                {
                    s.insert(0, c);
                }
                else
                {
                    s += c;
                }
            }
            else
            {
                if (!reverse)
                {
                    s += c;
                }
                else
                {
                    s.insert(0, c);
                }
            }
        }
    }

    if (reverse)
    {
        std::reverse(s.begin(), s.end());
    }

    cout << s;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
}


Measured memory_bytes: 912
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int N;
	int i;
	int cnt;
	vector<int> a;

	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	sort(a.begin(), a.end());
	a.push_back(-5);

	i = 0;
	cnt = 0;

	while (i < N) {
		if (a.at(i) != a.at(i+1)) {
			cnt++;
			i++;
			
		}
		else {
			int num = 1;
			while (a.at(i)==a.at(i+1))
			{
				i++;
				num++;
			}
			//cout << "num:" << num << endl;
			cnt += (num % 2);
			i++;
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 892
def factorial(number)
  if number.zero?
    1
  else
    number * factorial(number - 1)
  end
end

def foo(number)
  if number==2
    4
  else
    (number-1)*foo(number-1)
  end
end

N=gets.to_i
x=[]
y=[]
N.times do |i|
  x[i],y[i]=gets.chomp.split(" ").map{|j| j.to_i}
end

sum=0
num=0

N.times do |i|
  N.times do |j|
    next if i==j
    sum+=(Math.sqrt(((x[i]-x[j]).abs**2)+((y[i]-y[j]).abs**2)))*(foo(N)/4)
    num+=1
  end
end

puts "#{sum/factorial(N)}"


Measured memory_bytes: 1788
#2020-04-29
n = int(input()) #問題数
lst = list(map(int,input().split())) #問題にかかる時間
d = int(input()) #ドリンクの数

total_time = sum(lst)
ans = 0
for i in range(d):
    a,b = map(int,input().split()) #a;No/ b;sec
    ans = total_time + b - lst[a - 1]
    print(ans)

Measured memory_bytes: 3060
N = int(input())
# = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

if N == 0:
    if A[0] == 1 and len(A) == 1:
        print(1)
        exit()
    else:
        print(-1)
        exit()

elif A[0] != 0:
    print(-1)
    exit()

else:
    number = [1]*(N+1)
    for i in range(1, N+1):
        if number[i-1]-A[i-1] <= 0:
            print(-1)
            exit()
        else:
            number[i] = 2*(number[i-1]-A[i-1])
    if number[N] < A[N]:
        print(-1)
        exit()
    elif number[N] - A[N] > number[N-1] -A[N-1]:
        next = (number[N] - A[N]) - (number[N-1] -A[N-1])
        number[N] = A[N]
        for i in range(2, N):
            if next > (number[N-i] - A[N-i]):
                number[N-i+1] -= next
                next = next - (number[N-i] - A[N-i])
            else:
                number[N-i+1] -= next
                break
    else:
        number[N] = A[N]
print(sum(number))


Measured memory_bytes: 674300
#include<cstdio>
using namespace std;
#define N 1050000
#define mod 998244353
int v[N],ct[N],n,a,as;
int pw(int a,int p){int as=1;while(p){if(p&1)as=1ll*as*a%mod;a=1ll*a*a%mod;p>>=1;}return as;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a),v[a]=(v[a]+a)%mod,as=(as+mod-a)%mod;
	for(int i=1;i<=1e6;i++)
	for(int j=i;j<=1e6;j+=i)
	ct[i]=(ct[i]+v[j])%mod;
	for(int i=1;i<=1e6;i++)ct[i]=1ll*ct[i]*ct[i]%mod;
	for(int i=1e6;i>=1;i--)
	for(int j=i*2;j<=1e6;j+=i)
	ct[i]=(ct[i]-ct[j]+mod)%mod;
	for(int i=1;i<=1e6;i++)
	as=(as+1ll*ct[i]*pw(i,mod-2))%mod;
	printf("%d\n",1ll*as*pw(2,mod-2)%mod);
	
}

Measured memory_bytes: 8320
<?php
    $num = explode(" ",trim(fgets(STDIN)));
    
    hikaku($num,0,1);
    hikaku($num,1,2);
    hikaku($num,0,1);
    
    echo implode(" ",$num)."\n";
  
  function hikaku(&$num, $i, $j){
        if($num[$i] > $num[$j]){
            $temp = $num[$i];
            $num[$i] = $num[$j];
            $num[$j] = $temp;
        }
  }

Measured memory_bytes: 15280
N = int(input())
W = [0] * N
W = list(map(int, input().split()))

diff_min = abs(sum(W[:1]) - sum(W[1:]))

for n in range(N):
    S_1 = W[:n]
    S_2 = W[n:]

    diff = abs(sum(S_1) - sum(S_2))

    if diff < diff_min:
        diff_min = diff


print(diff_min)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
//#define vi vector<int>
#define vb vector<bool>
#define pii pair<int, int>
#define mii map<int, int>
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define tr(container, it) for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define inf (long long)1e18
#define F first
#define S second
#define SZ(x) ((int)(x).size())
//#define rep(i, n) for (int i = 0; i < n; i++)
//#define repd(i,n) for(int i=n-1;i>=0;i--)
//#define rep1(i,n) for(int i=1;i<=n;i++)
const int N = 1e9 + 7;

int pow(int x, int y)
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = ((res) * (x));
        res %= N;
        y = y >> 1;
        x = ((x) * (x));
    }
    return res;
}
ll powm(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll mxn(ll a, ll b)
{
    if (a > b)
        return a;
    else
    {
        return b;
    }
}
long long minl(long long a, long long b)
{
    if (a < b)
        return a;
    else
    {
        return b;
    }
}

void solve()
{
    ll n;
    cin >> n;
    ll a = powm(10, n, N);
    ll b = powm(9, n, N);
    ll c = powm(8, n, N);
    ll ans = a - 2 * (b - c) - c;
    ans += (ll)3 * N;
    cout << ans % N;
}

int32_t main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int t;
    // cin >> t;
    // while (t--)
    // {
    solve();
    // }
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second
main(){
  int a,b,x;
  cin>>a>>b>>x;
  if(a+b>=x&&a<=x)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <deque>
using namespace std;
int main() {
	string s;
	int q,t,f;
	cin >> s;
	cin >> q;
	deque<char> str(s.begin(), s.end());
	bool isNorm = true;
	char c;
	for (int i = 0; i < q; ++i) {
		cin >> t;
		if (t == 1) {
			isNorm = !isNorm;
		} else {
			cin >> f;
			cin >> c;
			if ((f == 1) ^ isNorm) { //true false:back
				str.push_back(c);
			} else {
				str.push_front(c);
			}
		}
	}
	string *ans;
	if (isNorm) {
		ans = new string(str.begin(), str.end());
	} else {
		ans = new string(str.rbegin(), str.rend());
	}
	cout << (*ans) << endl;
	delete ans;
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	
	vector<int> xv(n);
	for (auto &&e : xv)
		cin >> e;

	sort(xv.begin(), xv.end());
	
	vector<int> yv(m);
	for (auto &&e : yv)
		cin >> e;
	
	sort(yv.begin(), yv.end());

	if (xv.back() < yv.front() && xv.back() > x && xv.back() <= y && yv.front() > x && yv.front() <= y)
		cout << "No War" << endl;
	else
		cout << "War" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct data{
	int bit,v;
	double cost;
	data(){}
	data(int bb,int vv,double cc){
		bit=bb;
		v=vv;
		cost=cc;
	}
	bool operator<(const data &d)const{
		return d.cost<cost;
	}
};

int n,m;
P za[201][2];
P factory[15];
double dist[1<<15][15];
double dp[15][15];
double stf[201][2][15];

struct graph_scc{
	int V;
	vector<int> G[501];
	vector<int> rG[501];
	vector<int> vs;
	bool used[501];
	int cmp[501];
	void init(int n){
		V=n;
		for(int i=0;i<V;i++){
			G[i].clear();
			rG[i].clear();
		}
		vs.clear();
		memset(cmp,0,sizeof(cmp));
	}
	void add_edge(int from,int to){
		G[from].push_back(to);
		rG[to].push_back(from);
	}

	void dfs(int v){
		used[v]=true;
		for(int i=0;i<G[v].size();i++){
			if(!used[G[v][i]])dfs(G[v][i]);
		}
		vs.push_back(v);
	}
	void rdfs(int v,int k){
		used[v]=true;
		cmp[v]=k;
		for(int i=0;i<rG[v].size();i++){
			if(!used[rG[v][i]])rdfs(rG[v][i],k);
		}
	}

	int scc(){
		memset(used,0,sizeof(used));
		vs.clear();
		for(int v=0;v<V;v++){
			if(!used[v])dfs(v);
		}
		memset(used,0,sizeof(used));
		int k=0;
		for(int i=vs.size()-1;i>=0;i--){
			if(!used[vs[i]]){
				rdfs(vs[i],k++);
			}
		}
		return k;
	}
};

graph_scc sc;

bool C(double v){
	sc.init(n*2);
	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++){
			for(int k=i+1;k<n;k++){
				for(int l=0;l<2;l++){
					bool flag=false;
					for(int a=0;a<m;a++){
						for(int b=0;b<m;b++){
							double diss=stf[i][j][a];
							diss+=stf[k][l][b];
							diss+=dp[a][b];
							if(diss<=v)flag=true;
						}
					}
					if(!flag){
						sc.add_edge(i+j*n,k+(1-l)*n);
						sc.add_edge(k+l*n,i+(1-j)*n);
					}
				}
			}
		}
	}
	int k=sc.scc();
	for(int i=0;i<n;i++){
		if(sc.cmp[i]==sc.cmp[i+n])return false;
	}
	return true;
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&za[i][0].first,&za[i][0].second,&za[i][1].first,&za[i][1].second);
	}
	for(int i=0;i<m;i++){
		scanf("%d%d",&factory[i].first,&factory[i].second);
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<(1<<m);j++){
			for(int k=0;k<15;k++){
				dist[j][k]=1e9;
			}
		}
		dist[(1<<i)][i]=0.0;
		priority_queue<data> que;
		que.push(data(1<<i,i,0.0));
		while(que.size()){
			data d=que.top();
			que.pop();
			if(dist[d.bit][d.v]<d.cost)continue;
			for(int j=0;j<m;j++){
				int valx=(factory[j].first-factory[d.v].first);
				int valy=(factory[j].second-factory[d.v].second);
				double ncost=sqrt(valx*valx+valy*valy)+d.cost;
				if(dist[d.bit|(1<<j)][j]>ncost){
					dist[d.bit|(1<<j)][j]=ncost;
					que.push(data(d.bit|(1<<j),j,ncost));
				}
			}
		}
		for(int j=0;j<m;j++){
			dp[i][j]=dist[(1<<m)-1][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<m;k++){
				int valx=(za[i][j].first-factory[k].first);
				int valy=(za[i][j].second-factory[k].second);
				stf[i][j][k]=sqrt(valx*valx+valy*valy);
			}
		}
	}
	double l=0.0,r=114514.0;
	for(int i=0;i<100;i++){
		double mid=(l+r)/2.0;
		if(C(mid))r=mid;
		else l=mid;
	}
	printf("%.9f\n",r);
	return 0;
}

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


int main(){
    ll n,k;
    cin >> n >> k;
    ll res = n%k;
    ll b = k-res;
    cout << min(res,b) << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

		while(sc.hasNextInt()){
			int n = sc.nextInt();
			if(n == 0) break;

			double[] x = new double[n];
			double[] y = new double[n];
			double[] z = new double[n];
			double[] r = new double[n];

			for(int i=0;i<n;i++){
				x[i] = sc.nextDouble();
				y[i] = sc.nextDouble();
				z[i] = sc.nextDouble();
				r[i] = sc.nextDouble();
			}

			ArrayList<ArrayList<Edge>> map = new ArrayList<ArrayList<Edge>>();
			for(int i=0;i<n;i++) map.add(new ArrayList<Edge>());

			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					double dist = Math.sqrt( Math.pow(x[j]-x[i],2) +
																	 Math.pow(y[j]-y[i],2) +
																	 Math.pow(z[j]-z[i],2));

					Edge e = new Edge(i,j,0);
					if(dist > r[i] + r[j]){
						e.cost = dist - (r[i] + r[j]);
					}
					map.get(i).add(e);
				}
			}

			System.out.printf("%.3f\n",prim(map));
		}
	}

	private static double prim(ArrayList<ArrayList<Edge>> g){
		PriorityQueue<Edge> open = new PriorityQueue<Edge>();
		HashSet<Integer> closed = new HashSet<Integer>();
		double total = 0;
		open.add(new Edge(-1,0,0));
		ArrayList<Edge> ng = new ArrayList<Edge>();

		while(closed.size() != g.size()){
			Edge st = open.poll();
			if(closed.contains(st.to)) continue;
			closed.add(st.to);
			ng.add(st);
			total += st.cost;
			for(Edge e : g.get(st.to)){
				if(!closed.contains(e.to)){
					open.add(e);
				}
			}
		}

		return total;
	}
}

class Edge implements Comparable<Edge>{
	int from,to;
	double cost;

	Edge(int from,int to,double cost){
		this.from = from;
		this.to = to;
		this.cost = cost;
	}

	public int compareTo(Edge e){
		if(cost < e.cost) return -1;
		if(cost > e.cost) return 1;
		return 0;
	}
}

Measured memory_bytes: 14000
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n;
  double t, x, a;
  scanf("%d %lf %lf", &n, &t, &a);
  double h[MAX];
  rep(i, 0, n) scanf("%lf", &h[i]);

  int ans = 0;
  rep(i, 0, n) {
    double temp = fabs(t - h[i] * 0.006 - a);
    double min  = fabs(t - h[ans] * 0.006 - a);
    if (temp < min) ans = i;
  }
  printf("%d\n", ans + 1);
  return 0;
}


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

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

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

function<LL(LL, LL)> gcdlambda = [](LL n, LL m) { return __gcd(n, m); };

void solve(long long N, std::vector<long long> A)
{
  bool ok = true;

  int MAX = 1001000;
  vector<int> vec(MAX, 0);
  for (auto a : A)
    vec[a]++;

  for (int i = 2; i < MAX; i++)
  {
    int cnt = 0;
    for (int j = i; j < MAX; j += i)
    {
      cnt += vec[j];
    }
    if (cnt >= 2)
      ok = false;
  }

  if (ok)
  {
    cout << "pairwise coprime" << endl;
    return;
  }

  LL ans = A[0];
  for (auto a : A)
  {
    ans = gcdlambda(a, ans);
  }
  if (ans == 1)
  {
    cout << "setwise coprime" << endl;
    return;
  }
  cout << "not coprime" << endl;
}

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


Measured memory_bytes: 15196
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w,K = na()
s = []
for i in range(h):
    s.append(list(ns()))

ans = []
k = 1
bb = 0

for i in range(h):
    if '#' in s[i]:
        ret = []
        flag = True
        for j in range(w):
            if s[i][j] == '#':
                if flag:
                    flag = False
                else:
                    k+=1
            ret.append(k)
        ans.append(ret)
        k+=1
        if bb:
            for _ in range(bb):
                ans.append(ans[-1])
            bb = 0
    else:
        if len(ans) == 0:
            bb += 1
            continue
        ans.append(ans[-1])


for i in ans:
    print(*i,sep=' ')

Measured memory_bytes: 8272
while True:
    n,r = map(int,input().split())
    if n==0 and r==0:
        break
    cut = [i for i in range(1,n+1)][::-1]
    for i in range(r):
        p,c = map(int,input().split())
        cut = cut[p-1:p+c-1] + cut[:p-1] + cut[p+c-1:]
    print(cut[0])



Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
#define itc(n) char(n+48)
#define cti(ch) (ch-48)
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){ostringstream convert;convert<<n;return convert.str();}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>bool is_palindrome(T s){T s1=s;reverse(s1.begin(),s1.end());if(s==s1)return true;return false;}
template<class T>int digit_sum(T s){int sum=0; for(int i=0; i<s.size(); i++)sum+=cti(s[i]);return sum;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}
template<class T>T doStringSum(T s1, T s2){int len1=s1.length(), len2=s2.length();
    if(len1<len2)return doStringSum(s2, s1);
    T ans="";int carry=0, i, s;
    for(i=1;i<=len1;i++){s = carry+cti(s1[len1-i]);if(i<=len2)s += cti(s2[len2-i]);
    ans = itc(s%10)+ans;carry = s/10;}if(carry!=0)ans = itc(carry)+ans;
    return ans;
}
template<class T>T dostringmultiply(T s1, T s2){int len1=s1.length(), len2=s2.length();
    if(len1<len2)return dostringmultiply(s2,s1);
    int i,j,p, carry=0;T result, net="", c;
    for(i=len2-1;i>=0;i--){carry=0;result="";c="";
    for(j=len1-1;j>=0;j--){p=cti(s1[j])*cti(s2[i]);result = itc((p+carry)%10)+result;carry=(p+carry)/10;}
    if(carry!=0){c=to_string(carry);result=c+result;}
    for(j=i;j<len2-1;j++)result+="0";net=doStringSum(net,result);}
    return net;
}
template<class T>T nCr(T n, T r)
    {if(r > n - r) r = n - r;T ans = 1;T i;
    for(i = 1; i <= r; i++){ans *= n - r + i;ans /= i;}
    return ans;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    faster_io;

    int n;
    cin>>n;
    int a[n+5];
    for(int i=0; i<n; i++)cin>>a[i];
    int cnt[n+5]={0};
    int mx=0;
    for(int i=n-1; i>0; i--){
        if(a[i-1]<a[i])continue;
        else cnt[i-1]=cnt[i]+1;
        mx=max(mx,cnt[i-1]);
    }
//    for(int i=0; i<n; i++)cout<<cnt[i]<<" ";
    cout<<mx<<endl;

    return 0;
}


Measured memory_bytes: 1024
class Solution:
    def solve(self, N: int) -> str:

        f = 0
        tmp = N
        while tmp > 0:
            f += tmp % 10
            tmp //= 10

        if N % f == 0:
            return 'Yes'
        else:
            return 'No'


if __name__ == '__main__':

    # standard input
    N = int(input())

    # solve
    solution = Solution()
    print(solution.solve(N))


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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}
//_____________________________________________________\\

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        int a,b; cin>>a>>b;
        cout<<a*b;
    }
}

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

const long long INF = 1LL << 60;
const int MAX_N = 110;
const int MAX_V = 100100;

int N;
long long W, w[MAX_N], v[MAX_N];
long long dp[MAX_N][MAX_V];
signed main(void)
{
	cin >> N >> W;
	rep(i, N) cin >> w[i] >> v[i];
	for(int i = 0; i < MAX_N; i++)
	for(int j = 0; j < MAX_V; j++)
		dp[i][j] = INF;
	dp[0][0] = 0;
	rep(i, N)
	{
		for(int j = 0; j < MAX_V; j++)
		{
			if (j - v[i] >= 0)
				dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
		}
	}
	int ans = 0;
	for(int j = 0; j < MAX_V; j++)
	{
		if (W >= dp[N][j])
		{
			ans = j;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	int ans = 0;
	for(int i = 1; i < n; i++){
		if(i != n - i) ans++;
	}
	cout << ans / 2 << endl;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
#include <fstream>
#include <cassert>
//#include <bits/stdc++.h>
using namespace std;

//#include<bits/stdc++.h>


	
int main() {
	string a;
	long long int  b;
	cin >> a >> b;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] != '1') {
			d = i;
			break;
		}
	}
	//cout << d << endl;
	if (d >= b) {
		cout << 1 << endl;
	//	return 0;
	}
	else cout << a[d ] << endl;



	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
int main()
{
  
  
  int flag=1;
  ll sum=0;
  int flag1=0;
  ll tot=0;
  int ans=0;
  map<int,int>m;
  vi v;
  set<string>st;
  string s;
  sci(n);
  rep(i,0,n-1)
  {
    cin>>s;
    st.insert(s);
  }
  cout<<st.size();

  
  
    return 0;
}

Measured memory_bytes: 19344
@ptn = 0

# n:検索対象, previn:呼出元メソッドで選出された数値, sum:合計値, d:探索深さ
def sum4Integers(n, previn=0, sum=0, d=1, hist=[])
  (previn..9).each do |i|
    #p "n:#{n}, previn:#{previn}, sum:#{sum}, d:#{d}, i:#{i}, #{hist}"
    return if sum > n || i > n # 合計値or候補番号が検索対象値を上回ったら検索打ち切り
    if d != 4 then
      sum4Integers(n, i, sum+i, d+1, hist+[i])
    elsif (d == 4) && (sum+i == n) then     
      hist += [i]
      facttimes = 1
      hist.uniq.each do |num|
        facttimes *= fact(hist.count(num))
      end
      @ptn += fact(4)/facttimes
      return
    end
  end
end

# 階乗計算
def fact(n)
  n == 1 ? 1 : n*fact(n-1)
end

while n = gets
  n = n.chomp.to_i
  @ptn = 0
  sum4Integers(n)
  p @ptn
end



Measured memory_bytes: 6864
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, K;
    int Div;
    scanf("%d%d%d", &A, &B, &K);
    Div = min(A,B);
    int Num[Div];
    int i=0;
    int answer;
    while(Div>0){
        if(A%Div==0 && B%Div==0){
            Num[i] = Div;
            i++;
        }
        Div--;
    }
    printf("%d", Num[K-1]);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector> 
#include <algorithm>
#include <string>
#include <map>
#include <stack>
using namespace std;

int main() {
    int N = 1000;

    stack<string> s;
    string tmp;

    while(cin >> tmp) {
        
        // cout << tmp << endl;
        if(tmp == "+" || tmp == "*" || tmp == "-") {
            string a, b;
            int x;
            int y;
            string result;
            
            a = s.top();
            s.pop();
            b = s.top();
            s.pop();

            istringstream(a) >> x;
            istringstream(b) >> y;

            ostringstream oss;

            // cout << x << endl;
            // cout << y << endl;

            if(tmp == "+") {
                oss << y + x;
                result = oss.str();
            } else if(tmp == "*") {
                oss << y * x;
                result = oss.str();
            } else if(tmp == "-") {
                oss << y - x;
                result = oss.str();
            }

            s.push(result);
        } else {
            s.push(tmp);
        }

        // if(tmp == "*") {
        //     break;
        // }
    }

    cout << s.top() << endl;

    return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n,m,p,tf[100005],ac = 0,pn[100005],pnall = 0;
    string s;
    for(int i = 0;i < 100005;i++){
        tf[i] = 0;
        pn[i] = 0;
    }
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        cin >> p >> s;
        if(tf[p] == 0 && s == "AC"){
            tf[p] = 1;
            ac++;
        }else if(tf[p] == 0 && s == "WA"){
            pn[p]++;
        }
    }
    for(int i = 1;i <= n;i++){
        if(tf[i] == 1){
            pnall += pn[i];
        }
    }
    cout << ac << " " << pnall << endl;
    return(0);
}



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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for (int i=0; i<ty-sy; i++)
    cout << 'U';
  for (int i=0; i<tx-sx; i++)
    cout << 'R';
  for (int i=0; i<ty-sy; i++)
    cout << 'D';
  for (int i=0; i<tx-sx; i++)
    cout << 'L';
  cout << 'L';
  for (int i=0; i<ty-sy+1; i++)
    cout << 'U';
  for (int i=0; i<tx-sx+1; i++)
    cout << 'R';
  cout << 'D';
  cout << 'R';
  for (int i=0; i<ty-sy+1; i++)
    cout << 'D';
  for (int i=0; i<tx-sx+1; i++)
    cout << 'L';
  cout << 'U';
  return 0;
}

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

struct kugyu {
	int pos;
	int isOn;
	int idx;
};

int mareitaso(const void* x, const void* y) {
	struct kugyu a = *(const struct kugyu*)x, b = *(const struct kugyu*)y;
	if (a.pos != b.pos) return a.pos < b.pos ? -1 : 1;
	/* OFF → ON の順で並べる */
	if (a.isOn && !b.isOn) return 1;
	if (!a.isOn && b.isOn) return -1;
	return 0;
}

int N, M;
int a[114514], b[114514];

struct kugyu tomatu[271828];

int activeCount = 0;
int activeIndice[114514];
int isActive[114514];

int main(void) {
	int i;
	int count = 0;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < M; i++) {
		if (scanf("%d%d", &a[i], &b[i]) != 2) return 1;
	}
	for (i = 0; i < M; i++) {
		tomatu[i * 2].pos = a[i];
		tomatu[i * 2].isOn = 1;
		tomatu[i * 2].idx = i;
		tomatu[i * 2 + 1].pos = b[i];
		tomatu[i * 2 + 1].isOn = 0;
		tomatu[i * 2 + 1].idx = i;
	}
	qsort(tomatu, M * 2, sizeof(*tomatu), mareitaso);
	for (i = 0; i < M * 2; i++) {
		if (tomatu[i].isOn) {
			activeIndice[activeCount++] = tomatu[i].idx;
			isActive[tomatu[i].idx] = 1;
		} else {
			if (isActive[tomatu[i].idx]) {
				int j;
				count++;
				for (j = 0; j < activeCount; j++) {
					isActive[activeIndice[j]] = 0;
				}
				activeCount = 0;
			}
		}
	}
	printf("%d\n", count);
	return 0;
}

/*

溜めといて区間の右端で一気に落とす

*/


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

typedef long long ll;
typedef long double ld;

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

int main(){

    set<ll> a{1, 3, 5 , 7, 8, 10, 12};
    set<ll> b{4, 6, 9, 11};
    ll x, y;

    cin >> x >> y;

    cout << (a.count(x) * a. count(y) || b.count(x) * b.count(y) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 804000;
int n,m,head[N],to[N],nxt[N],deg[N],edgenum=1,sta[N],top;
bool vis[N];
void add(int u, int v){
	to[++edgenum]=v;nxt[edgenum]=head[u];head[u]=edgenum;
}
void dfs(int u){
	while(head[u]){
		int i=head[u];head[u]=nxt[i];
		if(vis[i>>1])continue;vis[i>>1]=1;
		dfs(to[i]);sta[++top]=u;
	}
}
int s[N];int len,tot;
Vi dot[5];
void ins(int x){
	if(!vis[x])s[++len]=x,vis[x]=1;
	else {
		while(s[len]!=x){
			if(tot<=1)dot[tot].pb(s[len]);
			vis[s[len]]=0,len--;
		}
		if(tot<=1)dot[tot].pb(x);
		tot++;
	}
}
int main() {
	read(n);read(m);
	while(m--){
		int u,v;read(u);read(v);deg[u]++;deg[v]++;
		add(u,v);add(v,u);
	}
	rep(i,1,n)if(deg[i]%2){puts("No");return 0;}
	dfs(1);sta[0]=1;
	memset(vis,0,sizeof(vis));
	per(i,top,0)ins(sta[i]);
	if(tot>=3)puts("Yes");else{
		if(tot==2){
			int cnt=0;set<int>Set;
			rep(i,0,SZ(dot[0])-1)Set.insert(dot[0][i]);
			rep(i,0,SZ(dot[1])-1)cnt+=Set.count(dot[1][i]);
			if(cnt>=3)puts("Yes");else puts("No");
		}
		else puts("No");
	}
	assert(len==1);cerr<<tot;
//	per(i,top,1)printf("%d ",sta[i]);
	return 0;
}


Measured memory_bytes: 20732
H, W = map(int, input().strip().split())
grid = [list(input()) for i in range(H)]
dp = [[0 for i in range(W+1)] for i in range(H+1)]
dp[0][0] = 1

for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            dp[i+1][j] += dp[i][j]
            dp[i][j+1] += dp[i][j]
        dp[i][j] = dp[i][j]%(1000000007)
print(dp[H-1][W-1])

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

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

import heapq
l = []
heapq.heapify(l)

ind=0
ans=0
for i in range(1,m+1):
    while n>ind and ab_list[ind][0] <= i:
        heapq.heappush(l,-ab_list[ind][1])
        ind+=1

    if len(l) !=0:
        b = -heapq.heappop(l)
        ans+=b
print(ans)

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

int main(void)
{
	int n,x,cnt;

	while (true)
	{
		cin >> n >> x;
		if (n == 0 && x == 0)
			break;

		cnt = 0;
		for(int i=1;i<=n;++i) {
			for (int j = i + 1;j <= n;++j) {
				for (int k = j + 1;k <= n;++k) {
					if (i + j + k == x)
						++cnt;
				}
			}
		}

		cout << cnt << endl;
	}
}



Measured memory_bytes: 3092
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    Node[] nodes = new Node[N];
    for (int i = 0; i < N; i++) nodes[i] = new Node();

    for (int i = 0; i < N - 1; i++) {
      int a = scanner.nextInt() - 1;
      int b = scanner.nextInt() - 1;
      int c = scanner.nextInt();
      nodes[a].edges.add(new Edge(nodes[b], c));
      nodes[b].edges.add(new Edge(nodes[a], c));
    }

    int Q = scanner.nextInt();
    int K = scanner.nextInt() - 1;
    dfs(nodes[K], null, 0);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Q; i++) {
      int x = scanner.nextInt() - 1;
      int y = scanner.nextInt() - 1;
      sb.append(nodes[x].depth + nodes[y].depth).append('\n');
    }
    System.out.print(sb.toString());
  }

  private static void dfs(Node node, Node from, long depth) {
    node.depth = depth;
    for (Edge e : node.edges) {
      if (e.to != from) dfs(e.to, node, node.depth + e.d);
    }
  }

  private static class Node {
    private List<Edge> edges = new ArrayList<>();
    private long depth = -1;
  }

  private static class Edge {
    private final Node to;
    private final int d;

    private Edge(Node to, int d) {
      this.to = to;
      this.d = d;
    }
  }
}


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


#define ll long long


//gcdやり直す

void swap (int *x, int *y) {
  int temp;    

  temp = *x;
  *x = *y;
  *y = temp;
}




/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}





/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int n;
  scanf("%d",&n);
  int A[n];
  for(int i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  qsort(A,n,4,dn);

  long int ans=A[0];
  for(int i=2;i<n;i++){
    ans+=A[i/2];
  }

  printf("%ld\n",ans);
}

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

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }   
    ll ans=1;
    rep(i,n){
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }

    ll c=pow(10,18);
    rep(i,n){
        c/=a[i];
        if(c<1){
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i,n){
        ans*=a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
  int N, Q;
  cin >> N >> Q;
  map<int, int> depth[2];
  for (int axis = 0; axis < 2; axis++) {
    depth[axis].insert(make_pair(N-1, N-1));
  }
  long stones = (long)(N-2)*(N-2);
  for (int q = 0; q < Q; q++) {
    int axis, x;
    cin >> axis >> x;
    axis--; // 0 or 1                                                                                                                                         
    x--; // make index 0-based                                                                                                                                
    int d = depth[axis].lower_bound(x)->second;
    stones -= (d-1);
    if (depth[1-axis].count(d) == 0 || depth[1-axis][d] > x) {
      depth[1-axis][d] = x;
    }
  }
  cout << stones << endl;
}

Measured memory_bytes: 7828
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(inp):
    (N, M) = map(int, inp.readline().strip().split(' '))
    SC = [map(int, inp.readline().strip().split(' ')) for i in range(M)]

    s2c = {}
    for (s, c) in SC:
        if s in s2c and s2c[s] != c:
            return "-1"
        s2c[s] = c

    r = ''
    for i in range(1, N + 1):
        if i in s2c:
            r += str(s2c[i])
        else:
            if i == 1 and N > 1:
                r += '1'
            else:
                r += '0'

    if len(str(int(r))) != N:
        return "-1"

    return r


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()


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

typedef long long ll;

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

	ll t=1;
	//cin >> t;

	for(ll i=1;i<=t;i++){
		ll n;
		cin >> n;

		vector<ll> l(n);
		for(ll j=0;j<n;j++)
			cin >> l[j];

		ll ans=0;
		for(ll j=0;j<n;j++){
			for(ll k=0;k<n;k++){
				for(ll m=0;m<n;m++){
					if(j!=k && k!=m && m!=j && l[j]!=l[k] && l[k]!=l[m] && l[m]!=l[j]){
						ll maxi=max(l[j],max(l[k],l[m]));
						ll sum=l[j]+l[k]+l[m];
						sum=sum-maxi;
						if(sum>maxi)
							ans++;
					}
				}
			}
		}

		ans=ans/6;
		cout << ans << "\n";
	}
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <map>
#include <string>


using namespace std;



int main() {


	int n = 0;
	string ord,val;
	map<string, int> mp;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> ord >> val;

		if (ord[0] == 'i')
			mp.insert(make_pair(val, 1));

		else if (ord[0] == 'f') {
			auto it = mp.find(val);
			if (it != mp.end()) cout << "yes" << endl;
			else  cout << "no" << endl;
		}

	}

	return 0;
}



Measured memory_bytes: 36908
h,w=list(map(int,input().split()))
maze1=[]
for i in range(h):
  maze1.append(list(input()))
from collections import deque
import copy

#スタートする座標をa,bとしておく
def bfs(a,b):
  maze=copy.deepcopy(maze1)
  dp=[[0 for i in range(w)] for j in range(h)]
  q=deque([[a,b]])
  #まず自分がいるところを＃に変えておく
  maze[a][b]="#"
  while len(q)>0:
    i,j=q.popleft()
    if 0<=i+1<=h-1 and 0<=j<=w-1 and maze[i+1][j]==".":
      maze[i+1][j]="#" 
      dp[i+1][j]=dp[i][j]+1
      q.append([i+1,j])
    if 0<=i-1<=h-1 and 0<=j<=w-1 and maze[i-1][j]==".":
      maze[i-1][j]="#"
      dp[i-1][j]=dp[i][j]+1
      q.append([i-1,j])
    if 0<=i<=h-1 and 0<=j-1<=w-1 and maze[i][j-1]==".":
      maze[i][j-1]="#"
      dp[i][j-1]=dp[i][j]+1
      q.append([i,j-1])
    if 0<=i<=h-1 and 0<=j+1<=w-1 and maze[i][j+1]==".":
      maze[i][j+1]="#"
      dp[i][j+1]=dp[i][j]+1
      q.append([i,j+1])
  sum=0
  for i in range(h):
    sum=max(max(dp[i]),sum)
  return sum
  
  
ans=0
for k in range(h):
  for l in range(w):
    if maze1[k][l]==".":
      ans=max(bfs(k,l),ans)

print(ans)

      
    
    
      
  
    
  

Measured memory_bytes: 3444
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

#define size_t int
typedef long long ll;
// #define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main(signed argc, char **argv) {
  int A, B;
  cin >> A >> B;
  int max = A > B ? A : B;
  int min = A < B ? A : B;
  if (max - 1 > min) {
    cout << 2*max - 1 << endl;
  } else {
    cout <<  max + min << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <functional>
#include <tuple>
 
using namespace std;
 
#define rep(i,x) for(int i=0;i<x;++i)
#define fst first
#define scd second
 
using pii=pair<int,int>;
using vpii=vector<pii>;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
 
using data=tuple<int, int, int>;
 
struct edge{
    int to, cost, id;
};
 
vector<edge> G[105];
bool used[1005];
int d[105];
 
void dijkstra(int s)
{
    fill_n(d, 105, 1e9);
    priority_queue<data, vector<data>, greater<data>> q;
 
    d[s]=0;
 
    q.push(data(0, s, 1001));
 
    while (q.size()) {
        data dat = q.top(); q.pop();
 
        int sum, v, eid;
        tie(sum, v, eid) = dat;
 
        if (d[v] < sum) continue;
        used[eid] = true;
 
        for (edge e : G[v]) {
            if (d[e.to] >= d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                q.push(data(d[e.to], e.to, e.id));
            }
        }
    }
}
 
signed main()
{
    int N, M; cin >> N >> M;
 
    rep(i, M) {
        int a, b, c; cin >> a >> b >> c;
        --a, --b;
 
        G[a].push_back(edge{b, c, i});
        G[b].push_back(edge{a, c, i});
    }
 
    rep(i, N) dijkstra(i);
 
    int ans = 0;
 
    rep(i, M) {
        if (!used[i]) ans++;
    }
 
    cout << ans << endl;
}

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

MAX = 2*10**5+100
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
    
for i in range(2, MAX):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD

def C(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD
    
N = int(input())
x = list(map(int, input().split()))
ans = 0
acc = [0]

for i in range(N-1):
    acc.append((acc[-1]+C(N-1, i+1)*fact[i]*fact[N-1-(i+1)])%MOD)

for i in range(N-1):
    d = x[i+1]-x[i]
    ans += d*acc[i+1]
    ans %= MOD
    """
    for j in range(i+1):
        ans += d*C(N-1, j+1)*fact[j]*fact[N-1-(j+1)]
        ans %= MOD
    """
print(ans)

Measured memory_bytes: 96520