akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

public class Prog
{
    public void run()
    {
        int N = int.Parse(Console.ReadLine());
        var input = Console.ReadLine().Split();
        int[] W = Array.ConvertAll(input, int.Parse);
        int sum = W.Sum();
        int ans = 0;
        int S1 = 0;
        int S2 = 0;
        for(int i = 0; i < N; i++)
        {
            S1 += W[i];
            S2 = sum - S1;
            if(S1 == S2)
            {
                ans = 0;
                break;
            }
            else if(S1 > S2)
            {
                ans = Math.Min(S1 - S2,ans);
                break;
            }
            else
            {
                ans = S2 - S1;
            }
        }
        Console.WriteLine(ans);
    }
    public static void Main()
    {
        //var input = Console.ReadLine().Split();
        //int[] X = Array.ConvertAll(input, int.Parse);
        var prog = new Prog();
        prog.run();
    }
}

//Array.ConvertAll(int.Parse)

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define ll long long

vector<int> v[nn],c[nn];
int n;


#define pll pair<ll,ll>
#define mp make_pair

vector<pll> merge(vector<pll> a,vector<pll> b)
{
	vector<pll> tp;
	int i=0,j=0;
	while(i<a.size() or j<b.size())
	{
		if(i<a.size() and j<b.size() and a[i].first==b[j].first)
		{
			tp.push_back(min(a[i],b[j]));
			i++,j++;
		}
		else if(i<a.size() and (j>=b.size() or a[i].first<b[j].first) )
		{
			tp.push_back(a[i]);
			i++;
		}
		else
		{
			tp.push_back(b[j]);
			j++;
		}
	}
	sort(tp.begin(),tp.end());

	if(tp.size()==0) return tp;
	vector<pll> cp;cp.push_back(tp[tp.size()-1]);
	for(int i=tp.size()-1;~i;i--)
	{
		if(tp[i].first==cp[cp.size()-1].first)
		{
			cp[cp.size()-1]=min(cp[cp.size()-1],tp[i]);
			continue;
		}
		if(tp[i].second<cp[cp.size()-1].second)
			cp.push_back(tp[i]);
		else if(tp[i].second==cp[cp.size()-1].second) cp[cp.size()-1]=max(cp[cp.size()-1],tp[i]);
	}
	reverse(cp.begin(),cp.end());
	return cp;
}
vector<pll> work(vector<pll> lc,vector<pll> rc,ll pr,ll pl,ll ce)
{
	vector<pll> tp;
	int i=lc.size()-1,j=rc.size()-1;
	ll es=1e15;ll ces=es;
	while( ~j)
	{
		ll x=rc[j].first-pr;
		
	//	if(ce) cout<<i<<" "<<j<<"\n";
		if(~i and rc[j].second+pl+pr<=lc[i].first)
		{
			es=min(es,lc[i].second+pl);
			i--;
		}
		else
		{
			if(es<1e15 ) tp.push_back(mp(x,es));// ensure complexity
			j--;ces=es;
		}
		
	}
	sort(tp.begin(),tp.end());
	if(tp.size()==0) return tp;
	vector<pll> cp;cp.push_back(tp[tp.size()-1]);
	for(int i=tp.size()-1;~i;i--)
	{
		if(tp[i].first==cp[cp.size()-1].first)
		{
			cp[cp.size()-1]=min(cp[cp.size()-1],tp[i]);
			continue;
		}
		if(tp[i].second<cp[cp.size()-1].second)
			cp.push_back(tp[i]);
		else if(tp[i].second==cp[cp.size()-1].second) cp[cp.size()-1]=max(cp[cp.size()-1],tp[i]);
	}
	reverse(cp.begin(),cp.end());
	return cp;
}


ll lim;
vector<pll> dfs(int x)
{
	vector<pll>tp;//now i mean   howmuch can be up & mini out
	if(v[x].size()==0)
	{
		tp.push_back(mp(lim,0));
	}
	else
	{
		vector<pll> lc,rc;
		assert(v[x].size()==2);
		ll pl=c[x][0],pr=c[x][1];
		lc=dfs(v[x][0]),rc=dfs(v[x][1]);
		vector<pll> fl,fr;
		int ce=0;
		if(x==1) ce=1;//spjajjjjjjjjjjjj
		fl=work(lc,rc,pr,pl,ce);
		fr=work(rc,lc,pl,pr,ce);
	
		tp=merge(fl,fr);
	}
	
//	for(int i=1;i<tp.size();i++) assert(tp[i].first>tp[i-1].first),assert(tp[i].second>tp[i-1].second);
//	cout<<x<<":\n";
//	for(int i=0;i<tp.size();i++) cout<<tp[i].first<<"  "<<tp[i].second<<"\n";
//	system("pause");
	return tp;
}

int check(ll mid)
{
	lim=mid;
	vector<pll> tp=dfs(1);
	for(int i=0;i<tp.size();i++)
		return 1;
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		int p,w;scanf("%d%d",&p,&w);
		v[p].push_back(i);c[p].push_back(w);
	}
	ll l=0,r=1e12;ll ans=-1;
	while(l<=r)
	{
		ll mid=(l+r)/2;
		if(check(mid))
			r=mid-1,ans=mid;
		else l=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 49408
import math  
  
# method to print the divisors 
def printDivisors(n,arr) : 
      
    # Note that this loop runs till square root 
    i = 1
    while i <= math.sqrt(n): 
          
        if (n % i == 0) : 
              
            # If divisors are equal, print only one 
            if (n // i == i) : 
                arr.append(i)
            else:
                arr.append(i)
                arr.append(n//i) 
        i = i + 1

n,k=map(int,input().split())
arr=list(map(int,input().split()))
for i in range(n):
    arr[i]=abs(arr[i]-k)
arrx=[]
printDivisors(min(arr),arrx)
arrx.sort(reverse=True)
for i in range(len(arrx)):
    flag=0
    for j in range(len(arr)):
        if(arr[j]%arrx[i]!=0):
            flag=1
            break
    if(flag==0):
        print(arrx[i])
        exit(0)


Measured memory_bytes: 15020
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int main() {
	int N;
	scanf("%d", &N);

	if (N <= 999) printf("ABC\n");
	else printf("ABD\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int ans = 0;
    ans += min(A, K);
    K -= min(A, K);
    K -= min(B, K);
    ans -= min(C, K);
    K -= min(C, K);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int dd[10] = { 0 };
	int p;
	for (int i = 0; i < k; i++) {
		cin >> p;
		dd[p] = 1;
	}
	for (int i = n;; i++) {
		int r = i;
		bool h = true;
		while (r > 0) {
			if (dd[r % 10] == 1) {
				h = false;
				break;
			}
			r /= 10;
		}
		if (h) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

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

int main(){
    long long n, h;
    while( cin >> h >> n ){
        for( int i = 0; i < n; i++ ){
            long long a; cin >> a;
            h -= a;
        }
        if( h <= 0 ){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;
bool dp[N];
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      int a[6]={100,101,102,103,104,105};
      int x;
      cin>>x;
      dp[0]=true;
      for(int i=1;i<=x;i++)
      {
        for(int j=0;j<6;j++)
        {
          if(i-a[j]>=0) dp[i]|=dp[i-a[j]];
        }
      }
      cout<<dp[x];
}
// I never lose. I either win or I learn

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

int main()
{
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    string all_s = "";
    rep(i, n)
    {
        cin >> s.at(i);
    }

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

    rep(i, n)
    {
        all_s += s.at(i);
    }

    cout << all_s << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
N = int(input())

X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

def BFS(n, E, i0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 0
    while Q:
        x = Q.popleft()
        for c in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return D

A = BFS(N, X, 0)
B = BFS(N, X, N-1)
print("Snuke" if sum([A[i] <= B[i] for i in range(N)]) * 2 <= N else "Fennec")

Measured memory_bytes: 63536
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

const ll MOD = 1e9 + 7;

ll power(ll x,ll y){

    if(y < 0) return 1;
    ll res = 1;

    while(y){
        if(y&1) res = (res*x)%MOD;
        x = (x*x)%MOD;
        y >>= 1;
    }
    return res;
}

const ll MAXN = 2005;
ll fact[MAXN];

ll nCr(ll n,ll r){
    if(r > n) return 0;
    ll ret = (fact[n]*power(fact[n-r],MOD-2))%MOD;
    ret = (ret * power(fact[r],MOD-2))%MOD;
    return ret;
}


void solve(){ 

    fact[0] = 1;
    FOR(i,1,2000) fact[i] = (fact[i-1]*i)%MOD;
    ll n,k;
    cin>>n>>k;
   
    FOR(i,1,k){
        ll ans = nCr(k-1,i-1);
        clog<<ans<<endl;
        ll nn = n-k-(i-1);
        ll rr = i+1;
        ans = (ans * nCr(nn+rr-1,rr-1))%MOD;
        cout<<ans<<endl;
    }
}

signed main(){

   FastRead;    


    ll t;
    t = 1; 
    //cin>>t;
    FOR(i,1,t){
        // cout<<"Case "<<i<<":\n";
        solve();
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
	char ch[200];
	int m;
	int h,i,j,k;
	char str[200];

	while(1){
		scanf("%s", ch);
		if(ch[0]=='-')
			break;
		scanf("%d", &m);
		for(i=0; i<m; i++){
			scanf("%d", &h);
			strncpy(str,ch,h);			
			for(j=h; j<strlen(ch); j++){
				ch[j-h] = ch[j];
			}
			for(k=0; k<h; k++){
				ch[strlen(ch)-h+k] = str[k]; 
			}
		}
		printf("%s\n",ch);

	}

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>

using namespace std;

unsigned long long roundup_div(unsigned long long m, unsigned long long d) {
    unsigned long long ans = m/d;
    if(m%d>0uLL) ++ans;
    return ans;
}

int main(int argc, char const *argv[])
{
    unsigned long long n, x=~0uLL, z;
    cin >> n;

    for(int i=0;i<5;++i) {
        cin >> z;
        x = min(x,z);
    }

    cout << roundup_div(n,x) +4 << endl;

    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int v[n];
    int i;
    for (i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    int q;
    cin >> q;
    while (q--)
    {
        int a, b, c;
        cin >> a >> b >> c;
        swap_ranges(v + a, v + b, v + c);
    }
    for (i = 0; i < n; i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3104
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    var N = input.nextInt()
    val K = input.nextInt()
    var digit = 0
    
    while (N > 0) {
      N /= K
      ++digit
    }
    
    println(digit)
  }
}

Measured memory_bytes: 36392
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  int N;
  string S;
  cin >> N >> S;

  int op = 0;
  int cl = 0;
  REP(i, S.size()) {
    if (S[i] == '(') {
      op++;
    } else {
      op--;
    }
    cl = min(cl, op);
  }
  REP(i, -cl) {
    cout << '(';
    op++;
  }
  cout << S;
  REP(i, op) {
    cout << ')';
  }
  cout << endl;
  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64_t N;
  cin >> N;
  int res = 0;
  if (N == 2) {
    cout << 1 << '\n';
    return 0;
  }
  for (int64_t i = 2; i * i < N + 1; i++) {
    if ((N - 1) % i == 0) {
      res += (i * i == N - 1 ? 1 : 2);
    }
    if (N % i == 0) {
      int64_t x = N;
      while (x % i == 0) {
        x /= i;
      }
      if (x % i == 1) res++;
    }
  }
  cout << res + 2 << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is >> *i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    vector<int> a(n);
    cin>>a;
    vector<int> cnt(100005);
    REP(i,n) {
        cnt[a[i]]++;
        cnt[a[i]+1]++;
        cnt[a[i]+2]++;
    }
    int ans=0;
    REP(i,100005) {
        chmax(ans,cnt[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
H = gets.chomp.to_i
hKeys = gets.chomp.split(' ').map(&:to_i)
hKeys.unshift(nil)

def maxHeapify(array, i)
    l = i * 2
    r = i * 2 + 1
    if l <= H && array[l] > array[i] then
        largest = l
    else
        largest = i
    end
    if r <= H && array[r] > array[largest] then
        largest = r
    end
    
    if largest != i then
        tmp = array[i]
        array[i] = array[largest]
        array[largest] = tmp
        maxHeapify(array, largest)
    end
end

(H / 2).downto(1) do |i|
    maxHeapify(hKeys, i)
end

puts hKeys.join(' ')


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

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int n, x;
  cin >> n >> x;

  int count = 0;
  for(int i = 0; i <= n; ++i)
    for(int j = 0; j <= n; ++j) {
      int k = x - i - j;
      if(k >= 0 &&  k <= n) count++;
    }
  cout << count << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt=1;
  //cin >> T;
  while(tt--) solve();

  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
          char c;
          cin>>c;
          c++;
          cout<<c<<endl;
}


Measured memory_bytes: 256
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val r = Array.fill(m*2)(sc.nextInt())
  val ret = r.groupMapReduce(identity)(_ => 1)(_ + _)
  (1 to n).foreach(i => if (ret.contains(i)) println(ret(i)) else println(0))
}

Measured memory_bytes: 55500
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

signed main()
{
	fastio();
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int x3, y3, x4, y4;
	x3 = x2 - (y2 - y1);
	y3 = y2 + (x2 - x1);
	x4 = x3 - (y3 - y2);
		y4 = y3 + (x3 - x2);
		cout << x3 << " " << y3 << " " << x4 << " " << y4;
	system("pause");
}

Measured memory_bytes: 504
def myAnswer(N:int,A:list) -> int:
   av = sum(A)//N
   tmp1 = 0
   tmp2 = 0
   tmp3 = 0
   for a in A:
      tmp1 += (a - av)** 2
      tmp2 += (a - (av + 1)) ** 2
      tmp3 += (a - av - 1) ** 2
   return min(tmp1,tmp2,tmp3)

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N, K; cin >> N >> K;
  string S; cin >> S;
  char x = *min_element(S.begin(), S.end());
  string ans = "~";
  K = min(K, 30);
  rep(i, N+1) {
    string U = S + string(S.rbegin(), S.rend());
    U = U.substr(i, N);
    rep(_, K-2) {
      int k = 0;
      while (k < N && U.rbegin()[k] == x) k++;
      U = U + string(U.rbegin(), U.rend());
      U = U.substr(k, N);
    }
    if (K >= 2) {
      int k = 0;
      while (k < N && U.rbegin()[k] == x) k++;
      U = U + string(U.rbegin(), U.rend());
      U = U.substr(N - k, N);
    }
    ans = min(ans, U);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    if(A>=13)cout<<B<<endl;
    else if(A<=12&&A>=6){cout<<B/2<<endl;}
    else cout<<0<<endl;

return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

int main() {
  ll r,d,x;
  cin>>r>>d>>x;
  rep(i,10){
    x=r*x-d;
    cout << x << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
S = list(input())
Q = int(input())
t_count = 0
before = []
after = []

for i in range(Q):
  list_ = list(input().split())
  T = int(list_[0])
  if T == 1:
    t_count += 1
  else:
    F, C = int(list_[1]), list_[2]
    if F == 1:
      if t_count%2 == 0:
        before.append(C)
      else:
        after.append(C)
    else:
      if t_count%2 == 0:
        after.append(C)
      else:
        before.append(C)
before.reverse()
S.extend(after)
before.extend(S)
if t_count%2 == 1:
  before.reverse() 
ans = ''.join(before)
print(ans)

Measured memory_bytes: 8412
#include<bits/stdc++.h>
using namespace std;
int f[100001];
#define mo 1000000007
int ksm(int a,int b){
	int ans=1;
	while (b){
		if (b&1) ans=1LL*ans*a%mo;
		b>>=1;
		a=1LL*a*a%mo;
	}
	return ans;
}
int main(){
	int i,n,l,r;
	scanf("%d",&n);
	for (i=1;i<=n+1;i++){
		int x;
		scanf("%d",&x);
		if (f[x]){l=f[x]-1; r=n-i+1; break;}
		else f[x]=i;
	}
	printf("%d\n",n);
	int t=l+r;
	int sum1=1,sum=n+1;
	for (i=2;i<=n+1;i++){
		if (t>=i-1) sum1=(1LL*sum1*(t-i+2)%mo*ksm(i-1,mo-2))%mo;
		else sum1=0;
		sum=(1LL*sum*(n-i+2)%mo*ksm(i,mo-2))%mo;
		printf("%d\n",(0LL+sum-sum1+mo)%mo);
	}
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void){
	int a,b;
	cin>>a>>b;
	if(!(a%2) || !(b%2)){
		cout<<"Even"<<endl;
	}else{
		cout<<"Odd"<<endl;
	}
    return 0;
}

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

int main(){
    char ch;
    cin>>ch;
    // Method - 1
    /*
    if(ch >= 'A' && ch <= 'Z'){
        cout<<"A"<<endl;
    }
    else
    {
        cout<<"a"<<endl;
    }
    */

   // Method - 2;
   /*
   if(ch < 97){
       cout<<"A"<<endl;
   }    
   else
   {
       cout<<"a"<<endl;
   }
    */
   // Method - 3

    /*
   if(ch - 'a' >= 0){
       cout<<"a"<<endl;
   }
   else
   {
       cout<<"A"<<endl;
   }
   */
    // Method - 4
   if(ch >= 'a'){
       cout<<"a"<<endl;
   }
   else
   {
       cout<<"A"<<endl;
   }
   
}

Measured memory_bytes: 3604
#include<stdio.h>
int max(int a, int b){return a > b ? a : b;}
int min(int a, int b){return a < b ? a : b;}
int main(){
    int n;
    scanf("%d",&n);
    char c[n + 1];
    scanf("%s",c);
    int ans = 100100100;
    int r = 0;
    int w = 0;
    for(int i = 0; i < n; i++){
        if(c[i] == 'R')
            r++;
        else w++;
    }
    if(w == n || r == n){
        puts("0");
        return 0;
    }
    int leftRed = 0;
    int leftWhite = 0;
    for(int i = 0; i < n; i++){
        if(c[i] == 'R'){
            leftRed++;
            r--;
        }
        else{
            leftWhite++;
            w--;
        }
        int p = max(leftWhite, r);
        ans = min(ans, p);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1924
#include <iostream>
#include <vector>
#include <cmath>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n-1; i >= 0; i--)
using namespace std;

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  int ans;
  int n = min(a, b);
  repr(i, n+1){
    if (a % i == 0 && b % i == 0) k--;
    if (k == 0){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




















int main(){
    string s, t, u;
    ll a, b;
    cin >> s >> t >> a >> b >> u;
    if(s == u){
        cout << a - 1 << " " << b << endl;
    }
    else{
        cout << a << " " << b - 1 << endl;
    }
}

Measured memory_bytes: 256
def answer(s, last)
	return 1 if s.size == 0
	if s.size >= 2 && s[-1] == s[-2]
		a = s.pop
		a = s.pop
		return answer(s, 2) * 3 % 1000000007 if last == 2
		return answer(s, 2) * 2 % 1000000007 if last == 1
		return answer(s, 2) * 6 % 1000000007 if last.nil?
	else
		a = s.pop
		return answer(s, 1) % 1000000007 if last == 2
		return answer(s, 1) * 2 % 1000000007 if last == 1
		return answer(s, 1) * 3 % 1000000007 if last.nil?
	end
end

N = gets.to_i
s = gets.chomp.split(//)
a = gets
p answer(s, nil)


Measured memory_bytes: 1788
#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
#include <string.h>
long long abs(long long);
int main(){
	long long n;
	scanf("%lld", &n);
	long long a[200010];
	long long subsum[200010];
	long long i, j;
	long long t;
	long long minimum=214748364700000;
	long long sum=0;
	long long x=0;
	for(i=1;i<=n;i++){
		scanf("%lld", &a[i]);
		sum+=a[i];
	}
	for(i=1;i<=n-1;i++){
		x+=a[i];
		subsum[i]=abs(2*x-sum);
		if(subsum[i]<minimum) minimum=subsum[i];
	}
	printf("%lld", minimum);
	return 0;
}
long long abs(long long a){
	if(a>=0) return a;
	else return -a;
}

Measured memory_bytes: 1664
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

const int INF = 1 << 29;

void main() {
    auto N = readln.chomp.to!int;

    if (N == 1) {
        writeln(1);
        return;
    }

    auto dist = new int[](N);
    dist.fill(INF);

    auto pq = new BinaryHeap!(Array!(Tuple!(int, int)), "a[1] > b[1]");
    pq.insert(tuple(1, 1));

    while (!pq.empty) {
        auto n = pq.front[0];
        auto c = pq.front[1];
        pq.removeFront;
        if (dist[n] <= c) continue;
        dist[n] = c;
        if (dist[(n+1)%N] > c+1) pq.insert(tuple((n+1)%N, c+1));
        if (dist[(n*10)%N] > c) pq.insert(tuple((n*10)%N, c));
    }

    dist[0].writeln;
}


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

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

int main(){

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

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

  int b[n];
  for(int i=n/2;i<n;i++) b[i] = a[i];

  for(int i=n/2-1;i>=0;i--){
    int sum = 0;
    for(int j=2;j*(i+1)<=n;j++)
      sum += b[j*(i+1)-1];
    b[i] = (a[i] +  sum)%2;
  }

  vector<int> ans;
  rep(i,n) if(b[i]) ans.push_back(i+1);

  cout << ans.size() << endl;
  rep(i,ans.size()) cout << ans[i] << endl;

  return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if ((B-A)%2==0) cout << "Alice" << endl;
  else cout << "Borys" << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];

        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        long cnt = 1;
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 == 0) {
                // even
                cnt *= 2;
            } else {
                // odd
                cnt *= 1;
            }
        }
        System.out.println((int)Math.pow(3, N) - cnt);

        return;
    }

}

Measured memory_bytes: 21840
A,B,C,D=map(int, input().split())
f=C
g=D
while f%g!=0:
  f,g=[g, f%g]
l=C*D//g
m=B//l
n=(A-1)//l
print(B-(B//C)-(B//D)+m-(A-1-((A-1)//C)-((A-1)//D)+n))

Measured memory_bytes: 3064
n = int(input())
p = [int(i) for i in input().split()]

cnt = 0

for i in range(1, n-1):
    x = [p[i-1], p[i], p[i+1]]
    if (x[1] < x[0] and x[1] > x[2]) or (x[1] > x[0] and x[1] < x[2]):
        cnt+=1

print(cnt)

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

using namespace std;

typedef long long ll;

const int MAX_N = 607;
const ll MOD = 1e9 + 7;

int N, K, match[MAX_N], match_mn[MAX_N][MAX_N], match_mx[MAX_N][MAX_N], match_cnt[MAX_N];
ll fac2[MAX_N], F[MAX_N][MAX_N], ans;

ll ways(int l, int r) {
    if (match_mn[l][r] < l || match_mx[l][r] > r) return 0;
    return fac2[r - l + 1 - (match_cnt[r] - match_cnt[l - 1])];
}

int main() {
    scanf("%d%d", &N, &K);
    for (int i = 1; i <= K; i++) {
        int a, b; scanf("%d%d", &a, &b);
        match[a] = b; match[b] = a;
    }
    for (int i = 1; i <= 2 * N; i++) {
        match_mn[i][i - 1] = 2 * N;
        match_mx[i][i - 1] = 1;
        for (int j = i; j <= 2 * N; j++) {
            if (match[j]) {
                match_mn[i][j] = min(match_mn[i][j - 1], match[j]);
                match_mx[i][j] = max(match_mx[i][j - 1], match[j]);
            } else {
                match_mn[i][j] = match_mn[i][j - 1];
                match_mx[i][j] = match_mx[i][j - 1];
            }
        }
    }
    for (int i = 1; i <= 2 * N; i++) match_cnt[i] = match_cnt[i - 1] + (match[i] ? 1 : 0);
    fac2[0] = 1;
    for (int i = 2; i <= 2 * N; i += 2) fac2[i] = fac2[i - 2] * (i - 1) % MOD;
    for (int len = 2; len <= 2 * N; len++) {
        for (int i = 1; i + len - 1 <= 2 * N; i++) {
            int j = i + len - 1;
            F[i][j] = ways(i, j);
            for (int k = i + 1; k < j; k += 2) {
                (F[i][j] += MOD - F[i][k] * ways(k + 1, j) % MOD) %= MOD;
            }
            (ans += F[i][j] * fac2[2 * N - (j - i + 1) - (2 * K - (match_cnt[j] - match_cnt[i - 1]))]) %= MOD;
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 6016
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<cmath>
#include<unordered_set>
using namespace std;

signed main() {
	string a; cin >> a;
	cout << a[0] << a.length() - 2 << a[a.length() - 1] << endl;
}

Measured memory_bytes: 256
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;

    ll arr[n+1],q[n],crr[n+1];
    for(int i=0;i<n;i++){
        cin>>q[i];
    }
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    for(int i=2;i<=n;i++){
        cin>>crr[i];
    }

    ll sum = 0;
    for(int i=0;i<n;i++){
        sum+=arr[q[i]];
        if(i>0){
            if(q[i]==q[i-1]+1){
                sum+=crr[q[i]];
            }
        }
    }
    cout<<sum;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
   long long a,b,k;
   scanf("%lld%lld%lld",&a,&b,&k);
   #include<stdio.h>


   if(a>=k){
      a-=k;
   }else if(a+b>=k){
      k-=a;
      a=0;
      b-=k;
   }else{
      a=0;
      b=0;
   }
   printf("%lld %lld",a,b);
   return 0;
   
}


Measured memory_bytes: 1712
#include <stdio.h>
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    int d=a/b;
    int r=a%b;
    double f=(double)a/b;
    
    printf("%d %d %lf\n",d,r,f);
    
    return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=15;
int n,m,x,c[N],a[N][N];
int f[1<<N][N];
int main()
{
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	}
	int ans=0x3f3f3f3f;
	for(int i=1;i<(1<<n);i++)
	{
		int res[15];
		for(int j=1;j<=m;j++) 
            res[j]=0;
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				for(int k=1;k<=m;k++)
					res[k]+=a[j+1][k];
			}
		}
		bool xx=1;
		int yy=0;
		for(int j=1;j<=m;j++)
			if(res[j]<x)
			{
				xx=0;
				break;
			}
		if(xx)
		{
			for(int j=0;j<n;j++)
				if(i&(1<<j))
					yy+=c[j+1];
			ans=min(ans,yy);
		}
	}
	if(ans==0x3f3f3f3f) puts("-1");
	else
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3636
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,K = MI()
a = LI()

d = {}
for i in range(N):
    d[a[i]] = d.get(a[i],0)+1
num = list(d.values())
num.sort()
n = len(num)
ans = 0
for i in range(n-K):
    ans += num[i]
print(ans)


Measured memory_bytes: 114252
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  double a,b;
  cin >>a >> b;
  int c;
  c = ceil((b-1) / (a-1));

  cout << c;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
  cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
    //配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
// const long mod = 1000000007;
const long mod = 1777777777;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(long &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
//    void solve() {
//       std::string ss; scan(ss);
//       std::vector<std::string> xs;
//       long n = ss.size();
//       for(long i = 0; i < n; ++i) {
//          for(long k = i + 1; k < n; ++k) {
//             char ss2[1000];
//             for(long t = 0; t < n; ++t) ss2[t] = ss[t];
//             ss2[n] = '\0';
//             std::reverse(ss2 + i, ss2 + k + 1);
//             xs.push_back(ss2);
//             printf("%s, i = %ld, k = %ld\n", ss2, i, k);
//          }
//       }
//       std::sort(xs.begin(), xs.end());
//       for(std::string x : xs) {
//          printf("%s\n", x.c_str());
//       }
//       dumpl((long)xs.size());
//       xs.erase(std::unique(xs.begin(), xs.end()), xs.end());
//       dumpl((long)xs.size());
//    }
   void solve() {
      std::string ss; scan(ss);
      LI xs(26, 0);
      for(char c : ss) {
         xs[c-'a'] += 1;
      }
      long n = ss.size();
      long res = n * (n - 1) / 2 + 1;
      for(long i = 0; i < 26; ++i) {
         long x = xs[i];
         res -= x * (x - 1) / 2;
      }
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.LinkedList;

public class Main {
	public static void main(String[] args) {

		// LinkedList型としてインスタンス化
		LinkedList<Integer> list = new LinkedList<>();

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
			int n = Integer.parseInt(br.readLine());
			for (int i = 0; i < n; i++) {
				String[] cmd = br.readLine().split(" ");
				switch (cmd[0]) {
				case "insert":
					// リストの先頭に追加
					list.addFirst(Integer.parseInt(cmd[1]));
					break;

				case "delete":
					// parseIntの戻り値はint型である為、
					// そのまま渡すとremove(int index)が呼び出されてしまう。
					// 明示的にInteger型に変換することで、
					// remove(Object o)メソッドを呼び出す。
					list.remove((Integer) Integer.parseInt(cmd[1]));
					break;

				case "deleteFirst":
					// 先頭の要素を削除
					list.removeFirst();
					break;

				case "deleteLast":
					// 末尾の要素を削除
					list.removeLast();
					break;
				}
			}

			PrintWriter out = new PrintWriter(System.out);
			for (Iterator<Integer> it = list.listIterator(); it.hasNext();) {
				out.print(it.next());
				if (it.hasNext()) {
					out.print(" ");
				} else {
					out.println();
				}
			}
			out.flush();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}


Measured memory_bytes: 203820
import bisect

def calc_distance(frm, x, y):
	return min(abs(frm - x), abs(frm - y) ) + abs(x - y)

def calc_2points(frm, us):
	idx = bisect.bisect_left(us, frm)
	return us[idx - 1], us[idx]

def calc_min(ss, ts, x):
	s1, s2 = calc_2points(x, ss)
	t1, t2 = calc_2points(x, ts)
	ans = min(calc_distance(x, s1, t1), calc_distance(x, s1, t2), calc_distance(x, s2, t1), calc_distance(x, s2, t2))
	return ans

INF = 10 ** 20
a, b, q = list(map(int, input().split()))
ss = [-INF] + [int(input()) for _ in range(a)] + [INF]
ts = [-INF] + [int(input()) for _ in range(b)] + [INF]
xs = [int(input()) for _ in range(q)]

for x in xs:
	print(calc_min(ss, ts, x))

Measured memory_bytes: 16144
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

const int MAX_N = (int)1e5 + 777;

vector<int64> costs[MAX_N];

void solve() {
	int n, k;
	cin >> n >> k;

	for(int i = 0; i < n; ++i) {
		int t;
		int64 d;

		cin >> t >> d;
		costs[t].push_back(d);
	}

	vector<int64> a, b;

	for(int i = 0; i < MAX_N; ++i) {
		if(costs[i].empty())
			continue;

		int mxpos = std::max_element(costs[i].begin(), costs[i].end()) - costs[i].begin();

		for(int j = 0; j < len(costs[i]); ++j) {
			if(j == mxpos) {
				a.push_back(costs[i][j]);
			} else {
				b.push_back(costs[i][j]);
			}
		}
	}

	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());

	int64 answ = 0;

	for(int i = 1; i < len(a); ++i) {
		a[i] += a[i - 1];
	}

	for(int i = 1; i < len(b); ++i) {
		b[i] += b[i - 1];
	}

	for(int i = 1; i <= len(a) && i <= k; ++i) {
		int j = std::min(len(b), k - i);
		int64 local = a[i - 1] + (j > 0 ? b[j - 1] : 0) + i * 1LL * i;

		answ = std::max(answ, local);
	}

	cout << answ << '\n';
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 6904
#include<cstdio>
#include<algorithm>
#include<cmath>
#define INF 0x7f7f7f7f
 
using namespace std;
 
int map[26][26];
 
int main()
{
    int h,w;
    scanf("%d%d",&h,&w);
     
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            scanf("%d",&map[i][j]);
        }
    }
    int ans=INF;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int sum=0;
            for(int t=0;t<h;t++){
                for(int l=0;l<w;l++){
                    int cos=min(abs(i-t),abs(j-l));
                    sum+=cos*map[t][l];
                }
            }
            ans=min(ans,sum);
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2760
#include "bits/stdc++.h"
using namespace std;

int main() {
    int n, z, w;
    cin >> n >> z >> w;
    vector< int> v(n + 1);
    for (int i = 1; i <= n; ++i) cin >> v[i];
    if (n == 1) cout << abs(v[1] - w) << endl;
    else {
        cout << max(abs(v[n] - w), abs(v[n] - v[n - 1])) << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int n,m;
  scanf("%d",&n);
  scanf("%d",&m);
  int a[m],i,sum=0;
  for(i=0;i<m;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  if((n-sum)>=0)
    printf("%d",n-sum);
  else
    printf("-1");
  
  return 0;
}

Measured memory_bytes: 1768
n = int(input())
SP = []
for i in range(n):
    s,p = input().split()
    SP.append([i+1,s,int(p)])
    
from operator import itemgetter

SP.sort(key = itemgetter(2),reverse = True)
SP.sort(key = itemgetter(1))
for j,s,p in SP:
    print(j)

Measured memory_bytes: 3060
A = int(input())
B = int(input())
C = int(input())
X = int(input())
result=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if X==500*i+100*j+50*k:
                result += 1
print(result)

Measured memory_bytes: 3060