akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;


int main() {
    ll n;
    cin >> n;
    vector<array<ll, 26>> alphabets(n, array<ll, 26>{});
    for (auto &&i: irange(0LL, n)){
        string s;
        cin >> s;
        for (auto &&c  : s) {
            alphabets.at(i).at(c-'a')++;
        }
    }
    array<ll, 26> minima{};
    minima.fill(numeric_limits<ll>::max());
    for (auto &&i: irange(0LL, n)){
        for (auto &&j: irange(0LL, 26LL)){
            minima.at(j) = min(minima.at(j), alphabets.at(i).at(j));
        }
    }

    for (auto &&i: irange(0LL, 26LL)){
        for (auto &&j: irange(0LL, minima.at(i))){
            cout << (char)('a'+i);
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const int N = 1010;

int main() {
    int n, m;
    cin >> n >> m;
    cout << (n-1)*(m-1);
	// your code goes here
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,m,l;
  int a[100][100],b[100][100],i,j,k;
 unsigned long int c[100][100];
  scanf("%d %d %d",&n,&m,&l);
  for(i=0; i<n; i++){
    for(j=0; j<m; j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=0; i<m; i++){
    for(j=0; j<l; j++){
      scanf("%d",&b[i][j]);
    }
  }
  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      c[i][j]=0;
    }
  }//----       
 for(i=0; i<n; i++){//                                                         
    for(j=0; j<l; j++){
      for(k=0; k<m; k++){
        c[i][j]+=(a[i][k]*b[k][j]);
      }
    }
  }
  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      if(j==l-1)printf("%ld\n",c[i][j]);
      else printf("%ld ",c[i][j]);
    }
  }
  return 0;
}

 


 



Measured memory_bytes: 2096
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


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

    if(k&1)P(b - a);
    else P(a - b);
    return  0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int a=0;
	for(int i=0;i<3;i++){
		int tmp;
		cin>>tmp;
		a+=(tmp<<i);
	}
	if(a==4||a==3)printf("Open\n");
	else printf("Close\n");
	return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 111;
LL w[maxn], v[maxn], w0;
int N, W;
LL ans;
vector<LL> vv[5];
LL pre[5][maxn];
bool cmp (LL a, LL b) {
    return a > b;
}
int main () {
    scanf ("%d%d", &N, &W);
    for (int i = 0; i < N; i++) {
        scanf ("%d%d", &w[i], &v[i]);
    }
    w0 = w[0];
    for (int i = 0; i < N; i++) {
        vv[w[i]-w0].push_back (v[i]);
    }
    for (int i = 0; i < 4; i++) {
        sort (vv[i].begin(), vv[i].end(), cmp);
        for (int j = 0; j < vv[i].size(); j++) {
            pre[i][j+1] = pre[i][j] + vv[i][j];
        }
    }
    for (int i = 0; i <= vv[0].size(); i++) {
        for (int j = 0; j <= vv[1].size(); j++) {
            for (int k = 0; k <= vv[2].size(); k++) {
                for (int l = 0; l <= vv[3].size(); l++) {
                    if (w0*i+(w0+1)*j+(w0+2)*k+(w0+3)*l <= W) {
                        ans = max (ans, pre[0][i]+pre[1][j]+pre[2][k]+pre[3][l]);
                    }
                }
            }
        }
    }
    printf ("%lld", ans);
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
int side_walls[30][30];
int down_walls[30][30];
int d[30][30];
int main(void){
  int w;
  int h;
  while(true){
    cin >> w >> h;
    if(w == 0 && h == 0){
      break;
    }
    for(int i = 0; i < 2 * h - 1; i++){
      if(i % 2 == 0){
        for(int j = 0; j < w - 1; j++){
          cin >> side_walls[i / 2][j];
        }
      } else {
        for(int j = 0; j < w; j++){
          cin >> down_walls[i / 2][j];
        }
      }
    }

    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        d[i][j] = INT_MAX;
      }
    }

    queue <pair <int, int> > q;
    d[0][0] = 1;
    q.push(make_pair(0, 0));
    while(!q.empty()){
      int cur_h = q.front().first;
      int cur_w = q.front().second;
      q.pop();
      int next_d = d[cur_h][cur_w] + 1;
      if(cur_h > 0 && down_walls[cur_h - 1][cur_w] == 0 && d[cur_h - 1][cur_w] == INT_MAX){
        d[cur_h - 1][cur_w] = next_d;
        q.push(make_pair(cur_h - 1, cur_w));
      }
      if(cur_h < h - 1 && down_walls[cur_h][cur_w] == 0 && d[cur_h + 1][cur_w] == INT_MAX){
        d[cur_h + 1][cur_w] = next_d;
        q.push(make_pair(cur_h + 1, cur_w));
      }
      if(cur_w > 0 && side_walls[cur_h][cur_w - 1] == 0 && d[cur_h][cur_w - 1] == INT_MAX){
        d[cur_h][cur_w - 1] = next_d;
        q.push(make_pair(cur_h, cur_w - 1));
      }
      if(cur_w < w - 1 && side_walls[cur_h][cur_w] == 0 && d[cur_h][cur_w + 1] == INT_MAX){
        d[cur_h][cur_w + 1] = next_d;
        q.push(make_pair(cur_h, cur_w + 1));
      }
    }

    if(d[h - 1][w - 1] == INT_MAX){
      cout << 0 << endl;
    } else {
      cout << d[h - 1][w - 1] << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3152
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
ll A[310][310], d[310][310];
 
ll INF = 10e9;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
  int n;
  cin >> n;
  
  rep(i,n){
    rep(j,n){
      cin >> A[i][j];
      d[i][j] = A[i][j];
    }
  }

  rep(k,n)rep(i,n)rep(j,n){
    if(i == j or i == k or j == k) continue;
    if(d[i][k] == INF or d[k][j] == INF) continue;
    if(A[i][j] == 0)continue;
    if(d[i][k]+d[k][j] == A[i][j]){
      d[i][j] = INF;
      d[j][i] = INF;
    }
    else if(d[i][k]+d[k][j] < A[i][j]){
      cout<<-1<<endl;
      return 0;
    }
  }
  ll sum = 0;
  rep(i,n)rep(j,n){
    if(d[i][j] == INF)continue;
    sum+=d[i][j];
  }
  cout<<sum/2<<endl;
  return 0;
}

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


public class Main {
	private	static	BufferedReader br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int		w = 0;
		int		h = 0;
		double	s = 0.0;

		while (true) {
			w = parseNum();
			h = parseNum();
			if (w == 0 && h == 0) {
				break;
			}
			s = (double)(w * w) + 2 * (double)w * Math.sqrt((double)w * w / 4.0 + (double)h * h);
			System.out.printf("%.6f\n", s);
		}
	}

	private static int parseNum() {
		int		num   = 0;
		String	strIn = null;

		if ((strIn = parseStdin()) != null) {
			num = Integer.parseInt(strIn); 
		}
		
		return num;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 16928
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    string s;
    cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout <<"Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    bool f=true;
    int n;cin>>n;
    rep(i,n){
        int a;cin>>a;
        if(a%2) continue;
        if(a%3==0 or a%5==0) continue;
        f=false;
    }
    if(f){
        cout<<"APPROVED"<<endl;
    }else{
        cout<<"DENIED"<<endl;
    }
    return 0;
}


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

const ll MOD = 1000000007;

class ModuloCombination {
private:
  vector<ll> fact, inv_fact;

  static ll modulo_power(ll a, ll n) {
    if(n == 0) return 1;
    if(n % 2 == 0) return modulo_power((a * a) % MOD, n / 2);
    return (a * modulo_power(a, n - 1)) % MOD;
  }

public:
  ModuloCombination(ll N): fact(N + 1), inv_fact(N + 1) {
    fact[0] = 1;
    REP(i, 1, N + 1) fact[i] = (i * fact[i - 1]) % MOD;
    REP(i, 0, N + 1) inv_fact[i] = modulo_power(fact[i], MOD - 2);
  }

  ll operator()(ll n, ll r) {
    return fact[n] * inv_fact[r] % MOD * inv_fact[n - r] % MOD;
  }
};

int main(void) {
  ll N, M;
  cin >> N >> M;

  const ll K = 200000;
  vector<bool> p(K, true);
  p[0] = p[1] = false;
  REP(i, 0, K) if (p[i]) for (ll j = i * 2; j < K; j += i) p[j] = false;

  ModuloCombination C(500000);

  ll ans = 1;
  REP(i, 0, K) if (p[i]) {
    ll cnt = 0;
    while (M % i == 0) {
      M /= i;
      cnt++;
    }
    if (cnt > 0) {
      ans *= C(cnt + N - 1, N - 1);
      ans %= MOD;
    }
  }
  if (M != 1) {
    ans *= C(N, N - 1);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 8064
#include <cstdio>
#include <algorithm>
#include <vector>

template<bool sort, typename T>
auto divisors(T n) -> std::vector<T>
{
	std::vector<T> r;
	T i = 1;
	for (; i * i < n; ++i)
	{
		if (n % i == 0)
		{
			r.emplace_back(i);
			r.emplace_back(n / i);
		}
	}
	if (i * i == n)
	{
		r.emplace_back(i);
	}
	if (sort)
	{
		std::sort(r.begin(), r.end());
	}
	return r;
}

int main()
{
	long long x;
	scanf("%lld", &x);
	auto f = divisors<false>(x);
	for (auto d : f)
	{
		for (long long b = -10000; b <= 10000; ++b)
		{
			long long a = b + d;
			if (a * a * a * a * a - b * b * b * b * b == x)
			{
				printf("%lld %lld\n", a, b);
				return 0;
			}
		}
	}
	for (auto d : f)
	{
		for (long long b = -10000; b <= 10000; ++b)
		{
			long long a = b - d;
			if (a * a * a * a * a - b * b * b * b * b == x)
			{
				printf("%lld %lld\n", a, b);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3228
a, b, c, x, y=map(int, input().split())
m=2*x*c
n=c*y*2+a*(x-y)
d=2*y*c
e=c*x*2+b*(y-x)
f=a*x+b*y
g=min(m,n,f)
h=min(d,e,f)
if x>=y:
    print(g)
else:
    print(h)


Measured memory_bytes: 3064
require 'prime'

A, B = gets.chomp.split(' ').map(&:to_i)

# ユーグリッドの互除法
# 最大公約数が算出される。すごい...
def gcd(x, y)
  return x if y.zero?

  gcd(y, x % y)
end

# 最大公約数 n を素因数分解する。
def factorize(n)
  res = []
  i = 2
  while i * i <= n
    next unless (n % i).zero?

    res.push(i)
    n /= i while (n % i).zero?

    i += 1
  end

  res.push(n) if n != 1

  res
end

g = gcd(A, B)
# 素因数分解の素数の合計 + 1する。
# p factorize(g).count + 1 # これじゃダメだった...
p g.prime_division.count + 1


Measured memory_bytes: 3964
s = list(input())
n = len(s)

if s[0] == '0' or s[n-1] == '1':
    print(-1)
    exit()

for i in range(n-1):
    if s[i] != s[n-2-i]:
        print(-1)
        exit()

p = n
for i in range(n-2,-1,-1):
    print(p,i+1)
    if s[i] == '1':
        p = i+1

Measured memory_bytes: 50808
#include <iostream>

using namespace std;

int main()
{
    int x;
    int no5=0,no7=0;
    for(int i=0;i<3;i++){
        cin>>x;
        if(x==5){
            no5++;
        }
        else if(x==7){
            no7++;
        }
    }
    if(no5==2 && no7==1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 256
//Zory-2018
//*******************主函数******************
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
#ifdef WIN32
#define BIGN "%I64d"
#else
#define BIGN "%lld"
#endif
using namespace std;
typedef long long ll;
//*******************全局常量*******************

//*******************全局定义*******************

//*******************实现******************

//*******************主函数******************
char mp[110][110];
int main()
{
	printf("100 100\n");
	for(int i=1;i<=100;i++)
		for(int j=1;j<=100;j++)
			if(i<=50) mp[i][j]='#';
			else mp[i][j]='.';
	
	int a,b;scanf("%d%d",&a,&b);
	int x,y;
	
	x=1;y=1;
	for(int i=1;i<=a-1;i++)
	{
		mp[x][y]='.';
		y+=2;if(y>100) x+=2,y=1;
	}
	
	x=100;y=1;
	for(int i=1;i<=b-1;i++)
	{
		mp[x][y]='#';
		y+=2;if(y>100) x-=2,y=1;
	}
	
	for(int i=1;i<=100;i++) puts(mp[i]+1);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef pair<int,int> pii;
const int MN = 2e5+5;
int N,D[MN][2];
string S;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> S;
    int N = S.size();
    D[0][1] = 1;
    D[0][2] = -1e9;
    D[1][1] = -1e9;
    if(S[0]!=S[1]) D[1][1] = 2;
    D[1][2] = 1;
    for(int i=2; i<N; i++){
        D[i][1] = D[i-1][2]+1;
        if(S[i-1]!=S[i]) D[i][1] = max(D[i][1],D[i-1][1]+1);
        D[i][2] = D[i-2][1]+1;
        if(i>=3&&(S[i-2]!=S[i]||S[i-3]!=S[i-1])) D[i][2] = max(D[i][2],D[i-2][2]+1);
    }
    cout << max(D[N-1][1],D[N-1][2]);
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int n,k;
	cin >> n >> k;
	vector<int> x(n);
	rep(i,n) cin >> x[i];

	ll ans = 1LL << 60;

	for(int l = 0; l < n; ++l){
		const int r = l + k - 1;
		if(r >= n) break;
		const int xl = x[l];
		const int xr = x[r];
		if(xl <= 0 and 0 <= xr){
			const ll cur = 2LL * min<ll>(abs(xl),abs(xr)) + max<ll>(abs(xl),abs(xr));
			chmin(ans,cur);
		} else {
			const ll cur = max<ll>(abs(xl),abs(xr));
			chmin(ans,cur);
		}
	}

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	string s;
	cin >> s;
	map<int, int> rem;
	rem[0] = 1;
	ll ans = 0, r = 0, p = 1;
	reverse(all(s));
	for(auto i : s){
		r = r + (i - '0') * p;
		r %= 2019;
		p *= 10;
		p %= 2019;
		ans += rem[r];
		rem[r]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3740
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;


int main(){
    cin>>sa>>sb;
    if(sa.size()>sb.size()){
        C "GREATER" E;
    }
    else if(sa.size()<sb.size()){
        C "LESS" E;
    }
    else{
        while(sa.size()){
            
            if(sa[0]>sb[0]){
                C "GREATER" E;
                break;
            }
            else if(sa[0]<sb[0]){
                C "LESS" E;
                break;
            }
            sa.erase(sa.begin());
            sb.erase(sb.begin());
        }
        if(sa.size()==0)C "EQUAL" E;
    }
    //C (a>b ? "GREATER":a==b ? "EQUAL":"LESS") E;
    
    
    
    
    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		int sum=0;
		bool prime[1000000];
		for(int i=2;i<=999999;i++){
			prime[i]=true;
		}
		for(int j=2;j<=999999;j++){
			if(prime[j]){
				for(int k=2*j;k<=999999;k+=j){
					prime[k]=false;
				}
			}
		}
		int m=0;
		for(int l=2;;l++){
			if(prime[l]){
				sum += l;
				m++;
			}
			if(m==n) break;
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 2136
// header {{{
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <stack>
// #include <tuple>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define ALPHABET    (26)
#define EPS         (1e-10)
#define INF         (1000000005LL)
#define MOD         (1000000007LL)
// #define EQ(a, b)    (abs((a)-(b)) < EPS)
inline bool EQ(double a, double b) {return abs(a-b) < EPS;}
// ciling(x/y) = (x+y-1)/y

// template<class T>
// using P = pair<T, T>;
using ll  = long long;
using ull = unsigned long long;
// }}}

vector<int> e[100000];
bool visited[2][100000];
int dst[2][100000];
// int ans = -1;
//
void dfs(int n, int i, int cost){
    visited[n][i] = true;
    dst[n][i] = cost;
    for(auto next : e[i]){
        if(!visited[n][next]){
            dfs(n, next, cost+1);
        }
    }
}
//
typedef pair<int, int> P;


int main() {
    int n;cin >> n;
    for(int i=0;i<n-1;i++){
        int a, b;cin >> a >> b;
        a--;b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    for(int i=0;i<n;i++){
        visited[0][i] = false;
        visited[1][i] = false;
    }

    dfs(0, 0, 0);
    dfs(1, n-1, 0);

    // for(int i=0;i<n;i++){
    //     dst[0][i] = INF;
    //     dst[1][i] = INF;
    // }
    // int fennec = dfs(0);
    // for(int i=0;i<n;i++) visited[i] = false;
    // int snuke = dfs(n-1);

    // for(int i=0;i<2;i++){
    //     queue<P> q;
    //     if(i == 0){
    //         q.push({0, 0});
    //     }else{
    //         q.push({0, n-1});
    //     }
    //     while(!q.empty()){
    //         auto cv = q.front();q.pop();
    //         int cid = cv.second;
    //         int ccost = cv.first;
    //
    //     }
    // }

    int count = 0;
    for(int i=0;i<n;i++){
        // cout << dst[0][i] << " " << dst[1][i] << endl;
        if(dst[0][i] <= dst[1][i]){
            count++;
        }
    }

    if(count > n/2){
        cout << "Fennec" << endl;
    }else{
        cout << "Snuke" << endl;
    }
    return 0;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n;
    cin >> n;
    long long a[n], s1[n], s2[n], m = 0, p = 0;
    for (long long i = 0; i < n; i++) cin >> a[i];
    for (long long i = 0; i < n; i++)
    {
        if (i > 0) s1[i] = s1[i - 1] + a[i];
        else s1[i] = a[i];
        if (i % 2 == 0)
        {
            if (s1[i] >= 0) 
            {
                long long k = s1[i] + 1;
                s1[i] = -1;
                m += k;
            }
        }
        else
        {
            if (s1[i] <= 0)
            {
                long long k = 1 - s1[i];
                s1[i] = 1;
                m += k;
            }
        }
    }
    for (long long i = 0; i < n; i++)
    {
        if (i > 0) s2[i] = s2[i - 1] + a[i];
        else s2[i] = a[i];
        if (i % 2 == 1)
        {
            if (s2[i] >= 0) 
            {
                long long k = s2[i] + 1;
                s2[i] = -1;
                p += k;
            }
        }
        else
        {
            if (s2[i] <= 0)
            {
                long long k = 1 - s2[i];
                s2[i] = 1;
                p += k;
            }
        }
    }
    cout << min(m, p);
}

Measured memory_bytes: 5936
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int input = Integer.parseInt( reader.readLine() );
        System.out.println((int) Math.pow(input, 3));
    }
 
}

Measured memory_bytes: 24248
fun main(args : Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val hh = IntArray(n)
    repeat(n) {
        hh[it] = readLine()!!.toInt()
    }
    hh.sort()

    var min = Int.MAX_VALUE

    for (i in 0..n-k) {
        val diff = hh[i+k-1] - hh[i]
        if (diff < min) min = diff
    }

    println(min)
}

Measured memory_bytes: 43120
import java.io.*;
import java.util.regex.Pattern;;

class Main {

    public static void main(String[] args) {
        try {
            BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
            Pattern patt = Pattern.compile("this|that|the");
            String st;
            while ((st = sc.readLine()) != null) {
                char[] xx = st.toCharArray();
                for (int i = 0; !patt.matcher(String.valueOf(xx)).find() & i < 26; i++) {
                    for (int j = 0; j < xx.length; j++) {
                        if (xx[j] >= 'a' && xx[j] < 'z')
                            xx[j]++;
                        else if (xx[j] == 'z')
                            xx[j] = 'a';
                    }
                    // System.err.println(xx);
                }
                System.out.println(xx);
            }
        } catch (Exception e) {
            System.out.println("Error");
        }
    }
}

Measured memory_bytes: 24520
#include<iostream>
#include<algorithm>
using namespace std;
main(){
  int l,a,b,c,d;
  cin>>l>>a>>b>>c>>d;
  int x,y;
  x=a/c;
  if(a%c!=0){
    x++;
  }
  y=b/d;
  if(b%d!=0){
    y++;
  }
  cout<<l-max(x,y)<<endl;
}

Measured memory_bytes: 1160
H,W=map(int,input().split())
field=[]

ans=0
next_num=0
print_list=[]

for j in range(H):
    
    y=j+1
    getrow = list(map(int,input().split()))
    row = [i%2 for i in getrow]
    if next_num: row[next_num-1]=int(row[next_num-1]==0)
    
    index1=[]
    for i in range(W):
        if row[i]==1: index1.append(i+1)
        
    while True:
        
        if len(index1)==0:
            next_num=0
            break
        
        elif len(index1)==1:
            if y != H:
                next_num=index1[0]
                print_list.append([y,next_num,y+1,next_num])
                ans += 1
            break
            
        else:
            a=index1[0]
            b=index1[1]
            for t in range(a,b):
                print_list.append([y,t,y,t+1])
                ans += 1
            del index1[1]
            del index1[0]
        
print(ans)
for r in print_list:
    print(r[0],r[1],r[2],r[3])

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

int N, a[2][105];
int main()
{
    std::cin >> N;
    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < N; ++j)
            std::cin >> a[i][j];

    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        int res = 0;
        for (int j = 0; j <= i; ++j)
            res += a[0][j];
        for (int j = i; j < N; ++j)
            res += a[1][j];

        ans = std::max(ans, res);
    }

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


Measured memory_bytes: 256
import java.util.*;
public class Main{
    void run(){
        Scanner sc = new Scanner(System.in);
        String exp = "(" + sc.next() + sc.next() + sc.next() + ")";
        while(true){
            String op = sc.next();
            if(op.equals("=")){
                break;
            }
            exp = "(" + exp + op + sc.next() + ")";
        }
        Parser parser = new Parser(exp);
        System.out.println(parser.expression());
    }
    public static void main(String[] args){
        new Main().run();
    }
}

class Parser{
    char[] exp;
    int begin;
    Parser(String str){
        this.exp = (str+"#").toCharArray();
    }
    //四則演算の式をパースして、その評価結果を返す
    int expression(){
        int ret = term();
        
        while(true){
            if(exp[begin] == '+'){
                begin++;
                ret += term();
            }
            else if(exp[begin] == '-'){
                begin++;
                ret -= term();
            }
            else{
                break;
            }
        }
        return ret;
    }
    //乗算除算の式をパースして、その評価結果を返す
    int term(){
        int ret = factor();
        while(true){
            if(exp[begin] == '*'){
                begin++;
                ret *= factor();
            }
            else if(exp[begin] == '/'){
                begin++;
                ret /= factor();
            }
            else{
                break;
            }
        }
        return ret;
    }
    //数字の列をパースして、その数を返す
    int number(){
        int ret = 0;
        while(Character.isDigit(exp[begin])){
            ret *= 10;
            ret += exp[begin] - '0';
            begin++;
        }
        return ret;
    }
    //括弧か数かをパースして、その評価結果を返す
    int factor(){
        if(exp[begin] == '('){
            begin++;//'('を飛ばす
            int ret = expression();
            begin++;//')'を飛ばす
            return ret;
        }
        else{
            return number();
        }
    }
}
//https://gist.github.com/draftcode/1357281

Measured memory_bytes: 18308
///A drunk man will find his way home, but a drunk bird may get lost forever...
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
typedef long long ll;
typedef double dd;
typedef pair <int, int> pii;
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define mp make_pair
#define all(x) x.begin() , x.end()
//const int mx = 1e5 + 5;
set < int > v[30];
set < pii > ms;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	string s, t;
	//	ms.clear();
		cin >> s >> t;
	//	for(int i = 0; i < 30; i++)
	//		v[i].clear();
		for(int i = 0; i < sz(s); i++)
			v[s[i] - 'a'].insert(i);
		int l = 0, ans = 0, ind = -1;
		bool b = 0;
		for(int i = 0; i < sz(t); i++){
			int x = t[i] - 'a';
	//		cout << i << " " << x << " " << ind << endl;
			if(ms.find({x , ind}) != ms.end()){
		//		cout << "vcbhxdjvhkjdfvhkjhgfk " << ind << endl;
				if(v[x].upper_bound(ind) != v[x].end()){
		//			cout << "bro " << endl;
					ind = *v[x].upper_bound(ind);
			//		cout << "ind1 " << ind << endl;
					l++;
					ms.insert({x , ind});
				}
				else{
					if(!l){
	//					cout << "i " << i << endl;
						b = 1;
						break;
					}
		//			cout << "l1 " << l << endl;
					ms.clear();
					l = 0;
					ans++;
					ind = 0;
					i--;
				}
			}
			else{
		//		cout << "blah" << endl;
				if(v[x].lower_bound(ind) != v[x].end()){
					ind = *v[x].lower_bound(ind);
				//	cout << "ind2 " << ind << endl;
					l++;
					ms.insert({x , ind});
				}
				else{
					if(!l){
			//			cout << "i2 " << i << endl;
						b = 1;
						break;
					}
				//	cout << "l2 " << l << endl;
					ms.clear();
					l = 0;
					ans++;
					ind = 0;
					i--;
				}
			}
		}
		if(b)
			cout << -1 << endl;
		else
			cout << ans * sz(s) + (l > 0 ? ind + 1 : 0) << endl;
	return 0;
}



Measured memory_bytes: 11472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

vector<ll> inv, fact, invfact;
void Mod_build(int n = 201010) {
    fact.resize(n + 1);
    inv.resize(n + 1);
    invfact.resize(n + 1);
    fact[0] = inv[0] = invfact[0] = 1;
    inv[1] = 1;
    for (ll i = 0; i < n; i++) {
        fact[i + 1] = fact[i] * (i + 1) % mod;
        if (i > 0) inv[i + 1] = mod - inv[mod % (i + 1)] * (mod / (i + 1)) % mod;
        invfact[i + 1] = invfact[i] * inv[i + 1] % mod;
    }
}
ll perm(int n, int k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return fact[n] * invfact[n - k] % mod;
}
ll comb(int n, int k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return (fact[n] * invfact[n - k] % mod) * invfact[k] % mod;
}
ll powmod(ll n, ll k) {
    k %= mod - 1;
    if (k < 0) k += mod - 1;
    ll ret = 1;
    while (k) {
        if (k & 1) ret = ret * n % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    Mod_build();
    ll h, w;
    cin >> h >> w;
    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    for (i = 0; i < h - a; i++) {
        ans += comb(i + b - 1, i) * comb(w - b + h - i - 2, h - 1 - i) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7820
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

constexpr lnt MOD = 1e9+7;
struct mint
{
	lnt v;
	mint():v(0){}
	mint(lnt v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(lnt k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(lnt n, lnt k) { if(n-k<k) k=n-k; mint num(1), dom(1); for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; } return num/dom; }
	static std::vector<mint> construct_comb(int n) {
		std::vector<mint> c(n+1); mint a = 1; c[0] = a; for(int i=1;i<=n;i++) { a = a*mint(n+1-i)/i; c[i] = a; } return c;
	}
	static std::vector<mint> construct_fact(int n) { std::vector<mint> f(n+1,1); for(int i=2;i<=n;i++) f[i]=f[i-1]*i; return f; }
};
std::istream& operator>>(std::istream&i,mint&a){ lnt t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


int main() {
	lnt n;
	std::cin >> n;
	if(n==1) {
		print(1);
	} else if(n==2) {
		print(4);
	} else {
		std::vector<mint> dp(n+1),ac(n+1,0);
		dp[1]=n;
		dp[2]=n*n;
		ac[1]=n;
		ac[2]=ac[1]+dp[2];
		for(int i=3;i<=n;i++) {
			dp[i]=dp[i-1]+mint((n-1)*(n-1))+mint(n+2-i);
			dp[i]+=ac[i-3];
			ac[i]=ac[i-1]+dp[i];
		}
		print(dp[n]);
	}
}


Measured memory_bytes: 18748
A = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
K = int(input())
A = A.split(', ')
print(A[K-1])


Measured memory_bytes: 2940
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   String s1 = sc.next();
   String s2 = sc.next();
   String s3 = sc.next();
   
   if(s1.charAt(s1.length()-1)==s2.charAt(0)&&s2.charAt(s2.length()-1)==s3.charAt(0))System.out.println("YES");
   else System.out.println("NO");
 }
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string S;
    cin >> S;
    ll Rcnt = 0,Lcnt = 0;
    vector<ll> cnt;
    for (int i = 0; i < S.size(); i++) {
        if(S[i] == 'R'){
            Rcnt++;
            if(Lcnt != 0){
                cnt.pb(Lcnt);
                Lcnt = 0;
            }
        } else {
            Lcnt++;
            if(Rcnt != 0){
                cnt.pb(Rcnt);
                Rcnt = 0;
            }
        }
    }
    cnt.pb(Lcnt);
    vector<ll> ans;
    for (int i = 0; i < cnt.size(); i++) {
        if(i % 2 == 1){
            ll c = 0;
            c += cnt[i-1]/2 + cnt[i]/2;
            if(cnt[i] % 2 == 1){
                c++;
            }
            ans.pb(c);
        }
        for (int j = 0; j < cnt[i]-1; j++) {
            ans.pb(0);
        }
        if(i % 2 == 0){
            ll c = 0;
            c += cnt[i]/2 + cnt[i+1]/2;
            if(cnt[i] % 2 == 1){
                c++;
            }
            ans.pb(c);
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i];
        if(i == ans.size()-1){
            cout << endl;
        } else {
            cout << " ";
        }
    }
}

Measured memory_bytes: 5584
#include <iostream>
#include<algorithm>
using namespace std;
const  int maxn =2e5+10;
struct node
{
    int val,num;
};
node a[maxn];
bool cmp(node a, node b)
{
    return a.val>b.val;
}
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i].val;
        a[i].num=i;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i!=a[j].num)
            {
                cout << a[j].val << endl;
                break;
            }
        }
    }
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

ll a[90010];
bool check[90010];
P p[90010];

int main(){
    cin.sync_with_stdio(false);
    int h, w, d;
    cin >> h >> w >> d;
    rep(i, h)rep(j, w) {
        int n;
        cin >> n;
        p[n] = P(i, j);
    }

    repr(i, h * w + 1, 1) {
        if (check[i]) continue;
        check[i] = true;
        a[i] = 0;
        int j = i - d;
        while(j >= 1) {
            a[j] = abs(p[j + d].fi - p[j].fi) + abs(p[j + d].se - p[j].se) + a[j + d];
            check[j] = true;
            j -= d;
        }
    }

    int q;
    cin >> q;
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        cout << a[l] - a[r] << endl;
    }
    return 0;
}

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

int main(){
int N; cin >> N;
vector<int> p(N);
int ans = 1,tmp;
for(int i = 0; i < N; i++) cin >> p.at(i);
tmp = p.at(0);
for(int i = 1; i < N;i++){
    if(p.at(i) <= tmp)
    {
        ans++;
        tmp = min(p.at(i),tmp);
    }
}
    cout << ans <<endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        string n = Console.ReadLine();
        int[] a = new int[4];
        for(int i = 0; i < 4; i++)
        {
            a[i] = int.Parse(n.Substring(i,1));
        }

        if (a[0] + a[1] + a[2] + a[3] == 7)
        {
            Console.WriteLine(a[0] + "+" + a[1] + "+" + a[2] + "+" + a[3] + "=7");
        }
       else if (a[0] + a[1] + a[2] - a[3] == 7)
        {
            Console.WriteLine(a[0] + "+" + a[1] + "+" + a[2] + "-" + a[3] + "=7");
        }
       else if (a[0] + a[1] - a[2] + a[3] == 7)
        {
            Console.WriteLine(a[0] + "+" + a[1] + "-" + a[2] + "+" + a[3]  + "=7");
        }
       else if (a[0] + a[1] - a[2] - a[3] == 7)
        {
            Console.WriteLine(a[0] + "+" + a[1] + "-" + a[2] + "-" + a[3] + "=7");
        }
       else if (a[0] - a[1] + a[2] + a[3] == 7)
        {
            Console.WriteLine(a[0] + "-" + a[1] + "+" + a[2] + "+" + a[3] + "=7");
        }
        else if (a[0] - a[1] + a[2] - a[3] == 7)
        {
            Console.WriteLine(a[0] + "-" + a[1] + "+" + a[2] + "-" + a[3] + "=7");
        }
        else if (a[0] - a[1] - a[2] + a[3] == 7)
        {
            Console.WriteLine(a[0] + "-" + a[1] + "-" + a[2] + "+" + a[3] + "=7");
        }
        else if (a[0] - a[1] - a[2] - a[3] == 7)
        {
            Console.WriteLine(a[0] + "-" + a[1] + "-" + a[2] + "-" + a[3] + "=7");
        }

        Console.ReadLine();
    }
   
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                // 素数ではない
                return false;
            }
        }

        // 素数である
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> a;
int o;

int main(){
    cin >> n;
    if (n % 2 == 0){
        for (int i = 0; i < n; i ++){
            int tmp;
            cin >> tmp;
            a.push_back(tmp);
        }
        sort(a.begin(),a.end());
        o = abs(a[n/2] - a[(n/2)-1]);
        cout << o;
    }else{
        cout << 0;
    }
}


Measured memory_bytes: 892
object Main extends App {

  val n = scala.io.StdIn.readLine.toInt
  val p = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList
  val q = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList

  var pp = 0
  var qq = 0
  var cnt = 1

  (1 to n).toList.permutations.foreach { aa =>
    if (p == aa) {
      pp = cnt
    }
    if (q == aa) {
      qq = cnt
    }
    cnt += 1
  }
  println(Math.abs(pp - qq))
}


Measured memory_bytes: 36860