akhauriyash/Code-Regression huggingface dataset:
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    
    S.splice(S.length - 8, 8, "");
    
    console.log(S.join(""));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7496
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        int cnt=0;

        for(int i = 0;i<n;i++){
            h[i] = sc.nextInt();
            if(h[i]>=k){
                cnt++;
            }
        }

        System.out.println(cnt);

        
    }
}


Measured memory_bytes: 48060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <utility>
#include <climits>
#include <string>

typedef long long ll;

using namespace std;

char ConvertCharacter(char c){
    if(c >= 'a' && c <= 'z'){
        return (char)toupper(c);
    }else if(c >= 'A' && c <= 'Z'){
        return (char)tolower(c);
    }else{
        return c;
    }
}

void solve(){
    string s;
    getline(cin, s);
    for(auto itr = s.begin(); itr < s.end(); itr++){
        cout << ConvertCharacter(*itr);
    }
    cout << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3160
#include <stdio.h>
 
int main(void) {
    int h,w;
    while(scanf("%d%d", &h,&w)){
        if(h == 0 && w == 0)
            break;
        int i,c;
        for(i =0; h > i; i++){
            for(c = 0; w > c; c++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2100
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;
int x[10], y[10];
int p[10];

double d(int i, int j){
    return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
}

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >>x[i] >> y[i];
        p[i] = i;
    }

    double sum = 0;
    int cnt = 0;
    do{
        for(int i=0;i<n-1;i++){
            sum += d(p[i], p[i+1]);
        }
        cnt++;
    }while(next_permutation(p, p+n));

    printf("%.8f\n", sum / cnt);


}




Measured memory_bytes: 256
N, L = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
l, i = max((A[i] + A[i - 1], i) for i in range(1, N))
ans = []
if l >= L:
    print('Possible')
    if i < N - 1:
        ans += list(range(N - 1, i, -1))
        ans += list(range(1, i + 1))
    else:
        ans += list(range(1, i + 1))
    print(*ans, sep='\n')
else:
    print('Impossible')


Measured memory_bytes: 14600
#include<bits/stdc++.h>
using namespace std;
const int N=200010;
pair<int,int> a[N],b[N];
int n,i,f[N],u[N],v[N],w[N],x,y,z,j;
long long ans;
struct edge{
	int u,v,w;
	bool operator<(const edge&x)const{
		return w<x.w;
	}
}e[N*4];
int gfa(int x){
	return f[x]==x?x:f[x]=gfa(f[x]);
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%d%d",&x,&y);
		a[i]=make_pair(x,i);
		b[i]=make_pair(y,i);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	f[1]=1;
	for(i=2;i<=n;++i){
		f[i]=i;
		e[++j]=(edge){a[i-1].second,a[i].second,a[i].first-a[i-1].first};
		e[++j]=(edge){b[i-1].second,b[i].second,b[i].first-b[i-1].first};
	}
	sort(e+1,e+j+1);
	for(i=1;i<=j && n>1;++i){
		x=gfa(e[i].u);
		y=gfa(e[i].v);
		if(x!=y){
			ans+=e[i].w;
			--n;
			f[x]=y;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11008
n = int(input())
for i in range(3,n+1):
  x = i
  if x % 3 == 0:
    print(' {0}'.format(i), end='')
    continue

  while x != 0:
    if x % 10 == 3:
      print(' {0}'.format(i), end='')
      break
    x //= 10

print()

Measured memory_bytes: 6732
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N;
    cin >> N;

    vector<int> A(N);
    for (int i = 0; i < N; i++)cin >> A[i];

    int sum = 0;
    vector<int> odd;
    for (int i = 0; i < N; i++) {
        if (A[i] & 1) odd.push_back(A[i]);
        if (!(A[i] & 1)) sum += A[i];
    }

    sort(odd.begin(), odd.end());
    sum += accumulate(odd.begin(), odd.end(), 0);
    if (odd.size() & 1) sum -= odd.front();

    cout << sum / 2 << endl;

}












Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    
  int main(){
      lint N;
      cin >>N; lint A[N];
      lint count=0;
      rep(i,N){cin >> A[i];
    if(A[i]%2==0)count++;
      }
      if(N!=count)cout<<"first";
      else cout<<"second";
  }
  
  
     
  

Measured memory_bytes: 1024
import math

def main():
	N, M = [int(a) for a in input().split(" ")]
	divM = []
	for i in range(1, int(math.sqrt(M)) + 1):
		if M % i == 0:
			divM += [i, M // i]
	divM.sort()
	divM = list(filter(lambda m: m >= N, divM))
	print(M // divM[0])

main()

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

int main() {
    int n;
    string s;
    cin>>n>>s;
    ll ans=0,all,r=0,g=0,b=0;
    rep(i,n) {
        if (s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else b++;
    }
    all=r*g*b;
    rep(i,n) {
        for (int j=i+1; j<n; j++) {
            if (s[i]==s[j]) continue;
            int k=2*j-i;
            if (s[k]==s[i]||s[k]==s[j]||k>=n) continue;
            ans++;
        }
    }
    cout<<all-ans<<endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

int	main()
{
	int	N, K;
	int	location, i, sum;

	i = 0;
	sum = 0;
	scanf("%d\n%d\n", &N, &K);
	while (i < N)
	{
		scanf("%d ", &location);
		if (location <= (K - location))
			sum += location * 2;
		else
			sum += (K - location) * 2;
		i++;
	}
	printf("%d\n", sum);
	return (0);
}

Measured memory_bytes: 128
k=int(input())
# 最大のk=100000
# ->3234566667
import sys
sys.setrecursionlimit(10**7)
def dfs(s):# 先頭がsのルンルンナンバーを返す。s自体もルンルンナンバー
    if len(str(s))==10:
        return[s]
    ret=[s]
    si=str(s)[-1]
    if si=='9':
        ret+=dfs(10*s+8)
        ret+=dfs(10*s+9)
        return ret
    elif si=='0':
        ret+=dfs(10*s)
        ret+=dfs(10*s+1)
        return ret
    else:
        ret+=dfs(10*s+s%10-1)
        ret+=dfs(10*s+s%10)
        ret+=dfs(10*s+s%10+1)
        return ret
lunlun=dfs(1)+dfs(2)+dfs(3)+dfs(4)+dfs(5)+dfs(6)+dfs(7)+dfs(8)+dfs(9)
lunlun.sort()
print(lunlun[k-1])


Measured memory_bytes: 13628
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<assert.h>
#include<stack>
ll z = 1000000007 ;
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b){if(b <= 0) return 1 ; ll c = power(a , b/2) ; if(b%2 == 0) return ((c*c)%z) ; else return ((((c*c)%z)*a)%z) ;}
ll inverse(ll a ,ll n){return power(a , n-2) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
using namespace std ;


//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);

 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	ll h , n ;
	cin >> h >> n ;
	ll sum = 0 ;
	fo(i , n)
	{
		ll u ;
		cin >> u ;
		sum += u ;
	}
	if(sum >= h)
	{
		cout << "Yes" << endl ;
	}
	else
	{
		cout << "No" << endl ;
	}
	return 0;
}

Measured memory_bytes: 256
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	long long int n, k;
	cin >> n >> k;
	cout << min(n % k, k - (n % k)) << endl;
}

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

using namespace std;

int a[5], ans = 0x3f3f3f3f;

int main() {
	cin >> a[1] >> a[2] >> a[3];
	sort(a+1, a+4);
	cout << a[2]-a[1]+a[3]-a[2];
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<58;
 
int main(){
    ll N;
  	cin >> N;
  	ll temp = N;
  	ll num;
  	ll sum = 0;
  	ll count = 0;
  	ll nine;
  	bool nflag = true;
  	while(temp > 0){
      num = temp % 10;
      temp /= 10;
      ++count;
    }
  	temp = N;
  	if(N >= 10){
      while(temp > 0){
        nine = temp % 10;
        sum += nine;
        if(nine != 9 && temp >= 10) {
          nflag = false;
          break;
        }
              	temp /= 10;
      }
      if(nflag){
        cout << sum << endl;
        return 0;
      }
      else{
        sum = 0;
  		if(num == 1) {
      		for(int i = 0; i < count - 1; ++i) sum += 9;
    	}
  		else{
      	sum = num - 1;
      		for(int i = 0; i < count - 1; ++i) sum += 9;
    	}
    }
    }
  	else{
      sum = N;
    }
  	
  	cout << sum << endl;
}

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

int main() {
    int n;
    int h[100];
    int count = 0;
    int maxh = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for(int i = 0; i < n; i++) {
        if (maxh <= h[i]) {
            count++;
            maxh = h[i];
        }
    }
    cout << count << endl;
}

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

int main() {
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N), y(M);
    for(int i=0; i<N; ++i) cin >> x[i];
    for(int i=0; i<M; ++i) cin >> y[i];
    sort(begin(x), end(x));
    sort(begin(y), end(y));

    if(x[N - 1] < Y && X < y[0] && x[N - 1] < y[0]) cout << "No War" << endl;
    else cout << "War" << endl;
}

Measured memory_bytes: 256
n, l = gets.split.map(&:to_i)

apples = []
(0..n-1).each do |nn|
  apples << l + nn
end

eat = 10 ** 20
a = 1000
apples.each_with_index do |ap, i|
  if ap.abs < eat.abs
    eat = ap
    a = i
  end
end
puts apples.inject(:+) - apples[a]

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
const int INF = 1<<20;

int main() {
	int n;
	while(cin >> n, n) {
		int dp[10][10];
		bool exist[10] = {};
		rep(i, 10) rep(j, 10) dp[i][j] = INF;
		rep(i, 10) dp[i][i] = 0;
		rep(i, n) {
			int a, b, c;
			cin >> a >> b >> c;
			dp[a][b] = dp[b][a] = c;
			exist[a] = exist[b] = true;
		}
		rep(k, 10) {
			rep(i, 10) {
				rep(j, 10) {
					dp[i][j] = min( dp[i][j], dp[i][k]+dp[k][j] );
				}
			}
		}
		int mini = INF, res = INF;
		rep(i, 10) {
			if(!exist[i]) continue;
			int sum = 0;
			rep(j, 10) {
				if(!exist[j]) continue;
				sum += dp[i][j];
			}
			if( sum < mini ) {
				mini = sum;
				res = i;
			}
		}
		cout << res << ' ' << mini << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];

    vec l(n), r(n);
    rep(i, n) l[i] = i - a[i];
    rep(i, n) r[i] = i + a[i];

    map<lint, int> ml;

    lint res = 0;

    for (int i = n-1; i >= 0; --i) {
        res += ml[r[i]];
        ml[l[i]]++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 30716
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
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; }
const long long MOD = 1000000007;
const long long INF = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))
int f(int x, int c, int d) {
	int res = x;
	res -= x / c;
	res -= x / d;
	res += x / lcm(c, d);
	return res;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b;
	int c, d;
	cin >> a >> b >> c >> d;
	int ans = f(b, c, d) - f(a - 1, c, d);
	cout << ans << endl;
	return 0;
}

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

int main()
{
  // ここにプログラムを追記
  int s, a, b, c;
  cin >> s;

  a = s / 100;
  b = s % 100 / 10;
  c = s % 10;
  cout << a + b + c << 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;

int main() {
  int n;
  cin >> n;

  vector<vector<pair<int, int>>> edges(n);
  rep(i, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    edges[u].push_back(make_pair(v, w));
    edges[v].push_back(make_pair(u, w));
  }

  vector<int> ans(n, -1);
  ans[0] = 0;
  queue<int> q;
  q.push(0);

  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (pair<int, int> p : edges[node]) {
      if (ans[p.first] != -1) continue;
      if (p.second % 2 == 0) {
        ans[p.first] = ans[node];
      } else {
        ans[p.first] = ans[node] ? 0 : 1;
      }
      q.push(p.first);
    }
  }

  rep(i, n) { printf("%d\n", ans[i]); }

  return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int a,b;
    cin>>a>>b;
    if(a>=13){cout<<b<<endl;return 0;}
    else if(a<=5){
        cout<<0<<endl;
    }
    else{
        cout<<b/2<<endl;
    }


    return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll N;
  scanf("%lld",&N);
  string S;
  cin >> S;
  ll ans=0;
  for (int i=1; i<N-1; i++) {
    ll tmp=0;
    string sl = S.substr(0,i);
    string sr = S.substr(i,N-i);
    sort(sl.begin(),sl.end());
    sl.erase(unique(sl.begin(), sl.end()), sl.end());
    for (auto cl:sl) {
      for (auto cr:sr) {
        if (cl==cr) {
          tmp++;
          break;
        }
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext())
		{
			double m = sc.nextDouble();
			double km = sc.nextDouble();
			if(m<35.50 && km<71.00)
				System.out.println("AAA");
			else if(m<37.50 &&km<77.00)
				System.out.println("AA");
			else if(m<40.00 &&km<83.00)
				System.out.println("A");
			else if(m<43.00 &&km<89.00)
				System.out.println("B");
			else if(m<50.00 &&km<105.00)
				System.out.println("C");
			else if(m<55.00 &&km<116.00)
				System.out.println("D");
			else if(m<70.00 &&km<148.00)
				System.out.println("E");
			else
				System.out.println("NA");
		}
	}
}

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

int gcd(int,int);
int L(int,int*,int*);
int R(int,int*,int*);

int N;

int main(){
	int ans=0;
	cin >> N;
	int A[N],M,memoL[N],memoR[N];
	for(int i=0;i<N;i++){
		cin >> A[i];
		memoL[i]=0;
		memoR[i]=0;
	}
	for(int i=0;i<N;i++){
		M=gcd(L(i,A,memoL),R(i+1,A,memoR));
		ans=max(ans,M);
	}
	cout << ans << endl;
	return 0;
}
int gcd(int a,int b){
	if(a==0){
		return b;
	}
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}
int L(int a,int* A,int* memoL){
	if(a==0){return 0;}
	if(memoL[a]!=0){return memoL[a];}
	return memoL[a] = gcd(L(a-1,A,memoL),A[a-1]);
}
int R(int a,int* A,int* memoR){
	if(a==N){return 0;}
	if(memoR[a]!=0){return memoR[a];}
	return memoR[a] = gcd(R(a+1,A,memoR),A[a]);
}

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

int main(){
    int N,M;
    cin >> N >> M;
    priority_queue<int> A;
    vector<int> B(M),C(M);
    vector<pair<int,int>> CB(M);
    int tmp=0;
    rep(i,N){
        cin >> tmp;
        A.push(tmp);
    }
    rep(i,M){
        cin >> CB[i].second >> CB[i].first;
    }
    
    sort(CB.begin(),CB.end(),greater<pair<int,int>>());

    int cnt=0;
    bool flag=true;
    rep(i,M){
        rep(j,CB[i].second){
            if(cnt<N){
                A.push(CB[i].first);
                cnt++;
            }else{
                flag=false;
                break;
            }
        }
        if(!flag) break;
    }

    ll ans=0;
    rep(i,N){
        ans+=A.top();
        A.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 2936
# 初期値
INF = 10**18

# ナップサック問題
N,W = map(int,input().split())

dp = [[0 for j in range(W+1)] for i in range(N+1)]

for i in range(N):
    v,w = map(int,input().split())
    # dp[i][j] = i番目までの品物から重さj以下でつくれる最大の価値
    for j in range(W+1):
        # jがwより小さいとき、wは選べない
        if j < w:
            dp[i+1][j] = dp[i][j]
        # jがw以上のときは、入れる->dp[i][j-w]+v、入れない->dp[i][j]が価値
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w] + v)

print(dp[N][W])





Measured memory_bytes: 25932
#include <iostream>
using namespace std;
#define ll long long
ll abc (ll sum, ll x, ll min) {
  if (sum <= x) {
    return 0;  
  }  
  ll difference = sum - x;
  
  // difference分減少させる必要がある.
  if (difference <= min) {
    return difference;  
  }
  return min;
}


int main () {
  ll n, x;
  cin >> n >> x;
  ll a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];  
  } 
  ll ans = 0;
  for (ll i = 0; i < (n - 1); i++) {
    ll sum = a[i] + a[i + 1];
    ll difference = abc(sum, x, a[i + 1]); 
    a[i + 1] = a[i + 1] - difference;
    ans = ans + difference;   
  } 
  ans = ans + abc(a[0] + a[1], x, a[0]);
  cout << ans << endl;
}

Measured memory_bytes: 1152
#include<iostream>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

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

	int sum = 0;
	for(int i = 1; i <= n; ++i){
		int tmp = i;
		int c = 0;
		REP(j, 5){
			c += tmp % 10;
			tmp /= 10;
		}
		if(a <= c && c <= b) sum += i;
	}

	cout << sum << endl;
	return 0;
}//解説参考.


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
	vector<bool> memo(10000001, false);
	int s;
	cin >> s;
	memo[s] = true;
	for (int i = 1; i <= 10000001; i++) {
		s = (s % 2 == 0) ? s / 2 : 3 * s + 1;
		if (memo[s]) {
			cout << i+1 << endl;
			return 0;
		}
		memo[s] = true;
	}
	return 0;

}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
ll n, a[N], b[N], c[N], biggerThanB[N];
ll finall = 0;
int main()
{
    Hello
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
        cin >> b[i];
    for(int i = 1; i <= n; i++)
        cin >> c[i];
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    sort(c + 1, c + n + 1);
    for(int i = 1; i <= n; i++)
    {
        int low = 1, high = n, mid, ans = n + 1;
        ///first idx > b[i]
        while(low <= high)
        {
            mid = (low + high)/2;
            if(c[mid] <= b[i])
                low = mid + 1;
            else if(c[mid] > b[i])
            {
                high = mid - 1;
                ans = mid;
            }
        }
        biggerThanB[i] += biggerThanB[i - 1] + (n - ans + 1);
    }
    for(int i = 1; i <= n; i++)
    {
        int low = 1, high = n, mid, ans = n + 1;
        while(low <= high)
        {
            mid = (low + high)/2;
            if(b[mid] <= a[i])
                low = mid + 1;
            else if(b[mid] > a[i])
            {
                high = mid - 1;
                ans = mid;
            }
        }
        finall += (biggerThanB[n] - biggerThanB[ans - 1]);
    }
    cout << finall;
    return 0;
}


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

int top = 0, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop(void) {
  top--;
  return S[top+1];
}

int main(void) {
  int a, b;
  top = 0;
  char s[100];
  while(scanf("%s",s) != EOF) {
    if(s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if(s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if(s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());

  return 0;
}



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

int main()
{
    int n;  cin >> n;
    int a[n+1], b[n];
    rep(i,n+1)  cin >> a[i];
    rep(i,n)  cin >> b[i];

    long long ans = 0;

    rep(i,n) {
        ans += min(a[i], b[i]);
        b[i] -= min(a[i], b[i]);
        ans += min(a[i+1], b[i]);
        a[i+1] -= min(a[i+1], b[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
Boolean isNull = str.equals("");
while(!isNull){
String[] datas = new String[8];
datas = str.split(" ",8);
double x1 = Double.parseDouble(datas[0]);
double y1 = Double.parseDouble(datas[1]);
double x2 = Double.parseDouble(datas[2]);
double y2 = Double.parseDouble(datas[3]);
double x3 = Double.parseDouble(datas[4]);
double y3 = Double.parseDouble(datas[5]);
double xp = Double.parseDouble(datas[6]);
double yp = Double.parseDouble(datas[7]);
double x = xp-x1;
double y = yp-y1;
double p = x2-x1;
double q = y2-y1;
double r = x3-x1;
double u = y3-y1;
double[] coefficient = new double[2];
coefficient = Simultaneous(p,r,x,q,u,y);
double s = coefficient[0];
double t = coefficient[1];
if(s<0||t<0){
System.out.println("NO");
}else if(s+t>0 && s+t<1){
System.out.println("YES");
}else{
System.out.println("NO");
}
str = br.readLine();
isNull=str==null;
//str = str == null?"":str;
//isNull = str.equals("");
 
}
}
public static double[] Simultaneous(double a,double b,double c,double d,double e,double f){
double x = (double) (e*c-b*f)/(a*e-b*d);
double y = (double) (a*f-c*d)/(a*e-b*d);
double[] answer = new double[2];
answer[0]=x;
answer[1]=y;
return answer;
}
}

Measured memory_bytes: 24552
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int q; cin>>q;
  vector<long long> a(q),b(q);
  for(int i=0; i<q; ++i) cin>>a[i]>>b[i];
  for(int i=0; i<q; ++i){
    long long ab=a[i]*b[i]-1,sqr=sqrtl(ab),sq=sqr*2;
    if(a[i]==1&&b[i]==1) cout<<0<<endl;
    else if(a[i]==b[i]) cout<<sq<<endl;
    else if(sqr*sqr!=ab&&sqr*(sqr+1)<=ab) cout<<sq-1<<endl;
    else cout<<sq-2<<endl;
  }
  return 0;
}


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

int with_0head=0,with_1head=0;

int main()
{
	string s;
	cin>>s;
	for (int i=0;i<=s.size()-1;i++)
	{
		if (s[i]-'0'!=i%2)  with_0head++;
		else with_1head++;
	}
	cout<<min(with_0head,with_1head)<<endl;
	return 0;
}

Measured memory_bytes: 512
def myAnswer(N:int,P:list) -> str:
   flag = False
   for i in range(N):
      if(i+1 != P[i]):
         if(flag):
            return "NO"
         flag = True
         P[P.index(i + 1)] = P[i]
         P[i] = i + 1
   return "YES"

def modelAnswer():
   return
def main():
   N = int(input())
   P = list(map(int,input().split()))
   print(myAnswer(N,P))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int s=abs(a-b),t=abs(b-c),u=abs(c-a);
  int k=s;
  if(k<t)k=t;
  if(k<u)k=u;  
  if(k==s)cout<<t+u;
  else if (k==t) cout<<s+u;
  else cout<<s+t;
}

Measured memory_bytes: 256
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).trim().split('\n');
main();

function main(){
  for(var i = 0, len = input.length; i < len; i++){
    var target = input[i];
    var decrypted = "";
    for(var j = 0; j < 27; j++){
      decrypted = decrypt(target, j);
      if(decrypted.indexOf("this") != -1 || decrypted.indexOf("the") != -1 || decrypted.indexOf("that") != -1 ){
        break;
      }
    }
    console.log(decrypted);
  }
}

function decrypt(a, i){
  var result = "";
  for(var j = 0, len = a.length; j < len; j++){
    var t = a.charCodeAt(j);
    if(t + i >= 123){
      result += String.fromCharCode(t + i - 26);
    }else if(t >= 61){
      result += String.fromCharCode(t + i);
    }else{
      result += a[j];
    }
    
  }
  return result;
}

Measured memory_bytes: 8700
#include <stdio.h>

main(){
  int n, m, tl[10001], tr[10001], i, j, k, max, data[20005] ;

  while(1){
    scanf("%d %d", &n, &m);
    if(n==0 && m==0) break;

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

    for(i=0;i<m;i++){
      scanf("%d", &tr[i]);
    }
    tr[i]=1000001;

    j=0;
    k=0;
    data[0]=0;
    for(i=1;i<m+n+1;i++){
      if(tl[j]<=tr[k]){
	data[i]=tl[j];
	j++;
      }
      else if(tl[j]>tr[k]){
	data[i]=tr[k];
	k++;
      }
    }

    max=-1;
    for(i=0;i<m+n;i++){
      //printf("%d ", data[i]);
      if(max<data[i+1]-data[i]) max=data[i+1]-data[i];
    }
    printf("%d\n", max);
    //printf("\n");
  }
  return 0;
}

Measured memory_bytes: 0
import collections

count = input()

l = []
ans = []
for i in range(int(count)):
    l.append(input())
c = collections.Counter(l)
#print(l)
#print(c)
#print(c.most_common()[0][1])
max_count = c.most_common()[0][1]
for i in c.most_common():
    if i[1] != max_count:
        break
    #print(i[0])
    ans.append(i[0])
ans.sort()
for i in ans:
    print(i)



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

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

int main()
{
    cin.tie(0); ios::sync_with_stdio(false); 
    
    int i,j;
    int h,w,m;
    cin >> h >> w >> m;
    map<pair<int,int>,int> mp;
    vector<int> hh(h,0);
    vector<int> ww(w,0);
    rep(i,m){
        int th, tw;
        cin >> th >> tw;
        --th, --tw;
        ++hh.at(th);
        ++ ww.at(tw);
        mp[make_pair(th, tw)]++;
    }

    int maxh = -1;
    rep(i,h){
        maxh = max(maxh, hh.at(i));
    }
    vector<int> listh;
    rep(i,h){
        if(hh.at(i) == maxh) listh.push_back(i);
    }

    int maxw = -1;
    rep(i,w){
        maxw = max(maxw, ww.at(i));
    }
    vector<int> listw;
    rep(i,w){
        if(ww.at(i) == maxw) listw.push_back(i);
    }
    
    for(i = 0;i < listh.size();++i){
        for(j = 0;j < listw.size();++j){
            if(mp.count(make_pair(listh.at(i), listw.at(j)))) continue;
            else{
                cout << hh.at(listh.at(i)) + ww.at(listw.at(j)) << endl;
                return 0;
            }
        }
    }
    cout << hh.at(listh.front()) + ww.at(listw.front()) - 1 << endl;

    return 0;
}

Measured memory_bytes: 28488
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
struct point{
    int x;
    int y;
    int flag=0;
};
map<int,point> op;
bool panduan(int a[][3]){
    for(int i=0;i<3;i++){
        if(a[i][0]==1&&a[i][1]==1&&a[i][2]==1)
            return true;
    }
    for(int i=0;i<3;i++){
        if(a[0][i]==1&&a[1][i]==1&&a[2][i]==1)
            return true;
    }
    if(a[0][0]==1&&a[1][1]==1&&a[2][2]==1)
        return true;
    if(a[0][2]==1&&a[1][1]==1&&a[2][0]==1)
        return true;
    return false;
}
int main(){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            int a;
            cin>>a;
            op[a].x=i,op[a].y=j,op[a].flag=1;
        }
    }
    int n;
    cin>>n;
    int b[3][3];
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(op[a].flag==1){
            b[op[a].x][op[a].y]=1;
        }
    }
    if(panduan(b)==1){
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
}



Measured memory_bytes: 256
package main

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

type currency int
type profit int

// assume that the size of currencies > 2
func calcMaxProfit(currencies []currency) profit {
	x, y := currencies[0], currencies[1]
	var initialBottom currency
	if x > y {
		initialBottom = y
	} else {
		initialBottom = x
	}
	return doCalcMaxProfit(initialBottom, profit(y - x), currencies[2:])
}

func doCalcMaxProfit(initialBottom currency, initialProfit profit, currencies []currency) profit {
	bottom := initialBottom
	maxProfit := initialProfit
	for _, currency := range currencies {
		if bottom <= currency {
			profit := profit(currency - bottom)
			if profit > maxProfit {
				maxProfit = profit
			}
		} else if currency < bottom {
			bottom = currency
		}
	}
	return maxProfit
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	currencies := make([]currency, n)
	for i := 0; i < n; i++ {
		c, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		currencies[i] = currency(c)
	}

	fmt.Println(calcMaxProfit(currencies))
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}


Measured memory_bytes: 5384
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

signed main() {
    vi a(3);
    cin>>a;
    sort(ALL(a));
    cout<<(a[0]+a[1]!=a[2]?"No":"Yes")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int money(int ranking)
{
    if (ranking == 1)
        return 300000;
    else if (ranking == 2)
        return 200000;
    else if (ranking == 3)
        return 100000;
    else
        return 0;
}
int main(void)
{
    int X, Y;

    cin >> X >> Y;

    if (X == 1 && Y == 1)
    {
        cout << "1000000" << endl;
    }
    else
    {
        cout << money(X) + money(Y) << endl;
    }
    return 0;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

void rerio(int hp, string s){
    if(hp == 0) print(s);
    else{
        for(char c = 'a'; c <= 'c'; c++) rerio(hp -1, s + c);
    }
}

int main(){
    ll N;
    cin >> N;
    if(N == 1 || N == 2) {
        print(0);
        return 0;
    }
    ll sum = 0;
    for(ll i = 1; N >= i * i; i++){
        ll x = (N / i) - 1;
      	// print(x);
        if(N / x == N % x ) sum += x;
        if(N / i == N % i ) sum += i;
    }
    print(sum);

}


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/
struct position{
  int x;
  int y;
};

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << min(a,b)+min(c,d) << endl;

          
             
          
        
        
        
          
}

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

using namespace std;


#define PI 3.14159265
#define int long long

const int mod = 1e9 + 7;


main(){


	int n, m;

	cin >> n >> m;

	int l, r, left = 1, right = n;

	for(int i = 0; i < m; i++){
		cin >> l >> r;

		left = max(left, l);
		right = min(right, r);
	}


	cout << max(0LL, right - left + 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node {
    int key;
    Node *r,*l,*p;
};

Node *rootw, *NIL;

Node * find(Node *u, int k){
    while (u != NIL && k != u->key ){
        if(k < u->key)u = u->l;
        else u = u->r;
    }
    return u;
}

void insert(int k){
    Node *y = NIL;
    Node *x = rootw;
    Node *z;

    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->l = NIL;
    z->r = NIL;

    while(x != NIL){
        y=x;
        if(z->key < x->key){
            x=x->l;
        }
        else{
            x = x->r;
        }
    }
    z->p = y;
    if (y==NIL){
    rootw = z;
    }
    else{
        if(z->key < y->key){
            y->l = z;
        }
        else{
            y->r = z;
        }
    }
}

void inorder(Node *u){
    if(u == NIL)return;
    inorder(u->l);
    printf(" %d",u->key);
    inorder(u->r);
}
void preorder(Node *u){
    if(u == NIL)return;
    printf(" %d", u->key);
    preorder(u->l);
    preorder(u->r);
}

int main(){
    int n,i,x;
    string com;

    scanf("%d", &n);

    for(i = 0; i<n ; i++){
        cin >> com;
        if(com[0]=='f'){
            scanf("%d", &x);
            Node *t = find(rootw,x);
            if(t != NIL)printf("yes\n");
            else printf("no\n");
        }
        else if(com == "insert"){
            scanf("%d", &x);
            insert(x);
        }
        else if (com == "print"){
            inorder(rootw);
            printf("\n");
            preorder(rootw);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 22028
#include <functional>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct Query {
  Query(int _t = 0, int _c = ' ') : type(_t), ch(_c) {}
  int type;
  char ch;
};

int main() {
  string s;
  cin >> s;

  int q;
  cin >> q;

  int len = s.size();
  vector<Query> qs;
  for (int i = 0; i < q; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      qs.push_back(Query(1));
    } else {
      int pos;
      char ch;
      cin >> pos >> ch;
      len++;
      if (pos == 1) {
        qs.push_back(Query(2, ch));
      } else {
        qs.push_back(Query(3, ch));
      }
    }
  }

  function<void(bool, int)> f = [&](bool rev, int qid) {
    if (qid == -1) {
      if (!rev)
        cout << s;
      else {
        for (int i = s.size() - 1; i >= 0; i--) cout << s[i];
      }
      return;
    }
    int type = qs[qid].type;
    char ch = qs[qid].ch;
    if (type == 1)
      f(!rev, qid - 1);
    else if (type == 2) {
      if (!rev) {
        cout << ch;
        f(rev, qid - 1);
      } else {
        f(rev, qid - 1);
        cout << ch;
      }
    } else {
      if (!rev) {
        f(rev, qid - 1);
        cout << ch;
      } else {
        cout << ch;
        f(rev, qid - 1);
      }
    }
  };

  f(false, qs.size() - 1);
  cout << endl;
}



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

int main(){
    string s,ans ="";
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='0') ans+="0";
        else if(s.at(i)=='1') ans+="1";
        else if(s.at(i)=='B'&&ans!="") ans.pop_back();
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import numpy as np
import math

N = int(input())

c = np.zeros((10, 10), dtype=int)
d = np.zeros((10, 10), dtype=int)

for n in range(1, N+1):
    k = math.floor(math.log10(n)) + 1
    #print('桁数: ', k)
    i = n// (10 ** (k-1))
    #print('1番大きな桁の数: ', i)
    j = n%10
    #print('1の位の数: ', j)
    c[i][j] += 1
    d[j][i] += 1

ans = np.sum(c*d)
print(ans)

Measured memory_bytes: 12636
// AOJ ALDS1_1_A Insertion Sort
// 2018.4.26 bal4u
 
#include <stdio.h>
 
//#define getchar_unlocked()  getchar()
int in()
{
    int n = 0, c = getchar_unlocked();
    do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
    return n;
}
 
#define MAX_N 102
 
int a[MAX_N];
 
void dump(int n)
{
    int i;
 
    printf("%d", a[0]);
    for (i = 1; i < n; i++) printf(" %d", a[i]);
    putchar('\n');
}
 
void insertion_sort(int n)
{
    int i, j, key;
 
    dump(n);
    for (i = 1; i < n; i++) {
        key = a[i];
        j = i-1;
        while (j >= 0 && a[j] > key) a[j+1] = a[j], j--;
        a[j+1] = key;
        dump(n);
    }
}
 
int main()
{
    int N, i;
 
    N = in();
    for (i = 0; i < N; i++) a[i] = in();
    insertion_sort(N);
    return 0;
}


Measured memory_bytes: 2044
S = input()
K = int(input())
n = len(S)

if len(set(S)) == 1:
    print(n * K // 2)
    exit()

SS = S[:] + S[:]
S = list(S)
SS = list(SS)
ans0 = 0
ans1 = 0

c = 0
cnt = 1
for i in range(1, n):
    if S[i - 1] == S[i]:
        cnt += 1
        if i == n-1:
            c += cnt // 2
    else:
        if cnt >= 2:
            c += cnt // 2
        cnt = 1
ans0 = c
c = 0
cnt = 1
m = len(SS)
for i in range(1, m):
    if SS[i - 1] == SS[i]:
        cnt += 1
        if i == m - 1:
            c += cnt // 2
    else:
        if cnt >= 2:
            c += cnt // 2
        cnt = 1

ans1 = c


num = ans1 - ans0
print(ans0 + (K-1) * num)


Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct dice{
    int f,b,u,d,l,r;
    dice(vector<int>& v){
        f = v[0];
        b = v[1];
        u = v[2];
        d = v[3];
        l = v[4];
        r = v[5];
    }
    void turn_east(){
        int tmp = f ; 
        f = l;
        l = b;
        b = r;
        r = tmp;
    }
    void turn_west(){
        int tmp = f ; 
        f = r;
        r = b;
        b = l;
        l = tmp;
    }
    void turn_north(){
        int tmp = f ; 
        f = d;
        d = b;
        b = u;
        u = tmp;
    }
    void turn_south(){
        int tmp = f ; 
        f = u;
        u = b;
        b = d;
        d = tmp;
    }
    
};
bool check(dice di){
    if(di.b+di.f>di.r+di.l+di.u+di.d)return false;
    if(di.l+di.r>di.b+di.f+di.u+di.d+1)return false;
    if(di.u+di.d>di.r+di.l+di.b+di.f+1)return false;
    int nxt=0;
    if(di.l+di.r==di.b+di.f+di.u+di.d+1)nxt|=1;
    if(di.u+di.d==di.r+di.l+di.b+di.f+1)nxt|=2;
    if(nxt==3)return false;
    return true;
}
void calc(dice& di,string& ans){
    di.b -= 1;
    if(di.l+di.r+di.f+di.b+di.u+di.d==0)return;
    int nxt=0;
    if(di.l+di.r==di.b+di.f+di.u+di.d+1)nxt|=1;
    if(di.u+di.d==di.r+di.l+di.b+di.f+1)nxt|=2;
    assert(nxt!=3);
    if(nxt==2){
        if(di.u>0){
            di.turn_north();
            ans+='N';calc(di,ans);
        }
        else {
            di.turn_south();
            ans += 'S';calc(di,ans);
        }
    }
    else if(nxt==1){
        if(di.r>0){
            di.turn_east();
            ans+='E';calc(di,ans);
        }
        else {
            di.turn_west();
            ans+='W';calc(di,ans);
        }
    }
    else {
        if(di.r>0){
            di.turn_east();
            ans+='E';calc(di,ans);
        }
        else if(di.u>0){
            di.turn_north();
            ans+='N';calc(di,ans);
        }
        else if(di.d>0){
            di.turn_south();
            ans += 'S';calc(di,ans);
        }
        else {
            di.turn_west();
            ans+='W';calc(di,ans);
        }
    }
}
void solve(vector<int>& v){
    int p, q;
    cin>>p>>q;
    --p;
    
    string ans="Z";
    do{
        dice di(v);
        if(!check(di))continue;
        string ret="";
        di.b+=1;
        calc(di,ret);
        ans = min(ans,ret);
    }while(next_permutation(v.begin(), v.end()));
    if(ans=="Z")cout<<"impossible"<<endl;
    else cout<<ans.substr(p,q-p)<<endl;
}



int main(){
    vector<int> v(6);
    while(1){
        rep(i,6)cin>>v[i];
        sort(v.begin(),v.end());
        if(v[5]==0)break;
        solve(v);
    }
    return 0;
}


Measured memory_bytes: 3264
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M, L, R;
int cnt[int(1e5 + 5)];

int main(){
  scanf("%d%d", &N, &M);
  L = 1; R = N;
  for (int i = 0; i < M; i++){
    int A, B; scanf("%d%d", &A, &B);
    L = max(L, A); R = min(R, B);
  }
  printf("%d\n", max(R - L + 1, 0));

  return 0;
}


Measured memory_bytes: 3772