akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class CFlipFlipAndFlip {
public:
    void solve(std::istream& in, std::ostream& out) {
        ll N, M;
        in >> N >> M;
        ll answer = abs((N-2) * (M-2));
        out << answer << "\n";
    }
};


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


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,m,x,i,s=0,t=0;
	scanf("%d %d %d",&n,&m,&x);
	for(i=0;i<m;i++){
		int b;
		scanf("%d",&b);
		if(b<x){s++;}
		else{t++;}
	}
	printf("%d",s<t?s:t);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> v(h, vector<char> (w));
  
  for (int i=0; i<h; i++){
    for (int j=0; j<w; j++){
      cin >> v[i][j];
    }
  }
  
 
  set<int> sh, sw;
  for (int i=0; i<h; i++){
    for (int j=0; j<w; j++){
      if (v[i][j] == '#'){
        sh.insert(i);
      }
    }
  }
  
  
  for (int i=0; i<w; i++){
    for (int j=0; j<h; j++){
      if (v[j][i] == '#'){
        sw.insert(i);
      }
    }
  }
  
  
  for (int i=0; i<h; i++){
    bool kaigyou = false;
    if(sh.count(i) == 0){
      continue;
    }
    for (int j=0; j<w; j++){
      if (sw.count(j) != 0){
        cout << v[i][j];
        kaigyou = true;
      }  
    }
    if(kaigyou){
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;
    vector<P> points(N);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        points[i] = P(x, y);
    }
    sort(points.begin(), points.end());

    map<P, int> m;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            m[P(points[i].first - points[j].first, points[i].second - points[j].second)]++;
        }
    }

    int mx = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
        mx = max(mx, it->second);
    }

    cout << N - mx << endl;
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nmk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nmk[0];
        var m = nmk[1];
        var k = nmk[2];
        UnionFind uf = new UnionFind(n);
        int[] member = new int[n];
        for (int i = 0; i < m; i++)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            uf.TryUnite(ab[0], ab[1]);
            member[ab[0]]--;
            member[ab[1]]--;
        }
        for (int i = 0; i < k; i++)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            if (uf.Find(ab[0]) != uf.Find(ab[1])) continue;
            member[ab[0]]--;
            member[ab[1]]--;
        }

        Console.WriteLine(string.Join(" ", Enumerable.Range(0, n).Select(x => uf.GetSize(x) + member[x] - 1)));
    }
}


class UnionFind
{
    public int Size { get; private set; }
    public int GroupCount { get; private set; }
    public IEnumerable<int> AllRepresents => Parent.Where((x, y) => x == y);
    int[] Sizes;
    int[] Parent;
    public UnionFind(int count)
    {
        Size = count;
        GroupCount = count;
        Parent = new int[count];
        Sizes = new int[count];
        for (int i = 0; i < count; i++) Sizes[Parent[i] = i] = 1;
    }
    public bool TryUnite(int x, int y)
    {
        int xp = Find(x);
        int yp = Find(y);
        if (yp == xp) return false;
        if (Sizes[xp] < Sizes[yp]) { var tmp = xp; xp = yp; yp = tmp; }
        GroupCount--;
        Parent[yp] = xp;
        Sizes[xp] += Sizes[yp];
        return true;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int GetSize(int x) => Sizes[Find(x)];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int Find(int x)
    {
        while (x != Parent[x]) x = (Parent[x] = Parent[Parent[x]]);
        return x;
    }
}


Measured memory_bytes: 22036
import java.util.*;
class Main
{
	public static void main(String arg[])
	{
	Scanner sc = new Scanner(System.in);
	int n,r;
	try
	{
	n=sc.nextInt();
	r=sc.nextInt();
	
	if(n<10)
	{
		int t=100*(10-n);
		int d=r+t;
		System.out.println(d);
	}
	else
	{
		System.out.println(r);
	}
	}
	catch(InputMismatchException e)
	{
		System.out.println("enter numeric value");
	}
	}
}

Measured memory_bytes: 22604
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		if (a + b == c + d) {
			System.out.println("Balanced");
		} else if (a + b > c + d) {
			System.out.println("Left");
		} else {
			System.out.println("Right");
		}
	}
}

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

int main() {
    int N,K;
    cin>>N>>K;
    
    vector<bool>vec(N);
    for(int i=0; i<K; i++){
        int d;
        cin>>d;
        vector<int>a(d);
    for(int j=0; j<d; j++){
    cin>>a.at(j);
    int y=a.at(j);
    vec.at(y-1)=true;
    }
    }
    int count=0;
    for(int i=0; i<N; i++){
    if(vec.at(i)==false){
    count++;
    }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define N 100005
using namespace std;
vector<int> g[N];
int n,m,a1,a2,a3;//a1 -- a single point ; a2 -- a binary graph ;a3 -- else
int vis[N];

bool DFS(int u,int col){
    vis[u]=col;bool ret=true;
    for(int i:g[u])
        if(vis[i]==0) ret&=DFS(i,col^1);
        else if(vis[i]==vis[u]) ret=false;
    return ret;
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1,f,t;i<=m;i++)
        scanf("%d%d",&f,&t),g[f].push_back(t),g[t].push_back(f);
    for(int i=1;i<=n;i++)
        if(vis[i]==0)
            if(g[i].size()==0) a1++;
            else if(DFS(i,2)) a2++;
            else a3++;
    cout<<1LL*a1*a1+a1*1LL*(n-a1)*2+(a2+a3)*1LL*(a2+a3)+a2*1LL*a2<<endl;
    return 0;
}

Measured memory_bytes: 9984
#include<stdio.h>

int main()
{
	int a,b,c;
	int d;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);

	if(a < b)
	{
		d = a;
		a = b;
		b = d;
	}
    if(a < c)
    {
		d = a;
		a = c;
		c = d;
	}

	if(b < c)
	{
		d = b;
		b = c;
		c = d;
	}
    
    printf("%d %d %d\n",c,b,a);
}



Measured memory_bytes: 2076
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++) 
        cin >> s[i];

    int count = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '.')
                count++;
        }
    }

    vector<vector<int> > dist(H, vector<int>(W, -1));
    queue<pair<int,int> > que;

    dist[0][0] = 0;
    que.push(pair<int, int>(0, 0));

    while (!que.empty()) {
        pair<int, int> v = que.front();
        for (int i = 0; i < 4; i++) {
            int nx = v.first + dx[i];
            int ny = v.second + dy[i];

            if (nx < 0 || H <= nx || ny < 0 || W <= ny)
                continue;
            if (s[nx][ny] == '#' || dist[nx][ny] != -1)
                continue;
            
            dist[nx][ny] = dist[v.first][v.second] + 1;
            que.push(pair<int, int>(nx, ny));
        }
        que.pop();
    }


    cout << ((dist[H-1][W-1] >= 0) ? count - dist[H-1][W-1] - 1 : -1)<< endl;

    return 0; 
}

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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef set<ll> si;
typedef map<string, ll> msi;
#define hell 1000000007
#define MAX 1000000000
#define max_int 1000000
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define pi 3.1415926536
#define r0 return 0
#define rep(i,a,b) for(ll i = a;i<b;i++)

// void solve() 
// {


//     return;
// }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    // int t=1;
    // cin>>t;
    // while(t--)
    // {
    //     int n;
    //     cin>>n;

    //     //solve();     
    // }
    int s,w;
    cin>>s>>w;
    if(s>w)
        cout<<"safe";
    else cout<<"unsafe";

}
 

Measured memory_bytes: 3656
s = input()
first_white = 0
first_brack = 0
for si in s[::2]:
    if si == '0':
        first_brack += 1
    else:
        first_white += 1
for si in s[1::2]:
    if si == '0':
        first_white += 1
    else:
        first_brack += 1
print(min(first_brack, first_white))


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec A(N, 0);
    REP(i,0,M) {
        ll a, b;
        cin >> a >> b;
        ++A[a-1];
        ++A[b-1];
    }

    REP(i,0,N) PR(A[i]);

    return 0;
}

/*



*/

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

int main(){
  string S;
  int num = 1e9+7;
  cin >> S;
  for(int i=0;i<S.size()-2;++i){
    string c = "";
    for(int j=i;j<i+3;++j){
      c += S.at(j);
    }
    num = min(num,abs(753-stoi(c)));
  }
  cout << num << endl;
}


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

#define int long long
#define fi first
#define se second
#define pb push_back

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

int n, a[105][2], dp[105][2];

signed main(){
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i][0];
	for(int i = 1; i <= n; i++) cin >> a[i][1];
	for(int i = 1; i <= n; i++){
		dp[i][0] = dp[i - 1][0] + a[i][0];
		dp[i][1] = max(dp[i][0], dp[i - 1][1]) + a[i][1];
	}
	cout << dp[n][1];
}


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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());

  int a_max = A.at(N - 1);
  vector<int> range(a_max + 1, 0);

  for (int i = 0; i < N; i++) {
    int a = A.at(i);
    range.at(a)++;

    // 2つ以上の約数が存在する場合
    if (range.at(a) >= 2) {
      continue;
    }

    for (int j = a * 2; j <= a_max; j = j + a) {
      range.at(j)++;
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int a = A.at(i);
    if (range.at(a) == 1) {
      ans++;
    }
  }

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

Measured memory_bytes: 7928
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    let mut v = vec![];
    for _ in 0..5 {
        let a: usize = read!();
        v.push(a);
    }

    for (i, &u) in v.iter().enumerate() {
        if u == 0 {
            println!("{}", i + 1);
        }
    }
}


Measured memory_bytes: 2124
N, K = map(int, input().split())
A = list(map(int, input().split()))

first = [0] * (N+1)
follow_idx = [-1] * (N+1)
d = {}
for i, a in enumerate(A[::-1]):
  j = N - 1 - i
  if a in d:
    idx = d[a][-1]
    d[a].append(j)
    if first[idx + 1] < 0:
      first[j] = first[idx + 1]
      follow_idx[j] = follow_idx[idx + 1]
    else:
      first[j] = -first[idx + 1]
      follow_idx[j] = idx + 1
  else:
    first[j] = a
    d[a] = [j]
    follow_idx[j] = j + 1


indices = [-1]
s0 = first[0]
if s0 >= 0:
  indices.append(0)
else:
  s0 = -s0
  indices.append(follow_idx[0])
    
if s0 == 0:
  print('')
  quit()

d2 = {0:0, s0:1}
for k in range(2, K+1):
  idx = d[s0][-1] + 1
  s0 = first[idx]
  if s0 >= 0:
    indices.append(idx)
  else:
    s0 = -s0
    indices.append(follow_idx[idx])
  if s0 in d2:
    break
  d2[s0] = k

if len(indices) < K:
  K = d2[s0] + (K - d2[s0]) % (k - d2[s0])

if K == 0:
  print('')
  quit()

ans = []
idx = indices[K]
while idx < N:
  s = first[idx]
  if s > 0:
    ans.append(s)
  idx = follow_idx[idx]

print(*ans)

Measured memory_bytes: 96252
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int ans0 = 0;
		int ans1 = 0;
		
		while(stdIn.hasNext()) {
			String tmp = stdIn.next();
			String[] tmp2 = tmp.split(",");
			
			int a = Integer.parseInt(tmp2[0]);
			int b = Integer.parseInt(tmp2[1]);
			int c = Integer.parseInt(tmp2[2]);
			
			if(a * a + b * b == c * c) {
				ans0++;
			}
			else {
				if(a == b) {
					ans1++;
				}
			}
		}
		System.out.println(ans0 + "\n"+ ans1);

	}

}

Measured memory_bytes: 17132
/* AOJ 0220 Binary Digit A Doctor Loved */

#include <iostream>

using namespace std;

void print_binary_digits(double x);

int
main()
{
    for (;;) {
        double x;

        cin >> x;
        if (x < 0) break;

        print_binary_digits(x);
    }

    return 0;
}

void
print_binary_digits(double x)
{
    int x_i = (int)x;
    double x_f = x - x_i;
    int digits[12] = {0};
    double b = 0.5;
    int i;

    try {
        // 整数部分
        for (i = 0; i < 8 && x_i > 0; i++) {
            digits[7 - i] = x_i & 1;
            x_i >>= 1;
        }
        if (x_i) throw 0;

        // 小数部分
        for (i = 0; i < 4 && x_f > 0; i++) {
            if (x_f >= b) {
                digits[8 + i] = 1;
                x_f -= b;
            }

            b /= 2;
        }
        if (x_f) throw 0;

        for (i = 0; i < 8; i++)
            cout << digits[i];
        cout << '.';
        for (i = 8; i < 12; i++)
            cout << digits[i];

        cout << endl;
    } catch (...) {
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 1292
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int now = 0;
        int ans = 1;
        for(int i = 0; i < n; i++){
            now += sc.nextInt();
            if(now > x){
                break;
            }else{
                ans++;
            }
        }
        System.out.println(ans);
    }
}

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

#define ll long long int
#define PI acos(-1.0)
#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

ll ar[500009],br[500009],cr[500009];
map<ll,ll>mp,mp1;
vector<ll>v;
string s,d;

int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    double q,w,e,r;
    cin>>q;
    r=(2*q*PI);
    cout<<fixed<<setprecision(6)<<r<<endl;
}



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

int main() {
	long big = 1e6;
	bool isPrime[big+1];
	for(long i=0;i<=big;++i){
		isPrime[i] = true;
	}
	isPrime[0] = false;
	isPrime[1] = false;
	for(long i=2;i*i<=big;++i){
		if(isPrime[i]){
			for(long j=2;i*j<=big;++j){
				isPrime[i*j] = false;
			}
		}
	}
	long X;
	cin>>X;
	long ans;
	for(long i=X;i<big;++i){
		if(isPrime[i]){
			ans = i;
			break;
		}
	}
	cout<<ans<<endl;
}


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

int main(){
    vector<int> dir({0, 1, 0, -1, 0});
    size_t H, W;
    cin >> H >> W;
    vector<vector<short>> dist(H, vector<short>(W, 9999));
    queue<pair<int, int>> q;
    for(size_t i = 0; i < H; ++i){
        string s;
        cin >> s;
        for(size_t j = 0; j < W; ++j){
            if(s[j] & 1){
                dist[i][j] = 0;
                q.emplace(i, j);
            }
        }
    }
    while(!q.empty()){
        auto t = q.front();
        q.pop();
        auto d = dist[t.first][t.second];
        for(size_t i = 0; i < 4; ++i){
            auto x = t.first + dir[i], y = t.second + dir[i + 1];
            if(0 <= x && x < H && 0 <= y && y < W && dist[x][y] > d + 1){
                dist[x][y] = d + 1;
                q.emplace(x, y);
            }
        }
    }
    vector<short> mx;
    transform(dist.begin(), dist.end(), back_inserter(mx), [](auto a){return *max_element(a.begin(), a.end());});
    cout << *max_element(mx.begin(), mx.end()) << endl;
    return 0;
}

Measured memory_bytes: 10384
#include<iostream>
using namespace std;
int main()
{
	int x;
	cin>>x;
	int a=x/100;
	x%=100;
	if(a*5>=x)
	{
		cout<<"1"<<endl;
	}
	else
	{
		cout<<"0"<<endl;
	}
	return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int N;
ll A, B;
vector<ll> h(100001);

bool enough(ll t)
{
  ll add = 0;
  REP(i, N)
  {
    if (B * t < h[i])
      add += ((h[i] - B * t) + (A - B) - 1) / (A - B);
  }
  return (add <= t);
}

ll meguru()
{
  ll ng = 0, ok = 1e9;
  while (1 < abs(ok - ng))
  {
    ll mid = (ok + ng) / 2;
    if (enough(mid))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

int main()
{
  cin >> N >> A >> B;
  REP(i, N)
  cin >> h[i];
  cout << meguru() << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, K;
    cin >> N >> K;
    int L=0;

    for (int i=0; i<N; i++){
        int xi;
        cin >> xi;
        L += 2*min(xi, K-xi);
    }
    cout << L << endl;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from heapq import heappop, heappush

t = readint()

ans = []

for _ in range(t):
    n,a,b,c,d = readints()
    x = [0,0,a,b,0,c]
    h = [(0,n)]
    dct = dict()
    while 1:
        cost,num = heappop(h)
        if num == 1:
            break
        for i in (2,3,5):
            new_cost = cost + min(x[i]+(num%i)*d,(num-num//i)*d)
            new_num = num//i
            if new_num not in dct or new_cost<dct[new_num]:
                heappush(h,(new_cost,new_num))
                dct[new_num] = new_cost
            new_cost = cost + min(x[i]+(i-num%i)*d,(num-num//i-1)*d)
            new_num = num//i+1
            if new_num not in dct or new_cost<dct[new_num]:
                heappush(h,(new_cost,new_num))
                dct[new_num] = new_cost

    ans.append(cost+d)

printrows(ans)

Measured memory_bytes: 78836
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n" // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n)             \
	for (int i = 0; i < (n); i++) \
		cin >> (c)[i];
#define exit_message(s) return 0 * printf(s)
#define show(c)           \
	for (auto i : (c))      \
		cout << i << " "; \
	cout << "\n";
#define display(c, n)           \
	for (int i = 0; i < (n); i++) \
		cout << (c)[i] << " ";    \
	cout << "\n";
#define forl(i, a, n) for (int (i) = (a); (i) < (n); (i)++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;
const int N = 100 + 5;

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}

int n, w;
const int W = 1e5 + 5;
pr p[N];
ll cache[N][W];

ll find(int idx, int w)
{
	if (idx >= n)
		return 0;
	ll &memo = cache[idx][w];
	if (memo != -1)
		return memo;
	memo = find(idx + 1, w);
	if (w >= p[idx].ff)
		memo = max(memo, p[idx].ss + find(idx + 1, w - p[idx].ff));
	return memo;
}

int32_t main()
{
#ifdef FASTIO
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	memset(cache, -1, sizeof cache);

	cin >> n >> w;
	forl(i, 0, n)
	{
		cin >> p[i].ff >> p[i].ss;
	}
	
	ll answer = find(0, w);

	cout << answer << "\n";

	return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c ;
  int d=max(a,max(b,c));
  if(d==a){
    cout << b*c/2 << endl;
  }
  if(d==b){
    cout << a*c/2 << endl;
  }
  if(d==c){
    cout << a*b/2 << endl;
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#import sys
#import copy
#import collections
#from bisect import bisect_left
#from bisect import bisect_right
#from collections import defaultdict
#from heapq import heappop, heappush
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
#import math

def main():
	N, K = map(int, input().split(" "))
	A = input().split(" ")
	A = [int(s) for s in A]
	
	DP = [100000000000000000000000000000000 for _ in range(N)]
	DP[0] = 0
	
	for i, val in enumerate(A):
		if i == 0:
			continue
		tmp = 100000000000000000000000000000000
		
		for j in range(K):
			index = j+1
			if i >= index:
				tmp1 = DP[i-index] + abs(A[i-index] - val)
				tmp = min(tmp, tmp1)
			else:
				break
		DP[i] = min(DP[i], tmp)
		
	#print(DP)
	print(DP[N-1])
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 55904
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VB=vector<bool>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}


void Main()
{
	ll x,n,m,l; ll res=0;
	string s,t,u; string sres="No or NO";

	cin>>x>>n;
	VI a(n),b(n);
	rep(i, n) cin >> a[i];
	ll min=10000;
	for(ll i=-101;i<=101;i++){
		ll tmp=abs(x-i);
		bool has=false;
		rep(j,n) {
			if (i==a[j]) has = true;
		}
		if(!has){
			if(chmin(min,tmp)){
				res=i;
			}
		}
	}
	cout << res << "\n";
	return;
}

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


Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<tuple>
#include<utility>
#include<cctype>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define enter "\n"

typedef long long ll;


int abc102_a(){
    //入力
    int n;
    cin >> n;

    //処理

    //出力
    if(n%2==0) cout << n <<enter;
    else cout << n*2 << enter;
    return 0;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

int N, M, Q;
int a[505][505];
int S[505][505];


int main() {
  
  scanf("%d %d %d", &N, &M, &Q);
  rep(i, 0, M) {
      int L, R;
      scanf("%d %d", &L, &R);
      a[L][R]++;
  }
  
  rep(i, 1, N+1) {
    rep(j, 1, N+1) {
      S[i][j] = S[i][j-1] + a[i][j];
    }
  }

  rep(i, 0, Q) {
      int p, q;
      int ans = 0;
      scanf("%d %d", &p, &q);
      rep(i, p, q+1) ans += S[i][q] - S[i][p-1];
      printf("%d\n", ans);
  }
  
  return 0;
}
 


Measured memory_bytes: 2944
#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>;

int main(){
  int n; cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  rep(i, n){
    if (s[i] == 'R') a[i] = 0;
    if (s[i] == 'G') a[i] = 1;
    if (s[i] == 'B') a[i] = 2;
  }
  vector<int> rgb(3);
  rep(i, n) rgb[a[i]]++;
  ll ans = 1;
  rep(i, 3) ans *= rgb[i];
  rep(j, n) rep(i, j){
    int k = j + j - i;
    if (k < n){
      if (a[i] == a[j]) continue;
      if (a[k] == a[j]) continue;
      if (a[k] == a[i]) continue;
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    double W,H,x,y;

    cin>>W>>H>>x>>y;

    cout<<fixed;
    cout<<setprecision(10);

    double area = (W*H)/2;
    double midx = W/2;
    double midy = H/2;

    if(midx == x && midy == y)
        cout<<area<<" "<<1<<endl;

    else
        cout<<area<<" "<<0<<endl;

    return 0;
}

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



int main(){
	
	int n;
	cin >> n;
	int t[n], x[n], y[n];
	for(int i = 0; i < n; i++)
	{
		cin >> t[i] >> x[i] >> y[i];
	}

	string ans="Yes";
	int bx = 0, by = 0, bt = 0;
	for(int i = 0; i < n; i++)
	{
		int num = abs(bx-x[i]) + abs(by-y[i]), numt = t[i] - bt;
		if(numt-num < 0 || (numt-num)%2!=0){
			ans = "No";
			break;
		}
		bx = x[i];
		by = y[i];
		bt = t[i];
	}
	
	
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int len=c%b;
	int flag=0;
	if(c%2==1&&a%2==0&&b%2==0)
	printf("NO\n");
	else
	{
		for(int i=a;i<=100000000;i+=a)
		{
			if(i%b==len){
			flag=1;
			break;
		}
		}
		if(flag==1)
		printf("YES\n");
		else
		printf("NO\n");
	}
}

Measured memory_bytes: 128
function Main(input) {
  input=input.split("\n");
  const N=input[0];
  var k=0;
  for(var i=0;i<N.length;i++){
    k=(k+(N[i]-0))%9;
  }
  console.log(k%9===0?'Yes':'No');
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


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

using namespace std;

int main(int argc, char** argv)
{
    std::string S;
    std::cin >> S;
    if (S == "SUN") cout << 7 << endl;
    else if (S == "MON") cout << 6 << endl;
    else if (S == "TUE") cout << 5 << endl;
    else if (S == "WED") cout << 4 << endl;
    else if (S == "THU") cout << 3 << endl;
    else if (S == "FRI") cout << 2 << endl;
    else if (S == "SAT") cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll mod = 1e9+7;

ll binpow(ll a,ll b){
    ll res  = 1;
    while(b){
        if(b&1) res*= a,res%= mod;
        a*= a,a%= mod;
        b/= 2;
    }
    return res;
}

main(){
    int n;cin>>n;
    if(n==1) cout<<"0";
    else if(n==2) cout<<"2";
    else{
        ll ans = binpow(10,n);
        ll eigth = binpow(8,n);
        ll nien = binpow(9,n);
        nien*= 2,nien%= mod;
        ans+= eigth,ans%=mod;
        ans-= nien,ans = (ans+mod)%mod;
        cout<<ans;
    }
}

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

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

    int N; cin >> N;
    int cake = 0;
    while (cake <= N) {
        if ((N - cake) % 7 == 0) {
            cout << "Yes\n";
            return 0;
        }
        cake += 4;
    }
    cout << "No\n";
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();

		Long N = fs.nextLong();

		Long sum = 0L;
		for(Long i = 1L; i <= N; i++) {
			if(i % 3 == 0 || i % 5 == 0) continue;
			sum += i;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 42108
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//* vamsicool007    You are never wrong to do the right thing    vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
bool isPrime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}
 
signed main()
{
    flash;
    int t=1;
    //cin>>t;
    while(t--)
    {
    	string s,t;
    	cin>>s>>t;
    	t.append(s);
    	cout<<t;
    }
	return 0;
}
  

Measured memory_bytes: 256
n = int(input())
ls = list(map(int,input().split(' ')))
pro=1
f=0
zero=0
for i in ls:
    if(i==0):
        zero=1
if(zero==1):
    print(0)
else:
    for i in ls:
        pro = pro*i
        if(pro > 1000000000000000000):
            print(-1)
            f=1
            break
    if(f==0 and pro<=1000000000000000000):
        print(pro)

Measured memory_bytes: 82548
package main

import (
	"fmt"
	//"sort"
	"math"
	"regexp"

)
func abs(x int)int{
	return int(math.Abs(float64(x)))
}

func max(x...int) int{
	var res int = x[0]
	for i:=1;i<len(x);i++{
		res = int(math.Min(float64(res),float64(x[i])))
	}
	return res
}

type Sortby []int
func (a Sortby) Len()int {return len(a)}
func (a Sortby) Swap(i,j int) {a[i],a[j] = a[j],a[i]}
func (a Sortby) Less(i,j int)bool { return abs(a[i]) > abs(a[j]) }


func reg(x,y string)bool {
	r:= regexp.MustCompile(x)
	return r.MatchString(y)
}

var N string
func main(){
	fmt.Scan(&N)
	
	for i:=0;i<len(N)-2;i++{
		if N[i] == N[i+1] && N[i+1] == N[i+2]{
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

Measured memory_bytes: 640
N, W = map(int, input().split())

w, v = [], []
for _ in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

# dp[in_n_items][below_w_weight] = max_value
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(W + 1):
        if j - w[i - 1] >= 0:
            if dp[i - 1][j - w[i - 1]] + v[i - 1] > dp[i - 1][j]:
                dp[i][j] = dp[i - 1][j - w[i - 1]] + v[i - 1]
            else:
                dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = dp[i - 1][j]
print(dp[N][W])


Measured memory_bytes: 171784
S = input()
divide = ["dream","dreamer","erase","eraser"]
S = S[::-1]
for i in range(len(divide)):
    divide[i]=divide[i][::-1]
can = True
i=0
while(i<len(S)):
    can2 = False
    for j in range(len(divide)):
        d = divide[j]
        if(S[i:i+len(d)]==d):
            can2 = True
            i += len(d)
    if(can2 != True):
        can=False
        break
if(can):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,m,s,t,p[100005],d[100005];
vector<P>g[100005];
int main(void){
    cin>>n>>m>>s>>t;
    s--;
    t--;
    for(int i=0;i<n;i++){
        scanf("%d",p+i);
        d[i]=100000001;
        if(i!=n-1){
            g[i+1].PB(P(i,0));
        }
    }
    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        b--;
        g[--a].PB(P(b,p[b]));
    }
    priority_queue<P,vector<P>,greater<P> >dik;
    dik.push(P(0,s));
    d[s]=0;
    while(!dik.empty()){
        int v=dik.top().S,c=dik.top().F;
        dik.pop();
        if(d[v]<c)continue;
        for(int i=0;i<g[v].size();i++){
            int u=g[v][i].F,q=g[v][i].S;
            if(d[u]>c+q){
                d[u]=c+q;
                dik.push(P(c+q,u));
            }
        }
    }
    cout<<d[t]<<endl;
}



Measured memory_bytes: 11392
#include <iostream>
#define ll long long
using namespace std;
const int N = 5009;
int n,k;
int p[N],c[N],sp[N],avail[N];
long long f[N][N];
int main(){
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++) cin >> c[i];
    for (int i = 1; i <= n; i++){
        memset(avail,0,sizeof(avail));
        int j = i , cnt = 0;
        while (avail[p[j]] == 0){
            cnt++;
            f[i][cnt] = f[i][cnt - 1] + c[p[j]];
            avail[p[j]] = 1;
            j = p[j];
        }
        sp[i] = cnt;
    }
    ll ans = -1e18;
    for (int i = 1; i <= n; i++){
        ll pos_max = 0 , val = -1e18;
         for (int j = 1; j <= min(sp[i],k); j++)
            if (f[i][j] > val){
                val = f[i][j];
                pos_max = j;
            }
        ans = max(ans,f[i][pos_max] + 1LL * ((k - pos_max)/sp[i]) * f[i][sp[i]]);
        ans = max(ans , 1LL * (k/sp[i]) * f[i][sp[i]] + f[i][k % sp[i]]);
        ans = max(ans,f[i][pos_max]);
    }
    cout << ans;
}

Measured memory_bytes: 198928
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
    
        if((b -a) == (c - b)){
            System.out.print("YES");
        }else{
            System.out.print("NO");
        }
    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 2000000000000000000 //1e16
 
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,pos,sum=0,flag=0,count=0;
    string S,T,U; 
    // int z;
    cin>>S;
    int ans=0;
    rep(i,0,3)
    {
        if(S[i]=='R') count++;
        ans=max(ans,count);
        if(S[i]=='S') count=0;
    }
    cout<<ans;
}


signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a;
  cin >> b;
  cin >> c;
  int result = c - (a - b);
  if(result <0) result = 0;
  cout << result << "\n";
  return 0;
}

Measured memory_bytes: 256
import numpy as np

def calculate_free_day(summer_days, need_days):
    return summer_days - np.sum(need_days)

if __name__ == "__main__":
    summer = int(input().split()[0])
    need = np.array([int(i) for i in input().split()])
    free_day = calculate_free_day(summer, need)

    if free_day >= 0:
        print(free_day)
    else:
        print(-1)

Measured memory_bytes: 27580
#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
INT n, m, L;
string s, t;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>s>>t;
    L = (m*n)/__gcd(m, n);
    n = L/n, m = L/m;
    for(int i = 0, ii = 0, j = 0, jj = 0 ; ii < s.size() and jj < t.size() ; )
    {
        if( i == j )
        {
            if( s[ii] != t[jj] ) return cout<<-1<<endl, 0;
            i+=n, j+=m;
            ii++, jj++;
        }
        if( i < j ) i+=n, ii++;
        else j+=m, jj++;
    }
    cout<<L<<endl;
}



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

using namespace std;
using ll = long long;
ll MOD = 1000000007;
int main() {
    ll n;
    cin >> n;
    ll a[n], sum[n];
    for(int i=0; i<n; i++) {
        cin >> a[i];
        (i > 0? (sum[i] = sum[i-1] + a[i])%=MOD: sum[i] = a[i]);
    }
    ll sumall = 0;
    for(int i=0; i<n-1; i++) {
        (sumall += (a[i]%MOD * (sum[n-1]-sum[i]+MOD)%MOD) % MOD ) %= MOD;
    }
    cout << sumall;
    return 0;
}


Measured memory_bytes: 6716
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n, m;
	cin >> n >> m;
	int ro[n+1] ={};
	int a, b;
	REP(i, m){
		cin >> a >> b;
		ro[a] ++;
		ro[b] ++;
	}
	REP1(i, n) cout << ro[i] << endl;
}

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

int main() {
    string s; cin >> s;
    char c[] = {'A', 'C', 'G', 'T'};
    int ans = 0, cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        int flag = 0;
        for (int j = 0; j < 4; j++) {
            if (s[i] == c[j]) flag = 1;
        }
        if (flag) cnt++;
        else { ans = max(ans, cnt); cnt = 0; }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
 
using namespace std;
 
static int f(const int* ws, int n, int P, int k) {
  int v = 0;
  int c = 0;
  int ntrack = 0;
  for (int i = 0; i < n; ++i) {
    if (c > 0 && P > 0 && c + ws[i] > P) {
      c = 0;
      ntrack++;
    }
    if (ntrack == k) {
      break;
    }
 
    if (c + ws[i] <= P) {
      c += ws[i];
      v++;
    }
  }
  return v;
}
 
int main() {
  int n, k;
 
  scanf("%d %d", &n, &k);
 
  //vector<int> ws(n);
  int ws[100000];
  int max = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &ws[i]);
    max += ws[i];
  }
 
  int min = 1;
  int mid = (min + max) / 2;
  while (min < max) {
    if (f(ws, n, mid, k) >= n) {
      max = mid;
    } else { // v < n
      min = mid + 1;
    }
    mid = (min + max) / 2;
  }
 
  printf("%d\n", max);
  return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
int main()
{
    ll n;
    cin>>n;
    cout<<(n+1)/2;
}


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

int main() {
    int N, L;
    std::cin >> N >> L;

    int all = 0;
    int min = 999;
    for (int i = 0; i < N; ++i) {
        all += (L + i);
        if (std::abs(min) > std::abs(L + i)) {
            min = L + i;
        }
    }

    std::printf("%d\n", all - min);

    return 0;
}


Measured memory_bytes: 256
# Aizu Problem NTL_1_E: Extended Euclid Algorithm
#
import itertools
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def extended_gcd(a, b):
    s, old_s = 0, 1
    t, old_t = 1, 0
    r, old_r = b, a
    while r != 0:
        q = old_r // r
        old_r, r = r, old_r - q * r
        old_s, s = s, old_s - q * s
        old_t, t = t, old_t - q * t
    return old_r, old_s, old_t

a, b = [int(_) for _ in input().split()]
g, x, y = extended_gcd(a, b)
print(x, y)

Measured memory_bytes: 7876