akhauriyash/Code-Regression huggingface dataset:
def C(n,m):
    S=1
    for i in range(1,n+1):
        S=S*i
    for i in range(1,m+1):
        S=S//i
    for i in range(1,n-m+1):
        S=S//i
    return S
N,P=map(int,input().split())
A=[int(i) for i in input().split()]
X=0;Y=0
#X:偶数
#Y:奇数
for i in range(N):
    if A[i]%2==0:
        X+=1
    else:
        Y+=1
Z=0
for i in range(Y+1):
    if i%2==P:
        Z+=C(Y,i)
print(Z*2**(X))


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

int n;
int mn[150];
int freq[150];

int main()
{
	cin >> n;

	for(int i=0;i<150;i++) mn[i] = 1e9;
	
	for(int i=0;i<n;i++)
	{
		string z;
		cin >> z;
		for(int j=0;j<150;j++) freq[j] = 0;
		
		for(int j=0;j<z.size();j++)
		{
			freq[z[j]]++;
		}
		
		for(int j=97;j<=122;j++)
		{
			mn[j] = min(mn[j] , freq[j]);
		}
	}
	
	for(int i=97;i<=122;i++)
	{
		for(int j=0;j<mn[i];j++) cout << (char)i;
	}
	
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[10],b[10];
bool vis[10];
int t[10];
int p,q,tim;
inline bool cck() {
	bool x=true,y=true;
	for (int i=1;i<=n;++i)
		if (a[i]^t[i]) {
			x=false;
			break;
		}
	for (int i=1;i<=n;++i)
		if (b[i]^t[i]) {
			y=false;
			break;
		}
	if (x) p=tim;
	if (y) q=tim;
}
void dfs(int pos) {
	if (pos==n+1) {
		++tim;
		cck();
		return ;
	}
	for (int i=1;i<=n;++i)
		if (!vis[i]) {
			t[pos]=i;
			vis[i]=true;
			dfs(pos+1);
			t[pos]=0;
			vis[i]=false;
		}
}
inline int abs(int v) {
	return v<0?-v:v;
}
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	for (int i=1;i<=n;++i) scanf("%d",&b[i]);
	dfs(1);
	printf("%d\n",abs(p-q));
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
    int N,m,i,j,minj,count,x;
    scanf("%d",&N);
    m=N-1;
    int a[m];
    scanf("%d",&a[0]);
    for(N=1;N<=m;N++){
        scanf(" %d",&a[N]);
    }
    count=0;
    for(i=0;i<N-1;i++){
        minj=i;
        for(j=i;j<=N-1;j++){
            if(a[j]<a[minj]){
                minj=j;
            }
        }
        j=i;
        x=a[j];
        a[j]=a[minj];
        a[minj]=x;
        if(minj!=i){
            count++;
        }
    }
    printf("%d",a[0]);
    for(N=1;N<=m;N++){
        printf(" %d",a[N]);
    }
    printf("\n%d\n",count);
    return 0;
}



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

int main()
{
    int n;
    cin>>n;
    long long ans=0;
    for(int i=1; i<=n; i++)
        if(i%3!=0 && i%5!=0) ans+=i;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        int[] T = new int[N];
        for (int i=0; i<N; i++) {
            T[i] = scan.nextInt();
        }

        int M = scan.nextInt();
        int P, X, ans;
        for (int i=0; i<M; i++) {
            P = scan.nextInt();
            X = scan.nextInt();

            ans = 0;
            for (int j=0; j<N; j++) {
                if (j+1 == P) {
                    ans += X;
                } else {
                    ans += T[j];
                }
            }

            System.out.println(ans);
        }
    }
}


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

int main(void){
  int H, W;
  cin >> H >> W;
  string S[H];
  int ans[H][W];
  for(int i=0; i<H; i++) for(int j=0; j<W; j++) ans[i][j] = 0;
  for(int i=0; i<H; i++) cin >> S[i];
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i][j] == '#'){
//        cout << i << ", " << j << endl;
        for(int k=max(0, i-1); k <= min(H-1, i+1); k++){
          for(int l=max(0, j-1); l <= min(W-1, j+1); l++){
            if(k == i && l == j) continue;
            ans[k][l]++;
//            cout << k << ", " << l << endl;
          }
        }        
      }      
    }    
  }
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      if(S[i][j] == '#') cout << '#';
      else cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys

sys.setrecursionlimit(10**7)
H,W=map(int,input().split())
sy,sx=map(int,input().split())
gy,gx=map(int,input().split())

sx,sy=sx-1,sy-1
gx,gy=gx-1,gy-1

maze=[[i for i in input()] for _ in range(H)]

visited = [[-1]*W for _ in range(H)]
queue = deque([])
queue.append((sx,sy))
visited[sy][sx] = 0
def bfs(v,queue,gx,gy,maze):
    check=deque([])



    while len(queue) != 0:
        n = queue.popleft()
        x,y = n[0], n[1]
        flag=0

        if n == (gx,gy):
            print(v)
            exit()

        for i, j in [(1,0), (0,1), (-1,0), (0,-1)]:
            if (x+i < 0) or (x+i >=W) or (y+j < 0) or (y+j >=H):
                continue
            if maze[y+j][x+i] == '.' and visited[y+j][x+i] == -1:
                queue.append((x+i,y+j))
                visited[y+j][x+i] = v
            elif maze[y+j][x+i] == '#':
                flag=1
        if flag==1:
            check.append((x,y))

    while len(check) != 0:
        n=check.popleft()
        x,y=n[0],n[1]
        for i in range(-2,3):
            for j in range(-2,3):
                if (x+i < 0) or (x+i >=W) or (y+j < 0) or (y+j >=H):
                    continue
                if maze[y+j][x+i] == '.' and visited[y+j][x+i] == -1:
                    queue.append((x+i,y+j))
                    visited[y+j][x+i] = v+1

    if len(queue)!=0:
        bfs(v+1,queue,gx,gy,maze)



bfs(0,queue,gx,gy,maze)
print(-1)


Measured memory_bytes: 428988
N = int(input())
As = [int(i) for i in input().split()]

x_0 = sum(As) - 2 * sum(As[1::2])
print(int(x_0), end=" ")
x = x_0

for i in range(N-2):
    x = 2*As[i] - x
    print(int(x), end=" ")

x = 2*As[N-2] - x
print(int(x))

Measured memory_bytes: 14024
N,M,C = map(int, input().split())
b_list = list(map(int, input().split()))
ans=0
for i in range(N):
  a_list = list(map(int, input().split()))
  atai=C
  for j in range(M):
    atai+=a_list[j]*b_list[j]
  if atai>0:
    ans+=1
print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=1000000007;
const long long inf=1ll<<61;
int a[400006];
signed main(){
  int k,n;cin>>k>>n;
  rep(i,n)cin>>a[i];
  rep(i,n)a[i+n]=a[i]+k;
  int ans=inf;
  rep(i,n)ans=min(ans,a[i+n-1]-a[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 6636
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main(void){
    int N,H;
    cin >> N >> H;
    
    int a[N], b[N];
    int sum = 0;
    cin >> a[0] >> b[0];
    int aMax = a[0];
    if(N > 1) {
        for(int i = 1;i < N;i++) {
            cin >> a[i] >> b[i];
            //aNの中で最大を見つける
            if(a[i] > aMax) { aMax = a[i]; }
        }
    }

    //bNのソート（降順）
    sort(b,b+N, greater<int>());
    for (int i = 0;i < N;i++) {
        if(aMax >= b[i]) { 
            if((H - sum) % aMax == 0) { cout << i + (H - sum) / aMax; return 0; }
            else {cout << i + (H - sum) / aMax + 1; return 0; }
        }
        else {
            sum += b[i];
            if(sum >= H) { cout << i + 1; return 0; }
        }
    }
    if((H - sum) % aMax == 0) { cout << N + (H - sum) / aMax; }
    else {cout << N + (H - sum) / aMax + 1; }
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

int main()
{
    int a, b, h, area, x;
    scanf("%d %d %d", &a, &b, &h);
    x = a + b;
    area = (0.5 * x * h);
    printf("%d\n", area);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
int n, k, neg;
std::deque<bool> q;
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	if(k > n + n) k = k % (n + n) + n + n;
	rep(i, 1, n) {
		char ch; cin >> ch;
		q.emplace_back(ch & 1);
	}
	rep(i, 1, k) {
		if(q.front() ^ neg)
			q.front() ^= 1;
		else
			q.emplace_back(q.front()), q.pop_front(), neg ^= 1;
	}
	for(auto i : q) cout.put("BA"[i ^ neg]);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
#define MOD 1000000007
#define PSET(x,y) fixed<<setprecision(y)<<x
#define ll long long
#define ld long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define lop(i,a,b) for(ll i=a;i<b;i++)
#define lopr(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define ff first
#define ss second
#define pi pair<int,int>
#define pll pair<ll, ll>
#define si set<int>
#define sll set<ll>
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define state tuple<int,int,int>
#define graph map<ll,list<ll>>

inline int sbt(int x){return __builtin_popcount(x);} //returns number of set bits

using namespace std;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

#define SIZE

int dig(char ch){
	return ch-'0';
}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    
    fast_io()
    
    string s;
    cin>>s;

    int y;
    y = dig(s[0]);
    y *= 10;
    y += dig(s[1]);
    y *= 10;
    y += dig(s[2]);
    y *= 10;
    y += dig(s[3]);

    int m;
    m = dig(s[5]);
    m *= 10;
    m += dig(s[6]);

    int d;
    d = dig(s[8]);
    d *= 10;
    d += dig(s[9]);

    deb(y,m,d);
    if(y<=2019 && m<=4 && d<=30)
		cout<<"Heisei";
    else
    	cout<<"TBD";

    return 0;
}

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

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

    int r, g, b;
    
    int count = 0;

    for (r=0; r*R<=N; r++){
        for (g=0; r*R + g*G<=N; g++){
            if( (N - r*R - g*G)%B == 0){

                count++;
            }
        }
    }

    printf("%d",count);
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> v;
	for(int i=0; i<m; i++){
		int a, b;
		cin >> a >> b;
		v.push_back(make_pair(a, b));
	}
	sort(v.begin(), v.end());
	int ans=0, l=v[0].first, r=v[0].second;
	for(int i=1; i<m; i++){
		if(r<=v[i].first){
			ans++;
			l=v[i].first;
			r=v[i].second;
		}else{
			l=v[i].first;
			r=min(r, v[i].second);
		}
	}
	ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
	long a, b, _a, _b, r;
	while( cin >> a >> b)
	{
		if( a < b ) swap(a, b);
		_a = a; _b = b;
		while( ( r = _a % _b ) != 0 ){
			_a = _b;
			_b = r;
		}
		cout << _b << " " << (a / _b) * b << "\n";
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main() {
  int k;
  scanf("%d",&k);
  int n[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};
  printf("%d\n", n[k-1]);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

bool ok(const string &small, const string& large){
    for(size_t b=0; b<large.size(); b++){
        //cout<<"b = "<<b<<endl;
        for(size_t d=0; b+d*(small.size()-1)<large.size(); d++){
            //cout<<"d = "<<d<<endl;
            for(size_t is=0, il=b; is<small.size() && il<large.size(); is++, il+=d){
                //cout<<is<<" "<<il<<endl;
                if(small[is]!=large[il]) break;
                if(small[is]==large[il] && is==small.size()-1){
                    //cout<<"found "<<large<<endl;
                    return true;
                }
            }
        }
    }
    //cout<<"not found "<<large<<endl;
    return false;
}

int n;
string small, large;
int main(){
    int n;
    while(cin>>n){
        cin>>small;
        int ans=0;
        while(n--){
            cin>>large;
            ans+=ok(small,large);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1208
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    long int n;
    cin >> n;
    long int t[2];

    double a1 = sqrt(n);
    int a = int(a1);
  
    while (n >= a * a) {
        if (n % a == 0) {
            t[0] = a;
            n /= a;
            break;
        } else {
            a--;
        }
    }
    t[1] = n;

    cout << t[0]-1+t[1]-1;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


void dfs(int v, int p, Graph &G, vector<ll> &cnt){
  for (int nv : G[v]){
    if (nv == p) continue;
    cnt[nv] += cnt[v];
    dfs(nv, v, G, cnt);
  }
}

int main() {
  int n,q; cin >>n >>q;
  Graph G(n);
  rep(i, n-1){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<ll> cnt(n, 0);
  rep(i, q){
    int p,x; cin >>p >>x; p--;
    cnt[p] += x;
  }
  dfs(0, 0, G, cnt);
  rep(i, n){
    cout <<cnt[i];
    if (i == n-1) cout <<endl;
    else cout <<" ";
  }
}

Measured memory_bytes: 30464
def main():
    from bisect import bisect_left, bisect_right
    from itertools import accumulate
    import sys

    input = sys.stdin.readline

    N, M, V, P = map(int, input().split())
    *A, = sorted(map(int, input().split()))
    acc = (0,) + tuple(accumulate(A))

    def is_ok(mid):
        x = A[mid]
        ika = bisect_right(A, x)
        rest = max(0, V - ika)
        if rest >= P:
            # 上位P-1に毎回加算して、
            # rest-(P-1)人に対し、最大値を上げないようにして、均等に割り振る
            rng = N - ika - (P - 1) # 加算先候補数
            times = V - (P - 1) - ika # M人のjudgeがtimes回加算する

            range_sum = acc[mid + 1 + rng] - acc[mid + 1]
            to_sub = A[mid + rng] * rng - range_sum
            to_dist = M * times - to_sub

            if to_dist <= 0:
                return A[N - P] <= x + M
            else:
                to_add = (to_dist + rng - 1) // rng
                return max(A[N - P], A[mid + rng] + to_add) <= x + M

        else:
            return A[N - P] <= x + M

    def binary_search():
        ok = N - 1
        ng = -1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    idx = binary_search()
    print(N - bisect_left(A, A[idx]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61720
import java.util.Scanner;
class Main {

	public static void main(String[] args) {
		int i,j,k,v;
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		int array[] = new int[n];

		for(i=0;i<n;i++)array[i] = Integer.parseInt(in.next());

	for(i=0;i<n;i++){
		v = array[i];
		j = i-1;
		while(j>=0 && array[j]>v){
			array[j+1] = array[j];
			j--;
		array[j+1] = v;
		}
	    for(k = 0;k<n-1;k++)System.out.print(array[k]+" ");
	    if(i<(n-1))System.out.println(array[k]);
	    else System.out.println(array[k]);
	}
	}
}

Measured memory_bytes: 31536
/**
*    created: 12.05.2020 09:15:30
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int c = b - a;
    if(c%2==0) cout << "Alice" << endl;
    else cout << "Borys" << endl;
}

Measured memory_bytes: 256
class SegTree:
    init_val = -1  # 問題によって変える

    def __init__(self, init_l):
        self.n = len(init_l)
        self.n0 = 2 ** (self.n - 1).bit_length()  # n以上で最小の2のべき乗
        self.l = [self.init_val] * 2 * self.n0  # 区間外の値を初期化
        for i in range(self.n):
            self.l[i + self.n0 - 1] = init_l[i]
        for i in range(self.n0 - 2, -1, -1):
            self.l[i] = self.func(self.l[2 * i + 1], self.l[2 * i + 2])

    # 問題によって変える
    def func(self, x, y):
        return max(x, y)

    def update(self, i, new):
        i += self.n0 - 1
        self.l[i] = new
        while i + 1:
            i = (i - 1) // 2
            self.l[i] = self.func(self.l[i * 2 + 1], self.l[i * 2 + 2])

    # Gets min between [a, b)
    def query(self, a, b):
        return self._query(a, b, 0, 0, self.n0)

    def _query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return self.init_val
        if a <= l and r <= b:
            return self.l[k]
        vl = self._query(a, b, k * 2 + 1, l, (l + r) // 2)
        vr = self._query(a, b, k * 2 + 2, (l + r) // 2, r)
        return self.func(vl, vr)

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ba = []
for _ in range(n):
    a, b = map(int, input().split())
    ba.append([b, a])
ba.sort(reverse=True)
days = [x for x in range(m)]
ans = 0
s = SegTree(days)
for x in ba:
    a = x[1]
    b = x[0]
    lim = m - a
    if lim < 0:
        continue
    d = s.query(0, lim+1)
    if d >= 0:
        ans += b
        s.update(d, -1)
print(ans)


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

int main() {
    int W, H, N, x, y, a;
    cin >> W >> H >> N;
    int x1 = 0, x2 = W, y1 = 0, y2 = H;
    for (int i = 0; i < N; i++) {
        cin >> x >> y >> a;
        if (a == 1) x1 = max(x1, x);
        else if (a == 2) x2 = min(x2, x);
        else if (a == 3) y1 = max(y1, y);
        else y2 = min(y2, y);
    }
    if (x2 - x1 < 0 || y2 - y1 < 0) cout << 0 << endl;
    else {
        int ans = (x2 - x1) * (y2 - y1);
        cout << ans << endl;
    }
    return 0;
}

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

const string K = "keyence";
const int K_len = 7;
string S;
int S_len;

int top_same(void) {
	int cnt = 0;
	for (int i = 0; i < K_len; ++i) {
		if (S[i] != K[i])
			break;
		++cnt;
	}
	return cnt;
}

int end_same(void) {
	int cnt = 0;
	for (int i = 0; i < K_len; ++i) {
		if (S[S_len - 1 - i] != K[K_len - 1 - i])
			break;
		++cnt;
	}
	return cnt;
}

int main(void) {
	cin >> S;
	S_len = S.length();

	string ans = "YES\n";
	int top_c = top_same();
	if (top_c != 7) {
		int end_c = end_same();
		if (top_c + end_c < K_len)
			ans = "NO\n";
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int n,a[maxn];
long long m,b[maxn];
long long check(int mid){
	long long s=0;
	for(int i=1;i<=n;i++)
		s+=n-(lower_bound(a+1,a+1+n,mid-a[i])-a)+1;
	return s;
}
void calc(int mid){
	long long ans=0,s=0;
	for(int i=1;i<=n;i++) b[i]=b[i-1]+a[i];
	for(int i=1;i<=n;i++){
		int x=lower_bound(a+1,a+1+n,mid+1-a[i])-a;
		ans+=1ll*a[i]*(n-x+1)+b[n]-b[x-1],s+=n-x+1;
	}
	printf("%lld\n",ans+(m-s)*mid);
}
int main()
{
	scanf("%d%lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int l=2,r=200000,mid;
	while(l<r){
		mid=(l+r+1)>>1;
		if(check(mid)>=m) l=mid;
		else r=mid-1;
	}
	calc(l);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL //デバッグ出力系
#define dout(s) cout<<s<<"\n";
#define debug() if(true)
#else
#define dout(s)
#define debug() if(false)
#endif//
#define next asdnext
#define prev asdprev
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define vout(v) for(auto &i:v){cout<<i<<" ";}cout<<"\n"; //配列出力
#define vin(v) for(auto &i:v)cin>>i; //配列入力
#define vec(v,n) vector<int> v(n);
typedef long long ll;
typedef unsigned long long ull;


void Main() {
	int N, M;
	cin >> N >> M;

	vector<vector<int>> den(M);
	vector<int> state(M);



	for (int i = 0; i < M; i++) {
		int K;
		cin >> K;
		rep(j,K) {
			int tmp;
			cin >> tmp;
			den[i].push_back(tmp);
		}
	}

	rep(i,M) {
		cin >> state[i];
	}

	debug() {
		for (int i = 0; i < M; i++) {
			cout << "den" << i << ":";
			for (auto&j:den[i]) {
				cout << j;
			}
			dout("");
		}
	}

	dout("out:");
	dout((1<<N));


	int cnt=0;

	for (int i = 0; i < (1 << N); i++) {
		bool endstate = true;
		for (int j = 0; j < M; j++) {
			int res = 0;
			for(auto&k:den[j]){
				if (i & (1 << (k - 1))) res++;
				dout("aaa" << k);
			}
			dout(i << "\t"<< j << "\t"<<res);
			if (res%2 != state[j]) {
				endstate = false;
				break;
			}
		}
		if (endstate) { 
			cnt++; 
			dout("end:" + to_string(i));
		}
	}
	cout << cnt << "\n";
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


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

using namespace std;
const int maxn =  1e6 + 50;
#define ll long long
#define ios std::ios::sync_with_stdio(false)
const ll INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
/*


ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}//xµÄn´Î·½mod


ll mult(ll a,ll b,ll p){a%=p;b%=p;ll r=0,v=a;while(b){if(b&1){r+=v;if(r>p)r-=p;}v<<=1;if(v>p)v-=p;b>>=1;}return r;}
ll quick_pow(ll a,ll b,ll p){ll r=1,v=a%p;while(b){if(b&1)r=mult(r,v,p);v=mult(v,v,p);b>>=1;}return r;}
bool CH(ll a,ll n,ll x,ll t)
{ll r=quick_pow(a,x,n);ll z=r;for(ll i=1;i<=t;i++){r=mult(r,r,n);if(r==1&&z!=1&&z!=n-1)return true;z=r;}return r!=1;}
bool Miller_Rabin(ll n)
{if(n<2)return false;if(n==2)return true;if(!(n&1))return false;ll x=n-1,t=0;while(!(x&1)){x>>=1;t++;}srand(time(NULL));
ll o=8;for(ll i=0;i<o;i++){ll a=rand()%(n-1)+1;if(CH(a,n,x,t))return false;}return true;}


*/

#define int long long
#define sc(t) scanf("%lld",&t)
#define pr(ans) printf("%lld\n",ans)
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}//xµÄn´Î·½mod
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
typedef unsigned long long ULL;

int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
#define debug(x) cout << #x << " : " << x << '\n';
#define sb cout << "sb\n" << '\n';
#define fi first
#define se second
#define pb(a) push_back(a)
#define cn cout << '\n'
const double pi = 3.1415926535897932384626;
signed main()
{
    ios;
    int a , b , t , m;
    cin >> a >> b >> t >> m;
    double ans = 0;
    double jiao = t * 30 + (1.0 * m / 60) * 30 - m * 6;
    if(jiao < 0)jiao = abs(jiao);
    jiao = min(360 - jiao , jiao);
    //cout << jiao << '\n';
    ans = a * a + b * b -  2.0 * a * b * cos(pi * jiao / 180);
    //cout << ans << '\n';
    cout << fixed << setprecision(20) << sqrt(ans) << '\n';
    return 0;
}
/*

*/


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int N;
vector<ll> a(401), sum(401, 0);
vector<vector<ll>> dp(401, vector<ll>(401, 1e15));

ll calc(int l, int r)
{
    if (dp[l][r] < 1e15)
        return dp[l][r];
    for (int k = l; k < r; k++)
    {
        dp[l][r] = min(dp[l][r], calc(l, k) + calc(k + 1, r) + (sum[r] - sum[l - 1]));
    }
    return dp[l][r];
}

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

    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        cin >> a[i];
        dp[i][i] = 0;
        sum[i] = sum[i - 1] + a[i];
    }
    cout << calc(1, N) << endl;
}


Measured memory_bytes: 1536
import itertools
import math
n, d = map(int, input().split())
l = list()
for i in range(n):
    l.append(list(map(int, input().split())))
a = list(itertools.combinations(l, 2))
count = 0
for i in range(len(a)):
    x = 0
    for j in range(d):
        x += (a[i][0][j]-a[i][1][j])**2
    if math.sqrt(x).is_integer():
        count += 1
print(count)

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

int main(){
  int N, ans=0;
  cin >> N;
  rep(i, N){
    string S;
    S = to_string(i+1);
    if (S.size()%2==1) ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;

#define clr(a) (a.clear())
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a))
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define pb push_back
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);

#define X first
#define Y second

using pii = pair <int, int>;
using pll = pair <ll, ll>;

const ll inf = 1;
const ll mod = 1E9;


#define SZ 100010



int main() {
#if defined JESI
//        freopen("1.txt", "r", stdin);
//        freopen("2.txt", "w", stdout);
#endif

    ios::sync_with_stdio(false);

    int n, c, k;
    cin >> n >> c >> k;

    vector <int> a(n);
    for (auto &x: a) cin >> x;
    sort(a.begin(), a.end());

    int last = -1, cap = 0, cnt = 0;
    for (auto &x: a) {
    	if (last < x || 0 == cap) {
    		cnt++;
    		last = x + k;
    		cap = c - 1;
    	} else {
    		cap--;
    	}
    }

    cout << cnt << endl;

    return 0;
}







Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

struct UnionFind {
	vector<int> data;
	void init(int n) { data.assign(n, -1); }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if(x != y) {
			if(data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
};

int main() {
	int N;
	while(~scanf("%d", &N)) {
		int K; int L;
		scanf("%d%d", &K, &L);
		UnionFind uf[2];
		rep(k, 2) uf[k].init(N);
		rep(k, 2) {
			rep(i, k == 0 ? K : L) {
				int u; int v;
				scanf("%d%d", &u, &v), -- u, -- v;
				uf[k].unionSet(u, v);
			}
		}
		vector<vi> ccs(N);
		rep(i, N) ccs[uf[0].root(i)].push_back(i);
		vector<int> count(N, 0);
		vector<int> ans(N, 0);
		rep(cc, N) if(!ccs[cc].empty()) {
			for(int i : ccs[cc])
				++ count[uf[1].root(i)];
			for(int i : ccs[cc])
				ans[i] = count[uf[1].root(i)];
			for(int i : ccs[cc])
				-- count[uf[1].root(i)];
		}
		for(int i = 0; i < (int)ans.size(); ++ i) {
			if(i != 0) putchar(' ');
			printf("%d", ans[i]);
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 13824
a,b,c = map(int, input().split())

if a > b:
  x = a
  a = b
  b = x
  
if b > c:
  x = b
  b = c
  c = x
  
if a > b:
  x = a
  a = b
  b = x
  
print(a,b,c)


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

#include <iostream>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  bool is_zero = false;
  bool is_over = false;
  __int128_t ans = 1;
  __int128_t max = pow(10, 18);
  for (int64_t i = 0; i < n; ++i) {
    int64_t temp;
    cin >> temp;
    if (temp == 0) {
      is_zero = true;
      break;
    }
    if (!is_over) {
      ans *= temp;
      if (ans > max) {
        is_over = true;
      }
    }
  }

  if (is_zero) {
    cout << 0 << endl;
  } else if (is_over) {
    cout << -1 << endl;
  } else {
    cout << static_cast<int64_t>(ans) << endl;
  }

  return 0;
}


Measured memory_bytes: 3572
#include<iostream>
using namespace std ;
int main()
{
	int a=0 , b=0 , i=0;
	cin >> a ;
	int box[a] ;
	for(i=0 ; i<a ; i++)
	{
		cin >> b ;
		box[i]=b ;
	}
	for(i=a-1 ; i>=0 ; i--)
	{
		if(i<a-1)
		{
			cout << " " ;
		}
		cout << box[i] ;
	}
	cout << endl ;
	return 0 ;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    int h,w;cin>>h>>w;
    vector<ll> a,b;
    for(int i=0;i<h;i++){
        int aa;cin>>aa;a.push_back(aa);
    }
    for(int i=0;i<w;i++){
        int bb;cin>>bb;b.push_back(bb);
    }
    sort(all(a));
    sort(all(b));
    ll ans=0;
    ll sum=0;
    int id=0;
    for(int i=0;i<h;i++){
        while(id<w&&b[id]<a[i]){
            sum+=b[id];
            id++;
        }
        ans+=sum+(w-id)*a[i];
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 5220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
ll dp[3000+5][3000+5][2];
ll arr[3000+5];

/* (i, j) -> max(A[i]+(i+1, j), A[j]+(i,j-1))
solve(i, j, c) -> c*max(arr[i] + solve(i+1, j, 1-c), arr[j] + solve(i, j-1, 1-c)) +
			(1-c)*min(-arr[i] + solve(i+1, j, 1-c), -arr[j] + solve(i, j-1, 1-c));
				
ll solve(ll i, ll j, ll c, ll X, ll Y){
	if (i > j) return X-Y;
	
	//if(dp[i][j][c] != -1) return dp[i][j][c];
	
	ll ans;
	if (c)
		ans = max(solve(i+1, j, 1-c, X+arr[i], Y), solve(i, j-1, 1-c, X+arr[j], Y));
	else
		ans = min(solve(i+1, j, 1-c, X, Y+arr[i]), solve(i, j-1, 1-c, X, Y+arr[j]));
	return ans;
}*/

ll solve(ll i, ll j, ll c){
	if (i > j) return 0;
	
	if(dp[i][j][c] != -1) return dp[i][j][c];

	dp[i][j][c] = c*max(arr[i]+solve(i+1, j, 1-c), arr[j]+solve(i, j-1, 1-c)) +
				 (1-c)*min(solve(i+1, j, 1-c)-arr[i], solve(i, j-1, 1-c)-arr[j]);
				 
	return dp[i][j][c];
}
			

int main(){
	cin>>N;
	for(ll i = 0;i<N;i++)cin>>arr[i];
	
	memset(dp, -1, sizeof dp);
	
	cout<<solve(0,N-1, 1)<<endl;
}	

Measured memory_bytes: 141568
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
        int n = sc.nextInt();
      	int l = sc.nextInt();
      	String words[] = new String[n];
      
      	for(int i = 0;i < n;i++) words[i] = sc.next();
        Arrays.sort(words);
        
          
        for(int i = 0;i < n;i++) System.out.print(words[i]);
        System.out.println();
      
	}
}

Measured memory_bytes: 37508
def main():
    n, m = map(int, input().split())
    a = set(map(int, input().split()))

    # type(x) == type(y) == string
    def bigger(x, y):
        if len(x) > len(y):
            return x
        elif len(x) < len(y):
            return y
        elif x < y:
            return y
        else:
            return x

    l = []
    if 1 in a:
        l.append((2, '1'))

    if 7 in a:
        l.append((3, '7'))

    if 4 in a:
        l.append((4, '4'))

    if 5 in a:
        l.append((5, '5'))
    elif 3 in a:
        l.append((5, '3'))
    elif 2 in a:
        l.append((5, '2'))

    if 9 in a:
        l.append((6, '9'))
    elif 6 in a:
        l.append((6, '6'))

    if 8 in a:
        l.append((7, '8'))

    dp = [None] * (n+1)
    dp[0] = ''
    for i in range(1, n+1):
        for cost, char in l:
            if i - cost < 0 or dp[i-cost] is None:
                continue
            candidate = max(dp[i-cost] + char, char + dp[i-cost])
            if dp[i] is None:
                dp[i] = candidate
            else:
                dp[i] = bigger(dp[i], candidate)

    print(dp[n])

main()

Measured memory_bytes: 98352
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S; cin >> S;
	if (S.substr(0,4)=="YAKI")cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,L;
    cin >> N >> L;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    int idx = -1;
    rep(i,0,N-1)if(V[i] + V[i+1] >= L)idx = i+1;
    if(idx == -1){
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    vector<int> ans;
    ans.push_back(idx);
    int left = idx-1, right = idx+1;
    while(left >= 1 || right < N){
        if(left >= 1)ans.push_back(left--);
        if(right < N)ans.push_back(right++);
    }

    rep(i,0,N-1)cout << ans[N-2-i] << endl;
}

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

const int INF = 1e9 + 10;

namespace std {
bool operator<(const complex<int> &c1, const complex<int> &c2) {
  if (c1.imag() == c2.imag()) {
    return c1.real() < c2.real();
  } else {
    return c1.imag() < c2.imag();
  }
}
} // namespace std

double cross_product(complex<int> a, complex<int> b) {
  return (conj(a) * b).imag();
}
bool is_in(complex<int> a, complex<int> b, complex<int> p) {
  return (cross_product(b - a, p - a) >= 0);
}

int n;

vector<complex<int>> make_frame(vector<complex<int>> P){
  vector<complex<int>> ans;
  for (int i = 0; i < n; i++) {
    while (ans.size() > 1 &&
           !is_in(ans[ans.size() - 2],
                  ans[ans.size() - 1], P[i])) {
      ans.pop_back();
    }
    ans.push_back(P[i]);
  }
  return ans;
}

int main() {
  cin >> n;
  vector<complex<int>> P(n);
  vector<complex<int>> ans_right;
  vector<complex<int>> ans_left;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    P[i] = complex<int>(x, y);
  }
  sort(P.begin(), P.end());
  ans_right = make_frame(P);
  reverse(P.begin(), P.end());
  ans_left = make_frame(P);

  cout << ans_right.size() + ans_left.size() -2 << endl;
  for (int i = 0; i < ans_right.size() - 1; i++)
    cout << ans_right[i].real() << ' ' << ans_right[i].imag() << endl;
  for (int i = 0; i < ans_left.size() - 1; i++)
    cout << ans_left[i].real() << ' ' << ans_left[i].imag() << endl;
}



Measured memory_bytes: 5224
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        int sum = Arrays.stream(a).sum();
        String result = h <= sum ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


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

typedef long long int lli;

long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
typedef pair<int,int> pii;
typedef vector<int> vec;
void solve(){
  lli n;
  cin>>n;
  vec adj[n];
  for(int i = 0;i<n;i++){
    int x;
    cin>>x;
    x--;
    adj[i].push_back(x);
  }

  vec dist(n);
  vector<bool> visit(n,0);
  queue<int> q;
  visit[0] = true;
  dist[0] = 0;
  q.push(0);
  while(!q.empty()){
    int s = q.front(); q.pop();

    for(auto c:adj[s]){
      if(visit[c]) continue;
      visit[c] = true;
      dist[c] = dist[s]+1;
      q.push(c);
    }
  }


  if(visit[1]==true){
    cout<<dist[1];
  }
  else{
    cout<<-1;
  }
}

int main(){
  solve(); 
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    cout<<max(0,c-a+b)<<endl;
    return 0;
}

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

string f(ll n) {
    if (n == 0) return "";
    n--;
    return f(n / 26) + string(1, 'a' + n % 26);
}

int main(){
    ll n;
    cin >> n;
    cout << f(n) << endl;
    return 0;
}


Measured memory_bytes: 3628
/*----------------
     Smit Patel
     DA-IICT
----------------*/
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ins insert
#define fori(i,a,n) for(ll i=a; i<n; i++)
#define ford(i,a,n) for(int i=a; i>n; i--)
#define clr(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define debug(x,y) cout<<#x<<" : "<<x<<"  "<<#y<<" : "<<y<<endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define bp __builtin_popcount
#define mod 1000000007
#define eps 1e-6
#define infi 1000000002
#define infll 1e18+5
#define N 200005
#define LN 23

typedef long double ld;
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef set<ll> sll;

ll choose(ll n,ll k);
bool isprime(ll n);
ll power(ll x,ll y,ll p);
ll power(ll x,ll y);
ll gcd(ll a,ll b);

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin>>s;
  ll n=s.length();
  ll cnt=0;
  ll dp[2020]={},tmp[2020]={};
  fori(i,0,n)
  {
    ll x=s[i]-'0';
    fori(j,0,2019)
    {
      ll y=(x+(10*j))%2019;
      tmp[y]+=dp[j];
    }
    fori(j,0,2019) dp[j]=tmp[j],tmp[j]=0;
    dp[x]++;
    // fori(j,0,200) cout<<dp[j]<<" ";
    // cout<<endl;
    cnt+=dp[0];
  }
  cout<<cnt<<"\n";
  return 0;
}

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

ll choose(ll n,ll k)
{
  if(k==0)
    return 1;
  return (n* choose(n-1,k-1))/k;
}

bool isprime(ll n)
{
  for(ll i=2;i*i<=n;i++)
  {
    if(n%i==0)
      return false;
  }
  return true;
}

ll power(ll x,ll y,ll p)
{
  ll res=1;
  x=x%p;
  while(y>0)
  {
    if(y&1)
      res=(res*x)%p;
    y=y>>1;
    x=(x*x)%p;
  }
  return res;
}

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y&1)
      res=res*x;
    y=y>>1;
    x=x*x;
  }
  return res;
}


Measured memory_bytes: 3764
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    const a = arg[1].split(" ").map(n=>parseInt(n));
    const list = [...Array(200000)].fill(0);
    
    for(let i in a) {
        list[a[i]]++;
    }
  
    list.sort((a,b)=>b-a);
    
    console.log(N - list.slice(0, K).reduce((m,n)=>m+n));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 50172
from collections import deque

N, M = map( int, input().split() )

G = [ [] for i in range( N ) ]
for i in range( M ):
  u, v = map( int, input().split() )
  G[ u - 1 ].append( v - 1 )
  G[ v - 1 ].append( u - 1 )

Q = int( input() )
V = []
D = []
C = []
for qi in range( Q ):
  v, d, c = map( int, input().split() )
  V.append( v - 1 )
  D.append( d )
  C.append( c )

vis = [ -1 for i in range( N ) ]
col = [ 0 for i in range( N ) ]
for qi in range( Q - 1, -1, -1 ):
  if D[ qi ] <= vis[ V[ qi ] ]: continue # 影響力不足
  que = deque()
  vis[ V[ qi ] ] = D[ qi ]
  que.append( ( D[ qi ], V[ qi ] ) )
  if col[ V[ qi ] ] == 0:
    col[ V[ qi ] ] = C[ qi ]
  while len( que ):
    d, u = que.popleft()
    if d == 0: continue
    for v in G[ u ]:
      if vis[ v ] >= d - 1: continue
      vis[ v ] = d - 1
      que.append( ( d - 1, v ) )
      if col[ v ] == 0:
        col[ v ] = C[ qi ]

for i in range( N ):
  print( col[ i ] )


Measured memory_bytes: 109600
#include<iostream>
#define _USE_MATH_DEFINES
#include <math.h>
#include<iomanip>
using namespace std;
int A, B, H, M;



int main()
{	
	cin >> A >> B >> H >> M;
	long double jisin, funsin;
	jisin = (60 *(long double) H +(long double) M) / 2;
	funsin = 6 * M;
	long double c = jisin - funsin;
	long double ans = (long double)(A * A + B *B) - (long double)(2*A * B) * cosl(M_PI*c/180);
	
	cout << setprecision(12)<<sqrtl(ans) << endl;
}


Measured memory_bytes: 4128
void main() {
    int[] tmp = readln.split.to!(int[]);
    int h = tmp[0], w = tmp[1];
    string[] s = new string[h];
    foreach (i; 0 .. h) {
        s[i] = readln.chomp;
    }
    foreach (i; 0 .. 2*h) {
        s[i/2].writeln;
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
import java.util.*;
public 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) {
            if (a != c) System.out.println("Yes");
            else System.out.println("No");
        } else if (a == c || b == c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define int long long int
int dp[100010][3],a[100010][3],n;
using namespace std;
int solve(int i,int s)
{
  if(i==-1)
    return 0;
  if(dp[i][s]!=-1)
    return dp[i][s];
  int m=0;
  for(int j=0;j<3;j++)
  { if(j==s)
      continue;
    m=max(m,a[i][j]+solve(i-1,j));}
  return dp[i][s]=m;
}
signed main()
{
  cin>>n;
  memset(dp,-1,sizeof(dp));
  for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
  cout<<solve(n-1,3)<<"\n";
  return 0;
}

Measured memory_bytes: 16108
#include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
int main()
{
    string s,t;

    cin>>s>>t;
    int i,c=0;
    for(i=0;i<3;i++)
    {
        if(s[i]==t[i])
        {
            c++;
            //cout<<"HI";
        }
//cout<<s[i]<<t[i]<<endl;
    }
   // cout<<s[0];
    cout<<c<<endl;
}


Measured memory_bytes: 256
// C - Prison
// https://atcoder.jp/contests/abc127/tasks/abc127_c
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, m, w, ans = 0, count = 0;
  string s, t;
  cin >> n >> m;
  vlli l(m), r(m);
  rep(i, 0, m)
  {
    cin >> l[i] >> r[i];
  }
  a = MAX(l);
  SORT(r);
  b = r[0];
  cout << max(b - a + 1LL, 0LL) << endl;
}

Measured memory_bytes: 1792
N, K = map(int, input().split())
MOD = 10 ** 9 + 7
A = list(map(int, input().split()))

# Kを無視して店頭数がいくつなのかを数える
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if A[i] > A[j]:
            cnt += 1
            cnt %= MOD

cnt2 = 0
A.extend(A)
for i in range(N*2):
    for j in range(i+1, N*2):
        if A[i] > A[j]:
            cnt2 += 1
            cnt2 %= MOD

cnt2 -= cnt * 2

ans = 0
ans += cnt * K % MOD
ans += cnt2 * (K * (K-1) // 2) % MOD
print(ans % MOD)


Measured memory_bytes: 41708