akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
	char hand[100000];
	bool player[100000];
	int N, K, R, S, P;
	
	scanf("%d %d", &N, &K);
	scanf("%d %d %d", &R, &S, &P);
	scanf("%s", hand);
	
	int value[100000]; // 0 = グー、 1 ＝チョキ、 2 = パー
	for(int i = 0; i < 100000; i++){
		value[i] = 0;
		player[i] = false;
	}
	
	for(int i = 0; i < N; i++){
		if(i > 0){
			int addValue = value[i-1];
			
			value[i] += addValue;
		}
		
		if(i < K){
			if(hand[i] == 'r'){
				value[i] += P;
			}
			else if(hand[i] == 's'){
				value[i] += R;
			}
			else if(hand[i] == 'p'){
				value[i] += S;
			}
		}
		else
		{
			if(hand[i] == 'r'){
				if(hand[i-K] != 'r'){
					value[i] += P;
				}else if(player[i-K]){
					value[i] += P;
				}else{
					player[i] = true;
				}
			}
			else if(hand[i] == 's'){
				if(hand[i-K] != 's'){
					value[i] += R;
				}else if(player[i-K]){
					value[i] += R;
				}else{
					player[i] = true;
				}
			}
			else if(hand[i] == 'p'){
				if(hand[i-K] != 'p'){
					value[i] += S;
				}else if(player[i-K]){
					value[i] += S;
				}else{
					player[i] = true;
				}
			}
		}
	}
	
	int lastValue = value[N-1];
	
	printf("%d\n", lastValue);
}



Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#define R(i, n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
int D,n,m;
while(cin>>D&&D){
ll r=0;
ll d[100010];
cin>>n>>m;
d[0]=0;
R(i,n-1){
cin>>d[i+1];
}
d[n]=D;
sort(d,d+n);
R(i,m){
ll k;
cin>>k;
ll *s=upper_bound(d,d+n+1,k);
r+=min(*s-k,k-*(s-1));
}
cout<<r<<endl;
}
}

Measured memory_bytes: 3716
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int n = sc.nextInt();
	int i= 1;
	 while (++i <= n){
		 if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 }
	 }
	 System.out.printf("\n"); 
	}
}

Measured memory_bytes: 30712
// 解き直し.
// https://img.atcoder.jp/arc079/editorial.pdf
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[55];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%lld", &a[i]);
    
    // 2. 操作回数をカウント.
    LL ans = 0;
    function<void()> f = [&](){
        // 終了条件.
        bool ok = true;
        rep(i, N){
            if(a[i] >= N){
                ok = false;
                break;
            }
        }
        if(ok) return;
        
        // 今回の操作回数を計算.
        LL cur = 0;
        rep(i, N) cur += a[i] / (LL)N;
        
        // 数列の各要素を更新.
        rep(i, N){
            LL b = a[i] / (LL)N;
            a[i] -= b * (LL)N;
            a[i] += cur - b;
        }
        
        // 今回の操作回数を加算.
        ans += cur;
        
        // 次回の操作.
        f();
    };
    f();
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 3768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace PaizaSkillCheck
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int sum = 0;
            int max = 0;

            for(int i = 0; i < n; i++)
            {
                int p = int.Parse(Console.ReadLine());

                if(p > max)
                {
                    sum += max;
                    max = p;
                }
                else
                {
                    sum += p;
                }
            }

            sum += (max / 2);

            Console.WriteLine(sum);
            Console.ReadLine();
        }

    }

}


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

using namespace std;

int main() {
    int64_t n, k, m;

    cin >> n >> k;

    if(n > k) {
        n %= k;
    }

    while(true) {
        m = abs(n - k);
        if(m >= n) {
            break;
        } else {
            n = m;
        }
    }

    cout << n << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 2010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

int up[maxn][maxn], down[maxn][maxn], lef[maxn][maxn], rig[maxn][maxn], n, m;
char s[maxn][maxn];
template <class T> void read(T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> s[i] + 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      up[i][j] = (up[i - 1][j] + 1) * (s[i][j] == '.');
      lef[i][j] = (lef[i][j - 1] + 1) * (s[i][j] == '.');
    }
  }
  for (int i = n; i; i--) {
    for (int j = m; j; j--) {
      down[i][j] = (down[i + 1][j] + 1) * (s[i][j] == '.');
      rig[i][j] = (rig[i][j + 1] + 1) * (s[i][j] == '.');
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ans = max(ans, up[i][j] + down[i][j] + lef[i][j] + rig[i][j] - 3);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 67200
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	max := -1000
	if max < a+b {
		max = a + b
	}
	if max < a-b {
		max = a - b
	}
	if max < a*b {
		max = a * b
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r,g,b,n;
    cin >> r >> g >> b >>n;
    int cnt = 0;
    for (int i = 0; i <= n/r; ++i) {
        for (int j = 0; j <= (n-r*i)/g; ++j) {
            if((n - r * i - g * j)%b==0)cnt++;
                
            
        }
    }
    cout << cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#include <functional>
#include <cstdio>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */
int dic[12000000];
ull pow(ull x,ull n) {
  ull res = 1;
  while(n > 0) {
    if(n&1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
int dic_op(char str[14],int& key)
{
  int j;
  int f = 1;
  int g = 0;
  for(j = 0;j<10;j++) {
    if(str[j] == 'A')
      g += f * 1;
    else if(str[j] == 'C')
      g += f * 2;
    else if(str[j] == 'G')
      g += f * 3;
    else if(str[j] == 'T')
      g += f * 4;
    else break;
    f *= 5;
  }
  key = 0;
  if(j == 10) {
    f = 1;
    for(;j<10;j++) {
      if(str[j] == 'A')
        key += f * 1;
      else if(str[j] == 'C')
        key += f * 2;
      else if(str[j] == 'G')
        key += f * 3;
      else if(str[j] == 'T')
        key += f * 4;
      else break;
        f *= 5;
    }
  }
  return g;
}
int main()
{
  int i,j,k,l;
  long n;
  long ans = 0;
  char opstr[7];
  char str[13];
  int key;
  int a = 1;
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%s %s",opstr,str);
    if(opstr[0] == 'i') {
      int tmp = dic_op(str,key);
      if( (dic[tmp] >> key) % 2 == 0) {
        dic[tmp] += 1 << key;
      }
    }
    else if(opstr[0] == 'f') {
      int tmp = dic_op(str,key);
      /*
      printf("tmp = %d\n",tmp);
      printf("key = %d\n",key);
      printf("dic[tmp] = %d\n",dic[tmp]);
      */
      if( (dic[tmp] >> key) % 2 == 1) {
        puts("yes");
      }
      else {
        puts("no");
      }
    }
  }
  return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    ll cnt = 0;
    string s;
    cin >> N;
    cin >> s;
    for (int i = 0; i < N; i++) {
        if(s[i] == 'R'){
            cnt++;
        }
    }
    Yes(cnt > (N-cnt));
}

Measured memory_bytes: 3564
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void) {
	int x,ans=1;
	cin >> x;
	for(int i=2; i<x; i++){
		int temp=i;
		while(temp*i<=x){
			temp*=i;
			ans=max(ans,temp);
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> nWhites(N + 1, 0);
  vector<int> nBlacks(N + 1, 0);
  nBlacks[N - 1] = (S[N - 1] == '.');
  for (int i = N - 2; i >= 0; --i) {
    if (S[i] == '.') {
      nBlacks[i] = nBlacks[i + 1] + 1;
    } else {
      nBlacks[i] = nBlacks[i + 1];
    }
  }
  
  nWhites[1] = (S[0] == '#');
  for (int i = 2; i <= N; ++i) {
    if (S[i - 1] == '#') {
      nWhites[i] = nWhites[i - 1] + 1;
    } else {
      nWhites[i] = nWhites[i - 1];
    }
  }

  int ans = 1e9;
  for (size_t i = 0; i < nWhites.size(); ++i) {
    ans = min(ans, nWhites[i] + nBlacks[i]);
  }
  cout << ans << endl;
  return 0;
}



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

int fp;
long long n;

vector<long long> g(long long a) {
	vector<long long> dr;
	for(long long i = 2; i * i <= a; ++i) {
		if(a % i == 0) {
			dr.push_back(i);
			if(a / i != i) dr.push_back(a / i);
		}
	}
	if(a > 1) dr.push_back(a);
	return dr;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	fp = g(n - 1).size();
	vector<long long> v = g(n);
	for(long long i : v) {
		long long p = n;
		while(p % i == 0) {
			p /= i;
		}
		if(p % i == 1) ++fp;
	}
	cout << fp << endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

class Main
{
    public static void main(String args[])
    {
        Scanner scan = new Scanner(System.in);
        
        int S = scan.nextInt();
        int h = S/3600;
        int m = (S%3600)/60;
        int s = S%60;
        System.out.println(h+":"+m+":"+s);
    }
}


Measured memory_bytes: 26144
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e6+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]--;
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(i==a[a[i]])cnt++;
	}
	cnt/=2;
	cout << cnt << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll X;
  cin >> X;
  for (int i = -200; i <= 200; i++) {
    for (int j = -200; j <= 200; j++) {
      if (pow(i, 5) - pow(j, 5) == X) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3992
N = int(input())
W = list(map(int, input().split()))
S1 = 0
S2 = sum(W)
min_S = 1000000000

for i in range(N):
    S1 += W[i]
    S2 -= W[i]
    min_S = min(min_S, abs(S2 - S1))

print(min_S)

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

// one-based numbering
template<class T> struct Fenwick {
    vector<T> bit; int N;
    Fenwick(int n) {
        N = n;
        bit.resize(n+1, 0);
    }
    void add(int a, T w) {
        for (int x = a; x <= N; x += x & -x) bit[x] = max(bit[x], w);
    }
    T max_range(int a) {
        T ret = 0;
        for (int x = a; x > 0; x -= x & -x) ret = max(ret, bit[x]);
        return ret;
    }
};

int main() {
    int n; cin >> n;
    vector<int> h(n);
    vector<long long> a(n);
    Fenwick<long long> f(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
        f.add(h[i], f.max_range(h[i]-1)+a[i]);
    }
    cout << f.max_range(n) << endl;
}

Measured memory_bytes: 4096
#include<stdio.h>

int A[1000000], n;

int main(){
  int i, q, key, sum = 0;

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

  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&key);
    if(binarySearch(key)){
      sum++;
    }
  }
  printf("%d\n",sum);

  return 0;
}

int binarySearch(int key){
  int left = 0;
  int right = n;
  int mid;
  while(left < right){
    mid = (left + right) / 2;
    if(key == A[mid]){
      return 1;
    }
    if(key > A[mid]){
      left = mid + 1;
    }
    else if(key < A[mid]){
      right = mid;
    }
  }
  return 0;
}
	

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

/*
最大値の最小化(今回の場合, 最長の最短化)は二分探索が使える典型問題.
全ての丸太を, 丸太の長さを表す数直線上のある点X以下の長さにするために必要な切る回数が
K以下であるかどうかを判定する問題.
今回は最大値を最小化するので, 数直線上において大きい側がok, 小さい側がngとなる.
(長さ0の丸太は切ることができない)
二分探索である長さXを取って, 全ての丸太について, それぞれ長さX以下にするためには
何回切る必要があるかを調べる((A[i]-1)/x). その合計がK以下かどうか判定.
基本的に, Xが大きい方が切る回数は減るので, 合計がK以上ならXを大きくするべき(left(ng)=X)だし,
Kかそれ以下ならもっと攻められるから小さくするべき(right(ok)=X)
そうやって探索範囲を半分にしていって, 最終的にleftとrightの差が1以下になったら終了.
最小の最大値を求めるので, rightの値を取る.
*/

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  
  // めぐる式二分探索法
  // ngは解が存在しない値, okは解が存在する値を設定すれば良いので, 今回の場合はそれぞれ0, 1e9でも良い
  int ng = 0, ok = 1e9;
  while (abs(ok - ng) > 1) {  // どちらが大きいか明白であればabsは要らない
    int mid = (ok + ng) / 2;
    
    ll count = 0;
    rep(i, N) count += abs(A.at(i) - 1) / mid;
    (count <= K ? ok : ng) = mid;
    
    /*
    // ラムダ式. [&]で既出の変数を関数内で使うことができる. }後の()は関数呼び出しの意
    auto check = [&] {
      ll count = 0;
      // 全ての丸太について, それぞれを長さmid以下にするために必要な切断回数を求め足し合わせる
      rep(i, N) count += (A[i] - 1) / mid;
      return count <= K;  // return true or false
    }() ? ok = mid : ng = mid;
    */
    
    /*
    上の処理は以下と同義
    auto check = [&] {処理};
    if (check(mid)) ok = mid;
    else ng = mid;
    */
  }
  
  // 最小の最大値ok(right)
  cout << ok << endl;
}

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




int main(){

  int mod=998244353;

  int n,k,a,b,l,r;
  

  cin>>n>>k;
  
  vector<ll> sum(n+1,0);
  vector<ll> ans(n+1,0);  
  vector<pair<int,int>> pair;

  rep(i,k){
      cin>>a>>b;
      pair.push_back(make_pair(a,b));
  }

  //sort(pair.begin(), pair.end());
  
  sum[0] = 0;
  sum[1] = 1;
  ans[1] = 1;
  
  for(int i = 2; i <= n; i++){
    
      rep(j,k){
          l = i - pair.at(j).second;
          r = i - pair.at(j).first;
          if(r < 0) continue;
          l = max(l , 1);
          
          ans[i] +=  sum[r]-sum[l-1];
          ans[i] %= mod;
      }
          sum[i] = (ans[i] + sum[i-1]) %mod;
          
  }
  
  //for(int x: sum) cout << x <<" ";
  
  if(ans[n]<0)ans[n]+=mod;
  cout<<ans[n]<<endl;
  
}

Measured memory_bytes: 6412
import java.util.Scanner;
 
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    if((A+B+C) == 17){
    System.out.println("YES");
    }
    else {
    System.out.println("NO");
    }
  }
}
 

Measured memory_bytes: 35620
#include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    
    int main(){
        int n;
        vector<int> v;
        
        cin >> n;
        int c;
        int ans = 0;
        for(int i = 0; i < n ; i++){
            cin >> c;
            v.push_back(c);
        }
        for(int i = 1; i < n - 1 ; i++){
            if(v[i] > v[i - 1] && v[i] < v[i + 1] ){
                ans += 1;
            }else if(v[i] < v[i - 1] && v[i] > v[i + 1] ){
                ans += 1;
            }
            
        }
        
        cout << ans << endl;
        
        return 0;
        
    }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String [] args)
	{
		int [] a= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		Scanner cin = new Scanner(System.in);
		int k=cin.nextInt();
		System.out.println(a[k-1]);
		cin.close();
	}
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>
#define imposs {cout<<"-1\n";return 0;}
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

//MOD//
const ll MOD = 1000000007;
struct big;
big ex(big a, ll tms);
typedef struct big{
  ll val;
  big():val(0){}
  big(ll val):val((val%MOD+MOD)%MOD){}
  big& operator += (const big& obj){ (val+=obj.val)%=MOD; return *this;}
  big& operator -= (const big& obj){ (val+=MOD-obj.val)%=MOD; return *this;}
  big& operator *= (const big& obj){ (val*=obj.val)%=MOD; return *this;}
  big& operator /= (const big& obj){ (val*=ex(obj,MOD-2).val)%=MOD; return *this;}
  big operator + (const big& obj)const{ return big(*this) += obj;}
  big operator - (const big& obj)const{ return big(*this) -= obj;}
  big operator * (const big& obj)const{ return big(*this) *= obj;}
  big operator / (const big& obj)const{ return big(*this) /= obj;}
  bool operator < (const big& obj)const{ return val < obj.val;}
  bool operator == (const big& obj)const{ return val == obj.val;}
} big;
istream& operator >> (istream& i, big& obj){ i>>obj.val; return i;}
ostream& operator << (ostream& o, const big& obj){ o<<obj.val; return o;}
big ex(big obj, ll tms){
  if(!tms) return 1;
  big ret = ex(obj, tms/2);
  ret *= ret;
  return (tms&1) ? ret*obj : ret;
}
//MOD//

big dp[1<<21];

int a[21][21];

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

  int N;
  cin >> N;
  rep(i,N)rep(j,N) cin >> a[i][j];

  dp[0] = 1;
  rep(i,1<<N) {
    int s = 0;//iのビット1の数
    rep(j,N) {
      int x = 1 << j;
      if (i&x) s++;
    }
    rep(j,N) {
      int x = 1 << j;
      if (i&x) {
        if (a[s-1][j]) {
          dp[i] += dp[i^x];
        }
      }
    }
  }
  big ans = dp[(1<<N)-1];
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 16640
//=template==================================================================//
// include
#include <vector>
#include <list>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

// namespace
using namespace std;

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

// typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long LL;

// conversion
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout<<x; return sout.str();}
//===========================================================================//

//=function prototype========================================================//

//===========================================================================//

//=variables=================================================================//
int a, b;
int diff; // 高さの差分
int n; // 埋もれた塔の数
int h; // 積もった雪の高さ
//===========================================================================//
int main(void)
{
  // Scan begin.
  cin >> a >> b;
  // Scan done.

  // Code begin.
  diff = b - a;
  n = diff -2;
  h = (n*(n+1)/2) + ((diff-1)-a);
  cout << h << endl;
  // Code done.

  return 0;
}

//=functions=================================================================//

//===========================================================================//

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE

const Int INF = 1e18;

Int dp[2][55][22];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;
  vector<string> ss(n);
  vector<Int> cs(n);
  for(Int i=0;i<n;i++) cin>>ss[i]>>cs[i];

  for(Int i=0;i<55;i++)
    for(Int j=0;j<22;j++)
      dp[0][i][j]=dp[1][i][j]=INF;

  Int ans=INF;
  using T = tuple<Int, Int, Int, Int>;

  priority_queue<T, vector<T>, greater<T>> pq;
  auto push=[&](Int LR,Int x,Int d,Int dist){
    // cout<<LR<<' '<<x<<' '<<d<<':'<<dist<<endl;
    if(dp[LR][x][d]<=dist) return;
    dp[LR][x][d]=dist;
    pq.emplace(dp[LR][x][d],LR,x,d);
  };

  auto palin=[&](string s){
    string t(s.rbegin(),s.rend());
    return s==t;
  };

  for(Int i=0;i<n;i++){
    if(palin(ss[i])){
      chmin(ans,cs[i]);
      continue;
    }

    Int len=ss[i].size();
    push(0,i,len,cs[i]);
    push(1,i,len,cs[i]);

    // center on a character
    for(Int c=0;c<len;c++){
      Int flg=1;
      Int L=c;
      Int R=len-(c+1);
      for(Int j=1;j<=min(L,R);j++)
        flg&=(ss[i][c-j]==ss[i][c+j]);
      if(flg) push(L<R,i,abs(L-R),cs[i]);
    }

    // center between characters
    for(Int c=1;c<len;c++){
      Int flg=1;
      Int L=c;
      Int R=len-c;
      for(Int j=1;j<=min(L,R);j++)
        flg&=(ss[i][c-j]==ss[i][c+j-1]);
      if(flg) push(L<R,i,abs(L-R),cs[i]);
    }
  }
  // exit(0);
  // cout<<"UKU"<<endl;

  while(!pq.empty()){
    auto [dist, LR, x, d] = pq.top();pq.pop();
    if(dp[LR][x][d]<dist) continue;

    for(Int i=0;i<n;i++){
      Int len=ss[i].size();
      if(LR==0){
        Int L=d;
        Int R=len;

        Int flg=1;
        for(Int j=0;j<min(L,R);j++)
          flg&=(ss[i][j]==ss[x][L-(j+1)]);

        if(flg){
          if(L==R) chmin(ans,dist+cs[i]);
          else push(L<R,(L<R?i:x),abs(L-R),dist+cs[i]);
        }
      }
      if(LR==1){
        Int L=len;
        Int R=d;

        Int flg=1;
        for(Int j=0;j<min(L,R);j++)
          flg&=(ss[i][L-(j+1)]==ss[x][ss[x].size()-R+j]);

        if(flg){
          if(L==R) chmin(ans,dist+cs[i]);
          else push(L<R,(L<R?x:i),abs(L-R),dist+cs[i]);
        }
      }
    }
  }

  if(ans==INF) ans=-1;
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[110000];
main(){
  //ll n,k,ans=0;
  //cin>>n;
  //rep(i,0,n)cin>>a[i];
  string  s,t;
  cin>>s>>t;
  cout<<t<<s;
  
}


Measured memory_bytes: 764
import java.util.Scanner;

class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String tapSequence = sc.next();
		sc.close();
		
		String[] sequenceArr = tapSequence.split("");
		
		boolean isEasy = true;
		
		for(int i = 0; i < sequenceArr.length ; i++) {
			String tap = sequenceArr[i];
			if((i + 1) %2 == 0) {
				if(tap.equals("R")) {
					isEasy = false;
					break;
				}
			}else {
				if(tap.equals("L")) {
					isEasy = false;
					break;
				}
			}
		}
		
		if(isEasy) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}		
	}

}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define RB rbegin()
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define MD 1000000007
#define PPF pop_front()
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;u.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C
V<LL>v;
V<LL>w,ab;
set<LL>uo;
map<LL,LL>u;
map<LL,LL>ww,cc,bc;
LL ar[500][500];
LL br[500][500];
LL cr[500][500];
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    while(tt--)
    {
        UOSMOY;
       for(i=0;i<5;i++)
       {
           cin>>o;
           if(o==0)
           {
               k=i+1;
           }
       }
       cout<<k<<endl;

    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 3656
#include<map>
#include<cmath>
#include<stack>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,a[105],ans,sum;
bool cmp(int x,int y){
	return x>y;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++){
    	if(i%2==0)ans+=a[i];
    	else sum+=a[i];
    }
    cout<<ans-sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 2000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll k;
ll a[5001];
bool dp[5001][5001];
bool dp2[5001][5001];
int cnt[5001];
ll sum2[5001];

bool func(int v){
	if(sum2[v+1]>=k)return false;
	memset(dp,false,sizeof(dp));
	memset(dp2,false,sizeof(dp2));
	dp[0][0]=true;
	dp2[0][0]=true;
	for(int i=0;i<n;i++){
		for(int j=0;j<k;j++){
			if(dp[i][j]){
				dp[i+1][j]=true;
				if(j+a[i]<k && i>v)dp[i+1][j+a[i]]=true;
			}
		}
	}
	for(int i=0;i<=v;i++){
		for(int j=0;j<k;j++){
			if(dp2[i][j]){
				dp2[i+1][j]=true;
				if(j+a[i]<k)dp2[i+1][j+a[i]]=true;
			}
		}
	}
	for(int j=k-1;j>=1;j--){
		if(dp2[v+1][j])dp2[v+1][j-1]=true;
	}
	for(int i=k-1;i>=1;i--){
		if(dp[n][i] && dp2[v+1][k-i])return false;
	}
	return true;
}

int main(void){
	scanf("%d%lld",&n,&k);
	ll sum=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		sum+=a[i];
		if(a[i]<k)cnt[a[i]]++;
		else cnt[k]++;
	}
	for(int i=0;i<k;i++){
		cnt[i+1]+=cnt[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		sum2[i+1]=sum2[i]+a[i];
	}
	if(sum<k){
		printf("%d\n",n);
		return 0;
	}
	if(a[0]>=k){
		printf("%d\n",0);
		return 0;
	}
	int l=-1,r=n;
	while(r-l>1){
		int mid=(l+r)/2;
		if(func(mid))l=mid;
		else r=mid;
	}
	printf("%d\n",l+1);
	return 0;
}

Measured memory_bytes: 49152
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

a,b = S()
num = int(a+b)
for i in range(1,1000):
    if i**2 == num:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 9888
#include <bits/stdc++.h>
#define li long long int
using namespace std;

int main() {
 li m;
 cin>>m;
 li ret=-1;
 li k=0;
 vector<bool>vis(m);
 li cur=0;
 for(k=0; ;k++){
    cur=((cur*10)+7)%m;
    if(vis[cur])break;
    vis[cur]=true;
    if(cur==0){
        ret=k+1;
        break;
    }
    
 }
 cout<<ret<<endl;
 return 0;
}


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

int main()
{
  int N,n,d,i;
  int dx[4]={-1,0,1,0};
  int dy[4]={0,1,0,-1};
  int x,X,y,Y;
  map< int, pair<int,int> > m;
  while(cin>>N,N){
    m.clear();
    m[0] = make_pair(0,0);
    x=X=y=Y=0;
    for(i=1;i<N;i++){
      cin>>n>>d;
      m[i] = make_pair(m[n].first+dx[d],m[n].second+dy[d]);
      if(m[i].first<x)x=m[i].first;
      if(m[i].first>X)X=m[i].first;
      if(m[i].second<y)y=m[i].second;
      if(m[i].second>Y)Y=m[i].second;
    }
    cout<<(X-x)+1<<" "<<(Y-y)+1<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    using namespace std;
    using ll = long long;
     
    int main() 
    {
     int a,b,c,d;
     cin >> a >> b >> c >> d;
     int syo1 = c/b;
     int amari1 = c%b;
     int syo2 = a/d;
     int amari2 = a%d;
     if(amari1 != 0) syo1++;
     if(amari2 != 0) syo2++;
     if(syo1 <= syo2){
      cout << "Yes" << endl;
     }else{
      cout << "No" << endl; 
     }
      
      return 0;
    }

Measured memory_bytes: 3624
use std::io::*;
use std::str::FromStr;

fn main() {
	let h: f32 = read();
	let a: f32 = read();
	
	let ans = (h/a).ceil() as i32;
	println!("{}",ans);
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}



Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <numeric>

int main() {
  int n;
  std::cin >> n;
  std::vector<int> primes = {19, 29, 59, 79, 89, 109, 139, 149, 179, 199, 229, 239, 269, 349, 359, 379, 389, 409, 419, 439, 449, 479, 499, 509, 569, 599, 619, 659, 709, 739, 769, 809, 829, 839, 859, 919, 929, 1009, 1019, 1039, 1049, 1069, 1109, 1129, 1229, 1249, 1259, 1279, 1289, 1319, 1399, 1409, 1429, 1439, 1459, 1489, 1499, 1549, 1559, 1579, 1609, 1619, 1669, 1699, 1709, 1759, 1789, 1879, 1889, 1949, 1979, 1999, 2029, 2039, 2069, 2089, 2099, 2129, 2179, 2239, 2269, 2309, 2339, 2389, 2399, 2459, 2539, 2549, 2579, 2609, 2659, 2689, 2699, 2719, 2729, 2749, 2789, 2819, 2879, 2909, 2939};
  for (int i = 0; i < n; ++i) {
    std::cout << primes[i] << (i == n-1 ? "\n" : " ");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main() {
 
  int a[3];
  bool flg = 0;
  int ans[4] ={0};
  while(cin >>a[0] >> a[1] >> a[2]) {
    
    sort(a,a+3);
 
    if(a[0]+a[1] <= a[2] ) flg = 1;
    if(flg == 1) continue;
 
     
    if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]) ans[0]++;
    else if(a[0]*a[0]+a[1]*a[1] < a[2]*a[2]) ans[1]++;
    else ans[2]++;
 
    ans[3]++;
 
  }
 
  cout <<ans[3]<<" "<<ans[0]<<" "<<ans[2]<<" "<< ans[1]<<endl;
  return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define pno return 0&puts("No")

long long int N, A, B;
char s[13];

int main(){
    cin >> A >> B;
    scanf("%s", s);
    N = strlen(s);
    if(N != A + B + 1)pno;
    for(int i = 0; i < A; ++i){
        if(s[i] == '-')pno;
    }
    if(s[A] != '-')pno;
    for(int i = A + 1; i <= A + B; ++i){
        if(s[i] == '-')pno;
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int a[n+1];
    for(int i = 0; i <= n; i++){
        a[i] = 0;
    }
    for(int i = 0; i < m; i++){
        int t;
        cin >> t;
        a[t] = 1;
    }
    int cost1 = 0;
    for(int i = 0; i <= x; i++){
        cost1 += a[i];
    }
    int cost2 = 0;
    for(int i = x; i <= n; i++){
        cost2 += a[i];
    }
    cout << min(cost1, cost2) << endl;
    return 0;
}


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

const int INF = 1001001001;
const int LIM_M = 10000;
const int LIM_N = 500;

int M, N;
int P[LIM_M + 10];
int C[LIM_N + 10], E[LIM_N + 10];

int PSum[LIM_M + 10];
int dp[LIM_M + 10];

int main() {
	int i, j;
	
	scanf("%d%d", &M, &N);
	for (i = 0; i < M; ++i) {
		scanf("%d", &P[i]);
	}
	for (j = 0; j < N; ++j) {
		scanf("%d%d", &C[j], &E[j]);
	}
	
	//	PSum[i] := maximum price for selling i manjus.
	sort(P, P + M, greater<int>());
	for (i = 0; i < M; ++i) {
		PSum[i + 1] = PSum[i] + P[i];
	}
	
	//	dp[i] := minimum expense for boxes to pack i manjus.
	//	invariant: dp[0] <= dp[1] <= ... <= dp[M].
	for (i = 0; i <= M; ++i) {
		dp[i] = INF;
	}
	dp[0] = 0;
	for (j = 0; j < N; ++j) {
		for (i = M; i >= 0; --i) {
			if (dp[i] > dp[max(i - C[j], 0)] + E[j]) {
				dp[i] = dp[max(i - C[j], 0)] + E[j];
			}
		}
	}
	
	int ans = 0;
	for (i = 0; i <= M; ++i) {
		if (ans < PSum[i] - dp[i]) {
			ans = PSum[i] - dp[i];
		}
	}
	printf("%d\n", ans);
	
	return 0;
}

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

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

    long long h;
    cin >> h;

    long long ans = 0, num = 1;
    while (h >= 1) {
        ans += num;
        num *= 2;
        h /= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <cstdlib>

int main() {
  int N;
  std::cin >> N;
  float sum = 0;
  float amount;
  std::string code;
  for(int i=0; i<N; i++) {
    std::cin>>amount>>code;
    if(code=="JPY") sum+=amount;
    else sum+= amount*380000.0;
  }
  std::cout<<sum;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int ans = 0;
        for(int i=1; i<=n; i++) {
            int num = sc.nextInt();
            if((i%2)==1&&(num%2)==1) {
                ans++;
            }
        }
        System.out.print(ans);
    }
}


Measured memory_bytes: 35684
n,m,x,y = map(int,input().split())	
a = list(map(int,input().split()))
b = list(map(int,input().split()))
k = 0
aa = max(a)
bb = min(b)

for i in range(x+1,y+1):
    if i > aa and i <= bb:
        k = 1
if k == 0:
    print('War')
else:
    print('No War')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int a[505], b[505], l[505], r[505], n, k;
bool ok(int m) {
	for(int i=0;i<n;i++)
		b[i] = a[i] % m;
	sort(b, b+n);
	l[0] = b[0];
	for(int i=1;i<n;i++)
		l[i] = l[i-1] + b[i];
	r[n] = 0;
	for(int i=n-1;i>=0;i--)
		r[i] = r[i+1] + m - b[i];
	int req = 0;
	for(int i=0;i<n;i++) 
		if(l[i] == r[i+1])
			req = l[i];
	return req <= k;
}

int32_t main()
{
	IO_OP;
	
	cin >> n >> k;
	for(int i=0;i<n;i++)
		cin >> a[i];
	int sm = accumulate(a, a+n, 0), ans = 0;
	for(int i=1;i*i<=sm;i++)
		if(sm % i == 0)
			for(int e:{i,sm/i})
				if(ok(e)) 
				ans = max(ans, e);
	cout << ans << endl;
}



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

typedef long long ll;
int N;
ll H[200010],A[200010];
vector<pair<ll,ll>> v;

#include <iostream>
#include <climits>
using namespace std;

const int MAX_N = 1<<18;
ll n,dat[2*MAX_N-1];

void init(int n_){
	n = 1;
	while(n<n_) n *= 2;
	for(int i=0;i<2*n-1;i++) dat[i] = 0;
}

ll update(int k, ll a){
	k += n-1;
	dat[k] = a;
	while(k>0){
		k = (k-1)/2;
		dat[k] = max(dat[k*2+1],dat[k*2+2]);
	}
}

ll query(int a,int b,int k,int l,int r){
	if(r<=a || b<=l) return 0;
	if(a<=l && r<=b) return dat[k];
	else{
		ll vl = query(a,b,k*2+1,l,(l+r)/2);
		ll vr = query(a,b,k*2+2,(l+r)/2,r);
		return max(vl,vr);
	}
}

int main(){
	cin >> N;
	init(N);
	for(int i=0;i<N;i++){
		cin >> H[i];
		H[i]--;
		v.push_back({H[i],i});
	}
	sort(v.begin(),v.end());
	for(int i=0;i<N;i++){
		cin >> A[H[i]];
	}
	ll ans = 0;
	for(int i=0;i<N;i++){
		ll value = query(0,v[i].second,0,0,n);
		ans = max(ans,value+A[v[i].first]);
		update(v[i].second,value+A[v[i].first]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 13040
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    string S;
    cin >> S;

    const auto cnt = count_if(ALL(S), [](char c) { return c == 'A'; });
    cout << (cnt == 1 || cnt == 2 ? "Yes" : "No")  << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int D()
{
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
const int N=2e5+9;

int arr[N],in[N];
int main(){
    string st;
    cin>>st;
    int sz=st.size();
    for(int i =0 ;i <sz;i++)
        if(st[i]==',')
        cout<<" ";
    else cout<<st[i];
    }

/**
bool ok(int val){
  int cntm=0,cntp=0;
  for(int i=0;i<n-val;i++)
  {
      cntm=0;cntp=0;
      for(int j=i;j<val;j++)
      {
      (arr[j]==1)?cntp++:cntm++;
      }
      if(cntp==cntm)
        break;
  }
  return cntp==cntm;
}
int binarySearch(){
  int low = 0, med, hi =n;
  while(low<hi){
    med = (low+hi+1)>>1;
    cout<<med<<" "<<hi<<" "<<low<<endl;
    if(ok(med))  low = med;
    else  hi = med-1;
  }
  return low;
}*/



/**
  int power1(int b, int p){               //O(p)
    if(!p)  return 1;
    return b*power1(b, p-1);
  }
  int power2(int b, int p){               //O(Log(p))
    if(!p)  return 1;
    int ret = power2(b, p/2);
    return (p&1 ? ret*ret*b : ret*ret);
  }
   int mul(int a, int b, int m){
      return (a%m * b%m) % m;
  }

*/


/**
void seive()
{
    bitset<N>iscomp;
    iscomp[0]=iscomp[1]=1;
    for(long long i=2; i<=N; ++i)
    {
        if(!iscomp[i])
        {
            a.push_back(i);
            for(long long j=i*i; j<=N; j+=i)
                iscomp[j]=1;
        }
    }
}
3
abc
abc
*/

    /**


    */


Measured memory_bytes: 256
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	int n; cin >> n; string s; cin >> s;
 
    int ans = 0;
 
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (s[i] == s[j]) continue;
            for (int k = j + 1; k < n; ++k) {
                if (s[j] != s[k] && s[i] != s[k] && j - i != k - j) ++ans;
            }
        }
    }
 
  cout << ans << endl;
	
}

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


#define lld long long 
#define mod 1000000007

lld dp[1001][1001];

string a[1001];

lld max(lld x,lld y)
{
	if(x>y)
		return x;
	return y;
}		
lld min(lld x,lld y)
{

	if(x<y)
		return x;
	return y;
}

lld power(lld x, lld y) 
{ 
    lld temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
} 

lld foo(lld i,lld j,lld n, lld m)
{
	
	lld ans=0;
	if(i==n || j==m)
	{
		return 0;
	}
	else if(dp[i][j]!=-1)
	{
		return dp[i][j];
	}
	/*else if(a[i][j]=='#')
	{
		//dp[i][j]=0;
		//return dp[i][j];
		dp[i][j]=0;
		return 0;
	}*/
	if(i==n-1 && j==m-1)
	{
		return 1;
	}
	if(a[i+1][j]=='.')
	{
		ans=ans+foo(i+1,j,n,m);
		
	}
	if(a[i][j+1]=='.')
	{
		ans=ans+foo(i,j+1,n,m);
	}
	dp[i][j]=ans%mod;
	//cout<<"ppp";
	return dp[i][j];
}

int main()
{
	lld n,m;
	cin>>n>>m;
	memset(dp,-1,sizeof(dp));
	for(lld i=0;i<n;i++)
	{
		cin>>a[i];
		
	}
	//cout<<a[2][2]<<"\n";
	cout<<foo(0,0,n,m)%mod<<"\n";
}

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

int main() {
  int n,l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i = 0; i < n; i++){
    cin >> s.at(i);
  }

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

  for(string i : s){
    cout << i;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(vector<vector<T>> x){cerr<<"\n{"; int f=x.size();for(int i=0;i<f;i++){cerr<<"("; int g=x[i].size(); for(auto j:x[i]){cerr<<j; (--g!=0)?cerr<<",":cerr<<"";}cerr<<")\n";}cerr<<"}";}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define trace(x...)
#endif
 
template<typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
 
template<typename... T>
void writ(T&&... args) {
    ((cout << args << " "), ...);
}
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define IINF (int)1e9
#define EPS 1e-9
/*
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    In the blazing sun I saw you
    In the shadows hiding from yourself
    When the lights are on I know you
    See you're grey from all the lies you tell 
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k; cin>>k;
    if(k%5!=0 && k&1){
        ll x=0; //This is mostly assumption based but I still need to prove it
        bool flag=true;
        ll ans=0;
        while(flag){//there is meant to be some condition here I don't know what
            x=((x*10)+7)%k;
            ans++;
            trace(ans,x);
            if(!x) flag=false;
        }
        cout<<ans<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}



Measured memory_bytes: 3660
an = list(map(int, open(0).read().split()[1:]))


def f(flg):
    accum = 0
    ret = 0
    for ai in an:
        accum += ai
        if flg:
            flg = False
            if accum <= 0:
                ret += -accum + 1
                accum = 1
        else:
            flg = True
            if 0 <= accum:
                ret += accum + 1
                accum = -1
    return ret


def main():
    print(min(f(False), f(True)))
    return


main()


Measured memory_bytes: 14156
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define N 500
int w[N][N];
char m[N][N+1];

int sol(int r,int c){
  rep(i,r){
    w[i][0]=m[i][0]=='.'?1:0;
    REP(j,1,c)w[i][j]=m[i][j]=='*'?0:w[i][j-1]+1;
  }
  int ret=0,mw;
  rep(j,c){
    rep(i,r){
      mw=w[i][j];
      ret=max(ret,mw);
      REP(k,i+1,r&&mw){
	mw=min(mw,w[k][j]);
	ret=max(ret,(k-i+1)*mw);
      }
    }
  }
  return ret;
}

main(){
  int r,c;
  while(cin>>r>>c && r){
    rep(i,r)cin>>m[i];
    cout<<sol(r,c)<<endl;
  }
}

Measured memory_bytes: 2092