akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int n,x[30],y[30],r[30],c[30],cover[30];
char dp[1<<24];
vector<int> same_col[5];

int rec(int bit){
  if(dp[bit])return dp[bit];

  int res = 0;
  for(int i=0;i<4;i++){
    if(same_col[i].size()<2)continue;
    for(int j=0;j<(int)same_col[i].size();j++){
      for(int k=0;k<j;k++){
	const int a = *(same_col[i].begin()+j), b = *(same_col[i].begin()+k);
	if(a<=b)continue;
	if( (~bit)&(1<<a) && (~bit)&(1<<b) ){
	  if( (~bit)&cover[a] || (~bit)&cover[b])continue;
	  same_col[i].erase(same_col[i].begin()+j); same_col[i].erase(same_col[i].begin()+k);
	  res = max(res, rec(bit | (1<<a) | (1<<b))+2);
	  same_col[i].insert(same_col[i].begin()+k,b); same_col[i].insert(same_col[i].begin()+j,a);
	}
      }
    }
  }
  return dp[bit]=res;
}
  
int main(){
  while(cin >> n, n){
    for(int i=0;i<n;i++)cin >> x[i] >> y[i] >> r[i] >> c[i];
    for(int i=0;i<4;i++)same_col[i].clear();

    for(int i=0;i<n;i++){
      same_col[c[i]-1].push_back(i);
      cover[i] = 0;
      for(int j=0;j<i;j++){
	if( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) < (r[i]+r[j])*(r[i]+r[j]) ){
	  cover[i] |= 1<<j;
	}
      }
    }

    memset(dp,0,sizeof(dp));
    cout << rec(0) << endl;
  }	  
}

Measured memory_bytes: 17600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+6;
const ll inf=1e14;
int n,a[N];
ll b[N];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<=n;i++) scanf("%d",&a[i]);
    b[0]=1-a[0];
    if(b[0]<0)
    {
        printf("-1\n");return 0;
    }
    for(int i=1;i<=n;i++)
    {
        b[i]=b[i-1]*2-a[i];
        b[i]=min(b[i],inf);
        if(b[i]<0)
        {
            printf("-1\n");return 0;
        }
    }
    ll ans=a[n],sum=a[n];
    for(int i=n-1;i>=0;i--)
    {
        if(sum>b[i])
        {
            ll k=sum-b[i];
            if(k>sum/2)
            {
                printf("-1\n");return 0;
            }
        }
        sum=min(sum,b[i])+a[i];
        ans+=sum;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 4932
#include <iostream>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
#define pb push_back
#define sp " "
#define ff first
#define ss second
//               When something is important enough, you do it even if the odds are not in your favor.

int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    /*/#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      int k,a,b;cin>>k>>a>>b;
      int d=a/k;
      int c=d*k+k;
      if((a<=c&&c<=b)||(a%k==0)||(b%k==0)) cout<<"OK";
      else cout<<"NG";
    }
    return 0;
}

Measured memory_bytes: 3108
import bisect #二分探索を用いて、ソートされた配列に対して、順序を考慮してある値を挿入できる
INF = 10**18

a,b,q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [int(input()) for _ in range(q)]
s = [-INF] + s + [INF]
t = [-INF] + t + [INF]

for i in x:
    index_s = bisect.bisect_left(s, i)
    #right_s = bisect.bisect_right(s, x)
    index_t = bisect.bisect_left(t, i)
    #right_t = bisect.bisect_right(t, x)
    l_s = s[index_s-1]
    r_s = s[index_s-0]
    l_t = t[index_t-1]
    r_t = t[index_t-0]
    ret = INF
    for ss in [l_s,r_s]:
        for tt in [l_t,r_t]:
            d1 = abs(ss-i) + abs(tt-ss)
            d2 = abs(tt-i) + abs(ss-tt)
            ret = min(d1,d2,ret)
    print(ret)

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

using namespace std;

using ll = long long;

int main()
{
	int n, m; cin >> n >> m;
	vector<pair<int, int>> lr(m);
	for (auto &p : lr)
		cin >> p.first >> p.second;
	pair<int, int> p = accumulate(lr.begin(), lr.end(), pair<int, int>(0, n), [](pair<int, int> a, pair<int, int> b) { return pair<int, int>(a.first > b.first ? a.first : b.first, a.second < b.second ? a.second : b.second);});
	cout << (p.first > p.second ? 0 : p.second - p.first + 1);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int ans = 0;
		for(int i=0;i<s.length();i++) {
			String a = s.substring(i,i+1);
			if(a.equals("A")) {
	//			System.out.println(i);
				ans += i;
				break;
			}
		}
		for(int i=s.length()-1;i>=0;i--) {
			String z = s.substring(i,i+1);
			if(z.equals("Z")) {
	//			System.out.println(i);
				ans -= i;
				break;
			}
		}
		System.out.println(-ans+1);
	}

}

Measured memory_bytes: 33616
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        List<Integer> numbers = new ArrayList<>();
        boolean[] hits = new boolean[9];

        for(int i = 0 ; i < 9 ; i++){
            numbers.add(scanner.nextInt());
            hits[i] = false;
        }

        int n = scanner.nextInt();
        boolean isBingo = false;
        for(int i = 0 ; i < n ; i++){
            int b = scanner.nextInt();
            if(numbers.contains(b)){
                int idx = numbers.indexOf(b);
                hits[idx] = true;
            }

            if(i % 5 == 0){
                isBingo = isBingo(hits);
                if(isBingo){
                    break;
                }
            }
        }
        if(!isBingo){
            isBingo = isBingo(hits);
        }

        System.out.println(isBingo ? "Yes" : "No");
    }

    private static boolean isBingo(boolean[] hits) {
        //012,345,678
        for(int i = 0 ; i < 3 ; i++){
            if(hits[3 * i + 0] && hits[3 * i + 1] && hits[3 * i + 2]){
                return true;
            }
        }
        //036, 147, 258
        for(int i = 0 ; i < 3 ; i++){
            if(hits[i + 0] && hits[i + 3] && hits[i + 6]){
                return true;
            }
        }
        //048
        if(hits[0] && hits[4] && hits[8]){
            return true;
        }
        //246
        if(hits[2] && hits[4] && hits[6]){
            return true;
        }
        return false;
    }
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL A,B,N;cin >> A >> B >> N;
    LL x;
    if(B-1 > N)x = N;
    else x = B-1;
    double t = A*x/B;
    LL ans = t;
    cout << ans << endl;
}

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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main()
{
    fast;
    int x;
    cin>>x;
    int a,b;
    int p,q;
    for(int i=1;i<=800;i++)
    {
        for(int j=-800;j<=800;j++)
        {
            a=power(i,(int)5);
            b=power(j,(int)5);
            if(a-b==x)
            {
              p=i;
              q=j;
             break;
             }
        }
        if(a-b==x)
         break;
    }
    cout<<p<<" "<<q<<"\n";
      return 0;
}


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

int main(void) {
    int a,b;
    cin>>a>>b;
    int k = (a+b)/2;
    if(abs(a-k) != abs(b-k)) {
        printf("IMPOSSIBLE\n");
    } else {
        printf("%d\n", k);
    }
    return 0;
}


Measured memory_bytes: 256
h , w , k = map(int, input().split())
c = [input() for i in range(h)]

s1 = [bin(x)[2:].zfill(h) for x in range(2**h)]
s2 = [bin(x)[2:].zfill(w) for x in range(2**w)]
ans=0
for i in s1:
    for j in s2:
        ans1=0
        for x in range(h):
            for y in range(w):
                if i[x]!='0' and j[y]!='0' and c[x][y]=='#':
                    ans1+=1
        if ans1==k:
            ans+=1
print(ans)


Measured memory_bytes: 9200
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
const int NMAX = 14, INF = 800;

int n;
vector<string> city(14);
int dist[NMAX][NMAX], dp[1 << NMAX][NMAX];

void remove_small_city() {
  int n_ = n;
  for (int i = n - 1; i >= 0; i--) {
    REP(j, n) {
      if (i == j) continue;
      if (city[j].find(city[i]) != string::npos) {
        city[i] = "";
        n_--;
        break;
      }
    }
  }
  for (int i = 0, index = 0; i < n; i++) {
    if (city[i] != "") {
      city[index] = city[i];
      index++;
    }
  }

/*  cout << "n=" << n_ << endl;
  REP(i, n) {
    cout << city[i] << endl;
  }*/
  n = n_;
}

int rec(int S, int v) {
  if (dp[S][v] >= 0) {
    return dp[S][v];
  }

  int res = INF;
  for (int u = 0; u < n; u++) {
    if (!(S >> u & 1)) {
      res = min(res, rec(S | 1 << u, u) + dist[v][u]);
    }
  }
  return dp[S][v] = res;
}

int concat_score(int i, int j) {
  int l1 = city[i].size();
  int l2 = city[j].size();
  int ans = min(l1, l2);
  while (city[i].substr(l1 - ans) != city[j].substr(0, ans)) {
    ans--;
  }
  return ans;
}

void map_to_graph() {
  remove_small_city();
  REP(i, n) REP(j, n) {
    if (i == j) continue;
    dist[i][j] = city[j].size() - concat_score(i, j);
  }
}

int solve() {
  int res = INF;
  for (int goal = 0; goal < n; goal++) {
    memset(dp, -1, sizeof(dp));
    REP(i, n) {
      dp[(1 << n) - 1][i] = 0;
    }
    int distance = rec(0, goal);
    int candidate = distance + city[goal].size();
    /*cout << "res=" << res << " cand=" << 
      distance << "+" << city[goal].size() << endl;
*/
    res = min(res, candidate);
  }
  return res;
}

int main() {
  while (cin >> n and n) {
    REP(i, n) {
      cin >> city[i];
    }
    map_to_graph();
    cout << solve() << endl;
  }
}

Measured memory_bytes: 2124
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N;
int V[20];
int C[20];
int diff[20];

int main(){
    cin>>N;
    rep(i,N) cin>>V[i];
    rep(i,N) cin>>C[i];
    rep(i,N) diff[i]=-(V[i]-C[i]);

    sort(diff,diff+N);

    int ans=0;
    rep(i,N){
        if(diff[i]<0){
            ans+=diff[i];
        }else{
            break;
        }
    }
    ans*=-1;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define rep(i, a) for (int i = 0; i < (a); i++)
#define repd(i, a) for (int i = (a)-1; i >= 0; i--)
#define reps(i, a, j) for (int i = (j); i < (a); i++)
#define deb(x) cout << #x << " " << x << endl;
#define debs(x) cout << #x << " " << x << " ";
#define deba(x) for (auto _i:x) cout << _i << " "; cout << endl;
#define ms(a) memset(a,0,sizeof(a));
#define mp make_pair
#define eb emplace_back
#define pii pair < int , int >
#define all(a) a.begin(),a.end() 
//int power(int x,int p){if(p==0)return 1;if(p==1)return x;if(p%2)return x*power(x,p-1);int y=power(x,p/2);return y*y;}
/*

*/

void solve() {
    int n; cin >> n;
    int arr[n]; rep(i,n) cin >> arr[i];
    int dp[n+1][n+1];
    ms(dp);
    repd(i,n) {
        rep(j,n) {
            if (i > j) continue;
            if (i == j) {
                if ((n-1)%2 == 0) dp[i][j] = arr[i]; 
            }else {
                if ( (n-(j-i+1))%2 == 0) {
                    // maximize
                    dp[i][j] = max(arr[i] + dp[i+1][j], arr[j] + dp[i][j-1]);
                }else {
                    // minimize
                    dp[i][j] = min( dp[i+1][j] , dp[i][j-1]);
                }
            }
        }
    }
    int sum = 0;
    rep(i,n) sum += arr[i];
    cout << 2*dp[0][n-1] - sum << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t; t=1;
    while (t--) solve();
}





Measured memory_bytes: 74004
program main
  implicit none
  integer i,ans
  character(3) S,T
  read(*, *)S
  read(*, *)T
  !read(*, *) (L(i), i = 1,N)
  ans = 0
  do i = 1,3
    if (S(i:i) == T(i:i)) then
      ans = ans + 1
    endif
  enddo

  write(*, *) ans
end program main


Measured memory_bytes: 768
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    int n,m,x,y;
    cin >>n>>m>>x>>y;
    int x_max = -101, y_min = INF;
    
    rep(i,n) {
        int tmp;
        cin >> tmp;
        x_max = max(tmp,x_max);
    }
    x_max++;

    rep(i,m) {
        int tmp;
        cin >> tmp;
        y_min = min(tmp,y_min);
    }
    for(int z = x_max; z <= y_min; z++) {
        if(x<z && z <= y) { cout << "No War" << endl; return 0; } 
    }

    cout << "War" << endl; 

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;
const int MOD = 1000000007;
int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    vector<int> a(n); rep (i, n) cin >> a[i];
    vector<vector<ll> > dp (n + 1, vector<ll>(2 * k + 1));
    dp[0][k] = 1;

    rep (i, n) {
        rep (j, k + 1) {
            if (j == 0) {
                ll tmp = 0; rep (k, a[i] + 1) tmp += dp[i][k];
                dp[i + 1][0] = tmp % MOD;
            } else {
                dp[i + 1][j] = (MOD + (dp[i + 1][j - 1] - dp[i][j - 1] + dp[i][j + a[i]]) % MOD) % MOD;
            }
        }
    }
    rep (i, k + 1) {rep (j, n + 1) eprintf("%4lld", dp[j][i]); eprintf("\n");}
    cout << dp[n][0] << "\n";
    return 0;
}

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

const int MOD = 1000000007;

int main(){
	int n;
	scanf("%d", &n);
	long ans = 1;
	for(int i = 1; i <= n; i++) {
		ans = ans *  i % MOD;
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {

	long long int p = 100;
	long long int x;
	long int years = 0;

	cin >> x;

	while (1) {
		years++;
		if (p + p / 100 >= x) {
			cout << years << endl;
			break;
		}
		p = p + p / 100;
	}

	return 0;
}

Measured memory_bytes: 3620
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int A, B;
  char s;
  ci(A, s, B);
  s == '+' ? co(A + B) : co(A - B);
}

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

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        long N = sc.nextLong();

        int ans = Integer.MAX_VALUE;
        for (long A = 1; A <= Math.sqrt(N); ++A) {
            if (N % A != 0) {
                continue;
            }
            long B = N / A;
            ans = Math.min(ans, F(A, B));
        }
        _out.println(ans);
    }
    private Map<Integer, Integer> primeFactorization(long n) {
        return null;
    }
    private int F(long a, long b) {
        return Math.max(String.valueOf(a).length(), String.valueOf(b).length());
    }
    private static List<Integer> primeList;
    private static void makePrimeList(int n) {
        List<Integer> searchList = new ArrayList<>();
        for (int i = 2; i <= n; ++i) {
            searchList.add(i);
        }
        primeList = new ArrayList<>(n);

        do {
            int prime = searchList.remove(0);
            primeList.add(prime);
            int i = 2;
            while (prime * i <= n) {
                searchList.remove((Integer)(prime * i));
                ++i;
            }
        } while (searchList.size() > 0 && searchList.get(0) <= Math.sqrt(n));
        primeList.addAll(searchList);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC092C - Traveling Plan
  // cost[i]:Ai地点に到着するまでに要するコスト
  // cost[i+1]-cost[i-1]でAi地点を取りやめたことで浮くコストを計算
  // abs(A[i+1]-A[i-1])でAi-1地点からAi+1地点に行くコストを足してやる
  int N; cin >> N;
  vector<int> A(N+2, 0); // スタートとゴール地点の座標0も追加する
  for(int i = 1; i <= N; i++){
    cin >> A[i];
  }

  vector<int> cost(N+2, 0);
  for(int i = 1; i <= N+1; i++){
    cost[i] = abs(A[i] - A[i-1]) + cost[i-1];
  }

  for(int i = 1; i <= N; i++){
    cout << cost[N+1] - (cost[i+1]-cost[i-1]) + abs(A[i+1] - A[i-1]) << endl;
  }
}

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

int dp[100005];

int main(){
    int n; cin>>n;
    vector<int> h(n);
    for(int i=0;i<n;i++) cin>>h[i];

    dp[2]=abs(h[1]-h[0]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(h[i-2]-h[i-1]),dp[i-2]+abs(h[i-3]-h[i-1]));
    }
    cout<<dp[n]<<endl;
}

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

#define INF 1LL << 60
#define MOD 1000000007;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, b, e) for (int i = b; i <= e; i++)

const int nMax = 3005;
int N;
double p[nMax];
double dp[nMax][nMax];

double solve() {
    dp[0][0] = 1.0;
    REPP(i, 1, N) {
        REPP(j, 0, N) {
            if (j == 0) {
                dp[i][j] = dp[i-1][j] * (1 - p[i-1]);
            } else {
                dp[i][j] = dp[i-1][j-1] * p[i-1] + dp[i-1][j] * (1 - p[i-1]);
            }
        }
    }
    double sum = 0;
    REPP(j, 0, N) {
        if (j > N/2) {
            sum += dp[N][j];
        }
    }
    return sum;
}

int main() {
    cin >> N;
    REP(i, N) cin >> p[i];

    cout << setprecision(10) << solve() << endl;
    return 0;
}

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

int main()
{
    const string Yes="Yes";
    const string No="No";
    int N;
    int i,j;
    int flag[1000],len=0;
    for(i=1;i<=9;i++)
        for(j=i;j<=9;j++)
            flag[len++]=i*j;
    cin>>N;
    for(i=0;i<len;i++)
        if(flag[i]==N)
        {
            cout<<Yes<<endl;
            break;
        }
    if(i==len)
        cout<<No<<endl;
    return 0;
}


Measured memory_bytes: 256
N,Q = list(map(int,input().split()))
s = input()
lis=[0]*N
 
count = 0
for i in range(1,len(s)):
    if s[i-1] == 'A' and s[i] == 'C':
        count +=1
    lis[i]+=count
for i in range(Q):
    l,r = list(map(int,input().split()))
    print(lis[r-1]-lis[l-1])


Measured memory_bytes: 12912
#include <iostream>
#include <algorithm>
using namespace std;
int a[10];
int main (void){
	int n;cin>>n;
	for(int i=0 ; i < n ;i++){
		cin>>a[i];
	}
	sort (a, a+n);
	a[n-1]/=2;
	int ans;
	for(int i=0;i<n;i++){
		ans+=a[i];
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+10;
const int mod=1e9+7;
string s;
ll a[maxn],c[maxn],cnt1[maxn],cnt2[maxn];
ll mi[maxn];
void init()
{
    mi[0]=1;
    for(int i=1;i<maxn;i++){
        mi[i]=(mi[i-1]*3)%mod;
    }
}
int main()
{
    cin>>s;
    init();
    int len=s.length();
    for(int i=0;i<len;i++){
        a[i]=a[i-1]+(s[i]=='A'?1:0);
        cnt1[i]=cnt1[i-1]+(s[i]=='?'?1:0);
    }
    for(int i=len-1;i>=0;i--){
        c[i]=c[i+1]+(s[i]=='C'?1:0);
        cnt2[i]=cnt2[i+1]+(s[i]=='?'?1:0);
    }
    ll ans=0;
    for(int i=1;i<len-1;i++){
        if(s[i]=='B'||s[i]=='?'){
            int l=i-1,r=i+1;
            ans=(ans+a[l]*c[r]%mod*mi[cnt1[l]+cnt2[r]]%mod)%mod;
            ans=(ans+a[l]*cnt2[r]%mod*mi[cnt1[l]+cnt2[r]-1]%mod)%mod;
            ans=(ans+c[r]*cnt1[l]%mod*mi[cnt1[l]+cnt2[r]-1]%mod)%mod;
            ans=(ans+cnt1[l]*cnt2[r]%mod*mi[cnt1[l]+cnt2[r]-2]%mod)%mod;
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int a, b;

int main(void){
    
    scanf("%d %d", &a, &b);
    int num = b - a;
    
    int sum = 0;
    for(int i = 1; i < num; ++i) sum += i;
    printf("%d\n", sum - a);
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	class Point{
		int y, x;
		Point(int _y, int _x){
			this.y = _y;
			this.x = _x;
		}
	}

	class Gravity{
		double x, weight;
		Gravity(double _x, double _w){
			this.x = _x;
			this.weight = _w;
		}
		Gravity add(Gravity a){
			double nw = this.weight + a.weight;
			double nx = (this.x * this.weight + a.x * a.weight)/nw;
			return new Gravity(nx,nw);
		}
	}

	char[][] tmpboard;
	int[][] board;
	int[] dy = {-1,0,0,1};
	int[] dx = {0,1,-1,0};
	double EPS = 1e-7;
	Point[] over;
	Gravity tG;
	int MAX_P = 600;
	int W, H;
	int L, R;
	int Lcnt, Rcnt, Wcnt;

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			W = in.nextInt(); H = in.nextInt();
			if(W==0 && H==0) return ;
			tmpboard = new char[H][];
			for(int i=0; i<H; i++){
				tmpboard[i] = in.next().toCharArray();
			}
			System.out.println(solve()?"STABLE":"UNSTABLE");
		}
	}

	void dfs(int y, int x, int c){
		if(board[y][x] != c) return ;
		if(y==H-1 || board[y+1][x] == -1 ||  (board[y+1][x] > 0 && board[y+1][x] != c)){
			L = Math.min(L, x);
			R = Math.max(R, x+1);
		}
		board[y][x] = -2;
		tG = tG.add(new Gravity(x+0.5, 1));
		for(int k=0; k<4; k++){
			int ny = y + dy[k],
				nx = x + dx[k];
			if(0<=ny && ny<H && 0<=nx && nx<W){
				if(k == 0 && board[ny][nx] > 0 && board[ny][nx] != c){
					over[board[ny][nx]] = new Point(ny,nx);
				}
				else if(board[ny][nx] == c){
					dfs(ny,nx,c);
				}
			}
		}
	}

	Gravity rec(int y, int x){
		over = new Point[MAX_P];
		tG = new Gravity(0,0);
		L = Integer.MAX_VALUE; R = Integer.MIN_VALUE;
		dfs(y,x,board[y][x]);
		dfs2(y,x,-2,-1);
		Gravity myG = new Gravity(tG.x, tG.weight);
		Point[] tmp = over.clone();
		int left = L, right = R;
		for(int i=1; i<MAX_P; i++){
			if(tmp[i] != null){
				Gravity result = rec(tmp[i].y, tmp[i].x);
				if(result == null) return null;
				myG = myG.add(result);
			}
		}
		if(left + EPS <= myG.x && myG.x <= right - EPS){
			return myG;
		}
		else{
			return null;
		}
	}

	boolean solve(){
		init();
		for(int i=0; i<W; i++)if(board[H-1][i] != 0){
			return rec(H-1,i) != null;
		}
		return false;
	}

	void dfs2(int y, int x, int cur, int to){
		board[y][x] = to;
		for(int k=0; k<4; k++){
			int ny = y + dy[k],
				nx = x + dx[k];
			if(0<=ny && ny<H && 0<=nx && nx<W && board[ny][nx] == cur){
				dfs2(ny,nx,cur,to);
			}
		}
	}

	void init(){
		board = new int[H][W];
		for(int i=0; i<H; i++){
			for(int j=0; j<W; j++)if(tmpboard[i][j] != '.'){
				board[i][j] = (int)tmpboard[i][j] + 100000;
			}
		}
		int cnt = 1;
		for(int i=0; i<H; i++){
			for(int j=0; j<W; j++)if(board[i][j] >= 100000){
				dfs2(i,j,board[i][j],cnt);
				cnt++;
			}
		}
	}

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

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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  for (int s = 0; s < (1 << (N - 1)); s++){
    bitset<5> d(s);
    int sum=S.at(0)-'0';
    vector<char> vec(3);
    for(int i=0;i<3;i++){
      if(d.test(i)){
        sum+=S.at(3-i)-'0';
        vec.at(2-i)='+';
      }
      else{
        sum-=S.at(3-i)-'0';
        vec.at(2-i)='-';
      }
    }
    if(sum==7){
      cout<<S.at(0)<<vec.at(0)<<S.at(1)<<vec.at(1)<<S.at(2)<<vec.at(2)<<S.at(3)<<"=7"<<endl;
      return 0;
    }
    
  }
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define sz 200002
#define pb push_back
#define ff first
#define ln '\n'
#define ss second
#define ll long long
#define VEC vector<ll int>v
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}



int main()
{

string s;
cin>>s;
for(int i=0;i<s.size();i++)cout<<"x";
    return 0;
}




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

using namespace std;

int a[500000];
int dp[500000];

int main(){
	
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		dp[i]=INT_MAX;
	}
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=1;j<=k;j++){
			if(i+j<n) dp[j+i]=min(dp[i+j],dp[i]+abs(a[i]-a[i+j]));
		}
	//	if(i+1<n) dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
	//	if(i+2<n) dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]));
	}
	cout<<dp[n-1];
	
	return 0;
	
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)


int main()
{
	cin.tie( 0 ); ios::sync_with_stdio( false );
	ll n;cin>>n;
	vector<ll> v( n, 0 );
	REP(i,n) cin>>v[i];
	ll sum = 0;
	REP(i,n-1)if(i!=0)
	{
		if( v[i-1]<v[i]&&v[i]<v[i+1] ) ++sum;
		if( v[i-1]>v[i]&&v[i]>v[i+1] ) ++sum;
	}
	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll ch[3][3];
	for(ll i=0;i<3;i++){
		for(ll j=0;j<3;j++){
			cin>>ch[i][j];
		}
	}
	map<ll,ll>ch2;
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		ch2[now]++;
	}
	for(ll i=0;i<3;i++){
		vector<ll>cnt;
		for(ll j=0;j<3;j++){
			ll now=ch[i][j];
			cnt.push_back(now);
		}
		for(ll j=0;j<3;j++){
			if(ch2[cnt[j]]==0){
				break;
			}
			if(j==2){
				cout << "Yes";
				return 0;
			}
		}
	}
	for(ll i=0;i<3;i++){
		vector<ll>cnt;
		for(ll j=0;j<3;j++){
			ll now=ch[j][i];
			cnt.push_back(now);
		}
		for(ll j=0;j<3;j++){
			if(ch2[cnt[j]]==0){
				break;
			}
			if(j==2){
				cout << "Yes";
				return 0;
			}
		}
	}
	if(ch2[ch[0][0]]==1&&ch2[ch[1][1]]==1&&ch2[ch[2][2]]==1){
		cout << "Yes";
		return 0;
	}
	if(ch2[ch[2][0]]==1&&ch2[ch[1][1]]==1&&ch2[ch[2][0]]==1){
		cout << "Yes";
		return 0;
	}	
	cout << "No";
	// your code goes here
	return 0;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
	static class Player{
		int num , group;
		double time;
		public Player(){}
		public Player(int g,int n,double t){
			group = g;
			num = n;
			time = t;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		LinkedList<Player> list = new LinkedList<Player>();
		Player[] g1 , g2 , g3;
		Player pl = new Player();
		for( int i = 0; i < 24; i++ ) {
			int g = (i+1) / 8;
			int n = sc.nextInt();
			double t = sc.nextDouble();
			Player p = new Player(g,n,t);
			list.add(p);
		}
		Player win , swin;
		for ( int i = 0; i < 3; i++ ) {
			win = list.get(6*i); swin = win;
			for ( int j = 0; j < 8; j++ ) {
				if ( win.time > list.get(6*i+j).time ) {
					swin = win;
					win = list.get(6*i+j);
				} else if ( swin.time > list.get(6*i+j).time )
					swin = list.get(6*i+j);
			}
			System.out.println(win.num+" "+win.time);
			System.out.println(swin.num+" "+swin.time);
			list.remove(win); list.remove(swin);
		}
		win = list.get(0); swin = list.get(0);
		for ( int i = 1; i < list.size(); i++) {
			if ( win.time > list.get(i).time ) {
				swin = win;
				win = list.get(i);
			} else if ( swin.time > list.get(i).time )
				swin = list.get(i);
		}
		System.out.println(win.num+" "+win.time);
		System.out.println(swin.num+" "+swin.time);
	}
}

Measured memory_bytes: 0
#include<stdio.h>
typedef long long LL;
const int e[40]={0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,
                 5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8};
LL IN(void)
{
  LL x=0;short f=0,c=getchar();
  while(c<48||c>57)f^=c==45,c=getchar();
  while(c>47&&c<58)x=x*10+c-48,c=getchar();
  return f?-x:x;
}
int main(void)
{
  int x=0;LL a=0,p=1,q=-1,N=IN();
  while(N%2==0){x++;N/=2;}a+=e[x],x=0;
  while(N%3==0){x++;N/=3;}a+=e[x];
  while(q*q<=N)
  {
    p+=6,q+=6;
    x=0;while(!(N%p)){x++;N/=p;}a+=e[x];
    x=0;while(!(N%q)){x++;N/=q;}a+=e[x];
  }
  if(N>1)a++;
  return printf("%lld\n",a),0;
}

Measured memory_bytes: 1604
#prag\
ma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

struct node{
	long long a,b;
}a[100001];

bool cmp(node a,node b){
	return a.b>b.b;
}

int main()
{
	ios::sync_with_stdio(false);
	long long n,h,maxv=0;
	cin>>n>>h;
	long long s=0;
	for(long long i=1;i<=n;i++) cin>>a[i].a>>a[i].b,maxv=max(maxv,a[i].a);
	sort(a+1,a+n+1,cmp);
	long long tot=0;
	for(long long i=1;i<=n;i++)
		if(a[i].b>maxv)
		{
			h-=a[i].b,tot++;
			if(h<=0) break;
		}
		else break;
	if(h<=0){
		cout<<tot;
		return 0;
	}
	if(h%maxv==0) cout<<h/maxv+tot;
	else cout<<h/maxv+1+tot;
}

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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="7767555555555555555";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
import java.util.Scanner;
public class Main {
	static int N;
	static int Y;
	static int A=-1,B=-1,C=-1;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N=sc.nextInt();
		Y=sc.nextInt();
		for(int i=0;i<=N;i++) {
			for(int j=0;j<=N-i;j++) {
				if(i*10000+j*5000+(N-i-j)*1000==Y) {
					A=i ;B=j;C=N-i-j;
				}
			}
		}
		System.out.println(A+" "+B+" "+C);
	}
}

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

ll n;
ll arr[1 << 20];
ll brr[1 << 20];
ll cnt ;

ll solve(ll index){
    if(index == n){
        for(ll i = 0;i < n;i++){
            if(brr[i]%2 == 0 ){
                cnt++;
                return 0;
            }
        }
        return 0;
    }
    for(ll i = -1;i <= 1;i++){
        brr[index] = arr[index]+i;
        solve(index+1);
    }
    return 0;
}
int main(){
    cin >> n;
    for(ll i = 0;i < n;i++){
        cin >> arr[i];
    }
    solve(0);
    cout << cnt;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}


int main(){
	ll n;
	cin>>n;
	vector<ll> a(n);
	
	rep(i,0,n) cin>>a[i];
	
	vector<ll> p(n);
	p[0] = a[0];
	rep(i,1,n) p[i] = p[i-1] + a[i];
	ll ans = 0;
	rep(i,0,n){
		ll temp = mod(a[i]*mod(p[n-1]-p[i]));
		ans = mod(ans+temp);
	}
	cout<<ans;
	
	
}

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

int main() {
    int a, b, t;
    cin >> a >> b >> t;
    int res = 0;
    for(int i = a; i <= t; i += a) {
        res += b;
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
import sys

def main():
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    s = SI()
    n = len(s)
    k = NI()

    def conv(x):
        return ord(x) - ord('a')

    bit = [0] * (n+1)

    def bit_add(i):
        while i <= n:
            bit[i] += 1
            i += i & (-i)

    def bit_sum(i):
        ret = 0
        while i > 0:
            ret += bit[i]
            i -= i & (-i)
        return ret

    z = [0] * n
    top = [-1] * 26
    nxt = [-1] * n
    bef = [-1] * 26
    for i in range(n):
        cv = conv(s[i])
        if bef[cv] >= 0:
            nxt[bef[cv]] = i
        bef[cv] = i
        if top[cv] < 0:
            top[cv] = i

    ans = []
    while k > 0:
        for i in range(26):
            if top[i] < 0: continue
            p = top[i]
            cost = p - bit_sum(p+1)
            if cost <= k:
                ans.append(chr(ord('a')+i))
                z[top[i]] = 1
                k -= cost
                top[i] = nxt[top[i]]
                bit_add(p+1)
                break
        else:
            break


    for i in range(n):
        if z[i] == 0: ans.append(s[i])
    print(*ans,sep='')


if __name__ == '__main__':
    main()


Measured memory_bytes: 21412
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=min(A)+min(B)
for _ in range(m):
    i,j,c=map(int,input().split())
    ans=min(ans, A[i-1]+B[j-1]-c)
print(ans)

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


int main(){
    int H, W;
    cin >> H >> W;
    char s[100][100];
    for(int i=0; i<=H+1; i++){
        for(int j=0; j<=W+1; j++){
            if(i==0 || i==H+1 || j==0 || j==W+1)
                s[i][j] = '.';
            else
                cin >> s[i][j];
        }
    }
    int dx[]={0,-1,1,0}, dy[]={-1,0,0,1};
    
    bool F=true;
    for(int i=0; i<=H+1; i++){
        for(int j=0; j<=W+1; j++){
            if(s[i][j]=='#'){
                bool flag=false;
                for(int k=0; k<4; k++){
                    if(s[i+dx[k]][j+dy[k]]=='#'){
                        flag=true;
                    }
                }
                if(!flag) F=false;
            }
        }
    }
    cout << (F?"Yes":"No") << endl;
}


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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
constexpr ll infl = 1ll<<60;
vector<pair<int,int>> E[405];
vector<int> dist(405);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(s.substr(0,n/2) == s.substr(n/2))cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



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

int main()
{
	int a[1001];
	int n,m;
	while(cin >> n >> m && n && m)
	{
		rep(i,n)
		{
			a[i] = 1;
		}

		int i = 0;
		int count = 0;
		int delete_count = 0;

		rep(i,n)
		{
			if(delete_count == n-1)
			{
				break;
			}

			if(a[i] == 1)
			{
				count++;

				if(count == m)
				{
					a[i] = 0;
					count = 0;
					delete_count++;
				}
			}

			if(i == n-1)
			{
				i = -1;
			}
		}

		
	
		rep(i,n)
		{
			if(a[i] == 1)
			{
				cout << i+1 << endl;
			}
		}
		
	}
	return 0;
}

Measured memory_bytes: 1164
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "bitset"

using namespace std;

//const long long int MOD = 998244353;
const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

vector<int> Prime(int num) {
	vector<int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= num; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (j < 5)continue;
			if (j*j > i) {
				break;
			}
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if (j < 5)continue;
			if (j*j > i + 2) {
				break;
			}
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

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

	cin >> N;
	vector<long long int>v(N);
	vector<long long int>cube;
	auto P = Prime(100000);
	bool flag = false;
	unordered_map<long long int, int>m;
	for (auto &i : v) {
		cin >> i;
	}
	for (auto i:P) {
		long long int box = i;
		box *= i;
		box *= i;
		if (box > 10000000000)break;
		cube.push_back(i*i*i);
	}
	for (auto i : v) {
		for (auto j : cube) {
			while (i%j == 0)i /= j;
		}
		if (i == 1) {
			flag = true;
			continue;
		}
		m[i]++;
	}
	vector<int>prime(100001);
	for (auto i : P)prime[i] = 1;
	int ans = 0;
	for (auto i : m) {
		vector<long long int>box;
		long long int bag = i.first;
		for (auto j : P) {
			if (bag%j == 0) {
				box.push_back(j);
				bag /= j;
				if (bag%j == 0) {
					bag /= j;
				}
			}
			else if (bag < j*j) {
				if (bag >= 100000)break;
				if (prime[bag]) {
					box.push_back(bag);
					bag = 1;
				}
				break;
			}
			if (bag == 1)break;
		}
		if (bag > 1) {
			ans += i.second;
			continue;
		}
		long long int num = 1;
		for (auto j : box) {
			num *= j;
			if (num > 10000000000)break;
			if (i.first % (j*j)) {
				num *= j;
				if (num > 10000000000)break;
			}
		}
		auto it = m.find(num);
		if (it == m.end()) {
			ans += i.second;
			continue;
		}
		if (num < i.first)continue;
		ans += max(i.second, (*it).second);
	}
	if (flag)ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5668
//プロ技のテストって裏あったの！？
#include<bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<(n); i++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define int long long
#define abs(a) llabs(a)
#define re(s) reverse((s).begin(),(s).end())
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;
using namespace std;

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    int x[1000010];

    cin>>n;
    n = n * 2;
    rep(i,n) cin>>x[i];
    sort(x,x+n);
    int cnt=0;

    for(int i=0; i<n; i++){
        bool a=false;
        if(i%2==0) a = true;
        if(a == true)
            cnt = cnt + x[i];
    }
    cout<<cnt<<'\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)

int main() {

string S; int Q; cin >> S >> Q;

deque<char> R;

rep(i,S.size()) R.push_back(S[i]);

int rev=1;//revは反転状態を表す数。%2==1なら反転していない

rep(i,Q){
  int T,F; char C;
  cin>>T;

  if(T==1){
    rev++; continue;
  }

  else{//T==2

    cin >> F >> C ;

    if(rev%2==F%2){
      R.push_front(C);
    }

    else{
      R.push_back(C);
    }

  }

}

if(rev%2==0){//反転がある場合は後ろから
  while(!R.empty()){
  cout << R.back();
  R.pop_back();
  }
}

else{//反転がない場合は前から
  while(!R.empty()){
  cout << R.front();
  R.pop_front();
  }
}


cout << endl;

return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
ll cal(int t)
{
    return t * (t - 1) / 2;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    ll n, res = 0;
    cin >> n;
    string s;
    map <string,ll> a;
    FOR(i, 1, n)
    {
        cin >> s;
        sort(s.begin(), s.end());
        a[s]++;
    }
    for(auto &i : a)
            res += (i.se * (i.se - 1) / 2);
    cout << res;
    return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

ll BIT[200010];

void update(ll idx,ll val)
{
    while(idx<200010)    
    {
        BIT[idx]=max(BIT[idx],val);
        idx+=(idx&(-idx));
    }
}


ll query(ll idx)
{
    ll ans=0;
    while(idx)    
    {
        ans=max(BIT[idx],ans);
        idx-=(idx&(-idx));
    }
    return ans;
}


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

    memset(BIT,0,sizeof(BIT));
    ll n,val;
    cin>>n;
    ll height[n];
    ll beauty[n];
    for(ll i=0;i<n;i++)
    {
        cin>>height[i];
    }
    for(ll i=0;i<n;i++)
    {
        cin>>beauty[i];
    }
    ll ans=NEGINF;
    for(ll i=0;i<n;i++)
    {
        val=query(height[i]);
        val+=beauty[i];
        ans=max(ans,val);
        update(height[i],val);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4992