akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long m=1e9+7;
long long fac[100001];

long long power(long long x, long long y, long long p)
{
    long long res = 1;      // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

long long modInverse(long long n, long long p)
{
    return power(n, p-2, p);
}

long long nCrModPFermat(long long n, long long r, long long p)
{
   if (r==0)
      return 1;
    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

int main()
{
    long long n,k;
    cin>>n>>k;
    fac[0] = 1;
    for (long long i=1 ; i<=100000; i++)
        fac[i] = fac[i-1]*i%m;
    long long a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    if(k==1)
    {
        cout<<0<<endl;
        return 0;
    }
    sort(a,a+n);
    long long sum[n]={0}; sum[0]=a[0];
    for(int i=1; i<n; i++)
        sum[i]=(sum[i-1]+a[i])%m;
    long long ans=0;
    for(long long i=0; i<=n-k; i++)
    {
        long long start=0,end=n-k-i;
        long long sum1=0,sum2=0;
        if(start==0) sum1=sum[end];
        else sum1=sum[end]-sum[start-1];
        start=min(n-1,start+k+i-1); end=min(n-1,end+k+i-1);
        sum2=sum[end]-sum[start-1];
        long long mul=nCrModPFermat(k+i-2,k-2,m);
        //cout<<sum2<<" "<<sum1<<" "<<mul<<endl;
        ans = (ans+(((sum2-sum1+m)%m)*mul)%m)%m;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    cin>>s;
    int ans = 0;
    if(s == "RRR")ans=3;
    else if(s=="RRS" || s=="SRR")ans=2;
    else if(s == "SSS")ans=0;
    else ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>

using namespace std;

unsigned long long int GCD(unsigned long long int a, unsigned long long int b)
{
	if(a % b == 0)
	{
		return(b);
	}
	GCD(b, a % b);
}

void solve()
{
	unsigned long long int a, b;
	while(cin >> a >> b)
	{
		if(a < b)
		{
			swap(a, b);
		}
		unsigned long long int gcd = GCD(a, b);
		cout << gcd << " " << a * b / gcd << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <cstdio>

const int N = 3e3 + 7, MOD = 1e9 + 7;
int n, m, total, corder[N], prev[N], dp[N][N];
char now;

inline int max(int a, int b){return a > b?a:b;}

int main(){
	scanf("%d %d", &n, &m);
	for (register int i = 1;i <= n;i ++){
		while (now = getchar(), now != '1' && now != '0')continue;
		prev[i] = prev[i - 1], corder[i] = i;
		if (now == '1')total ++, prev[i] ++;
	}
	prev[n + 1] = prev[n], corder[n + 1] = n + 1;
	for (register int i = 1, x, y;i <= m;i ++){
		scanf("%d %d", &x, &y);
		corder[x] = max(corder[x], y);
	}
	for (register int i = 1;i <= n + 1;i ++)corder[i] = max(corder[i], corder[i - 1]);
	dp[1][prev[corder[1]]] = 1;
	for (register int i = 1;i <= n;i ++)
		for (register int j = 0;j <= total;j ++)
			if (dp[i][j]){
				if (j)dp[i + 1][j + prev[corder[i + 1]] - prev[corder[i]] - 1] = (dp[i + 1][j + prev[corder[i + 1]] - prev[corder[i]] - 1] + dp[i][j])%MOD;
				if (corder[i] + 1 - i - j)dp[i + 1][j + prev[corder[i + 1]] - prev[corder[i]]] = (dp[i + 1][j + prev[corder[i + 1]] - prev[corder[i]]] + dp[i][j])%MOD;
			}
	return !printf("%d", dp[n + 1][0]);
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t x, a;
  std::cin >> x >> a;
  if (x < a) {
    std::cout << 0 << std::endl;
  } else {
    std::cout << 10 << std::endl;
  }
  return 0;
}


Measured memory_bytes: 764
'use strict';

function main(stdin) {
  const input = stdin.split('');
  let flag = false;

  input.reduce((a, b) => {
    if (a === b) flag = true;
    return b;
  });

  if (flag) console.log('Bad');
  else console.log('Good');
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <stdio.h>
int main(void){
    int N, M, i, ans = 0, cnt = 0;
    int a[1000];
    
    scanf("%d %d", &N, &M);
    
    for(i = 0; i < N; i++){
        scanf("%d", &a[i]);
    }
    
    for(i = 0; i < N; i++){
        ans = ans + a[i];
    }
    
    for(i = 0; i < N; i++){
        if(a[i] >= ans / (4.0 * M)){
            cnt = cnt + 1;
        }
    }
    
    if(cnt >= M){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
}


Measured memory_bytes: 1664
#include <iostream>
#include <cmath>
#include <map>
#include <functional>
#include <algorithm>

using namespace std;

int main(void){
    int num[3];
    int cnt = 0;
    cin >> num[0] >> num[1] >> num[2];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            if(j == i) continue;
            for(int k=0; k<3; k++){
                if(k == j || k == i) continue;
                if(num[i]%2 == 0 && num[j]%2 == 1 && num[k]%2 == 1){
                    num[j] += 1;
                    num[k] += 1;
                    cnt += 1;
                    break;
                }
                if(num[i]%2 == 0 && num[j]%2 ==0 && num[k]%2 == 1){
                    num[i] += 1;
                    num[j] += 1;
                    cnt += 1;
                    break;
                }
            }
        }
    }
    sort(num, num+3, greater<int>());
    cnt += (num[0]-num[1])/2 + (num[0]-num[2])/2;
    cout << cnt;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define comp(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define infile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvli;
const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);


void solve(){
    int n;cin>>n;
    map<ll,ll> m;
    ll s=0;
    ll x;
    FOR(i,0,n){
        cin>>x;
        m[x]++;
        s+=x;
    }
    
    int q;cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        s -= b*m[b];
        s += (m[b])*c;
        m[c] += m[b];
        m[b]=0;
        cout<<s<<'\n';
    }
}





int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    
	return 0;
	
	
}


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


Measured memory_bytes: 9536
import sys
import heapq


def input(): return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())

    w = [[] for _ in range(10 ** 5 + 1)]
    for _ in range(N):
        a, b = map(int, input().split())
        w[a].append(b)

    ans = 0
    hq = []
    for i in range(1, M+1):
        for x in w[i]:
            heapq.heappush(hq, -x)

        if not hq:
            continue

        ans += -heapq.heappop(hq)

    print(ans)


if __name__ == "__main__":
    main()


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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dp[(1 << 15)][20];

int n;
int x[30], y[30], p[30];

int get(int bit){
	vector<pair<int, int>> tate, yoko; 
	int ans = LLONG_MAX;
	int cnt = 0;
	for(int i = 0;i < n;i++){
		if(bit & (1 << i)){
			tate.push_back({y[i], p[i]});
			yoko.push_back({x[i], p[i]});
			cnt += p[i];
		}
	}

	{
		sort(tate.begin(), tate.end());
		int tmp = 0;
		int now;
		for(int i = 0;i < tate.size();i++){
			tmp += tate[i].second;
			now = tate[i].first;
			if(tmp >= (cnt+1)/2) break;
		}

		int ret = 0;
		for(int i = 0;i < tate.size();i++){
			ret += abs(now-tate[i].first)*tate[i].second; 
		}
		chmin(ans, ret);
	}

	{
		sort(yoko.begin(), yoko.end());
		int tmp = 0;
		int now;
		for(int i = 0;i < yoko.size();i++){
			tmp += yoko[i].second;
			now = yoko[i].first;
			if(tmp >= (cnt+1)/2) break;
		}

		int ret = 0;
		for(int i = 0;i < yoko.size();i++){
			ret += abs(now-yoko[i].first)*yoko[i].second; 
		}
		chmin(ans, ret);
	}
	return ans;
}

int get2(int bit){
	int ans = 0;
	for(int i = 0;i < n;i++){
		if(!(bit & (1 << i))){
			ans += min(abs(x[i]), abs(y[i]))*p[i];
		}
	}
	return ans;
}

int memo[(1 << 15)];
signed main(){
	cin >> n;
	for(int i = 0;i < (1 << n);i++){
		dp[i][0] = 0;
		for(int j = 1;j < 20;j++){
			dp[i][j] = LLONG_MAX/10;
		}
	}

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

	cout << get2(0) << endl;

	int aa = LLONG_MAX;
	for(int i = 0;i < (1 << n);i++){
		memo[i] = dp[i][1] = get(i); 
		chmin(aa, dp[i][1]+get2(i));
	}
	cout << aa << endl;

	for(int k = 2;k <= n;k++){
		int ans = LLONG_MAX;
		for(int b = 0;b < (1 << n);b++){
			for(int b2 = b;b2 >= 0;b2 = (b2-1)&b){
				chmin(dp[b][k], dp[b2][k-1] + memo[b^b2]);
				if(b2 == 0) break;
			}
			chmin(ans, dp[b][k]+get2(b));
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 8980
def func(var):
    res = 1 if all(c in str(var) for c in '357') else 0
    if var > N:
        return 0
    else:
        for v in 3, 5, 7:
            res += func(var * 10 + v)
    return res


N = int(input())
res = 0
for v in 3, 5, 7:
    res += func(v)
print(res)


Measured memory_bytes: 2940
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;

int main()
{
	FAST;
	int n;
	int arr[10];

	cin >> n;
	int sum = 0;
	int m = INT_MIN;
	for(int i=0 ; i<n ; i++)
	{
		cin >> arr[i];
		m = max(arr[i] , m);
		sum += arr[i];
	}

	sum += (-m + (m/2));
	cout << sum;
	return 0;
}

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

ll mod = 1e9 + 7;

int main() {
    ll n, d, ans = 0;
    cin >> n >> d;
    vector<ll> x(n), y(n);
    for(int i=0; i<n; i++) cin >> x[i] >> y[i];
    ll dist = d * d;
    for(int i=0; i<n; i++) {
        ll l = x[i] * x[i] + y[i] * y[i];
        if(dist >= l) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6392
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>
#define lint int64_t
typedef pair<int, int> PII;
#define INF 10000
typedef long long int ll;

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

  vector<int> hi(N);
  rep(i,N) cin >> hi[i];

  vector<ll> f(N);

  f[0] = 0;
  f[1] = abs(hi[1] - hi[0]);

  rep2(i,2,N){
    f[i] = min(abs(hi[i]-hi[i-2]) + f[i-2], abs(hi[i]-hi[i-1]) + f[i-1]);
  }

  cout << f[N-1] << endl;
}


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



int main()
{
	int n,j=0;
	cin>>n;
	int z=n;
	double arr[n+10];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	sort(arr, arr+n);
	while(z>1)
	{
		arr[j+1]=(arr[j]+arr[j+1])/2;
		arr[j]=0;
		j++;
		sort(arr+j-1,arr+n);
		z--;
	}
	cout<<arr[n-1];
}

Measured memory_bytes: 256
package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func newLine() int {
  sc.Scan()
  i, e := strconv.Atoi(sc.Text())
  if e != nil {
    panic(e)
  }
  return i
}

func main() {
  var N int 
  var A []int 

  sc.Split(bufio.ScanWords)

  // n枚を変数にする
  fmt.Scanf("%d", &N)
  // カードをarrayに落とし込む
  for i := 1; i <= N; i++ {
    A = append(A, newLine())
  }

  // sort
  //sort.Ints(a)
  sort.Sort(sort.Reverse(sort.IntSlice(A)))

  fmt.Println(A[0] - A[N-1])
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

ll CalcPow(ll n, ll r) {
    if (r == 0) {
        return 1ll;
    }
    if (r == 1) {
        return n;
    }
    if (r%2 == 0) {
        ll Temp = CalcPow(n, r/2);
        return Temp * Temp % MOD;
    } else {
        return n * CalcPow(n, r-1) % MOD;
    }
}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    
    vector<ll> Num(K+1);
    for (int k = K; k >= 1; --k) {
        Num[k] = CalcPow(K/k, N);
        for (int m = 2*k; m <= K; m += k) {
            Num[k] = (MOD + Num[k] - Num[m]) % MOD;
        }
    }
    
    ll Res = 0;
    for (int k = 1; k <= K; ++k) {
        Res = (Res + k * Num[k] % MOD) % MOD;
    }
    cout << Res << endl;

    return 0;
}


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

int main() {
  string ops;
  cin >> ops;
  int a = 0;
  for (int i = 0; i < 4; i++) {
    if (ops.at(i) == '+') {
      a++;
    }
    if (ops.at(i) == '-') {
      a--;
    }
  }
  cout << a << endl;
}

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

int a[30];
string _min, _max;
int buf, L;

void solve() {
  for(int i = 1; i < 21; ++i) {
    // L桁に整形
    ostringstream ss;
    ss << setw(L) << setfill('0') << a[i - 1];
    string s(ss.str());

    // 辞書順最大と最小を求める
    sort(s.begin(), s.end());
    _min = s;
    reverse(s.begin(), s.end());
    _max = s;

    // a_iを求める
    a[i] = stoi(_max) - stoi(_min);
    //cout << _max << " - " << _min << " = " << a[i] << endl;
    s = to_string(a[i]);

    // a_i = a_j を満たす最小のiを求める
    for(int j = 0; j < i; ++j) {
      if(a[j] == a[i]) {
        cout << j << ' ' << a[i] << ' ' << i - j << endl;
        return;
      }
    }
  }
}

int main() {
  while(cin >> a[0] >> L && a[0] && L) solve();
  return 0;
}



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

#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()

const int NAX = 2e5 + 5, MOD = 1000000007;

struct Solution
{
    Solution() {}
    void solveCase();
};

void Solution::solveCase()
{
    int s;
    cin >> s;
    vector<int> dp(s + 1);
    dp[0] = 1;
    for (int i = 1; i <= s; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            if (i - j >= 3)
            {
                dp[i] += dp[j];
                dp[i] %= MOD;
            }
        }
        db(i, dp[i]);
    }
    cout << dp[s] << '\n';
}

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef LOCAL
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 3656
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
      	int[] arrs = new int[n + 1];
      	for (int i = 1; i <= n; i++) {
        	arrs[i] = sc.nextInt();
        }
		int result = 0;
      	for (int i = 1; i <= n; i++) {
        	result += Math.max(arrs[i] - arrs[i - 1], 0);
        }
      	System.out.println(result);
    }
}

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

#define int long long

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

 	int a, b;
 	cin >> a >> b;
 	if(b > a){
 	    swap(a, b);
 	}	
 	for(int i = 0; i < a; i++)
 		cout << b;
 	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e9
typedef long long ll;
typedef pair<ll,ll> P;
unsigned long long popCount64bitB(unsigned long long x) 
{ 
    x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) 
      +  (x & 0x5555555555555555UL); 
    x = ((x & 0xccccccccccccccccUL) >> 2) 
      +  (x & 0x3333333333333333UL); 
    x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) 
      +  (x & 0x0f0f0f0f0f0f0f0fUL); 
    x = ((x & 0xff00ff00ff00ff00UL) >> 8) 
      +  (x & 0x00ff00ff00ff00ffUL); 
    x = ((x & 0xffff0000ffff0000UL) >> 16) 
      +  (x & 0x0000ffff0000ffffUL); 
    x = ((x & 0xffffffff00000000UL) >> 32) 
      +  (x & 0x00000000ffffffffUL); 
    return x; 
} 

int main(void){
    int ans=0;
    string s;
    cin>>s;
    int i=0;
    if(s.length()==1)ans=1;
    else{
        string pre="";
        for(int i=0;i<s.length();i++){
            if(i+2==s.length()){
                if(s[i]==s[i+1]){
                    ans++;
                    i+=2;
                    continue;
                }
            }
            if(s.substr(i,1)==pre){
                pre=s.substr(i,2);
                i++;
            }
            else{
                pre=s.substr(i,1);
            }
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int h, w, n;
  cin >> h >> w >> n;
  vector<pair<int, int>> o(n);
  for (int i = 0; i < n; ++i) {
    int r, c;
    cin >> o[i].first >> o[i].second;
  }
  sort(o.begin(), o.end());
  int b = 0, ans = h + 1;
  for (auto p : o) {
    int y = p.first, x = p.second;
    if (y - x == b) {
      ++b;
    } else if (y - x > b) {
      ans = y;
      break;
    }
  }
  cout << ans - 1 << endl;
  return 0;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
   ll k; cin>>k;
   ll now  = 7 % k;
   rep(i,1e+6){
       if(now == 0) {
           cout<< i + 1 <<endl;
           return 0;
       }else now = (10 * now % k + 7 % k) % k; 
   }
   cout<< -1 <<endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
using namespace std;

int main(){
  int a,p; cin>>a>>p;
  int total=a*3+p;
  if (total%2==0) cout<<total/2<<endl;
  else cout<<(total-1)/2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr int MOD = 1000000007;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

VL prime_decomposition(ll n) {
	ll i = 2;
	VL table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace_back(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace_back(n);
		return table;
	}
	return table;
}

int main() {
	int n;
	cin >> n;
	VL v(n);
	REP(i, n) { cin >> v[i]; }

	ll v1 = 0, v2 = 0, v4 = 0;
	REPC(t, v) {
		if (t % 4 == 0) { ++v4; }
		else if (t % 2 == 0) { ++v2; }
		else { ++v1; }
	}

	int now = 4;
	REP(i, n) {
		if (now == 4) {
			if (v1 == 0) {
				cout << "Yes" << endl;
				return 0;
			}
			--v1;
			now = 1;
		} else if (now == 2) {
			if (v1 == 0) {
				cout << "Yes" << endl;
				return 0;
			}
		} else {
			if (v4 == 0) {
				cout << "No" << endl;
				return 0;
			}
			--v4;
			now = 4;
		}
	}
	cout << "Yes" << endl;
}

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

int main() {
  int n;
  cin >> n;
  int maxm = -1;
  int cnt = 0;
  rep(i, n) {
    int h;
    cin >> h;
    if(h >=maxm) {
      maxm = h;
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int root[114514], depth[114514];

// xの根を求める
int find(int x){
	if(root[x]==x){
		return x;
	}
	else{
		return root[x]=find(root[x]);
	}
}

// xとyが属する集合を併合
void unite(int x, int y){
	x=find(x);
	y=find(y);
	if(x==y){
		return;
	}
	if(depth[x]<depth[y]){
		root[x]=y;
	}
	else{
		root[y]=x;
		if(depth[x]==depth[y]){
			++depth[x];
		}
	}
	return;
}

// xとyが同じ集合に属するか判定
bool same(int x, int y){
	return find(x)==find(y);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, p, pp[114514], x, y;
	cin>>n>>m;
	REP(i, n){
		cin>>p;
		pp[i]=p-1;
	}
	// 初期化
	REP(i, n){
		root[i]=i;
		depth[i]=0;
	}
	REP(i, m){
		cin>>x>>y;
		unite(x-1, y-1);
	}
	int ans=0;
	REP(i, n){
		ans+=same(pp[i], i);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1408
S=input()
if len(S)%2==0:
    S1=S[:len(S)//2]
    S2=S[len(S)//2:][::-1]
else:
    S1=S[:len(S)//2]
    S2=S[len(S)//2+1:][::-1]

ans=0
for i in range(len(S1)):
    if S1[i]!=S2[i]:
        ans+=1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> cnt(N, 0);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        ++cnt[a - 1];
        ++cnt[b - 1];
    }
    bool judge = true;
    rep(i, N) {
        if (cnt[i] % 2) judge = false;
    }
    cout << (judge ? "YES\n" : "NO\n");
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


ll a[33];



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


  cin >> n;
  rep(i, n) cin >> a[i];
  FOR(i, 1, n - 1) {
    if (a[i] > a[i - 1] && a[i] < a[i + 1])ans++;
    if (a[i] < a[i - 1] && a[i] > a[i + 1])ans++;
  }
  cout << ans << endl;





  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        #include <chrono>
      
        using namespace std;
        using namespace std::chrono; 
     
        typedef long long int ll;
     
        #define MOD (ll)(1e9+7)
        #define endl "\n"
        #define pb push_back
        #define TEST_CASES  ll t;cin>>t;while(t--)
        #define forn(i,a,n) for (int i = a; i < n; ++i)
        #define f first
        #define s second
        #define all(x) x.begin(), x.end()


        
        ll powD(ll x,ll y){
          ll res = 1;
          while(y > 0){
            if(y & 1)
              res = (res*x)%MOD;
            x = (x*x)%MOD;
            y = y>>1;
          }
          return res;
        }
    
        int main()
        {
          ios_base::sync_with_stdio(false);
          cin.tie(NULL);
          int n;
          cin>>n;
          vector<int> a(n),cnt(1e6+1,0);
          forn(i,0,n){
            cin>>a[i];
            cnt[a[i]]++;
          }
          if(cnt[1] == 1){
            cout<<1<<endl;
            return 0;
          }
          int ans = 0;
          forn(i,0,n){
            if(cnt[a[i]] > 1)
              continue;
            bool flag = 1;
            for (int j = 1; j*j <= a[i]; ++j)
            {
              if(a[i]%j == 0 && (cnt[j] || (j == 1 ? 0 : cnt[a[i]/j])) ){
                flag = 0;
                break;
              }
            }
            if(flag)
              ans++;
          }
          cout<<ans<<endl;
        }

        
      


Measured memory_bytes: 7956
#include<stdio.h>
#define ll long long
#define MOD 1000000007

ll dp[110][10];
ll coe[]={1,1,2,3,5,8,13,21,34};
int main(){
	int h,w,k;
	scanf("%d%d%d",&h,&w,&k);
	dp[0][1]=1;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			//もらうDP
			ll temp=0;
			temp+=dp[i-1][j  ]*coe[j-1]*coe[w-j];
			if(j!=1)temp+=dp[i-1][j-1]*coe[j-2]*coe[w-j];
			if(j!=w)temp+=dp[i-1][j+1]*coe[j-1]*coe[w-j-1];
			dp[i][j]=temp%MOD;
		}
	}
	printf("%d",dp[h][k]);
}

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

int main(){
double siita,a,b,c;
cin>>a>>b>>c;
siita=c/360*2*acos(-1);
printf("%.8lf\n%.8lf\n%.8lf\n",a*b*sin(siita)*0.5,a+b+sqrt(a*a+b*b-2*a*b*cos(siita)),a*b*sin(siita)/a);
return 0;
}


Measured memory_bytes: 3456
N = int(input())
X = list(map(int, input().split()))
a = 0
b = 0
l = []
for j in range(1,101):
    for i in X:
    
        a = abs((i-j)**2)
        b = b + a
    l.append(b)
    b = 0

print(min(l))


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

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    input! {
        n:usize,
        mut a:[usize;n],
    }

    let sum = a.iter().sum::<usize>();

    for i in 1..n {
        if a[i] < a[i - 1] {
            a[i] = a[i - 1];
        }
    }

    let after = a.iter().sum::<usize>();

    println!("{}", after - sum);
}


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

int main(){
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for(int i = 0; i <= n; i++) for(int j = 0; j <= m; j++) if(k == i * j + (n - i) * (m - j)){ puts("Yes"); return 0;}
puts("No");
}

Measured memory_bytes: 256
N,K = gets.split.map(&:to_i)
  p   = gets.split.map(&:to_i)


  pExp = [] #期待値配列
  N.times do |i|
    pExp[i] = (p[i]+1) / 2.to_f
  end

  pSum = [] #期待値合計配列
  pSum[0] = pExp[0,K].inject(:+)
  (1..(N-K)).each do |i|
    pSum[i] = pSum[i-1] - pExp[i-1] + pExp[i+K-1]
  end

  puts pSum.max

Measured memory_bytes: 18380
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B) =  explode(" ",trim(fgets(STDIN)));
$d = explode(" ",trim(fgets(STDIN)));

$tot = 0;
for($i=0;$i<$N;$i++) {
  for($j=$i;$j<$N;$j++) {
    if ($i==$j) continue;
    $tot += $d[$i]*$d[$j];
  }
}
printf("%d\n",$tot);


Measured memory_bytes: 4728
import java.util.*;
import java.util.regex.Pattern;

public class Main {

  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int result = 0;
    
    Pattern p = Pattern.compile("");
    
    for(int i = 1; i <= n; i++){
      
      int sum = p
        .splitAsStream(String.valueOf(i))
        .mapToInt(Integer::valueOf)
        .sum();
      
      if(sum >= a && sum <= b){
        result += i;
      }
      
    }
    
    System.out.println(result);

  }

}

Measured memory_bytes: 33144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////
 
 
int main() {
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    rep(i,n) {
        rep(j,n-1) {
            cin >> a[i][j];
            a[i][j]--;
        }
        reverse(a[i].begin(), a[i].end());
    }
    typedef pair<int, int> P;
    vector<P> que;
 
    auto add = [&](int i) -> void {
        if (!a[i].size()) return;
        int j = a[i].back();
        if (a[j].back() == i) {
            que.emplace_back(i,j);
            if (que.back().first > que.back().second) {
                swap(que.back().first, que.back().second);
            }
        }
    };
 
    rep(i,n) add(i);
 
    int ans = 0;
    while (que.size()) {
        ans++;
        sort(que.begin(), que.end());
        que.erase(unique(que.begin(), que.end()), que.end());
        vector<P> copy;
        swap(copy, que);
        for (auto v : copy) {
            int i = v.first, j = v.second;
            a[i].pop_back();
            a[j].pop_back();
        }
        for (auto v : copy) {
            int i = v.first, j = v.second;
            add(i);
            add(j);
        }
    }
 
    rep(i,n) {
        if (a[i].size()) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int total, step;
    vector<int> person;
    vector<int>::iterator it;
    int i, m;

    while(1){
        //get input
        cin >> total >> step;

        //finish condition
        if(total == 0 && step == 0) break;

        //init
        for(i = 1; i <= total; i++){
            person.push_back(i);
        }
        it = person.begin();
        
        while(1){
            //answer
            if(person.size() == 1){
                cout << person[0] <<endl;
                person.clear();
                break;
            }

            //step forward
            for(m = 0; m < (step - 1); m++){
                it++;                
                if(it == person.end()){
                    it = person.begin();
                }
            }

            //delete
            person.erase(it);
            if(it == person.end()){
                it = person.begin();
            }

//            for(int k = 0; k < person.size(); k++){
//                cout << *it <<"is erased " << person[k] << endl;
//            }
        }
    }

    return 0;
}

Measured memory_bytes: 3012
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;

int main(){
    ll a[6];
    ll ans=0;
    ll mi=1e16;
    int mii=-1;
    for(int i=0;i<=5;i++){
        cin >> a[i];
        if(a[i]<mi){
            mi=a[i];
            mii=i;
        }
    }
    cerr << mi << " " << mii << endl;
    if(a[0]%mi==0){
        ans=a[0]/mi;
    }else{
        ans=a[0]/mi+1;
    }
    if(a[0]==mi){
        cout << 5 << endl;
    }else{
        cout << ans +5 - mii + mii-1<< endl;
    }
    return 0;
}
/*
int main(){
    ll N; cin >> N;
    ll a[5];
    for(int i=0;i<5;i++){
        cin >> a[i];
    }
    vector<ll> s(6,0);
    s[0]=N;
    ll cnt=0;
    int lp=0;
    while(true){
        cnt++;
        vector<ll> tmp(5,0);
        for(int i=0;i<5;i++){
            if(s[i]<=0){
                continue;
            }
            if(i>=1 && tmp[i-1]>0){ //直前に移動した人は移動できない
                tmp[i] = min<ll>(a[i],s[i]-tmp[i-1]);
            }else{
                tmp[i] = min<ll>(a[i],s[i]); //移動した人数
            }
            s[i+1] += tmp[i];
            s[i] -= tmp[i];
        }
        for(int j=0;j<=5;j++){
            cerr << s[j] << " ";
        }
        cerr << "\n";
        if(s[5]==N){
            break;
        }
    }
    cout << cnt << endl;
    return 0;
}
*/

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    int max_a = 0, ans = 0;
    while (n--) {
        int a, b;
        cin >> a >> b;
        if (a > max_a) {
            max_a = a;
            ans = a + b;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3600
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

def nCr(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod

def prep(n, mod):
    for i in range(2, n):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)


def main():
    n, k = list(map(int, input().split()))
    mod = 10 ** 9 + 7
    prep(10**6, mod)
    a = nCr(n + n - 1, n - 1, mod)
    if k < n:
        t = 0
        for x in range(k + 1):
            t = (t + nCr(n, x, mod) * nCr(n - 1, x, mod)) % mod
        print(t)
    else:
        print(a)
    


main()


Measured memory_bytes: 127696
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        LiningUp solver = new LiningUp();
        solver.solve(1, in, out);
        out.close();
    }

    static class LiningUp {
        public static int MOD = 1_000_000_007;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            HashMap<Integer, Integer> map = new HashMap<>();
            for (int i = 1; i <= n; i++) {
                int left = i - 1;
                int right = n - i;
                int key = Math.abs(right - left);
                map.put(key, 0);
            }

            for (int i = 1; i <= n; i++) {
                int a = in.nextInt();
                if (!map.containsKey(a)) {
                    out.println(0);
                    return;
                }
                map.put(a, map.get(a) + 1);
            }
            long result = 1;
            for (int key : new ArrayList<>(map.keySet())) {
                if (key == 0) {
                    if (map.get(key) != 1) {
                        out.println(0);
                        return;
                    }
                } else {
                    if (map.get(key) != 2) {
                        out.println(0);
                        return;
                    }
                }
                result *= map.get(key);
                result %= MOD;
            }
            out.println(result);

        }

    }
}



Measured memory_bytes: 62576
#include <iostream>
using namespace std;
int main(){
  int n,y;
  cin >> n >>y;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n-i;j++){
          int sum=10000*i+5000*j+(n-i-j)*1000;
          if(sum==y){
            cout << i <<" "<< j <<" "<< n-i-j<< endl;
            return 0;
          }
      }
    }
  cout << -1<<" " <<-1 <<" " <<-1 <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
int h,w;
vector <int> g[20*20];
vector <int> d;
int mx=-1,ind=-1;
void bfs(int s)
{
    d=vector <int> (h*w,INF);
    d[s]=0;
    if (mx<d[s])
    {
        mx=d[s],ind=s;
    }
    queue<int> q;
    q.push(s);
    while (!q.empty())
    {
        int f=q.front();
        q.pop();
        for (auto to:g[f])
        {
            if (d[to]==INF)
            {
                d[to]=d[f]+1;
                if (mx<d[to])
                {
                    mx=d[to],ind=to;
                }
                q.push(to);
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    vector <int> x={1,-1,0,0};
    vector <int> y={0,0,1,-1};
    cin>>h>>w;
    vector <string> s(h);
    for (int i=0;i<h;i++)
        cin>>s[i];
    for (int i=0;i<h;i++)
    {
        for (int j=0;j<w;j++)
        {
            for (int k=0;k<4;k++)
            {
                if (i+x[k]>=0&&i+x[k]<h&&j+y[k]<w&&j+y[k]>=0)
                {
                    if (s[i][j]=='.'&&s[i+x[k]][j+y[k]]=='.')
                    {
                        g[i*w+j].pb((i+x[k])*w+j+y[k]);
                    }
                }
            }
        }
    }
    int u;
    for (int i=0;i<h*w;i++)
    {
        if (s[i/w][i%w]=='.')
        {
            bfs(i);
            u=i;
            break;
        }
    }
    for (int i=0;i<h*w;i++)
    {
        if (s[i/w][i%w]=='.')
        bfs(i);
    }
    cout<<mx;

}

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__);
#else
#define dbg(...) 
#endif

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

	int n, m;
	cin >> n >> m;
	vector<int> d(n);
	vector<pair<int, int>> e(m);
	vector<vector<pair<int, int>>> graph(n);
	for(int i=0; i<n; i++) cin >> d[i];
	for(int i=0; i<m; i++){
		cin >> e[i].first >> e[i].second;
		e[i].first--;
		e[i].second--;
		graph[e[i].first].push_back({e[i].second, i});
		graph[e[i].second].push_back({e[i].first, i});
	}

	vector<pair<int, int>> ds(n);
	for(int i=0; i<n; i++) ds[i] = {d[i], i};

	sort(ds.begin(), ds.end());

	vector<pair<int, int>> es;
	for(int i=0; i<m; i++){
		if(d[e[i].first]!=d[e[i].second]) continue;
		es.push_back({d[e[i].first], i});
	}
	sort(es.begin(), es.end());

	vector<int> c(n);
	vector<int> x(m, 1e9);

	for(int i=0; i<n; i++){
		int v=ds[i].second;
		if(c[v]>0) continue;
		bool done = false;
		for(auto p: graph[v]){
			int u = p.first;
			if(c[u]>0){
				c[v] = 3-c[u];
				x[p.second] = ds[i].first;
				done=true;
				break;
			}
		}
		if(done) continue;

		for(auto p: graph[v]){
			int u = p.first;
			if(d[u]==d[v]){
				c[u] = 1;
				c[v] = 2;
				x[p.second] = ds[i].first;
				done = true;
				break;
			}
		}
		if(!done){
			cout << -1 << endl;
			return 0;
		}
	}

	string ans;
	for(int i=0; i<n; i++){
		if(c[i]==1) ans += "B";
		else ans += "W";
	}
	cout << ans << endl;
	for(int i=0; i<m; i++){
		cout << x[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 15096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int mod = 1e9 + 7;

int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    for (int i = 0; i < n;i++){
        cin >> a[i] >> b[i];
    }
    vector<pair<int, int>> ab(n);
    for (int i = 0; i < n;i++){
        ab[i] = make_pair(a[i], b[i]);
    }
    sort(ab.begin(), ab.end());
    ll sum = 0;
    for (int i = 0; i < n;i++){
        if(m>0){
            int tmp = min(m, ab[i].second);
            sum += (ll)tmp * ab[i].first;
            m -= tmp;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAX = 1e4;

int n;
vector<int> v,array;
int tri[MAX+1];

void init(){
  int t = 1;
  tri[0] = 0;
  for(int i = 1 ; i <= MAX ; i++){
    tri[i] = tri[i-1] + t;
    t++;
  }
}

bool check(){
  int len = array.size();
  for(int i = 0 ; i < len ; i++){
    if(array[i] != i+1) return false;
  }
  return true;
}

void judge(){
  int LIMIT = MAX,cnt = 0;
  bool possible = false;

  while(LIMIT--){
    if(check()){
      break;
    }
    
    int s = 0, len = array.size();
    for(int i = 0 ; i < len ; i++){
      if(array[i]){
	array[i]--;
	s++; 
      }
    }
    array.push_back(s);
    for(int i = 0 ; i < len ; i++){
      if(!array[i]){
	array.erase(array.begin() + i);

      }
    }

    ++cnt;
  }
  if(check()) possible = true;
  if(possible) cout << cnt << endl;
  else cout << "-1" << endl;
}

int main(){ 
  init(); 
  while(cin >> n ,n){
    int in,sum = 0;
    array.clear();
    for(int i = 0 ; i < n ; i++){
      cin >> in;
      sum += in;
      array.push_back(in);
    }

    bool flg = false;
    for(int i = 1 ; i <= MAX ; i++){
      if(tri[i] == sum){
	flg = true;
	break;
      } 
    }

    if(!flg){
      cout << "-1" << endl;
    }
    else{
      judge();
    }
  }

  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ll  long long
#define mod 1000000007
#define ve vector
#define pi pair<int,int>
#define pb push_back
#define F first
#define S second
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int inf=1e9+5;
vector<ll>A,B;


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

void path(ll a,int state)
{
 for(ll i=2;i*i<=a;i++)
 {
  if(a%i==0)
  {
    if(state==0)A.push_back(a/i);
     else B.push_back(a/i);
      path(a/i,state);
      return ;
  }
 }
}

void solve()
{ 
   string s;
    cin>>s;
    int ans=0,cnt=0;
    for(char c:s)
    {
     if(c=='R')cnt++;
        else 
        {
         ans=max(ans,cnt);
            cnt=0;
        }
    }
    ans=max(ans,cnt);
    cout<<ans<<endl;
}

signed main()
{
//#ifndef ONLINE_JUDGE
    //  freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
//#endif
    FAST;
   
    
     int t=1;
    //cin>>t;
     while(t--)
    	solve();
    return 0;
}



Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	S := getString()
	fmt.Println(strings.Repeat("x", len(S)))
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

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

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return n * powMod(n, p-1)
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}


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

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

int main() {
  int64_t A,B,N;
  int64_t maxt=0;
  cin >> A >> B >> N;
  
  maxt=min(B-1,N);
  cout << (A*maxt)/B-A*(maxt/B) << endl;
      
}


Measured memory_bytes: 3648