akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto S_ = readln.chomp.to!(wchar[]);
    auto T = readln.chomp.to!(wchar[]);

    wchar[] S;
    foreach_reverse (i; 0..S_.length - T.length + 1) {
        auto s = S_.dup;
        foreach_reverse (j; 0..T.length) {
            if (S_[i+j] == '?')
                s[i+j] = T[j];
            else if (S_[i+j] != T[j])
                goto loop;
        }
        S = s;
        break;
        loop:
    }
    if (S) {
        foreach (ref c; S) if (c == '?') c = 'a';
        writeln(S);
    } else {
        writeln("UNRESTORABLE");
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>

struct state {
  int cards;
  int step;

  state(int cards, int step) {
    this->cards = cards;
    this->step = step;
  }
};

// value ??? digit ???????????°????????????
int get_digit(int value, int digit) {
  return (value / (int)pow(10, digit - 1)) % 10;
}

// value ??? a ????????¨ b ???????????°????????????
int swap_digit(int value, int a, int b) {
  int _a = get_digit(value, a);
  int _b = get_digit(value, b);
  return value -
    (_a * pow(10, a - 1) + _b * pow(10, b - 1)) +
    (_b * pow(10, a - 1) + _a * pow(10, b - 1));
}

void push_swapped_state(state _state, int z, int y,
                        std::map<int, int> *map,
                        std::queue<state> *queue) {
  int new_cards = swap_digit(_state.cards, z, y);
  if (map->find(new_cards) == map->end()) {
    queue->push(state(new_cards, _state.step + 1));
  }
}

// state => step ??? key-value map ?????????
std::map<int, int> *make_map() {
  std::map<int, int> *result = new std::map<int, int>();
  std::queue<state> queue;
  queue.push(state(1234567, 0));

  while (queue.size() > 0) {
    state _state = queue.front();
    queue.pop();

    (*result)[_state.cards] = _state.step;

    int z = 0; // index of zero
    for (int i = 1; i <= 8; i++) {
      if (get_digit(_state.cards, i) == 0) z = i;
    }

    // swap with left card
    if (z % 4 != 0) {
      push_swapped_state(_state, z, z + 1, result, &queue);
    }

    // swap with right card
    if ((z - 1) % 4 != 0) {
      push_swapped_state(_state, z, z - 1, result, &queue);
    }

    // swap with top card
    if (z < 5) {
      push_swapped_state(_state, z, z + 4, result, &queue);
    }

    // swap with bottom card
    if (z > 4) {
      push_swapped_state(_state, z, z - 4, result, &queue);
    }
  }
  return result;
}

int main() {
  char buf[256];
  std::map<int, int> *steps = make_map();
  while (scanf(" %[^\n]", buf) != EOF) {
    int state = 0;
    int radix = 1;
    for (int i = 7; i >= 0; i--) {
      state += (buf[i * 2] - '0') * radix;
      radix *= 10;
    }
    printf("%d\n", (*steps)[state]);
  }
  delete steps;
  return 0;
}

Measured memory_bytes: 2024
#include <stdio.h>

int main(void){
   
   int N = 5;
   int Time[N];
   int i,j;
   
   for(i = 0;i < N;i++){
      scanf("%d",&Time[i]);
   }
   
   int sum = 0;
   int error = 0;
   int max_error = 0;
   int inv_max_error;
   
   for(i = 0;i < N;i++){
      if((10 - Time[i]%10) >= max_error && Time[i]%10 != 0){
         max_error = 10 - Time[i]%10;
         inv_max_error = i;
      }
   }
   
   for(i = 0;i < N;i++){
      if(i != inv_max_error && Time[i]%10 != 0){
         error = error + 10 - Time[i]%10;
      }
   }
   
   //printf("%d\n",error);
   
   for(i = 0;i < N;i++){
      sum = sum + Time[i];
   }
   
   sum = sum + error;
   
   printf("%d\n",sum);
   
   return 0;
}


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

Measured memory_bytes: 128
def com(_x):
    _flg = 1
    mx  = int(_x**0.5)
    for i in range(2, mx+1):
        if _x % i == 0:
            _flg = 0
            break
    return _flg


x = int(input())
flg = 0
while flg == 0:
    #print("a")
    flg = com(x)
    if flg == 0:
        x+=1
print(x)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    ll L, R;
    cin >> L >> R;
    vector<ll> V;

    for(ll i=L; i<=R; i++) {
        V.push_back(i % 2019);
        if(i % 2019 == 0 && i!= 0) break;
    }
    ll min_value = 2020;
    for(int i=0; i<V.size(); i++) {
        for(int j=i+1; j<V.size(); j++) {
            min_value = min((V[i] * V[j]) % 2019, min_value);
        }
    }
    cout << min_value << endl;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int a[100000];
	int b[100000];
	int c, d;
	int k;
	int n, m;
	int s, t;
	int x, y, z;


	scanf("%d %d", &n,&m);



	printf("%d\n", (n+m)%24);

	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while(true){
            String[] ar = br.readLine().split(" ");
            int x = Integer.parseInt(ar[0]);
            int y = Integer.parseInt(ar[1]);
            if(x == 0 && y == 0){ break;
            }
            int ans = 0;
            for(int i = 1; i <= x; i++){
                for(int j = 1; j <= x; j++){
                    if(i == j){break;
                    }
                    for(int k = 1; k <= x; k++){
                        if(i == k || j == k){ break;
                        }
                        if(i+j+k == y){
                            ans++;
                        }
                    }
                }
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 25244
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

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

    for(int i=x;x<=pow(10,5);i++){
        bool flg=false;
        for(int j=2;j*j<=i;j++){
            if(i%j==0){
                flg=true; 
                break;
            }
        }
        if(!flg){
            cout<<i<<endl;
            return 0;
        }
    }
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	for (int i = 1; i <= n; i++) {
		if ((int)(i * 1.08) == n) {
			std::cout << i << std::endl;
			return 0;
		}
	}
	std::cout << ":(" << std::endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    n,m = map(int,input().split())
    lst = list(map(int,input().split()))
    total = sum(lst)
    counter = 0
    for i in lst:
        if i >= total * (1 / (4 * m)):
            counter += 1

    if counter >= m:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


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

signed main() {
  int n,m;
  cin >> n >> m;
  vector<int> l(m), r(m);
  rep(i,m) cin >> l[i] >> r[i];

  int mnr=n, mxl=1;
  rep(i,m) {
    mxl = max(mxl, l[i]);
    mnr = min(mnr, r[i]);
  }
  if(mnr < mxl) cout << 0 << endl;
  else cout << mnr - mxl + 1 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i=0; i < (int)(N); i++)
 
int main() {
  int N;
  cin >> N;
  int l, r;
  
  int ans = 0;
  
  rep(i, N) {
    cin >> l >> r;
    ans += (r - l + 1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(N,R);
    if(N>=10){
        cout << R << nn;
    }else{
        cout << R + 100* (10-N) << nn;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;




signed main() {
    ll n, k;
    cin >> n >> k;
    
    vll a(n);
    
    map <ll, ll> mp;
    ll loop = 0;
    ll cnt = 0;
    ll amari = 0;
    vll lp(n);
    ll flg = 0;
    
    ll now = 1;
    ll r = 0;
    
    
    rep(i, n) {
        cin >> a[i];
        mp[i] = 0;
    }
    
    while(true) {
        
        if(cnt == k) {
            mes(now);
            re0;
        }
        cnt++;
        mp[now]++;
        
        if (mp[now] == 2) flg = 1;
        if (mp[now] == 3) break;
        if (flg == 1) {
            amari = cnt;
            lp[loop] = now;
            loop++;
        }
        now = a[now-1];
    }
    
    r = (k-amari) % loop;
    mes(lp[r]);
    
    
}

Measured memory_bytes: 18824
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int H, W;
    cin >> H >> W;

    vs m(H);
    REP(i, H) cin >> m[i];

    queue<pii> q;
    q.push(pii(0, 0));
    vvi dist(H, vi(W, -1));
    dist[0][0] = 1;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {-1, 0, 1, 0};
    while (!q.empty())
    {
        pii now = q.front();
        q.pop();

        REP(i, 4) {
            int nx = now.first + dx[i];
            if (!INRANGE(nx, 0, W-1)) continue;
            int ny = now.second + dy[i];
            if (!INRANGE(ny, 0, H-1)) continue;

            if (m[ny][nx] == '#') continue;
            if (dist[ny][nx] != -1) continue;

            q.push(pii(nx, ny));
            dist[ny][nx] = dist[now.second][now.first] + 1;
        }
    }


    
    if (dist[H-1][W-1] == -1) {
        cout << -1 << endl;
    } else {
        int cnt = 0;
        for (string l : m) {
            for (char c : l) if (c == '#') cnt++;
        }
        int nw = cnt + dist[H-1][W-1];

        cout << H*W - nw << endl;
    }

    return 0;
}


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

using namespace std;

const int HUGEI = 2147483647;  // (1 << 31) - 1
const long long HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";

int main(void) {
    long long x;
    cin >> x;
    long long pairs = x / 11;
    long long rest = x % 11;
    if (rest == 0) {
        cout << pairs * 2 << endl;
    } else if (rest <= 6) {
        cout << pairs * 2 + 1 << endl;
    } else {
        cout << pairs * 2 + 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
std::vector<vector<long long int>> v;
long long int h,w;
long long int cnt = 0;
long long MOD = 1000000000 + 7;
int main() {
	// your code goes here
	
     
     cin >> h >> w;
     std::vector<vector<long long int>> dp(h,vector<long long int>(w,0));
     v = dp;
     for(long long int i=0;i<h;i++){
          string x;
          cin >> x;
          for(long long int j=0;j<x.length();j++){
               if(x[j]=='.'){
                    v[i][j]=1;
                    
               }else{
                    v[i][j]=0;
               }
          }
     }
     for(long long int i=0;i<h;i++){
          if(v[i][0]==1){
               dp[i][0]=1;
          }else{
               break;
          }
     }
     for(long long int i=0;i<w;i++){
          if(v[0][i]==1){
               dp[0][i]=1;
          }else{
               break;
          }
     }
     // dp = v;
     dp[0][0]=1;
     for(int i=1;i<h;i++){
          for(int j=1;j<w;j++){
               if(v[i][j]==0){
                    dp[i][j]=0;
                    continue;

               }
               if(v[i-1][j]==1){
                    dp[i][j]+=dp[i-1][j];
                    dp[i][j]%=MOD;
               }
               if(v[i][j-1]==1){
                    dp[i][j]+=dp[i][j-1];
                    dp[i][j]%=MOD;
               }
          }
     }
     // for(int i=0;i<h;i++){
     //      for(int j=0;j<w;j++){
     //           cout << dp[i][j] << " ";
     //      }
     //      cout << endl;
     // }
     cout << dp[h-1][w-1];
	return 0;
}


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

const int divisor = 1000000007;

int main(){
	vector<int> ansvec;

	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	int* word = new int[100000] {0};

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;
		
		//まず0番目の単語を入れておく
		for (int i = 0; i < N; i++) word[i] = i + 1;

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		//word[i]をkey, word[i]より小さい数がそれ以前にいくつ使われていたかをvalueとして格納するmap
		map<int, int> bubblehist;
		bubblehist[word[0]] = 0;

		long long ans = factmodary[N-1] * (word[0] - 1);

		for (int i = 1; i < N; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.lower_bound(word[i]);

			if (it != bubblehist.end()){
				bubblenum = it->second;
				--it;
			}
			else {
				bubblenum = (--it)->second + 1;
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			map<int, int>::iterator it2 = bubblehist.insert(it, p);
			//word[i]より大きい数はすべてvalueが1増える
			for (++it2; it2 != bubblehist.end(); it2++) ++(it2->second);

			ans += factmodary[N - (i + 1)] * (facttime - bubblenum);
			ans %= divisor;
		}
		ansvec.push_back((int)ans);
	}

	for (vector<int>::iterator it = ansvec.begin(); it != ansvec.end(); it++) cout << *it << "\n";

	delete[] word;
	delete[] factmodary;
	return 0;
}

Measured memory_bytes: 6816
while True:
    try:
        a, b, c, d, e, f = map(float, input().split())
        x = (c*e - b*f)/(a*e - b*d)
        y = (a*f - c*d)/(a*e - b*d)
        print('%.3f %.3f' %(x+0,y+0))
    except:
        break

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

using namespace std;

#define all(c) (c).begin(), (c).end()

int main() {
	int n;
	cin>>n;
	vector <int> a(n);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		cin>>a[i];
		if (i > 0 && a[i] < a[i-1]) {
			sum += (a[i-1] - a[i]);
			a[i] = a[i-1];
		}
	}
	cout<<sum;
	cout<<endl;
	return 0;
}

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

int w,h;
double x,y;

int main(){
	scanf("%d%d",&w,&h);
	scanf("%lf%lf",&x,&y);
	printf("%.9lf ",((double)(w) * (double)(h))/2.0);
	if(x == ((double)(w)/2.0) && y==((double)(h)/2.0)){
		printf("1\n");
	} else {
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, a, b, c, A, B, C;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d %d", &a, &b, &c);
        A = a * a;
        B = b * b;
        C = c * c;
        if (A + B == C || A + C == B || B + C == A)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2520
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

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 int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    
    int ans = 0;
    int border = 0;
    REP(i,N){
        int tmp = 1;
        char c = S[i];
        if(S[i]=='L') while(i < N - 1 && S[i+1] == 'L') i++,tmp++;
        else while(i < N - 1 && S[i+1] == 'R') i++,tmp++;
        if(c == 'L'){
            ans += tmp - 1;
        }
        else{
            ans += tmp - 1;
        }
        border++;
    }
    cout << min(ans + 2 * K, N - 1) << endl;
}


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<ll, ll>;

vector<pii> lr;
int n, m;

bool can(int x) {
    vector<int> have;
    for (int i = 0; i < x; i++)
        have.push_back(0);
    for (int i = 1; i <= m; i++)
        have.push_back(i);
    priority_queue<int> R;
    vector<int> pos;
    reverse(have.begin(), have.end());
    for (auto p : lr) {
        if (have.empty())
            return false;
        R.push(-p.second);
        if (have.back() <= p.first) {
            have.pop_back();
            continue;
        }
        pos.push_back(-R.top());
        R.pop();
    }
    sort(pos.begin(), pos.end());
    int ptr = 0;
    reverse(have.begin(), have.end());
    for (int p : pos) {
        while (ptr < (int)have.size() && have[ptr] < p)
            ptr++;
        if (ptr == (int)have.size())
            return false;
        ptr++;
    }
    return true;
}
    
int main() {
#ifdef LOCAL
    // freopen("input", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(12);
    cin >> n >> m;
    //n = m = 200000;
    lr.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> lr[i].first >> lr[i].second;
        /*lr[i].first = rand() % (m + 2);
        lr[i].second = rand() % (m + 2);
        if (lr[i].first > lr[i].second)
            swap(lr[i].first, lr[i].second);
        */
    }
    sort(lr.begin(), lr.end());
    int low = -1;
    int high = n;
    while (high - low > 1) {
        int mid = (low + high) / 2;
        if (can(mid))
            high = mid;
        else
            low = mid;
    }
    cout << high << "\n";
}

Measured memory_bytes: 5492
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(decltype(N+k) i=k; i<N;i++)
#define rep(i,N) for(decltype(N) i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<< " ";}cout<<endl;}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return 約数unordered_set 1 <= x <= n
auto divv = [](auto n) {
  unordered_set<decltype(n)> v;
  for(decltype(n) i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.insert(i);
      if(i*i != n) v.insert(n/i);
    }
  }
  return v;
};

// check prime (and n>=2) or not
auto isPrime = [](auto n){
  if(n <= 1) return false;
  for(decltype(n) i = 2; i <= sqrt(n); ++i) {
      if(n % i == 0) {
          return false;
      }
  }
  return true;
};

// 最小公倍数
auto lcm = [](auto a, auto b){
    if(a<b) swap(a,b);
    auto r = a % b;
    auto x = a*b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return x/b;
};

// 最大公約数
auto gcd = [](auto a, auto b){
    return (a * b)/lcm(a,b);
};

// factorial n mod prm
ll factmod(ll a, ll prm){
    return a == 0 ? 1 : (a * factmod(a-1, prm)) % prm;
};

// 1/x mod prm
auto invmod = [](auto x, auto prm){
    decltype(x) r = 1;
    if (x==1) return r;
    for (auto ex = prm - 2; ex; ex >>= 1) {
        if (ex&1) r = (r * x) % prm;
        x = (x * x) % prm;
    }
    return r;
};

int main() {
  ll n,m;
  cin>>n>>m;
  if(n==m) pr("Yes");

  else pr("No");
  
}


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

const int MOD = 1e9 + 7;
int f[603][603] , N , K , pr[1203] , jc[1203];

int poww(long long a , int b){
	int times = 1;
	while(b){
		if(b & 1) times = times * a % MOD;
		a = a * a % MOD; b >>= 1;
	}
	return times;
}

int main(){
	cin >> N >> K; memset(pr , -1 , sizeof(pr));
	jc[0] = 1;
	for(int i = 1 ; i <= N ; ++i) jc[i] = 1ll * jc[i - 1] * (2 * i - 1) % MOD; 
	for(int i = 1 ; i <= K ; ++i){
		int x , y; cin >> x >> y; --x; --y; if(x > y) swap(x , y);
		pr[x] = y; pr[y] = x;
	}
	for(int i = 0 ; i < 2 * N ; ++i)
		for(int j = i + 1 ; j < 2 * N ; j += 2){
			int p1 = 0; bool flg = 1;
			for(int k = i ; k <= j ; ++k)
				if(pr[k] == -1) ++p1;
				else if(pr[k] < i || pr[k] > j) flg = 0;
			if(!flg) continue;
			f[i][j] = jc[p1 / 2];
		}
	
	for(int i = 1 ; i < 2 * N ; i += 2)
		for(int j = 0 ; j + i < 2 * N ; ++j){
			bool flg = 1;
			for(int t = (j + i + 1) % (2 * N) ; t != j ; t = (t + 1) % (2 * N))
				if(pr[t] >= j && pr[t] <= j + i) flg = 0;
			if(!flg) continue;
			int mn = j + i , p1 = 0;
			for(int t = j + i ; t > j ; --t){
				if(pr[t] != -1) mn = min(pr[t] , mn); else ++p1;
				if(t > mn || (p1 & 1)) continue;
				f[j][j + i] = (f[j][j + i] + MOD - 1ll * f[j][t - 1] * jc[p1 / 2] % MOD) % MOD;
			}
		}
	int sum = 0;
	for(int i = 0 ; i < 2 * N ; ++i)
		for(int j = i ; j < 2 * N ; ++j)
			if(f[i][j]){
				int p1 = 0;
				for(int t = (j + 1) % (2 * N) ; t != i ; t = (t + 1) % (2 * N))
					if(pr[t] == -1) ++p1;
				sum = (sum + 1ll * jc[p1 / 2] * f[i][j]) % MOD;
			}
	cout << sum; return 0;
}

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

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

Measured memory_bytes: 256
import numpy as np
from itertools import product

h, w, k = map(int, input().split())
l = []
for _ in range(h):
    s = input().replace(".", "0")
    s = map(int, list(s.replace("#", "1")))
    l.append(np.array(list(s)))
arr = np.array(l)
cnt = 0
for i in product((0, 1), repeat=h):
    tmp = (arr.T * i).T
    for j in product((0, 1), repeat=w):
        if sum(sum(tmp * j)) == k:
            cnt += 1
print(cnt)

Measured memory_bytes: 27248
n, k = map(int, input().split())
x = list(map(int, input().split()))
 
ans = []
 
for _ in range(n - k + 1):
    a = abs(x[k + _ - 1]) + abs(x[k + _ - 1] - x[_])
    b = abs(x[_]) + abs(x[_] - x[k + _ - 1])
    
    ans.append(min(a, b))
 
print(min(ans))

Measured memory_bytes: 85108
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() { 
  int h,w;
  cin >> h >> w;

  int a,b;
  cin >> a >> b;

  int ans = 0;
  ans = w * a;
  if (a < h) {
    ans += abs(h-a) * b;
  }
  cout << h * w - ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) ((a).begin(), (a).end())
typedef long long ll;
// const long long INF = 1LL << 60;
const int INF = 1010101010;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;

#define MAX_N 1000000

struct edge {
  int to;
  int cost;
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

int n;
vector<edge> G[MAX_N];
int d[MAX_N];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + n, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;

    for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int x, y;
  cin >> n >> x >> y;

  for (int i = 0; i < n - 1; i++) {
    edge e1 = {i, 1};
    edge e2 = {i + 1, 1};
    G[i + 1].push_back(e1);
    G[i].push_back(e2);
  }
  x--;
  y--;
  edge e1 = {y, 1};
  edge e2 = {x, 1};
  G[x].push_back(e1);
  G[y].push_back(e2);
  vector<int> ans(n);

  rep(k, n) {
    dijkstra(k);
    for (int i = 0; i < n; i++) {
      if (d[i] != INF) ans[d[i]]++;
    }
  }

  for (int i = 1; i < n; i++) cout << ans[i] / 2 << endl;
}

Measured memory_bytes: 25600
/*
M=額縁の数
C[]=額縁の大きさ
N=絵の枚数
S[]=絵の大きさ
V[]=絵の価値
*/
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main(void){
	int N,M,S,V;
	cin>>N>>M;
	int C[M];
	pair<int,int> paints[N]; //first V,second S
	for(int i=0;i<N;i++){
		cin>>S>>V;
		paints[i]=make_pair(V,S);
	}
	for(int i=0;i<M;i++){
		cin>>C[i];
	}
	sort(paints,paints+N);
	sort(C,C+M);
	int ans=0;
	for(int i=N-1;i>=0&&ans<M;i--){
		if(C[M-ans-1]>=paints[i].second){
			ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4340
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int n,k;
int dp[100005];
int a[100005];
int func(int i){
    if(i==n-1)  return 0;
    if(dp[i]!=-1)   return dp[i];
    int mini = INT_MAX;
    for(int j=1;j<=min(k,n-1-i);j++){
        mini = min(mini,abs(a[i+j] - a[i]) + func(i+j));
    }
    return dp[i] = mini;
}
int main(){
    cin>>n;
    cin>>k;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int cost  = func(0);
    cout<<cost<<endl;
}

Measured memory_bytes: 10560
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

   
    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var n = Read();
        var p = new long[n];
        for(int i = 0; i < n; i++)
        {
            p[i] = Read();
        }
        Console.WriteLine(p.Sum() - p.Max() / 2);

        Console.Out.Flush();
    }
}

Measured memory_bytes: 13396
#include "bits/stdc++.h"
#define rep(i,N) for (int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

	int N; std::cin >> N;
	std::vector<int> W(N);
	int sum = 0;
	rep(i, N) {
		std::cin >> W[i];
		sum += W[i];
	}
	int sum_before = 0;
	int sum_after = sum - sum_before;
	int difference = 10000;
	rep(T, N) {
		sum_before += W[T];
		sum_after = sum - sum_before;
		difference = std::min(difference, abs(sum_after - sum_before));
	}

	std::cout << difference;

	return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;

struct edge { int to,cost; };

int main() {
  string Sa,Sb,Sc;cin>>Sa>>Sb>>Sc;
  // せいぜい300なので順番に追いかける
  // カードを捨てる->交代なので、
  char cur = 'a';

  while (true) {
    if (cur=='a') {
      if (Sa.empty()) break;
      cur = Sa[0];
      Sa.erase(0,1);
    } else if (cur=='b') {
      if (Sb.empty()) break;
      cur = Sb[0];
      Sb.erase(0,1);
    } else {
      if (Sc.empty()) break;
      cur = Sc[0];
      Sc.erase(0,1);
    }
  }

  OUT((char)toupper(cur));

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int a,b,res;
char c;
while(1)
{
    cin>>a>>c>>b;
    if(c=='?')
        break;

    if(c=='+')
        res=a+b;
    else if(c=='-')
         res=a-b;
    else if(c=='*')
         res=a*b;
    else if(c=='/')
         res=a/b;

    cout<<res<<endl;
}

}




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

#define ll long long

int main(){
  
  ll A,B,C,X,Y,a,b,c,d,e,f,g;
  
  cin>>A>>B>>C>>X>>Y;
  a=A*X+B*Y;
  if(X>Y){
    
    b=C*2*X;
    c=C*2*Y+A*(X-Y);
    d=C*2*X;
    
  }else{
    
    b=C*2*Y;
    c=C*2*X+B*(Y-X);
    d=C*2*Y;
    
  }
  
  cout<<min(min(a,b),min(c,d))<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i, j, k, l, n, m;
    cin >> n;
    string s;
    cin >> s;
    ll red = 0, white = 0;
    for(auto x:s){
        if(x=='R')
            red++;
        else
            white++;
    }
    ll minans = min(red,white);
    ll ini = 1;
    ll fina = n;
    ll moves = 0;
    while(1){
        while(ini<=n&&s[ini-1]!='W')
            ini++;
        while(fina>=1&&s[fina-1]!='R')
            fina--;
        if(ini<fina){
            moves++;
            swap(s[ini - 1], s[fina - 1]);
        }    
        else{
            break;
        }
    }
    cout << min(minans, moves) << "\n";
    return 0;
}

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

int bfs(vector<string> &m) {
  bool used[12][12];
  for (int i=0; i<12; i++) {
    for (int j=0; j<12; j++) {
      used[i][j] = false;
    }
  }
  int cnt = 0;

  for (int i=0; i<12; i++) {
    for (int j=0; j<12; j++) {
      if (used[i][j]) {
        continue;
      }
      if (m[i][j] == '0') {
        continue;
      }
      queue<pair<int, int> > que;
      que.push({i, j});
      while (!que.empty()) {
        auto f = que.front();
        que.pop();
        int y = f.first;
        int x = f.second;
        if (used[y][x]) continue;
        if (m[y][x] == '0') continue;

        used[y][x] = true;

        if (y > 0) que.push({y-1, x});
        if (y < 11) que.push({y+1, x});
        if (x > 0) que.push({y, x-1});
        if (x < 11) que.push({y, x+1});
      }
      ++cnt;
    }
  }
  return cnt;
}
int main() {
  while (true) {
    vector<string> m(12);
    for (int i=0; i<12; i++) {
      cin>>m[i];
      if (m[i].empty()) {
        return 0;
      }
    }
    cout<<bfs(m)<<endl;
  }
}


Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);

	int dif1 = a[2] - a[0];
	int dif2 = a[2] - a[1];

	if ((dif1 + dif2) % 2 == 0) cout << (dif1 + dif2) / 2 << endl;
	else cout << (dif1 + dif2 + 3) / 2 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a,b,c,x,d,T=0;

	scanf("%d %d %d",&a,&b,&c);
	for (x = a;x <= b;x++) {
		if (c%x == 0) {
			T++;
		}
	}
	printf("%d\n",T);
	return 0;
}

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

int main() {
	int n;
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	b[n-2]=abs(a[n-1]-a[n-2]);
	if(n>=3)
	b[n-3]=abs(a[n-1]-a[n-3]);
	for(int i=n-4;i>=0;i--){
		b[i]=min(b[i+1]+abs(a[i]-a[i+1]),b[i+2]+abs(a[i+2]-a[i]));
	}
	cout<<b[0];
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,n;
ll N = 1e5+5;
vector<ll> arr(N);

bool ok(ll t){
	ll t1=t;
	for(int i=0;i<n;i++){
		if((arr[i]-(b*t1)) <=0){
			continue;
		}

			t =t- (arr[i]-(b*t1)+a-b-1)/(a-b);
	
			if(t<0){
				return 0;
			}
		

	}
	return 1;
	
}
int main(){
	cin>>n>>a>>b;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}

	ll l,r;
	l =1;
	r = *max_element(arr.begin(),arr.begin()+n);
	ll ans ;
	while(l<=r){
		ll mid = l+(r-l)/2;
		//cout<<mid<<"ok"<<l<<"ok"<<r<<endl;
		if(ok(mid)){
			r = mid-1;
			ans = mid;
		}
		else{
			l = mid+1;
		}
	}
	cout<<ans<<endl;
	
}

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

using namespace std;

int ans[200005];
int lef[200005];
int righ[200005];

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = (int)s.size();
    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == 'L') lef[i] = i;
        else lef[i] = lef[i + 1];
    }
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') righ[i] = i;
        else righ[i] = righ[i - 1];
    }
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') {
            int go = lef[i] - i;
            if (go % 2 == 0) {
                ans[lef[i]]++;
            }
            else {
                ans[lef[i] - 1]++;
            }
        }
        else {
            int go = i - righ[i];
            if (go % 2 == 0) ans[righ[i]]++;
            else ans[righ[i] + 1]++;
        }
    }
    for (int i = 0; i < n; ++i) cout << ans[i] << " ";
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define int ll
#define PI (acos(-1))

//const ll mod = 1000000007;

int p, a, b, c;

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

edge es[11223]; // 辺
int d[10000];   // 最短距離[頂点の最大数]
int V, E;       // V:頂点数，E:辺数

// 頂点sから各頂点への最短距離を求める
bool shortest_path(int s) {
    // 初期化
    for (int i = 0; i < V; i++) d[i] = INF;
    d[s] = 0;

    int cnt = 0;
    int temp = 0;
    while (true) {
        bool is_updated = false;
        // 全ての辺について更新（実際は到達域から伸びている辺について更新）
        for (int i = 0; i < E; i++) {
            edge e = es[i];
            // 到達域の辺　かつ　より短くなる　場合更新
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                is_updated = true;
            }
        }

        cnt++;
        if (cnt == V) temp = d[V - 1];
        if (cnt == 10 * V) {
            if (temp == d[V - 1]) {
                return true;
            }
            else {
                return false;
            }
        }
        // 更新されなくなったら終了
        if (!is_updated) return true;
    }
}

signed main() {
    cin >> V >> E >> p;
    for (int i = 0; i < E; i++) {
        cin >> a >> b >> c;
        es[i] = {a - 1, b - 1, p - c};
    }

    bool ok = shortest_path(0);
    if (ok) cout << max(-d[V - 1], 0LL) << endl;
    else cout << -1 << endl;

}

// グラフ
// コスト最大化(ベルマンフォード)

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#define mop 1000000007

using namespace std;

int m[101][101] = {};
int d[101] = {};
int n;
int INFTY = (1 << 15);
void bfs(int s){
    queue<int> q;
    q.push(s);
    for (int i=0; i<=n;i++){
        d[i] = INFTY;
    }
    d[s] = 0;
    int u;
    while(!q.empty()){
        u = q.front();
        q.pop();
        for (int v=1;v<=n;v++){
            if(m[u][v] == 0){
                continue;
            }
            if(d[v] != INFTY){
                continue;
            }
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for (int i=1;i<=n;i++){
        cout << i << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
    }
}
int main() {
    
    cin >> n;
    for (int i=1;i<=n;i++){
        int u,k;
        cin >> u >> k;
        for (int j = 0;j<k;j++){
            int p;
            cin >> p;
            m[i][p] = 1;
           
        }
    }
    bfs(1);

}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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




ll N,K,h[101010];
ll i, j, k;


int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i,0,N){
        scanf("%lld", &h[i]);
        if(h[i]>=K)
            j++;
    }
    printf("%lld", j);
    return 0;
}

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

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

using namespace std;

int main() {
  int N;
  cin >> N;
  while( N-- ) {
    int r,t;
    cin >> r >> t;
    if( r % 100 == 0 && t % 30 == 0 ) {
      printf("%d\n",int(r/100)+int(t/30)*5);
    } else if( r % 100 == 0 ) {
      printf("%d %d\n",int(t/30)*5+int(r/100),(int(t/30)+1)*5+int(r/100));
    } else if( t % 30 == 0 ) {
      printf("%d %d\n",int(t/30)*5+int(r/100),int(t/30)*5+int(r/100)+1);
    } else {
      printf("%d %d %d %d\n",int(t/30)*5+int(r/100),int(t/30)*5+int(r/100)+1,(int(t/30)+1)*5+int(r/100),(int(t/30)+1)*5+int(r/100)+1);
    }
  }
  return 0;
}

Measured memory_bytes: 1148
#include <stdio.h>
 
int main()
{
  char S[8];
  scanf("%s",&S);
  if (S[0] == 'S')
  {
    printf("Cloudy");
  }
  else if (S[0] == 'C')
  {
    printf("Rainy");
  }
  else
  {
    printf("Sunny");
  }
}

Measured memory_bytes: 128
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(string, "x", long, "y");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto a = aryread();
    auto s = a.sum();
    bool flag = true;
    foreach (i; iota(n))
        if(a[i] >= s - a[i])
            flag = false;

    if(flag)
        writeln("Yes");
    else
        writeln("No");
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

int main(){
    int a[3]={0};
    int i;
    for (int j=0;j<2;j++){
        cin >> i;
        a[i-1] = 1;
    }
    for (int j=0;j<3;j++){
        if(a[j]==0){
            cout << j+1;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	for(int i = 1; i <= n; i++){
		int x = i;
		if(x % 3 == 0)
			cout << " " << i;
		else {
			while(x > 0){
				if(x % 10 == 3){
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}

	}
	cout << endl;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int fi=n;
  int dig,sum=0;
  while(n){
    dig=n%10;
    sum+=dig;
    n=n/10;
  }
  if(fi%sum==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256