akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
using namespace std;

#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define INF               1e18
#define ff                first
#define ss                second
#define vi                vector<int>
#define pii               pair<int,int>
#define mii               map<int,int>
#define endl              "\n"
#define GCD(x,y)          (__gcd((x), (y)))
#define LCM(x,y)          (((x)/__gcd((x), (y)))*(y))
#define debug(x)          cout<<#x<<" is "<<(x)<<endl
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(long long i=a;i<b;i++)
#define sp(ans,p)         fixed <<setprecision(p)<<ans;
#define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// constexpr int N=;
void solve()
{
    int in, t, d;
    cin >> in >> t >> d;
    int ff = 0;
    if (in < 0)
    {
        in *= -1;
        ff = 1;
    }

    int mulp = in / d;
    mulp = min(mulp, t);
    int rem = (t - mulp) % 2;
    int prefinal = in - d * mulp ;
    if (rem == 0)
    {
        cout << prefinal << endl;
    }
    else
    {
        cout << min(abs(prefinal + d), abs(prefinal - d)) << endl;
    }
    // cout << << "   " << (t - mulp) % 2  << endl;
    return;
}

signed main()
{
    IOS;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    // sieve();
    int t = 1;
    //cin >> t;
    while (t--)   solve();
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,a[N];long long ans;
int main(){
	scanf("%d",&n);
	a[0]=-1;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (a[i]>a[i-1]+1) return puts("-1"),0;
	}a[n+1]=-1;
	for (int i=n;i;i--){
		ans+=(a[i]>=a[i+1]?a[i]:0);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  cin >> n;
  
  vector<int> v(n);
  for(int i; i < n; i++)
    cin >> v.at(i);
  
  int s = 0;
  int t = 0;
  int u = 0;
  
  while(t < n){
    while(u < t){
      if(v.at(u) <= v.at(t))
        u++;
      else
        break;
    }
    if(u == t)
      s++;
    t++;
    u = 0;
  }
  cout  << s << endl;
}
        

Measured memory_bytes: 256
#include <stdio.h>

#define MAX_H 250

int A[MAX_H];

int main() {
  int H;
  int i;
  scanf("%d", &H);  
  for(i = 0; i < H; i++) scanf("%d", A+i);

  for(i = 0; i < H; i++) {
    printf("node %d: ", i+1);
    printf("key = %d, ", A[i]);
    if(i) printf("parent key = %d, ", A[(i-1)/2]);
    if(2*i+1 < H) printf("left key = %d, ", A[2*i+1]);
    if(2*i+2 < H) printf("right key = %d, ", A[2*i+2]);
    puts("");
  }
  
  return 0;
}

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

int main()
{
	int a,sum=0;
	for(int i=0;i<3;i++)
	{
		cin>>a;
		sum+=a;
	}
	if(sum>=22)cout<<"bust"<<endl;
	else cout<<"win"<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())

n, k = nm()
l = nl()

l.sort(reverse=True)
ans = 0
for i in range(k):
    ans += l[i]
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int f[4][4];
int main()
{
    int a,b,c;
    scanf("%d%d%d",&f[1][1],&f[1][2],&f[2][2]);
    a=f[2][2]*3;
    f[1][3]=a-f[1][1]-f[1][2];
    f[3][1]=a-f[1][3]-f[2][2];
    f[3][3]=a-f[1][1]-f[2][2];
    f[2][1]=a-f[1][1]-f[3][1];
    f[2][3]=a-f[2][1]-f[2][2];
    f[3][2]=a-f[1][2]-f[2][2];
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            printf("%d ",f[i][j]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(stdR.readLine());
        double sum = 0;
        for(int i = 0 ; i < N ; i++) {
            String[] s = stdR.readLine().split(" ");
            double d = Double.parseDouble(s[0]);
            String cur = s[1];
            if(cur.equals("JPY")) {
                sum += d;
            }else {
                sum += d * 380000d;
            }
        }
        System.out.println(sum);
    }
}


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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>
#define REP(x,n) for(int x = 0;x < n;x++)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

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

struct SimpleHash {
    size_t operator()(const std::pair<ll, ll>& p) const {
        return p.first * mod + p.second;
    }
};

ll gcd( ll a, ll b )
{
    ll c;
    while ( a != 0 ) {
        c = a; a = b%a;  b = c;
    }
    return b;
}

ll lcm( ll m, ll n )
{
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    
    return ((m / gcd(m, n)) * n);
}

int main()
{
    string s;
    cin >> s;
    for(int i = 0;i < 4;i++)
    {
        cout << s[i];
    }
    cout << " ";
    for(int i = 4;i < s.length();i++)
    {
        cout << s[i];
    }
    cout << endl;
    return 0;
    
}

Measured memory_bytes: 256
/*
Competitive programming template
Author: Aswin Sampath

*/


#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef priority_queue<ll,vl,greater<ll>()> pq_ll_min;
typedef priority_queue<ll> pq_ll_max; 
typedef stack<ll> s;
typedef queue<ll> q;


#define pi 3.141592653589793
#define PI  acos(-1.0)
#define space " "
#define endl '\n'
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define testcase ll t;cin>>t;while(t--)
#define dbxstl(x){for(auto ele:x)cout<<ele<<space; cout<<endl;}
#define dbxval(x){cout<<x<<endl;}

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

void solve(){
    printf("Hello\n");
}

int main(int argc, char const *argv[])
{
    ll a,b;
    double k;
    cin>>a>>b;
    
    if((a+b)%2==0){
        cout<<(a+b)/2<<endl;;
    }
    else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#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;}

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

int main() {
    ll n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    ll len = n * m / gcd(n, m);
    if (s[0] != t[0]) {
        cout << -1 << endl;
        return 0;
    }

    if (n >= m) {
        FOR(i, 1, n - 1) {
            if (((i * len / n) % (len / m) == 0) && (s[i] != t[i * m / n])) {
                cout << - 1 << endl;
                return 0;
            }
        }
    } else {
        FOR(i, 1, m - 1) {
            if (((i * len / m) % (len / n) == 0) && (t[i] != s[i * n / m])) {
                cout << - 1 << endl;
                return 0;
            }
        }
    }
    cout << len << endl;
    return 0;
}

Measured memory_bytes: 3764
#include<iostream>
using namespace std;
int a[17]={1};
int n,k;
int main()
{
	cin>>n>>k;
    for(int i=1;i<=n;i++)a[i]=min(a[i-1]+k,a[i-1]*2);
    cout<<a[n]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a,b;
	int result;
	char op;
	while(1){
		scanf("%d %c %d", &a, &op, &b);
		if(a>=0&&b<=20000){
			if(op=='+'){
				result=a+b;
			}
			else if(op=='-'){
				result=a-b;
			}
			else if(op=='*'){
				result=a*b;
			}
			else if(op=='/'){
				if(b!=0){
					result=a/b;
				}
			}
			else if(op=='?'){
				break;
			}
			printf("%d\n", result);
		}
	}
	return 0;
}

Measured memory_bytes: 600
d = int(input())
c = list(map(int, input().split()))

for _ in range(d):
    s = list(map(int, input().split()))
    ret = -20000
    ans = 1
    for i in range(26):
        tmp = s[i] - c[i] * 200
        if ret < tmp:
            ret = tmp
            ans = i + 1
    print(ans)

Measured memory_bytes: 9224
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 1e4 + 5;

int n, ans, a, b, cnt;
int len[maxn];
string s[maxn];

int main(){
	cin >> n;
	FOR(i, 0, n){
		cin >> s[i];
		len[i] = s[i].size();
		if(s[i].back() == 'A' && s[i][0] == 'B')
			++cnt;
		else if(s[i].back() == 'A')
			++a;
		else if(s[i][0] == 'B')
			++b;
		FOR(j, 0, len[i] - 1)
			if(s[i][j] == 'A' && s[i][j + 1] == 'B')
				++ans;
	}
	//printf("%d %d %d %d\n", a, b, cnt, ans);
	if(cnt)
		ans += cnt - 1;
	if(a && cnt)
		--a, ++ans;
	if(b && cnt)
		--b, ++ans;
	ans += min(a, b);
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
typedef struct team{
	int p,n,r;
}TEAM;
TEAM t[105];
int comp(const void *p,const void *q){
	TEAM *a=(TEAM *)p,*b=(TEAM *)q;
	return b->p - a->p ;
}
int a,b,c,d,n,i,j,x[105];
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++)t[i].n=i;
	for(i=0;i<n*(n-1)/2;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if(c>d)t[a].p+=3;
		else if(c==d)t[a].p++,t[b].p++;
		else t[b].p+=3;
	}
	qsort(t,n+1,sizeof(TEAM),comp);
	t[0].r=1;
	x[t[0].n]=1;
	for(i=1;i<n;i++){
		//printf("%d:%d\n",t[i].n,t[i].p);
		if(t[i].p==t[i-1].p)t[i].r=t[i-1].r;
		else t[i].r=i+1;
		x[t[i].n]=t[i].r;
	}
	for(i=1;i<=n;i++)printf("%d\n",x[i]);
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void)
{
    int r,c,i,j;
    static int s[101][101];
    
    scanf("%d%d",&r,&c);
    
    for(i=0;i<=r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&s[i][j]);
            printf("%d ",s[i][j]);
            s[i][c]+=s[i][j];
            s[r][j]+=s[i][j];
        }
        printf("%d\n",s[i][c]);
        
    }
    return 0;
    
}



Measured memory_bytes: 2048
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {
	
	int n;
	cin >> n;
	vector<int>p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	sort(p.rbegin(), p.rend());
	long long int t = 0;
	for (int i = 0; i < n; i++) {
		if (i)t += p[i];
		else t += p[i] / 2;
	}
	cout << t << endl;

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 #define PI 3.141592653
using namespace std;

int A[21], B[21], C[21];

void solve(){
	int n; cin>>n;
	for(int i=1; i<=n; i++){
		cin>>A[i];
	}
	int ans=0;
	for(int i=1; i<=n; i++){
		cin>>B[i];
	}
	for(int i=1; i<n; i++){
		cin>>C[i];
	}
	for(int i=1; i<=n ;i++){
		ans += B[A[i]];
		if(i != 1 && A[i] == A[i-1]+1){
			ans += C[A[i-1]];
		}
	}
	cout<<ans;


}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}


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



int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	int x, n; cin >> x >> n;
	
	if(n == 0){
		cout << x << endl;
		return 0;
	}
	
	vector<int> a(n), b(0); rep(i,n) cin >> a[i];
	sort(all(a));
	
	int j = 0;
	
	rep(i,100){
		if(i+1 != a[j]){
			b.push_back(i+1);
			//cout << i+1 << endl;
		}
		else j++;
	}
	int l = b.size();
	
	if(l == 0){
		if(x <= 50){
			cout << 0 << endl;
			return 0;
		}
		else{
			cout << 101 << endl;
			return 0;
		}
	}
	vector<int> c(l);
	
	rep(i, l) c[i] = abs(b[i] - x);
	
	sort(all(c));
	
	int d = c[0];
	
	//cout << d << endl;
	
	rep(i, n){
		if(b[i] == x-d){
			cout << x-d << endl;
			return 0;
		}
		else if(x-d <= 0){
			cout << 0 << endl;
			return 0;
		}
		else if(b[i] == x+d){
			cout << x+d << endl;
			return 0;
		}
		else if(x+d >= 101){
			cout << 101 << endl;
			return 0;
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		Integer length = s.nextInt();
		Integer[] seq = new Integer[length];
		for(int i = 0; i < length; i++){
			seq[i] = s.nextInt();
		}
		Integer count = 0;
		
		for(int i = 0; i < length; i++){
			Integer mini = i;
			for(int j = i; j < length; j++){
				if(seq[j] < seq[mini]){
					mini = j;	
				}
			}
			Integer bkp = seq[i];
			if(seq[i] != seq[mini]){
				seq[i] = seq[mini];
				seq[mini] = bkp;
				count++;
			}
		}
		
		for(int i = 0; i < length; i++){
			if(i == length - 1){
				System.out.print(seq[i] + "\n");
			}
			else{
				System.out.print(seq[i] + " ");
			}
		}
		System.out.println(count);
	}

}

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



int main(void) {
    string s;
    cin >> s;
    string ans;
    for (auto &&c : s) {
        if (c == 'B') {
            if ((int)ans.size() == 0) continue;
            ans.pop_back();
        }
        else
            ans.push_back(c);
    }
    cout << ans << endl;
    return 0;
}

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


using namespace std;


int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int x = tx - sx, y = ty - sy;
	for( size_t i = 0; i < x; i++ ) {
		cout << "R";
	}
	for( size_t i = 0; i < y; i++ ) {
		cout << "U";
	}
	cout << "R";
	for( size_t i = 0; i < y + 1; i++ ) {
		cout << "D";
	}
	for( size_t i = 0; i < x + 1; i++ ) {
		cout << "L";
	}
	cout << "U";

	for( size_t i = 0; i < y; i++ ) {
		cout << "U";
	}
	for( size_t i = 0; i < x; i++ ) {
		cout << "R";
	}
	cout << "U";
	for( size_t i = 0; i < x + 1; i++ ) {
		cout << "L";
	}
	for( size_t i = 0; i < y + 1; i++ ) {
		cout << "D";
	}
	cout << "R";
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << 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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vl march(5,0);
  string MARCH = "MARCH";
  rep(i, n){
    string s;
    cin >> s;
    rep(j,5){
      if(s[0]==MARCH[j]){
        march[j]++;
      }
    }
  }
  ll sum = 0;
  rep(i, 3){
    for (ll j = i + 1; j < 4;j++){
      for (ll k = j + 1; k < 5;k++){
        sum += march[i] * march[j] * march[k];
      }
    }
  }
  print(sum);
}


Measured memory_bytes: 3576
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#include <cmath>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int n, a[(int)1e5 + 5], b[(int)1e5 + 5];
ll ans;
int main(void) {
	scanf("%d", &n);
	for (int i = 0; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 0; i < n; i++) scanf("%d", &b[i]);
	for (int i = 0; i < n; i++) {
		if (a[i] <= b[i]) {
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
		}
		else {
			ans += b[i];
			b[i] = 0;
			a[i] -= b[i];
		}
		if (a[i + 1] <= b[i]) {
			ans += a[i + 1];
			a[i + 1] = 0;
			b[i] -= a[i + 1];
		}
		else {
			ans += b[i];
			a[i + 1] -= b[i];
			b[i] = 0;
		}
	}
	printf("%lld\n", ans);
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

ll gcd(ll x, ll y){
    if(y == 0) return x;
    return gcd(y, x % y);
}

map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

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

    ll g = gcd(a, b);
    auto mp = prime_factor(g);
    cout << mp.size() + 1 << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long int
#define pair <ll, ll> pi
#define vector <ll> vi
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define SQ(a) (a) * (a)
#define ordered_set tree<ll, null_type, greater_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen('input.txt', 'r', stdin);
    //freopen('output.txt', 'w', stdout);
    ll i, j, k, n, m, d, ans = 0,x,y;
    string s;
    ll cnt1=0,cnt2=0;
    char c;
    cin>>s;
    c=s[0];
    for(i=1;i<s.size();i++){
        if(s[i]!=c){
            cnt1++;
            c=s[i];
        }
    }
    string t;
    reverse(s.begin(),s.end());
    t=s;
    c=t[0];
    for(i=1;i<t.size();i++){
        if(t[i]!=c){
            cnt2++;
            c=t[i];
        }
    }
    cout<<min(cnt1,cnt2)<<endl;
    return 0;
}

Measured memory_bytes: 3716
def main():
    n, m = map(int, input().rstrip(" ").split(" "))
    shops = []
    for i in range(n):
        shops.append(list(map(int, input().rstrip(" ").split(" "))))

    shops.sort()

    total_price = 0
    total_bottles = 0
    for price, bottles in shops:
        if (total_bottles + bottles) < m:
            total_price += price * bottles
            total_bottles += bottles
        else:
            total_price += price * (m - total_bottles)
            break
    print(total_price)


if __name__ == '__main__':
    main()

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

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

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

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

const int MAX = 100100;

struct T
{
	int a, b, c;

	bool operator <(const T& t) const
	{
		return b - c > t.b - t.c;
	}
} A[MAX];

LL R1[MAX];
LL R2[MAX];

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

	int x, y, z;

	scanf("%d%d%d", &x, &y, &z);

	int n = x + y + z;
	FOR (i, 0, n)
	{
		scanf("%d%d%d", &A[i].a, &A[i].b, &A[i].c);
	}

	sort(A, A+n);


	FILL(R1, -1);
	FILL(R2, -1);

	multiset<int> S;

	LL sum = 0;
	FOR (i, 0, y)
	{
		S.insert(A[i].a - A[i].b);
		sum += A[i].b;
	}

	R1[y-1] = sum;
	FOR (i, y, n)
	{
		S.insert(A[i].a - A[i].b);
		sum += A[i].b;

		int a = *S.rbegin();
		S.erase(S.find(a));

		sum += a;
		R1[i] = sum;
	}

	S.clear();
	sum = 0;
	FOR (i, 0, z)
	{
		S.insert(A[n-i-1].a - A[n-i-1].c);
		sum += A[n-i-1].c;
	}

	R2[n-z] = sum;
	RFOR(i, n-z, 0)
	{
		S.insert(A[i].a - A[i].c);
		sum += A[i].c;

		int a = *S.rbegin();
		S.erase(S.find(a));

		sum += a;
		R2[i] = sum;
	}

	LL res = -LINF;
	FOR (i, 0, n - 1)
	{
		if (R1[i] == -1 || R2[i+1] == -1) continue;
		res = max(res, R1[i] + R2[i+1]);
	}

	cout<<res<<endl;

}


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

bool comp(char a, char b){
  return a > b;
}
int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), comp);

  bool ret = true;
  
  if(s.size() < t.size()){
 	int i = 0;
    while(i < s.size()){
      if(s.at(i) != t.at(i)) ret = false;
      i++;
    }
  }else ret = false;
  
  if(!ret){
    ret = false;
    for(int i = 0; i < min(s.size(), t.size());i++){
      if(s.at(i) < t.at(i)) ret = true;
    }
  }
  if(ret) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
INFTY=10**18

def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    if(a.count(0)!=0):
        return 0
        
    res=a[0]
    for i in range(1,n):
        res*=a[i]
        if res>INFTY:
            return -1
    return res

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

Measured memory_bytes: 21644
#include "bits/stdc++.h"
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first
#define s second
using namespace std;
const int mod = 1e9 + 7;
int logi(int n) {int p = 0; while (n / 2) {n = n / 2; p++;} return p;}
int poww(int x, int y) {int pro = 1; while (y) {if (y & 1)pro = ((pro % mod) * (x % mod) % mod); y = y >> 1; x = ((x % mod) * (x % mod) % mod);} return pro;}
int poww2(int x, int y) {int pro = 1; while (y) {if (y & 1)pro = pro * x; y = y >> 1; x = x * x;} return pro;}
bool isprime(int n) { if (n == 1) return false; for (int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true;}
vector<vector<int>> adj(2e5);
vi visited(2e5, 0);
/*

*/

int solve() {
	string n;
	cin >> n;
	int sum = 0, size = n.size();
	for (int i = 0; i < size; i++)
	{
		sum = (sum + (n[i] - '0')) % 9;
	}
	if (sum % 9 == 0) cout << "Yes";
	else cout << "No";
	return 0;
}
int32_t main() {
	/*#ifndef ONLINE_JUDGE
	    //for getting input from input.txt
	    freopen("input.txt","r",stdin);
	    //for writing output to output.txt
	    freopen("output.txt","w",stdout);
	#endif*/
	fast;
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 9824
from sys import stdin,stdout
def ws(pos,win):
    l,r=win
    l1=pos-r
    r1=pos-l
    l=max(l1,0)
    r=max(r1,0)
    # print(pos,l,r)
    sm=ps[r]-(ps[l-1] if l>=1 else 0)
    return (sm+M)%M
n,k=list(map(int,stdin.readline().split()));w=[];s=[];M=998244353
for _ in range(k):
    x,y=list(map(int,stdin.readline().split()))
    w+=[[x,y]]
dp=[0]*(n+1);dp[1]=1;ps=[0,1]
for i in range(2,n+1):
    for win in w:
        ans=ws(i,win)
        dp[i]=(dp[i]+ans)%M
    ps+=[ps[-1]+dp[i]]
# print(dp)
# print(ps)
print(dp[n])

Measured memory_bytes: 28092
N = int(input())
S = [None for _ in range(N)]
T = [None for _ in range(N)]

for n in range(N):
    s, t = input().split()
    S[n] = s
    T[n] = int(t)

X = input()

is_sleep = False
sleep_t = 0
for n in range(N):
    if is_sleep:
        sleep_t += T[n]
    if S[n] == X:
        is_sleep = True

print(sleep_t)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
map< string , int > mp;
int main()
{
	dhoom;
	ll n , k;
	cin >> n >> k;
	if(n % k == 0)
		cout << 0 << endl;
	else
		cout << 1 << endl;
	return 0;
} 



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a==1) a=14;
  if(b==1) b=14;
  if(a==b){
    printf("Draw\n");
  }else if(a>b){
    printf("Alice\n");
  }else{
    printf("Bob\n");
  }

  return 0;

}

Measured memory_bytes: 128
n = int(input())
l = list(map(int,input().split()))
if len(l) < 3:
  print(0)
  exit()
count = 0
l = sorted(l)
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if l[i] != l[j] != l[k] and l[i]+l[j] > l[k]:
        count += 1
print(count)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K; cin>>N>>K;
    vector<int> h(N,0);
    for(int i=0;i<N;i++){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    long long int mini=2000000000;
    for(int i=0;i<=N-K;i++){
        long long int ans=0;
        ans=h[i+K-1]-h[i];
        mini=min(ans,mini);
    }
    cout<<mini;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main() {
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if (a*b > c*d) {
		printf("%d\n", a*b);
	}
	if (c*d >= a*b) {
		printf("%d\n", c*d);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A,B,C = 0;
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        if(A + B >= C){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-

input()
data = list(map(int, input().split()))

# Nを打ち消す
lis = [data[i-1]-i for i in range(1, len(data)+1)]

# ソートして中央値をとる
lis.sort()
med = lis[len(lis)//2]

# 各値から中央値を引く
reslis = [abs(i - med) for i in lis]

# 和を出す
print(sum(reslis))


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

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

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

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

int color(int rate) {
  if (rate <= 399) return 0;
  else if (rate <= 799) return 1;
  else if (rate <= 1199) return 2;
  else if (rate <= 1599) return 3;
  else if (rate <= 1999) return 4;
  else if (rate <= 2399) return 5;
  else if (rate <= 2799) return 6;
  else if (rate <= 3199) return 7;
  else return 8;
}

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

  map<int, int> cnt;
  rep(i, N) {
    int a;
    cin >> a;
    cnt[color(a)]++;
  }

  int b = 0;
  rep(i, 8) {
    b += (cnt[i] != 0);
  }

  int mini, maxi;
  mini = (b == 0) ? 1 : b;
  maxi = (b == 0) ? cnt[8] : mini + cnt[8];

  cout << mini << " " << maxi << endl;
  return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <int> W(N, 0);
	int sum = 0;
	for (int ii = 0; ii < N; ++ii){
		cin >> W[ii];
		sum += W[ii];
	}

	int ans = 100100100100;
	int index = 1;
	while (index < N) {
		int A = 0;
		for (int ii = 0; ii < index; ++ii){
			A += W[ii];
		}
		int B = sum - A;
		int diff = abs(A - B);
		ans = min(ans, diff);
		index++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if ((x - r) < 0 || (x + r) > W || (y - r) < 0
		|| (y + r) > H) {
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
}


Measured memory_bytes: 2104
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, D = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    d2=D**2
    cnt=0
    for x,y in S:
        if x**2+y**2<=d2:
            cnt+=1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 107648
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 10, M = 1e3 + 10;
const int INF = INT_MAX;
const db PI = acos(-1);

void test();

int main() {
    fast_io();
    test();
    return 0;
}

void test() {
    int n;
    cin >> n;
    pair < pair < string, int >, int >p[n];
    for (int i = 0; i < n; ++i) {
        cin >> p[i].F.F >> p[i].F.S;
        p[i].F.S = -p[i].F.S;
        p[i].S = i + 1;
    }
    sort(p, p + n);
    for (int i = 0; i < n; ++i) {
        cout << p[i].S << "\n";
    }
}


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

int main(){
    int i, j, f;
    int b[26] = {};
    char c;
    string s, t;
    cin >> s >> t;
    for(i=0; i<26; i++){
        f = 0;
        for(j=0; j<s.size(); j++){
            if(s[j] == (char)'a'+i){
                if(f == 0){
                    c = t[j];
                    f++;
                    if(b[(int)c-'a'] == 1){
                        cout << "No";
                        return 0;
                    }else{
                        b[(int)c-'a']++;
                    }
                }else{
                    if(t[j] != c){
                        cout << "No";
                        return 0;
                    }
                }
            }
        }
    }
    cout << "Yes";
    return 0;
}

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

using namespace std;

const int N = 3010;
const int P = 998244353;

int dp[N][N];

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (int i = a; i <= c; ++i) {
        for (int j = b; j <= d; ++j) {
            dp[i][j] += (j * 1ll * dp[i-1][j])%P;
            dp[i][j] += (i * 1ll * dp[i][j-1])%P;
            dp[i][j] -= (((i - 1) * 1ll * (j - 1))%P * 1ll * dp[i-1][j-1])%P;
            dp[i][j] %= P;
            dp[i][j] += P;
            dp[i][j] %= P;
        }
    }
    printf("%lld\n", dp[c][d]);
}

Measured memory_bytes: 38900
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int r, g, b;
    cin >> r >> g >> b;
    const int num = r * 100 + g * 10 + b;
    cout << (num % 4 == 0 ? "YES" : "NO") << endl;
}


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

#define rep(i, j) for (ll i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << " : " << x << endl;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

int main() {

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

    const ll mod = 1e9 + 7;
    vll primes = {2};
    for(ll i = 3; i * i <= 1001000; i+=2) {
        bool ok = true;
        for(const auto& e: primes) if (i % e == 0) {
            ok = false;
            break;
        }
        if (ok) primes.push_back(i);
    }

    map<ll, ll> mp;
    vector<map<ll,ll>> vmp(n);
    vll ps(n, 1);
    set<ll> se;
    rep(i, n) {
        ll x = a[i];
        for(const auto& e: primes) {
            while(x % e == 0) {
                x /= e;
                vmp[i][e]++;
            }
            if (vmp[i][e] > 0) {
                mp[e] = max(mp[e], vmp[i][e]);
            }
        }
        ps[i] = x;
        if(x > 0) se.insert(x);
    }

    // for(auto p: mp) if(p.second > 0) {
    //     cout << p.first << " : " << p.second << endl;
    // }

    // rep(i, n) if (ps[i] > 1) cout << ps[i] << " ";
    // cout << endl;

    vector<ll> vse;
    for(auto z: se) vse.push_back(z);
    ll ans = 0;
    rep(i, n) {
        ll y = 1;
        for(auto z: vse) if(z != ps[i]) y = (y * z) % mod;
        for(const auto& p: mp) {
            ll key = p.first;
            // cout << key << " " << mp[key] << " " << vmp[i][key] << endl;
            rep(k, mp[key] - vmp[i][key]) {
                y = (y * key) % mod;
            }
        }
        // cout << i << " " << y << endl;
        ans = (ans + y) % mod;
    }

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

Measured memory_bytes: 106496
N=int(input())

input_=[N]
for n in range(N):
    input_.append(input())
    
P=[]
for n in range(N):
    P.append(int(input_[n+1].split()[0]))
    
P.append(int(input_[n+1].split()[1]))

M=[[0]*(N) for x in range(N)]

for n in range(1,N):
    for i in range(N-n):
        M[i][i+n]=10**100
        for k in range(i,i+n):
            P_0=P[i]
            P_1=P[k+1]
            P_2=P[i+n+1]
            M_=M[i][k]+M[k+1][i+n]+P_0*P_1*P_2
            M[i][i+n]=min(M[i][i+n],M_)
            
print(M[0][-1])


Measured memory_bytes: 5676
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		String s1 = s.next();
		String s2 = s.next();
		
		char[] s1c = s1.toCharArray();
		char[] s2c = s2.toCharArray();
		
		boolean ok = true;
		
		for(int i = 0; i < s1c.length; i++) {
			if(s1c[i] != s2c[i])
				ok = false;
		}
		
		if(ok) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		s.close();
	}
}


Measured memory_bytes: 35660
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int N=(int)1e5+6;
vector<bool>primes(N);
void sieve(){
	fill(allv(primes),1);
	primes[0]=primes[1]=0;
	loop(N,i,2){
		for(int j=i*2;j<N;j+=i)
			primes[j]=0;
	}
}
int main() {
	sieve();
	int cum[N]={},q;
	loop(N,i,2){
		cum[i]+=(cum[i-1]+(primes[i]&&primes[(i+1)/2]));
	}
	cin>>q;
	while(q--){
		int l,r;cin>>l>>r;
		cout<<cum[r]-cum[l-1]<<endl;
	}
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#define RE(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define SZ(x) ((int)(x.size()))
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using C = complex<double>;
const double PI = 3.14159265;
const double eps = 1e-8;
const int N = 1e6 +10;
const int M = 1e9 + 7;
const int inf = 1e9+7;
const ll INF = 1e18;
ll pw(ll a, ll b){ll t=1;a%=M;for(;b;b>>=1){if(b&1){t=t*a%M;}a=a*a%M;}return t;}
ll gcd(ll a, ll b){return b?gcd(b, a%b): a;}

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	string s;
    cin>>s;
    int j=s.size()-1;
    int ans=0;
    for(int i=0;i<j;i++){
        if(s[i]!=s[j])ans++;
        j--;
    }
    cout<<ans<<"\n";
}

/*
#ifdef DEBUG
	cout<<"I Love Co shu Nie [ https://coshunie.com/ ]"
#endif
*/


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long a, b, n, sol;
int main(){
    cin>> n >> a >> b;
    sol = min(b - 1, n - a);
    if( (b - a) % 2 == 0){
        sol = min(sol, (b - a) / 2);
    }
    else{
        sol = min(sol, (b - a) / 2 + 1 + min(a - 1, n - b) );
    }
    cout<< sol;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = INT_MAX / 2;

int main(){
    ll N, M; cin >> N >> M;
    ll ans;
    for (int i = M/N; i >= 1; i--)
    {
        if((M-N*i)%i==0){
            ans = i;
            break;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 4000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

std::vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){ 
        IsPrime.resize(max+1,true); 
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i)
        if(IsPrime[i])
            for(size_t j=2; i*j<=max; ++j) 
                IsPrime[i*j] = false;     
}

int main(){
	init();
	ll a;cin>>a;
	string s;cin>>s;
	ll n=0;
	for(int i=0;i+2<s.size();i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')n++;
	}
	cout<<n<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1027_buginner_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int result;

            String[] inputNum = Console.ReadLine().Split(' ');
            int numA = int.Parse(inputNum[0]);
            int numB = int.Parse(inputNum[1]);

            if (((numA < 10) && (0 < numA)) && ((numB < 10) && (0 < numB)))
            {
                result = numA * numB;
            }
            else
            {
                result = -1;
            }

            Console.WriteLine(result);

        }
    }
}


Measured memory_bytes: 13140
# -*- coding: utf-8 -*-

w, h, x, y = map(int, input().split())

def multi(w, h, x, y):
    core = (w/2, h/2)
    if (x == core[0])^(y == core[1]):
        return False
    elif x == core[0]:
        return True
    else:
        return False

print(w*h/2, 1 if multi(w, h, x, y) else 0)


Measured memory_bytes: 9036
#include <iostream>
#include <string>

int main()
{
        std::string str;
        getline(std::cin,str);

        for(int i=0;i<str.size();i++)
        {

                if('a' <= str[i] && str[i] <= 'z')
                        str[i] -= ('a'-'A');
                else if('A' <= str[i] && str[i] <= 'Z')
                        str[i] += ('a'-'A');

        }

        std::cout << str << std::endl;
}


Measured memory_bytes: 3156
#include<iostream> 
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> vii;
const int MOD=1000000007;

ll add(ll a,ll b){ 
	int v=a+b;
	if(v>=MOD){ 
		v-=MOD;
	} 
	return v;
}
ll modmul(ll a,ll b){ 
	return (a%MOD)*(b%MOD)%MOD;
}

vii matmul(vii a,vii b){ 
	int n=a.size();
	vii out(n,vector<ll>(n)); 
	for(int i=0;i<n;i++){ 
		for(int j=0;j<n;j++){ 
			int val=0;
			for(int p=0;p<n;p++){ 
				val=add(val,modmul(a[i][p],b[p][j])); 
			}
			out[i][j]=val;
		} 
	}
	return out;
} 
vii bin_exp(vii a,ll b){ 
	int n= a.size();
	vii res(n,vector<ll>(n));
	for(int i=0;i<n;i++){ 
		for(int j=0;j<n;j++){ 
			res[i][j]=i==j?1:0; 
		} 
	} 
	while(b>0){ 
		if(b&1){ 
			res=matmul(res,a);
		}
		a=matmul(a,a);
		b>>=1;
	} 
	return res;
}



int main(){ 
	ios::sync_with_stdio(false); 
	cin.tie(0); 
	int n;
	ll k;
	cin>>n>>k;
	vii adj(n,vector<ll>(n));
	for(int i=0;i<n;i++){ 
		for(int j=0;j<n;j++){
			cin>>adj[i][j];
		} 
	} 
	vii res=bin_exp(adj,k); 
	ll am=0;
	for(int i=0;i<n;i++){ 
		for(int j=0;j<n;j++){
			am=add(am,res[i][j]); 
		}
	}
	cout<<am;



	
	return 0;
} 



Measured memory_bytes: 384