akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i =0; i < n ;i++)
using namespace std;
long long A[100005];
long long b[100005];

int main(){
    int N;
    long long ans =0;
    cin >> N;

    for(int i =0; i < N ; i++){
        cin >>A[i];
    }

    //sort(A, A+N, std::greater<int>());
    sort(A, A+N);

    if(N % 2==0){
        int c = N/2;
        rep(i, c){
            if(i % 2==0){
                b[c+i] = A[i];
                b[c-i-1] = A[N-1-i];
            }
            else{
                b[c+i] = A[N-1-i];
                b[c-i-1] = A[i];
            }
        }
        rep(i, N-1){
            ans += abs(b[i+1]- b[i]);
        }
        
    }
    else{
        int c = (N+1)/2 - 1;
        b[c] = A[0]; 
        rep(i, c){
            if(i % 2==0){
                b[c+1+i] = A[N-1-i];
                b[c-1-i] = A[N-2-i];
            }
            else{
                b[c+i+1] = A[i];
                b[c-i-1] = A[i+1];
            }
        }
        long long tempans=0;
        rep(i, N-1){
            tempans += abs(b[i+1]- b[i]);
        }

        b[c] = A[N-1]; 
        rep(i, c){
            if(i % 2==0){
                b[c+i+1] = A[i];
                b[c-i-1] = A[i+1];
            }
            else{
                b[c+i+1] = A[N-1-i];
                b[c-i-1] = A[N-2-i];
            }
        }
        ans = tempans;
        tempans=0;
        rep(i, N-1){
            tempans += abs(b[i+1]- b[i]);
        }
        ans = max(ans, tempans);
    }
    cout << ans << endl;
    return 0;

   
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<int>g[100001];
vector<int>in(100001,0);
 vector<int>dp(100001,0);
int main(){
    int n,m;
    cin>>n>>m;
   
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        ++in[b];
    }
    stack<int>st;
    for(int i=1;i<=n;i++){
         if(in[i]==0){
              st.push(i);
         }
    }
    while(!st.empty()){
         int top=st.top();
         st.pop();
     //    cout<<top<<endl;
         for(int i=0;i<g[top].size();i++){
              dp[g[top][i]]=max(dp[g[top][i]],dp[top]+1);
              if(in[g[top][i]]>0){
                   --in[g[top][i]];
                   if(in[g[top][i]]<=0){
                         st.push(g[top][i]);
                    }
              }
              
              
         }
    }
    int maxi=0;
   for(int i=1;i<=n;i++){
        maxi=max(maxi,dp[i]);
   }
   cout<<maxi<<endl;
}

Measured memory_bytes: 9356
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

k = ni()
que = deque([(1,1)])

kmod = [0]*k

while kmod[0] == 0:
    cost, idx = que.popleft()
    if kmod[idx] == 0:
        kmod[idx] = cost
        if kmod[10*idx%k] == 0:
            que.appendleft((cost, (10*idx%k)))
        if kmod[(idx+1)%k] == 0:
            que.append((cost+1, (idx+1)%k))            
        
print(kmod[0])

Measured memory_bytes: 9804
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define EPS 1e-10
using namespace std;
typedef long long ll;
struct Point{
	double x,y;
	Point(double x = 0.0,double y = 0.0): x(x),y(y) {}
	Point operator + (Point p){
		return Point(x + p.x,y + p.y);
	}
	Point operator - (Point p){
		return Point(x - p.x,y - p.y);
	}
	Point operator * (double lambda){
		return Point(x * lambda,y * lambda);
	}
	Point operator / (double lambda){
		return Point(x / lambda,y / lambda);
	}
	double norm(){
		return x * x + y * y;
	}
	double abs_(){
		return sqrt(norm());
	}
	bool operator == (const Point &p)const
	{
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
	bool operator < (const Point &p)const
	{
		if(abs(x - p.x) < EPS) return y < p.y;
		else return x < p.x;
	}
};
typedef Point Vector;
struct Segment{
	Point p1,p2;
	Segment(Point p1 = Point(),Point p2 = Point()): p1(p1),p2(p2) {}
};
typedef Segment Line;
struct Circle{
	Point c;
	double r;
	Circle(Point c = Point(),double r = 0.0): c(c),r(r) {}
};
typedef vector<Point> Polygon;
double dot(Vector a,Vector b){
	return a.x * b.x + a.y * b.y;
}
double det(Vector a,Vector b){
	return a.x * b.y - b.x * a.y;
}
bool vertical(Line l1,Line l2){
	return abs(dot(l1.p2 - l1.p1,l2.p2 - l2.p1)) < EPS;
}
bool parallel(Line l1,Line l2){
	return abs(det(l1.p2 - l1.p1,l2.p2 - l2.p1)) < EPS;
}
Point proj(Point p,Line l){
	Vector a = l.p2 - l.p1;
	double r = dot(a,p - l.p1) / a.norm();
	return l.p1 + a * r;
}
Point ref(Point p,Line l){
	Point A = proj(p,l);
	return A + (A - p);
}
int main(){
	Line l; Point p;
	scanf("%lf%lf%lf%lf",&l.p1.x,&l.p1.y,&l.p2.x,&l.p2.y);
	int t;
	scanf("%d",&t);
	while(t--){
		scanf("%lf%lf",&p.x,&p.y);
		Point A = ref(p,l);
		printf("%.10f %.10f\n",A.x,A.y);
	}
	return 0;
}



Measured memory_bytes: 3252
//HovalHaq!
#include <bits/stdc++.h>
using namespace std;
const int Mx = 1 >> 19;
typedef pair<int, int> PII;
int main() {
	int h, w, n; cin >> h >> w >> n;
	vector<int> H(h + 1), W(w + 1);
	vector<bool> HH(h + 1), HW(w + 1);
	vector<PII> P(n);
	for(int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		H[x] ++;
		W[y] ++;
		P[i] = PII(x, y);
	}
	int maxH = 0, maxW = 0, cH = 0, cW = 0;
	for(int i = 1; i <= h; i++) maxH = max(maxH, H[i]);
	for(int i = 1; i <= w; i++) maxW = max(maxW, W[i]);
	for(int i = 1; i <= h; i++) if(H[i] == maxH) HH[i] = true, cH++;
	for(int i = 1; i <= w; i++) if(W[i] == maxW) HW[i] = true, cW++;
	long long s = ((long long) cH) * cW;
	for(PII p : P)
		if(HH[p.first] && HW[p.second])
			s--;
	cout << maxH + maxW - (s == 0);
}


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

using namespace std;

#define N 1000

int LCS(string x, string y){
  int apx[N+1][N+1];
  int a=x.size();
  int k=y.size();
  int max_l =0;

  x=' '+x;
  y=' '+y;

  for(int i=0;i<=a;i++) apx[i][0] =0;
  for(int j=0;j<=k;j++) apx[0][j] =0;

  for(int i=1;i<=a;i++){
    for(int j=1;j<=k;j++){
      if(x[i] == y[j])  apx[i][j] = apx[i-1][j-1] +1;
      else apx[i][j] = max(apx[i-1][j],apx[i][j-1]);
      max_l=max(max_l,apx[i][j]);
    }
  }
  return max_l;
}


int main(){
  int q;
  string x,y;

  cin >> q;

  for(int i=0;i<q;i++){
    cin >> x >> y;
    cout << LCS(x,y) << endl;
  }
  return 0;


}



Measured memory_bytes: 6976
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum long mod = 10^^9 + 7;

void main() {
    int n;
    int[] a;

    scan(n);
    a = readln.split.to!(int[]);

    int[int] b1, b2;
    int mc;
    int ans;

    foreach (i ; 0 .. n) {
        if (i % 2 == 0) {
            b1[a[i]]++;
        }
        else {
            b2[a[i]]++;
        }
    }

    auto c1 = b1.byPair.array.sort!"a[1] > b[1]";
    auto c2 = b2.byPair.array.sort!"a[1] > b[1]";

    if (c1.front[0] != c2.front[0]) {
        ans = n - c1.front[1] - c2.front[1];
    }
    else {
        ans = n;

        if (c1.length > 1) {
            ans = min(ans, n - c1[1][1] - c2[0][1]);
        }
        else {
            ans = min(ans, n - c2[0][1]);
        }

        if (c2.length > 1) {
            ans = min(ans, n - c1[0][1] - c2[1][1]);
        }
        else {
            ans = min(ans, n - c1[0][1]);
        }
    }

    writeln(ans);

    debug {
        writeln(c1);
        writeln(c2);
    }
}

























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 12864
#include <iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string>
using namespace std;

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

	int a[60] = { 0 };
	int b[60] = { 0 };
	for (int i = 0; i < M; ++i)cin >> a[i];
	for (int i = 0; i < M; ++i)cin >> b[i];

	int baketto[60] = { 0 };
	for (int i = 0; i < M; ++i) baketto[a[i]]++;
	for (int i = 0; i < M; ++i) baketto[b[i]]++;

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

		cout << int(baketto[i]) << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]

num = [-1]*n
#print(num)
for i in range(m):
    if (num[sc[i][0]-1] == -1) or (num[sc[i][0]-1] == sc[i][1]):
        num[sc[i][0]-1] = sc[i][1]
    else:
        print(-1)
        exit()

if (num[0] == 0) and (n != 1):
    print(-1)
    exit()
elif ((num[0] == -1) and (n != 1)):
    num[0] = 1

elif ((num[0] == -1) and (n == 1)):
    num[0] = 0
    
for i in range(n):
    if num[i] == -1:
        num[i] = 0
    
ans = 0

for i in range(n):
        ans += num[i]*10**(n-i-1)
print(ans)

Measured memory_bytes: 9248
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    Vec<i64> A(100001, 0);
    for (i32 i = 0; i < N; i++) {
        i32 a;
        cin >> a;
        A[a]++;
    }
    i32 Q;
    cin >> Q;
    i64 sum = 0;
    for (i32 i = 1; i < 100001; i++) sum += A[i] * i;
    for (i32 i = 0; i < Q; i++) {
        i32 B, C;
        cin >> B >> C;
        sum -= A[B] * B;
        sum += A[B] * C;
        A[C] += A[B];
        A[B] = 0;
        cout << sum << endl;
    }

}


Measured memory_bytes: 3988
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var s = Read();
            var ans = 0;
            for (int i = 0; i < n-1;)
            {
                if (s[i] != s[i + 1])
                {
                    ans++;
                    i += 2;
                }
                else
                {
                    i++;
                }

            }
            WriteLine(ans);
        }


        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }


        public static bool IsPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

        //最大公約数
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        //文字数を数える
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
        public static void debuglist(List<int> x)
        {
            foreach (var item in x)
            {
                WriteLine(item);
            }
        }
        public static void debuglist(List<string> x)
        {
            foreach (var item in x)
            {
                WriteLine(item);
            }
        }
        public static void debugarray(int[] x)
        {
            foreach (var item in x)
            {
                WriteLine(item);
            }
        }
        public static void debugarray(string[] x)
        {
            foreach (var item in x)
            {
                WriteLine(item);
            }
        }
    }
}



Measured memory_bytes: 17992
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x))%modulo)
#define Inf 100000000000000000



int main(){
	string S;
	cin>>S;
	
	vector<int> ans(S.size(),0);
	
	vector<int> RL_ind(0);
	
	for(int i=0;i<S.size()-1;i++){
		if(S[i]=='R'&&S[i+1]=='L')RL_ind.push_back(i);
	}
	
	for(int i=0;i<S.size();i++){
		if(S[i]=='R'){
			int x = *lower_bound(RL_ind.begin(),RL_ind.end(),i);
			if(abs(x-i)%2==0){
				ans[x]++;
			}
			else{
				ans[x+1]++;
			}
		}
		else{
			auto a = lower_bound(RL_ind.begin(),RL_ind.end(),i);
			a--;
			int x = *a;
			if(abs(x-i)%2==0){
				ans[x]++;
			}
			else{
				ans[x+1]++;
			}
		}
	}
	
	for(int i=0;i<S.size();i++){
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
	
	
	return 0;
}




Measured memory_bytes: 1280
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
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; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int x, n, a[111], ans = -1, flag;
bool us[111];
main() {
  file("threesum");
  ios;
  fo(i, 1, 5, 1) cin >> a[i];
  fo(i, 1, 5, 1) if (!a[i]) cout << i;
  return 0;
}
/**

*/


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll dp[100000][3];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    int a[N],b[N],c[N];
    rep(i,0,N) cin>>a[i]>>b[i]>>c[i];
    rep(i,0,N){
        if(i==0){
            dp[i][0]=a[0];
            dp[i][1]=b[0];
            dp[i][2]=c[0];
        }
        else{
            dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
            dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
            dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
        }
    }
    cout <<max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2]))<<"\n";
}

Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

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

  if(b%a == 0) cout << a + b << endl;
  else cout << b - a << endl;
  
  return 0;
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, p;
string s;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>p>>s;
    ll ans=0;
    if(p==2||p==5){
        rep(i,n){
            if((s[n-i-1]-'0')%p==0)ans+=n-i;
        }
    }
    else{
    vector<ll> val(p,0);
    ll tenfactor=1;
    ll cur=0;
    val[cur]++;//最初の0
    rep(i,n){
        cur=(cur+(s[n-i-1]-'0')*tenfactor)%p;//i+1桁目までのあまり
        tenfactor*=10;
        tenfactor%=p;
        val[cur]++;
    }
    rep(i,p){
        ans+=val[i]*(val[i]-1)/2;
    }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 720
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = S()
ans = s.count("R")
if s == "RSR":
    print(1)
else:
    print(ans)

Measured memory_bytes: 76580
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> arr(n);
    map <ll,ll> val1,val2;
    rep (i,1,n+1)
    {
        cin>>arr[i-1];
        val2[-arr[i-1]-i]++;
    }
    ll ans=0;
    rep (i,0,n)
    {
        ans+=val2[arr[i]-i-1];
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 27332
#include <iostream>

using namespace std;

int main() {
   int n;
   cin>>n;
   int ara[n];
   long long ans=0;
   for(int i=0;i<n;i++){
       cin>>ara[i];
       if(i){
           if(ara[i]<ara[i-1]){
               ans+=ara[i-1]-ara[i];
               ara[i]=ara[i-1];
           }
       }
   }
   cout<<ans<<endl;
    
    
}

Measured memory_bytes: 4416
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Vector<Integer> vec = new Vector<>();
        int q = sc.nextInt();
        for(int i = 0 ; i < q ; i++){
            char c = sc.next().charAt(0);
            switch(c){
            case '0' : vec.add(Integer.parseInt(sc.next())); break;
            case '1' : System.out.println(vec.elementAt(Integer.parseInt(sc.next()))); break;
            case '2' : vec.remove(vec.size()-1); break;
            }
        }
    }
}


Measured memory_bytes: 118388
#pragma GCC optimize("trapv")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

#define int long long

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SZ = 1e5 + 10, INF = 1e9 * 1e9;
ll dp[SZ], push[SZ * 8][4], tree[SZ * 8][4];

void p(int v, int ind) {
	tree[v * 2 + 1][ind] += push[v][ind];
	tree[v * 2 + 2][ind] += push[v][ind];
	push[v * 2 + 1][ind] += push[v][ind];
	push[v * 2 + 2][ind] += push[v][ind];
	push[v][ind] = 0;
}

ll get(int v, int l, int r, int askl, int askr, int ind) {
	p(v, ind);
	if (l >= askr || r <= askl) {
		return INF;
	}

	if (l >= askl && r <= askr) {
		return tree[v][ind];
	}
	int mid = (l + r) / 2;
	ll q = get(v * 2 + 1, l, mid, askl, askr, ind), q2 = get(v * 2 + 2, mid, r, askl, askr, ind);
	return min(q, q2);
}

void upd(int v, int l, int r, int askl, int askr, int add, int ind) {
	p(v, ind);
	if (l >= askr || r <= askl) return;

	if (l >= askl && r <= askr) {
		tree[v][ind] += add;
		push[v][ind] += add;
		return;
	}

	int mid = (l + r) / 2;
	upd(v * 2 + 1, l, mid, askl, askr, add, ind);
	upd(v * 2 + 2, mid, r, askl, askr, add, ind);
	tree[v][ind] = min(tree[v * 2 + 1][ind], tree[v * 2 + 2][ind]);
}

signed main()
{
	fastInp;

	ll n, e, t;
	cin >> n >> e >> t;
	vector<ll> vec(n);

	for (int i = 0; i < n; i++) cin >> vec[i];

	vec.push_back(e);

	for (int i = n - 1; i >= 0; i--) {
		upd(0, 0, n + 1, i + 1, n + 1, (vec[i + 1] - vec[i]) * 1, 0);
		upd(0, 0, n + 1, i + 1, n + 1, (vec[i + 1] - vec[i]) * 3, 1);

		dp[i] = dp[i + 1] + (vec[i + 1] - vec[i]) + t;
		
		int l = i, r = n + 1;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			if ((vec[mid] - vec[i]) * 2 >= t) {
				r = mid;
			}
			else {
				l = mid;
			}
		}

		ll q = INF;
		if (i + 1 < r) q = get(0, 0, n + 1, i + 1, r, 0) + t;
		if (r < n + 1) q = min(q, get(0, 0, n + 1, r, n + 1, 1));

		dp[i] = min(dp[i], q);
		upd(0, 0, n + 1, i, i + 1, dp[i + 1] + (vec[i + 1] - vec[i]), 0);
		upd(0, 0, n + 1, i, i + 1, dp[i + 1] + (vec[i + 1] - vec[i]), 1);
	}

	cout << dp[0] + vec.front();

	return 0;
}

Measured memory_bytes: 37644
#include<iostream>
using namespace std;
int main() {
    long long n;  cin>>n;
    long long a[n];
    long long c=0;
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        if(a[i-1]>a[i]){
             c+=(a[i-1]-a[i]);
             a[i]=a[i-1];
        }
    }
    cout<<c;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
using ll=long long;using ull=unsigned ll;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPARR(i,v) for(int i=0;i<v.size();++i)
#define all(v) (v).begin(),(v).end()
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"":"im")<<"possible"<<endl
#define Poss(n) cout<<((n)?"P":"Imp")<<"ossible"<<endl
template<typename T>ostream&operator<<(ostream&o,const vector<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<typename T>ostream&operator<<(ostream&o,const set<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T,typename U>ostream&operator<<(ostream&o,const pair<T,U>&v){o<<v.first<<' '<<v.second;return o;}

int main(){
    int n,k;
    cin>>n>>k;
    vi x(k);
    cin>>x;
    sort(all(x));
    vi y(k-1);
    REP(i,k-1){
        y[i]=x[i+1]-x[i];
    }
    sort(all(y));
    //cerr<<y<<endl;
    ll ans=0;
    /*REP(i,k-1){
        ans+=y[i];
        if(i==k-n+1)break;
    }*/
    cout<<accumulate(y.begin(), y.begin()+min(max(0,k-n),k-1), 0)<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
using namespace std;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define mem(a,b) memset(a,b,sizeof a)

const  int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

typedef long long ll;
typedef long double ld;

int n, t;
int a[N];

int main()
{
	scanf("%d", &n);
	fo(i, 1, n)
	{
		sc(a[i]);
	}
	fo(i, 1, n)
	{
		if ((a[i] - a[i + 1] > 2 && i != n) || a[i] < a[i - 1])
		{
			puts("No");
			return 0;
		}
		else if(a[i]>a[i-1])
			a[i]--;	
	}
	puts("Yes");
	
}

Measured memory_bytes: 640
n = int(input())


row_a = [0]*(n+1)

t = list(map(int, input().split()) )
for ai in range(1,n+1):
    row_a[ai] += row_a[ai-1] + t[ai-1]

row_b = [0]*(n+1)
t = list(map(int, input().split()) )
for bi in range(1,n+1):
    row_b[bi] += row_b[bi-1] + t[bi-1]


#print(row_a)
#print(row_b)

ans = 0

if n == 1:
    ans = row_a[1]+row_b[1]
else:
    for i in range(1,n):
        t = row_a[i] + (row_b[n]-row_b[i-1])
        ans = max(t, ans)

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long
main(){
  int n,p,q,a=0,b=0;
  cin>>n>>q;
  while(--n){
    p=q;
    cin>>q;
    if(p>=q)a++;
    else a=0;
    b=max(b,a);
  }
  cout<<b;
}

Measured memory_bytes: 384
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<double> v(n);
        for(i = 0; i < n; i++){
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        double ans;
        ans = v[0] + v[1];
        ans /= 2;
        for(i = 2; i < n; i++){
            ans = (ans + v[i]) / 2;
        }
        cout <<fixed << setprecision(12) << ans;
    }
    return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for (int i = x;i < n;++i)

int main() {
	int n, l, p;
	scanf("%d%d%d", &n, &l, &p);
	f(i, 1, n) {
		int t;
		scanf("%d", &t);
		if (t + p >= l) {
			printf("Possible\n");
			f(j, 1, i)printf("%d\n", j);
			for (int j = n - 1; j > i; --j) printf("%d\n", j);
			printf("%d\n", i);
			return 0;
		}
		p = t;
	}
	printf("Impossible\n");
}

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

using namespace std;

#define loop(i, a, b, inc) for(int i = a; i < (b); i += inc)
#define rep(i, n) loop(i, 0, n, 1)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	int k;
	cin >> k;
	int s = 0;
	loop(a, 1, k+1, 1)
		loop(b, 1, k+1, 1)
			loop(c, 1, k+1, 1)
				s += __gcd(a, __gcd(b, c));
	cout << s << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
using namespace std;

int main(){
  int sx, sy, tx, ty;
  string ans;
  cin >>sx >> sy >> tx >> ty;

  int dx = tx - sx;
  int dy = ty - sy;

  for(int i = 0; i < dy; i++){
    ans.push_back('U');
  }
  for(int i = 0; i < dx; i++){
    ans.push_back('R');
  }
  for(int i = 0; i < dy; i++){
    ans.push_back('D');
  }
  for(int i = 0; i < dx+1; i++){
    ans.push_back('L');
  }
  for(int i =0; i < dy+1; i++){
    ans.push_back('U');
  }
  for(int i=0; i < dx+1; i++){
    ans.push_back('R');
  }
  ans.push_back('D');
  ans.push_back('R');
  for(int i = 0; i < dy+1; i++){
    ans.push_back('D');
  }
  for(int i = 0; i < dx+1; i++){
    ans.push_back('L');
  }
  ans.push_back('U');

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


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

string map_rates(int rate){
    string color;
    if (1 <= rate && rate <=399){
        color = "grey";
    } else if (400 <= rate && rate <= 799){
        color = "brown";
    } else if (800 <= rate && rate <= 1199){
        color = "green";
    } else if (1200 <= rate && rate <= 1599){
        color = "light_blue";
    } else if (1600 <= rate && rate <= 1999){
        color = "blue";
    } else if (2000 <= rate && rate <= 2399){
        color = "yellow";
    } else if (2400 <= rate && rate <= 2799){
        color = "orange";
    } else if (2800 <= rate && rate <= 3199){
        color = "red";
    } else{
        color = "sp";
    }
    return color;
}

map<string, int> counter(vector<string> colors){
    map<string, int> color_frequency;
    for (auto &c : colors){
        color_frequency[c] += 1;
    }
    return color_frequency;
}


int main(){
    int n;
    cin >> n;
    vector<int> rates(n);
    for (int i=0;i<n;i++){
        cin >> rates[i];
    }

    vector<string> colors(n);
    for (int i=0;i<n;i++){
        colors[i] = map_rates(rates[i]);
    }

    auto color_frequency = counter(colors);

    int acc = 0;
    for (auto& item: color_frequency){
        if (item.first != "sp"){
            acc += 1;
        }
    }
    cout << max(acc, 1) << " " << acc + color_frequency["sp"] << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;
typedef pair<int,int> P;

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int main()
{

    int N;
    cin >> N;

    vector<int> A;

    int a;
    REP(i,N){
    	cin >> a;
    	A.push_back(a);
    }
    sort(ALL(A));

    vector<int> minus;
    vector<int> plus;

    //minus.push_back(A[0]);
    //plus.push_back(A[N-1]);

    FOR(i,1,N-1){
    	if(A[i]>0) plus.push_back(A[i]);
    	else minus.push_back(A[i]);
    }

    lint ans=0;
    ans += A[N-1] - A[0];
    for(auto i:minus) ans -= i;
    for(auto i:plus) ans += i;


    cout << ans << endl;

    int tmp=A[0];
    for(auto i:plus){
    	cout << tmp << " " << i << endl;
    	tmp -= i;
    }

    lint tmp2=A[N-1];
    for(auto i:minus){
    	cout << tmp2 << " " << i << endl;
    	tmp2 -= i;
    }
    cout << tmp2 << " " << tmp << endl;


}


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

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a*a <= n; a++) {
    if (n%a != 0) continue;
    ll ex = 0;
    while (n%a == 0) {
      ex++;
      n /= a;
    }
    res.push_back({a,ex});
  }
  if (n != 1) res.push_back({n,1});
  return res;
}

int main() {
    ll n;
    cin >> n;
    auto res = prime_factorize(n);
    ll ans = 0;
    for (auto p : res) {
      ll num = p.second;
      for (ll a = 1; num-a >= 0; a++) {
        ans++;
        num -= a;
      }
    }
    cout << ans << endl;
    return 0;
}

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

/*==============変数宣言==============*/
int N;
const int M = 26;
int n;
int m = M;
const int def = 1000000;

int c[30];
int s[400][30];

void input(){
	scanf("%d", &N);
	n = N;

	for(int i = 0;i < M;i++) scanf("%d", &c[i]);

	for(int i = 0;i < N;i++)
		for(int j = 0;j < M;j++)
			scanf("%d", &s[i][j]);
	
	return;
}

/*================関数================*/
struct RandomNumberGenerator {
  mt19937 mt;

  RandomNumberGenerator() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}

  int operator()(int a, int b) { // [a, b)
    uniform_int_distribution< int > dist(a, b - 1);
    return dist(mt);
  }

  int operator()(int b) { // [0, b)
    return (*this)(0, b);
  }
};

struct Timer {
  chrono::high_resolution_clock::time_point st;

  Timer() { reset(); }

  void reset() {
    st = chrono::high_resolution_clock::now();
  }

  chrono::milliseconds::rep get() {
    auto ed = chrono::high_resolution_clock::now();
    return chrono::duration_cast< chrono::milliseconds >(ed - st).count();
  }
};

Timer timer;
RandomNumberGenerator rnd;
/*====================================*/



void init(){
	input();
	return;
}


void output(short ans[]){
	for(int i = 0;i < n;i++){
		printf("%d\n", ans[i]+1);
	}
}

int getScore(short a[]){
	int last[30] = {};
	int ans = 0;
	for(int i = 0;i < n;i++){
		ans += s[i][a[i]]; 
		last[a[i]] = i+1;
		for(int j = 0;j < M;j++){
			ans -= c[j] * ((i+1)-last[j]); 
		}
	}
	return ans;
}

int main(){
	init();

	short now[500];
	short ans[500]; 

	for(int i = 0;i < n;i++){
		ans[i] = now[i] = rnd(26); 
	}

	int ans_score = getScore(ans);

	const int fin = 1990;
	const double C = fin*1000.0;

	int now_time = 0;
	while((now_time = timer.get()) < fin){
		int idx = rnd(365);
		int old = now[idx];
		int next = rnd(26);
		now[idx] = next;
		int now_score = getScore(now);

		double r = rnd(100000)/100000.0;

		double line = (fin-now_time)/C; 

		if(ans_score <= now_score || line > r){
			ans[idx] = next;
			ans_score = now_score;
			//cerr << ans_score << endl;
		}else{
			now[idx] = old; 
		}
	}

	output(ans);
	//cerr << getScore(ans) << endl;

	return 0;
}

Measured memory_bytes: 3868
/**    epsileer 07 September 2019  23:21:33  **/    
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL,LL> PII;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define TEST int t = 1; while(t--) solve()

void solve(){
    int n,k; cin>>n>>k;
    string s; cin>>s;
    int ans = 0;
    for(int i=0;i<n-1;i++){
        if(s[i] == s[i+1])
            ans++;
    }
    cout << min(n-1, ans + 2*k);
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST;
return 0;
}

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

int N, M;

int main() {
    cin >> N >> M;
    vector<int> WA(N + 1);
    int cnt = 0, pty = 0;
    vector<bool> AC(N + 1);
    int p; string S;
    for (int i = 0; i < M; i++) {
        cin >> p >> S;
        if (S == "AC") {
            if (!AC[p]) cnt++;
            AC[p] = true;
        } else if (!AC[p]) {
            WA[p]++;
        }
    }
    for (int i = 1; i < N + 1; i++) {
        if (AC[i]) {
            pty += WA[i];
        }
    }
    cout << cnt << ' ' << pty << endl;
}


Measured memory_bytes: 640
// https://atcoder.jp/contests/abc106/tasks/abc106_b

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
const long long INF = 1LL << 60;
// map<int,int> mp;

bool solve(int n) {
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    // cout << n % i << endl;
    if (n % i == 0) cnt += 1;
  }

  if (cnt == 8 && n % 2 == 1) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int N, ans = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    if (solve(i) == true) ans += 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3576
n = (int)(input())
cost = []
s = []
freq = []
for i in range(n-1):
  a, b, c = (list)(map(int, input().split()))
  cost.append(a)
  s.append(b)
  freq.append(c)


def t(num):
  time = 0
  for j in range(num, n-1):
    if time < s[j]:
      #print("not staredt", time)
      time = s[j]
      #print("start", time)
    elif time % freq[j]:
      #print("wait", time)
      time = wait_next(time, freq[j])
      #print("stae", time)
    time += cost[j]
    #print("time", time)

  return time


def wait_next(now, freq):
  while(1):
    if not now % freq:
      break
    now += 1
  return now


for i in range(n):
  print(t(i))


Measured memory_bytes: 3188
/*
--> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED,
	DON'T ADJUST THE GOALS,
	ADJUST THE ACTION STEPS.

--> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU UNCOMFORTABLE.

--> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT.
*/

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(all(x))
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef pair< int, int >	pii;
typedef pair< ll, ll >		pl;
typedef vector< int >		vi;
typedef vector< ll >		vl;
typedef vector< pii >		vpii;
typedef vector< pl >		vpl;
typedef vector< vi >		vvi;
typedef vector< vl >		vvl;

const int MOD = 1e9 + 7;

ll power(ll a, ll b)
{
	ll ans = 1;

	while (b > 0)
	{
		if (b & 1)
			ans *= a;
		a = a * a;
		b >>= 1;
	}
	return ans;
}

ll powm(ll a, ll b)
{
	a %= MOD;
	ll ans = 1;

	while (b > 0)
	{
		if (b & 1)
			ans = (ans * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return ans;
}

void IO()
{
	#ifndef ONLINE_JUDGE
		freopen("Input.txt", "r", stdin);
		freopen("Output.txt", "w", stdout);
	#endif
}

//================================

int main()
{
	FAST;

	ll n;
	cin >> n;

	ll ans = 0;
	for (ll i = 1; i <= n; i++)
		for (ll j = 1; j <= n; j++)
			for (ll k = 1; k <= n; k++)
				ans += __gcd(i, __gcd(j, k));
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    char a, b;
    cin >> a >> b;
    if (a == 'H')
    {
        if (b == 'H')
        {
            cout << 'H';
        }
        else
        {
            cout << 'D';
        }
    }
    else
    {

        if (b == 'H')
        {
            cout << 'D';
        }
        else
        {
            cout << 'H';
        }
    }
}

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

int main(){
  ll l, r;
  cin >> l >> r;
  ll ans = 1e9;
  ll a = min(r, l+2019);
  for(ll i = l; i <= a; i++){
    for(ll j = i+1; j <= a; j++){
      ll b = (i*j) % 2019;
      ans = min(ans, b);
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int s, n, cnt = 0;

void solve(int x, int y, int sum){
	if(y == n){
		if(sum == s){
			++cnt;
		}
		return ;
	}
	if(x > 9) return ;
	solve(x + 1, y + 1, sum + x);
	solve(x + 1, y, sum);
}

int main(){
	while(1){
		cin >> n >> s;
		if(n == 0 && s == 0) break;
		cnt = 0;
		solve(0, 0, 0);
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    ll sum = 0;
    rep(i, n) sum += a[i];
    if (sum < k) {
        cout << n << "\n";
        return 0;
    }
    
    vector<vector<int>> dp1(n + 1, vector<int>(k, 0)), dp2(n + 1, vector<int>(k, 0));
    dp1[0][0] = 1;
    rep(i, n) rep(j, k) {
        if (not dp1[i][j]) continue;
        dp1[i + 1][j] = 1;
        if (j + a[i] < k) dp1[i + 1][j + a[i]] = 1;
    }
    dp2[n][0] = 1;
    for (int i = n; i > 0; --i) rep(j, k) {
        if (not dp2[i][j]) continue;
        dp2[i - 1][j] = 1;
        if (j + a[i - 1] < k) dp2[i - 1][j + a[i - 1]] = 1;
    }
    
    int ans = n;
    rep(i, n) {
        bool need = false;
        int m = k - 1;
        rep(j, k) {
            if (not dp1[i][j]) continue;
            chmin(m, k - j - 1);
            while (m >= 0) {
                if (dp2[i + 1][m]) break;
                --m;
            }
            if (m < 0) break;
            if (j + m >= k - a[i]) need = true;
        }
        if (need) --ans;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 198948
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>a>>b>>x;

    int ans = (x/a)*b;

    cout<<ans<<"\n";

    return 0;
}


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

const int INF = 1e9 + 5;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	vector<int> h(n);
	for (int& x : h) {
		scanf("%d", &x);
	}
	vector<int> dp(n, INF);
	dp[0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j : {i + 1, i + 2}) {
			if (j < n) {
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
			}
		}
	}
	printf("%d\n", dp[n - 1]);
}

Measured memory_bytes: 4068
read=lambda :list(map(int,input().split()))
n=int(input())
t,a=read(),read()
mod=10**9+7
t=[(i!=j,i) for i,j in zip(t,[0]+t)]
a=[(i!=j,i) for i,j in zip(a,(a+[0])[1:])]

ans=1
for p,q in zip(t,a):
  if(p[0]):
    if(q[0]):
      if(p[1]!=q[1]):
        print(0)
        exit()  
    elif(q[1]<p[1]):
      print(0)
      exit()
  elif(q[0]):
    if(p[1]<q[1]):
      print(0)
      exit()
  else:
	  ans=ans*min(p[1],q[1])%mod
print(ans) 


Measured memory_bytes: 26304