akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int a[200],n;

void cut(int k)
{
  int b[200],i;
  for(i=0;i<k;i++){
    b[i] = a[i];
  }
  for(i=0;i<2*n-k;i++){
    a[i] = a[i+k];
  }
  for(;i<2*n;i++){
    a[i] = b[i-(2*n-k)];
  }
}
void refull()
{
  int b[100],c[100],i;
  for(i=0;i<n;i++){
    b[i] = a[i];
  }
  for(;i<2*n;i++){
    c[i-n] = a[i];
  }
  for(i=0;i<n;i++){
    a[2*i] = b[i];
    a[2*i+1] = c[i];
  }
}
int main()
{
  int i,m;
  scanf("%d",&n);
  for(i=0;i<2*n;i++){
    a[i] = i+1;
  }
  scanf("%d",&m);
  while(m>0){
    scanf("%d",&i);
    if(i == 0) refull();
    else cut(i);
    m--;
  }
  for(i=0;i<2*n;i++){
    printf("%d\n",a[i]);
  }
  return 0;
}

Measured memory_bytes: 0
def sep(S):
    l=r=0
    for i,s in enumerate(S):
        l+=s=='('
        r+=s==')'
        if l==r:
            j=S.find(']',i)
            s_l=S[1:i]
            s_r=S[j+2:-1]
            s_c=int(S[i+2:j])
            break
    return s_l,s_c,s_r
def solve(A,B):
    if A=='' or B=='':
        return ''
    a_l,a_c,a_r=sep(A)
    b_l,b_c,b_r=sep(B)
    return '(%s)[%d](%s)'%(solve(a_l,b_l),a_c+b_c,solve(a_r,b_r))
print(solve(input(),input()))


Measured memory_bytes: 5780
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	REP(i,0,n-1) {
		if(a.substr(i,n-i)==b.substr(0,n-i)) {
			cout<<2*n-(n-i);
			return;
		}
	}
	cout<<2*n;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main()
{

    int L;
    double ans;
    cin >> L ;
    ans =((double)L / 3)* ((double)L/3)* ((double)L/3);
    printf("%.12f\n",ans);
    return 0;
}

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

const int N = 200005;

int n, nn, p[N], ip[N], tot, ans[N];

struct st {
	int a[17][N / 2];
	void init() {
		for (int i = 1; i < 17; ++i)
			for (int j = 0; j <= nn - (1 << i); ++j)
				a[i][j] = std::min(a[i - 1][j], a[i - 1][j + (1 << i - 1)]);
	}
	int query(int l, int r) {
		int k = 31 - __builtin_clz(r - l);
		return std::min(a[k][l], a[k][r - (1 << k)]);
	}
} s[2];

std::priority_queue<std::tuple<int, int, int>> q;

int query(int l, int r, bool e) {
	l = l + !e >> 1, r = r + !e >> 1;
	return s[e].query(l, r);
}
void update(int l, int r) {
	if (l == r) return;
	q.emplace(-query(l, r, l & 1), l, r);
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n, nn = n >> 1;
	for (int i = 0; i < n; ++i) std::cin >> p[i], ip[p[i]] = i;
	for (int i = 0; i < n; ++i) s[i & 1].a[0][i >> 1] = p[i];
	s[0].init(), s[1].init(), update(0, n);
	while (q.size()) {
		int v, l, r; std::tie(v, l, r) = q.top(); q.pop();
		int L = ip[-v], R = ip[query(L + 1, r, l & 1 ^ 1)];
		ans[tot++] = p[L], ans[tot++] = p[R];
		update(l, L), update(L + 1, R), update(R + 1, r);
	}
	for (int i = 0; i < n; ++i) std::cout << ans[i] << ' '; std::cout << '\n';
	return 0;
}

Measured memory_bytes: 17784
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	int n; ll x;
	cin >> n >> x;
	ll g = -1;
	for (int i = 0; i < n; i++)
	{
		ll currX;
		cin >> currX;
		ll diff = abs(x - currX);
		if (g == -1)
			g = diff;
		else
			g = __gcd(g, diff);
	}
	cout << g << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);
    final int x = scanner.nextInt();

    final int count500 = x / 500;
    final int count5 = (x % 500) / 5;

    System.out.println(count500 * 1000 + count5 * 5);
  }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	map<ll, ll> s;
	ll N; cin >> N;
	for (ll i = 0; i < N; ++i)
	{
		ll a; cin >> a;
		++s[a];
	}

	ll res{0};
	for (auto &e : s)
	{
		res += (e.second % 2);
	}
	std::cout << res << std::endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int sum[n] = {};
  int w = 0;
  for(int i = 0; i < n; i++){
    sum[i] = w;
    if(s[i] == 'W')w++;
  }
  int e = 0;
  for(int i = n - 1; i > -1; i--){
    sum[i] += e;
    if(s[i] == 'E')e++;
  }
  int ans = n;
  for(int i: sum)if(i < ans)ans = i;
  cout << ans << endl;
  return 0;
}

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

int main() 
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n,last,cont,x,ans;
    while(cin >> n)
    {
        cin >> last; cont = 1; ans = 0;
        for(int i = 1; i < n; i++)
        {
            cin >> x;
            if(x == last)
                cont++;
            else
            {
                ans += cont/2;
                last = x; cont = 1;
            }
        }
        ans += cont/2;
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define mp(x,y) make_pair(x,y)
#define ALL(a) a.begin(),a.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define pii pair<int,int>
#define INF 1<<29
#define MAX 101010
using namespace std;

int n,k,a[MAX],sum[MAX];

void solve(){
 for(;;){
  cin>>n>>k;
  if(!n) break;
  FOR(i,n) cin>>a[i];
  FOR(i,n) sum[i+1]=sum[i]+a[i];
  int ma=0;
  FOR(i,n-k) ma=max(ma,sum[i+k]-sum[i]);
  cout<<ma<<endl;
 }
}

int main(){
 solve();
 return 0;
}

Measured memory_bytes: 3876
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    double n,m;
    cin>>n;
     m= n/3;
    cout<<fixed<<setprecision(12)<<m*m*m<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		int rating = scanner.nextInt();
		int goal = scanner.nextInt();
		
		int ans = (goal*2)-rating;
		
		System.out.println(ans);
		
		scanner.close();
	}

}

Measured memory_bytes: 21716
#include <stdio.h>
#include<string.h>
 
int main(void){
    int size;
 
    char n[4];
    int A=0;
    int B=0;
    int C=0;
    int D=0;
    scanf("%d", &size);
 
    for(int i = 0; i < size; i++) {
        scanf("%s", n);
 
        if (strcmp("AC",n)==0){
            A++ ;
        }
        else if (strcmp("WA",n)==0){
            B++ ;
        }
        else if (strcmp("TLE",n)==0){
            C++ ;
        }
        else if (strcmp("RE",n)==0){
            D++ ;
        }
    }
    printf("AC x %d \n", A);
    printf("WA x %d \n", B);
    printf("TLE x %d \n", C);
    printf("RE x %d \n", D);
 
    return 0;
}

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

typedef long long ll;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main(void) {
  int N;
  cin >> N;
  vector<long long> t(N);
  long long ret = 1;
  for(int i=0;i<N;i++){
    cin >> t[i];
    ret = lcm(ret,t[i]);
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;
ll mod = 1e9 + 7;
const int N = 1e5 + 10;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll n, a[N];



int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int cur = 1, ans = 0;
	for (int i = 1; i <= 2 * n; i++) {
		if (cur == 2) {
			cout << ans;
			return 0;
		}
		cur = a[cur];
		ans++;
	}
	cout << -1;
	return 0;
}

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

using namespace std;
typedef long long int lli;

int H, W;

lli getAns(lli A, lli B, lli C)
{
	lli mx = max( A , B );
	mx = max( mx , C );

	lli mn = min( A , B );
	mn = min( mn , C );

	return mx - mn;
}

int main()
{
	scanf("%d %d",&H,&W);

	lli ans = H;
	ans *= W;

	for(int i = 0 ; i < 2 ; i++)
	{
		lli A = H/3;
		lli B = H/3;
		lli C = H/3;

		if( H%3 >= 1 ) B++;
		if( H%3 >= 3 ) C++;

		A *= W;
		B *= W;
		C *= W;

		ans = min( ans , getAns( A , B , C ) );

		for(int x = 1 ; x <= H ; x++)
		{
			A = x;
			A *= W;

			B = W/2;
			C = W/2;

			if( W%2 == 1 ) C++;

			B *= ( H - x );
			C *= ( H - x );

			ans = min( ans , getAns( A , B , C ) );
		}

		swap( H , W );
	}

	printf("%lld\n",ans);
}

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

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define uset unordered_set
#define endl '\n'
#define umap unordered_map
#define pii pair<int, int> 
#define ld long double
#define pll pair<long long, long long> 

const int N = 2e5 + 15;
int n, m, a[N];

int main() {
	cin >> n >> m;
	if(n == 2 || m == 2)
		puts("No");
	else
		puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, S: str):
    Y = 0
    X = 0

    if S[0] == "L":
        Y += 1
    if S[-1] == "R":
        Y += 1

    for i in range(len(S)-1):
        if S[i:i+2] == "RL":
            X += 1

    H = len(S) - 2 * X - Y
    H += min(K,X) * 2
    if K-X > 0:
        H += min(K-X, Y) 

    H = min(len(S)-1, H)

    print(H)



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	ll n;
	cin >> n;
	cout << ((n * (n + 1)) / 2) - n;
}


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

using namespace std;

#define gc getchar_unlocked
#define foi(i,n) for(int i=0;i<n;i++)
#define Foi(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define fol(i,n) for(ll i=0;i<n;i++)
#define Fol(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
        g[u-1].pb(v-1);
        g[v-1].pb(u-1);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> x(n);
    cin>>x[0]>>x[1];
    ll xo = x[1];
    for(int i=2;i<n;i++)
    {
        cin>>x[i];
        xo = xo^x[i];
    }   
    cout<<xo<<" ";    
    for(int i=1;i<n;i++)
    {
        ll temp = (xo^x[i-1])^x[i];
        cout<<temp<<" ";
        xo = temp;
    }
    return 0;
}

Measured memory_bytes: 11760
a,b= map(str, input().split())
ab = a*int(b)
ba = b*int(a)
if ab < ba:
    print(ab)
else:
    print(ba)
# p = list(map(int,input().split()))

# count = 0
# val = sum(p[0:k])
# val_lis = [val]
# mx_val = val
# index = 0
# mx_index = 0
# for i,j in enumerate(p[k:]):
#     val = val - p[index] + j
#     val_lis.append(val)
#     index +=1
#     if val > mx_val:
#         mx_index = index
#         mx_val = val 
    
# ans = 0
# for i in range(k):
#     ans += ((p[mx_index + i]+1.0)*(p[mx_index+i]))/ (p[mx_index+i] *2.0)
# print(ans)  




# h = sorted(h,reverse = True)
# print(sum(h[k:]))

# s,t= map(str, input().split())
# a,b= map(int, input().split())
# u = input()
# print("x"*len(u))

# if(u == s):
#     print(a-1,b)
# else:
#     print(a,b-1)


Measured memory_bytes: 2940
//          ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define ull unsigned long long int
#define ll long long int
#define ui unsigned int
#define pb push_back
 
#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000000005
#define MOD 1000000007
                              //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}



int main() {
   
    fastio;
    string s;
    ll n, k;
    cin >> n >> k;
    ll p[n+1], c[n+1];
    fr(i, 1, n)
    cin >> p[i];
    fr(i, 1, n)
    cin >> c[i];
    ll score = 0;
    vector<ll> sti[n+1];
    fr(i, 1, n)
    {
        //sti[i].pb(0);
        score = 0;
        ll pi = p[i];
        while(pi != i)
        {
            score += c[pi];
            pi = p[pi];
            sti[i].pb(score);
        }
        sti[i].pb(score+c[i]);
    }
    ll ans = sti[1][0];
    fr(i, 1, n)
    {
        
        ll maxSum = sti[i][0];
        ll maxIdx = 0;
        ll need = sti[i].size();
        fr(j, 0, min(k-1, (ll)sti[i].size()-1))
        {
            //cout << sti[i][j] << " ";
            if(sti[i][j] > maxSum)
            {
                maxSum = sti[i][j];
                maxIdx = j;
            }

        }
        if(sti[i][need-1] <= 0 || k <= need)
            ans = max(ans, maxSum);
        
        else
        {
            ll xyz = 0;
            ll m = k % need;
            ll mm = k / need;
            fr(j, 0, m-1)
            {
                xyz = max(xyz, sti[i][j]);
            }
            ll sum = (mm-1) * sti[i][need-1] + maxSum;
            ll sum_dash = mm * sti[i][need-1] + xyz;

            ans = max(ans, sum);
            ans = max(ans, sum_dash);
            
        }



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

}

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

int main(){
    int n;
    cin >> n;
    for(int i = 9; i > 0; i--){
        for(int j = 9; j > 0; j--){
            if(n == i * j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;


void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
ll mul(ll l, ll r) {
    ll ret =1;
    for(int i=0; i<l-r+1; ++i) {
        ret*=i+r;
        ret%=MOD;
    }
    return ret;
}
ll com(ll n, ll k) {
    ll ret1 = mul(n,n-k+1);
    ll ret2 = mul(k,1);
    ll ret3 = modPow(ret2, MOD-2);
    return ret1*ret3%MOD;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    int ans = 0;
    for(int i=1; i<=n; ++i) {
      string s = to_string(i);
      if (s.size()%2==1) ans++;
    }
    ct(ans);
}



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

using namespace std;



int main() {

    int n,res=0,k,arr[1000];
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n);
    for(int i=0;i<k;i++)res+=arr[i];
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inputs;
		inputs = br.readLine().split(" ");
		int n = Integer.parseInt(inputs[0]);
		int k = Integer.parseInt(inputs[1]);

		char s[] = new char[n];
		s = br.readLine().toCharArray();

		int sum = 0;
		char prev = ' ';
		for ( int i = 0; i < n; i++ ) {
			if(prev == s[i]) {
				sum++;
			}
			prev = s[i];
		}
		System.out.print(Math.min(n-1, sum + k*2));
		br.close();
	}
}

Measured memory_bytes: 24916
#include<iostream>
#include<cctype>
#include <string>
using namespace std;
int main(){
	string a;

	while (1){
		cin >> a;
		if ( a[0] == '0')break;
		int sum = 0;

		for (int i = 0; i < a.size(); i++)
		{
			sum += a[i] - '0';
		}

		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3184
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

template <class T> T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}


#include <algorithm>
#include <iostream>
#include <utility>

int main() {
	usize n;
	::std::cin >> n;
	::std::vector<char> s(n);
	for (auto &e : s) {
		::std::cin >> e;
	}
	usize q;
	::std::cin >> q;
	while (q--) {
		usize k;
		::std::cin >> k;
		u64 cntall = 0,cntd = 0, cntm = 0;
		u64 ans = 0;
		for (const auto i : rep<u64>(0, n)) {
			if (i >= k) {
				if (s[i - k] == 'D') {
					--cntd;
					cntall -= cntm;
				}
				else if (s[i - k] == 'M') {
					--cntm;
				}
			}
			if (s[i] == 'C') {
				ans += cntall;
			}
			else if (s[i] == 'M') {
				cntall += cntd;
				++cntm;
			}
			else if (s[i] == 'D') {
				++cntd;
			}
		}
		::std::cout << ans << ::std::endl;
	}
	return 0;
}


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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if(s == u) {
    cout << a - 1 << " " << b << endl;
  }
  else {
    cout << a << " " << b - 1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    int a,b;
    cin >> a >> b;
    cout << a * b  / 2 << endl;
    return 0;
}

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

// void printarray(ll arr[])
// {
// 	ll l=sizeof(arr)/sizeof(arr[0]);
// 	for(ll i=0;i<l;i++)
// 		cout << arr[i] <<" ";
// 	cout << "\n";
// }

void solve()
{
	string s;
	cin >> s;
	int max1=0,c=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='R')
			c=c+1;
		else
		{
			if(max1<c)
				max1=c;
			c=0;
		}
	}
	if(max1<c)
		max1=c;
	cout << max1 ;
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("ouput.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        var p = sc.nextInt();
        var q = sc.nextInt();
        var r = sc.nextInt();

        Console.WriteLine(Math.Min(p + q, Math.Min(q + r, r + p)));
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

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

using namespace std;

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v,int N,bool visited[nmax]){
    bool all_visited = true;

    for(int i = 0;i < N;i++){
        if(!visited[i]){
            all_visited = false;
        }
    }

    if(all_visited){
        return 1;
    }

    int ret = 0;
    for(int i = 0;i < nmax;i++){
        if(!graph[v][i]){
            continue;
        }
        if(visited[i]){
            continue;
        }
        visited[i] = true;
        ret += dfs(i,N,visited);
        visited[i] = false;
    }
    return ret;
}

int main(){
    int N,M,a,b,ans;
    bool visited[nmax];
    
    cin >> N >> M;
    for(int i = 0;i < nmax;i++){
        visited[i] = false;
        for(int j = 0;j < nmax;j++){
            graph[i][j] = false;
        }
    }

    for(int i = 0;i < M;i++){
        cin >> a >> b;
        graph[a-1][b-1] = graph[b-1][a-1] = true;
    }
    visited[0] = true;
    ans = dfs(0,N,visited);

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

Measured memory_bytes: 256
N = int(input())
testimo_ls = [ [] for i in range(N) ]
rst = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split(' '))
        testimo_ls[i].append([x - 1, y])
for i in range(1 << N):
    honest_ls = []
    for j in range(N):
        if i >> j & 1:
            honest_ls.append(j)
    is_ok = True
    for s in honest_ls:
        for t in testimo_ls[s]:
            if t[1] == 0 and t[0] in honest_ls:
                is_ok = False
                break
            if t[1] == 1 and not t[0] in honest_ls:
                is_ok = False
                break
    if is_ok:
        rst = max(rst, len(honest_ls))
print(rst)

Measured memory_bytes: 9068
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<stack>
#include<iomanip>
#include<map>
using namespace std;
//def lib
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define drep(i,n) for(int i=((int)n)-1;i>-1;i--)
#define Rep(i,n0,n) for(int i=n0;i<((int)n);i++)
#define dRep(i,n0,n) for(int i=((int)n)-1;i>n0-1;i--)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<((int)n);j++)
#define W(x) cout<<x<<endl;
#define print(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
#define INF2 (long long)8*(long long)INF*(long long)INF
#define mod 1000000007
//def end
typedef long long ll;
// lib
int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){if(y>x)return y;else return x;}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
int mfact(int x){int i=1;rep(j,x){i*=(j+1);} return i%mod;}
int modulo(int x){return x%mod;}
long long fact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i;}
long long mfact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i%mod;}
long long modulo(long long x){return x%mod;}
int gcd(int x, int y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
ll gcd(ll x, ll y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
void say(bool x){if(x){cout<<"Yes"<<endl;}else {cout<<"No"<<endl;}return;}
//lib end
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1};
int main()
{
    int n,m=-1;
    cin >> n;
    Rep(i,2,500){
        if(n==((i*(i-1))/2)){
            m = i;
        }
    }
    if(m==-1){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
        cout<<m<<endl;
        vector<int> g[m];
        int num = 1;
        Com(i,j,m){
            g[i].push_back(num);
            g[j].push_back(num);
            num++;
        }
        rep(i,m){
            cout<<m-1;
            rep(j,g[i].size()){
                cout<<" "<<g[i][j];
            }
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()


int main() {
	ll n, i;
	cin >> n >> i;
	cout << n - i + 1 << endl;
}


Measured memory_bytes: 256
//39
#include<iostream>
#include<map>

using namespace std;

int main(){
  for(;;){
    map<int,int> c;
    for(int a,b;cin>>a>>b,cin&&(a|b);){
      c[a]++;
      c[b]++;
    }
    if(!cin)return 0;
    map<int,int>::iterator it;
    for(it=c.begin();it!=c.end();it++){
      if(it->first==1 || it->first==2){
	if(it->second%2==0)break;
      }else{
	if(it->second%2!=0)break;
      }
    }
    cout<<((it==c.end())?"OK":"NG")<<endl;
  }
  return 0;
}

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

 

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    bool flag=false;
    for(int i=0;i<s.size()-1;i++)
    {
    	if(s[i]==s[i+1])
    		flag=true;
    }
    if(flag)
    {
    	cout<<"Bad"<<endl;
    }
    else
    {
    	cout<<"Good"<<endl;
    }

	return 0;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef pair<int, int> PII;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const int INF = numeric_limits<int>::max();
int main()
{
  
	int row{}, col{};//行,列
	int sy{},sx{};//スタート地点の座標(y,x)
	int gy{},gx{};//ゴール地点の座標(y,x)
	cin >> row >> col;
	char C[row+1][col+1];
	char CC[row+1][col+1];
	REP( i, row )
	{
		REP( j, col )
		{
			cin >> CC[i+1][j+1];//座標は1,1から始まるので+1して合わせる
		}
	}

	REP( i, row )
	{
		REP( j, col )
		{
			C[i+1][j+1]= CC[i+1][j+1];//座標は1,1から始まるので+1して合わせる
		}
	}
	int ans=0;
  for(int ii=1;ii<=row;ii++){for(int jj=1;jj<=col;jj++){
  for(int kk=1;kk<=row;kk++){for(int ll=1;ll<=col;ll++){
  if(C[ii][jj]=='#'||C[kk][ll]=='#')continue;
  
	int distance[row+1][col+1];//距離格納配列
	REP(i,row+1)REP(j,col+1)distance[i][j]=INF;//配列初期化
	queue<PII> q;
	q.emplace( ii, jj );//スタート地点座標をqueueに代入
	distance[ii][jj] = 0;//初期状態からの距離を0に設定

	int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };//移動4方向のベクトル

	while( !q.empty() )
	{
		PII now = q.front();//現在地
		q.pop();

		//移動4方向をループ
		REP( i, 4 )
		{
			//移動した後の点を(ny,nx)とする
			int ny = now.first + dy[i], nx = now.second + dx[i];

			//移動が可能かの判断と既に訪れた事があるかの判定
			if( 1<= ny && ny <= row && 1 <= nx && nx <= col && C[ny][nx] != '#' && distance[ny][nx] == INF )
			{
				q.emplace( ny, nx );//次の位置をqueueに入れる
				distance[ny][nx] = distance[now.first][now.second] + 1;//点の距離をnowから+1の距離で確定する                
			}   
		}
	}
	ans=max(ans,distance[kk][ll]);
	
	//if(ii==3&&jj==1&&kk==1&&ll==5)cout << distance[kk][ll] << endl;
	C[ii][jj]=CC[ii][jj];
  C[kk][ll]=CC[kk][ll];
  }}}}
  std::cout << ans << std::endl;
}


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

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

  int counter = 0;
  
  if ( s[0] == '1' ) ++counter;
  if ( s[1] == '1' ) ++counter;
  if ( s[2] == '1' ) ++counter;
  
  cout << counter << endl;
    
  }


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	string s; cin >> s;
	int N = SZ(s); 
	VI a(N); {
		int c = 0;
		FOR(i, 0, N) {
			if (s[i] == 'g')c++;
			else c--;
			a[i] = c;
		}
		DD(De(a));
	}
	LL ans = 0;
	int mn = a.back();
	FORR(i, N - 1, 0 - 1) {
		DD(de(i, mn));
		if (s[i] == 'g') {
			mn = min(mn, a[i]);
			if (a[i] >= 2 && mn >= 2) {
				ans++;
				mn = min(mn-2, a[i] - 2);
			}
			DD(de(mn));
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 848
n, x, m = map(int, input().split())
S = [0]
F = [None] * m
for i in range(m + 1):
    S.append(S[-1] + x)
    if F[x] is not None:
        j = F[x]
        q, r = (n - j) // (i - j), (n - j) % (i - j)
        print((S[i] - S[j]) * q + S[j + r])
        exit()
    F[x] = i
    x = pow(x, 2, m)
print(0)


Measured memory_bytes: 13644
#include <stdio.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  string a;
  int b;
  string c;
  cin >> a >> b;
  int tmp;
  int flag = 0;
  string mae = "";
  string ushiro = "";
  for (int i = 0; i < b; i++) {
    cin >> tmp;
    if (tmp == 1) {
      if (flag == 0) {
        flag = 1;
      } else {
        flag = 0;
      }
    } else {
      cin >> tmp >> c;
      if (tmp == 1) {
        if (flag == 0) {
          mae += c;
        } else {
          ushiro += c;
        }
      } else {
        if (flag == 0) {
          ushiro += c;
        } else {
          mae += c;
        }
      }
    }
  }
  if (flag == 0) {
    reverse(mae.begin(), mae.end());
    a = mae + a + ushiro;
  } else {
    reverse(a.begin(), a.end());
    reverse(ushiro.begin(), ushiro.end());
    a = ushiro + a + mae;
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

vecl cnt(51),p(51);

void init() {
    cnt[0] = 1;
    p[0] = 1;
    for(int i = 0; i < 50; i++) {
        cnt[i+1] = 2*cnt[i]+3;
        p[i+1] = 2*p[i]+1;
        //cout << p[i+1] << " " << cnt[i+1] << endl;
    }
}

ll f(ll L, ll X) {
    //cout << L << " " << X << endl;
    //cout << cnt[L-1] << " " << p[L-1] << endl;
    if(L == 0 && X == 1)  return 0;
    if(X == 1) return 0;
    if(1 < X && X < cnt[L-1]+1) return f(L-1,X-1);
    else if(X == cnt[L-1]+1) return p[L-1];
    else if(X == cnt[L-1]+2) return p[L-1]+1;
    else if(X < 2*cnt[L-1]+2) return f(L-1,X-(cnt[L-1]+2))+p[L-1]+1;
    else if(X >= 2*cnt[L-1]+2) return 2*p[L-1]+1;
}

int main() {
    ll N,X; cin >> N >> X;
    init();
    cout << f(N,X) << endl;
}

Measured memory_bytes: 3628
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
inline int read() {
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
const int maxn=2010;
int n,m;
int h[maxn],A[maxn][maxn];
int left[maxn],right[maxn];
char M[maxn][maxn]; 
int main() {
	n=read();m=read();
	rep(i,1,n) scanf("%s",M[i]+1);
	rep(i,1,n-1) rep(j,1,m-1) {
		if(M[i][j]=='#') A[i][j]++;
		if(M[i+1][j]=='#') A[i][j]++;
		if(M[i][j+1]=='#') A[i][j]++;
		if(M[i+1][j+1]=='#') A[i][j]++;
		(++A[i][j])%=2;
	}
	int ans=max(n,m);
	n--;m--;
	h[0]=h[m+1]=-1;
//	rep(i,1,n) rep(j,1,m) printf("%d%c",A[i][j],j==m?'\n':' ');
	rep(i,1,n) {
		rep(j,1,m) {
			if(A[i][j]) h[j]++;
			else h[j]=0;
		} 
		rep(j,1,m) {
			left[j]=j-1;
			while(h[j]<=h[left[j]]) left[j]=left[left[j]];
		}
		dwn(j,m,1) {
			right[j]=j+1;
			while(h[j]<=h[right[j]]) right[j]=right[right[j]];
			ans=max(ans,(h[j]+1)*(right[j]-left[j]));
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*
4 4
.#.#
....
.#.#
....
*/

Measured memory_bytes: 19840
N = int(input())
colors = list(input())


sums = [0] * N

if colors[0] == "R":
    sums[0] = 1

for i in range(1,N):
    if colors[i] == "R":
        sums[i] = sums[i-1] + 1
    else:
        sums[i] = sums[i-1]

red_sum = sums[-1]

print(red_sum-sums[red_sum-1])


Measured memory_bytes: 18420
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y,z;
    cin >> x >> y >> z;
    int a=x/(y+z);
    if(a*(y+z)+z==x){
    cout << a << endl;
  }
  else if(a*(y+z)+z!=x){
  cout << a-1 << endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long double ld;
typedef long long ll;
 
int main(){
  ld M,Rd,Rr,Cd,Cr;
 
  cin >> M >> Rd >> Rr >> Cd >> Cr;
 
  ld D,R;
 
  D = ceil(Cd*100/Rd); R = ceil(Cr*100/Rr);
 
  if(M - (D + R) >= 0) printf("%lld\n" ,(ll)(M-(D+R)));
  else cout << "-1" << endl;
 
  return 0;
}

Measured memory_bytes: 1224
// B - Toll Gates
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N,M,X; cin>>N>>M>>X;
	int l = 0, r = 0;
	rp(i, 0, M){
		int a; cin>>a;
		if(a < X) l++;
		else r++;
	}
	cout<< min(l, r) <<endl;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B
#include <bits/stdc++.h>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n;
	cin>>n;
	vector<int> s(n);
	rep(i,n)cin>>s[i];
	int q;
	cin>>q;
	vector<int> t(n);
	rep(i,q)cin>>t[i];

	int ans=0;
	rep(i,q){
		int c = upper_bound(all(s),t[i]) - lower_bound(all(s),t[i]);
		if(c!=0)ans++;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3500
N = int(input())
buttons = [int(input()) - 1 for _ in range(N)]
#N = 5
# buttons = [2, 2, 3, 1, 3]
# N = 3
# buttons = [2, 0, 1]


def judge(buttons):
    move_cnt = 1
    # 最初押してそのボタンが1だったら終了
    next_idx = buttons[0]
    if next_idx == 1:
        return move_cnt, True

    while True:
        move_cnt += 1
        if move_cnt > N:
            return None, False
        next_idx = buttons[next_idx]
        if next_idx == 1:
            return move_cnt, True
    return move_cnt, True


cnt, is_Yes = judge(buttons)
if is_Yes:
    print(cnt)
else:
    print(-1)


Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, a, b;
	cin >> n >> a >> b;
	--a;
	--b;
	vector<vector<int> > G;
	G.resize(n);
	for(int i = 0; i < n - 1; ++i) {
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	vector<vector<int> > d;
	d.resize(2);
	for(int i = 0; i < 2; ++i) {
		d[i].resize(n);
	}
	function<void(int, int, int)> dfs = [&] (int u, int f, int t) {
		for(auto v : G[u]) {
			if(v != f) {
				d[t][v] = d[t][u] + 1;
				dfs(v, u, t);
			}
		}
	};
	dfs(a, -1, 0);
	dfs(b, -1, 1);
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if(d[0][i] < d[1][i]) {
			ans = max(ans, d[1][i] - 1);
		}
	}
	// 0 - 0 - 0 - 0 - 0
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 14208
n,k = gets.to_s.split.map{|t|t.to_i}
# d = gets.to_s.to_i
# a = gets.to_s.split.map{|t|t.to_i}
# s = gets.to_s.chomp

ans = [1] * (n+1)
ans[0] = 0

k.times do
  
  d = gets.to_i
  a = gets.to_s.split.map{|t|t.to_i}
  
  a.each{ |t| ans[t] = 0 }
end

puts ans.sum

Measured memory_bytes: 14296
// C - Grid Repainting 2

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

bool grid[52][52];

int main() {
	int H, W;
	cin >> H >> W;

	for (int i=1; i<=H; i++) {
		for (int j=1; j<=W; j++) {
			char s;
			cin >> s;

			if (s == '#') grid[i][j] = true;
		}
	}

	string ans = "Yes";
	for (int i=1; i<=H; i++) {
		for (int j=1; j<=W; j++) {
			if (grid[i][j]) {
				if ((!grid[i+1][j]) && (!grid[i][j+1]) && (!grid[i-1][j]) && (!grid[i][j-1])) {
					ans = "No";
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long a;
  scanf("%lld", &a);
  long long b;
  scanf("%lld", &b);

  string s1(b, a + '0');
  string s2(a, b + '0');

  if (s1 < s2) {
    put(s1);
    return 0;
  }

  put(s2);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 256