akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
   
   
    const int mod=1e9+7;
    const int N=1e6+5; 
   
    bool sortbysec(const pair<pair<ll,ll>,ll> &a, 
                      const pair<pair<ll,ll>,ll> &b) 
        { 
            return (a.second > b.second); 
        } 
        ll powermod(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;
        }
       
        bool isprime(int n) 
        { 
            if (n <= 1)  return false; 
            if (n <= 3)  return true; 
            if (n%2 == 0 || n%3 == 0) return false; 
            for (int i=5; i*i<=n; i=i+6) 
                if (n%i == 0 || n%(i+2) == 0) 
                   return false; 
           return true; 
        }
       
        
     
        int main()
    {
        FAST;
       ll n;
       cin>>n;
       vll a(n);
       for(ll i=0;i<n;i++)
       cin>>a[i];
       ll dp[n+1][n+1]={0};
       for(ll L=n-1;L>=0;L--)
       {
          for(ll R=L;R<n;R++)
          {
              dp[L][R]=max(a[L]-dp[L+1][R],a[R]-dp[L][R-1]);
          }
       }
       cout<<dp[0][n-1];
        return 0;
    }

Measured memory_bytes: 70656
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        string S = ReadLine();

        int ans = 0;
        for (int i = 0; i < N-1; i++)
        {
            string s = S.Substring(i);
            var zalgo = new ZAlgorithm(s);
            for (int j = 0; j < s.Length; j++)
            {
                ans = Max(ans, Min(j, zalgo[j]));
            }
        }
        WriteLine(ans);
    }
}

class ZAlgorithm
{
    private static string S;
    private int[] Same;
    public ZAlgorithm(string s)
    {
        S = s;
        Same = Search();
    }
    static int[] Search()
    {
        int N = S.Length;
        int c = 0;
        var Z = new int[N];
        for (int i = 1; i < N; i++)
        {
            int l = i - c;
            if (i + Z[l] < c + Z[c])
            {
                Z[i] = Z[l];
            }
            else
            {
                int leng = Math.Max(0, c + Z[c] - i);
                while (leng + i < N && S[i + leng] == S[leng])
                {
                    leng++;
                }
                Z[i] = leng;
                c++;
            }

        }
        Z[0] = N;
        return Z;
    }

    public int this[int i] => Same[i];
}


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

int N, arr[200005];

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &arr[i]);
	long long total = 0;
	for (int i = 0; i < N; i++) total += arr[i];
	long long ans = 1000000000000000000ll;
	long long cur = 0;
	for (int i = 0; i < N - 1; i++) {
		cur += arr[i];
		ans = min(ans, abs(cur - (total - cur)));
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    static HashSet<Integer> dic = new HashSet<>();
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for(int i=0;i<n;i++) h[i]=sc.nextInt();
        Arrays.sort(h);
        int ans = Integer.MAX_VALUE;
        for(int i=0;i+k-1<n;i++){
            ans = Math.min(ans,h[i+k-1]-h[i]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50576
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int n;
int d[10][10];

bool bound(int k, long long *length, bool used[], int home[], long long c[], const int n)
{
  bool res = false;
  long long lb;                 // ??????????????¢?´¢?????????
  int t = home[k-1];
  lb = c[k-1];

  int m = 0;
  for (int i=0;i<n;i++)
  {
    if (!used[i])
    {
      m = max(m, d[t][i]);
    }
  }
  // ????????????????????§??????????§£??????????????´???
  if (lb + max(m, n-k+1) >= *length && *length > 0) res = true;
  return res;
}

void dfs(int k, long long *length, bool used[], int home[], long long c[], const int n)
{
  if (k == n)
  {
    if (*length > c[n-1] || *length == 0) *length = c[n-1];
    return;
  }
  else if (k > 0 && *length > 0 && bound(k, length, used, home, c, n)) return;
  else
  {
    for (int i=0;i<n;i++)
    {
      if (!used[i])
      {
        used[i] = true;
        home[k] = i;
        if (k == 0) c[k] = 0;
        else
        {
          c[k] = c[k-1] + d[home[k]][home[k-1]];
          for (int j=k-2;j>=0;j--) c[k] = max(c[k], c[j] + d[home[k]][home[j]]);
        }
        dfs(k+1, length, used, home, c, n);
        used[i] = false;
      }
    }
  }
  return ;
}

int main()
{
  while (1)
  {
    cin >> n;
    if (n == 0) return 0;

    for (int i=0;i<n;i++) for (int j=0;j<n;j++) cin >> d[i][j];
    for (int i=0;i<n;i++) for (int j=0;j<n;j++) d[i][j] = max(d[i][j], d[j][i]);

    long long length = 0;
    bool used[10] = {false, false, false, false, false, false, false, false, false, false};
    int home[10];
    long long c[10];

    dfs(0, &length, used, home, c, n);
    cout << length << endl;
  }
}

Measured memory_bytes: 1156
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------
ll permutation(ll n,ll r)
{
    ll a=1;
    for(ll i=n-r+1;i<=n;i++)
    {a*=i;a%=MOD;}
    return a;
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    int m;cin>>m;
    if(abs(n-m)>=2){
        cout<<0<<endl;
        return 0;
    }
    if(n>m)swap(n,m);
    ll ans=0;
    ans=1;
    
    if(n!=m){

    ans%=MOD;
    ans*=permutation(m, m);
    ans%=MOD;
    ans*=permutation(m-1, n);
    ans%=MOD;
    }
    else{
        ans*=2;
        ans%=MOD;
        ans*=permutation(m, m);
        ans%=MOD;
        ans*=permutation(m, n);
        ans%=MOD;
        
    }
    cout<<ans%MOD<<endl;
    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------







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

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes"<<"\n";
    }
    else{
        cout<<"No"<<"\n";
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <complex>

using namespace std;

const double INF = 1000000;

int main()
{
    for (;;) {
        int n, m;
        complex<double> bb[1000];
        double di[1000][1000];
        int sg[1000][2];

        // read bill
        scanf("%d", &n);
        if (n == 0)
            break;
        for (int i = 0; i < n; ++i) {
            int b, x, y;
            scanf("%d %d %d", &b, &x, &y);
            bb[b - 1] = complex<double>(x, y);
        }

        // eval distance
        // TODO: ビルの番号が 0 から n - 1 と仮定
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < i; ++j) {
                di[i][j] = di[j][i] = abs(bb[i] - bb[j]);
                if (di[i][j] > 50)
                    di[i][j] = di[j][i] = INF;
                //printf("  %d to %d is %f\n", i, j, di[i][j]);
            }
        }

        // read move
        scanf("%d", &m);
        for (int i = 0; i < m; ++i) {
            scanf("%d %d", &sg[i][0], &sg[i][1]);
            --sg[i][0];
            --sg[i][1];
        }

        for (int ci = 0; ci < m; ++ci) {
            double dt[1000];
            bool vi[1000] = {};
            int from[1000] = {};
            for (int i = 0; i < n; ++i)
                dt[i] = INF;

            // Dijkstra
            int p = sg[ci][0];
            dt[p] = 0;
            from[p] = -1;
            for (;;) {
                vi[p] = true;
                //printf("  - search %d\n", p+1);
                for (int j = 0; j < n; ++j) {
                    if (!vi[j] && di[p][j] != INF && dt[j] > dt[p] + di[p][j]) {
                        dt[j] = dt[p] + di[p][j];
                        from[j] = p;
                    }
                }

                int min = INF;
                for (int j = 0; j < n; ++j) {
                    if (!vi[j] && dt[j] < min) {
                        p = j;
                        min = dt[j];
                    }
                }
                if (min == INF)
                    break;
            }

            if (dt[sg[ci][1]] == INF) {
                printf("NA\n");
            } else {
                int i, p, list[1000];
                p = list[0] = sg[ci][1];
                for (i = 1; p != -1; ++i) {
                    p = list[i] = from[p];
                }
                for (i -= 2; i >= 0; --i)
                    printf("%d%c", list[i] + 1, i == 0 ? '\n' : ' ');
            }
        }

    }

    return 0;
}

Measured memory_bytes: 1572
#include<stdio.h>
int main(){

  int n,i,j,a[100],b,min,count=0;

  scanf("%d",&n);

  for(i = 0; i < n;i++){
    scanf("%d",&a[i]);
  }

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

    min = i;

    for(j = i; j < n; j++){

      if(a[j] < a[min]){
	min = j;


      }
    }

    if(i != min){
    	b = a[i];
	a[i] = a[min];
	a[min] = b;
		count++;
    }
  }


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

    if(i == n-1){
      printf("%d\n",a[i]);
      printf("%d\n",count);
      break;
    }

    printf("%d ",a[i]);

  }

  return 0;
}

 



Measured memory_bytes: 2144
#include<stdio.h>

int main(){

  int a,b,d;
  int r;
  double f;

  scanf("%d %d",&a,&b);

  d=a/b;
  r=a%b;
  f= (double) a/(double) b;

  printf("%d %d %lf",d,r,f);
  return 0;
}

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

int main(){
  long N;
  cin >> N;
  vector<long> Member(5);
  for(int i = 0; i < 5; i++) cin >> Member.at(i);
  sort(Member.begin(), Member.end());
  if(Member.at(0) < N){
    if(N % Member.at(0) != 0){
    cout << N / Member.at(0) + 5 << endl;
    }else{
      cout << N / Member.at(0) + 4 << endl;
    }
  }else{
    cout << 5 << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << p.first << " " << p.second;
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  //for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }

  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  if (M == 0) {
    if (K == 0) {
      print("0 0");
    } else {
      print(-1);
    }
    return 0;
  }

  if (M == 1) {
    if (K == 0) {
      print("0 0 1 1");
    } else {
      print(-1);
    }
    return 0;
  }

  ll MX = 1 << M;
  if (K >= MX) {
    print(-1);
    return 0;
  }

  std::vector<ll> vans;
  for(ll i = 0; i < MX; i++) if(i != K) vans.push_back(i);
  vans.push_back(K);
  for(ll i = MX-1; i >= 0; i--) if(i != K) vans.push_back(i);
  vans.push_back(K);

  print(vans);
  return 0;
}


Measured memory_bytes: 8048
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define abs(x) ((x) < 0 ? (-(x)) : (x))
#define rep(i,a,m) for((i) = (a) ; (i) < (m) ; ++(i))
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
#define PI 3.14159265

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;
int a, b, c, i, j, k;
long long ans = 0LL;
long double eps = 1.0E-14;
long long MOD = 1000000007;
int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll a,b,n;
    cin >> a >> b >> n;
    ll x = min(n,b-1);
    cout << (a*x)/b - (a*(x/b)) << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include <limits>
#include <iomanip>
#include <map>

using namespace std;

int main(){
	int n;
	int ans = 0;
	long long int temp;
	
	cin >> n;
	
	vector<pair<long long int,long long int>> v;
	
	for(int i=0;i<n;i++){
		int a,b;
		cin >> a >> b;
		
		v.push_back(make_pair(a+b,a-b));
	}
	
	sort(v.begin(),v.end());
	
	temp = v[0].second;

	for(int i=0;i<n;i++){
		if(v[i].second >= temp){
			temp = v[i].first;
			ans++;
		}
	}
	
	cout << ans << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define N 605

double dp[N][2];
vector<int> adj[N];
double getMaxi(int block,int n) {
	dp[n][0] = 0, dp[n][1] = 1e18;
	for (int i = n - 1; i; --i) {
		double sum = 0, minZero = 1e18, minDiff = 1e18;
		int sz = adj[i].size();
		for (int j = 0; j < sz; ++j) {
			int id = adj[i][j];
			double zero = dp[id][0], one = dp[id][1];
			minDiff = min(minDiff, one - zero);
			minZero = min(minZero, -zero);
			sum += zero;
		}
		dp[i][0] = 1 + sum / sz;
		if (sz >= 2 && block == i) {
			dp[i][0] = 1 + (sum + minZero) / (sz - 1);
		}
	}
	return dp[1][0];
}
int main(void) {
	//solve 
	int n, m; scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int s, t; scanf("%d %d", &s, &t);
		adj[s].push_back(t);
	}
	double ret = 1e18;
	for (int i = n - 1; i; --i) {
		ret = min(ret, getMaxi(i, n));
	}
	printf("%0.9lf\n", ret);
	return 0;
}

Measured memory_bytes: 1408
def bin_search(temp, x, start, end):
	# print(temp)
	ind = -1
	while start <= end:
		middle = (start + end)//2
		# print(start, middle, end, x)
		if x > temp[middle]:
			ind = middle
			end = middle-1
		else:
			start = middle+1
	# print(ind)
	if ind == -1:
		temp += [x]
	else:
		temp[ind] = x




n = int(input())
arr = []
for i in range(n):
	arr += [int(input())]

temp = [arr[0]]
arr.pop(0)
for x in arr:
	bin_search(temp, x, 0, len(temp)-1)

print(len(temp))

Measured memory_bytes: 7836
def main():
    n, d = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(n)]
    ans = 0

    for i in range(n - 1):
        for j in range(i + 1, n):
            dist = 0
            for k in range(d):
                dist += (x[i][k] - x[j][k]) ** 2
            if float(dist ** 0.5).is_integer():
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62720
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if (abs(a-b)>k||abs(a-c)>k||abs(a-d)>k||abs(a-e)>k||abs(b-c)>k||abs(b-d)>k||abs(b-e)>k||abs(c-d)>k||abs(c-e)>k||abs(d-e)>k) {
        cout<<":("<<endl;
    } else {
        cout<<"Yay!"<<endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
	"strings"
)

var (
	suf = []string{"dream", "dreamer", "erase", "eraser"}
)

func hasAnySuffix(s string) string {
	for _, v := range suf {
		if strings.HasSuffix(s, v) {
			return v
		}
	}

	return ""
}

func main() {
	var s string
	fmt.Scan(&s)

	for len(s) > 0 {
		res := hasAnySuffix(s)
		if res == "" {
			fmt.Println("NO")
			os.Exit(0)
		}
		s = strings.TrimSuffix(s, res)
	}

	fmt.Println("YES")
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(){
		loc = weight = 0;
	}
	Info(int arg_loc,int arg_weight){
		loc = arg_loc;
		weight = arg_weight;
	}
	int loc,weight;
};

struct Data{
	Data(int arg_state,int arg_total_cost){
		state = arg_state;
		total_cost = arg_total_cost;
	}
	bool operator<(const struct Data &arg) const{
		return total_cost > arg.total_cost;
	}
	int state,total_cost;
};


int main(){

	int POW[16];
	for(int i = 0; i < 16; i++)POW[i] = pow(2,i);

	int N,init_pos,W;
	scanf("%d %d %d",&N,&init_pos,&W);

	vector<int> V[N+1];
	Info info[15];
	int index = 0,tmp,max_h;

	for(int h = 1; h <= N; h++){
		scanf("%d",&tmp);
		for(int i = 0; i < tmp; i++){
			scanf("%d",&info[index].weight);
			if(h == 1)continue;
			max_h = h;
			info[index].loc = h;
			V[h].push_back(index);
			index++;
		}
	}

	if(index == 0){
		printf("0\n");
		return 0;
	}

	int* min_cost = new int[POW[index]];
	int pre_cost,ans = abs(init_pos-max_h),state = 0,item_num = 0,item_id[index],sum_weight;
	int rest_num,rest_id[index],add_state,not_carry_min_weight,add_cost;
	priority_queue<Data> Q;

	for(int floor = max_h; floor >= 2; floor--){

		if(V[floor].size() == 0){
			ans += pre_cost;
			continue;
		}
		for(int i = 0; i < V[floor].size(); i++){
			item_id[item_num++] = V[floor][i];
		}
		state = POW[item_num];

		for(int i = 0; i < state; i++)min_cost[i] = BIG_NUM;

		Q.push(Data(0,0));

		while(!Q.empty()){

			if(Q.top().state == state-1){
				Q.pop();
			}else if(Q.top().total_cost > min_cost[Q.top().state]){
				Q.pop();
			}else{

				rest_num = 0;
				for(int loop = 0; loop < item_num; loop++){
					if(Q.top().state & (1 << loop)){
						//do nothing
					}else{
						rest_id[rest_num++] = loop;
					}
				}

				for(int state = 1; state < POW[rest_num]; state++){
					sum_weight = 0;
					not_carry_min_weight = BIG_NUM;
					add_state = 0;
					for(int loop = 0; loop < rest_num; loop++){
						if(state & (1 << loop)){
							sum_weight += info[item_id[rest_id[loop]]].weight;
							add_state += POW[rest_id[loop]];
						}else{
							not_carry_min_weight = min(not_carry_min_weight,info[item_id[rest_id[loop]]].weight);
						}
					}

					if(sum_weight > W || sum_weight+not_carry_min_weight <= W)continue;

					if(Q.top().state == 0){
						add_cost = 1;
					}else{
						add_cost = 2;
					}

					if(min_cost[Q.top().state+add_state] > Q.top().total_cost+add_cost){
						min_cost[Q.top().state+add_state] = Q.top().total_cost+add_cost;
						Q.push(Data(Q.top().state+add_state,min_cost[Q.top().state+add_state]));
					}
				}
				Q.pop();
			}
		}
		ans += min_cost[state-1];
		pre_cost = min_cost[state-1];
	}

	printf("%d\n",ans);

	return 0;
}

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;

signed main() {
    cin >> N;
    vector<pint> ans;
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++)if (i != N / 2 * 2 + 1 - j)ans.push_back(pint(i, j));
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)cout << ans[i].first << " " << ans[i].second << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define fs first
#define sc second
#define pb push_back
#define sz size() 
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef vector<ll> vl;
typedef vector<string> vs;

const static int INF = 1e8;
const static D EPS = 1e-8;

vector<vl> pre(vl x, ll L){
  ll n = x.size();
  vector<vl> d(n+1, vl(31, 0));
  
  ll l=0, r=0;
  while(l<n){
    while(r<n && x[r] <= x[l]+L) r++;
    d[l][0] = r-1-l;
    l++;
  }

  rep(k,30){
    rep(i,n){
      int nxt = i+d[i][k];
      d[i][k+1] = d[i][k] + d[nxt][k];
    }
  }
  return d;
}

bool check(const vector<vl> &d, ll day, ll a, ll b){
  ll k = 0;
  while(day){
    if(day&1LL) a += d[a][k];
    k++; day >>= 1;
  }
  return b <= a;
}

int main(){
  ll n; cin >> n;
  vl x(n);
  rep(i,n) cin >> x[i];
  ll l; cin >> l;

  vector<vl> fd = pre(x, l);
  reverse(all(x));
  rep(i,n) x[i] *= -1;
  vector<vl> rd = pre(x, l);

  ll q; cin >> q;
  rep(i,q){
    ll a,b; cin >> a >> b; a--; b--;
    vector<vl> &d = (a<b)?fd:rd;
    if(a>b){
      a = n-1-a; b = n-1-b;
    }

    ll l = 0, r = 1e6;
    while(r-l>1){
      ll m = (l+r)/2;
      if(check(d,m,a,b)) r = m;
      else l = m;
    }
    cout << r << endl;
  }
}


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

int main(){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> p(n, k-q);
    rep(i, q){
        int a;
        cin >> a;
        --a;
        p[a]++;
    }
    rep(i, n){
        if(p[i] <= 0) puts("No");
        else puts("Yes");
    }
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

ll dp[55][55];

vector<ll>v;

int main() {

	int i, j;


	dp[0][0] = 1ll;
	for (i = 1; i <= 52; i++) {
		dp[i][0] = 1ll;
		for (j = 1; j <= 52; j++) {
			dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
		}
	}

	int N, A, B;

	scanf("%d %d %d",&N,&A,&B);


	for (i = 0; i < N; i++) {
		ll x;
		scanf(" %lld",&x);
		v.push_back(x);
	}

	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	if (v[0] == v[A - 1]) {
		int cnt = 0;
		for (i = 0; i < N; i++) {
			if (v[0] == v[i]) { cnt++; }
		}
		ll ans = 0ll;
		for (i = A; i <= B; i++) {
			if (v[i - 1] != v[0]) { break; }
			ans += dp[cnt][i];
		}
		double a = (double)v[0];
		printf("%.9f\n", a);
		cout << ans << endl;
	}
	else {
		int cnt = 0;
		for (i = 0; i < N; i++) {
			if (v[A - 1] == v[i]) { cnt++; }
		}
		int cnt2 = 0;
		for (i = 0; i < A; i++) {
			if (v[A - 1] == v[i]) { cnt2++; }
		}
		double average = 0ll;
		for (i = 0; i < A; i++) {
			average += (double)v[i];
		}
		average /= (double)A;
		printf("%.9f\n",average);
		cout << dp[cnt][cnt2] << endl;
	}

	return 0;
}

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

int main(){
  int a[100000];
  int i,j,n;
  
  cin >> n;
  
  for(i=0;i<n;i++){
    cin >> j;
    a[j-1] = i + 1;
  }
  
  for(i=0;i<n;i++){
    cout << a[i] << " ";
  }
  
  cout << "\n";
  
  return 0;
  
}

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

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

using namespace std;

double dist(pair<int, int> l, pair<int, int> r){
  double dx = l.first-r.first;
  double dy = l.second-r.second;
  return pow(dx*dx+dy*dy, 0.5);
}

int main(){
  int n;
  cin>>n;
  vector<pair<int,int>> xy;
  rep(i, n){
    int x,y;
    cin>>x>>y;
    xy.emplace_back(x,y);
  }
  
  vector<int> ar;
  rep(i,n){
    ar.push_back(i);
  }
  
  double sum = 0;

  do {
    rep(i,n-1){
      sum += dist(xy[ar[i]], xy[ar[i+1]]);
    }
  } while( next_permutation(ar.begin(), ar.end()) );
  
  int fac = 1;
  rep(i,n) fac *= (i+1);

  cout<<fixed<<setprecision(6)<<(sum/fac)<<setprecision(6);

  return 0;
}

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

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

		BufferedReader buff = null;

		try {
			buff = new BufferedReader(new InputStreamReader(System.in));

			String line = buff.readLine();
			String[] box = buff.readLine().split(" ");
			int[] L = new int[box.length];
			for(int i = 0; i < box.length; ++i){
				L[i] = Integer.parseInt(box[i]);
			}

			for(int i = 0; i < L.length - 1; ++i){
				for(int j = i + 1; j < L.length; ++j){
					if(L[i] > L[j]){
						int sw = L[i];
						L[i] = L[j];
						L[j] = sw;
					}
				}

			}

			int ans = 0;
			for(int i = L.length - 2; i >= 0; i -= 2){

				ans += L[i];
			}

			System.out.println(ans);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

Measured memory_bytes: 8016
import math
def main15():
    strbuf1 = input('');
    strbuf2 = input('');
    strbufs1 = strbuf1.split();
    strbufs2 = strbuf2.split();
    buf1 = [];
    buf2 = [];
    ba = 0;
    for i in range(2):
        buf1.append(int(strbufs1[i]));
    for i in range(buf1[0]):
        buf2.append(int(strbufs2[i]));
        if(buf2[i] == 1):
            ba = i;
            break;
    are = buf1[1] - 1;
    kai1 = math.ceil(ba/are);
    kk = are * kai1 - ba;
    kai2 = math.ceil((buf1[0] -(ba+1+kk))/are)
    print(int(kai1+kai2));

def main16():
    strbuf = input('');
    num = int(strbuf);
    kazu = 0;
    number = 1;
    while(kazu<num):


        kazu = kazu + 1;

        number = number + 1;


if __name__ == '__main__':
    main15()

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n)
  cin >> a[i];
  ll ans1 = 0, ans2 = 0;
  ll sum = 0;
  REP(i, n)
  {
    sum += a[i];
    if (i % 2 == 0 && sum <= 0)
    {
      ans1 += -sum + 1;
      sum = 1;
    }
    else if (i % 2 == 1 && 0 <= sum)
    {
      ans1 += sum + 1;
      sum = -1;
    }
  }
  sum = 0;
  REP(i, n)
  {
    sum += a[i];
    if (i % 2 == 0 && 0 <= sum)
    {
      ans2 += sum + 1;
      sum = -1;
    }
    else if (i % 2 == 1 && sum <= 0)
    {
      ans2 += -sum + 1;
      sum = 1;
    }
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}

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

int main()
{
    ll n;
    cin >> n;
    double v[n];
    rep(i, n) cin >> v[i];
    sort(v, v + n);
    rep(i, n - 1)
    {
        v[i + 1] = (v[i] + v[i + 1]) / 2;
    }
    cout<<v[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 3756
defmodule Main do
  def main() do
    _n =
      IO.gets("")
      |> String.trim()
      |> String.to_integer()
    a =
      IO.gets("")
      |> String.trim()
      |> String.split()
      |> Enum.map(&String.to_integer/1)
      |> Enum.sort(:desc)
    take(a)
    |> IO.puts()
  end

  def take(a) do
    alice =
      Enum.take_every(a, 2)
      |> Enum.sum()
    bob = Enum.sum(a) - alice
    alice - bob
  end
end


Measured memory_bytes: 30644
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;

const int INF = 1001001001;
const ll INFLL = 1001001001001001001LL;


template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }


int main() {


	
	int A,B,C;

	scanf("%d %d %d", &A,&B,&C);
	
	int K;
	scanf("%d", &K);

	
	
	vector<int> VA;
	/*
	for (int i = 0;i<N;i++) {
		int tmp;
		scanf("%d",&tmp);
		VA.push_back(tmp);
	}
	*/

	VA.push_back(A);
	VA.push_back(B);
	VA.push_back(C);

	sort(VA.begin(), VA.end());

	for (int i = 0; i < K; i++) {
		VA[2] *= 2;
	}
	
	printf("%d", VA[0] + VA[1] + VA[2]);





	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n);
    vector<tuple<ll,ll,ll>> vec(n);
    ll a,b;
    rep(i,n){
        in(a,b);
        vec[i]=make_tuple(a+b,a,b);
    }
    sort(rall(vec));
    a=0,b=0;
    rep(i,n){
        if(i%2==0)a+=get<1>(vec[i]);
        else b+=get<2>(vec[i]);
    }
    out(a-b);
}


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

int n;

int dfs(ll a) {
    if (n<a)
        return 0;
    int f3,f5,f7;
    f3=f5=f7=0;
    ll t=a;
    while (t) {
        int b=t%10;
        if (b==3)
            f3=1;
        else if (b==5)
            f5=1;
        else if (b==7)
            f7=1;
        t/=10;
    }
    int f=f3&&f5&&f7;
    return f+dfs(a*10+3)+dfs(a*10+5)+dfs(a*10+7);
}

int main() {
    cin>>n;
    cout<<dfs(0)<<endl;
    return 0;
}

Measured memory_bytes: 256
def readinput():
    n,m=list(map(int,input().split()))
    prefs=[]
    for _ in range(n+1):
        prefs.append([])
    for i in range(1,m+1):
        pi,yi=list(map(int,input().split()))
        prefs[pi].append([i,yi])
    return n,m,prefs

def main(n,m,prefs):
    citycodes=['000000000000']*(m+1)
    for i in range(1,n+1):
        pref=prefs[i]
        pref.sort(key=lambda x:x[1])
        prefcode='{:06}'.format(i)
        #print(pref, prefcode)
        for j, city in enumerate(pref):
            citycode='{:06}'.format(j+1)
            #print(city, citycode)
            citycodes[city[0]]=prefcode+citycode
    return citycodes

if __name__=='__main__':
    n,m,prefs=readinput()
    citycodes=main(n,m,prefs)
    for i in range(1,m+1):
        print(citycodes[i])
    


Measured memory_bytes: 40524
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

int main(int argc, char **argv) {
    string s;
    cin >> s;
    __uint128_t x = parse(s);

    __uint128_t money{100};
    i64 ans{0};

    while (true) {
        ++ans;
        money = money * 101 / 100;
        if (money >= x)
            break;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
lst = list(input())
v_lakes = []
idx_stack = []
for i, c in enumerate(lst):
    if (c == '\\'):
        idx_stack.append(i)
    elif (idx_stack and c == '/'):
        # 対応する'\\'の位置
        j = idx_stack.pop()
        v = i - j
        while (v_lakes and v_lakes[-1][0] > j):
            v += v_lakes.pop()[1]
        v_lakes.append((j, v))
ans = [len(v_lakes)]
v = [v[1] for v in v_lakes]
ans.extend(v)

print(sum(v))
print(*ans)


Measured memory_bytes: 6448
#include <stdio.h>

int main(void)
{
  int A,B,i;
  int answer = 0;
  
  scanf("%d",&A);
  scanf("%d",&B);
  
  
  for(i=0; i<=1; i++){
    if(A>B){
      answer += A;
      A--;
    }else if(A==B){
      answer += A;
      A--;
    }else {
      answer += B;
      B--;
    }
  }
  
  printf("%d\n",answer);
  
  return 0;
}
    


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

int score;

int main(void){
    string s;
    char temp;
    cin>>s;
    temp=s[0];
    for(int i=1;i<s.size();i++){
        if(s[i] != temp){
            score++;
            temp=s[i];
        }
    }
    cout<<score<<endl;
    return 0;
}


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

long dfs(int n, long x) {
  if (!n && x) return 1;
  long len = (1L << (n + 2)) - 3;
  if (x <= 1) return 0;
  if (x <= len / 2) return dfs(n - 1, x - 1);
  return dfs(n - 1, x - (len / 2 + 1)) + 1 + ((1L << n) - 1);
}

int main() {
  int N;
  long X;
  cin >> N >> X;
  cout << dfs(N, X) << "\n";
}

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


void solve(){
    char ch;
    cin>>ch;
    if(isupper(ch)) cout<<"A";
    else cout<<"a";


}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int q;
    q=1;
    // cin>>q;
    while(q--) solve();


    return 0;
}

Measured memory_bytes: 3496
#include <iostream>

using namespace std;
int v[105];
int w[105];
int c[105][10005];

int main() {
    int n;
    int wei;
    cin >> n >> wei;
    for (int i = 1; i <= n; i++) {
        cin >> v[i] >> w[i];
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= wei; j++) {
            if (i == 0) {
                c[i][j] = 0;
            } else {
                c[i][j] = c[i - 1][j];
            }
            if (i > 0 && j >= w[i]) {
                c[i][j] = max(c[i][j], c[i - 1][j - w[i]] + v[i]);
            }
        }
    }
    cout << c[n][wei] << endl;
    return 0;
}

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

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

int main()
{
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if(S == U)
    {
        cout << (A - 1) << ' ' << B << endl;
    }
    else if(T == U)
    {
        cout << A << ' ' << (B - 1) << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define ll long long
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 100000000
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mk(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x,y)              (x>y)?x:y
#define min2(x,y)              (x<y)?x:y
#define mid(s,e)               (s+(e-s)/2)
#define mini                   INT_MIN
#define maxo                   INT_MAX
#define rep(i,a,b) for(int i=a;i<(int)(b);++i)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define show(a,n) for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl
#define en cout<<"\n";

int main()
{
    // #ifndef ONLINE_JUDGE
    //  freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[i] = a[i];
    }
    sort(a,a+n);
    ll r = a[n-1];
    ll t = a[n-2];
    for(int i=0;i<n;i++)
    {
        if(b[i]==r)
            cout<<t<<endl;
        else
            cout<<r<<endl;
    }
}

Measured memory_bytes: 4736
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int main(){
    string s, t; cin >> s >> t;
    map<char, vector<int>> mp;
    rep(i, s.size()){
        mp[s[i]].push_back(i);
    }
    ll roop = 0, index = -1; bool fg = true;
    for(char c: t){
        auto iter = upper_bound(all(mp[c]), index);
        if(iter != mp[c].end()){
            index = *iter;
        }else{
            roop++; index = -1;
            iter = upper_bound(all(mp[c]), index);
            if(iter != mp[c].end()){
                index = *iter;
            }else{
                fg = false;
                break;
            }
        }
    }


    ll res = fg ? roop * s.size() + index + 1 : -1;
    cout << res << ln;
}

Measured memory_bytes: 1216
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

#define endl "\n"

typedef long long ll;
typedef pair <ll, ll> pii;
typedef long double ld;

const ll DIM = 100007;
const ll INF = 1000000007;
ll n, m, k;
ll a, b, c;
ll v[DIM+7], w[DIM+7], ans[200][DIM+7];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (ll i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];

	}

	for (ll i = 0; i <= n; i++)
		ans[i][0] = 0;
	for (ll i = 1; i <= DIM; i++)
		ans[0][i] = INF;
	for (ll j = 1; j <= DIM; j++)
		for (ll i = 1; i <= n; i++)
			ans[i][j] = INF;
	for (ll j = 1; j <= DIM; j++) {
		for (ll i = 1; i <= n; i++) {
			if (j < v[i])ans[i][j] = ans[i - 1][j]; else ans[i][j] = min(ans[i - 1][j], ans[i - 1][j - v[i]] + w[i]);

		}

	}
	ll ans1 = 0;
	for (ll i = 1; i <= DIM; i++) {
		if (ans[n][i] <= k)ans1 = i;
		//	if (i <= 20)  cout << ans[n][i] << ' ' << k << endl;
	}
	
	cout << ans1;
	return 0;
}


Measured memory_bytes: 82176
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans;
  ans = min(a,b)+min(c,d);
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
    int N,L;
    cin >> N >> L;
    vector<string> S(N);
    rep(i,N) cin >> S[i];
    sort(S.begin(),S.end());
    string ans = "";
    rep(i,N){
        ans += S[i];
    }
    cout << ans << endl;
}

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

string s;
int a[4];

void f(int sum,int now,string ans){
    if(now==4){
        if(sum==7)s=ans+"=7";
        return;
    }
    f(sum+a[now],now+1,ans+"+"+to_string(a[now]));
    f(sum-a[now],now+1,ans+"-"+to_string(a[now]));
}

void solve() 
{
    cin>>s;
    REP(i,4)a[i]=s[i]-'0';
    f(a[0],1,to_string(a[0]));
    cout<<s<<endl;
}

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

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll a, b;
  cin >> a >> b;

  string ans;
  if (a > 0)
    ans = "Positive";
  else if (a == 0)
    ans = "Zero";
  else if (b >= 0)
    ans = "Zero";    
  else {
    ans = (b - a + 1) % 2 == 0 ? "Positive" : "Negative";
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
	int a,b;
	while(1){
		a=-1;
		int ret = 0;
		int data[102]={0};
		while(cin >> a >> b && a || b){
			a--;b--;
			data[a]++;
			data[b]++;
		}
		if(data[0]%2==0 || data[1]%2==0)ret = 10000;
		for(int i=0;i<102;i++){
			if(data[i]%2==1 && data[i]){
				ret++;
			}
		}
		if(a==-1)return 0;
		cout << (ret>2?"NG":"OK") << endl;
	}
	
	
}

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

using namespace std;
typedef long long ll;
typedef long double ld;

ll big = 1000000007ll;
ll n,q,m,k,x,y;

vector<ll> A;
vector<vector<ll> > C(100001 , vector<ll>());
ll deg[100001] = {0};
bool yes = 1;

ll dfs(ll i, ll par){
if(par != -1 && deg[i] == 1)return A[i];
ll sum = 0;
ll ma = -1;
for(ll c1 = 0; c1 < deg[i]; c1++){
    ll a = C[i][c1];
    if(a != par){
        ll d = dfs(a,i);
        sum += d;
        ma = max(ma,d);

    }
}

ll x = 2*A[i] - sum;
if(x > A[i])yes = 0;
if(x < 0)yes = 0;
if(ma-x > sum-ma)yes = 0;
if(par == -1 && x != 0)yes = 0;
return x;
}




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

    ll c1,c2,c3,c4,c5;
    ll a,b,c;

    cin >> n;

    for(c1 = 0; c1 < n; c1++){
        cin >> a;
        A.push_back(a);
    }
    ll i = 0;
    for(c1 = 0; c1 < n-1; c1++){
        cin >> a >> b;
        a--;
        b--;
        deg[a]++;
        deg[b]++;
        if(deg[a] > 1)i = a;
        if(deg[b] > 1)i = b;
        C[a].push_back(b);
        C[b].push_back(a);
    }

    if(n == 2){
        yes = (A[0] == A[1]);
    }
    else{
        dfs(i,-1);
    }
    if(yes == 1){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
    return 0;
}


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

int main(){
	int a, b;
	cin >> a >> b;
	if( a % 2 == 0 || b % 2 == 0){
		cout << "Even" << endl;
	}else{
		cout << "Odd" << endl;
	}
}


Measured memory_bytes: 3592
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i <= 50000; i++) {
		    if (i * 108 / 100 == n) {
		        System.out.println(i);
		        return;
		    }
		}
		System.out.println(":(");
	}
}


Measured memory_bytes: 23380