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

const int INF = 2e9;

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

    unordered_map<int,int> F; // F[i] := 数字iを作るのに使うマッチ数
    F[1] = 2, F[2] = 5, F[3] = 5,F[4] = 4, F[5] = 5,
    F[6] = 6, F[7] = 3, F[8] = 7, F[9] = 6;

    vector<int> dp(N+1, -INF); // dp[i] := マッチ棒をi本使って作れる数の最大の桁数
    string ans = "";

    //dpテーブルを埋めていく
    dp[0] = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j < M; j++){
            if(i - F[A[j]] >= 0) dp[i] = max(dp[i], dp[i-F[A[j]]] + 1);
        }
    }

    //前処理(数字がなるべく大きい方が辞書順が大きくなるので、数字が大きいものを先に並べておく)
    sort(A.begin(), A.end(), greater<int>());

    // dpテーブルが動いた時に数字は追加されているのでそれを逆に辿る
    int remain = dp[N]; // 残り桁数
    int match = N;      // 残りマッチ数
    while(match > 0){
        for(int i = 0; i < M; i++){
            if( match - F[A[i]] >= 0 && dp[match - F[A[i]]] == remain - 1){
                ans += string{(char)(A[i] + '0')};
                match -= F[A[i]];
                remain--;
                break;
            }
        }
    }

    //　最大桁数の中で辞書順最大なものを出力したい
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());

    cout << ans << endl;

}

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

int p[200000];
int r[200000];
typedef pair<int,int> P;
void init(int n){
  for(int i = 0;i < n;i++){
    p[i] = i;
    r[i] = 0;
  }
}

int find(int x){
  if(p[x] == x){
    return x;
  }
  else{
    return p[x] = find(p[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return;
  if(r[x] < r[y]){
    p[x] = y;
  }
  else{
    p[y] = x;
    if(r[x] == r[y]) r[x]++;
  }
}

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

int p2[200000];
int r2[200000];
void init2(int n){
  for(int i = 0;i < n;i++){
    p2[i] = i;
    r2[i] = 0;
  }
}

int find2(int x){
  if(p2[x] == x){
    return x;
  }
  else{
    return p2[x] = find2(p2[x]);
  }
}

void unite2(int x,int y){
  x = find2(x);
  y = find2(y);
  if(x == y) return;
  if(r2[x] < r2[y]){
    p2[x] = y;
  }
  else{
    p2[y] = x;
    if(r2[x] == r2[y]) r2[x]++;
  }
}

bool same2(int x,int y){
  return find2(x) == find2(y);
}

int main(){
  int n,k,l;
  cin >> n >> k >> l;
  init(n);
  init2(n);
  for(int i = 0;i < k;i++){
    int a,b;
    cin >> a >> b;
    unite(a-1,b-1);
  }
  for(int i = 0;i < l;i++){
    int a,b;
    cin >> a >> b;
    unite2(a-1,b-1);
  }
  map<P,int> ans;
  for(int i = 0;i < n;i++){
     ans[make_pair(find(i),find2(i))]++;
  }
  for(int i = 0;i < n;i++){
    cout << ans[make_pair(find(i),find2(i))] << ' ';
  }
  cout << endl;
  /*for(int i = 0;i < n;i++){
    cout << find(i) << ' ' << find2(i) << endl;
  }*/
}

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

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

ll lcm(ll a, ll b){
    ll g = gcd(a,b);
    return a/g * b;
}

int main(){
    int n;
    cin>>n;
    ll ans = 1LL;
    rep(i,n){
        ll t;
        cin>>t;
        ans = lcm(ans,t);
    }
    cout << ans << endl;
    return 0;
    
}


Measured memory_bytes: 256
package main

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

var (
	scanner = bufio.NewScanner(os.Stdin)
	w       = bufio.NewWriter(os.Stdout)
)

func readInt() (read int) {
	scanner.Scan()
	read, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

func arrayEqual(A []int, B []int, N int) bool {
	for i := 0; i < N; i++ {
		if A[i] != B[i] {
			return false
		}
	}
	return true
}

func main() {
	buf := make([]byte, 1024*1024)
	scanner.Buffer(buf, bufio.MaxScanTokenSize)
	scanner.Split(bufio.ScanWords)
	defer w.Flush()

	n := readInt()
	k := readInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}

	for i := 0; i < k; i++ {
		b := make([]int, n+1)
		for j := 0; j < n; j++ {
			l := max(j-a[j], 0)
			r := min(j+a[j]+1, n)
			b[l]++
			b[r]--
		}
		for j := 0; j < n; j++ {
			b[j+1] += b[j]
		}
		if arrayEqual(a, b, n) {
			break
		}
		a = b[:len(b)-1]
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(w, "%d ", a[i])
	}
}


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


#define TRACE

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

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

int a[400009],ans[400009];
int n,lst[400009],nxt[400009];
bool vis[400009];
void solve(int i){
	if(vis[i]) return;
	if(nxt[i]+1>=n) {
		ans[i] = (nxt[i]+1)-n;
		vis[i]=1;
		return;
	}
	solve(nxt[i]+1);
	ans[i]=ans[nxt[i]+1];
	vis[i]=1;
}
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	cin>>n;
	ll k;cin>>k;
	rep(i,n){
		cin>>a[i];
		a[n+i]=a[i];
	}
	repD(i,2*n-1,n) lst[a[i]]=i;
	repD(i,n-1,0){
		nxt[i] = lst[a[i]];
		lst[a[i]]=i;
	}
	rep(i,n){
		if(!vis[i]) solve(i);
	}
	ans[n]=0;
	vi v;
	v.pb(0);
	memset(lst,-1,sizeof(lst));
	lst[0]=0;
	int cur=0;
	while(lst[ans[cur]]==-1){
		cur=ans[cur];
		lst[cur]=sz(v);
		v.pb(cur);
	}
	cur=ans[cur];
	k--;
	if(k>=sz(v)){
		k-=lst[cur];
		k%=(sz(v)-lst[cur]);
		k+=lst[cur];
	}
	fill(vis);
	vi fns;
	repA(i,v[k],n-1){
		if(!vis[a[i]]) fns.pb(a[i]),vis[a[i]]=1;
		else{
			while(fns.back()!=a[i]) vis[fns.back()]=0,fns.pop_back();
			vis[a[i]]=0;
			fns.pop_back();
		}
	}
	trav(i,fns) cout<<i<<' ';
	return 0;
}



Measured memory_bytes: 9076
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

char s[110000];

int main()
{
  int i,j,k,n,ans,tmp;
  scanf("%s",s);
  n=strlen(s);
  ans=n;
  for (i=0;i+1<n;i++)
  {
    if (s[i]!=s[i+1])
    {
      tmp=i+1;
      if (n-(i+1)>tmp) tmp=n-(i+1);
      if (tmp<ans) ans=tmp;
    }
  }
  printf("%d\n",ans);
}

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

using namespace std;

int main() {

	string str;

	getline(cin,str);

	for (int i = 0;; i++) {

		if (str[i] >= 97 && str[i] <= 122) {

			str[i] -= 32;

		}
		else if (str[i] >= 65 && str[i] <= 90) {

			str[i] += 32;

		}

		if (str[i] == 0) {

			break;

		}
		else {

			

		}


	}
	cout << str << endl;
	return 0;

}



Measured memory_bytes: 3100
#include <stdio.h>

int main(void) {
	int n, i, dep = 0, cnt = 0;
	char s;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++) {
		scanf(" %c", &s);
		if (s == 'W')
			dep++;
		else if (dep > 0)
			dep--, cnt++;
	}
	
	printf("%d\n", cnt);
	
	return 0;
}

Measured memory_bytes: 128
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = sc.nextInt()
    val b = sc.nextInt()
    if (n * a < b) {
        print(n*a)
     } else {
        print(b)
     }

}

Measured memory_bytes: 31532
#include <iostream>
#include <set>

int main() {

    std::multiset<int> s;
    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int t;
        std::cin >> t;
        if (t == 0) {
            int x;
            std::cin >> x;
            s.insert(x);
            std::cout << s.size() << "\n";
        } else if (t == 1) {
            int x;
            std::cin >> x;
            std::cout << s.count(x) << "\n";
        } else if (t == 2) {
            int x;
            std::cin >> x;
            s.erase(x);
        } else {
            int l, r;
            std::cin >> l >> r;
            auto e = s.upper_bound(r);
            for (auto itr = s.lower_bound(l); itr != e; ++itr) std::cout << *itr << "\n";
        }
    }
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 056 C / Link: http://abc056.contest.atcoder.jp/tasks/abc056_c  ----- */


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

	LL N; 
	cin >> N;
	LL ans = 0LL;
	FOR(i, 1, N+1) {// sqrt(N)
		LL a = i * (i + 1LL) / 2;
		if (N <= a) {
			ans = i;
			break;
		}
	}
	
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
import sys

N, W = map(int, sys.stdin.readline().strip().split())
weights = []

for _ in range(N):
    v, w = map(int, sys.stdin.readline().strip().split())
    weights.append((v, w))

dp = [0 for _ in range(W+1)]
for j in range(W+1):
    for i in range(N):
        v, w = weights[i]
        if j - w >= 0:
            dp[j] = max(dp[j], dp[j-w] + v)

print(max(dp))


Measured memory_bytes: 5928
n=int(input())
a=list(map(int, input().split()))
r=[0]*n

while max(a) != min(a):
    for i in range(n):
        a1,a2,a3=a[i-1], a[i], a[(i+1)%n]
        if a2 > a1:
            val=min(a3, a2-a1)
            r[(i+1)%n]+=val*2
            a[i]-=val
            a[(i+1)%n]-=val
        if a2 > a3:
            val=min(a1, a2-a3)
            r[i]+=val*2
            a[i]-=val
            a[i-1]-=val

    for i in range(n)[::-1]:
        a1,a2,a3=a[i-1], a[i], a[(i+1)%n]
        if a2 > a1:
            val=min(a3, a2-a1)
            r[(i+1)%n]+=val*2
            a[i]-=val
            a[(i+1)%n]-=val
        if a2 > a3:
            val=min(a1, a2-a3)
            r[i]+=val*2
            a[i]-=val
            a[i-1]-=val

b=max(a)
print(" ".join(list(map(lambda x: str(x+b), r))))

Measured memory_bytes: 19256
import fractions


def lcm(a, b):
    return a * b // fractions.gcd(a, b)


def f(x, a, b):
    return x - x // a - x // b + x // lcm(a, b)


def main():
    a, b, c, d = map(int, input().split())
    print(f(b, c, d) - f(a - 1, c, d))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5088
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long K = sc.nextLong();
        
        if(A>=K){
            System.out.println(A-K + " " + B);
        } else if(A+B > K){
            System.out.println(0+" "+(A+B-K));
        } else {
            System.out.println(0+" "+0);
        }
    }
}


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

int main () {
  int N;
  cin >> N;
  map<string,int> poll;
  int max = 0;
  for(int i=0; i<N; i++) {
    string a;
    cin >> a;
    poll[a]++;
    if(poll[a] > max) max = poll[a];
  }
  for(auto x : poll) {
    if(x.second == max) {
      cout << x.first << endl;
    }
  }
}



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

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

int q;

deque< char > d;

int main()
{
	string s;
	cin >> s >> q;

	while( !s.empty() )
	{
		d.push_front( s.back() );
		s.pop_back();
	}

	bool isReversed = false;

	for(int i = 1 ; i <= q ; i++)
	{
		int type;
		cin >> type;

		if( type == 1 ) isReversed = !isReversed;
		else 
		{
			int t;
			char c;
			cin >> t >> c;

			t--;

			bool aux = isReversed^t;

			if( !aux ) d.push_front( c );
			else d.push_back( c );
		}
	}

	while( !d.empty() )
	{
		if( isReversed )
		{
			printf("%c",d.back());
			d.pop_back();
		}
		else
		{
			printf("%c",d.front());
			d.pop_front();
		}
	}
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(ll &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
ll a[4],n,res=6e18;
ll solve(ll n, int S){
	ll res=0;
	if(S>>3&1)res+=n/8*a[3],n%=8;
	if(S>>2&1)res+=n/4*a[2],n%=4;
	if(S>>1&1)res+=n/2*a[1],n%=2;
	if(S>>0&1)res+=n/1*a[0],n%=1;
	return !n?res:6e18;
}
int main() {
	rep(i,0,3)read(a[i]);rep(i,1,3)a[i]=min(a[i],a[i-1]*2);
	read(n);cout<<n/2*a[3]+n%2*a[2];return 0;
	n*=4;
//	rep(i,1,15)res=min(res,solve(n,i));
	cout<<solve(n,15);
	return 0;
}


Measured memory_bytes: 256
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize,
        xa: [i64; n],
    }

    let answer = xa.windows(k)
        .map(|x| {
            let first = *x.first().unwrap();
            let last = *x.last().unwrap();

            if last <= 0 {
                first.abs()
            } else if first >= 0 {
                last
            } else if first.abs() > last {
                first.abs() + last * 2
            } else {
                first.abs() * 2 + last
            }
        })
        .min()
        .unwrap();

    println!("{}", answer);
}


Measured memory_bytes: 4352
#include <stdio.h>

int main ()
{
	char a,b;
	scanf("%c %c",&a,&b);
	getchar();
	if(a=='H'&&b=='H')
	{
		printf("H\n");
	}
	else if(a=='D'&&b=='H')
	{
		printf("D\n");
	}
	else if(a=='H'&&b=='D')
	{
		printf("D\n");
	}
	else if(a=='D'&&b=='D')
	{
		printf("H\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b; cin >> a >> b;
  if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define io ios_base::sync_with_stdio(0);cin.tie(0);
#define mod 1000000007
#define pi 2*acos(0)
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
using namespace std;



int main()
{

	io;
	
	int n; cin >> n;
	int cnt = 0;

	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		if (x == y) {
			cnt++;
			if (cnt == 3) {
				cout << "Yes";
				return 0;
			}
		}
		else
			cnt = 0;
	}
	
	cout << "No";

}



Measured memory_bytes: 3616
def invpol(f):
    s = []
    for c in f:
        if c == '+':
            a = s.pop()
            s.append(s.pop() + a)
        elif c == '-':
            a = s.pop()
            s.append(s.pop() - a)
        elif c == '*':
            a = s.pop()
            s.append(s.pop() * a)
        elif c == '/':
            a = s.pop()
            s.append(s.pop() / a)
        else:
            s.append(int(c))
    return(s[0])

while True:
    try:
        f = input().strip().split()
        print("%.6f" % invpol(f))

    except EOFError:
        break

Measured memory_bytes: 7744
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict               as M
import           Data.Char
import Data.Bits

modN = 1000000007


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

pow :: Int -> Int -> Int -> Int
pow base 1 modNum = base `mod` modNum
pow base time modNum
    | odd time = let 
        a = pow base (time `div` 2) modNum `mod` modNum
        in
        a * a * base `mod` modNum
    | otherwise = let
        a = pow base (time `div` 2) modNum `mod` modNum
        in
        a * a `mod` modNum



main = do
    (n, _) <- readTuple2
    as <- readInts
    let t = sum as
    print $ max (negate 1) (n - t)






Measured memory_bytes: 4848
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define NIL -2000000001
#define MAX 2000000000000

int main() {
  int n;
  scanf("%d", &n);
  long long A[n];
  for (int i=0; i<n; i++) {
    scanf("%lld", &A[i]);
  }
  for (int i=0; i<n; i++) {
    A[i] -= i+1;
  }
  sort(A, A + n);

  long long b;
  long long min=0;


  b = A[n/2];
  for (int j=0; j<n; j++) {
    if (A[j] > b) {
      min += A[j]-b;
    } else {
      min += b-A[j];
    }
  }

  printf("%lld\n", min);

  return 0;
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e5 + 1;
int a[N], n;

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.precision(10);
   cout << fixed;
   
   cin >> n;
   deque<int> dq1, dq2;
   ll s1 = 0, s2 = 0;


   for (int i = 0; i < n; ++i){
      cin >> a[i];
      dq1.push_back(a[i]);
      dq2.push_back(a[i]);
   }
   sort(dq1.begin(), dq1.end());
   sort(dq2.begin(), dq2.end(), greater<int>());

   a[n / 2] = dq1.front();
   dq1.pop_front();
   int i1 = n / 2 - 1, i2 = n / 2 + 1;
   bool f = 0;
   while (i1 >= 0)
   {
      f ^= 1;
      if (f){
         a[i1] = dq1.back();
         dq1.pop_back();
         a[i2] = dq1.back();
         dq1.pop_back();
      }
      else {
         a[i1] = dq1.front();
         dq1.pop_front();
         a[i2] = dq1.front();
         dq1.pop_front();
      }
      --i1;
      ++i2;
   }
   if (n % 2)
      a[i2] = dq1.front();
   dq1.pop_front();

   for (int i = 0; i < n - 1; ++i)
      s1 += abs(a[i + 1] - a[i]);

   a[n / 2] = dq2.front();
   dq2.pop_front();
   i1 = n / 2 - 1, i2 = n / 2 + 1;
   f = 0;
   while (i1 >= 0)
   {
      f ^= 1;
      if (f){
         a[i1] = dq2.back();
         dq2.pop_back();
         a[i2] = dq2.back();
         dq2.pop_back();
      }
      else {
         a[i1] = dq2.front();
         dq2.pop_front();
         a[i2] = dq2.front();
         dq2.pop_front();
      }
      --i1;
      ++i2;
   }
   if (n % 2)
      a[i2] = dq2.front();
   dq1.pop_front();

   for (int i = 0; i < n - 1; ++i)
      s2 += abs(a[i + 1] - a[i]);
   
   cout << max(s1, s2) << '\n';

   return 0;
}

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

int main() {
  int h, n, a, sum=0;
  cin >> h >> n;
  REP(i,n) { cin >> a; sum += a; }
  if (h - sum > 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
N = gets.to_i
abc = N.times.map{gets.split.map(&:to_i)}

dp = Array.new(N+1){Array.new(3, 0)}
N.times do |i|
    3.times do |j|
        3.times do |k|
            if j != k
                result = dp[i][j] + abc[i][k]
                dp[i+1][k] = result if dp[i+1][k] < result
            end
        end
    end
end

puts dp[N].max

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

int main(){
    int N;
    int A_list[100002] = {0};
    long long sum = 0;
    cin >> N;
    for(int i=1; i<N+1; i++){
        cin >> A_list[i];
    }
    for(int i=0; i<N+1; i++){
        sum += abs(A_list[i+1]-A_list[i]);
    }
    for(int i=1; i<N+1; i++){
        cout << sum - abs(A_list[i]-A_list[i-1]) - abs(A_list[i+1]-A_list[i]) + abs(A_list[i+1]-A_list[i-1]) << endl;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        System.out.println(s.nextInt()-s.nextInt()+1);


    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

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

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

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25372
#include<stdio.h>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
set<long long>k;
vector<long long>t;
int main()
{
    long long a,h,siz,p,q;
    scanf("%lld",&a);
    for(long long i=0;i<a;i++)
    {
        siz=k.size();
        scanf("%lld",&h);
        k.insert(h);
        if(k.size()==siz)
        {
            t.push_back(h);
        }
    }
    sort(t.begin(),t.end());
    p=count(t.begin(),t.end(),t[t.size()-1]);
    if(p>=3)
    {
    printf("%lld",t[t.size()-1]*t[t.size()-1]);
    }
    else if(t.size()>=2)
    {
    printf("%lld",t[t.size()-1]*(t[t.size()-p-1]));
    }
    else printf("0");
    return 0;
}



Measured memory_bytes: 4992
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
		int N = sc.nextInt();
		int[] numP = new int[N+1];
		int[] numQ = new int[N+1];
		int ans1 = 0,ans2 = 0;
		int[] ff = new int[]{0,1,2,6,24,120,720,5040};
		for( int i=N; i>=1; i-- ){
			numP[i] = sc.nextInt();
		}
		for( int i=N; i>=1; i-- ){
			numQ[i] = sc.nextInt();
		}
		for( int i=N; i>=1; i-- ){
			int count1 = 0,count2 = 0;
			for( int j=N; j>=i; j-- ){
				if( numP[i] > numP[j] ){
					count1++;
				}
				if( numQ[i] > numQ[j] ){
					count2++;
				}
			}
			ans1 += (numP[i]-1-count1)*ff[i-1];
			ans2 += (numQ[i]-1-count2)*ff[i-1];
		}
		System.out.println(Math.abs(ans1-ans2));
	}
}

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

#define PII pair < int , int >
const int dir[4][2] = {0,1,0,-1,1,0,-1,0};
queue < PII > q; int N , M , dist[1003][1003];

int main(){
	cin >> N >> M; memset(dist , -1 , sizeof(dist));
	for(int i = 1 ; i <= N ; ++i)
		for(int j = 1 ; j <= M ; ++j){
			char c; cin >> c;
			if(c == '#'){dist[i][j] = 0; q.push(PII(i , j));}
		}
	int mx = 0;
	while(!q.empty()){
		PII t = q.front(); q.pop();
		for(int i = 0 ; i < 4 ; ++i){
			int x = t.first + dir[i][0] , y = t.second + dir[i][1];
			if(x && x <= N && y && y <= M && dist[x][y] == -1){
				mx = max(mx , dist[x][y] = dist[t.first][t.second] + 1);
				q.push(PII(x , y));
			}
		}
	}
	cout << mx; return 0;
}

Measured memory_bytes: 12304
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma comment(linker, "/STACK:16777216")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cassert>
#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(), (x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(), v.end());
#define mx(a) max_element(a.begin(), a.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (ll i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (ll i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for (ll i = 0; i < n; ++i){ll a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<vector<char> > fd;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1e18;
const ll inf = 1e9;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const ll MAXN = 200001;
const ld EPS = 1e-7;
signed main()
{
	fastio();
	int n;
	cin >> n;
	if (n & 1)
	{
		cout << "Hello World";
	}
	else
	{
		int a, b;
		cin >> a >> b;
		cout << a + b;
	}
	sp;
}


Measured memory_bytes: 504
#include <iostream>

using namespace std;

int main()
{
    int j,N;
    char s[1000],t[1000],T[1000];
    cin>>N>>s>>t;
    j=0;
    for(int i=0; i<N; i++)
    {
        T[j++]=s[i];
        T[j++]=t[i];
    }
    for(int i=0; i<2*N; i++)
        cout<<T[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define loop(a,b) for(ll i=a;i<b;i++)
#define iloop(a,b) for(int i=a;i<b;i++)
#define it(c) for(auto it=c.begin();it!=c.end();it++)
#define MOD 1000000007

using namespace std;

void Thai_Jase() {
    string s;
    cin>>s;
    ll sum=0;
    loop(0,s.size()) {
        sum+=(s[i]-'0');
    }
    if(sum%9==0) cout << "Yes";
    else cout << "No";
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int ts=1;
    while(ts--) {
      Thai_Jase();
    }
    return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include<math.h>
using namespace std;
 
int main() 
{
    int n, m;
    cin >> n >> m;
    int a[100][100], b[100];
    for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
    for(int j = 0; j < m; j++)
	{
        cin  >> b[j];
    }
    for(int i = 0; i < n; i++)
	{
        int c = 0;
        for(int j = 0; j < m; j++) c += a[i][j] * b[j];
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 3120
def main():
    N, M = map(int, input().split())
    maxM = M//N + 1
    for m in range(maxM, 0, -1):
        tmp = m * N
        remain = M - tmp
        check = remain % m
        if check == 0 and remain >= 0:
            print(m)
            return

if __name__ == "__main__":
    main()


Measured memory_bytes: 62964
import java.util.Scanner;
import java.util.StringJoiner;

class Card {
	char mark;
	int num;
	
	@Override
	public String toString() {
		return "" + this.mark + this.num;
	}

	public boolean equals(Card o) {
		return this.mark == o.mark && this.num == o.num;
	}
	
}

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		sc.nextLine();
		
		String[] inputs = sc.nextLine().split(" ");
		Card[] cards = new Card[n];
		for (int i = 0; i < n; i++) {
			Card card = new Card();
			
			card.mark = inputs[i].charAt(0);
			card.num = inputs[i].charAt(1) - '0';
			
			cards[i] = card;
		}		
		sc.close();
		
		Card[] sortedB = bubbleSort(cards.clone(), n);
		show(sortedB, " ");
		System.out.println("Stable");
		
		Card[] sortedS = selectionSort(cards.clone(), n);
		show(sortedS, " ");
		
		boolean stable = true;
		for(int i = 0; i < n; i++) {
			if(!sortedB[i].equals(sortedS[i])){
				stable = false;
				break;
			}
		}
		if(stable) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}

	}

	private static Card[] bubbleSort(Card[] cards, int n) {

		for (int i = 0; i < n; i++) {
			for (int j = n-1; j > i; j--) {
				if(cards[j].num < cards[j-1].num) {
					Card wk = cards[j];
					cards[j] = cards[j-1];
					cards[j-1] = wk;
				}
			}

		}
		return cards;
	}

	private static Card[] selectionSort(Card[] cards, int n) {

		for (int i = 0; i < n; i++) {
			int minj = i;
			for (int j = i; j < n; j++) {
				if(cards[j].num < cards[minj].num) minj = j;
			}
			
			if(minj != i) {
				Card wk = cards[i];
				cards[i] = cards[minj];
				cards[minj] = wk;
			}
		}
		return cards;
	}

	private static void show(Card[] a, String joiner) {

		StringJoiner sj = new StringJoiner(joiner);
		
		for (Card card : a) {
			sj.add(card.toString());
		}
		System.out.println(sj.toString());
	}
}

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

namespace Volume20_2006
{
    class Program
    {
        static void Main(string[] args)
        {
            Enumerable
                .Range(0, Convert.ToInt32(Console.ReadLine()))
                .Select(cnt => Console.ReadLine().Split('0'))
                .Select(s_ary => s_ary.Where(s => s != "").ToArray())
                .Select(s_ary => s_ary.Select(s => Decode(s.First().ToString(), s.Length)))
                .Select(s_ary => s_ary.Aggregate((all, next) => all += next))
                .ToList()
                .ForEach(output => Console.WriteLine(output));
        }
        public static string Decode(string key, int count)
        {
            int len = 0;
            int ch = 0;
            switch(key)
            {
                case "1":             len = 5; break;
                case "2":   ch = 'a'; len = 3; break;
                case "3":   ch = 'd'; len = 3; break;
                case "4":   ch = 'g'; len = 3; break;
                case "5":   ch = 'j'; len = 3; break;
                case "6":   ch = 'm'; len = 3; break;
                case "7":   ch = 'p'; len = 4; break;
                case "8":   ch = 't'; len = 3; break;
                case "9":   ch = 'w'; len = 4; break;
                default: return null;
            }
            if(key == "1")
            {
               switch( (count - 1) % len)
                {
                    case 0: return ".";
                    case 1: return ",";
                    case 2: return "!";
                    case 3: return "?";
                    case 4: return " ";
                }
            }
            return Convert.ToChar( ch + ( (count - 1) % len) ).ToString();
        }
    }
}

Measured memory_bytes: 9848
/************************************************************
/  AUTHOR :  DEVANSHU SINGLA                                /
/  NICK :  DSINGLA                                          /
/  INSTITUTE :  IITK                                        /
************************************************************/
//                     TEMPLATE                            //

#include <bits/stdc++.h>
#define ll long long
#define N 100005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define F first
#define S second
#define MAX(x, y) (x) > (y) ? (x) : (y)
#define MIN(x, y) (x) < (y) ? (x) : (y)

// use cin.ignore() after cin statement.
using namespace std ;

void solve(){
    long n;
    cin>>n;
    long h[n];
    for(long i=0; i<n; i++){
        cin>>h[i];
    }
    ll p[n];
    p[0] = 0;
    p[1] = abs(h[1] - h[0]);
    for(long i=2;i<n; i++){
        p[i] = MIN(p[i-1] + abs(h[i] - h[i-1]), p[i-2] + abs(h[i] - h[i-2]));
    }
    cout<<p[n-1];
}

int main(){
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;

    solve();
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
#define MAX 2000000000
#define PI 3.1415926535897932
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  int N,T; cin>>N>>T;
  int res = 1001;
  rep(i,N){
    int c,t;cin>>c>>t;
    if(t<=T){
      res = min(res,c);
    }
  }
  if(res==1001)cout<<"TLE"<<endl;
  else cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (n-1)/m  + 1 ;
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 2e5 + 5 , inf = 1e13;

signed main(){
	int  l , r ;
	cin >> l >> r ;
	if( r - l + 1 > 2019 ) cout <<"0\n" ;
	else{
		int ans = LLONG_MAX ;
		for ( int i = l ; i<=r ; i++){
			for ( int j = i+1 ; j<=r ; j++ ){
				ans = min ( ans , (i*j)%2019) ;
			}
		}
		cout << ans  << endl ;
	}
}

Measured memory_bytes: 256
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]
import math

def main():
    n = II()
    print(2*n*math.pi)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
#include<iostream>
#include<vector>

int main(void){
    int r,c;
    std::cin>>r>>c;
    std::vector<std::vector<int>> data(r,std::vector<int>(c,0));
    int i,j;
    for(i=0;i<r;i++){
        int sum=0;
        for(j=0;j<c;j++){
            std::cin>>data[i][j];
            sum+=data[i][j];
        }
        data[i].push_back(sum);
    }
    for(i=0;i<r;i++){
        for(j=0;j<c+1;j++){
            std::cout<<data[i][j];
            if(j!=c)std::cout<<" ";
        }
        std::cout<<std::endl;
    }
    for(i=0;i<c+1;i++){
        int sum=0;
        for(j=0;j<r;j++){
            sum+=data[j][i];
        }
        std::cout<<sum;
        if(i!=c)std::cout<<" ";
    }
    std::cout<<std::endl;
    return 0;
}

Measured memory_bytes: 3216
/*

  _    _ _      _ _      _ _     _____ ____________ 
 | |__| | | _ _| | | _ _| | | __|__ / |__ /__ /__  |
 | '_ \_  _| ' \_  _| ' \_  _(_-<|_ \ ||_ \|_ \ / / 
 |_.__/ |_||_||_||_||_||_||_|/__/___/_|___/___//_/  

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define db1(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << '\n'
#define rep(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(x) scanf("%s", x)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(x) printf("%s\n", x)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define F first
#define S second
#define pb push_back
#define ll long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

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

int mpow(int base, int exp);
void ipgraph(int n,int m);
int dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N, OO = 1e9 + 7;
const ll LLOO = 1e18 + 7;
//=======================

vi g[N];
int a[N],n,m;
bool vis[N];
void solve()
{
    si(n);
    si(m);
    ipgraph(n,m);
    
    int ans = 1;
    
    rep(i,0,n)
    {
		int sz = dfs(i,-1);
		ans = max(ans,sz);
	}
	pi(ans);
}

int main()
{
    // uncomment if file :
    // freopen("in","r",stdin);
    // freopen("out","w",stdout);
    int t = 1;
    // si(t); // uncomment if testcases
    while (t--)
        solve();
    return 0;
}

int mpow(int base, int exp)
{
    base %= mod;
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m)
{
    int u, v;
    while (m--)
    {
        scanf("%d %d", &u, &v);
        g[u - 1].pb(v - 1);
        g[v - 1].pb(u - 1);
    }
}

int dfs(int u, int par)
{
	if (vis[u]) return 0;
	vis[u] = 1;
	int sz = 1;
    for (int v : g[u])
    {
        if (v == par)
            continue;
        sz += dfs(v, u);
    }
    return sz;
}


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

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

int main()
{
  string s;
  cin >> s;
  int ans1 = -1, ans2 = -1;
  rep(i, s.length() - 2)
    {
      if(s[i] == s[i+1])
	{
	  ans1 = i+1;
	  ans2 = i+2;
	}
      if(s[i] == s[i+2])
	{
	  ans1 = i+1;
	  ans2 = i+3;
	}
      if(s[i+1] == s[i+2])
	{
	  ans1 = i+2;
	  ans2 = i+3;
	}
    }
  rep(i, s.length()-1)
    {
      if(s[i] == s[i+1])
	{
	  ans1 = i+1;
	  ans2 = i+2;
	}
    }
  cout << ans1 << " " << ans2 << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int era[102000];
void initEra(){
    for(int i = 2; i < 102000; i++)era[i] = 1;
    for(int i = 2; i * i < 102000; i++){
        if(era[i] == 0)continue;
        for(int j = i + i; j < 102000; j += i)era[j] = 0;
    }
}

int main(){
    initEra();
    vector<int>prime;
    for(int i = 0; i < 102000; i++){
        if(era[i])prime.push_back(i);
    }
    
    for(int n, p; cin >> n >> p;){
        if(n < 0)break;
        vector<int>A;
        for(int i = 0; A.size() < p; i++){
            if(prime[i] > n)A.push_back(prime[i]);
        }
        vector<int>B;
        for(int i = 0; i < A.size(); i++){
            for(int j = i; j < A.size(); j++){
                B.push_back(A[i] + A[j]);
            }
        }
        sort(B.begin(), B.end());
        cout << B[p - 1] << endl;
        // for(int i = 0; i < 10; i++)cout << "#" << B[i] << endl; 
        // break;
    }

    return 0;
}


Measured memory_bytes: 3620
H, W = map(int, input().split(' '))
board = [input() for _ in range(H)]
dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]
ans = 'Yes'
for i in range(H):
    for j in range(W):
        if (board[i][j] == '#'):
            isFound = False
            for d in range(len(dx)):
                x = i + dx[d]
                y = j + dy[d]
                if (x < 0 or H <= x):
                    continue
                if (y < 0 or W <= y):
                    continue
                if (board[x][y] == '#'):
                    isFound = True
            if (isFound is False):
                ans = 'No'
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
    a=0;char x=getchar();bool f=0;
    for(;x<'0'||x>'9';x=getchar())f|=x=='-';
	for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
    if(f)a=-a;
    return a;
}
using namespace std;


int d[500];

int main() {
	int ans = 0, n;
	read(n);
	n *= 2;
	for (int i = 1; i <= n; ++i) {
		read(d[i]);
	}
	sort(d + 1, d + n + 1);
	for (int i = 1; i <= n; i += 2) {
		ans += d[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
/*
    ThunderClap and Flash
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod) + (b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod) * (b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod) - (b%mod) + mod)%mod;}

void Flash(){
    ll a;
    cin>>a;
    ll ans = (a + (a * a) + (a * a * a));
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){ 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    ThunderClap;
    ll t = 1;
    //cin>>t;
    for(ll i = 1; i <= t; i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}


Measured memory_bytes: 3580
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
_max = 0
for i in range(n):
    s = 0
    for j in range(i+1):
        s += a[j]
    for j in range(n-i):
        s += b[j+i]
    if(s > _max):
        _max = s
print(_max)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	REP(i, N) scanf("%lld", A.begin() + i);
	
	vector<ll> po, ne;
	ll ze = 0;
	REP(i, N) {
		if (A[i] > 0) po.push_back(A[i]);
		else if (A[i] < 0) ne.push_back(-A[i]);
		else ++ze;
	}
	sort(ALL(po));
	sort(ALL(ne));
	
	ll l = -longINF, r = longINF;
	while (r - l > 1) {
		ll m = (l + r) / 2;
		// m以下の個数
		
		ll cnt = 0;
		
		if (m >= 0) {
			REP(i, po.size()) {
				cnt += upper_bound(ALL(po), m / po[i]) - po.begin();
				if (po[i] * po[i] <= m) --cnt;
			}
			REP(i, ne.size()) {
				cnt += upper_bound(ALL(ne), m / ne[i]) - ne.begin();
				if (ne[i] * ne[i] <= m) --cnt;
			}
			cnt /= 2;
			
			cnt += (ll)po.size() * ne.size();
			cnt += ze * (ne.size() + po.size());
			cnt += ze * (ze - 1) / 2;
		}
		else {
			REP(i, ne.size()) cnt += po.end() - lower_bound(ALL(po), (-m + ne[i] - 1) / ne[i]);
		}
		if (cnt >= K) r = m;
		else l = m;
	}
	
	cout << r << endl;
	
	return 0;
}


Measured memory_bytes: 3956