akhauriyash/Code-Regression huggingface dataset:
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans=0
a=[0]*(n+1)
b=[0]*(m+1)

for i in range(n):
    a[i+1] = A[i] + a[i]
for i in range(m):
    b[i+1] = B[i] + b[i]

j = m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k -a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47368
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    int X, n;
    cin >> X >> n;
    vector<bool> ex(102);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        ex[a] = true;
    }
    int best = 1000;
    int ans;
    for(int i = 0; i <= 101; ++i){
        if(ex[i] == false){
            if(abs(i - X) < best){
                best = abs(i - X);
                ans = i;
            }
        }
    }
    cout << ans << endl;
}
int main(int argv, char **argc){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    t  = 1;
    while(t--)
        solve();

}


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

struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       if(par[x]>par[y]){
           par[y]+=par[x];
           par[x]=y;
       }
       else{
           par[x]+=par[y];
           par[y]=x;
       }
       return true;
   }
 
   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};

int main(){
  int n,m;
  cin >> n >> m;
  UnionFind uf(n+m);
  rep(i,n){
    int k;
    cin >> k;
    rep(j,k){
      int x;
      cin >> x;
      x--;
      uf.unite(n+x,i);
    }
  }
  rep(i,n){
    if(uf.find(0)!=uf.find(i)){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
return 0;}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= n - i; j++)
		{
			for (int k = 0; k <= (n - i - j); k++)
			{
				if (i + j + k == n && 10000 * i + 5000 * j + 1000 * k == y)
				{
					cout << i << " " << j << " " << k << endl;
					return 0;
				}
			}
		}
	}

	for (int i = 0; i < 3; i++)
	{
		cout << -1 << (i == 2 ? "" : " ");
	}

	cout << endl;
}

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

int main() {
    cpp_int h, w;
    cin >> h >> w;

    cpp_int tmp = h * w;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
    }
    else if (h % 2 == 0 || w % 2 == 0) {
        cout << tmp/2 << endl;
    }
    else {
        cout << tmp/2 + 1 << endl;
    }
}


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

vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};

int main() {
  int x, y;
  cin >> x >> y;
  vector<string> canvas(x);
  for (auto &e : canvas) cin >> e; 
  
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      if (canvas[i][j] != '#') continue;
      bool b = true;
      
      for (int k = 0; k < 4; k++) {
        int X = i + dx[k];
        int Y = j + dy[k];
        if (X < 0 || X >= x || Y < 0 || Y >= y) continue;
        if (canvas[X][Y] == '#') {
          b = false;
          break;
        }
      }
      
      if (b) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>

int n;
std::unordered_map<long long,int> cnt;
int main(){
  std::cin>>n;
  for(int i=0;i<n;++i){
    long long temp;
    std::cin>>temp;
    ++cnt[temp];
  }
  
  int ans=0;
  for(auto&& Map:cnt)
    if(Map.second%2==1)
      ++ans;
  
  std::cout<<ans<<std::endl;
  return 0;
}

Measured memory_bytes: 4388
# -*- coding: cp932 -*-
# ??°??????
# EOF ??§??\?????????
# chomp.split, to_i

while n = gets
  a, b = n.chomp.split
  a, b = a.to_i, b.to_i
  c = a+b
  i = 0
  while c > 0 
    c = c/10
    i += 1
  end
  puts i
end

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,n-2){
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C') ans++;
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <cstdio>

int main() {
  int n;
  long long ans = 0;
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    if(i % 3 != 0 && i % 5 != 0) ans += i; 
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

bool f(int y, int m){
    if(m > 12 || m == 0)return false;
    return true;
}

signed main(void) {
    string s;
    cin >> s;
    int a,b;
    a = (s[0]-'0')*10+(s[1]-'0');
    b = (s[2]-'0')*10+(s[3]-'0');
    if(f(a,b) && f(b,a)){
        cout << "AMBIGUOUS" << endl;
    }else if(f(a,b)){
        cout << "YYMM" << endl;
    }else if(f(b,a)){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }

}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

	int X;
	cin >> X;

	if (X == 3 || X == 5 || X == 7) cout << "YES" << "\n";
	else cout << "NO" << "\n";

	return 0;
}

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    bool ok = true;
    if (n % 3 != 0) {
        for (int i = 1; i < n; i++) {
            if (a[i] != a[0]) ok = false;
        }
    } else {
        for (int i = 0; i < n; i++) {
            if (a[i] != a[i - i % (n / 3)]) ok = false;
        }
        if ((a[0] ^ a[n / 3]) != a[n / 3 * 2]) ok = false;
    }
    cout << (ok ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int n, k;

    while (scanf("%d %d", &n, &k), n){
        int blood[128];
        int i, j;

        for (i = 0; i < k; i++) scanf("%d", blood + i);
        for (i = 0; i < n; i++){
            for (j = 0; j < k; j++){
                int b;

                scanf("%d", &b);
                blood[j] -= b;
            }
        }

        for (i = 0; i < k; i++){
            if (blood[i] < 0) break;
        }
        puts(i == k ? "Yes" : "No");
    }

    return 0;
}

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

using namespace std;

const int N = 1005;

int n, m, d[N][N];
char a[N][N];
queue <pair <int, int> > q;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

bool inside (int x, int y) {
    return x >= 1 && x <= n && y >= 1 && y <= m;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j];
    memset(d, 0x3f, sizeof(d));

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i][j] == '#') {
                d[i][j] = 0;
                q.push({i, j});
            }
        }
    }

    while (!q.empty()) {
        int x = q.front().first, y = q.front().second; q.pop();
        for (int i = 0; i < 4; i++) {
            if (inside(x + dx[i], y + dy[i]) && d[x + dx[i]][y + dy[i]] > d[x][y] + 1) {
                d[x + dx[i]][y + dy[i]] = d[x][y] + 1;
                q.push({x + dx[i], y + dy[i]});
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) ans = max(ans, d[i][j]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 13328
/*
  This C++ Source Is
  Writen By syksykCCC
  (2020)
*/
#include <bits/stdc++.h>
#define rep(i, x, y) for(register int i = x; i < y; i++)
#define REP(i, x, y) for(register int i = x; i <= y; i++)
#define per(i, x, y) for(register int i = x; i > y; i--)
#define PER(i, x, y) for(register int i = x; i >= y; i--)
#define repl(i, x, y) for(register long long i = x; i < y; i++)
#define REPL(i, x, y) for(register long long i = x; i <= y; i++)
#define perl(i, x, y) for(register long long i = x; i > y; i--)
#define PERL(i, x, y) for(register long long i = x; i >= y; i--)
#define LLL __int128
#define int128 __int128
#define DEBUG(x) cerr << #x << " : " << x << endl
using namespace std;
typedef unsigned int uint;
typedef long long int64;
typedef long long LL;
typedef unsigned long long uint64;
typedef long long ULL;
typedef long double LLF;
template<typename T> inline void read(T &val)
{
	val = 0; char c = getchar(); int f = 1;
	while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)) { val = (val << 3) + (val << 1) + (c ^ 48); c = getchar(); }
	val *= f;
}
template<typename T> void write_(T val) { if(!val) return; write_(val / 10); putchar(val % 10 + 48); }
template<typename T> inline void write(T val)
{
	if(val == 0) putchar(48);
	else if(val < 0) { putchar('-'); write_(-val); }
	else write_(val);
}

int main()
{
#ifdef LOCAL
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	LL x;
	cin >> x;
	LL c = 100, a = 0;
	while(c < x)
	{
		c += c / 100;
		a++; 
	}
	cout << a << endl;
	return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(a - x) < abs(b - x)) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;
typedef pair<int,int> product;

int main() {
    int n,w;
    cin >> n >> w;
    vector<product> products(n);    // <value,weight>
    for(int i=0;i<n;i++){
        cin >> products.at(i).first >> products.at(i).second;
    }

    vector<vector<int> > dp(n+1,vector<int>(w+1,0));
    for(int i=0;i<n;i++){
        for (int j=0;j<=w;j++){
            if (j < products[i].second){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = max(dp[i][j],dp[i][j-products[i].second] + products[i].first);
            }
        }
    }
    cout << dp[n][w] << endl;
}


Measured memory_bytes: 6836
import java.util.Scanner;

public class Main {
	int anum = 1;
	int bnum = 0;
	int cnum = 0;

	void run() {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char turn = a.charAt(0);
		while(true) {
			if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			}


		}
		sc.close();
	}

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

Measured memory_bytes: 23764
#include<iostream>
#define int long long
using namespace std;
int dp[101][100100] , v[101] , w[101] , n , W , i , j;
main(){
	cin >> n >> W;
	for(i=0 ; i<n ; ++i) cin >> w[i] >> v[i];
	for(i=0 ; i<101 ; ++i)
		for(int j=0 ; j<100100 ; ++j)
			dp[i][j] = 1e13;
	for(i=0 ; i<n ; ++i) dp[i][0] = 0;
	for(dp[0][v[0]] = w[0] , i=1 ; i<n ; ++i)
		for(j=100099 ; j>=0 ; --j)
			j-v[i] >= 0 ? dp[i][j] = min(dp[i-1][j] , dp[i-1][j-v[i]]+w[i]) : dp[i][j] = dp[i-1][j];
	for(j=100099 ; j>=0 ; --j)	if(dp[n-1][j] <= W) return cout << j , 0;
}

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

int main(){
  int A , B , C , D;
  cin >> A  >> B >> C >> D;
  if(A + B > C + D) cout << "Left" << endl;
  else if(A + B < C + D) cout << "Right" << endl;
  else cout << "Balanced" << endl;
}

 

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

#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(c,x)       ((c).find(x) != (c).end())
#define isp(c,x)      (find(all(c),x) != (c).end())
#define pb             push_back
#define ppb            pop_back
#define sz(x)          (int)x.size()
#define fill(a,v)      memset(a, v, sizeof a)
#define fs first
#define sc second
#define ub upper_bound
#define lb lower_bound
#define en '\n'

typedef long long int lli;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair< int, int > pii;
typedef pair< lli, lli > plli;
typedef list<int> li;
typedef map<int, int> mi;
typedef map<lli, lli> mlli;
lli gcd(lli a,lli b){return (!b)?a:gcd(b,a%b);}
int t = 1; int ti;



const int N = 1e5 + 5;
lli n, dp[N][3], a[N][3];

void solve(){
    cin>>n;

    fori(i, 1, n){
        fori(j, 0, 2)
        cin>>a[i][j];
    }  

    lli ans = 0;  

    fori(i, 1, n){
        fori(j1, 0, 2){
            fori(j2, 0, 2){
                if(j1 != j2){
                    dp[i][j1] = max(dp[i][j1] , dp[i-1][j2] + a[i][j1]);
                    ans= max(ans, dp[i][j1]);
                }
            }
        }
    }

    cout<<ans;
}
//THINK OF SPECIAL CASES, ARRAY LIMITS, LLI vs INT, 1LL

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

    // cin>>t;

    // for(ti= 1; ti <= t; ti++)
    solve();

//    cout<<"\nTHINK OF SPECIAL CASES, ARRAY LIMITS, LLI vs INT, 1LL";
}

Measured memory_bytes: 4992
// educational dp - vacation
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pr cout<<
#define in cin>>
#define tc(t) ll t;cin>>t;while(t--)
#define fr(i,n) for(ll i=0;i<n;i++)
#define mod 1e9+7
#define nl pr "\n"
#define rt return


int main()
{
    ll n;
    in n;
    ll a[n][3];
    fr(i,n) fr(j,3) in a[i][j];
    ll dp[n][3];
    fr(i,1) fr(j,3) dp[i][j]=a[i][j];
    
    for(ll i=1;i<n;i++)
    {
        fr(j,3)
        {
            if(j==0)
                dp[i][j]=max(dp[i-1][j+1]+a[i][j],dp[i-1][j+2]+a[i][j]);
            if(j==1)
                dp[i][j]=max(dp[i-1][j-1]+a[i][j],dp[i-1][j+1]+a[i][j]);
            if(j==2)
                dp[i][j]=max(dp[i-1][j-2]+a[i][j],dp[i-1][j-1]+a[i][j]);
            
        }
    }
    //fr(i,n) pr dp[i];
    pr max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	rt 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int n, m, p[1010];

int main() {
	while (cin >> n >> m, n) {
		for_(i,0,n) cin >> p[i];
		
		sort(p, p + n, greater< int >());
		
		int ans = 0, cnt = 1;
		
		for_(i,0,n) {
			if (cnt == m) {
				cnt = 1;
			} else {
				++cnt;
				ans += p[i];
			}
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 1176
//
//  2.cpp
//  sample
//
//  Created by Sakiko Miyazawa on 2020/03/22.
//  Copyright © 2020 Sakiko Miyazawa. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

int main() {
    int K;
    string S;
    cin>>K;
    cin>>S;
    
    if(S.length()<=K){
        cout<<S<<endl;
    }else{
        cout<<S.substr(0,K)<<"..."<<endl;
    }
    
    
}


Measured memory_bytes: 3520
#include <stdio.h>

int main(void) {

  int n,m;
  scanf("%d %d", &n, &m);
  int a[m],b[m];
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a[i], &b[i]);
  }
  int permutation[n];
  for (int i = 0; i < n; i++) {
    permutation[i] = i+1;
  }
  int check[n+1];
  for (int j = 1; j <= n; j++) {
    check[j] = 1;
  }
  int path = 0;
  int flag;
  for (int i = 0; ; i++) {
    for (int j = 1; j < n; j++) {
      flag = 0;
      for (int k = 0; k < m; k++) {
        if (a[k] == permutation[j-1] && b[k] == permutation[j]) {
          flag = 1;
          break;
        } else if (a[k] == permutation[j] && b[k] == permutation[j-1]) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        break;
      }
    }
    if (flag == 1) {
      path++;
    }
    for (int j = n-1; j > 0; j--) {
      check[permutation[j]] = 0;
      if (permutation[j] > permutation[j-1]) {
        check[permutation[j-1]] = 0;
        for (int k = permutation[j-1]+1; k <= n; k++) {
          if (check[k] == 0) {
            check[k] = 1;
            permutation[j-1] = k;
            break;
          }
        }
        for (int k = j; k < n; k++) {
          for (int l = 1; l <= n; l++) {
            if (check[l] == 0) {
              check[l] = 1;
              permutation[k] = l;
              break;
            }
          }
        }
        break;
      }
    }
    if (permutation[0] != 1) {
      break;
    }
  }
  printf("%d\n", path);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
const int mod=1000000007;
const ll inv2=(mod+1)>>1;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
	for(;isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
	return (f==1)?x:-x;
}
inline ll fpow(ll a,ll b)
{
	ll ret=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ret=ret*a%mod;
	return ret;
}
int n,a[maxn],cnt[maxn];
ll p[maxn],S[maxn],invS[maxn],c[maxn][2];
#define lowbit(x) ((x)&(-(x)))
inline void add(int x,ll y) { for(;x<=n;x+=lowbit(x)) (c[x][0]+=y)%=mod,c[x][1]++; }
inline ll sum(int x,int y) { ll ans=0; for(;x;x-=lowbit(x)) (ans+=c[x][y])%=mod; return ans; }
int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read(),cnt[a[i]]++;
	for(int i=n;i;i--) cnt[i]+=cnt[i+1];
	ll val=1,ans=0;
	for(int i=1;i<=n;i++)
		if(cnt[i]-(n-i)<=0) { puts("0"); return 0; }
		else (val*=cnt[i]-(n-i))%=mod;
	S[0]=1;
	for(int i=1;i<=n;i++)
	{
		ll x=(cnt[i]-(n-i)-1)*fpow(cnt[i]-(n-i),mod-2)%mod;
		if(x==0) S[i]=S[i-1],p[i]=i;
		else S[i]=S[i-1]*x%mod,p[i]=p[i-1];
		invS[i]=fpow(S[i],mod-2);
	}
	for(int i=1;i<=n;i++)
	{	
		(ans+=(sum(a[i],0)-sum(p[a[i]]-1,0))%mod*S[a[i]]%mod*inv2)%=mod;
		add(a[i],invS[a[i]]);
	}
	for(int i=1;i<=n;i++) c[i][0]=c[i][1]=0;
	for(int i=n;i;i--)
	{
		(ans-=(sum(a[i]-1,0)-sum(p[a[i]]-1,0))%mod*S[a[i]]%mod*inv2)%=mod;
		(ans+=sum(a[i]-1,1))%=mod;
		add(a[i],invS[a[i]]);
	}
	printf("%lld\n",(ans*val%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 13120
import sys, array, re, functools
from math import sqrt, ceil; from itertools import count, islice
input = lambda: sys.stdin.readline()
@functools.lru_cache(maxsize = 10000)



def isPrime(n):
    return n > 1 and all(n%i for i in islice(count(2), int(sqrt(n)-1)))
def f(a, b):
  return  max(len(str(a)), len(str(b)))

def Main():
  N = int(input())
  v = -1
  if isPrime(N):
    print(len(str(N)))
  elif not isPrime(N):
    for i in range(1, ceil(sqrt(N)) + 1):
      if N%i == 0:
        t = f(int(i), int (N/i))
        if v == -1 or v > t:
          v = t
    print(v)
    
if __name__ == '__main__':
  Main()

Measured memory_bytes: 3828
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int main(){
  lint A,B;
  cin>>A>>B;
  if(A==B){
    puts("1");
    return 0;
  }
  while(__builtin_clzll(A)==__builtin_clzll(B)){
    lint a=__builtin_clzll(A);
    A^=(1ll<<(63-a));
    B^=(1ll<<(63-a));
  }
  ++B;
  int k;
  for(k=63;k>=0;--k){
    lint K=(1ll<<k);
    if(A<=K && K<B){
      break;
    }
  }
  lint K=(1ll<<k);

  lint tmp=0;
  bool fail=false;
  for(int i=k-1;i>=0;--i) if((B-1)>>i&1){
    tmp=(1ll<<(i+1));
    fail=true;
    break;
  }
  if(!fail) ++tmp;


  lint res=K-A+min(K,K-A+tmp);
  cout<<res<<endl;

  return 0;
}





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

const int kMaxn = 1e3 + 5;
int N, M;
pair<int, int> st, se;
char mp[kMaxn][kMaxn];
int getid(int x, int y);
int uf[kMaxn * kMaxn];
int find_set(int x);
void merge(int x, int y);
int go[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
set<int> E[kMaxn * kMaxn];
bool vis[kMaxn * kMaxn];
int dis[kMaxn * kMaxn];
void spfa(int stid);

int main() {
  //
  scanf("%d%d", &N, &M);
  scanf("%d%d", &st.first, &st.second);
  scanf("%d%d", &se.first, &se.second);
  for (int i = 1; i <= N; i++) scanf("%s", mp[i] + 1);
  for (int i = 1, cnt = 0; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      cnt++;
      uf[cnt] = cnt;
    }
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      if (mp[i][j] == '#') continue;
      for (int k = 0; k < 4; k++) {
        int x = i + go[k][0], y = j + go[k][1];
        if (x < 1 || x > N || y < 1 || y > M || mp[x][y] == '#') continue;
        merge(getid(i, j), getid(x, y));
      }
    }
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      if (mp[i][j] == '#') continue;
      for (int k = -2; k <= 2; k++)
        for (int l = -2; l <= 2; l++) {
          int x = i + k, y = j + l;
          if (x < 1 || x > N || y < 1 || y > M || mp[x][y] == '#') continue;
          int f1 = find_set(getid(i, j)), f2 = find_set(getid(x, y));
          // cout << i << " " << j << " " << f1 << endl;
          if (f1 != f2) {
            E[f1].insert(f2);
            E[f2].insert(f1);
          }
        }
    }
  spfa(find_set(getid(st.first, st.second)));
  int ans = dis[find_set(getid(se.first, se.second))];
  if (ans == dis[0]) ans = -1;
  printf("%d\n", ans);
  return 0;
}

void spfa(int stid) {
  memset(dis, 2, sizeof(dis));
  queue<int> Q;
  dis[stid] = 0;
  Q.push(stid);
  vis[stid] = true;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    vis[u] = false;
    for (int v : E[u])
      if (dis[v] > dis[u] + 1) {
        dis[v] = dis[u] + 1;
        if (!vis[v]) {
          Q.push(v);
          vis[v] = true;
        }
      }
  }
}

int find_set(int x) { return (uf[x] == x) ? uf[x] : uf[x] = find_set(uf[x]); }

void merge(int x, int y) {
  int fx = find_set(x), fy = find_set(y);
  uf[fy] = fx;
}

int getid(int x, int y) { return (x - 1) * M + y; }

Measured memory_bytes: 55248
#include <iostream>
#include <vector>
#include <cstdlib>
#include <utility>
#include <algorithm>

using namespace std;

const int N = 1001;
vector<int> F, djset, szset;
//vector<pair<int, pair<int, int>>> G;

int root(int v)
{
    int r = djset[v];
    while (r != djset[r]) r = djset[r];
    djset[v] = r;
    return r;
}

bool same(int v1, int v2)
{
    return (root(v1) == root(v2));
}

void unite(int v1, int v2)
{
    int r[2] = {root(v1), root(v2)};
    if (szset[r[1]] > szset[r[0]]) swap(r[0], r[1]);
    djset[r[1]] = r[0];
    szset[r[0]] += szset[r[1]];
    szset[r[1]] = 0;
}

int main(void)
{
    int V, D;
    F.resize(N);
    F[0] = 2;
    F[1] = 3;
    for (int i = 2; i < N; i++) F[i] = (F[i - 1] + F[i - 2]) % N;
    while (cin >> V >> D)
    {
        djset.resize(V);
        szset.resize(V, 1);
        for (int i = 0; i < V; i++) djset[i] = i;
        for (int i = 0; i < V; i++)
        {
            for (int j = 0; j < V; j++)
            {
                if (abs(F[i] - F[j]) >= D || same(i, j)) continue;
                unite(i, j);
            }
        }
        int ans = 0;
        for (auto i : szset) if (i) ans++;
        cout << ans << endl;
        djset.clear();
        szset.clear();
    }
    return 0;
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, n;
  int ans, min;
  cin >> x >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  ans = 10000;
  min = 10000;
  bool flg;
  for (int i = 0; i <= 101; i++) {
    flg = false;
    for (int j = 0; j < n; j++) {
      if (i == p[j]) {
        flg = true;
        break;
      }
    }
    if (flg) {
      continue;
    } else {
      if (min > abs(x - i)) {
        min = abs(x - i);
        ans = i;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
N = int(input())
A = list(map(int,input().split()))

csum1 = [A[0] for _ in range(N)]
for i in range(1,N):
  csum1[i] = csum1[i-1]+A[i]
csum2 = [A[-1] for _ in range(N)]
for i in range(N-2,-1,-1):
  csum2[i] = csum2[i+1]+A[i]

ans = float('inf')
for i in range(N-1):
  ans = min(abs(csum1[i]-csum2[i+1]),ans)
print(ans)


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

void fnInput(int& rnMaxNum)
{
  cin >> rnMaxNum;
}

int64_t fnConvInt(const vector<char>& cnrvcNum)
{
  const vector<int> cnvnNum = {0, 3, 5, 7};

  vector<char> vcRevNum(cnrvcNum);
  reverse(begin(vcRevNum), end(vcRevNum));

  int64_t nNum = 0;
  for (int i = 0; i < vcRevNum.size(); i++)
  {
    if (vcRevNum[i] == '0') break;
    nNum += cnvnNum[ vcRevNum[i] - '0' ] * pow(10, i);
  }

  return nNum;
}

int fnDgt753_Check(const vector<char>& cnrvcNum)
{
  int nDig3 = 0, nDig5 = 0, nDig7 = 0;

  for (int i = 0; i < cnrvcNum.size(); i++)
    if      (cnrvcNum[i] == '1') nDig3++;
    else if (cnrvcNum[i] == '2') nDig5++;
    else if (cnrvcNum[i] == '3') nDig7++;

  if (nDig3 && nDig5 && nDig7)
    return 1;
  else
    return 0;
}

int fnDgt753_Count(int nMaxNum)
{
  vector<char> vcNum(10, '0');
  int nDgt753Cnt = 0;

  while (fnConvInt(vcNum) <= nMaxNum) 
  {
    if (fnDgt753_Check(vcNum)) nDgt753Cnt++;

    vcNum[vcNum.size() - 1]++;
    for (int i = vcNum.size() - 1; i >= 1; i--)
      if (vcNum[i] > '3')
      {  
        vcNum[i - 1]++;
        vcNum[i] = '1';
      }
      else
        break;
  }

  return nDgt753Cnt;
}

int main()
{
  int nMaxNum;

  fnInput(nMaxNum);
  cout << fnDgt753_Count(nMaxNum) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007
using namespace std;


int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,k,n,m;
     ll t;
     string s;
     ll x;
     cin>>x;
     vector<ll> v;
     for(i=-1000;i<=1000;i++)
     {
         v.pb(i*i*i*i*i);
     }
     i=0;
     j=1;
     while(i<(ll)v.size() && j<(ll)v.size())
     {
         ll r=v[j]-v[i];
         if(r==x)
         {
             cout<<j-1000<<" "<<i-1000;
             return 0;
             
         }
         else if(r>x)
         {
             i++;
         }
         else
             j++;
         if(i==j)
             j++;
     }
}  


Measured memory_bytes: 3652
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] input = new int[n];
        for (int i = 0; i < n; i++) {
            input[i] = sc.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
 
        for(int i=1;i<n;i++){
            for(int j=1;j<=k;j++){
                if(i>=j) {
                    dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(input[i] - input[i - j]));
                }
            }
        }
        System.out.println(dp[n-1]);
    }
}

Measured memory_bytes: 50792
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;


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

    ll n,k;
    cin>>n>>k;
    ll ar[n];
    for(ll i=0;i<n;++i){
        ll x;
        cin>>x;
        ++x;
        ar[i]=x;
    }
    ll ans=0;
    ll ch=0;
    for(ll i=0;i<n;++i){
        if(i<k-1){ch+=ar[i];}
        else if(i==k-1){
            ch+=ar[i];
            ans=max(ans,ch);
        }
        else{
            ch+=ar[i];
            ch-=ar[i-k];
            ans=max(ans,ch);
        }
    }
    long double aa=ans/2.0;
    cout<<fixed;
    cout<<setprecision(9)<<aa;

    return (0);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b="CODEFESTIVAL2016";
    cin>>a;
    int d=0;
    for(int i=0;i<16;i++)
    {
        if(a[i]!=b[i])
        {
            d++;
        }
    }
    cout<<d<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static boolean flag = false;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		for(int i = 0; i < s.length()-1; i++) {
			String subst = s.substring(i, i+2);
			if(subst.charAt(0) == subst.charAt(1)) {
				System.out.println((i+1) + " " + (i+2));
				flag = true;
				break;
			}
		}

		if(!flag) {
		for(int i = 0; i < s.length()-2; i++) {
			String subst = s.substring(i, i+3);
			if(subst.charAt(0) == subst.charAt(2)) {
				System.out.println((i+1) + " " + (i+3));
				flag = true;
				break;
			}
		}
		}

		if(!flag) System.out.println("-1 -1");

//		int half = s.length() / 2;
//		int[] count = new int[26];
//		for(int i = 0; i < 26; i++) {
//			count[i] = 0;
//		}
//
//
//		for(int i = 2; i < s.length(); i++) {
//			int startIndex = 0;
//			int endIndex = i;
//			while(endIndex <= s.length()) {
//				check(s, startIndex, endIndex);
//				startIndex++;
//				endIndex++;
//				if(flag) break;
//			}
//			if(flag) break;
//		}
//
//		if(!flag)System.out.println("-1 -1");
//	}
//
//	static void check(String s, int beginIndex, int endIndex) {
//		String subst = s.substring(beginIndex, endIndex);
//		HashMap<Character, Integer> count = new HashMap<Character, Integer>();
//		for(int i = 0; i < s.length(); i++) {
//			char temp = s.charAt(i);
//			if(!count.containsKey(temp)) {
//				count.put(temp, 1);
//			}else {
//				count.replace(temp, count.get(temp)+1);
//			}
//
//			if(count.get(temp) > (endIndex - beginIndex) / 2) {
//				System.out.println((beginIndex+1) + " " + (endIndex));
//				flag = true;
//				break;
//			}
//		}
	}

}


Measured memory_bytes: 19556
n=int(input())
w=[]
j=0
for i in range(n):
    k=input()
    w.append(k)
for i in range(n):
    if i!=0:
        a=w[i]
        b=w[i-1]
        if a[0]!=b[len(b)-1]:
            print("No")
            j+=1
            break

    if w.count(w[i])>1:
        print("No")
        j+=1
        break
if j==0:
    print("Yes")
    

Measured memory_bytes: 9196
a,b,c,x=[int(input()) for i in range(4)]
x//=50
p=min(a,x//10)
ans=0
for i in range(p+1):
    y=x-10*i
    q=min(b,y//2)
    for j in range(q+1):
        z=y-2*j
        if c>=z:ans+=1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, a[200008];

bool f(ll x){
	map<ll, ll> dp;
	zep(i, 1, n){
		if(a[i] <= a[i-1]){
			if(x == 1){
				return false;
			}
			if(a[i] < a[i-1]){
				vector<ll> er;
				for(auto it = dp.upper_bound(a[i]); it != dp.end(); it++){
					er.push_back((*it).first);
				}
				zep(j, 0, er.size()){
					dp.erase(er[j]);
				}
			}
			
			ll at = a[i];
			if(dp.find(at) != dp.end()){(*dp.find(at)).second++;}
			else{dp[at] = 1;}
			
			while(dp.find(at) != dp.end() && dp[at] == x){
				dp.erase(at);
				at--;
				if(dp.find(at) == dp.end()){
					dp[at] = 1;
				}
				else{
					dp[at]++;
				}
				if(at < 1){return false;}
			}
		}
	}
	return true;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	zep(i, 0, n){cin >> a[i];}
	
	ll ok = n;
	ll ng = 0;
	while(ok-ng > 1){
		ll mid = (ok+ng)/2;
		if(f(mid)){ok = mid;}
		else{ng = mid;}
	}
	print(ok)
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
int main(){for(float a,b,c,d,e,f,x,y,g,h;;printf("%.3f %.3f\n",x,y)){std::cin>>a>>b>>c>>d>>e>>f;if(std::cin.eof())break;g=b*d-a*e;h=c*d-a*f;d*g?(x=f/d-e*h/g/d,y=b?c/b-a*x/b:f/e-d*x/e):(y=h/g,x=a?c/a-b*y/a:f/d-e*y/d);}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n;
    cin >> n;
    vector<string> vs(n);

    rep(i, n) cin >> vs[i];

    bool flag = true;
    rem(i, 1, n)
    {
        // std::cout << std::endl;
        // std::cout << vs[i - 1] << " , " << vs[i] << std::endl
        //           << endl;
        if (vs[i - 1][vs[i - 1].length() - 1] != vs[i][0])
        {
            flag = false;
        }
        rep(j, i)
        {
            if (vs[i] == vs[j])
            {
                flag = false;
            }
        }
    }

    if (flag)
        cout << "Yes"
             << "\n";
    else

        cout << "No"
             << "\n";

    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n;
  readf (" %d", &n);
  auto a = new int[n];
  foreach (t; 0 .. n) {
    readf (" %d", &a[t]);
  }
  auto b = a.dup;
  sort (b);
  int m = n / 2;
  foreach (i; 0 .. n) {
    if (a[i] <= b[m-1]) {
      writeln (b[m]);
    } else {
      writeln (b[m-1]);
    }
  }
}


Measured memory_bytes: 5500
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc077/tasks/arc084_a

"""
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
input = stdin.readline


def main(args):
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    A.sort()
    B.sort()
    C.sort()

    lut_A = {}
    lut_C = {}
    for b in B:
        i = bisect_left(A, b)
        lut_A[b] = i
        j = bisect_right(C, b)
        lut_C[b] = N - j


    ans = 0
    for b in B:
        i = lut_A[b]
        j = lut_C[b]
        ans += i * j

    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 38708
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#include <map>

#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

struct pos { int x, y; };
int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0)break;
		vector<pos> building(n);
		vector<vector<double> > cost(n, vector<double>(n, 0));
		for (int i = 0; i < n; i++) {
			int b;
			cin >> b; b--;
			cin >> building[b].x >> building[b].y;
		}
		for (int i = 0; i < n; i++)for (int j = 0; j < n; j++) {
			if (i == j)cost[i][j] = 0;
			else cost[i][j] = sqrt(pow(building[i].x - building[j].x, 2) + pow(building[i].y - building[j].y, 2));
			if (cost[i][j] > 50)cost[i][j] = INF_LL;
		}

		int m;
		cin >> m;
		for (int i = 0; i < m; i++) {
			int s, g, c;
			cin >> s >> g;
			s--; g--;
			c = g;
			vector<double> d(n, INF);
			vector<bool> used(n, false);
			vector<int> prev(n, -1);
			vector<int> path;
			d[s] = 0;
			while (1) {
				int v = -1;
				for (int u = 0; u < n; u++) {
					if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
				}
				if (v == -1)break;
				used[v] = true;
				for (int u = 0; u < n; u++) {
					if (d[u] > d[v] + cost[v][u]) {
						d[u] = d[v] + cost[v][u];
						prev[u] = v;
					}
				}
			}
			for (; g != -1; g = prev[g]) path.push_back(g);
			reverse(path.begin(), path.end());
			if (path[0] == c && s != c)cout << "NA" << endl;
			else {
				for (int i = 0; i < path.size(); i++) {
					cout << path[i] + 1;
					if (i != path.size() - 1) cout << " ";
				}
				cout << endl;
			}
		}
	}


	return 0;
}


Measured memory_bytes: 3132
#include <algorithm>
#include <iostream>
#include <set>
#include <stack>
#include <vector>

using namespace std;

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

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

    int x_max = *max_element(x.begin(), x.end());
    int y_max = *max_element(y.begin(), y.end());

    vector<set<int>> g(x_max + y_max + 2, set<int>());
    for (int i = 0; i < n; i++) {
        g[x[i]].insert(y[i] + x_max + 1);
        g[y[i] + x_max + 1].insert(x[i]);
    }

    long long res = 0;
    for (int i = 0; i <= x_max + y_max + 1; i++) {
        set<int> sx, sy;
        long long ce = 0;

        stack<int> st;
        st.push(i);
        while (!st.empty()) {
            int s = st.top();
            st.pop();

            if (s <= x_max) {
                sx.insert(s);
            } else {
                sy.insert(s);
            }

            while (!g[s].empty()) {
                int t = *g[s].begin();
                g[s].erase(t);
                g[t].erase(s);
                st.push(t);
                ce++;
            }
        }

        if (static_cast<int>(sx.size()) >= 2 && static_cast<int>(sy.size()) >= 2) {
            res += static_cast<long long>(sx.size()) * static_cast<long long>(sy.size()) - ce;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 19968
#include <iostream>
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;

int main()
{
    int n;
    cin>>n;
    int A[n+1];
    for(int i = 1; i <= n; i++){
        cin>>A[i];
    }
    for(int i = 1; i <= n; i++){
        if(A[i] != i){
            swap(A[i], A[A[i]]);
            break;
        }
    }
    for(int i = 1; i <= n; i++){
        if(A[i] != i){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sz(a) int((a).size())
#define all(c) c.begin,c.end()
#define tr(c,i) for(typeof(c).begin() i=c.begin; i!=c.end(); i++)
#define present(c,x) (c.find(x)!=c.end())
#define cpresent(c,x) (find(all(c),x)!=c.end())
#define pb push_back
#define F first
#define S second
#define INF 1e9+7
typedef long long int ll;
typedef vector< int > vi;
typedef vector< bool > vb;
typedef vector< vb > vvb;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef vector< ii > vii;

int h,w,k;
vvb G;

int number_of_cut(vi cut,int n){
    int ans=n;
    //rep(i,h-1) cout<<cut[i]<<" ";
    //cout<<"\n";
    vvi p(1+n,vi (w,0));
    int cnt=0;
    rep(i,h){
        rep(j,w)   p[cnt][j]+=G[i][j];
        if(cut[i]) cnt++; 
    }
    vi sum(n+1,0);
    rep(j,w) {
        rep(i,n+1) {
            sum[i]+=p[i][j]; 
            if(p[i][j]>k) return INF;
            else if(sum[i]>k) { rep(i,n+1) sum[i]=p[i][j];ans++;break;}
            //cout<<p[i][j]<<" ";
        }
        //cout<<"\n";
    }
    //cout<<ans<<"\n";
    return ans;
}

void solve(){
    int ans=INF;
    cin>>h>>w>>k;
    G= vvb (h,vb (w,0));
    char ch;
    rep(i,h) rep(j,w) { cin>>ch; G[i][j]=ch-'0';}
    rep(i,pow(2,h-1)){
        vi cut(h-1);
        int n=0;
        rep(j,h-1) {cut[j]=(i>>j) & 1; if(cut[j]) n++;}
        ans=min(ans,number_of_cut(cut,n));
        //cout<<"*********************\n";
    }
    cout<<ans;
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
}

Measured memory_bytes: 256
s = gets.chomp
n = s.length
count = 0
judge = "AC"
for i in 0...n do
  if i == 0
    judge = "WA" if s[i] != "A"
  elsif i >= 2 && i <= (n-2) && s[i] == "C"
    count += 1
  else
    judge = "WA" if s[i] < "a" || s[i] > "z"
  end
end
judge = "WA" if count != 1
puts judge


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 200005, INF = 1000000000;

int n, m;
int d[N];
vector<pair<int, int> > a[N];

char c[N];
int ans[N];

void dfs(int x)
{
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i].first;
        if (!c[h])
        {
            if (d[h] > d[x])
            {
                c[h] = c[x];
                ans[a[x][i].second] = d[h] - d[x];
                dfs(h);
            }
        }
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &d[i]);
    for (int i = 0; i < m; ++i)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        a[x].push_back(m_p(y, i));
        a[y].push_back(m_p(x, i));
        ans[i] = INF;
        if (d[x] == d[y])
        {
            if (!c[x] && !c[y])
            {
                c[x] = 'W';
                c[y] = 'B';
                ans[i] = d[x];
            }
            else if (!c[y])
            {
                if (c[x] == 'W')
                    c[y] = 'B';
                else
                    c[y] = 'W';
                ans[i] = d[x];
            }
            else if (!c[x])
            {
                if (c[y] == 'W')
                    c[x] = 'B';
                else
                    c[x] = 'W';
                ans[i] = d[x];
            }
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        if (c[i])
            dfs(i);
    }
    for (int i = 1; i <= n; ++i)
    {
        if (!c[i])
        {
            printf("-1\n");
            return 0;
        }
    }
    for (int i = 1; i <= n; ++i)
        printf("%c", c[i]);
    printf("\n");
    for (int i = 0; i < m; ++i)
        printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
int main(){
    string N; cin>>N;
    int size=N.size();
    int ans=N[size-1]-'0';
    if(ans==0 ||ans==1 ||ans==6||ans==8){
        cout<<"pon";
    }
    else if(ans==3){
        cout<<"bon";
    }
    else{
        cout<<"hon";
    }
    return 0;
}

Measured memory_bytes: 3624