akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    int n,a,b;
    scanf("%d%d%d", &n,&a,&b);

    printf("%d\n", MIN(a*n,b));





    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

void ROLL_E(int dice[6])
{
	
	int a = dice[0];
	dice[0] = dice[3];
	dice[3] = dice[5];
	dice[5] = dice[2];
	dice[2] = a;
}

void ROLL_N(int dice[6])
{
	int a = dice[0];
	dice[0] = dice[1];
	dice[1] = dice[5];
	dice[5] = dice[4];
	dice[4] = a;
}
void ROLL_S(int dice[6])
{
	int a = dice[0];
	dice[0] = dice[4];
	dice[4] = dice[5];
	dice[5] = dice[1];
	dice[1] = a;
}
void ROLL_W(int dice[6])
{
	int a = dice[0];
	dice[0] = dice[2];
	dice[2] = dice[5];
	dice[5] = dice[3];
	dice[3] = a;		
}
int main()
{
	int i,j,a;
	int dice[6] = {0};
	char move;
	
	for(i=0;i<6;i++){
		scanf("%d\n",&dice[i]);
	}
	
	while(1){
		scanf("%c",&move);
		if(move == 'E'){
			ROLL_E(dice);
		}else if(move == 'N'){
			ROLL_N(dice);
		}else if(move == 'S'){
			ROLL_S(dice);
		}else if(move == 'W'){
			ROLL_W(dice);
		}
		
		if(move == '\n'){
			break;
		}
	}
	
	printf("%d\n",dice[0]);
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
typedef long long ll;
const int mod = 1e9+7;
int a[N];
int main()
{
    int n;
    while(~scanf("%d", &n))
    {
        memset(a,0,sizeof(a));
        for(int i = 2; i <= n; i++)
        {
            int x = i;
            for(int j = 2; j <= x; j++)
                    while(x%j == 0) x /= j,a[j]++;
            if(x > 1) a[x]++;
        }
        ll ans = 1;
        for(int i = 0; i <= n;i++)
            if(a[i]) ans = ((ans%mod)*(a[i]+1))%mod;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>

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

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

int main(int argc, const char * argv[]) {
    int X, N;
    cin >> X >> N;
    
    vector<int> p(N,0);
    for(int i=0; i<N; i++){
        cin >> p[i];
    }
    
    sort(p.begin(), p.end());
    
    int c = 0;
    int ans = X;
    
    while(N){
        int x1 = X-c;
        int x2 = X+c;
        
        bool jauge1=true;
        bool jauge2=true;
        for(int i=0; i<N; i++){
            if(p[i]==x1){
                jauge1=false;
            }
            if(p[i]==x2){
                jauge2=false;
            }
        }
    
        if(jauge1){
            ans = x1;
            break;
        }
        if(jauge2){
            ans = x2;
            break;
        }
        c++;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	

	void solve(){
		


		ini(n);
		int tmp = 0;
		FOR(i,1,1e7){
			tmp*=10;
			tmp+=7;
			if(tmp%n ==0){
				return out(i);
			}
			tmp%=n;
		}
		out(-1);
			
			
			


				
		


		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>

using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define shosu setprecision(10)
typedef long long ll;
typedef pair<ll,ll> P;
ll longinf=1ll<<60;



ll n,m,s,t;
ll dista[100002],distb[100002];
vector<P> machia[100002],machib[100002];
priority_queue<P,vector<P>,greater<P>> quea,queb;
ll mini[100002];

int main(){
  cin>>n>>m>>s>>t;
  rep1(i,m){
    ll u,v,a,b;
    cin>>u>>v>>a>>b;
    machia[u].push_back(make_pair(a,v));
    machia[v].push_back(make_pair(a,u));
    machib[u].push_back(make_pair(b,v));
    machib[v].push_back(make_pair(b,u));
  }
  rep1(i,n){
    dista[i]=longinf;
    distb[i]=longinf;
  }
  dista[s]=0;
  rep0(i,machia[s].size()){
    quea.push(machia[s][i]);
    dista[machia[s][i].second]=machia[s][i].first;
  }
  while(quea.size()){
    P p=quea.top();
    quea.pop();
    if(p.first>dista[p.second]) continue;
    for(int i=0;i<machia[p.second].size();i++){
      if(machia[p.second][i].first+dista[p.second]<dista[machia[p.second][i].second]){
        dista[machia[p.second][i].second]=machia[p.second][i].first+dista[p.second];
        quea.push(machia[p.second][i]);
      }
    }
  }
   distb[t]=0;
  rep0(i,machib[t].size()){
    queb.push(machib[t][i]);
    distb[machib[t][i].second]=machib[t][i].first;
  }
  while(queb.size()){
    P p=queb.top();
    queb.pop();
    if(p.first>distb[p.second]) continue;
    for(int i=0;i<machib[p.second].size();i++){
      if(machib[p.second][i].first+distb[p.second]<distb[machib[p.second][i].second]){
        distb[machib[p.second][i].second]=machib[p.second][i].first+distb[p.second];
        queb.push(machib[p.second][i]);
      }
    }
  }
  ll shozikin=1e15;
  mini[n]=dista[n]+distb[n];
  for(int i=n-1;i>=1;i--){
    mini[i]=min(mini[i+1],dista[i]+distb[i]);
  }
  rep1(i,n){
    printf("%ld\n",shozikin-mini[i]);
  }
    return 0;
}


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

string s;
ll ans = 0;

void dfs(int idx, ll sum, ll num){
    if(idx == s.size()){
        ans += sum + num;
        return;
    }
    // + を入れない場合
    dfs(idx + 1, sum, num * 10 + s[idx] - '0');
    // + を入れる場合
    if(idx != 0) dfs(idx + 1, sum + num, s[idx] - '0');
}

int main(){
    cin >> s;
    dfs(0, 0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<climits>
#include<ctime>
#include<complex>
#include<sstream>
#include<cstring>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

struct edge{
    int to,cost;
    edge(int a,int b):to(a),cost(b){}
    edge(){}
};
int memo[400];
vector<edge>G[400];

int dfs(int pos){
    if(memo[pos]!=-1)return memo[pos];

    int ret=0;
    rep(i,G[pos].size()){
        edge &e=G[pos][i];
        ret=max(ret,dfs(e.to)+e.cost);
    }
    return memo[pos]=ret;
}
int main(){
    int N,M;
    scanf("%d%d",&N,&M);
    rep(i,M){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        G[b].pb(edge(a,c));
    }

    fill_n(memo,N,-1);
    memo[0]=0;
    printf("%d\n",dfs(N-1));
    return 0;
}

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

string nums[3] = {"3", "5", "7"};
int N;

bool is753Num(int n) {
  if (n > N) {
    return false;
  }

  bool exist3 = false;
  bool exist5 = false;
  bool exist7 = false;

  while (n != 0) {
    int lastDidit = n % 10;
    if (lastDidit == 3) {
      exist3 = true;
    } else if (lastDidit == 5) {
      exist5 = true;
    } else if (lastDidit == 7) {
      exist7 = true;
    }

    n /= 10;
  }

  return exist3 && exist5 && exist7;
}

int solve(string &s) {
  if (s.size() >= 9) {
    return 0;
  }

  int count = 0;
  for (int i = 0; i < 3; i++) {
    string sNext = s + nums[i];
    if (is753Num(stoi(sNext))) {
      count++;
    }
    count += solve(sNext);
  }

  return count;
}

int main() {
  cin >> N;

  string s = "";
  cout << solve(s) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,m,k;
int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<=n;++i)
	{
		for(int j=0;j<=m;++j)
		{
			int f=i*m+j*n-i*j*2;
			if(f==k)
			{
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
}


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

const int maxn = 1e5 + 10;
typedef long long int ll;
double pi = 3.14159;
void solved(){
    int r;cin>>r;
    printf("%.2lf\n",2.0 * pi * r);
}
int main(){
    solved();
    return 0;
}

Measured memory_bytes: 3752
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String str1 = scan.nextLine();
		String str2 = scan.nextLine();
		
		String[] strAry = str2.split(" ");
//		int int1 = Integer.parseInt(strAry[0]);
//		int int2 = Integer.valueOf(strAry[1]).intValue();
		
		int num = Integer.parseInt(str1);
		int minP = 1;
		int minPow=0;
		for(int i =1; i < 101; i++) {
			int pow = 0;
			for(int l =0; l < num; l++) {
				pow += Math.pow(Integer.parseInt(strAry[l])-i, 2);
			}
			if(i==1) {
			    minPow = pow;
			}else if(minPow>pow){
			    minPow = pow;
			    minP = i;
				
			}
		
		}
		System.out.println(minPow);



		
	
		
	}

}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  if(a1 > b1){
    swap(a1, b1); swap(a2, b2);
  }
  if(a2 < b2){
    cout << 0 << endl;
    return 0;
  }
  ll pre = t1 * (a1 - b1);
  ll post = t2 * (a2 - b2);
  ll all = pre + post;
  if(all == 0){
    cout << "infinity" << endl;
  }
  else if(all > 0){
    ll num = ((-1LL * pre) / all + 1LL) * 2LL - 1LL;
    if(pre % all == 0) num --;
    cout << num << endl;
  }
  else{
    cout << 0 << endl;
  }

}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  ll n, tmp, cnt = 1;
  cin >> n;
  map<int, int> mp;

  rep(i, n) {
    cin >> tmp;
    mp[tmp]++;
  }

  bool flg = true;
  if (n % 2 != 0) {
    if (mp[0] != 1) {
      flg = false;
    }
    for (auto x : mp) {
      if (x.first == 0) continue;
      if (x.second != 2) {
        flg = false;
      } else {
        cnt *= 2;
        cnt %= MOD;
      }
    }
  } else {
    for (auto x : mp) {
      if (x.second != 2)
        flg = false;
      else {
        cnt *= 2;
        cnt %= MOD;
      }
    }
  }

  cout << (flg ? cnt : 0) << endl;
  return 0;
}


Measured memory_bytes: 3200
from collections import defaultdict
n = int(input())

def f(x):
    a1 = int(str(x)[0])
    a2 = x%10
    return (a1, a2)

count = defaultdict(int)
for x in range(1, n+1):
    key = f(x)
    count[key] += 1

ans = 0
for x in range(1, n+1):
    a0, a1 = f(x)
    if a1 != 0:        # !
        key = (a1, a0) # swap
        ans += count[key]

print(ans)

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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>


#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

char getOther(char ch) {
    for (auto x: {'R', 'G', 'B'})
        if (x != ch)return x;
}

char gett(char ch, char ch1) {
    for (auto x: {'R', 'G', 'B'})
        if (x != ch and x != ch1)return x;
}

void solve() {
    int n;
    cin >> n;

    string s;
    cin >> s;

    map<char, ordered_set > mp;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        char cur = s[i];
        char next = getOther(s[i]);
        char nn = gett(cur, next);
        for (auto x:mp[next]) {
            int id = i - x;
            int fd = (i - 2 * x) * -1;
            int del = 0;
            if (mp[nn].find(fd) != mp[nn].end())del = -1;

            ans += mp[nn].order_of_key(x) + del;
        }
        swap(nn, next);
        for (auto x:mp[next]) {
            int id = i - x;
            int fd = (i - 2 * x) * -1;
            int del = 0;
            if (mp[nn].find(fd) != mp[nn].end())del = -1;

            ans += mp[nn].order_of_key(x) + del;
        }
        mp[s[i]].insert(i);
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3920
import java.util.*;

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

    public static void main(String[]$) {
        int[] in = new int[] {scanner.nextInt(), scanner.nextInt(), scanner.nextInt()};
        Arrays.sort(in);
        System.out.println(in[0] + in[1]);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> x(n + 2, 0), v(n + 2, 0);
  for (int i = 1; i <= n; i++) cin >> x[i] >> v[i];
  x[n + 1] = k;
  vector<long long> c(n + 1, 0), C(n + 1, 0), d(n + 1, 0), D(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    c[i] = c[i - 1] + v[n + 1 - i] - (x[n + 2 - i] - x[n + 1 - i]);
    C[i] = C[i - 1] + v[n + 1 - i] - ((x[n + 2 - i] - x[n + 1 - i]) << 1);
    d[i] = d[i - 1] + v[i] - (x[i] - x[i - 1]);
    D[i] = D[i - 1] + v[i] - ((x[i] - x[i - 1]) << 1);
  }
  for (int i = 1; i <= n; i++) {
    c[i] = max(c[i], c[i - 1]);
    C[i] = max(C[i], C[i - 1]);
    d[i] = max(d[i], d[i - 1]);
    D[i] = max(D[i], D[i - 1]);
  }
  long long ret = 0;
  for (int i = 0; i <= n; i++) {
    ret = max(ret, c[i] + D[n - i]);
    ret = max(ret, C[i] + d[n - i]);
  }
  cout << ret << '\n';
  return 0;
}


Measured memory_bytes: 4992
#!/usr/bin/env python3
import sys

def calc(n, k):
    ret = 0
    while n < k:
        n *= 2
        ret += 1
    return ret


def solve(N: int, K: int):
    ret = 0.0
    for i in range(1, N + 1):
        ret += (0.5 ** calc(i, K)) * (1.0 / N)
    print(ret)
    return


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

if __name__ == '__main__':
    main()


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

int a,b;
int ans;

inline bool judge(int x){
	int k=x,len=0,p[10];
	while(k){
		p[++len]=k%10;
		k/=10;
	}
	for(int i=1;i<=len/2+1;i++){
		if(p[i]!=p[len-i+1])return false;
	}
	return true;
}

int main(){
	cin>>a>>b;
	for(int i=a;i<=b;i++){
		if(judge(i))ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
 
ans = 0
tmp = 0
 
for i in range(n-1):
    if h[i] >= h[i+1]:
        tmp += 1
    elif h[i] < h[i+1]:
        ans = max(ans, tmp)
        tmp = 0
ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int cnt = 0;
    string s, a;
    cin >> s;
    a = s;
    reverse(a.begin(), a.end());
    int len = s.size();
    for(int i = 0 ; i < len ; i++)
    {
        if(s[i] != a[i])
        {
            cnt++;
        }
    }
    if(cnt % 2 != 0)
    {
        cout << cnt / 2 + 1 << endl;
    }
    else
    {
        cout << cnt / 2 << endl;
    }
    return 0;
}


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


int main(){
  int n;
  cin >> n;
  long L[87];
  L[0] = 2;
  L[1] = 1;

  for(int i = 2; i <= n; i++){
    L[i] = L[i - 1] + L[i - 2];
  }
  cout << L[n] << endl;
}


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

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

    if (x < a) {
        cout << "NO" << endl;
    }
    else {
        if (x - a <= b) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


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

const int MAN_N = 100;
long long int N, K, d;
int A[100*100];

int main(void) {
  cin >> N >> K;
  int num;
  int d[K];
  int index = 0;
  int i     = 0;
  bool roop = true;
  int sum   = 0;
  cin >> d[i];
  for (int j=0; j<10000; j++) {
    if (index == d[i] && i != K) {
      cin >> d[i+1];
      index = 0;
      i = i+1;
    } else if (index == d[i] && i != K) {
      break;
    } else {
      cin >> A[sum];
      sum++;
      index++;
    }
  }
  sort(A, A + sum);
  int ans = 0;
  for (int k=1; k<=N; k++) {
    int a = 0;
    for (int j=0; j<sum; j++){
      if (A[j] == k) a++; 
    }
    if (a == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace std; 
using namespace __gnu_pbds;
 
typedef long long ll;
typedef double db;
typedef long double ld;
typedef string str;
 
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<str, str> pstr;
 
typedef vector<int> vi; 
typedef vector<ll> vll; 
typedef vector<db> vdb; 
typedef vector<ld> vld;
typedef vector<str> vstr; 
typedef vector<pi> vpi;
typedef vector<pll> vpll; 
typedef vector<pdb> vpdb; 
 
#define fi first
#define se second
#define mp make_pair
#define pf push_front 
#define pb push_back
#define ins insert 
#define eb emplace_back 
#define fbo find_by_order
#define ook order_of_key
#define rsz resize
#define lb lower_bound 
#define ub upper_bound 

#define len(s) (int)s.length()
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define srt(v) sort(all(v))

#define rep(a, b, c) for(int a=b; a<c; a++) 
#define per(a, b, c) for(int a=b; a>c; a--) //do not include boundaries on the right
#define repn(a, b, c) for(int a=b; a<=c; a++) 
#define pern(a, b, c) for(int a=b; a>=c; a--) //include boundaries on the right
 
#define yes cout << "YES"<< "\n" 
#define no cout << "NO" << "\n" 
#define out(x) cout << x << "\n"
#define outs(x) cout << x << " "
#define el cout << "\n"

#define navi ios_base::sync_with_stdio(false); cin.tie(NULL)    
 
const ll mod = 1e9+7;
const double eps = 1e-9;

int main(){
	navi;
	ll n; cin >> n;
  ll a[100003];
  ll sum=0;
  rep(i,0,100003){
   a[i]=0;
  }
  rep(j,0,n){
   ll m; cin >> m;
    a[m]++;
    sum+=m;
  }
  ll q; cin >> q;
  rep(k,0,q){
    ll x, y; cin >> x >> y;
    sum+=a[x]*(y-x);
    a[y]+=a[x];
    a[x]=0;
    out(sum);
  }
}


Measured memory_bytes: 4320
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int w[n],ans[n];
	for(int i=0;i<n;i++)
	{
		cin>>w[i];
	}
	int sum,sum1;
	for(int i=0;i<n;i++)
	{
		sum=0;
		sum1=0;
		for(int l=0;l<i;l++)
		{
			sum+=w[l];
		}
		for(int j=i;j<n;j++)
		{
			sum1+=w[j];
		}
		ans[i]=abs(sum-sum1);
	}
	int min=9999;
	for(int i=0;i<n;i++)
	{
		if(ans[i]<min)
		{
			min=ans[i];
		}
	}
	cout<<min;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
#include <iostream>
#include <cmath>
#include<map>
using namespace std;

int main(){
    int N;
    map<string,int>S;
    cin>>N;
    string S_;
    for(int i=0;i<N;i++){
        cin>>S_;
        S[S_]=1;
    }
    cout<<S.size();



}

Measured memory_bytes: 19228
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;string s;
    cin>>n>>k;k--;
    cin>>s;
    if(s[k]=='A')
    s[k]='a';
    else if(s[k]=='B')
    s[k]='b';
    else
    s[k]='c';
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
a = raw_input()
n = int(a.split(" ")[0])
k = int(a.split(" ")[1])

def toStr(n,base):
   convertString = "0123456789ABCDEF"
   if n < base:
      return convertString[n]
   else:
      return toStr(n//base,base) + convertString[n%base]

res = toStr(n,k)
print(len(str(res)))

Measured memory_bytes: 2568
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    private static int[] cards;
    
    public static void main(String[] args) {
        int n;
        while((n = scn.nextInt()) > 0) {
            createCards(n);
            for(int i = scn.nextInt(); i > 0; i--) {
                shuffleCards();
            }
            System.out.println(cards[0]);
        }
    }
    
    private static void createCards(int n) {
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) {
            ary[i] = n - i;
        }
        cards = ary;
    }
    
    private static void shuffleCards() {
        int p = scn.nextInt() - 1, c = scn.nextInt();
        int[] btm = Arrays.copyOfRange(cards, 0, p);
        int[] top = Arrays.copyOfRange(cards, p, p + c);
        System.arraycopy(top, 0, cards, 0, top.length);
        System.arraycopy(btm, 0, cards, top.length, btm.length);
    }
}

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

struct JOI{//cがn個ある
	char c;
	int n;
};

std::vector<JOI> jv;
std::string str;

void kako(){
	char c = str[0];
	int n = 1;
	int str_length = str.size();
	for(int i=1;i<str_length;i++){
		if(c != str[i]){
			jv.push_back({c, n});
			c = str[i];
			n = 1;
		}else{
			n++;
		}
	}
	jv.push_back({c, n});
}

int main(){
	std::cin >> str;
	kako();

	int jv_size = jv.size(), k = 0;
	for(int l=0;l+2<jv_size;l++){
		JOI j = jv[l], o = jv[l+1], i = jv[l+2];
		if(j.c == 'J' && o.c == 'O' && i.c == 'I' && j.n >= o.n && i.n >= o.n){
			k = std::max(k, o.n);
		}
	}

	std::cout << k << std::endl;
}

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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const ll mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k, q;
    cin >> k >> q;
    vector<int> d1(k);
    for (auto &c : d1) cin >> c;
    while (q--) {
        int n, x, m;
        cin >> n >> x >> m;
        vector<int> d = d1;
        for (auto &c : d) c %= m;
        int total = n - 1;
        /// a[j] = a[j + 1]
        ll last = x;
        for (int i = 0; i < k; i++) {
            ll cnt = (n - 1) / k + (i < ((n - 1) % k));
            if (d[i] == 0) total -= cnt;
            last += d[i] * cnt;
        }
        /// a[j] > a[j + 1]
        total -= (last / m - x / m);
        cout << total << "\n";
    }
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>

using namespace std;

int main() {
	int N;
	cin >> N;
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.size() - 2; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<cstring>
#include<vector>
#define pa pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
const int M=1e7+10,N=2e3+10;
struct edge{int next,to,w;}a[N*N*2];
int pri[M],tot,head[N],cnt=1,cur[N],S,T;
int dep[N],nod,dis[N],n,ans;
bool ispri[M],A[M],B[M];
vector<pa> L,R;
queue<int> Q;
void Pre()
{
	int u=1e7;
	for(int i=2;i<=u;i++)
	{
		if(!ispri[i]) pri[++tot]=i;
		for(int j=1;j<=tot&&pri[j]*i<=u;j++)
		{
			ispri[i*pri[j]]=1;
			if(i%pri[j]==0) break;
		}
	}
	ispri[1]=ispri[2]=1;
}
void link(int x,int y,int w)
{
	a[++cnt]=(edge){head[x],y,w};head[x]=cnt;
	a[++cnt]=(edge){head[y],x,0};head[y]=cnt;
}
int BFS()
{
	memset(dep,0,sizeof(dep));
	dep[S]=1;Q.push(S);
	while(!Q.empty())
	{
		int x=Q.front();Q.pop();
		for(int i=head[x];i;i=a[i].next)
			if(!dep[a[i].to]&&a[i].w)
				dep[a[i].to]=dep[x]+1,Q.push(a[i].to);
	}
	return dep[T];
}
int DFS(int x,int flow)
{
	if(x==T) return flow;
	for(int &i=cur[x];i;i=a[i].next)
	{
		int R=a[i].to;
		if(!a[i].w||dep[R]!=dep[x]+1) continue;
		int k=DFS(R,min(flow,a[i].w));
		if(k) {a[i].w-=k;a[i^1].w+=k;return k;}
	}
	return 0;
}
int main()
{
	Pre();cin>>n;
	for(int i=1,x;i<=n;i++) cin>>x,A[x]=1;
	for(int i=1;i<=1e7+1;i++)
		if(A[i]!=A[i-1]) i%2?L.pb(mp(++nod,i)):R.pb(mp(++nod,i));
	S=nod+1;T=S+1;
	for(auto x:L) link(S,x.fi,1);
	for(auto x:R) link(x.fi,T,1);
	for(auto x:L)
		for(auto y:R)
			if(!ispri[abs(y.se-x.se)])
				link(x.fi,y.fi,1);
	while(BFS())
	{
		for(int i=1;i<=T;i++) cur[i]=head[i];
		while(int tmp=DFS(S,100000)) ans+=tmp;
	}
	int res1=(L.size()-ans)/2;
	int res2=(R.size()-ans)/2;
	int res3=(L.size()-ans)%2;
	ans=ans+res1*2+res2*2+res3*3;
	cout<<ans<<endl;
}


Measured memory_bytes: 26880
#include <stdio.h>
using namespace std;

int main(){
	int a, b, c, d, e, k;
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
	if(e - a <= k) printf("Yay!\n");
	else printf(":\(\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define 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;
}
 
 
int main() { 
    int n;
    cin >> n;
    vector<int64_t> a(n);
    for (int i = 0 ; i < n; i++) {
        cin >> a.at(i);
    }

    vector<int64_t> r(n + 1, 0);
    for (int i = 0; i < n; i++) {
        r.at(i + 1) = r.at(i) + a.at(n - i - 1);
        r.at(i + 1) %= MOD;
    }

    // for (int i = 0; i < n + 1; i++) {
    //     cout << r.at(i) << endl;
    // }

    int64_t ans = 0;
    for (int i = 0; i < n - 1; i++) {
        int64_t x = a.at(i) * r.at(n - i - 1);
        x %= MOD;
        ans += x;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6420
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int K, A, B;

    cin >> K >> A >> B;

    string Answer = "NG";

    for (int i = A; i <= B; i++)
    {
        if (i % K == 0)
        {

            Answer = "OK";
            break;
        }
    }

    cout << Answer << endl;
}

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

N,M=map(int,input().split())
MAP=[list(input().strip()) for i in range(N)]

start=N*M+2
goal=N*M+3

EDGE=[set() for i in range(N*M+5)]

for i in range(N):
    for j in range(M):
        if (i+j)%2==0 and MAP[i][j]==".":
            EDGE[start].add(i*M+j)

            for x,y in [(i+1,j),(i-1,j),(i,j+1),(i,j-1)]:
                if 0<=x<N and 0<=y<M and MAP[x][y]==".":
                    EDGE[i*M+j].add(x*M+y)

        if (i+j)%2==1 and MAP[i][j]==".":
            EDGE[i*M+j].add(goal)

count=0 # カット数をカウント

while True:

    USED=[0]*(N*M+5)
    ROUTE=[-1]*(N*M+5)
    Q=[start]
    
    while Q: # 探索
        NOW=Q.pop()
        if NOW==goal:
            break
        
        for to in EDGE[NOW]:
            if USED[to]==0:
                ROUTE[to]=NOW # EDGEの更新用に後ろから辿る方法を覚えておく
                USED[to]=1
                Q.append(to)
    else:
        break

    count+=1
    i=goal
    while i!=start: # goalからたどり,Routeを使ってEDGEの更新
        j=ROUTE[i]
        EDGE[j].remove(i) # 使ったルートをいけなく更新
        EDGE[i].add(j) # 逆向きに進めるようにする.これらを重みつきにすれ普通のフロー
        i=j
        
print(count)

for i in range(N):
    for j in range(M):
        if (i+j)%2==1:
            for to in EDGE[i*M+j]:
                if M>1 and to == i*M+j-1:
                    MAP[i][j]="<"
                    MAP[i][j-1]=">"
                elif M>1 and to == i*M+j+1:
                    MAP[i][j]=">"
                    MAP[i][j+1]="<"
                elif to == i*M+j-M:
                    MAP[i][j]="^"
                    MAP[i-1][j]="v"
                elif to == i*M+j+M:
                    MAP[i][j]="v"
                    MAP[i+1][j]="^"

for m in MAP:
    print("".join(m))
                    


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

bool overlap(int a, int b, int c, int d){
  if ( d <= a ) return false;
  if ( b <= c ) return false;
  return true;
}
 
int main(){
  int a, b, s, f, n;
  cin >> a >> b >> n;
  for ( int i = 0; i < n; i++ ){
    cin >> s >> f;
    if ( overlap(a, b, s, f) ){
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 3104
s = input()
n = list(map(int, [int(s[i]) for i in range(len(s))]))

for i in range(2**3):
  tmpsum = n[0]
  ops = []
  for j in range(3):
    if (( i >> j) & 1):
      tmpsum += n[j+1]
      ops += ["+"]
    else:
      tmpsum -= n[j+1]
      ops += ["-"]
      
  if tmpsum == 7:
    ans = ""
    for k in range(3):
      ans += s[k] + ops[k]
    print(ans + s[3] + "=7")
    break

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

using namespace std;

class DisjointSets {
private:
    vector<int> rank;
    vector<int> parent;

public:
    DisjointSets() {}

    DisjointSets(int size)
    {
        rank.resize(size, 0);
        parent.resize(size, 0);
        for (int i = 0; i < size; i++)
            makeSet(i);
    }

    void makeSet(int x)
    {
        rank[x] = 0;
        parent[x] = x;
    }

    int findSet(int x)
    {
        if (x != parent[x])
            parent[x] = findSet(parent[x]);
        return parent[x];
    }

    void unite(int x, int y)
    {
        link(findSet(x), findSet(y));
    }

    void link(int rep1, int rep2)
    {
        if (rank[rep1] < rank[rep2])
            parent[rep1] = rep2;
        else
        {
            parent[rep2] = rep1;
            if (rank[rep1] == rank[rep2])
                rank[rep1]++;
        }
    }

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }
};

int main()
{
    int n;
    cin >> n;
    DisjointSets disjointSets(n);
    int query;
    cin >> query;
    int command;
    int x;
    int y;
    for (int i = 0; i < query; i++)
    {
        cin >> command;
        cin >> x >> y;
        if (command == 0)
            disjointSets.unite(x, y);
        else
            cout << (disjointSets.same(x, y) ? 1 : 0) << endl;
    }
}


Measured memory_bytes: 3200
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()


def func(a, b):
    if a | b == 0:
        return 0
    else:
        return 1


class SegmentTree:
    """
    各ノードが半開区間に対応した完全二分木。
    子は親を半分にした区間を持つ。
    構築O(n), 区間に対する操作O(logn), 値の更新O(logn)
    区間に対する操作は最小値, 最大値, 区間に対する和など柔軟に変更して用いよう！
    """

    def __init__(self, x, init_val):  # 構築, init_valは配列の初期値
        self.init_val = init_val
        self.length = 2 ** ((len(x) - 1).bit_length())
        self.data = [init_val] * 2 * self.length
        for i in range(len(x)):
            self.data[i + self.length - 1] = x[i]
        for i in range(self.length - 2, -1, -1):
            self.data[i] = func(self.data[2 * i + 1], self.data[2 * i + 2])

    def teach_current_val(self, index):
        return self.data[index + self.length - 1]

    def replace(self, index, val):  # indexの値をvalに更新
        index += self.length - 1
        self.data[index] = val
        while index:
            index = (index - 1) // 2
            self.data[index] = func(self.data[2 * index + 1], self.data[2 * index + 2])

    def query(self, left, right):  # 半開区間の最小値等を求める, 葉からさかのぼっていくイメージ。
        if right <= left:
            return self.init_val
        left += self.length - 1  # self.dataの位置に合わせる。
        right += self.length - 2  # self.dataの位置に合わせる。半開区間
        ans_ = self.init_val
        while right > left + 1:
            if left & 1 == 0:  # if left_index%2 == 0:
                ans_ = func(ans_, self.data[left])
            if right & 1 == 1:  # if right_index%2 == 1:
                ans_ = func(ans_, self.data[right])
                right -= 1
            left //= 2
            right = (right - 1) // 2
        if left == right:
            ans_ = func(ans_, self.data[left])
        else:
            ans_ = func(func(ans_, self.data[left]), self.data[right])
        return ans_


N = int(input())
S = input()
Q = int(input())
alphabets = string.ascii_lowercase
segs = []
check = dict()
for i in alphabets:
    segs.append([1 if S[l] == i else 0 for l in range(N)])
for i in range(26):
    segs[i] = SegmentTree(segs[i], 0)
for _ in range(Q):
    Query = list(map(str, input().split()))
    if Query[0] == "1":
        i, c = int(Query[1]), Query[2]
        if check.get(str(i - 1)):
            segs[ord(check[str(i - 1)]) - 97].replace(i - 1, 0)
            segs[ord(c) - 97].replace(i - 1, 1)
            check[str(i - 1)] = c
        else:
            segs[ord(S[i - 1]) - 97].replace(i - 1, 0)
            segs[ord(c) - 97].replace(i - 1, 1)
            check[str(i - 1)] = c
    else:
        l, r = map(int, (Query[1], Query[2]))
        ans = 0
        for i in segs:
            ans += i.query(l - 1, r)
        print(ans)


Measured memory_bytes: 367964
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
 
using namespace std;
 
#define MAX_LETTERS  12
 
const char Alphabet[5] = "ACGT";

const int power[MAX_LETTERS + 1] = { 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216 };
 
int cipher(string S)
{
    int Ans = 0;
    
    unsigned size_ = S.size();
 
    for (unsigned i = 0; i < size_; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if (Alphabet[j] == S[i])
            {
                Ans += power[size_ - i - 1] * j;
            }
        }
    }
 
    return Ans;
}
 
int main()
{
    vector<vector<bool> > D;
 
    unsigned n;
 
    for (int i = 0; i <= MAX_LETTERS; i++)
    {
        D.push_back(vector<bool>(power[i], false));
    }
 
    scanf("%d", &n);
 
    vector<string> W;
 
    vector<bool> F(n);
 
    for (unsigned i = 0; i < n; i++)
    {
        char S1[20], S2[20];
 
        scanf("%s%s", &S1, &S2);
 
        if (S1[0] == 'f')
        {
            F[i] = true;
        }
 
        W.push_back(S2);
    }
 
    for (unsigned i = 0; i < n; i++)
    {
        if (F[i] == false)
        {
            D[W[i].size()][cipher(W[i])] = true;
        }
        else
        {
            printf("%s\n", (D[W[i].size()][cipher(W[i])] ? "yes" : "no"));
        }
    }
 
    return 0;
}

Measured memory_bytes: 59916
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define seg_tree_valtype int
#define inf (int)(1e18)

typedef struct {
	seg_tree_valtype *dat;
	int n; //要素数
	int N; //要素数以上の最小の2のべき乗
	seg_tree_valtype (*f)(seg_tree_valtype x, seg_tree_valtype y);//演算
	seg_tree_valtype e;//演算の単位元
}seg_tree;

//要素n, 演算f, 単位元eのsegment_treeを作る
seg_tree *make_seg_tree(int n, seg_tree_valtype (*f)(seg_tree_valtype x, seg_tree_valtype y), seg_tree_valtype e){
	seg_tree *t = (seg_tree *)malloc(sizeof(seg_tree));
	int N, i;
	for(N = 1; N < n; N *= 2){}
	t->dat = (seg_tree_valtype *)malloc(sizeof(seg_tree_valtype) * (2 * N - 1));
	for(i = 0; i < 2 * N - 1; i++){
		t->dat[i] = e;
	}
	t->n = n;
	t->N = N;
	t->f = f;
	t->e = e;
	return t;
}

//i番目の要素を返す
seg_tree_valtype look_val(int i, seg_tree *t){
	if(i < 0 || t->n <= i){
		printf("In function 'look_val':\nrefered out of array\n");
	}
	return t->dat[i + t->N - 1];
}

//i番目の値をxに更新する
void update(int i, seg_tree_valtype val, seg_tree *t){
	if(i < 0 || t->n <= i){
		printf("In function 'update':\nrefered out of array\n");
	}
	i += t->N - 1;
	t->dat[i] = val;
	while(i > 0){
		i = (i - 1) / 2;
		t->dat[i] = (t->f)(t->dat[2 * i + 1], t->dat[2 * i + 2]);
	}
}

seg_tree_valtype query_sub(int a, int b, int k, int l, int r, seg_tree *t){
	if(r <= a || b <= l){
		return t->e;
	}
	else if(a <= l && r <= b){
		return t->dat[k];
	}
	else{
		int h = (l + r) / 2;
		seg_tree_valtype vl = query_sub(a, b, 2 * k + 1, l, h, t);
		seg_tree_valtype vr = query_sub(a, b, 2 * k + 2, h, r, t);
		return (t->f)(vl, vr);
	}
}

//[a, b)の区間に対しての演算の結果を返す
seg_tree_valtype query(int a, int b, seg_tree *t){
	if(a < 0 || b < 0 || t->n < a || t->n < b){
		printf("In function 'query':\nrefered out of array\n");
	}
	if(a >= b){
		return t->e;
	}
	else{
		return query_sub(a, b, 0, 0, t->N, t);
	}
}

int max(int a, int b){
	if(a > b){
		return a;
	}
	else{
		return b;
	}
}

signed main(){
	int N, i;
	scanf("%lld", &N);
	int *h = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &h[i]);
	}
	int *a = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &a[i]);
	}
	seg_tree *t = make_seg_tree(N + 1, max, -inf);
	update(0, 0, t);
	for(i = 0; i < N; i++){
		update(h[i], query(0, h[i], t) + a[i], t);
	}
	printf("%lld\n", query(0, N + 1, t));
	return 0;
}

Measured memory_bytes: 7424
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

fn main() {
    use std::collections::HashMap;
    let div = 1000000007;

    input!{
        n: u64,
    }

    let mut counts = HashMap::new();

    for i in 1..(n+1) {
        let mut i = i;
        for pi in 2..(i + 1) {
            while i % pi == 0 {
                i = i / pi;
                *counts.entry(pi).or_insert(0u64) += 1;
            }
        }
    }

    let answer: u64 = counts.values().fold(1, |answer, x| {
        (answer % div) * ((x + 1) % div) % div
    });
    println!("{}", answer);
}


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

int main() {
	long long L, INF = 1000000000000000;
	vector<long long> A;
	cin >> L;
	A.resize(L);
	for (int i = 0; i < L; i++) cin >> A[i];
	vector<vector<long long> > DP(L + 1, vector<long long>(5, INF));
	DP[0][0] = 0;
	for (int i = 0; i < L; i++) {
		if (A[i] == 0) {
			DP[i + 1][0] = DP[i][0];
			DP[i + 1][1] = min(DP[i][0], DP[i][1]) + 2;
			DP[i + 1][2] = min({ DP[i][0], DP[i][1], DP[i][2] }) + 1;
			DP[i + 1][3] = min({ DP[i][0], DP[i][1], DP[i][2], DP[i][3] }) + 2;
			DP[i + 1][4] = min({ DP[i][0], DP[i][1], DP[i][2], DP[i][3], DP[i][4] });
		}
		else {
			DP[i + 1][0] = DP[i][0] + A[i];
			DP[i + 1][1] = min(DP[i][0], DP[i][1]) + A[i] % 2;
			DP[i + 1][2] = min({ DP[i][0], DP[i][1], DP[i][2] }) + (A[i] + 1) % 2;
			DP[i + 1][3] = min({ DP[i][0], DP[i][1], DP[i][2], DP[i][3] }) + A[i] % 2;
			DP[i + 1][4] = min({ DP[i][0], DP[i][1], DP[i][2], DP[i][3], DP[i][4] }) + A[i];
		}
	}
	cout << min({ DP[L][0], DP[L][1], DP[L][2], DP[L][3], DP[L][4] }) << endl;
}

Measured memory_bytes: 15872
// input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// body
fn main() {
    input! {
        n: usize,
        d: usize,
        points: [[f64; d]; n]
    };
    let mut ans = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            let mut sum = 0.0;
            for k in 0..d {
                sum += (points[i][k] - points[j][k]).powf(2.0);
            }
            if sum.sqrt() % 1.0 == 0.0 {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outv(v) rep(_, SZ(l)) cout << l[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    n = 10000;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> l;
    l.eb(a[0]);
    rep3(i, 1, n) {
        auto it = lower_bound(all(l), a[i]) - l.begin();
        //out("it " << it);
        if (it == 0) {
            l.insert(l.begin(), a[i]);
        } else {
            if (l[it - 1] != a[i]) l[it - 1] = a[i];
            else {
                l.insert(l.begin() + it, a[i]);
            }
        }
        //outv(l);
    }
    out(SZ(l));
}



Measured memory_bytes: 1276
import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		if(a < b){
			System.out.println("a < b");
		}

		if(a > b) System.out.println("a > b");

		if(a == b) System.out.println("a == b");

		scan.close();
	}
}



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

using namespace std;
int main() {
    int N;
    int A[100000];
    vector<int> negV, posV;
    cin >> N;
    for (int i=0; i < N; i++) {
        cin >> A[i];
        if (A[i] < 0) {
            negV.push_back(A[i]);
        } else {
            posV.push_back(A[i]);
        }
    }
    if (negV.size() > 0 && posV.size() > 0) {
        cerr << 1 << endl;
        long long su = 0;
        for (auto v : negV) su -= v;
        for (auto v : posV) su += v;
        cout << su << endl;

        long long x = posV[0];
        for (int i=1; i<negV.size(); i++) {
            cout << x << " " << negV[i] << endl;
            x -= negV[i];
        }
        long long y = negV[0];
        for (int i=1; i<posV.size(); i++) {
            cout << y << " " << posV[i] << endl;
            y -= posV[i];
        }
        cout << x << " " << y << endl;
    } else if (negV.size() == 0) {
        cerr << 2 << endl;
        // pos only
        sort(posV.begin(), posV.end());
        long long su = -posV[0];
        for (int i=1; i<N; i++) su += posV[i];
        cout << su << endl;
        long long x = posV[0];
        for (int i=0; i<N-2; i++) {
            cout << x << " " << posV[i+1] << endl;
            x -= posV[i+1];
        }
        cout << posV[N-1] << " " << x << endl;
    } else {
        cerr << 3 << endl;
        // neg only
        sort(negV.begin(), negV.end());
        long long su = negV[N-1];
        for (int i=0; i<N-1; i++) su -= negV[i];
        cout << su << endl;
        long long x = negV[N-1];
        for (int i=0; i<N-1; i++) {
            cout << x << " " << negV[i] << endl;
            x -= negV[i];
        }
    }

    return 0;
}



Measured memory_bytes: 2812