akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long l1,l2;
    l1=2;l2=1;
    if (n==1){
        cout<<1;
        exit(0);
    }
    else if (n==2){
        cout<<3;
        exit(0);
    }
    for (int i =0;i<n-1;i++){
        long long tmp;
        tmp=l2;
        l2+=l1;
        l1=tmp;
    }
    cout<<l2;
    
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename F>
static inline constexpr decltype(auto) fix(F&& f) noexcept {
  return [f = std::forward<F>(f)](auto&&... args) {
    return f(f, std::forward<decltype(args)>(args)...);
  };
}
template<typename T>
static inline T fin() { T t; cin >> t; return std::move(t); }

int main() {
  i64 n;
  cin >> n;
  vector<i64> h(n);
  for(int i = 0;i < n;i++) cin >> h[i];
  vector<i64> dp(n + 1, 1e9);
  dp[1] = 0;
  for(int i = 1;i < n;i++) {
    dp[i + 1] = dp[i] + abs(h[i] - h[i - 1]);
    if(i > 1) {
      dp[i + 1] = min(dp[i + 1], dp[i - 1] + abs(h[i] - h[i - 2]));
    }
  }
  cout << dp[n] << endl;
}


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

Measured memory_bytes: 4992
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

long long int MOD = 1e9 + 7;

int main(){

  // read problem
  long long int N;
  std::string Stmp;
  scanf("%lld", &N);
  std::cin >> Stmp;
  std::string S = "W" + Stmp;

  std::cerr << "S: " << std::endl << S << std::endl;

  // solve problem
  long long int tmp_left = 0;
  long long int tmp_state = 0; // left
  long long int ans = 1;
  long long int possible = 1;

  for(long long int i = 1; i <= 2*N; i++){
    std::cerr << i << " " << tmp_left << " " << tmp_state << std::endl;
    if(S[i] != S[i-1]){
      // keep tmp_state
      if(tmp_state == 0){ // left
        tmp_left++;
      }
      else{// right
        ans *= tmp_left;
        ans = (ans+MOD)%MOD;
        tmp_left--;
      }
    }
    else{
      // change tmp_state
      if(tmp_state == 0){
        tmp_state = 1; // right
        ans *= tmp_left;
        ans = (ans+MOD)%MOD;
        tmp_left--;
      }
      else{
        tmp_state = 0; // left
        tmp_left++;
      }
    }
    // check answer
    if(tmp_left < 0){
      ans = 0;
      break;
    }
  }

  // left has not been used up
  if(tmp_left != 0){
    ans = 0;
  }

  // order of choosing pairs
  for(long long int i = 1; i <= N; i++){
    ans *= i;
    ans = (ans+MOD)%MOD;
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 772
#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>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

    int x,y;
    cin >> x >> y;
    ll ans = 0;
    if(x == 3) ans+=100000;
    if(x == 2) ans+=200000;
    if(x == 1) ans+=300000;
    if(y == 3) ans+=100000;
    if(y == 2) ans+=200000;
    if(y == 1) ans+=300000;
    if(x == 1 and y == 1) ans+=400000;

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        char[][] map = new char[H][W];
        for (int i = 0; i < H; i++) {
            map[i] = scan.next().toCharArray();
        }
        int[][] dp = new int[H][W];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                dp[i][j] = Integer.MAX_VALUE;
            }
        }
        dp[0][0] = map[0][0] == '#' ? 1 : 0;
        for (int j = 0; j < W-1; j++) {
            dp[0][j+1] = dp[0][j] + (map[0][j] != map[0][j+1] && map[0][j+1] == '#' ? 1 : 0);
        }
        for (int i = 0; i < H - 1; i++) {
            dp[i+1][0] = dp[i][0] + (map[i][0] != map[i+1][0] && map[i+1][0] == '#' ? 1 : 0);
        }
        for (int i = 1; i < H; i++) {
            for (int j = 1; j < W; j++) {
                dp[i][j] = Math.min(dp[i][j], dp[i-1][j] + ((map[i-1][j] != map[i][j] && map[i][j] == '#') ? 1 : 0));
                dp[i][j] = Math.min(dp[i][j], dp[i][j-1] + ((map[i][j-1] != map[i][j] && map[i][j] == '#') ? 1 : 0));
            }
        }
        System.out.println(dp[H-1][W-1]);
    }
    class UnionFind {
        int H;
        int W;
        int[] parent;
        int[] size;
        UnionFind(int H, int W) {
            this.H = H;
            this.W = W;
            int[] size = new int[H*W];
            Arrays.fill(size, 1);
            int[] parent = new int[H*W];
            for (int i = 0; i < H*W; i++) {
                parent[i] = i;
            }
            this.size = size;
            this.parent = parent;
        }
        int find(int r, int c) {
            return find(r * W + c);
        }
        int find(int key) {
            if (key == this.parent[key]) {
                return key;
            }
            return this.parent[key] = find(this.parent[key]);
        }
        boolean same(int r1, int c1, int r2, int c2) {
            return find(r1, c1) == find(r2, c2);
        }
        void unite(int r1, int c1, int r2, int c2) {
            int parent1 = find(r1, c1);
            int parent2 = find(r2, c2);
            if (parent1 == parent2) {
                return;
            }
            int size1 = this.size[parent1];
            int size2 = this.size[parent2];
            if (size1 < size2) {
                this.size[parent2] += this.size[parent1];
                this.size[parent1] = 0;
                this.parent[parent1] = parent2;
                return;
            }
            this.size[parent1] += this.size[parent2];
            this.size[parent2] = 0;
            this.parent[parent2] = parent1;
        }
    }
}


Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ofstream w_file("abc145_e.txt", ios::out);

    ll N, T;
    cin >> N >> T;
    vector<pair<ll, ll>> dish(N);
    Rep (i, N) {
        ll A, B;
        cin >> A >> B;
        dish[i] = make_pair(A, B);
    }

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

    vector<vector<ll>> dp(N+1, vector<ll>(T+1, 0));
    Rep (i, N) {
        ll a = dish[i].first, b = dish[i].second;
        Rep (j, T+1) {
            chmax(dp[i+1][j], dp[i][j]);
            if (j-a >= 0) {
                chmax(dp[i+1][j-a], dp[i][j] + b);
            }
        }
    }

    ll ans = 0;
    Rep (i, N) {
        chmax(ans, dp[i][1] + dish[i].second);
    }

    cout << ans << "\n";
}

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

// zero-based numbering
template<class T> struct Fenwick {
    vector<T> bit; int N;
    Fenwick(int n) : N(n) { bit.assign(n+1, 0); }
    void clear() { bit.assign(N+1, 0); }
    // add w to a
    void add(int a, T w) {
        for (int x = ++a; x <= N; x += x & -x) bit[x] += w;
    }
    // sum [0, a)
    T sum(int a) {
        T ret = 0;
        for (int x = a; x > 0; x -= x & -x) ret += bit[x];
        return ret;
    }
    // sum [a, b)
    T sum(int a, int b) { return sum(b) - sum(a); }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    using Line = array<double, 2>;
    vector<Line> x, y;
    vector<int> idx;
    for (int i = 0; i < N; i++) {
        double a, b, c; cin >> a >> b >> c;
        x.push_back({-a/b, c/b});
        y.push_back({-b/a, c/a});
        idx.emplace_back(i);
    }
    Fenwick<int> fw(N);
    auto f = [&](auto &v) {
        const int M = (N * (N - 1) / 2) / 2;
        const int C = 100;
        sort(v.begin(), v.end());
        double ok = 1e10, ng = -1e10;
        for (int ci = 0; ci < C; ci++) {
            fw.clear();
            double x = (ok + ng) / 2;
            auto cmp = [&](int &i, int &j) {
                double p = v[i][0] * x + v[i][1];
                double q = v[j][0] * x + v[j][1];
                return (p != q) ? p < q : i > j;
            };
            sort(idx.begin(), idx.end(), cmp);
            int m = 0;
            for (auto &i: idx) {
                m += fw.sum(i, N); fw.add(i, 1);
            }
            if (m <= M) ok = x;
            else ng = x;
        }
        return ok;
    };
    cout << setprecision(12) << f(x) << " " << f(y) << "\n";
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  long long c1 = 0, c2 = 0, s1 = 0, s2 = 0;
  for (int i = 0; i < n; i++) {
    s1 += a[i];
    s2 += a[i];
    if (i & 1) {
      if (s1 >= 0) {c1 += s1 + 1; s1 = -1;}
      if (s2 <= 0) {c2 += 1 - s2; s2 = 1;}
    } else {
      if (s1 <= 0) {c1 += 1 - s1; s1 = 1;}
      if (s2 >= 0) {c2 += s2 + 1; s2 = -1;}
    }
  }
  cout << min(c1, c2) << '\n';
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define N 1050
using namespace std;
int a[N],n,ans;
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
int main() {
	n = rd() * 2;
	for (int i=1;i<=n;i++) a[i] = rd();
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i+=2) ans += a[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) b[a[i]-1] = i+1;
    rep(i,n-1) cosp(b[i]);
    co(b[n-1]);
    return 0;

}

Measured memory_bytes: 1664
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>


int main() {
	
	int S,W;
	scanf("%d %d",&S,&W);
	
	if(S>W){
		printf("safe");
	}else{
		printf("unsafe");
	}
	
	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int a[200] = { 1,9,30,76,141,267,400,624,885,1249,1590,2208,2689,3411,4248,5248,6081,7485,8530,10248,11889,13687,15228,17988,20053,22569,25242,28588,31053,35463,38284,42540,46581,50893,55362,61824,65857,71247,76884,84388,89349,97881,103342,111528,120141,128047,134580,146316,154177,164817,174438,185836,194157,207927,218812,233268,245277,257857,268182,288216,299257,313635,330204,347836,362973,383709,397042,416448,434025,456967,471948,499740,515581,536073,559758,583960,604833,633651,652216,683712,709065,734233,754734,793188,818917,846603,874512,909496,933081,977145,1006126,1041504,1073385,1106467,1138536,1187112,1215145,1255101,1295142,1342852,1373253,1422195,1453816,1502376,1553361,1595437,1629570,1691292,1726717,1782111,1827492,1887772,1925853,1986837,2033674,2089776,2145333,2197483,2246640,2332104,2379085,2434833,2490534,2554600,2609625,2693919,2742052,2813988,2875245,2952085,3003306,3096024,3157249,3224511,3306240,3388576,3444609,3533637,3591322,3693924,3767085,3842623,3912324,4027884,4102093,4181949,4270422,4361548,4427853,4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692 };
int main() {
    int k;
    cin >> k;
    cout << a[k - 1] << endl;
}


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

int cnt;

void selectionSort(int A[], int n){
  for(int i = 0; i < n - 1; i++){
    int min = i;
    for(int j = i + 1; j < n; j++){
      if(A[j] < A[min]) min = j;
    }
    if(min != i){
      swap(A[i], A[min]);
      cnt++;
    }
  }
}

int main(void){
  int n, A[100];
  
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];

  selectionSort(A, n);

  for(int i = 0; i < n; i++){
    cout << A[i];
    if(i < n - 1) cout << " ";
  }
  cout << "\n" << cnt << endl;
  return 0;
}

Measured memory_bytes: 1164
#!/usr/bin/python
# coding: UTF-8


#import scipy.optimize
#import numpy as np

    
##################################################################

if __name__ == "__main__":

    Input1 = [input() for i in range(1)]
    DD = Input1[0]
    Easy = 'Yes'
    for step in range(len(DD)):
        if step % 2 == 0:
            if not DD[step] in ['R','U','D']:
                Easy = 'No'
                break
        else:
            if not DD[step] in ['L','U','D']:
                Easy = 'No'
                break
    print(Easy)


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define eb emplace_back

int main()
{
    ll N, K;
    cin >> N >> K;
    mat G(N);
    REP(i,0,N-1) {
        ll a, b;
        cin >> a >> b;
        --a; --b;
        G[a].eb(b);
        G[b].eb(a);
    }

    if(K == 1) {
        if(N == 1) PR(1);
        else PR(0);
    }
    else if(K == 2) {
        if(N <= 2) PR(2);
        else PR(0);
    }
    else {
        vec P(K-1, 1);
        REP(i,1,K-1) P[i] = (P[i-1] * (K-i-1)) % MOD; // = (K-2)_P_i = (K-2) * ... * (K-i-1)
        ll cnt = K, d = 0, c;
        queue<ll> Q;
        vec F(N, false);
        Q.push(0);
        F[0] = true;
        while(!Q.empty()) {
            ll v = Q.front(); Q.pop();
            c = 0;
            FORR(nv,G[v]) {
                if(!F[nv]) {
                    Q.push(nv);
                    F[nv] = true;
                    ++c;
                }
            }
            ++d;
            if(d == 1) {
                if(K-1 < c) {
                    cnt = 0;
                    break;
                }
                else {
                    REP(i,0,c) cnt = (cnt * (K-1-i)) % MOD;
                }
            }
            else {
                if(K-2 < c) {
                    cnt = 0;
                    break;
                }
                else {
                    cnt = (cnt * P[c]) % MOD;
                }
            }
        }
        PR(cnt);
    }

    return 0;
}

/*



*/

Measured memory_bytes: 11816
n, m, l = map(int, input().split())
matrix_a = [list(map(int, input().split())) for i in range(n)]
matrix_b = [list(map(int, input().split())) for i in range(m)]
mul_matrix_a_b = [[sum([matrix_a[i][k] * matrix_b[k][j] for k in range(m)]) for j in range(l)] for i in range(n)]
for result in mul_matrix_a_b:
    print(*result)

Measured memory_bytes: 7768
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int answer = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			answer += a[i] * a[j];
		}
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h> 
int main()
{
	int n; 
	while(scanf("%d",&n)!=EOF)
	{
		int i,j,a[3005],b[3005];
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]); 
			b[i]=a[i]-1; 
		}
		int sum=0;
		for(i=0;i<n;i++)
		{
			sum=sum+b[i]; 
		}
		printf("%d\n",sum);		 
	} 
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#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)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r=0,w=0;
  rep(i,n){
    if(s[i]=='R')r++;
  }
  int ans = INF;
  chmin(ans,max(w,r));
  rep(i,n){
    if(s[i]=='R')r--;
    else w++;
    chmin(ans,max(w,r));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
struct Interval{ll start,end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}

vll divisors[10000001];
int main(){
	fio;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll first = 0, last = n-1;
	ll total = 0;
	while(first < last){
		if(s[first] == 'R'){
			first++;
			continue;
		}
		if(s[last] == 'W'){
			last--;
			continue;
		}
		if(s[first] == 'W' && s[last] == 'R'){
			s[first] = 'R';
			s[last] = 'W';
			first++;
			last--;
			total++;
		}
	}
	cout<<total;
	return 0;
}

Measured memory_bytes: 238144
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n+1)

    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)

        if x == y:
            return False
        if self.Size(x) < self.Size(y):
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x

        return True

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    def Size(self, x):
        return -self.root[self.Find_Root(x)]

N, M = map(int, input().split())
A = [0] * M
B = [0] * M
for i in range(M):
    A[i], B[i] = map(int, input().split())

ans = [0] * M
ans[-1] = N * (N-1) // 2

Uni = UnionFind(N)

for i in range(M-1, 0, -1):
    ans[i-1] = ans[i]
    if Uni.Find_Root(A[i]) != Uni.Find_Root(B[i]):
        ans[i-1] -= Uni.Size(A[i]) * Uni.Size(B[i])
        Uni.Unite(A[i], B[i])

for i in range(M):
    print(ans[i])


Measured memory_bytes: 16960
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args)
	{
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);
 		
 		long n =fr.nextLong() ,i ,j ;
 		i =(n/500l) * 1000l ;	n %= 500l ;
 		i += (n/5l)*5l ;
 		op.println(i) ;
		op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

		String next() {
			while (st==null || (!st.hasMoreElements())) 
			{
				try
				{
					st =new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}
				
			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}


Measured memory_bytes: 24404
#include <iostream>

using namespace std;

int main() {
	
	int n;
	
	while(cin >> n && n != 0) {
		
		int temp, sum = 0;
		
		for(int i=0;i<n/4;i++) {
			
			cin >> temp;
			sum += temp;
			
		}
		
		cout << sum << "\n";
		
		
	}
	
	return 0;
	
}


Measured memory_bytes: 3076
fn main() {
    let (n, mut k): (usize, usize) = (read::<usize>(), read::<usize>());
    let mut adjl: Vec<Vec<usize>> = vec![vec![]; n];
    for i in 0..n {
        adjl[i].push(read::<usize>() - 1);
    }
    let mut rem = HashSet::new();
    let mut path = vec![];
    let mut cur = 0;
    // 閉路が見つかる && kがつきるまで
    let mut s = 0;
    for _ in 0..n {
        if k == 0 {
            break;
        }
        if rem.contains(&cur) {
            // pathからそのインデックスの位置を探したい.
            for i in 0..path.len() {
                if path[i] == cur {
                    s = i;
                    break;
                }
            }
            break;
        } else {
            rem.insert(cur);
            path.push(cur);
            cur = adjl[cur][0];
        }
        k -= 1;
    }
    if k == 0 {
        println!("{}", cur + 1);
    } else {
        println!("{}", path[s + k % (path.len() - s)] + 1);
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    for (int i = 0; 2 * i <= N - 1; ++i) {
        ll sum;
        if (2 * i == N - 1) {
            sum = A[N - 2] + A[N - 1];
        } else
            sum = A[2 * i] + A[2 * i + 1];
        if (-sum > sum) {
            A[2 * i] *= -1;
            A[2 * i + 1] *= -1;
        }
    }
    ll ans = 0;
    rep(i, N) ans += A[i];
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N;
    cin >> N;
    vector<ll> P(N),S(N);
    for(int i=0;i<N;i++){
        cin >> P[i];
        S[i]=P[i];
    }
    sort(S.begin(),S.end());
    ll mis=0;
    for(int i=0;i<N;i++){
        if(S[i]!=P[i]) mis++;
    }
    
    cout << (mis==0 || mis==2 ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut seq = vec![(0, 0); n];
    for i in 0..n {
        seq[i].0 = read();
        seq[i].1 = i;
    }
    seq.sort();
    let left = seq[n / 2 - 1].0;
    let right = seq[n / 2].0;
    let mut ans = vec![0; n];
    for i in 0..n {
        ans[seq[i].1] = if i < n / 2 { right } else { left };
    }
    for i in 0..n {
        println!("{}", ans[i]);
    }
}


Measured memory_bytes: 12412
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 87;
const int INF = 8787;
int A[MAXN], B[MAXN];
int dp[1 << 20][MAXN];

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    for (int i = 0; i < N; i++)
        scanf("%d", &B[i]);
    for (int S = 0; S < (1 << N); S++)
        for (int i = 0; i < N; i++)
            dp[S][i] = INF;
    dp[0][0] = 0;
    for (int S = 0; S < (1 << N); S++) {
        for (int lst = 0; lst < N; lst++) {
            if (S && !((1 << lst) & S)) continue;
            int cnt = 0;
            for (int i = 0; i < N; i++)
                if ((1 << i) & S)
                    cnt++;
            for (int i = 0; i < N; i++) {
                if ((1 << i) & S) continue;
                int nS = (S | (1 << i));
                int cost = 0;
                for (int j = 0; j < i; j++)
                    if (!((1 << j) & S))
                        cost++;
                int lst_num = A[lst];
                if (abs(lst - (cnt - 1)) % 2)
                    lst_num = B[lst];
                int cur_num = A[i];
                if (abs(i - cnt) % 2)
                    cur_num = B[i];
                if (S && (cur_num < lst_num)) continue;
                dp[nS][i] = min(dp[nS][i], dp[S][lst] + cost);
            }
        }
    }
    int ans = -1;
    for (int i = 0; i < N; i++) {
        int cur = dp[(1 << N) - 1][i];
        if (cur == INF)
            continue;
        else if (ans == -1)
            ans = cur;
        else
            ans = min(ans, cur);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 90496
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
typedef pair<int, int> P;

int a,b,n;
int point[20][20];
bool busy[20][20];
bool used[20][20];

int main(){
	while(scanf("%d%d", &a, &b)){
		if(a == 0 && b == 0) break;
		for(int i = 0; i < 20; i++) for(int j = 0; j < 20; j++){
			point[i][j] = 0;
			busy[i][j] = 0;
			used[i][j] = 0;
		}
		scanf("%d", &n);
		point[1][1] = 1;
		for(int i = 0; i < n; i++){
			int x, y;
			scanf("%d%d", &x, &y);
			busy[y][x] = true;
		}
		if(busy[1][1]){
			printf("0\n");
			return 0;
		}
		queue<P> que;
		que.push(P(1,1));
		while(!que.empty()){
			P p = que.front(); que.pop();
			int pf = p.first, ps = p.second;
			if(pf < b && busy[pf+1][ps] == false){
				point[pf+1][ps] += point[pf][ps];
				if(!used[pf+1][ps]) que.push(P(pf+1,ps));
				used[pf+1][ps] = true;
			}
			if(ps < a && busy[pf][ps+1] == false){
				point[pf][ps+1] += point[pf][ps];
				if(!used[pf][ps+1]) que.push(P(pf,ps+1));
				used[pf][ps+1] = true;
			}
		}
		printf("%d\n", point[b][a]);
	}
}

Measured memory_bytes: 1036
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

long long x[1005];
long long y[1005];
long long z[1005];

long long xx[8] = {1,1,1,1,-1,-1,-1,-1};
long long yy[8] = {1,1,-1,-1,1,1,-1,-1};
long long zz[8] = {1,-1,1,-1,1,-1,1,-1};

int main(){
  int n,m;cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>z[i];
  }

  long long ans = 0;
  for(int i=0;i<8;i++){
    vector<long long> vi;
    for(int j=0;j<n;j++){
      vi.push_back(x[j]*xx[i] + y[j]*yy[i] + z[j]*zz[i]);
    }
    sort(vi.begin(),vi.end());
    long long tmp=0LL;
    for(int j=0;j<m;j++)tmp+= vi[n-1-j];
    ans = max(ans,tmp);
  }
  cout<<ans<<endl;


}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int tmp;
    int ans = 0;
    int most = 0;
    rep(i,5)
    {
        cin >> tmp;
        if(tmp%10 != 0)
        {
            if((10 - tmp%10) > most) most = (10 -tmp%10);
            tmp += (10 - tmp%10);
        }
        ans += tmp;
    }
    ans -= most;
    cout << ans << endl;

}


Measured memory_bytes: 256
from collections import deque

n,k = map(int,input().split())

h = []
for i in range(n):
	h.append(int(input()))

h.sort()
h = deque(h)
d = []
d = deque(d)

for _ in range(k):
	d.append(h.popleft())

ans = d[-1] - d[0]
for _ in range(n-k):
	d.popleft()
	d.append(h.popleft())
	num = d[-1] - d[0]
	if ans > num:
		ans = num
print(ans)


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

const int INF=1e8;
const int N=2e5+5;
int n,dp[N],nxt[26];
pair<int,int> trace[N];
string s;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>s;
	n=s.size();
	for(int i=0;i<N;++i) 
		dp[i]=INF;
	dp[n+1]=0;
	dp[n]=1;
	for(int i=0;i<26;++i)
		nxt[i]=n+1;
	for(int i=n-1;~i;--i){
		nxt[s[i]-'a']=i+1;
		for(int j=0;j<26;++j)
			if(dp[nxt[j]]+1<dp[i]){
				dp[i]=dp[nxt[j]]+1;
				trace[i]=make_pair(j,nxt[j]);
			}
	}
	for(int i=0;i<n+1;){
		char c=trace[i].first+'a';
		cout<<c;
		i=trace[i].second;
	}
	cout<<'\n';
}




Measured memory_bytes: 6132
#include<bits/stdc++.h>
using namespace std;
int main() {
	double n;
	cin>>n;
	double a,b,h;
	a=n/3.0;
	b=n/3.0;
	h=n-a-b;
	printf("%0.12f",(double)(a*b*h));
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        mut a: [i64; n],
    }
    a.push(0i64);
    a.reverse();
    a.push(0i64);
    a.reverse();

    let mut s: i64 = 0;;
    for i in 0..n + 1 {
        s += (a[i] - a[i + 1]).abs();
    }
    for i in 1..n + 1 {
        println!(
            "{}",
            s + (a[i - 1] - a[i + 1]).abs() - ((a[i - 1] - a[i]).abs() + (a[i] - a[i + 1]).abs())
        )
    }
}


Measured memory_bytes: 5372
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];
	
	string ans="Three";
	for (int i = 0; i < n; i++) {
		if (s[i] == "Y") {
			ans = "Four";
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc153/tasks/abc153_e
// dynamic programming
import std.algorithm;
import std.stdio;

void main() {
    long h, n;
    readf("%s %s\n", &h, &n);

    long[] a = new long[n];
    long[] b = new long[n];

    foreach(i; 0..n) {
        readf("%s %s\n", &a[i], &b[i]);
    }

    const long MAXN = 10^^5;
    const long INF = 1<<30;

    long[] dp = new long[MAXN];
    for(long i = 0; i < MAXN; ++i)
        dp[i] = INF;

    dp[0] = 0;

    for(long i = 0; i < n; ++i) {
        for(long hp = 0; hp < h; ++hp) {
            if(dp[hp] < INF)
                dp[hp+a[i]] = min(dp[hp]+b[i], dp[hp+a[i]]);
        }
    }

    long minima = INF;
    for(long i = h; i < MAXN; ++i)
        minima = min(minima, dp[i]);

    minima.writeln;
}



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

int main() {
  string s;
  cin >> s;
  
  int r = 0;
  int c = 0;
  
  for(int i = 0; i < 3; i++){
    if(s.at(i) == 'R'){
      c++;
      if(r < c){
        r = c;
      }
    }
    else c = 0;
  }
  cout << r << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int n;
    cin>>n;

    string s;
    cin>>s;

    if ( s.length() % 2 != 0 )
    {
        cout<<"No"<<endl;
    }
    else
    {
        int found = 0;
        rep(i,0,s.length()/2)
        {
            if ( s[i] != s[i+s.length()/2] )
            {
                found = 1;
                break;
            }
        }

        if ( found == 1 )
        {
            cout<<"No"<<endl;
        }
        else
        {
            cout<<"Yes"<<endl;
        }
        
    }
    
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

int main(){
    string s;
    cin >> s;
    VI a(4);
    rep(i,4) a[i] = s[i] - '0';

    char op[3];
    rep(b,8){
        int sum = a[0];
        rep(i,3){
            if(b & (1 << i)){
                sum += a[i+1];
                op[i] = '+';
            }else{
                sum -= a[i+1];
                op[i] = '-';
            }
        }
        if(sum==7) break;
    }

    cout<<a[0]<<op[0]<<a[1]<<op[1]<<a[2]<<op[2]<<a[3]<<"=7"<<endl;

    return 0;
}

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

using namespace std;

int main(){
    int N;
    bool ans = true;
    cin >> N;
    vector<string> W(N);
    for(int i=0;i<N;i++){
        cin >> W.at(i);
    }
    for(int i=1;i<N;i++){
        for(int j=0;j<i;j++){
            if(W.at(i)==W.at(j)){
                ans = false;
            }
        }
        if(ans==true){
            if(W.at(i-1).back()!=W.at(i).front()){
                ans = false;
            }
        }
    }
    cout << (ans==true ? "Yes" : "No") << endl;
    
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
s=input()
cnt1=0
cnt2=0
for i in range(n):
  if s[i]=='a':
    if cnt1+cnt2<a+b:
      cnt1+=1
      print('Yes')
    else:
      print('No')
  elif s[i]=='b':
    if cnt1+cnt2<a+b and cnt2<b:
      cnt2+=1
      print('Yes')
    else:
      print('No')
  else:
    print('No')

Measured memory_bytes: 4016
def Z_algo(S):
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    c = 0#最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        #i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i+LCP[i-c] < c+LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and S[j] == S[i+j]: j+=1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP
ans = 0
N = int(input())
S = input()
for i in range(N):
    LCP = Z_algo(S[i:])
    for j, l in enumerate(LCP):
        tmp = min(l, j)
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 52572
n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
  s=input()
  if s=="AC":
    ac+=1
  elif s=="WA":
    wa+=1
  elif s=="TLE":
    tle+=1
  else:
    re+=1

print("AC"+" x "+str(ac))
print("WA"+" x "+str(wa))
print("TLE"+" x "+str(tle))
print("RE"+" x "+str(re))


Measured memory_bytes: 9200
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e3 + 10;
int dp[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int ncase;
	cin >> ncase;
	while (ncase--)
	{
		int n, k;
		cin >> n >> k;
		if (n % 2 == 0) k ^= 127;
		cout << 127 * (n - 1) + k << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = list(input())
t = list(input())

s.sort()
t.sort(reverse=True)

flag = False
for i in range(min(len(s), len(t))):
    if s[i] < t[i]:
        flag = True
        break
    elif s[i] > t[i]:
        flag = False
        break
    else:
        if i == min(len(s), len(t)) - 1:
            if len(s) < len(t):
                flag = True
            else:
                flag = False

if flag:
    print('Yes')
else:
    print('No')


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

using namespace std;

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

#define F first
#define S second

const int MAXN = 300 + 5;

int n;
bool ok[MAXN][MAXN];
string s[MAXN];

int get(int x){return x < n? x: x - n;}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) cin >> s[i];
	int ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++){
			bool fail = false;
			for (int w = 0; w < n; w++)
				fail |= s[get(i+w)][j] != s[i][get(j+w)];
			ok[i][j] = !fail;
		}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			bool fail = false;
			for (int w = 0; w < n; w++)
				fail |= !ok[get(i+w)][get(j+w)];
			ans += !fail;
		}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int k;
    string s;
    cin >> k >> s;
    if(s.length() <= k)
    cout << s;
    else{
    cout << s.substr(0,k);
    cout << "...";
    }
}









Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s;  
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s;
    rep(i, 0, s.size()) {
        if (s[i] == '1') cout << 9;
        else cout << 1;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 764