akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fi   first
#define se   second
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

const int N = 105, oo = 1e9 + 5, maxV = 1e5 + 5;
int dp[maxV + 5], w[N], v[N], W, n;

void input() {
	 scanf("%d %d", &n, &W);
	 FOR(i, 1, n) {
	 	scanf("%d %d", &w[i], &v[i]);
	 }
	 FOR(i, 1, maxV) dp[i] = oo;
	 dp[0] = 0;
}

void solve() {
	FOR(i, 1, n) {
		FORD(j, maxV, v[i]) {
			dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
		}
	}
	int res = 0;
	FOR(i, 1, maxV) if (dp[i] <= W) res = i;
	printf("%d\n", res);
}

int main(int argc, char const *argv[])
{

	input();
	solve();

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &i : v) os << i << ' ';
    return os;
}
void co() { cout << '\n'; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << '\n'; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void) {
    ll n;
    cin >> n;
    Vec a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) chmin(a[i], 3e5);

    ll l = 0, r = 3e5;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        map<ll, ll> mp;
        ll len = 0;
        rep(i, n){
            if (a[i] > len) {
                len = a[i];
                continue;
            }
            len = a[i];
            ll p = len;
            while(p >= 1 && mp[p] >= m - 1){
                --p;
            }
            mp.erase(mp.upper_bound(p), mp.end());
            mp[p]++;

            if (mp[0] != 0) break;
        }

        if (mp[0] == 0) r = m;
        else l = m;
    }
    co(r);

    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int const MOD = 1e9+7;

int main() {
  int N, M; cin >> N >> M;
  set<int> aset;
  rep(i, M) {
    int a; cin >> a; aset.insert(a);
  }
  vector<int> dp(N + 1);
  dp[0] = 1;
  REP(i, 1, N + 1) {
    if (aset.count(i)) continue;
    (dp[i] += dp[i - 1]) %= MOD;
    if (i - 2 >= 0) (dp[i] += dp[i - 2]) %= MOD;
  }
  cout << dp[N] << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, k;
    std::string s;
    std::cin >> n >> k >> s;
    int t = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) t++;
    }
    int r = std::min(n - 1 - t, 2 * k);
    std::cout << t + r << std::endl;

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
    int a,sumA = 0;
    int b,sumB = 0;
    int i;
    for(i = 0; i < 4; i++){
        scanf("%d",&a);
        sumA += a;
    }
    for(i = 0; i < 4; i++){
        scanf("%d",&b);
        sumB += b;
    }
    if(sumA >= sumB) printf("%d\n",sumA);
    else if(sumA < sumB) printf("%d\n",sumB);

    return 0;
}

Measured memory_bytes: 592
let xy = readLine()!.split(separator: " ").map { Int($0)! }
let (x, y) = (xy[0], xy[1])

if ((0...x).filter { t in
  let c = x - t
  if 2 * c + 4 * t == y {
    return true
  }
  return false
}.isEmpty) {
  print("No")
} else {
  print("Yes")
}


Measured memory_bytes: 8212
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll llINF=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  int n;
  cin>>n;
  vi x(n);
  rep(i,n) cin>>x[i];
  vi c(n);
  copy(x.begin(),x.end(),c.begin());
  sort(all(c));
  int cen=c[(n+1)/2];
  rep(i,n){
    if(x[i]>=cen){
      cout<<c[(n+1)/2-1]<<endl;
    }
    if(x[i]<cen){
      cout<<c[(n+1)/2]<<endl;
    }
  }
}

Measured memory_bytes: 4792
import sys
def input(): return sys.stdin.readline().rstrip()
def dfs(s,mxs):
    if len(s)==n:
        print(s)
    else:
        for i in range(ord('a'),ord(mxs)+1):
            dfs(s+chr(i),chr(i+1) if i ==ord(mxs) else mxs)

def main():
    global n
    n=int(input())
    dfs('','a')
    

if __name__=='__main__':
    main()

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

int main() {
  int currentRating = 0;
  int goalRating = 0;
  
  // 現在のレーティングと、目標のレーティングを入力
  cin >> currentRating >> goalRating;
  
  // 次のコンテストで取るパフォーマンスを出力
  cout << goalRating * 2 - currentRating << endl;
}

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

using namespace std;

class bit{
	
	public:
	vector<int> v;
	int n;

	bit(int arg){
		n = arg;
		//initially all nodes are 0
		for(int i=0;i<n+1;i++){
			v.push_back(0);
		}
	}
	
	int sum(int i){
		int s = 0;
		while(i>0){
			s += v[i];
			i -= i & -i;
		}
		return s;
	}
	
	void add(int i, int x){
		while(i <= n){
			v[i] += x;
			i += i & -i;
		}
	}
};

int main(void){
	int n,k;
	
	while(cin >> n >> k){
		if((n|k) == 0) break;
		
		bit b = bit(n);
		int tmp;
		vector<int> sumvec;

		//construct Binary Index Tree
		for(int i=1;i<=n;i++){
			cin >> tmp;
			b.add(i,tmp);
			//cerr << "added " << tmp << endl;
		}
		
		sumvec.push_back(0);
		//calculate sum
		for(int i=1;i<=n;i++){
			sumvec.push_back(b.sum(i));
			//cerr << sumvec[i] << endl;
		}
		
		int maxi = 0;
		for(int i=1;i<=n-k;i++){
			maxi = max(maxi, sumvec[i+k] - sumvec[i]);
		}
		
		cout << maxi << endl;
	}
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    int n;
    cin >> n;
    vi a(n + 1);
    vector<bool> foi(n + 1, false);

    fo(i, n) cin >> a[i + 1];

    int at = 1;
    int ans = 0;
    while ( true ) {
        if ( foi[at] or at == 2 ) break;

        foi[at] = true;
        ans++;
        at = a[at];
    }

    cout << (at == 2 ? ans : -1) << endl;

    return 0;
}

Measured memory_bytes: 640
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans = -LINF, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll dp[ohara][4];

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

  cin >> n;
  rep(i, n) cin >> a[i];

  rep(i, n) rep(j, 3) dp[i][j] = -LINF;

  if (n % 2 == 0) {
    for (ll i = n - 2; i >= 0; i -= 2) {
      dp[i][0] = max(dp[i + 2][0], dp[i + 2][1]) + a[i];
      dp[i][1] = dp[i + 2][1] + a[i + 1];
    }
    ans = max(dp[0][0], dp[0][1]);
    Cout(ans);
  } else {
    for (ll i = n - 2; i >= 0; i -= 2) {
      dp[i][0] = max(dp[i + 2][0], dp[i + 2][1]) + a[i];
      dp[i][1] = dp[i + 2][1] + a[i + 1];
      dp[i][2] = max({dp[i + 2][0], dp[i + 2][1], dp[i + 2][2]}) + a[i - 1];
    }
    ans = max({ans, dp[1][0], dp[1][1], dp[1][2]});
    Cout(ans);
  }
  return 0;
}


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

def main():
    n,m=map(int,input().split())
    Edges=[[] for _ in range(n)]
    for _ in range(m):
        a,b=map(int,input().split())
        a-=1; b-=1
        Edges[a].append(b)
        Edges[b].append(a)
        F=[]
        l=0
    for i,E in enumerate(Edges):
        e=len(E)
        if e%2:
            return 'No'
        if e==4:
            F.append(i)
        if e>=6:
            l+=1
    if l:
        return 'Yes'
    if len(F)<2:
        return 'No'
    if len(F)>2:
        return 'Yes'
    s,t=F[0],F[1]
    Visited=[False]*n
    Visited[s]=True
    for v in Edges[s]:
        fr=v
        while fr!=t:
            Visited[fr]=True
            for to in Edges[fr]:
                if not Visited[to]:
                    fr=to
                    break
            if Visited[fr]:
                break
        if fr!=t:
            return 'Yes'
    return 'No'

print(main())

Measured memory_bytes: 53424
//ABC 174 --> Put in review package later
/*Author: Aayush Khazanchi                                   Date: 02/08/20
 * 
 * 
 * */
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {  //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int x = I.nextInt();
		O.pln(x>=30?"Yes":"No");
	}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static long abs(long x, long y) {return Math.abs(x-y);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(max(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 25588
#include <bits/stdc++.h>
using namespace std;
vector< vector<long long int> > g(200005);
vector<long long int> ft;
long long int s[200005],e[200005],n,q;
void dfs(long long int u,long long int p)
{
	s[u]=ft.size();
	ft.push_back(0LL);
	for(long long int v:g[u])
	{
		if(v!=p)
		{
			dfs(v,u);
		}
	}
	e[u]=ft.size()-1;
}
int main()
{
	cin>>n>>q;
	for(long long int i=1;i<n;i++)
	{
		long long int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,0);
	ft.push_back(0);
	while(q--)
	{
		long long int x,y;
		cin>>x>>y;
		ft[s[x]]+=y;
		ft[e[x]+1]-=y;
	}
	for(int i=1;i<=n;i++)
	{
		ft[i]+=ft[i-1];
	}
	
	for(int i=1;i<=n;i++)
	{
		cout<<ft[s[i]]<<" ";
	}
	cout<<endl;
}


Measured memory_bytes: 30580
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int ans = 0;

void dfs(vector<int> A,int size_N, int size_Q,int size_M, int Qa[],int Qb[],int Qc[],int Qd[]){

    if(A.size() == size_N + 1) {
        int now = 0;
        for (int i = 0; i < size_Q; ++i) {
            if (A[Qb[i]] - A[Qa[i]] == Qc[i]) {
                now += Qd[i];
            }
        }
            if (ans < now) {
                ans = now;
            }
            return;

    }

    A.push_back(A.back());
    while(A.back() <= size_M) {
        dfs(A,size_N,size_Q,size_M,Qa,Qb,Qc,Qd);
        A.back()++;
    }
}


int main(){
    int n, m, num, i, as=1, bs;
    scanf("%d%d", &n, &m);
    bs = n / 2 + n % 2 + 1;
    num = bs;
    for(i = 0;i < m;i++){
        if(i % 2 == 0){
            printf("%d %d\n", as, num - as);
            as++;
        } else {
            if(n % 2 != 0)
                printf("%d %d\n", bs, n - bs + num);
            else
                printf("%d %d\n", bs, n - bs + num - 1);
            bs++;
        }
    }
    return 0;
}

int C(){
    int N, M, Q;
    scanf("%d %d %d", &N, &M, &Q);
    int Qa[Q];
    int Qb[Q];
    int Qc[Q];
    int Qd[Q];
    for (int i = 0; i < Q; ++i) {
        scanf("%d %d %d %d", &Qa[i], &Qb[i], &Qc[i], &Qd[i]);
    }
    dfs(vector<int>(1, 1), N, Q, M, Qa, Qb, Qc, Qd);
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

#define stoi stoll

int main() {
	string s;
	cin >> s;
	int len = s.size();
	LL ans = 0;
	string tmp;
	REP(i,0,1<<(len-1)) {
		tmp = "";
		REP(j,0,len-1) {
			tmp += s[j];
			if (i & (1<<j)) {
				ans += stoi(tmp);
				tmp = "";
			}
		}
		tmp += s[len-1];
		ans += stoi(tmp);
	}
	cout << ans << endl;
	
	return 0;
}

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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            
            
            var list = cin.ReadIntArray(N);
            List<int> ansList = new List<int>();
            
            for(int i =0; i<N; i++){
                for(int j =0; j<N; j++){
                    ansList.Add(Math.Abs(list[i]-list[j])); 
                }
            }
            
            var ans = ansList.Max();
            
            WriteLine(ans);
            
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator ;
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator )
        {
            this._separator = separator;
            this._stream = stream;
            WriteLine(_separator);
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                       inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 13380
package main

import "fmt"

func main() {
	var N, M, K, L int
	fmt.Scan(&N, &M)
	score := make(map[int]int, M)
	for i := 0; i < N; i++ {
		fmt.Scan(&K)
		for j := 0; j < K; j++ {
			fmt.Scan(&L)
			score[L]++
		}
	}
	c := 0
	for _, p := range score {
		if p == N {
			c++
		}
	}
	fmt.Println(c)
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
	String [] order = {"","n","s", "e", "w", "nn"};
	String [] orderrev = {"","s","n", "w", "e", "nn"};
	int n, ans;
	Dice [] d;
	
	class Dice{
		//dice is, 0 = south, 1 = east, 2 = top, 3 = bottom, 4 = west, 5 = north;
		int [] dice;

		public Dice(int[] dice) {
			this.dice = dice;
		}
		
		private void slide() {
			swap(0,4,5,1);
		}
		
		private void turn(char c) {
			switch(c){
			case 'n':
				swap(2,5,3,0); break;
			case 's':
				swap(2,0,3,5); break;
			case 'w':
				swap(2,4,3,1); break;
			case 'e':
				swap(2,1,3,4); break;
			}
		}

		private void swap(int i, int j, int k, int l) {
			int temp = dice[l];
			dice[l] = dice[k];
			dice[k] = dice[j];
			dice[j] = dice[i];
			dice[i] = temp;
		}
		
	}
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			if(n == 0) break;
			HashMap<String, Integer> tonum = new HashMap<String, Integer>();
			d = new Dice[n];
			for(int i = 0; i < n; i++){
				int [] input = new int[6];
				for(int j = 0; j < 6; j++){
					String s = sc.next();
					int ind = -1;
					if(tonum.containsKey(s)){
						ind = tonum.get(s);
					}
					else{
						ind = tonum.size() + 1;
						tonum.put(s, ind);
					}
					input[j] = ind;
				}
				d[i] = new Dice(input);
			}
			ans = 1 << 24;
			if(n == 1){
				System.out.println(0);
				continue;
			}
			dfs(0);
			System.out.println(ans);
		}
	}
	
	private void dfs(int deep){
		if(deep == n-1){
			//判定
			int sum = 0;
			for(int i = 0; i < 6;i++){
				HashMap<Integer,Integer> s = new HashMap<Integer, Integer>();
				
				for(int j = 0; j < d.length; j++){
					if(s.containsKey(d[j].dice[i])){
						s.put(d[j].dice[i], s.get(d[j].dice[i]) + 1);
					}
					else{
						s.put(d[j].dice[i] , 1);
					}
				}
				
				if(n == 4 && s.size() == 2){
					for(int key: s.keySet()){
						if(s.get(key) == 2){
							sum += 2;
						}
						else{
							sum += 1;
						}
						break;
					}
				}
				else{
					sum += s.size() - 1;
				}
			}
			ans = Math.min(sum, ans);
			return;
		}
		
		for(int i = 0 ; i < order.length; i++){
			for(int j = 0; j < order[i].length(); j++){
				d[deep + 1].turn(order[i].charAt(j));
			}
			for(int k = 0; k < 4; k++){
				d[deep + 1].slide();
				dfs(deep + 1);
			}
			for(int j = 0; j < orderrev[i].length(); j++){
				d[deep + 1].turn(orderrev[i].charAt(j));
			}
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    arr = list(map(int, input().split()))
    
    ok = 1
    for i in reversed(range(n - 1)):
        if arr[i] > arr[i + 1]:
            arr[i] -= 1
        if arr[i] > arr[i + 1]:
            ok = 0
    
    if ok:
        print("Yes")
    else:
        print("No")
    
    return 0

main()

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

int main()
{
    int S, A, B;

    cin >> S;

    A = S % 100;
    B = S / 100;

    if( ( A > 0 && A <= 12 ) && ( B > 0 && B <= 12 ) )
        cout << "AMBIGUOUS" << endl;
    else if( A > 0 && A <= 12 )
        cout << "YYMM" << endl;
    else if( B > 0 && B <= 12 )
        cout << "MMYY" << endl;
    else
        cout << "NA" << endl;

    return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// INPUT
		int n = sc.nextInt(); // 競技の数
		if(n < 1 || n > 1000) {
			System.out.println("範囲外の入力");
			System.exit(-1);
		}
		int m = sc.nextInt(); // 審査員の人数
		if(m < 1 || m > 1000) {
			System.out.println("範囲外の入力");
			System.exit(-1);
		}
		int[] cost = new int[n]; // 実施費用が格納される配列
		for(int i=0; i<n; i++) {
			cost[i] = sc.nextInt();
			if(cost[i] < 1 || cost[i] > 1000) {
				System.out.println("範囲外の入力");
				System.exit(-1);
			}
		}
		int[] judge = new int[m]; // 審査基準が格納される配列
		for(int i=0; i<m; i++) {
			judge[i] = sc.nextInt();
			if(judge[i] < 1 || judge[i] > 1000) {
				System.out.println("範囲外の入力");
				System.exit(-1);
			}
		}
		
		// PROCESS
		int[] vote = new int[n]; // 投票数をカウントする配列
		for(int i=0; i<m; i++) { // 配列judgeを参照
			for(int k=0; k<n; k++) { // 配列costと配列voteを参照
				if(judge[i] >= cost[k]) {
					vote[k]++;
					break;
				}
				// System.out.printf("vote[%d] = %d\n", k, vote[k]);
			}
		}
		// 得票数の高い競技を導く処理
		int max = 0;
		int maxidx = 0;
		for(int i=0; i<n; i++) {
			if(vote[i] > max) {
				max = vote[i];
				maxidx = i+1; // 要素番号+1が競技番号
			}
		}
		// OUTPUT
		System.out.println(maxidx);
	}
}

Measured memory_bytes: 24992
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
using namespace std;

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

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;

int main(){
    int D,N;
    cin >> D >> N;
    int mod = pow(100,D);
    int ans=mod*N;
    if(N==100){
        ans += mod;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n; cin>>n;
    const auto &res = prime_factorize(n);
    cout<<n<<":";
    for(auto p: res){
        for(int i=0; i<p.second; i++) cout<<" "<<p.first;
    }
    cout<<endl;
    return 0;
}


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

using namespace std;

int main() {

	string a, b;
	cin >> a >> b;

	int ab;
	ab = stoi(a + b);
	
//	cout << ab;

	int s = (int)sqrt(ab);
	//cout << s;

	int ss = s * s;

	if (ab == ss) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	system("pause");
	return 0;
}

Measured memory_bytes: 504
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	ll N, M;

	cin >> N >> M;
	vector<ll>talist;
	vector<bool>flag(100005, true);

	for (int i = 0; i < N; i++) {
		ll num;
		cin >> num;
		talist.push_back(num);
	}

	for (int i = 0; i < M; i++) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		if (talist[a] < talist[b]) {
			flag[a] = false;
		}
		else if (talist[a] > talist[b]) {
			flag[b] = false;
		}
		else if (talist[a] == talist[b]) {
			flag[a] = false;
			flag[b] = false;
		}
	}

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (flag[i] == true) {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 4336
import collections
sent = -1

def insert(hoge, new_node, root):
    #print(hoge)
    parent_maybe = sent
    now_looking = root
    hoge[new_node]['node_id'] = new_node
    while now_looking != sent:
        parent_maybe = now_looking
        if new_node < hoge[now_looking]['node_id']:
            now_looking = hoge[now_looking]['left']
        else:
            now_looking = hoge[now_looking]['right']
    hoge[new_node]['parent'] = parent_maybe
    
    if parent_maybe == sent:
        root = new_node
        hoge[new_node]['parent'] = sent
        hoge[new_node]['left'] = sent
        hoge[new_node]['right'] = sent
    elif new_node < hoge[parent_maybe]['node_id']:
        hoge[parent_maybe]['left'] = new_node
        hoge[new_node]['left'] = sent
        hoge[new_node]['right'] = sent
    else:
        hoge[parent_maybe]['right'] = new_node
        hoge[new_node]['left'] = sent
        hoge[new_node]['right'] =sent
    
    return root
    
def inorder(node_id):
    if node_id == sent:
        return None
    inorder(hoge[node_id]['left'])
    print(' {}'.format(node_id), end='')
    inorder(hoge[node_id]['right'])

def preorder(node_id):
    if node_id == sent:
        return None
    print(' {}'.format(node_id), end='')
    preorder(hoge[node_id]['left'])
    preorder(hoge[node_id]['right'])
    
    
def getTree(root):
    inorder(root)
    print()
    preorder(root)
    print()

if __name__ == '__main__':
    num = int(input())
    hoge = collections.defaultdict(dict)
    root = -1
    for _ in range(num):
        command = input()
        if command.split()[0] == 'insert':
            root = insert(hoge, int(command.split()[1]), root)
        else:
            getTree(root)


Measured memory_bytes: 161816
// =====================================================================================
// 
//       Filename:  E.cpp
//        Created:  2017년 06월 03일 21시 27분 46초
//       Compiler:  g++ -O2 -std=c++14
//         Author:  baactree ,  bsj0206@naver.com
//        Company:  Chonnam National University
// 
// =====================================================================================

#include <bits/stdc++.h>
using namespace std;
int n, k;
int arr[200000];
typedef long long ll;
ll solve(int le, int ri){
	if(le==ri)
		return arr[le]>=0;
	int mid=(le+ri)/2;
	ll left_ret=solve(le, mid);
	ll right_ret=solve(mid+1, ri);
	ll ret=0;
	vector<ll> vec;
	ll sum=0;
	for(int i=mid;i>=le;i--){
		sum+=arr[i];
		vec.push_back(sum);
	}
	sort(vec.begin(), vec.end());
	sum=0;
	for(int i=mid+1;i<=ri;i++){
		sum+=arr[i];
		ll cnt=(ll)vec.size()-(lower_bound(vec.begin(), vec.end(), -sum)-vec.begin());
		ret+=cnt;
	}
	return ret+right_ret+left_ret;
}
int main(){
	scanf("%d%d", &n, &k);
	for(int i=0;i<n;i++){
		scanf("%d", &arr[i]);
		arr[i]-=k;
	}
	printf("%lld\n", solve(0, n-1));
	return 0;
}



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

int main() {
	long long int n;
	cin>>n;
	long long int b[n];
	long int count=0,p=1;
	for(int i=0;i<n;i++){
	    cin>>b[i];
	    if(b[i]==p){
	        p++;
	    }
	    else{
	        count++;
	    }
	}
	
	if(count==n){
	    cout<<-1;
	}
	else{
	    cout<<count;
	}
	return 0;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  long m, a, ans = 0;;
  cin >> m;
  for(int i = 1; i < N; i++){
    cin >> a;
    if(m > a){
      ans += m - a;
    } else m = a;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    while (true) {
      int n = stdin.nextInt();
      if (n == 0) {
        break;
      }

      int[] arr = new int[n];
      double m = 0;
      for (int i = 0; i < n; i++) {
        arr[i] = stdin.nextInt();
        m += arr[i];
      }
      m /= n;

      double a = 0;
      for (int i = 0; i < n; i++) {
        a += Math.pow(arr[i] - m, 2);
      }

      System.out.printf("%f%n", Math.sqrt(a / n));
    }
  }

}

Measured memory_bytes: 23924
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
char _;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#ifdef _getchar_nolock
#define getchar _getchar_nolock
#endif
#ifdef _putchar_nolock
#define putchar _putchar_nolock
#endif
#ifdef getchar_unlocked
#define getchar getchar_unlocked
#endif
#ifdef putchar_unlocked
#define putchar putchar_unlocked
#endif
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
template <typename t> void scan (t& x) {do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0);}
void scan(pii &x) {scan(x.first); scan(x.second);}
template <typename t, typename ...r> void scan (t& x, r&... xs) {scan(x); scan(xs...);}
const int MN = 1e5+2, MM = 1e6+2, MOD = 1e8, BASE = 131;
int fpow (int base, int ex) {int res = 1;while (ex) {if (ex&1) res = res*1LL*base%MOD;base = base*1LL*base%MOD;ex>>=1;}return res;}
ll lcm (ll a, ll b) {return a*b/__gcd(a,b);}
int moddiv (int a, int b) {return a*1LL*fpow(b,MOD-2)%MOD;}
pii a[MN];
set<int> ind;
int main () {
    int n; ll ans = 0;
    scan(n);
    for (int i = 1; i <= n; i++) {
        scan(a[i].first);
        a[i].second = i;
    }
    sort(a+1,a+1+n);
    ind.insert(0); ind.insert(n+1); ind.insert(a[n].second);
    for (int i = n-1; i >= 1; i--) {
        auto l = ind.lower_bound(a[i].second), r = l--;
        if (l != ind.begin())ans += (ll)a[i].first * (*l-*prev(l)) * (*r-a[i].second);
        if (*r != n+1)ans += (ll)a[i].first * (*next(r)-*r) * (a[i].second-*l);
        ind.insert(a[i].second);
    }
    printf ("%lld\n",ans);
}

Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int numH = in.nextInt();
		int numW = in.nextInt();
		int numh = in.nextInt();
		int numw = in.nextInt();
		
		int ans = (numH - numh) * (numW -numw);
		
			System.out.println(ans);
		
		in.close();
	}

}


Measured memory_bytes: 22612
#!/usr/bin/env python3

def main():
    R, C, K = map(int, input().split())
    S = [[0]*(C+1) for _ in range(R+1)]
    for i in range(K):
        r, c, v = map(int, input().split())
        S[r][c] = v

    dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

    for i in range(1,R+1):
        for j in range(1,C+1):
            V = S[i][j]
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])# アイテムを取らないで下に進む
                dp[1][i][j] = max(dp[1][i][j], dp[k][i-1][j] + V)# アイテムを取って下に進む
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])# アイテムを取らないで右に進む
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V)# アイテムを取って右に進む
    ans = 0
    for k in range(4):
        ans = max(ans, dp[k][R][C])
    print(ans)

if __name__ == "__main__":
    main()

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

typedef long long int lld;

/*
g++ -std=c++11 c-vacation.cpp -o k
*/
int main() {
    int N, a, b ,c;
    cin >> N;
    vector<vector<int>> v; // a[0] a ; a[1] b ; a[2] c
    v.push_back(vector<int>());
    v.push_back(vector<int>());
    v.push_back(vector<int>());
    for(int i = 0; i < N; i++) {
        cin >> a >> b >> c;
        v[0].push_back(a);
        v[1].push_back(b);
        v[2].push_back(c);
    }

    vector<vector<int>> h;
    h.push_back(vector<int>(N));
    h.push_back(vector<int>(N));
    h.push_back(vector<int>(N));
    h[0][0] = v[0][0];
    h[1][0] = v[1][0];
    h[2][0] = v[2][0];
    for(int i = 1; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            int k1 = (j == 0 ? 1 : 0);
            int k2 = ((j == 0 || j == 1) ? 2 : 1);
            h[j][i] = v[j][i] + max(h[k1][i-1], h[k2][i-1]);
        }
    }
    cout << max(h[0][N-1], max(h[1][N-1], h[2][N-1])) << endl;

    return 0;
}


Measured memory_bytes: 2796
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        int count = 0;
            
        for (int i = 0; i < N; i++) {
            if (sc.nextInt() >= K) {
                count++;
            }
        }
        System.out.println(count);
    }
 
}

Measured memory_bytes: 47296
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;



signed main(){
  int w,h;
  cin>>w>>h;
  vector<pair<int,int>> v;
  REP(i,w){
    int p;
    cin>>p;
    v.PB(MP(p,0));
  }
  REP(i,h){
    int q;
    cin>>q;
    v.PB(MP(q,1));
  }
  sort(ALL(v));
  int sum=0;
  int x=h+1;
  int y=w+1;
  REP(i,w+h){
    if(v[i].SEC==0){
      sum+=v[i].FIR*x;
      y--;
    }else{
      sum+=v[i].FIR*y;
      x--;
    }
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 6384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	string s; int n, k; cin >> n >> k >> s;
	int lr = 0, rl = 0;
	for0(i, n)if (s[i] == 'R' && s[i + 1] == 'L')rl++; else if (s[i] == 'L' && s[i + 1] == 'R')lr++;
	int p = min(k, min(lr, rl));
	k -= p; lr -= p; rl -= p;
	if (k == 0)cout << n - 1 - (rl + lr);
	else cout << n - 1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 100;
const int MOD = 1000000007;

void doc() {
    freopen("OB.inp","r",stdin);
    freopen("OB.out","w",stdout);
    ///cerr << "OK" << '\n';
}

void solve() {
    int n;
    cin >> n;
    int a[n + 1];
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    long long f[n + 1][n + 1];
    memset(f, 0, sizeof(f));
    for(int i = 1; i <= n; i++){
        if (i + 1 <= n) f[i][i + 1] = a[i] + a[i + 1];
        f[i][i] = 0;
    }

    long long s[n + 1];
    memset(s, 0, sizeof(s));
    for(int i = 0; i <= n; i++)
        s[i] = s[i - 1] + a[i];

    for(int k = 2; k <= n - 1; k++)
    for(int i = 1; i + k <= n; i++){
        int j = i + k;
        f[i][j] = 1e18;
        for(int t = i; t <= j - 1; t++){
            f[i][j] = min(f[i][j], f[i][t] + f[t + 1][j]);
            //cout << " ** " << i << " " << t << " " << j << " " << f[i][t] << " " << f[t + 1][j] << '\n';
        }

        f[i][j] += s[j] - s[i - 1];
       // cout << i << " " << j << " " << f[i][j] << '\n';
    }
    cout << f[1][n];
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
   /// doc();
    solve();
}



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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << min({a+b,b+c,c+a}) << "\n";
    return 0;
}


Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <string>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll K, X;
    cin >> K >> X;
    yes(K * 500 >= X);
    return 0;
}

Measured memory_bytes: 3084
#include <vector> 
#include <list> 
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

#define YES_ cout<<"YES"<<endl;return0;
#define NO_ cout<<"NO"<<endl;return0;

const int white = 0, black = 1;
int board[51][51];
const int dx[4] = { 0,1,-1,0 };
const int dy[4] = { 1,0,0,-1 };
int H, W;

bool is_ok(int x, int y) {
	return (0 <= x && x<W && 0 <= y && y<H);
}
bool is_goal(int x, int y) {
	return x == W - 1 && y == H - 1;
}

int cost[51][51];
const int INF = 114514;
int shortpathcost() {
	//memset((cost), -1, sizeof(cost));
	REP(y, H)REP(x, W) {
		cost[y][x] = INF;
	}
	cost[0][0] = 0;
	while (true) {
		bool update = false;
		REP(y, H)REP(x, W) {

			if (cost[y][x] != INF&&board[y][x]!=black) {
				for (int i = 0; i<4; i++) {
					int xx = x + dx[i], yy = y + dy[i];
					if (is_ok(xx, yy)&&board[yy][xx]!=black) {
						if (cost[yy][xx]>cost[y][x] + 1) {
							cost[yy][xx] = cost[y][x] + 1;
							update = true;
						}
					}
				}
			}
		}
		if (!update) { break; }
	}
	return 0;
}

int main() {

	cin >> H >> W;
	int whitenum = 0;
	REP(y, H)REP(x, W) {
		char a;
		cin >> a;
		a == '.' ? board[y][x] = white : board[y][x] = black;
		whitenum += (a == '.');
	}
	shortpathcost();
	int c = cost[H - 1][W - 1];
	if (c == INF) {
		cout << "-1" << endl; return 0;
	}
	cout << whitenum - c-1 << endl;
	return 0;
}


Measured memory_bytes: 256