akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(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 &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 INF = 1LL << 60;
int main(){
    ll a,b,k; cin >> a >> b >> k;
    while(a>0 || b>0){
        if(a>0){
            if (a>=k){
                a-=k;
                cout << a << " " << b << endl;
                return 0;
            }else{
                k-=a;
                a=0;
            }
        }else if(b>0){
            if (b>=k){
                b-=k;
                cout << a << " " << b << endl;
                return 0;
            }else{
                b=0;
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int main(void) {
    int i, n, p[20], ans=0;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (i = 0; i < n-2; i++) {
        if ((p[i] < p[i+1] && p[i+1] < p[i+2]) ||
            (p[i] > p[i+1] && p[i+1] > p[i+2])) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    while(1){
        int N;
        cin>>N;
        if(cin.eof())return 0;

        while(N--){
            int x,y,z;
            cin>>x>>y>>z;
            if((x*x+y*y)==(z*z)||(x*x+z*z)==(y*y)||(y*y+z*z)==(x*x))cout<<"YES\n";
            else cout<<"NO\n";
        }
    }
}

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

int main(void){
    int h,w,k;cin >> h >> w >> k;
    char c[h][w];
    rep(i,h){
        rep(j,w)cin >> c[i][j];
    }
    int sum = 0;
    for(int i = 0;i < (1 << h);i++){
        for(int j = 0;j < (1 << w);j++){
            int ans = 0;
            rep(p,h){
                if(i & (1 << p))continue;
                rep(q,w){
                    if(j & (1 << q))continue;
                    if(c[p][q] == '#')ans++;
                }
            }
            if(ans == k)sum++;
        }
    }
    cout << sum << endl;
}

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

#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vec;
typedef vector<pll> vecp;
typedef map<ll, ll> mpll;


const int N = 1e5 + 10;
const ll INF = 1LL << 60;

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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << endl;
  debug_out(T...);
}
#define LOCAL 3
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


void solve()
{
	ll n, m;
	cin>>n>>m;
	if(n == m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


int main()
{
	ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
    	solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#include<cmath>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int N;
    int v[20],c[20];
    cin >> N;
    int sum = 0;
    for(int i = 0; i < N; i++) cin >> v[i];
    for(int i = 0; i < N; i++) cin >> c[i];
    for(int i = 0; i < N; i++){
        if(v[i] - c[i] > 0) sum += v[i]-c[i];
    }
    cout << sum << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

class vertex{
public:
    int id;
    int parent = -1;
    int left = -1;
    int right = -1;
};
bool operator<(const vertex &a, const vertex &b){
    return a.id<b.id;
}

void preorder(vertex *v, int i){
    cout << " " << v[i].id;
    if(v[i].left>=0) preorder(v, v[i].left);
    if(v[i].right>=0) preorder(v, v[i].right);
}
void inorder(vertex *v, int i){
    if(v[i].left>=0) inorder(v, v[i].left);
    cout << " " << v[i].id;
    if(v[i].right>=0) inorder(v, v[i].right);
}
void postorder(vertex *v, int i){
    if(v[i].left>=0) postorder(v, v[i].left);
    if(v[i].right>=0) postorder(v, v[i].right);
    cout << " " << v[i].id;
}

int main(){
    int n;
    vertex v[25];
    cin >> n;
    for(int i=0;i<n;i++){
        int id, l, r;
        cin >> id >> l >> r;
        v[i].id=id;
        v[i].left=l;
        v[i].right=r;
    }
    sort(v, v+n);
    for(int i=0;i<n;i++){
        int l = v[i].left;
        int r = v[i].right;
        if(l>=0){
            v[l].parent=i;
        }
        if(r>=0){
            v[r].parent=i;
        }
    }

    int p;
    for(int i=0;i<n;i++){
        if(v[i].parent<0){
            p=i;
            break;
        }
    }

    cout << "Preorder" << endl;
    preorder(v, p);
    cout << endl;

    cout << "Inorder" << endl;
    inorder(v, p);
    cout << endl;

    cout << "Postorder" << endl;
    postorder(v, p);
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3112
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

ll a[10][10];

int main() {
	IOS();
	ll l, r;
	cin >> l >> r;
	if (r >= l + 2019) {
		dump(0);
		return 0;
	}
	l %= 2019;
	r %= 2019;
	if (l > r) {
		dump(0);
		return 0;
	}
	ll ans = 2018;
	for (ll i = l; i <= r; i++) {
		for (ll j = i + 1; j <= r; j++) {
			ans = min(ans, (i * j) % 2019);
		}
	}
	dump(ans);
	return 0;
}


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

int N, W;
int _dp[110][10010];
int v[110];
int w[110];

int dp(int num,int weight){
	if(_dp[num][weight]) return _dp[num][weight];
	if(num == 0 || weight == 0){
		return 0;
	}
	int max = dp(num-1,weight);
	if(weight >= w[num-1]){
		int t = dp(num,weight-w[num-1])+v[num-1];
		if(max < t) max = t;
	}
	_dp[num][weight] = max;
	return max;
}

int main(void){
	cin >> N >> W;
	
	for(int i=0; i<N; i++) cin >> v[i] >> w[i];
	
	cout << dp(N,W) << endl;
	
	return 0;
}


Measured memory_bytes: 7536
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(int  i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

using namespace std;

int main() 
{
    int n; cin >> n;
    vector<int> c(n,0), s(n,0), f(n,0);

    rep(i,n-1) { cin >> c[i] >> s[i] >> f[i]; }
    
    for(int i = 0; i < n; i++) { 
        int next = c[i] + s[i];
        for(int j = i+1; j < n-1; j++) {
            if(next <= s[j]) {
                next = s[j] + c[j];
            } else {
                int train = s[j];
                while(next > train) {
                    train += f[j];
                }
                next = train + c[j];
            }
        }
        cout << next << endl;
    }

    return 0;
}
    



Measured memory_bytes: 256
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n = inl();
        vl a(n);
        rep(i, n) cin >> a[i];
//
//        ll dp[n + 1][2]; // -1する/しない
//        dp[0][0] = 0;
//        dp[0][1] = 0;
//        rep(i, n + 1) rep(j, 2) dp[i][j] = 0;
//
//        rep(i, n) {
//            dp[i + 1][0] = max({dp[i + 1][0], dp[i][0] + a[i], dp[i][1] + a[i]});
//            dp[i + 1][1] = max({dp[i + 1][1], dp[i][0] + a[i], dp[i][1] + a[i]});
//            if (i <= n - 2) {
//                dp[i + 2][0] = max(
//                        {dp[i + 2][0], dp[i][1] - a[i] - a[i + 1], dp[i][0] - a[i] - a[i + 1]});
//            }
//        }
//        cout << max(dp[n][0], dp[n][1]) << endl;
        ll c = 0;
        rep(i, n) {
            if (a[i] < 0) c++;
            if (a[i] == 0) {
                c = 0;
                break;
            }
        }
        ll ans = 0;
        if (c % 2 == 0) {
            rep(i, n) ans += abs(a[i]);
        } else {
            ll max_mi = ll_inf;
            rep(i, n) {
                max_mi = min(max_mi, abs(a[i]));
            }
            bool b = false;
            rep(i, n) {
                if (!b && abs(a[i]) == max_mi) ans -= abs(a[i]), b = true;
                else ans += abs(a[i]);
            }
        }
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vi>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _per(i, n) peri(i, 0, n)
#define peri(i, a, n) for (int i = (n) - 1; i >= (a); --i)
#define per(...) _overload3(__VA_ARGS__, peri, _per)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void chmax(T& a, const T& b) {if (a < b) a = b;}
template<typename T> inline void chmin(T& a, const T& b) {if (a > b) a = b;}
template<typename T> inline void print(const T& x) {cout << x << "\n";}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) {is >> p.fi >> p.se; return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {os << p.fi << " " << p.se; return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v) {each(in, v) is >> in; return is;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {rep(i, sz(v)) {os << v[i] << (i + 1 != sz(v) ? " " : "");} return os;}
struct Init {Init() {ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10);}} init;

int main() {
    int k;
    string s;
    cin >> k >> s;
    if (sz(s) <= k) print(s);
    else print(s.substr(0, k) + "...");
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int d, n;
	cin >> d >> n;
	if (n == 100)n++;
	cout << n * (int)pow(100, d) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 5e5 + 5;
int n, a[M];

int32_t main() 
{
	ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
	cin >> n;
	unordered_map <int, int> mp;
	int sum = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		mp[a[i]]++;
		sum += a[i];
	}
	int q;		cin >> q;
	while(q--)
	{
		int b, c;	cin >> b >> c;
		if(mp.find(b) != mp.end())
		{
			sum -= b * mp[b];
			sum += c * mp[b];
			mp[c] += mp[b];
			mp.erase(b);
		}
		cout << sum << "\n";
	}
    	return 0;
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int res = a-b+1;
  if(res%2==0) puts("Borys");
  else puts("Alice");
  return 0;
}


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

int main()
{
    int a,b,c,d,e,f,g,h,i,j;
    int ar[3];
    for(i=1; i<=3; i++)
    {
        cin>>ar[i];
    }
    sort(ar+1,ar+4);

    c=ar[3]-ar[2];
    int ans=c;
    ar[1]+=c;
    ar[2]+=c;
    if((ar[2]-ar[1])%2)
    {
        ans+=(ar[2]-ar[1])/2+2;
    }
    else
    {
        ans+=(ar[2]-ar[1])/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rep1(i,n) for(int (i)=1;(i)<(int)(n)+1;(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;


struct Mahou{
    int at;
    int mp;
};

int main(){
    cin.tie( 0 ); 
    ios::sync_with_stdio( false );
    int h,n;
    cin >> h >> n;
    Mahou mahou[n+1]={};
    rep1(i,n) cin >> mahou[i].at >> mahou[i].mp;
    vector<vector<int>> dp(n+1,vector<int>(h+1,inf+1));
    rep(i,n+1) dp[i][0]=0;
    rep1(i,n){
        rep1(j,h){
            dp[i][j]=min(dp[i-1][j],dp[i][max(0,j-mahou[i].at)]+mahou[i].mp);
            //cout <<"i:"<<i<<" attack:"<<j<<" minmp;"<< dp[i][j]<<endl;
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

Measured memory_bytes: 39424
N = int(input())
Alist = [int(i) for i in input().split()]
Blist = [int(i) for i in input().split()]
Clist = [int(i) for i in input().split()]

satisfied = 0
for i in range(N):
    A = Alist[i]-1
    satisfied += Blist[A]
    if i>=1 and Alist[i] == Alist[i-1]+1:
        satisfied += Clist[Alist[i-1]-1]

print(satisfied)




Measured memory_bytes: 3064
def mark_zero1(s):
    index = [i for i, s_ in enumerate(s) if s_ == "0" and safe_get(s, i - 1) != "0"]
    return index


def mark_zero2(s):
    index = [i for i, s_ in enumerate(s) if s_ == "0" and safe_get(s, i + 1) != "0"]
    return index


def safe_get(lis, index):
    if index < 0:
        return -1
    elif index >= len(lis):
        return len(s)
    else:
        return lis[index]


def get_score(a, b, i, j):
    return safe_get(a, j + 1) - safe_get(b, i - 1) - 1


n, k = list(map(int, input().split(" ")))
s = input()
a = mark_zero1(s)
b = mark_zero2(s)


try_num = min(len(a), k)
ij_list = [(idx, idx + try_num - 1) for idx in range(len(a) - try_num + 1)]

print(max([get_score(a, b, i, j) for i, j in ij_list]))


Measured memory_bytes: 14284
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    string s;
    cin>>s;
    ll c=0;
    for(ll i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]=='0') c++;
        }else{
            if(s[i]=='1') c++;
        }
    }
    cout<<min(c,(ll)s.size()-c)<<endl;
    return 0;
}

Measured memory_bytes: 512
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

data = l()

su = sum(data)

po = onem()

for i in range(po):
    a,b = m()
    a -= 1
    print(su + b - data[a])


Measured memory_bytes: 67372
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<vi>F(n, vi(10));
	rep(i, n) {
		rep(j, 10) {
			cin >> F[i][j];
		}
	}
	vector<vi>P(n, vi(11));
	rep(i, n) {
		rep(j, 11) {
			cin >> P[i][j];
		}
	}
	
	ll count = -1e9;
	int i = 1;
	while (i < pow(2, 10)) {
		vector<int>C(n);
		rep(k, 10) {
			if (i&(1 << k)) {
				rep(j, n) {
					if (F[j][k] > 0) {
						C[j]++;
					}
				}
			}
		}
		ll tmp = 0;
		bool flag = 0;
		rep(i, n) {
			tmp += P[i][C[i]];
		//	cout <<"i "<<i<< " c " << C[i] << endl;
		//	cout << P[i][C[i]] << endl;
		}
		//cout << tmp << endl;
		count = max(count, tmp);
	
		i++;
	}
	cout << count << endl;
}



Measured memory_bytes: 256
from fractions import gcd
from functools import reduce
n=int(input())
t=[]
for _ in range(n):
    a=int(input())
    t.append(a)
def lcm_base(x,y):
    return (x*y // gcd(x,y))
def lcm_list(l):
    return reduce(lcm_base,l,1)
print(lcm_list(t))

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

struct SegmentTree {
    int n;
    vector<ll> node;

    SegmentTree(int _n, ll v = -1e18) {
        n = 1;
        while (n < _n)
            n *= 2;
        node.resize(2 * n - 1, v);
    }
    SegmentTree(vector<ll> a, ll v = -1e18) {
        n = 1;
        while (n < a.size())
            n *= 2;
        node.resize(2 * n - 1, v);
        for (int i = 0; i < a.size(); i++)
            node[i + n - 1] = a[i];
        for (int i = n - 2; i >= 0; i--)
            node[i] = max(node[2 * i + 1], node[2 * i + 2]);
    }

    void update(int k, ll v) {
        k += n - 1;
        node[k] = max(node[k], v);
        while (k > 0) {
            k = (k - 1) / 2;
            node[k] = max(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    ll get(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)
            return -1e18;
        if (a <= l && r <= b)
            return node[k];
        ll vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
        ll vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
    ll get(int a, int b) {
        return get(a, b, 0, 0, n);
    }
};

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

    int n;
    cin >> n;
    SegmentTree seg(n + 1);
    seg.update(0, 0);
    vector<ll> a(n), h(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> h[i];

    rep(i, 0, n) {
        ll mx = seg.get(0, a[i]);
        seg.update(a[i], h[i] + mx);
    }
    cout << seg.get(0, n + 1) << endl;

    return 0;
}

Measured memory_bytes: 7552
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll h,w,n;
  cin>>h>>w>>n;
  ll mx=max(h,w);
  cout<<(n+mx-1)/mx<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        if (ab.Sum() == 15) Console.WriteLine("+");
        else if (ab[0] * ab[1] == 15) Console.WriteLine("*");
        else Console.WriteLine("x");
    }
}


Measured memory_bytes: 13268
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
l, r = 0, 0
for i in range(x):
    if i in a:
        l += 1
for i in range(x+1, n+1):
    if i in a:
        r += 1
print(min(l, r))


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define rep(i,n) for (i=1;i<=(n);++i)
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
	HWND hwndFound;         // This is what is returned to the caller.
	char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
	char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
	ULARGE_INTEGER nt;
	nt.QuadPart = GetTickCount64();
	GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
	wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart, GetCurrentProcessId());
	SetConsoleTitle(pszNewWindowTitle);
	Sleep(40);
	hwndFound = FindWindow(NULL, pszNewWindowTitle);
	SetConsoleTitle(pszOldWindowTitle);
	return(hwndFound);
}
#endif
int mod = 1e9 + 7;
int main()
{
	static ll n, a[100000 + 10], b[100000 + 10];
	ll i, j, k,ans=0;
	cin >> n;
	for (i = 1; i <= n+1; i++)
	{
		cin >> a[i];
	}
	for (i = 1; i <= n; i++)
	{
		cin >> b[i];
	}
	for (i = 1; i <= n; i++)
	{
		if (a[i] <= b[i])
		{
			ans += min(b[i], a[i] + a[i + 1]);
			a[i + 1] = max(0ll,a[i+1]-(b[i] - a[i]));
		}
		else {
			//a>b
			ans += b[i];
			a[i] -= b[i];
		}
		//cout << ans << endl;
	}
	cout << ans << endl;
}


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

using namespace std;
using ll = long long;

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

const ll INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    ll dp[100010];
    for (int i = 0; i <= n; i++) dp[i] = INF;
    dp[0] = 0;

    for (int i = 0; i < n; i++) {
        if (i + 1 < n) chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        if (i + 2 < n) chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 4416
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 998244353 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 300010


ll factmemo[SIZE];
ll factmemoMod = -1;
void initFactorial(int n, int M){
  factmemoMod = M;
  factmemo[0] = 1;
  for(int i=1;i<=n;i++) factmemo[i] = (factmemo[i-1] * i)%M;
}

ll factorial(int n,int M){
  if(factmemoMod == M) return factmemo[n];
  
  ll ret=1;
  if(n<=1) return 1;
  
  for(int i=1;i<=n;i++) ret = (ret*i)%M;
  
  return ret;
 }

ll power(int k,int n,int M){
  if(n==0) return 1;
  if(n==1) return (ll)k;
  
  ll ret = power(k,n/2,M);
  
  ret=(ret*ret)%M;
  
  if(n%2==1) ret=(ret*k)%M;
  
  return ret;
}


//nCm nPm nHm (mod M)

/*Combination*/
int C(int n,int m,int M){
  if(n<m) return 0;
  if(m==0 || n==m) return 1;
  
  ll chi = factorial(n,M);
  ll mot = (factorial(m,M) * factorial(n-m,M))%M;
  
  mot = power((int)mot,M-2,M);
  
  ll ret = (chi*mot)%M;
  
  return (int)ret;
}
/*Permutation*/
int P(int n,int m,int M){
  if(n<m) return 0;
  if(m==0) return 1;
  
  ll chi = factorial(n,M);
  ll mot = factorial(n-m,M);
  
  mot = power((int)mot, M-2,M);
  
  ll ret = (chi*mot)%M;
  
  return (int)ret;
}
/*Combination with Repetitions*/
int H(int n,int m,int M){
  if(n==0 && m==0) return 1;
  return C(n+m-1,m,M);
}


int main(){
  int n;
  ll a, b, k, ans = 0;

  cin >> n >> a >> b >> k;

  initFactorial(n, mod);
  
  for(int i=0;i<=n;i++){
    if (k >= i*a && (k - i*a)%b == 0 && (k-i*a)/b <= n) {
      ll p = (k - i*a)/b;
      ans = (ans + (ll)C(n, i, mod) * C(n, p, mod) % mod) % mod;
    }
  }

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



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

using namespace std;

int main() {
  int k;
  string s;
  cin >> k >> s;
  if(s.length() > k){
    cout << s.substr(0, k) + "..." << endl;
  }
  else cout << s << endl;
}

Measured memory_bytes: 3600
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

SumA=[0 for _ in range(N+1)]
SumB=[0 for _ in range(M+1)]
for i in range(1,N+1):
    SumA[i]=SumA[i-1]+A[i-1]
for i in range(1,M+1):
    SumB[i]=SumB[i-1]+B[i-1]

def binary_search(Time,IndexA):
    if Time>K:
        return 0 
    l=0
    r=M
    c=(l+r)//2
    while r-l>1:
        if Time+SumB[c]>K: r=c
        if Time+SumB[c]<=K: l=c
        c=(l+r)//2
    if Time+SumB[r]>K: IndexB=l
    else: IndexB=r
    NumOfBooks=IndexA+IndexB
    return NumOfBooks

MaxNumOfBooks=0
for IndexA in range(N+1):
    NumOfBooks=binary_search(SumA[IndexA],IndexA)
    if MaxNumOfBooks<NumOfBooks: MaxNumOfBooks=NumOfBooks
print(MaxNumOfBooks)


Measured memory_bytes: 134112
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
#define PI 3.1415926535
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;

int main()
{
	double a, b, x;
	cin >> a >> b >> x;
	cout << setprecision(10);
	if (x<=a*a*b/2)
	{
		co(atan(a*b*b/2/x) / PI * 180);
	}
	else
	{
		co(atan(2 * b / a - 2 * x / a / a / a) / PI * 180);
	}
	return 0;
}

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

int main(){
	int temp[7][2];
	int t;
	for(int i=0;i<7;i++){
		cin >> temp[i][0] >> temp[i][1];
		cout << temp[i][0]-temp[i][1] << endl;
		}
		
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
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; }
typedef long long ll;

int main() {
    ll mod = 1e9+7;
    int n, m; cin >> n >> m;
    vector<bool> v(n + 1, false);
    rep(i, m){
        int a; cin >> a;
        v[a] = true;
    }

    vector<int> dp(n + 2);
    dp[n] = 1;
    for(int i = n - 1; i >= 0; i--){
        // 壊れている時
        if(v[i]){
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
    }
    cout << dp[0] << endl;
}

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

using namespace std;

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

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

  long b[n];
  for (int i = 0; i < n; i++) {
    b[i] = a[i] - (i + 1);
  }

  sort(b, b + n);
  long mid = b[n / 2];

  long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += abs(b[i] - mid);
  }

  cout << ans << endl;
}

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




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

    int N;  cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; ++i) cin >> L[i];
    sort(L.begin(), L.end());
    // DUMP(L);
    long long ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            // DUMP(pair<int, int>(i, j));
            ans += lower_bound(L.begin(), L.end(), L[i] + L[j]) - lower_bound(L.begin(), L.end(), L[j] - L[i] + 1);
            --ans;
            if (L[j] < 2 * L[i]) --ans;
            // DUMP(ans);
        }
    }
    cout << ans / 3 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi                first
#define se                 second
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                push_back
#define all(v)             v.begin(),v.end()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
               const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.se >b.se);
    }
    else
        return (a.fi<b.fi);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
ll sumofdigit(ll n)
{
    ll c=0,d=0,sum=0,i;
    while(n>0)
    {
        c=n%10;
        sum+=c;
        n/=10;
    }
    return sum;
}
int main()
{
 fast;
     int t=1;
     //cin>>t;
     while(t--)
     {
        ll m,i=0,j=0,c=0,d=0,e=0,f=0,sum=0,g=0,h=0,n,maxi=0;
        cin>>n;
        string a;
        map<string,ll> k;
        while(n--)
        {
            cin>>a;
            k[a]++;
        }
        cout<<"AC"<<" "<<'x'<<" "<<k["AC"]<<endl;
        cout<<"WA"<<" "<<'x'<<" "<<k["WA"]<<endl;
        cout<<"TLE"<<" "<<'x'<<" "<<k["TLE"]<<endl;
        cout<<"RE"<<" "<<'x'<<" "<<k["RE"]<<endl;
     }
}



Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

const int H = 40;
ll dp[H];

struct Shop {
	ll a, b;
	Shop(ll av, ll bv) : a(av), b(bv) {}

	bool operator<(const Shop& rhs) const {
		return a * rhs.b > rhs.a * b;
	}
};

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

	// Increment all b_i's and t by one to account for the time to traverse between stores

	// If we visit stores i and j, and have already spent k time, we spend
	// (a_i k + b_i) + (a_j (a_i k + b_i + k) + b_j)
	// = a_i k + b_i + a_j a_i k + a_j b_i + a_j k + b_j
	// = (a_i k + a_j k + b_i + b_j + a_i a_j k) + a_j b_i

	// So we visit i first if a_j b_i <= a_i b_j
	// that is, a_j / b_j <= a_i / b_i
	// So we visit in decreasing order of a_i / b_i

	// How many stores with a_i > 0 can we visit?
	// We go from k to at least (k + 1) + k >= 2k,
	// thus at most log_2(T)

	// 1 0, 2 1
	// 1 -> 3 -> 11
	// 1 -> 5 -> 11

	int n;
	ll t;
	cin >> n >> t;
	++t;

	dp[0] = 1;
	for (int j = 1; j < H; ++j) dp[j] = t + 1;

	vector<ll> offs = {0};
	vector<Shop> shops;
	for (int i = 0; i < n; ++i) {
		ll a, b;
		cin >> a >> b;
		++b; // Time to move to next shop
		if (a == 0) offs.push_back(b);
		else shops.emplace_back(a, b);
	}
	sort(shops.begin(), shops.end());
	
	for (auto sp : shops) {
		for (int m = H-2; m >= 0; --m) {
			ll off = dp[m] * (sp.a + 1) + sp.b;
			if (off <= t) dp[m+1] = min(dp[m+1], off);
		}
	}

	sort(offs.begin(), offs.end());
	for (int i = 1; i < (int)offs.size(); ++i) offs[i] += offs[i-1];

	int j = (int)offs.size() - 1;
	int res = 0;
	for (int m = 0; m < H; ++m) {
		while(j >= 0 && dp[m] + offs[j] > t) --j;
		if (j < 0) break;
		res = max(res, m + j);
	}
	cout << res << '\n';
}


Measured memory_bytes: 6512
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

// Union find
struct uf {
  vi d;
  uf(){}
  uf(int mx):d(mx,-1){}
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y]; d[y] = x;
    return true;
  }
  int size(int x) { return -d[root(x)];}
};
//



int main() {
  df(n); df(q);
  vi x(n,INF);
  vector<Q> es;
  rep(i,q) {
    df(a); df(b); df(c);
    es.pb(Q(c,P(a,b)));
    mins(x[a], c+1);
    mins(x[b], c+2);
  }
  rep(i,n*2) mins(x[(i+1)%n], x[i%n]+2);
  rep(i,n) es.pb(Q(x[i], P(i, (i+1)%n)));
  sort(rng(es));
  uf t(n);
  ll ans = 0;
  for (Q e : es) {
    if (t.unite(e.se.fi, e.se.se)) ans += e.fi;
  }
  cout << ans << endl;
  return 0;
}







Measured memory_bytes: 7280
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(decltype(N+k) i=k; i<N;i++)
#define rep(i,N) for(decltype(N) i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return 約数unordered_set 1 <= x <= n
auto divv = [](auto n) {
  unordered_set<decltype(n)> v;
  for(decltype(n) i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.insert(i);
      if(i*i != n) v.insert(n/i);
    }
  }
  return v;
};

// check prime (and n>=2) or not
auto isPrime = [](auto n){
  if(n <= 1) return false;
  for(decltype(n) i = 2; i <= sqrt(n); ++i) {
      if(n % i == 0) {
          return false;
      }
  }
  return true;
};



int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    
    pr(a == c ? 0 : 1);
}


Measured memory_bytes: 256
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;

struct Input
{
	string s;
}

void parseInput(T)(out Input input, T file)
{
    with (file) with (input)
    {
        s = readln().strip();
    }
}

auto main2(Input* input)
{
	switch (input.s)
	{
		case "Sunny" : return "Cloudy";
		case "Cloudy" : return "Rainy";
		case "Rainy" : return "Sunny";
			default: assert(0);
	}
}


void main()
{
    Input input = void;
    parseInput(input, stdin);
    auto result = main2(&input);
    writeln(result);
}

void parseExample(out Input input, string example)
{
    struct Adapter
    {
        import std.string;
        string[] _lines;
        this(string input) { _lines = input.splitLines(); }

        string readln()
        {
            auto line = _lines[0];
            _lines = _lines[1..$];
            return line;
        }
/+
        uint readf(Data...)(scope const(char)[] format, auto ref Data data)
        {
            import std.format;
            return formattedRead(readln(), format, data);
        }+/
    }
    Adapter a = Adapter(example);
    parseInput(input, a);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  int num=0,a;
  for(int i=0;i<3;i++){
    cin>>a;
    num=num<<1;
    num+=a;
    //cout<<num<<endl;
  }
  if(num==6||num==1){
    cout<<"Open"<<endl;
  }
  else{
    cout<<"Close"<<endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i < (int)(n); i++)
typedef long long ll;
#define NP next_permutation
#define MP make_pair

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n, q;
  cin >> n >> q;
  vector<char> s(n);
  rep(i,n) cin >> s[i];
  rep(i,n-1) {
    if(s[i] == 'A' && s[i+1] == 'C') s[i] = 'a';
  }
  vector<int> cnt(n);
  int count = 0;
  rep(i,n){
    if(s[i] == 'a') count++;
    cnt[i] = count;
  }

  rep(i,q){
    int l, r;
    cin >> l >> r;
    int ans = cnt[r-2] - cnt[l-2];
    cout << ans << endl;
  }
}




Measured memory_bytes: 1280
#include <iostream>

using namespace std;

int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if((w >= (x+r))&&(h >= (y+r))){
        if((x>=r)&&(y>=r)){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else { 
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iso646.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

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

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

int main() {
    ll A, B, N;
    cin >> A >> B >> N;
    if(N >= B) {
        cout << A - (A + B - 1) / B << endl;
    } else {
        cout << A * N / B - A * (N / B) << endl;
    }
    return 0;
}

Measured memory_bytes: 3188