akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
using namespace std;
int s[21];
int t[21];
int u[21];
int v[21];
int can[11][45000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			scanf("%d%d%d",s+i,t+i,u+i);
		}
		for(int i=0;i<a;i++)for(int j=0;j<45000;j++)can[i][j]=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<60;j++){
				int S=(s[i]+j)%60;
				int T=(t[i]+j)%60;
				int U=(u[i]+j)%60;
				if(S%5==T/12)can[i][S/5*3600+T*60+U]=1;
				if(S%5==U/12)can[i][S/5*3600+U*60+T]=1;
				if(T%5==S/12)can[i][T/5*3600+S*60+U]=1;
				if(T%5==U/12)can[i][T/5*3600+U*60+S]=1;
				if(U%5==S/12)can[i][U/5*3600+S*60+T]=1;
				if(U%5==T/12)can[i][U/5*3600+T*60+S]=1;
			}
		}
		for(int i=0;i<a;i++)v[i]=0;
		int l=0;
		int r=50000;
		int now=0;
		int num=0;
		for(int i=0;i<44000;i++){
			while(now<44000&&num<a){
				for(int j=0;j<a;j++){
					if(!can[j][now])continue;
					v[j]++;
					if(v[j]==1)num++;
				}
				now++;
			}
			if(num<a)break;
			if(r-l>now-i){
				r=now;l=i;
			}
			for(int j=0;j<a;j++){
				if(!can[j][i])continue;
				v[j]--;
				if(v[j]==0)num--;
			}
		}
		r--;
		printf("%02d:%02d:%02d %02d:%02d:%02d\n",l/3600,l%3600/60,l%60,r/3600,r%3600/60,r%60);
	}
}

Measured memory_bytes: 2800
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T = double>
using point = complex<T>; // 2D point only

using ll = long long;
using ull = unsigned long long;
using ldob = long double;

template <typename T = int>
using ii = pair<T,T>;
template <typename T = int>
using iii = pair<T,ii<T>>;
template <typename T = int>
using ii_i = pair<ii<T>,T>;
template <typename T = int>
using vi = vector<T>;
template <typename T = int>
using vvi = vector<vi<T>>;
template <typename T = int>
using vii = vector<ii<T>>;
template <typename T = int>
using viii = vector<iii<T>>;
template <typename T = int>
using lim = numeric_limits<T>;

#define re real()
#define im imag()
#define fi first
#define se second
#define all(v) v.begin(), v.end()

// OST
template <typename T>
using ordered_set = __gnu_pbds::tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// from: https://codeforces.com/blog/entry/62393
// struct custom_hash {
// 	static uint64_t splitmix64(uint64_t x) {
// 		// http://xorshift.di.unimi.it/splitmix64.c
// 		x += 0x9e3779b97f4a7c15;
// 		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
// 		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
// 		return x ^ (x >> 31);
// 	}

// 	size_t operator()(uint64_t x) const {
// 		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
// 		return splitmix64(x + FIXED_RANDOM);
// 	}
// };

const int INF = ~(1<<31);
const ll LINF = (1LL << 60);
const long double EPS = 1e-9;
const long double PI = acos(-1);

const int N = 200005;
const int NN = 101;
const int MOD = 1e9+7;
const int IMAX = 1e9+7;
const ll LMAX = 1e15+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};
const int dx8[8] = {-1,-1,-1,0,0,1,1,1};
const int dy8[8] = {-1,0,1,-1,1,-1,0,1};

ll n, k, a[N], ord[N];

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0); // cout.tie(0);
	// cout.precision(2); cout << fixed;

	cin >> n >> k;

	memset(ord, -1, sizeof ord);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	vector<int> A;
	int s = 1;
	while (ord[s] == -1) {
		ord[s] = A.size();
		A.push_back(s);
		s = a[s-1];
	}
	int tmp = ord[s];
	int c = A.size() - tmp;

	if (k < tmp) {
		cout << A[k] << endl;
	} else {
		k -= tmp;
		k %= c;
		cout << A[tmp+k] << endl;
	}

	return 0;
}

Measured memory_bytes: 7380
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  if (n % 2 == 0) {
    ll now = 0;
    for (int i = 0; i < n; i += 2) now += a[i];
    ll maximum = now;
    for (int i = n-2; i >= 0; i -= 2) {
      now += a[i+1]; now -= a[i];
      maximum = max(maximum, now);
    }

    cout << maximum << endl;
  }
  else {
    vector<vector<ll> > dp(n+2, vector<ll>(3, (ll) -1e18));
    dp[0][0] = a[0];
    dp[1][1] = a[1];
    dp[2][2] = a[2];
    for (int i = 0; i < n; i++) {
      if (i+2 < n) dp[i+2][0] = max(dp[i+2][0], dp[i][0] + a[i+2]);
      if (i+2 < n) dp[i+2][1] = max(dp[i+2][1], dp[i][1] + a[i+2]);
      if (i+2 < n) dp[i+2][2] = max(dp[i+2][2], dp[i][2] + a[i+2]);
      if (i+3 < n) dp[i+3][1] = max(dp[i+3][1], dp[i][0] + a[i+3]);
      if (i+3 < n) dp[i+3][2] = max(dp[i+3][2], dp[i][1] + a[i+3]);
      if (i+4 < n) dp[i+4][2] = max(dp[i+4][2], dp[i][0] + a[i+4]);
    }

    cout << max(max(dp[n-3][0], dp[n-2][1]), dp[n-1][2]) << endl;
  }

  return 0;
}


Measured memory_bytes: 15876
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll max(ll a, ll b)
{
    if(a>=b) return a; else return b;
}
//ll a[3000][3000];
// ll lcs(string s, string t, ll m, ll n)
// {
//     if(m<0||n<0) return 0;
//     if(a[m][n]!=-1) return a[m][n];
//     if(s[m]==t[n])
//     {
//         a[m][n]=lcs(s,t,m-1,n-1)+1;
//     }
//     else
//     {
//         a[m][n]=max(lcs(s,t,m-1,n),lcs(s,t,m,n-1));
//     }
//     return a[m][n];
// }

int main() {
    // for(ll i=0;i<3000;i++)
    // {
    //     for(ll j=0;j<3000;j++)
    //     {
    //         a[i][j]=-1;
    //     }
    // }
    string s,t;
    cin>>s>>t;
    ll m=s.size();
    ll n=t.size();
    ll a[m+1][n+1];
    string ans;
    for(ll i=0;i<=m;i++)
    {
        for(ll j=0;j<=n;j++)
        {
            if(i==0||j==0) a[i][j]=0;
            else if(s[i-1]==t[j-1]) a[i][j]=1+a[i-1][j-1];
            else a[i][j]=max(a[i-1][j],a[i][j-1]);
        }
    }
    
    
    ll i=m;
    ll j=n;
    //ll k = lcs(s,t,m-1,n-1);
    while(ans.size()<a[m][n])
    {
        if(s[i-1]==t[j-1])
        {
            ans.push_back(s[i-1]);
            i--;
            j--;
        }
        else
        {
            //if(i==0||j==0) break;
            if(a[i-1][j]>=a[i][j-1]) i--; else j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
	return 0;
}


Measured memory_bytes: 70656
#include <iostream>
using namespace std;
int N, A, B;
int Fact[20000005], Inv[20000005];
const int MOD = 998244353;
int powerLog(int n, int p){
    int sol = 1;
    while(p){
        if(p & 1)
            sol = (1LL * sol * n) % MOD;
        p /= 2;
        n = (1LL * n * n) % MOD;
    }
    return sol;
}
void precalcFact(){
    Fact[0] = 1;
    Inv[0] = 1;
    for(int i = 1; i <= 20000000; i++)
        Fact[i] = (1LL * Fact[i - 1] * i) % MOD;
    Inv[20000000] = powerLog(Fact[20000000], MOD - 2);
    for(int i = 20000000 - 1; i >= 0; i--)
        Inv[i] = (1LL * Inv[i + 1] * (i + 1)) % MOD;
}

int Combinations(int n, int k){
    return (((1LL * Fact[n] * Inv[k]) % MOD) * Inv[n - k]) % MOD;
}
int CatalanTriangle(int n, int k){
    if(n < k)
        return 0;
    return (((((1LL * Fact[n + k] * (n - k + 1)) % MOD) * Inv[k]) % MOD) * Inv[n + 1]) % MOD;
}

inline void Add(int& x, int y){
    x += y;
    if(x >= MOD)
        x -= MOD;
}
void Solve(){
    int ans = 0;
    if(B == 0){
        cout << "1\n";
        return;
    }
    for(int k = 0; k <= N - B - 1 && A - k >= 0; k++){
        int set0Ways = Combinations(N - B - k - 1 + A - k, A - k);
        Add(ans, (1LL * set0Ways * CatalanTriangle(B - 1, k)) % MOD);
    }
    if(B - (N - B) == B - A)
    Add(ans, CatalanTriangle(B - 1, N - B));
    cout << ans << '\n';
}
int main()
{
    cin >> N >> A >> B;
    precalcFact();
    Solve();
    return 0;
}


Measured memory_bytes: 156544
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define itrep(it,v) for(auto it=(v).begin();it!=(v).end();it++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
using namespace std;

int ans=1000000000000000ll;
void foo(int n,vi b,vi a){
    int c=0;
    rep(i,n){
        if(b[i]!=a[i]){
            int j;
            for(j=i+1;j<n&&b[j]!=a[i];j++);
            if(j==n)return;
            for(;j>i;j--)swap(b[j],b[j-1]),c++;
        }
    }
    ans=min(ans,c);
}
            
signed main(){
    int n,m;
    cin>>n>>m;
    vi b(n);
    rep(i,n)cin>>b[i];
    vi p(m);
    rep(i,m)cin>>p[i];
    vi a(n);
    int c=0;
    int f=0;
    rep(i,m){
        rep(j,p[i]){
            a[c++]=f;
        }
        f=!f;
    }
    foo(n,b,a);
    rep(i,n)a[i]=!a[i];
    foo(n,b,a);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3148
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int h, w;
	cin >> h >> w;
	VI2D maze(h, VI(w));
	REP(i, h) {
		string line;
		cin >> line;
		REP(j, w) { maze[i][j] = line[j] == '.' ? 0 : 1; }
	}
	VI2D dp(h, VI(w, 0));
	REP(i, h) {
		REP(j, w) {
			if(i == 0 && j == 0) {
				dp[i][j] = maze[i][j];
			} else if(i == 0) {
				if(maze[i][j] == 1 && maze[i][j - 1] == 0) {
					dp[i][j] = dp[i][j - 1] + 1;
				} else {
					dp[i][j] = dp[i][j - 1];
				}
			} else if(j == 0) {
				if(maze[i][j] == 1 && maze[i - 1][j] == 0) {
					dp[i][j] = dp[i - 1][j] + 1;
				} else {
					dp[i][j] = dp[i - 1][j];
				}
			} else {
				dp[i][j] =
					min(dp[i][j - 1] +
							(maze[i][j] == 1 && maze[i][j - 1] == 0 ? 1 : 0),
						dp[i - 1][j] +
							(maze[i][j] == 1 && maze[i - 1][j] == 0 ? 1 : 0));
			}
		}
	}
	cout << dp[h - 1][w - 1] << endl;
	return 0;
}


Measured memory_bytes: 3712
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class FDistinctNumbers {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vc<int> cnt(N, 0);
        REP(i, N){
            int a;
            in>>a;
            a--;
            cnt[a]++;
        }
        sort(RALL(cnt));
        int sum = 0, nxt = 0, last = 0;
        for(auto& c : cnt) sum += c;
        vc<int> ans(N+1, 0);
        for(int t=N;t;--t){
            while(nxt<N and cnt[nxt]==t){
                sum -= t;
                ++nxt;
            }
            int mxk = (sum+nxt*t) / t;
            FOR(k, last+1, mxk+1) ans[k] = t;
            last = mxk;
        }
        RREP(i, N) out<<ans[i]<<'\n';
    }
};


int main() {
	FDistinctNumbers solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int n; cin >> n;
  int p[n],max=0,maxi;
  for(int i=0;i<n;i++){
    cin >> p[i];
    if(p[i]>max){
      max=p[i];
      maxi=i;
    }
  }
  int len=0;
  for(int i=0;i<n;i++){
    if(i!=maxi) 
      len+=p[i];
  }
  if(len>max) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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


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

  int count = 0;
  for(int i=0; i < N; i++){
    if(S[i] != S[i + 1]){
      count++;
    }
  }
  cout << count << endl;
}


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

int top, S[1000];

void push(int x){
    S[++top] = x;
}
int pop(){
    top--;
    return S[top+1];
}

int main()
{
    int a, b;
    top = 0;
    char s[100];

    while ( scanf("%s", s) != EOF ){
        if (s[0] == '+'){
            a = pop();
            b = pop();
            push(a + b);
        }
        else if (s[0] == '-'){
            b = pop();
            a = pop();
            push(a - b);
        }
        else if (s[0] == '*'){
            a = pop();
            b = pop();
            push(a * b);
        }
        else {
            push(atoi(s));
        }
    }
    printf( "%d\n", pop());
    return 0;
}



Measured memory_bytes: 3236
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
 
//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//infinity
#define INTINF 2000000000
#define LONGINF 20000000000
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
int main(){
	int t;
	cin >> t;
	REP(i, t){
		long long a, b, c, d;
		cin >> a >> b >> c >> d;
		
		if( b > a || b > d || a % b > c ){
			cout << "No" << endl;
			continue;
		}

		if( d == b || d % b == 0 || b - 1 <= c ){
			cout << "Yes" << endl;
			continue;
		}

		long long incre = d % b;
		long long da = d; long long bb = b;
		while(incre!=0){
			da = bb;
			bb = incre;
			incre = da % bb;
		}
		incre = bb;
		
		if( d % incre == 0 ){
			long long low = c - (a % b) + 1;
			long long high = b - (a % b) - 1;
			if( low % incre == 0 || high % incre == 0 || low / incre != high / incre){
				cout << "No" << endl;
				continue;
			}else{
				cout << "Yes" << endl;
				continue;
			}
		}else{
			cout << "No" << endl;
			continue;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=4448283280358331064;

/*
int main(){
    int n;
    cin>>n;
    ll k;
    cin>>k;
    vector<ll> pos(0), neg(0);
    int zero=0;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        if(a>0) pos.push_back(a);
        if(a==0) zero++;
        if(a<0) neg.push_back(-a);
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());

    ll ub=INF;
    ll lb=-INF;
    while(ub-lb>1){
        ll m=(ub+lb)/2;
        ll num=0;
        //cout<<m<<endl;
        if(m<=0){
            for(ll u:neg){
                num+=pos.end()-upper_bound(pos.begin(),pos.end(),-m/u);
            }
        }else{
            num+=neg.size()*pos.size();
            num+=zero*(neg.size()+pos.size());
            num+=zero*(zero-1)/2;
            for(int i=0;i<pos.size();i++){
                num+=lower_bound(pos.begin()+i, pos.end(), m/pos[i])-(pos.begin()+i);
            }
            for(int i=0;i<neg.size();i++){
                num+=lower_bound(neg.begin()+i, neg.end(), m/neg[i])-(neg.begin()+i);
            }
        }
        if(num<=k){
            lb=m;
        }else{
            ub=m;
        }
    }
    cout<<ub<<endl;
}

*/

int main(){
    ld a,b,h,m;
    cin>>a>>b>>h>>m;
    ld ans=a*a+b*b;
    ld arg=11*m/12/60-h/12;
    arg*=2*3.14159265359;
    ans-=2*a*b*cos(arg);
    ans=sqrt(ans);
    cout<<setprecision(15)<<ans<<endl;

}

Measured memory_bytes: 3488
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
  scanf("%d %d %d", a1, a2, a3);
  return 0;
}

#define NUM_MAX 500

struct train {
    int duration;
    int start;
    int interval;
};

int main(void) {
    int num = get_int();

    static struct train trains[NUM_MAX];
    int i;
    for(i = 0; i < num-1; i++) {
        int c, s, f;
        get_int3(&c, &s, &f);
        trains[i] = (struct train){c, s, f};
    }

    static int ans[NUM_MAX];
    int start;
    for(start = num-2; start >= 0; start--) {
        int elapse = 0;
        for(i = start; i < num-1; i++) {
            struct train t = trains[i];
            elapse = max(t.start, elapse);
            elapse = ((elapse-1)/t.interval+1)*t.interval;
            elapse += t.duration;
#ifdef DEBUG
            printf("start: %d -> %d\n", start, elapse);
#endif
        }
        ans[start] = elapse;
    }

    for(i = 0; i < num; i++) {
        printf("%d\n", ans[i]);
    }
    return 0;
}

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

const int maxn = 1e5 + 10;
ll a[maxn];
ll b[maxn];
int n;
void solve() {
    while(cin >> n) {
        for (int i = 0; i < n; i++) {
            cin >> a[i] >> b[i];
        }
        ll res = 0;
        for (int i = n - 1; i >= 0; i--) {
            a[i] += res;
            if(a[i] % b[i] == 0) continue;
            ll t = b[i] - a[i] % b[i];
            res += t;
        }
        cout <<res << endl;
    }

}
int main() {
    //freopen("test.in", "r", stdin);
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
 
using namespace std;
const int maxn=1000005;
int n,m,dp[maxn],best,path[maxn],root;
vector<pair<int,int>> g[maxn];
 
int dfs_With_dp(int u)
{
    if(dp[u]) return dp[u];
    dp[u]=1;
    for(auto v:g[u]) {
        int c=v.first;
        if(dp[u]<dfs_With_dp(c)+1) {
            dp[u]=dp[c]+1;
            path[u+1]=c+1;
        }
    }
    return dp[u];
}
 
int main()
{
    int x,y;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++) {
        scanf("%d%d",&x,&y);
        x-=1;
        y-=1;
        g[x].push_back(make_pair(y,i+1));
    }
    for(int i=0;i<n;i++) {
        int path_len=dfs_With_dp(i);
        if(best<path_len) {
            root=i;
            best=path_len;
        }
    }
    cout<<best-1;
    
    return 0;
}

Measured memory_bytes: 32000
#include<cstdio>
#include<cstring>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 10010
#define MOD 998244353
using namespace std;
typedef long long ll;
int dp[MAXN][MAXN];
char a[MAXN],b[MAXN];
int cnta,cntb;
ll fac[MAXN],ifac[MAXN];
ll ans;
ll fsp(ll x,int y){
	ll res=1;
	while(y){
		if(y&1)
			res=res*x%MOD;
		x=x*x%MOD;
		y>>=1;
	}	
	return res;
}
void prepare(){
	fac[0]=1;
	for(int i=1;i<=10000;i++)
		fac[i]=fac[i-1]*i%MOD;
	ifac[10000]=fsp(fac[10000],MOD-2);
	for(int i=10000;i>=1;i--)
		ifac[i-1]=ifac[i]*i%MOD;
}
ll C(int n,int m){
	return fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;	
}
int main(){
	prepare();
	SF("%s%s",a,b);
	int len=strlen(a);
	for(int i=0;i<len;i++){
		if(a[i]=='1'){
			if(b[i]=='1')
				cnta++;
			else
				cntb++;
		}
	}
	dp[0][0]=1;
	for(int i=0;i<=cnta;i++)
		for(int j=1;j<=cntb;j++){
			if(i!=0)
				dp[i][j]=1ll*dp[i-1][j]*i%MOD*j%MOD;
			dp[i][j]=(dp[i][j]+1ll*dp[i][j-1]*j%MOD*j%MOD)%MOD;
		}
	//PF("{%d %d}\n",dp[0][1],dp[1][1]);
	for(int i=0;i<=cnta;i++){
		int les=cnta-i;
		//PF("{%d %lld %lld %lld}\n",dp[i][cntb],fac[les],C(cnta,les),C(cnta+cntb,les));
		ans=(ans+1ll*dp[i][cntb]*fac[les]%MOD*fac[les]%MOD*C(cnta,les)%MOD*C(cnta+cntb,les)%MOD)%MOD;
	}
	PF("%lld",ans);
}

Measured memory_bytes: 299648
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> AB(N);
  int a, b;
  for (int i = 0; i < N; i++)
  {
    cin >> a >> b;
    AB[i].first = a;
    AB[i].second = b;
  }
  sort(AB.begin(), AB.end());
  
  long long ans = 0;
  for (int i = 0; i < N; i++)
  {
    while (AB[i].second > 0)
    {
      ans += AB[i].first;
      M--;
      if (M == 0) goto TRAVEL;
      AB[i].second--;
    }
  }
  TRAVEL:
  cout << ans;
} 

Measured memory_bytes: 4056
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
import collections
edges = collections.defaultdict(list)
for i in range(N-1):
	u, v = rl()
	if v < u:
		u, v = v, u
	edges[u-1].append(v-1)

s = 0
for i in range(N):
	for e in edges[i]:
		s += N-1-e+1
ans = N*(N**2+3*N+2)//6-s
for i in range(N):
	if edges[i]:
		for e in edges[i]:
			s -= (N-1-e+1)
	ans -= s
print(ans)


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int n;
  cin >> n;

  vector<int> back(100100, 0);
  ll ans = 0;
  rep(i, n){
    int a;
    cin >> a;
    ans += a;
    back[a]++;
  }

  int q;
  cin >> q;
  vector<ll> vecans;
  rep(i, q){
    int b, c;
    cin >> b >> c;
    if(back[b] > 0){
      back[c] += back[b];
      ans += (c-b) * back[b];
      back[b] = 0;
    }
    vecans.push_back(ans);

  }

  rep(i, q){
    cout << vecans[i] << endl;
  }




  return 0;
}


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

int main(){
	while(1){
		int n;
		cin>>n;
		
		if(n==0){
			break;
		}
		
		char c[100];
		for(int i=0;i<n;i++){
			cin>>c[i];
		}
		int cnt[26]={0};
		for(int i=0;i<n;i++){
			cnt[(int)(c[i]-'A')]++;
			int max1=-1;
			int max2=-1;
			for(int j=0;j<26;j++){
				if(cnt[j]>max1){
					max2=max1;
					max1=cnt[j];
				}else if(cnt[j]>max2){
					max2=cnt[j];
				}
			}
			if(max1-max2>n-(i+1)){
				for(int j=0;j<26;j++){
					if(cnt[j]==max1){
						cout<<(char)(j+'A')<<' ';
						break;
					}
				}
				cout<<(i+1)<<endl;
				break;
			}
			if(i==n-1){
				cout<<"TIE"<<endl;
				break;
			}
		}
	}
	return 0;
}	

Measured memory_bytes: 3052
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

lint L, R;
const lint MOD = 1000000007;
lint dp[64][2][2][2];

lint F(int bit, int xg, int yl, int fs)
{
    if (bit == -1) {
        return fs == 1 ;
    }

    lint& ans = dp[bit][xg][yl][fs];
    if (ans >= 0) {
        return ans;
    }

    int LBit = (L >> bit) & 1, RBit = (R >> bit) & 1;

    ans = 0;
    FOR(yb, 0, 2)
        FOR(xb, 0, 2) {
            if (xg == 0 && xb < LBit)
                continue;
            if (yl == 0 && yb > RBit)
                continue;
            if (xb == 1 && yb == 0)
                continue;
            if (fs == 0 && yb == 1 && xb == 0)
                continue;

            ans = (ans + F(bit - 1, xg | (xb > LBit),
                            yl | (yb < RBit), fs | (yb == 1))) % MOD;
        }

    return ans;
}

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    cin >> L >> R;

    memset(dp, -1, sizeof dp);
    cout << F(60, 0, 0, 0) << endl;
    return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
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 / GCD(x, y) * y;}
//cout << fixed << setprecision(10);
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}

int main(){
    ll n;
    string s;
    cin>>n>>s;
    vector<char>l(52);
    char a='A';
    l[0]=a;
    rep(i,25){
        a++;
        l[i+1]=a;
    }
    a='A';
    l[26]=a;
    rep(i,25){
        a++;
        l[i+27]=a;
    }
    rep(i,s.size()) cout<<l[s[i]-'A'+n];
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 1;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregion

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

  string s;
  cin >> s;
  int n = s.length();
  reverse(all(s));
  ll csum[200010];
  csum[0] = 0;
  ll cnt[2019] = {};
  cnt[0]++;
  ll pow10 = 1;
  rep(i, n)
  {
    csum[i + 1] = (csum[i] + (s[i] - '0') * pow10) % 2019;
    cnt[csum[i + 1]]++;
    pow10 = pow10 * 10 % 2019;
  }
  ll ans = 0;
  rep(i, 2019)
  {
    ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3800
/*===============================================================
*  Filename: A.cpp
*  Author: zhuyutian
*  Date: 2018.04.15
================================================================*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100005;

int n;
int a[maxn];
vector<pair<int,int> > ans;

int main()
{
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    cin>>n;
	for(int i = 0; i < n; i++) cin>>a[i];
	int x = 0;
	for(int i = 0; i < n; i++)
		if(abs(a[x]) < abs(a[i]))
			x = i;
	for(int i = 0; i < n; i++){
		if(a[i] == a[x]) continue;
		ans.push_back(make_pair(x + 1,i + 1));
		a[i] += a[x];
	}
	if(a[n - 1] < 0)
		for(int i = n - 1; i; i--){
			ans.push_back(make_pair(i + 1,i));
			a[i - 1] += a[i];
		}
	else for(int i = 1; i < n; i++){
		ans.push_back(make_pair(i,i + 1));
		a[i] += a[i - 1];
	}
	cout<<ans.size()<<endl;
	for(int i = 0; i < ans.size(); i++)
		cout<<ans[i].first<<" "<<ans[i].second<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;


int main(){
  long ii,jj,kk;
  vector<int> ret;
  queue<int> s[1001];
  
  int n,q,c,t,x;

  cin >> n >> q;

  for(ii=0;ii<q;ii++){
    //cout << ii << endl;
    cin >> c;
    switch(c){

    case 0:
      cin >> t >> x;
      s[t].push(x);
      break;

    case 1:
      cin >> t;
      if(!s[t].empty()){
        cout << s[t].front() << endl;
      }
      break;

    case 2:
      cin >> t;
      if(!s[t].empty()){
        s[t].pop();
      }
      break;

    }
  }
  
  return 0;
}



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

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

  for (int i = 1; i <= b; i++) {
    if (a * i % b == c) {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i,n)cin >> a[i];

    ll row[n] = {};
    stack<P> s;

    ll ans = 0;

    rep(i,n){
        if(i==0){
            row[i] = a[i];
            s.push(P(a[i],1)); 
        } else {
            row[i] = row[i-1] + a[i];
            P p;
            p.first = a[i];
            p.second = 1;
            while(0 < s.size() && a[i] < s.top().first){
                P tmp = s.top();
                s.pop();
                row[i] -= (tmp.first - a[i]) * tmp.second;
                p.second += tmp.second;
            }
            s.push(p);
        }

        ans += row[i];
    }

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


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int A[]=new int[10000];

		for(int i=0; i<N; i++) {
			A[i]=sc.nextInt();
		}
		//System.out.println(N);
		int fn=0;
		for(int i=0; i<N; i++) {
			while(A[i]%2==0) {
				fn++;
				A[i]/=2;

			}
		}
		System.out.println(fn);
	}

}

Measured memory_bytes: 34440
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsProgramSpace
{
    class Program
    {
        static void Main(string[] args)
        {
            //n,m
            short[] inf = (Console.ReadLine().Split(' ').Select(_ => short.Parse(_)).ToArray());
            short n = inf[0], m = inf[1];
            short[] b = new short[m];
            short[][] a = new short[n][];//~m
            short[] temp = new short[m];
            int[] c = new int[n];
            //Inputs a
            for(int i=0;i<n;i++)
            {
                a[i] = new short[m];
                temp = (Console.ReadLine().Split(' ').Select(_ => short.Parse(_)).ToArray());
                for (int j = 0; j<m;j++)
                {
                    a[i][j] = temp[j];
                }
            }
            for(int i = 0; i<m;i++)
            {
                b[i] = short.Parse(Console.ReadLine());
            }
            //Calc
            for(int i = 0; i<n;i++)
            {
                c[i] = 0;
                for(int j = 0; j<m;j++)
                {
                    c[i] += a[i][j] * b[j];
                }
            }
            foreach(int i in c)
            {
                Console.WriteLine(i);
            }
        }
    }
}


Measured memory_bytes: 18484
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);

const int m = 10e6;
using namespace std;


int main() {

   ll int tst,a,b,c,d;
   string s;
    cin>>a>>s;
    //cout<<s.size();
    if(a >= s.size()){
    cout<<s<<endl;
    }
    else {
    cout<<s.substr(0,a);
    cout<<"..."<<endl;
    }
       return 0;
}


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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define all(a) (a).begin(), (a).end()

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  vector<int> hoge(3);
  rep(i,3)cin>>hoge[i];
  sort(all(hoge));
  cout<<hoge[0]*hoge[1]/2<<endl;
}


Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N, L = ri_()
if L >= 0:
    eaten = 0
elif L <= -N:
    eaten = N - 1
else:
    eaten = -L
ans = N * L + N * (N - 1) // 2 - (L + eaten)
print(ans)

Measured memory_bytes: 63468
import sys
input = sys.stdin.readline
 
n, m = map(int, input().split())
 
def Find(x, par, diff_weight):
  if par[x] < 0:
    return x
  else:
    # 経路圧縮
    px = Find(par[x], par, diff_weight)
    diff_weight[x] += diff_weight[par[x]]
    par[x] = px
    return px
 
def Unite(x, y, par, rank, diff_weight, w):
  w += diff_weight[x] - diff_weight[y]
  x = Find(x, par, diff_weight)
  y = Find(y, par, diff_weight)
  
  if x != y:
    # rankの低い方を高い方につなげる
    if rank[x] < rank[y]:
      x, y =  y, x
      w = -w
    if rank[x] == rank[y]:
        rank[x] += 1
    par[x] += par[y]
    par[y] = x
    diff_weight[y] = w
 
def Same(x, y, par, diff_weight):
  return Find(x, par,diff_weight) == Find(y, par, diff_weight)
 
def Size(x, par):
  return -par[Find(x)]
 
def Weight(x, par, diff_weight):
  Find(x, par, diff_weight)
  return diff_weight[x]
 
def Diff(x, y, par, diff_weight):
  return Weight(y, par, diff_weight)  - Weight(x, par, diff_weight)
 
par = [-1]*n
rank = [0]*n
diff_weight = [0]*n
for i in range(m):
  l, r, d = map(int, input().split())
  l, r = l-1 ,r-1
  if Same(l, r, par, diff_weight) == False:
    Unite(l, r, par, rank, diff_weight, d)
  else:
    if d != Diff(l, r, par, diff_weight):
      print('No')
      exit()
print('Yes')

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

typedef long long ll;

int main(){
	ll n;
	ll a[100010];
	scanf("%lld",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%lld",&a[i]);
	}
	
	ll ret[2];
	for(int t = 0 ; t < 2 ; t ++){
		ll sum = 0;
		for(int i = 0 ; i < n ; i ++){
			sum += a[i];
			if((i&1) == t){
				if(sum <= 0){
					ret[t] += 1-sum;
					sum = 1;
				}
			}
			else {
				if(sum >= 0){
					ret[t] += sum+1;
					sum = -1;
				}
			}
		}
	}
	cout << min( ret[0] , ret[1] ) << endl;
}


Measured memory_bytes: 1024
/*
N?????????????????§?§???????????????¨T????????????
????????????1~N?????§???????????????????????????1??????????????????
T??????????????\??????2????????????????????????:
	
M v:?????????v??????????????????
Q v:v??????????????????????????????????\????????????????????????????

?????????????????????????????????????????????(?????????1??????)???
???????????????????????????????¨?????????????????????????

??????????????°:N<=100000
?????¨????????°:Q<=100000

?????????1???:N??¨Q
???????¬????N-1???:2~N??????????????????
?¬????Q???:?????¨???(M v or Q v)?????¢
*/

#include <cstdio>
#include <iostream>
using namespace std;

long const long N=100000;

long par[N+1];
long tree[N+1]; //??¨????§????

long find(long x){
	//printf(" x=%ld\n", x);
	if(par[x]==x) return x;
	else return find(par[x]);	
}

int main(){
	while(1){
		long n, q;
		scanf(" %ld %ld", &n, &q);
		if(n==0) break;
			
		par[1]=1;
		for(long i=2; i<=n; ++i) scanf(" %ld", &par[i]);
		
		long ans=0;
		for(long i=0; i<q; ++i){
			char req;
			long m;
			
			scanf(" %c %ld", &req, &m);
			if(req=='M') par[m]=m; //????????§????????¢?????????????????????
			else if(req=='Q') ans+=find(m);
			//printf("%ld\n", ans);
		}
			
		printf("%ld\n", ans);
	}
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
   int a,b,c,d;
   cin >>a>>b>>c>>d;
   if(a*b >= c*d)   cout << a*b;
   else{
       cout << c*d;
   }
   cout << '\n';


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
void fff()
{
	ll a,b,k;
	cin >> a >> b >> k;
	ll t = min(a,k);
	a-=t;
	k-=t;
	t = min(b,k);
	b-=t;
	cout<<a<<" "<<b<<ln;	
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = 0;
	if(a != c){
		ans = 1;
	}
	cout << ans << endl;
}

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

const long long mod = 998244353;

template< typename T >
T mod_pow(T x, T n, const T &p) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= p;
        (x *= x) %= p;
        n >>= 1;
    }
    return ret;
}

vector<long long> fact, fact_inv, inv;

template< typename T >
void init_combi(size_t size, const T mod) {
    fact.resize(size);
    fact_inv.resize(size);
    inv.resize(size);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 1; i < size-1; i++) {
        fact[i+1] = fact[i] * (i + 1) % mod;
        inv[i+1] = mod - inv[mod % (i+1)] * (mod / (i+1)) % mod;
        fact_inv[i+1] = fact_inv[i] * inv[i+1] % mod;
    }
}

template< typename T >
T mod_combi(T n, T k, T mod) {
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

int main() {
    long long N, M, K;
    cin >> N >> M >> K;
    long long ans = 0;
    init_combi(N, mod);
    for (long long k = 0; k <= K; ++k) {
        long long s = mod_combi(N-1, k, mod);
        s = (s * M) % mod;
        s = (s * mod_pow(M-1, N-k-1, mod)) % mod;
        ans = (ans + s) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 7864
# abc164_c.py
# https://atcoder.jp/contests/abc164/tasks/abc164_c

# C - gacha /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# くじ引きを N回行い、i 回目には種類が文字列 Siで表される景品を手に入れました。
# 何種類の景品を手に入れましたか？

# 制約
#     1≤N≤2×105
#     Siは英小文字のみからなり、長さは 1 以上 10以下

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# S1
# :
# SN

# 出力
# 何種類の景品を手に入れたか出力せよ。

# 入力例 1
# 3
# apple
# orange
# apple

# 出力例 1
# 2

# apple と orange の 2種類の景品を手に入れました。

# 入力例 2
# 5
# grape
# grape
# grape
# grape
# grape

# 出力例 2
# 1

# 入力例 3
# 4
# aaaa
# a
# aaa
# aa

# 出力例 3
# 4


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    values = list()
    for i in range(N):
        values.append(lines[i+1])
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    tmps = list()
    for value in values:
        tmps.append(value)

    log(list(set(tmps)))
    result = len(list(set(tmps)))

    return [result]


# 引数を取得
def get_input_lines():
    line = input()
    N = int(line)
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', 'apple', 'orange', 'apple']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['5', 'grape', 'grape', 'grape', 'grape', 'grape']
        lines_export = [1]
    if pattern == 3:
        lines_input = ['4', 'aaaa', 'a', 'aaa', 'aa']
        lines_export = [4]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 41308
<?php

$n = trim(fgets(STDIN));
$i = 1;
echo dfs('');

function dfs($s){
	global $n;
	$count = 0;
	$array = ['3', '5', '7'];
	$next  = [1, 2, 0, 1, 2];
	for ($i=0; $i < 3; $i++) { 
		$str = $s . $array[$i];
		if (strpos($str, $array[$next[$i]]) !== false && strpos($str, $array[$next[$i+1]]) !== false && (int)$str <= $n) {
			++$count;
		}
		if (strlen($str) < strlen((string)$n)) {
			$count += dfs($str);
		}
	}
	return $count;
}

Measured memory_bytes: 4604
#include <stdio.h>

int main(void)
{
	int n;
	
	scanf("%d",&n);
	
	int a = n;
	int m=0;
	int s = a % 10;
	
	while(a > 0)
	{
		a = a / 10;
		m = a - (a/10)*10;
		s = s+m;
	}
	
	//printf("%d \n",s);
	
	if(n%s == 0)
	{
		printf("Yes \n");
	}else{
		printf("No \n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MAX(a,b) (a>b?a:b)
int main()
{
    int n, i, j;
    int x[100],y[100],h[100];
    int X, Y, H, max=0;

    scanf("%d",&n);
    for(i=0; i<n; i++) {
        scanf("%d %d %d",&x[i],&y[i],&h[i]);
        max = MAX(max, h[i]);
    }

    for(X=0; X<101; X++) {
        for(Y=0; Y<101; Y++) {
            for(H=max; H<max+201; H++) {
                int flag = 1;
                for(i=0; i<n; i++) {
                    if(h[i] != MAX(0, H-abs(X-x[i])-abs(Y-y[i])) ) {
                        flag = 0;
                        break;
                    }
                }
                if(flag==1) {
                    printf("%d %d %d",X, Y, H);
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a, b;
	while (cin >> a >> b) {
		for (int i = min(a,b); i > 0; i--)
		{
			if (a%i == 0 && b%i == 0)
			{
				cout << i << endl;
				goto Cpp;
			}
		}
		Cpp:
		for (int i = 0; i < 1; i++)
		{

		}
	}
}

Measured memory_bytes: 2980
N = int(input())
dp = [N] * 110000
dp[0] = 0
for i in range(0,N+1):
    m = 1
    while m <= N:
        dp[i] = min(dp[i],dp[i-m]+1)
        m *= 6
    m = 1
    while m <= N:
        dp[i] = min(dp[i],dp[i-m]+1)
        m *= 9
print(dp[N])

Measured memory_bytes: 3828