akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,k;
int a[200010];
int check(int mid){
	int cur=0;
	for(int i=1;i<=n;i++){
		if(a[i]%mid==0)cur+=a[i]/mid-1;
		else cur+=a[i]/mid;
	}
	// cout<<cur<<' '<<k<<endl;
	return cur<=k;
}
signed main(){
	cin>>n>>k;
	// k+=n;
	int l=1,r=0;
	for(int i=1;i<=n;i++)cin>>a[i],r=max(r,a[i]);
	while(l+1<r){
		int mid=(l+r)>>1;
		// cout<<l<<' '<<r<<' '<<mid<<' '<<endl;
		if(check(mid))r=mid;
		else l=mid+1;
	}
	if(check(l))cout<<l<<endl;
	else cout<<r<<endl;
	// cout<<l<<' '<<r<<endl;
	return 0;
}


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

int main() {
  long long num;
  long long sum = 0;
  long long kekka = 0;
  
  cin >> num;
  
  vector<int> vec(num);
  for(int i = 0; i < num; i++){
    cin >> vec.at(i);
  }
  
  long long small = -1;
  for(int j = 1; j <= 100; j++){
    kekka = 0;
    for(int i = 0; i < num; i++){
      kekka += (vec.at(i) - j) * (vec.at(i) - j);
    }
    
    if(small == -1){
      small = kekka;
    }else if(small > kekka){
      small = kekka;
    }
  }
  
  cout << small;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100004

string to_id(int p, int y);

int main(){
    int n,m; cin >> n >> m;
    string id[MAX];
    pair<int, pair<int, int> > city[MAX];
    for(int i = 0; i < m; i++){
        int p,y; cin >> p >> y;
        city[i] = make_pair(y, make_pair(p,i));
    }
    sort(city, city+m);

    int num[MAX];
    for(int i = 0; i < n; i++) num[i] = 0;

    for(int i = 0; i < m; i++){
        int year =  city[i].first, pr = city[i].second.first, ind = city[i].second.second;
        num[pr-1]++;
        id[ind] = to_id(pr,num[pr-1]);

    }

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

    return 0;   
}

string to_id(int p, int y){
    string pre = to_string(p), ye = to_string(y);
    int len = pre.length();
    for(int i = 0; i < 6-len; i++) pre = "0" + pre;
    len = ye.length();
    for(int i = 0; i < 6-len; i++) ye = "0" + ye;
    return pre+ye;
}

Measured memory_bytes: 8576
#include<cstdio>

const int MAX_N = 200000;
int a[MAX_N+1];
int b[MAX_N];
int c[MAX_N];

int main(){
	int n;
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		b[i] = 0;
		c[i] = 0;
	}
	for(int i=1;i<=n;i++) {
		scanf("%d", &a[i]);
		if(i + a[i] < n) b[i + a[i]]++;
		if(i - a[i] >= 0) c[i - a[i]]++;
	}
	long long int ans = 0;
	for(int i=0;i<n;i++) {
		ans += (long long int)b[i] * (long long int)c[i];
	}
	printf("%lld\n", ans);
	return 0;
}


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

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

  int N=s.size();
  int x=-1,y=-1;
  //2
  for(int i=0;i<N-1;++i){
    if(s[i]==s[i+1]){
      x=i+1,y=i+2;
    }
  }
  //3
  for(int i=0;i<N-2;++i){
    if(s[i]==s[i+2]){
      x=i+1,y=i+3;
    }
  }

  cout<<x<<" "<<y<<endl;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A>=B && A>=C){
  cout << 10*A+B+C<< endl;
  }
  else if(B>A && B>=C){
    cout << A+10*B+C << endl;
  }

  else{
  cout << A+B+10*C <<endl;
  }
  
  
return  0;
}


Measured memory_bytes: 768
//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
string S[1000001];
int dmin[1000001]={},lastpm[1000001];
vpint p,z;
vector<pair<int,pint> > m;/*
set<pair<pint,int> > dst;
vpint dpm;
int pmmax[1000001];
int maxi[1000001];*/
int main(){
	int N;
	int pmsum=0;
	scan(N);
	rep(i,N){
		scan(S[i]);
		int now=0;
		rep(j,S[i].size()){
			if(S[i][j]=='('){
				now++;
			}
			else{
				now--;
			}
			dmin[i]=min(dmin[i],now);
		}
		lastpm[i]=now;
		pmsum+=now;
		if(lastpm[i]>0) p.push_back({dmin[i],lastpm[i]});
		else if(lastpm[i]==0) z.push_back({dmin[i],lastpm[i]});
		else{
			int revnow=0;
			int revdmin=0;
			brep(j,S[i].size()){
				if(S[i][j]==')') revnow++;
				else revnow--;
				revdmin=min(revdmin,revnow);
			}
			m.push_back({revdmin,{dmin[i],lastpm[i]}});
		}
	}
	if(pmsum!=0){
		prin("No");
		return 0;
	}
	sort(rALL(p));
	sort(ALL(m));
	sort(rALL(z));
	int now=0;
	for(auto x:p){
		debug(x.first,x.second,now);
		if(now+x.first<0){
			prin("No");
			return 0;
		}
		else{
			now+=x.second;
		}
	}
	for(auto x:z){
		debug(x.first,x.second,now);
		if(now+x.first<0){
			prin("No");
			return 0;
		}
		else{
			now+=x.second;
		}
	}
	for(auto x:m){
		if(now+x.second.first<0){
			prin("No");
			return 0;
		}
		else{
			now+=x.second.second;
		}
	}
	prin("Yes");
	return 0;
}


Measured memory_bytes: 52276
#include<bits/stdc++.h>
using namespace std;
#define fep(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a, b) for (int i = (b)-1; i >= (a); i--)
struct node {
	int t,a,b;
	bool operator<(const node &q)const {
		return t<q.t;
	}
} p[100100];
int main() {
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	fep(j,0,n) cin>>p[j].t>>p[j].a>>p[j].b;
	sort(p,p+n);
	int posx=0,posy=0,post=0,mark=0;
	fep(j,0,n) {
		int cnt=abs(p[j].a-posx)+abs(p[j].b-posy);
		if (cnt>p[j].t-post) {mark=1; break;}
		else {
			if (cnt<p[j].t&&(p[j].t-post-cnt)%2!=0) {mark=1;break;}
		}
	}
	if (mark) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}


Measured memory_bytes: 1408
R, G, B, N = map(int,input().split())
 
i = 0
j = 0
cnt = 0
 
while i*R <= N:
    while i*R + j*G <= N:
        temp = N - i*R - j*G
        if temp % B == 0:
            cnt += 1
        j += 1
    j = 0
    i += 1
 
print(cnt)

Measured memory_bytes: 40556
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
result = 0
flag = [True] * N
result = N
for a, b in AB:
    if H[a-1] < H[b-1]:
        flag[a-1] = False
    elif H[a-1] > H[b-1]:
        flag[b-1] = False
    else:
        flag[a-1] = False
        flag[b-1] = False
print(flag.count(True))

Measured memory_bytes: 32052
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 1005;
char sl[nax][nax];

const int mod = 1e9 + 7;

void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

int main() {
    int h, w;
    scanf("%d%d", &h, &w);
    for(int row = 0; row < h; ++row) {
        scanf("%s", sl[row]);
    }
    vector<vector<int>> dp(h, vector<int>(w));
    dp[0][0] = 1;
    for(int row = 0; row < h; ++row) {
        for(int col = 0; col < w; ++col) {
            for(int r2 : {row, row + 1}) {
                int c2 = col;
                if(r2 == row) {
                    c2 = col + 1;
                }
                if(r2 < h && c2 < w && sl[r2][c2] == '.') {
                    add_self(dp[r2][c2], dp[row][col]);
                }
            }
        }
    }
    printf("%d\n", dp[h-1][w-1]);
}


Measured memory_bytes: 5120
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
#define int long long
const int maxn=100005;
int n,val[maxn],dif[maxn];
struct BIT {
	int c[maxn<<2],lim;
	inline void t() {
		memset(c,0,sizeof c);
	}
	inline int l(int x) {
		return x&-x;
	}
	inline void d(int p) {
		for(;p<=lim;p+=l(p))
			c[p]++;
	}
	inline int r(int p) {
		int res=0;
		for(;p;p-=l(p))
			res+=c[p];
		return res; 
	}
}T;
inline ll check(int x) {
	T.t();
	for(int i=1;i<=n;++i)
		dif[i]=dif[i-1]+(val[i]>=x?1:-1);
	ll num=0;
	T.d(n+1);
	for(int i=1;i<=n;++i)
		num+=T.r(dif[i]+n+1),T.d(dif[i]+n+1);
	return num;
}
signed main() {
	T.lim=400000;
	read(n);
	for(int i=1;i<=n;++i)
		read(val[i]);
	int l=0,r=1e9,mid,ans=0;
	while(l<=r) {
		mid=(l+r)>>1;
		ll now=check(mid);
//		cout<<"!!!"<<mid<<" "<<now<<" "<<n*(n-1)/2-now<<endl;
		if(now>=n*(n+1)/2-now)
			ans=mid,l=mid+1;
		else
			r=mid-1;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;



int main(void){
    int n;
    cin >> n;
    ll pa,na,ans=0;
    cin >> pa;
    REP(i,n-1){
        cin >> na;
        if(na < pa){
            ans+=pa-na;
            na=pa;
        }
        pa=na;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N, K;
        cin >> N >> K;
        Int ans = 0;
        while (N) {
            ans++;
            N /= K;
        }
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  int rb,rp;
  int sb,sp;
  double min;
  int min2;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>rb>>rp>>sb>>sp;
    if(sp>=2&&sb>=5){
      min=((rb*sb)+(rp*sp));
      min*=0.8;
    }
    else if((rb*sb)+(rp*sp)>((rb*5)+(rp*2))*0.8&&sb<5&&sp<2){
      min=((rb*5)+(rp*2));
      min*=0.8;
    }
    else if(sb<5&&sp>=2 && rb*sb+rp*sp>((rb*5)+rp*sp)*0.8){
      min=((rb*5)+rp*sp);
      min*=0.8;
    }
    else if(sb>=5&&sp<2&&rb*sb+rp*sp>((rb*sb)+(rp*2))*0.8){
      min=((rb*sb)+(rp*2));
      min*=0.8;
    }
    else{
      min=rb*sb+rp*sp;
    }
    min2=min;
    cout<<min2<<endl;
  }
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

string s;

int main(){
  cin>>s;
  if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3]))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll k;
  cin>>k;
  queue<ll> que;
  // push top numbers
  for (ll i = 1; i <= 9; ++i)
  {
    que.push(i);
  }
  for (int i = 0; i < k-1; ++i)
  {
    ll x=que.front();
    que.pop();
    ll m=x%10;
    if(m!=0) que.push(10*x+m-1);
    que.push(10*x+m);
    if(m!=9) que.push(10*x+m+1);
  }
  cout<<que.front();
}

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

namespace ALDS1_4_A {
    class Program {
        static void Main(string[] args) {
            Console.ReadLine();
            string[] S = Console.ReadLine().Split(' ');
            Console.ReadLine();
            int count = Console.ReadLine().Split(' ')
                .Where(t => S.Contains(t))
                .Count();
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 9868
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer[] h = new Integer[10];
		for (int i = 0; i < 10; ++i) {
			h[i] = sc.nextInt();
		}
		Arrays.sort(h, Comparator.reverseOrder());
		for (int i = 0; i < 3; ++i) {
			System.out.println(h[i]);
		}
		sc.close();
	}
}


Measured memory_bytes: 26120
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

int main(void){
    string s, a;
    cin >> s;
    a += s[0];
    a += to_string(s.size()-2);
    a += s[s.size()-1];
    cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int n;
ll dp[110][5][5][5];

int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n; i++){
        if(i == 0 || i == 1){
            for(int j = 0; j < 5; j++){
                for(int k = 0; k < 5; k++){
                    for(int l = 0; l < 5; l++){
                        dp[i][j][k][l] = 0;
                    }
                }
            }
        }else if(i == 2){
            for(int j = 0; j < 5; j++){
                for(int k = 0; k < 5; k++){
                    for(int l = 0; l < 5; l++){
                        dp[i][j][k][l] = 1;
                    }
                }
            }
            dp[i][0][2][1] = 0;
            dp[i][0][1][2] = 0;
            dp[i][2][0][1] = 0;//0->A, 2->G, 1->C
        }else{
            for(int j = 0; j < 4; j++){
                for(int k = 0; k < 4; k++){
                    for(int l = 0; l < 4; l++){
                        dp[i][j][k][l] = dp[i-1][0][j][k] + dp[i-1][1][j][k] + dp[i-1][2][j][k] + dp[i-1][3][j][k];
                    }
                }
            }
            dp[i][3][2][1] -= dp[i-1][0][3][2];//A?GC
            dp[i][1][2][1] -= dp[i-1][0][1][2];//ACGC
            dp[i][2][2][1] -= dp[i-1][0][2][2];//AGGC
            dp[i][0][2][1] -= dp[i-1][0][0][2];//AAGC
            for(int j = 0; j < 4; j++){
                dp[i][0][2][1] -= dp[i-1][j][0][2];//AGC
                dp[i][0][1][2] -= dp[i-1][j][0][1];//ACG
                dp[i][2][0][1] -= dp[i-1][j][2][0];//GAC
            }
        }

        for(int j = 0; j < 4; j++){
            for(int k = 0; k < 4; k++){
                for(int l = 0; l < 4; l++){
                    dp[i][j][k][l] %= mod;
                }
            }
        }
    }
    ll ans = 0;
    for(int j = 0; j < 4; j++){
        for(int k = 0; k < 4; k++){
            for(int l = 0; l < 4; l++){
                ans += dp[n-1][j][k][l];
            }
        }
    }
    cout << ans%mod << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp> //required

// using namespace __gnu_pbds; 
using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // ordered_set <ynt> s; // order_of_key(value)

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second


const int N = 1019;
double d[N][N], dmin[N];
int n, k, m, a, b, x[N], y[N], r[N], use[N];

double dist(int a, int b) {
	long long X = x[a] - x[b];
	long long Y = y[a] - y[b];
	return sqrt(X * X + Y * Y);
}

double getd(int i, int j) {
	return max(0., dist(i, j) - r[i] - r[j]);
}

double dijkstra() {
	for(int i = 1; i <= n; i++) dmin[i] = 1e18;
	dmin[0] = 0;
	// use[0] = 0;
	
	for(int i = 0; i <= n; i++) {
		
		double minn = 1e17;
		int k = -1;

		for(int i = 0; i <= n; i++)
			if(!use[i] && dmin[i] < minn) {
				k = i;
				minn = dmin[i];
			}

		use[k] = 1;
		for(int i = 0; i <= n; i++)
			if(dmin[i] > dmin[k] + d[i][k])
				dmin[i] = dmin[k] + d[i][k];
	}
	return dmin[1];
}

int main() {
	ios_base::sync_with_stdio(false);

	cin >> x[0] >> y[0] >> x[1] >> y[1];
	r[0] = r[1] = 0;
	cin >> n;
	n++;
	for(int i = 2; i <= n; i++)
		cin >> x[i] >> y[i] >> r[i];

	for(int i = 0; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			d[i][j] = d[j][i] = getd(i, j);

	cout << fixed << setprecision(10) << dijkstra() << '\n';
}	
  

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define prln(x) (cerr << #x << ' ' << x << endl)
#define pr(x) (cerr << #x << ' ' << x)
const int INF = 0x3f3f3f3f;
int n, q;
string s;
int k[75];

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cin >> n >> s >> q;
    for (int i = 0; i < q; ++i) {
        cin >> k[i];
    }

    for (int i = 0; i < q; ++i) {
        ll ans = 0, nd = 0, nm = 0, ndm = 0;
        for (int j = 0; j < n; ++j) {
            if (j - k[i] >= 0) {
                if (s[j - k[i]] == 'D') {
                    ndm -= nm;
                    --nd;
                }
                if (s[j - k[i]] == 'M') {
                    --nm;
                }
            }

            if (s[j] == 'D') {
                ++nd;
            }else if (s[j] == 'M') {
                ndm += nd;
                nm++;
            }else if (s[j] == 'C') {
                ans += ndm;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1412
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

struct edge { int to, cost; edge(int to, int cost) : to(to), cost(cost) {} };
typedef vector<edge> edges;

int N, K;
int C[5010], R[5010];

vi a[5010];
edges G[5010];
bool visited[5010];
int d[5010];
int d_bfs[5010];

void bfs(int s)
{
    fill_n(d_bfs, N, inf);

    queue<int> q;
    d_bfs[s] = 0;
    q.push(s);

    while (q.size()) {
        int num = q.front(); q.pop();
        
        if (d_bfs[num] >= R[s]) continue;
        
        rep(i, a[num].size()) {
            int v = a[num][i];

            if (d_bfs[v] > d_bfs[num] + 1) {
                d_bfs[v] = d_bfs[num] + 1;
                G[s].PB(edge(v, C[s]));
                q.push(v);
            }
        }
    }
}

void solve()
{
    fill_n(d, N, inf);

    priority_queue<pii, vpii, greater<pii> > pq;

    pq.push(pii(0, 0));
    d[0] = 0;

    while (pq.size()) {
        pii p = pq.top(); pq.pop();

        int v = p.scd;

        if (d[v] < p.fst) continue;

        if (!visited[v]) {
            bfs(v);
        }
        visited[v] = true;

        rep(i, G[v].size()) {
            edge &e = G[v][i];
            
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push(pii(d[e.to], e.to));
            }
        }
    }

    cout << d[N - 1] << endl;;
}

signed main()
{
    cin >> N >> K;

    rep(i, N) {
        cin >> C[i] >> R[i];
    }
    
    rep(i, K) {
        int A, B; cin >> A >> B;
        -- A, -- B;

        a[A].PB(B);
        a[B].PB(A);
    }

    solve();
}

Measured memory_bytes: 125888
#include <stdio.h>
int main(){
  int H,W,h,w;
  while(1){
    scanf("%d %d",&H,&W);  
    for(h=1;h<=H;h++){  
    if(h%2==1){
      for(w=1;w<=W;w++){
	if(w<W){	
	  if(w%2==1){
	  printf("#");
	}
	else if(w%2==0){
	  printf(".");
	}}
	else if(w==W){
	  if(w%2==0){
	    printf(".\n");
	  }
	  else if(w%2==1){
	    printf("#\n");
	  }}
      }}
     if(h%2==0){
      for(w=1;w<=W;w++){
	if(w<W){	
	  if(w%2==1){
	  printf(".");
	}
	else if(w%2==0){
	  printf("#");
	    }
	}
	else if(w==W){
	  if(w%2==0){
	    printf("#\n");
	  }
	  else if(w%2==1){
	    printf(".\n");
	  }
	}
      }
     }
    }
    if(H!=0){
      if(h==H+1){
	printf("\n");
      }
    }
    
	if(H==0&&W==0){
      break;
	}
      }
  return 0;
}

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

long divi(long a, long b) {
	return (a + b - 1) / b;
}

int main() {
	long N;
	vector<long> a(5);
	cin >> N;
	for (long& i : a) cin >> i;
	long ans = 0;
	/*for (long i = 0; i < 5; ++i) {
		if (divi(N - (a[i] * i), a[i]) <= 0) ++ans;
		else ans += divi(N - (a[i] * i), a[i]);
		//cout << divi(N - a[i] * i, a[i]) << ' ';
	}*/
	/*for (int i = 0; i < 5; ++i) {
		if (divi(N, a[i]) - i > 0) ans += divi(N, a[i]) - i;
		else ++ans;
		//cout << divi(N, a[i]) - i - 1 << ' ';
	}*/
	sort(a.begin(), a.end());
	cout << divi(N, a[0]) + 4;
	//cout << ans;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <unordered_set>
#include <string>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <thread>
#include <algorithm>
#include <iterator>

using namespace std;

const int N = 1e3 + 10;
char c[N][N];
const int dx[4] = { -1, 0, 1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
bool used[N][N];
pair <int, int> q[N * N];
int dist[N][N];
int ql = 0, qr = 0;

int main()
{
	srand(time(NULL));
	::ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> c[i][j];
			if (c[i][j] == '#') {
				q[qr++] = { i, j };
				used[i][j] = true;
			}
		}
	}
	int res = 0;
	while (ql != qr) {
		pair <int, int> lr = q[ql++];
		int i = lr.first;
		int j = lr.second;
		for (int d = 0; d < 4; ++d) {
			int x = i + dx[d];
			int y = j + dy[d];
			if (x >= 0 && x < n && y >= 0 && y < m) {
				if (!used[x][y]) {
					used[x][y] = true;
					q[qr++] = { x,y };
					dist[x][y] = dist[i][j] + 1;
					res = max(res, dist[x][y]);
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b ==c+d)
		cout<<"Balanced\n";
	else if((a+b)>(c+d))
		cout<<"Left\n";
	else 
		cout<<"Right\n";
}

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



int main(void){
	
	string str;
	getline(cin, str);


	for (int i = 0; i < (str.length()/2); i++){
	
		swap(str[i], str[str.length() - i-1]);
	}


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

		cout << str[i];
	}cout << endl;

	
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  int d,n;
  cin>>d>>n;
  int a=1;
  rep(i,d){
    a*=100;
  }
  if(n==100)
    n++;
  
  cout<<n*a<<endl;



  return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int L;
  cin >> L;
  double E = (double)L / 3.0;
  double answer = E * E * E;
  cout << setprecision(10) << answer << endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
X=[int(i) for i in input().split()]
Y=sorted([X[i] for i in range(N)])
MidS=Y[N//2-1]
MidL=Y[N//2]
for i in range(N):
  if X[i]<=MidS:
    print(MidL)
  else:
    print(MidS)


Measured memory_bytes: 25472
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
string s;stack<char> st;
signed main(){
  cin>>s;
  rep(i,s.length()){
    if(s[i] == 'A')st.push('A');
    else if(s[i] == 'B'){
      if(i != s.length()-1 && s[i+1] == 'C'){
        st.push('B');i++;
      }
      else st.push('#');
    }
    else if(s[i] == 'C')st.push('#');
  }
  int ans = 0, pre = 0, i = 0;
  while(!st.empty()){
    i++;
    char c = st.top();st.pop();
    if(c == 'A'){
      ans += i-pre-1;pre++;
    }else if(c == '#'){
      pre = i;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 5010;
const int INF = 1e9 + 7;
int N;
vector<int> V[1010];
int X[1010];
int b[1010][2][MC];

void mn(int &s , int t){
	s = min(s,t);
}

int dfs(int p , int q){
	int t = 0;
	fill(b[q][0],b[q][0]+MC,INF);
	b[q][0][0] = 0;
	for(auto u : V[q]){
		int z = dfs(q,u);
		if(z<0) return -1;
		fill(b[q][(t+1)%2],b[q][(t+1)%2]+MC,INF);
		repp(i,0,MC){
			if(b[q][t%2][i]+z<MC) mn(b[q][(t+1)%2][b[q][t%2][i]+z],i+X[u]);
			if(b[q][t%2][i]+X[u]<MC) mn(b[q][(t+1)%2][b[q][t%2][i]+X[u]],i+z);
			if(i+z<MC) mn(b[q][(t+1)%2][i+z],b[q][t%2][i]+X[u]);
			if(i+X[u]<MC) mn(b[q][(t+1)%2][i+X[u]],b[q][t%2][i]+z);
		}
		++t;
	}
	int m = INF;
	repp(i,0,MC){
		if(i<=X[q]) mn(m,b[q][t%2][i]);
		if(b[q][t%2][i]<=X[q]) mn(m,i);
	}
	if(m == INF) m = -1;
	return m;
}

int main(){
	cin >> N;
	repp(i,1,N){
		int P;
		cin >> P;
		V[P].PB(i+1);
	}
	repp(i,1,N+1){
		cin >> X[i];
	}
	cout << (dfs(-1,1)<0?"IMPOSSIBLE":"POSSIBLE") << endl;
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")

using namespace std;

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

const int N = 500000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000010;
const int delta = 11353;

string NN, n, n9;

string ADD(string a, string b){
	int Car = 0;
	if (a.size() > b.size()) swap(a, b);
	reverse(all(a));
	int SZ = a.size();
	for (int i = 0; i < ((int)b.size() - SZ); i++) a += "0";
	reverse(all(b));
	//if (f)cout << a << ' ' << b << '\n';
	for (int i = 0; i < a.size(); i++){
		int nxt = (a[i] - '0') + (b[i] - '0');
		nxt += Car;
		Car = 0;
		if (nxt >= 10) Car = 1;
		a[i] = ('0' + (nxt % 10));
	}
	if (Car > 0) a += ('0' + Car);
	reverse(all(a));
	return a;
}

bool isval(int x){
	string res = "";
	x *= 9;
	int xx = x;
	while (xx){
		res += ('0' + (xx % 10));
		xx /= 10;
	}
	reverse(all(res));
	//cout << res << ' ' << n9 << '\n';
	res = ADD(res, n9);
	//cout << res << '\n';
	int sm = 0;
	for (auto u:res) sm += (u - '0');
	return (sm <= x);
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> NN;
	bool f = 0;
	for (int i = 0; i < NN.size(); i++){
		if (NN[i] != '0') f = 1;
		if (f) n += NN[i];
	}
	n9 = n;
	//cout << n <<'\n';
	for (int i = 1; i <= 8; i++) n9 = ADD(n9, n);
	//cout << n9 << '\n';
	int l = -1, r = n.size() + 10;
	while (r - l > 1){
		int md = (l + r) >> 1;
		if (isval(md)) r = md;
		else l = md;
	}
	//cout << isval(11) << '\n';
	cout << r;
	//cout << isval(3);
	return 0;
}


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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

void multiply(vector<vector<int>> &mat1,vector<vector<int>> &mat2) {
	int n = mat1.size();
	vector<vector<int>> res(n, vector<int>(n));
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			for(int k=0;k<n;k++) {
				res[i][j]+=(mat1[i][k]*mat2[k][j])%MOD;
				res[i][j]%=MOD;
			}
		}
	}
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			mat1[i][j]=res[i][j];
		}
	}
}

void matexpo(vector<vector<int>> &mat1, int power) {
	int n = mat1.size();
	vector<vector<int>> res(n, vector<int>(n));
	for(int i=0;i<n;i++)
		res[i][i]=1;
	while(power>0) {
		if(power&1) {
			multiply(res, mat1);
		}
		multiply(mat1, mat1);
		power/=2;
	}
	for(int i = 0;i<n;i++) {
		for(int j=0;j<n;j++) {
			mat1[i][j]=res[i][j];
		}
	}
}

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

	int n, k;
	cin>>n>>k;
	vector<vector<int>> A(n, vector<int>(n, 1)), B(n, vector<int>(n, 1));
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			cin>>A[i][j];
		}
	}
	matexpo(A, k);
	// multiply(A, B);
	int ans = 0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			ans = (ans+A[i][j])%MOD;
		}
	}

	cout<<ans;

	return 0;
}

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

int main() {
  int M,D,ans=0,dt,dd;
  cin>>M>>D;
  for(int m=4;m<=M;m++){
    for(int d=22;d<=D;d++){
      dt=d/10;
      dd=d-dt*10;
      if(dd<2) continue;
      if(dt*dd==m) ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
a,b,c,d,e,f = map(int, input().split())

waters = []
for i in range(f // (100 * a) + 1):
    for j in range(f // (100 * b) + 1):
        amount = 100 * (i * a + j * b)
        if amount <= f:
            waters.append(amount)

sugers = []
for i in range(f // c + 1):
    for j in range(f // d + 1):
        amount = i * c + j * d
        if amount <= f:
            sugers.append(amount)

maxp = -1.0
res_w = 0
res_s = 0

for w in waters:
    for s in sugers:
        if w + s > f or w + s == 0:
            continue
        capa = w // 100 * e
        if s > capa:
            continue
        p = 100 * s / (w + s)
        if maxp < p:
            maxp, res_w, res_s = p, w + s, s

print("%d %d" % (res_w, res_s))

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int l, r, d;
  int ans = 0;
  cin >> l >> r >> d;

  rep(i, l, r + 1) {
    if (i % d == 0) ++ans;
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <queue>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
int main()
{
    long long a,b,c;
    cin>>a>>b>>c;
    cout<<min(min(a*b*(c%2),a*c*(b%2)),b*c*(a%2))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
    do {                                                                       \
    } while (0)
#define dump(x)                                                                \
    do {                                                                       \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

void solve() {
    int n;
    cin >> n;
    VI c(n), s(n), f(n);
    REP(i, 0, n) cin >> c[i] >> s[i] >> f[i];
    REP(i, 0, n) {
        int ans = 0;
        REP(j, i, n - 1) {
            int next = max(s[j], (f[j] - ans % f[j]) % f[j] + ans);
            ans = next + c[j];
        }
        cout << ans << endl;
    }
}

signed main() {
    solve();

    return 0;
}

Measured memory_bytes: 256
'use strict'
function main(input) {
  input = input.trim().split('\n')
  const NM = input.shift().split(' ').map(v => Number(v))
  input = input[0].split(' ').map(v => Number(v)).sort((a, b) => a - b)

  if (NM[1] - NM[0] <= 0 || NM[1] === 1) return console.log(0)

  let distance = []
  for (let i = 1; i < NM[1]; i++) {
    distance.push(input[i] - input[i - 1])
  }
  distance = distance.sort((a, b) => b - a)

  let ans = input[NM[1]-1] - input[0]
  for (let j = 0; j < NM[0] - 1; j++) {
    ans -= distance[j]
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 28440
N,M=map(int,input().split())
P=[]
S=[]
for i in range(M):
  p,s=map(str,input().split())
  P.append(int(p))
  S.append(s)
ac=0
wa=0
U=[0]*(N+1)
T=[0]*(N+1)
#print(P)
#print(S)

for i in range(M):
  if S[i]=="AC":
    U[P[i]]=1
  elif S[i]=="WA" and U[P[i]]!=1:
    T[P[i]] += 1
for i in range(N+1):
  if U[i]==0:
    T[i]=0
print(sum(U),sum(T))

Measured memory_bytes: 15012
fn main() {
    let mut str = String::new();
    use std::io;
    io::stdin().read_line(&mut str).unwrap();
    let k = str.len() - 1;
    str.remove(k);
    let n: f64 = str.parse().unwrap();
    let two: f64 = 2.0;

    println!("{}", two.powf(n.log(2.0).floor()));
}


Measured memory_bytes: 4352
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
		Console.SetOut(sw);

		string s = Console.ReadLine();
		while (s.Length >2)
		{
			s = s.Remove(s.Length - 2, 2);
			
			if (s.Substring(0, s.Length / 2)==(s.Substring(s.Length / 2)))
			{
				Console.WriteLine(s.Length);
				Console.Out.Flush();
				return;
			}
            
            
		}
        

		Console.Out.Flush();
	}
}

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

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int times = 1;
		while(true) {
			String str = br.readLine();
			String[] s = str.split(" ");
			int[] n = new int[s.length];
			for (int i = 0; i < s.length; i++) {
				n[i] = Integer.parseInt(s[i]);
			}
			
			if (n[0] == 0 && n[1] == 0) {
				break;
			}
			System.out.println(Math.min(n[0], n[1]) + " " + Math.max(n[0], n[1]) );
			times++;
		}
	}
}

Measured memory_bytes: 26640
c=[int(i) for i in input().split()]
S=input()
d=[(0,0,1),(-1,0,0),(0,1,0),(0,-1,0),(1,0,0),(0,0,-1)]
def north(r):
    res=[]
    for p in r:
        res.append((p[2],p[1],-p[0]))
    return res
def south(r):
    res=[]
    for p in r:
        res.append((-p[2],p[1],p[0]))
    return res
def east(r):
    res=[]
    for p in r:
        res.append((p[0],p[2],-p[1]))
    return res
def west(r):
    res=[]
    for p in r:
        res.append((p[0],-p[2],p[1]))
    return res
D=[i for i in d]
for i in S:
    if i=="N":
        D=north(D)
    elif i=="S":
        D=south(D)
    elif i=="W":
        D=west(D)
    else:
        D=east(D)
for k in range(6):
    if D[k]==(0,0,1):
        print(c[k])



Measured memory_bytes: 5616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			double r = 100000;
			for (int i = 0; i < n; i++)
			{
				r *= 1.05;
				if (r % 1000 != 0) r += 1000 - r % 1000;
			}
			Console.WriteLine(r);
		}
	}
}

Measured memory_bytes: 5640
#include <iostream>
#include <algorithm>
#include <array>
using namespace std;

const long long MOD = 998244353;

int main() {
    int n;
    array<int, 3> count = {}, prev = {};
    string s;
    cin >> n >> s;
    long long result = 1;
    for (char c : s) {
        if (c == 'R') {
            count[0]++;
        } else if (c =='G') {
            count[1]++;
        } else {
            count[2]++;
        }
        auto sorted = count;
        sort(begin(sorted), end(sorted));
        if (sorted[2] != prev[2]) {
            result = result * sorted[2] % MOD;
        } else if (sorted[0] != prev[0]) {
            result = result * (sorted[1] - sorted[0] + 1) % MOD;
        } else {
            result = result * (sorted[2] - sorted[1] + 1) % MOD;
        }
        swap(prev, sorted);
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 900
module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)t.d(n,o,function(e){return r[e]}.bind(null,o));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(r,e){function t(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=r[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var e=r.split("\n"),n=t(e[0].split(" ").map(function(r){return Number(r)}),2),o=n[0],u=n[1],i=e[1],f=[],a=0;a<u;a++){var l=e[a+2].split(" ").map(function(r){return Number(r)-1});f.push(l)}var c=new Array(o);c[0]=0;for(var p=1;p<o;p++)"A"==i[p-1]&&"C"==i[p]?c[p]=c[p-1]+1:c[p]=c[p-1];for(var s=0;s<u;s++){var d=f[s],y=d[0],v=c[d[1]]-c[y];console.log(v)}}},function(r,e){r.exports=require("fs")}]);

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n;

	(n<=999)?cout<<"ABC"<<endl:cout<<"ABD"<<endl;



}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,a,b,cnt = 0,maxv = 0;
  cin>>n;
  for(i = 0;i<n;i++)
  {
    cin>>a>>b;
    if(a == b)
      cnt++;
    else
      cnt = 0;
    maxv = max(maxv,cnt);
  }
  if(maxv >= 3)
    cout<<"Yes";
  else
    cout<<"No";
  
}


Measured memory_bytes: 3616