akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>

using namespace std;

#define endl '\n'

const int dx[2] = {+1, 0};
const int dy[2] = {0, +1};

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

    int h, w;
    cin >> h >> w;

    vector<string> board(h);

    for (int i = 0; i < h; ++i)
        cin >> board[i];

    vector<vector<int>> dist(h, vector<int>(w, h * w + 1));
    dist[0][0] = 0;

    deque<pair<int, int>> q;
    q.push_back({0, 0});

    while (!q.empty())
    {
        auto c = q.front();
        q.pop_front();

        int x = c.first, y = c.second, d = dist[x][y];

        for (int k = 0; k < 2; ++k)
        {
            int nx = x + dx[k], ny = y + dy[k];

            if (0 <= nx && nx < h && 0 <= ny && ny < w)
            {
                if (board[x][y] == board[nx][ny])
                {
                    if (dist[nx][ny] > d)
                    {
                        dist[nx][ny] = d;
                        q.push_front({nx, ny});
                    }
                }
                else
                {
                    if (dist[nx][ny] > d + 1)
                    {
                        dist[nx][ny] = d + 1;
                        q.push_back({nx, ny});
                    }
                }
            }
        }
    }

    cout << (dist[h - 1][w - 1] + (board[0][0] == '#') + (board[h - 1][w - 1] == '#') + 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;

int main(){
  int n;
  cin >> n;
  int d, x;
  cin >> d >> x;
  vector<int> v(n, 0);
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> v[i];
    v[i] = 1 + ((d - 1) / v[i]);
    sum += v[i];
  }
  cout << sum + x << endl;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			final int m = sc.nextInt();
			
			if(n == 0 && m == 0){
				break;
			}
			
			int[] array = new int[n + m + 1];
			array[0] = 0;
			for(int i = 1; i < array.length; i++){
				array[i] = sc.nextInt();
			}
			
			Arrays.sort(array);
			//System.out.println(Arrays.toString(array));
			
			int max = 0;
			for(int i = 0; i < (array.length - 1); i++){
				max = Math.max(max, array[i+1] - array[i]);
			}
			
			System.out.println(max);
		}
		
	}

}

Measured memory_bytes: 13000
#include       <set>
#include       <map>
#include     <queue>
#include     <cmath>
#include    <cstdio>
#include    <cctype>
#include    <vector>
#include   <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int maxn = 105;

ll fast_pow(ll a,ll b,ll mod){
    ll ans = 1;
    while(b){
        if(b&1)
            ans = ans*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ans;
}

int w[maxn], v[maxn];
int dp[maxn*4][maxn];

int main(){
    int n, W, c;
    scanf("%d%d",&n,&W);
    for(int i=0;i<n;i++)
        scanf("%d%d",&w[i],&v[i]);
    for(int i=1;i<n;i++)
        w[i] -= w[0]-1;
    c = w[0]-1;
    w[0] = 1;
    for(int i=0;i<n;i++)
        for(int j=n*4;j>=w[i];j--)
            for(int k=1;k<=i+1;k++){
                dp[j][k] = max(dp[j][k],dp[j-w[i]][k-1]+v[i]);
    }
    int ans = 0;
    for(int j=n*4;j>=0;j--)
        for(int k=1;k<=n;k++){
            if(1ll*k*c+j<=W){
                ans = max(ans,dp[j][k]);
            }
    }
    printf("%d\n",ans);
    return 0;
}



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

using namespace std;
typedef long long ll;
const int N = 3010, M = 998244353;
ll n, s, a[N], dp[N];

int main() {
    cin >> n >> s;
    for (int i = 1; i <= n; i++) cin >> a[i];
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = s - a[i]; j >= 1; j--) {
            dp[j + a[i]] = (dp[j + a[i]] + dp[j]) % M;
        }
        dp[a[i]] += i;
        ans = (ans + dp[s]) % M;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string ab = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string as = {"abcdefghijklmnopqrstuvwxyz"};

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

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

//--------------------------


int main() {

  string s;
  cin >> s;

  int cnt = 0;
  for(int i=0; i<s.length()/2; ++i) {
    if(s[i]!=s[s.length()-i-1]) ++cnt;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();
 


    int n, r; cin >> n >> r;
    cout << ((n >= 10) ? r : (r + (100 * (10 - n)))) << endl;   

    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"
#include <set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N,D,Q;
vector <pair <int,int> > A;
vector <int> ans;
vector <int> s;



int main()
{
	int H,W;
	cin >> H >> W >> D;
	N = H*W;
	A.resize(N);
	s.resize(N);
	REP(i,H){
		REP(j,W){
			int a;
			cin >> a;
			A[a-1].first = i;
			A[a-1].second = j;
		}
	}




	REP(i,N){
		if(i<D){
			s[i] = 0;
		}else{
			s[i] = s[i-D] + abs(A[i].first-A[i-D].first) + abs(A[i].second-A[i-D].second);
		}
	}

	cin >> Q;
	ans.resize(Q);
	REP(i,Q){
		int L,R;
		cin >> L >> R;
		ans[i] = s[R-1] - s[L-1];
	}

	REP(i,Q){
		cout << ans[i] << endl;
	}
}




Measured memory_bytes: 2560
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
struct LazySegmentTree {
private:
    ll n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        ll sz = (ll)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(ll i=0; i<sz; i++) node[i+n-1] = v[i];
        for(ll i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(ll k, ll l, ll r) {
        if(lazy[k] % 2 == 1) {
            node[k] = r - l - node[k];
            if(r - l > 1) {
                lazy[2*k+1] += 1;
                lazy[2*k+2] += 1;
            }
            lazy[k] = 0;
        }
    }


    void update(ll a, ll b, ll x, ll k=0, ll l=0, ll r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += 1;
            eval(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

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

vector<ll> tree[100010];
vector<ll> euler;
ll v_begin[100010] = {}, v_end[100010] = {};
int idx = 0;

void dfs(int cur, int par){
    v_begin[cur] = idx;
    euler.push_back(cur);
    idx++;
    for(auto &e: tree[cur]){
        if(e == par) continue;
        dfs(e, cur);
        // euler.push_back(cur);
        // idx++;
    }
    v_end[cur] = idx;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,Q;
    cin >> N >> Q;
    rep(i,1,N){
        ll p;
        cin >> p;
        p--;
        tree[i].push_back(p);
        tree[p].push_back(i);
    }
    dfs(0,-1);
    vector<ll> c;
    rep(i,0,N){
        char s;
        cin >> s;
        if(s == 'G') c.push_back(1);
        else c.push_back(0);
    }
    vector<ll> v(N, 0);
    rep(i,0,N){
        v[i] = c[euler[i]];
    }

    LazySegmentTree sg(v);
    // printa(euler, euler.size());
    // print(v_begin[1], v_end[1]);
    while(Q--){
        ll v;
        cin >> v;
        v--;
        sg.update(v_begin[v], v_end[v], 1);
        ll sum = sg.getsum(0, N);
        if(sum * 2 >= N){
            print("broccoli");
        }else{
            print("cauliflower");
        }

    }


    

}


Measured memory_bytes: 23460
#include<bits/stdc++.h>
const int N=103;
using namespace std;
long long ns,rs;
int n,to[N*2],hd[N*2],lk[N],cnt=1,
nd,rd,mx[N];
inline void add(int u,int v){
	to[++cnt]=v,hd[cnt]=lk[u],lk[u]=cnt;
}int u,v;
inline void sol(int d){
	ns=d;
	for(int j=1;j<=n&&mx[j];j++)
	ns*=mx[j];
	if(rd>nd||rd==nd&&rs>ns)
	rd=nd,rs=ns;
	nd=0;
	for(int j=1;j<=n;j++)mx[j]=0;
}
void dfs(int x,int y,int d){
	nd=max(nd,d);
	int de=0;
	for(int i=lk[x];i;i=hd[i])
	if(i^y)dfs(to[i],i^1,d+1),de++;
	mx[d]=max(mx[d],de);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	scanf("%d%d",&u,&v),
	add(u,v),add(v,u);
	rd=n;
	for(int i=1;i<=n;i++)
	dfs(i,0,1),sol(1);
	for(int i=2;i<cnt;i+=2)
	dfs(to[i],i^1,1),
	dfs(to[i^1],i,1),sol(2);
	printf("%d %lld",rd,rs);
}

Measured memory_bytes: 256
A,B,M = map(int,input().split())
A_li = list(map(int,input().split()))
B_li = list(map(int,input().split()))

inf = float("inf")
posibility = inf

for m in range(M):
    x,y,c=map(int,input().split())
    tmp_posibility=A_li[x-1]+B_li[y-1]-c
    posibility=min(posibility,tmp_posibility)
 

no_c = min(A_li)+min(B_li)
decition = min(posibility,no_c)

print(decition)

Measured memory_bytes: 66540
import sys

class Node():
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left, self.right = None, None

def insert(z):
    global root
    x, y = root, None
    while x:
        y = x
        if z < x.key:
            x = x.left
        else:
            x = x.right
    
    if y == None:
        root = Node(z)
    elif z < y.key:
        y.left = Node(z)
    else:
        y.right = Node(z)
        
def find(z):
    global root
    x, y = root, None
    while x:
        y = x
        if z < x.key:
            x = x.left
        elif z > x.key:
            x = x.right
        else:
            print("yes")
            return
    print("no")
        
def preorder(x):
    return f" {x.key}" + preorder(x.left) + preorder(x.right) if x else ""

def inorder(x):
    return inorder(x.left) + f" {x.key}" + inorder(x.right) if x else ""
        
input()
root = None
for s in sys.stdin:
    if s[0] == "p":
        print(inorder(root))
        print(preorder(root))
    elif s[0] == "f":
        find(int(s[5:]))
    else:
        insert(int(s[7:]))



Measured memory_bytes: 53440
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
using namespace std;


#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<VV> VVV;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}


vector<pair<int,int>> slice(vector<pair<int,int>> vec,int p,int s) {
	pair<int, int> par1, par2;
	if (vec[p].first < s % (vec[p].first + vec[p].second)) {
		par1 = make_pair(vec[p].first, s % (vec[p].first + vec[p].second) - vec[p].first);
		par2 = make_pair(vec[p].first, vec[p].second - (s % (vec[p].first + vec[p].second) - vec[p].first));
	}
	else {
		par1 = make_pair(vec[p].first- s % (vec[p].first + vec[p].second),vec[p].second);
		par2 = make_pair(vec[p].first - (vec[p].first - (s % (vec[p].first + vec[p].second))), vec[p].second);
	}
	remove(vec, p);
	if (par1.first*par1.second >= par2.first*par2.second) {
		vec.push_back(par2);
		vec.push_back(par1);
	}
	else {
		vec.push_back(par1);
		vec.push_back(par2);
	}
	return vec;
}

int main() {
	int n, w, d,p,s;
	cin >> n >> w >> d;
	while (w != 0) {
		vector<pair<int, int>>vec;
		vec.push_back(make_pair(w, d));
		for (int i = 0; i < n; i++) {
			cin >> p>> s;
			vec = slice(vec,p-1,s);
		}
		vector<int>sum;
		for (int i = 0; i < vec.size(); i++) {
			sum.push_back(vec[i].first*vec[i].second);
		}
		sort(sum.begin(), sum.end());
		cout << sum[0];
		for (int i = 1; i<sum.size(); i++) {
			cout <<" "<< sum[i];
		}
		cout << "" << endl;

		cin >> n >> w >> d;
	}
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int h,w,n;
  cin >> h >> w >> n;
  int sh,sw;
  cin >> sh >> sw;
  string s,t;
  cin >> s >> t;
  int tsh = sh;
  bool flag = false;
  rep(i,0,n){
    if(s[i] == 'U'){
      tsh--;
    }
    if(tsh == 0){
      // cout << "a" << endl;
      flag = true;
    }
    if(t[i] == 'D'){
      if(tsh != h) tsh++;
    }
  }
  tsh = sh;
  rep(i,0,n){
    if(s[i] == 'D'){
      tsh++;
    }
    if(tsh == h+1){
      // cout << "b" << endl;
      flag = true;
    }
    if(t[i] == 'U'){
      if(tsh != 1) tsh--;
    }
  }
  int tsw = sw;
  rep(i,0,n){
    if(s[i] == 'R'){
      tsw++;
    }
    if(tsw == w+1){
      flag = true;
      // cout << "c" << endl;
    }
    if(t[i] == 'L'){
      if(tsw != 1) tsw--;
    }
  }
  tsw = sw;
  rep(i,0,n){
    if(s[i] == 'L'){
      tsw--;
    }
    if(tsw == 0){
      flag = true;
      // cout << "d" << endl;
    }
    if(t[i] == 'R'){
      if(tsw != w) tsw++;
    }
  }
  if(flag) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 776
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(b-a)<=d && abs(c-b)<=d)cout<<"Yes";
    else if(abs(c-a)<=d)cout<<"Yes";
    else cout<<"No";
system("pause");
return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    vector< long long > v;
    v.push_back(a*c);
    v.push_back(a*d);
    v.push_back(b*c);
    v.push_back(b*d);
    if(a <= 0 && 0 <= b) v.push_back(0);
    if(c <= 0 && 0 <= d) v.push_back(0);
    sort(v.begin(), v.end(), greater<long long>());
    cout << v[0] << endl;
}


Measured memory_bytes: 3196
K,N=map(x->parse(Int,x),split(readline()," "))
A=map(x->parse(Int,x),split(readline()," "))
#K,N=20,3
#A=[0,5,15]
maxD,tmp=0,0
for i in 1:N-1
    tmp=A[i+1]-A[i]
    tmp>maxD  && (maxD=tmp)
end 
tmp=A[1]+(K-A[end]) 
tmp > maxD && (maxD=tmp)
print(K-maxD)

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

int main()
{
  int n;
  int a, b, c, d;
  
  cin >> n;
  a = n % 10;
  n = n / 10;
  b = n % 10;
  n = n / 10;
  c = n % 10;
  n = n / 10;
  d = n % 10;
  if (a == b && b == c && c == d)
    cout << "Yes" << endl;
  else if (a == b && b == c)
    cout << "Yes" << endl;
  else if (b == c && c == d)
   	cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

using namespace std;

int main()
{
	int xs[256], ys[256];
	int xmin, xmax, ymin, ymax;
	int dx[] = {-1, 0, 1, 0};
	int dy[] = {0, 1, 0, -1};
	int N;
	
	xs[0] = ys[0] = 0;
	while (scanf("%d", &N) && N){
		xmin = xmax = ymin = ymax = 0;
		for (int i = 1; i < N; i++){
			int n, d;
			scanf("%d %d", &n, &d);
			xs[i] = xs[n] + dx[d];
			ys[i] = ys[n] + dy[d];
			xmin = min(xmin, xs[i]), ymin = min(ymin, ys[i]);
			xmax = max(xmax, xs[i]), ymax = max(ymax, ys[i]);
		}
		
		printf("%d %d\n", xmax - xmin + 1, ymax - ymin + 1);
	}
	
	return (0);
}

Measured memory_bytes: 1028
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int a[100010], t[100010], bit[200010];

void bitAdd(int n, int a){
	for(int i=n; i<200010; i += (i&(-i))){
		bit[i] += a;
	}
}

int bitSum(int n){
	int res=0;
	for(int i=n; i>0; i -= (i&(-i))){
		res += bit[i];
	}
	return res;
}

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i){
		cin >> a[i];
		t[i]=a[i];
	}
	sort(t, t+N);
	int ng=-1, ok=N-1;
	ll total= (ll) N*(N+1)/2;
	while(ng+1<ok){
		int mid=(ng+ok)/2, now=N+1;
		ll sum=0;
		for(int i=0; i<200010; ++i) bit[i]=0;
		for(int i=0; i<N; ++i){
			bitAdd(now, 1);
			if(a[i]<=t[mid]) ++now;
			else --now;
			sum += bitSum(now-1);
		}
		if(sum*2<=total) ng=mid;
		else ok=mid;
	}
	cout << t[ok] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A, A + N);
    vector<ll> v;
    v.push_back(0);
    v.push_back(0);
    for(int i = 1; i < N; i++) {
        if(A[i - 1] == A[i]) {
            v.push_back(A[i]);
            i++;
        }
    }
    sort(v.begin(), v.end(), greater<ll>());
    cout << v[0] * v[1] << "\n";
    return 0;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  if(n < k) {
    ans = min(n, abs(n-k));
  }
  
  else {
    ll cmp = 0;
    cmp =  n - (n / k)*k;
    ans = min(cmp, abs(cmp-k));
  }
  cout << ans << endl;
  return 0;
}

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

int a[200010],c[200010];

int max(int a,int b){
    return a>b?a:b;
}

inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}

inline void writeln(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
     puts("");
}

signed main(){
    int n=read(),k=read();
    
    for(int i=1;i<=n;i++)
        a[i]=read();
        
    for(int j=1;j<=k;j++){
        memset(c,0,sizeof(c));
        for(int i=1;i<=n;i++){
            c[max(1,i-a[i])]++;
            c[min(n+1,i+a[i]+1)]--;
        }
        int s=0,f=1;
        
        for(int i=1;i<=n;i++){
            a[i]=s+=c[i];
            if(a[i]<n)
                f=0;
        }
        if(f)
            break;
    }
    
    for(int i=1;i<=n;i++)
        write(a[i]),cout<<" ";
        
    puts("");
        
    return 0;
}

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

#define pb push_back

using ll=long long;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, d;
    cin >> n >> d;
    cout << (n+2*d) / (2*d+1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

bool isPrime[100'001];
int numOf2017[50'001];

bool isLike2017(int i)
{
    return isPrime[i] && isPrime[(i + 1) / 2];
}

int main()
{

    isPrime[1] = false;
    for (int i = 2; i <= 100'000; i++)
    {
        isPrime[i] = true;
        for (int j = 2; j <= (int)floor(sqrt(i)); j++)
        {
            if (i % j == 0)
            {
                isPrime[i] = false;
                break;
            }
        }
    }

    numOf2017[0] = 0;
    for (int i = 1; i < 100'000; i += 2)
    {
        int idx = (i + 1) / 2;
        numOf2017[idx] = numOf2017[idx - 1];
        if (isLike2017(i))
        {
            numOf2017[idx]++;
        }
    }

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

        int num = numOf2017[(r + 1) / 2] - numOf2017[(l + 1) / 2 - 1];
        cout << num << endl;
    }

    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
long long n,tmp;
int f[35];
int i;
int maxi;
int main() {
	memset(f,0,sizeof(f));
	cin>>n;
	if(n==0) {
		cout<<0;
		return 0;
	}
	for(int i=0;n;i++) {
		tmp = pow(-2,i+1);
		if(n%labs(tmp)==0) f[i] = 0;
		else {
			f[i] = 1;
			n-=pow(-2,i);
		}
//		maxi = 99999999;
//		long long tmp=0;
//		int t=-1;
//		for(int i=0;i<=30;i++) {
//			ans = pow(-2,i);
//			tmp = ans-n;
//			tmp = abs(tmp);
//			cout<<"tmp = "<<tmp<<'\n';
//			if(f[i]!=0)
//				continue;
//			if(tmp<maxi) {
//				maxi = tmp;
//				t = i;
////				cout<<"into it\n";
//			}
//		}
////		cout<<"t = "<<t<<endl;
//		n-=pow(-2,t);
////		cout<<"n = "<<n<<endl;
//		f[t]++;
	}
	int i;
	for(i=35;f[i]!=1;i--){}
	for(;i>=0;i--) {
		cout<<f[i];
	}
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
k = int(input())
check = [[1 for _ in range(k+3)] for i in range(k+3)]
for i in range(1, k+2):
    for j in range(i, k+2):
        check[i][j] = gcd(i, j)

result = 0
for s in range(1, k+1):
    for t in range(1, k+1):
        for u in range(1, k+1): 
            n, m = sorted([s, t])
            x = check[n][m]
            x, y = sorted([x, u])
            result += check[x][y]
print(result)

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

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

    vector<int> c(n), s(n), f(n);
    for(auto i = 0; i < n; i++) cin >> c[i] >> s[i] >> f[i];

    for (auto i = 0; i < n; i++) {
        auto t = s[i] + c[i];
        for (auto j = i + 1; j < n; j++) {
           if(s[j] >= t) t = s[j];
           else if((t - s[j]) % f[j] != 0) t += f[j] - (t % f[j]);
           t += c[j];
        }
        cout << t << endl;
    }

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

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T1,typename T2> using M = map< T1, T2>;
using Mii = M<int, int>;

int f(int n){
    if(n%2==0){
        return n/2;
    }else{
        return 3*n+1;
    }
}

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

    Mii a;
    a[s]++;
    int cnt = 1;
    int b = s;
    while(1){
        b = f(b);
        cnt++;
        auto it = a.find(b);
        if(it != a.end()){
            cout<<cnt<<endl;
            break;
        }else{
            a[b]++;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){

  int n, t;
  int a[200000];

  scanf("%d %d", &n, &t);
  for(int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  int res = 0;
  for(int i = 0; i < n; i++){
    res += t;
    if(i > 0 && a[i - 1] + t > a[i]){
      res -= a[i - 1] + t - a[i];
    }
  }

  printf("%d\n", res);

  return 0;
}


Measured memory_bytes: 896
#include <iostream>

using namespace std;


struct CARD {char suit,  value;};

void babble(int n, CARD *pcard)
{
	for(int i=0;i<n;i++){
		for(int j=n-1;i<j;j--){
			if(pcard[j].value<pcard[j-1].value) swap(pcard[j],pcard[j-1]);
		}
	}
}

void selectsort(int n, CARD *pcard)
{
	int min;
	int minv;
	for(int i=0;i<n;i++){
		min=i;
		for(int j=i+1; j<n;j++){
			if(pcard[j].value<pcard[min].value) min=j;
		}
		swap(pcard[min],pcard[i]);
	}
}

void stable(CARD *in, CARD *out, int n)
{
	int flag=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int a=0;a<n;a++){
				for(int b=a+1;b<n;b++){
					if((in[i].value==in[j].value)&&(in[i].suit==out[b].suit)&&(in[j].suit==out[a].suit)&&(in[i].value==out[b].value)&&(in[j].value==out[a].value)){ 
						flag=1;
						break;
					}
				}
			}
		}
	}
	if(flag==1){ cout <<"Not stable"<<endl;}
	else cout <<"Stable"<<endl;
}

int main()
{

	CARD c1[100],c2[100];

	int n;
	int buff[200];
	cin>>n;
	for(int i=0;i<n;i++) cin>>c1[i].suit>>c1[i].value;
	for(int i=0;i<n;i++) c2[i]=c1[i];

	babble(n, c1);
	for(int j=0;j<n-1;j++) cout << c1[j].suit<<c1[j].value<<" ";
	cout << c1[n-1].suit<<c1[n-1].value<<endl;

	stable(c2,c1,n);
	for(int i=0;i<n;i++) c1[i]=c2[i];
	selectsort(n,c2);
	for(int j=0;j<n-1;j++) cout << c2[j].suit<<c2[j].value<<" ";
	cout << c2[n-1].suit<<c2[n-1].value<<endl;
	stable(c1,c2,n);


	return 0;
}



Measured memory_bytes: 3104
from math import sqrt,ceil,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())


# for _ in range(ii()):

a,b,c=mi()
k=ii()
for i in range(k):
    if a>=b:
        b*=2
    else:
        c*=2
    if a<b<c:
        break
# print(a,b,c)
if a<b<c:
    print("Yes")
else:
    print('No')

Measured memory_bytes: 62068
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

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


Measured memory_bytes: 256
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 g=l if l<H and A[i]<A[l]else i
 if r<H and A[g]<A[r]:g=r
 if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


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

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

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

const int maxn = 2e5 + 5;
bool vis[maxn];

int n, m;
int a[maxn], b[maxn];
vector<int> G[maxn];
int pre[maxn];

void bfs(int st){
    queue<int> q;
    q.push(st);
    vis[st] = true;
    memset(pre, -1, sizeof(pre));
    while(!q.empty()){
        int p = q.front(); q.pop();
        for(auto v : G[p]){
            if(!vis[v]){
                vis[v] = true;
                pre[v] = p;
                q.push(v);
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 1;i <= m;i++){
        cin >> a[i] >> b[i];
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    bfs(1);
    bool ok = true;
    for(int i = 1;i <= n;i++){
        if(!vis[i])
            ok = false;
    }
    if(ok){
        cout << "Yes" << endl;
        for(int i = 2;i <= n;i++){
            cout << pre[i] << endl;
        }
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

// コンテスト中のみ
#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;


int dp[3010][3010][10];
int items[3010][3010];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int R, C, K; cin >> R >> C >> K;
	vector<int>r(K), c(K), v(K);
	rep(i, K)
	{
		cin >> r[i] >> c[i] >> v[i]; r[i]--; c[i]--;
		items[r[i]][c[i]] = v[i];
	}
	dp[0][0][1] = items[0][0];
	rep(i, R) {
		rep(j, C) {
			if (i == 0 && j == 0)continue;
			rep(k, 4) {

				if (i > 0) {
					dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k] );


						dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][k] + items[i][j]);
					
				}
				
			}
			rep(k, 4) {
				if (j > 0) {
					dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
					if (k < 3)dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j - 1][k] + items[i][j]);
				}

			}
		}
	}
	int ans = 0;
	rep(i, R) {
		rep(j, C) {
			rep(k, 4) {
				
				ans = max(ans, dp[i][j][k]);
			}
		}
	}

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

Measured memory_bytes: 783332
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String buf = br.readLine();
			int s = Integer.parseInt(buf);
			int h = s / 3600;
			s = s % 3600;
			int m = s / 60;
			s = s % 60;
			System.out.println(h + ":" + m + ":" + s);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16864
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

// bool comp(vector<int> v1, vector<int> v2)
// {
//     return v1[1] < v2[1];
// }

int main()
{
    string S; cin >> S;
    int count = 0;
    int count_old = 0;

    for (int i = 0; i < S.length(); ++i)
    {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')
        {
            count++;
        } else {
            if (count > count_old)
                count_old = count;
            count = 0;
        }
        
    }
            if (count > count_old)
                count_old = count;

    cout << count_old << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    int n; cin>>n;
    string s,ss; cin>>s>>ss;
    int ans=1,place,swi;
    if(s.at(0)==ss.at(0)){
        ans*=3;
        place=1;
        swi=0;
    }else{
        ans*=6;
        place=2;
        swi=1;
    }
    while(place<n){
        if(s.at(place)==ss.at(place)){
            if(swi==0)ans=(ans*2)%mod;
            swi=0;
            place++;
        }else{
            if(swi==0)ans=(ans*2)%mod;
            else ans=(ans*3)%mod;
            swi=1;
            place+=2;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,max=0,n,c=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(max<=a){
            c++;
            max=a;
        }
    }
    cout<<c<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
using namespace std;
#define MAXSIZE 1e5
#define MAXL 100
typedef long long int lli;

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

    int k;
    cin >> k;

    bool judge = false;
    for(int i = 0; i < 4; ++i){
        for(int j = i + 1; j < 5; ++j){
            if(a[j] - a[i] > k){
                judge = true;
                goto END;
            }
        }
    }

END:
    cout << ((judge)? ":(" : "Yay!") << endl;
    return 0;
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;


/**
   ceil(0, 2) == 0
   ceil(1, 2) == 1
   ceil(2, 2) == 1
   ceil(3, 2) == 2
   ceil(4, 2) == 2
*/
template<class T>
T ceil(T dividend, T divisor)
{
    return (dividend + (divisor - 1)) / divisor;
}
int main()
{
    int64_t A, B, C, D, E, F;
    std::cin >> A >> B >> C >> D >> E >> F;

    // 100 * S <= W * E
    // W + S <= F

    // W += 100*A
    // W += 100*B
    // S += C;
    // S += D;

    // F 以下となる水の組み合わせ

    std::unordered_set<int64_t> water;
    for (int64_t a = 0; a*100*A <= F; ++a) {
        for (int64_t b = 0; b*100*B <= F; ++b) {
            auto w = 100*a*A + 100*b*B;
            if (w <= 0 || w > F) {
                continue;
            }
            water.insert(w);
        }
    }

    std::unordered_set<int64_t> suger;
    for (int64_t c = 0; c*C <= F; ++c) {
        for (int64_t d = 0; d*D <= F; ++d) {
            auto s = c*C + d*D;
            // 砂糖0も候補にいれないと通らない
            if (/*s <= 0 ||*/ s > F) {
                continue;
            }
            suger.insert(s);
        }
    }


    double max = 0;
    int64_t maxW = 0;
    int64_t maxS = 0;

    for (auto w: water) {
        for (auto s: suger) {
            if (w + s > F) {
                continue;
            }
            if (100 * s > w * E) {
                continue;
            }

            double n = 100.0 * s / (w + s);
            // 砂糖0のときnも0なので、そのときの候補を拾わないといけない
            if (max <= n) {
                maxW = w;
                maxS = s;
                max = n;
            }
        }
    }

    std::cout << maxS + maxW << " " << maxS << std::endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
#define rep(i,n) for(int i=0;i<(n);i++)
 
int main(){
  string s;
  cin>>s;
  if(s[0]==s[1] && s[1]==s[2]){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
}

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

using namespace std;

int c[300300];

int main() {
	int n;
	string s;
	cin >> n >> s;
	c[0] = s[0] == 'W';
	for (int i = 1; i < n; i++) {
		c[i] = c[i - 1];
		if (s[i] == 'W') {
			c[i]++;
		}
	}
	int tot = c[n - 1];
	int ans = n - tot - (1 - c[0]);
	for (int i = 1; i < n; i++) {
		int tmp = c[i - 1] + (n - i - 1 - (tot - c[i]));
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

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

const int MOD = 1e9 + 7;

int mul(int a, int b) {
	return (long long) a * b % MOD;
}
// O(log(b))
int my_pow(int a, int b) {
	int r = 1;
	while(b) {
		if(b % 2) {
			r = mul(a, r);
		}
		a = mul(a, a);
		b /= 2;
	}
	return r;
}
int my_inv(int a) {
	return my_pow(a, MOD-2);
}

const int MAX = 1e6 + 5;

int main() {
	int n;
	cin >> n;
	vector<int> answer(MAX);
	vector<int> a(n);
	vector<int> cnt(MAX);
	// O(N * sqrt(X))
	for(int j = 0; j < n; j++) {
		int x;
		cin >> x;
		a[j] = x;
		// map<int,int> cnt;
		
		// 20 -> 2*2*5     24 -> 2*2*2*3
		vector<int> indices;
		for(int i = 2; i * i <= x; i++) {
			indices.push_back(i);
			while(x % i == 0) {
				++cnt[i];
				x /= i;
			}
		}
		if(x != 1) {
			indices.push_back(x);
			++cnt[x];
		}
		for(int i : indices) {
			answer[i] = max(answer[i], cnt[i]);
			cnt[i] = 0;
		}
	}
	// lcm/a[0] + lcm/a[1] + lcm/a[2] + ...
	int lcm = 1;
	for(int i = 0; i < MAX; i++) {
		int prime = i;
		int k = answer[i];
		for(int _ = 0; _ < k; _++) {
			lcm = mul(lcm, prime);
		}
	}
	cerr << "lcm = " << lcm << endl;
	int sum = 0;
	for(int x : a) {
		if(n <= 10) cerr << "add " << mul(lcm, my_inv(x)) << " x = " << x << endl;
		sum = (sum + mul(lcm, my_inv(x))) % MOD;
	}
	cout << sum << endl;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int n;
char s[105];
char pre;
int flag;
map<string,bool> mm;
int main()
{
	cin>>n;
	cin>>s;
	mm[string(s)]=1;
	pre=s[strlen(s)-1];
	for(int i=2;i<=n;i++)
	{
		cin>>s;
		if(s[0]==pre&&!mm[string(s)])
		{
		mm[s]=1;
		pre=s[strlen(s)-1];
		}
		else
		{
			flag=1;
			break;
		}
	}
	if(flag==1)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;

ll gcd(ll x, ll y) {
    return y? gcd(y, x%y) : x;
}

vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    res.emplace_back(1, 1);
    for(ll i=2; i*i<=n; i++) {
        if(n%i) continue;
        res.emplace_back(i, 0);
        while(n%i == 0) {
            res.back().second++;
            n /= i;
        }
    }
    if(n>1) {
        res.emplace_back(n, 1);
    }

    return res;
}

void print_factorize(vector<pair<ll, int>> f) {
    for(auto a: f) {
        cout << a.first << "^" << a.second << endl;;
    }
}

int main() {
    ll A, B; cin >> A >> B;
    ll g = gcd(A, B);
    // print("g=", g);
    auto f = factorize(g);
    // print_factorize(f);
    print(f.size());

}

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

using namespace std;

int main () {
  int n;
  cin >> n;
  vector <char> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int cnt = 0;
  int it0 = 0, it1 = n - 1;
  while (it0 < it1) {
    if (a[it0] == 'W' && a[it1] == 'R') {
      swap(a[it0], a[it1]);
      cnt++;
      it0++;
      it1--;
      continue;
    }
    if (a[it0] == 'R') it0++;
    if (a[it1] == 'W') it1--;
  }
  for (int i = 0; i < n - 1; i++)
    if (a[i] == 'W' && a[i + 1] == 'R') cnt++;
  cout << cnt;
  return 0;
}

Measured memory_bytes: 3620
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

N=int(input())
T,A=map(int,input().split())
h=list(map(int,input().split()))
k=[]
for i in range(N):
	v=T-h[i]*0.006
	k.append(abs(A-v))
	
print(k.index(min(k))+1)
	
	
	

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int w = scanner.nextInt();
		int h = scanner.nextInt();
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		int r = scanner.nextInt();
		
		
		if (x - r < 0) {
			System.out.println("No");
			return;
		}
			
		
		if (y - r < 0) {
			System.out.println("No");
			return;
		}
		
		if (x + r > w) {
			System.out.println("No");
			return;
		}
		
		if (y + r > h) {
			System.out.println("No");
			return;
		}
		
		System.out.println("Yes");
	}
}



Measured memory_bytes: 26348
n,m = map(int,input().split())
s,c = [0]*m,[0]*m
for i in range(m):
    s[i],c[i] = map(int,input().split())
a = [0]*n

flag = True
                    
for i in range(m):
    if s[i]==1 and c[i]==0:
        flag = False
        
if n==1:
    flag = True

if flag == True:        
    for i in range(m):
        for j in range(i,m):
            if s[i]==s[j]:
                if c[i]!=c[j]:
                    flag = False
                    
if flag == True:
    for i in range(m):
        a[s[i]-1] = c[i]
    if n!=1 and a[0]==0:
        a[0]=1
    print(*a,sep="")
else:
    print("-1")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
int main(){
    int n;
    cin>>n;
    vector<int64_t> a(n),b(n);
    int64_t suma=0,sumb=0;
    rep(i,n){
        cin>>a[i];
        suma += a[i];
    }
    rep(i,n){
        cin>>b[i];
        sumb += b[i];
    }
    if(suma<sumb){
        cout<<-1<<endl;
        return 0;
    }
    int ans=0;
    int64_t husoku=0;
    rep(i,n){
        if(a[i]<b[i]){
            ans++;
            husoku += b[i]-a[i];
        }
    }
    vector<int64_t> sa(n);
    rep(i,n){
        sa[i]=a[i]-b[i];
    }
    all(sa);
    //reverse(sa.begin(),sa.end());
    Re(sa);
    rep(i,n){
        if(sa[i]>0&& husoku>0){//ここに入れる
            husoku = husoku -min(sa[i],husoku);
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;

    int arr[3];

    arr[0] = a + b;
    arr[1] = a - b;
    arr[2] = a * b;

    sort(arr, arr + 3, greater<int>());

    cout << arr[0] << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
arr = [int(s) for s in input().split(" ")]

def calculate(n,arr):
    arr = sorted(arr)
    data = []
    for i in range(1,101):
        sum = 0
        for ar in arr:
            sum += (ar - i) ** 2

        data.append(sum)

    return min(data)


result = calculate(n,arr)

print(result)

Measured memory_bytes: 3060
#include <iostream>
 
using namespace std;
 
int main(void)
{
    int N, d[50], i, j, sum=0;
 
    cin >> N;
 
    for(i=0; i<N; i++){
        cin >> d[i];
    }
 
    for(i=0; i<N-1; i++){
        for(j=i+1; j<N; j++){
            sum += d[i] * d[j];
        }
    }
 
    cout << sum << endl;
 
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

def main():
    N, K, Q = [int(i) for i in input().split()]
    Submits = Counter([int(input()) for _ in range(Q)])
    for n in range(1, N + 1):
        try:
            if K - Q + Submits[n] > 0:
                print("Yes")
            else:
                print("No")
        except:
            print("No")


if __name__ == "__main__":
    main()

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

B = [int(n) for n in input().rstrip().split(' ')]
A = []

A.append(B[0])

for i in range(0, N-2):
  if i == 0:
    prev = B[-1]
  else:
    prev = B[0]
  
  next = B[i+1]
  b = B[i]
  
  max_b = (max(prev, b))
  min_b = (min(next, b))
  
  A.append(min_b)

if N > 2:
  A.append(B[-1])
else:
  A.append(B[-1])

print(sum(A))
  


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const double pi=acos(-1);

vector<int>edges[200010];
ll ans[200010];

void dfs(int v,int p){
  for(int nv:edges[v]){
    if(nv!=p){
      ans[nv]+=ans[v];
      dfs(nv,v);
    }
  }
}
int main(){
  int n,q;
  cin >> n >> q;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  rep(i,q){
    int p,x;
    cin >> p >> x;
    p--;
    ans[p]+=x;
  }
  dfs(0,-1);
  rep(i,n) cout << ans[i]<< " ";
  return 0;

}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;}
void submain();

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

int N, Q; cin >> N;
VI A(N); invec(A);
cin >> Q;
VI B(Q), C(Q);
rep(i, 0, Q) cin >> B[i] >> C[i];

i64 sum = accumulate(ALL(A), (i64)0);
map<int, int> m;
for(int a: A) ++m[a];
rep(i, 0, Q) {
    sum += (C[i] - B[i]) * m[B[i]];
    m[C[i]] += m[B[i]];
    m[B[i]] = 0;
    cout << sum << "\n";
}


return 0;
}

// 制限が緩い場合での愚直解を書く。
void submain(){

}

// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 10036