akhauriyash/Code-Regression huggingface dataset:
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

//#define DEBUG

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> c(n);
    vector<vector<int>> tree(n+1);
    fori(n-1) {
        int a, b;
        cin>>a>>b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

#ifdef DEBUG
cout<<"didread tree"<<endl;
#endif
    auto vcmp=[&](int i1, int i2) {
            return tree[i2].size()<tree[i1].size();
    };

    fori(n) {
        cin>>c[i];
        /* sort childs by number of edges desc. */
        sort(tree[i+1].begin(), tree[i+1].end(), vcmp);
    }
#ifdef DEBUG
cout<<"didread c"<<endl;
#endif

    sort(c.begin(), c.end(), greater<int>());

    /* find fattest vertex in tree, use as root. */
    int fat=1;
    int fatsz=(int)tree[fat].size();
    for(int i=2; i<=n; i++) 
        if((int)tree[i].size()>fatsz) {  
            fatsz=(int)tree[i].size();
            fat=i;
        }

#ifdef DEBUG
cout<<"didfind fat"<<endl;
#endif
    int cidx=0;
    vector<int> ans(n+1);
    function<ll(int, int)> dfs=[&](int vertex, int parent) {
        ans[vertex]=c[cidx];
#ifdef DEBUG
cout<<"dfs, vertex="<<vertex<<" parent="<<parent<<" cidx="<<cidx<<" ans[vertext]="<<ans[vertex]<<endl;
#endif
        cidx++;
        ll sum=0;
        for(int chld : tree[vertex])
            if(chld!=parent) {
                sum+=dfs(chld, vertex);
                sum+=min(ans[vertex], ans[chld]);
            }
        return sum;
    };

    ll ans2=dfs(fat, -1);
#ifdef DEBUG
cout<<"did dfs"<<endl;
#endif
    cout<<ans2<<endl;
    for(int i=1; i<=n; i++) 
        cout<<ans[i]<<" "<<endl;
    cout<<endl;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  int a[4][4];
  bool d[4][4];
  rep(i,3)rep(j,3)
    d[i][j]=0;
  rep(i,3)rep(j,3)
    cin>>a[i][j];
  int b;
  cin>>b;
  vector<int>c(b);
  rep(i,b)
    cin>>c[i];
  rep(i,b){
    rep(j,3)rep(k,3){
      if(a[j][k]==c[i])
        d[j][k]=1;
  }
  }
  bool ans=0;
  rep(i,3){
    if(d[i][0]&&d[i][1]&&d[i][2])
      ans=1;
      }
  rep(i,3){
 if(d[0][i]&&d[1][i]&&d[2][i])
      ans=1;
  }
    
  if((d[0][0]&&d[1][1]&&d[2][2])||(d[0][2]&&d[1][1]&&d[2][0])||ans){
  cout<<"Yes"<<endl;
  }
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
string s;
ll dfs(string s, int n){
    //cout<<s.size()<<s<<"\n";

    if(s.size()==n+1){
        //cout<<s<<"\n";
        ll ans=0;
        int count=-1;
        for(int i=0;i<n+1;i++){
            if(s[i]=='+'){
                //cout<<atoi(s.substr(count+1,i-count).c_str())<<"\n";
                //cout<<s<<"\n";
                ans+=atoll(s.substr(count+1,i-count).c_str());
                count=i;
            }
            else if(i==n){
                ans+=atoll(s.substr(count+1,i-count).c_str());
            }
        }
        //cout<<ans<<"\n";
        return ans;
    }
    if(s[n]!='+'){
    string temp=s;
    ll a=dfs(temp.insert(n+1,"+"),n+1);
    ll b=dfs(s,n+1);
    return a+b;
    }
    else{
        return dfs(s,n+1);
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    cout<<dfs(s,0)<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<queue>
using namespace std;
int main()
{
	int n, m;
	int t;
	priority_queue<int> q;
	long long ans = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> t;
		q.push(t);
	}
	while (m--)
	{
		t = q.top() / 2;
		q.pop();
		q.push(t);
	}
	while (!q.empty())
	{
		ans += q.top();
		q.pop();
	}
	cout << ans;
	return 0;
}



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

int main(void){
    int m1, m2, d1, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (d2 == 1) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		
		while(true) {
			int a = s.nextInt();
			String op = s.next();
			int b = s.nextInt();
			
			if(op.equals("+")) {
				System.out.println(a+b);
			} else if(op.equals("-")) {
				System.out.println(a-b);
			} else if(op.equals("*")) {
				System.out.println(a*b);
			} else if(op.equals("/")) {
				System.out.println(a/b);
			} else {
				break;
			}
			
		}
		s.close();
	}

}

Measured memory_bytes: 26260
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

ll n, m, q;
vector<ll> a, b, c, d;
ll ans;

void dfs(vector<ll> A){
  if(A.size() == n+1){
    ll now = 0;
    REP(i, q){
      if(A[b[i]]-A[a[i]] == c[i]) now += d[i];
    }
    chmax(ans, now);
    return;
  }

  A.emplace_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
}

int main(void){
  cin >> n >> m >> q;
  a = b = c = d = vector<ll>(q);
  REP(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs(vector<ll>(1, 1));
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    vector<int> num(26, 0);
    for (int i = 0; i < H; ++i) {
        cin >> a[i];
        for (char c : a[i]) {
            num[c - 'a']++;
        }
    }
    int odd_num = 0, num4 = 0;
    for (int i = 0; i < 26; ++i) {
        num4 += num[i] / 4;
        if (num[i] % 2 == 1) {
            odd_num++;
        }
    }

    int h = (H % 2 == 0 ? H / 2 : (H - 1) / 2);
    int w = (W % 2 == 0 ? W / 2 : (W - 1) / 2);

    if (odd_num == (H % 2 == 1 && W % 2 == 1)
            && h * w <= num4)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

int n;
db d,x,res;

void Work(int n,db d,db x){
	if (n==0) return;
	res+=(d+d+(2*n-1)*x)/2;
	db l,r;
	l=((2*n-2)*d+d+2*x+3*d+3*x)/2/n;
	r=((2*n-2)*(d+(2*n-1)*x)+d+(2*n-3)*x+3*d+(6*n-6)*x)/2/n;
	Work(n-1,l,(r-l)/(2*(n-1)-1));
}

int main(){
	n=IN();
	scanf("%lf%lf",&d,&x);
	Work(n,d,x);
	printf("%.20lf\n",res);
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
A = list(map(int,input().split()))

mod = 10**9 + 7
l = 10**5 + 3

M = [1]  # i!のmod
m = 1
for i in range(1, l):
    m = (m * i) % mod
    M.append(m)

def pow(x, y, mod):  # x**y の mod を返す関数
    ans = 1
    while y > 0:
        if y % 2 == 1:
            ans = (ans * x) % mod
        x = (x**2) % mod
        y //= 2
    return ans

def inv(x, mod):  # x の mod での逆元を返す関数
    return pow(x, mod-2, mod)

# print(inv(8,13))

MI = [0] * (l-1) +[inv(M[l-1], mod)]  # i!の逆元
for i in range(l-2, -1, -1):
    MI[i] = MI[i+1] * (i+1) % mod

def C(x, y):  # コンビネーション
    if x<y:
        return 0
    ans = M[x]
    ans = (ans * MI[y]) % mod
    return (ans * MI[x-y]) % mod

A.sort()
ans = 0
for i in range(n-1):
    ans = (ans + (A[i+1]-A[i])*(C(n,k) - C(i+1,k) - C(n-i-1, k))%mod)%mod
    # print(C(n,k) - C(i+1,k) * C(n-i-1, k))
print(ans)

Measured memory_bytes: 62376
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;



auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}

ll dp[21+1][(int)pow(2,21)];
bool a[21][21];
int n;

ll fdp(int ind,int bin)
{
	if(dp[ind][bin]!=-1)
		return dp[ind][bin];
	dp[ind][bin]=0;
	fo(i,n)
	{
		//cout<<i<<endl;
		//if(bin&(1<<i))
		//	cout<<i<<endl;
		if((bin&(1<<i)) && a[ind-1][i])
		{
			dp[ind][bin]+=fdp(ind-1,bin-(1<<i));
		}
	}
	dp[ind][bin]%=mod;
	return dp[ind][bin];
}

signed main()
{
	fio
	cin>>n;
	fo(i,n)
		fo(j,n)
			cin>>a[i][j];
	memset(dp,-1,sizeof(dp));
	dp[0][0]=1;
	cout<<fdp(n,(int)(pow(2,n)-1))<<'\n';
	//cout<<fdp(1,2)<<endl;
	printclock;
}

Measured memory_bytes: 360832
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;

/**
 * Walking in JOI Kingdom
 */
public class Main {

	static final int EAST = 1;
	static final int WEST = -1;
	static final long NONSTOP = (long) Math.pow(10, 18) + 1;

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

		words = br.readLine().split(" ");

		int N, Q;
		long T;
		N = parseInt(words[0]);
		T = parseLong(words[1]);
		Q = parseInt(words[2]);

		long[] pos = new long[N];
		int[] dir = new int[N];
		long[] stop = new long[N];

		for (int i = 0; i < N; i++) {
			words = br.readLine().split(" ");
			pos[i] = parseLong(words[0]);
			dir[i] = parseInt(words[1]) == EAST ? EAST : WEST;
			stop[i] = NONSTOP;
		}

		//solve
		for (int i = 1; i < N - 1; i++) {
			if (dir[i] == EAST) {
				if (dir[i + 1] == WEST) {
					stop[i] = stop[i + 1] = (pos[i + 1] - pos[i]) / 2;
				}
			} else {
				if (dir[i - 1] == EAST) {
					stop[i - 1] = stop[i] = (pos[i] - pos[i - 1]) / 2;
				}
			}
		}

		for (int i = 0; i < N; i++) {
			if (stop[i] == NONSTOP) {
				if (dir[i] == EAST) {
					for (int j = i + 1; j < N; j++) {
						if (stop[j] != NONSTOP) {
							stop[i] = pos[j] - pos[i] + stop[j];
							break;
						}
					}
				} else {
					for (int j = i - 1; j >= 0; j--) {
						if (stop[j] != NONSTOP) {
							stop[i] = pos[i] - pos[j] + stop[j];
							break;
						}
					}
				}
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < Q; i++) {
			int q = parseInt(br.readLine()) - 1;
			if (T < stop[q]) {
				sb.append(pos[q] + dir[q] * T).append('\n');
			} else {
				sb.append(pos[q] + dir[q] * stop[q]).append('\n');
			}
		}
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 65080
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll n,m,i,j,k,x,t;
 while(cin>>n)
 {
   string s;
   map<string,ll>mp;
   map<string,ll>::iterator it;
   for(i=0;i<n;i++)
   {
     cin>>s;
     sort(s.begin(),s.end());
     mp[s]++;

   }
   ll ans=0;

   for(it=mp.begin();it!=mp.end();it++)
   {
     ans+=(it->second*(it->second-1))/2;
   }
   cout<<ans<<endl;
 }
  return 0;
}



Measured memory_bytes: 11136
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
string n;int k;
int check(int x,int y){
	if(x<y)RE 0;
	int re=1;
	FOR(i,1,y)re*=x-i+1;
	FOR(i,2,y)re/=i;
	FOR(i,1,y)re*=9;
	RE re;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>k;
	int l=n.size();
	int ans=0;
	rep(i,0,l){
		if(n[i]>'0'){
			ans=ans+check(l-i-1,k);
			ans=ans+check(l-i-1,k-1)*(n[i]-'0'-1);
			k--;
		}
		if(!k){
			ans++;break;
		}
	}
	cout<<ans;
	RE 0;
}



Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
static ll p = 1000000007;

int main(){
  int n,m; cin >> n >> m;
  bool broken[n+1];
 fill(broken,broken+n+1,false);
  REP(i,m){
    int a; cin >> a;
    broken[a] = true;
  }
  ll dp[n+1];
  dp[0] = 1;
  dp[1] = broken[1] ? 0 : 1;
  for(int i = 2; i <= n; i++){
    dp[i] = broken[i] ? 0 : dp[i-1]+dp[i-2];
    dp[i] %= p;
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main(void)
{
	string a;cin >> a;
	if (a == "abc" ||a == "acb" || a == "bac" || a == "bca"||a == "cab" || a == "cba")
	{
		cout << "Yes" << "\n";
	}
	else{
		cout << "No" << "\n";
	}
}


Measured memory_bytes: 256
# 2019/08/10

import sys
input=sys.stdin.readline
from collections import Counter

n=int(input())
s=[]
for i in range(n):
    a=sorted(list((input().rstrip('\n'))))
    a=''.join(a)
    s.append(a)
c=Counter(s)

cnt=0
for k,v in c.items():
    if v>1:
        cnt+=v*(v-1)//2

print(cnt)

Measured memory_bytes: 19728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

int main() {
    string s;
    cin >> s;
    if (s[s.size()-1] == 's') s = s + "es";
    else s = s + "s";
    cout << s << endl;
}

Measured memory_bytes: 3624
/*
  Author: Alokit Kumar
  */
  #include<bits/stdc++.h>
  using namespace std;
  #define int long long
  int32_t main()
  {
    int t,n,i,j,k,l,l1,r,d;
    cin>>l>>r>>d;
    j=(l+d-1)/d;
    k=r/d;
    l=k-j+1;
    if(l<=0) cout<<"0";
    else cout<<l;
  }

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  string s;
  cin >> s;
  int k=s.size();
  vector<int> a(k);
  s +='R';
  a[k-1]==0;
  int n=-1,m,t;
  for(int i=0;i<k;i++){
    if(s[i]=='R'&&s[i+1]=='L'){
      t=i;
    }
    else
      a[i]==0;
    if(s[i]=='L'&&s[i+1]=='R'){
      m=i;
      a[t]=1+(m-t)/2+(t-n-1)/2;
      a[t+1]=m-n-a[t];
      n=m;
    }
  }
  for(int i=0;i<k-1;i++){
    cout << a[i] << " ";
  }
  cout << a[k-1] << endl;
}

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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000000
#define INFL 10000000000000000LL
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>


int main() {
  int n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];
  ll os = 0, es = 0;
  vector<int> op, ep;
  REP(i, n){
    if(i%2 == 0 && a[i]>0){
      es += a[i];
      ep.pb(i);
    }
    if(i%2 == 1 && a[i]>0){
      os += a[i];
      op.pb(i);
    }
  }
  if(os == 0 && es == 0){
    ll mn = -1000000001;
    ll ind = 0;
    REP(i, n){
      if(mn < a[i]){
        ind = i;
        mn = a[i];
      }
    }
    cout << mn << endl;
    cout << n-1 << endl;
    REP(i, ind) cout << 1 << endl;
    REP(i, n-1-ind) cout << n-ind-i << endl;
  }
  else if(os > es){
    cout << os << endl;
    vector<int> ans;
    REP(i, op[0]) ans.pb(1);
    REP(i, op.size()-1){
      int dif = op[i+1]-op[i];
      dif /= 2;
      REP(j, dif-1) ans.pb(3);
      ans.pb(2);
    }
    REP(i, n-1-op[op.size()-1]) ans.pb(n-op[op.size()-1]-i);
    cout << ans.size() << endl;
    for(int e: ans) cout << e << endl;
  }
  else{
    cout << es << endl;
    vector<int> ans;
    REP(i, ep[0]) ans.pb(1);
    REP(i, ep.size()-1){
      int dif = ep[i+1]-ep[i];
      dif /= 2;
      REP(j, dif-1) ans.pb(3);
      ans.pb(2);
    }
    REP(i, n-1-ep[ep.size()-1]) ans.pb(n-ep[ep.size()-1]-i);
    cout << ans.size() << endl;
    for(int e: ans) cout << e << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    int n;
    cin>>n;
    int max_val=0;
    int max_pos=0;
    for(int i=1;i<n;i++){
        cout<<"? "<<1<<" "<<i+1<<endl;
        int res;
        cin>>res;
        if(res>max_val){
            max_val = res;
            max_pos = i;
        }
    }
    vector<int> ans(n);
    ans[0] = max_pos;
    rep(i,n){
        if(i==max_pos)continue;
        cout<<"? "<<max_pos+1<<" "<<i+1<<endl;
        int res;
        cin>>res;
        ans[res]=i;
    }
    cout<<"!";
    rep(i,n)cout<<" "<<ans[i]+1;
    cout<<endl;
}

Measured memory_bytes: 3608
main=do
 getLine
 d<-map read.words<$>getLine
 let k=length d
 ans<-unlines.map(show.(\[n,x,m]->n-1-div(x`mod`m+sum[(m-(-e)`mod`m)*div(n-i+k)k|(e,i)<-zip d[2..]])m).map read.words).lines<$>getContents
 putStr ans

Measured memory_bytes: 5500
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
typedef pair<int, int> PR;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//cout<<""<<endl;
int main(){
  int N,M;cin>>N>>M;
  vi a(M),b(M);
  vvb G(9,vb (9));
  rep(i,9){
    rep(j,9){
      G[i][j]=false;
    }
  }
  rep(i,M){
    cin>>a[i]>>b[i];
    G[a[i]][b[i]]=true;
    G[b[i]][a[i]]=true;
  }
  vi num(N);
  rep(i,N)num[i]=i+1;
  int cnt=0;
  do {
    bool ok=true;
    for(int i=0;i<N;i++){
      if(i==0){
        if(num[0]!=1)ok=false;
      }
      if(i!=N-1){
        if(!G[num[i]][num[i+1]]){
          ok=false;
          break;
        }
      }
    }
    if(ok)cnt++;
  } while (next_permutation(num.begin(), num.end()));
  cout<<cnt<<endl;
}






Measured memory_bytes: 3696
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;

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

    int w,h;
    int dx[8]={1,1,1,0,-1,-1,-1,0},dy[8]={-1,0,1,1,1,0,-1,-1};
    while(cin>>w>>h,w||h){
        vector< vector<int> > field(h,vector<int>(w));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>field[i][j];
            }
        }
        int res=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(field[i][j]){
                    //cout<<i<<" "<<j<<endl;
                    queue<P> q;
                    field[i][j]=0;
                    q.push(P(i,j));
                    while(!q.empty()){
                        P p=q.front();q.pop();
                        for(int k=0;k<8;k++){
                            int nx=p.first+dx[k],ny=p.second+dy[k];
                            if(nx<0||h<=nx||ny<0||w<=ny) continue;
                            if(field[nx][ny]==0) continue;
                            field[nx][ny]=0;
                            q.push(P(nx,ny));
                        }
                    }
                    res++;
                }
            }
        }
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3144
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())
    
    print('ACL' * K)
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61796
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// 解説AC http://drken1215.hatenablog.com/entry/2019/02/04/013700
// ans = max(dp[39][0], dp[39][1])
// smaller(0: not smaller)
ll dp[41][2];

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, k;
    cin >> n >> k;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    rep(dig, 40){
        ll mask = 1ll << (39-dig);
        int cnt = 0;
        rep(i, n) if(a[i]&mask) cnt++;
        // スコアのうち，ビットdigの寄与
        ll score0 = mask*cnt;
        ll score1 = mask*(n-cnt);
        if(dp[dig][1] != -1){
            chmax(dp[dig+1][1], dp[dig][1] + max(score0, score1));
        }
        if(dp[dig][0] != -1 && (k & mask)){
            chmax(dp[dig+1][1], dp[dig][0] + score0);
            chmax(dp[dig+1][0], dp[dig][0] + score1);
        }
        if(dp[dig][0] != -1 && !(k & mask)){
            chmax(dp[dig+1][0], dp[dig][0] + score0);
        }
    }
    cout << max(dp[40][0], dp[40][1]) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
bool check (char);

int main() {
    string s;
    cin >> s;
    char first_letter = s[0];
    int ans = check(first_letter) ? 1 : 0;
    int count = ans;
    for (int i = 1; i < s.size(); i++) {
        if ((check(s[i - 1]) && check(s[i])) || (count == 0 && check(s[i]))) {
           count++; 
           ans = (ans < count) ? count: ans;
        }else {
            count = 0;
        }
    }
    cout << ans << endl;
}

bool check (char c) {
    if (c == 'A' || c == 'T' || c == 'G' || c == 'C') {
        return true;
    } else {
        return false;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define whatis(x) cout << #x << " is " << x << endl;
#define MOD 1000000007
#define endl "\n"
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MAX 100001
#define N 101
using namespace std;

vector<int> weight(MAX);
vector<int> value(MAX);
ll k[N][MAX];

ll knapsack(int n, int wmax)
{
    for (int i = 0; i <= n; i++)
    {
        for (int w = 0; w <= wmax; w++)
        {
            if (i == 0 || w == 0)
                k[i][w] = 0;
            else if (weight[i-1]<=w)
                k[i][w] = max(k[i-1][w] , value[i - 1] + k[i - 1][w - weight[i - 1]]);
            else
                k[i][w]=k[i-1][w];
        }
    }
    return k[n][wmax];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, i, j, wmax;
    cin >> n >> wmax;
    for (i = 0; i < n; i++)
        cin >> weight[i] >> value[i];
    ll ans = knapsack(n, wmax);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80000
n = int(input())
a = list(map(int, input().split()))
d = {}
for i,j in enumerate(a):
    d[j] = i

uf = [-1]*n
def root(a):
    if uf[a] < 0:
        return a
    uf[a] = root(uf[a])
    return uf[a]
def unite(a,b):
    ra,rb = root(a),root(b)
    if ra==rb:
        return False
    if uf[ra] > uf[rb]:
        ra,rb = rb,ra
    uf[ra] += uf[rb]
    uf[rb] = ra
    return True

ans = 0
for i in range(n,0,-1):
    left=right=0
    ind = d[i]

    if ind<n-1 and a[ind] < a[ind+1]:
        right -= uf[root(ind+1)]
        unite(ind, ind+1)
    if ind>0 and a[ind] < a[ind-1]:
        left -= uf[root(ind-1)]
        unite(ind, ind-1)
    ans += i*(left+1)*(right+1)

print(ans)

Measured memory_bytes: 38100
#include <iostream>
#include <set>
#include <vector>
#include <climits>
#include <algorithm>
#include <cstring>
using namespace std;

int n, m;
int x[5002], y[5002];
int sum[5002][5002];
set<int> setx, sety;
vector<int> vx, vy;

int main(){
  while(cin >> n >> m){
    setx.clear();
    sety.clear();

    setx.insert(INT_MIN);
    sety.insert(INT_MIN);

    for(int i = 0; i < n; i++){
      cin >> x[i] >> y[i];
      setx.insert(x[i]);
      sety.insert(y[i]);
    }

    vx.clear();
    vy.clear();

    for(set<int>::iterator iter = setx.begin(); iter != setx.end(); iter++){
      vx.push_back(*iter);
    }
    for(set<int>::iterator iter = sety.begin(); iter != sety.end(); iter++){
      vy.push_back(*iter);
    }

    memset(sum, 0, sizeof(sum));

    for(int i = 0; i < n; i++){
      int idxx = find(vx.begin(), vx.end(), x[i]) - vx.begin();
      int idxy = find(vy.begin(), vy.end(), y[i]) - vy.begin();
      sum[idxx][idxy]++;
    }

    for(int i = 1; i < vx.size(); i++){
      for(int j = 1; j < vy.size(); j++){
        sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      }
    }

    /*
    for(int i = 0; i < vx.size(); i++){
      for(int j = 0; j < vy.size(); j++){
        printf("%3d", sum[i][j]);
      }
      cout << endl;
    }
    */

    for(int i = 0; i < m; i++){
      int lx, ly, hx, hy;
      cin >> lx >> ly >> hx >> hy;

      int idx_lx = lower_bound(vx.begin(), vx.end(), lx) - vx.begin();
      int idx_ly = lower_bound(vy.begin(), vy.end(), ly) - vy.begin();
      int idx_hx = upper_bound(vx.begin(), vx.end(), hx) - vx.begin() - 1;
      int idx_hy = upper_bound(vy.begin(), vy.end(), hy) - vy.begin() - 1;

      if(idx_lx > idx_hx || idx_ly > idx_hy){
        cout << 0 << endl;
        continue;
      }

      //cout<<idx_lx<<", "<<idx_ly<<", "<<idx_hx<<", "<<idx_hy<<endl;

      int calc =
        sum[idx_hx    ][idx_hy    ] -
        sum[idx_lx - 1][idx_hy    ] -
        sum[idx_hx    ][idx_ly - 1] +
        sum[idx_lx - 1][idx_ly - 1];

      cout << calc << endl;
    }
  }
}

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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
const int mod = 1000000007;

map<ll, int> factorize(ll n) {
    map<ll, int> res;

    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        res[i] = 0;
        while (n % i == 0) {
            n /= i;
            res[i]++;
        }
    }

    if (n != 1) res[n] = 1;
    return res;
}

ll comb(ll l, ll r) {
    map<ll, ll> factors;
    for (ll j = l; j > (l - r); j--) {
        auto fs = factorize(j);
        for (auto f : fs) {
            factors[f.first] += f.second;
        }
    }

    for (ll j = 1; j <= r; j++) {
        auto fs = factorize(j);
        for (auto f : fs) {
            factors[f.first] -= f.second;
        }
    }

    ll s = 1;

    for (auto e : factors) {

        for (int k = 0; k < e.second; k++) {
            s *= e.first;
        }
    }

    return s;
}


ll f(ll a, ll b, ll c) {
    ll ans = 0;
    for (ll i = a; i <= b; i++) {
        ll now = comb(c, i);
        ans += now;
    }
    return ans;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    vector<ll> items(n);
    rep(i, n) cin >> items[i];
    sort(items.rbegin(), items.rend());

    double sum = accumulate(items.begin(), items.begin() + a, 0ll);

    printf("%.20f\n", sum / a);

    ll k = items[a - 1];
    int c = count(items.begin(), items.end(), k);

    if (k == items.front()) {
        ll p = f(a, b, c);
        cout << p << endl;
    } else {
        int g = count_if(items.begin(), items.end(), [&](ll i) { return i > k; });
        ll p = comb(c, a - g);
        cout << p << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    string S;
    cin >> S;

    int ret = 0;
    FOR(i, 1, SZ(S)) {
        string left = S.substr(0, i);
        if (SZ(left) % 2 != 0)
            continue;
        int s = SZ(left) / 2;
        if (left.substr(0, s) == left.substr(s))
            ret = max(ret, s);
    }
    cout << ret * 2 << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

struct Tree {
	Tree* left, * right;
	int val;
};

int num(const string&, int&);
Tree* t(const string&, int&);

Tree* t(const string& s, int& i) {
	if (s[i] == ')')return NULL;

	Tree* res = new Tree;
	i++;
	res->left = t(s, i);
	i++;

	assert(s[i] == '[');
	i++;
	res->val = num(s, i);
	i++;

	i++;
	res->right = t(s, i);
	i++;
	return res;
}
int num(const string& s, int& i) {
	int res = 0;
	while (s[i] != ']') {
		res *= 10;
		res += s[i] - '0';
		++i;
	}
	return res;
}

Tree* merge(Tree* a, Tree* b) {
	Tree* res = new Tree;
	res->left = NULL;
	res->right = NULL;
	res->val = a->val + b->val;
	if (a->left != NULL && b->left != NULL)res->left = merge(a->left, b->left);

	if (a->right != NULL && b->right != NULL)res->right = merge(a->right, b->right);
	return res;
}

string to_string(Tree* a) {
	if (a == NULL)return "";
	return "(" + to_string(a->left) + ")" + "[" + to_string(a->val) + "]" + "(" + to_string(a->right) + ")";
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a, b;
	cin >> a >> b;
	int pos = 0;
	auto ta = t(a, pos);
	pos = 0;
	auto tb = t(b, pos);
	auto ans = merge(ta, tb);
	cout << to_string(ans) << endl;
}


Measured memory_bytes: 3316
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a: u8 = read(&mut stdin_lock, &mut buf, b' ');
    let b: u8 = read(&mut stdin_lock, &mut buf, b' ');
    let x: u8 = read(&mut stdin_lock, &mut buf, b'\n');
    let ans = if a <= x && x <= a + b { "YES" } else { "NO" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;

    int64_t d = std::max(std::abs(x1 - x2), std::abs(y1 - y2));

    int64_t x3, y3, x4, y4;
        x3 = x2 - (y2-y1);
        y3 = y2 + (x2-x1);

        x4 = x3 - (x2-x1);
        y4 = y3 - (y2 - y1);
    
    std::cout <<  x3 << " " << y3 << " " << x4 << " " << y4;
#if 0
    if (x1 < x2) {
        x3 = x2 - (y2-y1);
        y3 = y2 + (x2-x1);

        x4 = x3 - (x2-x1);
        y4 = y3 - (y2 - y1);
    }
    else if (x2 < x1) {
        x3 = x2 - (y2-y1);
        y3 = x2 - (x2-x1);

        x4 = x2 
           
#endif

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<48


def solve(N: int):
    # 約数の全列挙
    def divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n//i)
        # divisors.sort(reverse=True)  # ソート
        return divisors

    l = divisors(N)
    l.append(1)
    l.sort()

    ans = INF

    for i in l:
        M = N // i
        ans = min(ans, M+i-2)

    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3272
S = input()

if len(S) == 1:
    print(0)
else:
    if S.count("0")== S.count("1"):
        print(S.count("0")*2)
    else:
        print(len(S)-(max(S.count("0"),S.count("1")) - min(S.count("0"),S.count("1"))))

Measured memory_bytes: 3188
#include<stdio.h>
int main(){
	int n,x[101],m,a,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&x[i]);
	x[n]=0;
	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%d",&a);
		if(x[a-1]!=2019&&x[a-1]+1!=x[a])x[a-1]++;
	}
	for(i=0;i<n;i++)printf("%d\n",x[i]);
	return 0;
}


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

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

    int a, b, m;
    cin >> a >> b >> m;

    long long mia = 1e18, mib = 1e18;
    map<int, long long> ma, mb;
    for(int i = 0; i < a; i++){
        long long x;
        cin >> x;
        ma[i + 1] = x;
        mia = min(mia, x);
    }
    for(int i = 0; i < b; i++){
        long long x;
        cin >> x;
        mb[i + 1] = x;
        mib = min(mib, x);
    }

    long long ans = 1e18;
    for(int i = 0; i < m; i++){
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, ma[x] + mb[y] - c);
    }

    ans = min(ans, mia + mib);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12800
#include<iostream>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<stdio.h>
#define cle(n) memset(n,0,sizeof(n))
typedef long long  ll;
typedef unsigned long long ull;
const int inf=100000000;
const long long mod=1e9+7;
const long long maxn =1e5+10;
using namespace std;

unsigned long long n,m,a,b;

int main()
{
   while(cin>>n)
   {
       cin>>a>>b;
       if(n==1&&b>a)
       {
           cout<<0<<endl;continue;
       }
       if(a>b)
       {
           cout<<0<<endl;continue;
       }
       if(a==b)
       {
           cout<<1<<endl; continue;
       }
  unsigned long long  ans=(n-1)*b+a-((n-1)*a+b)+1;
  
  if(ans<0)
  {
      cout<<0<<endl;continue;
  }
  else
       cout<<ans<<endl;
   }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
int n,k,w[N],q[N];
int main(){
	cin>>n>>n;
	for(int i=1;i<=n;i++) cin>>w[i];
	for(int i=1;i<=n;i++) if(w[i]%2==1) swap(w[1],w[i]);
	for(int i=2;i<=n;i++) if(w[i]%2==1) swap(w[n],w[i]);
	for(int i=2;i<n;i++) if(w[i]%2==1) k++;
	if(k>0){
		puts("Impossible"); return 0;
	}
	for(int i=1;i<=n;i++) cout<<w[i]<<" "; cout<<endl;
	w[1]--; if(n==1) w[++n]=1; else w[n]++;
	for(int i=1;i<=n;i++) if(w[i]) q[++q[0]]=w[i];
	cout<<q[0]<<endl;
	for(int i=1;i<=q[0];i++) cout<<q[i]<<" "; cout<<endl;
}

Measured memory_bytes: 2304
N = gets.to_i
As = gets.split.map(&:to_i)

a1, a2, *rs = As
s = a1 + a2
t =  rs.inject(0, :^)
ans = -1
if s >= t && (s - t)[0] == 0
  y = (s - t)/2
  z = s - y*2
  if y <= a1 && (z & y) == 0
    r = y
    60.downto(0){|i| r |= 1<<i if z[i] == 1 && r + (1<<i) <= a1}
    ans = a1 - r if r > 0
  end
end
puts ans

Measured memory_bytes: 14388
#include<iostream>
typedef long long ll;

using namespace std;

int main()
{
    ll n,x,t;
    cin>>n>>x>>t;
    if(n%x==0)
    {
        cout<<(n/x)*t<<endl;
    }
    else
    {
    cout<<((n/x)+1)*t<<endl;
    }
}


Measured memory_bytes: 3160
#include<iostream>
int main(void)
{
    int n=32;
    int a[n]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    std::cin>>k;
    std::cout<<a[k-1];
}


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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int res = 0;
    int m = 0;
    rep(i,n-1){
        if(h[i] >= h[i+1])res++;
        else{
            res = 0;
        }
      	m = max(m,res);
    }
    cout << m << endl;
}

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

#define rep(i,x) for(i=0;i<x;i++)
#define rrep(i,x) for(i=x-1;i>=0;i--)
#define rep_to(a,i,x) for(i=a;i<x;i++)
#define si_1(x) scanf("%d",&x)
#define si_2(x,y) scanf("%d %d",&x,&y)
#define debug(x) printf("x:%d\n",x)

int main()
{
	int i=0,j=0,n,m;
	int mark,num[114]={};
	int min=0,max=0,len=0;
	int flag=0;

	while(si_2(m,n)!=EOF)
	{
		i=0;
		j=0;
		min=0;
		max=0;
		len=0;
		flag=0;

		if(n==0 && m==0)break;
		rep(i,n)
		{
			si_1(num[i]);
			max+=num[i];
		}
		while(min<=max)
		{
			mark=(min+max)/2;
			flag=0;
			i=0;
			j=0;
			while(1)
			{
				++i;
				len=0;
				for(;j<n;j++)
				{
					if(mark<=len+num[j])
					{
						break;
					}
					else len+=num[j];
				}
				if(i<=m && j==n)//?¶?????????¬?????\??£??????
				{				
					flag=1;
					break;
				}
				else if(i>m)//??\?????????????????£??????
				{
					flag=0;
					break;
				}
			}
			if(flag==0)min=mark+1;
			else if(flag==1)max=mark-1;
		}
		printf("%d\n",(min+max)/2);
	}
	return 0;
}

Measured memory_bytes: 1028
import math
n = input()
lists = [int(i) for i in input().split()]
list.sort(lists)

mid = math.floor((len(lists))/2)
mnnaka = lists[mid]
ikkosita = lists[mid-1]

if(mnnaka==ikkosita):
    print(0)
else:
    print(mnnaka-ikkosita)


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    int n, count = 1, MAX = 0;
    cin >> n;
    vector<int> h(n);
    rep(i, n){
        cin >> h[i];
    }
    MAX = h[0];
    for(int i = 1; i < n; i++){
        if(MAX <= h[i]){
            count++;
            MAX = h[i];
        }
    }
    print(count);
}

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

int pos=0;

void solve(const vector<int> &preorder, const vector<int> &inorder, vector<int> &postorder, 
	int L, int R) {
    if(L<R) {
    int root=preorder[pos++];
    int m = distance(inorder.begin(), find(inorder.begin(), 
    	inorder.end() ,root) );

   solve(preorder, inorder, postorder, L, m);
   solve(preorder, inorder, postorder, m+1, R);
   postorder.push_back(root);
   }
 }

int main(){

	int n;
	cin>>n;
	vector<int> preorder, inorder, postorder;
	int k;    
    for( int i = 0; i < n; ++i ) { 
    	cin >> k; preorder.push_back(k); 
    }
    for( int i = 0; i < n; ++i ) { 
    	cin >> k; inorder.push_back(k); 
    }
    pos=0;
    solve(preorder, inorder, postorder, 0, n);
    
    for( int i = 0; i < postorder.size(); ++i ) {
    	if ( i ) cout << " ";
    	cout << postorder[i];
    }
    cout<<endl;
    
	return 0;
}


Measured memory_bytes: 3168
N = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
res, point = 0, 0
for i in range(N):
    point = sum(a1[:i+1]) + sum(a2[i:N])
    res = max(res, point)
print(res)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> H(N);
	for(int i = 0; i < N; i++)
		cin >> H.at(i);
	int max = H.at(0), sum = 0;
	for(int i = 0; i < N; i++){
		if(H.at(i) >= max){
			sum++;
			max = H.at(i);
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256