akhauriyash/Code-Regression huggingface dataset:
import itertools
import math
import numpy as np
import sys
input = sys.stdin.readline

n = int(input())
xy = np.array([list(map(int, input().split())) for _ in range(n)])

n_list = [l for l in range(n)]
dsum = 0
for i in itertools.permutations(n_list, n):
    xy1 = xy[list(i)][:-1]
    xy2 = xy[list(i)][1:]
    dsum += np.sum(np.sqrt(np.sum((xy1 - xy2)**2, axis=1)))

print(dsum/math.factorial(n))

Measured memory_bytes: 14452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=440;
const ll INF=1e18+7;
ll dp[M][M],a[M],pre[M];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) 
	{
		cin>>a[i];
		pre[i]=pre[i-1]+a[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		dp[i][j]=INF;
	}
	for(int i=1;i<=n;i++) dp[i][i]=0;
	for(int ln=2;ln<=n;ln++)
	{
		for(int i=1;i+ln-1<=n;i++)
		{
			int j=i+ln-1;
			if(ln==2)	
			dp[i][j]=a[i]+a[j];
			else
			{
				ll mn=INF;
				for(int k=i;k<j;k++)
				mn=min(mn,dp[i][k]+dp[k+1][j]);
				dp[i][j]=mn+pre[j]-pre[i-1];
			}
		}
	}
	cout<<dp[1][n];
	return 0;
}

Measured memory_bytes: 1664
n = int(input())
lis = list(map(int, input().split()))

b = [0]*3

for i in lis:
    if i % 4 == 0:
        b[2] += 1
    elif i % 2 == 0:
        b[1] += 1
    else:
        b[0] += 1

if b[1] == 0:
    if b[2] + 1 >= b[0]:
        print("Yes")
        exit()
    else:
        print("No")
        exit()



if b[2]  >= b[0]:
    print("Yes")
else:
    print("No")


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

int main() {
	int a;
	cin >> a;
	vector<char> n(a);
	for (int i = 0; i < a; i++) {
		cin >> n.at(i);
	}
	int sum = 1;
	for (int i = 0; i < a; i++) {
		if (i == a-1) {
			break;
		}
		if (n.at(i) != n.at(i + 1)) {
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}

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

int s[110];

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a++; b++; c++; d++;
    for(int i=1;i<105;i++){
        s[i]=s[i-1];
        if(i==a)s[i]++;
        if(i==c)s[i]++;
        if(i==b)s[i]--;
        if(i==d)s[i]--;
    }
    int ans=0;
    for(int i=0;i<105;i++){
        if(s[i]==2)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
// Print a Frame
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_B
//
// Accepted

#![allow(non_snake_case)]

use std::io::{BufRead, stdin};

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    loop {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();

        let mut data = buf.split_whitespace();

        let H: i32 = data.next().unwrap().parse().unwrap();
        let W: i32 = data.next().unwrap().parse().unwrap();

        if H == 0 && W == 0 {
            break;
        }

        for i in 1..(H + 1) {
            for j in 1..(W + 1) {
                if i == 1 || i == H || j == 1 || j == W {
                    print!("#");
                } else {
                    print!(".");
                }
            }
            println!();
        }
        println!()
    }
}


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

using namespace std;

int main() {
  int n, m;

  while(cin>>n>>m && n>0) {
    int taroPts = 0, hanakoPts = 0;
    vector<int> taroSet, hanakoSet;
    for(int i=0; i<n; i++) {
      int tmp;
      cin>>tmp;
      taroPts += tmp;
      taroSet.push_back(tmp);
    }
    for(int i=0; i<m; i++) {
      int tmp;
      cin>>tmp;
      hanakoPts += tmp;
      hanakoSet.push_back(tmp);
    }

    int t2h, h2t, sumPts = 1000;
    for(int i=0; i<taroSet.size(); i++) {
      for(int j=0; j<hanakoSet.size(); j++) {
        if(taroPts-taroSet[i]+hanakoSet[j] == hanakoPts-hanakoSet[j]+taroSet[i] && taroSet[i]+hanakoSet[j]<sumPts) {
	  t2h = taroSet[i];
	  h2t = hanakoSet[j];
	  sumPts = t2h+h2t;
        }
      }
    }
    if(sumPts != 1000) {
      cout<<t2h<<" "<<h2t<<endl;
    }
    else {
      cout<<"-1"<<endl;
    }
  }
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=262244,M=22,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T> inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T> inline void print(T x){
	if(!x){puts("0");return;}
	if(x<0){putchar('-');x=-x;}
	int a[20],m=0;
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');puts("");
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,a[N],v[20],l[20][N],r[20][N],f[N],g[N];


void solve(int x){
	for(int i=1;i<=n;i++){
		int t=i;
		while(t<n&&a[t+1]-a[t]<=v[x]) t++;
		for(int j=i;j<=t;j++)
			l[x][j]=t+1,r[x][j]=i-1;
		i=t;
	}
	l[x][n+1]=n+1;
	r[x][0]=0;
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
	srand(time(0));
#endif
	ios::sync_with_stdio(0);
	read(n);read(v[0]);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int j=1;v[j-1];j++,m=j) v[j]=v[j-1]>>1;
	for(int i=0;i<m;i++) solve(i);
	debug(m);
	f[0]=1;g[0]=n;
	for(int i=1;i<(1<<m-1);i++){
		f[i]=1,g[i]=n;
		for(int j=1;j<m;j++)
			if(i&(1<<j-1)) gmax(f[i],l[j][f[i^(1<<j-1)]]),gmin(g[i],r[j][g[i^(1<<j-1)]]);
		}
	int u=(1<<m-1)-1;
	for(int i=1;i<=n;i++){
		int r=i,isok=0;
		while(r<n&&a[r+1]-a[r]<=v[0]) r++;
		for(int j=0;j<(1<<m-1);j++)
			if(f[j]>=i&&g[u^j]<=r) isok=1;
		for(int j=i;j<=r;j++)
			if(isok) puts("Possible"); else puts("Impossible");
		i=r;
	}
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}


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

using namespace std;
typedef long long LL;

inline LL read(){LL x; scanf("%lld", &x); return x;}
inline void read(char *s){scanf("%s", s);}
inline void no(){printf("no\n");exit(0);}

#define maxn 120000
int v[2][maxn], ans[2], pans[2];
int main(){
	int n = read();
	for(int i = 0; i < n; i += 1)
		v[i & 1][read()] += 1;
	ans[0] = ans[1] = 0;
	v[0][0] = v[1][0] = -1;
	for(int i = 0; i < maxn; i += 1)
		for(int j = 0; j < 2; j += 1)
			if(v[j][i] > v[j][ans[j]]) ans[j] = i;
	if(ans[0] != ans[1]) printf("%d", n - v[0][ans[0]] - v[1][ans[1]]);
	else{
		for(int i = 0; i < maxn; i += 1)
			for(int j = 0; j < 2; j += 1)
				if(v[j][i] > v[j][pans[j]] && i != ans[j]) pans[j] = i;
		printf("%d", n - max(v[0][ans[0]] + v[1][pans[1]], v[0][pans[0]] + v[1][ans[1]]));
	}
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){

	pair<int, int>tmp = make_pair(1, 1);

	while (1){
		cin >> tmp.first >> tmp.second;
		if (tmp.first == 0 && tmp.second == 0)
			break;
		if (tmp.first<tmp.second)
			cout << tmp.first << " " << tmp.second <<endl;
		else
			cout << tmp.second << " " << tmp.first << endl;
	}

	return 0;
}


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

using namespace std;

int a[200100],b[200100];

int main()
{
    int i,l,f = 0;
    string s,t;
    cin >> s >> t;
    l = s.length();
    for(i = 0; i < l; i ++)
    {
        a[s[i]-'a'] ++;
        b[t[i]-'a'] ++;
    }
    sort(a,a+26);
    sort(b,b+26);
    for(i = 0; i < 26; i ++)\
    {
        if(a[i] != b[i])
        {
            f = 1;
            break;
        }
    }
    if(f == 1) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long

using namespace std;


int main() {
  ll x, y; cin >> x >> y;
  ll ans = 0;
  while (x <= y) {
    x *= 2;
    ans++;
  }
  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 *
 * @author 97797
 */
public class Main {
    public static void main(String[] args) throws IOException {
        System.out.println(new Main().run(args, System.in));
    }
    public String run(String[] args, InputStream in) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        long N = Long.valueOf(reader.readLine());
        String[] val = reader.readLine().replaceAll("\\s+", " ").split(" ");
        List<Integer> list = Stream.of(val).map(Integer::parseInt).collect(Collectors.toList());

        int direct = 0;
        int pre = 0;
        int count = 0;
        for (Integer n : list) {
            if (pre == 0) {
                pre = n;
            } else {
                if (pre == n) {
                    // nop;
                } else {
                    if (direct == 0) {
                        if (n > pre) {
                            direct = 1;
                        } else {
                            direct = -1;
                        }
                    } else if (direct > 0) {
                        if (n > pre) {
                            //
                        } else {
                            count++;
                            direct = 0;                    
                        }
                    } else {//direct < 0
                        if (pre > n) {
                            //
                        } else {
                            count++;
                            direct = 0;                    
                        }
                    }
                    pre = n;
                }
            }
       }
        count++;
       return String.valueOf(count);
    }      
}


Measured memory_bytes: 55512
#include<bits/stdc++.h>
#include<queue>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N,M;
  cin>>N>>M;
  int perm[N],ans=0;
  bool tmp=true;
  RREP(i,1,N+1) perm[i-1]=i;
  int g[10][10]={};
  REP(i,M){
    int a,b;
    cin>>a>>b;
    g[a][b]=1,g[b][a]=1;
  }
  do{
    if(perm[0]!=1)continue;
    tmp=true;
    //REP(i,N)cout<<perm[i];
    //cout<<endl;
    tmp=true;
    REP(i,N-1)if(g[perm[i]][perm[i+1]]!=1) tmp=false;
    if(tmp)ans++;
  }while(next_permutation(perm,perm+N));
  cout<<ans;

  return 0;
}

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

// varibable settings {{{
#define infile "../test/sample-1.in"
#define int long long
const int INF=1e18;
const int MOD=1e9+7;
// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
#include "/home/koji0708/go/src/github.com/kjnh10/pcl/template/codes/lib/dump.hpp"
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  vector<int> a(n);
  map<int, int> cnt;
  int M = -1;
  rep(i, n) {
    cin>>a[i];
    cnt[a[i]]++;
    chmax(M, a[i]);
  }
  sort(all(a));
  dump(a);
  dump(cnt);

  int m = INF;
  rep(i, (M+2-1)/2){
    dump(i);
    chmin(m, M-i);
    if (!(cnt[M-i]>=2)) {
      cout << "Impossible" << endl;
      return 0;
    }
    else{
      cnt[M-i] -= 2;
    }
  }
  if (M%2==0) {
    chmin(m, M/2);
    dump(M/2);
    if (!(cnt[M/2]>=1)) {
      cout << "Impossible" << endl;
      return 0;
    }
    else{
      cnt[M/2] -= 1;
    }
  }
  dump(m);
  dump(cnt);

  //他の項は最小値+1以上であることが必要
  each(el, cnt){
    int v = el.first;
    int num = el.second;
    if (v <= m && num > 0){
      cout << "Impossible" << endl;
      return 0;
    }
  }
  cout << "Possible" << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a[32]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int ans = 0x3f3f3f;
char mp[25][25];
int dp[407][407];
int sum = 0;
int n,m;
int dir[4][2] = {{0,1},{1,0},{-1,0},{0,-1}};
int check(int x,int y){
	if(mp[x][y]=='#'||x<1||x>n||y<1||y>m) return 0;
	return 1;
}
int dfs(int x,int y){
	for(int i = 0;i < 4;i++){
		int a = (x-1)*m+y;
		int nx = x + dir[i][0];
		int ny = y + dir[i][1];
		if(check(nx,ny)){
			int b = (nx-1)*m+ny;
			dp[a][b] = 1;
		}
	}
}
int main(){
	scanf("%d %d",&n,&m);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			cin >> mp[i][j];
		}
	}
	for(int i = 1;i <= n * m;i++){
		for(int j = 1;j <= n * m;j++){
			dp[i][j] = 0x3f3f3f3f;
		}
		dp[i][i] = 0;
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(mp[i][j]=='.'){
				dfs(i,j);
			}
		}
	}
	int ans = 0;
	for(int k = 1;k <= n*m;k++){
		for(int i = 1;i <= n*m;i++){
			if(dp[i][k] == 0x3f3f3f3f) continue;
			for(int j = 1;j <=n*m;j++){
				if(dp[k][j] == 0x3f3f3f3f) continue;
				dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
	for(int i = 1;i <= n*m;i++){
		for(int j = 1;j <=n*m;j++){
			if(dp[i][j] != 0x3f3f3f3f) ans = max(ans,dp[i][j]);
		}
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 896
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  ulong N = readln.chomp.to!ulong;
  ulong[] a = readln.chomp.split.to!(ulong[]);
  ulong[ulong] h;

  foreach (e; a) {
    if (e in h) {
      h[e]++;
    } else {
      h[e] = 1;
    }
  }

  ulong ans;

  foreach (k, v; h) {
    if (k < v) {
      ans += v - k;
    } else if (k > v) {
      ans += v;
    }
  }

  writeln(ans);
}


Measured memory_bytes: 9304
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
ll ans;
string S;
ll N;
ll T[101];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b)*b;
}

int main() {
	cin >> N;
	ll num;
	cin>>num;
	rep(i, 1, N) {
		cin >> T[i];
		num = lcm(num, T[i]);
	}
	cout << num << endl;
	cin >> num;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define ll long long int
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
struct objects{
    int weight,value;
};
ll solve(){
   int n,w;
   cin>>n>>w;
   objects object[n];
   int totalvalue=0;
   for(int i=0;i<n;i++){
       cin>>object[i].weight>>object[i].value;
       totalvalue+=object[i].value;
   }
   ll dp[n+1][totalvalue+1];
   dp[0][0]=0;
   int ans=0;
   for(int i=1;i<=totalvalue;i++){
       dp[0][i]=1e18;
   }
   for(int i=0;i<n;i++){
       for(int j=0;j<=totalvalue;j++){
           if(j>=object[i].value){
                dp[i+1][j]=min(dp[i][j],dp[i][j-object[i].value]+object[i].weight);
           }
           else{
               dp[i+1][j]=dp[i][j];
           }
           if(dp[i+1][j]<=w){
               ans=max(ans,j);
           }
       }
   }
   return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);;
    cout<<solve();
}

Measured memory_bytes: 79104
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

class CDiceAndCoin {
public:
	void solve(std::istream& in, std::ostream& out) {
        int N, K;
        in >> N >> K;
        double ans = 0;
        for (int i = 1; i <= N; i++) {
            double prob = 1.0 / N;
            int score = i;
            while (score < K) {
                score *= 2;
                prob /= 2.0;
            }
            ans += prob;
        }
        out << setprecision(12) << ans << '\n';
	}
};


int main() {
	CDiceAndCoin solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define MAX_N 100000
#define INF 10000000000LL
typedef long long int ll;

std::priority_queue<std::pair<ll, int>> ss;
std::priority_queue<std::pair<ll, int>, std::vector<std::pair<ll, int>>, std::greater<std::pair<ll, int>>> replacable;
std::vector<ll> ds(MAX_N + 1, - INF);
int t_count[MAX_N + 1];

int main() {
  int n, k;

  std::cin >> n >> k;
  for(int i = 0; i < n; ++i) {
    ll d;
    int t;
    std::cin >> t >> d;
    ss.emplace(d, t);
  }

  int cnt = 0;
  ll v = 0;
  std::vector<std::pair<ll, int>> temp;

  for(int i = 0; i < k; ++i) {
    auto p = ss.top();
    ss.pop();

    v += p.first;
    if(t_count[p.second] == 0) ++cnt;
    ++t_count[p.second];
    temp.push_back(p);
  }

  ds[cnt] = v;
  for(auto p : temp) {
    if(t_count[p.second] > 1) {
      replacable.push(p);
    }
  }
  int cnt0 = cnt;

  while(cnt < k && replacable.size() > 0) {
    auto r = replacable.top();
    replacable.pop();
    if(t_count[r.second] < 2) continue;

    bool replace = false;
    while(ss.size() > 0) {
      auto p = ss.top();
      ss.pop();

      if(t_count[p.second] == 0) {
        ++t_count[p.second];
        v += p.first;
        ++cnt;
        replace = true;
        break;
      }
    }
    if(replace) {
      --t_count[r.second];
      v -= r.first;
    }

    ds[cnt] = v;
  }

  ll ans = 0;
  for(int c = cnt0; c <= k; ++c) {
    ans = std::max(ans, ds[c] + (ll) c * c);
  }

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

Measured memory_bytes: 6384
#include <stdio.h>

int check(int array[], int n)
{
	int sorted;
	for (int i=0; i<(n-1); i++)
	{
		if (array[i]<array[i+1])
			sorted=1;
		else{
			sorted=0;
			break;//once here the code breaks out of the loop and returns false
		}
	}
	return sorted;
	// if (n == 0)
	// {
	// 	return 1;
	// } else {
	// 	if (array[n] > array[n-1])
	// 	{
	// 		return check(array, n-1);
	// 	} else {
	// 		return 0;
	// 	}
	// }
}

int main()
{
	int n, temp, i, j, k, res = 0, che;
	scanf("%d", &n);
	int arr[n];
	int temparr[n];
	for (i = 0; i < n; ++i)
	{
		scanf("%d", &temp);
		arr[i] = temp;
		temparr[i] = temp;
	}
	for (i = 0; i < n; ++i)
	{
		if (check(temparr, n))
		{
			res = 1;
			break;
		}
		for (j = 0; j < n; ++j)
		{
			if (i == j)
			{
				continue;
			}

			temp = temparr[i];
			temparr[i] = temparr[j];
			temparr[j] = temp;

			// printf("%d-%d\n", temparr[j], temparr[i]);
			// for (k = 0; k < n; ++k)
			// {
			// 	printf("%d\t", temparr[k]);
			// }
			// che = check(temparr, n);
			// printf("\n%d\n\n", check(temparr, n));

			if (check(temparr, n) == 1)
			{
				res = 1;
				// printf("%d-%d", temp, arr[i]);
				break;
			}

			temparr[i] = arr[i];
			temparr[j] = arr[j];

		}
	}

	if (res == 1)
	{
		printf("YES");
	} else {
		printf("NO");
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

// #define int long long
#define int __int128
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

long long MOD;

template<typename type>
vector<vector<type>> product(vector<vector<type>> &a, vector<vector<type>> &b){
	vector<vector<type>> res(a.size(),vector<type>(b[0].size(),0));
	
	
	for(int i = 0; i < a.size(); i++){
		for(int j = 0; j < b[0].size(); j++){
			for(int k = 0; k < b.size(); k++){ 
				res[i][j] += a[i][k]*b[k][j];
				res[i][j] %= MOD;
			}
		}
	}
	
	return res;
}

template<typename type>
vector<vector<type>> matrix_power(vector<vector<type>> matrix, long long n){
	vector<vector<type>> res(matrix.size(), vector<type>(matrix.size(),0));
	
	for(int i = 0; i < matrix.size(); i++) res[i][i] = 1;
	
	for( ; n > 0; n >>= 1){
		if(n&1) res = product(res,matrix);
		matrix = product(matrix,matrix);
	}
	
	return res;
}

int check(int num){
	int con = 0;
	while(num) con++, num /= 10;
	
	return con;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	vector<vector<int>> ans(3,vector<int>(1,0));
	long long L, A, B;
	int b = -1;
	
	cin>>L>>A>>B>>MOD;
	
	ans[0][0] = 0;
	ans[1][0] = A;
	ans[2][0] = 1;
	
	for(int i = 1, power = 10; i <= 18; i++, power *= 10){
		vector<vector<int>> matrix(3,vector<int>(3,0));
		int d = 0;
		int m = 0, l = 0, h = L;
		
		while(l + 1 < h){ 
			int m = (l + h)/2;
			if(check(A + m*B) > i){
				h = m;
			} else {
				l = m;
			}
		}
		
		if(check(A + l*B) < i) continue;
		d = l - b;
		b = l;
		
		matrix[0][0] = power;
		matrix[0][1] = matrix[1][1] = matrix[2][2] = 1;
		matrix[1][2] = B;
		
		matrix = matrix_power(matrix, d);
		ans = product(matrix, ans);
	}
	
	cout<<(long long)ans[0][0]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main() {
    int N, M;
    int Sum = 0;

    // input
    cin >> N >> M;
    int array[N], A[N];
    for(int i=0; i<= N-1; i++){
        cin >> array[i];
    }

    // 配列の和の計算
    for(int i=0; i<= N-1; i++){
        Sum = Sum + array[i];
    }

    // 降順ソート
    std::sort(array, array + SIZE_OF_ARRAY(array), std::greater<>());

    // 出力
    if(array[M-1] * 4 * M >= Sum){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
priority_queue<int> q;
struct qwq
{
	int a,b;
}e[100233];
bool cmp(qwq x,qwq y)
{
	return x.a<y.a;
}
long long ans=0;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d",&e[i].a,&e[i].b);
	}
	sort(e+1,e+n+1,cmp);
	int j=1;
	for (int i=1;i<=m;i++)
	{
		for (;j<=n;j++)
		{
			if (e[j].a<=i) q.push(e[j].b);
			else break;
		}
		if (!q.empty())
		{
//		printf("qwq");
			ans+=(long long)q.top();
			q.pop();
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1660
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>
#include <numeric>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;


namespace BF {

llong F(const VI& P) {
   llong res = 0;
   REP(i, SZ(P)) {
      res += (i+1) % P[i];
   }
   return res;
}

llong solve(int N) {
   VI P(N);
   iota(P.begin(), P.end(), 1);
   llong res = 0;
   do {
      llong cur = F(P);
      if (cur > res)
         res = cur;
   } while (next_permutation(P.begin(), P.end()));
   return res;
}

}

namespace GR {

llong solve(int N) {
   if (N <= 1) return 0;
   llong NN = N - 1;
   return NN * (NN+1) / 2;
}

}


int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N;
   cin >> N;
   llong res;
   if (N <= 9)
      res = BF::solve(N);
   else
      res = GR::solve(N);
   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[int(x) for x in input().split()]
vl =[]
tmp =[]
ans=[0]*n
for i,value in enumerate(a):
  tmp.append(i)
  vl.append(value)
for i in range(n):
  ans[vl[i]-1]=tmp[i]+1
print(*ans)

Measured memory_bytes: 64172
#include<bits/stdc++.h>
using namespace std;
const int N=666;
int vis[2][N][N];
int n,d1,d2,m;
vector<pair<int,int> >v[2];
void dfs(int opt,int x,int y,int st)
{
    if(x<0||x>=m||y<0||y>=m||vis[opt][x][y]) return;
    vis[opt][x][y]=st;
    for(int i=0;i<v[opt].size();i++)
        dfs(opt,x+v[opt][i].first,y+v[opt][i].second,st==1?2:1);
}
int main(void)
{
    scanf("%d%d%d",&n,&d1,&d2);
    m=n*2;
    for(int i=0;i*i<=d1;i++)
    {
        int j=sqrt(d1-i*i);
        if(j*j==d1-i*i)
        {
            v[0].push_back({i,j});
            v[0].push_back({-i,j});
            v[0].push_back({i,-j});
            v[0].push_back({-i,-j});
        }
    }
    for(int i=0;i*i<=d2;i++)
    {
        int j=sqrt(d2-i*i);
        if(j*j==d2-i*i)
        {
            v[1].push_back({i,j});
            v[1].push_back({-i,j});
            v[1].push_back({i,-j});
            v[1].push_back({-i,-j});
        }
    }
    for(int i=0;i<m;i++)
        for(int j=0;j<m;j++)
        for(int k=0;k<2;k++)
        if(!vis[k][i][j])
        {
            dfs(k,i,j,1);
        }
    int k=n*n;
    for(int i=0;i<m;i++)
        for(int j=0;j<m;j++)
        if(vis[0][i][j]==1&&vis[1][i][j]==1)
        {
            printf("%d %d\n",i,j);
            k--;
            if(k==0) return 0;
        }
}


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

using namespace std;
int main(void){
    vector<string> week ={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;
    cin >> s;
    for (size_t i = 0; i < week.size(); i++)
    {
        if(s == week[i]){
            cout << 7 -i;
        }
    }
    
}

Measured memory_bytes: 256
S=raw_input()
K=int(raw_input())

if len(S)==1:
    print S[0]
else:
    one_count=0
    for i in range(len(S)):
        if S[i]=='1':
            one_count+=1
        else:
            break
    if K<=one_count:
        print '1'
    else:
        print S[one_count]


Measured memory_bytes: 2568
// In the name of God
#include <bits/stdc++.h>

using namespace std;
#define Size(x) ((int)(x).size())
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int INF = 1e9 + 10;

int n;
string s,ans;

void make()
{
	for(int i=1;i<n-1;++i){
		if(ans[i] == 'W'){
			if(s[i] == 'o'){ // yeki nis
				if(ans[i-1] == 'W') ans[i+1] = 'S';
				else ans[i+1] = 'W';
			}else{ // yeki has
				if(ans[i-1] == 'W') ans[i+1] = 'W';
				else ans[i+1] = 'S';
			}
		}else{
			if(s[i] == 'o'){ // yeki has
				if(ans[i-1] == 'W') ans[i+1] = 'W';
				else ans[i+1] = 'S';	
			}else{ // yeki nis
				if(ans[i-1] == 'W') ans[i+1] = 'S';
				else ans[i+1] = 'W';
			}
		}
	}
	bool fl = false;
	for(int i=0;i<n;++i){
		char x = ans[(i+n-1)%n] , y = ans[(i+1)%n];
		if(s[i] == 'o' && ans[i] == 'W'){
			if(x == y) fl = true;
		}
		if(s[i] == 'o' && ans[i] == 'S'){
			if(x != y) fl = true;
		}
		if(s[i] == 'x' && ans[i] == 'W'){
			if(x != y) fl = true;
		}
		if(s[i] == 'x' && ans[i] == 'S'){
			if(x == y) fl = true;
		}
	}
	if(!fl){
		cout << ans << '\n';
		exit(0);
	}
}

int main()
{
	ios_base :: sync_with_stdio(false) ,cin.tie(0) , cout.tie(0);
	cin >> n;
	cin >> s;
	ans.resize(n);
	ans[0] = 'S';
	ans[1] = 'S';
	make();
	ans[0] = 'S';
	ans[1] = 'W';
	make();
	ans[0] = 'W';
	ans[1] = 'S';
	make();
	ans[0] = 'W';
	ans[1] = 'W';
	make();
	cout << -1 << '\n';
	return 0;
}


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

int inf = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  
  //nが1のとき
  if(n == 1){
    cout << 1 << endl;
    return 0;
  }
  
  //約数を格納するベクトル
  vector<int> div(n+1);
  
  //約数を探す
  for(int i = 2; i <= n; i++){
    int x = i;
    for(int j = 2; j <= i; j++){
      while(x % j == 0){
        x  = x / j;
        div[j]++;
      }
    }
  }

  
  //答え
  long long ans = 1;
  for(int i = 2; i <= n; i++){
    if(div[i] != 0){
      ans = ans * (div[i] + 1);
      ans = ans % inf;
    }
  }
  
  cout << ans  << endl;
}

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

int main(int argc, char const *argv[])
{
	int n,m,c;
	cin>>n>>m>>c;
	int b[m],a[n][m];
	for (int i = 0; i < m; ++i)
	{
		cin>>b[i];
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			cin>>a[i][j];
		}
	}
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		int s=0;
		for (int j = 0; j < m; ++j)
		{
			s+=a[i][j]*b[j];
		}
		if (s+c>0)
		{
			++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
K=int(input())
from collections import deque

#queue = list(range(1,10))
queue = deque(list(range(1,10)))

for i in range(K):
  lunlun = queue.popleft()
  #print(lunlun)
  last = lunlun%10
  if last!=0:
    queue.append(10*lunlun+last-1)
  queue.append(10*lunlun+last)
  if last!=9:
    queue.append(10*lunlun+last+1)

print(lunlun)

Measured memory_bytes: 11956
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
    ll n, m;
    cin >> n >> m;
    scc_graph g(n);
    REP(i, m){
        int ai, bi;
        cin >> ai >> bi;
        g.add_edge(ai, bi);
    }

    vector<vector<int>> scc = g.scc();
    cout << scc.size() << endl;
    for(const auto& c : scc){
        cout << c.size() << ' ';
        REP(i, c.size()){
            cout << c.at(i);
            if(i + 1 < c.size()){
                cout << ' ';
            }else{
                cout << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 40096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int f(int x, int y, int z) {
    return x*x+y*y+z*z+x*y+y*z+z*x;
}

int main() {
    int n; cin >> n;
    map<int,int> mp;
    for (int x = 1; x <= 100; x++) {
        for (int y = 1; y <= 100; y++) {
            for (int z = 1; z <= 100; z++) {
                mp[f(x,y,z)]++;
            }
        }
    } 
    for (int i = 1; i <= n; i++) {
        printf("%d\n",mp[i]);
    }
}

Measured memory_bytes: 5504
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

D = [r - l for l, r in zip(X, X[1:])]
D.sort()

ans = sum(D)
while D and N > 1:
    N -= 1
    ans -= D.pop()
print(ans)


Measured memory_bytes: 20440
//************************
//** author  :  Alex Hu **
//************************

//  _______        __________         ________        __
//  \      \   ____\______   \ ____  /  _____/  _____/  |_
//  /   |   \ /  _ \|       _// __ \/   \  ____/ __ \   __\
// /    |    (  <_> )    |   \  ___/\    \_\  \  ___/|  |
// \____|__  /\____/|____|_  /\___  >\______  /\___  >__|
//         \/              \/     \/        \/     \/

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back

#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define fi first
#define se second
#define sqr(a) ((a)*(a))

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll mod=1e9+7;
const int INF=0x3f3f3f3f; 
const int MAX=2e5+5;

int n;

int main()
{
	cin>>n;
	cout<<(n-2)*180<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    bool flag = 1;
    int cnt = 0;

    while(flag) {
        flag = 0;
        for(int j = n-1; j > 0; j--) {
            if(A[j] < A[j-1]) {
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                cnt++;
            }
        }
    }

    for(int i = 0; i < n; i++) {
        if(i != n-1) cout << A[i] << ' ';
        else cout << A[i] << endl;
    }
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 3088
/*package whatever //do not write package name here */

import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;


class Main {
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next(){
            while(st==null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
    }
    
	public static void main (String[] args) {
		FastReader ob = new FastReader();
	    int n = ob.nextInt(),k=ob.nextInt(),x=ob.nextInt(),y=ob.nextInt();
	    int ans ;
	    if(k>=n){
	        System.out.println(x*n);
	    }
	    else{
	        System.out.println(x*k + (n-k)*y);
	    }
	     
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
    while(1) {
        int a;
        int b;
        string op;
        
        cin >> a >> op >> b;
        
        if (op == "+") {
            cout << a + b << endl;
        } else if (op == "-") {
            cout << a - b << endl;
        } else if (op == "*") {
            cout << a * b << endl;
        } else if (op == "/") {
            cout << a / b << endl;
        } else if (op == "?") {
            break;
        }
    }
    
    return 0;
}


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

using namespace std;

const int N = 2e5 + 5;
int arr[N], v[N];

int main() {
  //  freopen("in.txt", "rt", stdin);
    int n, x;
    scanf("%d", &n);
    int ans = 1;
    multiset<int> st;
    scanf("%d", &x);
    st.insert(x);
    for (int i = 1; i < n; ++i) {
        scanf("%d", &x);
        auto it = st.lower_bound(x);
        if (it == st.begin()) {
            ++ans;
            st.insert(x);
            continue;
        }
        --it;
        st.erase(it);
        st.insert(x);
    }
    printf("%d", ans);
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N, i; cin >> N >> i;
    cout << N - i + 1 << endl;
    return 0;
}

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

int h, w, n;
char m[1010][1010];
int d[1010][1010];
bool f[1010][1010];

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

void init()
{
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      d[i][j] = 1e9 + 9;
      f[i][j] = false;
    }
  }
}

int main()
{
  int sx, sy;

  cin >> h >> w >> n;
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      cin >> m[i][j];
      if (m[i][j] == 'S') sx = j, sy = i;
    }
  }

  int ans = 0;
  for (int i = 1; i <= n; i++){
    queue<pair<int, int> > q;
    q.push(make_pair(sy, sx));

    init();
    f[sy][sx] = true;
    d[sy][sx] = 0;
    while (!q.empty()){
      pair<int, int> nv = q.front();
      q.pop();

      if (m[nv.first][nv.second] == '0' + i){
        sy = nv.first;
        sx = nv.second;
        ans += d[sy][sx];
        while (!q.empty()) q.pop();
        break;
      }

      for (int j = 0; j < 4; j++){
        int ny = nv.first + dy[j];
        int nx = nv.second + dx[j];
        if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
        if (f[ny][nx]) continue;
        if (m[ny][nx] == 'X') continue;
        d[ny][nx] = d[nv.first][nv.second] + 1;
        q.push(make_pair(ny, nx));
        f[ny][nx] = true;
      }
    }
  }

  cout << ans << endl;
}

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

int main(){
  string S;
  cin >> S;
  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    puts("Yes");
  }
  else{
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 256
N,M = map(int, input().split())

NOT_LIKE = []
T = [i for i in range(1,M+1)]
for i in range(N):
    A = list(map(int, input().split()))
    tmp = [i for i in range(1,M+1)]
    for j in range(1, len(A)):
        tmp.remove(A[j])
    for t in tmp:
        if t in T:
            T.remove(t)

print(len(T))

Measured memory_bytes: 3064
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val s = sc.next

  val keyence = "keyence"

  val sp = (0 to keyence.length).map{k =>
    ( keyence.substring(0,k), keyence.substring(k) )
  }

  val res = if(sp.exists{case (start, end) => s.startsWith(start) && s.endsWith(end)}) "YES" else "NO"

  println(res)
}

Measured memory_bytes: 25624
import sys
from bisect import bisect_left, bisect_right

n, *l = map(int, sys.stdin.read().split())
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        # i: 1番目に長い棒　j: 2番目に長い棒
        # 3番目に長い棒の条件 -> jよりも短く a<b+cよりa-bより大きい
        cnt = (n - 1) - j - bisect_right(l, l[-(i+1)] - l[-(j+1)])
        if cnt > 0:
            ans += cnt
print(ans)


Measured memory_bytes: 43740
#include <stdio.h>
#include <string.h>
int main(void){
    char s[10+5];
    scanf("%s", s);
    int max=0, l=0;
    for(int i=0; i<strlen(s); i++){
        if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
            l++;
        }else{
            if(max<l)max=l;
            l=0;
        }
    }
    if(max<l)max=l;
    printf("%d\n", max);
    return 0;
}


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

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n; cin >> n;
        map<string, int> freq;
        while (n--) {
                string s; cin >> s;
                sort(all(s));
                freq[s]++;
        }

        ll ans = 0;
        for (auto it: freq) ans += (ll)(it.second) * (it.second - 1) / 2;
        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 11416
#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 << 18;
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() {
	ll A, B;
	scanf("%lld %lld", &A, &B);
	if (abs(A - B) > 1) printf("Alice\n");
	else printf("Brown\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(10));
	vector<vector<int>> b(n, vector<int>(11));
	rep(i, n) {
		rep(j, 10) {
			cin >> a[i][j];
		}
	}
	rep(i, n) {
		rep(j, 11) {
			cin >> b[i][j];
		}
	}
	int tmp;
	int cnt;
	int now;
	int max = -99999999999;
	rep(i, pow(2, 10)) {
		if (i == 0) {
			continue;
		}
		now = 0;
		rep(j, n) {
			tmp = i;
			cnt = 0;
			rep(k, 10) {
				if (tmp % 2 && a[j][k]) {
					cnt++;
				}
				tmp /= 2;
			}
			now += b[j][cnt];
		}
		if (max < now) {
			max = now;
		}
	}
	cout << max << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())

name = []
time = []

for _ in range(n):
  a, b = input().split()
  name.append(a)
  time.append(int(b))

x = input()
result = 0

num = name.index(x)

for i in range(num+1, n):
  result += time[i]

print(result)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 200010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-12
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int n, cnt, ans;

int main() {
	io(); cin >> n;
	vector<pair<string, int> > vec;
	rep(i, 1, n) {
		string s; int x;
		cin >> s >> x;
		vec.emplace_back(mp(s, x));
	}
	string sp; cin >> sp; bool f = false;
	rep(i, 1, n) {
		if (f) { ans += vec[i - 1].second; continue; }
		if (sp == vec[i - 1].first) f = true;
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int n  = sc.nextInt();
		
		
		int[][] arr = new int[n][3];
		
		for(int i =0 ; i < n ; i++){
			arr[i][0] = sc.nextInt();
			arr[i][1] = sc.nextInt();
			arr[i][2] = arr[i][0]+arr[i][1];
		}
		
		Arrays.sort(arr, (ar1,ar2) -> -Integer.compare(ar1[2],ar2[2]));

		long ans[] = new long[2];
		int now = 0;
		for(int i = 0; i < n ; i++){
			ans[now] += arr[i][now];
			now = 1 - now;
		}
		
		System.out.println(ans[0]-ans[1]);
	}
}


Measured memory_bytes: 94500
import java.util.Scanner;

public class Main {

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

		int n = scan.nextInt();
		long[] a = new long[n+1];
		long[] s = new long[n+1];
		s[0] = 0;

		for(int i = 1; i < n+1; i++) {
			a[i] = scan.nextInt();
			s[i] = s[i-1] + a[i];
		}

		int mid = 0;

		for(int i = 1; s[i] <= s[n]/2; i++) {mid = i;}


		long ans = Math.abs(s[n] - 2*s[mid]);

		if(s[n] - 2*s[mid] > 0) {
			mid++;
		}else {
			mid--;
		}
		long tmp = Math.abs(s[n] - 2*s[mid]);
		if(tmp < ans) {
			ans = tmp;
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 90232
#include <bits/stdc++.h>
using namespace std;
stack<int> stk;
int main(){
  int x;
  cin>>x;
  do {
    int r = x > 0 ? x % 2 : -(x%2);
    stk.push(r);
    x-=r;
    x/=-2;
  } while(x);
  while(!stk.empty()){
    cout<<(stk.top()!=0);
    stk.pop();
  }
  cout<<'\n';
  return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 110, mod = 1e9 + 7;

int n;
int a[N];
int res = 0x3f3f3f3f;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = -100; i <= 100; i++)
    {
        int sum = 0;
        for(int j = 1; j <= n; j++)
        {
            int t = abs(a[j] - i);
            sum += t * t;
        }
        res = min(res, sum);
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256