akhauriyash/Code-Regression huggingface dataset:
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_list = []
    one_list = []
    for i in range(n):
        if i % 2 == 0:
            zero_list.append(num_list[i])
        else:
            one_list.append(num_list[i])

    zero_c = Counter(zero_list)
    one_c = Counter(one_list)

    zero_saihin_key = zero_c.most_common()[0][0]
    zero_saihin_val = zero_c.most_common()[0][1]
    one_saihin_key = one_c.most_common()[0][0]
    one_saihin_val = one_c.most_common()[0][1]

    if zero_saihin_key != one_saihin_key:
        print(n - zero_saihin_val - one_saihin_val)
        exit()

    if num_list.count(zero_saihin_key) == n:
        print(n//2)
        exit()

    if len(zero_c) == 1:
        zero_saihin_val2 = zero_saihin_val
    else:
        zero_saihin_val2 = zero_c.most_common()[1][1]

    if len(one_c) == 1:
        one_saihin_val2 = one_saihin_val
    else:
        one_saihin_val2 = one_c.most_common()[1][1]

    count1 = n - zero_saihin_val - one_saihin_val2
    count2 = n - zero_saihin_val2 - one_saihin_val

    print(min(count1, count2))

if __name__ == '__main__':
    main()


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

int A[303];
ll dp[303][101010],dp2[303][101010];

int main(){
  int N; cin>>N;
  int sum=0;
  rep(i,N){
    cin>>A[i];
    sum+=A[i];
  }
  ll ans=1;
  rep(i,N) (ans*=3)%=MOD;
  dp[0][0]=1;
  rep(i,N) rep(j,sum+1) if(dp[i][j]){
    (dp[i+1][j+A[i]]+=dp[i][j])%=MOD;
    // GとBに振り分ける
    (dp[i+1][j]+=dp[i][j]*2)%=MOD;
  }
  dp2[0][0]=1;
  rep(i,N) rep(j,sum+1) if(dp2[i][j]){
    (dp2[i+1][j+A[i]]+=dp2[i][j])%=MOD;
    // GとBの一方のみに振り分ける
    (dp2[i+1][j]+=dp2[i][j])%=MOD;
  }
  ll tmp1=0,tmp2=0;
  for(int i=sum/2+1;i<=sum;i++){
    (tmp1+=dp[N][i])%=MOD;
  }
  if(sum%2==0){
    (tmp2+=dp[N][sum/2])%=MOD;
    tmp2=(tmp2-dp2[N][sum/2]+MOD)%MOD;
  }
  // comb(3,1)とcomb(3,2)
  (tmp1*=3)%=MOD;
  (tmp2*=3)%=MOD;
  ans=((ans-tmp1+MOD)%MOD-tmp2+MOD)%MOD;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 475904
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(lli i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
#define deb(x) cout << #x": " << (x) << endl;


int main(){ _
    string a,b;
    cin >> a >> b;
    vector<lli> l(0);
    fore(i,0,sz(a)-sz(b)+1)
    {
      lli dif=0;
      fore(n,0,sz(b))
      {
        if(b[n]!=a[i+n])dif++;
      }
      l.pb(dif);
    }
    sort(all(l));
    cout << l[0] <<ENDL;
    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
using namespace std;
char s[105];
int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    for(register int i=1;i<=len;i++)
        if(s[i]=='C')  for(register int j=i+1;j<=len;j++)
            if(s[j]=='F')  return puts("Yes"),0;
    return puts("No"),0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        String s = S.substring(0,N/2) + S.substring(0,N/2);
        if(N%2 == 1) {
            System.out.println("No");            
        }else if(S.equals(s)) {
            System.out.println("Yes");
        }else {

            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23764
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
  	
  	let temp = Math.floor(N / 11);
  	let rest = N % 11;
  	
//   	console.log(temp)
//   	console.log(rest)
//     console.log(temp * 11)
    
//     console.log(temp * 2)

    console.log((temp * 2) + Math.ceil(rest / 6));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
import sys
k = int(input())
if k <= 9:
	print(k)
	sys.exit()

def judge(s):
	for i in range(1,len(s)):
		if abs(int(s[i-1]) - int(s[i])) > 1:
			return 0
	return 1

q = ['1','2','3','4','5','6','7','8','9']
cnt = 9
cond = False
while True:

	cp = q.pop(0)
	digit = int(cp[-1])
	for d in range(-1,2):
		if 0 <= digit + d <= 9:
			cnt += 1
			if cnt == k:
				ans = cp+str(digit+d)
				cond = True
				break
			q.append(cp+str(digit+d))
	
	if cond:
		break
print(ans)


Measured memory_bytes: 7724
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint s(n);
  int q,c;
  rep(i,n){
    cin>>s.at(i);
  }
  sort(all(s));
  cin>>q;
  ll count=0;
  rep(i,q){
    cin>>c;
    if(upper_bound(all(s),c)-lower_bound(all(s),c)!=0){
      count++;
    }
  }
  
  cout<<count<<'\n';
  return(0);
}


Measured memory_bytes: 3360
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (a >= b && a >= c) {
			System.out.print(b + c);
		} else if (b >= c && b >= a) {
			System.out.print(c + a);
		} else {
			System.out.print(a + b);
		}

	}
}

Measured memory_bytes: 22736
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
int main() {

	char c;

	cin >> c;

	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {

		cout << "vowel" << endl;

	}
	else {

		cout << "consonant" << endl;

	}

	return 0;
}

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

const int N = 1e6 + 11;
bool isPrime[N];
set<int> primes;


void pre() {
  fill (isPrime + 2, isPrime + N, true);
  for (int i = 2; i < N; i++){
    if (isPrime[i]){
      primes.insert(i);
      for (int j = 2; i * j < N; j++){
        isPrime[i * j] = false;
      }
    }
  }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    

    pre();
    int x;
    cin >> x;
    cout << *primes.lower_bound(x) << endl;
} 

Measured memory_bytes: 4864
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
 
//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
//const ll mod = 998244353 ;
const ll mod=1e9+7;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return ((a%mod)*1ll*b)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}


/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 

ll i,j,k,l,m,r,n;
ll a[MAX],b[MAX];


int main()
{
 
  #ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//cout << setprecision(15) << fixed;
fast

string s;
cin >> s;
if(s[1] == 'B')
	s[1]= 'R';
else
	s[1] = 'B';
cout << s;

  #ifndef ONLINE_JUDGE
  cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  #endif
 
  return 0;
 
}

Measured memory_bytes: 3648
A[20000];z(int*a,int*b){return*b-*a;}
main(n,i,j){for(;scanf("%d",&n),n;puts(i<n?"No":"Yes")){
for(i=0;i<n*2;i++)scanf("%d",A+i);
for(i=qsort(A,n,4,z);i<n;i++){for(j=0;j<n;j++)if(A[j+n])A[i]--,A[j+n]--;if(A[i])break;}
}exit(0);}

Measured memory_bytes: 736
using System;

namespace abc056
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            if (input[0] == "H")
            {
                Console.WriteLine(input[1]);
            }
            else
            {
                if (input[1] == "H")
                    Console.WriteLine("D");
                else
                    Console.WriteLine("H");
            }
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define d1(x) cout<<#x<<" "<<x<<endl;
#define d2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define d2i(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
#define all(v) v.begin(),v.end()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll dp[2002][2002];
ll comp(const pair<ll,ll>&a,const pair<ll,ll>&b){
  return a>b;
}
ll find(vector<pair<ll,ll>>&v,ll l,ll r){
  if(l>r)
  return 0; 
  ll n=v.size();
  ll id=(n-1)-(r-l);
  //if(id<0)
  //return 0;
  ll &ans=dp[l][r];
  if(ans!=-1)
  return ans;
  //d2(id,v[id].ff);
  
  ans=max(abs(v[id].ss-l)*v[id].ff+find(v,l+1,r),abs(v[id].ss-r)*v[id].ff+find(v,l,r-1));
  return ans;
   
}

void solve(){
  ll n;
  cin>>n;
  vector<pair<ll,ll>>v(n);
  fr(i,0,n){
    cin>>v[i].ff;
    v[i].ss=i;
  }
  mems(dp,-1);
  sort(all(v),comp);
  cout<<find(v,0,n-1);
  


}




int main(){
    ll t=1;
 // cin>>t;
  ll f=1;
    while(f<=t){
      //  cout<<"Case #"<<f<<": ";
        solve();
        cout<<endl;
        f++;
    }
    return 0;
}

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

long long INF=pow(10LL, 16LL);

int main(){
  long N, D, A;
  cin >> N >> D >> A;
  
  pair<long, long> monsters[N]; //place, hp
  for (int i = 0; i < N; i++) {
    long X, H;
    cin >> X >> H;
    monsters[i]={X,H};
  }
  sort(monsters, monsters+N);
  
  long comulativeDamage = 0L;
  long ans = 0L;
  queue<pair<long, long>> q; //maximumRange, Damage
  for (int i = 0; i < N; i++) {
    
    long x = monsters[i].first;
    long hp = monsters[i].second;

    long decreaseDamage = 0;
    while (!q.empty()){
      if (x <= q.front().first) break;
      decreaseDamage += q.front().second;
      q.pop();
    }
    
    comulativeDamage -= decreaseDamage;
    
    hp -= comulativeDamage;
    
    if (hp > 0L) {
      long atacks = (hp + A - 1L) / A;
      ans += atacks;
      comulativeDamage += A*atacks;
      q.push({x+2L*D,A*atacks});
    }
    
  }

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

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

class UnionFind {
public:
	UnionFind(int n) : par(n), rank(n) {
		for (int i = 0; i < n; i++)	par[i] = i;
	}
	int find(int x) {
		return par[x] == x ? x : par[x] = find(par[x]);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		} else {
			par[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
private:
	vector<int> par, rank;
};

int main() {
	int N, K, L;
	cin >> N >> K >> L;
	
	UnionFind uf1(N), uf2(N);
	for (int i = 0; i < K; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		uf1.unite(a, b);
	}
	for (int i = 0; i < L; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		uf2.unite(a, b);
	}
	
	map<int, int> gid1, gid2;
	vector<int> g1(N), g2(N);
	for (int i = 0; i < N; i++) {
		int p1 = uf1.find(i);
		int p2 = uf2.find(i);
		if (!gid1.count(p1)) {
			int id = gid1.size();
			gid1[p1] = id;
		}
		if (!gid2.count(p2)) {
			int id = gid2.size();
			gid2[p2] = id;
		}
		g1[i] = gid1[p1];
		g2[i] = gid2[p2];
	}

	map<pair<int, int>, int> nums;
	for (int i = 0; i < N; i++) {
		nums[make_pair(g1[i], g2[i])]++;
	}
	for (int i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << nums[make_pair(g1[i], g2[i])];
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 30848
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        if(int(i * 1.08) == n)
        {
            cout << i << "\n";
            return 0;
        }
    }
    cout << ":(\n";
    
    return 0;
}

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

using namespace std;
int main()
{
    int n,a,b;
    
    cin>>n>>a>>b;
    
    if((n*a)>=b)
        cout<<b;
    else 
        cout<<n*a<<endl;
    
    return 0;
}


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


#define INF 1000000007
using namespace std;

int main(){
  int n;
  cin >> n;
  long long a[n] = {0};
  for(int i = 0;i < n;i++){
    int b;
    cin >> b;
    a[b]++;
  }
  long long f = 1,sum = 1;
  
  if(n%2 == 1){
    if(a[0] != 1)
      f = 0;
    for(int i = 1;i < n;i++){
      if(i%2 == 0){
	if(a[i] != 2){
	  f = 0;
	  break;
	}
      }
      else{
	if(a[i] != 0){
	  f = 0;
	  break;
	}
      }
    }
    for(int i = 0;i < n/2;i++){
      sum = sum*2%INF;
    }
  }
  else{
    for(int i = 0;i < n;i++){
      if(i%2 == 1){
	if(a[i] != 2){
	  f = 0;
	  break;
	}
      }
      else{
	if(a[i] != 0){
	  f = 0;
	  break;
	}
      }
    }
    for(int i = 0;i < n/2;i++){
      sum = sum*2%INF;
    }
  }
  if(f == 1)
    cout << sum << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using namespace std;
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I,N) for(i8t I=0,I##_N=N;I<I##_N;I++)
#define FR(I,N) for(i8t I=N;I--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;

i8t calc_gcd(i8t a,i8t b){
  if(a<b)swap(a,b);
  while (1){
    a%=b;
    if(a==0)return b;
    b%=a;
    if(b==0)return a;
  }
}

int main() {
  R(K);
  i8t sum=0;
  F(a,K)F(b,K){
    auto gcd2=calc_gcd(a+1,b+1);
    F(c,K){
      sum+=calc_gcd(gcd2,c+1);
    }
  }
  P(sum);
  return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
#include <cstdio>
#include <iostream>
#include <iomanip>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
using namespace std;
ll l = 1000000007;

float x[10] = {};
string u[10] = {};


int main()
{
	int n;
	float ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> x[i] >> u[i];
		if (u[i] == "BTC") {
			ans += x[i] * 380000.0;
		}
		else {
			ans += x[i];
		}

	}

	cout << fixed << setprecision(5) << ans << endl;


}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    D=LI()
    #同じ時差の都市に対して3人以上いる場合は0
    if 0 in D:
        print(0)
        exit()
    if D.count(12)>=2:
        print(0)
        exit()
    
    temp=[0]*24
    temp[0]=1
    if 12 in D:
        temp[12]=1
    
    d=[]
    cnt=0
    for i in range(1,12):
        if D.count(i)==1:
            d.append(i)
            cnt+=1
        elif D.count(i)==2:
            temp[i]=1
            temp[24-i]=1
        elif D.count(i)>=3:
            print(0)
            exit()
            
            
    ans=[]
    
    for i in range(1<<cnt):
        temp2=[0]*24
        
        #コピー
        for k in range(24):
            temp2[k]=temp[k]
        
        for j in range(cnt):
            if i>>j & 1:
                temp2[d[j]]=1
            else:
                temp2[24-d[j]]=1
                
        aaa=24
        for ii in range(24):
            for jj in range(ii+1,24):
                if temp2[ii]==1 and temp2[jj]==1:
                    diff=min(jj-ii,24-(jj-ii))
                    if diff<aaa:
                        aaa=diff
        ans.append(aaa)
    print(max(ans))
            
    
        

main()


Measured memory_bytes: 73484
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
typedef long long int ll;

int main()
{
	int N, K, dp[10000000] = {};
	cin >> N >> K;
	vector<int>h(N);
	for (int i = 0; i < N; i++)cin >> h[i];
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < N; i++)
	{
		dp[i]=1000000000;
		for(int j=max(i-K,0);j<i;j++)
		{
			dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
		}
	}
	cout << dp[N - 1];
}


Measured memory_bytes: 39680
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,n,i,j,e;
    scanf("%d%d",&x,&n);
    int a[n+1];
    map<int,int>m;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        m[a[i]]++;
    }
    if(m.find(x)==m.end())
      printf("%d\n",x);
    else{
        i=1;
        e=0;
        while(1){
            if(e==0){
               if(m.find(x-i)==m.end()){
                  printf("%d\n",x-i);
                  break;
               }
               else{
                   e=1;
               }
            }
            else{
                if(m.find(x+i)==m.end()){
                   printf("%d\n",x+i);
                   break;
                }
                else{
                    e=0;
                    i++;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3784
main=map read.words<$>getLine>>=print.(\x->f(if(even x)then 2 else 1)3(g x 2)).(\(a:[b])->gcd a b)
 where f ans uo hai | hai==1    = ans
                    | uo*uo>hai = ans+1
                    | (mod hai uo)==0 = f (ans+1) (uo+2) (g hai uo)
                    |otherwise  = f ans (uo+2) hai
       g x i = if(mod x i)==0 then(g(quot x i)i)else x

Measured memory_bytes: 1020
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)


long long gcd(long long a, long long b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

long long lcm(long long a, long long b)
{
    return a / gcd(a, b) * b;
}


int main(){
    int n;
    cin >> n;
    long long t[n];
    rep(i,n) cin >> t[i];
    long long ans = 1;

    rep(i,n){
        ans = lcm(ans,t[i]);
    }
    cout << ans;
    

    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
    return 0;
}


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

using namespace std;

int main(){
        int a[200001];
        vector <int> b;
        int N;
        cin>>N;
        for(int i=0;i<N;i++){
                cin>>a[i];
        }
        for(int i=0;i<N;i++){
                if(i%2==0)
                        b.push_back(a[i]);
                else
                        b.insert(b.begin(), a[i]);
        }
        if(N%2==1){
                reverse(b.begin(), b.end());
        }
        for(int i=0;i<N;i++){
                cout<<b[i];
                if(i!=N-1)cout<<" ";
                else cout<<endl;
        }
        return 0;
}


Measured memory_bytes: 3828
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>

using namespace std;

int main() 
{
	int N, L;
	cin >> N >> L;
	
  int min = 100 + 200 - 1, sum = 0;
	for (int i = 0; i < N; ++i) {
		int taste = L + (i + 1) - 1;
		if (abs(min) > abs(taste)) min = taste;
		sum += taste;
	}
	cout << sum - min << endl;
}


Measured memory_bytes: 256
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let T = read![f64, String; N];

    let mut yen = 0.0;

    for i in 0..N {
        let &(v, ref c) = &T[i];

        if c == "JPY" {
            yen += v;
        } else {
            yen += v * 380000.0;
        }
    }

    println!("{}", yen)
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
//const int INF = 100100100;
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

#define equals(a,b) (fabs((a) - (b)) < EPS)

class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0) : x(x), y(y) {}

	Point operator+(Point p) { return Point(x + p.x, y + p.y); }
	Point operator-(Point p) { return Point(x - p.x, y - p.y); }
	Point operator*(double a) { return Point(a * x, a * y); }
	Point operator / (double a) { return Point(x / a, y / a); }

	double norm() { return x * x + y * y; }
	double abs() { return sqrt(norm()); }

	bool operator<(const Point & p) const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator==(const Point & p) const {
		return fabs(x - p.x) < EPS and fabs(y - p.y) < EPS;
	}
};

typedef Point Vector;
typedef vector<Point> Polygon;

double dot(Vector a, Vector b) {
	return a.x* b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x* b.y - a.y * b.x;
}

class Segment {
public:
	Point p1, p2;
	Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
};

class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
};

//直交判定
bool isOrthogonal(Vector a, Vector b) {
	return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
	return isOrthogonal(a1 - a2, b1 - b2);
}

bool isOrthogonal(Segment s1, Segment s2) {
	return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

//平行判定
bool isParallel(Vector a, Vector b) {
	return equals(cross(a, b), 0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2) {
	return isParallel(a1 - a2, b1 - b2);
}

bool isParallel(Segment s1, Segment s2) {
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

//線分sに対する点pの射影
Point project(Segment s, Point p) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base * r;
}

signed main() {
	//ios::sync_with_stdio(false);
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int q;
	cin >> q;
	Segment seg = Segment(Point(x1, y1), Point(x2, y2));
	rep(i, q) {
		int x, y;
		cin >> x >> y;
		Point p = project(seg, Point(x, y));
		printf("%.9f %.9f\n", p.x, p.y);
	}
	return 0;
}




Measured memory_bytes: 3212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            //ここから
            int N = IO.ReadLineToInt();
            int[] s = new int[N];
            for(int i = 0; i < N; i++)
            {
                s[i] = IO.ReadLineToInt();
            }

            s = s.OrderBy(o=>o).ToArray();

            var sum = s.Sum();
            if (sum % 10 == 0)
            {
                int min = s.Where(w => w % 10 != 0).FirstOrDefault();
                sum = min == 0 ? 0 : sum-(int)min;
            }

            //ここまで

            Console.WriteLine(sum);
            Console.ReadKey();
        }

    }

    static class Func
    {
        static public long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); }


        public static double ToAngle(this double radian)
        {
            return (double)(radian * 180 / Math.PI);
        }

        public static double ToRadian(this double angle)
        {
            return (double)(angle * Math.PI / 180);
        }

        static public long Conbination(long n, long m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * Conbination(n - 1, m - 1) / m;
        }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }

        static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }

        static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }

        static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }

        static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 13396
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define int long long
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
const int MAXN = 5e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
signed main(){
#ifndef ONLINE_JUDGE
    //freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
#endif // ONLINE_JUDGE
    int n,a,b; cin>>n>>a>>b;
    if(a>b) swap(a,b);
    if((b-a)&1) cout<<min(a+(b-a-1)/2,(n-b+1)+(n-(a+n-b+1))/2)<<endl;
    else cout<<(b-a)/2<<endl;
    return 0;
}


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

#define pb push_back

void solution(int n, vector<vector<int> >& days);
void solution1(int n, vector<vector<int> >& days);

int main(void){
	int n;
	cin >> n;
	vector<vector<int> > days(n, vector<int>(3));
	for(int i = 0;i < n;i++){
		cin >> days[i][0];
		cin >> days[i][1];
		cin >> days[i][2];
	}
	solution(n, days);
	solution1(n, days);
}

// iterative
void solution(int n, vector<vector<int> >& days){
	vector<vector<int> > dp(n, vector<int>(3, -1));
	dp[0][0] = days[0][0];
	dp[0][1] = days[0][1];
	dp[0][2] = days[0][2];
	for(int i =1;i < n;i++){
		for(int j = 0;j < 3;j++){
			dp[i][j] = max(dp[i][j], dp[i-1][(j+1)%3] + days[i][j]);
			dp[i][j] = max(dp[i][j], dp[i-1][(j+2)%3] + days[i][j]);
		}
	}
	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
	return;
}

// recursive
void solution1(int n, vector<vector<int> >& days){

}

Measured memory_bytes: 11136
#include <stdio.h>
#include <math.h>
 
typedef struct{
  double x,y;
}Point_t;
 
void kock(int n,Point_t p1,Point_t p2){
  Point_t s,t,u;
 
  if(n==0) return;
 
  s.x=(2*p1.x+1*p2.x)/3;
  s.y=(2*p1.y+1*p2.y)/3;
  t.x=(1*p1.x+2*p2.x)/3;
  t.y=(1*p1.y+2*p2.y)/3;
 
  u.x=(t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
  u.y=(t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;
 
  kock(n-1,p1,s);
  printf("%f %f\n", s.x,s.y);
  kock(n-1,s,u);
  printf("%f %f\n", u.x,u.y);
  kock(n-1,u,t);
  printf("%f %f\n", t.x,t.y);
  kock(n-1,t,p2);
}
 
int main(){
  int n;
  Point_t p1,p2;
 
  p1.x=0;
  p1.y=0;
 
  p2.x=100;
  p2.y=0;
 
  scanf("%d",&n);
 
  printf("%f %f\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
 
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define N 100005
using namespace std;
int a[N],dp[N];
int main(){
    int n,x,i;
    cin>>n;
    for(i=1; i<=n; ++i)
        cin>>a[i];
    dp[2]=abs(a[2]-a[1]);
    for(i=3; i<=n; ++i)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int X;
    cin >> X;
    int ans = 1;
    for(int i = 2; i <= X; i++){
        int now = i * i;
        while(now <= X){
            ans = max(ans, now);
            now *= i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long n,m,i,j,k,x,y,z;
    cin>>n>>m;
    x=0;
    for (i=0;i<m;i++)
    {
    	cin>>arr[i];
    	x+=arr[i];
	}
	y=n-x;
	if (y<0)
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<y<<endl;
	}
}

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

int main()
{
    int r, c, i, j;
    scanf("%d %d", &r, &c);
    int ans[r + 1][c + 1] = {};

    for (i = 0; i < r; i++)
    {
        for (j = 0; j < c + 1; j++)
        {
            if (j == c)
                ans[r][c] += ans[i][c];
            else
            {
                scanf("%d", &ans[i][j]);
                ans[i][c] += ans[i][j];
                ans[r][j] += ans[i][j];
            }
        }
    }

    for (i = 0; i < r + 1; i++)
    {
        for (j = 0; j < c + 1; j++)
        {
            if (j == c)
                printf("%d\n", ans[i][j]);
            else
                printf("%d ", ans[i][j]);
        }
    }
}


Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;

ll fast_exp(int base, int exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%MOD;
       base=(base*base)%MOD;
       exp/=2;
    }
    return res%MOD;
}

unordered_map<int,vector<int>> graph;
int N;
// #define black 1
// #define white 2 //1-black and 2-white
// vector<bool> visited;
vector<vector<int>> dp;
int dfs(int src,int color,int par){
    if(dp[src][color]!=-1){
        return dp[src][color];
    }
    
    //dp[src][color] = 1;
    ll ans=1;
    for(auto neigh:graph[src]){
        if(neigh!=par){
            if(color==0){
                ans = ans*(dfs(neigh,0,src)+dfs(neigh,1,src))%MOD;
            }
            else{
                ans = ans*dfs(neigh,0,src)%MOD;
            }
        }
    }
    
    return dp[src][color]=ans;
}
int main(){
   
   int n;
   cin>>n;
   N=n;
   int u,v;
   graph.clear();
    //visited.resize(n+1);
    dp.clear();
    dp.resize(n+1,vector<int>(2,-1));
    
   for(int i=1;i<=n-1;i++){
       cin>>u>>v;
       graph[u].push_back(v);
       graph[v].push_back(u);
   }
   
   ll ans = (dfs(1,1,0)+dfs(1,0,0))%MOD;
   cout<<ans<<endl;
   return 0;
}

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

using namespace std;

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

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

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

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

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

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m,k;
const int FMAX = 600002;
ll fact[FMAX];
ll ifact[FMAX];

ll modpow(ll a,ll b,ll c){
  ll r = 1;
  while(b){
    if(b&1)r=r*a%c;
    a=a*a%c;
    b>>=1;
  }
  return r;
}
ll modinv(ll a,ll c){
  return modpow(a,c-2,c);
}

int main(){
  scanf("%d%d%d",&n,&m,&k);
  // fact init
  fact[0] = 1;
  FOR(i,1,FMAX)fact[i]=fact[i-1]*i%MOD;
  ifact[FMAX-1]=modinv(fact[FMAX-1],MOD);
  FORR(i,0,FMAX-1)ifact[i]=ifact[i+1]*(i+1)%MOD;
  // a == n-1 && b <= m && c <= k
  ll ans = 0;
  int a = n-1;
  ll bipow = 1;
  ll subsum = 0;
  ll tris = modpow(3,m+k,MOD);
  ll invtri = modinv(3,MOD);
  ll factabc = (a==0?1:fact[a-1]);
  int befbeg,befend;
  FOR(s,0,m+k+1){
    int abc = a+s;
    if(abc!=0){
      factabc = factabc*abc%MOD;
    }
    ll unit = factabc*ifact[a]%MOD*ifact[s]%MOD*tris%MOD;
    tris = tris*invtri%MOD;

    int beg = max(s-k,0);
    int end = min(s,m);
    if(s>0){
      bipow <<= 1;
      subsum <<= 1;
      if(bipow>=MOD)bipow-=MOD;
      if(subsum>=MOD)subsum-=MOD;
      if(befbeg+1==beg){
        subsum += fact[s-1]*ifact[befbeg]%MOD*ifact[s-1-befbeg]%MOD;
        if(subsum>=MOD)subsum-=MOD;
      }
      if(befend==end){
        subsum += fact[s-1]*ifact[befend]%MOD*ifact[s-1-befend]%MOD;
        if(subsum>=MOD)subsum-=MOD;
      }
    }
    befbeg = beg;
    befend = end;
    ans += unit*(bipow+MOD-subsum)%MOD;
    if(ans>=MOD)ans-=MOD;
  }
  printf("%lld\n",ans);
  return 0;
}


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


#define ll long long int
#define ld long double
#define mod 1000000007
#define big 1e18+10
#define small -big
#define pb push_back
#define endl "\n"


template <typename T>

void prarr(T a)
{
     cerr << "[ ";
     
     for(auto i : a){
         cerr << i << " ";
     }
     
     cerr << "]" << endl;
}


#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char* name, Arg1&& arg1){
	cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char* names, Arg1&& arg1, Args&&... args){
    
	const char* comma = strchr(names + 1, ',');
	cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
	_er(comma+2, args...);
}





void solve() {
    
        ll n;
        cin >> n;
        
        char A[n + 1];
        
        set<ll> pos;
        for(ll i = 1; i <= n; i++) {
                cin >> A[i];
                if(A[i] == 'W') {
                    pos.insert(i);    
                }
        }
        
        ll c = 0;
        for(ll i = n; i >= 1; i--) {
                if(A[i] == 'R') {
                    
                    if(pos.size()) {
                        auto it = pos.begin();
                        if(*it < i) {
                                A[*it] = 'R';
                                A[i] = 'W';
                                c++;
                                pos.erase(it);
                        }
                    }
                }
        }
        
      
        cout << c << endl;
        
}


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

    int t = 1;
    //cin >> t;

    for(int i = 1; i <= t; i++) {  
   
         solve();
    }


    return 0;
        
}


Measured memory_bytes: 13144
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if ((n | m) == 0)
				break;
			int time[][] = new int[m + 1][m + 1];
			int cost[][] = new int[m + 1][m + 1];
			for (int i = 0; i < m + 1; i++) {
				Arrays.fill(time[i],Integer.MAX_VALUE/2);
				Arrays.fill(cost[i], Integer.MAX_VALUE/2);
				time[i][i] = 0;
				cost[i][i] = 0;
			}
			for (int i = 0; i < n; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				int c = sc.nextInt();
				int t = sc.nextInt();
				cost[a][b] = cost[b][a] = c;
				time[a][b] = time[b][a] = t;
			}
			for (int k = 1; k < m + 1; k++) {
				for (int i = 1; i < m + 1; i++) {
					for (int j = 1; j < m + 1; j++) {
						cost[i][j] = Math.min(cost[i][j], cost[i][k]
								+ cost[k][j]);
						time[i][j] = Math.min(time[i][j], time[i][k]
								+ time[k][j]);
					}
				}
			}
			int k = sc.nextInt();
			for (int i = 0; i < k; i++) {
				int p = sc.nextInt();
				int q = sc.nextInt();
				int r = sc.nextInt();
				System.out.println(r == 0 ? cost[p][q] : time[p][q]);
			}
		}
	}
}

Measured memory_bytes: 14000
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner in = new Scanner(System.in);

		char[] c = in.next().toCharArray();

		StringBuffer sb = new StringBuffer();
		sb.append("2018");
		for (int i = 4; i < c.length; i++) {
			sb.append(c[i]);
		}

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

	}

}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,k,a,s,ans,tr[200005];
pair<ll,ll> b[200005];
ll sum(ll p){
	ll res=0;
	while(p)res+=tr[p],p-=p&-p;
	return res;
}
void add(ll p){
	while(p<=n+1)tr[p]++,p+=p&-p;
}
int main(){
	n=read(),k=read();
	for(ll i=1;i<=n;i++){
		a=read();
		s+=a;
		b[i]={s-k*i,i};
	}
	sort(b,b+n+1);
	for(ll i=0;i<=n;i++){
		ans+=sum(b[i].second);
		add(b[i].second+1);
	}
	cout << ans;
	return 0;
}

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


int main() {
 int N, Y, k;
  cin >> N >> Y;
  
  string a = "no";
  
  if(Y%1000==0){
  
  for(int i=Y/10000;i>=0;i--){
    for(int j=(Y-10000*i)/5000;j>=0;j--){
      k= (Y-10000*i-5000*j)/1000;
        if(i+j+k==N){
          cout << i <<" " <<j <<" " << k <<endl;
          a="Yes";
          break;
        }
    }
  if(a=="Yes")break;
  }
  }
    
  if(a=="no"){
    cout <<-1 <<" " << -1 << " " << -1 <<endl;
  }
}
  

Measured memory_bytes: 3632