akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        long l = nextInt();
        long t = nextInt();
        long[] x = new long[n];
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = nextInt();
            w[i] = nextInt() == 1 ? 1 : -1;
        }
        long[] y = new long[n];
        long q = 0;
        for (int i = 0; i < n; i++) {
            int ww = w[i] - w[0];
            y[i] = x[i] + t * ww;
            if (y[i] >= l) {
                q -= y[i] / l;
                y[i] %= l;
            }
            if (y[i] < 0) {
                q += ((-y[i] - 1) / l) + 1;
                y[i] %= l;
                if (y[i] < 0) y[i] += l;
            }
        }
        q %= n;
        if (q < 0) q += n;
        Arrays.sort(y);

        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            int k = (int) ((i + q) % n);
            res[k] = y[i] + w[0] * t;
            res[k] %= l;
            if (res[k] < 0) res[k] += l;
        }
        for (int i = 0; i < n; i++) {
            out.println(res[i]);
        }
    }

    // ------------------

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

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

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 47904
def flatten(nested_list):
    return [e for inner_list in nested_list for e in inner_list]

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
l = flatten([[i+1] * a[i] for i in range(N)])
l2 = [l[i:i + W] for i in range(0, len(l), W)]
for i in range(H):
    if not i % 2:
        print(" ".join(map(str,l2[i])))
    else:
        print(" ".join(map(str, list(reversed(l2[i])))))

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

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

    int max_v = -1000000000, min_r = R[0];
    for (int i = 1; i < n; i++) {
        max_v = max(max_v, R[i] - min_r);
        min_r = min(min_r, R[i]);
    }
    cout << max_v << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 10**9

int main() {
    int n,sx,sy;
    string x,y;
    cin >> n;
    rep(i,n){
        cin >> x >> y;
        sx = x.size();
        sy = y.size();
        vector<vector<int>> c(sy+1,vector<int>(sx+1));
        rep(j,sy+1)rep(k,sx+1) c.at(j).at(k) = -1;
        rep(j,sy+1)rep(k,sx+1){
            if (j==0 or k==0){
                c.at(j).at(k) = 0;
            }
            else if (x.at(k-1) == y.at(j-1)){
                c.at(j).at(k) = c.at(j-1).at(k-1) + 1;
            }
            else {
                c.at(j).at(k) = max(c.at(j).at(k-1),c.at(j-1).at(k));
            }
        }
        cout << c.at(sy).at(sx) << endl;
    }
}


Measured memory_bytes: 6824
import sys
input = sys.stdin.buffer.readline

def main():
    A,B = map(int,input().split())
    
    x,y = B*10,(B+1)*10
    for i in range(x,y):
        if int(i*0.08) == A:
            print(i)
            exit()

    print(-1)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  char c;
  cin >> c ;

  if (c == 'a' || c == 'e' || c == 'i' || c== 'o' || c == 'u'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }

}

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

switch = []

for _ in range(M):
    k, *sss = list(map(int,input().split()))
    t = 0
    for s in sss:
        t += 1 << (s-1)
    switch.append(t)
    
p = list(map(int,input().split()))


cnt = 0
for i in range(1 << N):
    for sw, pp in zip(switch, p):
        t = i&sw
        c = bin(t).count("1")
        if c % 2 != pp:
            break
    else:
      cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main(){
    char s[100];
    int flag = 0;
    int i,j;
    
    scanf("%s",s);
    for(i = 0; i < strlen(s); i++){
        if(i%2 == 0) {
            if(s[i] == 'L'){
                flag = 1;
//                printf("%d is out\n",i);
                break;
            }
        }else{
            if(s[i] == 'R'){
                flag = 1;
//                printf("%d is out\n",i);
                break;
            }
        }
    }
    if(flag == 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}


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

#define rep(i,n) for(ll i=0;i<(n);i++)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<ll>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
const ll INF = (ll)1e9;

void d(){
    ll n,a,b;
    cin >> n >> a >> b;
    auto x = v<>(n+1,0);
    for(int i=0;i<n;i++) {
        cin >> x[i];
    }

    auto dp = v<>(n+1,0);
    dp[0]=0;
    rep(now,n-1){
        dp[now+1] = dp[now]+min(a*(x[now+1]-x[now]),b);
    }
    cout <<dp[n-1];

}

int main(){
    d();
    return 0;
}

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

int main()
{
  int N;
  cin >> N;

  vector<int> L(N);
  int max = 0;
  int sum = 0;

  for (int i = 0; i < N; i++)
  {
    cin >> L.at(i);

    sum += L.at(i);

    if (L.at(i) > max)
      max = L.at(i);
  }

  cout << (sum - max > max ? "Yes" : "No") << endl;
}


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

map<ll, int> prime_factor(ll n){
    map<ll, int> res;
    for(ll i = 2; i*i <= n; i++){
        while (n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n]++;
    return res;
}

int main(void)
{
    ll N;
    cin >> N;
    auto mp = prime_factor(N);

    ll ans = 0;
    for(auto&& mi : mp){
        // pr(mi.fi, mi.se);
        Rep(i, 1, 10000000){
            if(mi.se >= i){
                ans++;
                mi.se -= i;
            }else{
                break;
            }
        }
    }   
    pr(ans);
}

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

int main(){
	int n, d, x, inp;
	cin >> n >> d >> x;
	int a[n+5];

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

	int tot = 0;
	for( int i = 0; i < n; ++i ){
		///cout << i << " " << d/a[i]+1 << endl;
		if( d%a[i] )
			tot += d/a[i]+1;
		else
			tot += d/a[i];
	}

	cout << tot + x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

int main(void) {
	uint32_t a, b, c, d;

	scanf("%"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32, &a, &b, &c, &d);

	const uint32_t distanceAB = a > b ? a - b : b - a;
	const uint32_t distanceBC = b > c ? b - c : c - b;
	const uint32_t distanceAC = a > c ? a - c : c - a;

	printf("%s", (distanceAB <= d && distanceBC <= d) || (distanceAC <= d) ? "Yes" : "No");

	return 0;
}

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

int main() {
    int a, b, c;
    int x = 0;
    cin >> a >> b >> c;

    for(int i = a; i <= b; i++) {
        if(c % i == 0) {
            x++;
        }
    }

    cout << x << endl;

    return 0;
}


Measured memory_bytes: 3084
s = input()
t = input()
tins = False
for i in range(len(s)-len(t),-1,-1):
    et = True
    for j in range(len(t)):
        if s[i+j] != "?" and s[i+j] != t[j]:
            et = False
    if et:
        s = s[0:i]+t+s[i+len(t):len(s)]
        tins = True
        break
if tins:
    s = s.replace("?","a")
    print(s)
else:
    print("UNRESTORABLE")

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

#define ll long long

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

    ll res = 0;
    for(ll p = 1;p*p < N;p++) {
        ll m = N/p - 1;
        ll r = N%p;

        if(p < m && r == 0) {
            res += m;
        }
    }
    printf("%lld\n", res);
    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 P = pair<int,int>;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    vector<int> A(9);
    REP(i,9)cin >> A[i];
    int N;
    cin >> N;
    vector<int> b(N);
    REP(i,N)cin >> b[i];
    REP(i,N){
        REP(l,9)if(A[l] == b[i])A[l] = 0;
    }
    if(A[0] == 0 && A[1] == 0 && A[2] == 0){
        cout <<"Yes"<< "\n";
    }else if(A[3] == 0 && A[4] == 0 && A[5] == 0){
        cout <<"Yes"<< "\n";
    }else if(A[6] == 0 && A[7] == 0 && A[8] == 0){
        cout <<"Yes"<< "\n";
    }else if(A[0] == 0 && A[3] == 0 && A[6] == 0){
        cout <<"Yes"<< "\n";
    }else if(A[1] == 0 && A[4] == 0 && A[7] == 0){
        cout <<"Yes"<< "\n";
    }else if(A[2] == 0 && A[5] == 0 && A[8] == 0){
        cout <<"Yes"<< "\n";
    }else if(A[0] == 0 && A[4] == 0 && A[8] == 0){
        cout <<"Yes"<< "\n";
    }else if(A[2] == 0 && A[4] == 0 && A[6] == 0){
        cout <<"Yes"<< "\n";
    }else{
        cout <<"No"<< "\n";
    }
}

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

int main(){
	int N;
	cin >> N;
	vector<int> sor(N);
	int roop,roop2;
	for(roop=0;roop<N;roop++){
		cin >> sor[roop];
	}
	int v,j;
	for(roop=0;roop<N;roop++){
		v=sor[roop];
		j=roop-1;
		while(j>=0&&sor[j]>v){
			sor[j+1]=sor[j];
			j--;
		}
		sor[j+1]=v;
		for(roop2=0;roop2<N;roop2++){
			cout << sor[roop2];
			if(roop2<N-1){
				cout << " ";
			}else{
				cout << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>

int N,M,ans;
int gra[101][101];
int pgra[101][101];
int used[101][101];

int min(int x,int y){
	if(x<y)return x;
	return y;
}

void search(int start,int goal){
	int i;
	int cur;
	cur=start;
	/*while(cur!=goal){
		for(i=1;i<=N;i++)
			if((i!=cur) && (pgra[cur][i]+gra[i][goal]==gra[cur][goal])){
				if(used[cur][i]==0)ans--;
				used[cur][i]=1;
				used[i][cur]=1;
				cur=i;
				break;
			}
	}*/
	for(i=1;i<=N;i++)
		if((i!=cur) && (pgra[cur][i]+gra[i][goal]==gra[cur][goal])){
			if(used[cur][i]==0)ans--;
			used[cur][i]=1;
			used[i][cur]=1;
			search(i,goal);
		}
}

int main(){
	
	scanf("%d%d",&N,&M);
	ans=M;
	
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)if(i!=j)gra[i][j]=9999999;
	
	for(int i=0;i<M;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		gra[a][b]=gra[b][a]=c;
	}
	
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)pgra[i][j]=gra[i][j];
	
	
	for(int k=1;k<=N;k++)
		for(int i=1;i<=N;i++)
			for(int j=1;j<=N;j++){
				gra[i][j]=min(gra[i][j],gra[i][k]+gra[k][j]);
			}
	
	for(int i=1;i<N;i++)
		for(int j=i+1;j<=N;j++)search(i,j);
			
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	priority_queue<pair<int,int> > h;
	while(a--){
		int w;
		cin>>w;
		h.push(make_pair(w,1));
	}
	while(b--){
		int w;
		cin>>w;
		h.push(make_pair(w,2));
	}
	while(c--){
		int w;
		cin>>w;
		h.push(make_pair(w,3));
	}
	int z=x+y;
	int ans=0;
	while(z){
		pair<int,int> f=h.top();
		h.pop();
		if(f.second==3){
			ans+=f.first;
			--z;
		}
		else if(f.second==1 && x){
			ans+=f.first;
			--z;
			--x;
		}
		else if(f.second==2 && y){
			ans+=f.first;
			--y;
			--z;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10348
#include<stdio.h>

int main(){
  int n,i;
  int T[251*2+1];

  for(i = 1;i <= 250*2+1;i++) T[i] = -2000000001;

  scanf("%d",&n);

  for(i = 1;i <= n;i++) scanf("%d",&T[i]);

  for(i = 1;i <= n;i++){
    if(i == 1) printf("node 1: key = %d, left key = %d, right key = %d, \n",T[i],T[i*2],T[i*2+1]);
    else{
      printf("node %d: key = %d, parent key = %d, ",i,T[i],T[i/2]);
      
      if(T[i*2] == -2000000001){
	printf("\n");
	continue;
      }
      else printf("left key = %d, ",T[i*2]);

      if(T[i*2+1] == -2000000001){
	printf("\n");
	continue;
      }
      else printf("right key = %d, \n",T[i*2+1]);
    }
  }
  return 0;
}



Measured memory_bytes: 2052
# AtCoder Beginner Contest 175
# A - Rainy Season

S=input()

ans=0
count=0

if S[0]=="R":
    count=1

for i in range (1,len(S)):
    if S[i]=="R":
        if count>0:
            pass
        else:
            count=1
        if S[i-1]=="R":
            count+=1
        else:
            if count>ans:
                ans=count
                count=0
else:
    if count>ans:
        ans=count

print(ans)

Measured memory_bytes: 9088
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
o = input()
e = input()
ans = ""
for i in range(len(o)):
    ans += o[i]
    if i >= len(e):
        pass
    else:
        ans += e[i]
print(ans)


Measured memory_bytes: 10180
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

const int INF = 100000; 

int main(){
    int a, b, h;
    cin >> a >> b >> h;

    int ans = (a + b) * h / 2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
  char c;
  cin >> c;
  c++;
  cout << c << endl;
}

Measured memory_bytes: 256
def insertionSort():
    N = int(input())
    lst = list(map(int, input().split()))
    
    for i in range(1, N):
        print(*lst)
        v = lst[i]
        j = i - 1
        while j >= 0 and lst[j] > v:
            lst[j+1] = lst[j]
            j -= 1
        lst[j+1] = v
    
    print(*lst)
        
insertionSort()

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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vector<ll> S(N);
    for (int i = 0; i < N; i++) {
        S[i] = A[i];
        if (i > 0)
            S[i] += S[i - 1];
    }

    int ans = 1;
    for (int i = N - 2; i >= 0; i--) {
        if (A[i + 1] <= 2 * S[i]) {
            ans++;
        } else {
            break;
        }
    }
    cout << ans << endl;
}


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

int main() {
	int x1,x2,x3,x4,x5;
	cin>>x1>>x2>>x3>>x4>>x5;

	if (0==x1) {
		cout << "1" << endl;
	} else if (0==x2) {
		cout << "2" << endl;
	} else if (0==x3) {
		cout << "3" << endl;
	} else if (0==x4) {
		cout << "4" << endl;
	} else {
		cout << "5" << endl;
	}

	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			int result = 0;
			int count = 0;

			for (char c : s.toCharArray()) {
				if (c == 'R') {
					count++;
				} else {
					count = 0;
				}
				if (result < count) {
					result = count;
				}
			}
			System.out.println(result);
		}
	}
}


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


#define _LL long long

_LL* mallocint(int si)
{
    return (_LL*) malloc(si * sizeof(_LL));
}

_LL* inputint(_LL n)
{
    _LL *ans = mallocint(n);
    for( _LL i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

//　合計がx以上になる探し方がどれくらいあるか
_LL bsearchcount(_LL x, _LL n, _LL *a)
{
    _LL pindex = n - 1;
    _LL ans = 0;
//    cout << "x = " << x ;
    for( _LL i = 0; i < n; i++ )
    {
        while( pindex >= 0 && a[pindex] + a[i] < x ) 
        {
            pindex--;
        }
        ans += pindex + 1;
    }
//    cout << "  ans = " << ans << endl;
    return ans;
}

_LL bsearch(pair<int,int> window, _LL m, _LL n, _LL *a)
{
//    cout << "<" << window.first << "," << window.second << ">" << endl;
    if ( window.first  + 1 == window.second ) return window.first;
    _LL border = window.first + (window.second - window.first) / 2;
    _LL bcount = bsearchcount(border, n, a);
    if( bcount >= m )
    {
        if( border + 1 == window.second )
        {
            return border;
        }
        return bsearch( make_pair(border, window.second), m, n, a );
    }
    else
    {
        if( window.first + 1 == border ) return window.first;
        return bsearch( make_pair(window.first, border), m, n, a );
    }
}

_LL getans(_LL x, _LL n, _LL *a, _LL m)
{
    long long pindex = n - 1;
    long long ans = 0;
    long long psum = 0;
    long long pcount = 0;
    _LL minsum = a[0] + a[0];
    for( _LL i = 0; i < n; i++ ) psum += a[i];

    for( _LL i = 0; i < n; i++ )
    {
        while( pindex >= 0 && a[pindex] + a[i] < x ) 
        {
            psum -= a[pindex];
            pindex--;
        }
//        cout << " pindex = " << pindex << ", psum = " << psum << endl; 
        ans += psum + a[i] * (pindex + 1);
        if( pindex >= 0 && a[i] + a[pindex] < minsum ) minsum = a[i] + a[pindex];
        pcount += pindex + 1;
    }
    ans -= (pcount - m) * minsum;
    return ans;
 
}

int main()
{
    _LL n, m;
    cin >> n >> m;
    _LL *a = inputint(n);

    sort(a + 0, a + n, greater<>());

    _LL borderx = bsearch(make_pair(a[n-1] + a[n-1], a[0] + a[0] + 1), m, n, a);
//    cout << borderx << endl;
    cout << getans(borderx, n, a, m);
    return 0;
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n;
  cin >> n;
  
  double x[n],y[n];
  double distAbs[n];
  for(int i=0;i<n;i++){
      cin >> x[i];
  }
  for(int i=0;i<n;i++){
      cin >> y[i];
  }
  
  double max = 0.0;
  for(int i=0;i<n;i++){
      distAbs[i] = abs(x[i]-y[i]);
      if(max<distAbs[i]) max = distAbs[i];
  }
  
  for(int i=0;i<3;i++){
      double value = 0.0;
      for(int j=0;j<n;j++){
          double s = distAbs[j];
          for(int k=0;k<i;k++){
              s *= distAbs[j];
          }
          value += s;
      }
      value = pow(value, 1.0/(1.0+(double)i));
      cout << fixed << setprecision(6) << value << endl;
  }
  cout << fixed << setprecision(6) <<  max << endl;
  
 
  return 0;
}


Measured memory_bytes: 3424
#include <iostream>
#include <algorithm>
#include <cstring>
#include<cstdio>
#include <cmath>
using namespace std;


int main()
{
	int k, n, cnt = 1, box, var = 0;
	int *a, *b;
	cin >> n >> k;

	a = new int[n];
	b = new int[n];

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

	if (n <= k){
		cout << 0 << endl;
		return 0;
	}
	sort(a, a+n);
	
	
	for (int i = 1; i < n; i++){
		if (a[i] == a[i-1])
			cnt++;
		else{
			b[var] = cnt;
			cnt = 1;
			var++;
		}
		
	}
	if (cnt != 1){
		b[var] = cnt;
	}
	else
		b[var] = cnt;
	var++;

	if (var <= k){
		cout << 0 << endl;
		return 0;
	}
		sort(b, b + var);
		box = var - k;

		cnt = 0;
		for (int i = 0; i < n&&box; i++){
			if (b[i] != 0){
				cnt += b[i];
				box--;
			}
		}

		cout << cnt << endl;

	delete[] a;
	delete[] b;
	return 0;
}

Measured memory_bytes: 1792
// ABC158A - Station and Bus

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

int main() {
	string S;
	cin >> S;

	if (S[0] == 'A' && S[1] == 'A' && S[2] == 'A') {
		cout << "No" << endl;
		return 0;
	}
	if (S[0] == 'B' && S[1] == 'B' && S[2] == 'B') {
		cout << "No"<< endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}


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

cnt1 = 0
cnt2 = 0
acs = 0

for i in range(n):
    acs += lst[i]
    if acs == 0:
        if i%2==0:
            acs = 1
        else:
            acs = -1
        cnt1 += 1
    
    if i%2 == 0 and acs < 0: #偶数番目が正の場合
        cnt1 += 1 - acs
        acs = 1
        
    elif i%2 != 0 and acs > 0:
        cnt1 += abs(-1 - acs)
        acs = -1

acs = 0

for i in range(n):
    acs += lst[i]
    if acs == 0:
        if i%2==0:
            acs = -1
        else:
            acs = 1
        cnt2 += 1
    if i%2 != 0 and acs < 0: #奇数番目が正の場合
        cnt2 += 1 - acs
        acs = 1
        
    elif i%2 == 0 and acs > 0:
        cnt2 += abs(-1 - acs)
        acs = -1
        
print(min(cnt1,cnt2))

Measured memory_bytes: 14332
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll n, k;
    cin >> n >> k;
    vector<pair<ll, ll>> ab(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(ab.begin(), ab.end());
    ll cnt = 0;
    rep(i, n) {
        cnt += ab[i].second;
        if (cnt >= k) {
            cout << ab[i].first << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 4816
/*****Enigma_27*****/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pll         pair<ll,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,i,j,k,l,t=1,ans=0,flag=0,x,y;
int main()
{   ios
	cin>>x>>y;
	int a[]={1,3,5,7,8,10,12};
	int b[]={4,6,9,11};
	if(bs(a,a+7,x)&&bs(a,a+7,y)) cout<<"Yes";
	else if(bs(b,b+4,x)&&bs(b,b+4,y)) cout<<"Yes";
	else if(x==y) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll ans = 0;
    if( 2*c <= a + b ){
        int temp = min(x, y);
        x -= temp;
        y -= temp;
        
        ans += 2*c*temp;

        if(x == 0){
            if( 2*c <= b ){
                ans += 2*c*y;
            }
            else{
                ans += b*y;
            }
        }
        else if(y == 0){
            if( 2*c <= a ){
                ans += 2*c*x;
            }
            else{
                ans += a*x;
            }
        }
    }
    else{
        ans += x*a + y*b;
    }

    cout << ans;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int A,B;

int Ceil(int a,int b){return ((a%b==0)?a/b:a/b+1);}

int ans=0;
int C[100010],D[100010],E[100010];

signed main(){
	cin>>A>>B;
	if(A%2==0){
		ans=((B-A+1)/2)%2;
		if((B-A+1)%2==1)ans^=B;
	}
	else{
		ans=((B-A)/2)%2;
		ans^=A;
		if((B-A)%2==1)ans^=B;
	}
	cout<<ans<<endl;
	return 0;
}


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

#define x first
#define y second
using namespace std;
const int mx = 112345;
typedef pair<int, int> ii;

int a[mx], b[mx], ap[mx];

ii v[mx];
int main () {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ap[i] = a[i];
  }
  int N = 0;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if(a[i] > b[i]) v[N++] = {a[i]-b[i], i};
  }
  bool ok = 1;
  sort(v, v+N, greater<ii>());
  int k = 0;
  for (int i = 0; i < n; i++) {
    while (a[i] < b[i] && k < N) {
      auto &x = v[k];
      int d = min(x.x, b[i]-a[i]);
      x.x -= d;
      a[i] += d;
      a[x.y] -= d;
      if(!x.x) k++;
    }
    ok &= a[i] >= b[i];
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i] != ap[i];
  }
  cout << ans << endl;
}










Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    int k;
    string s;
    cin >> k >> s;
    if(s.length() <= k){
        cout << s << endl;
    }else{
        for(int i=0;i<k;i++){
            cout << s.at(i);
        }
        cout << "..." << endl;
    }
    return 0;
}

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

ll solve() {
    string S;
    cin >> S;
    int n = S.size();
    vector<vector<int>> dp(2,vector<int>(n));
    dp[0][0] = 1;
    for ( int i = 1; i < n; i++ ) {
        if ( S[i] != S[i-1] ) {
            dp[0][i] = max(dp[0][i-1] + 1, dp[1][i-1] + 1);
            if ( i >= 2 ) dp[1][i] = dp[0][i-2] + 1;
        } else {
            dp[0][i] = dp[1][i-1] + 1;
            if ( i >= 2 ) dp[1][i] = dp[0][i-2] + 1;
        }
    }

    ll ans = max(dp[0][n-1], dp[1][n-1]);
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef pair<int, bool> ib;

#define FOR(a, b, c) for(int a = b; a < c; ++a)
#define RFOR(a, b, c) for(int a = b; a >= c; --a)
#define mp(a, b) make_pair(a, b)
#define all(v) v.begin(), v.end()

#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define vb vector<bool>
#define fst first
#define snd second
#define MAXN 100010
#define LOGMAXN 20
#define MAXM 44100
#define LOGMAXN 20
#define INF 1000000007
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007LL

int n;
ll v[MAXN];
int freq[MAXN];

ll getMax()
{
	int idx = 0;
	RFOR(i, 63, 0)
	{
		if(freq[i]&1) continue;
		ll mx = -1;
		int id = idx;
		FOR(j, idx, n)
		{
			if((v[j] & (1LL << i)) > 0 && mx < v[j])
			{
				mx = v[j];
				id = j;
			}
		}
		if(mx == -1) continue;
		swap(v[idx], v[id]);
		FOR(j, 0, n)
		{
			if(idx != j && (v[j] & (1LL << i)) > 0)
				v[j] ^= v[idx];
		}
		idx++;
	}
	ll ans = 0LL;
	FOR(i, 0, n)
	{
		ans ^= v[i];
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	while(cin >> n)
	{
		ll xr = 0LL;
		FOR(i, 0, n)
		{
			cin >> v[i];
			xr ^= v[i];
		}
		RFOR(i, 63, 0)
		{
			freq[i] = 0;
			FOR(j, 0, n)
			{
				if((v[j] & (1LL << i)) > 0)
					freq[i]++;
			}
		}
		ll mx = getMax();
		printf("%lld\n", mx + (xr^mx));
	}
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

int main(){
  int x;
  gets(x)
  if (x >= 1200) {
    puts("ARC")
  }else{
    puts("ABC")
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct edge
{
  int from;
  int to;
  int cap;
};

int solve(int N, int M, int R, vector< int > visits, vector< edge > edges)
{
  long long INF = 0x3f3f3f3f;
  long long A[N][N];
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      if (i == j)
        A[i][j] = 0;
      else
        A[i][j] = INF;

  for (auto it = edges.begin(); it != edges.end(); it++)
  {
    edge e = *it;
    A[e.from - 1][e.to - 1] = e.cap;
    A[e.to - 1][e.from - 1] = e.cap;
  }

  for (int k = 0; k < N; k++)
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++)
        A[i][j] = min(A[i][j], A[i][k] + A[k][j]);

  long long min_d = INF;
  sort(visits.begin(), visits.end());
  do
  {
    long long d = 0;
    for (int r = 0; r < R - 1; r++)
      d += A[visits[r] - 1][visits[r + 1] - 1];

    min_d = min(min_d, d);

  } while (next_permutation(visits.begin(), visits.end()));

  return min_d;
}

int main(int argc, char **argv)
{
  int N, M, R;
  cin >> N >> M >> R;

  vector< int > visits(R);
  for (int i = 0; i < R; i++)
  {
    cin >> visits[i];
  }

  vector< edge > edges(M);
  for (int i = 0; i < M; i++)
  {
    int from, to, cap;
    cin >> from >> to >> cap;
    edges.push_back((edge){from, to, cap});
  }

  int ans = solve(N, M, R, visits, edges);

  cout << ans << endl;

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector <int> a(N);
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    int cnt=0;
    for(int i=0; i<N; i++){
        if(a[i]-1>i){
            int j=a[i]-1;
            if(a[j]-1==i) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
  using item= pair<int, int>;
  constexpr int Wmax = 100'000;
  constexpr int Dmax = 18;
  constexpr int Dhalf= 10;

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

  int N;
  cin >> N;

  vector<item> data(N+1);
  for(int v=1; v<=N; v++){
    cin >> data.at(v).first >> data.at(v).second;
  }

  // auto trimming= [](vector<int> *output){
  //   int val_cummax= -1;
  //   for(size_t w=0; w< output->size(); w++){
  //     val_cummax= max(val_cummax, output->at(w));
  //     output->at(w)= val_cummax;
  //   }
  // };

  const int Vupper= min(N+1, 1<< Dhalf);
  vector<vector<int>> above_half(Vupper, vector<int>(Wmax+ 1));
  for(int v=1; v<Vupper; v++){
    above_half.at(v)= above_half.at(v/2);
    auto [val_v, wgh_v]= data.at(v);
    for(int w=Wmax; w >= wgh_v; w--){
      above_half.at(v).at(w)= max(above_half.at(v/2).at(w), val_v+ above_half.at(v/2).at(w- wgh_v));
    }
    // trimming(&above_half.at(v));
  }

  int Q;
  cin >> Q;

  vector<int> answers(Q);

  int v_query; int W_query;
  for(int q=0; q<Q; q++){
    cin >> v_query >> W_query;

    if(v_query < Vupper){
      answers.at(q)= above_half.at(v_query).at(W_query);
    }
    else{
      int D_query= (32- __builtin_clz(v_query))- Dhalf;
      int v_anc= v_query >> D_query; 
 
      int ans= 0;
      for(int tmp=0; tmp<(1<< D_query); tmp++){
        bitset<Dhalf> bs(tmp);
 
        int wgh_lower= 0;
        int val_lower= 0;
        for(int i=0; i<D_query; i++){
          if(bs.test(i)){
            wgh_lower+= data.at((v_query>> i)).second;
            val_lower+= data.at((v_query>> i)).first;
          }
        }
 
        if(wgh_lower <= W_query){
          int val_upper= above_half.at(v_anc).at(W_query- wgh_lower);
 
          ans= max(ans, val_upper+ val_lower);
        }
      }
      answers.at(q)= ans;
    }
  }

  for(auto ans:answers){
    cout << ans << endl;
  }
}

Measured memory_bytes: 407120
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c) 
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

const int max_n=100000;
int n;
ll a[max_n+1];

void solve(){
    ll ans=0,ans2=0,hu=0;
    bool flag=false;
    rep(i,n){
        if(a[i]==0) flag=true;
        else if(a[i]<0) hu++;
    }
    if(flag || hu%2==0){
        rep(i,n) ans+=abs(a[i]);
        cout << ans;
    }else{
        rep(i,n) ans2+=abs(a[i]);
        priority_queue<ll,vector<ll>,greater<ll>> p;
        priority_queue<ll,vector<ll>,greater<ll>> m;
        rep(i,n){
            if(a[i]>0) p.push(a[i]);
            else m.push(abs(a[i]));
        }
        if(p.empty()) ans2-=2*m.top();
        else ans2-=2*min(p.top(),m.top());
        cout << ans2;
    }
}

int main(){
    cin >> n;
    rep(i,n) cin >> a[i];
    solve();
}

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

#ifndef bhartiya
    // #pragma GCC optimize("Ofast")
    // #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;

#define pb push_back
#define bitc  __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second

#define swap(a,b) {a=a^b;b=a^b;a=a^b;}
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)

#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cout << "\n\nTime elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
}
#else
#define endl '\n'
#define trace(...)
#define start_routine()
#define end_routine()
#endif

#define inf 200000000000000ll
#define mod 1000000007ll
#define eps 1e-7

ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }
const ll maxn = 51, maxj = 60;
ll n,k;
ll dp[maxn][maxn][maxj+2];
map<pll, ll> rec;

ll recur(ll s, ll k){
    ll ans = 0;
    if(k==0) return 1;
    if(rec.find(mp(s,k)) != rec.end()) return rec[mp(s,k)];
    frr(i,maxj,0){
        if(k >= (1ll << i)){
            ll pos = k-(1ll<<i);
            rep(j,n){
                if(dp[s][j][i])
                    ans = (ans+ (dp[s][j][i] * recur(j,pos))%mod)%mod;
            }
            rec[mp(s,k)] = ans;
            return ans;
        }
    }
}

int main()
{ 
    start_routine();
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.precision(10);
    cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        cin>>n>>k;
        rep(i,n){
            rep(j,n){
                cin>>dp[i][j][0];
            }
        }
        fr(j,1,maxj-1){
            rep(i,n){
                rep(k,n){
                    rep(l,n){
                        dp[i][l][j] =(dp[i][l][j] + (dp[i][k][j-1]*dp[k][l][j-1])%mod)%mod;
                    }
                }
            }
        }
        ll ans = 0;
        rep(i,n){
            ans = (ans + recur(i,k))%mod;
        }
        cout<<ans;
    }
    end_routine();
}


Measured memory_bytes: 1664
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
costs = [0] + [abs(A[i] - A[i+1]) for i in range(N+1)]
sum_costs = sum(costs)

for i in range(1, N+1):
    print(sum_costs - costs[i] - costs[i+1] + abs(A[i-1] - A[i+1]))


Measured memory_bytes: 13920
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<iomanip>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
vector < vector<int>> chi;
vector<int>nPar;//各頂点iについての親の数nPar[i]
vector<int>dist;//探索でiに達する度にnPar[i]をデクリメントする
vector<int>ans;//nPar[i]=0になったときに以降の探索を行う
void dfs(int n) {
	if (chi[n].size() == 0)return;
	//葉に達したら探索を終える
	int nChi = chi[n].size();
	//頂点nの子の根からの距離を求める
	for (int i = 0; i < nChi; ++i) {
		int nxt = chi[n][i];
		nPar[nxt]--;
		if (dist[nxt] < dist[n] + 1) {
			//距離が更新される時に親を更新する
			dist[nxt] = dist[n] + 1;
			ans[nxt] = n;
		}
		//頂点nxtへのnPar[nxt]回目の参照の時以降の探索を行う
		if (nPar[nxt] == 0)dfs(nxt);
	}
}
int main() {
	int N, M;
	cin >> N >> M;
	chi = vector<vector<int>>(N + 1);//chi[i][j]は頂点iのj番目の子
	//各頂点の親の数を数えておく
	nPar = vector<int>(N + 1, 0);
	for (int i = 0; i < N + M - 1; ++i) {
		int A, B; cin >> A >> B;
		chi[A].push_back(B);
		nPar[B]++;
	}
	//根を求める
	vector<bool>rootCand(N + 1, true);
	for (int i = 1; i <= N; ++i) {
		int nChi = chi[i].size();
		for (int j = 0; j < nChi; ++j) {
			rootCand[chi[i][j]] = false;
		}
	}
	int root;
	for (int i = 1; i <= N; ++i) {
		if (rootCand[i])root = i;
	}
	//dist[i]は根から頂点iへの距離
	dist = vector<int>(N + 1, 0);
	//ans[i]は頂点iの親
	ans = vector<int>(N + 1, 0);
	dfs(root);
	for (int i = 1; i <= N; ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 12160
n = int(input())
p = list(map(int, input().split()))
count = 0

for i in range(1, n-1):
    l = [p[i-1], p[i], p[i+1]]
    if p[i] < max(l) and p[i] > min(l):
        count += 1
    else:
        continue

print(count)


Measured memory_bytes: 38384
function Main(input) {
    var input = input.split(' ');
    var A = input[0];
    var B = input[1];
    var cnt = 0;
    function hoge(){
        var x = A.toString();
        if(x[0] === x[4] && x[1] === x[3]){
            return true;
        }
    }
    while(A <= B) {
     if(hoge()) {
            cnt++;
        }
    A++;
    }
    console.log(cnt);
    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 24508
n, p = map(int,input().split())

div = []
for i in range(2,int(p**0.5)+2):
  count = 0
  if p%i==0:
    while p%i==0:
      p//=i
      count += 1
    div.append((i, count))
if p != 1:
  div.append((p, 1))

ans = 1
for d,c in div:
  ans *= d**(c//n)
print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int MOD = 1000000007;

long long modpow(long long a,long long n,long long MOD){
    int ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return ret;
}

int main() {
    ll N;cin >> N;
    ll A[N] = {};
    for (int i = 0;i < N;i++) cin >> A[i];
    int B[61][2] = {};
    for (int i = 0;i < 61;i++){
        for (int j = 0;j < N;j++){
            if (A[j] & (1ll << i)) B[i][1]++;
            else B[i][0]++;
        }
    }
    ll res = 0;
    for (int i = 0;i < 61;i++){
        if (B[i][0] == 0 || B[i][1] == 0) continue;
        res += modpow(2,i,MOD) * B[i][0] % MOD * B[i][1] % MOD;
        res %= MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 2560
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL T, X;
	cin >> T >> X;

	double ans = T / (double)X;

	cout << ans << endl;

	return 0;
}

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

char s[100001];

int main() {
	int k;
	scanf("%s%d", s, &k);
	int n = strlen(s);
	f(i, 0, n)if (s[i] != 'a') {
		int d = 'z' + 1 - s[i];
		if (d <= k) {
			k -= d;
			s[i] = 'a';
		}
	}
	if (k) {
		k = k % 26;
		s[n - 1] += k;
		if (s[n - 1] > 'z')s[n - 1] -= 26;
	}
	printf("%s\n", s);
}

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

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
constexpr ll mod = 1e9+7;

void add(ll &a, ll b){
  a += b;
  a %= mod;
}

int main(){
#define int ll
  string s; cin >> s;
  
  vvi dp(s.size()+1,vi(4));
  dp[0][0] = 1;
  rep(i,s.size()){
    if(s[i] == '?')
      rep(j,4) add(dp[i+1][j], dp[i][j]*3);
    else
      rep(j,4) add(dp[i+1][j], dp[i][j]);

    if(s[i] == 'A' or s[i] == '?')
      add(dp[i+1][1],dp[i][0]);
    if(s[i] == 'B' or s[i] == '?')
      add(dp[i+1][2],dp[i][1]);
    if(s[i] == 'C' or s[i] == '?')
      add(dp[i+1][3],dp[i][2]);
  }
  cout << dp[s.size()][3] << endl;
}

Measured memory_bytes: 7424