akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

//splitElement return elements of one line.
func splitElement() []int {
	var list []int
	sc.Scan()
	for _, v := range strings.Split(sc.Text(), " ") {
		num, _ := strconv.Atoi(v)
		list = append(list, num)
	}
	return list
}

func calcMin(p, q, r int) int {
	min := 201
	if p+q < min {
		min = p + q
	}
	if q+r < min {
		min = q + r
	}
	if r+p < min {
		min = r + p
	}
	return min
}

func main() {
	inputArray := splitElement()
	p := inputArray[0]
	q := inputArray[1]
	r := inputArray[2]

	fmt.Println(calcMin(p, q, r))
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int A = scan.nextInt();
    int B = scan.nextInt();
    int result = 0;
    
    if (A > B) {
      result += A--;
    } else {
      result += B--;
    }

    if (A > B) {
      result += A;
    } else {
      result += B;
    }
    System.out.println(result);
  }
}


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

typedef long long ll;
double eps=0.000001;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    double cube;
    cin>>cube;
    double ans=((cube)/3.0);
    ans=ans*ans*ans;
    printf("%0.6lf\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


vector<LL> divi(LL K){
    vector<LL> v;
    for(int i=1;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        v.pb(K/i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    return v;
}

int main(){
    LL n,k;cin >> n >> k;
    vector<LL> a(n);
    LL x=0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x+=a[i];
    }
    auto p=divi(x);
    sort(RALL(p));
    int ans=0;
    for(auto d:p){
        vector<LL> c;
        for (int j = 0; j < n; j++) {
            if(a[j]%d==0) continue;
            c.pb(a[j]%d);
        }
        sort(ALL(c));
        int cn=c.size();
        vector<LL> cum(cn+1,0),rcum(cn+1,0);
        for (int j = 0; j < cn; j++) {
            cum[j+1]=cum[j]+c[j];
        }
        for (int j = 0; j < cn; j++) {
            rcum[cn-1-j]=rcum[cn-j]+d-c[cn-1-j];
        }
        LL sum=k+1;
        for (int j = 0; j <= cn; j++) {
            sum=min(sum,max(cum[j],rcum[j]));
        }
        if(sum<=k){
            cout << d << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/list"
	"os"
	"strconv"
	"fmt"
)

const (
	MAX = 100000
	NIL = -1
)

var (
	n     int
	G     [MAX][]int
	color [MAX]int
)

func DFS(r int, c int) {
	S := list.New()
	S.PushFront(r)
	color[r] = c
	for S.Len() != 0 {
		u := S.Remove(S.Front()).(int)
		for i := 0; i < len(G[u]); i++ {
			v := G[u][i]
			if color[v] == NIL {
				color[v] = c
				S.PushFront(v)
			}
		}
	}
}

func assignColor() {
	id := 1
	for i := 0; i < n; i++ {
		color[i] = NIL
	}
	for i := 0; i < n; i++ {
		if color[i] == NIL {
			id++
			DFS(i, id)
		}
	}
}

func main() {
	var s, t, m, q int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	scanner.Scan()
	m, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < m; i++ {
		scanner.Scan()
		s, _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		t, _ = strconv.Atoi(scanner.Text())
		if i == 0 {
			G[s] = make([]int, 0)
			G[t] = make([]int, 0)
		}
		G[s] = append(G[s], t)
		G[t] = append(G[t], s)
	}

	assignColor()
	scanner.Scan()
	q, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < q; i++ {
		scanner.Scan()
		s, _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		t, _ = strconv.Atoi(scanner.Text())
		if color[s] == color[t] {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}



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

int main() {
  int H,W;
  cin>>H>>W;
  
  vector<char> a(H*W);
  for(int x=0;x<H*W;x++){
    cin>>a.at(x);
  }
  for(int n=0;n<H*W;n+=W){
    bool TF=1;
    for(int i=0;i<W;i++){
      if(a.at(i+n)=='#'){
        TF*=0;
      }
    }
    if(TF==1){
      for(int i=0;i<W;i++){
        a.at(i+n)=' ';
      }
    }
  }
  for(int m=0;m<W;m++){
    bool FT=1;
    for(int j=0;j<H*W;j+=W){
      if(a.at(j+m)=='#'){
        FT*=0;
      }
    }
    if(FT==1){
      for(int j=0;j<H*W;j+=W){
        a.at(j+m)=' ';
      }
    }
  }
  for(int l=0;l<H*W;l+=W){
    string c;
    bool empty=1;
    for(int k=0;k<W;k++){
      if(a.at(k+l)!=' '){
        c+=a.at(k+l);
        empty*=0;
      }
    }
    if(empty==0)
      cout<<c<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
	int n, a, b, sum = 0, tmp = 0, tmpi, tmpj;
    cin >> n >> a >> b;

    for (int i = 1; i <= n; i++)
    {
        tmp = 0;
        tmpi = i;
        for (int j = 10000; j != 1; j /= 10)
        {
            tmpj = tmpi / j;
            tmp += tmpj;
            tmpi -= j * tmpj;
        }
        tmp += tmpi;

        if (a <= tmp && b >= tmp)
        {
            sum += i;
        }
    }

    cout << sum << endl;
    return 0;
}



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

int add(int a,int b){
        return a+b;
}

int de(int a,int b){
        return a-b;
}

int op(int i, int a, int b){
        if(i == 0){
                return add(a,b);
        }
        return de(a,b);
}


int main(){
        int num, a,b,c,d;
        cin >> num;
        a= num / 1000;
        b= num % 1000 / 100;
        c= num % 100 / 10;
        d= num % 10;

        for(int i = 0; i < 2; i++){
                int tmp1=0;
                tmp1 = op(i,a,b);
                for(int j = 0; j < 2; j++){
                        int tmp2=0;
                        tmp2 = op(j,tmp1,c);
                        for(int k = 0; k < 2; k++){
                                int tmp3 = 0;
                                tmp3 = op(k,tmp2,d);
                                if(tmp3 == 7){
                                        string op1,op2,op3;
                                        if(i == 0) op1 = "+";
                                        else op1 = "-";
                                        if(j == 0) op2 = "+";
                                        else op2 = "-";
                                        if(k == 0) op3 = "+";
                                        else op3 = "-";
                                        cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
                                        return 0;
                                }
                        }
                }
        }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli a,b,c;
    cin>>a>>b>>c;
    if((a*b*c)%2==0){
        out(0);
        return 0;
    }
    else{
        lli ans=min(a*b,min(b*c,c*a));
        out(ans);
    }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  int bucket[35] = {0};
  int K, A;

  for (int j = 0; j < N; j++) {
    cin >> K; // それぞれの好きな物の数
    for (int i = 0; i < K; i++) {
      cin >> A;
      bucket[A]++;
    }
  }
  
  int result = 0;
  for (int i = 1; i <= M; i++) {
    if (bucket[i] == N) {
      result++;
    }
  }

  cout << result << endl;
}


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

int n;
int mapp[505][505];
int vis[505][505]={0};
int p[500005];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void bef(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			mapp[i][j]=min(i-1,min(j-1,min(n-i,n-j)));
//			cout<<mapp[i][j]<<" ";
		}
//		cout<<endl;
	}
	return;
}
void dfs(int x,int y){
	for(int i=0;i<4;i++){
		int tx=x+dx[i];
		int ty=y+dy[i];
		if(tx>=1&&tx<=n&&ty>=1&&ty<=n){
			if(mapp[tx][ty]>mapp[x][y]+vis[x][y]+1){
				mapp[tx][ty]=mapp[x][y]+vis[x][y]+1;
				dfs(tx,ty);
			}
		}
	}
	return;
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	bef();
	for(int i=1;i<=n*n;i++){
		cin>>p[i];
	}
	int sum=0;
	for(int i=1;i<=n*n;i++){
		int x=(p[i]+n-1)/n;
		int y=(p[i]%n==0)?n:(p[i]%n);
		sum+=mapp[x][y];
		vis[x][y]=-1;
		dfs(x,y);
	}
	cout<<sum<<endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    vector<int> t(n);
    for (int i = 0; i < n; i++)
    {
        cin >> t.at(i) >> x.at(i) >> y.at(i);
    }
    int memo = 0;
    int time;
    int a=0;
    int b=0;
    memo = abs(x.at(0)) + abs(y.at(0));
    time=t.at(0);
        if (time>=memo && (time-memo)%2==0)
        {

        }
        else{
            b++;
        }

    for (int i = 0; i < n - 1; i++)
    {
        memo = abs(x.at(i) - x.at(i + 1)) + abs(y.at(i) - y.at(i + 1));
        time=t.at(i + 1) - t.at(i);
        if (time>=memo && (time-memo)%2==0)
        {
            
        }
        else{
            b++;
            break;
        }
    }
    if(b>0){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) 			a.begin(),a.end()
#define pb 				push_back
#define vi				vector<int>
#define vl 				vector<long long>
#define MOD 			1000000007
#define FOR(i,a,b) 		for(int i = a; i <= b ; i++)
#define forn(i,n) 		for(int i = 0 ; i < n; i++)
#define br 				cout<<endl;
#define testc()			int t;cin>>t;while(t--)
#define ll				long long
#define printv(v)		for(auto x : v) cout<<x<<' ';br;
#define ff				first
#define ss 				second
#define fast 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vb 				vector<bool>

using namespace std;
using pii = pair<int,int>;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll power(ll a,ll b,ll mod)
{
	ll res = 1;
	a = a % mod;
	while(b)
	{
		if(b & 1)
			res = (res * a) % mod;
		b = b >> 1;
		a = (a * a) % mod;
	}
	return res;
}
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/


int main()
{
	fast
	string s;
	cin>>s;
	multiset<char> m;
	forn(i,4)
	{
		m.insert(s[i]);
	}
	int ans = 0;
	set<char> y;
	for(auto x : m)
	{
		if(m.count(x) == 2 && !y.count(x))
		{
			y.insert(x);
			ans++;
		}
	}
	if(ans == 2)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int suit[200][200];
int main(void){
	int d,n,i,j,k,ans=0;
	scanf("%d %d",&d,&n);
	int tem[d],A[n],B[n],hade[n],dp[d][n];
	for(i=0;i<d;i++){
		scanf("%d",&tem[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d %d %d",&A[i],&B[i],&hade[i]);
	}
	for(i=0;i<d;i++){
		for(j=0;j<n;j++){
			dp[i][j]=0;
		}
	}
	for(i=0;i<d;i++){
		for(j=0;j<n;j++){
			if(A[j]<=tem[i]&&tem[i]<=B[j]){
				suit[i][j]=1;
			}
			else{
				dp[i][j]=-1;
			}
		}
	}
	for(j=0;j<n;j++){
		if(suit[0][j]==1)dp[0][j]=0;
	}
//????????????
	
	for(i=0;i<d-1;i++){
		for(j=0;j<n;j++){ if(suit[i][j]==1){
			for(k=0;k<n;k++){ if(suit[i+1][k]==1){
				if(dp[i+1][k]<dp[i][j]+abs(hade[j]-hade[k]))dp[i+1][k]=dp[i][j]+abs(hade[j]-hade[k]);
			}}
		}}
	}
	
	for(i=0;i<n;i++){
		if(ans<dp[d-1][i])ans=dp[d-1][i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2020
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    ios::sync_with_stdio(false);
    int n,record,ans=0,sum=0; cin>>n;
    string s[n],x;
    int t[n];
    rep(i,n) cin >>s[i]>>t[i];
    cin >>x;
    rep(i,n) sum+=t[i];
    rep(i,n){
        if(s[i]==x){
            record=i;
            break;
        }
    }
    for(int i=0;i<=record;i++){
        sum-=t[i];
    }
    cout << sum <<endl;
    return 0;
}


Measured memory_bytes: 256
// g++ -std=gnu++1y -O2 main.cpp

#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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; }

int main() {
	int N, R;
	cin >> N >> R;

	if (N >= 10) {
		cout << R << endl;
	} else {
		cout << (R + 100 * (10 - N)) << endl;
	}

	return 0;
}

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

const int MAX = 1000001;

// structure to store queries
struct Query
{
    int l, r, idx;
};

// cmp function to sort queries according to r
bool cmp(Query x, Query y)
{
    return x.r < y.r;
}

// updating the bit array
void update(int idx, int val, int bit[], int n)
{
    for (; idx <= n; idx += idx&-idx)
        bit[idx] += val;
}

// querying the bit array
int query(int idx, int bit[], int n)
{
    int sum = 0;
    for (; idx>0; idx-=idx&-idx)
        sum += bit[idx];
    return sum;
}

void answeringQueries(int arr[], int n, Query queries[], int q)
{
    // initialising bit array
    int bit[n+1];
    memset(bit, 0, sizeof(bit));

    // holds the rightmost index of any number
    // as numbers of a[i] are less than or equal to 10^6
    int last_visit[MAX];
    memset(last_visit, -1, sizeof(last_visit));

    // answer for each query
    int ans[q];
    int query_counter = 0;
    for (int i=0; i<n; i++)
    {
        // If last visit is not -1 update -1 at the
        // idx equal to last_visit[arr[i]]
        if (last_visit[arr[i]] !=-1)
            update (last_visit[arr[i]] + 1, -1, bit, n);

        // Setting last_visit[arr[i]] as i and updating
        // the bit array accordingly
        last_visit[arr[i]] = i;
        update(i + 1, 1, bit, n);

        // If i is equal to r of any query  store answer
        // for that query in ans[]
        while (query_counter < q && queries[query_counter].r == i)
        {
            ans[queries[query_counter].idx] =
                     query(queries[query_counter].r + 1, bit, n)-
                     query(queries[query_counter].l, bit, n);
            query_counter++;
        }
    }

    // print answer for each query
    for (int i=0; i<q; i++)
        cout << ans[i] << endl;
}

// driver code
int main()
{
    int n,q;
    cin>>n>>q;
    int a[n+5];
    for(int i=0;i<n;i++)
    cin>>a[i];
    Query queries[q];
    for(int i=0;i<q;i++)
    {
        int x,y,z;
        cin>>x>>y;
        x--;
        y--;
        queries[i].l=x;
        queries[i].r=y;
        queries[i].idx=i;
    }
   // int q = sizeof(queries)/sizeof(queries[0]);
    sort(queries, queries+q, cmp);
    answeringQueries(a, n, queries, q);
    return 0;
}


Measured memory_bytes: 19324
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n;cin>>n;cout<<n*(n-1)/2<<endl;
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/07/21
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int A[21] = {0};
int B[21] = {0};
int C[21] = {0};


int main()
{
	int N = 0, i = 0, ans = 0, prev = 0;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (i = 0; i < N; i++) {
		scanf("%d", &B[i]);
	}
	for (i = 0; i < N-1; i++) {
		scanf("%d", &C[i]);
	}
	for (i = 0; i < N; i++) {
		//printf("A %d\n", A[i]);
		ans  += B[A[i]-1];
		//printf("B %d\n", B[A[i]-1]);
		if (i != 0) {
			if ((prev + 1) == A[i]) {
				//printf("prev =%d C %d\n", prev, C[prev-1]);
				ans += C[prev-1];
			}
		}
		prev = A[i];
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
import Data.List
main=do
 n<-getLine;a<-sort.map read.words<$>getLine
 (putStrLn.unwords.map show)(f(init a)(last a))
  where f [a] l = [l,a]
        f (x:y:a) l = if(abs(2*x-l))<(abs(2*y-l))then[l,x]else(f(y:a)l)

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
//#define max(a,b) (a>b ? a : b)
//#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 100000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  map<ll ,ll> cnt;
  rep(i,N){
    if(!cnt.count(A[i])){
      cnt[A[i]] = 1;
      //cout <<i <<" "<< cnt[A[i]] << endl;
    }else{

      cnt[A[i]] +=1; 
      //cout << i << " " << cnt[A[i]] << endl;
    }
  }
  ll cs =0;
  
  for(auto x = cnt.begin(); x!= cnt.end(); ++ x){
    ll a = x->second;
    cs += a*(a-1)/2;
  }
  //cout <<"cs " <<cs << endl;

  rep(i,N){
    ll k = cnt[A[i]];
    cout << cs - (k-1) << endl;
  }
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    long long A, B;
    cin >> A >> B;
    int K;
    cin >> K;
    vector<long long> res;
    REP(i, K) {
        if(A + i <= B) {
            res.push_back(A + i);
        }
    }
    REP(i, K) {
        if(B - i >= A) {
            res.push_back(B - i);
        }
    }
    sort(ALL(res));
    res.erase(unique(res.begin(), res.end()), res.end());
    REP(i, res.size()) { cout << res[i] << endl; }
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
  input! {
    n: usize, m: usize,
    sc: [(usize, i64); m],
  }
  
  let mut digits = vec![-1; n];
  
  for &(s, c) in &sc {
    if digits[s-1] == -1 {
      digits[s-1] = c;
    } else if digits[s-1] != c {
      println!("-1");
      return;
    }
  }
  
  if n == 1 {
    if digits[0] == -1 { digits[0] = 0 };
  } else {
    if digits[0] == -1 { digits[0] = 1 };
    if digits[0] == 0 {
      println!("-1");
      return;
    }
    for i in 1..n {
      if digits[i] == -1 { digits[i] = 0 };
    }
  }
  
  let str = digits.iter().map(|c| c.to_string()).collect::<String>();
  println!("{}", str);
}

Measured memory_bytes: 2120
n, k = map(int, input().split())
a = list(map(int, input().split()))

dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]].append(i)
    else:
        dic[a[i]] = [i]

zero = [-1 for i in range(n)]
for key, value in dic.items():
    num = len(value)
    for i in range(num-1):
        zero[value[i]] = value[i+1] - value[i] + 1
    zero[value[-1]] = n - value[-1] + value[0] + 1

lst = [zero]
while lst[-1][0] <+ n*k - 1:
    before = lst[-1]
    after = []
    for i in range(n):
        after.append(before[i] + before[(before[i]+i)%n])
    lst.append(after)
lst.pop()

i = 0
while lst != []:
    lsti = lst.pop()
    while True:
        if i + lsti[i%n] <= n*k - 1:
            i = i + lsti[i%n]
        else:
            break

i = i % n
nokori = a[i:]
lst = []
dic = {}
ko = 0
for i in range(len(nokori)):
    if nokori[i] not in dic:
        lst.append(nokori[i])
        dic[nokori[i]] = ko
        ko += 1
    else:
        lst = lst[:dic[nokori[i]]]
        dic = {}
        for j in range(len(lst)):
            dic[lst[j]] = j
        ko = len(lst)
print(*lst)

Measured memory_bytes: 278736
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

ll N,K;
ll x[100],y[100];
map<ll,map<ll,ll>> imos;

signed main(){
	ll ans = LLONG_MAX;
	cin >> N >> K;
	FOR(i,0,N)cin >> x[i] >> y[i];
	vl X(N),Y(N);
	FOR(i,0,N)X[i] = x[i];
	FOR(i,0,N)Y[i] = y[i];
	sort(ALL(X));
	sort(ALL(Y));
	map<ll,ll> mx,my;
	FOR(i,0,N)mx[X[i]] = i;
	FOR(i,0,N)my[Y[i]] = i;
	FOR(i,0,N)x[i] = mx[x[i]];
	FOR(i,0,N)y[i] = my[y[i]];
	FOR(i,0,N)imos[x[i]][y[i]] += 1;
	FOR(i,0,N+1)FOR(j,0,N+1)imos[i+1][j] += imos[i][j];
	FOR(i,0,N+1)FOR(j,0,N+1)imos[i][j+1] += imos[i][j];
	FOR(i,0,N)FOR(j,0,N)FOR(k,i+1,N)FOR(l,j+1,N){
		ll Count = imos[k][l] + imos[i-1][j-1] - imos[k][j-1] - imos[i-1][l];
		if(Count >= K){
			ll S = (X[k] - X[i]) * (Y[l] - Y[j]);
			chmin(ans,S);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void) {
	int a[52] = {0};
	char b[4] = {'S','H','C','D'};
	int d, n;
	char c;
	int e, f;

	scanf("%d", &n);

	for (f = 0; f < n; f++)
	{
		scanf("%*c%c %d", &c, &d);
		for (e = 0; b[e] != c; e++)
		{
			d += 13;
		}
		a[d - 1] = 1;
	}

	for (f = 0; f < 4; f++)
	{
		for (e = 0; e < 13; e++) 
		{
			if (a[f * 13 + e] == 0) 
			{
				printf("%c %d\n", b[f], e + 1);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1752
n = gets.chop.to_i
a = gets.chop.split.map(&:to_i)
b = gets.chop.split.map(&:to_i)
c = gets.chop.split.map(&:to_i)


ans = 0
pre = n

a.each do |elem|
  ans += b[elem - 1]

  if elem - 1 == pre
    ans += c[elem-2]
  end

  pre = elem
end

print ans


Measured memory_bytes: 3836
import java.util.*;
class S{
	String r;
	long b;
	int t;
	public S(String r,long b,int t) {
		this.r=r;
		this.b=b;
		this.t=t;
	}
}
public class Main{
	static boolean i(S a[]) {
		for(int i=0;i<a.length-1;i++) {
			if(a[i].b==a[i+1].b&&a[i].t>a[i+1].t) {
				return true;
			}
		}
		return false;
	}
	static int q(S a[],int low,int high) {
		 int i=low-1;
	    long key = a[high].b;
	    for(int j=low;j<high;j++) {
	    	if(a[j].b<=key) {
	    		i++;
	    		S temp = a[i];
	    		a[i] = a[j];
	    		a[j] = temp;
	    	}	
	    }
	    S temp=a[i+1];
	    a[i+1]=a[high];
	    a[high]=temp;
	    return i+1;
	}
	static void sort(S a[],int low,int high){
		if(low<high) {
			int q=q(a,low,high);
			sort(a,low,q-1);
			sort(a,q+1,high);
		}
	}
	public static void main(String args[]) {
		Scanner in=new Scanner(System.in);
		int n=Integer.parseInt(in.nextLine());
		S a[]=new S[n];
		for(int i=0;i<n;i++) {
			String r=in.nextLine();
			String c[]=r.split(" ");
			a[i]=new S(r,Long.parseLong(c[1]),i);
		}
		sort(a,0,n-1);
		if(i(a))System.out.println("Not stable");
		else System.out.println("Stable");
		for(S i:a) {
			System.out.println(i.r);
		}
	}
}

Measured memory_bytes: 160924
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getval(_T& a) {
	std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}

static void C();

int main()
{
	C();
	fflush(stdout);
	return 0;
}

static void C()
{
	int N, M;
	getval(N, M);

	LLONG K;
	getval(K);

	std::vector<LLONG> sumAi(N + 1, 0), sumBi(M + 1, 0);
	for (int i = 1; i <= N; i++) {
		LLONG ai;
		getval(ai);
		sumAi[i] = sumAi[i - 1] + ai;
	}
	for (int i = 1; i <= M; i++) {
		LLONG bi;
		getval(bi);
		sumBi[i] = sumBi[i - 1] + bi;
	}
	
	int bookMax = 0, bIdx = M;
	for (int a = 0; a <= N; a++) {
		if (sumAi[a] <= K) {
			bookMax = std::max(bookMax, a);
		}
		while(bIdx) {
			if (sumAi[a] + sumBi[bIdx] <= K) {
				bookMax = std::max(bookMax, bIdx + a);
				break;
			}
			else {
				bIdx--;
			}
		}
	}
	printf("%d\n", bookMax);
}


Measured memory_bytes: 6384
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    double gyakusuuNoWa = 0;
    for (int i = 0; i < n; i++)
    {
        gyakusuuNoWa += (double)1/a[i];
    }
    
    double gyakusuunoWanoGyakusuu = 1 / gyakusuuNoWa;

    cout << gyakusuunoWanoGyakusuu << endl;
    
    return 0;
}



Measured memory_bytes: 256
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f
let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

let list_of_string str = range 0 (String.length str) |> List.map (fun i -> str.[i])
let array_of_string str = Array.init (String.length str) (fun i -> str.[i])

let () = scanf "%d" (fun n -> n / 3) |> printf "%d\n"


Measured memory_bytes: 384
N = int(input())
x = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

fac = 1

for i in range(2, N) :
  fac = fac * i % mod

inv_sum = [pow(i, mod - 2, mod) for i in range(1, N)]
for i in range(1, N - 1) :
  inv_sum[i] += inv_sum[i-1]

ret = 0
for i in range(N - 1) :
  d = x[i + 1] - x[i]
  ret += d * inv_sum[i] % mod
  ret %= mod

print(ret * fac % mod)

Measured memory_bytes: 63544
Scanf.scanf "%d %d %d" (fun n a b ->
    (if (a + b) mod 2 = 0 then abs (a - b) / 2 else
        let d1 = max a b - 1 in
        let d2 = min a b + ((abs (a - b)  - 1) / 2) in
        let a = n - a + 1 in
        let b = n - b + 1 in
        let d3 = max a b - 1 in
        let d4 = min a b + ((abs (a - b)  - 1) / 2) in
        min (min d1 d2) (min d3 d4)
    ) |> Printf.printf "%d\n"
)

Measured memory_bytes: 384
virgin = true

loop do
  n = gets.to_i
  break if n.zero?
  puts "" unless virgin

  teams = Hash.new{ |h,k| h[k] = [] }

  n.times do
    team, win, lose, draw = gets.chomp.split
    score = 3*win.to_i + draw.to_i
    teams[score] << team
  end

  teams.sort.reverse.each do |score_teams|
    s = score_teams.first
    score_teams.last.each{ |t| puts "#{t},#{s}"}
  end

  virgin = false if virgin
end

Measured memory_bytes: 6124
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N; vector<int>vec;

int main() {
	scanf("%d", &N); vec.resize(N, 0);
	for (int i = 1; i <= N; i++) cin >> vec[i - 1];

	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	cout << vec.size() << endl;
	return 0;
}


Measured memory_bytes: 3500
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#define SIZE 100005
#define INF 100000000000000LL

using namespace std;
typedef long long int ll;

map <ll,int> mp;
map <ll,int>::iterator it;

ll to(ll x)
{
	for(ll i=2;;i++)
	{
		ll t=i*i*i;
		if(t>x) break;
		while(x%t==0) x/=t;
	}
	return x;
}
ll tg(ll x)//toしてる -> x=P*Q^2 に直したい -> そして、P^2*Qに
{
	ll A=1,B=1;
	for(ll i=2;;i++)
	{
		if(i*i*i>x) break;
		int cnt=0;
		while(x%i==0)
		{
			x/=i;
			cnt++;
		}
		if(cnt==1) A*=i;
		else if(cnt==2) B*=i;
	}
	//x/(A*B^2)=C*D^2だから、C=1 or D=1
	ll dt=(ll) floor(sqrt(x)+0.5);
	if(dt*dt==x) B*=dt;
	else A*=x;
	ll ret=A*B;
	if(ret>INF/A+1) ret=INF;
	else ret*=A;
	return ret;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		ll x;
		scanf("%lld",&x);
		x=to(x);
		//printf("%lld ",x);
		mp[x]++;
	}
	//puts("");
	int ret=0;
	set <ll> st;
	for(it=mp.begin();it!=mp.end();it++)
	{
		ll x=it->first;
		if(st.count(x)) continue;
		int cnt=it->second;
		ll t=tg(x);
		//if(x<=t) printf("%lld %lld : %d %d\n",x,t,mp[x],mp[t]);
		if(x!=t) ret+=max(cnt,mp[t]);
		else ret++;
		st.insert(t);
	}
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 14336
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		int i,cnt=0,big,sma,mid;
		// TODO Auto-generated method stub
   Scanner sca=new Scanner(System.in);
    int hair1[]=new int[sca.nextInt()];
    for(i=0;i<hair1.length;i++){
    	hair1[i]=sca.nextInt();
    }
    int hair2[]=new int[sca.nextInt()];
    for(i=0;i<hair2.length;i++){
    	hair2[i]=sca.nextInt();
    }
    for(i=0;i<hair2.length;i++){
    	big=hair1.length;
    	sma=0;
    	while(sma<big){
    		mid=(big+sma)/2;
    		if(hair1[mid]==hair2[i]){
    			cnt++;
    			break;
    		}
    		if(hair1[mid]>hair2[i])big=mid;
    		if(hair1[mid]<hair2[i])sma=mid+1;
    		}
    	}
    System.out.println(cnt);
	}

}


Measured memory_bytes: 80848
import java.util.*;

public class Main {
	int p;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			String str = sc.nextLine();
			if(str.equals("0:")) break;
			str = str.replaceAll(" ", "");
			String [] str2 = str.split(":");
			p = Integer.parseInt(str2[0]);
			
			Parse pa = new Parse(str2[1]+"#");
			int ans = pa.exp();
			if(pa.flg){
				System.out.println("NG");
			}
			else{
				System.out.println(str2[1] + " = " + ans + " (mod " + p + ")");
			}
		}
	}

	class Parse{
		String str;
		int pos;
		boolean flg;
		public Parse(String str){
			this.str = str;	pos = 0;
			flg = false;
		}
		
		private int exp() {
			if(flg) return 1;
			int res = term();
			while(true){
				char op = str.charAt(pos);
				if((op == '+') || (op == '-')){
					int old = res;
					pos++;
					res = term();
					switch(op){
					case '+': 
						res = (old + res) % p;
						break;
					case '-':
						int temp = p - res;
						res = (temp + old) % p;
						break;
					}
				}
				else break;
			}
			return res;
		}

		private int term() {
			if(flg){
				return 1;
			}
			int res = fact();
			while(true){
				char op = str.charAt(pos);
				if((op == '*') || (op == '/')){
					int old = res;
					pos++;
					res = fact();
					switch(op){
					case '*':
						res = (old * res) % p;
						break;
					case '/':
						if(res == 0){
							flg = true;
							return 1;
						}
						int temp = modpow(res,p-2, p);
						res = (old * temp) % p;
						break;
					}
				}
				else break;
			}
			return res;
		}

		private int fact() {
			if(flg) return 1;
			if(Character.isDigit(str.charAt(pos))){
				int t = str.charAt(pos) - '0';
				pos++;
				while(Character.isDigit(str.charAt(pos))){
					t = t * 10 + (str.charAt(pos) - '0');
					pos++;
				}
				return t;
			}
			else if(str.charAt(pos) == '('){
				pos++;
				int res = exp();
				pos++;
				return res;
			}
			return 0;
		}
	}

	private int modpow(int a, int e, int mod) {
		long result = 1;
		while(e > 0){
			if((e&1) == 1){
				result = (result * a) % mod;
			}
			e >>= 1;
			a = (a * a) % mod;
		}
		return (int)result;
	}


	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 56580
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int a; cin >> a;
    string s; cin >> s;
    if(a>=3200) cout << s << endl;
    else cout << "red" << endl;
    
    return 0;
}





Measured memory_bytes: 256
a = int(input())
res = 0
flag = False
for i in range(0, a):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        res += 1
    else:
        res = 0
    if res == 3:
        flag = True
        break
if flag:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 8844
#include <iostream>
#include <cstring>
#define MOD 1000000007
using namespace std;

int n, x, arr[200010], k[200010];

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>x;
	if(x==1||x==2*n-1){
		cout<<"No";
		return 0;
	}
	if(n==2){
		if(x==1||x==3){
			cout<<"No";
			return 0;
		}
		cout<<"Yes"<<endl<<1<<endl<<2<<endl<<3<<endl;
		return 0;
	}
	arr[n]=x;
	k[x]=1;
	if(x<3){
		arr[n-1]=x-1;
		arr[n+1]=x+1;
		arr[n-2]=x+2;
		k[x-1]=1;
		k[x+1]=1;
		k[x+2]=1;
	}else{
		arr[n-1]=x-1;
		arr[n+1]=x+1;
		arr[n+2]=x-2;
		k[x-1]=1;
		k[x+1]=1;
		k[x-2]=1;
	}

	int j=1;
	for (int i = 1; i <= 2*n-1; ++i){
		if(!arr[i]){
			while(k[j])j++;
			arr[i]=j;
			k[j]=1;
			j++;
		}
	}
	cout<<"Yes"<<endl;
	for (int i = 1; i <= 2*n-1; ++i){
		cout<<arr[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// gcd, lcm
ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}


int main() {
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2 == 1) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#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 <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 200000000
#define LINF 1000000000000000000

using namespace std;

const int N = 8e5 + 10;

LL a[N];
int h[N];
LL dp[N];
LL tree[N];

void update(int v, int l, int r, int pos, LL val) {

	if (l > pos || r < pos)
		return;

	if (l == r) {
		tree[v] = val;
		return;
	}

	int mid = (l + r) / 2;
	update(v * 2, l, mid, pos, val);
	update(v * 2 + 1, mid + 1, r, pos, val);

	tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
}

LL mx(int v, int l, int r, int r1) {

	if (l > r1)return 0;

	if (r <= r1)
		return tree[v];

	int mid = (l + r) / 2;
	return max(mx(v * 2, l, mid, r1), mx(v * 2 + 1, mid + 1, r, r1));
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1;i <= n;i++)
		scanf("%d", &h[i]);

	for (int i = 1;i <= n;i++)
		scanf("%lld", &a[i]);

	for (int i = 1;i <= n;i++) {
		dp[i] = mx(1, 1, n, h[i]) + a[i];
		update(1, 1, n, h[i], dp[i]);
	}

	LL ans = 0;
	for (int i = 1;i <= n;i++)
		ans = max(ans, dp[i]);

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

Measured memory_bytes: 11216
#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<complex>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=1000000000000;
const ll mod=998244353;

ll  MOD(ll  a,ll  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
ll  max3(ll  a,ll  b,ll c)
{
    return max(c,max(a,b));
}
ll min3(ll a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y )
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);//%mod;
        y = y>>1;
        x = (x*x);//%mod;
    }
    return res;//%mod;
}
ll  power1(ll  x,ll  y )
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod;
        y = y>>1;
        x = (x*x)%mod;
    }
    return res%mod;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x)
{
    return power1(x,mod-2);
}
int n;
ll W;
vll v;
vll weight;
int main()
{
    cin>>n;
    v.resize(n);
    cin>>W;
    weight.resize(n);
    for(int i=0;i<n;i++)
    {
        cin>>weight[i];
        cin>>v[i];
    }
    ll dp[101][100001];
    for(int j=0;j<101;j++)
    {
        dp[j][0]=0;
        for(int k=1;k<100001;k++)
        {
            dp[j][k]=INF;
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int k=0;k<=100000;k++)
        {
            if(i>0)
            {
                if(v[i]<=k)
                {
                    dp[i][k]=min3(dp[i][k],dp[i-1][k-v[i]]+weight[i],dp[i-1][k]);
                }
                else
                {
                    dp[i][k]=min(dp[i][k],dp[i-1][k]);
                }
            }
            else
            {
                if(k==v[i])
                {
                    dp[i][k]=weight[i];
                }
            }
        }
    }
    for(int j=100000;j>=0;j--)
    {
        if(dp[n-1][j]<=W)
        {
            cout<<j;return 0;
        }
    }
    cout<<0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    int costs[N];
    for(int i = 0; i < N; i++) {
        cin >> costs[i];
    }
    int sum = 0;
    for(int i = 0; i < N; i++) {
        int cc;
        cin >> cc;
        if(costs[i] < cc) {
            costs[i] = 0;
        } else {
            costs[i] = costs[i] - cc;
        }
        sum += costs[i];
    }
    cout << sum;

    return 0;
}

Measured memory_bytes: 256
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n1 = Number(lines.shift());
  const arr1 = lines.shift().split(' ').map(Number);
  const n2 = Number(lines.shift());
  const arr2 = lines.shift().split(' ').map(Number);

  const solve = memoization(function(i, m) {
    if (m == 0) return true;
    if (i >= n1) return false;
    return solve(i + 1, m) || solve(i + 1, m - arr1[i]);
  });

  arr2.map(m => solve(0, m) ? 'yes' : 'no').forEach(res => console.log(res));
})();

function memoization(f) {
  let cache = {};
  return function innerFunc(...param) {
    const c = cache[param];
    if (typeof c !== 'undefined') return c;
    return cache[param] = f(...param);
  }
}



Measured memory_bytes: 24396
#include<iostream>
//#include<algorithm>
#include<cmath>
#include<string>
//#include<set>
//#include<vector>
#include<iomanip>
using namespace std;
int main(){

    int n;
    cin >> n;
    if(n%10==7){cout<<"Yes"; return 0;}
    else{n/=10;}
    if(n%10==7){cout<<"Yes"; return 0;}
    else{n/=10;}
    if(n%10==7){cout<<"Yes"; return 0;}
    else{n/=10;}
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3504
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<queue>
typedef long long ll;
using namespace std;
#define INF (1 << 30)
#define INFLL (1LL << 60)
#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 true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void exec()
{
	ll ans = 0;
	int N; cin >> N;
	vector<int> L, R;
	vector<pair<int, int>> Kl, Kr;

	int il = 0, ir = 0;
	rep(i, N) {
		int k, l, r;
		cin >> k >> l >> r;
		int d = l - r;
		if (d > 0) {
			ans += r;
			L.push_back(d);
			Kl.push_back(make_pair(k, il++));
		}
		else if (d < 0) {
			ans += l;
			R.push_back(r - l);
			Kr.push_back(make_pair(N - k, ir++));
		}
		else {
			ans += l;
		}
	}

	using Pii = pair<int, int>;
	auto solve = []
	(
			vector<int> happy
		,	vector<pair<int, int>> ki
	)
	{
		ll happiest = 0;
		priority_queue<Pii, vector<Pii>, greater<Pii>> pq;	//嬉しさ差分、インデックス
		sort(ki.begin(), ki.end());
		int hz = happy.size();
		int k = 0, idx = 0;
		while (idx < hz) {
			k = ki[idx].first;
			while ((idx < hz) && k == ki[idx].first) {
				int i = ki[idx].second;
				pq.emplace(make_pair(happy[i], i));
				++idx;
			}
			//K番以内からはみ出すものを取り除く
			while (pq.size() > k) pq.pop();
		}
		while (!pq.empty()) {
			Pii hi = pq.top(); pq.pop();
			happiest += happy[hi.second];
		}
		return happiest;
	};
	ans += solve(L, Kl);
	ans += solve(R, Kr);
	cout << ans << endl;
}

int main()
{
	int T; cin >> T;
	rep(i, T) exec();
	return 0;
}


Measured memory_bytes: 8312
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int Ans = 0;
        for (int i=0;i<3;i++){if(S.charAt(i)==T.charAt(i)){Ans += 1;}}
        System.out.println(Ans);
    }
}

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

const int INF = 1 << 30;
 
int main()
{
  long long  N, C[500], S[500], F[500];
 
  cin >> N;
  for(int i = 0; i < N - 1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }
 
  for(int i = 0; i < N - 1; i++) {
    long long t = 0;
    for(int j = i; j < N - 1; j++) {
      t = max(t, S[j]);
      t = S[j] + C[j] + (t - S[j] + F[j] - 1) / F[j] * F[j];
    }
    cout << t << endl;
  }
  cout << 0 << endl;
 
 
}

Measured memory_bytes: 256
mod = 1000000007
n, k = map(int, input().split())
d = [0] * (k+1)
for i in range(1, k+1):
    d[i] = pow(k//i, n, mod)
for i in range(k, 0, -1):
    for j in range(2*i, k+1, i):
        d[i] -= d[j]
        d[i] %= mod
ans = 0
for i in range(1,k+1):
    ans += d[i] * i
    ans %= mod
print(ans)

Measured memory_bytes: 11136
N = int(input())
S = input()
 
def z_algo(s):
    s_length = len(s)
    l, r = 0, 0
    Z = [0]*s_length
    Z[0] = s_length
    for i in range(1, s_length):
        if r<i:
            l, r = i, i
            while r<s_length and s[r]==s[r-l]:
                r += 1
            Z[i] = r-i
            r -= 1
        else:
            k = i-l
            if i+Z[k]-1<r:
                Z[i] = Z[k]
            else:
                l = i
                while r<s_length and s[r]==s[r-l]:
                    r += 1
                Z[i] = r-i
                r -= 1
    return Z

ans = 0
for i in range(N):
    z = z_algo(S[i:])
    for j in range(i, N):
        ans = max(ans, min(j-i, z[j-i]))
print(ans)

Measured memory_bytes: 48860