akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    ll K;
    cin >> N >> K;
    ll P[N],C[N];
    rep(i,N) {
        ll p;
        cin >> p;
        p--;
        P[i] = p;
    }
    rep(i,N) {
        ll c;
        cin >> c;
        C[i] = c;
    }
    ll ans = -1e18;
    
    rep(i,N) {
        //i = 1;
        set<ll> seen;
        vector<ll> A;
        ll psum = 0;
        ll s = i;
        ll c = 0;

        while(1) {
            A.push_back(C[P[s]]);
            psum += C[P[s]];
            c++;
            s = P[s];
            if (s==i) break; 
        }

        ll tmp = 0;
        for (ll j=0;j<c;j++) {
            if (j+1>K) break;
            tmp += A[j];
            ans = max(tmp,ans);
            if (K-(j+1)>=c) {
                ans = max(ans,tmp+psum*((K-(j+1))/c));
            }
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,A,B;
    cin >> N >> A >> B;
    while(1){
        //Alice
        if(A == 1 && B == 2){
            pr("Borys");
            return 0;
        }
        if(A+1 < B){
            A++;
        }else{
            A--;
        }

        //Borys
        if(B == N && A == N-1){
            pr("Alice");
            return 0;
        }
        if(A < B-1){
            B--;
        }else{
            B++;
        } 

    }
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,a[100005],judge[2];
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i) {scanf("%d",&a[i]);judge[a[i]%2]++;}
	if(!(judge[1]%2)) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 512
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int r,c;
int main(){
	while(cin>>r>>c,r||c){
		if(r%2&&c%2){
			printf("no\n");
		}else{
			printf("yes\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define plll pair<pll,ll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

ll arr1[2010],arr2[2010];
ll size1,size2;

ll dp[2010][2010];
ll solve(ll idx1,ll idx2)
{
    if(idx2==0 || idx1==0)
    {
        return 0;
    }
    if(dp[idx1][idx2]!=-1)
    {
        return dp[idx1][idx2];
    }
    ll ans=0,store;
    store=solve(idx1-1,idx2);
    ans=(ans+store)%MOD;
    store=solve(idx1,idx2-1);
    ans=(ans+store)%MOD;  
    store=solve(idx1-1,idx2-1);
    ans=(ans-store+MOD)%MOD;
    if(arr1[idx1]==arr2[idx2])
    {
        ans++;
        store=solve(idx1-1,idx2-1);
        ans=(ans+store)%MOD;
    }
    dp[idx1][idx2]=ans;
    return ans;
}

int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    memset(dp,-1,sizeof(dp));
    cin>>size1>>size2;
    for(ll i=1;i<=size1;i++)
    {
        cin>>arr1[i];
    }
    for(ll i=1;i<=size2;i++)
    {
        cin>>arr2[i];
    }
    ll result=solve(size1,size2);
    result++;
    cout<<result;
    return 0;
}

Measured memory_bytes: 32128
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long int li;


int main(){
  if(df) printf("*debug mode*\n");
  string s,t; cin >>s >>t;
  vector<vector<int>> vec(2,vector<int>(1,0));
  rep(j,2){
    int n=(j?t:s).size(),temp=0;
    rep(i,n){
      temp+=((j?t:s).at(i)=='A')?1:-1;
      vec.at(j).push_back(temp);
    }
  }
  auto get=
    [&](int a,int b,int i){ 	// get[a,b)  0-origin
      return vec.at(i).at(b)-vec.at(i).at(a);
    };
  int q; cin >>q;
  rep(i,q){
    int a,b,c,d; cin >>a >>b >>c >>d; a--; c--;
    printf("%s\n",(get(a,b,0)-get(c,d,1))%3?"NO":"YES");
  }
}



/// confirm df==0 ///


Measured memory_bytes: 1788
import java.util.*;
class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int a=sc.nextInt();
  int b=sc.nextInt();
  int c=sc.nextInt();
  if((a==b & b!=c) | (a!=b & b==c) | (a==c & b!=c)){
    System.out.println("Yes");
  }
  else{
    System.out.println("No");
  }
}
}

Measured memory_bytes: 23764
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

def main():

	N = INT()
	S = input()

	former = S[:N]
	latter = S[N:][::-1]

	dic_f = defaultdict(int)
	dic_l = defaultdict(int)

	for x in product([0, 1], repeat=N):
		tmp_red = ""
		tmp_blue = ""
		for i in range(N):
			if x[i]:
				tmp_red += former[i]
			else:
				tmp_blue += former[i]
		dic_f["{},{}".format(tmp_red, tmp_blue)] += 1

	for x in product([0, 1], repeat=N):
		tmp_red = ""
		tmp_blue = ""
		for i in range(N):
			if x[i]:
				tmp_red += latter[i]
			else:
				tmp_blue += latter[i]
		dic_l["{},{}".format(tmp_red, tmp_blue)] += 1

	ans = 0

	for key in dic_f:
		ans += dic_f[key] * dic_l[key]

	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 103440
import sys
input = sys.stdin.buffer.readline
import heapq

def main():
    N,Q = map(int,input().split())
    event = []
    
    for _ in range(N):
        s,t,x = map(int,input().split())
        event.append((s-x,1,x))
        event.append((t-x,0,x))
        
    for i in range(Q):
        a = int(input())
        event.append((a,2,i))
    
    event.sort()
    ans = [-1]*Q
    use = set()
    stop = []
    
    for a,b,c in event:
        if b == 1:
            use.add(c)
            heapq.heappush(stop,c)
        elif b == 0:
            use.remove(c)
        else:
            while stop and stop[0] not in use:
                heapq.heappop(stop)
            ans[c] = -1 if len(stop) == 0 else stop[0]
    
    for num in ans:
        print(num)

if __name__ == "__main__":
    main()


Measured memory_bytes: 97552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll ch[3];
int main() {
	ll n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	for(ll i=0;i<n;i++){
		cout << s[i]<<t[i];
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3624
#!/home/matsumotokazuho/.pyenv/shims/pypy
# import math
# from copy import deepcopy
# from operator import itemgetter
# from collections import defaultdict
# from collections import Counter
from collections import deque
# import itertools
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

H, W, = map(int, input().split())
Map = [input().rstrip() for _ in range(H)]
# print(Map)

White = 0
White += Map[0].count('.', 1)
for i in range(1, H - 1):
    White += Map[i].count('.')
White += Map[-1].count('.', 0, -1)

s = (0, 0)
e = (H-1, W-1)

dis = [[-1]*W for _ in range(H)]

q = deque()
q.append(s)
dis[q[0][0]][q[0][1]] = 0
while q:
    for delta in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        y, x = [o + d for o, d in zip(q[0], delta)]
        if y < 0 or H - 1 < y or x < 0 or W - 1 < x:
            pass
        elif Map[y][x] == '#':
            pass
        elif dis[y][x] != -1:
            pass
        else:
            dis[y][x] = dis[q[0][0]][q[0][1]] + 1
            q.append((y, x))
            if (y, x) == e:
                break
    else:
        q.popleft()
        continue
    break

if dis[e[0]][e[1]] == -1:
    print(-1)
else:
    print(White-(dis[e[0]][e[1]]-1))


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

using namespace std;


// Function for finding sum of larger numbers 
string findSum(string str1, string str2) 
{ 
    // Before proceeding further, make sure length 
    // of str2 is larger. 
    if (str1.length() > str2.length()) 
        swap(str1, str2); 
  
    // Take an empty string for storing result 
    string str = ""; 
  
    // Calculate length of both string 
    int n1 = str1.length(), n2 = str2.length(); 
  
    // Reverse both of strings 
    reverse(str1.begin(), str1.end()); 
    reverse(str2.begin(), str2.end()); 
  
    int carry = 0; 
    for (int i=0; i<n1; i++) 
    { 
        // Do school mathematics, compute sum of 
        // current digits and carry 
        int sum = ((str1[i]-'0')+(str2[i]-'0')+carry); 
        str.push_back(sum%10 + '0'); 
  
        // Calculate carry for next step 
        carry = sum/10; 
    } 
  
    // Add remaining digits of larger number 
    for (int i=n1; i<n2; i++) 
    { 
        int sum = ((str2[i]-'0')+carry); 
        str.push_back(sum%10 + '0'); 
        carry = sum/10; 
    } 
  
    // Add remaining carry 
    if (carry) 
        str.push_back(carry+'0'); 
  
    // reverse resultant string 
    reverse(str.begin(), str.end()); 
  
    return str; 
} 

int main()
{

    int n;
    cin >> n;
    vector<int> vec;
  
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        vec.push_back(x);
    }
    int m = vec[0];
    string sum;
    for (int i = 1; i < n; i++)
    {
        if(m>vec[i])
        {
            sum = findSum( sum , to_string(m - vec[i]) );
            

        }
        else
            m = vec[i];
    }
    if(sum.length()==0) {cout<<"0"; return 0;}
    cout << sum;
    return 0;
}


Measured memory_bytes: 4300
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
#define ll long long
#define inf int(1e9+7)
#define pb push_back
#define mp make_pair
string s,t;
bool ch[30];
int main()
{
	cin>>s;
	int n=s.size();
	for(int i=0;i<n;i++)
		ch[s[i]-'a']=1;
	if(n!=26)
	{
		cout<<s;
		for(int i=0;i<26;i++)
		{
			if(ch[i])
				continue;
			cout<<char(i+'a');
			return 0;
		}
	}
	t=s;
	if(!next_permutation(t.begin(),t.end()))
	{
		cout<<-1;
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		cout<<t[i];
		if(t[i]!=s[i])
			break;
	}
	return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int ans = a + b + c;

  if(ans <= 21) cout << "win" << endl;
  else cout << "bust" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    put(accumulate(all(a), 0) - n);

    return 0;
}

Measured memory_bytes: 3568
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
class UnionFind {
public:
	vector<int>par, rank, node;//親、木の高さ、連結成分の大きさ
	//Constructer
	UnionFind(int n) :par(n), rank(n, 0),node(n,1) {
		for (int i = 0;i < n;i++)par[i] = i;
	}
	void init(int n) {
		for (int i = 0;i < n;i++) {
			par[i] = i;
			rank[i] = 0;
			node[i] = 1;
		}
	}

	int find(int x) {
		return par[x] == x ? x : par[x] = find(par[x]);
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	void unite_tree(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	int size(int x) {
		return node[find(x)];
	}

	void unite_node(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (size(x) < size(y))swap(x, y);
		node[x] += node[y];
		par[y] = par[x];
	}
};

ll ans[100010];

int main(void){
	int n, m, ans = 0;
	string t;
	map<string, int>x;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> t;
		x[t]++;
	}
	cin >> m;
	for (int i = 0;i < m;i++) {
		cin >> t;
		x[t]--;
	}
	for (auto u = x.begin();u != x.end();++u) {
		ans = max(ans, u->second);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 












int main()
{
     int n;
     cin>>n;
     string s;
     cin>>s;
     int dp[n+1][2];memset(dp,0,sizeof(dp));
     for(int i=0;i<n;i++)
     {
          if(s[i]=='.')
          {
               dp[i+1][1]=dp[i][1];
               dp[i+1][0]=min(dp[i][1],dp[i][0])+1;
          }
          else
          {
               dp[i+1][0]=min(dp[i][1],dp[i][0]);
               dp[i+1][1]=1+dp[i][1];
          }
     }
     cout<<min(dp[n][1],dp[n][0]);

     
}







 
 

















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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b && b==c){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(); //問題数を決定
		int []time = new int[N]; //各問題にかかる時間を格納
		int T=0;
		for(int i=0;i<N;i++){//所要時間決定
			T = T + (time[i] = sc.nextInt());//ドリンクなしの場合の合計時間
		}
		
		int M=sc.nextInt();//ドリンクの数を決定
		
		int sumtime = 0; 
		for(int i=0;i<M;i++){
			sumtime = T - (time[sc.nextInt()-1] - sc.nextInt()); //要素０も参照できるようにする
			System.out.println(sumtime);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int a,b,c,k;
int main () {
cin >> a >>b >> c;
cin>>k;
for (int i=1;i<=k;i++) {
if (a>b && a>c) {
	a=a*2;
} else if (b>a && b>c) {
	b=b*2;
} else {
	c=c*2;
}
}
cout <<a+b+c<< endl;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, q int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&q)
	fmt.Scan(&s)

	counts := make([]int, n)
	for i := 1; i < n; i++ {
		if s[i] == 'C' && s[i-1] == 'A' {
			counts[i] = counts[i-1]+1
		} else {
			counts[i] = counts[i-1]
		}
	}

	qs := make([][]int, q)
	for i := 0; i < q; i++ {
		var l, r int
		fmt.Scan(&l)
		fmt.Scan(&r)

		qs[i] = []int{l-1, r-1}
	}

	for i := 0; i < q; i++ {
		fmt.Println(counts[qs[i][1]] - counts[qs[i][0]])
	}
}

Measured memory_bytes: 10116
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int A,B,C,X;
int main() {
	cin>>A>>B>>C>>X;
	int ans=0;
	for(int i=0;i<A+1;i++){
		for(int j=0;j<B+1;j++){
			for(int k=0;k<C+1;k++){
				if(i*500+j*100+k*50==X)ans++;
			}
		}
	}

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


Measured memory_bytes: 256
import math
import queue

mod = 1e9+7

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a):
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def main():
    n = int(input())
    b = [x for x in map(int,input().split())]
    ans = [b[0]]
    for i in range(n-1):
        if ans[i]>b[i]:
            ans[i] = b[i]
        ans.append(b[i])
    print(sum(ans))
    return

if __name__ == '__main__':
    main()

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


signed main(){

    i64 n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i];

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

    vector<i64> sum(n + 1, 0);
    for(int i = 0; i < n; ++i)
        sum[i + 1] = sum[i] + a[i];

    auto f = [&](int k){
        i64 cnt = 0;
        for(int i = 0; i < n; ++i){
            auto it = lower_bound(a.begin(), a.end(), k - a[i]);
            cnt += distance(it, a.end());
        }
        return cnt;
    };

    i64 ok = 0, ng = MOD;
    while(abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        (f(mid) >= m ? ok : ng) = mid;
    }

    i64 ans = 0;
    i64 cnt = 0;
    for(int i = 0; i < n; ++i){
        auto it = lower_bound(a.begin(), a.end(), ok - a[i]);
        i64 d = distance(it, a.end());
        ans += d * a[i];
        ans += sum[n] - sum[n - d];
        cnt += d;
    }
    ans -= (cnt - m) * ok;
    cout << ans << endl;

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;} // if(a%b == 0) (a/b) + 1
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0
template<typename T> void vecdbg(vector<T>& v){ rep(i, v.size()){cout << v[i] << " ";} br;}
template<typename T> void vecvecdbg(vector<vector<T>>& v){ rep(i, v.size()){rep(j, v[i].size()){cout << v[i][j] << " ";} br;}}

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, r; cin >> n >> r;
    if(n >= 10){
        cout << r << endl;
    }else{
        cout << r + 100*(10-n) << endl;
    }

}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef ll Weight;
typedef vector<vector<Weight>> Graph;
void add_edge(vector<vector<Weight>>& g, Weight from, Weight to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

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

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

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

	for (int i = k; i < n; ++i) {
		if (a[i - k] < a[i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
  

}

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


bool check_go(string s, int start, int goal) {
  if(s.at(goal)=='#') {
    return false;
  }
  for(int i=start;i<goal;i++) {
    if(s.at(i)=='#'&&s.at(i+1)=='#') {
      return false;
    }
  }
  return true;
}

bool check_change(string s, int start, int goal) {
  if(goal-start<2) {
    return false;
  }
  for(int i=start;i<=goal;i++) {
    if(s.at(i-1)=='.'&&s.at(i)=='.'&&s.at(i+1)=='.') {
      return true;
    }
  }
  return false;
}

int main() {
  int n,as,bs,ag,bg;
  string maze;
  cin >> n >> as >> bs >> ag >> bg >> maze;
  as--;
  bs--;
  ag--;
  bg--;
  //cout << int(check_go(maze,as,ag)) << int(check_go(maze,bs,bg)) << endl;
  if(check_go(maze,as,ag)&&check_go(maze,bs,bg)) {
    if(ag<bg) {
      cout << "Yes" << endl;
    }
    else if(check_change(maze, bs, bg)) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 900
def ng():
    print("No")
    exit(0)


H, W, A, B = map(int, input().split())

vT = [0,] * W
mR = []

if (A, B) == (0, 0):
    for h in range(H):
        mR.append(["0",] * W)

elif A == 0:
    for b in range(B):
        mR.append(["1",] * W)
    for h in range(H - B):
        mR.append(["0",] * W)

elif B == 0:
    for h in range(H):
        vR = ["1",] * A + ["0",] * (W-A)
        mR.append(vR)

else:
    for b in range(B):
        vR = ["1",] * A + ["0",] * (W-A)
        mR.append(vR)
    for h in range(H - B):
        vR = ["0",] * A + ["1",] * (W-A)
        mR.append(vR)
    
    
    
    # for h in range(H):
    #     cnt = 0
    #     vR = []
    #     for w in range(W):
    #         if cnt < A:
    #             if vT[w] < B:
    #                 vR.append("1")
    #                 vT[w] += 1
    #                 cnt += 1
    #             else:
    #                 pass
    #         else:
    #             vR.append("0")

    #     if cnt != A and cnt != (W - A):
    #         ng()

    #     mR.append(vR)

    # if min(vT) != A:
    #     ng()

for v in mR:
    print("".join(v))


Measured memory_bytes: 11892
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	string s;
	cin>>s;
	ll ans=0,ct=0;
	for(ll i=0;i<s.size();i++)
	{
		if(s[i]=='R')
		{
			ct++;
		}
		else
		{
			ct=0;
		}
		if(ct>ans)
		{
			ans=ct;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3624
// Last Change: 08/04/2019 22:33:20.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  string S;
  cin >> S;
  vector<ll> ans(S.size(), 0);

  auto pos = S.find("RL");
  while (pos != string::npos) {
    ans[pos] = ans[pos + 1] = 1;
    ll odd = 0, even = 0, cnt = 0;
    ll leftPos = pos;
    while (leftPos > 0 and S[leftPos - 1] != 'L') {
      --leftPos;
      ++cnt;
      if (cnt % 2 == 1) {
        ++odd;
      } else {
        ++even;
      }
    }
    ans[pos] += even;
    ans[pos + 1] += odd;

    odd = 0, even = 0, cnt = 0;
    ll rightPos = pos + 1;
    while (rightPos < S.size() - 1 and S[rightPos + 1] != 'R') {
      ++rightPos;
      ++cnt;
      if (cnt % 2 == 1) {
        ++odd;
      } else {
        ++even;
      }
    }
    ans[pos] += odd;
    ans[pos + 1] += even;

    pos = S.find("RL", pos + 1);
  }

  for (auto &&e : ans) {
    cout << e << ' ';
  }
  cout << endl;
}



Measured memory_bytes: 1408
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    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 main():
    s = input()

    l, r = 0, len(s) - 1
    x_l, x_r = 0, 0

    while l <= r:
        if s[l] == s[r]:
            l += 1
            r -= 1
            continue
        if s[l] == 'x':
            l += 1
            x_l += 1
            continue
        if s[r] == 'x':
            r -= 1
            x_r += 1
            continue
        print(-1)
        return

    print(x_l + x_r)


main()


Measured memory_bytes: 67904
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

int main(){

	char ans_upper[9],ans_under[5];
	int upper,under,S;
	double number;

	while(true){
		scanf("%lf",&number);
		if(number < 0)break;

		upper = (int)floor(number);

		if(upper >= 256){
			printf("NA\n");
			continue;
		}

		S = 128;

		for(int i = 0; i < 8; i++){
			if(upper >= S){
				ans_upper[i] = '1';
				upper -= S;
			}else{
				ans_upper[i] = '0';
			}
			S /= 2;
		}

		ans_upper[8] = '\0';


		under = 10000*(number - (int)floor(number));

		for(int i = 0; i < 4; i++){
			under *= 2;
			if(under/10000 >= 1){
				ans_under[i] = '1';
			}else{
				ans_under[i] = '0';
			}
			under %= 10000;
		}

		if(under != 0){
			printf("NA\n");
			continue;
		}

		ans_under[4] = '\0';

		printf("%s.%s\n",ans_upper,ans_under);

	}

	return 0;
}

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

using namespace std;

int main() {
  int N; cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  int c = 0;
  int ans = 0;
  while(true) {
    if(a[c] == 2) {
      ans++;
      break;
    }
    else if(a[c] == -1) {
      ans = -1;
      break;
    }

    int t = a[c] - 1;
    a[c] = -1;
    c = t;
    ans++;
  }

  if(ans == -1) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    
    int x;
    vector<int> v;

    cin >> x;

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

    for(int i = 1; i <= x; i++){
        for(int j = 2; j <= x; j++){
            if(pow(i, j) <= x){
                v.emplace_back(pow(i, j));
            }
        }
    }

    cout << *max_element(v.begin(), v.end()) << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int q;
ll a[110], b[110];

void solve() {
    for (int i = 0; i < q; i++) {
        if (a[i] > b[i]) swap(a[i], b[i]);
        if (b[i] <= a[i]+1) {
            cout << 2 * (a[i] - 1) << endl;
        } else {
            ll lb = 0, ub = b[i] - a[i] + 1;
            while (ub - lb > 1) {
                ll mid = (lb + ub) / 2;
                ll m0 = mid / 2, m1 = (mid + 1) / 2;
                ll v0 = (a[i] + m0) * (a[i] + mid - m0);
                ll v1 = (a[i] + m1) * (a[i] + mid - m1);
                if (max(v0, v1) < a[i] * b[i]) {
                    lb = mid;
                } else {
                    ub = mid;
                }
            }
            cout << 2 * (a[i] - 1) + lb << endl;
        }
    }
}

void input() {
    cin >> q;
    for (int i = 0; i < q; i++) cin >> a[i] >> b[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


Measured memory_bytes: 3564
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  string s;cin>>s;
  string p;cin>>p;
  int l=s.size();
  string t=s;
  if(s==p){
    cout<<"Yes"<<endl;
    return 0;
  }
  rep(i,l){
    string tt=t;
    char tmp=t[l-1];
    rep(j,l-1){
      tt[j+1]=t[j];
    }
    tt[0]=tmp;
    if(tt==p){
      cout<<"Yes"<<endl;
      return 0;
    }
    t=tt;
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
(* Vicfred
 * https://atcoder.jp/contests/abc146/tasks/abc146_a
 * implementation
 * *)
Printf.printf "%d\n" @@ match read_line () with
| "SUN" -> 7
| "MON" -> 6
| "TUE" -> 5
| "WED" -> 4
| "THU" -> 3
| "FRI" -> 2
| "SAT" -> 1
| _ -> -1



Measured memory_bytes: 3604
include Math
define_method :max, -> (a,b) { a > b ? a : b }
define_method :min, -> (a,b) { a < b ?  a : b }
define_method :swap, -> (a,b) { a, b = b, a }
define_method :rep, -> (num, &block) { num.times do |i| block.call(i) end }
define_method :repl, -> (st,en, &block) { st.upto en-1 do |i| block.call(i) end }
define_method :array, -> (size,init = nil) { Array.new(size){init} }
define_method :darray, -> (size1, size2, init = nil) { Array.new(size1){Array.new(size2){init}} }
define_method :gi, -> () { gets.split.map(&:to_i) }
define_method :gs, -> () { gets.chomp }
define_method :putall, -> (obj) { obj.each do |o| puts o end }
define_method :fi, ->() {first}

	n = gi.fi

	if n >=1200
		puts "ARC"
	else
		puts "ABC"
	end


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

char A[2010], B[2010];
int s[6030], x[2010], y[2010];

int main(void) {
  scanf("%s%s", A, B);
  int n = strlen(A), flg = 0;
  for(int i = 0; i < n; i++) {
    flg |= A[i] - '0';
    s[i] = !i ? B[i] - '0' : s[i - 1] + B[i] - '0';
  }
  if(flg && !s[n - 1]) return puts("-1"), 0;

  for(int i = 0, lst; i < 2 * n; i++) {
    if(B[i % n] == '1') lst = i;
    if(i >= n)
      x[i - n] = i - lst;
  }
  for(int i = n; i < 3 * n; i++)
    s[i] = s[i - 1] + B[i % n] - '0';
  for(int i = 3 * n - 1, lst; i >= n; i--) {
    if(B[i % n] == '1') lst = i;
    if(i < 2 * n)
      y[i - n] = lst - i;
  }

  /*
  for(int i = 0; i < n; i++)
    cerr << x[i] << " " << y[i] << endl;
  */

  int ans = 0x3f3f3f3f;
  for(int dis = -n + 1; dis < n; dis++) {
    int now = 0, l = max(-dis, 0), r = max(dis, 0);
    vector<pair<int, int> > vec;
    for(int i = 0; i < n; i++) {
      int j = ((i + dis) % n + n) % n;
      if(A[i] == B[j]) continue;
      now++;
      if(dis > 0 ? s[i + dis + n] - s[i + n - 1] : s[i + n] - s[i + dis + n - 1]) continue;
      //cerr << dis << " " << i << " " << x[i] << " " << y[i] <<endl;
      vec.push_back(make_pair(x[i], y[i]));
    }
    if(vec.size()) {
      sort(vec.begin(), vec.end());
      //cerr << now << endl;
      int tmp = 0x3f3f3f3f;
      for(int i = vec.size() - 1; i >= 0; i--) {
	l = max(-dis, vec[i].first);
	if(i + 1 == vec.size() || vec[i].first < vec[i + 1].first)
	  tmp = min(tmp, l * 2 + r * 2 - abs(dis));
	r = max(r, vec[i].second);
      }
      tmp = min(tmp, max(-dis, 0) * 2 + r * 2 - abs(dis));
      now += tmp;
    }
    else now += abs(dis);
    //cerr << dis << " " << now << endl;
    ans = min(ans, now);
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int main() {
	scanf("%s", s);
	int remain = 0;
	int n = strlen(s);
	for(int i = 0; i < n; ++i) {
		int dig = s[i] - '0';
		remain += dig;
		remain %= 9;
	}
	if(remain == 0) puts("Yes");
	else puts("No");
	return 0;
}


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

int main()
{
   int i;
   cin >> i;
   int h, m, s;
   h = i / 60 / 60;
   m = (i / 60) % 60;
   s = i % 60;
   cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3100
#include <cmath>
#include <cstdio>
#include <iostream>
#include<cstdlib>
using namespace std;


int main(){
int k,s;
cin >> k>>s;
long ans=0;
for(int a=0;a<=k;a++){
  for(int b=0;b<=k;b++){
    if (s - a - b <= k and s - a - b >=0){
      ans++;
    }
  }
}
cout << ans<<endl;
}

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

int main(void)
{
    int x, a, b;
    cin >> x >> a >> b;

    if(abs(x-a) > abs(x-b))
        cout << "B" << endl;
    else
        cout << "A" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define P printf
int main(void){int h,w,i,j;for(;;){scanf("%d %d",&h,&w);if(h+w==0)return 0;for(i=h;i>0;--i){for(j=w;j>0;--j)P(i==h||i==1||j==w||j==1?"#":".");P("\n");}P("\n");}}

Measured memory_bytes: 588
#include<bits/stdc++.h>
using namespace std;
template<unsigned N,unsigned M> struct Maxcost_Maxflow
{
    #define int long long
    int const inf=1e15;
    int target[M],pre[M],last[N],tot=1,flow[M],maxflow,
    cost,deep[N],w[M],ef[M],upd[M],dis[N],pr[N],s,t;
    void add(int x,int y,int z,int co)
    {
        tot++;
        target[tot]=y;
        pre[tot]=last[x];
        last[x]=tot;
        flow[tot]=z;
        w[tot]=co;
        target[++tot]=x;
        pre[tot]=last[y];
        last[y]=tot;
        w[tot]=-co;
    }
    queue<int>q;
    bool inq[N];
    bool spfa()
    {
        q.push(s);
        for(register int i=s;i<=t;i++)
            dis[i]=-inf,ef[i]=inf,pr[i]=0,upd[i]=0;
        dis[s]=0;
        inq[s]=1;
        while(!q.empty())
        {
            int now=q.front();inq[now]=0;q.pop();
            for(register int i=last[now];i;i=pre[i])
            {
                int tar=target[i];
                if(flow[i]&&(dis[now]+w[i]>dis[tar]))
                {
                    dis[tar]=dis[now]+w[i];
                    pr[tar]=now;
                    upd[tar]=i;
                    ef[tar]=min(ef[now],flow[i]);
                    if(!inq[tar])q.push(tar),inq[tar]=1;
                }
            }
        }
        return pr[t];
    }
    void ek()
    {
        while(spfa())
        {
            maxflow+=ef[t];
            cost+=dis[t]*ef[t];
            for(register int i=t;i!=s;i=pr[i])
            {
                flow[upd[i]]-=ef[t];
                flow[upd[i]^1]+=ef[t];
            }
        }
    }
    #undef int
};
Maxcost_Maxflow<4005,400005>g;
int main()
{
    int n,x,y,z;
    scanf("%d",&n);
    g.t=2*n+5;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        g.add(i,2*n+1,1e9,x+y);
        g.add(i,2*n+2,1e9,x-y);
        g.add(i,2*n+3,1e9,-x+y);
        g.add(i,2*n+4,1e9,-x-y);
        g.add(0,i,z,0);
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        g.add(2*n+1,i+n,1e9,-x-y);
        g.add(2*n+2,i+n,1e9,-x+y);
        g.add(2*n+3,i+n,1e9,x-y);
        g.add(2*n+4,i+n,1e9,x+y);
        g.add(i+n,g.t,z,0);
    }
    g.ek();
    printf("%lld\n",g.cost);
    return 0;
}

Measured memory_bytes: 4512
#include <iostream>
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int H,W;
  std::cin >> H >> W;
  while(H != 0 && W != 0) {
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        if(i > 0 && i < H-1 && j > 0 && j < W-1 ) {
          printf(".");
        }
        else {
          printf("#");
        }
      }
      printf("\n");
    }
    printf("\n");
    std::cin >> H >> W;
  }
  return 0;
}

Measured memory_bytes: 3040
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    count=0
    l=[0]*(10**6)
    for a in A:
        l[a]+=1
        l[a+1]+=1
        l[a+2]+=1
    print(max(l))




if __name__ == "__main__":
    main()

Measured memory_bytes: 60768
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

int main() {
	int H, W;
	while (true) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 1; i <= H; ++i) {
			for (int j = 1; j <= W; ++j) {
				if (j == W)cout << "#" << endl;
				else cout << "#" << flush;
			}
		}
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
// template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    int n;
    ll k;
    cin >> n >> k;
    priority_queue<pii, vector<pii>, greater<pii> > q;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        q.push(pii(a, b));
    }
    ll c = 0;
    while (!q.empty()) {
        pii now = q.top();
        q.pop();
        c += now.S;
        if (c >= k) {
            cout << now.F << endl;
            return 0;
        }
    }
}



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

void solve()
{
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    A--, B--, C--, D--;

    string S;
    cin >> S;
    S += "##";

    if(S[C] == '#' || S[D] == '#') {
        cout << "No" << endl;
        return;
    }
    while(true) {
        if(B == D)
            break;
        if(B != C && S[B-1] == '.' && S[B+1] == '.')
            break;
        if(S[B+1] == '#' && S[B+2] == '#')
        {
            cout << "No" << endl;
            return;
        }
        if(S[B+1] == '.')
            B++;
        else if(S[B+1] == '#')
            B+=2;
    }

    while(true) {
        if(A == C)
            break;
        if(S[A+1] == '.' && A+1 != B)
            A++;
        else if(S[A+2] == '#' || A+2 == B) {
            cout << "No" << endl;
            return;
        }
        else
            A+=2;
    }

    while(true) {
        if(B == D)
            break;
        if(S[B+1] == '.' && B+1 != A)
            B++;
        else if(S[B+2] == '#' || B+2 == A) {
            cout << "No" << endl;
            return;
        }
        else
            B += 2;
    }

    cout << "Yes" << endl;
}

int main()
{
    cin.sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
}

Measured memory_bytes: 592
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    long long n;
    cin>>n;
    
    if(n<=2){
        cout<<"1"<<endl;
        return 0;
    }else{
    long long s;
    for(long long i=1;i<n;i++){
        
        s=i*i;
        if(s>n){
            cout<<(i-1)*(i-1)<<endl;
            return 0;
        }
        
    }
    }
    return 0;
}








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

class F
{
	static void Main()
	{
		Func<long[]> read = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
		var t = read();
		var a = read();
		var b = read();
		if (a[0] > b[0]) { var _ = a; a = b; b = _; }

		var sa = t.Zip(a, (u, x) => u * x).Sum();
		var sb = t.Zip(b, (u, x) => u * x).Sum();
		if (sa == sb) { Console.WriteLine("infinity"); return; }
		if (sa < sb) { Console.WriteLine(0); return; }

		var n = t[0] * (b[0] - a[0]) / (double)(sa - sb);
		Console.WriteLine((long)n * 2 + ((long)n == n ? 0 : 1));
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, n) {
        cin >> s[i];
    }
    sort(whole(s));
    rep(i, n) cout << s[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 3648
n, k = map(int,input().split())
p = list(map(int,input().split()))
mu = [(a+1)/2 for a in p]
maxsum = sum(mu[:k])
now = maxsum
left = 0
right = k
while right<n:
    now = now+mu[right]-mu[left]
    if maxsum<now:
        maxsum = now
    left += 1
    right += 1
print(maxsum)

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

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    char t = 'a';
    char w;
    while(true){
        if(t == 'a'){
            if(a.size() == 0){
                w = 'A';
                break;
            }
            t = a[0];
            a.erase(0, 1);
        }else if(t == 'b'){
            if(b.size() == 0){
                w = 'B';
                break;
            }
            t = b[0];
            b.erase(0, 1);
        }else if(t == 'c'){
            if(c.size() == 0){
                w = 'C';
                break;
            }
            t = c[0];
            c.erase(0, 1);
        }
    }

    cout << w << endl;
}

Measured memory_bytes: 3584
#include <iostream>

using namespace std;
const int MAXN = 100010;

int n;
int a[MAXN];
int cnt[MAXN];

void solve() {
  for (int i=0;i<n;i++) {
    for (int j=-1;j<=1;j++) {
      int v = a[i] + j;
      if (v >= 0) {
        cnt[v]++;
      }
    }
  }
  int maxCnt = 0;
  for (int i=0;i<MAXN;i++) {
    maxCnt = max(maxCnt, cnt[i]);
  }
  cout << maxCnt << endl;
}

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


Measured memory_bytes: 1024
a = list(map(int,input().split()))
n = a[0]
k = a[1]

kind = set()

for i in range(k):
    d = input()
    list_a = list(map(int,input().split()))
    s_a = set(list_a)
    kind = kind | s_a

print(n-len(kind))

Measured memory_bytes: 9212