akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import math
import copy
import random
import time
import numpy as np

start = time.time()
limit_time = 1.8

# 整数の入力
d = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for j in range(d)]

c_num = np.array(c)
s_num = np.array(s)

# d_map = {i: [] for i in range(d)}

def point(t):
    result = 0
    map = {
        0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0,
        10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0,
        20: 0, 21: 0, 22: 0, 23: 0, 24: 0, 25: 0
    }
    for i in range(d):
        comp = t[i] - 1
        day = i + 1
        map[comp] = day
        # d_map[comp].append(day)
        result = result + s[i][comp]
        for cc in range(26):
            result = result - c[cc] * (day - map[cc])
    return result

t = np.argmax(s_num, axis=1) + 1
# t = [int(input()) for i in range(d)]

p = point(t)

# m = int(input())

# for i in range(m):
#     [d, q] = input().split()
#     list = d_map[d - 1]
#     old_q = t[d - 1]
#     index = np.searchsorted(list, d)
#
#     t[d - 1] = q

t_list = [(t, p)]
while time.time() - start < limit_time:
    new_d = math.floor(d * random.random())
    new_t = math.floor(26 * random.random()) + 1
    for i in range(3):
        l = copy.copy(t_list[i][0])
        l[new_d] = new_t if l[new_d] != new_t else (new_t + 1) % 26
        t_list.append((l, point(l)))
    t_list = sorted(t_list, key=lambda x: x[1], reverse=True)[:3]

print("\n".join([str(i) for i in t_list[0][0]]))


Measured memory_bytes: 27480
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
    double a[1010];
    double b[1010];
    int n;
    double m = 0;
    double ans = 0;
    int i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%lf", &a[i]);
    }
    for (i = 0; i < n; i++)
    {
        scanf("%lf", &b[i]);
    }
    for (i = 1; i < 4; i++)
    {
        m = 0;
        for (j = 0; j < n; j++)
        {
            m += pow(abs(a[j] - b[j]), i);
        }
        printf("%lf\n", pow(m, 1.0 / (double)i));
    }
    m = 0;
    for (i = 0; i < n; i++)
    {
        m = fmax(m, abs(a[i] - b[i]));
    }
    printf("%lf\n", m);
    return 0;
}



Measured memory_bytes: 2036
fun main(args: Array<String>) {
    val (A, B) = readLine()!!.split(" ").map(String::toInt)

    val start = listOf(B * 10, A * 100 / 8).max()!!
    val end = listOf((B + 1) * 10, (A + 1) * 100 / 8).min()!!
    for(m in start until end) {
        val a = m * 8 / 100
        val b = m / 10
        if( a == A && b == B) {
            println("${m}")
            return
        }
    }
    println("-1")
}

Measured memory_bytes: 37916
divs = [2, 3, 5]

t = int(input())

for _ in range(t):
    n, a, b, c, d = list(map(int, input().split()))
    costs = [a, b, c]

    dp = {0: 0}

    def dfs(x):
        if x in dp:
            return dp[x]

        ret = x * d

        for cost, div in zip(costs, divs):
            lx = x // div * div
            ret = min(ret, dfs(lx // div) + cost + (x - lx) * d)

            if lx == x:
                continue
            lx += div
            if lx // div >= x:
                continue
            ret = min(ret, dfs(lx // div) + cost + (lx - x) * d)

        dp[x] = ret
        return ret

    print(dfs(n))


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

int main()
{
	int N[10000];
	while(1){
		cin >> N[0];
		if(N[0]==0)break;
		int sum = 0;
		for(int i=1;i<=N[0];i++){
			cin >> N[i];
			sum+=N[i];
		}
		int avr = sum / N[0];
		int cnt = 0;
		for(int i=1;i<=N[0];i++)
			if(N[i]<=avr)cnt++;
		cout << cnt << endl;
	}

	return 0;
}


Measured memory_bytes: 3088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc.B
{
    public class Question
    {
        public static void Main(string[] args)
        {
            new Question().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var s = cin.Read;
            var cnt = 0;
            for(int i = 0; i < n - 2; i++)
            {
                if(s.Substring(i, 3) == "ABC")
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 27912
N = int(input())
h = list(map(int, input().split()))

dp = [0]*N
dp[1] = abs(h[1]-h[0])

for i in range(2,N):
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))

print(dp[-1])


Measured memory_bytes: 13980
N = int(input())
cnt = 0
L = [list(map(int, input().split())) for x in range(N)]
for a, b in L[::-1]:
    a += cnt
    if a < b and a != 0 : cnt += b - a
    if a > b: 
        if a % b:
            cnt += b - a % b
        else:
            cnt += a % b
print(cnt)

Measured memory_bytes: 28276
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cstdint>

#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<iterator>
#include<algorithm>
#include<utility>

using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int32_t i=x; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int32_t i = n-1; i>=x; i--)
#define rrep(i,n) RREP(i,0,n)

#define P(p) cout<<(p)<<endl;
#define pb push_back

typedef vector<int> VI;

// --------------------

int main(void){
    uint32_t W = 0, H = 0, x = 0, y = 0, r = 0;
    
    cin >> W >> H >> x >> y >> r;
    
    // ?????????????????????4?????????????????????????????????
    
    // ???
    if( ( y + r > H ) || ( y - r > H ) || ( y + r < 0 ) || ( x - r < 0 ) ||
        ( x + r > W ) || ( x - r > W) || ( x + r < 0 ) || ( x - r < 0 ) ){
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl;
    return 0;
}

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

void solve(int n, int l, int r){
        int a[n] = {};
        for(int i=0; i<n; ++i) cin >> a[i];
        int ans = 0;
        for(int i=l; i<=r; ++i){
                bool f = n % 2 == 0;
                for(int j=0; j<n; ++j){
                        if(i % a[j] == 0){
                            f = j % 2 == 0;
                            break;
                        }
                }
                if(f) ++ans;
        }
        cout << ans << "\n";
}

int main(){
//      cin.tie(0);
//      ios::sync_with_stdio(false);
        while(1){
                int n, l, r;
                cin >> n >> l >> r;
                if(n == 0) return 0;
                solve(n, l, r);
        }
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int x;
    cin >> x;
    if(x == 1) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    string n; cin >> n;
    replace(n.begin(), n.end(), '1', '.');
    replace(n.begin(), n.end(), '9', '1');
    replace(n.begin(), n.end(), '.', '9');

    print(n);
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var N = GetInt();
            var ans = 800 * N - 200 * (N / 15);

            Console.WriteLine(ans);


            Console.Out.Flush();
            Console.ReadKey();
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public Double[] GetDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V,W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W,X>(out T a, out U b, out V c, out W d,out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);e = cv<X>(ar[4]);
        }
    }
}

Measured memory_bytes: 11220
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

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

const ll inf=1000000000000000000ll;
const int mod=1000000007;

pll a[200][200];

int main()
{
    //freopen("input.txt","r",stdin);
    int l=1;a[1][1]=make_pair(1,2);a[1][2]=make_pair(1,3);
    while (a[l][1].second<=inf)
    {
        for (int i=1;i<=l+1;i++) a[l+1][i]=make_pair(a[l][i].second,a[l][i].first+a[l][i].second);
        ++l;a[l][l+1]=make_pair(a[l-1][1].second,a[l-1][1].second*2+a[l-1][1].first);
    }
    int q;scanf("%d",&q);
    while (q--)
    {
        ll x,y;scanf("%lld%lld",&x,&y);
        if (x>y) swap(x,y);
        if (x==y&&x==1) {puts("1 1");continue;}
        int ans1=0;
        for (int i=1;i<=l;i++)
            if (a[i][1].first>x||a[i][1].second>y) {ans1=i-1;break;}
        if (ans1==1) {printf("1 %d\n",x*y%mod);continue;}
        int ans2=0;
        for (int i=1;i<=ans1;i++)
        {
            ll u=a[ans1-1][i].first,v=a[ans1-1][i].second;
            if (v<=x) ans2=((y-u)/v+(x-u)/v+ans2)%mod;
        }
        printf("%d %d\n",ans1,ans2);
    }
    return 0;
}


Measured memory_bytes: 4224
a = input().split()
n = int(a[0])
m = int(a[1])
qq = int(a[2])

x = [[0] * n for _ in range(n)]

for _ in range(m):
    a = input().split()
    x[int(a[0]) - 1][int(a[1]) - 1] += 1

c = list()

for i in range(n):
    c.append(list())
    for j in range(n):
        a = x[i][j]

        if 0 < j:
            a += c[i][j - 1]

        c[i].append(a)

z = list()

for i in range(n):
    z.append(list())
    for j in range(n):
        a = c[i][j]

        if 0 < i:
            a += z[i - 1][j]

        z[i].append(a)

for _ in range(qq):
    r = 0
    a = input().split()
    p = int(a[0])
    q = int(a[1])

    if 0 < q:
        r += z[q - 1][q - 1]

    if 0 < q and 1 < p:
        r -= z[q - 1][p - 2] + z[p - 2][q - 1]

    if 1 < p:
        r += z[p - 2][p - 2]

    print(r)


Measured memory_bytes: 19416
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

res = 0
for i in range(N):
  now = A[i]-1
  res += B[now]
  if i > 0:
    prev = A[i-1]-1
    if now == prev+1:
      res += C[prev]

print(res)


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

int main(){
    int n,l;
    cin>>n>>l;
    vector<string> s(n);
    rep(i,n) cin>>s[i];
    sort(s.begin(),s.end());

    rep(i,n) cout<<s[i];
    return 0;
}

Measured memory_bytes: 3648
use std::cmp;

fn main() {
    let aaa = read_vec::<i64>();

    let mut takahashi = aaa[0];
    let mut aoki = aaa[1];
    let num = aaa[2];

    takahashi -= num;
    if takahashi < 0 {
        aoki += takahashi;
        takahashi = 0;
        aoki = cmp::max(aoki, 0);
    }

    println!("{} {}", takahashi, aoki);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


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

N, M = map(int, input().split())
s = []
for _ in range(M):
    t = list(map(int, input().split()))
    t.pop(0)
    s.append(t)

p = list(map(int, input().split()))

count = 0
for i in range(2 ** N):
    c = bin(i)[2:]
    c = '0' * (N - len(c)) + c if len(c) < N else c
    u = []
    for j, l in enumerate(s):
        tmp = [int(c[k-1]) for k in l]
        u.append(sum(tmp) % 2)

    if u == p:
        count += 1

print(count)


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextInt();
  map<int, int> count;
  REP(i, N) ++count[nextInt()];
  int ans = 0;
  for (auto it = count.begin(); it != count.end(); ++it) {
    int v = it->first;
    int c = it->second;
    if (v <= c) {
      ans += c - v;
    } else {
      ans += c;
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 4736
N=int(input())
Hik=[0]*N
A=list(map(int,input().split()))
B=0
for i in range(N):
 Hik[max(-A[i]+N-1-i,0)]+=1
for j in range(N):
 if 0<=A[N-1-j]+j and A[N-1-j]+j<=N-1:
  B+=Hik[A[N-1-j]+j]
 Hik[max(-A[N-1-j]+j,0)]+=1
print(B)


Measured memory_bytes: 104464
#include<stdio.h>
#include<stdlib.h>

int *c[100000];
int *k,*p,*d;

int main(){
  int n,i,j,id;

  scanf("%d",&n);
  k = (int *)malloc(n * sizeof(int));
  d = (int *)malloc(n * sizeof(int));
  p = (int *)malloc(n * sizeof(int));

  for(i = 0;i < n;i++){
    k[i] = 0;
    d[i] = 0;
    p[i] = -1;
  }


  for(i = 0;i < n;i++){
    scanf("%d",&id);
    scanf("%d",&k[id]);
    c[id]=(int *)malloc(k[id] * sizeof(int));

    if(k[id]  > 0){
      for(j = 0;j < k[id];j++){
	scanf("%d",&c[id][j]);
      }
    }
  }

  for(i = 0;i < n;i++){
    for(j = 0;j < k[i];j++){
      if(c[i][0] >= 0){
	p[c[i][j]] = i;
      }
    }
  }

  for(i = 0;i < n;i++){
    j = i;
    while(1){
      if(p[j] == -1)break;
      d[i]++;
      j = p[j];
    }
  }

  for(i = 0;i < n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,p[i],d[i]);
    if(p[i] == -1){
      printf("root, ");
    }
    else if(k[i] >= 1 && p[i] != -1){
      printf("internal node, ");
    }
    else{
      printf("leaf, ");
    }

    printf("[");
    if(k[i] >= 1){
      for(j = 0;;){
	printf("%d",c[i][j]);
	j++;
	if(j == k[i])break;
	printf(", ");
      }
    }
    printf("]\n");
  }

  return 0;
}

Measured memory_bytes: 6088
N=int(input())
S=input()

w=e=0
for s in S:
  if s=='W':
    w+=1
  else:
    e+=1

if S[0]=='W':
  v=e
else:
  v=e-1

r=v
for p in range(1, N):
  if S[p]=='W':
    t=v
    if S[p-1]=='W':
      t+=1
  else:
    t=v-1
    if S[p-1]=='W':
      t+=1
  if t<r:
    r=t
  v=t

print(r)



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

using namespace std;

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main () {
    int k; cin >> k;
    long long sum = 0;

    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= k; j++) {
            for (int l = 1; l <= k; l++) {
                sum += gcd(l, gcd(i, j));
            }
        }   
    }

    cout << sum << endl;
}

Measured memory_bytes: 3556
N, Y = map(int, input().split())

# N枚の紙幣で表現可能な額面を求めて，その中にYがあればOK
count = 0
for x in range(0, N + 1):
    for y in range(0, N + 1 - x):
        z = N - x - y
        if (10000 * x) + (5000 * y) + (1000 * z) == Y:
            print(x, y, z)
            break
    else:  # if内でbreakされなかったら実行される（インデント注意）
        count += 1
        continue # 外側のループに渡す
    break

if count == N + 1:
    print(str(-1), str(-1), str(-1))


Measured memory_bytes: 3060
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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; }

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

    ll n, p; cin >> n >> p;
    int flg = 0;
    ll ans = 0;
    rep(i, n) {
        ll a; cin >> a;
        if(a & 1) flg = 1;
    }
    if(flg) {
        ans = pow(2, n - 1);
    } else {
        if(p) ans = 0;
        else ans = pow(2, n);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define sc second
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define pb push_back
#define endl '\n'
#define po(x) (1ll<<x)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> satan_set;
const ll DIM = 100+7;
const ll INF = 10E16;

int main()
{
    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a,b,k;
    cin>>a>>b>>k;
    ll g = min(a,k);
    a-=g;
    k-=g;
    b-=k;
    b = max(0ll,b);
    cout<<a<<' '<<b<<endl;
    return 0;
}

// 1 2 3
//


Measured memory_bytes: 256
// awesome imos method!!!

#include<cstdio>
#include<cstdlib>
#include<cstring>

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

using namespace std;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	int *nail[5002];
	rep(i,n+2){
		nail[i]=(int *)malloc((i+3)*sizeof(int));
		memset(nail[i],0,sizeof nail[i]);
	}

	rep(i,m){
		int a,b,x; scanf("%d%d%d",&a,&b,&x); a--; b--;
		nail[a][b]++;
		nail[a][b+1]--;
		nail[a+x+1][b]--;
		nail[a+x+2][b+1]++;
		nail[a+x+1][b+x+2]++;
		nail[a+x+2][b+x+2]--;
	}
	rep(i,n+2) rep(j,i+1) nail[ i ][j+1]+=nail[i][j];
	rep(i,n+1) rep(j,i+1) nail[i+1][ j ]+=nail[i][j];
	rep(i,n+1) rep(j,i+1) nail[i+1][j+1]+=nail[i][j];

	int ans=0;
	rep(i,n) rep(j,i+1) if(nail[i][j]>0) ans++;
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 50048
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI A(N), B(N);
	REP(i, N) cin >> A[i];
	REP(i, N) cin >> B[i];
	int ans = 0;
	for (int d = 29; d >= 0; d--) {
		int bekihigh = 1 << (d + 1), bekilow = 1 << d;
		REP(i, N) A[i] %= bekihigh, B[i] %= bekihigh;
		SORT(B);
		int num = 0;
		REP(i, N) {
			int add = 0;
			if (bekilow - A[i] >= 0) {
				add += LB(B, bekihigh - A[i]) - LB(B, bekilow - A[i]);
			}
			else {
				add += LB(B, bekihigh - A[i]) - B.begin();
				add += LB(B, bekihigh) - LB(B, bekihigh + bekilow - A[i]);
			}
			num += add;
		}
		if (num & 1)ans += bekilow;
	}

	cout << ans << endl;

	return 0;
}



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

int main()
{
    int no_of_moves, no_of_stones;
    cin >> no_of_moves >> no_of_stones;

    vector <int> move(no_of_moves + 1);
    for(int i = 1; i <= no_of_moves; i++)
        cin >> move[i];

    vector <int> winner(no_of_stones + 1, 2);
    for(int i = 1; i <= no_of_stones; i++)
    {
        for(int j = 1; j <= no_of_moves; j++)
        {
            if(move[j] > i) continue;

            if(winner[i - move[j]] == 2)
                winner[i] = 1;
        }
    }

    cout << (winner[no_of_stones] == 1 ? "First\n" : "Second\n");
    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  string s;
  cin >> s;
  bool t=false;
  rep(i,s.size()-1){
    if (s[i]=='A' && s[i+1]=='C') t=true;
  }
  if (t) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
N,A,B = map(int,input().split())

if (B-A)%2 == 0:
    ans = [N-A,(B-A)//2,B-1]
    print(min(ans))
else:
    ans = [N-A,B-1,((B-A-1)//2)+(N-B+1),((B-A-1)//2)+A]
    print(min(ans))

Measured memory_bytes: 3064
import java.util.*;

class Main {
	public static void main(String[] args){
		final Scanner sc = new Scanner(System.in);		
		final String str = sc.nextLine();
		StringBuilder sb = new StringBuilder();

		for(int i = 0; i < str.length(); i++){
			final char[] ca = str.toCharArray();
			final char c = ca[i];
			if('a' <= c && c <= 'z'){
				sb.append(String.valueOf(c).toUpperCase());
			} else if('A' <= c && c <= 'Z'){
				sb.append(String.valueOf(c).toLowerCase());
			} else {
				sb.append(String.valueOf(c));
			}
			
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 20216
#include <stdio.h>

void solve(char a, char b) {
	char ans;
	if (a == 'H') {
		ans = b;
	}
	else if (b == 'H'){
		ans = 'D';
	}
	else {
		ans = 'H';
	}

	printf("%c", ans);
}

int main()
{
	char a, b;
	scanf("%c %c", &a, &b);
	solve(a, b);
    return 0;
}

Measured memory_bytes: 128
// #include "lcs.h"
#include <algorithm>
#include <iostream>
#include <vector>

std::string trace_string(const std::string& lhs,
                         const std::string& rhs,
                         const std::vector<std::vector<int>>& dp);

std::string lcs(const std::string& lhs, const std::string& rhs)
{
    std::vector<std::vector<int>> dp(lhs.size() + 1,
                                     std::vector<int>(rhs.size() + 1));

    for (size_t left = 1; left <= lhs.size(); ++left)
        for (size_t right = 1; right <= rhs.size(); ++right)
            dp[left][right] =
                (lhs[left - 1] == rhs[right - 1])
                    ? 1 + dp[left - 1][right - 1]
                    : std::max(dp[left][right - 1], dp[left - 1][right]);

    return trace_string(lhs, rhs, dp);
}

std::string trace_string(const std::string& lhs,
                         const std::string& rhs,
                         const std::vector<std::vector<int>>& dp)
{
    std::string result;
    result.reserve(dp.back().back());

    for (size_t left = lhs.size(), right = rhs.size(); left > 0 && right > 0;) {
        if (lhs[left - 1] == rhs[right - 1]) {
            result.push_back(lhs[left - 1]);
            --left;
            --right;
            continue;
        }
        dp[left][right - 1] > dp[left - 1][right] ? --right : --left;
    }

    std::reverse(result.begin(), result.end());
    return result;
}

int main(int argc, char* argv[])
{
    std::string lhs, rhs;
    std::cin >> lhs >> rhs;
    std::cout << lcs(lhs, rhs) << std::endl;
    return 0;
}


Measured memory_bytes: 35584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();

		if(A == B){
			System.out.println("Draw");
		}else if(A != 1 && B != 1){
			if(A>B){
				System.out.println("Alice");
			}else{
				System.out.println("Bob");
			}
		}else{
			if(A == 1){
				System.out.println("Alice");
			}else if(B == 1){
				System.out.println("Bob");
			}
		}

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2100000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

vector<vpl> G(55);
vl ed;

bool dfs(ll u, ll goal, ll p){
	if(u==goal) return true;
	for(auto v : G[u]){
		if(v.first==p) continue;
		if(dfs(v.first,goal,u)){
			ed.push_back(v.second);
			return true;
		}
	}
	return false;
}

int main(){
	ll n; cin >> n;
	rep(i,n-1){
		ll a,b; cin >> a >> b; a--; b--;
		G[a].emplace_back(b,i);
		G[b].emplace_back(a,i);
	}
	ll m; cin >> m;
	vector<P> con(m);
	rep(i,m){
		ll u,v; cin >> u >> v; u--; v--;
		if(u>v) swap(u,v);
		con[i].first = u;
		con[i].second = v;
	}
	vl edges(m,0);
	rep(i,m){
		dfs(con[i].first,con[i].second,-1);
		for(auto e : ed){
			edges[i] += 1LL<<e;
		}
		ed.clear();
	}
	ll ans = 0;
	rep(bit,1<<m){
		ll cnt = 0;
		ll mask = 0;
		rep(i,m){
			if(bit>>i & 1){
				cnt++;
				mask |= edges[i];
			}
		}
		ll white = 0;
		rep(i,n) if(mask>>i & 1) white++;
		ll houjo = cnt & 1 ? -1 : 1;
		ans += houjo * 1LL<<(n-1-white);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

const Mod = 998244353

func main() {
	N, K := ReadInt(), ReadInt()
	L := make([]int, K)
	R := make([]int, K)
	for i := 0; i < K; i++ {
		L[i], R[i] = ReadInt(), ReadInt()
	}
	seg := MakeSegTree(N + 1)
	seg.Add(1, 1)
	for i := 2; i <= N; i++ {
		v := 0
		for k := 0; k < K; k++ {
			l := Max(0, i-R[k])
			r := Max(0, i-L[k])
			v += seg.getSum(l, r+1)
			v %= Mod
		}
		seg.Add(i, v)
	}
	fmt.Println(seg.getSum(N, N+1) % Mod)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

// Segment Tree for Range Sum Query (RSQ)
type SegTree []int

func MakeSegTree(n_ int) SegTree {
	n := 1
	for n < n_ {
		n <<= 1
	}
	return make([]int, n<<1)
}

func (t SegTree) Add(i, x int) {
	i += len(t) >> 1
	for i > 0 {
		t[i] += x
		t[i] %= Mod
		i >>= 1
	}
}

func (t SegTree) getSum(a, b int) int {
	return t.getSumRecur(a, b, 1, 0, len(t)>>1)
}
func (t SegTree) getSumRecur(a, b, k, l, r int) int {
	if b <= l || r <= a {
		return 0
	}
	if a <= l && r <= b {
		return t[k]
	}
	sum := 0
	sum += t.getSumRecur(a, b, k<<1, l, (l+r)>>1)
	sum %= Mod
	sum += t.getSumRecur(a, b, k<<1+1, (l+r)>>1, r)
	sum %= Mod
	return sum
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}


Measured memory_bytes: 5192
#include <iostream>
using namespace std;
int main(){
	int x,y;
	for(int i=0; ;i++){
	cin>>x>>y;
        if(x==0&&y==0){
               break;
         }
	if(x>y){
		swap(x,y);
	}
	cout<<x<<" "<<y<<endl;
        
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(void)
{
   int a, b, k, i;

   scanf("%d%d%d", &a, &b, &k);

   for(i=a;i<=b;i++){
      if((i<=a+k-1)||(i>=b-k+1))
      printf("%d\n", i);
      }

   return 0;
}

Measured memory_bytes: 128
open System
open System.IO

let sw = new StreamWriter(Console.OpenStandardOutput())
sw.AutoFlush <- false
Console.SetOut(sw)

let n = stdin.ReadLine() |> int
let a = stdin.ReadLine().Split()

let parentNoDict = a |> Array.countBy id |> dict

{1..n} |> Seq.map (fun x -> parentNoDict.TryGetValue(string x))
|> Seq.map (fun (x1, x2) -> 
    match x1, x2 with
    | true, v -> v
    | false, _ -> 0)
|> Seq.map string
|> Seq.iter stdout.WriteLine

stdout.Flush()

Measured memory_bytes: 87216
A=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
B=[int(input()) for _ in range(n)]

for i in B:
    for j in range(3):
        for k in range(3):
            if A[j][k]==i:
                A[j][k]=0

for i in range(3):
    if sum(A[i])==0:
        print("Yes")
        exit()

for i in range(3):
    if A[0][i]+A[1][i]+A[2][i]==0:
        print("Yes")
        exit()

for i,j,k in [[(0,0),(1,1),(2,2)],[(0,2),(1,1),(2,0)]]:
    if A[i[0]][i[1]]+A[j[0]][j[1]]+A[k[0]][k[1]]==0:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
    int a, b, c;
    
    scanf("%d%d%d", &a, &b, &c);
    
    if(a<b && b<c){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
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; }

ll MOD = 1000000007;

int main(void){
  int l,r,d; cin >> l >> r >> d;
  int count  = 0;
  for(int i = l; i <= r; i++){
    if(i % d == 0) count++;
  }
  cout << count << endl;
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    rep(i, N) cin >> V[i];
    rep(i, N) cin >> C[i];

    int sum = 0;
    rep(i, N) {
        if(V[i] > C[i]) sum += V[i] - C[i];
    }

    cout << sum << endl;
    return 0;

}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>

int main(){

	long int A, B, sum;

	scanf("%ld %ld", &A, &B);

	sum = A + B;
	if (A - B > sum)
		sum = A - B;
	if (A * B > sum)
		sum = A * B;

	printf("%ld\n",sum );

	return 0;
}

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

long long N, X, A[200009], S, ret;

int main() {
	cin >> N >> X;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A, A + N);
	for (int i = 0; i < N; i++) {
		S += A[i];
		if (S <= X) { ret = i + 1; }
	}
	if (S != X && ret == N) ret = N - 1;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

int main() {
	string st; cin >> st;
	string stack;
	bool ok = true;
	for (int i = 0; i < st.size(); ++i) {
		stack.push_back(st[i]);
		while (stack.size() >= 3) {
			if (stack.substr(stack.size() - 3, 3) == "mew") {
				stack.pop_back();
				stack.pop_back();
				stack.pop_back();
			}
			else {
				break;
			}
		}
		if (stack.empty() && i != st.size() - 1) {
			ok = false;
			break;
		}
	}
	if (stack.size()||!ok) {
		cout << "Rabbit" << endl;
	}
	else {
		cout << "Cat" << endl;
	}
	return 0;
}

Measured memory_bytes: 3232
while line = gets
  n=line.chomp.to_i;
  l=gets.chomp.split(" ").map(&:to_i);
  array = l.sort
  sum = 0
  len = array.length / 2
  (0...len).each do |i|
    a = array[i * 2]
    b = array[i * 2 + 1]
    sum += a
  end
  puts sum
end



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

const int INF = 1001001001;
int a[12][12];

int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  int ans = INF;
  rep(s, 1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i, n) {
      if (s>>i&1) {
        cost += c[i];
        rep(j, m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j, m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
  int date, HW, HWdate, HWsum = 0, play, i;
  scanf("%d", &date);
  scanf("%d",&HW);
  for(i=0;i<HW;i++){
    HWdate = 0;
    scanf("%d",&HWdate);
    HWsum = HWsum + HWdate;
  }
  play = date - HWsum;
  
  if(play<0){
    play = -1;
  }
 
  printf("%d",play);
  
  return 0;
}

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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,lessl<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define double long double

#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)

#define bp __builtin_popcountll
#define inf 1e18

const int N=3e3+5;
const int M=1e9+7;
int dp[N][N];
int ans[N][N][4];
void solve()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			dp[i][j]=0;
			for(int p=0;p<4;p++)
			ans[i][j][p]=0;
		}
	}
	while(k--)
	{
		int r1,c1,v1;
		cin>>r1>>c1>>v1;
		dp[r1][c1]=v1;
	}
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			ans[i][j][0]=max(ans[i-1][j][3],ans[i][j-1][0]);
			ans[i][j][1]=max(dp[i][j]+ans[i-1][j][3],max(ans[i][j-1][1],ans[i][j-1][0]+dp[i][j]));
			ans[i][j][2]=max(dp[i][j]+ans[i-1][j][3],max(ans[i][j-1][2],ans[i][j-1][1]+dp[i][j]));
			ans[i][j][3]=max(dp[i][j]+ans[i-1][j][3],max(ans[i][j-1][3],ans[i][j-1][2]+dp[i][j]));
			ans[i][j][1]=max(ans[i][j][1],ans[i][j][0]);
			ans[i][j][2]=max(ans[i][j][2],ans[i][j][1]);
			ans[i][j][3]=max(ans[i][j][3],ans[i][j][2]);
			// cout<<ans[i][j][3]<<" ";
		}
		// cout<<endl;
	}
	int res=ans[n][m][3];
	cout<<res<<endl;
	
}



signed main()
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}


Measured memory_bytes: 356336
N = int(input())
c = list(input())
sousa = 0
w = 0
r = N-1

for i in range(N):
    if c[w] == 'W' and c[r] == 'R':
        c[w] = 'R'
        c[r] = 'W'
        r -= 1
        w += 1
        sousa += 1
    elif c[w] == 'W':
        r -= 1
    elif c[r] == 'R':
        w += 1
    else:
        r -= 1
        w += 1
    if w >= r:
        break

print(sousa)

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

int main() {
	int n, l;
	cin >> n >> l;
	vector<string> sen(n);
	for (int i = 0; i < n; i++) {
		cin >> sen.at(i);
	}
	sort(sen.begin(), sen.end());
	for (int i = 0; i < n; i++) {
		cout << sen.at(i);
	}
	cout << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = [0] + sorted(map(int, input().split()))

# iを除いた左右の部分集合でK以上の数が作れるか
rdp_shift = [N + 1] * K  # rdp_shift[j] = (右からi個を使って部分和jを作れるような最初のi)
rdp_shift[0] = 0
rdp = [0] * K  # rdp[i][j] = (a(-1),...,a(-i)の部分和でjを作れるか)
rdp[0] = 1
for i in range(1, N + 1):
    rdp2 = [0] * K
    for j in range(K):
        if rdp[j] == 1:
            rdp2[j] = 1
            continue
        # print(j, -i, j - A[-i])
        # print(i, j)
        if j - A[-i] >= 0 and rdp[j - A[-i]] == 1:
            rdp2[j] = 1
            rdp_shift[j] = i
    rdp = rdp2

# print(rdp_shift, A)
ldp = [0] * K
ldp[0] = 1
S = [0] * (K + 1)
ans = 0
for i in range(1, N + 1):
    # ここで一つ一つチェックしている！！
    # A[i]が不要かチェック
    for j in range(K):
        # print(j)
        S[j + 1] = S[j]
        if rdp_shift[j] <= N - i:
            # print(S, rdp_shift, j, N - i, A[i])
            S[j + 1] += 1
            # print(S)
            # print(S, rdp_shift[j], N - i, i, j)
    no_need = True
    for lval in range(K):
        # print(ldp, lval)
        if ldp[lval] == 0:
            continue
        # print(K - A[i] - lval)
        rval = S[K - lval] - S[max(0, K - A[i] - lval)]
        # print(S, K - lval, K - A[i] - lval, rval)
        # print(rval, no_need, A[i], lval)
        # rval > 0というのはA[i]がなければ、K以上の集合を作れない場合があるということ
        if rval > 0:
            # print(S, K - lval, K - A[i] - lval, lval, rval, i, j, A[i])
            no_need = False
            break
    if no_need:
        ans += 1

    # ldp[i][:]の計算
    ldp2 = [0] * K
    for j in range(K):
        if ldp[j] == 1 or (j >= A[i] and ldp[j - A[i]] == 1):
            ldp2[j] = 1
    ldp = ldp2
print(ans)


Measured memory_bytes: 76288
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

ll a, b, n;
ll f(ll x){
  return (a*x) / b - a * (x / b);
}

int main(void){
  cin >> a >> b >> n;
  
  if (b <= n){
    cout << max(f(b), f(b-1)) << endl;
  }
  else {
    cout << f(n) << endl;
  }

  return 0;
}


Measured memory_bytes: 3596
function F()
    N = parse(BigInt,readline())
    A = parse.(BigInt,split(readline()))
    
    S = 0
    for i= 2:N
        if A[i-1]>=A[i]
            S += A[i-1]-A[i] 
            A[i] = A[i-1]
            
        end
    end
    println(S)
    
    
end
F()

Measured memory_bytes: 326204
#include <algorithm>
#include <climits>
#include <iostream>
#include <iomanip>
#include <random>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using std::cin;
using std::cerr;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
using std::stack;
using std::string;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using std::lower_bound;
using std::upper_bound;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  if (n / 100 == 7 || n % 100 / 10 == 7 || n % 10 == 7) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  int max=1;
  for(int i=1;i<1000;i++){
    if(N/std::pow(K,i) >= 1)max=i+1;
  }
  cout << max;
}

Measured memory_bytes: 640
#include<stdio.h>

int is_prime(int n)
{
	int i;

	if (n == 2) {
		return (1);
	}
	else if (n < 2 || n % 2 == 0) {
		return (0);
	}
	for (i = 3; i * i <= n; i += 2) {
		if (n % i == 0) {
			return (0);
		}
	}
	return (1);
}

int main()
{
	int n;
	int num;
	int cnt;

	scanf("%d", &n);
	cnt = 0;
	while (n--) {
		scanf("%d", &num);
		if (is_prime(num) == 1) {
			cnt++;
		}
	}
	printf("%d\n", cnt);

	return 0;
}


Measured memory_bytes: 2016
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int MAX_N = 12;
const int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
int h, w;
int table[MAX_N][MAX_N];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> h >> w, h | w)
    {
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++) cin >> table[i][j];
        }
        int ans = 0;
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                for(int k = i + 2; k < h; k++)
                {
                    for(int l = j + 2; l < w; l++)
                    {
                        int num = INF;
                        for(int p = i; p <= k; p++) num = min(num, table[p][j]);
                        for(int p = i; p <= k; p++) num = min(num, table[p][l]);
                        for(int q = j; q <= l; q++) num = min(num, table[i][q]);
                        for(int q = j; q <= l; q++) num = min(num, table[k][q]);
                        int cnt = 0;
                        bool flag = false;
                        for(int p = i + 1; p < k; p++)
                        {
                            for(int q = j + 1; q < l; q++)
                            {
                                if(table[p][q] >= num) flag = true;
                                cnt += (num - table[p][q]);
                            }
                        }
                        if(flag) cnt = -1;
                        ans = max(ans, cnt);
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 3228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();


		int maxl = 0;
		int minr = 100000;

		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			maxl = Math.max(maxl, l);
			int r = sc.nextInt();
			minr = Math.min(minr, r);
		}
		sc.close();

		System.out.println(minr-maxl+1>=0?minr-maxl+1:0);

	}

}


Measured memory_bytes: 63256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	cout << fixed << setprecision(18);
	ll x, a, b;

	cin >> x;

	rep(i, 1000)
	{
		rep(j, 1000)
		{
			if ((ll)pow(i, 5) - (ll)pow(j, 5) == x)
			{
				a = i;
				b = j;
				break;
			}
			else if ((ll)pow(i, 5) + (ll)pow(j, 5) == x)
			{
				a = i;
				b = -j;
				break;
			}
		}
	}

	cout << a << " " << b << endl;


	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t A;
  cin >> A ;
  double B;
  cin >> B;
  int64_t C = B*100 + 0.01 ;
  
  int64_t mul = A * C;
  int64_t ans = mul/100;
cout << ans << endl;
}


Measured memory_bytes: 3732