akhauriyash/Code-Regression huggingface dataset:
while True:
    H,W = map(int, input().split())
    
    if H == 0 and W == 0:
        break;
    
    for i in range(H):
        if i % 2 == 0:
            a = "#."
            l = a*W
            print(l[:W])
        if i % 2 == 1:
            a = ".#"
            l = a*W
            print(l[:W])

    print()


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
int main(){
    string w;
    cin >> w;
    vector<char> data;
    int w_size = w.size();
    if(w_size % 2 == 0){
        for (int i = 0; i < w_size; i++){
            data.push_back(w[i]);
        }
        sort(data.begin(), data.end());
        bool flag;
        for (int i=0; i < w_size/2; i++){
            if(data[2*i] == data[2 * i + 1]){
                flag = true;
            }else{
                flag = false;
                break;
            }
        }
        if (flag == true){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        }
    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
N, K = map(int, input().split())
#N: , K: K個以上の数を選ぶ
MOD = pow(10, 9)+7
#fix = pow(10, 100, MOD) #10の100乗をmodで計算した結果
#この値は使用しない

    #最大値: 小さい順にm個 -> 0+1+2+....+(m-1) = m*(m-1)/2
    #最小値: 大きい順にm個 -> N+(N-1)+...+(N-m+1) = m*(2N-m+1)/2
    #最大値から最小値までの全ての値を作ることができる
    #mの値はK以上N+1以下

ans = 0
for m in range(K, N+2):
    ans += ((N-m+1)*m+1)%MOD #((N-m+1)*m+1)通り

print(ans%MOD)


Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

ll lcm(ll x, ll y) {
    return x / __gcd(x, y) * y;
}

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  rep(i, 0, N) cin >> A[i];
  long maxa = accumulate(all(A), A[0], [](long x, long y) {return max(x, y);});
  if (maxa < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  long gcd1 = accumulate(all(A), A[0], [](long x, long y) {return __gcd(x, y);});
  long gcd2 = __gcd(gcd1, K);
  if (gcd1 == gcd2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n, a[100005], b[100005];
  cin >> n;
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];

  ll ans = 0;
  rep(i, n){
    if(a[i] <= b[i]){
      ans += a[i];
      b[i] -= a[i];
    }
    else{
      ans += b[i];
      b[i] = 0;
    }
    if(a[i+1] <= b[i]){
      ans += a[i+1];
      a[i+1] = 0;
    }
    else{
      ans += b[i];
      a[i+1] -= b[i];
    }
  }
  cout << ans << endl;
}


/*





















*/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
const int M =998244353; 
#define int long long int
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define MAX 1e15+1
#define pi  pair<int,int>  
const int mod = 1e9 + 7;
const int N = 3e5 + 7;
 
int n,k,a[409];
int dp[409][409],pre[409];

int sum(int aa, int b){
	if(aa>b)return 0;
	if(aa==0)return pre[b];
	return pre[b]-pre[aa-1];
}
int solve(int l,int r) {
	if(l>=r){
		
		return 0;

	}
	if(dp[l][r]!=-1)return dp[l][r];
  	int val=MAX;
  	for(int i=l;i<r;i++){

  		int x = solve(l,i);
  		int y = solve(i+1,r);
  		int p = x+y+sum(l,i)+sum(i+1,r);
  		val=min(val,p);



  	}
  	dp[l][r] = val;
  	return val;



	
 
 
}
 
signed main() {
  fast;
  
  cin>>n;
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  pre[0]=a[0];
  for(int i=1;i<n;i++)
  	pre[i]=pre[i-1]+a[i];
  	
  memset(dp,-1,sizeof(dp));
  cout<<solve(0,n-1);
  



  	
}

Measured memory_bytes: 1536
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int v[3];
char s[SIZE];
char cc[4]="rsp";
int get(char c){
    REP(i,3){
        if(cc[i]==c)return i;
    }
    return -1;
}
int dp[SIZE][3];
int main(){
    int N,K;
    R(N,K);
    REP(i,3)R(v[i]);
    RS(s);
    int an=0;
    auto maa = [](auto& x,auto y){if(x<y)x=y;};
    REP(i,N){
        int id=get(s[i]);
        if(i<K){
            dp[i][(id+2)%3]=v[(id+2)%3]; 
        }
        else{
            REP(j,3)REP(k,3){
                if(j==k)continue;
                if(j==(id+2)%3) maa(dp[i][j],dp[i-K][k]+v[j]);
                else maa(dp[i][j],dp[i-K][k]);
            }
        }
        if(i+K>=N)an+=*max_element(dp[i],dp[i]+3);
    }
    W(an);
    return 0;
}


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

int main() {

    string S;
    cin >> S;

    if (S == "Sunny") cout << "Cloudy" << endl;
    if (S == "Cloudy") cout << "Rainy" << endl;
    if (S == "Rainy") cout << "Sunny" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <boost/multi_array.hpp>

int main() {
    unsigned long long ans = 0;
    int N;
    std::cin >> N;
    
    std::vector<std::string> words(N);
    
    //入力
    for (int i = 0; i < N; i++) {
        std::string str;
        std::cin >> str;
        //ソートできる！！！
        std::sort(str.begin(), str.end());
        words[i] = str;
    }
    
    //要素のメモにはマップが良い
    std::map<std::string, int> m;
    
    //文字の組み合わせがいくつずつあるか記録する
    for (int i = 0; i < N; i++) {
        m[words[i]] = m[words[i]] + 1; //要素が存在しなければ追加され、0が帰る
    }
    if (false) {
        for (int i = 0; i < N; i++) {
            int n = m[words[i]];
            std::cout << n << std::endl;
        }
    }
    //文字の組み合わせの数がnなら、nC2通りの取り方がある
    //mapはイテレータでレンジを回せる
    for (auto itr = m.begin(); itr != m.end(); itr++) {
        long long n = itr->second;
        ans += n*(n-1)/2;
    }
    
    
    //これはTLE
    /*
     std::vector<std::vector<int>> array(N, std::vector<int>(26, 0));
    for (int i = 0; i < N; i++) {
        std::string str = words[i];
        for (int j = 0; j < 10; j++) {
            char moji = str[j];
            int num = 0;
            for (char ch = 'a'; ch <= 'z'; ch++) {
                if (moji == ch) {
                    array[i][num] += 1;
                    break;
                }
                num += 1;
            }
        }
    }
    //テスト
    if (false) {
        for (int i = 0; i < N; i++) {
            for (int num = 0; num < 26; num++) {
                std::cout << array[i][num] << ", ";
            }
            std::cout << std::endl;
        }
    }
    
    
    
    
    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
            if (array[i] == array[j]) {
                ans += 1;
            }
        }
    }*/
    
    
    
    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 11904
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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


fn solve(n: i64, m: i64) -> i64 {
    if n >= m / 2 {
        return m / 2
    }

    let rem = m - n * 2;
    n + rem / 4
}


fn main() {
    input! {
        n: i64,
        m: i64,
    }
    println!("{}", solve(n, m));
}


Measured memory_bytes: 4352
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();      
        String n = r.s();
        print(n.replace('1', '0')
               .replace('9', '1')
               .replace('0', '9'));
    }
    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int Int(String s){
            return Integer.parseInt(s);
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 21204
def Floor_sum(N,M,A,B):
    ANS=0

    if A>=M:
        ANS+=N*(N-1)//2*(A//M)
        A%=M
    if B>=M:
        ANS+=B//M*N
        B%=M

    y_max=(A*N+B)//M
    x_max_divA=y_max*M-B

    if y_max==0:
        return ANS
    else:
        ANS+=Floor_sum(y_max,A,M,A*N-x_max_divA)
        return ANS

T=int(input())
for tests in range(T):
    N,M,A,B=map(int,input().split())
    print(Floor_sum(N,M,A,B))

Measured memory_bytes: 9072
local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1], x) then return 1 end
  if comp(ary[num], x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid], x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local function upper_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[1]) then return 1 end
  if not comp(x, ary[num]) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid]) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, q = io.read("*n", "*n")
local a = {io.read("*n")}
local asum = {a[1]}
for i = 2, n do
  a[i] = io.read("*n")
  asum[i] = asum[i - 1] + a[i]
end
local oddsum = {a[1]}
for i = 2, n do
  if i % 2 == 0 then
    oddsum[i] = oddsum[i - 1]
  else
    oddsum[i] = oddsum[i - 1] + a[i]
  end
end

local function get_ao_state(x, taka_count)
  local p_right = n - taka_count
  local len = a[p_right] - x
  if len <= 0 then
    -- taka_count should be smaller
    return true, 0
  end
  local p_left = lower_bound(a, x - len)
  local need_ao_count = p_right - p_left + 1
  if taka_count < need_ao_count then
    -- taka_count should be larger
    return false
  else
    return true, need_ao_count
  end
end

for iq = 1, q do
  local x = io.read("*n")
  local x_lbpos = lower_bound(a, x)
  local taka_count_lim = n + 1 - x_lbpos
  local taka_count, ao_count = 0, 0
  if 0 < taka_count_lim then
    local f = get_ao_state(x, 0)
    if not f then
      local min, max = 0, taka_count_lim
      while 1 < max - min do
        local mid = mfl((max + min) / 2)
        if get_ao_state(x, mid) then
          max = mid
        else
          min = mid
        end
      end
      taka_count = max
    end
  end
  local _u, ao_count = get_ao_state(x, taka_count)
  if ao_count < taka_count - 1 then
    ao_count = taka_count - 1
  end
  local takasum = asum[n] - asum[n - taka_count]
  local rem = n - taka_count - ao_count
  if 0 < rem then
    if rem % 2 == 0 then
      if ao_count < taka_count then
        takasum = takasum + oddsum[n - taka_count - ao_count]
      else
        takasum = takasum + asum[n - taka_count - ao_count] - oddsum[n - taka_count - ao_count]
      end
    else
      if ao_count < taka_count then
        takasum = takasum + asum[n - taka_count - ao_count] - oddsum[n - taka_count - ao_count]
      else
        takasum = takasum + oddsum[n - taka_count - ao_count]
      end
    end
  end
  print(takasum)
end


Measured memory_bytes: 5120
#include<iostream>
#include<algorithm>
#include<vector>
#include<complex>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define pb         push_back
typedef complex<double> P;

const double inf = 1e10;
const double eps = 1e-10;

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

bool isp(P a,P b,P c){
  return abs(a-c)+abs(b-c) < abs(a-b)+eps;
}

bool is_intersected_ls(P a1,P a2,P b1,P b2){
  if ( isp(a1,a2,b1))return true;
  if ( isp(a1,a2,b2))return true;
  if ( isp(b1,b2,a1))return true;
  if ( isp(b1,b2,a2))return true;
  if (  ( cross(a2-a1,b1-a1) * cross(a2-a1,b2-a1)<-eps ) && //-EPS
	( cross(b2-b1,a1-b1)*cross(b2-b1,a2-b1)<-eps))return true;
  else return false;
}


P intersection_ls(P a1,P a2,P b1,P b2){
  P b = b2-b1;
  double d1=abs(cross(b,a1-b1));//
  double d2=abs(cross(b,a2-b1));
  double t = d1/(d1+d2);//p[^ t:1-t = d1:d2
  return a1+(a2-a1)*t;
}


double iscrash(P a,P b,P op1,P op2,double ver,double t){
  if (!is_intersected_ls(a,b,op1,op2))return -1;
  P cp = intersection_ls(a,b,op1,op2);
  double cmpt = abs(cp-a)/ver;
  if (cmpt > -eps && cmpt < t)return cmpt;
  return -1;
}

double find_min(vector<P> in,vector<int> time,
		vector<P> v){
  
  int t;
  double x;
  P s1,s2;
  P sv;//shot v
  double len;
  cin>>t>>x>>sv.real()>>sv.imag()>>len;
  double ret = 2*inf;
  s1=P(x,0);
  s2=P(x-(len*sv.real()/abs(sv)),-(len*sv.imag()/abs(sv)));
  
  int now = 0;//now time
  P move(0,0);
  bool flag=false;

  rep(i,time.size()){
    if (!flag&&now <= t && t <= time[i]){//[now,t],[t,time[i]]
      P tmpmove=move;
      flag=true;
      time.insert(time.begin()+i,time[i]);
      v.insert(v.begin()+i,v[i]);
      time[i]=t;
    }else if(flag){//t < time[i]
      double tv=abs(v[i]-sv);
      double ttime = time[i]-now;
      rep(j,in.size()){
	double tmp;
	tmp=iscrash(in[j]+move,in[j]+move+(ttime)*(v[i]-sv),
		    s1,s2,
		    tv,ttime);
	if (tmp >-eps)ret=min(tmp+now,ret);
	
	tmp=iscrash(s1,s1+(ttime)*(sv-v[i]),
		    in[j]+move,in[(j+1)%in.size()]+move,
		    tv,ttime);
	if (tmp > -eps)ret=min(tmp+now,ret);

	tmp=iscrash(s2,s2+(ttime)*(sv-v[i]),
		    in[j]+move,in[(j+1)%in.size()]+move,
		    tv,ttime);
	if (tmp > -eps)ret=min(tmp+now,ret);
      }
      s1+=sv*(double)(time[i]-now);
      s2+=sv*(double)(time[i]-now);
    }

    move+=((double)time[i]-now)*v[i];
    now=time[i];
    if (!(ret>inf))return ret;
  }
  
  return -1;
}

void solve(vector<P> &in,vector<int>&time,
	   vector<P> &v,int b){

  vector<double>ans;
  rep(i,b){ 
    double tmp = find_min(in,time,v);
    if (tmp >-eps)ans.pb(tmp);
  }


  sort(ans.begin(),ans.end());
  cout << ans.size() << endl;
  rep(i,ans.size()){
    printf("%.3lf\n",ans[i]);
  }
}

main(){
  int n,m,b;
  while(cin>>n>>m>>b && n){
    vector<P> in;
    rep(i,n){
      P tmp;
      cin>>tmp.real()>>tmp.imag();
      in.pb(tmp);
    }
    vector<int> time;
    vector<P>   v;
    rep(i,m){
      int a;P b;
      cin>>a>>b.real()>>b.imag();
      time.pb(a);
      v.pb(b);
    }
    time.pb(10000000);
    v.pb(P(0,0));
    solve(in,time,v,b);
  }


  return false;
}

Measured memory_bytes: 1044
A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
x = [int(input()) for _ in range(Q)]
INF = 100000000000


def binary_search(x, l, lo, hi):
    med = (lo + hi) // 2
    if hi - lo <= 1:
        if x < l[0]:
            return INF, abs(x-l[med])
        elif x > l[-1]:
            return abs(x-l[med]), INF
        else:
            return abs(x-l[med]), abs(x-l[med+1])

    if x > l[med]:
        return binary_search(x, l, med, hi)
    elif x < l[med]:
        return binary_search(x, l, lo, med)
    else:
        return 0, 0


for i in x:
    sl, sr = binary_search(i, s, 0, len(s))
    tl, tr = binary_search(i, t, 0, len(t))

    if tl >= sl and tr >= sr:
        print(min(tl, tr))
    elif sl >= tl and sr >= tr:
        print(min(sl, sr))
    elif tl >= sl and sr >= tr:
        sl1 = min(tl, 2*sl+tr)
        tr1 = min(sr, 2*tr+sl)
        print(min(sl1, tr1))
    else:
        tl1 = min(sl, 2*tl+sr)
        sr1 = min(tr, 2*sr+tl)
        print(min(tl1, sr1))


Measured memory_bytes: 17708
#include<stdio.h>
int main(){
  int i, j, k, N, K, d, A[100], count=0;
  scanf("%d %d", &N, &K);
  for(i=0; i<N; i++){
    A[i]=1;
  }
  for(i=0; i<K; i++){
    scanf("%d", &d);
    for(j=0; j<d; j++){
      scanf("%d", &k);
      A[k-1]=0;
    }
  }
  for(i=0; i<N; i++){
    count+=A[i];
  }
  printf("%d", count);
  return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  string s, t;
  cin >> s >> t;
  string ans = t + s;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;

int main() {
    while (1) {
        int n;
        cin >> n;
        if (!n) return 0;
        
        int lim = n * 499 + 1;
        vector<P> dp(lim, P(-M, -M));
        dp[0] = P(0, 0);
        for (int i = 0; i < n; ++i) {
            int p;
            cin >> p;
            vector<P> nex = dp;
            int q = (500 - p % 500) % 500;
            if (p % 1000 > 0 && p % 1000 <= 500)
                for (int j = q; j < lim; ++j)
                    nex[j] = max(nex[j], P(dp[j - q].first + 1, dp[j - q].second - p));

            else {
                int r = p % 500 == 0 ? 500 : p % 500;
                for (int j = q; j < lim; ++j)
                    nex[j] = max(nex[j], P(dp[j - q].first, dp[j - q].second - p));
                for (int j = 0; j + r < lim; ++j)
                    nex[j] = max(nex[j], P(dp[j + r].first + 1, dp[j + r].second - p));
            }
            dp = nex;
        }
        int ma = 0, mi = 0;
        for (auto& a : dp) {
            if (a.first > ma) {
                ma = a.first;
                mi = -a.second;
            }
            else if (a.first == ma && -a.second < mi)
                mi = -a.second;
        }
        cout << ma << " " << mi << "\n";
    }
}



Measured memory_bytes: 3624
def inpl(): return list(map(int, input().split()))
N, M = inpl()
X = sorted([inpl() for _ in range(N)], key=lambda x: -x[0])
ans = 0
while M:
    a, b = X.pop()
    buy = min(M, b)
    ans += a*buy
    M -= buy
print(ans)

Measured memory_bytes: 33016
use List::Util qw/ min /;

my ($n, $m, $x) = split ' ', <>;
my @c = ();
my @a = ();

for (0..$n-1) {
    my ($c_tmp, @a_tmp) = split ' ', <>;
    push @c, $c_tmp;
    push @a, \@a_tmp;
}

my @candidates = map {
    my $cost = buy($_, [ map {0} (0..$m-1) ]);
    ($cost == -1) ? () : $cost;
} (0..$n-1);

print((@candidates) ? min(@candidates) : -1);


sub progress_skill {
    my ($i, $progress) = @_;
    return [ map { $progress->[$_] + $a[$i]->[$_] } (0..$m-1)];
}
sub skill_check {
    my $progress = shift;
    my @beginner = grep { $progress->[$_] < $x } (0..$m-1);
    return (@beginner) ? 0 : 1;
}
sub buy {
    my ($i, $current_progress) = @_;
    my $next_progress = progress_skill($i, $current_progress);
    if(skill_check($next_progress)) {
        return $c[$i];
    }
    elsif($i == $n-1) {
        return -1;
    }
    else {
        my @costs = map {
            my $amount = buy($_, $next_progress);
            ($amount == -1) ? () : $amount;
        } ($i+1..$n-1);
        my $min_cost = (@costs) ? $c[$i] + min(@costs) : -1;
        return $min_cost;
    }
}

Measured memory_bytes: 5472
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
#define IMAX 0x3f3f3f3f
#define LLMAX 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef double db;
inline int read() {
  int x=0,f=1;
  char c=getchar();
  while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
  while(isdigit(c)){x=x*10+c-'0';c=getchar();}
  return x*f;
}
ll k,finali,finalj,lastnum,dp[15][12];
ll lastnow,now,num;

signed main() {
  k=read();
  rep(i,1,13){
    rep(j,0,9){
      if(i==1)dp[i][j]=1;
      else {
        if(j==0)dp[i][j]=dp[i-1][0]+dp[i-1][1];
        else if(j==9)dp[i][j]=dp[i-1][9]+dp[i-1][8];
        else dp[i][j]=dp[i-1][j-1]+dp[i-1][j]+dp[i-1][j+1];
      }
      // printf("%d ", dp[i][j]);
    }
    // puts("");
  }
  rep(i,1,13){
    rep(j,1,9){
      lastnow=now;
      now+=dp[i][j];
      if(now>=k&&finali==0){
        finali=i,lastnum=j;
        num=k-lastnow;
      }
    }
  }
  printf("%d",lastnum);
  per(i,finali-1,1){
    if(lastnum==9){
      int a=8,b=9;
      if(dp[i][a]<num)lastnum=b,num=num-dp[i][a];
      else lastnum=a;
    }else{
      int a=lastnum-1,b=lastnum,c=lastnum+1;
      if(dp[i][a]+dp[i][b]<num)lastnum=c,num=num-dp[i][b]-dp[i][a];
      else if(dp[i][a]<num)lastnum=b,num=num-dp[i][a];
      else lastnum=a;
    }
    printf("%d",lastnum);
  }
  puts("");
  return 0;
}

Measured memory_bytes: 256
main = do
    [a, b, h, m] <- map read . words <$> getLine :: IO [Double]
    let theta_h = (h + m / 60) / 12 * 2 * pi
    let theta_m = m / 60 * 2 * pi
    let x_h = a * cos theta_h
    let y_h = a * sin theta_h
    let x_m = b * cos theta_m
    let y_m = b * sin theta_m
    let d = sqrt ((x_h - x_m) ^ 2 + (y_h - y_m) ^ 2)
    print d


Measured memory_bytes: 4524
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void){
    int a, b;
    cin >> a >> b;
    int c = a%b;
    int ans;
    if(c == 0)
        ans = a/b;
    else if(c != 0)
        ans = a/b + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
 
class Program
{
    static void Main(string[] args)
    {
        ulong result = 0;
 
    	//読み込み情報を取得
        var input = Console.ReadLine().Split(' ');
        
        //数値に変換
        var priceA = ulong.Parse(input[0]);
        var priceB = ulong.Parse(input[1]);
        var priceAB = ulong.Parse(input[2]);
        var cnt1 = ulong.Parse(input[3]);
        var cnt2 = ulong.Parse(input[4]);
        
        //最小個数を求める
        var min = Math.Min(cnt1, cnt2);
        
        //単体の最大価格を求める
        ulong mp;
        if (min == cnt1) mp = priceB;
        else mp = priceA;
        
        var maxPrice = mp;
		//価格を求める
        if (priceA + priceB >= 2 * priceAB) 
        {
        	//単体個数の最大価格が、AB価格の倍以下の場合
            if (maxPrice<=2*priceAB) 
            {
            	//AB価格x最小個数の2倍を掛ける(単体の端数分以外を算出する)
            	result += 2 * priceAB * min;
            }
            else 
            { 
                //AB価格で、最大個数の方を掛ける(A,B半分余っても価格安いケース)
                Console.WriteLine(2 * priceAB * Math.Max(cnt1, cnt2));
            	return; 
            }
        }
        else 
        {
        	//単体の掛け算が最も安いケース
            Console.WriteLine(priceA * cnt1 + priceB * cnt2); 
        	return; 
        }
        //端数を足して残りの額を合算して結果を求める。
        Console.WriteLine((Math.Max(cnt1, cnt2) - min) * maxPrice + result);
    }
}

Measured memory_bytes: 13140
# -*- coding: utf-8 -*-

def main():
    
    str=input()
    ans=""
    for c in str:
        if(c=='B' and ans!=""):
            ans=ans[:-1]
        elif(c!='B'):
            ans+=c
    print(ans)
            

if __name__=="__main__":
    main()
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
    using namespace std;
 
    int main()
    {
        int a,b,c;
        cin>>a>>b>>c;
        if(a==b&&a!=c)cout<<"Yes";
        else if(a==c&&a!=b)cout<<"Yes";
        else if(c==b&&a!=c)cout<<"Yes";
        else cout<<"No";
 
        return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int weight[30] = {0}, zero[30] = {0};

void solve(string num, int &len, int &used, map<int,map<int,int>> &m, set<char> &s){
    int sum = 0;
    int i = 0;
    for(auto it:s){
        if(zero[it - 'A'] && num[i] == '0') return;
        sum+=weight[it - 'A'] * (num[i] - '0');
        i++;
    }
    m[sum][used]++;
}

void dfs(int used, string s, int &len, map<int,map<int,int>> &m, set<char> &st){
    range(i,0,10){
        if(used & (1 << i)) continue;
        used ^= (1 << i);
        s+=('0' + i);
        if(s.size() == len) solve(s,len,used,m,st);
        else dfs(used,s,len,m,st);
        used ^= (1 << i);
        s.pop_back();
    }
}

void makeConvertTable(int up[30], int low[30], set<char> s){
    auto it = s.begin();
    int j = 0, k = 0;
    rep(i,s.size()){
        if(i < s.size() / 2){
            up[*it - 'A'] = j++;
        }else{
            low[*it - 'A'] = k++;
        }
        it++;
    }
}

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

    int n;
    while(cin >> n,n){
        map<int,map<int,int>> up, low; //sum -> map<used,count>
        set<char> s, s_up, s_low;
        memset(weight, 0, sizeof(weight));
        memset(zero, 0, sizeof(zero));


        rep(i,n){
            string a;
            cin >> a;
            int k = 1;
            for(int j = a.size() - 1; j >= 0; j--){
                if(i == n - 1) weight[a[j] - 'A'] -= k;
                else weight[a[j] - 'A'] += k;
                s.insert(a[j]);
                k*=10;
            }
            if(a.size() >= 2)  zero[a[0] - 'A'] = 1;
        }
        //rep(i,27) show(zero[i])

        {
            auto it = s.begin();
            rep(i,s.size()){
                if(i < s.size() / 2) s_up.insert(*it);
                else s_low.insert(*it);
                it++;
            }
        }

        int len = s.size() / 2;
        dfs(0,"",len,up,s_up);
        len = s.size() - len;
        dfs(0,"",len,low,s_low);

        int cnt = 0;
        for(auto i:up){
            for(auto k:i.second){
                for(auto j:low[-i.first]){
                    if((j.first & k.first) == 0){
                        cnt+=j.second*k.second;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 12776
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    pn = list(map(int, input().split()))
    is_ex_list = [False for i in range(max(pn) + 1)]
    for p in pn:
        is_ex_list[p] = True
    min_v = 101
    min_f = 101
    for i in range(-200, 201):
        if len(is_ex_list) > i and i >= 0:
            if not is_ex_list[i] and abs(x - i) < min_v:
                min_f = i 
                min_v = abs(x - i)
        elif abs(x - i) < min_v:
                min_f = i 
                min_v = abs(x - i)
    print(min_f)

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

typedef long long int ll;
typedef long long unsigned int ull;
typedef long double ld;
typedef vector<int> vr;
typedef pair<int, int> pr;
#define pb push_back
#define ff first
#define ss second
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433
#define endl "\n"
//cout << fixed << setprecision(2);


int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s, t;
    cin >> s >> t;
    int len = s.size();
    int ans = 0;
    for(int i = 0; i < len; i++){
        if(s[i] != t[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3884
N,X = map(int,input().split())

l1 = 'BPPPB'

L = [1]
for i in range(1,51):
    L.append(L[i-1]*2+3)

dp = [-1]*51

def solve(n, x):
    if n == 0:
        return 1
    l_num = L[n]
    temp = 0
    if dp[n-1]==-1:
        temp = solve(n-1, L[n-1])
        dp[n-1] = temp
    else:
        temp = dp[n-1]

    if x == l_num//2+1:
        return temp+1
    elif n < x < l_num//2+1:
        return solve(n-1, x-1)
    elif x > l_num//2+1:
        # if n==3:
        #     print(x-l_num//2)
        return temp+1 +\
                solve(n-1, x-l_num//2-1)
    elif x <= n:
        return 0

print(solve(N,X))


Measured memory_bytes: 38256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

public class Main {
    static int MOD = 1000000007;

    

    public static class Mas {
        int x;
        int y;
        int step;

        Mas(int x, int y, int step) {
            this.x = x;
            this.y = y;
            this.step = step;
        }
    }

    private static final int[] vX = { 1, 0, 0, -1 };
    private static final int[] vY = { 0, 1, -1, 0 };


    public static void main(String[] args) {

        FastScanner fs = new FastScanner();
        int r=fs.nextInt();
        System.out.println(r * 2 * 3.14);
       
    }

}


Measured memory_bytes: 25440
#include<bits/stdc++.h>
#define ull unsigned long long int 
#define pb push_back
#define F first
#define S second
#define ll long long 
#define ld long double 

#define int long long int

const int mod = 1000000007;
const ll inf = 1e18; 
 
int power(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int ncr(int n, int r){ int C[r+1]; memset(C, 0, sizeof(C)); C[0] = 1; for(int i = 1; i <= n; i++) {int t=i;if(r<t)t=r; for (int j = t; j > 0; j--) C[j] = C[j] + C[j-1]; }return C[r];} 
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}

int min(int a , int b){return a < b ? a : b;}
int max(int a , int b){return a > b ? a : b;}

using namespace std;

int dp[3005][3005] = {} , a[3005];

int solve(int l , int r){
	if(l == r)
		dp[l][r] = a[l];
	if(dp[l][r] > 0)
		return dp[l][r];
	
	dp[l][r] = max(a[l] - solve(l+1 , r) , a[r] - solve(l , r-1));
	
	return dp[l][r];
}

signed main(){

	 ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i++)
		cin >> a[i];
	
	
	cout << solve(0 , n-1);
}










Measured memory_bytes: 49952
import java.io.*;
import java.util.*;
import java.awt.Point;
public class Main {
	static Scanner sc;
	static PrintWriter out;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int a = (n/500)*1000;
		int r = n%500;
		int b = (r/5)*5;
		out.println(a+b);
		out.close();
	}
	static final int uncal = -1;
	static final long inf = Long.MIN_VALUE;
	static boolean isPalindrome(String s) {
		int l = s.length();
		char[] sa = s.toCharArray();
		for(int i=0;i<l/2;i++) {
			if(sa[i] != sa[l-i-1])
				return false;
		}
		return true;
	}

	static String reverse(String s) {
		int i = s.length();
		StringBuilder sb = new StringBuilder();
		while(i-->0) {
			sb.append(s.charAt(i));
		}
		return sb.toString();
	}
	static void merge(StringBuilder sb,Stack<Character> stack) {
		while(!stack.isEmpty())
			sb.append(stack.pop());		
	}
	static String max(String s,String s2) {
		if(s2.length() > s.length())
			return s2;
		return s;
	}

	static class Point extends java.awt.Point implements Comparable<Point>{
		public Point(int x,int y) {
			// TODO Auto-generated constructor stub
			super(x,y);
		}
		public String toString() {
			return x+" "+y;
		}
		@Override
		public int compareTo(Point p) {
			// TODO Auto-generated method stub
			if(x == p.x)
				return y - p.y;
			return x - p.x;
		}
		
	}
	static class Scanner{
		private BufferedReader br;
		private StringTokenizer st;
		public Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		public String next() throws IOException{
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException{
			return Long.parseLong(next());
		}
		public double nextDouble() throws IOException{
			return Double.parseDouble(next());
		}
		public int[] inArr(int n) throws Exception{
			int a [] = new int[n];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<n;i++) {
				a[i] = Integer.parseInt(st.nextToken());
			}
			return a;
		}
	}

}

Measured memory_bytes: 22868
MOD=1000000007
K=input()
n=len(K)
D=int(input())

dp=[[[0,0] for j in range(D)] for i in range(10005)]
dp[0][0][1]=1

for i in range(n):
    num = int(K[i])
    for j in range(D):
        for k in range(10):
            dp[i+1][j][0]+=dp[i][(j-k)%D][0]
            dp[i+1][j][0]%=MOD
        dp[i+1][j][1]+= dp[i][(j-num)%D][1]
        for k in range(num):
            dp[i+1][j][0]+=dp[i][(j-k)%D][1]
            dp[i+1][j][0]%=MOD
print((dp[n][0][0]+dp[n][0][1]-1)%MOD)

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

int main()
{
	int n,a,b;cin>>n>>a>>b;
	int k=b-a-1;
	if(k%2==0){
		cout<<"Borys"<<endl;
	}else{
		cout<<"Alice"<<endl;
	}
	return 0;
}


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

int main(){
    for( int x = 1;x < 10;x++ ){
        for( int y = 1;y < 10;y++ ){
            printf( "%dx%d=%d\n",x,y,x*y );
        }
    }
    return 0;
}

Measured memory_bytes: 1096
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int n;
int main(){
  cin >> n;
  string ans = "No";
  REP(i,26){
    REP(j,15){
      if(i*4+j*7==n) ans = "Yes";
    }
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n, k, a: [usize; n]);
    for i in k..n {
        if a[i - k] < a[i] {
            println!("{}", "Yes");
        } else {
            println!("{}", "No");
        }
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 5768
#include <iostream>

using namespace std;

typedef long long ll;

int n;
string s;
int q;
ll z[1222333];

void query(int k) {
	ll d = 0;
	ll m = 0;
	ll c = 0;
	int a = 0;
	for (int i = 0; i < n; i++) {
		while (i-a >= k) {
			if (s[a] == 'D') {
				d--;
				m -= z[i-1]-z[a];
			}
			a++;
		}
		z[i] = (i == 0) ? 0 : z[i-1];
		if (s[i] == 'D') d++;
		if (s[i] == 'M') {
			m += d;
			z[i]++;
		}
		if (s[i] == 'C') c += m;
	}
	cout << c << "\n";
}

int main() {
	cin >> n;
	cin >> s;
	cin >> q;
	while (q--) {
		int k;
		cin >> k;
		query(k);
	}
}

Measured memory_bytes: 9476
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;


  double s=0;
  for(ll i=0;i<n;i++){
    double x;
    string t;
    cin >> x >> t;
    if(t=="JPY")s+=x;
    else s+=x*380000;
  }
  cout << s << endl;


}

Measured memory_bytes: 3772
var
	N,K,i,L,R,Lsum,Rsum,now,ans,tmp,lim:Longint;
	V:array[1..50]of Longint;
	Lsorted:array[1..50]of Longint;
	LRsorted:array[1..50]of Longint;
begin
	read(N,K);
	for i:=1 to N do read(V[i]);
	for L:=0 to N do begin
		for i:=1 to N do LRsorted[i]:=0;
		if L>0 then begin
			Lsorted[L]:=V[L];
			inc(Lsum,V[L]);
			for i:=L-1 downto 1 do begin
				if Lsorted[i]>Lsorted[i+1]then begin
					tmp:=Lsorted[i];
					Lsorted[i]:=Lsorted[i+1];
					Lsorted[i+1]:=tmp;
				end else break;
			end;
		end;
		for i:=1 to L do LRsorted[i]:=Lsorted[i];
		Rsum:=Lsum;
		for R:=N+1 downto L+1 do begin
			lim:=K-L-(N-R+1);
			if lim<0 then break;
			if R<=N then begin
				LRsorted[L+(N-R)+1]:=V[R];
				inc(Rsum,V[R]);
				for i:=L+(N-R)downto 1 do begin
					if LRsorted[i]>LRsorted[i+1]then begin
						tmp:=LRsorted[i];
						LRsorted[i]:=LRsorted[i+1];
						LRsorted[i+1]:=tmp;
					end else break;
				end;
			end;
			now:=Rsum;
			for i:=1 to lim do begin
				if LRsorted[i]<0 then dec(now,LRsorted[i])
				else break;
			end;
			if ans<now then ans:=now;
		end;
	end;
	writeln(ans);
end.

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

int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> v(n);
    rep(i,n){
        cin>>c[i];
        rep(j,m){
            int a;
            cin>>a;
            v[i].push_back(a);
        }
    }
    bool flg=false;
    ll minv=100000*12;
    rep(i,pow(2,n)){
        ll cost=0;
        vector<int> ex(m,0);
        rep(j,n){
            if((i>>j)&1){
                cost+=c[j];
                rep(k,m){
                    ex[k]+=v[j][k];
                }
            }
        }
        int cnt=0;
        rep(l,m){
            if(ex[l]>=x)cnt++;
        }
        if(cnt==m){
            minv=min(minv,cost);
            flg=true;
        }

    }
    if(flg){
        cout<<minv<<endl;
    }else{
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 4112
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    while x%y != 0:
        z = x%y
        x = y
        y = z
    else:
        return y
def lcm(m,n):
    return int(m * n /gcd(m,n))

A,B = map( int ,input().split())
print(lcm(A,B))

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

int main(){
    using namespace std;
    size_t N;
    cin >> N;
    deque<pair<size_t, size_t>> bef, aft;
    vector<size_t> ans(N * N), a(N);
    for(size_t i = 0, A; i < N;){
        cin >> A;
        if(i)for(size_t j = 0; j < i; ++j)bef.emplace_back(A, i + 1);
        if(++i != N)for(size_t j = i; j < N; ++j)aft.emplace_back(N * N - A, i);
        ans[A - 1] = i;
    }
    sort(bef.begin(), bef.end());
    sort(aft.begin(), aft.end());
    size_t cnt{0UL};
    auto f = [&bef, &cnt](auto& i){
        ++cnt;
        if(i)return;
        if(bef.empty())return;
        if(bef[0].first < cnt)return;
        i = bef[0].second;
        bef.pop_front();
    };
    for_each(ans.begin(), ans.end(), f);
    if(!bef.empty())return 0 & puts("No");
    cnt = 0;
    swap(bef, aft);
    for_each(ans.rbegin(), ans.rend(), f);
    if(!bef.empty())return 0 & puts("No");
    puts("Yes");
    for(const auto& i : ans)cout << i << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 7168
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const LL INF = (LL)1e18;
const int MAXN = 123456;
LL dp[MAXN + 10];

int main() {
    int N, W;
    scanf("%d %d", &N, &W);
    for (int i = 1; i <= MAXN; i++) dp[i] = INF;
    for (int i = 1; i <= N; i++) {
        int w, v;
        scanf("%d %d", &w, &v);
        for (int j = MAXN; j >= v; j--) {
            dp[j] = min(dp[j], dp[j - v] + w);
        }
    }
    LL ans = 0;
    for (int i = MAXN; i >= 0; i--) {
        if (dp[i] <= W) {
           ans = i;
           break;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1152
a,b,c,x,y = gets.chomp.split(" ").map(&:to_i)
ans = 0
if a+b >= c*2
  ans += c*2*[x,y].min
  if x > y
    if a <= c*2
      ans += a*(x-y)
    else
      ans += c*2*(x-y)
    end
  else
    if b <= c*2
      ans += b*(y-x)
    else
      ans += c*2*(y-x)
    end
  end
else
  if a <= c*2 && b <= c*2
    ans += a*x+b*y
  elsif a > c*2
    ans += x*c*2+b*[y-x,0].max
  elsif b > c*2
    ans += y*c*2+a*[x-y,0].max
  end
end
puts ans

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



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

    int num = s.size()-2;
    ll ans = 0LL;
    ll kk = 0LL;
    rep(i, num) {
        if(s[i] == 'A') {
            kk++;
            if(s.substr(i, 3) == "ABC") {
                ans += kk;
                --kk;
                s[++i + 1] = 'A';
            }
        } else {
            kk = 0LL;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640