akhauriyash/Code-Regression huggingface dataset:
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let s: Vec<char> = it.next().unwrap().trim().chars().collect();
    let mut ans = 0;
    for i in 0..n {
        let s = &s[i..];
        let mut a = vec![0; s.len()];
        a[0] = s.len();
        let mut i = 1;
        let mut j = 0;
        while i < s.len() {
            while i + j < s.len() && s[j] == s[i + j] {
                j += 1;
            }
            a[i] = j;
            if j == 0 {
                i += 1;
                continue;
            }
            let mut k = 1;
            while i + k < s.len() && k + a[k] < j {
                a[i + k] = a[k];
                k += 1;
            }
            i += k;
            j -= k;
        }
        for j in 1..s.len() {
            let v = std::cmp::min(j, a[j]);
            ans = std::cmp::max(v, ans);
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4476
n, m = (int(i) for i in input().split())
swi = [[int(i) for i in input().split()[1:]] for _ in range(m)]
p = [int(i) for i in input().split()]

ans = 0
bits = [0]*n
for switch_state in range(2**n):
    swi_bin = str(bin(switch_state))
    for i in range(n):
        bits[i] = int(swi_bin[-1-i] if i < len(swi_bin) and swi_bin[-1-i] != 'b' else 0)
    for i in range(m):
        cnt_on = 0
        for s in swi[i]:
            cnt_on += bits[s-1]
        if cnt_on%2 != p[i]:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 41456
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int h,a,b,i,cnt;
	scanf("%d %d %d",&h,&a,&b);
	cnt=0;
	for(i=a;i<=b;i++)	{
		if(h%i==0)	cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


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

using Weight=int;

struct Edge{
    int from,to,rev;
    Weight cap;
};

using Edges=vector<Edge>;
using Graph=vector<Edges>;
Graph g;

void addEdge(int from,int to,Weight cap){
    g[from].push_back(Edge{from,to,int(g[to].size()),cap});
    g[to].push_back(Edge{to,from,int(g[from].size())-1,0});
}

const Weight INF=1e9;
Weight maxFlow(int s,int t){
    Weight res=0;
    Weight f;
    vector<int> used(g.size(),0);
    
    function<Weight(int,int)> dfs=[&](int v,Weight nf){
        if(v==t){
            return nf;
        }
        if(used[v]) return 0;
        used[v]=true;        
        for(int i=0;i<g[v].size();i++){
            Weight cap=g[v][i].cap;
            if(!cap) continue;
            Weight f=dfs(g[v][i].to,min(nf,cap));
            if(f){
                g[v][i].cap-=f;
                g[g[v][i].to][g[v][i].rev].cap+=f;
                return f;
            }
        }
        return 0;
    };

    while(f=dfs(s,INF)){
        res+=f;
        used.assign(g.size(),false);
    }
    return res;
}

int main(){
    int v,e;
    cin>>v>>e;
    g.assign(v,Edges());    
    for(int i=0;i<e;i++){
        int u,v;
        Weight c;
        cin>>u>>v>>c;
        addEdge(u,v,c);
    }
    cout<<maxFlow(0,v-1)<<endl;
    return 0;
}


Measured memory_bytes: 3204
#include <stdio.h>
#include <stdlib.h>

#define nMAX 44

int main() {
  int i, n, N[nMAX];

  scanf("%d", &n);
  if(n<0||nMAX<n) exit(8);
  
  for(i=0; i<=n; i++){
    if(i==0||i==1) N[i] = 1;
    else N[i] = N[i-1] +N[i-2];
    if(i==n) printf("%d\n", N[i]);
  }
    
  return 0;
}



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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

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

    vector<ll> h(n);
    rep(i, n) {
        cin >> h[i];
    }

    ll count = 0; ll maxi = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        /* code */
        if (i != n-1)
        {
            /* code */
            if (h[i] >= h[i+1])
            {
                /* code */
                count++;
                maxi = max(maxi, count);
            }
            else count = 0;
        }
    }
    
    printf("%d", maxi);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int N, A, B, C;
vector<int> l;
int dfs(int n, int a, int b, int c, int total) {
  if (n == N) {
    if (a == 0 || b == 0 || c == 0)
      return 1e9;
    return abs(A - a) + abs(B - b) + abs(C - c) + total - 30;
  }

  int x1 = dfs(n + 1, a + l[n], b, c, total + 10);
  int x2 = dfs(n + 1, a, b + l[n], c, total + 10);
  int x3 = dfs(n + 1, a, b, c + l[n], total + 10);
  int x4 = dfs(n + 1, a, b, c, total);
  return min({x1, x2, x3, x4});
}

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

  cin >> N >> A >> B >> C;
  l.resize(N);

  rep(i, 0, N) cin >> l[i];
  int ans = dfs(0, 0, 0, 0, 0);
  cout << ans << endl;
}


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

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

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

#define INF 1e16
#define mod 1000000007

ll N,M=100000;
vector<ll> g[200010];
bool vis[200010];
ll cnta,cntb;

void dfs(ll v){
  vis[v]=true;
  if(v>=M)cntb++;
  else cnta++;
  for(ll nv : g[v]){
    if(vis[nv])continue;
    dfs(nv);
  }
}

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

  cin>>N;
  rep(i,N){
    ll x,y;
    cin>>x>>y;
    x--;y--;
    g[x].push_back(y+M);
    g[y+M].push_back(x);
  }

  ll res=0;
  rep(i,2*M){
    if(vis[i])continue;
    cnta=cntb=0;
    dfs(i);
    res+=cnta*cntb;
  }
  cout<<res-N<<endl;

  return 0;
}


Measured memory_bytes: 10240
//run: g++ -std=c++14 -o run_sol.exe solution.cpp -DLOCAL_JUDGE
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define INFLL 1e17
#define PI 2*acos(0.0)
#define show(x) cout<< #x <<" is "<< x <<"\n"
using namespace std;

#define FS first
#define SC second
#define PB(t) push_back(t)
#define LEN(t) ((int)t.size())
#define ALL(t) t.begin(),t.end()
#define MP(x, y) make_pair((x), (y))
#define Fill(a,c) memset(&a, c, sizeof(a))
#define POPCOUNT __builtin_popcount

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;

int main() {
    #ifdef LOCAL_JUDGE
        freopen("../input.txt", "rt", stdin);
        freopen("../output.txt", "wt", stdout);
    #endif

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

    for (int n; cin >> n ;) {
        VI nums(n);

        for (auto& val : nums) {
            cin >> val;
        }

        VI dp(n, INF);
        dp[0] = 0;
        dp[1] = abs(nums[0] - nums[1]);
        for (int i = 2; i < n; i++) {
            dp[i] = min(dp[i - 2] + abs(nums[i] - nums[i - 2]), dp[i - 1] + abs(nums[i] - nums[i - 1]));
        }

        cout << dp[n - 1] << "\n";
    }

return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
#define lg 18
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t=0;
    boost;
    cin>>n;
    int arr[n+1],ans[n+1]={0};
    rep(i,1,n+1)cin>>arr[i];
    for(i=n;i>n/2;i--)
    {
        if(arr[i]) 
        {
            ans[i]=1;t++;
        }
    }
    for(i=n/2;i>=1;i--)
    {
        int sum=0;
        for(j=2*i;j<=n;j+=i)
        {
            sum+=ans[j];
        }
        if((arr[i]+sum)%2==1)
        {
            ans[i]=1;t++;
        }
    }
    cout<<t<<"\n";
    rep(i,1,n+1)if(ans[i]) cout<<i<<' ';

    return 0;
}



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

int main()
{
    int t,a,b,flag=0,s;
    cin>>t;
    cin>>a>>b;
    while(a<=b)
    {
        if(a%t==0)
        {
            flag=1;
            break;
        }
        else{
            a=a+1;
        }
    }
    if(flag == 1)
    {
        cout<<"OK"<<endl;
    }
    else{
        cout<<"NG"<<endl;
    }
    return 0;
}


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

using namespace std;


void solve(long long N){
    long long table[10][10] = {};
    for (int i = 1; i <= N; i++) {
        string a = to_string(i);
        table[a[0] - '0'][a[a.size()-1] - '0']++;
    }
    long long count = 0;
    for (int i = 1; i <= N; i++) {
        string a = to_string(i);
        count += table[a[a.size()-1] - '0'][a[0] - '0'];
    }
    cout << count << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <string>
#define int long long
using namespace std;
set<string>s; map<string, int>m;
int n, o, x; string st;
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> o >> st;
		if (o == 0) {
			cin >> x;
			s.insert(st);
			m[st] = x;
		}
		else if (o == 1) {
			if (s.count(st) == 0)cout << "0\n";
			else cout << m[st] << endl;
		}
		else if (s.count(st))s.erase(s.find(st));
	}
}


Measured memory_bytes: 37204
n = gets.to_i
s = gets.strip

count = 0
('000'..'999').each do |pass|
  if first = s.index(pass[0])
    if second = s.index(pass[1], first+1)
       count += 1 if s.index(pass[2], second+1)
    end
  end
end
puts count


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

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s = br.readLine();
    br.close();
    int p = s.length() - s.replaceAll("\\+","").length();
    int m = s.length() - p;
    System.out.println(p-m);
  }

}

Measured memory_bytes: 22996
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,a,b,pat[3]={};
  cin >> n >> a >> b;
  ll p[n];
  for(int i=0;i<n;i++){
    cin >> p[i];
    if(p[i]<=a){
      pat[0]++;
    }else if(p[i]<=b){
      pat[1]++;
    }else{
      pat[2]++;
    }
  }
  cout << min(pat[0],min(pat[1],pat[2]))<<endl;;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;


int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	string s;
	cin >> s;
	int res = 700;
	for (int i = 0; i < sz(s); i++)
		if (s[i] == 'o')
			res += 100;
	cout << res;
	return 0;

}

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

using namespace std;

//10進数1桁の文字を整数型にする
int toInt(char c){
	return c - '0';
}

int main(){
	const char buttonTable[10][5]={{},//確定ボタン　0
							{'.', ',' ,'!', '?', ' '},//1 (5)
							{'a','b','c'},//2 (3)
							{'d','e','f'},//3 (3)
							{'g','h','i'},//4 (3)
							{'j','k','l'},//5 (3)
							{'m','n','o'},//6 (3)
							{'p','q','r','s'},//7 (4)
							{'t','u','v'},//8 (3)
							{'w','x','y','z'}};//9(4)
	const int bsize[10] = {0,5,3,3,3,3,3,4,3,4};//ボタンの文字の種類
	
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		char command[1025];//char command[1025];
		cin >> command;
		int len = strlen(command);
		char result[76];//作ったメッセージ。サイズは[1,76) \0を忘れずに
		int idx = 0;//resultの入力場所
		int row=0;//ボタンを押した場所。表の行(row)
		int col=0;//同じボタンを押した回数。表の列(column)
		for(int j=0;j<len;j++){
			int button = toInt(command[j]);
			if(button == 0){
				if(row != 0){//文字を入力できる
					result[idx] = buttonTable[row][col];
					idx++;
					row = 0;
					col = 0;
				}
			}else if(button == row){
				col = (col+1)%bsize[button];
				
			}else{//文字を決定した次のコマンド
				row = button;
				//colの値は必ず0
			}
		}
		//result[idx] = '\0';
		//cout << idx << endl;
		//cout <<result << endl;
		for(int i=0;i<idx;i++){//文字列はidx文字ある
			cout << result[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>

using namespace std;

int min_sum(int a,int b,int min){
    if(a+b<min){
        return a+b;
    }else{
        return min;
    }

}

int main(){
    int P;
    int Q;
    int R;
    
    int min =5000;

    cin >>P>>Q>>R;
    min =min_sum(P,Q,min);
    min =min_sum(P,R,min);
    min =min_sum(Q,R,min);

    cout << min <<endl;

    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    cout << a.back() - a[0] << endl;
    return 0;
}

Measured memory_bytes: 3612
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdint>
#include <algorithm>
using namespace std;
using i64 = int64_t;

int main(void){
    i64 x, k, d, a = 0;
    cin >> x >> k >> d;
    if(x < 0) x = -x;
    if(k <= x/d) a = x-d*k;
    else if((k-(x-1)/d)%2 == 1) a = ((x+d-1)/d)*d-x;
    else a = x-(x-1)/d*d;
    cout << a << '\n';
    return 0;
}

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

using namespace std;

int main() {
    string S, T;

    cin >> S >> T;

    int A, B;

    cin >> A >> B;

    string U;

    cin >> U;

    if(S == U) {
        cout << A - 1 << " " << B << endl;
    } else {
        cout << A << " " << B - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int a = sc.nextInt();
      int p = n%500;
      if(a >= p) System.out.println("Yes");
      else System.out.println("No");
      sc.close();
    }
}

Measured memory_bytes: 21716
import numpy as np
n = int(input())
arr = input()

dp = [[0] * (n + 1) for _ in range(2)]
dp[1][0] = arr.count("R")

for i in range(1, n + 1):
    if arr[i - 1] == "W":
        dp[0][i] = dp[0][i - 1] + 1
        dp[1][i] = dp[1][i - 1]
    if arr[i - 1] == "R":
        dp[0][i] = dp[0][i - 1]
        dp[1][i] = dp[1][i - 1] - 1


dp = np.array(dp)

print(dp.min(axis=0).max())

Measured memory_bytes: 39488
s = int(input())
mod = 10**9 + 7
ans = 0
fact = [1 for i in range(2*s+1)]
for i in range(1,2*s):
    fact[i+1] = fact[i] * (i+1) % mod
for i in range(1,(s//3)+1):
    remain_ball = s - 3 * i
    ans += fact[remain_ball + i-1] * pow(fact[remain_ball],-1,mod) * pow(fact[i-1],-1,mod)
    ans %= mod
print(ans)

Measured memory_bytes: 8924
#include <stdio.h>
#include <string.h>

int main(void) {
	char w[1000];
	int i,a[26]={0},d,l;
	gets(w);
	l=strlen(w);
	for(i=0;i<l;i++){
		d=w[i]-'a';
		a[d]++;
	}
	for(i=0;i<26;i++){
		if(a[i]%2!=0){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n, ma, mb;
struct Node
{
	int a, b, c;
}a[50];
int f[510][510];

int cmp(Node a, Node b)
{
	return a.c < b.c;
}

int main()
{
	cin >> n >> ma >> mb;
	for(int i = 1; i <= n; i ++)
		cin >> a[i].a >> a[i].b >> a[i].c;
	for(int i = 0; i <= 500; i ++)
		for(int j = 0; j <= 500; j ++)
			f[i][j] = 1e8;
	for(int i = 1; i <= n; i ++)
		for(int j = 500; j >= a[i].a; j --)
			for(int k = 500; k >= a[i].b; k --)
			{
				if(j - a[i].a == 0 && k - a[i].b == 0){f[j][k] = min(f[j][k], a[i].c); break;}
				f[j][k] = min(f[j][k], f[j - a[i].a][k - a[i].b] + a[i].c);
			}
   // for(int i = 1; i <= 20; i ++, puts(""))
   //     for(int j = 1; j <= 20; j ++)
    //        cout << f[i][j] << " ";
	int mc = __gcd(ma, mb);
	int ans = 1e8;
	ma /= mc;
	mb /= mc;
	int i = 1;
	while(1)
	{
		int x = ma * i;
		int y = mb * i;
		if(x > 400 || y > 400) break;
		if(f[x][y]) ans = min(f[x][y], ans);
		i ++;
	}
	if(ans >= 1e8) cout << -1;
	else cout << ans;
	return 0;
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using indx = size_t;
#define endl '\n'

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int c5 = 0, c7 = 0;
    for (auto x : {a, b, c}) {
        if (x%5 == 0)
            c5++;
        else if (x%7 == 0)
            c7++;
    }
    if (c5 == 2 and c7 == 1)
        cout << "YES\n";
    else 
        cout << "NO\n";
}


Measured memory_bytes: 256
#include<cstdio>

int n;
bool jdg[55556];
int p[55];

int main() {
    scanf("%d", &n);
    for (int i = 2; i <= 55555; i++) jdg[i] = true;
    for (int i = 2, m = 0; i <= 55555; i++) {
        if (jdg[i]) {
            for (int j = 2 * i; j <= 55555; j += i) jdg[j] = false;
            if (i % 5 == 1) p[m++] = i;
            if (m == n) break;
        }
    }
    
    for (int i = 0; i < n - 1; i++) printf("%d ", p[i]);
    printf("%d\n", p[n - 1]);
    return 0;
}


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

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

	int count = 0;
	string str;
	cin >> str;
	vector<int> num(str.size());
	for (int i = 0; i < str.size(); ++i) {
		if (i == 0 && str[i] == 'R') {
			num[i]++;
		} else if (str[i] == 'R'){
			num[i] = num[i - 1] + 1;
		}
		count = max(count, num[i]);
	}
	cout << count << endl;
	return 0 ;
}

Measured memory_bytes: 3656
Var a,b,c:array[0..50] of integer;
    dp:array[0..50, 0..500, 0..500] of integer;
    n,ma,mb,i,ca,cb,ans:integer;

Function min(a,b:integer):integer;
    Begin
        if a < b then exit(a)
        else exit(b);
    End;

BEGIN
    readln(n,ma,mb);
    for i:=0 to n-1 do
        readln(a[i],b[i],c[i]);

    for i:=0 to n do
        for ca:=0 to 400 do
            for cb:=0 to 400 do
                dp[i,ca,cb] := maxint;  // maxint = 2^15 - 1 = 32767

    dp[0,0,0] := 0;
    for i:=0 to n-1 do
        for ca:=0 to 400 do
            for cb:=0 to 400 do
                if dp[i,ca,cb] <> maxint then
                    Begin
                        // khong lay
                        dp[i+1, ca, cb] := min(dp[i,ca,cb], dp[i+1, ca, cb]);
                        // lay
                        dp[i+1, ca+a[i], cb+b[i]] := min(dp[i,ca,cb] + c[i] , dp[i+1, ca+a[i], cb+b[i]]);
                    End;

    ans := maxint;
    for ca:=1 to 400 do
        for cb:=1 to 400 do
            if ma * cb = mb * ca then ans := min(ans, dp[n,ca,cb]);

    if ans = maxint then writeln(-1)
    else writeln(ans);
END.


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

int main(){
	int n;
	cin >> n;
	vector<int> d(n,0);
	int cnt=0;
	for(int i=0;i<n;i++){
		cin >> d[i];
		cnt++;
		for(int j=0;j<i;j++){
			if(d[i]==d[j]){
				cnt--;
				break;
			}
		}
	}	
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
/** 
 *                                                                   
 *   |    |                        ,   .              ,--.,--.,--.,--.
 *   |    |    ,---..    ,,---.    |   |,---..   .      -||  ||  ||  |
 *   |    |    |   | \  / |---'    `---'|   ||   |       ||  ||  ||  |
 *   `    `---'`---'  `'  `---'      |  `---'`---'    `--'`--'`--'`--'
 *                                   `                                
**/
#include <bits/stdc++.h>
using namespace std;

int n;
double p[3005], dp[3005][3005];

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

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}

	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			dp[i][j] = dp[i - 1][j] * (1 - p[i]);
			if (j) dp[i][j] += dp[i - 1][j - 1] * (p[i]);
		}
	}

	double ans = 0;
	for (int j = n / 2 + 1; j <= n; j++) {
		ans += dp[n][j];
	}

	cout << setprecision(10) << fixed << ans << '\n';

	return 0;
}

Measured memory_bytes: 69120
import java.util.*;
import java.lang.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
    	Scanner in = new Scanner(System.in);
		
		while(in.hasNext()) {
			int x = in.nextInt();
			int y = in.nextInt();
			
			int greatCD = 1; // 最大公約数
			int cd = 2;      // 公約数
			int min = x < y ? x : y;
			
			while(cd <= min) { 	
				for(cd = 2; cd <= min; cd++) {
					// cdはxとyの公約数か判断。
					if ((x % cd) == 0 && (y % cd) == 0) {
						//cdが公約数だったら、xとyをcdで割り、次の計算に備える。
						x = x / cd;
						y = y / cd;
						greatCD = greatCD * cd; // 算出した公約数を今まで求めた公約数の値に掛け合わせる
						min = min / cd;
						break;
					}
				}
			}
			
			// 最小公倍数は、最大公約数と最後に算出したxとyの値を掛け合わせることで算出できる。
			int lcd = greatCD * x * y;
			
	   		System.out.printf("%d %d\n", greatCD, lcd);
		}
	}
}

Measured memory_bytes: 18144
#include<stdio.h>
#define N 100

int main()
{
  int i,j,minj,num,A[N],swap,cnt = 0;

  while(1)
    {
      scanf("%d",&num);
      if(num >= 1 && num <= N) break;
    }

  for(i=0;i<num;i++) scanf("%d",&A[i]);

  for(i=0;i<num;i++)
    {
      minj = i;
      for(j=i;j<num;j++)
	{
	  if(A[j] < A[minj]) minj = j;
	}
      if(i != minj)
	{
	  swap = A[i];
	  A[i] = A[minj];
	  A[minj] = swap;
	  cnt++;
	}
    }

   for(i=0;i<num;i++)
    {
      if(i!=num-1) printf("%d ",A[i]);
      else printf("%d\n",A[i]);
    }

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

  return 0;
}



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

a = 1
b = n - 1
sum_b = 0
while b > 10:
    sum_b += b % 10
    b //= 10
sum_b += b

result = sum_b + 1

for i in range(2, n):
    a = i
    b = n - i
    sum_a = 0
    while a > 10:
        sum_a += a % 10
        a //= 10
    sum_a += a
    sum_b = 0
    while b > 10:
        sum_b += b % 10
        b //= 10
    sum_b += b
    if sum_a + sum_b < result:
        result = sum_a + sum_b

print(result)

Measured memory_bytes: 3064
//template.cpp
#include <bits/stdc++.h>
using namespace std;
 
#define lll long long int  
#define mp make_pair
#define pb push_back
 
#define fl(i,n) for (i=0;i<n;i++)
#define fl1(i,n) for (i=1;i<=n;i++)
#define fla(i,n,a) for (i=a;i<n;i++)
#define flr(i,n) for (i=n-1;i>=0;i--)
#define fl1r(i,n) for (i=n;i>=1;i--)
#define flar(i,n,a) for (i=n-1;i>=a;i--)
#define mem(a,i) memset(a,i,sizeof(a))
 
typedef pair<int,int> pii;
typedef pair<lll,lll> pll;
typedef pair<lll,int> pli;
typedef map<lll, lll> mll;
typedef map<int, int> mii;
typedef vector<pll> vpll;
typedef vector<lll> vll;
 
#define gcd __gcd
#define debug(x) cout<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl
#define debug4(x,y,z,P) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#P<<" :: "<<P<<endl
#define debug5(x,y,z,P,O) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#P<<" :: "<<P<<"\t"<<#O<<" :: "<<O<<endl
 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bb begin()
#define ee end()
 
#define MOD 1000000007
#define MAX 300001
 
lll aA[MAX], aB[MAX], aC[1001][1001];
vll vA, vB;
lll T,n,i,j,k,a,b,c,m,u,v,x,y,l,r,s,e,ans;
string sA, sB, sC[MAX];
 
int main(){
 
    boost;
    cin >> n;
    fl(i, n) cin >> aA[i];
    sort(aA, aA + n);
    aB[0] = aA[0]; aA[n] = 0;
    fl1(i, n - 1) aB[i] = aA[i] + aB[i - 1];
    ans = 0;
    fl1r(i, n){
        if(aA[i] / 2.0 <= aB[i - 1]) ans++;
        else break;
    }

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


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

#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define FORD(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define Debug(x) cerr << #x << " = " << x << '\n';
#define HERE cerr << "HERE\n\n";
#define X first
#define Y second
#define pb push_back
#define FASTER { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

using namespace std;

typedef pair <int, int> ii;
typedef vector <int> vi;



int main(){
    FASTER
//    freopen("x.INP", "r", stdin);
//    freopen("x.OUT", "w", stdout);
    int n;
    int cur = 1;
    cin >> n;
    FOR(i, 1, n){
        int x;
        cin >> x;
        if (x == cur)
            cur++;
    }
    if (cur == 1) cout << -1;
    else
    cout << n - cur + 1;
}


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

using namespace std;

int main()
{
    int n,p,cnt=0;
    cin >> n;

    for(int i=1; i<=n; i++){
        cin >> p;
        if(p != i)
        cnt++;
    }

    if(cnt <=2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    
   return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;


const int MAX = 5500000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(){
  int n, m; cin >> n >> m;
  COMinit();
  ll bunbo = COM(m+n, n)*2%mod;
  ll bunsi = max(m, n)*2%mod*COM(m+n, n)%mod;
  for(int i=1; i<=min(m, n); i++){
    bunsi+=COM(i*2, i)*COM(m+n-i*2, n-i)%mod; bunsi%=mod;
  }
  //cout << bunbo << " " << bunsi << endl;
  cout << bunsi*modinv(bunbo, mod)%mod << endl;
}


Measured memory_bytes: 132556
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextInt();
        var K = sc.nextInt();
        WriteLine(K * Pow(K - 1, N - 1));
    }
    
}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


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

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


  // ここにプログラムを追記

  if(S =="a" || S=="i" || S=="u" || S=="e" || S=="o"){
  cout << "vowel" << endl;
}
  else{
    cout << "consonant" << endl;
  }
}


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

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

    vector<int> X(N);
    vector<int> Y(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(Y.begin(), Y.end());

    int Y1 = Y[N / 2 - 1];
    int Y2 = Y[N / 2];

    if (Y1 != Y2) {
        for (int i = 0; i < N; i++) {
            if (X[i] <= Y1) {
                cout << Y2 << endl;
            }
            else if (X[i] >= Y2) {
                cout << Y1 << endl;
            }
        }
    }
    else {
        for (int i = 0; i < N; i++) {
            cout << Y1 << endl;
        }
    }
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <string.h>

int main()
{
  int N,X;
  int D=0;
  int L[100];
  int j,i,leng;
  int count=1;

  scanf("%d %d\n",&N,&X);

  for(i=0;i<N;i++){
    scanf("%d",&L[i]);
  }

  leng = strlen(L);

  for(j=0;j<N;j++){
    D=D+L[j];
    if(D<=X)
      count++;
  }
  printf("%d",count);
}

Measured memory_bytes: 128
#include <stdio.h>
#define MOD 1000000007

int doubleup(int num,int goal);

int main()
{
	int n,m,k;
	int i,j;
	int ans=0;
	int step[100010]={0};
	int dp[100010]={0};
	
	scanf("%d %d",&n,&m);
	
	for(i=0;i<m;i++)
	{
		scanf("%d",&k);
		step[k]=1;//1は壊れた床
	}
	
	
	for(j=0;j<=n;j++)
	{
		if(step[j])dp[j]=0;
		else if(j==0||j==1)dp[j]=1;
		else dp[j]=(dp[j-1]+dp[j-2])%MOD;
	}
	
	printf("%d",dp[n]);
	return 0;
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int weeks = Integer.parseInt(str);
		long debtRound = 100000;
		for (int i = 1; i <= weeks; i++) {
			long debt = (long) (debtRound * 1.05);
			debtRound = (long) Math.ceil((double) debt / 1000) * 1000;
		}
		System.out.println(debtRound);
	}
}

Measured memory_bytes: 24312
N , Y  = map(int, input().split())
res = (-1,-1,-1)
for x in range(0,(N+1)):
    for y in range(0,(N-x+1)): 
        total = 10000 * x + 5000 * y + 1000 * (N - x - y)
        if total == Y:
            res = (x, y, N - x - y)
print(res[0], res[1], res[2])

Measured memory_bytes: 3064
#pragma warning (disable:4996)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#define inf 0X7f7f7f7f
#define MS_I(x) memset(x,-inf,sizeof(x))
#define MS(x) memset(x,0,sizeof(x))
#define MSI(x) memset(x,inf,sizeof(x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 5e5 + 10;
//another solve is char s[maxn]
//					/const ll maxn = 5e5 + 10;
int main()
{
	string end;
	cin >> end;
	int q;
	cin >> q;
	string front;
	for (int i = 0; i < q; i++)
	{
		int t;
		cin >> t;
		if (t - 1)
		{
			int f;
			char c;
			cin >> f >> c;
			if (f - 1)
				end.push_back(c);
			else
				front.push_back(c);
		}
		else
			swap(end, front);
	}
	reverse(front.begin(), front.end());
	cout << front + end << endl;
	return 0;
}

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



struct comp{
	bool operator()(const pair<int,int>& a,const pair<int,int>& b){
		return a.second > b.second;
	}
};



int main() {
	int x,y;
	cin>>x>>y;
	int l=2*x;
	int h=4*x;
	if(y%2==0 && y>=l && y<=h)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3636
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[]:
        arr.append([n, 1])
 
    return arr
 
n = int(input())
 
arr = factorization(n) 
# print(arr)
 
cnt = 0
if n == 1:
    pass
else:
    for ar in arr:
        i = 1
        while 1:
            ar[1]-=i
            if ar[1] < 0:
                break
            cnt += 1
            i+=1
print(cnt)

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

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();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

int main(void){
    int A,B; cin >> A >> B;
    cout << (B%A ? B-A : A+B) << endl;
    return 0;
}

Measured memory_bytes: 256
S=input()
n=len(S)
R=[0]*13
cnt=[0]*13
Pow=[[] for i in range(6)]
mod=10**9+7

for i in range(6):
    c=10**i
    for j in range(10):
        Pow[i].append(c*j%13)
ans=0
flag=0
for i in range(n):
    if S[n-i-1]=="?":
        P=Pow[i%6]
        if flag==0:
            for p in P:
                R[p]=1
                flag=1
        else:
            for j in range(10):
                for k in range(13):
                    cnt[(k+P[j])%13]+=R[k]%mod
            R=cnt
            cnt=[0]*13
    else:
        x=int(S[n-i-1])
        ans+=Pow[i%6][x]
ans%=13
if flag==0:
    if ans==5:
        print(1)
    else:
        print(0)
else:
    print(R[(18-ans)%13]%mod)

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    char s;
    cin>>s;
    s++;
    cout<<s<<endl;
    
}

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

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

  if( a > b ) swap(a, b);
  if( b > c ) swap(b, c);
  if( a > b ) swap(a, b);

  cout<<a<<" "<<b<<" "<<c<<endl;
  return 0;
}



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

int main(){
    int res=0;
    string s;
    for(int i=0;i<4;i++){
        cin >> s[i];
        if(s[i]=='2')res++;
    }
    cout << res << endl;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    ll N,L;
    cin >> N >> L;

    vector<pair<ll,ll>> a(N);
    REP(i,N) {
        a[i].first = abs(L + i);
        a[i].second = L + i;
    }
    sort(all(a));

    ll ans = 0;
    for(int i=1;i<N;i++) {
        ans += a[i].second;
    }

    pl(ans)

    return 0;
}


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

using namespace std;

int main(){
	double d;
	cin >> d;
	int intd = (int)d;
	double load;
	double maxl = 0;
	int ind;

	for(int tate = intd; tate>0; tate--){
		 double yoko = sqrt(d*d - tate*tate);
		 if(yoko < 1){
		 	load = 1 + tate;
		 }else{
		 	load = tate + yoko;
		 }
		 if(load > maxl){
		 	maxl = load;
		 	ind = tate;
		 }
	}
	printf("%.13f\n",max(maxl,sqrt(2)*d));
	//cout <<  << endl;
}

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

typedef long long ll;

int resolve(int N, int K, int h[]) {
  int c[N];
  c[0] = 0;
  c[1] = abs(h[1] - h[0]);
  for (int i = 2; i < N; i++) {
    ll c_min = __LONG_LONG_MAX__;
    for (int k = 1; k <= K && i - k >= 0; k++) {
      ll cost = c[ i - k ] + abs( h[ i ] - h[ i - k ] );
      if (c_min > cost) {
        c_min = cost;
      } 
    }
    c[i] = c_min;
  }
  return c[N-1];
}

int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  int h[N];
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  cout << resolve(N, K, h) << endl;
}

Measured memory_bytes: 4344
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
ll h[100001][3],dp[100001][3];
int main(){
	ll n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>h[i][0]>>h[i][1]>>h[i][2];
		for(int i2=0;i2<3;i2++){
			if(i==1) dp[i][i2]=h[i][i2];
			else if(i2==0) dp[i][i2]=h[i][i2]+max(dp[i-1][1],dp[i-1][2]);
			else if(i2==1) dp[i][i2]=h[i][i2]+max(dp[i-1][0],dp[i-1][2]);
			else if(i2==2) dp[i][i2]=h[i][i2]+max(dp[i-1][0],dp[i-1][1]);
		}	
	}
	cout<<max(max(dp[n][0],dp[n][1]),dp[n][2]);
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

struct syu {
	int k;
	int n;
	vector<vector<int> > v;
};

int N;
vector<syu> ans;

void init()
{
	cin >> N;
	syu s;
	s.k = 1;
	s.v.resize(2, vector<int>(1, 1));
	ans.PB(s);
}

void culc()
{
	auto pre = ans.back();
}

void print(bool f)
{
	if (!f) {
		cout << "No" << endl;
		return;
	}
	auto& res = ans.back();
	cout << "Yes" << endl;
	cout << res.v.size() << endl;
	for (auto x : res.v) {
		cout << x.size();
		for (int y : x) {
			cout << " " << y;
		}
		cout << endl;
	}
}

void mak()
{
	auto ori = ans[ans.size() - 2];
	syu res;
	res.n = ori.n + 2;
	res.v = ori.v;
	int x = ori.k+1;
	for (auto& a : res.v) {
		a.PB(x++);
		a.PB(x++);
	}
	res.v.PB(vector<int>(1, x));
	res.v.PB(vector<int>(1, x));
	int si = res.v.size() - 1;
	reps(y, ori.k+1, x) {
		res.v[si].PB(y);
		y++;
		res.v[si-1].PB(y);
	}
	res.k = x;
	ans.PB(res);
}


void solve()
{
	if (N == 1) {
		print(1);
		return;
	}
	syu s;
	s.k = 3;
	s.n = 2;
	s.v.resize(3);
	s.v[0].PB(1);
	s.v[0].PB(2);
	s.v[1].PB(2);
	s.v[1].PB(3);
	s.v[2].PB(3);
	s.v[2].PB(1);
	ans.PB(s);
	if (N == 2) {
		print(0);
		return;
	}
	if (N == 3) {
		print(1);
		return;
	}
	while(true) {
		if (ans.back().k > N) {
			print(0);
			return;
		} else if (ans.back().k == N) {
			print(1);
			return;
		}
		mak();
	}
}





Measured memory_bytes: 126976
n = int(input())
if n <= 111:
    print(111)
elif n <= 222:
    print(222)
elif n <= 333:
    print(333)
elif n <= 444:
    print(444)
elif n <= 555:
    print(555)
elif n <= 666:
    print(666)
elif n <= 777:
    print(777)
elif n <= 888:
    print(888)
elif n <= 999:
    print(999)

Measured memory_bytes: 3060
import collections

def solve():
  def calc(x,y):
    cnt1=(x+k-1)//k
    cnt2=(w-1-x+k-1)//k
    cnt3=(y+k-1)//k
    cnt4=(h-1-y+k-1)//k
    return min(cnt1,cnt2,cnt3,cnt4)

  h,w,k=map(int,input().split())
  boards=[tuple(input()) for _ in range(h)]
  for i in range(h):
    for j in range(w):
      if boards[i][j]=='S':
        sx=j
        sy=i
        break
  q=collections.deque()
  checked=[[0]*w for _ in range(h)]
  checked[sy][sx]=1
  q.append((sx,sy,0))
  ans=1+calc(sx,sy)
  while 1:
    if len(q)==0:
      break
    tx,ty,cnt=q.popleft()
    if cnt==k+1:
      break
    ans=min(ans,1+calc(tx,ty))
    if tx!=0 and boards[ty][tx-1]!='#' and checked[ty][tx-1]==0:
      checked[ty][tx-1]=1
      q.append((tx-1,ty,cnt+1))
    if tx!=w-1 and boards[ty][tx+1]!='#' and checked[ty][tx+1]==0:
      checked[ty][tx+1]=1
      q.append((tx+1,ty,cnt+1))
    if ty!=0 and boards[ty-1][tx]!='#' and checked[ty-1][tx]==0:
      checked[ty-1][tx]=1
      q.append((tx,ty-1,cnt+1))
    if ty!=h-1 and boards[ty+1][tx]!='#' and checked[ty+1][tx]==0:
      checked[ty+1][tx]=1
      q.append((tx,ty+1,cnt+1))
  print(ans)
solve()

Measured memory_bytes: 14188