akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  random_device rd;
  mt19937 mt(rd());
  uniform_int_distribution<ll> a(1,26);
  vector<ll> day(26);
  rep(i,365) {
    while (1) {
      ll ans = a(mt);
      if (day[ans-1] != i/26 + 1) {
        cout << ans << '\n';
        ++day[ans-1];
        break;
      }
    }
  }
}

Measured memory_bytes: 3660
# N  個の都市があり、M 本の道路があります。
# i(1≦i≦M) 番目の道路は、都市 ai と 都市 bi (1≦ai,bi≦N) を双方向に結んでいます。
# 同じ 2 つの都市を結ぶ道路は、1 本とは限りません。
# 各都市から他の都市に向けて、何本の道路が伸びているか求めてください。

input_line_1 = gets.chomp.split
n = input_line_1[0].to_i
m = input_line_1[1].to_i

roads = Array.new

m.times do
  input_line = gets.chomp.split
  2.times do |i|
    input_line[i] = input_line[i].to_i
  end
  roads << input_line
end

n.times do |i|
  count = 0
  m.times do |j|
    if roads[j].include?(i+1)
      count += 1
    end
  end
  puts count
end


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible";
	else
		cout << "Impossible";
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A.reverse()
B.reverse()

ans = 0
for i in range(n):
    #print(ans)
    if A[i] <= B[i]:
        ans += A[i]
        B[i] -= A[i]
        if A[i+1] >= B[i]:
            ans += B[i]
            A[i+1] -= B[i]
            B[i] = 0
        else:
            ans += A[i+1]
            A[i+1] = 0
    else:
        ans += B[i]
        B[i] = 0
        A[i] -= B[i]
print(ans)


Measured memory_bytes: 82148
#include<bits/stdc++.h>
 
#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define pb push_back
 
using namespace std;
 
vector<int> pre, in, ans;
int n;
int pos;
 
 
void solve(int l, int r){
  if(l - r >= 0) return;
  int root = pre[pos];
  pos++;
  int d = distance(in.begin(), find(in.begin(), in.end(), root));
  solve(l, d);
  solve(d+1, r);
  ans.pb(root);
}
 
signed main(){
 
  cin >> n;
   
  int m;
  rep(i,n){
    cin >> m;
    pre.pb(m);
  }
  rep(i,n){
    cin >> m;
    in.pb(m);    
  }
 
  solve(0, pre.size());
 
  cout << ans[0];
  REP(i,1, n){
    cout << " " << ans[i];
  }
  cout << "\n";
   
}



Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, m, ans;
	cin >> n >> m;
	if (n > m) swap(n, m);

	if (n == 1) {
		if (m == 1) ans = 0;
		else if (m == 2) ans = m;
		else ans = 2;			
	}
	else ans = n * m - (n - 2) * (m - 2);

	cout << n * m - ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int digitsum(int num){
    int res = 0;
    while(num != 0){
        res += num % 10;
        num = num / 10;
    }
    return res;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b;
    cin >> n >> a >> b;
    
    int res = 0;
    rep(i, n+1){
        int tmp = digitsum(i);
        if(a <= tmp && tmp <= b){
            res += i;
            //cout << i << endl;
            //cout << tmp << endl;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int M=1000000;

int main(){
    int n[M],x[M];
    int m=0;
    while(1){
        cin>>n[m]>>x[m];
        if(n[m]==0&&x[m]==0) break;
        m++;
    }

    for(int v=0;v<m;v++){
    int count=0;
    for(int i=1;i<=x[v]/3;i++){
        if(x[v]-i<2*n[v]&&x[v]-i>2*i+2){
            for(int k=i+1;k<=(x[v]-i)/2;k++){
                if(x[v]-i-k<=n[v]&&x[v]-i-k>k) count++;
            }
        }
    }
    cout<<count<<endl;
}
    
}

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

int main()
{
	int n;
	int k;
	std::cin >> n >> k;

	std::vector<int> h(n);
	for (int i = 0; i < n; i++) std::cin >> h[i];
	std::sort(h.begin(), h.end());

	int ans = 1000000000;

	for (int i = 0; i < n - k +1; i++)
	{
		if (h[i + k - 1] - h[i] < ans) ans = h[i + k - 1] - h[i];
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m , cnt = 1;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		m = a[0];
		while(m != 2) {
			m = a[m-1];
			cnt++;
			if(cnt > n) {
				cnt = -1;
				break;
			}
		}
		System.out.print(cnt);
		
		
	}

}

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

using ll = long long;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define SORT(obj) sort((obj).begin(), (obj).end())
#define ALL(obj) (obj).begin(), (obj).end()
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  vector<vector<char>> v(n);
  REP(i, n) {
    vector<char> tmp_v(15);
    REP(i,11) {
      tmp_v[i] = getchar();
    }
    SORT(tmp_v);
    v[i] = tmp_v;
  }
  SORT(v);
  ll ans = 0;
  ll tmp = 1;
  REPS(i,1,n) {
    if(v[i] == v[i-1]) ans += tmp++;
    else tmp = 1;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		solve(s);
		s.close();
	}

	public static void solve(Scanner s) {
		String str = s.next();

		StringBuilder sb = new StringBuilder();

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

			switch (c) {
			case '0':
				sb.append(c);
				break;
			case '1':
				sb.append(c);
				break;
			case 'B':
				if (sb.length() > 0) {
					sb.deleteCharAt(sb.length() - 1);
				}
				break;
			}
		}

		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 9416
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define pb push_back
#define test ll t; cin>>t; while(t--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007LL
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define inc(i,a,n) for (ll i=a;i<n;i++)
#define dec(i,a,n) for (ll i=n-1;i>=a;i--)
int main()
{
  ll n;
  cin>>n;
  ll AC=0,WA=0,TLE=0,RE=0;
  inc(i,0,n)
  {
     string s;
     cin>>s;
     if(s=="AC")
     AC++;
     if(s=="WA")
     WA++;
     if(s=="TLE")
     TLE++;
     if(s=="RE")
     RE++;
  }

  cout<<"AC"<<" "<<"x"<<" "<<AC<<endl;
  cout<<"WA"<<" "<<"x"<<" "<<WA<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<TLE<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<RE<<endl;

  
   return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

double EPS = 1e-5;

double add(double a, double b){
    if(abs(a + b) < EPS * (abs(a) + abs(b)))return 0;
    return a + b;
}

struct P{
    double x, y;
    P(){}
    P(double x, double y) : x(x), y(y) {
    }
    P operator + (P p){
        return P(add(x, p.x), add(y, p.y));
    }
    P operator - (P p){
        return P(add(x, -p.x), add(y, -p.y));
    }
    P operator * (double d){
        return P(x * d, y * d);
    }
    double dot(P p){
        return add(x * p.x, y * p.y);
    }
    double det(P p){
        return add(x * p.y, -y * p.x);
    }
};

bool cmp_x(const P& p, const P& q){
    if(p.x != q.x)return p.x < q.x;
    return p.y < q.y;
}

vector<P> convex_hull(P* ps, int n){
    sort(ps, ps+n, cmp_x);
    int k = 0;
    vector<P> qs(n * 2);
    REP(i,n){
        while(k > 1 && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0)k--;
        qs[k++] = ps[i];
    }
    for(int i = n-2, t = k; i >= 0; i--){
        while(k > t && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0)k--;
        qs[k++] = ps[i];
    }
    qs.resize(k-1);
    return qs;
}

double dist(P p, P q){
    // return (p-q).dot(p-q);
    return sqrt((p-q).dot(p-q));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(48);
    int32 n;
    cin >> n;
    if(n == 1){
        int64 x, y;
        cin >> x >> y;
        cout << sqrt(x * x + y * y) << endl;
        return 0;
    }
    vector<P> engine;
    REP(i,n){
        int64 x,y;
        cin >> x >> y;
        engine.push_back(P(x, y));
    }
    vector<P> ps(1);
    ps[0] = engine[0];
    ps.push_back(P(0,0));
    FOR(i,1,n){
        int64 m = ps.size();
        REP(j,m){
            ps.pb(ps[j] + engine[i]);
        }
        ps = convex_hull(&ps[0] , ps.size());
    }
    double ans = 0;
    REP(i,(signed)ps.size()){
        ans = max(ans, dist(ps[i], P(0,0)));
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let inp = read_ints();
    let humans: Vec<_> = (0..inp[0]).map(|_| read_point()).collect();
    let points: Vec<_> = (0..inp[1]).map(|_| read_point()).collect();

    for h in humans {
        println!("{}", 1+closest_point(&h, &points));
    }
}

struct Point {
    x: i64,
    y: i64,
}

impl Point {
    fn man_dist(&self, other: &Point) -> i64 {
        (self.x - other.x).abs() + (self.y - other.y).abs()
    }
}

fn closest_point(p: &Point, ps: &[Point]) -> i64 {
    (*ps)
        .iter()
        .enumerate()
        .min_by_key(|&(_, loc)| p.man_dist(loc))
        .unwrap()
        .0 as i64
}


fn get_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("read");
    buf
}

fn read_ints() -> Vec<i64> {
    get_line()
        .trim()
        .split_whitespace()
        .map(|n| n.parse().expect("parse error"))
        .collect()
}

fn read_point() -> Point {
    let input = read_ints();
    Point {
        x: input[0],
        y: input[1],
    }
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  string t="";
  rep(i,s.size()-1){
    if(s[i]=='B'&&s[i+1]=='C'){
      t.push_back('X');
      i++;
    }
    else{
      t.push_back(s[i]);
    }
  }
  ll n=t.size();
  vll sum(n+1);
  rrep(i,n){
    sum[i]=sum[i+1];
    if(t[i]=='X') sum[i]++;
    else if(t[i]=='C' || t[i]=='B') sum[i]=0;
  }
  
  // cout<<t<<endl;
  // rep(i,n) cout<<sum[i]<<' ';
  // cout<<endl;
  
  ll ans=0;
  rep(i,n){
    if(t[i]=='A') ans+=sum[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2452
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int n,t[105],m,sowa=0,ans[105],p,x;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t[i];
    sowa+=t[i];
  }

  cin>>m;
  for(int i=0;i<m;i++){
    cin>>p>>x;
    ans[i]=x+sowa-t[p-1];
  }

  for(int i=0;i<m;i++)
    cout<<ans[i]<<endl;

  return(0);
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000



int lower_bound(int a[],int x,int n){
	int left=0;
	int right=n-1;
	int mid;
	char past='N';
	
	while(left<=right){
	
		mid=(left+right)/2;
		
		if(a[mid]==x){
			for(int i=mid;i>=0;i--)
				if(a[i]!=x)return i+1;
			return 0;
		}
		
		else if(a[mid] > x){
			right=mid-1;
		}
		else if(a[mid] < x){
			left=mid+1;
		}
		
	}
	
	
	if(a[mid] < x){
		for(int i=mid;i<n;i++)
			if(a[i] >= x)return i;
		return n;
		
	}
	else {
		for(int i=mid;i>=0;i--)
			if(a[i] <= x)return i+1;
		return 0;
	}

	
}



int main(){
	int n,i,q,x;
	int a[N];
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
	
		scanf("%d",&x);
		printf("%d\n",lower_bound(a,x,n));
	
	}
	
	return 0;
	
}


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

int main(){
  int A,B;
  cin >> A >> B;
  
  int K = A + B;
  if(0 == K%2) cout << K/2 << endl;
  else cout << "IMPOSSIBLE" << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// fは直前のドミノが縦2が1個パターンなら1、横2が2個パターンなら2
int n, f;
string s1, s2;
ll ans;

int main() {
	cin >> n >> s1 >> s2;
	
	// これは公式の解説の図が一番わかりやすい
	// https://atcoder.jp/img/arc081/editorial.pdf
	rep(i,n) {
		// 縦2のドミノ1個の場合
		if (s1[i]==s2[i]) {
			if (f==1) ans = ans * 2 % mod;
			else if (f==0) ans = 3;
			f = 1;
		}
		// そうでない場合 横2のドミノが縦に2個繋がってる
		else {
			if (f==1) ans = ans * 2 % mod, f = 2;
			else if (f==2) ans = ans * 3 % mod;
			else ans = 6;
			f = 2;
			i++;
		}
	}
	cout << ans << ln;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt(), k = fs.nextInt();
		
		long ans = 0;
		int cnt = 0;
		
		if(k%2==0) {
			int cnt_odd = 0, cnt_eve = 0;
			for(int a = k/2;a<=n;a+=k/2) {
				if(a%k==0)cnt_eve++;
				else cnt_odd++;
				ans = (long)cnt_eve * cnt_eve * cnt_eve;
				ans += (long)cnt_odd * cnt_odd * cnt_odd;
			}
		}
		else {
			for(int a=k;a<=n;a+=k) cnt++;
			ans = (long)cnt * cnt * cnt;
		}
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 23252
#include <cfloat>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

const int MAX_N = 600;
const int MAX_M = 179700;

class Edge {
    public:
        int from;
        int to;
};

int n, m;
map<int, vector<Edge> > edges;

double dp[MAX_N][MAX_N];

void calc_dp(int room_no, int block_room_no) {
    for (int i = room_no - 1; i >= 0; i--) {
        vector<Edge> es = edges[i+1];
        double sum = 0;
        // cout << "start: " << room_no << endl;
        for (auto it = es.begin(); it != es.end(); it++) {
            Edge e = *it;
            // cout << dp[0][e.to - 1] << endl;
            sum += dp[block_room_no-1][e.to - 1];
        }
        dp[block_room_no-1][i] = 1.0 + sum / ((double) es.size());
    }
}

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

    for (int i = 0; i < m; i++) {
        int s, t;
        Edge edge;
        cin >> s >> t;
        edge.from = s;
        edge.to = t;
        edges[s].push_back(edge);
    }

    calc_dp(n-1, n);

    for (int i = n-1; i >= 0; i--) {
        for (int j = i-1; j >= 0; j--) {
            dp[j][i] = dp[n-1][i];
        }
    }

    for (int i = n-2; i >= 0; i--) {
        vector<Edge> es = edges[i+1];
        Edge e;
        double max_cost = 0;
        double sum = 0;
        if (es.size() <= 1) {
            continue;
        }
        for (auto it = es.begin(); it != es.end(); it++) {
            e = *it;
            sum += dp[n-1][e.to - 1];
            if (dp[n-1][e.to - 1] > max_cost) {
                max_cost = dp[n-1][e.to - 1];
            }
        }
        dp[i][i] = 1.0 + (sum - max_cost) / ((double) es.size() - 1);

        calc_dp(i, i+1);
    }

    // Print edges
    // for (auto it = edges.begin(); it != edges.end(); it++) {
    //     vector<Edge> es = (*it).second;
    //     cout << (*it).first << ":" << endl;
    //     for (auto it2 = es.begin(); it2 != es.end(); it2++) {
    //         cout << (*it2).from << "->" << (*it2).to << endl;
    //     }
    // }

    // Print dp_i,n
    // for (int i = 0; i < n; i++) {
    //     cout << dp[n-1][i] << endl;
    // }

    // Print dp
    // cout << "dp: " << endl;
    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < n; j++) {
    //         printf("%3.6f ", dp[i][j]);
    //     }
    //     cout << endl;
    // }

    double answer = DBL_MAX;
    for (int i = 0; i < n; i++) {
        if (dp[i][0] != 0 && dp[i][0] < answer) {
            answer = dp[i][0];
        }
    }

    printf("%3.6f\n", answer);

    return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define int long long int 

int32_t main()
{
  int n;
  cin>>n;
  set<string> s;
  for(int i=0;i<n;i++)
  {
    string str;
    cin>>str;
    s.insert(str);
  }
    cout<<s.size();
}

Measured memory_bytes: 19228
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int d, n, m, k, d1, d2;
  while (cin >> d) {
    if (d == 0) break;
    cin >> n >> m;
    vector<int> s(n + 1);
    rep(i, n - 1) cin >> s[i];
    s[n - 1] = d;
    sort(s.begin(), s.end());

    int ans = 0;
    rep(i, m) {
      cin >> k;
      d1 = abs(k - *(upper_bound(s.begin(), s.end(), k) - 1));
      d2 = abs(k - *(upper_bound(s.begin(), s.end(), k)));
      ans += min(d1, d2);
    }

    cout << ans << endl;
  }

  
  return 0;
}


Measured memory_bytes: 3368
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  ll N,b,ans=0;
  cin>>N;
  vector<ll> A,B;
  REP(i,N){
    ll a;
    cin>>a;
    A.push_back(a);
    B.push_back(a-i-1);
  }
  SORT(B);
  
  if(N%2==0) b=(B.at(N/2-1)+B.at(N/2))/2;
  else b=B.at(N/2);
  
  REP(i,N) ans+=abs(B.at(i)-b);
  cout<<ans<<endl;
}

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

int a[100000];
int b, c;

int main(void) {
  int n;
  cin >> n;
  for(int i = 0; i < n+1;i++) {
   cin >> a[i];
  }
  long long cnt = 0;
  for(int i = 0; i < n; i++) {
    cin >> b;
    int s = 0;
    if(a[i] >= b) {
      s = b; 
      a[i] -= b;
    }
    else if(a[i+1]+a[i] >= b) {
        s = b; 
        a[i+1] -= (b - a[i]);
        a[i] = 0;
    }
    else {
      s = a[i+1]+a[i];
      a[i+1] = 0;
      a[i] = 0;
    }
    cnt += s;
  }
  
  cout << cnt << endl;
  return 0; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int n,M;cin>>n>>M;
  int cur = 0;
  int ans = 1;
  for (int i = 0; i < n; i++) {
  		int x; cin >> x;
    	cur += x;
    	if (cur<=M) ans = max(ans,i+2);
  }
  cout << ans << endl;
	return 0; 
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
const int MR=1e5+10;
typedef long long LL;
bool cmp(const int& x,const int& y){
	return x>y;
}
LL p[MR],q[MR],r[MR],a[MR*2];
int main() {
	int x,y,na,nb,nc;
	cin>>x>>y>>na>>nb>>nc;
	for(int i=0;i<na;i++){
		cin>>p[i];
	}
	for(int i=0;i<nb;i++){
		cin>>q[i];
	}
	for(int i=0;i<nc;i++){
		cin>>r[i];
	}  
	sort(p,p+na,cmp);
	sort(q,q+nb,cmp);
	sort(r,r+nc,cmp);

	LL ans=0;
	int len=0;
	for(int i=0;i<x;i++){
		ans+=p[i];
		a[len]=p[i];
		len++;
	}
	for(int i=0;i<y;i++){
		ans+=q[i];
		a[len]=q[i];
		len++;
	}
	sort(a,a+len);
	for(int i=0;i<nc && i<len;i++){
		if(a[i]<r[i]){
			ans+=r[i]-a[i];
		}
		else break;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  string str;
  cin >> N >> K >> str;
  
  int x;
  x = K - 1;
  
  if( str.at(x) == 'A' ){
   str.at(x) = 'a';
    cout << str << endl;
  }
  if( str.at(x) == 'B' ){
    str.at(x) = 'b';
    cout << str << endl;
  }
  if( str.at(x) == 'C' ){
    str.at(x) = 'c';
    cout << str << endl;
  }
      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;


int main() {
 int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if (e-a <=k){
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }

}

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

void print(vector<int> & arr) {
printf("%d", arr[0]);
for(vector<int>::iterator itr=++(arr.begin()); itr!=arr.end(); ++itr){
printf(" %d", *itr);
}
printf("\n");
}

int main() {
vector<int> arr;
int n, tmp, i, j;

scanf("%d", &n);
for(i=0; i<n; ++i) {
scanf("%d", &tmp);
arr.push_back(tmp);
}

print(arr);

for(int i=1; i<n; ++i) {
tmp = arr[i];
for(j=i-1; j>=0 && arr[j]>tmp; --j) {
arr[j+1] = arr[j];
}
arr[j+1] = tmp;
print(arr);
}

return 0;
}

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

typedef long long ll;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

string L;
mint dp[100005][2];
// dp[*][0] : Lと同じ
// dp[*][1] : Lより小さいであることが確定

void solve() {
  int n=L.size();
  dp[0][0] = 1;
  rep(i,n){
    // a+b=0
    if(L[i] == '0') {
      dp[i+1][0] = dp[i][0];
      dp[i+1][1] = dp[i][1];
    } else {
      dp[i+1][1] = dp[i][0] + dp[i][1];
    }
    if(L[i] == '0') {
      dp[i+1][1] += dp[i][1]*2;
    } else {
      dp[i+1][0] += dp[i][0]*2;
      dp[i+1][1] += dp[i][1]*2;
    }
  }
  cout << (dp[n][0] + dp[n][1]).x << endl;
}

int main() {
  cin >> L;
  solve();
  return 0;
}



Measured memory_bytes: 2048
package main

import "fmt"

const (
	n0 = 1
	n1 = 1
	n2 = 2 * n1
	n3 = 3 * n2
	n4 = 4 * n3
	n5 = 5 * n4
	n6 = 6 * n5
	n7 = 7 * n6
)

var frac = [8]int{n0, n1, n2, n3, n4, n5, n6, n7}

func count(n int, A [10]int) int {
	c := 0
	var q []int
	for i := 0; i < n; i++ {
		var p int
		if i == 0 {
			p = A[i] - 1
			//fmt.Printf("p = %d, A[%d] = %d\n", p, i, A[i])
		} else {
			tmp := A[i]
			p = tmp
			for j := 0; j < i; j++ {
				if A[j] < tmp {
					p--
				}
			}
			// fmt.Printf("p = %d, A[%d] = %d\n", p, i, A[i])
		}
		q = append(q, A[i])
		c += p * frac[n-i-1]
		//fmt.Printf("p = %d, frac[%d] = %d, c = %d\n", p, n-i-1, frac[n-i-1], c)
	}
	return c
}

func main() {
	var P, Q [10]int
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&P[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&Q[i])
	}
	v1 := count(n, P)
	v2 := count(n, Q)
	v := v1 - v2
	if v > 0 {
		fmt.Println(v)
	} else {
		fmt.Println(-v)
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main(void)
{
	int n;
	string a,b;
	cin >> a >> b;
	string c=a+b;

	n=stoi(c);

	if(int(sqrt(n))*int(sqrt(n))==n)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  for(int i = 0; i < m; ++i) cin >> x.at(i);
  
  sort(x.begin(), x.end());
  vector<int> l(m-1);
  for(int i = 0; i < m-1; ++i) l.at(i) = x.at(i+1) - x.at(i);
  sort(l.begin(), l.end());
  
  int ans = 0;
  for(int i = 0; i < m-n; ++i) ans += l.at(i);
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
l w = "+" ++ (take (w-2) $ repeat '-') ++ "+\n"

b w h =
  let line = "|" ++ (take (w-2) $ repeat '.') ++ "|\n"
  in
    concat $ take ((h-3)`div`2) $ repeat line

c w h cc =
  let b = take ((w-3)`div`2) $ repeat '.'
  in
    "|" ++ b ++ cc ++ b ++ "|\n"

ans (wc:hc:cc:_) =
  let w = read wc :: Int
      h = read hc :: Int
  in
    (l w) ++ (b w h) ++ (c w h cc) ++ (b w h) ++ (l w)

main = do
  l <- getLine
  let i = words l
      o = ans i
  putStr o
  



Measured memory_bytes: 3672
from numpy import array as n
N, C = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]
r1, r2, l1, l2 = [0],[0],[0],[0]
sum, out = 0, 0
for x, cal in xy:
    sum += cal
    r1.append(max(r1[-1], sum-x))
    r2.append(max(r2[-1], sum-2*x))
sum = 0
for x, cal in xy[::-1]:
    sum += cal
    l1.append(max(l1[-1], sum-C+x))
    l2.append(max(l2[-1], sum-2*(C-x)))
print(max(n(r1+r2)+n(l2[::-1]+l1[::-1])))


Measured memory_bytes: 54012
{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as M

main = do
    n <- readLn :: IO Int
    print =<< sum.map (\(k,a)->if a>k then a-k else if a/=k then a else 0).M.toList.foldl' (\m k -> M.insertWith(+)k 1 m) M.empty.unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine


Measured memory_bytes: 18812
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		HashMap<Integer,Integer> map=new HashMap<>();
		int[] a=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt();
			if(map.containsKey(i+1-a[i])){
				map.put(i+1-a[i],map.get(i+1-a[i])+1);
			}else{
				map.put(i+1-a[i],1);
			}
		}
		long ans=0;
		for(int i=0; i<n; i++){
			if(map.get(i+1+a[i])!=null){
				ans+=map.get(i+1+a[i]);
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 69644
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define pb  				push_back
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)      type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
const double pi = 3.1415926535897932384626433;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void JH(){
    int d=-1,e=-1,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int n;cin>>n;
    string ss;cin>>ss;
    // int n=ss.length();
    fo0(i,n){
    	if(ss[i]!='R'){
    		d=i;
    		break;
    	}
    }

    if(d==-1){
    	cout<<0;
    	return;
    }

    string s1;
    for(int i=d;i<n;i++){
    	s1.push_back(ss[i]);
    }
    int m=s1.length();
    // cout<<s1<<endl;

    if(m==0){
    	cout<<0;
    	return;
    }

    for(int i=n-1;i>=0;i--){

    	if(ss[i]!='W'){
    		e=i;
    		break;
    	}

    }
    if(e==-1){
    	cout<<0;
    	return;
    }
    string s;

    for(int i=d;i<=e;i++){
    	s.push_back(ss[i]);
    }
    int len=s.length();
    if(len==0){
    	cout<<0;
    	return;
    }
    // cout<<s<<endl;




    int left=0,right=0;
    for(int i=0;i<len;i++){
    	if(s[i]=='W')
    		left=i;
    	else
    		break;
    }

    for(int i=len-1;i>=0;i--){
    	if(s[i]=='R')
    		right=i;
    	else
    		break;
    }


    int r=0;w=0;
    fo0(i,s.length()){
    	if(s[i]=='W')
    		w++;
    	else
    		r++;
    }

    if(left+1==right){
    	cout<<min(r,w)<<endl;
    }
    else{
    	int t=0;
    	fo0(i,r){
    		if(s[i]=='W'){
    			t++;
    		}
    	}

    	cout<<min(t,min(r,w));

    }



    

}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<fixed<<setprecision(3)<<(double)(clock()-beg)/1000<<"s ";
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int f( int a, int b )
{
    if( b==0 )
        return a;
    return f( b, a%b );
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int k;
    int res=0;
    cin >> k;
    for (int i=1; i <= k;++i){
        for (int j = 1; j <= k;++j){
            for (int t = 1; t <= k;++t){
                res += f(f(i, j), t);
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3652
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll a,b,c;cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b<<endl;
}
  

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int a, b;
    cin >> a >> b;
    if(a > b) cout << "a > b" << endl;
    else if(a < b) cout << "a < b" << endl;
    else cout << "a == b" << endl;
}


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

using namespace std;

const int INF = 2e9;
const int MAX_N = 1e5 + 5;

int n;

int h[MAX_N];

int dp[MAX_N];

int main() {
  // dp[i] = the minimum cost to get a stone i
  // I can here to stone i from stone i - 1 and i - 2, so i gonna chose from those two
  // So, dp[i] = min(dp[i - 1] + query(i, i - 1), dp[i - 2] + query(i, i - 2)
  // I am at stone 1, so dp[1] = 0, no cost to get here
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
    dp[i] = INF;
  }
  dp[1] = 0;
  for (int i = 1; i < n; ++i) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    if (i + 2 <= n) {
      dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
  }
  cout << dp[n] << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector<int> v(n);
	
	for (int &i : v){
		cin >> i;
	}
	int i = 1;
	for (int j = 0; j < n; ++j){
		if (v[j] == i){
			++i;
		}
	}
	if (i == 1) cout << -1;
	else cout << n + 1 - i;
}


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

int main() {
  int n,k;
  scanf("%d%d", &n, &k);
  char buffer[101];
  char str[100][101];
  
  for(int i=0; i<n; i++){
    scanf("%s", &str[i]);
  }

  for(int i=0; i<n-1; i++){
    for(int j=n-1; i<j; j--){
      if(strcmp(str[j-1], str[j])>0){
        strcpy(buffer, str[j]);
        strcpy(str[j], str[j-1]);
        strcpy(str[j-1], buffer);
      }
    }
  }

  for(int i=0; i<n; i++){
    if(i==n-1){
      printf("%s\n", str[i]);
    }else{
      printf("%s", str[i]);
    }
  }
  return 0;
}


Measured memory_bytes: 1740
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            int l = scn.nextInt();
            int a = scn.nextInt();
            int b = scn.nextInt();
            int c = scn.nextInt();
            int d = scn.nextInt();
            while(a > 0 || b > 0) {
                a -= c;
                b -= d;
                l--;
            }
            System.out.println(l);
        }
    }
}

Measured memory_bytes: 26212
import sys

n, x = map(int,sys.stdin.readline().split())
A = list(map(int,sys.stdin.readline().split()))

ans = 10**18
mins = [a for a in A]
for k in range(n):
    for i in range(n):
        if k <= i:
            mins[i] = min(A[i-k], mins[i])
        else:
            mins[i] = min(A[n-(k-i)], mins[i])
    ans = min(sum(mins)+k*x, ans)
print(ans)


Measured memory_bytes: 43116
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int X = int.Parse(Console.ReadLine());
        int max = 1;
        for(int i = 2; i <= Math.Sqrt(X); i++)
        {
            for(int j = 2; ; j++)
            {
                if (Math.Pow(i, j) <= X)
                    max = Math.Max(max, (int)Math.Pow(i, j));
                else break;
            }
        }
        Console.WriteLine(max);
    }
}


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

int N, M;
int a[50];
int b[50];
int ans = 0;

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) cin >> a[i] >> b[i];
    
    int t[50] = {0};
    for (int i = 0; i < M; i++) {
        t[a[i] - 1]++;
        t[b[i] - 1]++;
    }
    
    for (int i = 0; i < N; i++) cout << t[i] << endl;
    return 0;
}


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

int main(){
  int n,mx=-11,mn=100000;
  cin>>n;
  vector<int>a(n);
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=1;i<=n;i++){
    mx=max(mx,a[i]);
    mn=min(mn,a[i]);
  }
  cout<<mx-mn<<endl;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define f(i,x,n) for(int i=x;i<n;i++)
#define int long long
#define mod 1000000007
#define endl "\n"
const int INF = 1e18;
void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
int32_t main() 
{
	fastio();
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	vector<int>vc;
	int fg=0;
	f(i,0,n)
	{
		int ct=0,id=i+1,an=-1;
		while(ct<m)
		{
			if(s[id]=='0')
				an=id;
			id++;
			ct++;
		}
		if(an==-1)
		{
			cout<<-1;
			return 0;
		}
		vc.pb(an);
		i=an-1;
	}
	for(int i=vc.size()-1;i>=1;i--)
	{
		cout<<vc[i]-vc[i-1]<<" ";
	}
	cout<<vc[0];
}

Measured memory_bytes: 1480
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    tmp0 = input[0].split(" ");
    N = Number(tmp0[0]);
    M = Number(tmp0[1])

    var s = {}
    for(var i=1; i <= M; i++)
    {
        var tmp = input[i].split(" ")
        var k = Number(tmp[0])
        var val = 0
        for(var j=1; j <= k; j++)
        {
            val += Math.pow(2,Number(tmp[j])-1)
        }
        // console.log((Array(N).join('0') + val.toString(2)).slice(-N))
        lamp_switch = val
        s[i] = lamp_switch
    }
    var tmpp = input[M+1].split(" ")
    
    var ans =0
    for(var j=0; j <Math.pow(2,N); j++)
    {
        // console.log((Array(N).join('0') + j.toString(2)).slice(-N))
        var switch_states = j
        var flashCnt=0
        for(var i=1; i <= M; i++)
        {
            //電球i
            var andStr = (Array(N).join('0') + (switch_states & s[i]).toString(2)).slice(-N)
            var onCnt = andStr.split("1").length-1
            // console.log(`電球${i}`)
            // console.log("lamp_switch: " + (Array(N).join('0') + s[i].toString(2)).slice(-N))
            // console.log("switch_states: " + (Array(N).join('0') + j.toString(2)).slice(-N))
            // console.log("and: " + andStr)

            if((onCnt%2 == Number(tmpp[i-1])))
            {
                flashCnt++
            }
        }
        if(flashCnt == M){
            ans++
        }
    }
    console.log(ans)
  }
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//   Main("5 2\n3 1 2 5\n2 2 3\n1 0\n");

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

int main(){
	LL n;
	cin >> n;
	LL a[n];
	LL b[n];
	for(LL i = 0; i < n; i++) cin >> a[i] >> b[i];
	LL z = 0;
	for(LL i = n-1; i >= 0; i--){
		a[i] += z;
		z += (b[i]-(a[i] % b[i])) % b[i];
	}
	cout << z << endl;
}


Measured memory_bytes: 1792
#include <bits/extc++.h>

#ifndef DUMP
#define DUMP(...) void(0)
#endif

using namespace std;

vector<int> min_factor;
void prepare(int n) {
  min_factor.assign(n + 1, 0);
  for (int p = 2; p <= n; ++p) {
    if (min_factor[p]) continue;
    for (int i = p; i <= n; i += p)
      if (min_factor[i] == 0) min_factor[i] = p;
  }
}
vector<int> factors(int n) {
  vector<int> res;
  while (int d = min_factor[n]) res.push_back(d), n /= d;
  return res;
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& e : a) cin >> e;

  constexpr int lim = 1e6;
  prepare(lim);
  if ([&] {
        vector<bool> exists(lim + 1);
        for (auto&& e : a) {
          for (int p : factors(e)) {
            if (exists[p]) return false;
          }
          for (int p : factors(e)) {
            exists[p] = true;
          }
        }
        return true;
      }()) {
    cout << "pairwise coprime\n";
  } else if (accumulate(begin(a), end(a), 0, gcd<int, int>) == 1) {
    cout << "setwise coprime\n";
  } else {
    cout << "not coprime\n";
  }
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector <vector <char>> vec(H, vector<char>(W));
  for ( int i = 0 ; i < H ; i++ ){
    for ( int j = 0 ; j < W ; j++ ){
      cin >> vec.at(i).at(j);
    }
  }
  
  vector <vector <char>> vecN( H + 2, vector<char>(W + 2, '%'));
  for ( int i = 0 ; i < H ; i++ ){
    for ( int j = 0 ; j < W ; j++ ){
      vecN.at(i + 1).at(j + 1) = vec.at(i).at(j);
    }
  }
  
  for ( int i = 0 ; i < H + 2 ; i++ ){
    for ( int j = 0 ; j < W + 2 ; j++ ){
      if (vecN.at(i).at(j) == '%'){
        vecN.at(i).at(j) = '#';
      }
    }
  }

  for ( int i = 0 ; i < H + 2 ; i++ ){
    for ( int j = 0 ; j < W + 2 ; j++ ){
      cout << vecN.at(i).at(j);
    }
    cout << endl;
  }
}

  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int n;
ll a[100010], b[100010];
int main(void){
	cin >> n;
	rep(i, n){
		scanf("%lld %lld", &a[i], &b[i]);
	}
	ll ans = 0;
	for (int i = n - 1; i >= 0; --i){
		a[i] += ans;
		if(a[i] % b[i] != 0){
			ll d = b[i] - (a[i] % b[i]);
			ans += d;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<numeric>
#include<sstream>
#include<cmath>
using namespace std;
long long int mod = 1e9+7;

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int r = 0;
  int b = 0;
  for(int i=0; i<n; i++){
    if(s[i] == 'R') r++;
    else b++;
  }
  if(r > b) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  // vector<int> a(n);
  // for(int i=0; i<n; i++) cin >> a[i];

  return 0;
}
//


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int n;
cin>>n;
vector<int>a(n),b(n);
for(int i=0;i<n-1;i++){
    cin>>a.at(i)>>b.at(i);
    a.at(i)--;
    b.at(i)--;
}
vector<int> score(n);
for(int i=0;i<n;i++)cin>>score.at(i);
sort(score.begin(),score.end(),greater<int>());
vector<vector<int>> graph(n);
for(int i=0;i<n-1;i++){
    int c=a.at(i),d=b.at(i);
    graph.at(c).push_back(d);
    graph.at(d).push_back(c);
}
vector<int> ans(n,0);
queue<int> Q;
Q.push(0);
int idx=0;
while(!Q.empty()){
    int now=Q.front();
    Q.pop();
    ans.at(now)=score.at(idx);
    idx++;
    for(int i=0;i<graph.at(now).size();i++){
        if(ans.at(graph.at(now).at(i))==0)Q.push(graph.at(now).at(i));
    }
}
ll total=0;
for(int i=1;i<n;i++){
    total+=score.at(i);
}
cout<<total<<endl;
for(int i=0;i<n;i++){
    cout<<ans.at(i)<<endl;
}
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n)    FOR(i, 0, n)
#define pb           push_back
#define all(a)       (a).begin(), (a).end()
#define UNIQUE(v)    v.erase(unique(all(v)), v.end());
#define fill(a, x)   memset(a, x, sizeof(a))
#define zero(a)      fill(a, 0)
#define minus(a)     fill(a, -1)
#define dbg(x)       cout << #x "=" << x << endl

int n;
int k;
vector<ll> vc_a;

int check(ll P) {
  int i = 0;
  rep(j, k) {
    ll s = 0;
    while (s + vc_a[i] <= P) {
      s += vc_a[i];
      i++;
      if (i == n) return n;
    }
  }
  return i;
}

int solve() {
  ll left = 0;
  ll right = 100000 * 10000;
  ll mid;
  while (right - left > 1) {
    mid = (left + right) / 2;
    int v = check(mid);
    if (v >= n)
      right = mid;
    else
      left = mid;
  }
  return right;
}

int main() {
  ios::sync_with_stdio(false);
  int c = 0;
  cin >> n;

  cin >> k;

  ll min = 0;
  // receiving input
  while (c < n) {
    ll tmp;
    cin >> tmp;
    vc_a.pb(tmp);
    c++;
  }

  min = solve();

  cout << min << endl;

  return 0;
}



Measured memory_bytes: 3868