akhauriyash/Code-Regression huggingface dataset:
var s, s1, s2 : ansistring;
    n : longint;
    
function check(s : ansistring) : boolean;
var n, i, j : longint;
begin
    n := length(s);
    i := 1; j := n;
    while (i < j) do
    begin
        if (s[i] <> s[j]) then exit(false);
        inc(i); dec(j);
    end;
    exit(true);
end;

begin
    readln(s);
    n := length(s);
    s1 := copy(s, 1, (n - 1) div 2);
    s2 := copy(s, (n + 3) div 2, (n - 1) div 2);
    if (check(s) and check(s1) and check(s2)) then writeln('Yes')
    else writeln('No');
end.

Measured memory_bytes: 128
a,b,c  = map(int, input().split())
d,e,f  = map(int, input().split())
g,h,i  = map(int, input().split())
n=int(input())
A = []
for j in range(n):
    A.append(int(input()))
if (a in A) and (b in A) and (c in A):
    print("Yes")
elif d in A and e in A and f in A:
    print("Yes")
elif g in A and h in A and i in A:
    print("Yes")
elif a in A and d in A and g in A:
    print("Yes")
elif b in A and e in A and h in A:
    print("Yes")
elif c in A and f in A and i in A:
    print("Yes")
elif a in A and e in A and i in A:
    print("Yes")
elif c in A and e in A and g in A:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
N = int(input())
P = [i for i in input().split()]
Q = [i for i in input().split()]

from itertools import permutations

sort_P = list(permutations(sorted(P)))

answer = 0
for i,x in enumerate(sort_P):
    if list(x) == P:
        answer += i + 1
    if list(x) == Q:
        answer -= i + 1

print(abs(answer))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b; cin >> a >> b;
    if(a*b % 2 == 1) OUT("Odd");
    else OUT("Even");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  
  vector<int> a(n),b(n),c(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    cin>>c[i];
  }
  
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  
  long long kotae=0;
  for(int i=0;i<n;i++){
    long long x=lower_bound(a.begin(),a.end(),b[i])-a.begin();
    long long y=n-(upper_bound(c.begin(),c.end(),b[i])-c.begin());
    kotae+=x*y;
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

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

    int n;
    cin >> n;

    int f[n][10];
    ll p[n][11];

    rep(n) repp(j, 10) cin >> f[i][j];
    
    rep(n) repp(j, 11) cin >> p[i][j];

    ll ans = LLONG_MIN;
    int a[10];
    reppp(i, 1, 1023){
        int pattern = i, j = 0;
        while(j < 10){
            a[j] = pattern % 2;
            pattern /= 2;
            j++;
        }

        ll ans_tmp = 0;
        repp(k, n){
            int cnt = 0;
            repp(j, 10){
                if(f[k][j] == 1 && a[j] == 1) cnt++;
            }
            ans_tmp += p[k][cnt];
        }
        ans = max(ans, ans_tmp);
    }
    cout << endl << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, k, p;
    cin >> n;
    while (n--) {
        cin >> k >> p;
        int mod = k % p;
        if (mod == 0) {
            cout << p << endl;
        }
        else {
            cout << mod << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n,k,q;
    cin >> n >> k >> q;
    vector<ll> array(n,k);
    vector<ll> seikai(n,0);
    for(int i=0;i<q;i++){
        int a;
        cin >> a;
        seikai.at(a-1) += 1;
    }
    for(int i=0;i<n;i++){
        array.at(i) = array.at(i) + seikai.at(i) - q;
    }

    for(int i=0;i<n;i++){
        if(array.at(i) <= 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}

Measured memory_bytes: 4836
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
int main(void)
{
  int i,j,n,m,p,ans=0;
  string s,t;
  cin>>s>>t;
  n=s.size();
  m=t.size();
  for(i=0;i<n-m+1;i++){
    p=0;
    for(j=0;j<m;j++){
      if(s[i+j]==t[j]){
        p++;
      }
    }
    if(ans<p){
      ans=p;
    }
  }
  printf("%d\n",m-ans);
  return 0;
}
      
  

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define BIT(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
#define MAXN 100010
int N, M, S, T;
vector< lli > graph[MAXN];
set< lli > graph3[MAXN];
set< lli > visited[3];
struct Object {
  lli id;
  lli cost;
};
queue< Object > q;

int bfs() {
  while (!q.empty()) {
    Object now = q.front();
    q.pop();
    if (now.id == T && now.cost % 3 == 0) {
      return now.cost / 3;
    }
    // cout << "id " << now.id << " cost " << now.cost << "\n";
    for (auto x : graph[now.id]) {
      Object next = {x, now.cost + 1};
      int mo = (now.cost + 1) % 3;
      auto it = visited[mo].find(x);
      if (it == visited[mo].end()) {
        visited[mo].insert(x);
        //  cout << x << "\n";
        q.push(next);
      }
    }
  }
  return -1;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  REP(i, M) {
    int x, y;
    cin >> x >> y;
    graph[x].push_back(y);
  }
  cin >> S >> T;

  Object start = {S, 0};
  q.push(start);
  visited[0].insert(S);
  int ans = bfs();
  cout << ans << "\n";
}

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

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

	ll ans = 1;
	rep(i, 1, x) {
		rep(j, 2, x) {
			ll c = pow(i, j);
			if (c > x) break;
			ans = max(ans, c);
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(void)
{
	int n, q, com, t, x;
	cin >> n >> q;
	vector<priority_queue<int> > ve(n);
	while (q--) {
		cin >> com >> t;
		switch (com) {
			case 0: 
				cin >> x;
				ve[t].push(x);
				break;
			case 1:
				if (!ve[t].empty()) {
					cout << ve[t].top() << endl;
				}
				break;
			case 2:
				if (!ve[t].empty()) {
					ve[t].pop();
				}
		}
	}
	
}


Measured memory_bytes: 4120
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;

  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
      y=x;
      if(z->key<x->key){
          x=x->left;
      }
      else{
          x=x->right;
      }

  }
  
  z->parent=y;
  
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key<y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
  
}

void inorder(Node u){
  if(u==NIL) return;

  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u==NIL) return;

  printf(" %d",u->key);

  preorder(u->left);
  preorder(u->right);
}
  

int main(){

  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  
  return 0;
}



Measured memory_bytes: 25180
//Deep Godhani
//DAIICT

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

#define N 100000000000
#define PI acos(-1)
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define ll long long int
#define ld long double
#define precision(x,d) cout << fixed << setprecision(d) << x
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))

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

bool checkPrime(int n)
{
	for(int i=0;i<=sqrt(n);i++)
	{
		if(n%i == 0)
		{
			return false;
		}
	}
	return true;
}


void solve()
{
	int n;
	cin >> n;
	while(n)
	{
		int a = n%10;
		if(a == 7)
		{
			cout << "Yes";
			return;
		}
		n = n/10;
	}
	cout << "No";
	return;
}
int main()
{
    FAST;
    ll t=1;
    //cin >> t;
    while(t--)
    {
      //cout << "************" << endl;
      solve();
      //cout << "************"  << endl;
    }
		return 0;
}


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

long long int N, M, K;

long long int MOD = 1000000007;

long long int num = 1;

long long int POW(long long int K, long long int p) {

	if (p == 0) { return 1; }
	else if (p == 1) { return K; }

	if ((p % 2) == 1) { return (K*POW(K, p - 1)) %MOD; }

	long long int tmp = POW(K, p / 2);

	return (tmp*tmp)%MOD;

}

int main(void) {

	cin >> N >> M >> K;

	
	for (int i = 0; i < K - 2; i++) {
		//cout << "num= " << num << endl;
		num *= (N*M - 2 - i);
		num %= MOD;
		//cout << POW(K - 2 - i, MOD - 2) << endl;
		num *= POW(K - 2 - i, MOD - 2);
		num %= MOD;
	}

	

	long long int ans = 0;

	if (K <= 1) {cout << 0 << endl; return 0;}

	for (long long int i = 1; i <= N + M - 2; i++) {

		long long int MA = min(N, i + 1);
		long long int m = max((long long int) 1,(long long int) 2+i - M);
		long long int tmp = 0;

		tmp =( (N + 1)*(M-i-1) %MOD) *(MA - m + 1) + (N - M + i+2)*(((MA*(MA + 1)) / 2 - ((m - 1)*m) / 2) %MOD) +MOD - (( ((MA*(MA + 1) %MOD) *(MA * 2 + 1)) %MOD)*POW(6,MOD-2) %MOD) + ((((m - 1)*m %MOD)*(m * 2 - 1)) %MOD) *POW( 6,MOD-2);
	
		if (M > i) { tmp -= (M - i)*N; }
		if (N > i) { tmp -= (N - i)*M; }
		
		tmp *= 2;
		if (M > i) { tmp += (M - i)*N; }
		if (N > i) { tmp += (N - i)*M; }

		tmp %= MOD;

		//cout << "i= " << i << " tmp= " << tmp << endl;
		ans += ((num*i)%MOD)*tmp;
			ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1e9 + 100;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 5e5 + 100;
int n;
int a[maxn];
int pos[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    pos[a[i]] = i;
  }
  return true;
}

void solve() {
  set<int> s;
  s.insert(-1);
  s.insert(n);
  ll res = 0;
  for (int i = 1; i <= n; i++) {
    auto j = s.lower_bound(pos[i]);
    int r = *j;
    int l = *(--j);
    res += (ll) (pos[i] - l) * (ll) (r - pos[i]) * (ll) i;
    s.insert(pos[i]);
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time: %.18f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
 
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
 
void solve(){
 
 
}

vi a;
int dp[3009][3009][3];

ll d(int i, int s, int t){
    if(i<0 || s<0) return 0;
    return dp[i][s][t];
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();

    int n,s;cin>>n>>s;
    a.resize(n,0);
    rep(i,n)cin>>a[i];

    rep(i,n){
        rep(j,s+1) dp[i][j][1] += d(i-1, j, 1), dp[i][j][1] %= 998244353;
        rep(j,s+1) dp[i][j][1] += d(i-1, j-a[i], 1), dp[i][j][1] %= 998244353;

        dp[i][a[i]][1] += 1, dp[i][a[i]][1] %= 998244353;
        dp[i][0][1] += 1, dp[i][0][1] %= 998244353;

        rep(j,s+1) dp[i][j][2] = d(i,j,1);
        rep(j,s+1) dp[i][j][2] += d(i-1,j,2), dp[i][j][2] %= 998244353;
    }

    cout << d(n-1,s,2);

	return 0;
}
 



Measured memory_bytes: 106112
#include "bits/stdc++.h"

// #define int long long

using namespace std;

signed main(void) {

  int num = 0;
  int n, m; cin >> n >> m;
  vector<int> k(m);
  vector<vector<int>> s(m);
  vector<int> p(m);

  for (int i = 0; i < m; ++i) {
    cin >> k[i];
    s[i] = vector<int>(k[i]);
    for (int j = 0; j < k[i]; ++j) cin >> s[i][j];
  }
  for (int i = 0; i < m; ++i)
    cin >> p[i];

  for (int b = 0; b < pow(2, n); ++b) {
    bitset<10> bs(b);

    bool flag = true;
    
    for (int i = 0; i < m; ++i) {
      int _k = k[i];
      auto _s = s[i];
      int tmp = 0;
      for (int j = 0; j < _k; ++j) {
        if (bs.test(_s[j] - 1))
          ++tmp;
      }
      if (tmp % 2 != p[i]) flag = false;
      if (!flag) break;
    }
    if (flag) ++num;
    
  }

  cout << num << endl;
  
  return 0;
}


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

int main(){
	int N,K;
  	cin >> N >> K;
  	int S=1;
  
  	for (int i = 0; i < N; i++) {
    	if(K < S){
        	S = S + K;
        }
      
      	else {
        	S = S * 2;
        }
    }
  	
  	cout << S << endl;
  
}

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

int main(){
  int n;
  int coins[17];
  for(int i = 0; i < 17; i++)
    coins[i]=(i+1)*(i+1);
  int dp[2][400];
  //fill(dp,dp+400,0);
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  // ツづづ個硬ツ嘉敖づーツ使ツつ、ツつゥ
  for(int j = 0; j < 17; j++){
    memset(dp[(j+1)%2],0,sizeof(dp[(j+1)%2]));
    for(int i = 0; i <= 300; i++){
      for(int k = 0; k <= 400; k++){
	if(i-k*coins[j]>=0)
	  dp[(j+1)%2][i]+=dp[j%2][i-k*coins[j]];
	else
	  break;
      }
    }
  }
  while(cin>>n&&n!=0)
    cout<<dp[1][n]<<endl;
  return 0;
}

Measured memory_bytes: 0
A, B, C = list(map(int, input().split(' ')))
K = int(input())
cnt = 0
flg = 0
while cnt < K:

  if B <= A:
    B *= 2
  elif C <= B:
    C *= 2
  cnt += 1

  if A < B < C:
    flg = 1
    break

if flg == 1:
  print("Yes")
else:
  print("No")

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

vector<int> BIT; //1-indexed

void bitadd(int faddend, int findex){ //call by reference
    for(int i=findex+1; i<BIT.size(); i += (i & -i))BIT[i] += faddend;
    return;
}

int bitsum(int fright){
    int res = 0;
    for(int i=fright+1; i>0; i -= (i & -i))res += BIT[i];
    return res;
}

int main(void){
    int N, Q, cbuf, lbuf, rbuf;
    vector<int> c;
    cin >> N >> Q;
    BIT.assign(N+1, 0);
    vector<int> Colors(N, -1);
    vector<int> colFormer(N, -1);
    vector<int> res(Q);
    vector<vector<pair<int, int>>> query(N);
    for(int i=0; i<N; i++){
        cin >> cbuf;
        cbuf--;
        c.push_back(cbuf);
        colFormer[i]=Colors[cbuf];
        Colors[cbuf]=i;
    }
    for(int iquery=0; iquery<Q; iquery++){
        cin >> lbuf >> rbuf;
        lbuf--;
        rbuf--;
        query[rbuf].push_back(pair<int, int>(iquery, lbuf));
    }
    int iquery_sorted=0;
    for(int curR=0; curR<N; curR++){
        if(colFormer[curR]>=0)bitadd(-1, colFormer[curR]);
        bitadd(1, curR);
        int rightsum = 0;
        int querysize = query[curR].size();
        if(querysize > 0)rightsum = bitsum(curR);
        for(int i=0; i<querysize; i++){
            res[query[curR][i].first] = rightsum - bitsum(query[curR][i].second-1);
        }
    }
    for(int iquery=0; iquery<Q; iquery++)cout << res[iquery] << endl;
    return 0;
}

Measured memory_bytes: 35116
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int n;
vector<int> a;
vector<long long> aSum;

pair<long long, long long> solve(int threshold)
{
    long long cnt = 0;
    long long sum = 0;
    int j = 0;
    for(int i=n-1; i>=0; --i){
        while(j < n && threshold <= a[i] + a[j])
            ++ j;
        cnt += j;
        sum += a[i] * (long long)j + aSum[j];
    }
    return make_pair(cnt, sum);
}

int main()
{
    long long m;
    cin >> n >> m;
    a.resize(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    sort(a.rbegin(), a.rend());

    aSum.assign(n+1, 0);
    for(int i=0; i<n; ++i)
        aSum[i+1] = aSum[i] + a[i];

    int left = 0;
    int right = 200001;
    while(left < right){
        int mid = (left + right) / 2;
        long long cnt, sum;
        tie(cnt, sum) = solve(mid);
        if(cnt <= m)
            right = mid;
        else
            left = mid + 1;
    }

    long long cnt, sum;
    tie(cnt, sum) = solve(left);
    sum += (m - cnt) * (left - 1);
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cmath>
 
using namespace std;
 
int main(){
    double a, b, c, d, e, f;
    double x, y;
    while(cin >> a >> b >> c >> d >> e >> f){
    	x = (c * e - f * b) / (a * e - d * b);
    	y = (a * f - d * c) / (a * e - d * b);
    	if(abs(x) < 0.0001) x = 0;
    	if(abs(y) < 0.0001) y = 0;
    	printf("%.3f %.3f\n", x, y);
    }
    return 0;
}

Measured memory_bytes: 1236
a,b,c,x,y = map(int,input().split())

ans = float("inf")

for i in range(3*10**5):
    tmp = 0
    tmp += c * i
    tmp += max(a * (x - i // 2), 0)
    tmp += max(b * (y - i // 2), 0)
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 3064
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int[] s=new int[m];
    int[] c=new int[m];
    for(int i=0;i<m;i++){
      s[i]=sc.nextInt();
      c[i]=sc.nextInt();
    }
    for(int i=0;i<1000;i++){
      String str=String.valueOf(i);
      if(str.length()==n){
        boolean flag=true;
        for(int j=0;j<m;j++){
          flag=flag&&(str.charAt(s[j]-1)==c[j]+'0');
        }
        if(flag){
          System.out.println(i);
          return;
        }
      }
    }
    System.out.println(-1);
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,M;cin >> N >> M;
  string s;cin >> s;
  int count = 0;
  rep(i,N+1){
    if(s[i] == '1')++count;
    else count = 0;
    if(count >= M){
      cout << -1 << endl;
      return 0;
    }
  }

  reverse(all(s));
  vector<int> ans;
  int index = 0;
  while(index < N){
    perr(n,1,min(M+1,N+1-index)){
      if(s[index+n] == '0'){
        index += n;
        ans.emplace_back(n);
        break;
      }
    }
  }
  reverse(all(ans));
  for(int a:ans) cout << a SPF;
  cout << endl;

  return 0;
}


Measured memory_bytes: 1096
#include <array>
#include <iostream>
#include <string>

int N;
std::string S;

std::array<long long int, 4005> sumR, sumG, sumB;

int main()
{
    std::cin >> N;
    std::cin >> S;

    sumR.fill(0);
    sumG.fill(0);
    sumB.fill(0);

    for (int i = 1; i <= N; ++i)
    {
        auto c = S[i - 1];

        sumR[i] = sumR[i - 1];
        sumG[i] = sumG[i - 1];
        sumB[i] = sumB[i - 1];

        if (c == 'R')
            sumR[i]++;
        else if (c == 'G')
            sumG[i]++;
        else if (c == 'B')
            sumB[i]++;
    }

    long long int ans = 0;
    for (int j = 2; j <= N - 1; ++j)
    {
        for (int k = j + 1; k <= N; ++k)
        {
            auto cj = S[j - 1];
            auto ck = S[k - 1];
            auto ieq = 2 * j - k - 1;
            if (cj == ck)
                continue;
            if ((cj == 'R' && ck == 'G') || (cj == 'G' && ck == 'R'))
            {
                ans += sumB[j - 1];
                if (ieq >= 0 && S[ieq] == 'B')
                {
                    ans--;
                }
            }
            else if ((cj == 'R' && ck == 'B') || (cj == 'B' && ck == 'R'))
            {
                ans += sumG[j - 1];
                if (ieq >= 0 && S[ieq] == 'G')
                {
                    ans--;
                }
            }
            else if ((cj == 'B' && ck == 'G') || (cj == 'G' && ck == 'B'))
            {
                ans += sumR[j - 1];
                if (ieq >= 0 && S[ieq] == 'R')
                {
                    ans--;
                }
            }
        }
    }

    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define eps 1e-6
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n>>a;
 // ll ar[n+2]={0};
 vector<ll>ar(n+2);
  //ll br[n]={0};
  vector<ll>br(n);
  ar[n]=1;
 // ar[n-1]=1;
  while(a--)
  {
    cin>>m;
    br[m]=1;
  }
  per(i,n-1,-1)
  {
    if(br[i]) continue ;
    ar[i]=(ar[i+1]+ar[i+2])%l;
  }
  cout<<ar[0];
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

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

using namespace std;

const int N = 1e5 + 5;

int n, a[N];

int main() {
  long long lo = 2, hi = 2;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
  }
  for (int i = n-1; i >= 0; --i) {
    long long low = 1LL * (lo+a[i]-1)/a[i] * a[i], hig = 1LL * (hi) / a[i] * a[i];
    if (low > hig) {
      puts("-1");
      return 0;
    }
    hig += a[i]-1;
    lo = low;
    hi = hig;
  }
  printf("%lld %lld\n", lo, hi);
  return 0;
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
#define M map
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
    ll n, k; cin >> n >> k;
    V<ll> a(n + 1);
    for(ll i = 1; i <= n; i++) cin >> a[i];

    V<bool> visit(n + 1);
    V<ll> root;
    ll now = 1;
    while(1){
        if(visit[now]) break;
        root.push_back(now);
        visit[now] = true;
        now = a[now];
    }

    // ループのスタート地点
    int s = find(all(root), now) - root.begin();
    // ループの周期
    int r = (int)root.size() - s;

    if(k < s) cout << root[k] << endl; // ループに到達しない場合
    else cout << root[(k - s) % r + s] << endl; // スタート地点までを引いて剰余で求める

}


Measured memory_bytes: 6860
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
template<typename T>
void print_to(std::ostream &os,const char *,const char *tail,const T &fst){
  os<<fst<<tail;
}
template<typename Fst,typename... Rst>
void print_to(std::ostream &os,const char *del,const char *tail,const Fst &fst,const Rst &... rst){
  os<<fst<<del;
  print_to(os,del,tail,rst...);
}
template<typename Iter>
void print_to_(std::ostream &os,const char *del,const char *tail,Iter bgn,Iter end){
  for(Iter it=bgn;it!=end;){
    os<<*it;
    if(++it!=end)os<<del;
    else os<<tail;
  }
}
template<typename Fst,typename... Rst>
void println(const Fst &fst,const Rst &... rst){
  print_to(std::cout,"\n","\n",fst,rst...);
}
template<typename Fst,typename... Rst>
void print(const Fst &fst,const Rst &... rst){
  print_to(std::cout," ","\n",fst,rst...);
}
template<typename Iter>
void println_(Iter bgn,Iter end){
  print_to_(std::cout," ","\n",bgn,end);
}
using namespace std;
const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;
ll mae[100001];
ll ato[100001];

ll inverse(ll a){
  ll now=MOD-2;
  ll res=1;
  while(now!=0){
    if(now&1)res=(res%MOD)*(a%MOD)%MOD;
    now>>=1;
    a=(a%MOD)*(a%MOD)%MOD;
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  ll a,b;
  cin>>h>>w>>a>>b;
  ll now=1;
  ll left=b-1;
  for(int i=0;i<h-a;i++){
    mae[i]=now;
    left++;
    now=((now%MOD)*(left%MOD))%MOD;
    now=((now%MOD)*(inverse(i+1)%MOD))%MOD;
  }
  now=1;
  left=w-b-1;
  for(int i=0;i<h;i++){
    if(h-i-1<h-a){ato[h-i-1]=now;}
    left++;
    now=((now%MOD)*(left%MOD))%MOD;
    now=((now%MOD)*(inverse(i+1)%MOD))%MOD;
  }
  ll ans=0;
  for(int i=0;i<h-a;i++){
    ans+=((mae[i]%MOD)*(ato[i]%MOD))%MOD;
    ans+=MOD;
    ans%=MOD;
  }
  print(ans);
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}






Measured memory_bytes: 1664
#078-C 
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,z,w=IL()
a=IL()
if n==1:
    print(abs(a[-1]-w))
else:
    print(max(abs(a[-1]-w),abs(a[-1]-a[-2])))

Measured memory_bytes: 3188
N,M=(int(x) for x in input().split())
A = list(map(int, input().split()))
count=0
sum=0

for i in range(N):
    sum+=A[i]

for i in range(N):
    if(A[i])>=(sum * (1/(4*M))):
        count=count+1

if(count>=M):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>

#define rep(i,n)	for(int i = 0;i < n;i++)
#define rep2(i,n)	for(int i = 1;i <= n;i++)
#define each(i,x)	for(auto & i : x)

using namespace std;

int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(cin.eof())
		{
			break;
		}
		int k = 1;
		rep2(j,n)
		{
			k += j;
		}
		cout << k << endl;
	}
	return 0;
}

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

const int MaxN=1e5+5;

int N,H=1,T=1;
int Fa[MaxN];

pair<int,int> Q[MaxN<<1];
set<int> To[MaxN];
map<int,int> Map[MaxN];
set<int>::iterator it1,it2;

int Get_Fa(int x){
	return x==Fa[x]?x:Fa[x]=Get_Fa(Fa[x]);
}

void Add(int u,int v){
	if(u>v)
		swap(u,v);
	To[u].insert(v);
	To[v].insert(u);
	if(++Map[u][v]>1)
		Q[T++]=make_pair(u,v);
}

void Del(int u,int v){
	if(u>v)
		swap(u,v);
	To[u].erase(v);
	To[v].erase(u);
	Map[u][v]=0;
}

int main(){
	int i,u,v,r1,r2;
	scanf("%d",&N);
	for(i=1;i<=N-1<<1;i++){
		scanf("%d%d",&u,&v);
		Add(u,v);
	}
	for(i=1;i<=N;i++)
		Fa[i]=i;
	for(i=1;i<N;i++){
		if(H==T){
			puts("NO");
			return 0;
		}
		u=Q[H].first,v=Q[H].second,H++;
		if(To[r1=Get_Fa(u)].size()>To[r2=Get_Fa(v)].size())
			swap(r1,r2);
		Fa[r1]=r2;
		Del(r1,r2);
		for(it1=To[r1].begin();it1!=To[r1].end();it1=it2){
			it2=it1;
			it2++;
			Del(r1,*it1);
			Add(r2,*it1);
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 39040
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


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

    int n;
    cin >> n;
    vector<vector<char>> s(8,vector<char>(8,'.'));
    
    rep(i,n) {
        int a,b;
        cin >> a >> b;
        s[a][b]='Q';
    }
    vector<int> a(8);
    rep(i,8) a[i]=i;
    do
    {
        vector<vector<char>> t(8,vector<char>(8));
        copy(s.begin(),s.end(),t.begin());
        bool flag=1;
        rep(i,8) {
            if (t[i][a[i]]=='#') {
                flag=0;
            } else {
                rep(j,8) {
                    rep(k,8) {
                        if (j==i || k==a[i] || j+k==i+a[i] || j-k==i-a[i]) {
                            if (t[j][k]=='Q' && !(j==i && k==a[i])) flag=0;
                            t[j][k]='#';
                        }
                    }
                }
                t[i][a[i]]='Q';
            }
        }
        if (flag) {
            rep(i,8) s[i][a[i]]='Q';
        }
    } while (next_permutation(a.begin(), a.end()));

    rep(i,8) {
        rep(j,8) cout << s[i][j];
        cout << endl;
    }

    return 0;   
}



Measured memory_bytes: 3220
def a_plus_problem(N, A, B):
    if A > B:
        return 0  # 最小がA,最大がBであることと矛盾
    if N == 1:  # 最小と最大が一致していれば1通り、していなければ矛盾
        if A == B:
            return 1
        else:
            return 0
    # 区間[A,B]からN-2個選ぶ。区間[(N-1)A+B,A+(N-1)B]内の数はすべて作れる
    return (B - A) * (N - 2) + 1

N, A, B = [int(i) for i in input().split()]
print(a_plus_problem(N, A, B))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main() {
	string x;
	cin>>x;
	int i,a=0,b=0;
	for(i=0;i<3;i++)
	{
		if(x[i]=='A') a++;
		else b++;
	}
	if(a*b!=0) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
	
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    fact();
    cin >> N >> K;
    REP(i, 1, K) {
        int red = N - K;
        int a = C(red + 1, i);
        int free = K - i;
        int b = Div(Div(F[free + i - 1], F[free]), F[i - 1]);
        cout << Mul(a, b) << endl;
    }



    return 0;
}
// x x o 
// 3C1 = 3
//
// x o x o | o x o x | o x x o
// 
// x x x x x o o
// x o x x o x x

// o o
// o |
// | | 

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

bool check(string s, char c) {
  rep(i, s.size()) if(s[i] != c) return false;
  return true;
}

map<string, int> mp;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;
  int ans = inf;
  for(char c = 'a'; c <= 'z'; c++) {
    queue<string> que;
    mp.clear();
    que.push(s);
    mp[s] = 0;
    while(1) {
      string t = que.front(); que.pop();
      if(check(t, c)) {
	chmin(ans, mp[t]);
	break;
      }
      string nt = "";
      rep(i, t.size()-1) {
	if(t[i] == c || t[i+1] == c) nt += c;
	else nt += t[i];
      }
      if(mp.count(nt)) continue;
      mp[nt] = mp[t]+1;
      que.push(nt);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll; 
const int Max = 2e5 + 5;
int n, k;
int a[Max];
bool cmp(int a, int b){
	return a > b;
}

int main(){
	cin >> n >> k;
	int tot = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		tot += a[i];
	}
	sort(a, a+n, cmp);
	int flag = 1;
	for(int i = 0; i < k; i++){
		if(a[i] < tot/(4*k) || (a[i] == tot/(4*k) && tot%(4*k) != 0)){
			flag = 0;
			break;
		}
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;

const int N = 1e5 + 5, oo = 1e9;


int main()
{
    string s;
    cin >> s;
    cout << (s.find('7') != -1 ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
#include <stack>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF INT_MAX>>1 //要climits#includ

typedef long long ll;

using namespace std;

int main(void){
	int a, p; cin >> a >> p;
	cout << (a*3+p)/2 << endl;


	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

a.sort()
ans = True
if n%2:
  key=0
  if a[0] != key:
    ans = False
  p = 1
else:
  key=1
  if a[0] != key or a[1] != key:
    ans = False
  p = 2

for i in range(p, n):
  if i%2 == n%2:
    key += 2
  if a[i] != key:
    ans = False
    break

if ans:
  print(pow(2, n//2, 10**9+7))
else:
  print(0)


Measured memory_bytes: 13880
import scala.math.abs

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val ps = Seq.fill(n, 2)(sc.nextInt)
    if (n == 1) {
      println(1)
      return
    }
    val deltas = for (i <- 0 until n; j <- i + 1 until n) yield {
      val (x1, y1) = (ps(i)(0), ps(i)(1))
      val (x2, y2) = (ps(j)(0), ps(j)(1))
      if (x1 == x2) {
        (0, abs(y1 - y2))
      } else if (x2 > x1) {
        (x2 - x1, y2 - y1)
      } else {
        (x1 - x2, y1 - y2)
      }
    }
    val count = deltas.groupBy(identity).mapValues(_.size).toSeq.map(_._2).max
    println(n - count)
  }
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    int now = 1;
    int ans = 0;
    rep(i, N) {
        if (A[i] == now) {
            ans++;
            now++;
        }
    }

    if (now == 1) {
        puts("-1");
    } else {
        cout << N - ans << endl;
    }
}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int[] ab = sc.intarr;
            int a = ab[0];
            int b = ab[1];

            int output = 0;

            for (int i = 0; i < 2; i++)
            {
                if (a > b)
                {
                    output += a;
                    a -= 1;
                }
                else
                {
                    output += b;
                    b -= 1;
                }
            }



            wr.wri(output);
        }
    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=a;i<(b);++i)
#define CLEAR(a,v) memset(a,v,sizeof(a))
using namespace std;

int main(){
    int N;
    cin >> N;
    long long ret = 0;
    bool prev = false;
    REP(i,N){
        int A;
        cin >> A;
        if(i!=0 && prev && A > 0){
            ret++;
            A--;
        }
        ret += A / 2;
        prev = A%2 == 1;
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	
    char a[110], b[110], c[110], s='a';
   
    int ap=0, bp=0,cp=0;
    scanf("%s",a);
    scanf("%s",b);
    scanf("%s",c);
    
    while(1){
    	if(s=='a'){
    		if(a[ap]!='\0'){
    			s=a[ap];
				ap++;
    			
			}
			
			else{
				printf("A");
				return 0;
			}
		}
		
		
			if(s=='b'){
    		if(b[bp]!='\0'){
    			s=b[bp];
				bp++;
    			
			}
			
			else{
				printf("B");
				return 0;
			}
		}
		
		
			if(s=='c'){
    		if(c[cp]!='\0'){
    			s=c[cp];
				cp++;
    			
			}
			
			else{
				printf("C");
				return 0;
			}
		}
	}
}

Measured memory_bytes: 128
//解説版
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
int main(){
    string s; cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
res = ['AC', 'WA', 'TLE', 'RE']
ans = [0] * 4

for i in range(N):
    s = input()
    idx = res.index(s)
    ans[idx] += 1

for r, n in zip(res, ans):
    print(r, 'x', n)

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

using namespace std;
typedef long long ll;
const int MAXN = 100100;

int N;
pair <int, int> event[MAXN];
ll ans[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> event[i].first;
        event[i].first = -event[i].first;
        event[i].second = i;
    }

    sort (event, event + N);
    int clo = N;
    ll csum = 0;
    for (int i = 0; i < N; i++)
    {
        ll xv = -event[i].first;
        int ind = event[i].second;

        if (ind < clo)
        {
            ans[clo] += csum - i * xv;
            csum = i * xv;
            clo = ind;
        }

        csum += xv;
    }
    ans[clo] += csum;

    for (int i = 0; i < N; i++)
    {
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 2688
//trial

#include <bits/stdc++.h>

using namespace std;

int main(){
	map<int,int> list;

	int n,q,temp,b,c;
	long long int sum = 0;
	cin  >> n;

	while (n--){
		cin >> temp;
		sum += temp;
		
		auto check = list.find(temp);

		if (check != list.end()) list[temp]++;
		else list[temp] = 1;
	}

	cin >> q;
	//cout << q << endl;

	//edits
	while (q--){
		//take input
		cin >> b >> c;

		//check if present
		auto check = list.find(b);
		auto yeet = list.find(c);

		//item is present
		if (check != list.end()){
			//number of b's
			temp = list[b];

			//change and print
			sum += (temp*(c-b));
			cout << sum << endl;

			//change database
			list.erase(b);
			if (yeet != list.end()) list[c] += temp;
			else list[c] = temp;

		}
		//no such key, nothing happens
		else cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 6432
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

struct BOX{
  int s, r, l;
  BOX(){}
  BOX(int a, int b, int c){
    s = a; r = b; l = c;
  }
};

int main(){
  string S;
  cin >> S;
  vector<BOX> box(0);
  for(int i = 0; i < S.size(); i++){
    int counter = 0;
    int rr, ll;
    for(int j = i; j < S.size(); j++){
      counter++;
      if(j == S.size()-1){
        i = S.size()-1;
        break;
      }

      if(S.at(j) == 'R'){
        if(S.at(j+1) == 'L'){
          rr = counter; ll = counter+1;
        }
      }
      else if(S.at(j+1) == 'L'){
      }
      else{
        i = j;
        break;
      }
    }
    box.push_back(BOX(counter, rr, ll));
  }

  //for(auto x: box) cout << x.s << ' ' << x.r << ' ' << x.l << endl;
  int bsize = box.size();
  vi rnum(bsize); //中央のRの人数
  vi lnum(bsize); //中央のLの人数
  for(int i = 0; i < bsize; i++){
    int rr = box.at(i).r;
    int ll = box.at(i).s - box.at(i).r;
    rnum.at(i) = (rr+1)/2 + ll/2;
    lnum.at(i) = (ll+1)/2 + rr/2;
    for(int j = 0; j < rr-1; j++){
      cout << "0 ";
    }

    cout << rnum.at(i) << ' ' << lnum.at(i);
    if(i == bsize-1 && box.at(i).l == 1) cout << endl;
    else cout << ' ';

    for(int j= 0; j < ll-1; j++){
      cout << "0";
      if(i == bsize-1 && j == ll-2) cout << endl;
      else cout << ' ';
    }
  }
  cout << endl;
}

Measured memory_bytes: 1592
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#define INF 1e16
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;
typedef pair<long long, int> P;

int main() {
    int N;
    cin >> N;
    vector<vector<pair<int, long long>>> Graph(N);
    rep(i, N - 1) {
        int u, v;
        long long w;
        cin >> u >> v >> w;
        Graph[u - 1].push_back(make_pair(v - 1, w));
        Graph[v - 1].push_back(make_pair(u - 1, w));
    }
    
    vector<long long> dist(N, INF);
    vector<bool> used(N, false);
    priority_queue<P, vector<P>, greater<P>> pq;
    dist[0] = 0;
    pq.push(make_pair(0LL, 0));
    while (pq.size() > 0) {
        int ver = pq.top().second;
        long long cost = pq.top().first;
        pq.pop();
        if (used[ver]) continue;
        for (auto x : Graph[ver]) {
            int v = x.first;
            long long alt = cost + x.second;
            if (alt < dist[v]) {
                dist[v] = alt;
                pq.push(make_pair(alt, v));
            }
        }
        used[ver] = true;
    }
    
    rep(i, N) cout << dist[i] % 2 << endl;
    return 0;
}


Measured memory_bytes: 8704
#include <iostream>

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

const long long INF = 1LL << 60;

using namespace std;

int main() {
    int n; cin >> n;
    long long h[100010], dp[100010];
    for (int i = 0; i < n; ++i) cin >> h[i];
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1792