akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  ll n;
  cin >> n;
  vector<ll> march(5);
  rep(i, 0, n) {
    string s;
    cin >> s;
    if(s[0] == 'M') march[0]++;
    if(s[0] == 'A') march[1]++;
    if(s[0] == 'R') march[2]++;
    if(s[0] == 'C') march[3]++;
    if(s[0] == 'H') march[4]++;
  }
  
  ll cnt = count(all(march), 0);
  
  if(cnt >= 3) {
    cout << 0 << "\n";
    return 0;
  }
  sort(all(march));
  ll ans = 0;
  if(cnt == 2) ans += march[2]*march[3]*march[4];
  else if(cnt == 1) {
    rep(i, 1, 5) {// 選ばないやつ
      ll c = 1;
      rep(j, 1, 5) {
        if(i != j) c *= march[j];
      }
      ans += c;
    }
  }
  else {
    rep(i, 0, 5) {
      rep(j, 0, 5) {// 選ばないやつら
        ll c = (i==j ?0 :1);
        rep(k, 0, 5){
          if(i != k and j != k) c *= march[k];
        }
        ans += c;
      }
    }
    ans /= 2;
  }
  
  cout << ans << "\n";
}

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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll gcd(ll x,ll y){
return y? gcd(y,x%y):x;
}

int main(){
  long double l;
  cin>>l;
  l/=3;
  l=l*l*l;
  cout<<fixed;
  cout<<setprecision(10)<<l<<endl;
return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut t = vec![0i32];
    let mut x = vec![0i32];
    let mut y = vec![0i32];
    for _ in 0..n {
        t.push(read());
        x.push(read());
        y.push(read());
    }

    for i in 0..n {
        let x = (x[i] - x[i + 1]).abs();
        let y = (y[i] - y[i + 1]).abs();
        let t = t[i + 1] - t[i];
        if t < x + y || (x + y) % 2 != t % 2 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;

    int ans = 0;
    For(b, k + 1, n) {
        int div = n / b;
        int rem = n % b;
        ans += (b - k) * div + max(rem - k + 1, 0LL);
        if (k == 0) ans--;
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int i,max=0,n,v[20],c[20];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&v[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&c[i]);
	}
	for(i=0;i<n;i++){
		if(v[i]-c[i] > 0) max = max + v[i] - c[i];
	}
	printf("%d\n",max);
	return 0;
}
	

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

using namespace std;

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

  int N,M; cin>>N>>M;
  vector<int> path[N];
  for (int i = 0; i < M; i++) {
    int s,t; cin>>s>>t;
    s--; t--;
    path[s].push_back(t);
  }
  double ans = numeric_limits<double>::max();
  for (int k = 0; k < N-1; k++) {
    double dp[N];
    dp[N-1] = 0;
    for (int i = N-2; i >= 0; i--) {
      double sume = 0;
      int num = path[i].size();
      double maxe = 0;
      for (auto to : path[i]) {
        sume += dp[to];
        maxe = max(maxe, dp[to]);
      }
      if (i == k and num > 1) {
        sume -= maxe;
        num--;
      }
      dp[i] = sume/num + 1;
    }
    ans = min(ans, dp[0]);
  }
  cout << fixed << setprecision(7) << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author naruse
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        XorSum4 solver = new XorSum4();
        solver.solve(1, in, out);
        out.close();
    }

    static class XorSum4 {
        final long mod = (long) 1e9 + 7L;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long a[] = new long[n];
            for (int i = 0; i < n; i++) a[i] = in.nextLong();
            int cnt[][] = new int[n][61];
            for (int i = 0; i < n; i++) {
                for (int j = 0; (a[i] >> j) > 0; j++) {
                    long now = a[i] >> j;
                    if (now % 2L == 1L) cnt[i][j] = 1;
                }
            }
            for (int i = 1; i < n; i++) {
                for (int j = 0; j < 61; j++) {
                    cnt[i][j] = cnt[i][j] + cnt[i - 1][j];
                }
            }
            long sum[][] = new long[n + 1][61];
            for (int i = 0; i <= n; i++) {
                sum[i][0] = i;
                for (int j = 1; j < 61; j++) {
                    sum[i][j] = sum[i][j - 1] << 1;
                    sum[i][j] %= mod;
                }
            }
            long ans = 0L;
            for (int i = 0; i < n - 1; i++) {
                for (int j = 0; j < 61; j++) {
                    long now = a[i] >> j;
                    int CntTrue = cnt[n - 1][j] - cnt[i][j];
                    int nowsum = 0;
                    if (now % 2L == 1L) {
                        nowsum = n - 1 - i - CntTrue;
                    } else {
                        nowsum = CntTrue;
                    }
//                for (int k = 0; k < j; k++) {
//                    sum = (sum % mod) << 1;
//                    sum %= mod;
//                }
                    ans = (ans % mod) + sum[nowsum][j];
                    ans %= mod;
                }
            }
            out.println(ans);
        }

    }
}



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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  cout << a[0] + a[1] <<endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll N; cin>>N;
    ll A,B; cin>>A>>B;
    ll mid=B-(A+1);
    if(mid%2!=0){
        cout<<mid/2+1<<endl;
        return 0;
    }
    else if(mid==0){
        cout<<min(B-1,N-A)<<endl;
        return 0;
    }
    ll ans=min(A-1+1+(mid-1)/2+1,N-B+1+(mid-1)/2+1);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define TR(it, c) for(typeof(c.begin()) it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }
const int INF=0x3F3F3F3F;

int gcd(int a, int b) {
  while (a) swap(b %= a, a);
  return b;
}

int main(int argc, char *argv[]) {
  int a, b;
  while (scanf("%d %d", &a, &b) == 2) {
    int g = gcd(a, b);
    printf("%d %d\n", g, a / g * b);
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <deque>

#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228                                                         
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define x first
#define y second

using namespace std;

const string FILENAME = "input";

int main(int argc, char const *argv[])
{
	int a, b, c; cin >> a >> b >> c;
	int six[6];
	six[0] = abs(b - a) + abs(c - b);
	six[1] = abs(c - a) + abs(b - c);
	six[2] = abs(a - b) + abs(c - a);
	six[3] = abs(c - b) + abs(a - c);
	six[4] = abs(a - c) + abs(b - a);
	six[5] = abs(b - c) + abs(a - b); 
	cout << *min_element(six, six + 6) << endl;
	return 0;
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            var a = int.Parse(s[0]);
            var b = int.Parse(s[1]);
            var c = int.Parse(s[2]);
            Console.WriteLine(Math.Max(0, c - (a - b)));






#if DEBUG
            Console.ReadKey();
#endif
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

int main(void)
{
	int a,b,H,W;

	while(1)
	{
		scanf("%d %d",&H,&W);
		if((H==0)&&(W==0))
		{
			break;
		}
		else
		{
			for(a=1;a<=H;a++)
			{
				for(b=1;b<=W;b++)
				{
					if((a!=1)&&(a!=H)&&(b!=1)&&(b!=W))
					{
						printf(".");
					}
					else
					{
					printf("#");
					}
				}
				printf("\n");
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
 
#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)
 
typedef long long ll;
#define INF 1e9


int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int mini;
  REP(i, N){
    cin >> A[i];
    if(A[i] == 1){
      mini = i;
    }
  }

  int start = max(0, mini-K+1);
  int end = min(mini, N-K);
  int minc = 1e9;
  FOR(i, start, end+1){
    int cnt = i/(K-1)+((N-1)-(i+K-1))/(K-1);
    int right = i/(K-1);
    int left = ((N-1)-(i+K-1))/(K-1);
    if(i%(K-1)){
      cnt++;
      right++;
    }
    if(((N-1)-(i+K-1))%(K-1)){
      cnt++;
      left++;
    }
    //cout << i << " " << right << " " << left << endl;
    minc = min(minc, cnt+1);
  }
  cout << minc << endl;


  return 0;
}

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

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

    ll ans = 0;
    ll d = 0;
    int flag = 0;

    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            d = (n / i) - 1;
            d += i - 1;

            if(flag == 0){
                ans = d;
            }else{
                if(ans >= d){
                    ans = d;
                }
            }
        }
    }

    if(ans == 0){
        ans = n - 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>

using namespace std;

/* PROBLEM

*/

/* INPUT

*/

/* OUTPUT

*/

long long M = 1000000007;

vector<long long> ways;
vector<bool> broken;

long long fill_ways(int index)
{
    if (index <= 1)
        return broken[index] ? 0 : 1;
    if (ways[index] == -1)
        ways[index] = broken[index] ? 0 : ((fill_ways(index-1) + fill_ways(index-2)) % M);
    return ways[index];
}

int main(int argc, char const *argv[])
{
    
    int steps_amount, broken_amount;

    cin >> steps_amount >> broken_amount;

    ways.resize(steps_amount+1);
    ways.assign(steps_amount+1, -1);
    
    broken.resize(steps_amount+1);
    broken.assign(steps_amount+1, false);

    for (int i = 0; i < broken_amount; i++)
    {
        int j;
        cin >> j;
        broken[j] = true;
    }

    cout << fill_ways(steps_amount) << "\n";

    return 0;
}

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

using namespace std;

#define long long long

int main() {

    string s;

    cin >> s;

    int ans = 0;
    for (int i = 0; i < s.length() / 2; i++) {
        if (s[i] != s[s.length() - i - 1]) ans++;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int N, K;

int main()
{
    cin >> N >> K;
    COMinit();

    for (int i = 1; i <= K; i++)
    {
        cout << (COM(K - 1, i - 1) * COM(N - K + 1, i)) % mod << endl;
    }
}

Measured memory_bytes: 12160
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

const ll MOD = 1000000007;

ll s(ll n, ll k, vector<vector<ll>> &dp) {
  if (k == 0) {
    return 0LL;
  }
  if (k == 1 or n == k) {
    return 1LL;
  }
  if (dp[n][k] != -1) {
    return dp[n][k];
  }
  return dp[n][k] = (s(n - 1, k - 1, dp) + (k * s(n - 1, k, dp) % MOD)) % MOD;
}

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

  ll n, k;
  cin >> n >> k;
  vector<vector<ll>> dp(1001, vector<ll>(1001, -1));
  ll ans = 0;
  for (int i = 0; i <= k and i <= n; i++) {
    ans += s(n, i, dp);
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10804
import java.util.Scanner;

//!
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int[] p = {2,3,5,7,11,13,17,19,23,29,31};
		for(;;){
			int n = sc.nextInt();
			char[] s = sc.next().toCharArray();
			if(n==0)break;
			long X = 0;
			for(char c:s){
				long x = 'A'<=c?(c-'A'+10):(c-'0');
				X = X*n+x;
			}
			long[] need = new long[11];
			int N = n;
			for(int i=0;i<11;i++){
				if(N%p[i]==0){
					N/=p[i];
					need[i--]++;
				}
			}
			long[] num = new long[11];
			for(int i=0;i<11;i++){
				long x = X;
				while(x>1){
					num[i]+=x/p[i];
					x/=p[i];
				}
			}
			long res = Long.MAX_VALUE;
			for(int i=0;i<11;i++)if(0<need[i])res=Math.min(res, num[i]/need[i]);
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
const fs = require('fs');

const main = () => {
  
  const input: string = fs.readFileSync('/dev/stdin', 'utf8'));
  const inputArr = input.split(" ");
  let sum = 0;
  for (let i = 0; i < inputArr.length; i++) {
    const inputInt = parseInt(inputArr[i]);
    sum += inputInt;
  }
  if (sum >= 22) {
    console.log("bust");
  }
  else {
    console.log("win");
  }
};

main();

Measured memory_bytes: 7372
#include <stdio.h>
int main(void){
    int left=0,right=0;
    int n,i;
    char s[101];
    scanf("%d %s",&n,s);
    for(i=0;i<n;i++){
        if(s[i]=='('){
            left++;}
           else if(s[i]==')'){
               if(left>0)left--;
               else right++;
               
           }
    }
    for(i=0;i<right;i++)printf("(");
    printf("%s",s);
    for(i=0;i<left;i++)printf(")");
    printf("\n");
    return 0;
           }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll modpow(ll a, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }

    return res;
}

ll comb(ll a, ll b) {
    ll ans = 1;

    for(ll i = a; i > a - b; i--) {
        ans = ans * i % mod;
    }
    for(ll i = 1; i <= b; i++) {
        ans = (ans * modpow(i, mod - 2)) % mod;
    }
    return ans;
}
int main() {
    int N, K;
    cin >> N >> K;
    vector<double> p(N);

    for(int i = 0; i < N; i++) {
        cin >> p[i];
    }
    vector<double> s(N + 1);
    s[0] = 0;
    for(int i = 1; i <= N; i++) {
        s[i] = s[i - 1] + (p[i - 1] + 1) / 2.0;  
    }
    long double ans = 0;
    for(int i = 1; i <= N - K; i++) {
        if(ans < s[i + K] - s[i]) { ans = s[i + K] - s[i]; }
    
    }
    if(ans < s[0 + K]) ans = s[K];
    
    cout << fixed << setprecision(20) << ans;

    return 0;
}

Measured memory_bytes: 3328
a,b,c,d = map(int,input().split())
if b <= d and a <= c:
	print(max(b-c,0))
elif b <= d and a > c:
	print(max(b-a,0))
elif b > d and a <= c:
	print(max(d-c,0))
else:
	print(max(d-a,0)) 


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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

void solve () {
	int n;
	cin >> n;
	map <string, int> g;
	string x;
	while (n--) {
		cin >> x;
		g[x]++;
	}
	string s[4] = {"AC", "WA", "TLE", "RE"};
	for (int i = 0; i < 4; i++) {
		cout << s[i] << " x " << g[s[i]] << "\n";
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
  #endif
	int t = 1;
	while (t--) {
		solve();
	}
 	return 0;
}

Measured memory_bytes: 3684
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
# mod = 10**9 + 7

n = int(input())

# s = deque(input())
# q = int(input())

# a, b = map(int, input().split())
a = list(map(int, input().split()))

c = 0
idx = 1
for i in range(n):
    if a[i] == idx:
        c += 1
        idx += 1

print(n-c if c > 0 else -1)

Measured memory_bytes: 24744
#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
int dp[1005][1005];
char arr[1005][1005];
 
int main()
{
	int h,w;
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			scanf(" %c",&arr[i][j]);
	if(arr[0][0]=='*' || arr[h-1][w-1]=='*')
		printf("0\n");
	else
	{
		dp[0][0]=1;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(arr[i+1][j]=='.')
				{
					dp[i+1][j]+=dp[i][j];
					dp[i+1][j]=dp[i+1][j]%mod;
				}
				if(arr[i][j+1]=='.')
				{
					dp[i][j+1]+=dp[i][j];
					dp[i][j+1]=dp[i][j+1]%mod;
				}
			}
		}
		printf("%d\n",dp[h-1][w-1]);
	}
}


Measured memory_bytes: 8608
size = int(int(input()))
num_list = [int(input()) for _ in range(size)]
maxv = num_list[1] - num_list[0]
minv = num_list[0]
for i in range(1, size):
    if minv > num_list[i]:
        minv = num_list[i]
        continue
    elif num_list[i] - minv > maxv:
        maxv = num_list[i] - minv


print(maxv)



Measured memory_bytes: 13600
def check(n):
    nn = [n//10**x % 10 for x in range(5)]
    return nn[0] == nn[4] and nn[1] == nn[3]


def main():
    A, B = map(int, input().split())
    ans = 0
    for i in range(A, B+1):
        if check(i):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 42020
a,b = map(int, input().split(" "))
p = []
q = []

for i in range(int(((a/8)*100)//1), int((((a+1)/8)*100)//1+1)):
  if i >= (a/8)*100 and i < ((a+1)/8)*100:
    p.append(i)
    
for i in range((b*10), (b+1)*10):
    q.append(i)

pq = list(set(p) & set(q))
if pq == []:
  print("-1")
else:
  print(min(pq))

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

ans = 0
for i in range(N):
    ans += B[i]
    if i == 0:
        continue
    judge = A[i] - A[i-1]
    if judge == 1:
        count = A[i-1] - 1
        ans += C[count]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

void solve(){
    int n;
    cin >> n;
    string s;
    string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        cout << a[((s[i] - 65) + n) % 26];
    }
}

int main(){
    int q = 1;
    //cin >> q;
    while(q--) solve();
}
// vse dolzhny vyiti v internet po hhtp


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

struct UnionFind {
    vector<int> par;
    UnionFind(int size) : par(size, -1) {}
    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if(x != y) {
            if(par[y] < par[x])
                swap(x, y);
            par[x] += par[y];
            par[y] = x;
        }
        return x != y;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
    int size(int x) { return -par[root(x)]; }
};

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    int A[M], B[M];
    for(int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    UnionFind UF(N);
    ll ans[M];
    ans[M - 1] = N * (N - 1) / 2;
    for(int i = M - 1; i > 0; i--) {
        ans[i - 1] = ans[i];
        if(UF.same(A[i], B[i]))
            continue;
        // debug(A[i]);
        // debug(B[i]);
        ans[i - 1] -= (ll)UF.size(A[i]) * UF.size(B[i]);
        UF.unionSet(A[i], B[i]);
    }
    for(int i = 0; i < M; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long 
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define setbit(x,k) (x |= (1 << k))
#define clearbit(x,k) (x &= ~(1ll << k))
#define checkbit(x,k) (x & (1ll << k))
#define mp make_pair
#define scl(x) scanf("%lld",&x)
#define sci(x) scanf("%d",&x)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define pii pair<int,int> 
#define YES printf("YES\n")
#define Yes printf("Yes\n")
#define yes printf("yes\n")
#define NO printf("NO\n")
#define No printf("No\n")
#define no printf("no\n")
#define nn printf("\n") 
#define mod 10000007
using namespace std;    

ll n, a[100005][3];
ll dp[100005][3][3];

ll solve(int pos, int konta, int koydin)
{
    if(pos == n) return 0;
    if(dp[pos][konta][koydin]!=-1) return dp[pos][konta][koydin]; 

    ll res = 0;
    if(koydin<1) res = max(res, a[pos][konta] + solve(pos+1, konta, koydin+1));
    if(konta == 0)
    {
        res = max(res, a[pos][1] + solve(pos+1, 1, 1));
        res = max(res, a[pos][2] + solve(pos+1, 2, 1));
    }
    if(konta == 1)
    {
        res = max(res, a[pos][0] + solve(pos+1, 0, 1));
        res = max(res, a[pos][2] + solve(pos+1, 2, 1));
    }
    if(konta == 2)
    {
        res = max(res, a[pos][1] + solve(pos+1, 1, 1));
        res = max(res, a[pos][0] + solve(pos+1, 0, 1));
    }
    return dp[pos][konta][koydin] = res;
}

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

Measured memory_bytes: 20792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main() {
	int H, W, K; cin >> H >> W >> K;
	vector<vector<int>>GRID(H, vector<int>(W));
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++)
		{
			char c; cin >> c;
			GRID[i][j] = c - '0';
		}

	int best_ans = 1e9;

	for (int x = 0; x < (1 << (H - 1)); x++)
	{
		int ans = 0;

		vector<int>white;
		int cnt = 1;
		for (int i = 0; i < H; i++)
			if ((x >> i) & 1)cnt++;
		white.resize(cnt);

		ans += cnt - 1;

		for (int j = 0; j < W; j++)
		{
			vector<int>add(cnt);
			int index = 0;
			for (int i = 0; i < H; i++)
			{
				if (GRID[i][j])add[index]++;
				if ((x >> i) & 1)index++;
			}
			bool dame = false;
			for (int k = 0; k < cnt; k++)
			{
				if (add[k] > K)dame = true;
			}
			if (dame)
			{
				ans = 1e9;
				break;
			}


			bool flag = false;
			for (int k = 0; k < cnt; k++)
			{
				if (white[k] + add[k] > K)flag = true;
			}

			if (flag)
			{
				ans++;
				for (int k = 0; k < cnt; k++)
					white[k] = add[k];
			}
			else
			{
				for (int k = 0; k < cnt; k++)
					white[k] += add[k];
			}
		}

		best_ans = min(best_ans, ans);
	}

	cout << best_ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<set>
#define LL long long
#define INF 1000000009
#define maxn 10000009
#include <set>
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
    int n,m,a[311][311],vis[310],sum[310],maxi=0,maxs=0;
    memset(vis,0,sizeof(vis));
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
    {
        scanf("%d",&a[i][j]);
    }
    }
    if(m==1)
    {
        printf("%d\n",n);
    }
    else
    {int mm=m-1,ans=INF;
    while(mm--)
    {
        memset(sum,0,sizeof(sum));
        maxs=0;
        for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            if(!vis[a[i][j]])
            {
                sum[a[i][j]]++;
               // printf(" %d  sum=%d,maxs=%d\n",a[i][j],sum[a[i][j]],maxs);
                if(maxs<sum[a[i][j]])
                {
                    //printf("!!");
                    maxs=sum[a[i][j]];
                    maxi=a[i][j];
                }
                break;
            }
        }
      //  printf("!%d %d\n",maxs,maxi);
        ans=min(ans,maxs);
        vis[maxi]=1;
    }
    printf("%d\n",ans);
    }
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{

	int X;

	cin >> X;

	if(X== 7 || X== 5 || X== 3 ){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}


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

int main(){
  while (true) {
    int H, W;
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (j == W-1) {
          cout << "#" << endl;
        }
        else if ((i == 0 || i == H-1) || (j == 0 || j == W-1)) {
          cout << "#";
        }
        else {
          cout << ".";
        }
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b>>u;
    if(u==s)cout<<a-1<<" "<<b<<endl;
    if(u==t)cout<<a<<" "<<b-1<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
int main(){
  int h, w;
  cin >> h >> w;
  int a[h][w] = {};
  REP(i, h){
    REP(j, w){
      a[i][j] = 0;
    }
  }
  int cnt = 0;
  vector<string> v;
  REP(i, h){
    REP(j, w){
      int x;
      cin >> x;
      a[i][j] += x;
      if(a[i][j] % 2 == 1){
        if(j == w - 1){
          if(i != h - 1){
            v.pb(to_string(i + 1) + " " + to_string(j + 1) + " " + to_string(i + 2) + " " + to_string(j + 1));
            cnt++;
            a[i + 1][j]++;
          }
        }else{
          v.pb(to_string(i + 1) + " " + to_string(j + 1) + " " + to_string(i + 1) + " " + to_string(j + 2));
          cnt++;
          a[i][j + 1]++;
        }
      }
    }
  }
  cout << cnt << endl;
  for(string s: v)cout << s << endl;
  return 0;
}

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

int main() {
  
  int a,b,c ;
  
  cin >> a >> b ;
  
  c = (a+b)/2;
  
   if(c*2==a+b)
     cout<<(a+b)/2<<endl;
  
  else
  cout<< (a+b)/2+1 <<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int H, W = 5; 
  while (cin >> H, H!=0) {
    // v[W][H]
    vector<vector<int>> v(W, vector<int>(H, 0));
    for (int i = H-1; i>=0; i--) {
      for (int j = 0; j < W; j++) {
        int t;
        cin >> t;
        v[j][i]=t;
      }
    }
    
    // くそこーどりょうさんきじゃないですか
    int ans = 0;
    for (int i = 0; i < H; i++) {
      for (int j = H-1; j >= 0; j--) {
        int last = 0, cnt = 0;
        for (int k = 0; k < W; k++) {
          if (v[k].size() <= j) {
            if (cnt >= 3) {
              ans += v[k-1][j]*cnt;
              for (int l = k-cnt; l < k; l++) {
                v[l].erase(v[l].begin()+j);
              }
            }
            cnt = 0;
            last = 0;
          } else if (last == v[k][j]) {
            cnt++;
          } else {
            if (cnt >= 3) {
              ans += v[k-1][j]*cnt;
              for (int l = k-cnt; l < k;  l++) {
                v[l].erase(v[l].begin()+j);
              }
            }
            cnt = 1;
            last = v[k][j];
          }
        }
        if (cnt >= 3) {
          ans +=v[W-1][j]*cnt;
          for (int l = W-cnt; l < W; l++) {
            v[l].erase(v[l].begin()+j);
          }
        }
      }
    }
    
    cout << ans << endl;
  }
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  string s;
  cin >> s;
  if (s[5]=='0'&&s[6]=='1') cout << "Heisei" << endl;
  else if (s[5]=='0'&&s[6]=='2') cout << "Heisei" << endl;
  else if (s[5]=='0'&&s[6]=='3') cout << "Heisei" << endl;
  else if (s[5]=='0'&&s[6]=='4') cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int N,i,j,x[101]={},a,b,c,d;
	scanf("%d",&N);
	for(i=0;i<N*(N-1)/2;++i)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if(c>d)x[a]+=3;else if(c<d)x[b]+=3;else x[a]++,x[b]++;
	}
	for(i=1;i<=N;printf("%d\n",a),++i)for(a=j=1;j<=N;++j)if(x[i]<x[j])++a;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll n;
string s;
ll cnt[300000+1];

int main(){
	cin >> n >> s;
	rep(i,n){
		if(s[i] == 'E')cnt[i]++;
	}
	FOR(i,1,n)cnt[i] += cnt[i-1];
	ll ans = INF;
	rep(i,n){
		ll sum = 0;
		if(i > 0)sum += i - cnt[i - 1];
		if(i < n-1)sum += (cnt[n-1] - cnt[i]);
		ans = min(ans,sum);
	}
	cout << ans << endl;
}

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("arrayop.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, k;
    cin >> n >> k;
    int a[n * 2];
    rep(i, 0, n)
    {
        cin >> a[i];
        a[n + i] = a[i];
    }
    int dp[n * 2][k + 1];
    rep(i, 0, n * 2)
        rep(j, 0, k + 1)
            dp[i][j] = -inf;
    rep(i, 0, n * 2)
        dp[i][0] = i;
    rep(i, 0, n * 2)
    {
        if (a[i] <= k)
            dp[i][a[i]] = max(dp[i][a[i]], i);
        if (i == 0)
            continue;
        rep(j, 0, k + 1)
        {
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
            if (a[i] <= j)
                dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]]);
        }
    }
    int cnt = 0;
    rep(i, 0, n)
    {
        bool ok = true;
        if (a[i] >= k)
            ok = false;
        rep(j, 0, k)
            if (dp[n + i - 1][j] > i && j + a[i] >= k)
            {
                ok = false;
                break;
            }
        if (ok)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 195712
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007
#define BOX 200000

typedef long long ll;

#define rep(i, s, e) for(unsigned int i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)
#define so(a) sort(begin(a), end(a))
#define soR(a) sort(begin(a), end(a), greater<ll>())
#define sum(a) accumulate(begin(a), end(a), 0)


template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }



int main() {
    ll H, W, N;
    cin >> H >> W >> N;
 
    ll masu[100][100];
    memset(masu, 0x00, sizeof(masu));
 
    vector<ll> a;
    rep(i, 0, N) {
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    ll x = 0;
    ll y = 0;
    ll color = 1;
    bool muki = true; // true:右、false:左
    rep(i, 0, N) {
        rep(ii, 0, a[i]) {
            masu[y][x] = color;
            if (muki) {
                if (x < (W - 1)) x++;
                else {
                    y++;
                    muki = false;
                }
                
            }
            else {
                if (x > 0) x--;
                else {
                    y++;
                    muki = true;
                }
            }
        }
        color++;
    }

    rep(i, 0, H) {
        rep(ii, 0, W) {
            cout << masu[i][ii] << ((ii < W - 1) ? " " : "\n");
        }
    }
    cout << endl;
    return 0;

}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;

const double EPS = 1e-5;

int X,Y,Z;
double dp[51][5000];
int V[4];
int event[51], event_A[51];

int main(){
    while(1){
        scanf("%d%d%d",&X,&Y,&Z);
        if(!X)break;

        for(int i = 0; i < X; i++){
            scanf("%d",&V[i]);
        }
        fill(event, event+Y+1, 0);
        for(int i = 0; i < Z; i++){
            int a, b, c;
            cin >> a >> b >> c;
            event[a] = b, event_A[a] = c;
        }
        for(int i = 0; i <= Y; i++){
            fill(dp[i], dp[i]+5000, 0);
        }
        dp[0][0] = 1;
        for(int i = 0; i < Y; i++){
            for(int j = 0; j < 5000; j++){
                for(int k = 0; k < X; k++){
                    if(abs(dp[i][j])==0) continue;
                    int nx = min(Y, i + V[k]), mn = j;
                    if(event[nx] == 2) mn += event_A[nx];
                    else if(event[nx] == 3) mn = max(0, j-event_A[nx]);
                    else if(event[nx] == 1) nx = min(Y, nx + event_A[nx]);
                    dp[nx][mn] += dp[i][j] / X;
                }
            }
        }
        double ans = 0;
        for(int i = 0; i < 5000; i++) ans += i * dp[Y][i];
        printf("%d\n", (int)(ans+EPS));
    }
    return 0;
}

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

int main() {
	string s;
	cin >> s;
	if(s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" || s == "cba"){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main(){
    ll N, K;
    cin >> N >> K;
    vector<bool> D(10, 1);
    int hate;
    rep(i, K){
        cin >> hate;
        D[hate] = 0;
    }
    for(int i = N; ; i++){
        bool valid = 1;
        int j = i;
        while(j){
            if(!D[j%10]) valid = 0;
            j /= 10;
        }
        if(valid){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
/*  ex3_3: Digits
    Jun_JPN */

#include <stdio.h>

int main(void){

    int num_10, num_k;
    int digit = 1;  // 10進数num_10が「num_k進数」で何桁かを数える変数

    scanf("%d %d", &num_10, &num_k);

// 「num_k^{N} <= num_10 < num_k^{N+1}」を満たすNをwhile文で求める
    int i = 1;
    while (!(i <= num_10 && num_10 < i*num_k)){ 
        i = i*num_k;
        digit ++;
    }

    printf("%d\n", digit);

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

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

		// 整数の入力
		int n = sc.nextInt();
		String st = Integer.toString(n);

		String a = String.valueOf(st.charAt(0));
		String b = String.valueOf(st.charAt(1));
		String c = String.valueOf(st.charAt(2));
		String d = String.valueOf(st.charAt(3));

		if(a.equals(b) & b.equals(c)){
			System.out.println("Yes");
		}else if(b.equals(c) & c.equals(d)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

		sc.close();
	}

}


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

int main(){
  int N; cin >> N;
  
  int t[N+1]={}, x[N+1]={}, y[N+1]={};
  for(int i=1;i<=N;i++) cin >> t[i] >> x[i] >> y[i];

  bool possible = true;
  rep(i,N){
    int dt = t[i+1]-t[i];
    int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);

    if (dist>dt) possible = false;
    if (dist%2 != dt%2) possible = false;

  }

  cout << (possible? "Yes" : "No") << endl;
  
}

 

Measured memory_bytes: 1408
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 200111;
int n, p[maxn];
int f[maxn], c[maxn];
int gf(int x) {return f[x]==x?x:f[x]=gf(f[x]);}
struct data
{
	ll a, b; int id;
	data (ll A=0, ll B=0, int Id=0) {a=A; b=B; id=Id;}
	data operator+(const data &t) const
	{
		return data(a+t.a, b+t.b, id);
	}
	bool operator<(const data &t) const
	{
		return MP(b*t.a, id)<MP(a*t.b, t.id);
	}
}a[maxn];

int main()
{
	geti(n);
	for (int i=2; i<=n; i++) geti(p[i]);
	for (int i=1; i<=n; i++)
	{
		geti(c[i]);
		a[i] = data(c[i]==0, c[i]==1, i);
		f[i] = i;
	}
	set<data> st;
	for (int i=2; i<=n; i++) st.insert(a[i]);
	ll ans = 0;
	data cur = a[1];
	while (st.size())
	{
		int x = st.begin()->id;
		st.erase(st.begin());
		assert(gf(x)==x);
		int y = gf(p[x]);
		if (y==1)
		{
			ans += cur.b*a[x].a;
			cur = cur+a[x];
		}
		else
		{
			int tsz = st.size();
			st.erase(a[y]);
			assert(st.size()==tsz-1);
			ans += a[y].b*a[x].a;
			a[y] = a[y]+a[x];
			st.insert(a[y]);
			assert(st.size()==tsz);
		}
		f[x] = y;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19840
#include <bits/stdc++.h>
#define int long long
using namespace std;
int w,h;
signed main(){;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>w>>h;
	if(w==1){
		cout<<1;
		return 0;
	}
	if(h==1){
		cout<<1;
		return 0;
	}
	int c1=(h+1)/2;
	int c2=h/2;
	int r=c1*((w+1)/2)+c2*(w/2);
	cout<<r;
}

Measured memory_bytes: 256