akhauriyash/Code-Regression huggingface dataset:
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
S=get_nsp
x=0
ans=0
N.times do|i|
  case S[i]
  when "I" then
      x+=1
  when "D" then
      x-=1
  end
  ans=x if ans<x
end
puts ans

Measured memory_bytes: 1788
#include <stdio.h>

int main(void) {
	int N;
	int K;
	int tmp;
	double result = 0;
	
	scanf("%d", &N);
	scanf("%d", &K);

	for (int i = 1; i <= N; i++) {
		tmp = i;

		while (tmp < K)
		{
			tmp *= 2;
		}
		result += 1 / (double)(tmp / i * N);
	}	
	
	printf("%.12lf", result);

	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
s = input()

s_a = s[:int(len(s)/2)]

if len(s)%2 == 0:
    s_b = s[(int(len(s)/2)):]
else:
    s_b = s[(int(len(s)/2) + 1):]
s_b = s_b[::-1]

res = 0
for i in range(len(s_a)):
    if s_a[i] == s_b[i]:
        pass
    else:
        res += 1

print(res)

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

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

  int i;
  int d, sum;

  while (cin >> d) {
    sum = 0;

    for (i = 0; (i * d != 600); i++) {
      sum += d * (i * i * d * d);
    }

    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 1192
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int[][] dxy = { { -1, 0 }, { 0, -1 }, { 0, 0 }, { 0, 1 }, { 1, 0 } };

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int MAX = 10;
		while (n-- > 0) {
			boolean[][] map = new boolean[MAX][MAX];
			for (int i = 0; i < MAX; i++) {
				for (int j = 0; j < MAX; j++) {
					map[i][j] = scanner.nextInt() == 0;
				}
			}
			boolean[][] fld = new boolean[MAX][MAX];
			for (int i = 0; i < 1 << 10; i++) {
				for (boolean[] b : fld) {
					Arrays.fill(b, false);
				}
				boolean[][] tmp = new boolean[MAX][MAX];
				for (int j = 0; j < MAX; j++) {
					tmp[j] = Arrays.copyOf(map[j], MAX);
				}
				for (int j = 0; j < MAX; j++) {
					if (((i >> j) & 1) == 1) {
						slove(0, j, tmp);
						fld[0][j] = true;
					}
				}
				for (int j = 1; j < MAX; j++) {
					for (int k = 0; k < MAX; k++) {
						if (!tmp[j - 1][k]) {
							slove(j, k, tmp);
							fld[j][k] = true;
						}
					}
				}
				boolean flag = true;
				for (int j = 0; j < MAX; j++) {
					if (!tmp[MAX - 1][j]) {
						flag = false;
						break;
					}
				}
				if (flag) {
					break;
				}
			}
			for (int i = 0; i < MAX; i++) {
				for (int j = 0; j < MAX; j++) {
					System.out.print(fld[i][j] ? '1' : '0');
					System.out.print(j == MAX - 1 ? '\n' : ' ');
				}
			}
		}
	}

	private static void slove(int y, int x, boolean[][] tmp) {
		for (int i = 0; i < 5; i++) {
			int dy = y + dxy[i][0];
			int dx = x + dxy[i][1];
			if (0 <= dy && dy < 10 && 0 <= dx && dx < 10) {
				tmp[dy][dx] = !tmp[dy][dx];
			}
		}
	}
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> a(n);
    cin >> a;
    sort(a.begin(), a.end());

    const int m = a.back();
    a.pop_back();
    
    int x = a.front();
    each (i, a) {
      int y = i;
      int z = x;
      if (m / 2 < y) y = m - y;
      if (m / 2 < z) z = m - z;
      if (z < y) {
        x = i;
      }
    }

    cout << m << ' ' << x << endl;
  }

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int r;
    cin >> r;
    cout << (10 - r/200) << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main(){
	int w, h, n; cin >> w >> h >> n;
	vector<int> ww(w, 1), hh(h, 1);
	for(int i = 0; i < n; i++){
		int x, y, a; cin >> x >> y >> a;
		if(a == 1) for(int j = 0; j < x; j++) ww[j] = 0;
		else if(a == 2) for(int j = x; j < w; j++) ww[j] = 0;
		else if(a == 3) for(int j = 0; j < y; j++) hh[j] = 0;
		else if(a == 4) for(int j = y; j < h; j++) hh[j] = 0;
	}
	cout << max(0, (accumulate(ww.begin(), ww.end(), 0)) * (accumulate(hh.begin(), hh.end(), 0))) << endl;
	return 0;
}



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

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a,k) accumulate(a.begin(),a.begin()+k,0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

int main(){
  ll n,w; cin >> n >> w;
  vector<vector<ll>> v(4);
  rep(i,4) v[i].pb(0);
  ll a,b; cin >> a >> b; v[0].pb(b);
  rep(i,n-1){
    ll c,d; cin >> c >> d;
    v[c - a].pb(d);
  }
  
  rep(i,4) sort(rall(v[i]));

  ll ans = 0;

  rep(i,v[0].size()) rep(j,v[1].size()) rep(k,v[2].size()) rep(l,v[3].size()){
    ll totalw = a * i + (a+1) * j + (a+2) * k + (a+3) * l;
    if(totalw > w) break; // lを増やしてもしょうがないのでbreak;
    ll totalv = SUM(v[0],i) + SUM(v[1],j) + SUM(v[2],k) + SUM(v[3],l);
    ans = max(ans, totalv);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;



const double PI=3.14159265358979323846;

int main(void){
    ll n;
    cin>>n;
    map<ll,ll>m;
    for(ll i=1;i<n;i++){
        ll a;
        cin>>a;
        m[a]++;
    }
    for(ll i=1;i<=n;i++)cout<<m[i]<<endl;
    return 0;
}

Measured memory_bytes: 16100
n,*aa = map(int, open(0).read().split())

def is_prime(x):
    if x in [0,1]:
        return False
    if x == 2:
        return True
    if not x%2:
        return False
    for i in range(3,int(x**0.5+1e-8)+1,2):
        if not x%i:
            return False
    return True

print(sum(is_prime(a) for a in aa))


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

int main()
{
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;

    if ((int)s.size() == a + b + 1)
    {
        for (int i = 0; i < a + b + 1;++i)
        {
            if(i==a)
            {
                if (s[i] != '-')
                {
                    cout << "No" << endl;
                    return 0;
                }
            }
            else if (s[i] < '0' || s[i] > '9')
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3588
#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<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



int main()
{

    int n, m, k;
    cin >> n >> m >> k;
    vector<ll>a(n+1), b(m+1);
    for (int i = 1; i <= n; i++)cin >> a[i];
    for (int i = 1; i <= m; i++)cin >> b[i];

    int x = 0, y = 0;
    int ans = 0;
    ll p = 0;
    vector<ll>ra(n+2), rb(m+2);

    for (int i = 0; i <= n; i++) {
        ra[i] += a[i];
        ra[i + 1] += ra[i];
    }
    for (int i = 0; i <= m; i++) {
        rb[i] += b[i];
        rb[i + 1] += rb[i];
    }
    int j = 0;
    for (int i = n ; i >= 0; i--) {
        if (ra[i] > k)continue;
        while (rb[j]+ra[i] <=   k&&j<=m) {ans = max(ans, j + i);
            j++;
        }
        if(ra[i]+rb[j]<=k && j <= m)ans = max(ans, j + i);
       // cout << i << " " << j << endl;
        
        
    }



    cout << ans << endl;

    return 0;

}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n, a, b;
    cin >> n >> a >> b;

    cout << min(a*n, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define repeat(i, n) for(int i=0;i<n;i++)
#define repeat_from(i, m, n) for(int i=m;i<n;i++)
using namespace std;
int main()
{
    int n;
    //cin>>n;
    while(cin>>n){
        vector<int> a1(n);
        vector<int> a2(n);
        repeat(i, n){
            cin>>a1[i]>>a2[i];
        }
        long long s=a1[0], t=a2[0];
        repeat_from(i, 1, n){
            long long ta=max(s/a1[i], t/a2[i]);
            while(!(s<=ta*a1[i]&&t<=ta*a2[i])){
                ta+=1;
            }
            s=ta*a1[i];
            t=ta*a2[i];
        }
        cout<<s+t<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
 
  // 変数aで入力を受け取る
  cin >> a;

  if (a%100%10==2 ||a%100%10==4||a%100%10==5||a%100%10==7||a%100%10==9){
  cout << "hon" << endl;}
  else if(a%100%10==0 ||a%100%10==1||a%100%10==6||a%100%10==8){
  cout << "pon" << endl;}
  else if(a%100%10==3){
  cout << "bon" << endl;}}
  

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define pb push_back
#define endl '\n'
#define IO ios::sync_with_stdio(false)
using namespace std;
const ll maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
int a,b,c,n,m,t,k,num[maxn];
string str;
int main(){
    ll k;
    cin >> k;
    int cnt = 0;
    while(k > 0){
        k--;
        num[++cnt] = k % 26;
        k /= 26;
    }
    for(int i = cnt; i >= 1; i--)
        cout << (char)('a' + num[i]);
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <stdint.h>
#include <vector>
#include <limits.h>
#include <utility>
#include <queue>
#include <map>

using namespace std;

typedef struct Edge {
  unsigned dest;
  unsigned dist;
} Edge;

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

  vector<uint64_t> dist_to_root(N+1,UINT64_MAX);
  multimap<unsigned, Edge> edges;
  
  for (int n=0; n<N-1; ++n) {
    unsigned u, v, w;
    cin >> u >> v >> w;
    Edge e1 = {v,w};
    edges.emplace(u,e1);
    Edge e2 = {u,w};
    edges.emplace(v,e2);
  }

  unsigned root=1;
  dist_to_root[root] = 0;

  queue<unsigned> parents;
  parents.push(root);
  while(!parents.empty()) {
    unsigned parent = parents.front();
    parents.pop();
    auto xx = edges.equal_range(parent);
    for (auto xxx=xx.first; xxx!=xx.second; ++xxx) {
      unsigned child = xxx->second.dest;
      uint64_t new_dist_to_root = dist_to_root[parent] + xxx->second.dist;
      if (new_dist_to_root < dist_to_root[child] ) {
	dist_to_root[child] = new_dist_to_root;
	parents.push(child);
      }
    }
  }

  for (int i=1; i<=N; ++i) {
    cout << dist_to_root[i]%2 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int n,a,ans=1;
  cin >> n;
  vector<int> cnt(n,0);
  REP(i,n) { cin >> a; cnt[a]++; }
  if (n%2 && cnt[0] != 1) { cout << 0 << endl; return 0; }
  for (int i = n%2?2:1; i < n; i+=2) {
    if (cnt[i] != 2) { cout << 0 << endl; return 0; }
    ans = ans*2%mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define N 10001
#define M 501
using namespace std;

int main(){
  int n,m;
  int A[N],B[M];
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];
  cin>>m;
  for(int i=0;i<m;i++)cin>>B[i];

  int cnt = 0;
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
      if(B[i] == A[j]) cnt++,j=n;

  cout<<cnt<<endl;


  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> p(n+2);
    vector<int> order(n+2);
    FOR(i,1,n) {
        cin>>p[i];
        order[p[i]]=i;
    }
    
    
    set<int> st;
    st.insert(0);
    st.insert(-1);
    st.insert(n+1);
    st.insert(n+2);
    
    ll ans=0;
    RFOR(i,n,1){
        auto itr=st.lower_bound(order[i]);
        itr++;
        int rightsright=min(n+1,*itr);
        itr--;
        int right=*itr;
        itr--;
        int left=*itr;
        itr--;
        int leftsleft=max(0,*itr);
        
        ans+=(ll)i*(left-leftsleft)*(right-order[i]);
        ans+=(ll)i*(rightsright-right)*(order[i]-left);
        st.insert(order[i]);
    }
    
    cout<<ans<<endl;
    
}


Measured memory_bytes: 5760
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int L = in.nextInt(), R = in.nextInt();
    int ans = Integer.MAX_VALUE;
    for (int i = L; i < Math.min(L + 2019, R); i++) {
      for (int j = i + 1; j <= Math.min(L + 2019, R); j++) {
        ans = Math.min(ans, (int) (((long) i * (long) j) % 2019));
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
import numpy as np
import collections
n=int(input())
a=list(map(int,input().split()))

#print(a[0])

b=np.zeros(n,dtype=int)
c=np.zeros(n,dtype=int)

for i in range(n):
    b[i]=a[i]-1
    c[i]=a[i]+1
#print(b)
#print(c)

mylist=[]
mylist.extend(a)
mylist.extend(b)
mylist.extend(c)

#print(mylist)

d=collections.Counter(mylist)
#print(d.most_common())
print(d.most_common()[0][1])


Measured memory_bytes: 40388
#include <algorithm>
#include <queue>
#include <cstdio>
typedef long long LL ;
using namespace std ;
int main()
{
    int X,Y,Z;
    while(scanf("%d %d %d",&X,&Y,&Z)!=EOF)
    {
        int sum;
        sum=X-Z;
        printf("%d\n",sum/(Y+Z));
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string S;
  cin >> S;
  
  if (S=="SUN") cout << 7 << endl;
  else if (S=="MON") cout <<6 << endl;
  else if (S=="TUE") cout <<5 << endl;
  else if (S=="WED") cout <<4 << endl;
  else if (S=="THU") cout <<3<<endl;
  else if (S=="FRI") cout <<2<<endl;
  else cout <<1<<endl;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n,m;
    string a,b,c;
    cin>>n;
    if(n%10==9||n/90==1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    return 0;
}




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


int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	
	vector<int> v(n+1);
	
	for(int i=1;i<=n;i++)
	scanf("%d",&v[i]);
	
	vector<int> dp(n+1,INT32_MAX);
	
	dp[1] = 0;
    dp[2] = fabs(v[1]-v[2]);
	
	for(int i=3;i<=n;i++)
	{
	    for(int j=1;j<=k;j++)
	    {
	        if(i-j<1)
	        break;
	        
	        int dx = fabs(v[i]-v[i-j]);
	        dp[i] =min(dp[i],dp[i-j]+dx);
	    }
	}
	printf("%d\n",dp[n]);
	
	return 0;
}

Measured memory_bytes: 3960
#include<iostream>
#include<math.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main() {
//input
long long N,m,i,j,ha,sum;
long long num=100000000;
cin>>N;
//compute
ha=sqrt(N);
for(i=ha;i>0;i--){
 m=N%i;
 if(m==0){
  j=N/i;
  cout<<i+j-2;
  break;
 // sum=i+j;
 // if(num>sum)num=sum;
 }
}
//cout<<num-2;
	return 0;
}


Measured memory_bytes: 256
from math import gcd
k = int(input())
point = 0
li = [[0 for i in range(k+1)]for j in range(k+1)]
for i in range(1,k+1):
    for j in range(1,k+1):
        li[i][j] = gcd(i,j)
lin = []
for i in li:
    for j in i:
        if j != 0:
            lin.append(j)
for i in lin:
    for j in range(1,k+1):
        point += li[i][j]
print(point)


Measured memory_bytes: 70132
#include<bits/stdc++.h>
#include<queue>
using namespace std;
 
#define what_is(x) cout << #x << " is " << x << endl; 
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
// #define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define bug(n) {outl(n);return;}
#define pii pair<int,int>
#define lim 9223372036854775805
#define ninf -9223372036854775802
#define M 1000000007
#define eps 1e-9
#define MAX 5
#define N 500001
#define db(a) for(auto it:a) {cout<<it<<" ";}cout<<endl;
ll prime[MAX]; 
ll fact[MAX];

const long long INF64 = 1e18;
ll vpow(ll a,ll b,ll p){
    if(b==0)
        return 1;
    if(b==1)
            return a;
    ll temp=vpow(a,b/2,p);
    temp*=temp;
    temp%=p;
    if(b%2==0)
        return temp;
    temp=temp*a;
    temp%=p;
    return temp;
}

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

 
ll inverseMod(ll a,ll b,ll p){
    if(b==0)
        return 1;
    ll temp=vpow(b,p-2,p);
    ll ans=temp*a;
    ans%=p;
    return ans;
}
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (ll i = 2; i < MAX; i++) { 
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
}

void factorial(){
    fact[0]=1;
    fact[1]=1;
    rep(i,2,MAX){
        fact[i]=(fact[i-1]*i);
        // fact[i]%=M;
    }
}

void solve(ll ttt){
	ll n;
	cin>>n;
	vll a(n);
	rep(i,0,n)
		cin>>a[i];
	ll ans=0;
	rep(i,1,n){
		if(a[i]<a[i-1]){
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<ans<<endl;
}

int main(){
    io;
   
    // sieve();
    // factorial();
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
   // freopen("output1.txt","w",stdout);
#endif
    ll t=1;
    // cin>>t;
    fix(12);
    rep(q,1,t+1){
        // cout<<"Case #"<<q<<": ";
         solve(q);
        //solve2();
    }
    return 0;
    
}


Measured memory_bytes: 4780
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

int main()
{
    string S, T;
    int A, B;
    string U;
    cin >> S >> T >> A >> B >> U;
    if (S == U) {
        A--;
    } else {
        B--;
    }
    
    cout << A << " " << B;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            double a,b,c,d,e,f,x,y;
            String line = br.readLine();
            StringTokenizer tokens;
            DecimalFormat df = new DecimalFormat("0.000");
            df.setRoundingMode(RoundingMode.HALF_UP);
            while(line!=null){
                tokens = new StringTokenizer(line);
                a=Double.parseDouble(tokens.nextToken());
                b=Double.parseDouble(tokens.nextToken());
                c=Double.parseDouble(tokens.nextToken());
                d=Double.parseDouble(tokens.nextToken());
                e=Double.parseDouble(tokens.nextToken());
                f=Double.parseDouble(tokens.nextToken());
                y=(c*d-f*a)/(b*d-e*a);
                x=(c*e-b*f)/(a*e-b*d);
                if(x==-0){
                    x=0;
                }
                if(y==-0){
                    y=0;
                }
                System.out.println(df.format(x)+" "+df.format(y));
                line = br.readLine();
            }
        }
        catch(Exception e){
            System.out.println(e);
        }

    }

}

Measured memory_bytes: 25936
#include <stdio.h>

int main (void) {
    int h, w;

    for (;;) {
        scanf ("%d %d", &h, &w);

        if (h==0 && w==0) break;

        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                if ((i+j)%2==0) printf ("#");
                else printf (".");
            }
             printf ("\n");
        }
        printf ("\n");
    }

    return 0;
}


Measured memory_bytes: 2108
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(i)
#e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
f.sort()
ans=0
ma = []
for i in range(f[0],f[-1]+1):
    for k in f:
        ans+=((k-i)**2)
    ma.append(ans)
    ans=0
print(min(ma))

        

Measured memory_bytes: 8932
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

template <typename T>
using vec = vector<T>;

template <typename T>
using vec2 = vector<vector<T>>;

template <typename T>
using vec3 = vector<vector<vector<T>>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    int n, m;
    cin >> n >> m;

    vec<int> a(n), b(n), c(m), d(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }

    vec<int> ans(n, m + 1);

    for (int i = 0; i < n; i++) {
        int dis = 2000050000;

        for (int j = 0; j < m; j++) {
            if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < dis) {
                dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                ans[i] = j + 1;
            }
        }
    }

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

    return 0;
}


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

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

class Edge {
public:
    int next;
    int dist;
    int weight;
    Edge() {}
    Edge(int n, int d, int w) {
	next = n;
	dist = d;
	weight = w;
    }
};

class Info {
public:
    int node;
    int dist;
    int left;
    Info(int n, int d, int l) {
	node = n;
	dist = d;
	left = l;
    }
    bool operator< (const Info &a) const {
	if (dist == a.dist && node == a.node) return left < a.left;
	return dist > a.dist;
    }
};

int dist[100][110];
vector<vector<Edge>> nexts;

signed main() {
    int N, M, L;
    while (cin >> N >> M >> L) {
	if (N == 0) break;

	nexts.clear();
	nexts.resize(N);
	rep(i, 100) rep(j, 101) dist[i][j] = INT_MAX;

	int A, B, D, E;
	rep(i, M) {
	    cin >> A >> B >> D >> E;
	    A--; B--;
	    nexts[A].push_back(Edge(B, D, E));
	    nexts[B].push_back(Edge(A, D, E));
	}

	priority_queue<Info> q;
	q.push(Info(0, 0, L));
	rep(i, 101) dist[0][i] = 0;
	while (!q.empty()) {
	    Info info = q.top(); q.pop();
	    if (info.dist > dist[info.node][info.left]) continue;
	    if (info.node == N - 1) {
		cout << info.dist << endl;
		break;
	    }
	    for (Edge &edge : nexts[info.node]) {
		if (info.left >= edge.dist && edge.weight > 0) {
		    if (dist[edge.next][info.left - edge.dist] > info.dist) {
			rep(i, info.left - edge.dist) {
			    if (info.dist >= dist[edge.next][i] - 1) break;
			    dist[edge.next][i] = info.dist - 1;
			}
			dist[edge.next][info.left - edge.dist] = info.dist;
			q.push(Info(edge.next, info.dist, info.left - edge.dist));
		    }
		}
		int ndist = info.dist + edge.weight;
		if (dist[edge.next][info.left] > ndist) {
		    rep(i, info.left) {
			if (dist[edge.next][i] >= ndist - 1) break;
			dist[edge.next][i] = ndist - 1;
		    }
		    dist[edge.next][info.left] = ndist;
		    q.push(Info(edge.next, ndist, info.left));
		}
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 4100
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int Pair[600];
long C[601];
long DP[600][600];
void Calc(){
	int N = rei()*2;
	int K = rei();
	for(int i=0;i<N;i++){
		Pair[i] = -1;
	}
	for(int i=0;i<K;i++){
		int f = rei()-1;
		int t = rei()-1;
		Pair[f] = t;
		Pair[t] = f;
	}
	C[0] = 1;
	for(int i=2;i<=N;i++){
		C[i] = C[i-2] * (i-1) % mod;
	}
	long ans = C[N-2*K];
	for(int i=1;i<N;i++){
		for(int j=i+1;j<N;j++){
			bool OK = true;
			int c1 = 0;
			int c2 = 0;
			for(int k=i;k<=j;k++){
				if(Pair[k] == -1){
					c1++;
				}
				else{
					OK &= i <= Pair[k] && Pair[k] <= j;
				}
			}
			if(!OK){
				continue;
			}
			c2 = N-2*K-c1;
			long d = C[c1];
			for(int k=i;k<j;k++){
				if(Pair[k] == -1){
					c1--;
				}
				d += mod - DP[i][k] * C[c1] % mod;
			}
			d %= mod;
			ans += d * C[c2] % mod;
			DP[i][j] = d;
		}
	}
	ans %= mod;
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 3072
#include <iostream>
using namespace std;
int main(){
int H,W;
while(1){
    cin>>H>>W;
    if(H==0&&W==0){
        break;
    }
    for(int n=0;n<H;n++){
        for(int i=0;i<W;i++){
            if(i%2==0&&n%2==0){
                cout<<"#";
            }
            else if(i%2==1&&n%2==1){
                cout<<"#";
            }
            else{
                cout<<".";
            }
        }
        cout<<endl;
    }
    cout<<endl;
}
return 0;
}



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


vector<vector<ll>> graf;
ll ans =0 , lans=0 ; 
ll visited[200001];
 void dfs(ll a ){
  visited[a]=1 ;  lans++;
  ll s = graf[a].size();
  for(ll i=0; i<s;i++){
    if(!(visited[graf[a][i]])){ dfs(graf[a][i]) ;}
  }
 }
int main(){
ll n , m ;
cin >>n >> m;

for(ll i=0; i<200001 ;i++){
  visited[i]=0;
}
for(ll i=0; i<=n ;i++){
  vector<ll>  v; graf.push_back(v);
}
while(m--){
ll a , b ; cin >>a  >> b; graf[a].push_back(b); graf[b].push_back(a);

}
  
  for(ll i=1; i<=n ;i++){
    lans =0;
    if(visited[i]==0){ dfs(i);    }
     ans = max(ans,lans);
  }
  cout << ans << endl;
   return 0;
  }
 



Measured memory_bytes: 24972
#include <iostream>
#include <vector>
#include <algorithm>

class Line{
public:
  Line(int h, int p, int q):h(h), p(p), q(q) {}
  int h,p,q;
};

int main(){
  int n,m,a;
  for(;;){
    std::cin >> n >> m >> a;
    if(n == 0) break;

    std::vector<Line> line;
    for(int i=0; i<m; i++){
      int h,p,q;
      std::cin >> h >> p >> q;
      line.push_back(Line(h,p,q));
    }

    std::sort(line.begin(),line.end(),[](Line a,Line b)->bool{return a.h < b.h;});

    int ns[n];
    for(int i=0; i<n; i++) ns[i]=i+1;

    for(Line l : line) std::swap(ns[l.p-1],ns[l.q-1]);

    std::cout << ns[a-1] << std::endl;
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int cost, one_yen, mod=0, sum=0;

      cin >> cost >> one_yen;
      mod = cost / 500;
      sum = cost - mod * 500;
      
      if((one_yen - sum) >= 0 ) {
      	cout << "Yes" << endl;
      } else {
          cout << "No" << endl;
      }
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
string str; set<string> s; char ss[N];
bool operator < (const string &x,const string &y)
{
  for(int i=0;i<min(x.length() , y.length());i++)
    if(x[i] != y[i]) return x[i] < y[i];
  return x.length() < y.length();
}
int main()
{
  scanf("%s",ss+1); int len = strlen(ss+1); int K; cin>>K;
  
  for(int i=1;i<=len;i++)
  {
  	str.clear();
  	for(int j=0;j<=K && i+j<=len;j++)
  	{
  	  str.push_back(ss[i+j]);
  	  s.insert(str);
  	}
  }
  
  while(K!=1){s.erase(s.begin()); K--;}
  cout<<(*s.begin())<<endl; 
  
  return 0;
}

Measured memory_bytes: 2176
/*==============================================*\
ID:          shahidul_brur
 
Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh
 
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = (int)2e5+5;
const int logn = 20;
int a[maxn], b[maxn];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    f1(i,n-1) cin>>b[i+1];
    ll tot = 0;
    a[1]= b[2];
    a[2]= b[2];
    f2(i,2,n)
    {
        if(b[i]<a[i-1]) a[i-1] = b[i];
        a[i] = b[i];
    }
    f1(i,n) tot+=a[i];
    cout << tot;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;
int main() {
    i64 L, R;
    cin >> L >> R;
    if(R - L >= 2019) {
        cout << 0 << endl;
    } else {
        R %= 2019, L %= 2019;
        if(R < L) {
            cout << 0 << endl;
        } else {
            i64 m = 1e10;
            for(i64 i = L; i <= R; i++) {
                for(i64 j = i + 1; j <= R; j++) {
                    m = min(m, (i * j) % 2019);
                }
            }
            cout << m << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)


int a, b, c, d, e, k;

bool solve() {
  if (abs(a - b) > k)
    return false;
  if (abs(a - c) > k)
    return false;
  if (abs(a - d) > k)
    return false;
  if (abs(a - e) > k)
    return false;
  if (abs(b - c) > k)
    return false;
  if (abs(b - d) > k)
    return false;
  if (abs(b - e) > k)
    return false;
  if (abs(c - d) > k)
    return false;
  if (abs(c - e) > k)
    return false;
  if (abs(d - e) > k)
    return false;
  return true;
}

int main() {
  cin >> a >> b >> c >> d >> e >> k;
  if (solve())
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define mkp(a,b) make_pair(a,b)
#define scf2(a,b) scanf("%lld%lld",&a,&b)
#define scf(a) scanf("%lld",&a)
#define pf(a) printf("%lld\n",a)
#define mx 10000010
using namespace std;

ll arr[100005];
ll dp[100005];
ll n,k;

int main()
{
    scf2(n,k);
    for(ll i=0;i<n;i++)scf(arr[i]);
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(ll i=2;i<n;i++)
    {
        //ll a=abs(arr[i]-arr[i-1])+dp[i-1];
        //ll b=abs(arr[i]-arr[i-2])+dp[i-2];
        ll mn=1e9;
        for(ll j=i-1;j>=max(0LL,i-k);j--)
        {
            ll a=abs(arr[i]-arr[j])+dp[j];
            mn=min(mn,a);
        }
        dp[i]=mn;
    }
    printf("%lld\n",dp[n-1]);
}









Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

char ch(int x){
    char t;
    if(x==0) t='A';
    else if(x==1) t='B';
    else if(x==2) t='C';
    else if(x==3) t='D';
    else if(x==4) t='E';
    else if(x==5) t='F';
    else if(x==6) t='G';
    else if(x==7) t='H';
    else if(x==8) t='I';
    else if(x==9) t='J';
    else if(x==10) t='K';
    else if(x==11) t='L';
    else if(x==12) t='M';
    else if(x==13) t='N';
    else if(x==14) t='O';
    else if(x==15) t='P';
    else if(x==16) t='Q';
    else if(x==17) t='R';
    else if(x==18) t='S';
    else if(x==19) t='T';
    else if(x==20) t='U';
    else if(x==21) t='V';
    else if(x==22) t='W';
    else if(x==23) t='X';
    else if(x==24) t='Y';
    else if(x==25) t='Z';
    return t;
}

int main(){
    int n;
    string s;
    cin>>n>>s;
    string t="";
    rep(i,s.size()){
        int a=s[i]-'A';
        a+=n;
        a%=26;
        //cout<<ch(a);
        t+=ch(a);
    }
    cout<<t<<endl;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
a.sort()
n = a[-1]
for i in range(N):
    if a[i]>=n/2:
        break

if n-a[i]>min(a[i-1],n-a[i-1]):
    r = a[i]
else:
    r = a[i-1]
print('{} {}'.format(n,r))

Measured memory_bytes: 14052
#include <bits/stdc++.h>
using namespace std;
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

const long long BIGINF = 2e18 + 7;
const int INF = 2e9 + 7;


int mul(int x, int y) {
	return (1LL * x * y) % MOD7;
}

int power(int x, int exp) {
	int res = 1;
	while (exp > 0) {
		if (exp % 2 == 1) {
			res = mul(res, x);
		}
		x = mul(x, x);
		exp /= 2;
	}
	return res;
}


int inv(int x) {
	return power(x, MOD7 - 2);
}


int main () {
	/*#ifndef ONLINE_JUDGE
		freopen("inputf.txt", "r", stdin);
		freopen("outputf.txt", "w", stdout);
	#endif*/

	int n;
	SCD(n);
	int a[10005];
	map<int, int> lcm;
	for (int i = 0; i < n; i++) {
		SCD(a[i]);
		int x = a[i];
		map<int, int> facts;
		for (int j = 2; j * j <= x; j++) {
			while(x % j == 0) {
				facts[j]++;
				x /= j;
			}
		}
		if (x != 1) facts[x]++;
		for(pair<int, int> p: facts) {
			lcm[p.first] = max(lcm[p.first], p.second);
		} 
	}
	int num = 1;
	for (pair<int, int> p: lcm) {
		for (int i = 0; i < p.second; i++) {
			num = mul(num, p.first);
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		//printf("%d ", mul(num, inv(a[i])));
		ans = (ans + mul(num, inv(a[i]))) % MOD7;
	}
	printf("%d" ,ans);
    return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

void solve(std::string X){
    LL ans=0;
    LL ns=0;
    for(auto c:X){
        if(c=='S'){
            ns++;
        }else{
            if(ns>0)ns--;
            else ans++;
        }
    }
    cout << ans+ns << endl;
}

int main(){
    std::string X;
    std::cin >> X;
    solve(X);
    return 0;
}


Measured memory_bytes: 772
#include<stdio.h>

int main(){
	int n,h[21]={0},ans=0,max=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&h[i]);
	}
	for(int i=1;i<=n;i++){
		if(max<=h[i]){
			ans++;
			max=h[i];
		}
			
	}
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
# ?を全てaに変えたときと、zに変えたときの順位を求める
import sys
readline = sys.stdin.readline

N = int(readline())

Alist = [None] * N
Zlist = [None] * N
for i in range(N):
  line = readline().rstrip()
  Alist[i] = line.replace("?","a")
  Zlist[i] = line.replace("?","z")
  
Alist = sorted(Alist)
Zlist = sorted(Zlist)

T = readline().rstrip()

import bisect
end = bisect.bisect_right(Alist, T)
start = bisect.bisect_left(Zlist, T)

print(*list(range(start + 1, end + 2)))


Measured memory_bytes: 10344
#include <bits/stdc++.h>
using namespace std;
int main() {
    
    int n, m;
    map<string, int> card;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string blue;
        cin >> blue;
        card[blue]++;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        string red;
        cin >> red;
        card[red]--;
    }
    
    int res = 0;
    for (auto itr = card.begin(); itr != card.end(); itr++)
        res = max(itr->second, res);
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int X;
	cin >> X;
	for(int i=1;100*i<=X;i++){
		int r=X-i*100;
		if(r<=5*i){
			cout << 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;

	return 0;
}



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

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    int res = 1;
    ll sign = 0LL;

    rep(i, 1, n){
        int pre = a[i - 1];
        int cur = a[i];

        if(sign == 0LL){
            sign = cur - pre;
        }
        else if((cur - pre) * sign < 0LL){
            sign = 0LL;
            res++;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <string>
const int maxn=100005;
char s[maxn];
std::string t[5];
int len;
bool flag=true;
inline bool check(int l,int r,int k){
	int lim=r-l;
	for(int i=0,j=l;i<=lim;i++,j++)
		if(t[k][i]!=s[j])
			return false;
	return true;
}
int main()
{
	scanf("%s",s);
	len=strlen(s);
	t[1]="dream";t[2]="erase";t[3]="eraser";t[4]="dreamer";
	for(int i=len-1;i>0;){
		if(s[i]=='m'){
			if(i<4||!check(i-4,i,1))
			{flag=false;break;}
			i-=4;
		}
		else if(s[i]=='e'){
			if(i<4||!check(i-4,i,2))
			{flag=false;break;}
			i-=4;
		}
		else if(s[i]=='r'){
			if(i>=5&&check(i-5,i,3))
				i-=5;
			else if(i>=6&&check(i-6,i,4))
				i-=6;
			else {flag=false;break;}
		}
		else {flag=false;break;}
		i--;
	}
	if(flag)printf("YES");
	else printf("NO");
	return 0;
}


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

#define start          ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nl            endl;
#define end_            system("pause");
#define sz(v)            ((int)((v).size()))
#define sc(x)            scanf("%d",&x)
#define sc2(x,y)         scanf("%d%d",&x,&y)
#define sc3(x,y,z)       scanf("%d%d%d",&x,&y,&z)
#define sc4(x,y,z,a)     scanf("%d%d%d%d",&x,&y,&z,&a)
#define sc5(x,y,z,a,b)   scanf("%d%d%d%d%d",&x,&y,&z,&a,&b)
#define sc6(x,y,z,a,b,c) scanf("%d%d%d%d%d%d",&x,&y,&z,&a,&b,&c)
#define scl(x)           scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define lp(i,n)        for(int i=0;i<n;i++)
#define lp1(i,f,l)     for(int i=f;i<l;i++)
#define R_(s)         freopen(s, "r", stdin)
#define W_(s)        freopen(s, "w", stdout)
#define R_W R_("input.txt"),W_("output.txt")
#define PI           acos(-1)
#define INF             1<<30
#define mp(a,b) make_pair(a,b)
typedef string            S;
typedef long long         ll;
typedef pair <int, int>   pii;
typedef pair<S, int>     si;
typedef pair<int, S>     is;
typedef pair<char, int>  chi;
typedef pair<S, S>       SS;
typedef vector<pii>        vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<S>        vs;
typedef vector<ll>       vll;
typedef vector<vll>     vvll;
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
ll gcd(ll a, ll b)  { return (b == 0 ? a : gcd(b, a % b)); }
ll sd(ll x)  { return x<10 ? x : x % 10 + sd(x / 10); }
ll lcm(ll a, ll b){ return ((a*b) / gcd(a, b)); }
vector<ll> get_divisors(ll n){vector<ll> arr;ll i=1;for(i;i*i<=n;i++){if(n%i==0)arr.push_back(i),arr.push_back(n/i);}return arr;}
int dx[4]={0 , 1 , 0 , -1};
int dy[4]={1 , 0 , -1 , 0};
ll fac(ll n)
{
	int o=1;
	lp1(i,2,n+1)
		o*=i;
	return o;
}

int main()
{
    start;
	ll ans=0,Q,H,S,D,N;
	cin>>Q>>H>>S>>D>>N;
	while(N>0)
	{
		if(N-2>=0)
		{
			if(D<=S*2&&D<=H*4&&D<=8*Q)
			ans+=D,N-=2;
			else if(D>=S*2&&S*2<=H*4&&S*2<=8*Q)
			ans+=(2*S),N-=2;
			else if(D>=H*4&&S*2>=H*4&&H*4<=8*Q)
			ans+=(H*4),N-=2;
			else
			ans+=(8*Q),N-=2;
		}
		else if(N-1>=0)
		{
			if(S<=H*2&&S<=Q*4)
			ans+=S,N-=1;
			else if(S>=H*2&&H*2<=Q*4)
			ans+=(2*H),N-=1;
			else
			ans+=(Q*4),N-=1;
		}
		else if(N-0.5>=0)
		{
			if(H<=Q*2)
			ans+=H,N-=0.5;
			else
			ans+=(Q*2),N-=0.5;
		}
		else
			ans+=Q,N-=0.25;
	}
	cout<<ans<<endl;
    //end_;
}

Measured memory_bytes: 256