akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
struct BIT {
	vector< int > container;
	BIT(int n) {
		container = vector< int >(n + 1, 0);
	}
	void add(int i, int x) {
		if (i > container.size())
			return;
		container[i] += x;
		add(i + (i & -i), x);
	}
	int sum(int i) { //[1,i]
		if (i == 0)
			return 0;
		return container[i] + sum(i - (i & -i));
	}
	int sum(int l, int r) { //[l,r)
		return sum(r - 1) - sum(l - 1);
	}
};
signed main() {
	cin >> N;
	string S;
	cin >> S;
	vector< BIT > bts(26, BIT(N));
	rep(i, N) {
		int c = S[i] - 'a';
		bts[c].add(i + 1, 1);
	}
	cin >> Q;
	while (Q--) {
		int q;
		cin >> q;
		if (q == 1) {
			int i;
			char c;
			cin >> i >> c;
			--i;
			int c2 = S[i] - 'a';
			bts[c2].add(i + 1, -1);
			S[i] = c;
			bts[S[i] - 'a'].add(i + 1, 1);
		} else {
			int l, r;
			cin >> l >> r;
			int ans = 0;
			rep(k, 26) {
				if (bts[k].sum(l, r + 1) > 0)
					++ans;
			}
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 106372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD (int) 1e9+7

int main(){
    string s;
    cin >> s;
    int len = s.size();
    while(len>0){
        // cout << len << endl;
        if(len>=5 && s.substr(len-5,5)=="dream"){
            len -= 5;
        }else if(len>=7 && s.substr(len-7,7)=="dreamer"){
            len -= 7;
        }else if(len>=5 && s.substr(len-5,5)=="erase"){
            len -= 5;
        }else if(len>=6 && s.substr(len-6,6)=="eraser"){
            len -= 6;
        }else{
            cout << "NO" << endl;
            return 0;
        }        
    }
    cout << "YES" << endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int dp[200000];
    int h[200000];

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

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

    cout << dp[n] << endl;


}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 2e3 + 2;
const int INF = 1e9;

int n, a[N], p[N][2], f[N][2];

void Solve()
{
    p[n][0] = INF;
    for (int i = n - 1; i >= 0; --i)
        for (int j = 0; j < 2; ++j)
            if (j == 0)
            {
                f[i][j] = max(p[i + 1][!j], abs(a[n] - a[i]));
                p[i][j] = min(p[i + 1][j], f[i][j]);
            }
            else
            {
                f[i][j] = min(p[i + 1][!j], abs(a[n] - a[i]));
                p[i][j] = max(p[i + 1][j], f[i][j]);
            }
    printf("%d", f[0][0]);
}

int main()
{
    scanf("%d %*d %d", &n, &a[0], &a[0]);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

ll mem[3002][3002];

const ll md = 998244353;

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	cin.exceptions(cin.failbit);

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	mem[a][b] = 1;

	rep(i,a,c){
		mem[i+1][b] = b * mem[i][b] % md;
	}
	rep(j,b,d){
		mem[a][j+1] = a * mem[a][j] % md;
	}

	rep(i,a,c) rep(j,b,d){
		mem[i+1][j+1] = mem[i+1][j] * (i+1)
			      + mem[i][j+1] * (j+1)
			      - mem[i][j] * i * j;
		mem[i+1][j+1] %= md;
	}

	ll ans = mem[c][d];
	ans %= md;
	if(ans < 0) ans += md;
	cout << ans << endl;
}


Measured memory_bytes: 73924
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define timer_start()                            \
    chrono::system_clock::time_point start, end; \
    start = chrono::system_clock::now();
#define timer_wrap()                                                       \
    end = chrono::system_clock::now();                                     \
    double time = static_cast<double>(                                     \
        chrono::duration_cast<chrono::microseconds>(end - start).count() / \
        1000.0);                                                           \
    printf("%lf[ms]\n", time);                                             \
    start = end;
#define optimize_cin() \
    cin.tie(0);        \
    ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
#define INF 1000000000    // 10^9
#define INFINF LLONG_MAX  // 2^63-1
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 ##########

#ifdef DEBUG_ON
void test_all();
#endif

void resolve() {
    int N;
    cin >> N;
    vector<vector<ll>> abc(N);
    vector<vector<ll>> dp(N);
    for (int i = 0; i < N; i++) {
        abc.at(i) = {0, 0, 0};
        dp.at(i) = {0, 0, 0};
        for (int j = 0; j < 3; j++) {
            cin >> abc.at(i).at(j);
        }
    }
    dp.at(0) = abc.at(0);
    for (int i = 1; i < N; i++) {
        dp.at(i).at(0) =
            max(dp.at(i - 1).at(1), dp.at(i - 1).at(2)) + abc.at(i).at(0);
        dp.at(i).at(1) =
            max(dp.at(i - 1).at(0), dp.at(i - 1).at(2)) + abc.at(i).at(1);
        dp.at(i).at(2) =
            max(dp.at(i - 1).at(0), dp.at(i - 1).at(1)) + abc.at(i).at(2);
    }

    int ans = 0;
    cout << max({dp.at(N - 1).at(0), dp.at(N - 1).at(1), dp.at(N - 1).at(2)})
         << endl;
}

int main() {
#ifdef DEBUG_ON
    test_all();
#else
    resolve();
#endif
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int n,m;
bool ch(int i,int j){
	return (i>=0&&i<n&&j>=0&&j<m);
}
int dx[8]={1,-1,1,-1,1,-1,0,0};
int dy[8]={1,-1,-1,1,0,0,-1,1};
int main(){
	cin>>n>>m;
	string s[n];
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	int num[n][m];
	memset(num,0,sizeof num);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			for(int z=0;z<8;z++){
				if(ch(i+dx[z],j+dy[z])&&s[i+dx[z]][j+dy[z]]=='#'){
					num[i][j]++;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]=='.'){
				cout<<num[i][j];
			}else{
				cout<<s[i][j];
			}
		}cout<<endl;
	}
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int cnt,n;
string s,ans;
int main()
{
	cin>>n>>s;
	ans=s;
	for(int i=0;i<n;i++)
	{
		if(s[i]==')')cnt--;
		else cnt++;
		if(cnt<0)
		{
			ans.insert(0,"(");
			cnt=0;
		}
	}
	while(cnt--)ans+=')';
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

from collections import defaultdict

I=sys.stdin.readline

n=int(I())
arr=sorted(list(map(int,I().split())))
d=defaultdict(int)

for i in arr:
	d[i]+=1

ans=0
visited=[0]*(arr[-1]+1)
for i in arr:
	if d[i]==1 and visited[i]==0:
		ans+=1

	for j in range(i,arr[-1]+1,i):
		visited[j]=1

print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    ll r;
    cin >> r;

    double pi = 4.0*atan(1.0);
    cout << r * pi * 2.0 << endl; 
    return 0;
}


Measured memory_bytes: 3796
#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 INM = 114514;
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};

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<ll> a(n), b(n + 1), c(n + 1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	b[0] = 0;
	c[n] = 0;
	for (int i = 0; i < n; i++) {
		b[i + 1] = max(b[i], a[i]);
	}
	for (int i = n; i > 0; i--) {
		c[i - 1] = max(c[i], a[i - 1]);
	}
	for (int i = 0; i < n; i++) {
		ll ans = max(b[i], c[i + 1]);
		dump(ans);
	}
}


Measured memory_bytes: 6272
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,M,C=rl()
B=rl()
ans = 0
for _ in range(N):
    A=rl()
    if sum(map(lambda x,y:x*y,A,B))+C > 0:
        ans += 1
    
print(ans)

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

int main(){
    int A;
    int B;
    cin >> A >> B;

    if(A + B == 4){
        cout << 2 << endl;
    }else if(A + B == 5){
        cout << 1 << endl;
    }else{
        cout << 3 << endl;
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	long int N,D;
	scanf("%ld %ld", &N,&D);
	long int X[200000];
	long int Y[200000];
	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		scanf("%ld %ld", X+i, Y+i);
	}
	D = D * D;
	for (int i = 0; i < N; i++)
	{
		X[i] = X[i] * X[i];
		Y[i] = Y[i] * Y[i];
		
		if (D >= (X[i] + Y[i]))
		{
			cnt++;
		}
			
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 4816
S = int(input())
n1 = S // 100
n2 = S % 100
if n1 < 1 or 12 < n1:
    if n2 < 1 or 12 < n2:
        print('NA')
    else:
        print('YYMM')
elif n2 < 1 or 12 < n2:
    if n1 < 1 or 12 < n1:
        print('NA')
    else:
        print('MMYY')
else:
    print('AMBIGUOUS')

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

int main(){
  int n, m, maxmoney;
  cin >> n;
  maxmoney = 0;
  vector<string> s(n);
  vector<string> t(m);
  for(int i = 0; i < n; i++){
    cin >> s.at(i);
  }
  cin >> m;
  for(int i = 0; i < m; i++){
    cin >> t.at(i);
  }
  for(int i = 0; i < n; i++){
    int money = 0;
    string a = s.at(i);
    for(int j = 0; j < n; j++){
      if(a == s.at(j)){
        money++;
      }
    }
    for(int k = 0; k < m; k++){
      if(a == t.at(k)){
        money--;
      }
    }
    if(money > maxmoney){
      maxmoney = money;
    }
  }
  cout << maxmoney << endl;
}

Measured memory_bytes: 512
from copy import deepcopy
N=input()
n=deepcopy(N)
total=0
for l in range(1,12):
    n-=26**l
    if n<=0: break
    total+=26**l

N-=total+1
ans=""
for i in range(l-1,-1,-1):
    ans+=chr(N/(26**i)+97)
    N%=(26**i)
print ans

Measured memory_bytes: 64792
# https://atcoder.jp/contests/abc123/tasks/abc123_a
# A - Five Antennas

import itertools

place_list = []

for _ in range(5):
    place_list.append(int(input().split()[0]))

k = int(input().split()[0])

p = itertools.combinations(place_list, 2)

is_ok = True

for p_1, p_2 in p:
    if abs(p_1 - p_2) > k:
        is_ok = False

ans = 'Yay!' if is_ok else ':('

print(ans)


Measured memory_bytes: 3064
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

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

const int N = 1e5 + 5;

int gcd(int a, int b);

int main()
{
	int n, k, g = 0, mx = 0;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
	{
		int a;
		cin >> a;
		g = gcd(g, a);
		mx = max(mx, a);
	}

	if (k <= mx and k % g == 0)
		cout << "POSSIBLE\n";
	else
		cout << "IMPOSSIBLE\n";
}

int gcd(int a, int b)
{
	if (!b)
		return a;

	return gcd(b, a % b);
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
#include <chrono>
#include <random>
#include <ctime>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	srand(time(0));
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i = 0; i < 5; i++) {
		int x;
		cin >> x;
		if (!x) {
			cout << i + 1;
			return 0;
		}
	}
}

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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repi(i, x) for (auto &i : (x))


using namespace std;

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

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N;
int A[100000];

ll tsum(int dist) {
    ll csum = 0;
    ll cmax = -INFL;
    for (int i = 1; i*dist < N-1; i++) {
        int cp = N-1-dist*i;
        csum += A[dist*i];
        csum += A[cp];
        if (cp > dist and (dist*i < cp or cp%dist != 0)) {
            get_max(cmax, csum);
        }
    }
    return cmax;
}

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    cin >> N;
    rep(i, N) cin >> A[i];

    ll res = 0;
    repp(i, N-1) get_max(res, tsum(i));
    cout << res << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int MAX=2100000;
const long long MOD=1000000007;

typedef long long ll;

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

ll mod_pow(ll x, ll n){ //べき乗
    ll ans=1;
    x%=MOD;
    while(n!=0){
        if(n&1) ans=ans*x%MOD;
        x=x*x%MOD;
        n=n>>1;
    }
    return ans%MOD;
}

void com_init(){ //初期化
    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;
        finv[i]=finv[i-1]*mod_pow(i,MOD-2)%MOD;//フェルマーの小定理より
    }
}

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

ll sum_comb(ll r, ll c){
    ll tmp=0;
    for(int i=1;i<=r+1;i++){
        tmp+=comb(i+c,c);
        tmp%=MOD;
    }
    return tmp%MOD;;
}

int main(){
    ll r1,c1,r2,c2; cin >> r1 >> c1 >> r2 >> c2;
    com_init();
    ll ans=sum_comb(r2,c2)+sum_comb(r1-1,c1-1)+2*MOD-sum_comb(r1-1,c2)-sum_comb(r2,c1-1);
    cout << ans%MOD << endl;
}

Measured memory_bytes: 33152
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra();


int main() {
    int k, u, v, c;

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> u >> k;
        for ( int j = 0; j < k; j++ ) {
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

}



void dijkstra() {
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for ( int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0]  = 0;
    PQ.push(make_pair(0, 0));
    color[0] = GRAY;

    while ( !PQ.empty()) {
        pair<int, int> f = PQ.top(); PQ.pop();
        int u = f.second;

        color[u] = BLACK;

        // take the minimum value, ignore if it is not the shortest
        if ( d[u] < f.first * (-1) ) continue;

        for ( int j = 0; j < adj[u].size(); j++ ) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) continue;
            if ( d[v] > d[u] + adj[u][j].second) {
                d[v] = d[u] + adj[u][j].second;
                // multiple (-1) because of priority large value in priority_queue
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
                }
        }
    }

    for ( int i = 0; i < n; i++ ) {
        cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << '\n';
    }
}



Measured memory_bytes: 7992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<ll> p(n);
    rep(i, 0, n) {
        ll x;
        cin >> x;
        x--;
        p[i] = x;
    }

    rep(i, 0, n) rep(j, i, n) {
        bool ok = true;
        rep(k, 0, n) {
            ll tmp;
            if(k == i) tmp = p[j];
            else if(k == j) tmp = p[i];
            else tmp = p[k];
            if(tmp != k) ok = false;
        }
        if(ok) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    cout<<fixed<<setprecision(5);
    float pi=3.14159f;
    int r;
    cin>>r;
    float ans=2*pi*r;
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 3804
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>
#include <deque>
#include <set>
#include <climits>
#include <complex>

#define rep_(v, f, l) for (int v = (f); v < (l); ++v)
#define rep(v, n) rep_(v, 0, n)

using namespace std;

typedef long long int lint;
typedef complex<double> P, point;
template<typename T> inline bool in(T& x){ return cin >> x; }
template<typename T> inline T in(){T x; cin >> x; return x; }

const double EPS = 1e-7;

pair<P, P> cci(const P& a, const P& b){
    P d=b-a;
    P A=conj(d), B=-d*A, C=d;
    P D=B*B-4.0*A*C;
    P z1=(-B+sqrt(D))/(2.0*A)+a, z2=(-B-sqrt(D))/(2.0*A)+a;
    return make_pair(z1, z2);
}

int get_max_overlaps(const vector<vector<int> >& graph, const vector<P> seals, int v)
{
    int maxi = 1;

    rep(i, graph[v].size()){
        int x = graph[v][i];
        pair<P, P> cp = cci(seals[v], seals[x]);
        int fc, sc;
        fc = sc = 2;
        rep(j, graph[v].size()){
            int y = graph[v][j];
            if (y == x) continue;
            if (abs(cp.first - seals[y]) <= 1.0 + EPS) fc++;
            if (abs(cp.second - seals[y]) <= 1.0 + EPS) sc++;
        }
        maxi = max(maxi, max(fc, sc));
    }
    return maxi;
}

int main()
{
    int n;
    while (in(n), n){
        vector<P> seals;
        rep(i, n){
            double x, y;
            scanf("%lf,%lf", &x, &y);
            seals.push_back(P(x, y));
        }
        vector<vector<int> > graph;
        rep(i, n){
            vector<int> edges;
            rep(j, n){
                if (i == j) continue;
                if (abs(seals[i] - seals[j]) < 2.0 + EPS){
                    edges.push_back(j);
                }
            }
            graph.push_back(edges);
        }
        int maxi = 1;
        rep(i, graph.size()){
            if (maxi <= graph[i].size()){
                maxi = max(maxi, get_max_overlaps(graph, seals, i));
            }
        }
        printf("%d\n", maxi);
    }

	return (0);
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    string s; cin >> s;
    int simo2 = stoi(s.substr(2, 2));
    int kami2 = stoi(s.substr(0, 2));
    if((0 < simo2 && simo2 <= 12) && (0 < kami2 && kami2 <= 12)){
        COUT("AMBIGUOUS");
    }
    else if(0 < simo2 && simo2 <= 12) {
        COUT("YYMM");
    }
    else if(0 < kami2 && kami2 <= 12) {
        COUT("MMYY");
    }
    else {
        COUT("NA");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 998244353; //1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e4+2;

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

      int n,m;
      cin>>n>>m;
      map<int,int> ma1,ma2;
      int cnt=0;
      int cnt1=0;
      for(int i=0;i<m;i++)
      {
      	int x;
      	string s;
      	cin>>x>>s;
      	if(s=="AC")
      	{
      		if(ma2[x]==0)
      		{
      			cnt+=ma1[x];
      			ma2[x]++;
      			cnt1++;
      		}
      		else{

      		}

      	}
      	else{
      		if(ma2[x]==0)
      		{
      			ma1[x]++;
      		}
      	}
      }
      cout<<cnt1<<" "<<cnt;
} 
// I never lose. I either win or I learn

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int v[1005][11][21];
void nxt(int &y, int &m, int &d) {
    int ed = y % 3 == 0 ? 20 : m % 2 == 1 ? 20 : 19;
    int em = 10;

    if (d == ed && m != em) {
        m++, d = 1;
    } else if (d == ed && m == em) {
        y++, m = 1, d = 1;
    } else {
        d++;
    }
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int y = 1, m = 1, d = 1;
    int rv = 1;
    while (y < 1001) {
        v[y][m][d] = rv;
        nxt(y, m, d);
        ++rv;
    }

    int n; cin >> n;
    rep(i, 0, n) {
        int y, m, d; cin >> y >> m >> d;
        cout << v[1000][1][1] - v[y][m][d] << endl;
    }
}


Measured memory_bytes: 4108
#D
N = int(input())
S = input()

ans = S.count('R')*S.count('G')*S.count('B')

for start in range(0,N-2):
    for interval in range(1,N):
        try:
            if S[start] != S[start+interval] and S[start] != S[start+2*interval] and S[start+interval] != S[start+2*interval]:
                ans -= 1
        except IndexError:
            break
print(ans)

Measured memory_bytes: 9224
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

c = Counter(A)

# 何も除いていない状態で、全体で可能な組み合わせ
comb = 0

# c[i](C)2のcombination計算
for i in c:
    comb += (c[i]) * (c[i] - 1) // 2

# 同じ数のボールがn個あったら組み合わせはn(n-1)/2
# 一つ取り除いた後の組み合わせは(n-1)(n-2)/2
# この差を計算するとn-1
# 除いたボールを使って可能にしていた組み合わせn-1通りが不可能になる、と直接考えてもOK
for i in A:
    ans = comb - (c[i] - 1)
    print(ans)


Measured memory_bytes: 34128
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n; cin >> n;
    int x_cur = 0;
    int y_cur = 0;
    int t_cur = 0;
    REP(i, n) {
        int t, x, y; cin >> t >> x >> y;
        int abs_diff = abs(x_cur - x) + abs(y_cur - y);
        int t_diff = t - t_cur;

        bool ok = false;

        if (abs_diff == t_diff) {
            ok = true;
        } else if (abs_diff < t_diff) {
            if (abs_diff % 2 == t_diff % 2) {
                ok = true;
            } else {
                ok = false;
            }
        } else {
            ok = false;
        }

        if (ok) {
            x_cur = x;
            y_cur = y;
            t_cur = t;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

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

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

  string ans = "NG";
  for(int i=A; i<=B; i++){
    if(i%K==0) {ans = "OK"; break;}
  }

  cout << ans;
}


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

class Hello
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = int.Parse(Console.ReadLine());
        }

        int index = 0;

        int count = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[index] == 2)
            {
                count++;
                break;
            }
            index = a[index]-1;
            count++;
        }

        if (count == a.Length)
        {
            count = -1;
        }

        Console.WriteLine(count);

    }
}

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

int main() {

  int N; cin >> N;
  int sum = 0;
  int mx = 0;
  for (int i = 0; i < N; i++) {
    int L; cin >> L;
    sum += L;
    if (L > mx) {
      mx = L;
    }
  }
  
  if (sum > mx * 2) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<ll> A(n), B(n);
  rep(i, n) {
    cin >> A.at(i) >> B.at(i);
  }
  ll cnt = 0;
  ll ans = 0;
  repr(i, n-1) {
    A.at(i) += cnt;
    if (A.at(i) % B.at(i) == 0) continue;

    ll v =  B.at(i) - (A.at(i) % B.at(i));
    ans += v;
    cnt += v;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4796
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
	  String s = sc.next();
      int count =0;
	  for(int i=0;i<3;i++){
        if(s.charAt(i)=='o'){
          count++;
        }
      }
      System.out.println(700+count*100);
    }
}

Measured memory_bytes: 35688
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double N = scan.nextInt();
		if (N == 1) {
			System.out.println(1);
		} else {
			double answer = Math.ceil(N / 2);
			System.out.println((int) answer);
		}
	}

}

Measured memory_bytes: 21972
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String s = "No";
        for(int i=1;i<10;i++){if(s.equals("Yes")){break;} 
          for(int j=1;j<10;j++){if(i*j==a){s="Yes";}                                                                                  
                               }                                                
                             }       
		System.out.println(s);
	}
}


Measured memory_bytes: 21972
import java.util.*;

public class Main {
	
	public static int polish(String[] equation) {
		
		Stack<Integer> stack = new Stack<Integer>();
		int index = 0;
		
		while(index < equation.length) {
			
			while(!equation[index].equals("+") & !equation[index].equals("-") & !equation[index].equals("*") & !equation[index].equals("/")) {
				stack.push(Integer.parseInt(equation[index]));
				index++;
			}
			
			if(equation[index].equals("+")) {
				
				int temp = stack.pop() + stack.pop();
				stack.push(temp);
				
			}
			else if(equation[index].equals("-")) {
				
				int first = stack.pop();
				int second = stack.pop();
				int temp = second - first;
				stack.push(temp);
				
			}
			else if(equation[index].equals("*")) {
				
				int temp = stack.pop() * stack.pop();
				stack.push(temp);
				
			}
			index++;
			
		}
		
		return stack.pop();
		
	}


	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		String line = in.nextLine();
		String[] equation = line.split(" ");
		
		int result = polish(equation);
		System.out.println(result);
		
		in.close();

	}

}


Measured memory_bytes: 26224
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String saa = sc.next();
		String sbb = sc.next();
		String scc = sc.next();
		
		int na = saa.length();
		int nb = sbb.length();
		int nc = scc.length();
		
		int a = 0;
		int b = 0;
		int c = 0;
		int turn = 0;
		
		while(true){
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}
			else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}
			else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		}
	}
}

Measured memory_bytes: 21844
#include<cstdio>

int main(){
    int n;
    scanf("%d",&n);
    bool card[4][13];
    for(int i = 0; i < 4; i++){
        for(int j = 0; j <13; j++){
            card[i][j] = false;
        }
    }
    for(int i = 0; i < n; i++){
        char c;
        scanf("\n%c",&c);
        int x;
        scanf("%d",&x);
        if(c == 'S'){
            card[0][x - 1] = true;
        }
        else if(c == 'H'){
            card[1][x - 1] = true;
        }
        else if(c == 'C'){
            card[2][x -1] = true;
        }
        else{
            card[3][x - 1] = true;
        }
    }
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 13; j++){
            if(card[i][j] == false){
                if(i == 0){
                    printf("S %d",j+1);
                }
                else if(i == 1){
                    printf("H %d",j+1);
                }
                else if(i == 2){
                    printf("C %d",j+1);
                }
                else{
                    printf("D %d",j+1);
                }
                printf("\n");
            }
        }
    }
    return 0;
}


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

#define loop(i,n) for(int i=1;i<=n;i++)
int c[202];
int d[202];
int n,m;

int rifuru(){
  loop(i,n){
    d[i*2-1]=c[i];
    d[i*2]=c[n+i];
  }
  loop(i,n*2)c[i]=d[i];
  return 0;
}

int katto(int k){
  loop(i,n*2){
    if(i<=k){
      d[n*2-k+i]=c[i];
    }else{
      d[i-k]=c[i];
    }
  }
  loop(i,n*2)c[i]=d[i];
  return 0;
}

int main(){
  int k;
  cin>>n>>m;
  loop(i,n*2)c[i]=i;
  loop(i,m){
    cin>>k;
    if(k==0)rifuru();
    else katto(k);
  }
  loop(i,n*2)cout<<c[i]<<endl;
  return 0;
}

Measured memory_bytes: 3096
n = int(input())
cnt = 1
l = [2, 1]
if n == 0:
    print(2)
elif n == 1:
    print(1)
else:
    while True:
        cnt += 1
        l.append(l[len(l)-1] + l[len(l)-2])
        if cnt == n:
            print(l[len(l) - 1])
            exit()


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int  i, n, a[10009],max ,min;
	long long int sum = 0;
	cin >> n;
	max = -1000001;
	min = -max;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for(i = 0; i < n; i++)
	{ sum += a[i];
	if (a[i] > max)max = a[i];
	if (a[i] < min)min = a[i];	
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}


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

int main() {

	int num[3][3];
	int N = 0;
	int bin[20];

	/*
	�r���S�̔���
	*/
	bool jud[3][3];

	for (int i = 0; i < 3;i++) {
		for (int j = 0; j < 3;j++) {
			cin >> num[i][j];
		}
	}
	cin >> N;

	for (int k = 0; k < N; k++) {
		cin >> bin[k];
	}

	for (int i = 0 ;i < 3; i++) {
		for (int j = 0 ;j < 3; j++) {
			jud[i][j] = false;
			for (int k = 0; k < N;k++) {
				if (num[i][j] == bin[k]) {
					jud[i][j] = true;
				}
			}
		}
	}
	string str = "No";

	for (int i = 0; i < 3; i++) {
		if (jud[i][0] && jud[i][1] && jud[i][2]) {
			str = "Yes";
		}
	}
	for (int i = 0; i < 3; i++) {
		if (jud[0][i] && jud[1][i] && jud[2][i]) {
			str = "Yes";
		}
	}

	if (jud[0][0] && jud[1][1] && jud[2][2]) {
		str = "Yes";
	}
	else if (jud[0][2] && jud[1][1] && jud[2][0]) {
		str = "Yes";
	}

	cout << str << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


typedef long long ll;

using namespace std;

int main() 
{ 

	ll n, a, b;
	cin >> n >> a >> b;

	ll divi = n / (a + b);
	ll rem = n % (a + b);

	if (rem > a){
		rem = a;
	}

	cout << (divi * a) + rem << endl;

	return 0; 
} 


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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int sieve[10000005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	
	rep(i, 1, 10000005) sieve[i] = 1;
	for (ll i = 2; i < 10000005; i++)
		for (ll j = i; j < 10000005; j += i)
			sieve[j]++;
	int n; read(n);
	ll ans = 0;
	rep(i, 1, n + 1)
		ans += 1ll * i * sieve[i];
	write(ans);
}


Measured memory_bytes: 42692
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		List<int> A = new List<int>();
        for(var i = 0; i < N; i++)
		{
			A.Add(input[i]);
		}
       
		A.Sort();
		var calc = new Calculation();
		/*int test = calc.GetGcdOfSortedList(A);
		Console.WriteLine(test);*/
		List<int> gcdlist = new List<int>();
		int[] gcdl = new int[N+1];
		int[] gcdr = new int[N+1];
		gcdl[0] = 0;
        for(var i =1; i <= N; i++)
		{
			if (i == 0) { continue; }
			gcdl[i] = calc.GetGcd(gcdl[i - 1], A[i - 1]);
		}
		gcdr[0] = 0;
        for(var i = 1; i <= N; i++)
		{
			if (i == 0) { continue; }
			gcdr[i] = calc.GetGcd(gcdr[i - 1], A[N - i]);
		}

        for(var i = 0; i < N; i++)
		{
			int gcd = calc.GetGcd(gcdl[i], gcdr[N - 1 - i]);

			gcdlist.Add(gcd);
		}
		gcdlist.Sort();
		Console.WriteLine(gcdlist[N-1]);

	}
}


//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
//入力用

public class Calculation //各種値計算
{
	public int GetGcd(int a, int b) //最大公約数(２数)
	{
		
		if (a < b)
		{
			int c = a;
			a = b;
			b = c;
		}
		if (b == 0)
		{
			return a;
		}

		int r = a % b;
		while (r > 0)
		{
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}
}

Measured memory_bytes: 29788
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////
LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

void solve() {
	int K;
	cin >> K;
	LL ans = 0;
	for (int a = 1; a <= K; ++a) {
		for (int b = 1; b <= K; ++b) {
			for (int c = 1; c <= K; ++c) {
				ans += gcd(a, gcd(b, c));
			}
		}
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 3652
use proconio::input;

fn main() {
  input! {
    a: u64, b: u64, c: u64
  };
  
  let mut ok = false;
  for i in 0..b {
    if a*i%b == c {
      ok = true;
      break;
    }
  }
  
  println!("{}", if ok {"YES"} else {"NO"});
}

Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
#define lld long double
int main()
{
	lld x,y,w,h;
	cin>>w>>h>>x>>y;
	if(x==w/2&&y==h/2)
	{
		cout<<(w*h)/2<<" 1\n";
	}
	else if(x==w/2)
	{
		cout<<(w*h)/2<<" 0\n";

	}
	else if(y==h/2)
	{
		cout<<(w*h)/2<<" 0\n";

	}
	else
	{
		cout<<(w*h)/2<<" 0\n";
	}

}

Measured memory_bytes: 3744
import numpy as np
n, k = map(int, input().split())
a = []
a.append(np.array(list(map(int, input().split()))) - 1)
for _ in range(60):
    a.append(a[-1][a[-1]])
ans = 0
i = 0
while k > 0:
    if k & 1:
        ans = a[i][ans]
    i += 1
    k //= 2
print(ans + 1)


Measured memory_bytes: 123872
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
typedef long long ll;

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

  vector<int> counter(n);
  for (int i = 0; i < n-1; i++) {
    if (s[i] == 'A' && s[i+1] == 'C') {
      if (i == 0) {
        counter[i]++;
      } else {
        counter[i] = counter[i-1] + 1;
      }
    } else {
      if (i == 0) {
        counter[i] = 0;
      } else {
        counter[i] = counter[i-1];
      }
    }
  }

  for (int i = 0; i < q; i++) {
    int l, r, ans;
    cin >> l >> r;
    l--;
    r--;

    if (l == 0) {
      cout << counter[r-1] << endl;
    } else {
      cout << counter[r-1] - counter[l-1] << endl;
    }
  }
}

Measured memory_bytes: 3484
def solv():
    n = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    ans = 0

    for i in range(n):
        x = A[i] + A[i+1]
        ans += min(x,B[i])
        A[i+1] = min(A[i+1],max(x-B[i],0))
    return print(ans)

solv()


Measured memory_bytes: 24144