akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
N = len(S)

c = Counter(S)
ans = INF
# 出現した文字は1つずつ試す
for k, v in c.items():
    S2 = list(S)
    others = len(S2) - S.count(k)
    cnt = 0
    # 他の文字がなくなるまで処理する
    while others > 0:
        for i in range(len(S2)):
            if i == 0: continue
            # 1つ後ろの文字を変える
            if S2[i] == k:
                if S2[i-1] != k:
                    S2[i-1] = k
                    others -= 1
        if S2[-1] != k:
            others -= 1
        # 削る文字は最後尾でいいと思う
        S2.pop(-1)
        cnt += 1
    # 一番短い処理数で済んだものが答え
    ans = min(cnt, ans)
print(ans)


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

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


#define pb push_back
#define ff first
#define ss second
#define INF int(3e9)
#define BIG_INF ll(9e18)
#define SIZE 200001
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define len(v) int((v).size())
#define BACK(v) ll((v).back())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout);


ll binpow(ll a, ll b, ll MOD = BIG_INF)
{
    ll res = 1;

    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
        a %= MOD;
        res %= MOD;
    }

    return res % MOD;
}

const ll mod = 1e9 + 7;

int T = 1;
int n, m;
ll a[SIZE];

string s;

void solve()
{
    cin >> n;

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

    ll ans = 0;
    ll mx = a[0];
    for(int i = 1; i < n; i++)
    {
        ans += max(a[i - 1] - a[i], 0LL);
        a[i] = max(a[i], a[i - 1]);
    }
    cout << ans;
    return;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//    filein;fileout;
//
//    cin >> T;

    while(T--)
    {
        solve();
    }
    return 0;
}



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

int main(){
  int n,maxnum=1;
  cin>>n;
  for(int i=2;i*i<=n;i++){
    int x=i*i;
    while(x<=n){
      maxnum=max(maxnum,x);
      x*=i;
    }
  }
  cout<<maxnum<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
	public class Main{
		public static void main(String args[]){
			Scanner sc = new Scanner(System.in);
			while(sc.hasNext()){
				int n = sc.nextInt();
				if(n == 0){
					break;
				}
				int num[] = new int[n];
				int max = -1000000000;
				int sum = 0;
				for(int i = 0; i < n ; i++){
					num[i]=sc.nextInt();
					sum = Math.max((sum + num[i]),num[i]);
					max = Math.max(max,sum);
				}
				System.out.println(max);
			}
		}
	}
	

Measured memory_bytes: 34688
#include<iostream>
#include <set>
#include<map>
#include <unordered_map>
#include <vector>

using namespace std;
const int N = 1e5+10;
typedef long long ll;
typedef  pair<ll,ll>PII;



int main(){

        int a,b;
        cin>>a>>b;
        cout<<6-a-b;
    
}

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

using ll = long long;

using namespace std;

int main(){
    ll h;
    cin>>h;
    ll ans_cur = 0;
    ll cnt_cur = 1;
    while(h>1){
        ans_cur += cnt_cur;
        h/=2;
        cnt_cur *=2 ;
    }
    if(h==1){
        ans_cur+=cnt_cur;
    }
    cout<<ans_cur;
    return 0;
}

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

const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.14159265;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

#define cout cout << setprecision(12)

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void dbg(T a) { cout << a << ' '; }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main() {
    cin >> n >> m;
    if (n==m)
    cout << "Yes" << endl;
    else
      dbg("No");
}


Measured memory_bytes: 256
#include <cassert>
#include "limits.h"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;



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

  ll n,w;
  std::cin>>n>>w;

  std::vector<ll> prev(100001,MOD),now(100001,MOD);

  prev[0]=0;

  rep(i,0,n){
    ll a,b;
    std::cin>>a>>b;

    rep(j,0,100001){
      now[j]=prev[j];
      if(j>=b)chmin(now[j],prev[j-b]+a);
    }
    prev=now;
  }

  ll ans=0;
  rep(i,0,100001)if(prev[i]<=w)chmax(ans,i);

  std::cout<<ans<<"\n";

  return 0;
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int match(string s) {
  if(s[0] != s[1] || s[1] != s[2] || s[2] != s[3] || s[3] != s[4] || s[4] != s[5] || s[5] != s[6] || s[6] != s[7] || s[7] != s[8])
   return 0;
  if(s[9] != s[10] || s[10] != s[11]) return 0;
  if(s[12] != s[13] || s[13] != s[14]) return 0;
  if(s[15] != s[16] || s[16] != s[17]) return 0;
  if(s[18] != s[19] || s[19] != s[20]) return 0;
  if(s[21] != s[22] || s[22] != s[23] || s[23] != s[24] || s[24] != s[25] || s[25] != s[26] || s[26] != s[27] || s[27] != s[28] || s[28] != s[29])
   return 0;

  return 1;
}

string lswap(string s) {
  swap(s[0], s[27]);
  swap(s[1], s[28]);
  swap(s[2], s[29]);
  swap(s[14], s[15]);
  swap(s[18], s[20]);
  return s;
}

string rswap(string s) {
  swap(s[6], s[21]);
  swap(s[7], s[22]);
  swap(s[8], s[23]);
  swap(s[12], s[17]);
  swap(s[9], s[11]);
  return s;
}

string uswap(string s) {
  swap(s[2], s[21]);
  swap(s[5], s[24]);
  swap(s[8], s[27]);
  swap(s[11], s[18]);
  swap(s[12], s[14]);
  return s;
}

string sswap(string s) {
  swap(s[0], s[23]);
  swap(s[3], s[26]);
  swap(s[6], s[29]);
  swap(s[9], s[20]);
  swap(s[15], s[17]);
  return s;
}

int solve(string s, int c, int i) {
  if(match(s) || c >= 8) return c;
  int a = 8, b = 8, d = 8, e = 8;
  if(i != 1) a = solve(lswap(s), c + 1, 1);
  if(i != 2) b = solve(rswap(s), c + 1, 2);
  if(i != 3) d = solve(uswap(s), c + 1, 3);
  if(i != 4) e = solve(sswap(s), c + 1, 4);

  return min(min(a, b), min(d, e));
}

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

  rep(i, 0, n) {
    string a, s = "";
    rep(i, 0, 30) {
      cin >> a;
      s += a;
    }
    cout << solve(s, 0, 0) << endl;
  }
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main(){

    int n, m; cin >> n >> m;
    int ans;
    ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans << endl;

}


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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> V(N);
	for (int i = 0; i < N; i++)
	{
		cin >> V[i];
	}
	vector<int> C(N);
	for (int i = 0; i < N; i++)
	{
		cin >> C[i];
	}
	
	int X = 0;
	int Y = 0;
	int answer = 0;
	for (int i = 0; i < N; i++)
	{
		if (V[i] - C[i] > 0)
		{
			X += V[i];
			Y += C[i];
		}
	}
	
	answer = X - Y;
	
	// 出力
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    cout << (n+1) / 2 << endl;
    
}




Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};

const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};


ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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 comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/

ll N;
string S;
ll dp[5010][5010];
int main(){
  cin >> N >> S;
  ll sl = S.size();
  dp[0][0] = 1;
  for(ll i = 1; i <= N; i++){
    for(ll j = 0; j < 5005; j++){
      if(j == 0) dp[i][j] = (dp[i-1][j+1] + dp[i-1][j]) % MOD;
      else dp[i][j] = (dp[i-1][j+1] + dp[i-1][j-1] * 2) % MOD;
    }
  }
  ll ans = dp[N][sl] * inverse(pow_mod(2, sl)) % MOD;
  cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll x;
  cin >> x;
  cout << lcm(x, 360) / x << endl;

  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL D;cin >> D;
    vector<LL> c(26);rep(i,26)cin >> c[i];
    vector<vector<LL>> s(D,vector<LL>(26));
    rep(i,D)rep(j,26)cin >> s[i][j];
    vector<LL> t(D);
    rep(i,D)cin >> t[i];
    map<LL,LL> m;
    LL ans = 0;
    rep(i,D){
        LL now_day = i+1;
        LL score = 0;
        m[t[i]-1] = now_day;
        rep(j,26){
            LL last = m[j];
            LL tmp = now_day - last;
            tmp *= c[j];
            score += tmp;
        }
        ans += s[i][t[i]-1];
        ans -= score;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3724
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

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

Measured memory_bytes: 256
n = int(input())
dp = [n] * (n + 1)
dp[0] = 0
a = [1, 6**1, 6**2, 6**3, 6**4, 6**5, 6**6, 9**1, 9**2, 9**3, 9**4, 9**5]
for i in range(1, n + 1):
    for j in a:
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + 1)
print(dp[n])

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

int
main ()
{
  string s, t ="CODEFESTIVAL2016"; cin >> s;
  int ans = 0;
  rep(i, s.size()){
      if(s.at(i) != t.at(i)) ans++; 
  }
  cout << ans << endl;
  return 0;
}


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

// using mint = modint1000000007;
// using mint = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

// mod付きコンビネーション
const int MAX = 1100000;
const int MOD = 1000000007;

Int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 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;
    }
}

// 二項係数計算
Int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve() {
    COMinit();
    Int s;
    cin >> s;
    Int res = 0;
    for (Int i = 1; i * 3 <= s; i++) {
        Int add = fac[s - i * 3 + i - 1];
        add = add * finv[s - i * 3] % mod;
        add = add * finv[i - 1] % mod;
        res = (res + add) % mod;
    }
    print(res);
}

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


Measured memory_bytes: 29420
def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(N):
        x, y, z = map(int, input().split())
        l.append((x,y,z))
    r = 0
    l2 = [i+j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [i+j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [i-j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [i-j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i+j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i+j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i-j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i-j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    return r
print(main())


Measured memory_bytes: 41040
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	
	for(int i = 1; i <= n; i++) {
		if(i * 108 / 100 == n) {
			printf("%d\n", i);
			return 0;
		}
	}
	printf(":(\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

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

int N;
int H,W;
map<char, int>m;
int kind;
char obj[8];
vector<string>p;
pipi pi[8]; // miny, maxy, minx, maxx

int judge(vector<string>s){ return s==p; }

int dfs(int n, int bit, vector<string>s){
  if(n==kind) return judge(s);

  rep(i,kind){
    if((bit>>i)&1) continue;
    for(int y=pi[i].Fi.Fi;y<=pi[i].Fi.Se;y++) for(int x=pi[i].Se.Fi;x<=pi[i].Se.Se;x++) s[y][x] = obj[i];
    if(dfs(n+1, bit | (1<<i), s)) return 1;
    for(int y=pi[i].Fi.Fi;y<=pi[i].Fi.Se;y++) for(int x=pi[i].Se.Fi;x<=pi[i].Se.Se;x++) s[y][x] = '.';
  }
  return 0;
}

string dot(int w){
  string res="";
  rep(i,w) res += ".";
  return res;
}

int main(){
  cin >> N;
  while(N--){
    kind=0;
    rep(i, 8) pi[i] = MP(MP(64,-1),MP(64,-1));
    m.clear();
    cin >> H >> W;
    p.resize(H);
    rep(i,H) cin >> p[i];

    rep(i,H) rep(j,W){
      if(p[i][j]=='.') continue;
      if(m.find(p[i][j]) == m.end()){
	m[p[i][j]] = kind;
	obj[kind] = p[i][j];
	kind++;
      }

      int pos = m[p[i][j]];
      pi[pos].Fi.Fi = min(pi[pos].Fi.Fi, i); pi[pos].Fi.Se = max(pi[pos].Fi.Se, i);
      pi[pos].Se.Fi = min(pi[pos].Se.Fi, j); pi[pos].Se.Se = max(pi[pos].Se.Se, j);
    }

    if(!kind) cout << "SAFE\n";
    else{
      vector<string>s(H, dot(W));
      if(dfs(0, 0, s)) cout << "SAFE\n";
      else cout << "SUSPICIOUS\n";
    }
  }
  return 0;
}

Measured memory_bytes: 1296
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
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 end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,M;
    in >> N >> M ;
    ll c = 0, a= 0;
    double b;
    vector<ll> A(N);
    REP(i, N){
        in >> A[i];
        c+=A[i];
    }


    REP(i, N){
        if(A[i]*4*M>=c) a++;
    }
    if(a>=M){
        out << "Yes"  << endl;
    }else{
        out << "No"  << endl;
    }
    //string s;
    //in >> s;
    //vector<string> s;
    //s.resize(N);


    

    
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, K: int, V: "List[int]"):
    a = 0
    answer = []
    reverse_V = V[::-1]
    for i in range(1,min(N,K)+1): ##iコまで宝石をとる
        for left in range(i+1): ##左からleftこ
            right = i-left
            if left>0 and right>0:
                answer =  V[:left]+reverse_V[:right]
            elif left>0:
                answer = V[:left]
            elif right>0:
                answer = V[:right]
            else:
                answer = []
            answer.sort()
            zero_index = bisect.bisect_left(answer,0)
            # 小さいものからK-iこすてる
            answer = answer[min(zero_index,K-i):]
            a = max(a,sum(answer))
    
    print(a)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, V)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40944
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
using namespace std;

int main(){
    int N,M,sum=0,p,x;
    cin >> N;
    vector<int> t(N);
    for(int i=0;i<N;i++){
        cin >> t[i];
        sum += t[i];
    }
    cin >> M;
    for(int i=0;i<M;i++){
        cin >> p >> x;
        cout << sum-(t[p-1]-x) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<long long> > a(n, vector<long long>(m));
  vector<vector<long long> > b(m, vector<long long>(l));
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<l;j++){
      cin >> b[i][j];
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      long long sum = 0;
      for(int k=0;k<m;k++){
        sum += a[i][k] * b[k][j];
      }
      cout << sum;
      if(j!=l-1)cout << " ";
    }
    cout << endl;
  }



  return 0;
}

Measured memory_bytes: 1380
#include <stdio.h>
int main(void){
    // Your code here!
    char s[7];
    scanf("%s\n",s);
    switch(s[0])
    {
        case 'S': printf("Cloudy\n"); break;
        case 'C': printf("Rainy\n"); break;
        case 'R': printf("Sunny\n"); break;
    }
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    print(N-K+1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int h, w;
	char s[105][105], c;
	int a[105][105];
	scanf("%d %d\n", &h, &w);
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			scanf("%c", &s[i][j]);
		}
		scanf("%c", &c);
	}
	a[1][1] = (s[1][1] == '#');
	for (int i = 2; i <= h; i++) {
		a[i][1] = a[i - 1][1] + (s[i][1] == '#' && s[i - 1][1] == '.');
	}
	for (int j = 2; j <= w; j++) {
		a[1][j] = a[1][j - 1] + (s[1][j] == '#' && s[1][j - 1] == '.');
	}
	for (int i = 2; i <= h; i++) {
		for (int j = 2; j <= w; j++) {
			a[i][j] = min(a[i - 1][j] + (s[i][j] == '#' && s[i - 1][j] == '.'), a[i][j - 1] + (s[i][j] == '#' && s[i][j - 1] == '.'));
		}
	}
	printf("%d", a[h][w]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
using namespace std;
signed main(){
	int n,k,ans=0;
	cin >> n >> k;
	vector<int> x(n);
	vector<int> y(n);
	REP(i,n){
		cin >> x[i];
		y[i] = k-x[i];
		ans += min(y[i],x[i]);
	}
	cout << ans*2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
string N; cin >> N; N="0"+N; int i, p=0, L=N.size(), ans=0, nw, h;  
for(i=L-1; i>0; i--){ 
nw=(N[i]-'0')+p;
if(nw==5){ ans+=5; if((N[i-1]-'0')>=5){ p=1; }else{ p=0; } }
else if(nw<5){ ans+=nw; p=0; }else{ h=10-nw; ans+=h; p=1; }
}
if(p==1){ans++;}
cout << ans << "\n";
}

Measured memory_bytes: 2308
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }

const ll MOD = 998244353;
const ll inf = 1e18;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll n, s;
    cin >> n >> s;
    vll a(n);
    REP(i, n) cin >> a[i];

    // dp[i + 1][j] : [x ^ j](2 + x ^ a[1])(2 + x ^ a[2])...(2 + x ^ a[i])
    // 遷移 : 暫定項に (2 + x ^ a[i]) を掛けていく
    vvll dp(n + 1, vll(s + 1));
    dp[0][0] = 1;
    REP(i, n) {
        REP(j, s + 1) {
            dp[i + 1][j] += 2 * dp[i][j];
            dp[i + 1][j] %= MOD;
            if (j + a[i] <= s) {
                dp[i + 1][j + a[i]] += dp[i][j];
                dp[i + 1][j + a[i]] %= MOD;
            }
        }
    }
    cout << dp[n][s] << endl;
    return 0;
}

Measured memory_bytes: 73640
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a , b , c;
    cin >> a >> b >> c;
    a -= c;
    cout << a / ( b + c);
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
typedef long long ll;
using namespace std;


int main() {
    ll n, m, minim=-1, maxim=-1, l, r, i;
    cin>>n>>m;
    for(i=1;i<=m;i++){
        cin>>l>>r;
        if(minim==-1||l>minim)
            minim=l;
        if(maxim==-1||r<maxim)
            maxim=r;
    }
    if(maxim<minim)
        cout<<"0"<<endl;
    else
        cout<<maxim-minim+1<<endl;
	return 0;
}


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

#define int long long
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; }

signed main(){
	int n, k;
	cin >> n >> k;
	int tmp = n % k;
	cout << min(tmp, k-tmp) << endl; 
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int f[10010];

void solve() {
    for (int x = 1; x <= 100; x++) {
        for (int y = 1; y <= 100; y++) {
            for (int z = 1; z <= 100; z++) {
                const int v = x*x+y*y+z*z+x*y+y*z+z*x;
                if (v <= n) {
                    f[v]++;
                }
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << f[i] << endl;
    }
}

void input() {
    cin >> n;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


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

using namespace std;

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

  vector<vector<int>> x(n + 1);
  vector<vector<int>> y(n + 1);
  vector<int> a(n + 1);

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

    x[i].resize(a[i] + 1);
    y[i].resize(a[i] + 1);
    for (int j = 1; j <= a[i]; j++)
    {
      cin >> x[i][j] >> y[i][j];
    }
  }

  int ans = 0;
  for (int mask = 1; mask < (1 << n); mask++)
  {

    bool ok = true;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
      if (!(mask & (1 << (i - 1))))
      //   if (!(mask >> (i - 1) & 1))
      {
        continue;
      }
      cnt++;
      for (int j = 1; j <= a[i]; j++)
      {
        // x[i][j]-1番目の人が正直ならビットは1なはず
        if (((mask >> (x[i][j] - 1)) & 1) ^ y[i][j])
        {
          ok = false;
        }
      }
    }

    if (ok)
    {
      ans = max(ans, cnt);
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <iomanip>

int main()
{
	std::cout << std::fixed;
	int N = 0;
	double ans = 0, B = 0;
	std::cin >> N;

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

	for (int i = 0; i < N; i++){
		std::cin >> A[i];
		B += 1 / A[i];
	}
	
	ans = 1 / B;
	std::cout << std::setprecision(6) << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> a >> b >> c;
	if (c > a&& c < b)
		cout << "Yes" << endl;
	else if (c<a && c>b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static int h;
    private static int w;
    private static String c[][];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        h = sc.nextInt();
        w = sc.nextInt();
        c = new String[h][w];

        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                c[i][j] = str.substring(j, j + 1);
            }
        }

        DepthFirstSearch dfs = new DepthFirstSearch(h, w, c);

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if(c[i][j].equals("#")){
                    if(! dfs.search(i,j)){
                        System.out.println("No");
                        return;
                    }

                }
            }
        }

        System.out.println("Yes");
        return;
    }


    static class DepthFirstSearch {
        int h;
        int w;
        String[][] c;

        DepthFirstSearch(int h, int w, String[][] c) {
            this.h = h;
            this.w = w;
            this.c = c;
        }

        boolean search(int x, int y) {
            if(check(x + 1, y)){
                return true;
            }
            if(check(x - 1, y)){
                return true;
            }
            if(check(x, y + 1)){
                return true;
            }
            if(check(x, y - 1)){
                return true;
            }
            return false;
        }

        boolean check(int x, int y){
            if (x < 0 || h <= x || y < 0 || w <= y || c[x][y].equals(".")) {
                return false;
            }
            if(c[x][y].equals("#")){
                return true;
            }

            return false;
        }
    }

}


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

#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 ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 100100;

typedef vector<VI> matr;

matr get(int n)
{
	return matr(n, VI(n, 0));
}

matr mul(matr a, matr b)
{
	matr res = get(SZ(a));
	FOR (i, 0, SZ(a))
	{
		FOR (j, 0, SZ(a))
		{
			FOR (k, 0, SZ(a))
			{
				res[i][j] = (res[i][j] + a[i][k] * (LL)b[k][j]) % MOD;
			}
		}
	}

	return res;
}

VI mul(matr a, VI v)
{
	VI res(SZ(v));
	FOR (i, 0, SZ(v))
	{
		FOR (j, 0, SZ(v))
		{
			res[i] = (res[i] + a[i][j] * (LL)v[j]) % MOD;
		}
	}

	return res;
}

matr bpow(matr a, int b)
{
	matr res = get(SZ(a));
	FOR (i, 0, SZ(a))
	{
		res[i][i] = 1;
	}

	while(b)
	{
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b /= 2;
	}

	return res;
}

int A[MAX];

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;
	scanf("%d%d", &n, &m);
	FOR (i, 0, m)
	{
		scanf("%d", &A[i]);
	}

	A[m] = n;
	m++;

	int prev = 0;
	VI v(4);
	v[0]++;

	matr a = get(4);
	a[0][0]++;
	a[0][3]++;

	a[1][0]++;
	a[1][1]++;
	a[1][3]++;

	a[2][0]++;
	a[2][2]++;
	a[2][3]++;

	a[3][0]++;
	a[3][1]++;
	a[3][2]++;
	a[3][3]++;
	a[3][3]++;

	matr b = a;
	b[0][3]--;
	b[1][3]--;
	b[2][3]--;
	b[3][3]--;

	FOR (i, 0, m)
	{
		int cur = A[i];
		int len = cur - prev;

		matr z = bpow(a, len - 1);
		z = mul(z, b);
		v = mul(z, v);
		prev = cur;
	}

	int res = v[3];
	cout<<res<<endl;
}


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

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

	vector<ll> sprine(a);
	vector<ll> temples(b);

	for(int i = 0; i < a; i++) cin>>sprine[i];
	for(int i = 0; i < b; i++) cin>>temples[i];

	sprine.push_back(-1e17);
	temples.push_back(-1e17);
	sprine.push_back(1e17);
	temples.push_back(1e17);

	
	sort(sprine.begin(),sprine.end());
	sort(temples.begin(),temples.end());


	for(int i = 0; i < q; i++){
		ll q;cin>>q;

		ll s = lower_bound(sprine.begin(),sprine.end(),q) - sprine.begin();
		ll t = lower_bound(temples.begin(),temples.end(),q) - temples.begin();

		ll rs = sprine[s] - q;
		ll rt = temples[t] - q;

		ll ls = q - sprine[s-1];
		ll lt = q - temples[t-1];

		ll ans = 1e18;
		ans = min(ans,max(rs,rt));
		ans = min(ans, max(ls,lt));
		ans = min(ans, rs+lt+min(rs,lt));
		ans = min(ans, ls+rt+min(ls,rt));
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 2912
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> m(N, vector<int>(N, 0));
    for(int i = 0; i < M; i++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        m[l][r]++;
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(i > 0) m[i][j] += m[i - 1][j];
            if(j > 0) m[i][j] += m[i][j - 1];
            if(i > 0 && j > 0) {
                m[i][j] -= m[i - 1][j - 1];
            }
        }
    }
    for(int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        int ans = 0;
        ans += m[r][r];
        if(l > 0) {
            ans -= m[l - 1][r] + m[r][l - 1];
            ans += m[l - 1][l - 1];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;

int calc(int a, int b) {
	if (b == 0)return 1;
	if (b % 2 == 0) {
		return (calc(a, b / 2)*calc(a, b / 2)) % MOD;
	}
	return (a*calc(a, b - 1)) % MOD;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int now = 0;
	int ans = 0;
	vector<int>tmp(n+1);
	tmp[0] = 1; tmp[1] = 1;
	rep(i, n + 1) {
		if (i == 0 || i == 1)continue;
		tmp[i] = (tmp[i - 1] * i) % MOD;
	}
	VE a(n); rep(i, n)cin >> a[i];
	rep(i, n) {
		if (i == 0)continue;
		int cnt = (tmp[n - 1] * calc(i, MOD - 2)) % MOD;
		now = (now + cnt) % MOD;
		ans = (ans + now * (a[i] - a[i - 1])) % MOD;
	}
	cout << ans % MOD << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    long long a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    cout << a[n-1];
    double x = a[n-1] / 2.0;
    int index=0;
    for(;index<n; index++){
        if((double)a[index] > x) break;
    }
    if(index == 0) cout << ' ' << a[index] << endl;
    else {
        long long  y = a[index], z = a[index-1];
        if(abs(x - (double)y) < abs(x - (double)z)) cout << ' ' << y << endl;
        else cout << ' ' << z << endl;
    }
    return 0;
}



Measured memory_bytes: 1024
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	int n;
	cin >> n;
	int c = 1;
	while (c*(c + 1) / 2 < n) {
		c++;
	}
	int diff = c*(c+1)/2 - n;
	IFOR(i, 1, c) {
		if (i != diff) {
			cout << i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
//
//  main.c
//  Print a Chessboard
//
//  Created by 曾億宜 on 2019/10/6.
//  Copyright © 2019 曾億宜. All rights reserved.
//

#include <stdio.h>

 int main()
{
     int h, w, i, j;
     while(1)
{
         scanf("%d %d ", &h, &w);
         if(h == 0 && w == 0)
         break;
         for(i = 0;i < h; i++)
       {
             for(j=0;j<w;j++)
            {
                 if((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
                   {
                     printf("#");
                    }
                  else
                    {
                     printf(".");
                    }
             }
             printf("\n");
         }
         printf("\n");
  }
     return 0;
 }



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

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll a, b, c;
    cin >> a >> b >> c;

    ll mi = min(a+b, b+c);
    mi = min(mi, c+a);

    p(mi);
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
 
using namespace std;
 
int main() {
 
    long long int x, y, i = 1;
    int flag = 0;
    cin >> x >> y;
 
    while(i <= x || i <= y){
 
        if (abs(x - i) == abs(y - i)) {
            flag = 1;
            break;
        }
 
        i++;
    }
 
    if(!flag)
        cout << "IMPOSSIBLE" << endl;
    else
        cout << i << endl;
 
    return 0;
}


Measured memory_bytes: 256