akhauriyash/Code-Regression huggingface dataset:
// C++ Program to print all permutations  
// of a string in sorted order.  
#include <bits/stdc++.h> 
using namespace std; 
  
/* Following function is needed for library function qsort(). Refer  
http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/ */
int compare (const void *a, const void * b)  
{ return ( *(char *)a - *(char *)b ); }  
  
// A utility function two swap two characters a and b  
void swap (char* a, char* b)  
{  
    char t = *a;  
    *a = *b;  
    *b = t;  
}  
  
// This function finds the index of the smallest character  
// which is greater than 'first' and is present in str[l..h]  
int findCeil (char str[], char first, int l, int h)  
{  
    // initialize index of ceiling element  
    int ceilIndex = l;  
  
    // Now iterate through rest of the elements and find  
    // the smallest character greater than 'first'  
    for (int i = l+1; i <= h; i++)  
    if (str[i] > first && str[i] < str[ceilIndex])  
            ceilIndex = i;  
  
    return ceilIndex;  
}  
  
// Print all permutations of str in sorted order  
int sortedPermutations ( char str[], string curr )  
{  
    long long int ijk = 0;
    // Get size of string  
    int size = strlen(str);  
  
    // Sort the string in increasing order  
    qsort( str, size, sizeof( str[0] ), compare );  
  
    // Print permutations one by one  
    bool isFinished = false;  
    while ( ! isFinished )  
    {  
        ijk++;
        if(str == curr){
            return ijk;
        }
        // print this permutation  
        
  
        // Find the rightmost character which is  
        // smaller than its next character. 
        // Let us call it 'first char'  
        int i;  
        for ( i = size - 2; i >= 0; --i )  
        if (str[i] < str[i+1])  
            break;  
  
        // If there is no such character, all are 
        // sorted in decreasing order, means we  
        // just printed the last permutation and we are done.  
        if ( i == -1 )  
            isFinished = true;  
        else
        {  
            // Find the ceil of 'first char' in 
            // right of first character.  
            // Ceil of a character is the smallest 
            // character greater than it  
            int ceilIndex = findCeil( str, str[i], i + 1, size - 1 );  
  
            // Swap first and second characters  
            swap( &str[i], &str[ceilIndex] );  
  
            // Sort the string on right of 'first char'  
            qsort( str + i + 1, size - i - 1, sizeof(str[0]), compare );  
        }  
    }  
}  
  
// Driver program to test above function  
int main(){
    int n;
    cin >> n;
    char str[8] = "";
    
    for(int i = 0; i < n; i++){
        str[i] = (i+1 + '0');
    }
    
    
    string p = "";
    string q = "";
    
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        p += to_string(x);
    }
    
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        q += to_string(x);
    }
    
    long long int res = abs(sortedPermutations( str, p ) - sortedPermutations( str, q ));
    cout << res << endl;
    return 0;  
}  

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int n, p;
string s;
int f[100009], ans;

int32_t main() {

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

    cin >> n >> p >> s;

    if(p == 2 || p == 5) {
        for(int i = 0; i < n; ++i) {
            int dig = s[i] - '0';
            if(dig%p == 0) {
                ans += (i+1);
            }
        }
        cout << ans << '\n';
        return 0;
    }
    
    f[0]++;
    int tn = 1;
    int cur = 0;
    for(int i = n-1; i >= 0; --i) {
        int dig = s[i] - '0';
        cur = (cur + dig*tn%p)%p;
        ans += f[cur];
        f[cur]++;
        tn = tn*10%p;
    }

    cout << ans << '\n';
    
    return 0;
}


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

#define INF INT32_MAX
#define MAX 100000

string S;

int c0, c1;

int main() {
	cin >> S;

	for( int i = 0; i < S.size(); i++ ) {
		if( S[i] == '0' ) {
			c0++;
		}
		else {
			c1++;
		}
	}
	int ans = min( c0, c1 ) * 2;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
import itertools
import math
import fractions
import functools

n = int(input())
dic = {"JPY":0, "BTC":0}
for i in range(n):
    l = list(input().split())
    if l[1] == 'JPY':
        dic["JPY"] += float(l[0])
    if l[1] == 'BTC':
        dic["BTC"] += float(l[0])

print(dic["JPY"] + 380000*dic["BTC"])

Measured memory_bytes: 63980
#include <iostream>
#include <string>
#include <vector>
#include <functional>

#define rep(i,s,N) for(int i=s;i<N;++i) 

struct Card {
	char suit;
	char value;
	int index;
};

template<typename T>
void swap(T& a, T& b) {
	T t = a;
	a = b;
	b = t;
}

void print(std::vector<Card> v) {
	for(int i=0;i<v.size();++i){
		if (i==0) std::cout << v[i].suit << v[i].value;
		else std::cout << " " << v[i].suit << v[i].value;
	}
}

template<typename U>
void sort_bubble(std::vector<U> &x) {
	// sort
	for (int i=0; i<x.size(); ++i) {
		for (int j=x.size()-1; j>i; --j) {
			if (x[j].value < x[j-1].value) {
				swap(x[j], x[j-1]);
			}
		}
	}
}

template<typename T>
void sort_selection(std::vector<T> &x){
	// sort
	for (int i=0; i<x.size(); ++i) {
		int min_index = i;
		for (int j=i+1; j<x.size(); ++j) {
			if (x[j].value < x[min_index].value) min_index = j; 
		}
		if (x[i].value == x[min_index].value) {
			continue;
		}
		swap(x[i], x[min_index]);
	}
}

template<typename T>
using sort_func = void (*)(std::vector<T> &);

template<typename T>
bool check_stability(const std::vector<T> &x) {
	for (int i=1; i<x.size(); ++i) {
		if (x[i-1].value == x[i].value
		    &&  x[i-1].index > x[i].index) {
			return false;
		}
	}
	return true;
}

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<Card> C(N);
	rep(i,0,N) {
		cin >> C[i].suit >> C[i].value;
		C[i].index = i;
	}
	vector<Card> C1(C), C2(C);
	vector<vector<Card> > CA = {C1, C2};	
	vector<sort_func<Card> > fA = { sort_bubble, sort_selection};

	rep(i,0,2) {
		fA[i](CA[i]);
		print(CA[i]); cout << endl;
		string s = check_stability(CA[i])
			 ? "Stable" : "Not stable";
		cout << s << endl;
	}
//	// sort
//	sort_bubble(C1);
//	sort_selection(C2);
//
//	print(C1); cout << endl; 
//	string s1 = check_stability(C1) ? "Stable" : "Not stable";
//	cout << s1 << endl;
//
//	string s2 = check_stability(C2) ? "Stable" : "Not stable";
//	print(C2); cout << endl; 
//	cout << s2 << endl;

	return 0;
}




Measured memory_bytes: 3152
import math

a, b, h, m = map(int, input().split())

m_rad = 2 * math.pi * m / 60.
h_rad = 2 * math.pi * (h / 12.) + 2 * math.pi / 12. * (m / 60.)
m_x, m_y = b * math.cos(m_rad), b * math.sin(m_rad)
h_x, h_y = a * math.cos(h_rad), a * math.sin(h_rad)
print(math.sqrt((m_x - h_x)**2 + (m_y - h_y)**2))

Measured memory_bytes: 9584
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, K, S;
  cin >> N >> K >> S;
  ll wrong;
  if (S != 1000000000) {
    wrong = 1000000000;
  }
  else {
    wrong =  999999999;
  }
  for (ll i = 0; i < N; ++i) {
    if (i < K) {
      cout << S << ' ';
    }
    else {
      cout << wrong << ' ';
    }
  }
  cout << endl;
}


Measured memory_bytes: 1280
S = input()
isA = 0
isB = 0
isC = 0
for i in S:
    if i == 'a':
        isA += 1
    if i == 'b':
        isB += 1
    if i == 'c':
        isC += 1
if isA == 1 and isB == 1 and isC == 1:
    print('Yes')
else:
    print('No')


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

#define qMAX 500000
#define eMAX 1000000000
#define eMIN -1000000000

typedef struct _list{
    int e;
    struct _list *prev;
    struct _list *next;
}LIST;

void output(LIST *END){
    LIST *p=END;
    while(p->prev!=NULL)p=p->prev;
    while(p->next!=NULL){
        printf("%d\n",p->e);
        p=p->next;
    }
}
void freeAll(LIST *END){
    LIST *p=END;
    while(END!=NULL){
        END=END->prev;
        free(p);
        p=END;
    }
}
int main(void){
    LIST *END=(LIST*)malloc(sizeof(LIST));
    END->e=eMIN-1;
    END->prev=NULL;
    END->next=NULL;
    LIST *p=END;
    LIST *prev,*next,*now;
    
    int q;
    scanf("%d\n",&q);
    
    int com,x;
    while(q--){
        scanf("%d \n",&com);
        switch(com){
            case 0:
                //insert
                scanf("%d\n",&x);
                if(p->prev==NULL){
                    now=(LIST*)malloc(sizeof(LIST));
                    now->next=p;
                    p->prev=now;
                    now->prev=NULL;
                    now->e=x;
                    p=now;
                }else{
                    prev=p->prev;
                    next=p;
                    now=(LIST*)malloc(sizeof(LIST));
                    prev->next=now;
                    next->prev=now;
                    now->e=x;
                    now->prev=prev;
                    now->next=next;
                    p=now;
                }
                break;
            case 1:
                //move
                scanf("%d\n",&x);
                if(x>0){
                    while(x--)p=p->next;
                }else{
                    while(x++)p=p->prev;
                }
                break;
            case 2:
                //erase
                if(p->e==eMIN-1){
                    //ENDをさしているため何もしない
                }else{
                    now=p;
                    prev=p->prev;
                    next=p->next;
                    if(prev!=NULL){
                        prev->next=next;
                        next->prev=prev;
                    }else{
                        next->prev=NULL;
                    }
                    p=next;
                    free(now);
                }
                break;
        }
    }
    
    output(END);
    freeAll(END);
    
    return 0;
    
}



Measured memory_bytes: 17232
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    string s;
    cin >> s;
    if(s == "SUN") cout << 7 << endl;
    else if(s == "MON") cout << 6 << endl;
    else if(s == "TUE") cout << 5 << endl;
    else if(s == "WED") cout << 4 << endl;
    else if(s == "THU") cout << 3 << endl;
    else if(s == "FRI") cout << 2 << endl;
    else cout << 1 << endl;
    
    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(a < b ? "a < b" : (a > b ? "a > b" : "a == b"));
		sc.close();
	}
}


Measured memory_bytes: 26264
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<usize>().unwrap());
    let (_, k) = (it.next().unwrap(), it.next().unwrap());
    let line = gets();
    let mut v: Vec<u32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<u32>().unwrap())
        .collect();
    v.sort();
    let mut ans = 0;
    for i in 0..k {
        ans += v[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 2072
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	n%=10;
	if(n==3)
	    cout<<"bon"<<endl;
	else if(n==0||n==1||n==6||n==8)
	    cout<<"pon"<<endl;
	else
	    cout<<"hon"<<endl;
	return 0;
}

Measured memory_bytes: 3076
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

int main(){
    
    int n;

    std::cin >> n;

    std::vector<int> l(n);

    for(auto&& e : l){
        std::cin >> e;
    }

    if((*std::max_element(l.begin(), l.end()) * 2) < std::accumulate(l.begin(), l.end(), 0)){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

bool f(int x, vl &a) {
  ll s = a[x];
  int n = a.size();
  for (int i = n - 1; i >= 0; i--) {
    if (i == x)
      continue;
    if (a[i] <= 2 * s) {
      s += a[i];
    } else {
      return false;
    }
  }
  return true;
}

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

  int n;
  cin >> n;
  vl a(n);
  REP(i, n) { cin >> a[i]; }
  sort(a.rbegin(), a.rend());
  if (!f(0, a)) {
    cout << 0 << endl;
    return 0;
  }
  int ok = 0;
  int ng = n;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (f(mid, a)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok + 1 << endl;
  return 0;
}


Measured memory_bytes: 1024
//
// Created by karth on 8/2/2020.
//
// BDTSL
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define INF 1e18
#define MOD 1e9+7

//void setIO(string s) {
//    ios_base::sync_with_stdio(0); cin.tie(0);
//    freopen((s+".in").c_str(),"r",stdin);
//    freopen((s+".out").c_str(),"w",stdout);
//}
int factorial(int n) {
    if (n == 1)
        return 1;
    return n * factorial(n - 1);
}

int nCr(int n, int r) {
    return factorial(n) / (factorial(r) * factorial(n - r));
}
int solve(int k){
    int n = 7%k;
    int ans = 0;
    for(int i = 1; i < 1e7; ++i){
        if(n == 0){
            return i;
        }
        else{
            n = (n*10+7)%k;
        }
    }

    return -1;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin >> k;
    cout << solve(k) << "\n";


    return 0;
}



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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long h, x = 0, z = 0;
	cin >> h;
	while(h){
		z += pow(2, x);
		++x;
		h /= 2;
	}
	cout << z;

	return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
using namespace std;
const int N=100+10;
double v[N],t[N],vv[N];
int n;
int main()
{
    while(~scanf("%d",&n)){
        double sum=0;
        for(int i=1;i<=n;i++)
            scanf("%lf",&t[i]);
        for(int i=1;i<=n;i++)
            scanf("%lf",&v[i]);
        vv[n]=0;
        for(int i=n-1;i>=1;i--)
            vv[i]=min(v[i],min(v[i+1],vv[i+1]+t[i+1]));
        double ans=0;
        for(int i=1;i<=n;i++){
            if(ans>=vv[i]){
                if(ans-vv[i]==t[i]){
                    sum+=(ans*t[i]-0.5*t[i]*t[i]);
                    ans=vv[i];
                }
                else {
                    double t3=ans-vv[i];
                    double t1=min((t[i]-t3)/2,v[i]-ans);
                    double t2=(t[i]-2*t1-t3);
                    sum+=(ans*t1*2+t1*t1+(ans+t1)*t2+ans*t3-0.5*t3*t3);
                    ans=vv[i];
                }
            }
            else {
                if(vv[i]-ans<t[i]){
                    double t1=vv[i]-ans;
                    double t2=min((t[i]-t1)/2,v[i]-vv[i]);
                    double t3=t[i]-t1-2*t2;
                    sum+=(ans*t1+0.5*t1*t1+vv[i]*t2*2+t2*t2+(ans+t1+t2)*t3);
                    ans=vv[i];

                }
                else {sum+=(ans*t[i]+0.5*t[i]*t[i]);ans+=t[i];}
            }
        }
        printf("%f\n",sum);
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        int count = 0;
        for (int i = 0; i < H; i++) {
            String s = scan.next();
            char[] d = s.toCharArray();
            for (int j = 0; j < W; j++) {
                if (d[j] == '#') {
                    count += 1;
                }
            }
        }
        if (count == H + W - 1) {
            System.out.println("Possible");
        } else {
            System.out.println("Impossible");
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
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 ll INF = 1LL << 60;
int N;
ll h[100001];
ll dp[100001];

int main() {
    ios::sync_with_stdio(false);
    cin >> N;
    
    for(int i = 0; i < 100001; ++i) dp[i] = INF;

    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }
    dp[1] = 0;
    /*
    for(int i = 2; i <= N; ++i){
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i > 2) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }
    */
    
    for (int i = 1; i <= N; i++) {
        chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }
    
    cout << dp[N] << endl;
    

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


signed main(){
    int n;cin>>n;
    vector<int> a(n),b(n);
    cin>>a>>b;
    map<int,vector<int>> aid,bid;
    map<int,int> ac,bc;
    rep(i,n){
        aid[a[i]].push_back(i);
        ac[a[i]]++;
        bid[b[i]].push_back(i);
        bc[b[i]]++;
    }

    using P=pair<int,int>;
    priority_queue<P> que;
    for(auto [num,cnt]:ac) que.push({cnt,num});

    vector<int> fr;
    vector<int> res(n,-1);
    while(!que.empty()){
        auto [cnt,num]=que.top();que.pop();
        auto brem=bc[num];

        while(brem){
            if(!que.empty()){
                auto [topcnt,topnum]=que.top();que.pop();
                while(brem and !aid[topnum].empty()){
                    res[aid[topnum].back()]=num;
                    aid[topnum].pop_back();
                    brem--;
                }
                if(!aid[topnum].empty()){
                    que.push({(int)aid[topnum].size(),topnum});
                }
            }else{
                while(brem and !fr.empty()){
                    res[fr.back()]=num;
                    brem--;
                    fr.pop_back();
                }
                if(brem and fr.empty()){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
        while(!aid[num].empty()){
            fr.push_back(aid[num].back());
            aid[num].pop_back();
        }
        bc[num]=brem;
    }
    for(auto [num,cnt]:bc){
        rep(_,cnt){
            res[fr.back()]=num;
            fr.pop_back();
        }
    }
    cout<<"Yes"<<endl;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 70312
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  cout << (n-1) * (m-1) << endl;
  return 0;
}


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

int main()
{
  int i, j;
  for (i = 1; i < 10; i++) {
    for (j = 1; j < 10; j++) {
      int seki = i * j;
      cout << i << "x" << j << "=" << seki << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
int n, a[101010][3], dp[101010][3];
int solve(int i, int t){
    if(i == n){
        return 0;
    }
    if(dp[i][t] != -1){
        return dp[i][t];
    }

    for(int k = 0; k < 3; k++){
        if(k != t)
            dp[i][t] = max(dp[i][t], solve(i + 1, k) + a[i][t]);
    }
    return dp[i][t];
}
int main(){
    memset(dp, -1, sizeof dp);
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i][0]>>a[i][1]>>a[i][2];
    cout<<max(solve(0, 0), max(solve(0, 1), solve(0, 2)))<<endl;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool is_pal(string S){
    int n=S.length();
    int i=0;
    while(i<n){
        if(S[i]!=S[n-1-i]){
            return false;
        }
        i++;
    }
    return true;
}
int main(){
    string S;
    cin>>S;
    int N=S.length();
    int p=1;
    if(is_pal(S)&&is_pal(S.substr(0,(N-p)/2))&&is_pal(S.substr((N-p)/2+1,(N-p)/2))){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out = "";
    int n = scanner.nextInt();
    scanner.nextLine();
    for (int ii = 0; ii < n; ii++) {
      String[] tr = new String[53];
      int pos = 26;
      String line = scanner.nextLine();
      for (int jj = 0, sum = 0; sum < line.length(); jj++) {
        int type = jj % 2 == 0 ? 1 : 2;
        String work = line.substring(sum, sum + type);
        sum += type;
        if (type == 1) {
          tr[pos] = work;
          continue;
        }
        if (work.equals("->")) {
          pos++;
        } else {
          pos--;
        }
      }
      for (int jj = 0; jj < tr.length; jj++) {
        if (tr[jj] == null) {
          continue;
        }
        out += tr[jj];
      }
      out += "\n";
    }
    System.out.print(out);
  }
}

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

namespace ConsoleApp8
{
	class Program
	{
		static void Main(string[] args)
		{
			// ごりら
			int sum = 0;
			var str = Console.ReadLine().Split(' ');
			int n = int.Parse(str[0]);
			int a = int.Parse(str[1]);
			int b = int.Parse(str[2]);
			char[] array;
			int temp = 0;
			for (int i = n; i > 0; i--)
			{
				array = i.ToString().ToCharArray();
				temp = array.Sum(x => (int)x - '0');
				if (a <= temp && b >= temp)
					sum += i;
			}
			Console.WriteLine(sum);
		}
	}
}


Measured memory_bytes: 11220
n, m = map(int, input().split())
ab = []
for i in range(m):
    a, b = map(int, input().split())
    ab.append((a - 1, 2, i))
    ab.append((b - 1, 1, i))

ab.sort()
ans = 0
separated = [False] * m
buf = set()
for island, ab, i in ab:
    if ab == 1:
        if separated[i]:
            continue
        else:
            ans += 1
            for j in buf:
                separated[j] = True
            buf.clear()
    else:
        buf.add(i)
print(ans)


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

#define REP(i, n) for (int i = 0; i < (int)n; i++)

int N, L[200];

int main()
{
  cin >> N;
  REP(i, 2*N) cin >> L[i];
  sort(L, L+2*N);
  int ans = 0;
  REP(i, N) ans += L[2*i];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a = 0,b = 0;
  scanf("%d %d",&a,&b);
  if(a < b){
    puts("a < b");
  }else if (a == b){
    puts("a == b");
  }else {
    puts("a > b");
  }
  return 0;
}

Measured memory_bytes: 580
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, K = Scanner.map_int()
    ans = 0
    for i in range(K, N + 2):
        a = (i * (i - 1)) // 2
        b = N * i - a
        ans += b - a + 1
        ans %= MOD
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10728
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
#define int long long
#define ll long long 
#define F first
#define sqr(x) ((x) * (x))
#define S second
#define make make_pair
#define pb push_back
#define sz(x) (ll)(x.size()) 
#define all(x) x.begin (), x.end ()

using namespace std;
                        
typedef unsigned long long ull;
typedef long double ld;

const int MOD = (int)1e9 + 7;
const int N = (int)2e6+ 222;
const ll INF = (ll)1e18;
const double eps = (double)1e-6;
                                    
string s, a[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"};
int n;


void solve () {                     
	cin >> n >> s;
	for (int i = 0; i < sz(s); ++i) {
		cout << char((((s[i] - 'A') + n) % 26)  + 'A') ;
	}


}





signed main () {
    #ifdef Maga
        freopen("input", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);                                              
    int t = 1;
   // cin >> t;
    while (t --) {
    	solve ();
    }
    return 0;
}





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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

#define MAX_NUM (1000000007)
#define PI 3.14159265358979323846

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T> &A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T> &A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T> &A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first > b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

i64 My_Comb(u64 n, u64 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

i64 My_Pow(u64 a, u64 n, i64 m) {
  u64 tmp = n, calc = 1;
  while (tmp > 0) {
    if (tmp % 2) {
      tmp--;
      calc *= a;
      calc %= m;
    } else {
      a *= a;
      a %= m;
      tmp /= 2;
    }
  }
  return calc;
}

class UnionFind {
 public:
  vector<u64> Par;
  vector<u64> sz;

  UnionFind(u64 n);
  u64 root(u64 x);
  bool same(u64 x, u64 y);
  void unite(u64 x, u64 y);
  u64 size(u64 x);
};

UnionFind::UnionFind(u64 n) {
  Par.resize(n);
  sz.assign(n, 1);
  for (u64 i = 0; i < n; ++i) Par[i] = i;
}

u64 UnionFind::root(u64 x) {
  if (Par[x] == x) {
    return x;
  } else {
    return Par[x] = root(Par[x]);
  }
}

bool UnionFind::same(u64 x, u64 y) { return root(x) == root(y); }

u64 UnionFind::size(u64 x) { return sz[root(x)]; }

void UnionFind::unite(u64 x, u64 y) {
  x = root(x);
  y = root(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  Par[y] = x;
}

template <typename T>
i64 BinSearch(vector<T> &V, i64 comp) {
  i64 l = 0, r = V.size() - 1;
  if (V[l] > V[r]) swap(l, r);
  if (V[l] >= comp) return l;
  if (V[r] <= comp) return r;
  while (abs(r - l) > 1) {
    i64 index = (l + r) / 2;
    if (V[index] == comp)
      return index;
    else if (V[index] > comp)
      r = index;
    else
      l = index;
  }
  if (abs(V[l] - comp) < abs(V[r] - comp))
    return l;
  else
    return r;
}
bool isPrime(u32 n) {
  if (n == 2) return true;
  if (n % 2) return false;
  for (u32 i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  cout << setprecision(18);

  u32 N;
  cin >> N;

  cout << (N ^ 0x01) << endl;

  return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> h(n, 0), a(n, 0);

    for (int i = 0; i < n; i += 1)
        cin >> h[i];
    for (int i = 0; i < n; i += 1)
        cin >> a[i];
    
    vector<int64_t> dp(n, 0);

    vector<int64_t> aib(n + 1, 0);

    auto query = [&] (int poz) {
        int64_t ans = 0;
        while(poz > 0) {
            ans = max(ans, aib[poz]);
            poz -= (poz & (-poz));
        }
        return ans;
    };

    auto update = [&] (int poz, int64_t value) {
        while(poz <= n) {
            aib[poz] = max(aib[poz], value);
            poz += (poz & (-poz));
        }
    };


    for (int i = 0; i < n; i += 1) {
        dp[i] = a[i] + query(h[i]);
        update(h[i], dp[i]);
    }

    cout << *max_element(dp.begin(), dp.end()) << "\n";
}

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

int main() {
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    a--;b--;c--;d--;
    string str;
    cin>>str;
    for(ll i=a;i<max(c,d);i++){
        if(str[i]=='#' && str[i-1]=='#'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(c>d){
        for(ll i=b+1;i<=d+1;i++){
            if(str[i]=='.' && str[i-1]=='.' && str[i-2]=='.'){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}


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

int main(){
  string str;
  string key = "keyence";
  cin>>str;
  int len = str.length();
  if(str.substr(0,7)==key){
    cout<<"YES"<<endl;
    return 0;
  }else if(str.substr(len-7,7)==key){
    cout<<"YES"<<endl;
    return 0;
  }else{
    for(int i = 1;i < 7;i++){
        if(str.substr(0,i)+str.substr(len-7+i,7-i)==key){
            cout<<"YES"<<endl;
            return 0;
        }
    }
  }
  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,a[maxn];
int main()
{
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(register int i=1;i<=n;i++)
		if(a[i]>a[i-1])
			a[i]--;
	for(register int i=1;i<=n;i++)
		if(a[i]<a[i-1])
		{
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

    int main(){
        int A,B;
        scanf("%d", &A);
        scanf("%d", &B);
        if (A + B <= 16) {
                if (A <= 8 && B <= 8 ){
                    printf("Yay!");
                } else {
                    printf(":(");
                }

        } else {
        }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
#include<numeric>

using namespace std;

unsigned long long gcd(unsigned long long a,unsigned long long b) {
	return b != 0 ? gcd(b, a % b) : a;
}
unsigned long long lcm(unsigned long long a, unsigned long long b) {
	return a * b / gcd(a, b);
}
int main() {
	unsigned long long n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	unsigned long long l = lcm(m, n);
	unsigned long long  a = l / n;
	unsigned long long  b = l / m;
	unsigned long long  c = lcm(a,b);
	unsigned long long a1 = c / a;
	unsigned long long b1 = c / b;
	//cout << a << endl << b << endl << c << endl;
	int count = 0;
	for (unsigned long long  i = 0; i < l / c; i++) {
		if (s[i*a1] != t[i*b1])
			goto d;
	}
	
	if (count ==0)
		cout << l << endl;
	else
		d: cout << -1 << endl;

}


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

int main(){
 string S;
  cin >> S;
  if(S.at(0)==S.at(1)||S.at(1)==S.at(2)||S.at(2)==S.at(3))cout << "Bad" << endl;
  else cout << "Good" <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int a,b,k,x;
	cin>>a>>b>>k;
	if((a+b)<=k){
		a=0;
		b=0;
	}
	else if(a>=k){
		a=a-k;
	}
	else if(a<k){
		x=k-a;
		a=0;
		b=b-x;
	}
	cout<<a<<" "<<b;
}

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

int solution(const int a, const int b, const int c) {
    int s = a + b + c;
    int p = std::max(a, std::max(b, c));
    return s - p + p * 10;
}

int main() {
    int a, b, c;
    std::cin >> a >> b >> c;
    std::cout << solution(a, b, c) << std::endl;
    return 0;
}


Measured memory_bytes: 256
/* https://atcoder.jp/contests/abc102/tasks/arc100_a */

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

long long solve(const int N, std::vector<int> &A)
{
  std::vector<int> B(N);

  for (int i = 0; i < N; ++i) {
    int x = i + 1;
    int y = A.at(i);
    B.at(i) = y - x;
  }

  std::sort(B.begin(), B.end());

  int b = B.at(N/2);

  long long sum_dist = 0;
  for (int i = 0; i < N; ++i) {
    sum_dist += std::abs(A.at(i) - (b + i + 1));
  }

  return sum_dist;
}

int main(int argc, char **argv)
{
  // Input
  int N;

  std::cin >> N;

  std::vector<int> A(N);

  for (auto& e: A)
    std::cin >> e;

  // Output
  std::cout << solve(N, A) << std::endl;

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<iomanip>
#include<algorithm>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(to); x++) // for簡略表記
#define DUMP(ar) for(int i=0; i<ar.size(); i++) cout << "[" << i << "]:" << ar[i] << endl // 配列一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// goto ANSWER; で最後へ飛ぶ

int dic_hash(string s){
    int num=0;
    for(unsigned int i=0; i<s.size(); i++){
        num *= 5;
        switch(s.at(i)){
        case 'A':
            num += 1;
            break;
        case 'T':
            num += 2;
            break;
        case 'G':
            num += 3;
            break;
        case 'C':
            num += 4;
            break;
        }
    }
    return num;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    cin >> ws;
    vector<string> strs(n);
    FOR(i, n) getline(cin, strs[i]);
    // for(int i=0; i<n; i++) getline(cin, strs[i]);
    vector<bool> dic(pow(5, 12), false);
    
    // DUMP(strs);

    int key;
    // string str;
    for(string str : strs){
        // cout << "hello" << endl;
        if(str.at(0) == 'i'){
            key = dic_hash(str.substr(7));
            dic[key] = true;
        }else{
            key = dic_hash(str.substr(5));
            if(dic[key]){
                cout << "yes" << '\n';
            }else{
                cout << "no" << '\n';
            }
        }
    }

    cout << flush;

ANSWER:
    return 0;
}


Measured memory_bytes: 90984
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	valstr := sc.Text()
	n, _ := strconv.Atoi(valstr)

	var array []int
	for {
		sc.Scan()
		aStr := sc.Text()
		if len(aStr) == 0 {
			break
		}
		val, _ := strconv.Atoi(aStr)
		array = append(array, val)

	}

	shellSort(array, n)
	fmt.Println(cnt)
	for _, v := range array {
		fmt.Println(v)
	}

}

var cnt int

func shellSort(a []int, n int) {
	cnt = 0
	var G []int
	for i := 1; i <= n; {
		G = append(G, i)
		i = i*3 + 1
	}

	fmt.Println(len(G))
	var Gstr []string
	for i := len(G) - 1; i >= 0; i-- {
		Gstr = append(Gstr, strconv.Itoa(G[i]))
	}
	fmt.Println(strings.Join(Gstr, " "))

	for i := len(G) - 1; i >= 0; i-- {
		insertionSort(a, n, G[i])
	}
}

func insertionSort(a []int, n int, g int) {
	for i := g; i <= n-1; i++ {
		v := a[i]
		j := i - g
		for j >= 0 && a[j] > v {
			a[j+g] = a[j]
			j = j - g
			cnt++
		}
		a[j+g] = v
	}
}



Measured memory_bytes: 24484
#include<iostream>
    #include <bits/stdc++.h>
    using namespace std;
    int main(){
        int H, W;
        cin >> H >> W;
        for(int i=0;i<W+2;i++) cout<<"#";
        cout <<endl;
        vector<string> vec(H);
        for(int i=0; i<H; i++){
            
            cin >> vec[i];
            cout << "#" << vec[i] << "#" << endl;
        }

        for(int i=0;i<W+2;i++) cout<<"#";

    }

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

int main(){
    int n;
    cin>>n;
    double a,sum=0;
    long long b;

    for(int i=0;i<n;i++) {
        cin>>a;
        sum+=1/a;
    }
    b=(1/sum)*100000000+0.5;
    cout<<(double)b/100000000<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,r, g, b;
	scanf("%d %d %d", &r, &g, &b);
	a = r*100 + g*10 + b;
	a %= 4;
	if (a==0){
		printf("YES");
	}
	else{
		printf("NO");
	}
	return 0;
}

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

int main(){
  char S[10];
  cin >> S;
  sort(S, S + 4);
  if(S[0] == S[1] && S[2] == S[3] && S[1] != S[2])
    cout << "Yes";
  else
    cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1e9 + 7;
i64 n, k;
vector<vector<i64>> g;

i64 dfs(i64 u, i64 p, i64 d) {
  i64 s = 1, c = min(i64(1), d) + 1;
  for (i64 v : g[u]) {
    if (v == p) continue;
    s = max(i64(0), s * (k - c)) % mod;
    ++c;
    s = s * dfs(v, u, d + 1) % mod;
  }
  cerr << u << '\t' << s << endl;
  return s;
}

int main() {
  cin >> n >> k;
  init_n(g, n + 1);
  for (i64 i = 0; i < n - 1; ++i) {
    i64 a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  i64 ans = k * dfs(1, 0, 0) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12800
//By MagicSpark
/*
Problem:AGC030B
Main Idea:greedy
Status:
*/
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
#pragma comment(linker, "/STACK:16000000")
//#define map gp_hash_table
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const long long inf2=0x3f3f3f3f3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
namespace fastio{
	char in[100000];
	int itr=0,llen=0;
	char get(){
		if(itr==llen)llen=fread(in,1,100000,stdin),itr=0;
		if(llen==0)return EOF;
		return in[itr++];
	}
	char out[100000];
	int itr2=0;
	void put(char c){
		out[itr2++]=c;
		if(itr2==100000){
			fwrite(out,1,100000,stdout);
			itr2=0;
		}
	}
	int clear(){
		fwrite(out,1,itr2,stdout);
		itr2=0;
		return 0;
	}
	int getint(){
    	int r=0; bool ng=0; char c; c=get();
    	while (c!='-'&&(c<'0'||c>'9')) c=get();
   		if (c=='-') ng=1, c=get();
    	while (c>='0'&&c<='9') r=r*10+c-'0', c=get();
    	return ng?-r:r;
	}
	string getstr(){
		string ret="";
		char ch=get();
		while(ch==' '||ch=='\n')ch=get();
		while(ch!=' '&&ch!='\n')ret.push_back(ch),ch=get();
		return ret;
	}
	void putstr(string s){
		for(int i=0;i<s.size();i++)put(s[i]);
	}
	void putint(int x){
		if(x==0){
			put('0');
			return;
		}
		char c[20];int pos=0;
		while(x){
			c[pos++]='0'+x%10;
			x/=10;
		}
		for(int i=pos-1;i>=0;i--)put(c[i]);
	}
}
#define N 200010
using namespace fastio;
#define fastio
int n;
int a[N];
ll sum[N];
ll getsum(int l,int r){
	return sum[r+1]-sum[l];
}
void getarr(int arrname[],int size){
	for(int i=0;i<size;i++)arrname[i]=getint();
}
ll ans;
int L;
signed main(){
	L=getint();n=getint();
	getarr(a,n);
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i-1];
	ans=max(a[0],L-a[n-1]);
	for(int i=1;i<n;i++){
		int len=min(i,n-i);
		ans=max(ans,2ll*(getsum(i-len,i-1)+1ll*len*L-getsum(i,i+len-1))-min(a[i-1],L-a[i]));
		len=min(i-1,n-i);
		ans=max(ans,2ll*(getsum(i-len-1,i-1)+1ll*len*L-getsum(i,i+len-1))-a[i-1]);
		len=min(i,n-i-1);
		ans=max(ans,2ll*(getsum(i-len,i-1)+1ll*(len+1ll)*L-getsum(i,i+len))-(L-a[i]));
	}
	cout<<ans<<endl;
	return 0;
}
/*syxakioi!
  syxakioi!
  syxakioi!
*/

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n, m, d;
	cin >> n >> m >> d;
	double Tmp = (double)(n - d) / (n * n);
	if (d != 0) Tmp *= 2;
	Tmp *= m - 1;
	printf("%.15f\n", Tmp);
	return 0;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string s;
  cin >> s;
  const int64_t L = static_cast<int64_t>(s.length());
  int64_t result = 0;
  int64_t count = 0;
  int64_t i = 0;
  while (i < L) {
    if (s.substr(i, 1) == "A") {
      ++count;
      ++i;
    } else if (s.substr(i, 2) == "BC") {
      result += count;
      i += 2;
    } else {
      count = 0;
      ++i;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3744
n,l= map(int,input().split())
b =[]
for i in range(1,n+1):
    a = l + i -1
    b.append(a)
    min = b[0]
for i in range(n):
    if abs(min) > abs(b[i]):
        min = b[i]
print(sum(b)- min)

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

int main() {
    int K,N; cin >> K >> N;
    vector<int> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];

    int res = min(A[N - 1] - A[0], K - (A[1] - A[0]));
    for(int i=1; i+1<N; i++) {
        res = min({res, K - abs(A[i - 1] - A[i]), K - abs(A[i + 1] - A[i])});
    }
    res = min(res, K - (A[N - 1] - A[N - 2]));
    //res = min(K - (K - A[N - 1]) - A[0]);
    cout << res << '\n';
}    

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

const int max_n = 1e5 + 5;



int main () {
	make(n);
	makev(v, n);
	int dp[2];
	dp[0] = 0;
	dp[1] = abs(v[0] - v[1]);
	FOR(i,2,n) {
		int val = min(dp[0] + abs(v[i-2]-v[i]), dp[1] + abs(v[i-1]-v[i]));
		dp[0] = dp[1];
		dp[1] = val;
	}
	printf("%d\n", dp[1]);
}	





Measured memory_bytes: 892