akhauriyash/Code-Regression huggingface dataset:
use std::io;

pub fn main(){
    let mut s_str: String = String::new();
    io::stdin().read_line(&mut s_str).expect("!!");
    let s: Vec<char> = s_str.trim().chars().collect();
    let N = s.len();
    let mut dp: Vec<Vec<i64>> = vec![vec![0i64;4];N as usize];

    let abc = ['A', 'B', 'C'];

    for i in (0..N).rev(){
        for j in 0..4 {
            let c = s[i];

            if i == N - 1 {
                match j {
                    3 => {
                        dp[i][j] = if c == '?' {3} else {1};
                    },
                    2 => {
                        dp[i][j] = if c == '?' || c == 'C' {1} else {0};
                    }
                    _ => {
                        dp[i][j] = 0
                    },
                }
            }else{
                match j{
                    3 => {
                        dp[i][j] = if c == '?' {3} else {1} * dp[i+1][j];
                    },
                    _ => {
                        if c == abc[j] {
                            dp[i][j] = dp[i+1][j+1] + dp[i+1][j];
                        }else if c == '?' {
                            dp[i][j] = 3 * dp[i+1][j] + dp[i+1][j+1];
                        }else{
                            dp[i][j] = dp[i+1][j];
                        }
                    }
                }
            }
            dp[i][j] %= 10i64.pow(9) + 7;

        }
    }
    println!("{}", dp[0][0]);


}

Measured memory_bytes: 10492
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	int N;
	cin>>N;
	cout<<N*(N+1)/2<<endl;
	return 0;
}


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

int N;
#define MOD 1000000007

int main(){
    cin >> N;
    long long Ans = 1;
    for(int i=1;i<=N;i++){
        Ans *= i;
        Ans = (Ans+MOD)%MOD;
    }

    cout << Ans << endl;
    return 0;
}

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

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

  int count_reg = 30;  
  for(int i=0; i<n; i++){
    int a;
    int count = 0;
    cin >> a;
    for(int j=0; j<30; j++){
      if(a%2==0){
        count++;
        a = a/2;
      }
      else break;
    }
    count_reg = min(count, count_reg);
    if(count_reg==0) break;
  }
  cout << count_reg;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>

using namespace std;
#define maxn 100000

int main()
{
   int n;
   cin>>n;
   int a[100];
   int b[100];
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
       b[i]=a[i];
   }
   sort(a,a+n);
   int f=0;
   for(int i=0;i<n;i++)
   {
       if(a[i]!=b[i])
        f++;
   }
   if(f==0||f==2)
    cout<<"YES"<<endl;
   else
    cout<<"NO"<<endl;
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

#define INF 1<<30
#define MAX_V 10010

// graph by adjacency list
struct Edge {
  int src, dst, weight;
  Edge(int src, int dst, int weight) :
    src(src), dst(dst), weight(weight) { }
  bool operator < (const Edge &e) const {
    return weight < e.weight;
  }
};

struct Graph {
  int V;
  std::vector<Edge> E;

  Graph(int V) : V(V) { }

  void add_edge(int src, int dst, int weight) {
    E.push_back(Edge(src, dst, weight));
  }
};


struct DisjointSet {
  int parent[MAX_V];
  int rank[MAX_V];

  DisjointSet(int N) {
    for (int i = 0; i < N; i++) {
      parent[i] = i;
      rank[i] = 0;
    }
  }

  int find(int x) {
    if (parent[x] == x) {
      return x;
    } else {
      return parent[x] = find(parent[x]);
    }
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return ;

    if (rank[x] < rank[y]) {
      parent[x] = y;
    } else {
      parent[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }
      
};

struct MinimumSpanningTree {
  Graph g;
  std::vector<Edge> msp;
  int mincost;

  MinimumSpanningTree(const Graph &g) : g(g) { }

  int find_mincost() {
    mincost = 0;
    std::sort(g.E.begin(), g.E.end());

    DisjointSet uf(g.V);

    for (int i = 0, edge_count = g.V - 1; edge_count; i++) {
      assert(i < (int)g.E.size());
      Edge e = g.E[i];
      if (!uf.same(e.src, e.dst)) {
	uf.unite(e.src, e.dst);
	mincost += e.weight;
	edge_count--;
      }
    }
    return mincost;
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int V, E;
  cin >> V >> E;
  Graph g(V);
  REP(i, E) {
    int src, dst, weight;
    cin >> src >> dst >> weight;
    g.add_edge(src, dst, weight);
    g.add_edge(dst, src, weight);
  }

  MinimumSpanningTree mst(g);
  cout << mst.find_mincost() << endl;
  return 0;
}

Measured memory_bytes: 6372
class BIT1():
    """
    Binary Indexed Tree (1-indexed)
    """
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (self.n + 1)
        self.data = [0] * (self.n + 1)

    def build(self, data):
        pass

    def add(self, idx, x):
        # add x to idx-th element
        # idx: 1-indexed
        self.data[idx] += x
        while idx <= self.n:
            self.bit[idx] += x
            idx += (idx & (-idx))

    def sum(self, idx):
        # get sum of [1, idx]
        # idx: 1-indexed
        s = 0
        while idx:
            s += self.bit[idx]
            idx -= (idx & (-idx))
        return s

    def bisect_left(self, w):
        # condition : always all element is not minus
        # return minimum idx where bit.sum(idx) >= w
        if w <= 0:
            return 0
        idx = 0  # self.bit[idx] < w
        k = 1 << ((self.n).bit_length() - 1)
        while k > 0:
            if idx + k <= self.n and self.bit[idx + k] < w:
                w -= self.bit[idx + k]
                idx += k
            k = k >> 1
        return idx + 1

    def bisect_right(self, w):
        # condition : always all element is not minus
        # return minimum idx where bit.sum(idx) > w
        if w < 0:
            return 0
        idx = 0  # self.bit[idx] <= w
        k = 1 << ((self.n).bit_length() - 1)
        while k > 0:
            if idx + k <= self.n and self.bit[idx + k] <= w:
                w -= self.bit[idx + k]
                idx += k
            k = k >> 1
        return idx + 1


n = int(input())
p = [0] + list(map(int, input().split()))

p2idx = [0] * (n + 1)
for i in range(1, n + 1):
    p2idx[p[i]] = i

ans = 0
bit = BIT1(n)
for x in reversed(range(1, n + 1)):
    idx = p2idx[x]
    bit.add(idx, 1)
    idx_rank = bit.sum(idx)
    idx_l2 = bit.bisect_left(idx_rank - 2)
    idx_l1 = bit.bisect_left(idx_rank - 1)
    idx_r1 = bit.bisect_left(idx_rank + 1)
    idx_r2 = bit.bisect_left(idx_rank + 2)

    cnt = 0
    cnt += (idx_l1 - idx_l2) * (idx_r1 - idx)
    cnt += (idx - idx_l1) * (idx_r2 - idx_r1)
    ans += x * cnt
    # print(x, idx, idx_l, idx_r, (idx - idx_l) * (idx_r - idx))

print(ans)


Measured memory_bytes: 58664
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 998244353
typedef long long ll;
using namespace std;

ll dp[303][90090];

int main(){
  int N;
  cin>>N;
  vector<int> a(N+1);
  for(int i=0;i<N;i++) cin>>a[i];

  int sum=0;
  for(int i=0;i<N;i++) sum+=a[i];
  dp[0][0]=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<=sum;j++){
      if(dp[i][j]==0) continue;
      dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+dp[i][j])%MOD;
      dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2%MOD)%MOD;
      dp[i+1][j]%=MOD;
    }
  }

  ll ans=1;
  for(int i=1;i<=N;i++) ans=ans*3%MOD;
  for(int j=0;j<=sum;j++){
    if(j+j>=sum) ans=(ans-3*dp[N][j]%MOD)%MOD;
    ans=(ans+MOD)%MOD;
  }

  ll dps[N+1][sum+1]={};
  dps[0][0]=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<=sum;j++){
      if(dps[i][j]==0) continue;
      dps[i+1][j+a[i]]=(dps[i+1][j+a[i]]+dps[i][j])%MOD;
      dps[i+1][j]=(dps[i+1][j]+dps[i][j])%MOD;
    }
  }

  if(sum%2==0) ans=(ans+dps[N][sum/2]*3%MOD)%MOD;
  ans=(ans+MOD)%MOD;
  cout<<(ans+MOD)%MOD<<endl;

  return 0;
}


Measured memory_bytes: 422144
N=gets.to_i
fs = N.times.map { gets.gsub(' ','').to_i(2) }
ps = N.times.map { gets.split.map(&:to_i)}

p (1...2**10).map { |i|
    fs.map.with_index.sum { |f,j| ps[j][(f&i).to_s(2).count('1')] }
}.max


Measured memory_bytes: 14332
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    long long x;
    cin >> x;
    for (long long a = -1000; a < 1000; a++) {
        for (long long b = -1000; b < 1000; b++) {
            if (a*a*a*a*a - b*b*b*b*b == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3540
import           Control.Monad
import           Data.List
import qualified Data.Map      as M

main :: IO ()
main = do
  [n, m] <- getInts
  ns <- replicateM m $ toTuple <$> getInts
  let d = make $ concat ns
  print $ solve n d


getInts :: IO [Int]
getInts = map read . words <$> getLine

toTuple [n, m] = [(n, m), (m, n)]

make xs = M.fromList $
          map (foldr (\(a, b) (c, d) -> (a, b:d)) (1, [])) $
          groupBy (\a b -> fst a == fst b) $ sort xs

solve n d = go 1 []
  where
    go i xs
      | length xs == (n - 1) = 1
      | otherwise = let ns = filter (not . (`elem` xs)) $ d M.! i
                    in sum $ map (\n -> go n (i:xs)) ns



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

int main(){
  int n, x;
  cin >> n >> x;
  vector<int> v(n);
  int max = 0;
  rep(i, n){
    cin >> v[i];
    max += v[i];
  }

  sort(v.begin(), v.end());
  int ans = 0;
  int sum = 0;
  rep(i, n){
    if ((sum + v[i]) > x) break;
    ans = i + 1;
    sum += v[i];
  }

  if (n == ans && sum != x){
    ans -= 1;
  }

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

Measured memory_bytes: 3628
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

/* MACROS */ 
typedef unsigned long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */ 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

// #define cerr if(false)cerr
/* CODE STARTS HERE */

void solve(){
    string s; cin >> s;
    int k,n=s.size(); cin >> k;
    
	set<string>st;
    string temp;
	     
    rep(i,0,n){
    	temp = "";
    	rep(j,i,n){
    		if(abs(j-i)>k) break;
    		temp += s[j];
			st.insert(temp);
    	}
    }

	cout << *(next(st.begin() , k-1));
}

int main(){
    IOS;
    solve();
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a, b;
  cin >> a >> b;
  string s = a + b;
  int n = stoi(s);
  for(int i = 0; i < n; i++) {
    if(i * i == n) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

    char s[4] ;
    char t[4] ;

    int i, k=0;

    scanf("%s %s", s, t);
    for(i=0; i<3; i++){
       k += (s[i] == t[i]);
    }
    printf("%d\n", k);
    return 0;
}

Measured memory_bytes: 128
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 3e5 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	vector<int> v(1 << n);
	for (auto& x : v) cin >> x;
	sort(v.rbegin(), v.rend());
	deque<int> q;
	vector<int> cur;
	cur.push_back(v.front());
	for (int i = 1; i < v.size(); i++) q.push_back(v[i]);
	for (int i = 1; i <= n; i++)
	{
		sort(cur.rbegin(), cur.rend());
		stack<int> s;
		for (int j = 0; j < (1 << (i - 1)); j++)
		{
			while (!q.empty())
			{
				int x = q.front();
				q.pop_front();
				if (x < cur[j])
				{
					cur.push_back(x);
					break;
				}
				else
				{
					s.push(x);
				}
			}
		}
		if (cur.size() != (1 << i)) puts("No"), exit(0);
		while (!s.empty())
		{
			q.push_front(s.top());
			s.pop();
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int N;
int main() {
    while (cin >> N) {
        cout << (N+1)/2 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

// 10進数のKをN進数に変換
vector<int>  base10_to_baseN(ll K, int N){
    int n = 0;
    while(K >= (ll)pow(N,n)) n++;
    vector<int> ans;
    REP(i, n){
        ans.pb((K-1)%N);
        K /= N;
        if(ans.back()==(N-1)) K--;
        if(K==0) break;
    }
    return ans;
}

int main(void)
{
    ll N;
    cin >> N;
    string ans;
    auto a = base10_to_baseN(N, 26);

    reverse(ALL(a));
    for(auto&& ai : a){
        printf("%c", 'a'+ai);
    }
    printf("\n");
}

Measured memory_bytes: 4072
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

i64 X; cin >> X;


cout << X / 500 * 1000 + X % 500 / 5 * 5 << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

string s;
llint ans[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	llint n = s.size();
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'R' && s[i+1] == 'L'){
			for(int j = i; j >= 0; j--){
				if(s[j] == 'L') break;
				if((j+i)%2 == 0) ans[i]++;
				else ans[i+1]++;
			}
			for(int j = i+1; j < n; j++){
				if(s[j] == 'R') break;
				if((j+i)%2 == 0) ans[i]++;
				else ans[i+1]++;
			}
		}
	}
	for(int i = 0; i < n; i++) cout << ans[i] << " ";  cout << endl;
	
	return 0;
}

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

int main(){
  int a,b,x;
  cin >>a >>b >>x;
  if(a<=x && a+b>=x) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n,x;
  std::cin >> n >> x;
  vt<int> a(n);
  rep(i,n)
    std::cin >> a[i];

  sort(a.begin(),a.end());
  int cnt = 0;
  rep(i,n){
    if(x >= a[i] && i != n-1){
      x -= a[i];
      cnt++;
    }
    else if(i == n-1 && x == a[i])
      cnt++;
    else
      break;
  }

  std::cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
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 ans = 0;
        ans += (n * (n - 1)) / 2;
        ans += (m * (m - 1)) / 2;
        System.out.println(ans);
    }
}


Measured memory_bytes: 22996
import java.util.*;
import java.io.*;
public class Main {
	static ArrayList<ArrayList<Integer>> perms = new ArrayList<ArrayList<Integer>>();
	static int n;
	static int m;
	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		StringTokenizer st = new StringTokenizer(bf.readLine());
 		n = Integer.parseInt(st.nextToken());
 		m = Integer.parseInt(st.nextToken());
 		int q = Integer.parseInt(st.nextToken());
 		int[][] quadruples = new int[q][4];
 		for(int i = 0;i<q;i++){
 			StringTokenizer st1 = new StringTokenizer(bf.readLine());
 			int a = Integer.parseInt(st1.nextToken());
 			int b = Integer.parseInt(st1.nextToken());
 			int c = Integer.parseInt(st1.nextToken());
 			int d = Integer.parseInt(st1.nextToken());
 			quadruples[i][0] = a;
 			quadruples[i][1] = b;
 			quadruples[i][2] = c;
 			quadruples[i][3] = d;
 				
 		}
 		for(int i =1;i<=m;i++){
 			ArrayList<Integer> te = new ArrayList<Integer>();
 			te.add(i);
 			recur(te);
 		}
 		int max = 0;
 		for(ArrayList<Integer> i : perms){
 			int count = 0;
 			for(int j = 0;j<q;j++){
 				if (i.get(quadruples[j][1]-1) - i.get(quadruples[j][0]-1) == quadruples[j][2])
 					count+=quadruples[j][3];
 			}
 			max = Math.max(count, max);
 		}
 		out.println(max);
 		out.close();
 		
 	}
	public static void recur(ArrayList<Integer> temp){
		if(temp.size() == n){
			perms.add((ArrayList<Integer>)temp.clone());
		}
		else{
			for(int i = temp.get(temp.size()-1);i<=m;i++){
				temp.add(i);
				recur(temp);
				temp.remove(temp.size()-1);
			}
		}
	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




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

int main()
{
    ll n, res = 0, x;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> x;
        while(x % 2 == 0)
        {
            x /= 2;
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
L = [LIST() for i in range(M)]
P = LIST()

import itertools
#L = [0, 1] #生成する数字
num = N #生成するビット数
bit_list = list(itertools.product([0, 1], repeat=num))
#print(bit_list)
ans = 0
#print(L[0][0])
on = 0
for bit in bit_list:
    # ココ注意
    cnt = 0
    for i in range(M):
        #print(L[i][1:])
        wa = 0
        on = 0
        for s in L[i][1:]:
            on ^= bit[s-1]
        # wa == P[i]なら，その電球は点灯する
        if P[i] == on:
            cnt += 1
        #if cnt == L[i][0]:
        #    c += 1
    if cnt == M:
        ans += 1
print(ans)


Measured memory_bytes: 5204
import collections
a = collections.deque(input())
b = collections.deque(input())
c = collections.deque(input())
s = a.popleft()
while True:
    if s == "a":
        if len(a) != 0:
            s = a.popleft()
        else:
            print("A")
            exit()
    elif s == "b":
        if len(b) != 0:
            s = b.popleft()
        else:
            print("B")
            exit()
    elif s == "c":
        if len(c) != 0:
            s = c.popleft()
        else:
            print("C")
            exit()


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

int main(){
    int A, B;
    cin >> A >> B;

    if(A > B){
        cout << (2*A-1) << endl;
    }else if(A == B){
        cout << (2*A) << endl;
    }else{
        cout << (2*B-1) << endl;
    }
}

Measured memory_bytes: 256
from collections import deque
S = deque(input())
Q = int(input())
cnt = 1
num = 0
for i in range(Q):
    TFC = input()
    if TFC == "1":
        cnt *= -1
        num += 1
    else:
        if TFC[:3]== "2 1":
            if cnt ==1:
                S.appendleft(TFC[4])
            else:
                S.append(TFC[4])
        else:
            if cnt ==1:
                S.append(TFC[4])
            else:
                S.appendleft(TFC[4])
if num % 2 ==1:
    print(("".join(reversed([i for i in S]))))
else:
    print(("".join([i for i in S])))

Measured memory_bytes: 90584
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<numeric>
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//æ˜‡é †

using namespace std;

const int mod=1e9+7;

signed dis(int x1,int y1, int x2, int y2){
    return abs(x1 - x2) + abs(y1 - y2);
}

signed main(){
    SPEED;
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = min(b,d)-max(a,c);
    if(ans<0)ans=0;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(auto i = 0; i <N; i++)
using namespace std;
typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}


int look_site(int i, int j, int H, int W){
    
    if (i < 0) return 0;
    if (j <0) return 0;
    if (i>=H)return 0;
    if (j >= W) return 0;
    
    return 1;
    
}


int main() {
    
    int N = in();
    

    int n9 = 0;
    int n6 = 0;
    
    vector<int> money;
    
    while(pow(9,n9) <= N){
        
        money.push_back((int)pow(9,n9));
        n9++;
    }
    
    while(pow(6,n6) <= N){
        money.push_back((int)pow(6,n6));
        n6++;
    }
    
    sort(money.begin(),money.end());
    
    money.erase(unique(money.begin(),money.end()),money.end());

    int dp[N+1];
    
    for(auto i = 0; i<=N; i++){
        dp[i] = 0;
    }
    
    dp[0]  = 0;

    for(auto i = 1; i<=N; i++){
        
        auto temp = INT_MAX;
        
        for(auto k : money){
            
            if(k > i) break;
            
            if (temp > dp[i-k]) temp = dp[i-k] + 1;
            
        }
        
        dp[i] = temp;
    }
    
    cout << dp[N] << endl;
    
    return 0;
}










Measured memory_bytes: 768
a = [chr(i) for i in range(65, 65+26)]
n = int(input())
s = input()
s_new = []

for i in range(len(s)):
    t = ord(s[i])
    t1 = t + n
    if t1 > 90:
        t1 = t1 - 26
    s_new.append(chr(t1))
print(*s_new,sep='')
    

Measured memory_bytes: 4724
#include <iostream>
using namespace std;
 
int main() {
  int a, b, c;
 
  cin >> a;
  cin >> b;
  cin >> c;
 
  if(a < b && a < c) {

    if(b < c) {
      cout << a << " " << b << " " << c << endl;
    } else {
      cout << a << " " << c << " " << b << endl;
    }

  } else if(b < a && b < c) {

    if(c < a) {
      cout << b << " " << c << " " << a << endl;
    } else {
      cout << b << " " << a << " " << c << endl;
    }

  } else {

    if(a < b) {
      cout << c << " " << a << " " << b << endl;
    } else {
      cout << c << " " << b << " " << a << endl;
    }

  }
 
  return 0;
}

Measured memory_bytes: 3088
#include<stdio.h>
#include<algorithm>
#define MAXN 100005
using namespace std;
template <typename T> inline void read(T &x)
{
	x=0;int f=1;char c=getchar();
	for(;c>'9'||c<'0';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x*=f;
}
template <typename T> inline void print(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) print(x/10);
	putchar(x%10+48);
}
const int mod=1e9+7;
int t[MAXN],a[MAXN],n;
int mul(int x,int y) 
{
    return 1LL*x*y%mod;
}
int main() 
{
    read(n);
    for(int i=1;i<=n;++i) read(t[i]);
    for(int i=1;i<=n;++i) read(a[i]);
    int ans=1;
    for(int i=1;i<=n;++i) 
	{
	    if(t[i]!=t[i-1]||a[i]!=a[i + 1]) 
		{
	        int x=-1,y=-1;
	        if(t[i]!=t[i-1]) x=t[i];
	        if(a[i]!=a[i+1]) y=a[i];
	        if(x!=-1&&y!=-1) 
		        if(x!=y) 
		        {
		        	printf("0");
					return 0;
				}		
	        if(y>t[i]) 
			{
				printf("0");
				return 0;
			}
	        if(x>a[i]) 
			{
				printf("0");;
				return 0;
			}
	    }
	    else 
	        ans=mul(ans,min(a[i],t[i]));
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 896
X=int(input())
S=[1 for i in range(10**6+1)]
S[1]=0
for i in range(2,10**6):
    if S[i]==1:
        for j in range(2,10**6):
            if i*j<=10**6:
                S[i*j]=0
            else:
                break
for i in range(X,10**6):
    if S[i]==1:
        print(i)
        exit()

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

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

LL a[2000];

LL dp[2001][2001];
LL maxdp[2001];

int main(){
  int n;
  LL z,w;
  LL ret,ret_pre;
  cin>>n>>z>>w;
  REP(i,n){
    cin>>a[i];
  }
  REP(i,n){
    if(i==0)
      dp[n-1][n]=abs(a[n-1]-w);
    else{
      REP(j,i){
	if(j==0)
	  dp[n-i-1][n-1]=abs(a[n-i-1]-a[n-1]);
	else
	  dp[n-i-1][n-j-1]=max(abs(a[n-1]-a[n-j-1]),maxdp[n-j]);
      }
    }
    
    maxdp[n-i-1]=10000000000;
    if(i==0)
      maxdp[n-1]=dp[n-1][n];
    else{
      REP(k,i){
	maxdp[n-i-1]=min(maxdp[n-i-1],dp[n-i-1][n-i+k]);
      }
    }
    //cout<<maxdp[n-i-1]<<endl;
  }
  ret=0;
  REP(i,n){
    ret=max(ret,maxdp[i]);
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 31104
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

using ll = long long;

#define MOD 1000000007

#define FOR(i, m, n) for (ll i = m; i <= n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)

ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
    ll H, W;
    cin >> H >> W;
    cout << (H == 1 || W == 1 ? 1 : (H * W + 1) / 2) << endl;
    return 0;
}


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

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 12
char _buf[INTSPACE*3 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}
int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

ll solve(int N, int C, vvi& stc) {
    priority_queue<ii> pq; // (endtime, channel)

    int Nc = 0;

    sort(ALL(stc));
    rep(i, N){
        int si = stc[i][0]*2, ti = stc[i][1]*2, ci = stc[i][2];
        if (pq.empty()) {
            ++Nc;
            pq.push(ii(-ti, ci));
            continue;
        }
        else {
            if (-pq.top().first <= si-1) {
                // just use it
                pq.pop();
                pq.push(ii(-ti, ci));
                continue;
            }

            bool done = false;
            vector<ii> tmp;
            while (!pq.empty() && -pq.top().first == si) {
                if (pq.top().second == ci) {
                    // just use it
                    pq.pop();
                    done = true;
                    break;
                }
                tmp.pb(pq.top());
                pq.pop();
            }
            for (ii item : tmp) pq.push(item);

            if (!done) {
                ++Nc;
            }
            pq.push(ii(-ti, ci));
        }
    }
    return Nc;
}

int main() {
    vi tmp(3); loadvec(tmp, 2);
    int N = tmp[0], C = tmp[1];

    vvi stc(N, vi(3));
    rep(i, N) {
        loadvec(stc[i], 3);
    }

    cout << solve(N, C, stc) << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <cstring>
#include <cstdio>
#define MOD 1000000007
typedef long long ll;
inline ll quick_pow(ll a, int n)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}
ll dp[25005][405], pre[25005][405];
int arr[25005];
bool vis[405];
int main()
{
	// freopen("ARC100-F.in", "r", stdin); 
	int n, k, m;
	scanf("%d%d%d", &n, &k, &m);
	for (int i = 0; i < m; i++)
		scanf("%d", arr + i);
	bool flg = false;
	for (int i = 0; i + k <= m && !flg; i++)
	{
		memset(vis, false, sizeof(vis));
		int cnt = 0;
		for (int j = 0; j < k; j++)
		{
			cnt += !vis[arr[i + j]];
			vis[arr[i + j]] = true;
		}
		flg |= cnt == k;
	}
	ll ans = quick_pow(k, n - m) * (n - m + 1) % MOD;
	if (flg)
	{
		printf("%lld\n", ans);
		return 0;
	}
	memset(vis, false, sizeof(vis));
	int lp = -1, rp = -1;
	for (int i = 0; i < m && -1 == lp; i++)
	{
		if (!vis[arr[i]])
			vis[arr[i]] = true;
		else
			lp = i;
	}
	memset(vis, false, sizeof(vis));
	for (int i = m - 1; i >= 0 && -1 == rp; i--)
	{
		if (!vis[arr[i]])
			vis[arr[i]] = true;
		else
			rp = i;
	}
	for (int i = 1; i < k; i++)
	{
		dp[0][i] = 1;
		pre[0][i] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j < k; j++)
		{
			dp[i][j] = (dp[i - 1][j + 1] * (k - j) + pre[i - 1][j]) % MOD;
			pre[i][j] = (pre[i][j - 1] + dp[i][j]) % MOD;
		}
	}
	for (int i = 0; i + m <= n; i++)
	{
		if (~lp)
			(ans -= dp[i][lp] * dp[n - i - m][m - rp - 1]) %= MOD;
		else
		{
			ll coef = 1;
			for (int j = m; j < k && i + j < n; j++)
			{
				(ans -= dp[i][j] * pre[n - (i + j) - 1][j] % MOD * coef) %= MOD;
				coef = coef * (k - j) % MOD;
			}
			if (n - i < k)
				(ans -= dp[i][n - i] * coef) %= MOD;
		}
	}
	printf("%lld\n", (ans + MOD) % MOD);
	return 0;
}


Measured memory_bytes: 158464
#include <iostream>
#include <bitset>
#include <cstdio>
using namespace std;

bitset<10000> cookie[10];
int r, c;

int main() {
	//freopen("0525-input.txt", "r", stdin);
	while (cin >> r >> c && r > 0) {
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				bool upwards; cin >> upwards;
				cookie[i][j] = upwards;
			}
		}
		int permute_r = 1 << r;
		int result = 0;
		do {
			for (int i = 0; i < r; i++) {
				if (permute_r & (1 << i)) cookie[i].flip();
			}
			int possible_answer = 0;
			for (int j = 0; j < c; j++) {
				int up_cookie_count = 0;
				for (int i = 0; i < r; i++) {
					if (cookie[i][j]) up_cookie_count++;
				}
				up_cookie_count = max(up_cookie_count, r - up_cookie_count);
				possible_answer += up_cookie_count;
			}
			result = max(result, possible_answer);
			for (int i = 0; i < r; i++) {
				if (permute_r & (1 << i)) cookie[i].flip();
			}
		} while (--permute_r);
		cout << result << endl;
	}
}

Measured memory_bytes: 2984
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[55];
int main() {
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	long long ans=0;
	while (true) {
		sort(a+1,a+1+n);
		if (a[n]<n) break;
		long long x=a[n]/n;
		ans+=x;
		for(int i=1;i<n;i++) a[i]+=x;
		a[n]%=n;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define REP(x,b) for(int x=0;x<b;x++)
#define FORSIZE(x,A) for(int x=0;x<A.size();x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define SORT(x) sort(x.begin(),x.end())
#define RSORT(x) sort(x.rbegin(),x.rend())
#define rsort(x,n) sort(x, x+n, greater<int>())
#define REV(x) reverse(x.begin(),x.end())
using namespace std;
typedef long long ll;
inline int toInt(std::string s) {int v; std::istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {std::ostringstream sout;sout<<x;return sout.str();}

int main( int argc, const char* argv[] )
{
    FOR(i, 1, 10) {
        FOR(j, 1, 10) {
            cout << i << "x" << j << "=" << i * j << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1116
n = int(input())

cards = {

}

for s in range(n):
    word = input()
    if word not in cards:
        cards[word] = 1
    else:
        cards[word] += 1

m = int(input())

for r in range(m):
    word = input()
    if word not in cards:
        cards[word] = -1
    else:
        cards[word] -= 1

print(max(max(cards.values()), 0))


Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val q = sc.nextLong()
    val h = sc.nextLong()
    var s = sc.nextLong()
    val d = sc.nextLong()
    val n = sc.nextLong()

    s = arrayOf(4 * q, 2 * h, s).min()!!
    println(Math.min(2 * s, d) * (n / 2) + s * (n % 2))
}


Measured memory_bytes: 35912
module Main where

import           Control.Monad
import           Data.List
import           Data.Ord
import           Data.List.Split
import           Data.Array.IO
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine :: IO [Int]
  s <- getLine :: IO String
  let sums = (V.fromList . scanl (+) 0 . count . group) s
  print . maximum $ f sums k
  where
    count cs =
      let xs = if (head . head) cs == '0' then []:cs    else cs
          ys = if (even . length) xs then xs ++ [] else xs
      in  map length ys
    f sums k =
      let ls = V.length sums
          a  = 2 * k + 1
      in  [(sums V.! min (i + a) (ls - 1)) - (sums V.! i) | i <- [0,2..(ls - 1)]]


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

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

Measured memory_bytes: 9200
import java.util.*;
 
class Main {
    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in);
    	DiceCtrl dc = new DiceCtrl();

    	for(int i = 0; i < 6; i++) {
    		dc.numList[i] = sc.nextInt();
    	}
    	
    	for(int i = 0; i < 6; i++) {
    		dc.numList2[i] = sc.nextInt();
    	}
    	dc.diceCheck();
    }
}

class DiceCtrl {
	public int[] numList = new int[6];
	public int[] numList2 = new int[6];
	private int tmp = 0;
	
	void ctrlE() {
		tmp = numList[0];
		numList[0] = numList[3];
		numList[3] = numList[5];
		numList[5] = numList[2];
		numList[2] = tmp;
	}
	void ctrlN() {
		tmp = numList[0];
		numList[0] = numList[1];
		numList[1] = numList[5];
		numList[5] = numList[4];
		numList[4] = tmp;
	}
	void ctrlS() {
		tmp = numList[0];
		numList[0] = numList[4];
		numList[4] = numList[5];
		numList[5] = numList[1];
		numList[1] = tmp;
	}
	void ctrlW() {
		tmp = numList[0];
		numList[0] = numList[2];
		numList[2] = numList[5];
		numList[5] = numList[3];
		numList[3] = tmp;
	}
	void ctrlR() {
		tmp = numList[1];
		numList[1] = numList[2];
		numList[2] = numList[4];
		numList[4] = numList[3];
		numList[3] = tmp;
	}
	void diceCheck() {
		for(int i = 0; i < 4; i++) {
			if(boolCheck()) {
				break;
			}
			ctrlN();
			for(int j = 0; j < 4; j++) {
				if(boolCheck()) {
					break;
				}
				ctrlR();
			}
		}
		for(int i = 0; i < 4; i++) {
			if(boolCheck()) {
				break;
			}
			ctrlW();
			for(int j = 0; j < 4; j++) {
				if(boolCheck()) {
					break;
				}
				ctrlR();
			}
		}
		if(Arrays.equals(numList, numList2)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
	boolean boolCheck() {
		if(numList[0] == numList2[0] &&
		   numList[1] == numList2[1] &&
		   numList[2] == numList2[2] &&
		   numList[3] == numList2[3] &&
		   numList[4] == numList2[4] &&
		   numList[5] == numList2[5]) {
			return true;
		} else {
			return false;
		}
	}
}

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

int main()
{
    string arr,frr;
    cin>>arr>>frr;
    string s=arr;

    while(1)
    {

        string f;
        for(int i=1;i<s.size();i++)
        {
            f+=s[i];
        }
        f+=s[0];

         if(f==frr)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        if(f==arr)break;
        s=f;
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
def main():
    a, b, c, operation = map(int, input().split())
    answer = a - b
    if abs(answer) > 10 ** 18:
        print("Unfair")
    else:
        if operation % 2:
            print(answer * -1)
        else:
            print(answer)


if __name__ == '__main__':
    main()




Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
using namespace std;

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main(){
    int x; cin >> x;
    cout << (x^1) << endl;
}


Measured memory_bytes: 3608
g = {}
n=int(input())
m = [-1]*n
import sys
sys.setrecursionlimit(1000000000)
def dfs(graph,node,height):
    global m
    global zeros
    global ones
    m[node-1]=height
    if height==0:
      zeros+=1
    if height==1:
      ones+=1
    for n in graph[node]:
      if m[n-1]==-1:
        dfs(graph,n,1-height)

zeros=0
ones=0
for i in range(n-1):
  a,b=map(int,input().split())
  if not a in g:
    g[a]=[b]
  else:
    g[a].append(b)
  if not b in g:
    g[b]=[a]
  else:
    g[b].append(a)
dfs(g,1,0)
ans=[0]*n
used=[0]*n
r=n//3
if 3*(r+1)<=n:
  r+=1
if zeros<=r:
  current=3
  for i in range(n):
    if m[i]==0:
      ans[i]=current
      used[current-1]=1
      current+=3
  counter=0
  for i in range(n):
    if m[i]==1:
      while True:
        if used[counter]==0:
          ans[i]=counter+1
          counter+=1
          break
        counter+=1
elif ones<=r:
  current=3
  for i in range(n):
    if m[i]==1:
      ans[i]=current
      used[current-1]=1
      current+=3
  counter=0
  for i in range(n):
    if m[i]==0:
      while True:
        if used[counter]==0:
          ans[i]=counter+1
          counter+=1
          break
        counter+=1
else:
  if zeros<ones:
    current=1
    for i in range(n):
      if m[i]==0:
        ans[i]=current
        used[current-1]=1
        current+=3
        if current>n:
          current=3
    counter=0
    for i in range(n):
      if m[i]==1:
        while True:
          if used[counter]==0:
            ans[i]=counter+1
            counter+=1
            break
          counter+=1
  else:
    current=1
    for i in range(n):
      if m[i]==1:
        ans[i]=current
        used[current-1]=1
        current+=3
        if current>n:
          current=3
      counter=0
    for i in range(n):
      if m[i]==0:
        while True:
          if used[counter]==0:
            ans[i]=counter+1
            counter+=1
            break
          counter+=1
for i in ans:
  print(i)

Measured memory_bytes: 202712
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
int ans,v, n;
int tt[500];
int vis[200];
void dfs(int s) {
    if(s >= n) {
        ans = min(ans, s);
        return;
    }
    for(int i = 0; i < 10; i++) {
        if(!vis[i]) {
            dfs(s * 10 + i);
        }
    }
}
int main() {
    string s;
    int k, a;
    while(cin >> n >> k) {
        memset(vis, 0, sizeof vis);
        for(int i = 0; i < k; i++)
            scanf("%d", &a), vis[a] = 1;
        ans = 1e9;
        for(int i = 9; i >= 0; i--) {
            if(!vis[i] && i) dfs(i);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int Ans=0;
  for(int i=1;i<=5;i++)
  {
    int X;
    cin>>X;
    if(!X)
      Ans=i;
  }
  cout<<Ans<<endl;
  return 0;
}

Measured memory_bytes: 3636