akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

struct ant {
	int id;
	bool goleft;
	int place;
};

struct attack {
	int id0;
	int id1;
	int time;
};

int main() {
	while (1) {
		int N, L; cin >> N >> L;
		if (!N)break;
		pair<int, int>ans(-1, -1);
		vector<ant>lants;
		vector<ant>rants;
		vector<pair<int, int>>ants;
		for (int i = 0; i < N; ++i) {
			char c; int a; cin >> c >> a;
			ants.push_back(make_pair(a, i));
			if (c == 'L') {
				lants.push_back(ant{ i,true,a });
				if (ans.first <= a) {
					ans = make_pair(a, i);
				}
			}
			else {
				rants.push_back(ant{ i,false,a });
				if (ans.first < L-a) {
					ans = make_pair(L-a, i);
				}
			}
		}
		sort(ants.begin(), ants.end());
		vector<int>perms(N);
		iota(perms.begin(), perms.end(), 0);
		/*for (int i = 0; i < ants.size(); ++i) {
			perms[i] = ants[i].second;
		}*/
		vector<attack>attacks;
		vector<vector<int>>times(lants.size(), vector<int>(rants.size(), -1));
		for (int l = 0; l < lants.size(); ++l) {
			for (int r = 0; r < rants.size(); ++r) {
				if (lants[l].place > rants[r].place) {
					if (!((lants[l].place - rants[r].place)%2)) {
						attacks.push_back(attack{ lants[l].id,rants[r].id,(lants[l].place-rants[r].place ) });
					}
				}
			}
		}
		sort(attacks.begin(), attacks.end(), [](const attack&l, const attack&r) {return l.time < r.time; });

		for (int i = 0; i < attacks.size(); ++i) {
			swap(perms[attacks[i].id0], perms[attacks[i].id1]);
		}
		cout <<  ans.first << " " << perms[ans.second]+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() 
{
	FAST
	ll n;
	cin>>n;
	ld a[n];
	for(ll i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(ll i=1;i<n;i++)
		a[i]=(a[i]+a[i-1])/2;
	cout<<a[n-1];
	return 0;
}

Measured memory_bytes: 256
def tc():
    n = int(input())
    stones = list(map(int, input().split()))
    # dp[i]: min cost to get to stone i (0 based)
    dp = [0] * n
    dp[1] = abs(stones[1] - stones[0])

    for i in range(2, n):
        dp[i] = min(dp[i - 1] + abs(stones[i] - stones[i - 1]),
                    dp[i - 2] + abs(stones[i] - stones[i - 2]))

    print(dp[-1])


tc()


Measured memory_bytes: 84208
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    int h,w;
    cin >> h >> w;
    p_queue(int) pos;
    rp(i,h){
        rp(j,w){
            int t;
            cin >> t;
            if(t&1){
                if(i&1) pos.push((i+1)*w-j-1);
                else pos.push(i*w+j);
            }
        }
    }
    int ctr=0;
    vector<pair<P,P>> ans(0);
    while(!pos.empty()){
        int p=pos.top(); pos.pop();
        if(pos.empty())break;
        int q=pos.top(); pos.pop();
        repi(i,p,q){
            P a,b;
            if((i/w)&1){
                a=mp(i/w+1,w-i%w);
            }
            else a=mp(i/w+1,i%w+1);
            if(((i+1)/w)&1) b=mp((i+1)/w+1,w-(i+1)%w);
            else b=mp((i+1)/w+1,(i+1)%w+1);
            ans.pb(mp(a,b));
            ctr++;
        }
    }
    print(ctr);
    for(auto pp : ans){
        princ(pp.first.first);
        princ(pp.first.second);
        princ(pp.second.first);
        print(pp.second.second);
    }
    return 0;
}

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

#define jk(i,j,k) for (int i = (j); i <= (k); i++)
#define kj(i,j,k) for (int i = (j); i >= (k); i--)
#define int long long
#define lb long double
#define ul unsigned long long
#define mp std::make_pair
#define pb push_back
#define pr(a,b) printf(a, b)
#define sc(a,b) scanf(a, &b)
#define x first
#define y second
#define al(x) (x).begin(), (x).end()
#define me(a) memset((a), 0, sizeof(a))

inline int rd() { int data = 0, w = 1; char ch = 0; while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar(); (ch == '-') && ( w = -1, ch = getchar() ); while (ch >= '0' && ch <= '9') { data = data * 10 + ch - '0'; ch = getchar(); } return data * w; }
inline void P (int v) { if (v < 0) { putchar('-'); v = -v; } if (v > 9) P(v / 10); putchar(v % 10 + '0'); }

signed main () {
    puts(rd() + rd() + rd() >= 22 ? "bust" : "win");
    return 0;
}

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

int main() {
  int i, p, q;
  bool b;
  char buf[201];
  char code[5][6] = {
    {'a', 'f', 'k', 'p', 'u', 'z'},
    {'b', 'g', 'l', 'q', 'v', '.'},
    {'c', 'h', 'm', 'r', 'w', '?'},
    {'d', 'i', 'n', 's', 'x', '!'},
    {'e', 'j', 'o', 't', 'y', ' '},
  };

  while (cin.getline(buf, sizeof(buf))) {
    i = 0;
    b = true;
    while (buf[i]!='\0') {
      if (i&1) {
        if (buf[i]<'1'||buf[i]>'5') {
          b = false;
          break;
        }
      } else {
        if (buf[i]<'1'||buf[i]>'6') {
          b = false;
          break;
        }
      }
      ++i;
    }
    if (i&1) b = false;

    if (b) {
      i = 0;
      while (buf[i]!='\0') {
        p = buf[i++]-'1';
        q = buf[i++]-'1';
        cout << code[q][p];
      }
      cout << endl;
    } else {
      cout << "NA" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1120
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<Long, Integer> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            long a = Long.parseLong(sc.next());
            map.merge(a, 1, Integer::sum);
        }
        int ans = 0;
        for (Map.Entry<Long, Integer> e : map.entrySet()) {
            if (e.getKey() > e.getValue()) {
                ans += e.getValue();
            } else if (e.getKey() < e.getValue()) {
                ans += (e.getValue() - e.getKey());
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50416
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<queue>
#define For(i,j,k)	for(ll i=j;i<=k;++i)
#define Dow(i,j,k)	for(ll i=k;i>=j;--i)
#define inf 1e17
#define ll long long
using namespace std;
inline ll read()
{
    ll t=0,f=1;char c=getchar();
    while(c<'0'||c>'9')	{if(c=='-')	f=-1;	c=getchar();}
    while(c>='0'&&c<='9')	t=t*10+c-'0',c=getchar();
    return t*f;
}
inline void write(ll x){if(x>=10)	write(x/10);putchar(x%10+'0');}
inline void writeln(ll x){write(x);puts("");}
inline void write_p(ll x){write(x);putchar(' ');}
int ans,rev[101],cnt[101],n,d[101],t[101],tim;
inline void check()
{
	For(i,1,n)	if(d[i]!=0)if(rev[i])	t[i]=d[i];else t[i]=24-d[i];
	int tans=1e8;
	For(i,1,n)
		For(j,i+1,n)	tans=min(tans,min(24-abs(t[i]-t[j]),abs(t[i]-t[j])));
	ans=max(tans,ans);
	tim++;
	if(tim*n*n>=100000000)	{writeln(ans);exit(0);}
}
inline void dfs(int x)
{
	if(x==n+1)	{check();return;}
	int t=rand()&1;
	if(t==1)	{rev[x]=0;dfs(x+1);rev[x]=1;dfs(x+1);rev[x]=0;}
	else 		{rev[x]=1;dfs(x+1);rev[x]=0;dfs(x+1);rev[x]=0;}
}
int main()
{
	srand(time(0));
	n=read();
	For(i,1,n)	d[i]=read(),cnt[d[i]]++;
	d[n+1]=0;n++;cnt[0]++;
	sort(d+1,d+n+1);
	if(n>25){puts("0");return 0;}
	For(I,1,100000)
	{
		For(j,1,n)	if(rand()&1)	t[j]=d[j];else t[j]=24-d[j];
		int tans=1e8;
		For(i,1,n)
			For(j,i+1,n)	tans=min(tans,min(24-abs(t[i]-t[j]),abs(t[i]-t[j])));
		ans=max(tans,ans);
	}
	writeln(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
bool ch[200010];ll ans;
	ll a[3];
void dep(char now){
	if(now=='r'){
		ans+=a[2];
	}
	else if(now=='s'){
		ans+=a[0];
	}
	else{
		ans+=a[1];
	}
}
int main() {
	ll n,k;
	cin>>n>>k;

	for(ll i=0;i<3;i++){
		cin>>a[i];
	}
	ch[0]=true;
	string s;
	cin>>s;
	for(ll i=0;i<n;i++){
		if(i-k>=0){
			if(s[i-k]==s[i]&&ch[i]){
				continue;
			}
			else{
				ch[i+k]=true;
				dep(s[i]);
			}
		}
		else{
			dep(s[i]);
			ch[i+k]=true;
		}
		//cout << ans<<" " <<i<<endl;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, K; cin >> N >> K;
    vector<int> A;
    //int x;
    for (int i = 0; i < N; ++i) {
        int x; cin >> x;
        A.push_back(x);
    }
    sort(A.begin(), A.end());
 
    int cnt[200003] = {};
    for (int i = 0; i < N; ++i) {
        ++cnt[A[i]];
    }
    sort(cnt, cnt + N + 1 , greater<int>());

    /*
    vector<int> cnt;
    int i = 0;
    while (i < N){
        int x = count(A.begin(), A.end(), A[i]);
        cnt.push_back(x);
        i += x;
    }
    sort(cnt.begin(), cnt.end(), greater<int>());
    */

    int sum = 0;
    //int sizecnt = cnt.size();
    //if (sizecnt <= K) {cout << 0; return 0;}
    for (int i = 0; i < K; ++i) {
        
        sum += cnt[i];
    }
    /*
    for (int i = 0; i < K; ++i) {

        sum += cnt[i];
    }
    */
    cout << N - sum << endl;
    return 0;
}

Measured memory_bytes: 1908
from collections import deque
def bfs(graph, N, start):
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(lambda n: int(n) - 1, input().split())
    graph[a].append(b)
    graph[b].append(a)
visited = bfs(graph, N, 0)[1:]
if all(visited):
    print("Yes")
    print(*visited, sep="\n")
else:
    print("No")


Measured memory_bytes: 38284
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll power(ll x, ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2,m)%m; 
    p = (p * p)%m; 
  
    return (y%2 == 0)? p : (x * p)%m ; 
} 

ll modInverse(ll a, ll m) 
{ 
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
    return power(a, m-2,m); 
} 
  
// To compute x^y under modulo m 


int main()
{
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin>>n;map<ll,int> ma;map<ll,int> mo;
    ll a[n+1];ll b[n+1];ll c[n+1];
    for(int i=1;i<=n;i++)
    {
      cin>>a[i];
      b[i] = i - a[i];
      ma[b[i]]++;
      c[i] = a[i] + i;
      mo[c[i]]++;
    }ll ans = 0;
    for(int i=1;i<=n;i++)
    {
      ans+=mo[b[i]];
    }
    cout<<ans;
   
    
    return 0;
}

Measured memory_bytes: 42556
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,x = inpl()
a = inpl()
a.sort()
if sum(a) < x:
    print(n-1)
else:
    s = 0
    for i,y in enumerate(a):
        # print(i,y)
        if s + y < x:
            s += y
        elif s + y == x:
            print(i+1)
            break
        else:
            print(i)
            break
    else:
        print(n-1)

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

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

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


void Main() {
	int M, K; cin >> M >> K;
	if (K >= (1<<M)) { cout << -1 << endl; return; }
	if (K == 0) {
		cout << 0;
		for (int i = 1; i < (1<<M); i++) cout << " " << i;
		for (int i = (1<<M)-1; i >= 0; i--) cout << " " << i;
		cout << endl;
		return;
	}
	if (M == 1 && K == 1) { cout << -1 << endl; return; }
	cout << 0;
	for (int i = (1<<M)-1; i >= 1; i--) {
		if (i != K) cout << " " << i;
	}
	cout << " " << 0 << " " << K;
	for (int i = 1; i < (1<<M); i++) {
		if (i != K) cout << " " << i;
	}
	cout << " " << K << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}

Measured memory_bytes: 1792
#
# abc072 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """atcoder"""
        output = """acdr"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """aaaa"""
        output = """aa"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """z"""
        output = """z"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """fukuokayamaguchi"""
        output = """fkoaaauh"""
        self.assertIO(input, output)


def resolve():
    print(input()[0::2])


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16160
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int k,modk=0;
	cin >> k;
	set<int>s;
	modk = 7 % k;
	s.insert(modk);
	rep(i, k) {
		if (modk == 0) {
			cout << s.size() << endl;
			return 0;
		}
		modk = (modk * 10 + 7) % k;
		if (s.count(modk))break;
		s.insert(modk);
	}
	cout << -1 << endl;

	return 0;
}



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

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    map<pair<int, int>, int> m;
    int d[] = {-2, -1, 0};
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) {
            int ny = a[i] + d[j], nx = b[i] + d[k];
            if (ny <= 0 || ny + 2 > h || nx <= 0 || nx + 2 > w) continue;
            m[make_pair(nx, ny)]++;
        }
    }
    long long ans[10];
    ans[0] = ((long long) h - 2) * (w - 2) - m.size();
    for (int i = 1; i < 10; i++) ans[i] = 0;
    for (auto p : m) ans[p.second]++;
    for (int i = 0; i < 10; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 57216
N = str(input())

if N[-1] == "2" or N[-1] == "5" or N[-1] == "4" or N[-1] == "7" or N[-1] == "9":
    print("hon")
elif N[-1] == "0" or N[-1] == "1" or N[-1] == "6" or N[-1] == "8":
    print("pon")
else:print("bon")

Measured memory_bytes: 9060
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import Control.Monad.ST

main :: IO ()
main = do
  [a,b,c,d] <- map read.words <$> getLine :: IO [Int]
  let f x = if a `mod` x == 0 then (+1) $ (b - a) `div` x else (+1) $ ( b - ((*x) $ (a `div` x) + 1)) `div` x
  putStrLn $ show $ b - a + 1 - ((f c) + (f d) - (f $ lcm d c))


Measured memory_bytes: 508
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    if (A + B == 3) {
      System.out.println("3");
    } else if (A + B == 4) {
	  System.out.println("2");
    } else {
      System.out.println("1");
    }
  }
}

Measured memory_bytes: 23124
n = int(input())
ac = 0
tle = 0
wa = 0
re = 0
for i in range(n) :
    s = input()
    if s == 'AC' :
        ac += 1
    elif s == 'WA' :
        wa += 1
    elif s == 'TLE' :
        tle += 1
    else :
        re += 1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)


Measured memory_bytes: 9192
<?php
// 答えだすよう
function answer($v) {
	echo "{$v}\n";
	exit(0);
}

//============================================================
// 素数を法とした値を出す用
//============================================================
const mod = 1000000007;

function MintInit(int $a) {
	return(($a % mod + mod) % mod);
}

function MintAdd(int $a, int $b) {
	return(MintInit($a + $b));
}

function MintSub(int $a, int $b) {
	return(MintInit($a - $b));
}

function MintMul(int $a, int $b) {
	return(MintInit($a * $b));
}

function MintDiv(int $a, int $b) {
	return(MintMul($a, modPow($b, mod - 2, mod)));
}
//============================================================

// 繰り返し二乗法
function modPow(int $a, int $n, int $p) {
	if($n == 1) {
		return($a % $p);
	}
	if($n % 2 == 1) {
		return(($a * modPow($a, $n - 1, $p)) % $p);
	}
	
	$t = modPow($a, $n / 2, $p);
	return(($t * $t) % $p);
}

//============================================================
// コンビネーション用
class combination {
	public $fact = [];
	public $ifact = [];
	public function __construct(int $n) {
		$this->fact[0] = 1;
		for($i = 1; $i <= $n; $i++) {
			$this->fact[$i] = MintMul($this->fact[$i - 1], $i);
		}
		// 逆数を取る
		$this->ifact[$n] = MintDiv(1, $this->fact[$n]);
		// 逆数をとったのでかけていけば良い
		for($i = $n; $i >= 1; $i--) {
			$this->ifact[$i - 1] = MintMul($this->ifact[$i], $i);
		}
	}
	public function c(int $n, int $k) {
		if($k < 0 || $k > $n) {
			return(0);
		}
		return(MintMul($this->fact[$n], MintMul($this->ifact[$k], $this->ifact[$n - $k])));
	}
}
//============================================================


// 入力
fscanf(STDIN, "%d %d", $n, $k);

// kは0の個数の最大になるので丸める
$k = min($k, $n - 1);

// クラス生成
$con = new combination($n);

$ans = 0;

// 0の個数(最小移動回数)を固定してパターン数を求める
for($i = 0; $i <= $k; $i++) {
	// 0の場所のパターン数 * 0以外の組み合わせ
	$ans = MintAdd($ans, MintMul($con->c($n, $i), $con->c(($n - $i - 1) + $i, $i)));
}

answer($ans);



Measured memory_bytes: 25588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int inf = 1e9;
int s, w;
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	cin>>s>>w;
	if(s <= w)cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;

	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
#define ls rt << 1
#define rs rt << 1 | 1
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define X first
#define Y second
using namespace std;
const int N = 1e5 + 10;

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
int n, m;
ll a[N], xi[N << 1], ch[N << 1];

int main()
{
	n = read();
	m = read();
	for(int i = 1; i <= n; i ++)
		a[i] = read();
	ll all = 0;
	for(int i = 2; i <= n; i ++)
	{
		int now = a[i - 1];
		int to  = a[i];
		now --;
		to --;
		now %= m;
		if(now > to) to += m;
		all += to - now;
		xi[now + 1] ++;
		xi[to + 1] --;
		ch[now + 1] += now;
		ch[to + 1] -= now;
	}
	
	for(int i = 1; i <= 2 * m; i ++)
	{
		xi[i] += xi[i - 1];
		ch[i] += ch[i - 1];
	}
	
	ll ans = all;
	for(int i = 0; i < m; i ++)
	{
		ll now = all;
		int k = xi[i];
		ll b = ch[i];
		now -= (ll) k * i - b - k;
		k = xi[i + m];
		b = ch[i + m];
		now -= (ll) k * (i + m) - b - k;
		ans = min(ans, now);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4096
#include<stdio.h>
#include<math.h>
typedef struct {
	double x;
	double y;
}point;
void koch(int n,point p1,point p2) {
	point s,t,u;
	double sum = M_PI * 60 / 180;
	if (n == 0) return;
	s.x = (2 * p1.x + p2.x) / 3;
	s.y = (2 * p1.y + p2.y) / 3;
	t.x = (p1.x + 2 * p2.x) / 3;
	t.y = (p1.y + 2 * p2.y) / 3;
	u.x = (t.x - s.x) * cos(sum) - (t.y - s.y) * sin(sum) + s.x;
	u.y = (t.x - s.x) * sin(sum) + (t.y - s.y) * cos(sum) + s.y;
	koch(n-1,p1,s);
	printf("%f %f\n",s.x,s.y);
	koch(n-1,s,u);
	printf("%f %f\n",u.x,u.y);
	koch(n-1,u,t);
	printf("%f %f\n",t.x,t.y);
	koch(n-1,t,p2);
}

int main(){
	int k;
	point p1,p2;
	p1.x=0.0;
	p2.x=100.0;
	p1.y=0.0;
	p2.y=0.0;
	scanf("%d",&k);
	printf("%.8f %.8f\n",p1.x,p1.y);
	koch(k,p1,p2);
	printf("%.8f %.8f\n",p2.x,p2.y);
	return 0;
}




Measured memory_bytes: 2140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int dp[110][10010]={0};
int main(){
	int n,m;
	while(cin>>n>>m,n){
		vvi dp(n+1,vi(m+1));
		int co;
		cin>>co;
		rep(i,co){
			int a,b;
			cin>>a>>b;
			dp[a][b]=-1;
		}
		dp[1][0]=1;
		rep(i,n)rep(j,m)if(dp[i+1][j+1]!=-1){
			if(dp[i][j+1]!=-1)dp[i+1][j+1]+=dp[i][j+1];
			if(dp[i+1][j]!=-1)dp[i+1][j+1]+=dp[i+1][j];
		}
		if(dp[n][m]!=-1)cout<<dp[n][m]<<endl;
	}
}

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

bool in_field(int x, int y, int W, int H)
{
    return 0 <= x && x < W && 0 <= y && y < H;
}

int main()
{
    int H, W;
    std::cin >> H >> W;

    std::vector<std::string> s(H);
    for (int i = 0; i < H; i++) {
        std::cin >> s[i];
    }
    
    int seat_cnt = 0;
    for (int i = 1; i < H; i++) {        
        for (int j = 0; j < W; j++) {
            bool ok = (s[i][j] == '-');
            for (int dj : {-1, 1}) {
                int nj = j + dj;
                if (in_field(nj, i, W, H) && s[i][nj] != '-') {
                    ok = 0;
                }
            }
            constexpr int di[] = {-1, -1, -1, +0, +0, +1, +1, +1};
            constexpr int dj[] = {-1, +0, +1, +0, +0, -1, +0, +1};
            for (int k = 0; k < 8; k++) {
                int ni = i + di[k];
                int nj = j + dj[k];
                if (in_field(nj, ni, W, H) && s[ni][nj] == 'x') {
                    ok = 0;
                }
            }

            seat_cnt += ok;
        }
    }

    std::cout << seat_cnt << std::endl;
    return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>

#define MAX 100005
#define NIL -1

struct Node {
  int p,l,r;
};

struct Node T[MAX];
int n,D[MAX];
void print(int);
int rec(int,int);

int main(){
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].p=T[i].l=T[i].r=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)T[v].l = c;
      else T[l].r = c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL) r=i;
  }
  rec(r,0);
  for(i=0;i<n;i++)print(i);

  return 0;
}
void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p == NIL )printf("root, ");
  else if ( T[u].l == NIL )printf("leaf, ");
  else printf("internal node, ");

  printf( "[");
    for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i)printf( ", ");
    printf("%d",c);

  }
  printf("]\n");
}

int rec(int u,int p){
  D[u]=p;
  if(T[u].r != NIL )rec(T[u].r,p);
  if( T[u].l !=NIL )rec(T[u].l,p+1);
}





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

int main()
{string S;
 cin >> S;
 
 int cnt1 = 0;
 int cnt2 = 0;
 
 for( int i = 0; i < S.size(); i++)
 {if( S[i] == '0'){cnt1++;}
  else if( S[i] == '1'){cnt2++;}}
 
 cout << 2 * min(cnt1,cnt2) <<endl;
 return 0;
}


Measured memory_bytes: 512
from itertools import permutations
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    perm = list(permutations(range(1, N)))
    edges = [[False] * N for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edges[a][b] = True
        edges[b][a] = True

    ans = 0
    for P in perm:
        i = 0
        for j in P:
            if edges[i][j]:
                i = j
            else:
                break
        else:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int A,B,K;
    cin>>A>>B>>K;

    if(B-A+1>=2*K){
        for(int i=A;i<=A+K-1;i++) cout<<i<<endl;
        for(int i=B-K+1;i<=B;i++) cout<<i<<endl;
    }
    else{
        for(int i=A;i<=B;i++) cout<<i<<endl;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 300009
ll m,a,b,c,d,n,arr[15][sz],i,k,j,x,y,l;
ll brr[sz];
int main()
{
scanf("%lld %lld %lld",&n,&m,&x);
for(i=1;i<=n;i++)
{
    for(j=0;j<=m;j++)
    scanf("%lld",&arr[i][j]);
}
y=1000000000000000000ll;
for(i=1;i<(1<<n);i++)
{
    k=0;
    for(j=1;j<=n;j++)
    {
        if((1<<(j-1))&(i))
        {
         //   printf("%lld %lld\n",i,j);
            k+=arr[j][0];
            for(l=1;l<=m;l++)
                brr[l]+=arr[j][l];
        }
    }
    l=0;
    for(j=1;j<=m;j++)
    {
        if(brr[j]<x)
            l=1;
    }
    if(l==0)
    {
       y=min(y,k);
    }
    for(j=1;j<=m;j++)
        brr[j]=0;
}
//printf("%lld\n",i);
if(y==1000000000000000000ll)
    printf("-1\n");
else
    printf("%lld\n",y);
return 0;
}


Measured memory_bytes: 3848
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, sum = 0, h, w;
ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
int main() {
    int a, b, x,ans = 0; cin >> a >> b >> x;
    if (a > 2 * b) {
        int amari = x % 1000;
        ans += (x / 1000) * (b * 2);
        if (amari > 0 && amari <= 500) ans += b;
        else if (amari > 500) ans += b * 2;
    }
    else {
        int amari = x % 1000;
        ans += (x / 1000) * a;
        if (amari > 0 && amari <= 500 && b < a) ans += b;
        else if (amari > 0 && amari <= 500) ans += a;
        else if(amari > 500) ans+= a;
    }cout << ans << endl;
}


Measured memory_bytes: 3124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0201
{
    public class Program
    {
        public static Dictionary<string, int> prices;
        public static Dictionary<string, List<string>> alchemy;


        public static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt(); if (n == 0) break;

                Init(n);
                string name = RSt();
                Console.WriteLine(Math.Min(prices[name], GetPrice(name)));
            }
        }

        private static void Init(int n)
        {
            prices = new Dictionary<string, int>(n);
            for (int i = 0 ; i < n ; i++)
            {
                string[] items = RStAr();
                prices.Add(items[0],int.Parse(items[1]));
            }

            int m = RInt();
            alchemy = new Dictionary<string, List<string>>(m);
            for (int i = 0 ; i < m ; i++)
            {
                string[] items = RStAr();
                alchemy.Add(items[0], items.Skip(2).Select(x => x).ToList());
            }

        }

        private static int GetPrice(string name)
        {
            if (!alchemy.ContainsKey(name)) return prices[name];
            else
            {
                int sum = 0;
                foreach (var item in alchemy[name])
                {
                    sum += GetPrice(item);
                }
                return Math.Min(prices[name], sum);
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 18380
#include <bits/stdc++.h>
#define Rep(i,j,n) for(int i=j; i<n; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;
 
int main(){
  int a,b,c; cin >> a >> b >> c;
  if((a<=c && c<=b) || (a>=c && c>=b)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void){
int h[26];
char m,c='a';
for(int a=0;a<26;a++)h[a]=0;
while(scanf("%c",&m)!=EOF){
if((m>='A'&&m<='Z')||(m>='a'&&m<='z')){
if(m>='A'&&m<='Z')m-='A';
if(m>='a'&&m<='z')m-='a';
h[m]++;
}
}
for(int b=0;b<26;b++){
printf("%c : %d\n",c+b,h[b]);
}
return 0;
}


Measured memory_bytes: 1968
// 去吧！皮卡丘! 把AC带回来！
//      へ　　　　　／|
// 　　/＼7　　　 ∠＿/
// 　 /　│　　 ／　／								AC		AC		AC		AC
//    │　Z ＿,＜　／　　 /`ヽ						AC		AC		AC		AC
//    │　　　　　ヽ　　 /　　〉					AC		AC		AC		AC
// 　Y　　　　　`　 /　　/  /						AC		AC		AC		AC
// 　亻●　.　●　　〈　/　/						AC		AC		AC		AC
// 　()　 へ　　　　|　＼〈							AC		AC		AC		AC
// 　　>- ._　 ィ　 │ ／／							AC		AC		AC		AC
// 　 / へ　　 /　/＜| ＼＼							AC		AC		AC		AC
// 　 ヽ_/　　(_／　 │／／							AC		AC		AC		AC
// 　　 7　　　　　　　|／							AC		AC		AC		AC
// 　　 ＞―r￣￣`-―＿/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

#define Pig (OO)

using namespace std;

const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

ll q;
priority_queue<ll> L;
priority_queue<ll,vector<ll>,greater<ll> > R; 
ll ans;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>q;
	
	while(q--)
	{
		ll op;
		cin>>op;
		
		if(op==1)
		{
			ll a,b;
			cin>>a>>b;
			
			L.push(a);
			R.push(a);
			
			ans+=b;
			
			if(L.top()>R.top())
			{
				ll x=L.top();L.pop();
				ll y=R.top();R.pop();
				
				ans+=abs(x-y);
				
				L.push(y);R.push(x);
			}
		}
		else cout<<L.top()<<' '<<ans<<endl;
	}
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

ll mat[65][55][55];

ll sol[55][55];
ll nsol[55][55];

int main() {
	int n;
	ll k;
	scanf("%d%lld", &n, &k);
	for (int i=0 ; i<n ; i++) {
		for (int j=0 ; j<n ; j++) {
			scanf("%d", &mat[0][i][j]);
		}
	}
	for (int p=1 ; p<65 ; p++) {
		for (int i=0 ; i<n ; i++) {
			for (int j=0 ; j<n ; j++) {
				ll x = 0;
				for (int k=0 ; k<n ; k++) {
					x = (x + mat[p-1][i][k]*mat[p-1][k][j]) % MOD;
				}
				mat[p][i][j] = x;
			}
		}
	}
	for (int i=0 ; i<n ; i++) sol[i][i] = 1;
	for (int p=63 ; p>=0 ; p--) {
		if (k&(1LL<<p)) {
			for (int i=0 ; i<n ; i++) {
				for (int j=0 ; j<n ; j++) {
					ll x = 0;
					for (int k=0 ; k<n ; k++) {
						x = (x + sol[i][k]*mat[p][k][j]) % MOD;
					}
					nsol[i][j] = x;
				}
			}
			for (int i=0 ; i<n ; i++) {
				for (int j=0 ; j<n ; j++) {
					sol[i][j] = nsol[i][j];
				}
			}
		}
	}
	ll uk = 0;
	for (int i=0 ; i<n ; i++) {
		for (int j=0 ; j<n ; j++) {
			uk = (uk + sol[i][j]) % MOD;
		}
	}
	printf("%lld\n", uk);
	return 0;
}

Measured memory_bytes: 5368
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

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

const int kMaxN = 2e5 + 5;
int n, q, L;
ll f[kMaxN][31], x[kMaxN];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", x + i);
  }
  scanf("%d%d", &L, &q);
  for (int i = 1; i <= n; ++i) {
    f[i][0] = upper_bound(x + 1, x + n + 1, x[i] + L) - x - 1;
  }
  for (int j = 1; j <= 30; ++j)
    for (int i = 1; i <= n; ++i) {
      f[i][j] = f[f[i][j - 1]][j - 1];
    }
  for (int i = 1; i <= q; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (l > r) swap(l, r);
    ll ans = 1;
    for (int j = 30; j >= 0; --j) {
      if (f[l][j] < r) {
        ans += 1LL << j;
        l = f[l][j];
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 26624
n,w=map(int,input().split())
lis=[list(map(int,input().split())) for _ in range(n)]
dp=[[0 for i in range(w+1)] for j in range(n+1)]
for i in range(n):
    for j in range(w+1):
        if w-lis[i][0]>=0 and j-lis[i][0]>=0:
            dp[i+1][j]=max(dp[i][j],dp[i][j-lis[i][0]]+lis[i][1])
        else:
            dp[i+1][j]=dp[i][j]
print(max(dp[n]))

Measured memory_bytes: 171656
#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>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k, score[3];
  string s;
  cin >> n >> k >> score[0] >> score[1] >> score[2] >> s;
  vector<bool> ok(n);
  for(int i = 0; i < k; ++i) {
    ok[i] = true;
  }
  for(int i = k; i < n; ++i) {
    ok[i] = (s[i] != s[i - k]) || (!ok[i - k]);
  }
  map<char, int> mp {{'r', 0}, {'s', 1}, {'p', 2}};
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    if(ok[i]) {
      ans += score[(mp[s[i]] + 2) % 3];
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
namespace modular{
    using ll = long long;
 
    const int mod = 998244353;
 
    int mul_mod(ll a, ll b){
        if (a < 0) a += mod;
        if (b < 0) b += mod;
        return a * b % mod;
    }
 
    int plus_mod(ll a, ll b){
        if (a < 0) a += mod;
        if (b < 0) b += mod;
        return (a + b) % mod;
    }
 
    int minus_mod(ll a, ll b){
        if (a < 0) a += mod;
        if (b < 0) b += mod;
        return (a - b + mod) % mod;
    }
 
    int pow_mod(ll a, ll k){
        ll res = 1;
        for (; k; k >>= 1, a = mul_mod(a, a))
            if (k & 1) res = mul_mod(res, a);
        return res;
    }
 
    ll ext_euclid(ll a, ll b, ll &x, ll &y){
        int g = a; x = 1; y = 0;
        if (b != 0){
            g = ext_euclid(b, a % b, y, x);
            y -= (a / b) * x;
        }
        return g;
    }
 
    int inverse(ll a){
        return pow_mod(a, mod - 2);
    }
 
    int div_mod(ll a, ll b){
        return mul_mod(a, inverse(b));
    }
};
 
using namespace modular;
 
const int N = 2e5 + 5;
const int C = 1e6 + 5;
int a[N], sum[C], w[C];
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, res = 0, maxv = 0; cin >> n;
    for (int i = 1, x; i <= n; i++){
        cin >> x; sum[x] = plus_mod(sum[x], x);
        maxv = max(maxv, x);
    }
    for (int i = 1; i <= maxv; i++){
        w[i] += inverse(i);
        for (int j = 2 * i; j <= maxv; j += i)
            w[j] = minus_mod(w[j], w[i]);
        int x = 0, y = 0;
        for (int j = i; j <= maxv; j += i){
            x = plus_mod(x, sum[j]);
            y = plus_mod(y, mul_mod(sum[j], j));
        }
        res = plus_mod(res, mul_mod(w[i],
            minus_mod(mul_mod(x, x), y)));
    }
    cout << div_mod(res, 2) << '\n';
}

Measured memory_bytes: 8448
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    # print(A)
    tot = sum(A)
    sub = 0
    for i in range(N):
        if i % 2 == 0:
            sub += A[i]
    ans = []
    ans.append(2*sub-tot)
    for i in range(N-1):
        ans.append(2*A[i]-ans[-1])
    # print(ans)
    return ans
if __name__ == '__main__':
    output = main()
    print(" ".join(map(str, output)))

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int N;
  cin>>N;
  vector<double>v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(rng(v));
  for(int i=0;i<N-1;i++){
    v[i+1]=(v[i]+v[i+1])/2;
  }
  cout<<v[N-1]<<endl;
  return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
//#define int __int128
//#define ll __int128
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}

void smain();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

#ifdef RUS_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}
const int oo = 1e9;
const int N = 51;
int MOD = 1e9 + 7;



void smain() {

    int n, l;
    cin >> n >> l;
    int mx = oo, sum = 0;
    for (int i = 1; i <= n; i++) {
        if (abs(l + i - 1) < abs(mx))
            mx = l + i - 1;
        sum += l + i - 1;
    }

    cout << sum - mx;

}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;

void solve() {
  int N;
  cin >> N;
  vi H(N + 1, 0);
  string ans = "Yes";
  for (int i = 1; i < N + 1; i++) {
    cin >> H[i];
    if (H[i] - H[i - 1] == 0) {
      ;
    } else if (H[i] - H[i - 1] > 0) {
      H[i]--;
    } else {
      ans = "No";
    }
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
using namespace std;
typedef long long ll;
const int N=200010;
const ll LINF=1ll<<60;
int n;
ll s[N];
template<class T> void updmin(T &x,T y){
	x=(y<x)?y:x;
}
template<class T> T max(T x,T y){
	return x>y?x:y;
}
template<class T> T min(T x,T y){
	return x<y?x:y;
}
template<class T> T abs(T x){
	return x>=0?x:-x;
}
void readData(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&s[i]);
		s[i]+=s[i-1];
	}
}
void find(int pl,int pr,ll &mn,ll &mx){
	int l=pl,r=pr-1,mid;
	while(l<=r){
		mid=(l+r)>>1;
		if((s[mid]-s[pl-1])>=(s[pr]-s[mid]))
			r=mid-1;
		else 
			l=mid+1;
	}
	ll best=LINF,x,y;
	x=s[l]-s[pl-1];
	y=s[pr]-s[l];
	if(abs(x-y)<best){
		best=abs(x-y);
		mn=min(x,y);
		mx=max(x,y);
	}
	if(l>pl){
		l--;
		x=s[l]-s[pl-1];
		y=s[pr]-s[l];
		if(abs(x-y)<best){
			best=abs(x-y);
			mn=min(x,y);
			mx=max(x,y);
		}
	}
}
void solve(){
	ll ans=LINF;
	ll lmn,lmx,rmn,rmx,cur;
	for(int p=2;p<n;p++){
		find(1,p,lmn,lmx);
		find(p+1,n,rmn,rmx);
		cur=max(lmx,rmx)-min(lmn,rmn);
		updmin(ans,cur);
	}
	printf("%lld\n",ans);
}
int main(){
	readData();
	solve();
	return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int ans = 1000000007;
  for (int p = 1; p <= 100; p++) {
    int tmp = 0;
    for (int i = 0; i < N; i++) {
      tmp += (A.at(i) - p) * (A.at(i) - p);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

lli n;

int main(void){
    cin >> n;
    vector<lli> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i], c[i]*=-1;
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    lli ans = 0;
    rep(i, n){
        lli u = lower_bound(a.begin(), a.end(), b[i])-a.begin();
        lli v = lower_bound(c.begin(), c.end(), -b[i])-c.begin();
        ans += u*v;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5616
s=input()
l=len(s)
mod=10**9+7
dp=[[0]*13 for i in range(l)]
if s[0]=="?":
  dp[0]=[1]*10+[0]*3
else:
  dp[0][int(s[0])]=1
for i in range(1,l):
  if s[i]=="?":
    for j in range(10):
      for k in range(13):
          dp[i][(10*k+j)%13]+=dp[i-1][k]%mod
  else:
    for k in range(13):          
      dp[i][(int(s[i])+10*k)%13]+=dp[i-1][k]%mod

print(dp[-1][5]%mod)


Measured memory_bytes: 61916