akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a, b = [], []
lst = []
for i in range(1, n+1):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
    lst.append([ai, bi, i])

if n % 2 == 1:
    a.sort()
    b.sort()
    idx = n//2
    print(b[idx]-a[idx]+1)
    exit()

a.sort()
b.sort()
mini = (a[n//2]+a[n//2-1])/2
maxi = (b[n//2]+b[n//2-1])/2
print(int((maxi-mini)*2+1))

Measured memory_bytes: 131256
#include <iostream>

int main(void) {
  int N;
  char hina;
  bool four = false;
  
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cin >> hina;
    four = four || (hina == 'Y');
  }
  std::cout << (four ? "Four" : "Three") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
  int i,j,a,b,c;
  string str;
  cin >> str;
  for(i=0;i<str.size();i++){
    if(str[i]<68){
      str[i]=str[i]+23;
    }
    else{
      str[i]=str[i]-3;
    }
  }
  for(i=0;i<str.size();i++){
    cout << str[i];
  }
  cout << endl;
}

Measured memory_bytes: 1176
#include <stdio.h>
#include <math.h>

int main(void) {
  int n,m,s[5],c[5];
  int i,j;
  int o,check = 0;

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

  for(i = 0;i < m;i++){
    scanf("%d %d", &s[i], &c[i]);
  }

  if (m == 0) {
    o = (int)(pow(10, (double)(n - 1)) + 0.5);
    if( n == 1 ){
      o = 0;
    }
    printf("%d", o);
    return 0;
  }

  for (i = 0; i < m; i++) {
    if(n != 1 && s[i] == 1 && c[i] == 0){
      printf("-1");
      return 0;
    }
    if (n > 1) {
      if (s[i] == 1) {
        check = 1;
      }
    }
  }
  if (n > 1 && check == 0) {
    o = (int)(pow(10, (double)(n - 1)) + 0.5);
  }

  for(i = 0;i < m-1;i++){
    for(j = i+1;j < m;j++){
      if(s[i] == s[j]){
        if(c[i] != c[j]){
          printf("-1");
          return 0;
        }
        if(c[i] == c[j]){
          c[j] = 0;
        }
      }
    }
  }

  // = 0;
  for(i = 0;i < m;i++){
    o += c[i] * (int)(pow(10, (double)(n - s[i])) + 0.5);
  }

  printf("%d", o);
}

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

int main() {
  int n;
  while(cin >> n, n) {
    int w, h; cin >> w >> h;
    bool field[110][110];
    //memset(field, false, sizeof(field));
    for(int i = 0; i < 110; i++) {
      for(int j = 0; j < 110; j++) {
        field[i][j] = false;
      }
    }

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

    int s, t; cin >> s >> t;
    int ans = 0;
    for(int i = 1; i < h-t+10; i++) {
      for(int j = 1; j < w-s+10; j++) {
        int sum = 0;
        for(int k = 0; k < t; k++) {
          for(int l = 0; l < s; l++) {
            if(field[i+k][j+l]) sum++;
          }
        }
        if(sum > ans) ans = sum;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1168
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=20005;
int n,s[N],ds[N],da[N],db[N],i,j,k,a[N],b[N];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%d",&j);
		s[j]=i;
	}
	for(i=1;i<n;++i)
		ds[i]=s[i+1]-s[i];
	k=0;
	for(i=1;i<n;++i)
	{
		da[i]=ds[i]+1;
		db[i]=1;
		k=min(k,da[i]);
	}
	for(i=1;i<n;++i)
		da[i]+=-k+1,db[i]+=-k+1;
	a[1]=1,b[1]=s[1]-1;
	for(i=2;i<=n;++i)
	{
		a[i]=a[i-1]+da[i-1];
		b[i]=b[i-1]-db[i-1];
	}
	for(i=1;i<=n;++i)
		b[i]+=-b[n]+1;
	for(i=1;i<=n;++i)
		printf("%d ",a[i]);
	puts("");
	for(i=1;i<=n;++i)
		printf("%d ",b[i]);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
long long dp[60][2501],a[60];
int main()
{
	long long  n,i,j,k,s,t,k1;
	scanf("%lld%lld",&n,&k1);
	{
	  for(i=1;i<=n;i++)
	  scanf("%lld",&a[i]);
	  memset(dp,0,sizeof(0));
	  dp[0][0]=1;
	  for(k=1;k<=n;k++)
	    {
	    	for(i=k-1;i>=0;i--)
	    	  {
	    	  	for(j=0;j<=50*i;j++)
	    	  	  dp[i+1][j+a[k]]+=dp[i][j];
			  }
		}
	  long long m=0;
	  for(i=1;i<=n;i++)
	    {
	    	int x=i*k1;
	    	if(x<=2500) m+=dp[i][x];
		}
		printf("%lld\n",m);
	}
  return 0;
}

Measured memory_bytes: 768
#include <cstdio>

int reserve[300];

int main()
{
  int h, w, k;
  scanf("%d%d%d", &h, &w, &k);
  char s[300][301];
  for (int i = 0; i < h; ++i)
  {
    scanf("%s", s[i]);
  }
  int ans[300][300];
  int id = 1;
  bool any = false;
  for (int i = 0; i < h; ++i)
  {
    int found = 0;
    for (int j = 0; j < w; ++j)
    {
      if (s[i][j] == '#')
      {
        ++found;
      }
    }
    if (found == 0)
    {
      if (any)
      {
        for (int j = 0; j < w; ++j)
        {
          ans[i][j] = ans[i - 1][j];
        }
      }
    }
    else
    {
      int target = id + found;
      for (int j = 0; j < w; ++j)
      {
        ans[i][j] = id;
        if (s[i][j] == '#' && id + 1 < target) ++id;
      }
      id = target;
      if (!any)
      {
        for (int ii = i - 1; ii >= 0; --ii)
        {
          for (int j = 0; j < w; ++j)
          {
            ans[ii][j] = ans[i][j];
          }
        }
      }
      any = true;
    }
  }
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      printf("%d%c", ans[i][j], j == w - 1 ? '\n' : ' ');
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[3005];
bool parity[3005];
vector<int> al[3005];
vector<pair<int,int> > sorted;
int memo[3005];

int dp(int node){
if (memo[node]!=-1) return memo[node];
    for (int x : al[node]){
        if (arr[x]<arr[node])
            if (dp(x)==0) return memo[node] = 1;
    }
    return memo[node] = 0;
    
}




int main(){
    scanf("%d",&n);
    memset(memo,-1,sizeof(memo));
    for (int x=1;x<=n;x++) {
    scanf("%d",&arr[x]);
    sorted.push_back({arr[x],x});
    }
    
    int a,b;
    for (int x=1;x<n;x++){
        scanf("%d%d",&a,&b);
        al[a].push_back(b);
        al[b].push_back(a);
    }
    for (int x = 1; x<=n; x++){
        if (dp(x)==1) printf("%d ",x);
    }
    
}

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

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

#define rep(i, j, k) for (int i = j; i < k; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int x;
    cin >> x;

    rep(a, -1000, 1001) rep(b, -1000, 1001) {
        if (a * a * a * a * a - b * b * b * b * b == x) {
            cout << a << " " << b << endl;
            return 0;
        }
    }
    return 0;
}


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

public class Main {

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

		int secTime = Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());

		int h = secTime / 3600;
		int m = (secTime - (secTime / 3600) * 3600) / 60;
		int s = secTime % 60;

		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 24296
while True:
    H, W = list(map(int, input().split()))
    if H == 0 and  W == 0:
        break
    for i in range(H):
        for j in range(W):
            if j == W-1:
                if i == H-1:
                    if (i+j)%2 == 0:
                        print("#\n")
                    else:
                        print(".\n")
                else:
                    if (i+j)%2 == 0:
                        print("#")
                    else:
                        print(".")                    
            else:
                if (i+j)%2 == 0:
                    print("#", end="")
                else:
                    print(".", end="")


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb push_back
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD= 1e9+7 ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}

bool compare(string a, string b){
	if(a.length()==b.length())
		return a<b;
	return a.length()<b.length();
}

int main()
{
    fast;
    int t;
    t = 1;
    //~ cin>>t;
    
    while(t--){
		ll n;
		cin>>n;
		if(n%10==7 or (n/10)%10==7 or ((n/10)/10)%10==7){
			cout<<"Yes";
		}else cout<<"No";
	}
    
    return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


int nCr(int n , int r ) {
	int p = 1, k = 1;

	if (n - r < r ) {
		r = n - r;
	}
	if (r != 0) {
		while (r != 0) {
			p *= n ;
			k *= r ;
			int m = __gcd(p, k);
			p /= m;
			k /= m;
			n--;
			r--;
		}
	}
	else {
		p = 1;
	}
	return p ;
}

void aryan_p() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}


int32_t main() {


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

	if(a<10 and b<10 and a>0 and b>0){
		cout<<a*b;
	}
	else{
		cout<<-1;
	}


	return 0;
}

Measured memory_bytes: 3600
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ll n,ans=0;
    cin>>n;
    lvec a(n),b(n),p(n);
    rep(i,n){
        cin>>a[i]>>b[i];
        p[i]=a[i]%b[i];
    }
    for(int i=n-1;i>0;i--){
        ans+=(b[i]-p[i])%b[i];
        p[i-1]=(ans+p[i-1])%b[i-1];
    }
    ans+=(b[0]-p[0])%b[0];
    cout<<ans<<endl;
}

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

int main() {
    string s;
    int a, z;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }
    for (int i = s.size()-1; i > 0; i--) {
        if (s[i] == 'Z') {
            z = i;
            break;
        }
    }
    cout << z-a+1 << endl;
}

Measured memory_bytes: 640
n,k=map(int, input().split())
r,s,p=map(int, input().split())
t=input()
ans=0
for i in range(k):
  u=t[i::k]
  u=u.replace("rr", "rx")
  u=u.replace("pp", "px")
  u=u.replace("ss", "sx")
  ans+=u.count("s")*r
  ans+=u.count("p")*s
  ans+=u.count("r")*p
print(ans)

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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

bool isCat(string &s) {
    int depth = 0;
    vector<int> stack(s.size(), 0);
    REP (i, 0, s.size()) {
        if (s[i] == 'm') {
            stack[depth++] = 1;
        } else if (s[i] == 'e') {
            if (depth <= 0 || stack[depth - 1] != 1) return false;
            stack[depth - 1] = 2;
        } else if (s[i] == 'w') {
            if (depth <= 0 || stack[depth - 1] != 2) return false;
            stack[depth - 1] = 0;
            depth--;
        } else {
            return false;
        }
        if (depth <= 0) return i == s.size() - 1;
    }
    return depth == 0;
}

int main () {
    string S;
    cin >> S;
    cout << (isCat(S) ? "Cat" : "Rabbit") << endl;
    return 0;
}

Measured memory_bytes: 3208
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        String s = new String(new StringBuilder(in.ns()).reverse());
        boolean flag = true;
        int i = 0;
        while(i < s.length()){
            if(i+5<=s.length()&&(s.substring(i,i+5).equals("maerd")||s.substring(i,i+5).equals("esare"))){
                i += 5;
                continue;
            }
            if(i+6<=s.length()&&s.substring(i,i+6).equals("resare")){
                i += 6;
                continue;
            }
            if(i+7<=s.length()&&s.substring(i,i+7).equals("remaerd")){
                i += 7;
                continue;
            }
            flag = false;
            break;
        }
        out.println(flag?"YES":"NO");
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 27476
w, h, n = gets.split.map(&:to_i)
max_y = Hash.new(0)
n.times do
    x, y = gets.split.map(&:to_i)
    max_y[x] = y if y > max_y[x]
end
d = w - 1
y = 0
(w - 2).downto(0) do |x|
    y = max_y[x + 1] if y < max_y[x + 1]
    d = x + y if d > x + y
end
p d


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


public class Main {
	
	static int W;
	static int H;
	static int[][] MAP ;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			// 整数の入力
			W = Integer.parseInt(sc.next());
			H = Integer.parseInt(sc.next());
			if(W==0 && H==0)break;
			MAP = new int[H][W];
			
			for(int h=0; h<H; h++){
				for(int w=0; w<W; w++){
					MAP[h][w] = Integer.parseInt(sc.next());
				}
			}
			int ans=0;
			
			for(int h=0; h<H; h++){
				for(int w=0; w<W; w++){
					if(MAP[h][w]==1){
						dfs(w,h);
						ans++;
					}
				}
			}
			
			
			System.out.println(ans);
		}
		sc.close();
	}
	
	public static void dfs(int w, int h){
		if(w<0 || w>=W || h<0 || h>=H)return;
		if(MAP[h][w] == 0)return;
		MAP[h][w] = 0;
		for(int dh=-1; dh<2; dh++){
			for(int dw=-1; dw<2; dw++){
				dfs(w+dw, h+dh);
			}
		}
	}
	
}



Measured memory_bytes: 39760
h, w = map(int, input().split())
if h == 1 or w == 1:
  a = 1
elif h % 2 == 1 and w % 2 == 1:
	a = int((h * w + 1) / 2) 
else:
	a = int(h * w / 2)
print(a)

Measured memory_bytes: 2940
#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() {
    string s;
    string ans;
    cin >> s;
    rep(i,s.size()) {
        if (i % 2 == 0) {
            ans += s[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;

#define ld long double
#define int long long
#define pb push_back 
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii map<int,int> 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef vector< pii > vp;
void swap(int &a,int &b)
{ auto tm=a; a=b; b=tm; }
 
  //Take care of duplicates

  const int mod=1000000007;
  const int mod2=998244353;
  const int INF=(1LL<<50)-1;
  const int N=2e5+25;
  const int M=123456;
 

 void bheja_fry()
 { 
   int a,b; cin>>a>>b;

   cout<<(a*b)/__gcd(a,b);
 }
                                                         
signed main()
{ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
   
   int t=1;                         
 //  cin>>t;
  rep(i,1,t+1)
  { // cout<<"Case #"<<i<<": ";
   bheja_fry();
   if(i<t)
   cout<<nl;
  }

 return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

long long int LCM(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return (a / dummy1) * (b / dummy1) * dummy1;
}

long long int GCD(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return dummy1;
}

int main(){
	
	int N = 100000;
	
	bool a[100000];
	
	for(int i = 0; i < N; i++){
		a[i] = true;
	}
	
	a[0] = false;
	a[1] = false;
	
	for(int i = 2; i < N; i++){
		if(a[i]){
			for(int j = i * 2; j < N; j += i){
				a[j] = false;
			}
		}
	}
	
	long long int p, q;
	
	cin >> p >> q;
	
	q = q / GCD(p, q);
	
	long long int ans = 1;
	long long int sq_q = sqrt(q);
	
	for(int i = 1; i <= sq_q; i++){
		if(a[i] && q % i == 0){
			ans *= i;
			while(q % i == 0){
				q /= i;
			}
		}
	}
	
	ans *= q;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3184
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int N,K;
int adj[5][5];
int a,b;
bool isImpossible;
int arr[4]={1,2,3,4};
bool isPossible(int cnt){
	if(cnt==3){
		return true;
	}
	if(adj[arr[cnt]][arr[cnt+1]]==1){
		return isPossible(cnt+1);
	}
	else{
		return false;
	}
}

int main(){
	for(int i=0;i<3;i++){
		scanf("%d %d",&a,&b);
		adj[a][b]=adj[b][a]=1;
	}
	bool solution=false;
	do{
		solution=isPossible(0);
		if(solution){
			break;
		}
	}while(next_permutation(arr,arr+4));

	if(solution){
		puts("YES");
	}
	else{
		puts("NO");
	}
	return 0;
}

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

int main() {
  int n; cin>>n;
  int res=0;
  for (int i=3; i<=n; i+=2) {
    int X=i;
    int cnt=0;
    for (int j=1; j*j<=X; j++) {
      if (X%j==0) {
        if (j*j!=X) cnt+=2;
        else cnt++;
      }
    }
    if (cnt==8) res++;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a,b,c;
    std::cin >> a >> b >> c;
    if (a > b) swap(a,b);
    if (b > c) swap(b,c);
    if (a > b) swap(a,b);
    std::cout << a << ' '
              << b << ' '
              << c << std::endl;
    return 0;
}


Measured memory_bytes: 3100
//OPTIMIZATONS
#pragma GCC optimize("02")
//CODE
#include<bits/stdc++.h>
#define int long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	string inp;
	set<string> s;
	for(int i=0;i<n;i++){
		cin>>inp;
		s.insert(inp);
	}
	cout<<s.size()<<endl;
	return 0;
}



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

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,c=0;
	string st;
	cin >> n >> st;
	for(int i=0;i<n-2;i++){
		// cout << st.substr(i,3) << endl;
		if(st.substr(i,3)=="ABC")c++;
	}
	cout << c;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [-1 for _ in range(n)]

curr = 0
cnt = 0
k += 1
while k > 1:
  if b[curr] != -1:
    loop = cnt - b[curr]
    break
  b[curr] = cnt
  cnt += 1
  k -= 1
  curr = a[curr] - 1

if k != 1:
  mod = k % loop
  for i in range((mod-1) % loop):
    curr = a[curr] - 1

print(curr + 1)

Measured memory_bytes: 32348
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const double eps=1e-9;
int t[303030];
long long sum[303030];
long long b[303030];
long long dp1[303030],dp2[303030];
int st[303030],sn;
double getc(int x,int y)
{
	return (double)(b[x]-b[y])/(x-y);
}
long long getv(int i,int x)
{
	return -(long long)i*x+b[i];
}
int n;
void work(long long *dp)
{
	sn=0;
	sum[0]=0;
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+t[i];
	dp[0]=0;
	b[0]=0;
	st[++sn]=0;
	for(int i=1;i<=n;i++)
	{
		dp[i]=dp[i-1];
		while(sn>1&&getv(st[sn-1],i)>=getv(st[sn],i))
			sn--;
		dp[i]=max(dp[i],getv(st[sn],i)+(long long)i*(i+1)/2-sum[i]);
		b[i]=dp[i]+(long long)i*(i-1)/2+sum[i];
		while(sn>1&&getc(i,st[sn])+eps>getc(i,st[sn-1]))
			sn--;
		st[++sn]=i;
	}
}
long long ans[303030];
long long tmp[303030];
void work1(int l,int r)
{
	if(l==r)
		return;
	int mid=(l+r)>>1;
	sn=0;
	for(int i=l;i<=mid;i++)
	{
		b[i]=dp1[i]+(long long)i*(i+1)/2+sum[i];
		while(sn>1&&getc(i,st[sn])+eps>getc(i,st[sn-1]))
			sn--;
		st[++sn]=i;
	}
	for(int i=mid+2;i<=r;i++)
	{
		while(sn>1&&getv(st[sn-1],i)>=getv(st[sn],i))
			sn--;
		tmp[i-1]=getv(st[sn],i)+dp2[i]+(long long)i*(i-1)/2-sum[i-1];
	}
	for(int i=r-2;i>=mid+1;i--)
		tmp[i]=max(tmp[i],tmp[i+1]);
	sn=0;
	for(int i=mid+1;i<=r;i++)
	{
		b[i]=dp2[i]+(long long)i*(i-1)/2-sum[i-1];
		while(sn>1&&getc(i,st[sn])+eps>getc(i,st[sn-1]))
			sn--;
		st[++sn]=i;
	}
	for(int i=l;i<mid;i++)
	{
		while(sn>1&&getv(st[sn-1],i)>=getv(st[sn],i))
			sn--;
		tmp[i+1]=getv(st[sn],i)+dp1[i]+(long long)i*(i+1)/2+sum[i];
	}
	for(int i=l+2;i<=mid;i++)
		tmp[i]=max(tmp[i],tmp[i-1]);
	for(int i=l+1;i<r;i++)
		ans[i]=max(ans[i],tmp[i]);
	work1(l,mid);
	work1(mid+1,r);
}
int main()
{
	int m,p,x;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&t[i]);
	work(dp1);
	for(int i=1;i<=(n>>1);i++)
		swap(t[i],t[n-i+1]);
	work(dp2);
	for(int i=0;i<=(n>>1);i++)
		swap(dp2[i],dp2[n+1-i]);
	for(int i=1;i<=(n>>1);i++)
		swap(t[i],t[n-i+1]);
	sum[0]=0;
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+t[i];
	for(int i=1;i<=n;i++)
		ans[i]=-1010101010;
	work1(0,n+1);
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&p,&x);
		printf("%lld\n",max(dp1[p-1]+dp2[p+1],ans[p]-x+t[p]));
	}
	return 0;
}

Measured memory_bytes: 19200
#include <bits/stdc++.h>
#define x first
#define y second 
using namespace std;

typedef pair<int, int> PII;

const int maxn = 3e5 + 5;

int w, h, n, ans;

int mx[maxn * 4], tag[maxn * 4];

PII a[maxn], b[maxn], p[maxn];

void pushdown(int x) {
	tag[x << 1] += tag[x];
	tag[x << 1 | 1] += tag[x];
	mx[x << 1] += tag[x];
	mx[x << 1 | 1] += tag[x];
	tag[x] = 0;
}

void update(int l, int r, int x, int a, int b, int d) {
	if(l > b || r < a) {
		return;
	}
	if(l >= a && r <= b) {
		tag[x] += d;
		mx[x] += d;
		return;
	}
	pushdown(x);
	int mid = (l + r) >> 1;
	update(l, mid, x << 1, a, b, d);
	update(mid + 1, r, x << 1 | 1, a, b, d);
	mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
}

void solve() {
	memset(mx, 0, sizeof(mx));
	memset(tag, 0, sizeof(tag));
	
	sort(p + 1, p + n + 1);
	
	int l = 0, r = 0;
	
	for(int i = 1; i < n; ++i) {
		if(p[i].y <= h / 2) {
			int nxt = i - 1;
			while(l && p[i].y > a[l].y) {
				update(1, n, 1, a[l].x, nxt, a[l].y - p[i].y);
				nxt = a[l].x - 1;
				--l;
			}
			if(nxt != i - 1) {
				a[++l] = PII(nxt + 1, p[i].y);
			}
		} else {
			int nxt = i - 1;
			while(r && p[i].y < b[r].y) {
				update(1, n, 1, b[r].x, nxt, p[i].y - b[r].y);
				nxt = b[r].x - 1;
				--r;
			}
			if(nxt != i - 1) {
				b[++r] = PII(nxt + 1, p[i].y);
			}
		}
		
		a[++l] = PII(i, 0);
		b[++r] = PII(i, h);
	
		update(1, n, 1, i, i, h - p[i].x);
	
		ans = max(ans, p[i + 1].x + mx[1]);	
	
	}
}

int main() {
	
	scanf("%d%d%d", &w, &h, &n);
	
	for(int i = 1; i <= n; ++i) {
		scanf("%d%d", &p[i].x, &p[i].y);
	}
	
	p[++n] = PII(0, 0);
	p[++n] = PII(w, h);
	
	solve();
	for(int i = 1; i <= n; ++i) {
		swap(p[i].x, p[i].y);
	}
	
	swap(w, h);
	
	solve();
	
	printf("%d\n", ans << 1);
	
	return 0;
}

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

int main() {
  int n;
  string s;
  vector<string> strings;
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> s;
    strings.push_back(s);
  }
  
  for (auto i : strings) {
    if (count(strings.begin(), strings.end(), i)>1) {
      cout << "No";
      return 0;
    }
  }
        
  for (int i=1; i<n; i++) {
    if (strings[i].substr(0, 1)!=strings[i-1].substr(strings[i-1].size()-1, 1)) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

struct mint {
	ll x;
	mint(ll x=0):x((x%MOD+MOD)%MOD){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
	if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += MOD-a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}

	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint mpow(int x, int r) {
	if (r == 0) return 1;
	mint res = mpow(x, r/2);
	res *= res;
	if (r % 2 == 1) res *= x;
	return res;
}

mint nCr(int n, int r) {
	mint x = 1, y = 1;
	rep(i,r) {
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << mpow(2, n) - 1 - nCr(n, a) - nCr(n, b) << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
  int N;
  cin >> N;
  int a[N];
  rep(i, N){
    cin >> a[i];
  }
  sort(a, a + N);
  int A = 0, B = 0;
  int j = 0;
  for (int i = N-1; i >= 0; --i)
  {
    if (j % 2 == 0)
    {
      A += a[i];
    }else{
      B += a[i];
    }
    j++;
  }
  cout << A - B << endl;
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  int count = 0;
  if (S.at(0) == S.at(1) && S.at(2) == S.at(3))
    count++;
  if (S.at(0) == S.at(2) && S.at(1) == S.at(3)) 
    count++;
  if (S.at(0) == S.at(3) && S.at(1) == S.at(2))
    count++;
  if (count == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
      
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>
int main(void)
{
    int i,n;
    char s[100];

    scanf("%s",s);
    n=strlen(s);

    if(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[5]=='c'&&s[6]=='e'){
        printf("YES");
    }
    else if(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[5]=='c'&&s[n-1]=='e'){
        printf("YES");
    }
    else if(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[n-2]=='c'&&s[n-1]=='e'){
        printf("YES");
    }
    else if(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[n-3]=='n'&&s[n-2]=='c'&&s[n-1]=='e'){
        printf("YES");
    }
    else if(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[n-4]=='e'&&s[n-3]=='n'&&s[n-2]=='c'&&s[n-1]=='e'){
        printf("YES");
    }
    else if(s[0]=='k'&&s[1]=='e'&&s[n-5]=='y'&&s[n-4]=='e'&&s[n-3]=='n'&&s[n-2]=='c'&&s[n-1]=='e'){
        printf("YES");
    }
    else if(s[0]=='k'&&s[n-6]=='e'&&s[n-5]=='y'&&s[n-4]=='e'&&s[n-3]=='n'&&s[n-2]=='c'&&s[n-1]=='e'){
        printf("YES");
    }
    else if(s[n-7]=='k'&&s[n-6]=='e'&&s[n-5]=='y'&&s[n-4]=='e'&&s[n-3]=='n'&&s[n-2]=='c'&&s[n-1]=='e'){
        printf("YES");
    }
    else{
        printf("NO");
    }
    
    return 0;
}

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

int main(void){

	int n;
	cin >> n;

	vector<int>h(n);
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}

	int ans = 1;
	for(int i = 1; i < n; i++){
		bool canSee = false;

		if(h[i-1] <= h[i]){
			canSee = true;
			for(int j = 0; j < i; j++){
				if(h[j] > h[i]){
					canSee = false;
					break;
				}
			}
		}

		if(canSee) ans++;
	}
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
s = input()
a = [0 for _ in range(len(s) + 1)]
for i in range(len(s)):
    if s[i] == "<": a[i+1] = a[i] + 1
for i in reversed(range(len(s))):
    if s[i] == ">" and a[i+1] >= a[i]: a[i] = a[i+1] + 1
print(sum(a))

Measured memory_bytes: 23976
import numpy as np
s = list(input())
count = np.array([1] + [0] * 3).astype("int64")
for i in s:
    if i == 'A':
        count[1] += count[0]
    elif i == 'B':
        count[2] += count[1]
    elif i == 'C':
        count[3] += count[2]
    else:
        count[3] = count[3] * 3 + count[2]
        count[2] = count[2] * 3 + count[1]
        count[1] = count[1] * 3 + count[0]
        count[0] *= 3
    count %= 1000000007
print(count[3])

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

int main() {
  int N;
  cin >> N;
  int B = 0;
  int C = 0;
  int D = 0;
  int E = 0;
  int F = 0;
  for ( int i; i < N ; i++){
    string A;
    cin >> A;
    if ( A == "G" ) {
      if ( C == 0)
        C++;
    }
    if ( A == "W" ) {
      if ( D == 0 ) 
        D++;
    }
    if ( A == "G" ) {
      if ( E == 0 )
        E++;
    }
    if ( A == "Y" ) {
      if ( F == 0 )
        F++;
    }
  }
  B = C + D + E + F;
  if ( B == 3 ) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
}


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

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    inc_flag = None
    dec_flag = None
    ans = 0
    for i in range(1, N):
        if inc_flag is None and dec_flag is None and a_list[i-1] < a_list[i]:
            inc_flag = True
        elif inc_flag is None and dec_flag is None and a_list[i-1] > a_list[i]:
            dec_flag = True
        elif inc_flag is True and a_list[i-1] > a_list[i]:
            ans += 1
            inc_flag = None
        elif dec_flag is True and a_list[i-1] < a_list[i]:
            ans += 1
            dec_flag = None
    print(ans + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14168
#include <stdio.h>

int main(){
    
    int a,b,c,d,e,f,g,h,i,j;
    int n1,n2,n3;
    
    scanf("%d",&a);
    scanf("%d",&b);
    
    if(b > a){
        
        n1 = b;
        n2 = a;
        
    }else{
        
        n1 = a;
        n2 = b;
        
    }
    
    scanf("%d",&c);
    
    if(c > n1){
        
        n2 = n1;
        n1 = c;
        
    }else if(c > n2){
        
        n3 = n2;
        n2 = c;
        
    }else{
        
        n3 = c;
        
    }
    
    scanf("%d",&d);
    
    if(d > n1){
        
        n3 = n2;
        n2 = n1;
        n1 = d;
        
    }else if(d > n2){
        
        n3 = n2;
        n2 = d;
        
    }else if(d > n3){
        
        n3 = d;
        
    }
    
    scanf("%d",&e);
    
    if(e > n1){
        
        n3 = n2;
        n2 = n1;
        n1 = e;
        
    }else if(e > n2){
        
        n3 = n2;
        n2 = e;
        
    }else if(e > n3){
        
        n3 = e;
        
    }
    
    scanf("%d",&f);
    
    if(f > n1){
        
        n3 = n2;
        n2 = n1;
        n1 = f;
           
    }else if(f > n2){
        
        n3 = n2;
        n2 = f;
        
    }else if(f > n3){
        
        n3 = f;
        
    }
    
    scanf("%d",&g);
    
    if(g > n1){
        
        n3 = n2;
        n2 = n1;
        n1 = g;
        
    }else if(g > n2){
        
        n3 = n2;
        n2 = g;
        
    }else if(g > n3){
        
        n3 = g;
        
    }
    
    scanf("%d",&h);
    
 if(h > n1){
        
        n3 = n2;
        n2 = n1;
        n1 = h;
        
    }else if(h > n2){
        
        n3 = n2;
        n2 = h;
        
    }else if(h > n3){
        
        n3 = h;
        
    }


    scanf("%d",&i);
    
     if(i > n1){
        
        n3 = n2;
        n2 = n1;
        n1 = i;
        
    }else if(i > n2){
        
        n3 = n2;
        n2 = i;
        
    }else if(i > n3){
        
        n3 = i;
        
    }
    
    
    scanf("%d",&j);
    
     if(j > n1){
        
        n3 = n2;
        n2 = n1;
        n1 = j;
        
    }else if(j > n2){
        
        n3 = n2;
        n2 = j;
        
    }else if(j > n3){
        
        n3 = j;
        
    }
    
    
    printf("%d\n",n1);
    printf("%d\n",n2);
    printf("%d\n",n3);
    

    return 0;   
}

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

using namespace std;

int main(){
  int n[3];

  for(int i = 0;i < 3;i++){
    cin >> n[i];
  }

  sort(n,n+3);

  cout << n[2] * 10 + n[1] + n[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;

int main()
{
    string a;
    cin >> a;
    int ans = 100000;
    for(int i = 0; i < a.size() - 2; i++){
        int tmp = (a[i]-'0') * 100 + (a[i+1]-'0') * 10 + a[i+2]-'0';
        ans = min(ans,abs(tmp-753));
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  int ans[100000]={0};
  bool R=true;
  int pl,pr,st=0;
  rep(i,s.size() ){
    // cout<<pl<<" "<<pr<<" "<<st<<endl;
    if(R){
      if(s[i]=='L'){
	if((i-st) %2 ==0 ){pl=i-1;pr=i;}
	else {pl=i;pr=i-1;}
      
	R=false;
      }
    }
    else{
      if(s[i]=='R'){
	ans[pl]=(i-st)/2;
	ans[pr]=(i-st)-ans[pl];
	st=i;
	R=true;
      }
    }
  }
  ans[pl]=(s.size()-st)/2;
  ans[pr]=(s.size()-st)-ans[pl];
  rep(i,s.size() ){
    cout<<ans[i];
    if(i!=s.size() -1) cout<<" ";
  }
  cout<<endl;
  
  return 0;
}


Measured memory_bytes: 1488
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll modpow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

const ll MAX = 2000000;
ll fac[MAX], finv[MAX], inv[MAX];
// nCk初期化
void nCkInit(const ll MOD) {//O(max(n,r)logmax(n,r) mは素数)
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll nCk(ll n, ll k,const ll MOD){//init後,O(1)
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll K;
string S;
map<char,ll> mp;
int main(){
    cin>>K>>S;
    nCkInit(MOD);
    ll ans=0;
    for(ll i=0;i<=K;i++){
        ans=(ans+nCk(K+S.length()-1-i,S.length()-1,MOD)*modpow(25,K-i,MOD)%MOD*modpow(26,i,MOD)%MOD)%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 51176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N; cin>>N;
	int P[N];
	rep(i,0,N){ cin>>P[i]; P[i]--; }
	int dp[N] = {}; int t = 0;
	rep(i,0,N){
		if(P[i] == 0) dp[0] = 1;
		else dp[P[i]] = dp[P[i]-1] + 1;
        t = max(t, dp[P[i]]);
	}cout<<N - t<<endl;
}

Measured memory_bytes: 1792
H, W = map(int, input().split())
ans = 1e10
for w in range(1, W):
    rec1 = [H * w]
    rec1.append((W-w) * (H//2))
    rec1.append((W-w) * (H - H//2))
    dif = max(rec1) - min(rec1)
    ans = min(ans, dif)
    
    rec2 = [H*w]
    rec2.append((W-w)//2 * H)
    rec2.append( (W-w-(W-w)//2) * H )
    dif2 = max(rec2) - min(rec2)
    ans = min(ans, dif2)
    
for h in range(1, H):
    rec1 = [h*W]
    rec1.append((H-h) * (W//2))
    rec1.append((H-h) * (W - W//2))
    dif = max(rec1) - min(rec1)
    ans = min(ans, dif)
    
    rec2 = [h*W]
    rec2.append((H-h)//2 * W)
    rec2.append( (H-h-(H-h)//2) * W )
    dif2 = max(rec2) - min(rec2)
    ans = min(ans, dif2)

print(ans)

Measured memory_bytes: 3188
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vi w(n);
    rep(i, n) {
        cin >> w[i];
    }

    auto check = [&](int b) {
        int j = 0;
        rep(i, k) {
            int hh = 0;
            while(hh <= b and j != n) {
                hh += w[j++];
            }
            if(hh <= b) break;
            j--;
        }
        if(j != n) return false;
        else return true;
    };
    int a = 0, c = INT_MAX, b;
    while(c-a != 1) {
        b = (c+a)/2;
        if(check(b)) {
            c = b; 
        } else {
            a = b;
        }
    }

    cout << c << endl;
}


Measured memory_bytes: 3264
program probC
  implicit none
  integer,allocatable :: a(:)
  integer i,ans1,n

  read(*,*) n
  allocate(a(0:n+1))
  a=0
  read(*,*) a(1:n)

  ans1=0
  do i =1,n+1
     ans1 = ans1 + abs(a(i-1)-a(i))
  end do

  do i = 1,n
     write(*,*) ans1+abs(a(i-1)-a(i+1))-(abs(a(i-1)-a(i))+abs(a(i)-a(i+1)))
  end do
  
end program probC


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <string>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



int main(void) {
  ll i, j, k;
  string L;
  cin >> L;
  ll N=L.size();
  
  ll s=0;
  for(i=0; i<N; i++) s+=L[i]-'0';
  pt(max(s, (L[0]-'0'-1)+(N-1)*9));
}



Measured memory_bytes: 256
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.cos
import kotlin.math.sqrt

fun main() {
    val iLine = readLine()!!.split(" ").map(String::toInt)

    val a = iLine[0]
    val b = iLine[1]
    val h = iLine[2]
    val m = iLine[3]

    var angle = ( m * 2 * PI / 60.toDouble() ) - (h * 2 * PI / 12.toDouble() + (m * 2 * PI / (60.toDouble() * 12.toDouble())))
    if(angle > PI){
        angle = 2 * PI - angle
    }

    var result = sqrt((a * a) + (b * b) - (2 * a * b * cos(angle)))

    //println(angle)
    println("%.10f".format(result))
}

Measured memory_bytes: 37668
#include <stdio.h>

typedef struct  {
    int f[6];
} dice;

//   123456
// S 513462
dice op_s(dice d) {
    dice tmp;
    tmp.f[0] = d.f[4];
    tmp.f[1] = d.f[0];
    tmp.f[2] = d.f[2];
    tmp.f[3] = d.f[3];
    tmp.f[4] = d.f[5];
    tmp.f[5] = d.f[1];
    return tmp;
}

//   123456
// N 263415
dice op_n(dice d) {
    dice tmp;
    tmp.f[0] = d.f[1];
    tmp.f[1] = d.f[5];
    tmp.f[2] = d.f[2];
    tmp.f[3] = d.f[3];
    tmp.f[4] = d.f[0];
    tmp.f[5] = d.f[4];
    return tmp;
}

//   123456
// W 326154
dice op_w(dice d) {
    dice tmp;
    tmp.f[0] = d.f[2];
    tmp.f[1] = d.f[1];
    tmp.f[2] = d.f[5];
    tmp.f[3] = d.f[0];
    tmp.f[4] = d.f[4];
    tmp.f[5] = d.f[3];
    return tmp;
}

//   123456
// E 421653
dice op_e(dice d) {
    dice tmp;
    tmp.f[0] = d.f[3];
    tmp.f[1] = d.f[1];
    tmp.f[2] = d.f[0];
    tmp.f[3] = d.f[5];
    tmp.f[4] = d.f[4];
    tmp.f[5] = d.f[2];
    return tmp;
}

//  1
// 4235
//  6
// S
//  5
// 4136
//  2
// N
//  2
// 4631
//  5
// W
//  3
// 1265
//  4
// E
//  4
// 6215
//  3
//
//   123456
// S 513462
// N 263415
// W 326154
// E 421653

int main()
{
    dice d;
    int i;
    int c;
    for(i = 0; i < 6; i++) {
        scanf("%d", &(d.f[i]));
    }
    scanf("%*c");
    while((c = getchar()) != '\n') {
        if(c == 'S') {
            d = op_s(d);
        }
        if(c == 'N') {
            d = op_n(d);
        }
        if(c == 'W') {
            d = op_w(d);
        }
        if(c == 'E') {
            d = op_e(d);
        }
    }
    printf("%d\n", d.f[0]);
    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int a=0,vv=0;
	
	if((s[0]=='1' && s[1]<='2') || (s[0]=='0' && s[1]!='0'))
	{
		a=1;
	}
	if((s[2]=='1' && s[3]<='2') || (s[2]=='0' && s[3]!='0'))
	{
		vv=1;
	}
	if(a==1 && vv!=1)
	{
		cout << "MMYY";
	}
	else if(a==1)
	{
		cout << "AMBIGUOUS";
	}
	else if(vv==1)
	{
		cout << "YYMM";
	}
	else
	{
		cout << "NA";
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int N; cin >> N;
	string s; cin >> s;
	rep(i, s.size()) {
		rep(j, N) {
			if (s[i] == 'Z')s[i] = 'A';
			else s[i]++;
		}
	}
	cout << s << "\n";


	return 0;
}


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

int collatz(int s)
{
    if (s % 2 == 0) return s / 2;
    else            return 3 * s + 1;
}

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

    bool a[1000000] = {false}; //今までiが出てきたかどうかを格納する配列a[i]
    int m = 1;
    while (!a[s]) {
        a[s] = true;
        s = collatz(s);
        m++;
    }

    cout << m << endl;
    
    return 0;
}

Measured memory_bytes: 1280
H, W = [int(i) for i in input().split()]
minelist = [list(input()) for i in range(H)]
dx = [-1, 0 , 1]
dy = [-1, 0 , 1]
for i in range(H):
    for j in range(W):
        count = 0
        if minelist[i][j] == "#":
            continue
        if minelist[i][j] == ".":
            for l in dx:
                for m in dy:
                    if (i + l < 0) or (i + l > H -1 ) or (j + m < 0) or (j + m > W -1):
                        continue
                    if minelist[i + l][j + m] == "#":
                        count += 1
        minelist[i][j] = str(count)
for i in minelist:
    k = "".join(i)
    print(k)

Measured memory_bytes: 3188