akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef pair<long long,long long> P;
//typedef pair<long long,P> P1;
//typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define se second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())


#define ALL(v)  (v).begin(),(v).end()
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))


const string MINUSINF = "-";


long long A,B,C,D,E,F,H,I,J,L,N,M,K,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long sum,sum1,sum2,sum3,sum4;
long long flg,flg1,flg2,flg3,cnt,cnt1,cnt2,cnt3,cnt4;
long long wk,wk1,wk2,wk3,wk4;
long long ans;

bool f;

long long n,h[100005];
vector<long long> p, c;
int vis[200001];

vector<string> fi;
int Left[2100][2100], Right[2100][2100], Up[2100][2100], Down[2100][2100];

long long match[10] = {2,5,5,4,5,6,3,7,6};

ll dp[10000010];


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

	long long max,max1;
	long long min,min1;

	sum=sum1=sum2=sum3=sum4=0;
	flg=flg1=flg2=flg3=cnt=cnt1=cnt2=cnt3=cnt4=0;
	max=max1=0;
	wk=wk1=wk2=wk3=wk4=0;
	ans=0;
	min=min1=INF;

	
	//**************************ここからスタート******************************************
	//std::cin >> N;
	//std::cin >> N >> M;
	//std::cin >> N >> M >> K;
	std::cin >> N >> K;
	//std::cin >> A >> B;
	//std::cin >> A >> B >> C;
    
	std::vector<long long> v(N);
	//std::vector<long long> w(N);
	//std::vector<long long> x(N);
	//std::vector<int> v(100, 0);
	//int a[26]={0};
	//vector<long long> flagment(N, 0);
	
	//vec.push_back(i);
	//accumulate(vec.begin(), vec.end(), 0)
    //v.resize
    
	// 配列入力1
	
	for(long long i=0; i<N; i++){
		std::cin >> v[i];
	}
	for(long long i=0; i<N; i++){
		dp[i]=INF;
	}
	
	
	//std::sort(v.begin(),v.end());//昇順ソート
	//std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
	
	//通常
	dp[0]=0;
	ll j;
	for(long long i=0; i<N; i++){
		j=i-K;
		while(j!=i){
			if(j<0){
				
			}
			else{
				
				dp[i]=MIN(dp[i],dp[j]+abs(v[j]-v[i]));
			}
			j++;
		}
	}
	printf("%lld",dp[N-1]);
	return 0;

}


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

int c[4][4];

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }

    bool b1 = (c[0][0] - c[1][0]) == (c[0][1] - c[1][1]) && (c[0][0] - c[1][0]) == (c[0][2] - c[1][2]);
    bool b2 = (c[1][0] - c[2][0]) == (c[1][1] - c[2][1]) && (c[1][0] - c[2][0]) == (c[1][2] - c[2][2]);
    bool b3 = (c[0][0] - c[2][0]) == (c[0][1] - c[2][1]) && (c[0][0] - c[2][0]) == (c[0][2] - c[2][2]);

    if (b1 && b2 && b3) {
        cout << "Yes\n";
    } else cout << "No\n";

    return 0;
}


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

int main(int argc, char const *argv[]) {
    ll N, L;
    std::cin >> N >> L;
    std::string a;
    std::vector<std::string> s;
    for (size_t i = 0; i < N; i++) {
        std::cin >> a;
        s.push_back(a);
    }

    std::sort(s.begin(), s.end());
    for (size_t i = 0; i < s.size(); i++) {
        std::cout << s[i];
    }
    std::cout << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int m = n;
    int s = 0;
    while(n > 0)
    {
        s = s + (n % 10);
        n = n/10;
    }
    
    if(m % s == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

string s;

int main(){
	cin >> s;
	ll ans = INF;
	rep(i,s.size()-2){
		ll num = 0;
		rep(j,3){
			num *= 10;
			num += s[i+j]-'0';
		}
		ans = min(ans,abs(num-753));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	long long int N, A, B;
	cin >> N >> A >> B;
  long long int ans=0;
  ans= A * (N / (A + B));
  if(N%(A+B)>A){
    ans=ans+A;
  }
  else{
    ans=ans+N%(A+B);
  }
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
//#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll n;cin>>n;
    ll a[n],b[n];
    rep(i,0,n-1){
        cin>>a[i]>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    ll aa,bb;
    if(n%2==0){
        aa=a[n/2-1]+a[n/2];
        bb=b[n/2-1]+b[n/2];
    }else{
        aa=a[(n-1)/2];
        bb=b[(n-1)/2];
    }
    cout<<bb-aa+1<<endl;
    return 0;
}





Measured memory_bytes: 6772
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <queue>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define forn(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(n==m)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
import collections


def search(sy, sx, gy, gx):
    visited = [[False for j in range(W)] for i in range(H)]
    visited[sy][sx] = True

    dq = collections.deque()
    dq.append((0, sy, sx))
    while dq:
        cost, y, x = dq.popleft()
        if (y, x) == (gy, gx):
            return cost
        for dy, dx in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            ny = y + dy
            nx = x + dx
            if ny < 0 or ny >= H or nx < 0 or nx >= W:
                continue
            if visited[ny][nx] or cells[ny][nx] == 'X':
                continue
            dq.append((cost + 1, ny, nx))
            visited[ny][nx] = True


def main(H, W, N, cells):
    points = {}
    for i in range(H):
        for j in range(W):
            points[cells[i][j]] = (i, j)
    points['0'] = points['S']
    total = 0
    for i in range(1, N + 1):
        sy, sx = points[str(i - 1)]
        gy, gx = points[str(i)]
        total += search(sy, sx, gy, gx)
    print(total)


if __name__ == '__main__':
    H, W, N = map(int, input().split())

    cells = []
    for i in range(H):
        cells.append(input())
    main(H, W, N, cells)

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int N, K, Q, ans=INF;
	int A[2005];

	cin >> N >> K >> Q;
	rep(i,N) cin >> A[i];

	rep(k,N){
		int thr = A[k];
		typedef priority_queue<int, vector<int>, greater<int>> PQ;
		PQ que;
		vector<int> v;
		rep(i,N){
			if( A[i] < thr ) PQ().swap(que);  // clear
			else que.push( A[i] );
			if( que.size() >= K ){
				v.push_back( que.top() );
				que.pop();
			}
		}
		if( v.size() >= Q ){
			sort(all(v));
			chmin(ans, v[Q-1] - v[0]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();	//人数
		long T = sc.nextLong();	//お湯出る時間
		long[] t = new long[N];
		for( int i=0; i<N; i++ ){
			t[i] = sc.nextLong();
		}
		long ans = 0;
		for( int i=1; i<N; i++ ){
			if( t[i]-t[i-1]<=T ){
				ans+=t[i]-t[i-1];
			}else{
				ans+=T;
			}
		}
		System.out.println(ans+T);
	}
}


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

struct Node {
    int key;
    struct Node *right, *left, *parent;
};

struct Node *root, *NIL;

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

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

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

}

void find(int key){
    struct Node *x = root;

    while(x != NIL){
        if(x->key > key){
            x = x->left;
        } else if(x->key < key) {
            x = x->right;
        } else{
            printf("yes\n");
            return;
        }
    }

    printf("no\n");
}

void inorder(struct Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(struct Node *u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

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

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

        }
    }

    return 0;
}


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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const ll INF = 1e9;
const ll INFF = 1e18;
const ll MAXN = 510;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

ll frek[100010];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    ll sum = 0;
    for (ll i = 1 ; i <= n ; i++)
    {
        ll ta;
        cin >> ta;
        frek[ta]++;
        sum += ta;
    }
    ll q;
    cin >> q;
    while (q--)
    {
        ll b,c;
        cin >> b >> c;
        ll hilang = frek[b] * b;
        ll muncul = frek[b] * c;
        ll delta = muncul - hilang;
        sum += delta;
        cout << sum << endl;
        frek[c] += frek[b];
        frek[b] = 0;
    }
    return 0;
}


Measured memory_bytes: 4388
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define LL long long
#define R register int
#define G if(++ip==ie)if(fread(ip=buf,1,SZ,stdin))
using namespace std;
const int SZ=1<<19,N=1e5+9;
char buf[SZ],*ie=buf+SZ,*ip=ie-1;
inline int in(){
	G;while(*ip<'-')G;
	R x=*ip&15;G;
	while(*ip>'-'){x*=10;x+=*ip&15;G;}
	return x;
}
int k,l[N],r[N];LL f[N];bool b[N];
struct Node{
	int r;mutable int v;
	inline Node(R a,R b=0):r(a),v(b){}
	inline bool operator<(const Node&a)const{return r<a.r;}
};
typedef set<Node>::iterator IT;
set<Node>s;
inline IT Split(R p){
	IT i=s.lower_bound(Node(p));
	return i->r!=p?s.insert(Node(p,i->v)).first:i;
}
inline void Set(R l,R r,R v){
	if(l>r)return;
	IT il=Split(l-1),ir=Split(r);
	ir->v=v;s.erase(++il,ir);
}
inline LL Calc(R p){
	R i=s.lower_bound(Node(p))->v;
	return i?f[i]+(p-r[i]+k)%k:0;
}
int main(){
	R n=in();LL k=::k=in(),a=0,a1=0,ans=1e18;
	s.insert(Node(-1));
	s.insert(Node(k-1));
	for(R i=1;i<=n;++i){
		a1=a;a+=in();
		if(!(b[i]=in()&1))continue;
		if(2*(a-a1)>k)return puts("-1"),0;
		l[i]=(-2*a1%k+k)%k;r[i]=(-2*a%k+k)%k;
		f[i]=Calc(r[i]);
		if(l[i]>r[i])Set(r[i]+1,l[i]-1,i);
		else Set(0,l[i]-1,i),Set(r[i]+1,k-1,i);
	}
	for(R i=1;i<=n;++i)
		if(b[i])ans=min(ans,min(Calc(l[i]),Calc(r[i])));
	cout<<ans+2*a<<endl;
	return 0;
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;


int main(){
    int m1,m2;
    int d1,d2;

    cin >> m1 >> d1 >> m2 >> d2;

    if(m1!= m2){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
   
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int N,D;
  	cin >> N >> D;
  	int count;
  	int s = 1;
  	while(s <= N){
    	s += 2*D;
      	s++;
      	count++;
    }
  	cout << count << endl;
}

Measured memory_bytes: 256
"use strict";
const main = input => {
    input = input.trim().split('\n');
    const nm = input.shift().split(' ').map(x => Number(x));
    const n = nm[0], m = nm[1];
    const p = input.pop().split(' ').map(x => Number(x));
    input = input.map(x => x.split(' ').slice(1).map(y => Number(y)));
    // console.log(n,p,input);
    const checkOn = (sw, state) => {
        sw = Math.pow(2, sw-1);
        return (sw & state) === sw
    };
    let count = 0;
    for(let i=0; i<Math.pow(2, n); i++) {
        let light = 0;
        for(let j=0; j<m; j++) {
            let swCount = 0;
            input[j].forEach(sw => {
                if (checkOn(sw,i)) swCount++;
            });
            if (swCount%2 === p[j]) light++;
        }
        if (light === m) count++;
    }
    console.log(count);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8264
// Aizu Vol-0 // Aizu Vol0 0070: Combination of Number Sequences
// 2017.8.11

#include <stdio.h>

int min[] = { 0, 0,  1,  4, 10,  20,  35,  56,  84, 120, 165 };
int max[] = { 0, 9, 26, 50, 80, 115, 154, 196, 240, 285, 330 };
int lim[] = { 0, 4, 13, 27, 45,  67,  94, 126, 162, 202, 247 };
int tbl[10][83] = { { 0 },
	/*  1 */ { 1, 1, 1, 1, 1 },
	/*  2 */ { 1, 2, 1, 3, 3, 3, 4, 5, 4, 5, 5, 4, 5 },
	/*  3 */ { 1, 3, 2, 6, 5, 6, 8, 13, 8, 16, 14, 14, 16, 23, 15, 26, 22, 21, 24, 30, 19, 31, 26, 22 },
	/*  4 */ { 1, 4, 4, 9, 11, 14, 16, 25, 20, 32, 29, 38, 38, 56, 45, 70, 61, 74, 69, 92, 71, 103, 88,
	105, 100, 136, 98, 131, 113, 131, 119, 150, 118, 150, 119, 160 },
	/*  5 */ { 1, 5, 7, 13, 22, 25, 32, 49, 52, 62, 76, 88, 91, 119, 114, 146, 160, 170, 172, 231, 223,
	249, 269, 298, 297, 372, 326, 375, 404, 407, 424, 484, 464, 481, 514, 553, 533, 581, 554, 589, 653,
	597, 601, 657, 630, 647, 660, 643 },
	/*  6 */ { 1, 6, 11, 19, 38, 44, 62, 88, 106, 124, 170, 188, 221, 271, 276, 323, 397, 395, 438, 533,
	544, 568, 687, 694, 769, 861, 893, 942, 1114, 1078, 1180, 1293, 1342, 1351, 1574, 1491, 1640, 1748,
	1775, 1764, 2029, 1920, 2026, 2162, 2178, 2191, 2430, 2292, 2383, 2552, 2488, 2488, 2709, 2583, 2598,
	2777, 2618, 2659, 2841, 2657 },
	/*  7 */ { 1, 7, 16, 28, 59, 75, 109, 151, 206, 234, 335, 360, 467, 529, 630, 675, 896, 878, 1053,
	1141, 1340, 1294, 1632, 1571, 1895, 1896, 2184, 2129, 2632, 2485, 2926, 2909, 3356, 3190, 3911,
	3583, 4259, 4158, 4663, 4477, 5370, 4886, 5622, 5475, 6171, 5776, 6772, 6186, 7073, 6776, 7435,
	6953, 8178, 7344, 8270, 7927, 8551, 8030, 9184, 8285, 9227, 8758, 9408, 8650, 9937, 8868, 9716,
	9281, 9870, 9035, 10092 },
	/*  8 */ { 1, 8, 22, 40, 83, 122, 173, 248, 350, 408, 575, 669, 842, 963, 1211, 1264, 1652, 1767,
	2083, 2248, 2752, 2671, 3274, 3352, 3928, 3978, 4624, 4554, 5428, 5384, 6115, 6158, 7195, 6897, 8052,
	7886, 8928, 8772, 10083, 9670, 11309, 10830, 12110, 11865, 13681, 12871, 14740, 14098, 15900, 15138,
	17241, 15947, 18464, 17353, 19307, 18345, 20745, 18949, 21681, 20236, 22624, 21027, 23607, 21467,
	24536, 22553, 24793, 23187, 26012, 23373, 26355, 24094, 26581, 24463, 27187, 24377, 27453, 24768, 27006 },
	/*  9 */ { 1, 9, 28, 51, 107, 177, 234, 360, 498, 619, 819, 1040, 1252, 1528, 1824, 2010, 2533, 2837,
	3180, 3676, 4305, 4493, 5130, 5672, 6156, 6909, 7424, 7830, 8773, 9392, 9892, 10678, 11647, 12141,
	13026, 13918, 14519, 15611, 16278, 16780, 18686, 19280, 19586, 20795, 22385, 22896, 23948, 24970,
	26012, 27096, 28467, 28427, 30540, 31272, 31774, 33264, 34748, 34499, 36299, 36596, 38456, 38926,
	39984, 39386, 42068, 42848, 42424, 42925, 45044, 44584, 46040, 45496, 46890, 47036, 47341, 47646,
	48887, 48840, 48044, 48540, 50066, 48970, 49062 } };

int main()
{
	int n, s, ans;

	while (scanf("%d%d", &n, &s) == 2) {
		if (n > 10 || s < min[n] || s > max[n]) ans = 0;
		else {
			if (s > lim[n]) s = max[n] + min[n] - s;
			s -= min[n];
			if (n == 10) n = 9;
			ans = tbl[n][s];
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 600
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bfs(nodes, src):
    """ BFS(一般グラフ、重みなし) """
    from collections import deque

    N = len(nodes)
    que = deque([(src, 0)])
    dist = [INF] * N
    while que:
        u, c = que.popleft()
        if dist[u] != INF:
            continue
        dist[u] = c
        for v in nodes[u]:
            que.append((v, c+1))
    return dist

N, x, y = MAP()
x -= 1; y -= 1

nodes = [[] for i in range(N)]
for i in range(N-1):
    nodes[i].append(i+1)
    nodes[i+1].append(i)
nodes[x].append(y)
nodes[y].append(x)

distx = bfs(nodes, x)
disty = bfs(nodes, y)

G = list2d(N, N, 0)
for i in range(N):
    for j in range(i+1, N):
        G[i][j] = min(j - i, distx[i] + disty[j] + 1, distx[j] + disty[i] + 1)
ans = [0] * N
for i in range(N):
    for j in range(i+1, N):
        ans[G[i][j]] += 1
[print(a) for a in ans[1:]]


Measured memory_bytes: 78940
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int[] p = new int[n];

        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        Arrays.sort(p);

        int result = 0;
        for (int i = 0; i < k; i++) {
            result += p[i];
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 38676
#include<stdio.h>

int rea(int x);

int main(void)
{
        int a,b,s;
        int i;

        scanf("%d%d",&a,&b);
        s=0;
        for(i=a;i<=b;i++){
                if((i%10==i/10000) && ((i/1000)%10 ==(i%100)/10))
                        s++;
        }

        printf("%d\n",s);
        return 0;
}


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

int main(){
  long long a, x, y;
  cin >> a;
  for(long long b=sqrt(a)+1; b>0; b--){
    if(a%b==0){
      x=a/b, y=b;
      break;
    }
  }
  cout << x+y-2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int num[104730] = {0}, Pnum[10000], n, ans;

	int k = 0;
	for (int i = 2; i < 104730; i++) {
		if (!(num[i])) {
			Pnum[k] = i;
			k++;
			for (int j = i + i; j < 104730; j+=i) {
				num[j] = 1;
			}
		}
	}
	
	while (cin >> n) {
		if (n == 0)	break;

		ans = 0;
		for (int i = 0; i < n; i++) {
			ans += Pnum[i];
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1612
#include<cstdio>
int main(){
	char s[51]={};
	char t[51]={};
	scanf("%s",s);
	scanf("%s",t);
	int ls;
	int lt;
	int k=0;
	for(int i=0;0==0;i++){
		if(s[i]==0){
			ls=i;
			break;
		}
	}
	for(int i=0;0==0;i++){
		if(t[i]==0){
			lt=i;
			break;
		}
	}
	for(int i=ls-lt;i>=0;i--){
		k=0;
		for(int j=i;j<i+lt;j++){
			if(s[j]!=t[j-i]&&s[j]!='?'){
				k=1;
				break;
			}
			if(j==i+lt-1){
				for(int p=i;p<i+lt;p++){
					s[p]=t[p-i];
				}
			}
		}
		if(k==0){
			for(int p=0;p<ls;p++){
				if(s[p]=='?')s[p]='a';
				printf("%c",s[p]);
				k=100;
			}
			break;
		}
	}
	if(k!=100)printf("UNRESTORABLE");
	printf("\n");
	return 0;
}
	

Measured memory_bytes: 128
#include <cstdio>
using namespace std;
int hash(int score) {
    if(score<=399) return 0;
    else if(score<=799) return 1;
    else if(score<=1199) return 2;
    else if(score<=1599) return 3;
    else if(score<=1999) return 4;
    else if(score<=2399) return 5;
    else if(score<=2799) return 6;
    else if(score<=3199) return 7;
    else return 8;
}
int main() {
    int N; scanf("%d", &N);
    int min = 0, max = 0; int color[9] = {0};
    for(int i = 0, a, p; i < N; i++) {
        scanf("%d", &a);
        p = hash(a);
        if(++color[p]==1&&p<8) {
            min++;
            max++;
        }
    }
    for(int i = 0, t = color[8]; i < t; i++) {
        if(min==0) min++;
        max++;
    }
    printf("%d %d", min, max);
}

Measured memory_bytes: 128
num = []

while a = gets

      num = a.split(nil)
      num = num.map{ |n| n.to_f}


      x = ((num[2]*num[4])-(num[5]*num[1]))/((num[0]*num[4])-(num[3]*num[1]))
      y = ((num[2]*num[3])-(num[5]*num[0]))/((num[1]*num[3])-(num[4]*num[0]))

      puts sprintf("%.3f %.3f",x+0.0, y+0.0) #　+0は(-0.0)と出力されるのを防ぐためです
end

Measured memory_bytes: 2320
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long i64;
const int inf = (int)1.05e9;

typedef vector<int> vertex;
typedef vector<vertex> graph;


int get_size(int v, graph& g, vector<bool>& visited, int n)
{
	if(visited[v])
		return 0;
	visited[v] = true;

	int s = (v < n);

	for(auto w : g[v]) {
		s += get_size(w, g, visited, n);
	}

	return s;
}


int main()
{
	int n, m;
	graph g;

	scanf("%d%d", &n, &m);
	g.resize(n + m);
	for(int i = 0; i < n; ++i) {
		int k;
		scanf("%d", &k);
		for(int j = 0; j < k; ++j) {
			int l;
			scanf("%d", &l);
			l -= 1;
			g[i].push_back(l + n);
			g[l + n].push_back(i);
		}
	}

	vector<bool> visited(n + m, false);

	int s = get_size(0, g, visited, n);

	printf("%s\n", (s == n) ? "YES" : "NO");

	return 0;
}


Measured memory_bytes: 8440
/**
 *  author: Behradm
 *  Created: 2020.07.05 16:33:38
 *  In The Name Of God
**/
#include <bits/stdc++.h>

using namespace std;

int main() {   
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a = 0, w = 0, t = 0, r = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "AC")
      a++;
    if (s == "WA")
      w++;
    if (s == "TLE")
      t++;
    if (s == "RE")
      r++;
  }

  cout << "AC x " << a << '\n';
  cout << "WA x " << w << '\n';
  cout << "TLE x " << t << '\n';
  cout << "RE x " << r << '\n';
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
 
int x[205], y[205], p[205];
 
int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d%d", &x[i], &y[i]);
    p[0] = 1;
    for (int i = 0; i < n; i++)
        p[i + 1] = (p[i] << 1) % MOD;
    int ans = p[n] - n - 1;// 要组成凸多边形 所有情况减去取一个点的情况减去都不取的情况
  //  cout<<p[n]<<endl;
    for (int i = 0; i < n; i++) {//固定两个点枚举其他点
        for (int j = 0; j < i; j++) {
            int cnt = 0;
            for (int k = 0; k < j; k++) {
                if ((x[i] - x[j]) * (y[i] - y[k]) == (x[i] - x[k]) * (y[i] - y[j]))//斜率相等 共线
                    cnt++;
            }
            ans =(ans-p[cnt]+MOD)%MOD;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
let N=stdin.ReadLine() |> int
let A=stdin.ReadLine().Split() |> Array.map int
let B=stdin.ReadLine().Split() |> Array.map int
let C=stdin.ReadLine().Split() |> Array.map int

let harmonized before now =
    if now = before + 1 then true
    else false

let eat (before, now) =
    if harmonized before now then
        B.[now-1]+C.[before-1]
    else
        B.[now-1]

let eat2 now = 
    B.[now-1]
 
(
    A 
    |> Array.pairwise
    |> Array.map eat  
    |> Array.sum 
)  
+ eat2 A.[0]
|> stdout.WriteLine

Measured memory_bytes: 11348
#include<iostream>
#include<string>
using namespace std;
int main() {
	string a;
	string b[10] = { "',.!?" ,"abc","def","ghi","jkl","mno",
		"pqrs","tuv","wxyz"," "};
	while (cin >> a) {
		for (int i = 0; i < a.length(); i++) {
			int j = i;
			while (a[i] == a[j]) {
				j++;
			}
			int c = j - i,f=c;
			int d = (int)a[i] - '0';
			if (d == 0) d = 9;
			else d--;
			char e;
			if (d == 9) {
				if (i != 0) {
					f--;
				}
				for (int z = 0; z < f; z++) {
					cout << " ";
				}
			}
			else {
				f--;
				f %= b[d].length();
				e = b[d][f];
				if (c > b[d].length()) e += ('A' - 'a');
				cout << e;
			}
			i = j-1;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3144
INF = 10 ** 15
MOD = 10 ** 9 + 7 

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A = list(enumerate(A))
    A.sort(key = lambda x:x[1])
    ans = 0
    for i,(j,v) in enumerate(A):
        ans += (j - i)%2
    print(ans//2)
if __name__ == '__main__':
    main()

Measured memory_bytes: 18060
long M=1e9+7,d[1<<17],i,j;s[222];main(n){for(;~scanf("%d",s-n);n--);for(qsort(s+1,~n,4,"\x8b\7+\6Ð");j++<*s;)d[j]=j;for(;j?:(j=*s,++i<~n);)d[j]=(d[j]*i+d[j--%s[i+1]])%M;printf("%d",d[j]);}

Measured memory_bytes: 896
h, w = map(int, input().split())
s = [input() for _ in range(h)]

ans_flg = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            flg = False
            for dr, dc in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
                r = i + dr
                c = j + dc
                if 0 <= r < h and 0 <= c < w:
                    if s[r][c] == '#':
                        flg = True
                        break
            if not flg:
                ans_flg = False
                break
        if not ans_flg:
            break
print('Yes' if ans_flg else 'No') 

Measured memory_bytes: 3064
i,t;p(n){for(i=t=2;i*i<=n;++i){n%i?:t++;}return t-2;}main(l,s,u){for(;scanf("%d",&l),u=l;){for(;p(l);l--);for(;p(u);u++);printf("%d\n",u-l);}return 0;}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <functional>
#include <cstring>
#include <queue>
#include <cmath>
#include <deque>
#include <list>
#include <iomanip>
#include <fstream>
#include <string>
#include <iterator>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, N) FOR(i, 0, N)
#define SZ(x) ((int)(x).size())

const int MAXN = 200007, INF = 1000000007;
const double pi = 3.141592653589793, l = 100.000000000000, r = 10.00000000000;

int main()
{
	int x1, y1, x2, y2, n, X[MAXN], Y[MAXN], k = 1, d[MAXN], len = 0;
	vector <pii> a;
	cin >> x1 >> y1 >> x2 >> y2 >> n;
	if (x1 > x2){
		swap(x1, x2);
		swap(y1, y2);
	}
	REP(i, n) cin >> X[i] >> Y[i];
	cout.precision(20);
	if (x1 == x2){
		if (y1 > y2) swap(y1, y2);
		REP(i, n){
			if (X[i] == x1 && Y[i] > y1 && Y[i] < y2){
				cout << (y2 - y1)*l + (pi - 2)*r;
				return 0;
			}
		}
		cout << (y2 - y1)*l;
		return 0;
	}
	if (y1 == y2){
		REP(i, n){
			if (Y[i] == y1 && X[i] > x1 && X[i] < x2){
				cout << (x2 - x1)*l + (pi - 2)*r;
				return 0;
			}
		}
		cout << (x2 - x1)*l;
		return 0;
	}
	if (y1 > y2) k = -1;
	REP(i, n){
		if (X[i] >= x1 && X[i] <= x2)
			if ((Y[i] >= y1 && Y[i] <= y2) || (Y[i] >= y2 && Y[i] <= y1))
				a.push_back(mp(X[i], k*Y[i]));
	}
	sort(a.begin(), a.end());
	n = SZ(a);
	d[0] = -INF;
	for (int i=1; i<=n; ++i)
		d[i] = INF;
	for (int i=0; i<n; i++) {
		int j = int (upper_bound (d, d + n, a[i].second) - d);
		if (d[j-1] < a[i].second && a[i].second < d[j])
			d[j] = a[i].second;
	}
	FOR(i, 1, n + 1)
		if (d[i] < INF) len = i;
	if (len < k*(y2 - y1) + 1 && len < x2 - x1 + 1)
		cout << ((x2 - x1) + k*(y2 - y1))*l + len*(pi/2 - 2)*r;
	else
		cout << ((x2 - x1) + k*(y2 - y1))*l + (len - 1)*(pi/2 - 2)*r + (pi - 2)*r;
	//cout << endl; system("pause");//please
	return 0;
}
/*
0 0 3 1
2
2 1
1 0
*/

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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll x, y;
	cin >> x >> y;
	ll cand = x;
	if (cand%y==0) cand*=__gcd(x,y);
	if (cand%y==0) cout << -1 <<endl;
	else cout << cand <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  int r,g,b,k;
  cin >> r >> g >> b;
  cin >> k;

  rep(i,k) {
    if(g <= r) {
      g *= 2;
      //cout << r << g << b << endl;
    }
    else if(b <= g) {
      b *= 2;
      //cout << r << g << b << endl;
    }
    
    if(b > g && g > r) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}



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

int main(void) {
  int t, n, i;
  int prices[4] = {6000, 4000, 3000, 2000};

  for (i = 0; i < 4; i++) {
    scanf("%d%d", &t, &n);
    printf("%d\n", prices[t - 1] * n);
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 600
n = int(input())
num = [0 for i in range(n + 1)]
for i in range(n):
    for j in range(n // (i + 1)):
        num[(i + 1) * (j + 1)] += 1
ans = 0
for i in range(n):
    ans += (i + 1) * num[i + 1]
print(ans)

Measured memory_bytes: 225028
N = int(input())
if 10000<=N<=99999:
  print(N-9999+909)
elif 1000<=N<=9999:
  print(909)
elif 100<=N<=999:
  print(N-99+9)
elif 10<=N<=99:
  print(9)
elif N==100000:
  print(90909)
else:
  print(N)
  




Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mod=1000000007;
int main(){
	ios;
	ll n,s,i;
	cin>>n;
	s=0;
	for(i=1;i<=n;i++)
	{
		if(i%3!=0 && i%5!=0) s+=i;
	}
	cout<<s;
	return 0;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> Keys(M);
	for (int i = 0; i < M; i++) {
		int b;
		cin >> Keys[i].first >> b;
		for (int j = 0; j < b; j++) {
			int c;
			cin >> c;
			Keys[i].second += (1 << (c - 1));
		}
	}
	vector<vector<int>> DP(M+1, vector<int>(1 << N, 1<<29));
	for (int i = 0; i < M + 1; i++) DP[i][0] = 0;
	for (int i = 1; i <= M; i++) {
		for (int j = 0; j < (1 << N); j++) {
			int next = j | Keys[i - 1].second;
			int before = DP[i - 1][next];
			int now = DP[i - 1][j] + Keys[i - 1].first;
			DP[i][next] = min({ before, now, DP[i][next] });
			DP[i][j] = min(DP[i][j], DP[i - 1][j]);
		}
	}
	cout << (DP[M][(1 << N) - 1] < (1 << 29) ? DP[M][(1 << N) - 1] : -1) << endl;
}

Measured memory_bytes: 19232
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

const int INF = 1e9;

vector<int> e[1000];
int x[1000];

int dfs(int u) {
    int i;
    bool dp[5001] {};
    dp[0] = true;
    int total = 0;
    for (auto v: e[u]) {
        int cost = dfs(v);
        total += cost + x[v];
        RREP (i,x[u],0) {
            bool tmp = dp[i];
            dp[i] = false;
            if (i + cost <= x[u]) dp[i + cost] |= tmp;
            if (i + x[v] <= x[u]) dp[i + x[v]] |= tmp;
        }
    }
    RREP (i,x[u],0) if (dp[i]) {
        return total - i;
    }
    puts("IMPOSSIBLE");
    exit(0);
}

int main(void) {
    int i, n;
    cin >> n;
    REP (i,1,n-1) {
        int p;
        cin >> p;
        p--;
        e[p].push_back(i);
    }
    REP (i,n) cin >> x[i];

    dfs(0);
    puts("POSSIBLE");
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main(){
    vector<int> a(3);
    for(int i=0; i<3; i++) cin>>a[i];
    sort(a.begin(),a.end());
    if(a[0]==a[1]&&a[1]!=a[2]){
        cout<<"Yes"<<endl;
    }else if(a[1]==a[2]&&a[0]!=a[1]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std; 
int main(){
    string s; cin >> s;
    int flag=0;
    if ( s [0]== s [1]&& s [1]== s [2]) flag = 1;
    else if ( s [1]== s [2]&& s [2]== s [3]) flag = 1;
    else flag = 0;
    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

long long cmn(long long a, long long b){
  long long maxval = fmax(a, b);
  long long minval = fmin(a, b);
  if (minval==0){
    return maxval;
  }
  long long amari = maxval%minval;
  return cmn(minval, amari);
}

int main(){
  long long A, B;
  scanf("%lld",&A);
  scanf("%lld",&B);
  long long cmnval = cmn(A, B);
  //printf("cmnval=%lld\n", cmnval);
  long long ans = (long long)A/cmnval;
  ans *= B;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cout << #x << " -> " << x << endl
#define booga cout << "booga" << endl
#define ll long long int
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int mod = 1e9 + 7;
int maxProductSubarrayOfSizeK(int A[], int n, int k){
    // sorting given input array 
    sort(A, A + n); 
  
    // variable to store final product of all element 
    // of sub-sequence of size k 
    ll product = 1; 
  
    // CASE I 
    // If max element is 0 and 
    // k is odd then max product will be 0 
    if (A[n - 1] == 0 && (k & 1)) 
        return 0; 
  
    // CASE II 
    // If all elements are negative and 
    // k is odd then max product will be 
    // product of rightmost-subarray of size k 
    if (A[n - 1] <= 0 && (k & 1)) { 
        for (int i = n - 1; i >= n - k; i--) {
            product *= (ll)A[i]; 
            product = product % mod;
		}
        return product; 
    } 
  
    // else 
    // i is current left pointer index 
    int i = 0; 
  
    // j is current right pointer index 
    int j = n - 1; 
  
    // CASE III 
    // if k is odd and rightmost element in 
    // sorted array is positive then it 
    // must come in subsequence 
    // Multiplying A[j] with product and 
    // correspondingly changing j 
    if (k & 1) { 
        product *= (ll)A[j];
        product = product % mod;
        j--; 
        k--; 
    } 
  
    // CASE IV 
    // Now k is even 
    // Now we deal with pairs 
    // Each time a pair is multiplied to product 
    // ie.. two elements are added to subsequence each time 
    // Effectively k becomes half 
    // Hence, k >>= 1 means k /= 2 
    k /= 2; 
  
    // Now finding k corresponding pairs 
    // to get maximum possible value of product 
    for (int itr = 0; itr < k; itr++) { 
  
        // product from left pointers 
        ll left_product = (ll)A[i] * (ll)A[i + 1]; 
  
        // product from right pointers 
        ll right_product = (ll)A[j] * (ll)A[j - 1]; 
  
        // Taking the max product from two choices 
        // Correspondingly changing the pointer's position 
        if (left_product > right_product) { 
            product *= A[i];
            product = product % mod;
            product *= A[i+1];
            product = product % mod;
            i += 2; 
        } 
        else { 
            product *= A[j];
            product = product % mod;
            product *= A[j-1];
            product = product % mod;
            j -= 2; 
        } 
    } 
  
    // Finally return product 
    return product % mod; 
}

void testcase(){
	int n,a[200005],k;
	cin >> n >> k;
	for(int i{0};i < n;i++){
		cin >> a[i];
	}
	int ans = maxProductSubarrayOfSizeK(a,n,k);
	if(ans < 0){
		ans += mod;
	}
	cout << ans << "\n";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 4392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
   int a, b;
   cin >> a >> b;
   if(b%a) cout << b-a << endl;
   else    cout << a+b << endl; 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using Uint = uint32_t;
constexpr int INF = 1e9;
constexpr LL INFLL = 1e18;
void solve() {
    string s;
    int k;
    cin >> s >> k;
    vector<int> len;
    int cur = 0;
    for (int i = 0; i < int(s.length()); ++i)
        if (i == 0 || s[i] == s[i - 1])
            ++cur;
        else {
            len.push_back(cur);
            cur = 1;
        }
    len.push_back(cur);
    LL ans = 0;
    if (len.size() == 1)
        ans = s.length() * k / 2;
    else {
        for (int i = 1; i + 1 < int(len.size()); ++i)
            ans += 1ll * len[i] / 2 * k;
        if (s[0] != s.back())
            ans += 1ll * len[0] / 2 * k + 1ll * len.back() / 2 * k;
        else
            ans += len[0] / 2 + len.back() / 2 + 1ll * (len[0] + len.back()) / 2 * (k - 1);
    }
    cout << ans << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL K;
std::vector<LL>ans;

LL f(LL n)
{
	LL res = 0;
	while (n > 0)
	{
		res += n % 10;
		n /= 10;
	}
	return res;
}

int main()
{
	in >> K;
	for (LL i = 0; i <= 20; ++i)
	{
		for (LL j = 1; j <= 1000; ++j)
		{
			if (i == 0 && j == 1) continue;
			LL tmp = j * pow(10LL, i);
			--tmp;
			ans.push_back(tmp);
		}
	}
	std::sort(ans.begin(), ans.end());
	ans.erase(std::unique(ans.begin(), ans.end()), ans.end());
	rep(i, ans.size())
	{
		for (int j = i + 1; j < ans.size(); ++j)
		{
			if ((long double)ans[i] / f(ans[i]) > (long double)ans[j] / f(ans[j]))
			{
				ans.erase(ans.begin() + i);
				--i;
				break;
			}
		}
	}
	rep(i, K) out << ans[i] << std::endl;
	return 0;
}


Measured memory_bytes: 640
package main;

import (
	"fmt"
)

func Max(x, y int64) int64 {
	if (x > y) {
		return x
	}
	return y
}

func main() {
	var A, B int64
	fmt.Scan(&A)
	fmt.Scan(&B)
	fmt.Println(Max(A + B, Max(A - B, A * B)))
}


Measured memory_bytes: 512
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[100], D[100];
	constexpr shuturyoku_unko() : C(), D() {
		for (int i = 10; i < 100; i++) {
			C[i] = '0' + i / 10;
			D[i] = '0' + i % 10;
		}
	}
} f;

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X < 10) {
		*di++ = '0' + X;
		*di++ = '\n';
		return;
	}
	*di++ = '0' + f.C[X];
	*di++ = '0' + f.D[X];
	*di++ = '\n';
}

char S[200010];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';
	fread(S, 1, 200000, stdin);
	

	int cnt = 0;
	rep(i, N) cnt += S[i] - '0';

	int mod1 = cnt + 1;
	int mod2 = cnt - 1;

	if (cnt == 0) {
		rep(i, N) putint(1);
		fwrite(dn, 1, di - dn, stdout);
		Would you please return 0;
	}
	if (cnt == 1) {
		rep(i, N - 1) putint('1' - S[i]);
		putint(('1' - S[N - 1]) * 2);
		fwrite(dn, 1, di - dn, stdout);
		Would you please return 0;
	}

	ll kazu1 = 0;
	ll kazu2 = 0;
	const ll ma = (1ll << 5) - 1;
	rep(i, N) {
		kazu1 = kazu1 * 2 + (S[i] - '0');
		kazu2 = kazu2 * 2 + (S[i] - '0');
		if (!(i & ma)) {
			kazu1 %= mod1;
			kazu2 %= mod2;
		}
	}
	int k1 = kazu1 % mod1;
	int k2 = kazu2 % mod2;

	int are1 = 1;
	int are2 = 1;
	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == '0') {
			int tmp = k1 + are1;
			if (tmp >= mod1) tmp -= mod1;
			int kotae = 1;
			while (tmp) {
				int k = __builtin_popcount(tmp);
				tmp = tmp % k;
				kotae++;
			}
			S[i] = kotae;
		}
		else {
			int tmp = k2 - are2 + mod2;
			if (tmp >= mod2) tmp -= mod2;
			int kotae = 1;
			while (tmp) {
				int k = __builtin_popcount(tmp);
				tmp = tmp % k;
				kotae++;
			}
			S[i] = kotae;
		}
		are1 *= 2;
		if (are1 >= mod1) are1 -= mod1;
		are2 *= 2;
		if (are2 >= mod2) are2 -= mod2;
	}

	rep(i, N) putint(S[i]);

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#define ll long long
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int main(){
    int n;
    scanf("%d",&n);
    a[0]=0;
    for (int i=1; i<=n; ++i) {
        scanf("%d",a+i);
    }
    ll dist=0;
    for (int i=1; i<=n; ++i) {
        dist+=abs(a[i]-a[i-1]);
    }
    dist+=abs(a[n]);
    for (int i=1; i<=n; ++i) {
        printf("%lld\n",dist-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]));
    }
//    printf("%d\n",3258*2+3095*2+4462);
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  vector<int> b(N);
  for(int i = N-1; i >= 0; i--) {
    int tmp = 0;
    for(int j = (i+1)*2; j <= N; j+=i+1)
      tmp ^= b[j-1];
    b[i] = a[i]^tmp;
  }
  int ans = 0;
  rep(i, N) {
    if(b[i] == 1)
      ans++;
  }
  cout << ans << endl;
  int flag = false;
  rep(i, N) {
    if(b[i] == 1) {
      if(flag)
        cout << " ";
      cout << i+1;
      flag = true;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	int n, x;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < 2 * n; i++) {
		cin >> x;
		v.pb(x);
	}
	sort(All(v));
	int sum = 0;
	for (int i = 0; i < 2 * n; i += 2) {
		sum += min(v[i], v[i + 1]);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 51;

string s[MAX_N];
int a[MAX_N][30];
int b[30];
int n;

int main()
{
	scanf("%d",&n);
	rep(i,n){
		cin >> s[i];
		rep(j,s[i].size()){
			a[i][(int)(s[i][j] - 'a')]++;
		}
	}
	rep(i,26){
		b[i] = INF;
	}
	rep(j,26){
		rep(i,n){
			b[j] = min(b[j],a[i][j]);
		}
	}
	rep(i,26){
		rep(j,b[i]){
			printf("%c",'a'+i);
		}
	}
	printf("\n");
	return 0;
}

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

  if(a>=b){
    a=b;
  }else{
  }if(c>=d){
    c=d;
  }else{
  }
   printf("%d\n",a+c);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
    #define ll long long
	using namespace std;
     
    int main()
    {
      ll int n,count =0;
      cin >> n;
      ll int ar[n];
      for(ll int i=0;i<n;i++)
      {
    	cin >> ar[i];
      }
      
      for(ll int i=0;i<n-1;i++)
      {
        if(ar[i]>ar[i+1])
        {
          count+=ar[i]-ar[i+1];
          ar[i+1]=ar[i];
      	}
      }
      cout << count;
      return 0;
    }

Measured memory_bytes: 5140
use std::io::stdin;
use std::str::FromStr;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn read_str_as_char_vec() -> Vec<char> {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().chars().collect()
}

fn main() {
    let s = read_str_as_char_vec();
    if s[1] == 'B' {
        println!("ARC");
    } else {
        println!("ABC");
    }
}


Measured memory_bytes: 2140