akhauriyash/Code-Regression huggingface dataset:
// Gaurav Aggarwal
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
 
ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif  

    int n;
    cin>>n;

    for(int i=1;i<10;++i) {
        for(int j=1;j<10;++j) {
            if(i*j == n) {
                cout<<"Yes\n";
                return 0;
            }
        }
    } 

    cout<<"No";

    return 0;
}

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

int main(void) {
	char  s[201] = { 0 };
	int len, half, x = 1;

	scanf("%s", &s);
	len = strlen(s);
	
	while (len > 2) {
		len -= 2;
		half = len / 2;
		for (int i = 0; i < half; i++) {
			if (s[i] != s[i + half]) {
				x = 0;
				break;
			}
		}
		if (x) break;
		else x = 1;
	}

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

	return 0;
}

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

using namespace std;


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

    if (N[0] == '7' || N[1] == '7' || N[2] == '7') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
n = gets.chomp.to_i
t = gets.chomp.split(" ").map(&:to_i)
count = t.inject(:+)
m = gets.chomp.to_i
m.times do
    pp, x = gets.chomp.split(" ").map(&:to_i)
    moto = t[pp-1]
    sa = x - moto
    ans = count + sa
    puts ans
end

Measured memory_bytes: 14244
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
    int N;cin>>N;
    map<string,int> m;
    for (int i = 0; i < N; i++){
        string s; cin>>s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    ll ans=0;
    for(auto p:m){
        ll x=p.second;
        ans+=x*(x-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() 
{ 
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    int mi=1e9;
    for(int i=1;i<=100;i++){
        int tot=0;
        for(int j=0;j<n;j++){
            tot+=(arr[j]-i)*(arr[j]-i);
        }
        mi=min(mi,tot);
    }
    cout<<mi;
	return 0; 
} 


Measured memory_bytes: 256
#include        "algorithm"
	#include        "iostream"
	#include        "numeric"
	#include        "iomanip"
	#include        "cstring"
	#include        "math.h"
	#include        "bitset"
	#include        "string"
	#include        "vector"
	#include        "ctime"
	#include        "queue"
	#include        "stack"
	#include        "map"
	#include        "set"

	#include        "ext/pb_ds/assoc_container.hpp" // Common file
	#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
	#include        "ext/pb_ds/detail/standard_policies.hpp"

	using namespace std;
	using namespace __gnu_pbds;


	#define          f first
	#define          lgn 25
	#define          endl '\n'
	#define          sc second
	#define          N (int)2e5+5
	#define          pb push_back
	#define          mod 1000000007
	#define          ld long double
	#define          vi vector<int>
	#define          eb emplace_back
	#define          vpii vector<pii>
	#define          mii map<int,int>
	#define          int long long 
	#define          pii pair<int,int>
	#define          pq priority_queue
	#define          BLOCK (int)sqrt(N)
	#define          test(x) while(x--)
	#define          all(x) begin(x),end(x)
	#define          allr(x) rbegin(x),rend(x)
	#define          fo(i,a,n) for(int i=a;i<n;i++)
	#define          rfo(i,n,a) for(int i=n;i>=a;i--)
	#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
	#define          PI acos(-1.0)
	#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

	typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
	OS ;

	template <typename Arg1>
	void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
	template <typename Arg1, typename... Args>
	void __f (const char* names, Arg1&& arg1, Args&&... args)
	{
	     const char* comma = strchr (names + 1, ',');
	     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
	}

	inline void INP()
	{
		#ifndef ONLINE_JUDGE
		    freopen("input.txt","r",stdin);   
		    freopen("output.txt","w",stdout);
		#endif 
	}

	const int inf = 0x3f3f3f3f;
	const int INF = 0x3f3f3f3f3f3f3f3f;

	int n,m,k,q,p;
	string s;
	vi adj[N];
	int vis[N],par[N],a[N];

	void go()
	{
		cin >> n >> p >> s;
		mii mp;
		mp[0]++;

		int no = 0 , po = 1;
		int ans = 0;

		if( p == 2 or p == 5 )
		{
			fo(i,0,n)
			{
				int d = s[i] - '0';
				if( d%p == 0 ) ans += ( i + 1 );
			}
			cout << ans << endl;
			return;
		}

		rfo(i,n-1,0)
		{
			int d = s[i] - '0';

			no = ( no + d*po )%p;
			ans += mp[no];
			mp[no]++;

			po = (po*10)%p;
		}

		cout << ans << endl;
	}

	int32_t main()
	{
		//INP(); 
		FAST;     
		int t=1; 
		// cin>>t;
		test(t) go();
	}

	 

Measured memory_bytes: 6292
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

N = ni()
ans = 0
for i in range(N, 1000):
    s = str(i)
    flag = True
    for j in range(len(s) - 1):
        if s[j] != s[j + 1]:
            flag = False
    if flag:
        ans = i
        break

print(ans)

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

using namespace std;
typedef long long int ll;


int main() {
   int n;
   cin>>n;
   double even, odd;
   cout<<setprecision(7);
   if(n%2 == 0){
       cout<<0.5;
   }
   else{
       even = n/2;
       odd = even + 1;
       cout<<odd/n;
   }

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;
typedef pair<int,int> P;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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 int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;

const double PI = acos(-1.0);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin>>N;
    vector<vector<int>> A(N,vector<int>(N-1,0));
    vector<vector<bool>> done(N,vector<bool>(N,false));
    rep(i,N){
        rep(j,N-1){
            cin>>A[i][j];
            A[i][j]--;
        }
        reverse(all(A[i]));
    }
    vector<P> q;
    auto check = [&](int i){
        if(A[i].size() == 0)return;
        int j = A[i].back();
        if(A[j].size() ==  0)return;
        if(i  != A[j].back())return;
        if(j < i)swap(i,j);
        if(done[i][j])return;
        q.push_back({i,j});
        done[i][j] = true;
    };
    rep(i,N)check(i);
    int ans = 0;
    while(!q.empty()){
        ans++;
        vector<P> prevQ;
        swap(prevQ, q);
        //prevQに入ってる試合を消化する（vectorから削除する）
        for(auto match: prevQ){
            int i = match.first;
            int j = match.second;
            A[i].pop_back();
            A[j].pop_back();
        }
        //試合が終わった選手に対してのみ、次の試合を考える
        for(auto match: prevQ){
            int i = match.first;
            int j = match.second;
            check(i);
            check(j);
        }
        //qに試合を突っ込み直す
    }
    rep(i,N){
        if(A[i].size() != 0){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 1e7 + 7;
const int P = 998244353;
int fac[maxn], inv[maxn];
int fpw(int x, int y){
	int ans = 1;
	for (; y; y >>= 1, x = 1LL * x * x % P)
		if (y & 1)
			ans = 1LL * ans * x % P;
	return ans;
}
int C(int n, int m){
	return 1LL * fac[n] * inv[m] % P * inv[n - m] % P;
}
int add(int x, int y){
	x += y;
	return x >= P ? x - P : x;
}
int calc(int n, int S, int m){
	int ans = 0;
	for (int i = 0; i <= min(S, min(n, m)); ++ i)
		if ((S - i) % 2 == 0){
			int s = (S - i) / 2;
			ans = add(ans, 1LL * C(n, i) * C(s + n - 1, n - 1) % P);
		}
	return ans;
}
int main(){
	int n, m;
	cin >> n >> m;
	fac[0] = 1;
	for (int i = 1; i <= 1e7; ++ i)
		fac[i] = 1LL * fac[i - 1] * i % P;
	inv[(int)(1e7)] = fpw(fac[(int)(1e7)], P - 2);
	for (int i = 1e7 - 1; i >= 0; -- i)
		inv[i] = 1LL * inv[i + 1] * (i + 1) % P;
	cout << add(calc(n, 3 * m, m), P - 1LL * n * add(calc(n, m, m), P - calc(n - 1, m, m)) % P) << endl;
}

Measured memory_bytes: 78336
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] v = new int[N];
    for (int i = 0; i < M; i++) {
      v[sc.nextInt()-1]++;
      v[sc.nextInt()-1]++;
    }
    boolean ans = true;
    for (int i = 0; i < N; i++) {
      if (v[i]%2 != 0) {
        ans = false;
        break;
      }
    }
    System.out.println(ans ? "YES" : "NO");
  }
}

Measured memory_bytes: 67044
#include<bits/stdc++.h>
using namespace std;
unsigned long long int pass(long long int n)
{
    unsigned long long int t = 0,s=1;
    while(1)
    {
        if(n==1)
        {
            return s;
            break;
        }
        else
        {
             n= (n/2);
             t++;
             //cout<<" n "<<n<<endl;
             s += pow(2,t);
             if(t==1)
             {
                 s -= 1;
                 //cout<<s<<endl;
             }
             //cout<<s<<endl;

        }
    }
}
int main()
{
    unsigned long long int m,n,t=0,c=0,s=0;
    cin>>n;
    if(n == 1)
    {
        cout<<"1\n";
    }
    else
    {
        m = pass(n);

        {
            cout<<m+1<<endl;
        }
    }
}



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

int main() {
  int H, W;
  cin >> H >> W;
  
  char c;
  for (int h = 0; h<H+2; h++){
    for (int w = 0; w<W+2; w++){
      if (h==0 || h==H+1 || w==0 || w==W+1)
        cout << '#';
      else{
        cin >> c;
        cout << c;
      }
    }
    cout << endl;
  }
}


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

int main(){
	int n,l[200];
	long long ans=0;
	cin>>n;
	for(int i=0;i<2*n;++i){
		cin>>l[i];
	}
	sort(l,l+2*n);
	for(int i=0;i<2*n;i+=2){
		ans+=l[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long count = 1; // (1,1)
        for(int i=2; i<=n; i++) {
            String s = Integer.toString(i);
            int len = s.length();
            int first = Integer.parseInt(s.substring(0, 1));
            int last = Integer.parseInt(s.substring(len-1));
            int mid = 0;
            if(len>2) {
                mid = Integer.parseInt(s.substring(1, len-1));
            }
            if(last == 0) {
                continue;
            }
            if(len<=1) {
                count++; // 1桁の数は必ず組になる
                continue;
            }

            // 2桁以上のとき、同桁数同士の組の数
            long scale = 1;
            if(len>2) {
                scale = (long)Math.pow(10, len-2);
            }
            if(last < first) {
                // ひっくり返したらiより小さい
                // 例：i=32 => (32, 23) * 2
                // 例：i=362 => (362, 203), (362, 213), ... * 2
                count+=2*scale;
            }
            if(last==first) {
                // ゾロ
                // 例：33 => (33, 33) ※ここでは (3, 33), (33, 3) は数えない。下位の桁は後で。
                // 例：323 => (323, 303), (323, 313), (323, 323) * 2 から　(323, 323) の重複組を引く
                count+=(mid+1)*2-1;
            }

            // 2桁以上かつゾロのとき、1桁との組
            if(last==first) {
                count+=2;
            }

            // 3桁以上のとき、下位桁（2桁以上）との組の数
            // ここでは重複は考えなくて良い
            // 例：i=512 => (512, 25) * 2
            // 例：i=1024 => (1024, 41), (1024, 4x1)*10    の2倍
            scale = 1;
            for(int j=0; j<len-2; j++) {
                count += scale * 2;
                scale *= 10;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 43856
/*
たて a cm よこ b cm の長方形の面積と周の長さを求めるプログラムを作成して下さい。
 */
#include <stdio.h>

int main(void)
{
    int a; // length
    int b; // breadth
    int area;
    int perimeter;

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

    area = a * b;
    perimeter = (a * 2) + (b * 2);

    printf("%d %d\n", area, perimeter);
    return (0);
}


Measured memory_bytes: 2044
#include<cstdio>

int main(){
    int i,j,n,count[100];
    for(int i = 0; i < 100; i++){
        count[i] = 0;
 	}
    char ch;
    while(scanf("%c",&ch)!=EOF){
        if(ch>='a' && ch<='z'){
            count[ch-'a']++;
        }
        else if(ch>='A'&& ch<='Z'){
            count[ch-'A']++;
        }
    }
    for(j=0;j<26;j++){
        printf("%c : %d\n",j+'a',count[j]);
    }
    return 0;
}


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

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

    for (int a = A; a <= min(A + K - 1, B); a++)
        cout << a << endl;

    for (int b = max(A + K, B - K + 1); b <= B; b++)
        cout << b << endl;
}

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

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

  int s = 0;
  rep(i, n) s ^= a[i];
  rep(i, n) a[i] ^= s;
  rep(i, n) cout << (i == 0 ? "" : " ") << a[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 4052
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
int n, m, K;
int main()
{
	while(~scanf("%d%d%d", &n, &m, &K)){
		bool ok = 0;
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= m; j++) {
				int now = i * m + j * n - 2 * i * j;
				if(K == now) ok = 1;
			}
		}
		if(ok) printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 256
use std::collections::HashSet;

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)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}

const MOD: i64 = 1_000_000_007;

fn main() {
    input! {
        n: usize,
        x: u64,
        mut a: [u64; n]
    }

    let mut c = 0;
    if a[0] > x {
        c += a[0] + a[1] - x;
        a[0] = x;
        a[1] = 0;
    }
    for i in 1..n {
        if a[i] + a[i - 1] > x {
            c += a[i] + a[i - 1] - x;
            a[i] = a[i] - (a[i] + a[i - 1] - x);
        }
    }

    println!("{}", c);
}


Measured memory_bytes: 4352
S = input()
T = input()
N = len(S)
M = len(T)
dp = [[0] * (M+1) for _ in range(N+1)]
for i in range(1,N+1):
    for k in range(1,M+1):
        if S[i-1] == T[k-1]:
            dp[i][k] = dp[i-1][k-1] + 1
        else:
            dp[i][k] = max(dp[i-1][k],dp[i][k-1])
ans = ''
x = N
y = M
while x > 0 and y > 0:
    if dp[x][y] == dp[x-1][y]:
        x -= 1
    elif dp[x][y] == dp[x][y-1]:
        y -= 1
    else:
        x -= 1
        y -= 1
        ans += S[x]
print(ans[::-1])

Measured memory_bytes: 112220
N, Y = map(int, input().split())
for i in range(N + 1):
  for j in range(N- i + 1):
    k = N - i - j
    if Y == 10000 * i + 5000 * j + 1000 * k:
        print(" ".join(map(str, [i, j, k])))
        quit(0)
print("-1 -1 -1")

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int Array[405][405];
bool Visited[405][405];
int white , black , h , w;

void dfs( int r , int c ){
    if( Visited[r][c] == true ) return;
    Visited[r][c] = true;
    int next;
    if( Array[r][c] == 0 ){ 
        ++black;
        next = 1;
    }
    else{ 
        ++white;
        next = 0;
    }

    if( r > 1 && Visited[r - 1][c] == false && Array[r - 1][c] == next ) dfs( r - 1 , c );
    if( r < h && Visited[r + 1][c] == false && Array[r + 1][c] == next ) dfs( r + 1 , c );
    if( c > 1 && Visited[r][c - 1] == false && Array[r][c - 1] == next ) dfs( r , c - 1 );
    if( c < w && Visited[r][c + 1] == false && Array[r][c + 1] == next ) dfs( r , c + 1 );
}

int main(){
    int i , j;
    scanf( "%d%d" , &h , &w );
    char ch;

    for( i = 1 ; i <= h ; ++i ){
        for( j = 1 ; j <= w ; ++j ){
            scanf( "%c" , &ch );

            while( ch != '#' && ch != '.' )
                scanf( "%c" , &ch );
            
            if( ch == '#' ) Array[i][j] = 0;
            else Array[i][j] = 1;

            Visited[i][j] = false;
        }
    }

    long long Ans = 0;

    for( i = 1 ; i <= h ; ++i ){
        for( j = 1 ; j <= w ; ++j ){
            if( Visited[i][j] == false ){
                white = black = 0;
                dfs( i , j );
                Ans = Ans + ( white * 1LL * black );
            }
        }
    }

    printf( "%lld\n" , Ans );
    return 0;
}

Measured memory_bytes: 13568
s=input()
a,b,c,d=int(s[0]),int(s[1]),int(s[2]),int(s[3])
if a+b+c+d==7:print(a,'+',b,'+',c,'+',d,'=',7, sep='')
elif a+b+c-d==7:print(a,'+',b,'+',c,'-',d,'=',7, sep='')
elif a+b-c+d==7:print(a,'+',b,'-',c,'+',d,'=',7, sep='')
elif a-b+c+d==7:print(a,'-',b,'+',c,'+',d,'=',7, sep='')
elif a+b-c-d==7:print(a,'+',b,'-',c,'-',d,'=',7, sep='')
elif a-b-c+d==7:print(a,'-',b,'-',c,'+',d,'=',7, sep='')
elif a-b+c-d==7:print(a,'-',b,'+',c,'-',d,'=',7, sep='')
elif a-b-c-d==7:print(a,'-',b,'-',c,'-',d,'=',7, sep='')

Measured memory_bytes: 38384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String... args) throws IOException {
        int n;
        Set<String> s = new HashSet<>();
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String line;

        line = bf.readLine();

        n = Integer.parseInt(line);

        for (int i = 0; i < n; i++) {
            line = bf.readLine();
            s.add(line);
        }

        System.out.println(s.size());
    }
}


Measured memory_bytes: 66008
#include<iostream>
using namespace std;
 
int main (){
    int N;
    cin>>N;
    int K[N];
    int P[N];
    for(int i=0;i<N;i++){
        cin>>K[i]>>P[i];
    }
    for(int j=0;j<N;j++){
        if(K[j]%P[j]==0){
            cout<<P[j]<<endl;
        }else{
        cout<<K[j]%P[j]<<endl;
        }
    }
return 0;
}

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

typedef long long ll;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define debug(x) cout << '>' << #x << ':' << x << "\n";
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair



int main() {
    int n,k;
    cin >> n>>k;
    string s;
    cin >> s;
    int ans = 0;
    for(int i=0;i<n;i++){
        if(i!=0 && s[i]=='L'){
            if(s[i-1]=='L'){
                ans++;
            }
        }
        
        if(i!=n-1 && s[i]=='R'){
            if(s[i+1]=='R'){
                ans++;
            }
        }
    }

    ans=min(n-1,ans+2*k);

    cout << ans;

return 0;
}

Measured memory_bytes: 512
using System.Collections.Generic;
using System.Linq;
using System;

public class C
{
    public const int INF = 999999999;
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var r = new int[n, n];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    if (i != j) r[i, j] = C.INF;
            var m = int.Parse(Console.ReadLine().Trim());
            for (int i = 0; i < m; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(',');
                var a = int.Parse(line[0]);
                var b = int.Parse(line[1]);
                var d = int.Parse(line[2]) / 100;
                r[a, b] = d; r[b, a] = d;
            }
            var minc = new int[n];
            for (int i = 0; i < n; i++) minc[i] = C.INF;
            goPrim(r, minc, 0);
            Console.WriteLine(minc.Sum() - n + 1);
        }
    }
    public static void goPrim(int[,] r, int[] minc, int targ)
    {
        var n = r.GetLength(0);
        var xL = new List<int>();
        xL.Add(targ);  minc[targ] = 0;
        var count = 0;
        while (count < n)
        {
            for (int i = 0; i < n; i++)
                if (!xL.Contains(i) && r[targ, i] != C.INF && r[targ, i] < minc[i]) minc[i] = r[targ, i];
            var mint = C.INF; var minb = -1;
            for (int i = 0; i < n; i++)
                if (!xL.Contains(i) && minc[i] < mint) {  mint =  minc[i] ; minb = i; }
            xL.Add(minb);
            targ = minb;
            count++;
        }
    }
}

Measured memory_bytes: 9984
#include <cstdio>
#include <vector>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;
const ll inf_ll=1e9+7;

struct Solver{
  int n;
  int k;
  vector< vector<int> > tree;
  vector<int> reached;
  explicit Solver(int N, int K): n(N), k(K){
    tree.resize(this->n);
    reached.resize(this->n);
  }
  void init(){
    rep(i,n-1){
      int a,b; scanf("%d %d", &a, &b);
      a--; b--;
      tree[a].push_back(b);
      tree[b].push_back(a);
    }
    reached.assign(this->n, 0);
  }
  ll dfs(int cur, int prev){
    int available_color = (prev==-1 ? k-1 : k-2);
    ll num=1;
    if(reached[cur]) return 1;
    reached[cur] = 1;
    
    if(k<(int)this->tree[cur].size()) return 0;
    for(int s : this->tree[cur]){
      if(s==prev) continue;
      num *= available_color; 
      available_color--;
      num %= inf_ll;
    }
    //printf("now = %d, color = %lld\n ----------\n", cur+1, num);
    for(int s : this->tree[cur]){
      if(s==prev) continue;
      num *= dfs(s, cur);
      num %= inf_ll;
    }
    return num;
  }
  void solve(){
    this->init();
    ll ans = k*dfs(0,-1);
    ans %= inf_ll;
    printf("%lld\n", ans);
  }
};

int main(){
  int N, K; scanf("%d %d", &N, &K);

  Solver solver(N, K);
  solver.solve();
  return 0;
}

Measured memory_bytes: 8576
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

const MAX = 55555

var pN [MAX]int

func initPrime() {
	for i := 2; i*i < MAX; i++ {
		for j := i * 2; j < MAX; j += i {
			if pN[j] == 0 {
				pN[j] = i
			}
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)

	initPrime()

	N := getInt()

	cnt := 0
	for i := 2; i < MAX; i++ {
		// 素数で、かつ、1引いたら５で割れる（５つ足すと５で割れる）
		if pN[i] == 0 && (i-1)%5 == 0 {
			fmt.Print(i, " ")
			cnt++
		}
		if cnt == N {
			break
		}
	}
	fmt.Println("")
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int a[200002], dp[200002];
int main(){
    int n, ans = 0;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
        dp[a[i]] = max(dp[a[i]], dp[a[i]-1]+1);
        ans = max(ans, dp[a[i]]);
    }   
    printf("%d\n", n-ans);
}

Measured memory_bytes: 1792
#include <cstdio>

int main(){
    int n;
    scanf("%d",&n);

    bool card[4][13];
    for(int i = 0;i < 4;i++){
        for(int j = 0;j < 13;j++){
            card[i][j] = false;
        }
    }
    for(int i = 0;i < n;i++){
        char c;
        scanf("\n%c",&c);

        int x;
        scanf("%d",&x);
        if(c == 'S'){
            card[0][x - 1] = true;
            continue;
        }
        if(c == 'H'){
            card[1][x - 1] = true;
            continue;
        }
        if(c == 'C'){
            card[2][x - 1] = true;
            continue;
        }
        card[3][x - 1] = true;
    }
    for(int i = 0;i < 4;i++){
        for(int j = 0;j < 13;j++){
            if(card[i][j] == false){
                if(i == 0){
                    printf("S %d\n",j + 1);
                    continue;
                }
                if(i == 1){
                    printf("H %d\n",j + 1);
                    continue;
                }
                if(i == 2){
                    printf("C %d\n",j + 1);
                    continue;
                }
                printf("D %d\n",j + 1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2588
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
 
void mul_mod(ll& a, ll b){
    a *= b;
    a %= MOD;
}
 
void add_mod(ll& a, ll b){
    b += MOD;
    a += b;
    a %= MOD;
}

int main(void){
    int a,b,n,x,y,i,j;
    ll dp[20][20];
    bool cst[20][20];
    cin >> a >> b;
    while(a || b){
        fill(cst[0],cst[20],false);
        cin >> n;
        for(i=0; i<n; ++i){
            cin >> x >> y;
            cst[x][y] = true;
        }
        for(i=0; i<=a; ++i){
            for(j=0; j<=b; ++j){
                if(cst[i][j] || !(i && j)){
                    dp[i][j] = 0ll;
                }else if(i==1 && j==1){
                    dp[i][j] = 1ll;
                }else{
                    dp[i][j] = dp[i-1][j] + dp[i][j-1];
                }
            }
        }
        cout << dp[a][b] << endl;
        cin >> a >> b;
    }
    return 0;
}


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

int main() {
  ll a,p,ans;
  cin >> a >> p;
  ans=(a*3+p)/2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#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;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
void radd(int &a, int b)
{
	a=add(a,b); 
}
	
const ll INF=3e18;
ll mult(ll a, ll b)
{
	if(a==0||b==0) return 0;
	if(a>INF/b) return INF;
	return a*b;
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	ll cur=1;
	for(int i=0;i<n;i++)
	{
		ll x; cin>>x;
		cur=mult(cur,x);
	}
	if(cur>ll(1e18)) cout<<-1<<'\n';
	else cout<<cur<<'\n';
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long X; cin >> X;
    long long money = 100;
    int count = 0;
    while(money < X){
        money *= 1.01;
        count++;
        //cout << money << endl;
    }
    cout << count << endl;
}


Measured memory_bytes: 3172
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
using namespace std;
long long INF = 1000000009;
map<int, int> mp;
int main()
{
	ios::sync_with_stdio(false);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = c - a, y = d - b;
	cout << c - y << " " << d + x << " " << a - y << " " << b + x << endl;
}

Measured memory_bytes: 256
import numpy as np
import sys
sys.setrecursionlimit(100000)

directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])


def acinput():
    return list(map(int, input().split(" ")))


sys.setrecursionlimit(100000)


directions = [[1, 0], [0, 1], [-1, 0], [0, -1]]
directions = list(map(np.array, directions))


def acinput():
    return list(map(int, input().split(" ")))


N, K = acinput()
s = list(map(int, list(input())))

nums = [1]
for i in range(1, N):
    if s[i] == s[i-1]:
        nums[-1] += 1
    else:
        nums.append(1)

if s[0] != 1:
    nums.insert(0, 0)
nums_cs = np.cumsum(nums)

res = nums_cs[min(len(nums_cs)-1,2*K)]
# if len(nums_cs) > 1:
#     res = nums_cs[min(len(nums_cs)-1, 2*K-1)]
# else:
#     res = nums_cs[0]

for i in range(1,len(nums_cs)-2*K+1):
    if i % 2 == 0:
        #print(i)
        res = max(res, nums_cs[min(i+2*K,len(nums_cs)-1)]-nums_cs[i-1])


print(res)

Measured memory_bytes: 15572
#include<stdio.h>
long long MIN(long long a,long long b){return a<b?a:b;}
long long R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(long long a){
  //if(C==1)R=1;
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
long long ta[60],to[300],nt[300],co[300],ti[300],i,j,g[1000010],p[1000010];
int main(){
  long long n,m,a,b,c,d,e[60],f[60],dp[3000][60],ng,gi,po,s;
  for(i=0;i<3000;i++){
    for(j=0;j<60;j++)dp[i][j]=1e18;
  }
  for(i=0;i<60;i++)ta[i]=-1;
  scanf("%lld %lld %lld",&n,&m,&s);
  s=MIN(s,2500);
  for(i=0;i<m;i++){
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    nt[i  ]=ta[to[i+m]=a];
    nt[m+i]=ta[to[i  ]=b];
    ti[i]=ti[i+m]=d;
    co[ta[a]=i]=co[ta[b]=i+m]=c;
  }
  for(i=0;i<n;i++)scanf("%lld %lld",&e[i+1],&f[i+1]);
  //for(i=0;i<n;i++)printf("e:%lld ",e[i+1]);printf("\n");
  hin(dp[g[R]=s][p[R]=1]=0);
  while(C-1){
    i=hout();
    po=p[i];
    gi=g[i];//printf("!%lld %lld %lld \n",po,gi,N[i]);
    ng=MIN(gi+e[po],2500);//printf("%lld %lld %lld\n",dp[ng][po],N[i]+f[po],ng);
    if(dp[ng][po]>N[i]+f[po]){//printf("%lld\n",R);
      hin(dp[g[R]=ng][p[R]=po]=N[i]+f[po]);//printf("!!!%lld\n",R);
    }
    if(gi&&dp[gi-1][po]>N[i])hin(dp[g[R]=gi-1][p[R]=po]=N[i]);//printf("%lld\n",C);
    for(j=ta[po];j+1;j=nt[j]){//printf("::::%lld %lld %lld\n",gi,to[j],co[j]);
      if(gi<co[j])continue;
      if(dp[gi-co[j]][to[j]]>N[i]+ti[j])hin(dp[g[R]=gi-co[j]][p[R]=to[j]]=N[i]+ti[j]);
    }
  }
  for(i=2;i<=n;i++)printf("%lld\n",dp[0][i]);
  return 0;
}
  
     


Measured memory_bytes: 7812
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    int a=0;
    cin >> a;
    A.at(i) = a;
  }
  sort(A.begin(), A.end());
  
  int sum_A = 0;
  int sum_B = 0;
  
  if(N%2==0){
    for(int i=0; i<N; i++){
      if(i%2==0){
        sum_B += A.at(i);
      }
      else{
        sum_A += A.at(i);
      }
    }
  }
  
  if(N%2==1){
    for(int i=0; i<N; i++){
      if(i%2==0){
        sum_A += A.at(i);
      }
      else{
        sum_B += A.at(i);
      }
    }
  }
  
  cout << sum_A - sum_B <<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		String[] IN =br.readLine().split("") ; 
		
		int MAX = 0;
		
		for(int i=0; i<N; i++) {
			
			HashMap<String,Integer> count = new HashMap<String,Integer>();
			//文字列をカットした左半分について
			for(int j=0; j<i+1; j++) {
				if (!count.containsKey(IN[j])) {
					count.put(IN[j], 1); //まだHashMapにキーが登録されていないなら、登録する
				}
			}
			
			//文字列をカットした右半分について
			for(int j=i+1; j<N; j++) {
				if (count.containsKey(IN[j])) { //HashMapに既にキーがあるとき
					int now = count.get(IN[j]); //キーSに紐づく中身のintを取得
					count.replace(IN[j], now + 1);
				}
			}
			
			int c = 0;
			for(int key1:count.values()) {
				if(key1 > 1) {
					c++;
				}
			}
			if(MAX<c) {
				MAX = c;
			}
		}
		
		System.out.println(MAX);	
	}
}

Measured memory_bytes: 33732
N = int(input())

# 現時点でのパラメータ
pt = 0
px = 0
py = 0

for i in range(N):
    t, x, y = map(int, input().split())

    time = abs(t - pt)
    # いわゆるマンハッタン距離
    dist = abs(x - px) + abs(y - py)

    if dist > time:
        print("No")
        exit()

    # x+yの偶奇は毎秒変わる
    # timeとdistの偶奇は一致する
    if time % 2 != dist % 2:
        print("No")
        exit()

    pt, px, py = t, x, y

print("Yes")

Measured memory_bytes: 9180
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

int N,A[222222],mi[555555]={};
LL ans=0ll;

int main() {
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>A[i];
		if(i-A[i]>0)mi[i-A[i]]++;
	}
	for(int i=1;i<=N;i++){
		int pl=i+A[i];
		if(pl<500000)ans+=mi[pl];
		if(i-A[i]>0)mi[i-A[i]]--;
	}
	cout<<ans<<endl;


	return 0;
}



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

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define int long long

using namespace std;

int32_t main() {
	fast
	int k;
	string s;
	cin >> k >> s;
	if (s.length() > k) s = s.substr(0, k) + "...";
	cout << s << endl;

}

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

int main() {
  string s;
  cin >> s;
  
  if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]){
    cout << "Bad" << endl;
  }
  else{
    cout << "Good" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
struct Union_Find{
    int d[SIZE],num[SIZE];
    void init(int n){
        REP(i,n)d[i]=i,num[i]=1;
    }
    int find(int x){
        return (x!=d[x])?(d[x]=find(d[x])):x;
    }
    bool uu(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y)return 0;
        if(num[x]>num[y])swap(x,y);
        num[y]+=num[x];
        d[x]=y;
        return 1;
    }
}U;
VI d[SIZE];
int main(){
    DRII(N,M);
    U.init(N);
    REP(i,N){
        DRI(K);
        REP(j,K){
            DRI(x);
            d[x].PB(i);
        }
    }
    REP(i,SIZE){
        for(int j=1;j<SZ(d[i]);j++)U.uu(d[i][j-1],d[i][j]);
    }
    if(U.num[U.find(0)]!=N)puts("NO");
    else puts("YES");
    return 0;
}


Measured memory_bytes: 25856
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define mkp make_pair
map<int,vector<int> >mp;
map<int,int>N1,N2;
int h,w,n,a[300004],b[300004];
set<pii>st;
int main(){
	cin>>h>>w>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		N1[a[i]]++,N2[b[i]]++;
		mp[a[i]].push_back(b[i]);
	}
	int ans=0;
	for(int i=0;i<n;i++)ans=max(N1[a[i]]+N2[b[i]]-1,ans);
	for(map<int,int>::iterator it=N2.begin();it!=N2.end();it++)st.insert(mkp(-it->second,it->first));
	for(map<int,vector<int> >::iterator it=mp.begin();it!=mp.end();it++){
		vector<int>v=it->second;
		for(int i=0;i<v.size();i++)st.erase(st.find(mkp(-N2[v[i]],v[i])));
		int dd=0;
		if(!st.empty())dd=-(*st.begin()).first;
		ans=max(ans,dd+(int)v.size());
		for(int i=0;i<v.size();i++)st.insert(mkp(-N2[v[i]],v[i]));
	}
	cout<<ans;
}

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

int main(){
    bool cards[4][14];
    int n,rank;
    char suit;
    
    for (int s=0;s<4;s++)
      for (int r=1;r<=13;r++)
         cards[s][r]=0;
         
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>suit>>rank;
        if (suit=='S') cards[0][rank] =1;
        if (suit=='H') cards[1][rank] =1;
        if (suit=='C') cards[2][rank] =1;
        if (suit=='D') cards[3][rank] =1;
        
    }
    
    for (int s=0;s<4;s++){
        for (int r=1;r<=13;r++){
            if (cards[s][r]) continue;
            if (s==0) suit='S';
            if (s==1) suit='H';
            if (s==2) suit='C';
            if (s==3) suit='D';
            cout<<suit<<" "<<r<<endl;
            
        }
    }
    
    return 0;
}


Measured memory_bytes: 3076
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define ll long long int
#define fab(a,b,i) for(int i=a;i<b;i++)
#define pb push_back
#define db double
#define mp make_pair
#define endl "\n"
#define f first
#define se second
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int n;ll a[200005];

ll seg[4*200005];
void update(int node,int l,int r,ll ind,ll val)
{
    if(l==r)
    {
        seg[node]=val;
        return;
        //cout<<"l:"<<l<<" "<<val<<" "<<seg[node]<<" "<<node<<endl;
        //a[ind]=val
    }
    else
    {
            int mid=(l+r)/2;
            if(ind<=mid)
                update(2*node,l,mid,ind,val);
            else
                update(2*node+1,mid+1,r,ind,val);

    }
    seg[node]=max(seg[2*node],seg[2*node+1]);

}

ll query(int node,int s,int e,int l,int r)
{
    if(s>r or e<l)
        return 0;
    //cout<<"AFdgS";
    if(l<=s and e<=r)
        return seg[node];
    int mid=(s+e)/2;
    return max(query(2*node,s,mid,l,r),query(2*node+1,mid+1,e,l,r));
}

int main()
{ quick;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin>>n;
    fab(0,n,i)
    cin>>a[i];
    ll b[n];
    fab(0,n,i)
    cin>>b[i];
    ll dp[n+1]={0};
    fab(0,n,i)
    {
        ll sm=query(1,0,n+1,0,a[i]);
       // cout<<"sm:"<<i<<" "<<sm<<endl;
        dp[a[i]]=max(dp[a[i]],sm+b[i]);
        //cout<<dp[i]<<" ";
        update(1,0,n+1,a[i],dp[a[i]]);

    }    
 //   fab(0,4*n,i)
   // cout<<seg[i]<<" ";
    cout<<query(1,0,n+1,0,n+1)<<endl;

 cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}

Measured memory_bytes: 12612
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <chrono>
#include <random>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 4e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

bool debug = false;

random_device rnd;
mt19937_64 mt(rnd());

ll c[26], s[370][26], D, last[26];

void input(){
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D) rep(j, 26) cin >> s[i][j];
}

void make_input(){
    rep(i, 365) c[i] = mt() % 101;
    rep(i, 365) rep(j, 26) s[i][j] = mt() % 20001;
}

ll calc_v(vll t){
    vll v(D, 0);
    rep(i, 26) last[i] = -1;
    rep(i,D){
        if (i>0)
            v[i] = v[i - 1];
        v[i] += s[i][t[i]];
        last[t[i]] = i;
        rep(j, 26) v[i] -= c[j] * (i - last[j]);
    }
    return v[D-1];
}



//note:ランダム

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    clock_t start = clock();
    D = 365;
    if(debug)
        make_input();
    else
        input();
    rep(i, 26) last[i] = -1;

    ll n = 50000;
    ll mx = -infl;
    vll ans(D, 0);

    //ans:答えをＤ日分入力
    //last[i]:i番目のコンテストを最後に行ったのはlast[i]日
    vll agr(n);
    rep(i,n){
        vll t(D, 0);
        rep(j, D) t[j] = (mt() % 26);
        ll v = calc_v(t);
        agr[i] = v;
        if (v>mx){
            ans = t;
            mx = v;
        }
    }
    clock_t end = clock();
    if (debug){
        cout << "min :" << *min_element(all(agr)) << ENDL;
        cout << "max :" << *max_element(all(agr)) << ENDL;
        ll sm = 0;
        rep(i, n) sm += agr[i];
        cout << "ave :" << sm / n << ENDL;
        ld time = static_cast<ld>(end - start) / CLOCKS_PER_SEC * 1000.0;

        cout << "time :" << fixed << setprecision(3) << time << "ms" << ENDL;
        
    }
    else 
        rep(i, D) cout << ans[i] + 1 << ENDL;
}


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


int func(int x){
  if(x%2 != 0) return 0;
  return func(x/2) + 1;
}


int main(){
  int N, a;
  cin >> N;
  int cnt = 0;
  for(int i=0; i<N; i++){
    cin >> a;
    cnt += func(a);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include <cstdlib>
#include <math.h>

using namespace std;

int main(){
        string s;
        int Ans=753;
        cin >> s;
        for(int i=0; i<s.length()-2; i++){
                int num = (s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
                Ans=min(Ans,abs(753-num));
        }
        cout<< Ans<<endl;
        return 0;
}


Measured memory_bytes: 256
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
#define biggest(A,B) A=max(A,B)
#define smallest(A,B) A=min(A,B)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n,a[200000+2];
int main(){
	fastio;
	cin>>n;
	rb(i,1,n)
		cin>>a[i];
	sort(a+1,a+1+n);
	reverse(a+1,a+1+n);
	bool col=0;
	int it=1;
	LL res=0;
	rb(i,1,n-1){
		res+=a[it];
		if(it==1){
			it++;
		}
		else
		if(col==1){
			col=0;
			it++;
		}
		else{
			col=1;
		}
	}cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 4432
#include <iostream>
#include <algorithm>

using namespace std;

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

    int n, m;
    cin >> n >> m;

    if (n % 2 == 0) {
        for (int i = 1, j = 2 * m + 1; i <= m; i++, j--) {
            if (i == (n + 2) / 4) {
                j--;
            }
            cout << i << " " << j << endl;
        }
    } else {
        for (int i = 1, j = 2 * m; i <= m; i++, j--) {
            cout << i << " " << j << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL W, H, X, Y;
  cin >> W >> H >> X >> Y;
  int mul = 0;
  if (2 * X == W && 2 * Y == H) mul = 1;
  printf("%.10lf %d\n", (double)W * H / 2, mul);
  // if (X == W || Y == H) {
  //   int mul = 0;
  //   if(X==W&&Y==H){
  //     mul=1;
  //   }
  //   printf("%.6lf %d\n", (double)W*H/2, mul);
  //   return 0;
  // }
  // LL tate = min(X * H, (W - X) * H);
  // LL yoko = min(Y * W, (H - Y) * W);
  // DUMP(tate, yoko);
  // if (tate == yoko) {
  //   printf("%.6lf 1\n", (double)tate);
  // } else {
  //   double ans = max(tate, yoko);
  //   printf("%.6lf 0\n", ans);
  // }

  return 0;
}


Measured memory_bytes: 256