akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  char c; cin >> c;
  ++c;
  cout << c << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        boolean[][] cl = new boolean[h+2][w+2];
        boolean ans = true;
        String res;
        String str;
        char c;
        for(int i=1; i<h+1; i++){
            str = sc.next();
            for(int j=1; j<w+1; j++){
                c = str.charAt(j-1);
                if(c == '.') cl[i][j] = true;
                else         cl[i][j] = false;
            }
        }
        for(int i=1; i<h+1; i++){
            cl[i][0]  = true;
            cl[i][w+1] = true;
        }
        for(int i=1; i<w+1; i++){
            cl[0][i]  = true;
            cl[h+1][i] = true;
        }
        for(int i=1; i<h+1; i++){
            for(int j=1; j<w+1; j++){
                if(cl[i][j] == false && cl[i-1][j]==true && cl[i][j-1]==true 
                                     && cl[i+1][j]==true && cl[i][j+1]==true){
                    ans = false;
                }
            }
        }
        if(ans == true) res = "Yes";
        else            res = "No";
        System.out.println(res);
    }
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	string s; cin >> s;
	int n = s.size();
	int ans = 1e9;
	for(int i = 0; i <= n - 3; i++) {
		string tmp;
		tmp += s[i];
		tmp += s[i + 1];
		tmp += s[i + 2];
		int t = stoi(tmp);
		int dif = abs(753 - t);
		ans = min(ans, dif);
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
typedef long long LL;

int main()
{
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	int vx = x2-x1;
	int vy = y2-y1;

	int vvx = -vy;
	int vvy = vx;

	int x3 = x2 + vvx;
	int y3 = y2 + vvy;

	int vvvx = -vvy;
	int vvvy = vvx;

	int x4 = x3 + vvvx;
	int y4 = y3 + vvvy;

	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}




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

int main()
{
int n;
  cin >> n;
  if(n >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s, t;
    cin >> s >> t;
    sort(ALL(s));
    sort(ALL(t));
    reverse(ALL(t));
    cout << (s < t ? "Yes" : "No") << endl;
    return 0;
}





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

int main() {
    int a, b;
    char op;
    cin >> a >> op >> b;
    while (true) {
        switch (op)
        {
        case '+':
            cout << a + b << endl;
            break;
        case '-':
            cout << a - b << endl;
            break;
        case '*':
            cout << a * b << endl;
            break;
        case '/':
            cout << a / b << endl;
            break;
        case '?':
            return 0;
        }
        cin >> a >> op >> b;
    }
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main(){
	int n,d;
	cin>>n>>d;

	int ans=1;
	while(n>ans+2*d*ans){
		ans++;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<string>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
const ll mod=1e9+7;

bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}


void solve(){

    double l;
    cin>>l;

    cout<<setprecision(13)<< (l*l*l)/27;

    return;
}
int main()
{
    IOS;
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }
 
    return 0;
}       

Measured memory_bytes: 256
class UnionFind(val n: Int) {

    private var par: IntArray
    private var sz: IntArray
    private var rank: IntArray

    init {
        par = IntArray(n, { it })
        sz = IntArray(n, { 1 })
        rank = IntArray(n, { 0 })
    }

    fun find(x: Int): Int {
        if(par[x] == x) return x
        else {
            par[x] = find(par[x])
            return par[x]
        }
    }

    fun unite(x: Int, y: Int) {
        val xp = find(x)
        val yp = find(y)
        if(xp == yp) return
        if(rank[xp] < rank[yp]) {
            par[xp] = yp
            sz[yp] += sz[xp]
        }
        else {
            par[yp] = xp
            sz[xp] += sz[yp]
            if(rank[xp] == rank[yp])rank[xp]++
        }
    }

    fun same(x: Int, y: Int) = find(x) == find(y)
    fun size(a: Int) = sz[find(a)]
}

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map{ it.toInt() }
    val v = Array(m, {Pair(0, 0)})

    for(i in 0 until m){
        var (a, b) = readLine()!!.split(" " ).map{ it.toInt() }
        a--
        b--
        v[i] = Pair(a, b)
    }


    val uf = UnionFind(n)
    val ans = LongArray(m)
    var now = 0L
    for(i in m - 1 downTo 0) {
        val (a, b) = v[i]
        ans[i] = now
        if(!uf.same(a, b)){
            now += uf.size(a).toLong() * uf.size(b).toLong()
            uf.unite(a, b)
        }
    }

    for(i in 0 until m){
        println(n.toLong() * (n.toLong() - 1L) / 2 - ans[i])
    }
}

Measured memory_bytes: 78884
#!/opt/local/bin/python3

# AtCoder Beginner Contest 084
# D: 2017-like Number

import sys, math
from itertools import accumulate

MAX_N = 100000

def sieve():
  isprime = [i >= 2 for i in range(MAX_N + 1)]
  for p in range(2, MAX_N + 1):
    if isprime[p]:
      for q in range(p + p, MAX_N + 1, p):
        isprime[q] = False
  return isprime

def isPrime(n):
  isPrime._ = isPrime._ or sieve()
  return isPrime._[n]
isPrime._ = None

def is2017like(n):
  return isPrime(n) and isPrime((n + 1) // 2)

# the number of 2017-like numbers less than or equal to n.
def n2017likeUnder(n):
  if n2017likeUnder._ == None:
    lis = [1 if is2017like(i) else 0 for i in range(MAX_N + 1)]
    n2017likeUnder._ = list(accumulate(lis))
  return n2017likeUnder._[n]
n2017likeUnder._ = None

# the number of 2017-like numbers between l and r.
def solve(l, r):
  return n2017likeUnder(r) - n2017likeUnder(l - 1)

Q = int(sys.stdin.readline())
for i in range(Q):
  l, r = [int(w) for w in sys.stdin.readline().split()]
  print(solve(l, r))


Measured memory_bytes: 7752
#include <bits/stdc++.h>
using namespace std;
int d,n,q,i,ptr,a[1<<18],x; long long ret;
main(){
	while(cin>>d>>n>>q){
		for(i=1;i<n;i++)cin>>a[i],a[i+n]=a[i]+d;ret=a[n]=d;
		sort(a,a+2*n);
		while(q--){
			cin>>x;
			ptr=lower_bound(a,a+n,x)-a;
			ret+=min(a[ptr]-x,x-a[ptr+n-1]+d);
		}
		cout<<ret-d<<endl;
	}
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

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

	int n, t;
	cin >> n >> t;

	vector<pll> v(n);
	rep(i, n) cin >> v[i].first >> v[i].second;

	sort(v.begin(), v.end());

	vector<ll> mxs(n+1, 0);
	for(int i = n - 1; i >= 0; i--){
		mxs[i] = max(mxs[i+1], v[i].second);
	}

	ll dp[n+1][t+1];
	rep(i, n+1) rep(j, t+1) dp[i][j] = -1;
	dp[0][0] = 0;

	rep(i, n){
		rep(j, t+1){
			dp[i+1][j] = dp[i][j];
			if(j - v[i].first >= 0 && dp[i][j - v[i].first] >= 0){
				// cout << i << ","  << j << ":" << dp[i][j] << " " << dp[i][j - v[i].first] + v[i].second << endl;
				dp[i+1][j] = max(dp[i][j], dp[i][j - v[i].first] + v[i].second);
			}
		}
	}

	ll ans = 0;
	rep(i, n){
		rep(j, t){
			ans = max(ans, dp[i+1][j] + mxs[i+1]);
		}
	}

	ans = max(ans, dp[n][t]);
	cout << ans << endl;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  string s;
  cin>>n>>s;
  int op=0,mi=0;
  for(int i=0;i<(int)s.size();i++){
    if(s[i]=='(') op++;
    else op--;
    mi=min(mi,op);
  }
  for(int i=0;i<-mi;i++) s='('+s,op++;
  for(int i=0;i<op;i++) s+=')';
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Measured memory_bytes: 13876
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = 0;
		int prev = 0;
		int count = 0;
		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			if (prev >= b) {
				count++;
				max = Math.max(count, max);
			} else {
				count = 0;
			}
			prev = b;
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 47556
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a = [int(item) for item in input().split()]
cuma = [0]
for item in a:
    cuma.append(cuma[-1] + item)
b = []
for i in range(n):
    for j in range(i + 1, n+1):
        b.append(cuma[j] - cuma[i])
ans = 0
for i in range(41, -1, -1):
    subset = []
    for item in b:
        if item & 1 << i: 
            subset.append(item)
    if len(subset) >= k:
        ans |= 1 << i
        b = subset[:]
print(ans)

Measured memory_bytes: 66300
import sys


def main():
    h_and_n_s = sys.stdin.readline().strip().split(' ')
    h, n = [int(s) for s in h_and_n_s]
    a = [int(s) for s in sys.stdin.readline().strip().split(' ')]

    if sum(a) >= h:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 13964
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)
int main(){
    string s;
    cin >> s;
    
    RAP(i, s.size()){
        s[i] = 'x';
    }
    
    cout << s << endl;
    return 0;
 
}


Measured memory_bytes: 256
from bisect import bisect_left
s = input()
t = input()
pos = {}
for i, c in enumerate(s):
    if c not in pos:
        pos[c] = [i]
    else:
        pos[c].append(i)
ans = 0
pre = -1
for c in t:
    if c not in pos:
        print(-1)
        exit()
    l = bisect_left(pos[c], pre+1)
    if l >= len(pos[c]):
        p = pos[c][0]
        ans += len(s)
    else:
        p = pos[c][l]
    ans += p - pre
    # print(c, l, pre)
    pre = p

print(ans)

Measured memory_bytes: 7796
import math
N, M = list(map(int, input().strip().split(' ')))
k = abs(N-M)
if k > 1:
  print(0)
elif k == 1:
  ans = (math.factorial(N)*math.factorial(M))%(10**9+7)
  print(ans)
elif k == 0:
  ans = (math.factorial(N)*math.factorial(M)*2)%(10**9+7)
  print(ans)

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

int main(){
    string s; cin >> s;
    string ans;
    rep(i,s.size()){
        if(s[i] == '1' || s[i] == '0'){
            ans.push_back(s[i]);
        }else if(s[i] =  'B' && ans.size() > 0){
            ans.pop_back();
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dp[100001];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	dp[0] = 1;
	for(int i=1; i<=n; i++) {
		for(int t=100; t<=105; t++) {
			if(i-t>=0 && dp[i-t] == 1) {
				dp[i] = 1;
				break;
			}
		}
	}
	cout << dp[n];
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359

int main(void)
{
	int q,a,b;
	string str,cmd,p;

	cin >> str >> q;
	rep(i, q) {
		cin >> cmd >> a >> b;
		if (cmd == "print") {
			cout << str.substr(a, b - a + 1) << endl;
		}
		else if (cmd == "reverse") {
			string tmp="";
			for (int j = b;j >= a;--j)
				tmp += str.at(j);
				str.replace(a, tmp.size(), tmp);
		}
		else if (cmd == "replace") {
			cin >> p;
			str.replace(a, p.size(), p);
		}
	}
}



Measured memory_bytes: 3208
from collections import deque

h, w = list(map(int, input().split()))

s = [input() for _ in range(h)]

c = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            c += 1

#DFS
q = deque([[0, 0]])
dist = [[10000] * w for _ in range(h)]
dist[0][0] = 0

flag = False

while len(q) > 0:
    i, j = q.popleft()
    if i == h-1 and j == w-1:
        break
    else:
        if i < h-1 and s[i+1][j] == "." and not dist[i+1][j] < 10000:
            q.append([i+1, j])
            dist[i+1][j] = dist[i][j] + 1
        if j < w-1 and s[i][j+1] == "." and not dist[i][j+1] < 10000:
            q.append([i, j+1])
            dist[i][j+1] = dist[i][j] + 1
        if i > 0 and s[i-1][j] == "." and not dist[i-1][j] < 10000:
            q.append([i-1, j])
            dist[i-1][j] = dist[i][j] + 1
        if j > 0 and s[i][j-1] == "." and not dist[i][j-1] < 10000:
            q.append([i, j-1])
            dist[i][j-1] = dist[i][j] + 1

if dist[h-1][w-1] < 10000:
    print(h * w - dist[h-1][w-1] - 1 - c)
else:
    print(-1)

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

int main() {
  int N;
  cin >> N;
  vector<int> diam(N);
  for(int i=0; i<N; i++)
    cin >> diam.at(i);
  
  vector<int> num(N, 0);
  int c=0;
  for(int i=0; i<N; i++){
    int match=0;
    for(int j=0; j<N; j++){
      if(diam.at(i)==num.at(j)){
        match=1;
        break;
      }
    }
    if(match==0){
      num.at(c)=diam.at(i);
      c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
import sys

n = int(input())
links = [set() for _ in [0] * n]
for line in sys.stdin:
	u, v, w = map(int, line.split())
	u -= 1
	v -= 1
	links[u].add((v, w))
	links[v].add((u, w))
ans = [-1] * n
q = [(0, 0, -1)]
while q:
	v, d, p = q.pop()
	if d % 2 == 0:
		ans[v] = 0
	else:
		ans[v] = 1
	for u, w in links[v]:
		if u == p:
			continue
		q.append((u, d + w, v))
print('\n'.join(map(str, ans)))


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

#define ll long long 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	ll x; cin >> x;
	ll y = x / 500;
	ll ans = y * 1000;
	x -= (y * 500);
	ans += (x / 5) * 5;
	cout << ans;
	return 0; 	
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        System.out.println(ret(line));
    }
    static String ret(String line){
        char c=line.charAt(0);
        c=(char)((int)c+1);
        return String.valueOf(c);
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>
int main(void)
{
	int a,len=0,i,j,k,l,cnt=0,cnt1,cnt2,X=0;
	char z[101],y[101][101];
	scanf("%d %s",&a,z);
	for(i=0;i<a;i++){
		scanf("%s",y[i]);
	}
	for(i=0;i<a;i++){
		len=strlen(y[i]);
		for(j=0;j<len;j++){
			for(k=0;k<len;k++){
				cnt1=j;
				cnt2=0;
					for(l=0;l<strlen(z);l++){
						if(y[i][cnt1]==z[l]){
							cnt2++;
						}
						cnt1+=k+1;
						if(cnt1>len) break;
					}
					if(cnt2==strlen(z)){
						cnt++;
						break;
					}
			}
			if(cnt>X){
				X++;
				break;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

signed main(void)
{
	int a, b, c;
	int ans;
	cin >> a >> b >> c;
	ans = b;
	if (c - b <= 0)
		ans += c;
	else
	{
		c -= b;
		ans += b;
		c--;
		ans++;
		if (c <= a)
			ans += c;
		else
			ans += a;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
	int res = a % MOD;
	if(res < 0) {
		return res + MOD;
	}
	return res;
}
int mul_mod(int a, int b)
{
	ll res = ((ll)a * (ll)b) % MOD;
	return mod((int)res);
}
int pow_mod(int a, int b)
{
	ll res = 1;
	while (b > 0) {
		if(b & 1) {
			res = res * (ll)a % (ll)MOD;
		}
		a = mul_mod(a, a);
		b >>= 1;
	}
	return (int)res;
}
int inv_mod(int a)
{
	return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
	return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 100000;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < FAC_MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll com_mod(int a, int b){
	if (a < b) return 0;
	if (a < 0 || b < 0) return 0;
	return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int dp[100001][13] = {1};
	rep (i, s.size()) {
		int digit = (int)(s[i] - '0');
		rep (j, 13) {
			if (s[i] == '?') {
				rep (k, 10) {
					dp[i + 1][(j * 10 + k) % 13] = mod(dp[i + 1][(j * 10 + k) % 13] + dp[i][j]);

				}
			} else {
				dp[i + 1][(j * 10 + digit) % 13] = mod(dp[i + 1][(j * 10 + digit) % 13] + dp[i][j]);
			}
		}
	}
	cout << dp[s.size()][5] << "\n";
	return 0;
}

Measured memory_bytes: 5584
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

total = 0
total += sum(B)
for i in range(N-1):
    if A[i] + 1 == A[i+1]:
        total += C[A[i]-1]
             
print(total)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = 302;
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll sum_digits(ll n)
{
	ll ret=0;
	while (n)
	{
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here



int main()
{
	IOS;
	ll n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	vector<int> ans(n);
	ans[0] = 0;
	ans[1] = v[0];
	int i = 2,j=1;
	while (i<n)
	{
		ans[i++] = v[j];
		if (i < n)
			ans[i++] = v[j++];
	}
	cout << accumulate(ans.begin(), ans.end(), 0LL) << endl;
	return 0;
}

Measured memory_bytes: 4784
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<long long, int> P;

long long a[100010], b[100010];
P c[100010];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		c[i] = P(a[i] + b[i], i);
	}
	sort(c, c + n);
	long long takahashi = 0, aoki = 0; 
	for (int i = n-1; i >=0; i--) {
		if ((n-1-i) % 2 == 0) {
			takahashi += a[c[i].second];
		}
		else {
			aoki += b[c[i].second];
		}
	}
	cout << takahashi - aoki << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { assert(x > 0); return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { assert(x > 0); return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
void fail() { puts("-1"); exit(0); }


V dx = {1, 0, -1, 0};
V dy = {0, 1, 0, -1};


int main() {
  int n; cin >> n;
  V p(n*n); cin >> p;

  VVbo vac(n, Vbo(n));
  VV d(n, V(n));
  rep(i, n) rep(j, n) d[i][j] = min({i, n-i-1, j, n-j-1});

  ll ans = 0;

  for (auto e : p) {
    --e;
    int si = e/n;
    int sj = e%n;
    queue<P> que;
    que.emplace(si, sj);
    ans += d[si][sj];
    vac[si][sj] = true;

    while (!que.empty()) {
      auto [i, j]  = que.front(); que.pop();
      rep(dir, sz(dx)) {
        int ii = i + dx[dir];
        int jj = j + dy[dir];
        if (ii < 0 || ii >= n || jj < 0 || jj >= n) continue;
        int dd = d[i][j] + 1 - vac[i][j];
        if (chmin(d[ii][jj], dd)) {
          que.emplace(ii, jj);
        }
      }
    }
  }

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


Measured memory_bytes: 5272
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		sa = br.readLine().split(" ");
		int[] a = new int[n * 3];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long sum1 = 0;
		PriorityQueue<Integer> que = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
			que.add(a[i]);
			sum1 += a[i];
		}

		TreeMap<Integer, Integer> map = new TreeMap<>();
		for (int i = n; i < a.length; i++) {
			addCntMap(map, a[i]);
		}
		long sum2 = 0;
		for (int i = 0; i < n; i++) {
			Integer min = map.firstKey();
			sum2 += min;
			delCntMap(map, min);
		}

		long ans = sum1 - sum2;
		for (int i = n; i < n * 2; i++) {
			que.add(a[i]);
			int min = que.poll();
			sum1 = sum1 + a[i] - min;

			if (map.containsKey(a[i])) {
				delCntMap(map, a[i]);
			} else {
				sum2 -= a[i];
				min = map.firstKey();
				sum2 += min;
				delCntMap(map, min);
			}
			ans = Math.max(ans, sum1 - sum2);
		}
		System.out.println(ans);
	}

	static void addCntMap(Map<Integer, Integer> map, Integer key) {
		if (map.containsKey(key)) {
			map.put(key, map.get(key) + 1);
		} else {
			map.put(key, 1);
		}
	}

	static void delCntMap(Map<Integer, Integer> map, Integer key) {
		if (key != null && map.containsKey(key)) {
			int val = map.get(key);
			if (val == 1) {
				map.remove(key);
			} else {
				map.put(key, val - 1);
			}
		}
	}
}


Measured memory_bytes: 87760
#include <iostream>

const int P = (int)1e9 + 7;
const int MAXN = (int)5e5 + 1;

int factorial[MAXN];
int comb[MAXN];       // comb[i] = C(n, i).

int64_t inv(int64_t x) {
  int64_t ans = 1, y = P - 2;
  while (y > 0) {
    if (y & 1) ans = ans * x % P;
    x = x * x % P;
    y >>= 1;
  }
  return ans;
}

void init(int n, int m) {
  factorial[0] = 1;
  for (int i = 1; i <= m; ++i) {
    factorial[i] = factorial[i - 1] * 1LL * i % P;
  }
  comb[0] = 1;
  for (int i = 1; i <= n; ++i) {
    comb[i] = comb[i - 1] * 1LL * (n - i + 1) % P * inv(i) % P;
  }
}

int64_t per(int x, int y) {
  return 1LL * factorial[x] * inv(factorial[x - y]) % P;
}

int solve(int n, int m) {
  init(n, m);
  int64_t ans = 0;
  int sign = 1;
  for (int i = 0; i <= n; ++i) {
    ans += sign * per(m - i, n - i) * comb[i];
    ans %= P;
    sign = sign == 1 ? -1 : 1;
  }
  ans = (ans + P) * per(m, n) % P;
  return ans;
}

int main() {
  int n, m;
  std::cin >> n >> m;
  std::cout << solve(n, m) << std::endl;
  return 0;
}



Measured memory_bytes: 7544
#include <bits/stdc++.h>
using namespace std;
using ll        = long long;
using ld        = long double;
using vl        = vector<ll>;
using vd        = vector<ld>;
using vs        = vector<string>;
using vb        = vector<bool>;
using vvl       = vector<vector<ll>>;
using vvd       = vector<vector<ld>>;
using vvs       = vector<vector<string>>;
using vvb       = vector<vector<bool>>;
using pll       = pair<ll, ll>;
constexpr ll mod= 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")

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

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    ll N,Q;
    cin >> N >> Q;
    vl knd(Q);
    vl x(Q);
    REP(i,Q)cin >> knd[i] >> x[i];
    REP(i,Q)x[i] = N-x[i]-1;
    vector<pll> l1(0);
    vector<pll> l2(0);
    l1.eb(mp(N-2,N-2));
    l2.eb(mp(N-2,N-2));
    ll ans = 0;
    REP(i,Q){
        if(knd[i] == 1){
            auto itr = lower_bound(ALL(l1),mp(x[i],(ll)0));
            if((*itr).fi == N-2){
                chmin(l2[l2.size()-1].se,N-2-x[i]-1);
                pll as = l1[l1.size()-1];
                ans += (*itr).se;
                l1.pop_back();
                l1.eb(mp(x[i],as.se));
                l1.eb(as);
            }else{
                ans += (*itr).se;
            }
        }else if(knd[i] == 2){
            auto itr = lower_bound(ALL(l2),mp(x[i],(ll)0));
            if((*itr).fi == N-2){
                chmin(l1[l1.size()-1].se,N-2-x[i]-1);
                ans += (*itr).se;
                pll as = l2[l2.size()-1];
                l2.pop_back();
                l2.eb(mp(x[i],as.se));
                l2.eb(as);
            }else{
                ans += (*itr).se;
            }
        }
    }
    cout << (N-2)*(N-2) - ans << "\n";
}

Measured memory_bytes: 9800
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <cassert>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }

int n;
int m;
int mod;
int cnk[310][310];
int res[310][310];
int res2[310][310];

int main () {
	scanf ("%d%d%d", &n, &m, &mod); n++; m--;
	for (int i = 0; i <= 301; i++)
		for (int j = 0; j <= i; j++)
			if (i == 0 || j % i == 0)
				cnk[i][j] = 1;
			else
				cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % mod;	
	res[0][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i; j++)
			for (int k = 1; k <= i; k++)
				res[i][j] = (res[i][j] + (ll)res[i - k][j - 1] * cnk[i - 1][k - 1]) % mod;
	for (int i = 1; i <= n; i++) res2[i][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			for (int k = 1; k <= i; k++)
				res2[i][j] = (res2[i][j] + (ll)res2[k][j - 1] * res[i][k]) % mod;
	printf ("%d\n", res2[n][m]);
	return 0;
}

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


long long int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


int main(){
  long long int X,K,D,O,N; 
  cin >> X >> K >> D;
  X = llabs(X);
  if(X/D>K){
    O=X-K*D;
  }else{
    N=X/D;
    X=X-N*D;
    K=K-N;
    if(K%2==0){
      O=X;
    }else{
      O=D-X;
    }
  }
  
  cout << O;
  
  return 0;
}


long long int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Measured memory_bytes: 3632
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
d = int(raw_input())
e = int(raw_input())
k = int(raw_input())

def an (a,b,c,d,e,k) :
  for i in {b,c,d,e} :
    if i-a>k :
      return ":("
  for i in {c,d,e} :
    if i-b>k :
      return ":("
  for i in {d,e} :
    if i-c>k :
      return":("
  for i in {e} :
    if i-d>k :
      return ":("
  return "Yay!"


ans = an(a,b,c,d,e,k)
print ans

Measured memory_bytes: 2692
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	cout << (a + b >= 24 ? a + b - 24 : a + b) << endl;
	return 0;
}

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

const int MM = 1e9 + 7;

ll ans = 0;

ll pw(ll p, ll q){
    if (q < 0) return 0;
    ll ret = 1;
    for (; q; q >>= 1){
        if (q & 1)
            ret = ret * p % MM;
        p = p * p % MM;
    }
    return ret;
}

void upd(int &x, int y){
    x += y;
    if (x >= MM) x -= MM;
}

int main(){
    char s;
    int ans0 = 0, ans1 = 0, ans2 = 0, ans3 = 0, db = 0, ab = 0, ad = 0, dd = 0, a = 0, d = 0;
    while (scanf("%c", &s) != EOF){
        if (s == 'A'){
            upd(a, 1);
        }
        else if (s == 'B'){
            upd(db, d);
            upd(ab, a);
        }
        else if (s == 'C'){
            upd(ans1, db);
            upd(ans0, ab);
            upd(ans1, ad);
            upd(ans2, dd);
        }
        else if (s == '?'){
            upd(ans3, dd);
            upd(ans2, ad);
            upd(ans2, db);
            upd(ans1, ab);
            upd(dd, d);
            upd(ad, a);
            upd(d, 1);
        }
    }
    ans = (ans0 * pw(3, d) + ans1 * pw(3, d - 1) + ans2 * pw(3, d - 2) + ans3 * pw(3, d - 3)) % MM;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

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

        Map<Integer, List<Integer>> routes = new HashMap<>();
        for (int i = 0; i < M; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();

            List<Integer> to = new ArrayList<>();
            if (routes.containsKey(a)) {
                to = routes.get(a);
            }
            to.add(b);

            routes.put(a, to);
        }

        List<Integer> src1Routes = routes.get(1);
        for (int to : src1Routes) {
            if (routes.containsKey(to)) {
                if (routes.get(to).contains(N)) {
                    out.println("POSSIBLE");
                    return;
                }
            }
        }

        out.println("IMPOSSIBLE");
    }
}

Measured memory_bytes: 129492
#!/usr/bin/env python
# -*- coding: utf-8 -*-

n, m = map(int, input().split())
sg_list = []
for i in range(m):
    start, goal = map(int, input().rstrip().split())
    sg_list.append([start, goal])


# 区間スケジューリング
# 終端箇所でソート
sg_list.sort(key=lambda x: x[1])

break_bridge_num = 0
past_goal = 0

for sg in sg_list:
    start, goal = sg
    if start >= past_goal:
        past_goal = goal
        break_bridge_num += 1

print(break_bridge_num)




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

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

    if(r < 1200){
        cout << "ABC";
    }else if(r >= 1200 && r < 2800){
        cout << "ARC";
    }else{
        cout << "AGC";
    }
}

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

using namespace std;

#define ll long long
#define PI 3.14159265358979323846264338327950L

int a,b,c,d;

void solve(){

    cin >> a >> b >> c >> d;

    if(ceil((double)a/d) >= ceil((double)c/b)) cout << "Yes" << endl;
    else cout << "No" << endl;
}





int main(){

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

    solve();

}

Measured memory_bytes: 3612
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val list = ArrayList<Restaurant>()
    repeat(n) {
        val line = readLine()!!.split(" ")
        list.add(Restaurant(it + 1, line[0], line[1].toInt()))
    }
    list.sort()
    list.forEach { println(it.number) }
}

data class Restaurant(val number: Int, val city: String, val score: Int) : Comparable<Restaurant> {
    override fun compareTo(other: Restaurant): Int {
        if (this.city != other.city) {
            return this.city.compareTo(other.city)
        }
        return -this.score.compareTo(other.score)
    }
}


Measured memory_bytes: 36144
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1){r=(r*a)%m;}
        b=b>>1;
        a=(a*a)%m;
    }
    return r%m;
}
int main(){
    ll n,w; cin>>n>>w;
    vi weight(n),val(n);
    for(ll i=0;i<n;i++)
    {
        cin>>weight[i]>>val[i];
    }
    vi dp(w+1,0);
    for(ll i = 0;i<n;i++)
    {
        //cout<<val[i]<<endl;
        if(weight[i]<=w)
        {
            for(ll j = w;j>=weight[i];j--)
            {
                dp[j] = max(dp[j],dp[j-weight[i]]+val[i]);
            }
        }
        //for(auto x:dp)cout<<x<<" ";
        //cout<<endl;
    }
    cout<<dp[w]<<endl;
    
    return 0;
}


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


if M < N:
    N, M = M, N

if N == 1:
    if M == 1:
        a = 1
    else:
        a = max(M-2, 0)
else:
    a = max(0, N-2) * max(0, M-2)
print (a)

Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))+[0]
c=list(map(int,input().split()))
satisfy=0
for i in range(n):
    satisfy+=b[a[i]-1]
    if i<=n-2 and a[i+1]==a[i]+1:
        satisfy+=c[a[i]-1]
print(satisfy)

Measured memory_bytes: 3064
n,k=gets.split(' ').map(&:to_i)
#h=gets.split(' ').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }
#maze = h.times.map { gets.chomp }
wari = Array.new(k+1)
kkk=10**9+7
=begin
for i in 1..k
  #puts i
  wari[i] = (k/i)**n
end
#puts wari
=end
ans=0
=begin
def power2(a, n)
  p = 1
  n.to_s(2).split('').each{|i|
    p *= p

    if i == '1'
      p *= a
    end
  }
  p
end
=end

def pow(x, n, mod)
  return 1 if n == 0
  return pow(x**2 % mod, n / 2, mod) if (n % 2) == 0
  return pow(x**2 % mod, n / 2, mod) * x % mod if (n % 2) == 1
end
#puts power2(a,n)
k.downto(1) do |soto|
  wari[soto] = pow(k/soto,n,kkk)  #((k/soto)**n)
  count=2
  while soto * count <= k
    wari[soto]-=wari[soto * count]
    count+=1
  end
  ans += (wari[soto]*soto)
  #puts wari[soto]
end
puts ans%kkk
=begin
puts "iii"
wari[0] = 0
for i in 0..(k/2-1)
  put = k/2-i
  count=2
  #puts i
  while put * count <= k
    wari[put]=wari[put] - wari[put * count]
    count+=1
  end
end
=end
#puts wari
=begin
ans=0
for i in 1..k
  ans += (i * wari[i]) % kkk
  ans %= kkk
#  ans = ans%kkk
end
=end
#puts ans


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

namespace IntModulo
{
	const int mod = 1e9 + 7;

	inline int add(int x, int y, int m = mod)
	{
		if (x + y < m)
			return x + y;
		return x + y - m;
	}

	inline int sub(int x, int y, int m = mod)
	{
		if (x >= y)
			return x - y;
		return x - y + m;
	}

	inline int mult(int x, int y, int m = mod)
	{
		return x * (LL) y % m;
	}

	inline int power(int x, int y, int m = mod)
	{
		int r = 1;
		while(y)
		{
			if (y & 1)
				r = mult(r, x, m);
			x = mult(x, x, m);
			y >>= 1;
		}
		
		return r;
	}
	
	inline int inverse(int x, int m = mod)
	{
		return power(x, m - 2, m);
	}
	
	inline void ADD(int& x, int y, int m = mod)
	{
		x += y;
		if (x >= m) x -= m;
	}
	
	inline void SUB(int& x, int y, int m = mod)
	{
		x -= y;
		if (x < 0) x += m;
	}
	
	inline void MULT(int& x, int y, int m = mod)
	{
		x = (x * (LL) y) % m;
	}
};

namespace Combinatorics
{
	using namespace IntModulo;
	
	const int N = 1 << 20;
	int fact[N];
	int inv[N];
	int invFact[N];
	bool inited = false;
	
	inline int C(int n, int k) // binomial C(n, k)
	{
		return n < k ? 0 : mult(fact[n], mult(invFact[k], invFact[n - k]));
	}
	
	inline int H(int n, int k) // number of solution x1 + .. + xn = k
	{
		return C(n + k - 1, k);
	}
	
	void init()
	{
		debug(Combinatorics::N);
		inited = true;
		inv[1] = 1;
		FOR(i, 2, N)
			inv[i] = mult(mod - mod / i, inv[mod % i]);
		
		invFact[0] = fact[0] = 1;
		FOR(i, 1, N)
		{
			fact[i] = mult(i, fact[i - 1]);
			invFact[i] = mult(invFact[i - 1], inv[i]);
		}
	}	
};

using namespace Combinatorics;

int n, k;
int a[N];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	Combinatorics::init();
	
	cin >> n >> k;
	FOR(i, 0, n) cin >> a[i];
	sort(a, a + n);
	int mx = 0, mn = 0;
	FOR(i, 0, n)
	{
		int val = a[i];
		if (val < 0) val += mod;
		int cnt_mn = 0, cnt_mx = 0;
		
		cnt_mn = C(n - i - 1, k - 1);
		cnt_mx = C(i, k - 1);		
		
		ADD(mx, mult(val, cnt_mx));
		ADD(mn, mult(val, cnt_mn));
	}
	
	int ans = sub(mx, mn);	
	cout << ans << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 12928
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func Input_int() int {
	stdin.Scan()
	out,err := strconv.Atoi(stdin.Text())
	if err != nil{
		panic(err)
	}
	return out
}


func main() {
	stdin.Split(bufio.ScanWords)
	A,B,C := Input_int(),Input_int(),Input_int()
	if(A*C < B){
		fmt.Println(C)
	}else{
		fmt.Println(B/A)
	}
}

Measured memory_bytes: 640
from sys import stdin
readline = stdin.readline


h, w = map(int, readline().split())
w += 1
dp = [list(map(int, readline().split())) + [1] for _ in range(h)]

for i in range(h):
    for j in range(w):
        dp[i][j] ^= 1
    
for i in range(1, h):
    for j in range(w):
        if dp[i][j]:
            dp[i][j] += dp[i - 1][j]

max_s = 0
for i in range(h):
    stack = []
    for j in range(w):
        if (stack[-1][0] if stack else 0) < dp[i][j]:
            stack.append((dp[i][j], j))
        elif stack and stack[-1][0] > dp[i][j]:
            while stack and stack[-1][0] > dp[i][j]:
                height, l = stack.pop()
                s = height * (j - l)
                if max_s < s:
                    max_s = s
            if dp[i][j]:
                stack.append((dp[i][j], l))
print(max_s)



Measured memory_bytes: 51984
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int a,b;
  cin >> a>> b;
  if(a>=13){
    cout<<b<<endl;
  }
  else if(a<=5){
    cout<<0<<endl;
  }
  else {
    cout<<b/2<<endl;
  }
  return 0;
}

Measured memory_bytes: 3580
import java.util.*;
	
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int[] A = new int[a];
		int m =0;
		while (m<a) {
			A[m]= in.nextInt();
			m++;
		}
		for (int i=0;i<a-1;i++) {
			System.out.print(A[i]+" ");
		}
		System.out.print(A[a-1]);
		System.out.println();
		for (int i=1;i<a;i++) {
			int key = A[i];
			int j =i-1;
			while (j>=0 && A[j]>key){
				A[j+1]=A[j];
				j--;
			}
			A[j+1]=key;
			for (int b=0;b<a-1;b++) {
				System.out.print(A[b]+" ");
			}
			System.out.print(A[a-1]);
			System.out.println();
		}
		in.close();
	}
}


Measured memory_bytes: 30304
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int k;cin>>k;
  int x=0;

  for(int i=1; i<=k; i++){
    for(int j=i+1; j<=k; j=j+2){
      x++;
    }
  }
  cout<<x<<endl;
}

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	ll r, d, x;
	cin >> r >> d >> x;

	rep(i, 10) {
		x = r * x - d;
		cout << x << endl;
	}

	return 0;
}


Measured memory_bytes: 256