akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

#define EPS 1e-7
#define INF 0x3f3f3f3f
#define ri register int
#define debug(s, i) (cout << "PARSING THROUGH " << s << " No." << i << endl)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

template <typename T> inline void chkmin(T &a, T b) {a < b ? a : a = b;}
template <typename T> inline void chkmax(T &a, T b) {a < b ? a = b : a;}

namespace fast_IO
{
	#define gets getchar
/*	inline char gets()
	{
		static char buf[100000], *p1, *p2;
		return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
	}*/

	inline int read_int()
	{
		register int ret = 0, f = 1; register char c = gets();
		while(c < '0' || c > '9') {if(c == '-') f = -1; c = gets();}
		while(c >= '0' && c <= '9') {ret = (ret << 1) + (ret << 3) + int(c - 48); c = gets();}
		return ret * f;
	}
	#undef gets
}using namespace fast_IO;

#define MAXN 100005
#define MOD 1000000007

int N;
ll bucket[30];
char s[MAXN];

inline void init()
{
	N = read_int();
	scanf("%s", s + 1);
	for(ri i = 1; i <= N; i++)
		bucket[s[i] - 'a']++;
	for(ri i = 0; i < 26; i++)
		bucket[i]++;
	ll ans = 1;
	for(ri i = 0; i < 26; i++)
		ans = ans * bucket[i] % MOD;
	printf("%lld\n", ans - 1);
}

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    if (H % h == 0 and W % w == 0) {
        cout << "No" << endl;
        return 0;
    }
    ll x = 1000;
    cout << "Yes" << endl;
    rep (i, H) {
        rep (j, W) {
            if (i % h == h - 1 and j % w == w - 1) {
                cout << -(h * w - 1) * x - 1 << " ";
            }
            else {
                cout << x << " ";
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 3640
import sys

def solve():
    n, m, d = map(int, input().split())
    DP = [0] * m
    if d == 0: add = n
    else: add = d * 2 + 2 * (n - 2 * d)
    print((m - 1) * add / pow(n, 2))
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 28020
using System;

public class AtCoderD
{
    static void Main()
    {
        int n;
        int k;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            k = int.Parse(words[1]);
        }

        decimal[] expects = new decimal[n];
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int i = 0; i < n; i++)
            {
                int num = int.Parse(words[i]);
                expects[i] = ((num * (num + 1)) / 2) / (decimal)num;
            }
        }

        decimal start = 0;
        for (int i = 0; i < k; i++)
        {
            start += expects[i];
        }
        decimal max = start;

        decimal sum = max;
        for (int i = 1; i < n - k + 1; i++)
        {
            sum -= expects[i - 1];
            sum += expects[i + k - 1];
            if (sum > max)
            {
                max = sum;
            }
        }

        Console.WriteLine(max);
    }
}

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

int main(){
    string s;
    cin >> s;
    vector<int> ans(s.length(), 0);
    vector<int> tmp_v;
    int new_right = 0;
    rep(i, s.length()) {
        if ( s[i] == 'R' && s[i+1] == 'L' ) {
            if ( i < s.length() - 1 ){
                ++ans[i];
                ++ans[i+1];
                for ( auto v : tmp_v ) {
                    if ( ( i - v ) % 2 == 0 ) {
                        ++ans[i];
                    }
                    else {
                        ++ans[i+1];
                    }
                }
                new_right = i + 1;
                ++i;
                tmp_v.clear();
            }
        }
        else if ( s[i] == 'R' ){
            tmp_v.push_back(i);
        }
        else {
            if ( ( i - new_right ) % 2 == 0 ) {
                ++ans[new_right];
            }
            else {
                ++ans[new_right-1];
            }
        }
//        bool flg = 0;
//        for ( auto ans_num : ans ) {
//            if ( flg ) cout << " ";
//            cout << ans_num;
//            flg = 1;
//        }
//        cout << endl;
    }
    bool flg = 0;
    for ( auto ans_num : ans ) {
        if ( flg ) cout << " ";
        cout << ans_num;
        flg = 1;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1528
N = int(input())
L = []

for i in range(N):
    l = []
    a,b = map(int, input().split())
    l.append(b)
    l.append(a)
    L.append(l)
L.sort()

count = 0
frag = 0
for i in range(N):
    count += L[i][1]
    if count > L[i][0]:
        print("No")
        frag = 1
        break
if frag == 0:
    print('Yes')

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

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<ll> a, b;

  ll t;
  rep(i,n*m) {
    cin >> t;
    a.push_back(t);
  }

  rep(i,m*l) {
    cin >> t;
    b.push_back(t);
  }

  rep(i,n) {
    rep(j,l) {
      ll s=0;
      rep(k,m) {
        s += a[i*m + k] * b[k*l + j];
      }
      cout << s;
      if(j==l-1) cout << endl;
      else cout << " ";
    }
  }

  return 0;
}



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

int main(){
    int n;
    cin>>n;
    string s, t;
    cin>>s>>t;
    string ans = "";
    for(int i= 0;i<n;i++){
        ans += s[i];
        ans += t[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
string s;
/**********************************/

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

    int len = s.size();
    REP(i, len) {
        FOR(j, i+1, len-1) {
            if(s[i] == s[j]) {
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
}


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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int gcd(int x, int y) {
    if (x % y == 0) {
        return y;
    }

    else {
        return gcd(y, x % y);
    }
}

int lcm(int x, int y) {
    int g = gcd(x, y);
    int l = x * y / g;
    return l;
}

int main() {
  ll N,M;
  cin>>N>>M;
  vector<ll> v(N);
  for(ll i = 0LL; i < N; i++) {
    ll a;
    cin>>a;
    v[i]=a/2LL;
  }
  ll cnt = 0LL;
  ll t = v[0];
  while(t%2LL==0LL){
    t/=2LL;
    cnt++;
  }
  ll G = 1LL;
  bool can = true;
  for(ll i = 0LL; i < N; i++){
    ll cntn = 0LL;
    ll s = v[i];
    while(s%2LL==0LL){
      s/=2LL;
      cntn++;
    }
    if(cntn!=cnt){
      can=false;
      break;
    }
    G=(G/gcd(G,v[i]))*v[i];
    if(G>M) {
      can = false;
      break;
    }
  }
  M=M/G;
  M=(M+1LL)/2LL;
  if(can) cout<<M<<endl;
  else cout<<0<<endl;
}

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

constexpr int INF = (1 << 28);

int min_dist[2000][2000];

int main()
{
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;

    int ans[2000] = {};

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            int d = j - i;
            d = min(d, abs(X - i) + 1 + abs(Y - j));
            ans[d]++;
        }
    }

    for (int d = 1; d < N; d++)
    {
        cout << ans[d] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int N;
char s[4002];
int r[4002],g[4002],b[4002];
long long int ans = 0;
int main(){
	scanf("%d",&N);
	scanf("%s",&s[1]);
	//printf("%d\n",N);
	//printf("%s\n",&s[1]);

	for(int i=N-1;i>0;i--){
		r[i] = r[i+1];
		g[i] = g[i+1];
		b[i] = b[i+1];

		if(s[i+1] == 'R')r[i] ++;
		else if (s[i+1] == 'G') g[i]++;
		else b[i]++;
	}
	//for(int i=1;i<=N;i++)printf("%d ",r[i]);
//		printf("\n");
	//for(int i=1;i<=N;i++)printf("%d ",g[i]);
//		printf("\n");
//	for(int i=1;i<=N;i++)printf("%d ",b[i]);
//		printf("\n");

	for(int i=1;i<=N-2;i++){
		for(int j=i+1;j<=N-1 ; j++){
			if(s[i] == s[j])continue;
			int x= j-i;
			
			

			if( (s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')){
				ans+=b[j]; 
				if(x+j <=N && s[x+j] == 'B') ans--;
			}
			else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')){
				ans+=g[j]; 
				if(x+j <=N && s[x+j] == 'G') ans--;
			}
			else {
				ans+=r[j]; 
				if(x+j<=N && s[x+j] == 'R') ans--;
			}
		//	printf("%d %d %d\n",i,j,ans);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3812
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
t = [0 for i in range(n+1)]
b = [1]
c = a[1]
d = 0
e=1
length = 0
first = 0
ans = 0


while t[d] < 1:
    t[d]=e
    b += [c]
    c = a[c]
    d = c
    e+=1

if d != 0:
    length = e - t[d]
    first = b.index(d)
if k <= first:
    ans = b[k]
elif d == 0:
    ans = 1
else:
    ans = b[(k - first) % length + first]
print(ans)


Measured memory_bytes: 108908
n,m = map(int, input().split())
h=list(map(int,input().split()))
li=[0]*n
 
for i in range(m):
        a,b=map(int, input().split())
        if h[a-1]>h[b-1]:
                li[b-1]+=1
        elif h[b-1]>h[a-1]:
                li[a-1]+=1
        else:
                li[a-1]+=1
                li[b-1]+=1

 
cnt=0
for i in range(n):
        if li[i]==0:
                cnt+=1

print(cnt)

Measured memory_bytes: 86316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  int n;
  cin >> n;
  vector<int> A(n),B(n),C(n);
  rep(i,n) cin >> A.at(i);
  rep(i,n) cin >> B.at(i);
  rep(i,n) cin >> C.at(i);
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  vector<int> D(n),E(n);
  rep(i,n){
    D.at(i) = B.end()-upper_bound(B.begin(),B.end(),A.at(i));
  }
  rep(i,n){
    E.at(i) = C.end()-upper_bound(C.begin(),C.end(),B.at(i));
  }
  ll ans = 0;
  int j = n-1;
  ll now = 0;
  for(int i=n-1;i>=0;--i){
    while(j > n-1-D.at(i)){
      now += E.at(j);
      -- j;
    }
    ans += now;
  }
  cout << ans << endl;
}
      
    

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> mp(h);
  rep(i, h) cin >> mp[i];
  rep(i, h){
    rep(j, w){
      if(mp[i][j] == '#') cout << "#";
      else{
        int cnt = 0;
        if(0 <= i-1){
          if(0 <= j-1 && mp[i-1][j-1] == '#') cnt++;
          if(mp[i-1][j] == '#') cnt++;
          if(j+1 < w && mp[i-1][j+1] == '#') cnt++;
        }
        if(0 <= j-1 && mp[i][j-1] == '#') cnt++;
        if(j+1 < w && mp[i][j+1] == '#') cnt++;
        if(i+1 < h){
          if(0 <= j-1 && mp[i+1][j-1] == '#') cnt++;
          if(mp[i+1][j] == '#') cnt++;
          if(j+1 < w && mp[i+1][j+1] == '#') cnt++;
        }
        cout << cnt;
      }
    }
    cout << endl;
  }
  return 0;
}
        
      
      
      
      
      
      
      
  

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;

int main(){
	
	priority_queue<int>Q;

	for (int i = 0; i < 10; i++){
		int tmp; cin >> tmp;
		Q.push(tmp);
	}

	for (int i = 0; i < 3; i++){
		cout << Q.top() << endl;
		Q.pop();
	}

	return 0;
}



Measured memory_bytes: 3072
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
//using
using namespace std;
/*using vi = vector<int>;
using vs = vector<string>;
using vc = vector<char>;*/
//define
#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
//グローバル変数宣言
int a=0,b=0,c=0;

signed main(){
    cin>>a>>b;
    a-=1;//+a
    b-=1;//b+
    if(b%a==0)cout<<b/a<<endl;
    else cout<<b/a+1<<endl;
}

Measured memory_bytes: 3620
/*
 *  author : Atul Anand   
 *  created on : Fri Apr 03 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int N = in.nextInt();
        int D = in.nextInt();
        println((int) Math.ceil((double) N/(1 + 2*D)));
        
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
#define crep(i, n) for(int i=1; i<=n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

//--------------------------



int main() {

  int n, total = 0;
  cin >> n;

  int a[21], b[21], c[21];
  for(int i=1; i<=n; ++i) cin >> a[i];
  for(int i=1; i<=n; ++i) cin >> b[i];
  for(int i=1; i<n; ++i) cin >> c[i];

  for(int i=1; i<=n; ++i) {
    total += b[a[i]];
    if(i>1&&a[i-1]+1==a[i]) {
      total += c[a[i-1]];
    }
  }

  cout << total << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    n, yen = map(int,input().split())
    x = 0
    y = 0
    z = 0
    for x in range(n+1):
        for y in range(n+1):
            z = n - x - y
            if z < 0:
                break
            if x * 10000 + y * 5000 + z * 1000 == yen:
                print(x,y,z)
                return

    print(-1,-1,-1)

if __name__ =='__main__':
    main()


Measured memory_bytes: 3060
import java.util.Scanner;

/**
 * Created by donamphuong on 25/09/2016.
 */
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int numStudents = input.nextInt();
        int A = input.nextInt();
        int B = input.nextInt();
        String students = input.next();

        int passed = 0;
        int oversea = 0;

        for(int i = 0; i < numStudents; i++) {
            char c = students.charAt(i);
            String answer = "No";

            if(c == 'b') {
                oversea += 1;
            }

            if((c == 'a' && passed < A+B)
                || (c == 'b' && passed < A+B && oversea<=B)) {
                answer = "Yes";
                passed++;
            }

            System.out.println(answer);
        }
    }
}


Measured memory_bytes: 23856
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

string S;

int sum[1000];

int main(){

	int N;

	cin>>N;

	cin>>S;

	int i;

	while(1){

		memset(sum,0,sizeof(sum));

		for(i=0;i<S.size();i++){
			if(S[i]=='('){sum[i]=-1;}
			else{sum[i]=1;}
		}

		for(i=1;i<S.size();i++){
			sum[i]+=sum[i-1];
		}

		int flag=0;

		for(i=0;i<S.size();i++){
			if(sum[i]>0){flag=1;}
			if(flag==0&&i==S.size()-1 && sum[i]!=0){
				flag=2;
			}
		}

		if(flag==0){break;}
		else if(flag==1){
			string add="(";
			S=add+S;
		}
		else{
			string add=")";
			S=S+add;
		}

	}
	cout<<S<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
void sorted_p(int a[],int n,int stage)
{

    if(stage == n)
    {
        vector<int> temp;
        for(int i=0;i<n;i++)
        {
            temp.push_back(a[i]);
        }
        v.push_back(temp);
          
    }
    for(int i=stage;i<n;i++)
    {
       
        int flag = a[i];
        for(int j=i;j>stage;j--)
        {
            a[j] = a[j-1];
        }
        a[stage] = flag;

        sorted_p(a,n,stage+1);

        
        flag = a[stage];
        for(int j=stage;j<i;j++)
        {
            a[j] = a[j+1];
        }
        a[i] = flag;

    }
}
int main()
{
    int n;
    cin>>n;
    int p[n];
    int q[n];
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>q[i];
    }
    int a[n];
    for(int i=0;i<n;i++)
    {
        a[i]=p[i];
    }
    sort(a,a+n);
        sorted_p(a,n,0);
        int x1,x2;
        int c1=0,c2=0;
        for(int i=0;i<v.size();i++)
        {
            
            for(int j=0;j<n;j++)
            {
                if(v[i][j]==p[j])
                {
                    c1++;
                }
            }
            if(c1==n)
            {
                x1=i;
            }
            for(int j=0;j<n;j++)
            {
                if(v[i][j]==q[j])
                {
                    c2++;
                }
            }
            if(c2==n)
            {
                x2=i;
            }
             c1=0,c2=0;

        }
        // for(int i=0;i<v.size();i++)
        // {
        //     for(int j=0;j<n;j++)
        //     {
        //         cout<<v[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }
        cout<<abs(x2-x1)<<endl;
    
}


Measured memory_bytes: 3256
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repositry is at "https://github.com/Loptall/prcn_lib"

/*
    青perfほしいよ〜！
*/

// from std...
use std::cmp::{
    max, min, Ordering,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::convert::TryInto;
use std::mem::swap;
use std::num::{NonZeroU32, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Index, IndexMut, Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,
    SubAssign,
};
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, multinomial, Integer};
use num_rational::Rational;
use num_traits::{clamp, one, pow, zero, Num, NumAssignOps, NumOps, One, Pow, Zero};
use permutohedron::Heap;
use proconio::{
    fastout, input, is_stdin_empty,
    marker::{Bytes, Chars, Isize1, Usize1},
};
use rand::random;

pub const MOD10E9_7: usize = 1000000007;
pub const MOD99_: usize = 998244353;
pub const MAX: usize = std::usize::MAX;
pub const PI: f64 = f64::consts::PI;
pub const ASCII_A: u8 = 65;

// code...
// #[fastout]
fn main() {
    input! {
        n: usize,
        x: Chars
    }

    // はじめ X の pop_count
    let mut p = 0usize;
    let x = x
        .iter()
        .map(|x| {
            if *x == '1' {
                p += 1;
                1u8
            } else {
                0u8
            }
        })
        .collect_vec();
    let p = p;

    let mut ans = vec![0usize; n];

    for b in 0..2 {
        let mut np = p;
        if b == 0 {
            np += 1;
        } else {
            if np == 0 {
                continue;
            }
            np -= 1;
        }
        let np = np;

        if np == 0 {
            continue;
        }

        let mut r = 0usize;
        for i in 0..n {
            r *= 2;
            r %= np;
            r += x[i] as usize;
        }

        let mut k = 1;
        for i in (0..n).rev() {
            if x[i] == b {
                let mut t = r;
                if b == 0 {
                    t += k;
                    t %= np;
                } else {
                    t += np - k;
                    t %= np;
                }
                ans[i] = f(t) + 1;
            }
            k *= 2;
            k %= np;
        }
    }

    for i in ans {
        println!("{}", i);
    }
}

fn f(n: usize) -> usize {
    if n == 0 {
        0
    } else {
        f(n % n.count_ones() as usize) + 1
    }
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)

typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#ifdef Rahul
# define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
# define error(...) 42;
#endif
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/
const int N = 5e5 + 42;
int fen[30][N];

void upd(int k, int i, int v) {
  for (; i < N; i += i & -i) fen[k][i] += v;
}
int get(int k, int i) {
  int res = 0;
  for (; i > 0; i -= i & -i) {
    res += fen[k][i];
  }
  return res;
}
int32_t main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int n, q;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; ++i) {
    upd(s[i] - 'a', i + 1, 1);
  }
  cin >> q;
  while (q--) {
    int t; cin >> t;
    if (t == 1) {
      int i; char c;
      cin >> i >> c;
      upd(s[i - 1] - 'a', i, -1);
      s[i - 1] = c;
      upd(s[i - 1] - 'a', i, +1);
    } else {
      int l, r;
      cin >> l >> r;
      int ans = 0;
      for (int i = 0; i < 26; ++i) {
        int cur = get(i, r) - get(i, l - 1);
        if (cur > 0) ++ans;
      }
      cout << ans << '\n';
    }
  }
}


Measured memory_bytes: 52124
def run():
    # sys.stdin.readline()
    import sys
    input = sys.stdin.readline
    r,c,k = map(int,input().split())
    t = [[0 for i in range(c)] for i in range(r)]
    for i in range(k):
        a,b,z = map(int,input().split())
        t[a-1][b-1] = z
    t = tuple(t)
    dp = [[[0 for i in range(c)]for i in range(r)]for i in range(4)]
    dp[0][0][0] = 0
    dp[1][0][0] = t[0][0]
    dp[2][0][0] = t[0][0]
    dp[3][0][0] = t[0][0]
    for i in range(r-1):
        dp[0][i+1][0] = dp[1][i][0]
        for j in range(1,4):
            dp[j][i+1][0] = dp[1][i][0]+t[i+1][0]
    for i in range(c-1):
        dp[0][0][i+1] = 0
        for j in range(1,4):
            dp[j][0][i+1] = max(dp[1][0][i],t[0][i+1])
        for j in range(2,4):
            dp[j][0][i+1] = max(dp[2][0][i],dp[1][0][i]+t[0][i+1])
        dp[3][0][i+1] = max(dp[3][0][i],dp[2][0][i]+t[0][i+1])
    for i in range(r-1):
        for j in range(c-1):
            u = max(dp[0][i+1][j],dp[3][i][j+1])
            for s in range(0,4):
                dp[s][i+1][j+1] =  u
            u = max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
            for s in range(1,4):
                dp[s][i+1][j+1] = u
            u = max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
            for s in range(2,4):
                dp[s][i+1][j+1] = u
            dp[3][i+1][j+1] = max(dp[2][i+1][j]+t[i+1][j+1],dp[3][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
    print(dp[3][r-1][c-1])

if __name__ == "__main__":
    run()

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), cnt(123456);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  int mx = 0;
  for (int i = 1; i <= 100000; i++) {
    mx = max(mx, cnt[i] + cnt[i - 1] + cnt[i + 1]);
  }
  mx = max(mx, cnt[0] + cnt[1]);
  printf("%d\n", mx);
  return 0;
}

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

using ll = long long;

int main() {
  // 入力
  int H, W;
  cin >> H >> W;
  int c[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> c[i][j];
    }
  }
  int a[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }

  // ワーシャルフロイド法
  for (int k = 0; k < 10; k++) { // 中継点
    for (int i = 0; i < 10; i++) { // 始点
      for (int j = 0; j < 10; j++) { // 終点
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  
  ll ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] == -1) continue;
      ans += c[a[i][j]][1];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
import math

a, b, h, m = map(int, input().split())

ho = (h+(m/60))*360/12
mi = m*360/60
diff = abs(ho - mi)

ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(diff)))
print(f'{ans:.19f}')

Measured memory_bytes: 9352
s = list(input())
len_s = len(s)
len_b = s.count('B')

b_index_list = []

for i in range(len_s):
    if s[i] == 'B':
        b_index_list.append(i)

b_index_list.reverse()
l0 = len_s - 1
cnt = 0

for b in b_index_list:
    cnt += l0 - b
    l0 -= 1

print(cnt)


Measured memory_bytes: 12836
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

int main() {
	int N;
	cin >> N;
	vector<int> P(N);
	rep(i, N) {
		cin >> P[i];
	}

	int m = 200000;
	int result = 0;
	rep(i, N) {
		int pi = P[i];
		if (m > pi) m = pi;

		if (m >= pi) result += 1;
	}	
	cout << result << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>
#include<regex>
#include<math.h>
#include<numeric>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}
bool cmp(pair<lli, lli> left, pair<lli, lli> right) {
	if (left.first != right.first)return left.first < right.first;
	else return left.second < right.second;
}

int main() {
	lli n, k, q;
	cin >> n >> k >> q;
	vector<lli> vec(n+1, 0);
	rep0(i,q){
		lli temp;
		cin >> temp;
		vec[temp]++;
	}
	rep1(i, n) {
		if (k <= q - vec[i])cout << "No" << '\n';
		else cout << "Yes" << '\n';
	}
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define sl set<ll>
#define vs vector<string>
#define vl vector<ll>
#define vi vector<int>
#define vpl vector<pair<ll,ll>>
#define pb push_back
#define PI 3.14159265358979323846
#define ll long long
#define ld long double
#define endl "\n"
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define repp(i,a,b) for (ll i = (a); i >= (b); i--)
#define rop(i,a,b)  for(ll i=(a); i>(b); i--)
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define tt long long t; cin>>t; while(t--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
const int maxn=1e5+100;


int main()
{
 ll n;
 cin>>n;
 if(n<=1000)cout<<abs(1000-n);
 else
 {
     while(n>1000)
     {
         n=n-1000;
     }
     cout<<abs(1000-n);
 }
 
}

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__);
#else
#define dbg(...) 
#endif

int main() {
	ios_base::sync_with_stdio(false);
	int n; cin >> n;
	n = n%10;
	if(n==0||n==1||n==6||n==8){
		cout << "pon" << endl;
	} else if(n==3){
		cout << "bon" << endl;
	} else {
		cout << "hon" << endl;
	}

	return 0;
}


Measured memory_bytes: 3640
n = int(input())
a = []
b = [] 
for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)

res = 0

for i in range(n):
    a[n-1-i] += res
    c = a[n-1-i]%b[n-1-i]
    if c != 0:
        res += b[n-1-i]-c

print(res)

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int m,n;
    cin >> n >> m;
    if(m == n)cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
    static boolean arr[];

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int arr[] = new int[n];
        for(int i=0;i<n;i++)arr[i]=s.nextInt();
        long min = Long.MAX_VALUE;
        for(int i=-100;i<=100;i++){
            long sum=0;
            for(int j=0;j<n;j++){
                sum+=Math.pow(arr[j]-i,2);
            }
            min = Math.min(min,sum);
        }
        System.out.println(min);

    }


}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25436
use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        h: usize,
        n: usize,
        magic: [(usize,usize);n]
    }

    // dp[x][y] 最初のx個を使ってyダメージ与える場合の消費魔力
    let mut dp = vec![vec![1_987_654_321; 20000 + 1]; n + 1];

    dp[0][0] = 0;

    for i in 1..n + 1 {
        let magic_index = i - 1;
        for j in 0..20001 {
            dp[i][j] = if j >= magic[magic_index].0 {
                cmp::min(
                    dp[i][j - magic[magic_index].0] + magic[magic_index].1,
                    dp[i - 1][j],
                )
            } else {
                dp[i - 1][j]
            }
        }
    }

    let mut ans = 1_987_654_321;
    for j in h..20001 {
        if ans > dp[n][j] {
            ans = dp[n][j];
        }
    }

    println!("{:?}", ans);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 178556
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
ll n;
cin>>n;
string s;
cin>>s;
ll cnt=0;
for(int i=1;i<s.size();i++){
    if(s.at(i)!=s.at(i-1)){
        cnt++;
    }
}
cout<<cnt+1<<endl;
}





Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

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

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

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

  cout << d[N / 2] - d[N / 2 - 1] << endl;
}

Measured memory_bytes: 640
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
LL n, m, ans=0,a[1000000]= {}, c[10000000] = {}, b[10000000] = {}, flag = 0, bb[10000000] = {};
string st[2];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	sort(b, b + n);
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	sort(c, c + n);
	LL sum = n;
	for (int i = n - 1; i >= 0; i--) {
		LL AA = sum, ff = 0;
		for (int j = sum - 1; j >= 0; j--) {
			if (c[j] == c[j - 1] && j > 0)ff++;
			if (b[i] < c[j])sum--;
			else {
				bb[i] = n - sum + bb[i + 1];
				break;
			}
			if (j == 0) {
				sum++;
				bb[i] = n + bb[i + 1];
			}
		}
	}

	sum = n;
	for (int i = n - 1; i >= 0; i--) {
		for (int j = sum - 1; j >= 0; j--) {
			if (a[i] < b[j])sum--;
			else break;
		}
		//cout << sum << endl;
		ans += bb[sum];
	}

	cout << ans << endl;
	return 0;
}
/*
6
2 3 6 14 53 159
6 9 58 79 84 323
2 50 79 288 383 2643

22*2+17+12+12+2
61
2,3,3,4,5,5
2,5,8,12,17,22
bb[1]=1,bb[0]=1+bb[0+1]

*/

Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    // dp[i][j] := i日目にjをした時の幸福度の最大値
    // j=0:A、j=1:B、j=2:C
    vector<vector<int>> dp(200000, vector<int>(3, -INF));
    //0日目は幸福度0
    for (int i = 0; i < 3; i++)
    {
        dp[0][i] = 0;
    }
    for (int i = 0; i < n; i++)
    {
        chmax(dp[i + 1][0], dp[i][1] + a[i]);
        chmax(dp[i + 1][0], dp[i][2] + a[i]);
        chmax(dp[i + 1][1], dp[i][0] + b[i]);
        chmax(dp[i + 1][1], dp[i][2] + b[i]);
        chmax(dp[i + 1][2], dp[i][0] + c[i]);
        chmax(dp[i + 1][2], dp[i][1] + c[i]);
    }
    int ans = dp[n][0];
    chmax(ans, max(dp[n][1], dp[n][2]));
    cout << ans << endl;
}

Measured memory_bytes: 12416