akhauriyash/Code-Regression huggingface dataset:
// b10, b14, b15 で, TLE と なった.
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
// 文字列 T の 先頭から, 順に, 文字列 S を 1グーゴル個連結した文字列(以下, S'と略記)中に, 出現する位置 を 保存.
LL dp[111111];
// 文字列 S の 各文字 の 出現位置 を 保管.
vector<vector<LL>> sPos(26);

int main(){
    
    // 1. 入力情報取得.
    char S[111111], T[111111];
    scanf("%s %s", S, T);
    int sl = strlen(S);
    int tl = strlen(T);
    
    // 2. 各文字の出現回数を保存.
    map<char, int> ms, mt;
    for(int i = 0; i < ALPHABET.size(); i++) ms[ALPHABET[i]] = 0, mt[ALPHABET[i]] = 0;
    for(int i = 0; i < sl; i++){
        ms[S[i]]++;
        int index = S[i] - 'a';
        sPos[index].push_back(i + 1);
    }
    for(int i = 0; i < tl; i++) mt[T[i]]++;
    // for(int i = 0; i < 26; i++){
    //     for(auto &p : sPos[i]) printf("%lld ", p);
    //     printf("\n");
    // }
    
    // 3. 存在しないケースを出力.
    // 文字列 S に 存在しない文字が, 文字列 T に 含まれている場合.
    for(auto &p : mt){
        char c = p.first;
        if(ms[c] == 0 && mt[c] > 0){
            printf("%d\n", -1);
            return 0;
        }
    }
    
    // 4. dp更新.
    // ex.
    // S = contest
    // T = sentence
    // -> 以下のように考える.
    // 文字列 T の 各文字 について, 文字列 S で, 何番目 を 使っているか見る.
    // s: 6
    // e: 5 -> 12
    // n: 3 -> 10 -> 17
    // t: 4 ->  7 -> 11 -> 14 -> 18
    // e: 5 -> 12 -> 19
    // n: 3 -> 10 -> 17 -> 24
    // c: 1 ->  8 -> 15 -> 22 -> 29
    // e: 5 -> 12 -> 19 -> 26 -> 33
    // -> 上記から, 33文字 と 判明.
    LL bef = 0; // 前回出現位置.
    for(int i = 0; i < tl; i++){
        // 今回チェックする文字列 T 中 の 文字 c.
        char c = T[i];
        int index = c - 'a';
        
        // 文字列 S 中 の 文字 c に関する出現位置情報 … sPos[index].
        // 今回出現位置 は 前回出現位置 から 逆算.
        LL tmp = lower_bound(sPos[index].begin(), sPos[index].end(), (bef % sl + 1)) - sPos[index].begin();
        LL cPos = 0;
        if(tmp == sPos[index].size()) cPos = (bef / sl + 1) * sl + sPos[index][0]; // 末尾なら, 次のサイクルの最初の要素を設定.
        else                cPos = (bef / sl) * sl     + sPos[index][tmp];
        
        // 上記までで計算した位置を元に, dp を 更新.
        dp[i] = cPos;
        
        // 前回情報更新.
        bef = cPos;
    }
    
    // 5. 出力 ～ 後処理.
    // for(int i = 0; i < tl; i++) printf("%lld ", dp[i]);
    // printf("\n");
    printf("%lld\n", dp[tl - 1]);
    return 0;
    
}

Measured memory_bytes: 2336
#1166
import queue

while True:
    tmp = input().split(" ")
    w = int(tmp[0])
    h = int(tmp[1])
    if w == 0:
        break

    yoko_wall = []
    tate_wall = []

    for i in range(2*h-1):
        if i%2 == 0:
            omega = []
            for k in input().split(" ")[1:]:
                omega.append(int(k))
            yoko_wall.append(omega)
            #縦向きの壁の事
        else:
            omega2 = []
            for r in input().split(" "):
                omega2.append(int(r))
            tate_wall.append(omega2)

    map_count = []
    for i in range(h):
        tmp = []
        for j in range(w):
            tmp.append(1000)
        map_count.append(tmp)

    q = queue.Queue()
    q.put([0,0])
    map_count[0][0] = 0

    while True:
        if q.empty():
            print("0")
            break

        start = q.get()

        if start[0] == h-1 and start[1] == w-1:
            print(str(map_count[h-1][w-1]+1))
            break

        ue = [start[0]-1,start[1]]
        sita = [start[0]+1,start[1]]
        migi = [start[0],start[1]+1]
        hidari = [start[0],start[1]-1]


        if ue[0] >= 0 and ue[0] < h and ue[1] >= 0 and ue[1] < w:
            if tate_wall[ue[0]][ue[1]] == 0:
                if map_count[ue[0]][ue[1]] == 1000:
                    map_count[ue[0]][ue[1]] = map_count[start[0]][start[1]] + 1
                    q.put(ue)

        if sita[0] >= 0 and sita[0] < h and sita[1] >= 0 and sita[1] < w:
            if tate_wall[start[0]][start[1]] == 0:
                if map_count[sita[0]][sita[1]] == 1000:
                    map_count[sita[0]][sita[1]] = map_count[start[0]][start[1]] + 1
                    q.put(sita)


        if migi[0] >= 0 and migi[0] < h and migi[1] >= 0 and migi[1] < w:
            if yoko_wall[start[0]][start[1]] == 0:
                if map_count[migi[0]][migi[1]] == 1000:
                    map_count[migi[0]][migi[1]] = map_count[start[0]][start[1]] + 1
                    q.put(migi)

        if hidari[0] >= 0 and hidari[0] < h and hidari[1] >= 0 and hidari[1] < w:
            if yoko_wall[hidari[0]][hidari[1]] == 0:
                if map_count[hidari[0]][hidari[1]] == 1000:
                    map_count[hidari[0]][hidari[1]] = map_count[start[0]][start[1]] + 1
                    q.put(hidari)



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

int main() {
    int N, M;
    cin >> N;
    map<long long int, long long int> mp;
    long long int sum = 0;
    for(int i = 0; i < N; i++) {
        int A;
        cin >> A;
        sum += A;
        mp[A]++;
    }
    cin >> M;
    for(int i = 0; i < M; i++) {
        int B, C;
        cin >> B >> C;
        long long int num = mp[B];
        sum -= B * num;
        sum += C * num;
        mp[B] = 0;
        mp[C] += num;
        cout << sum << endl;
    }
    return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a<=8 && b<=8)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}

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

void solve() {
	string s; cin >> s; // 入力文字列
	string res = ""; // 回答文字列

	// 入力文字列を前から読んでいき回答文字列に付け足したり削除したりする
	rep(i, s.size()) { 
		if (s[i] == 'B') {
			// 入力文字列がBで、かつ削除する文字列があれば削除する
			if(!res.empty()) res.pop_back();
			else continue; // 文字列が空ならば削除できないのでスルー
		}
		else res += s[i];
	}

	cout << res << endl;
}

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

Measured memory_bytes: 256
let () =
  let s = read_line () in
  print_endline @@
  if
    Array.fold_left ( && ) (String.length s mod 2 = 0) @@
    Array.init (String.length s) @@ fun i ->
      if i mod 2 = 0
      then s.[i] = 'h'
      else s.[i] = 'i'
  then "Yes"
  else "No"

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int n;
    cin >> n;
    int ans = IINF;
    rep(i, n + 1){
        int cnt = 0, tmp = i;
        while(tmp > 0){
            cnt += tmp % 6;
            tmp /= 6;
        }
        tmp = n - i;
        while(tmp > 0){
            cnt += tmp % 9;
            tmp /= 9;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())

xn = [0] * N
yn = [0] * N
hn = [0] * N

for i in range(N):
    xi, yi, hi = map(int, input().split())
    xn[i] = xi
    yn[i] = yi
    hn[i] = hi

for Cx in range(101):
    for Cy in range(101):

        flg = True

        for i in range(N):
            if 0 == hn[i]:
                continue

            h = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

            if flg:
                H = h
                flg = False
            else:
                if (H != h):
                    flg = True
                    break

        if flg:
            continue

        for i in range(N):
            if 0 == hn[i]:
                h = abs(xn[i] - Cx) + abs(yn[i] - Cy)
                if h < H:
                    flg = True
                    break

        if flg:
            continue

        print(Cx, Cy, H)
        break

    if not flg:
        break


Measured memory_bytes: 3064
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

l = abs(a-b)
if a==b:
    print('YES')
elif v < w:
    print('NO')
elif l <= (v-w)*t:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9188
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int[] len = new int[n];
        for (int i=0; i<n; i++) {
        	len[i] = sc.nextInt();
        }

      Arrays.sort(len);
      
      int count = 0;
      
      for (int i=0; i<n-2; i++) {
        int a = len[i];
      	for (int j=i+1; j<n-1; j++) {
          int b = len[j];
          for (int k=j+1; k<n; k++) {
            int c = len[k];
            if (a+b<=c) {
              break;
            } else if (a<b+c && b<c+a) {
              count++;
            }
          }
        }
      }
      
      System.out.println(count);
	}
}

Measured memory_bytes: 29812
function Main(input) {
 var In = input.split('');
  var count = 0;
  
  for(var i = 0; i < 3; i++){
    if(In[i] == '1'){
      count += 1;
    }
  }
  console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7496
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,x,y,t,q,r,max=0;
    cin>>a>>b>>c>>x>>y;
    t=x*a;
    q=y*b;
    max=t+q;
    if(x>y)
    {
        r=(x*2)*c;
        t= (y*2)*c;
        q= t+ ((x-y)*a);
    }
    else
    {
        r= (y*2)*c;
        t= (x*2)*c;
        q= t+ ((y-x)*b);
    }
    if(r<max)
        max=r;
    if(q<max)
        max=q;
    cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	string S, T;
	cin >> S;
	cin >> T;

	int ns = S.size();
	int nt = T.size();
	vector<vector<int>> idx(26);
	for(int i=0; i<ns; i++){
		idx[S[i]-'a'].push_back(i);
	}

	ll cur = 0;
	ll cnt = 0;
	for(int i=0; i<nt; i++){
		if(idx[T[i]-'a'].size()==0) {
			cout << -1 << endl;
			return 0;
		}
		auto it = lower_bound(idx[T[i]-'a'].begin(), idx[T[i]-'a'].end(), cur);
		if(it==idx[T[i]-'a'].end()){
			cur = idx[T[i]-'a'][0]+1;
			cnt++;
		} else {
			cur = *it+1;
		}
	}

	cout << cnt*ns+cur << endl;

	return 0;
}


Measured memory_bytes: 1344
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int A;
    cin >> A;
    
    cout << (A)/3 << endl; 

   return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal A = new BigDecimal(sc.next());
		BigDecimal B = new BigDecimal(sc.next());
		sc.close();
		BigDecimal ans = A.multiply(B);
		System.out.println(ans.setScale(0, RoundingMode.DOWN));

	}
}


Measured memory_bytes: 36008
n = int(input())
a = [int(i) for i in input().split(" ")]
cnt = 0
flag = True
while flag:
    flag = False
    for i in range(n-1, 0, -1):
        if a[i-1] > a[i]:
            a[i-1], a[i] = a[i], a[i-1]
            flag = True
            cnt += 1
print(" ".join([str(i) for i in a]))
print(cnt)

Measured memory_bytes: 7756
#coding: utf-8
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        # xの根を探索
        if self.parents[x] < 0:
            return x
        else:
            # 再帰的に根を探索
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        # 2つの木をマージする。
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def are_same(self, x, y):
        # 2つの要素の根が同じかどうかを調べる
        return self.find(x) == self.find(y)

    def members(self, x):
        # xと同じ根の要素をリストで出力
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == self.n]

    def roots(self):
        # 根である要素をリストで出力
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{} {}".format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uni = UnionFind(N)
for i in range(M):
    x, y, z = map(int, input().split())
    uni.union(x-1, y-1)
print(uni.group_count())

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

int main()
{
	int N;
	char prev;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> W[i];
	}

	for (int i = 0; i < N-1; ++i)
	{
		for (int j = i+1; j < N; ++j)
		{
			if (W[i] == W[j])
			{
				cout << "No" << endl;
				return 0;
			}
		}
	}

	for (int i = 0; i < N-1; ++i)
	{
		if (W[i][W[i].size()-1] != W[i+1][0])
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main()
{
	//2.すごろく	
	int n;
	cin >> n;
	int A, _A = 1;
	int k = 0;
	int A_count[100];
	A_count[0] = 1;
	for (int i = 0; i < n; i++)
	{
		cin >> A;
		if (A == 1)
		{
			if (A == _A)
			{
				A_count[k]++;
			}
			else
			{
				k++;
				A_count[k] = 2;
			}
		}
		_A = A;
	}
	sort(A_count, A_count + k + 1);
	cout << A_count[k] << endl;

	return 0;
}


Measured memory_bytes: 3140
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

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

int main()
{
	int n, k, i, a, m[200005] = {}, s = 0;

	cin >> n >> k;
	for (i = 0; i < n; i++) {
		cin >> a;
		m[a]++;
	}

	sort(m, m + n, greater<int>());

	for (i = k; i <= 200001; i++) {
		s += m[i];
	}

	cout << s << endl;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

char itoc(int i){
  return i+'0';
}

char ctoi(char c){
  return c-'0';
}

bool LeftIsBigger(const std::string& l,const std::string& r){
  // cerr<<"In Function"<<endl;
  // cerr<<l<<" "<<r<<endl;
  if(l.size()>r.size()) return true;
  if(l.size()<r.size()) return false;
  for(int i=0;i<l.size();i++){
    if(l[i]!=r[i]){
      return l[i]>r[i];
    }
  }
  return false;
}



int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);



  int n,m;
  cin>>n>>m;
  std::vector<int> a(m);
  for(int i=0;i<m;i++){
    cin>>a[i];
  }
  std::string dp[10001];

  std::vector<int> match={-1,2,5,5,4,5,6,3,7,6};


  for(auto v:a){
    if(n-match[v]>=0){
      dp[n-match[v]]=std::string{itoc(v)};
    }
  }

  for(int i=n;i>=0;i--){
    for(auto v:a){
      if(i+match[v]<=n){
        if(dp[i+match[v]].empty()) continue;
        // cerr<<itoc(v)<<endl;
        std::string pre=itoc(v)+dp[i+match[v]];
        std::string suf=dp[i+match[v]]+itoc(v);
        if(dp[i+match[v]].empty()){
          dp[i]=pre;
        }
        // cerr<<pre<<" "<<suf<<endl;
        if(LeftIsBigger(pre,dp[i])){
          dp[i]=pre;
        }
        if(LeftIsBigger(suf,dp[i])){
          dp[i]=suf;
        }
      }
    }
  }

  cout<<dp[0]<<endl;




  return 0;
}


Measured memory_bytes: 36992
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            int W,H,x,y,r;
            W = sc.nextInt();
            H = sc.nextInt();
            x = sc.nextInt();
            y = sc.nextInt();
            r = sc.nextInt();
            if((0<=x && x<W && 0<=y && y<H) && (Math.abs(x-0)>=r || Math.abs(x-W)>=r) && (Math.abs(y-0)>=r || Math.abs(y-H)>=r)) {
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];

    ll res = 0;
    REP(i, 30){
    	ll tmp = 0;
    	if(K>>i & 1){
    		ll X = (K>>i) - 1;
    		REP(j, N){
    			ll Y = (A[j]>>i);
    			if((~X&Y)==0){
    				tmp += B[j];
    			}
    		}
    	}
    	chmax(res, tmp);
    }
    ll tmp = 0;
    REP(i, N){
    	if((~K&A[i])==0) tmp += B[i];
    }
    chmax(res, tmp);

    cout << res << endl;
    return 0;
}

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

typedef long long ll;

int main(){
  ll n,k;
  cin >> n >> k;
  
  ll h[n];
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  
  sort(h, h+n);
  
  ll ans = h[n-1];
  for(int i=0; i<n-k+1; i++){
    ans = (ans < (h[i+k-1] - h[i])) ? ans : h[i+k-1]-h[i];
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a, b;
    cin >> a >> b;
    
    if(a*b % 2 == 0)
        cout << "Even" << endl;
    else
        cout << "Odd" << endl;
        

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int cnt = 0;
    int hoge = 1;
    while(hoge<b){
        hoge--;
        hoge += a;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int count=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        int total=i*500+100*j+50*k;
          if(total==x){count++;}
      }
    }
  }
  cout<<count<<endl;
}
        


Measured memory_bytes: 3592
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 301;
int n; double dp[maxn][maxn][maxn];

double dfs(const int i, const int j, const int k)
{
    if (i == 0 && j == 0 && k == 0)
        return 0;
    double& ans = dp[i][j][k];
    if (-1 == ans) {
        ans = 1;
        if (i)
            ans += 1.0*i/n * dfs(i-1,j+1,k);
        if (j)
            ans += 1.0*j/n * dfs(i,j-1,k+1);
        if (k)
            ans += 1.0*k/n * dfs(i,j,k-1);
        ans /= (1-1.0*(n-i-j-k)/n);
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n) {
        int cnt[4] = {0};
        FOR(i,0,n) {
            int x; cin >> x;
            cnt[x]++;
        }
        FOR(i,0,n+1) FOR(j,0,n+1) FOR(k,0,n+1)
            dp[i][j][k] = -1;
        const double ans = dfs(cnt[3],cnt[2],cnt[1]);
        printf("%.10f\n",ans);
    }
    return 0;
}


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


def main():
    """Function."""
    h, w = map(int, input().split())

    counter = 0
    for _ in range(h):
        s = str(input())
        counter += s.count("#")

    if counter == h + w - 1:
        print("Possible")
    else:
        print("Impossible")


if __name__ == "__main__":
    main()


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

int main(){
    int n;cin>>n;
    vector<int> v(n);
    int k;cin>>k;
    for(int i=0;i<n;i++)cin>>v[i];
    vector<int> dp(n,INT_MAX);
    dp[0]=0;
    
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i-j>=0)dp[i]=min(dp[i-j]+abs(v[i]-v[i-j]),dp[i]);
        }
    }

    cout<<dp[n-1]<<endl;
}

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

int main() {
	int n, r, l = 0;
	cin >> n;
	vector<int> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		r += w[i];
	}
	int d, m = r;
	for (int j = 0; j < n; j++) {
		r -= w[j];
		l += w[j];
		d = abs(r - l);
		m = min(d, m);
	} 
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int N;
    int ac = 0, wa = 0, tle = 0, re = 0;
    cin >> N;
    for(int i = 0; i < N; ++i)
    {
        string input;
        cin >> input;
        if(input == "AC")
        {
            ++ac;
        }
        else if(input == "WA")
        {
            ++wa;
        }
        else if(input == "TLE")
        {
            ++tle;
        }
        else if(input == "RE")
        {
            ++re;
        }
    }


    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>

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

int main() {
	string S, T;
	cin >> S >> T;
	int len = S.size();
	int A[50] = { 0 };
	for (int i = 0; i < len; i++) {
		if (S[i] != T[i]) {
			int x = S[i] - 'a';
			int y = T[i] - 'a';
			if (A[y] != 0 || A[x] != 0) {
				cout << "No";
				return 0;
			}
			A[y] = 1;
			char c1 = T[i];
			char c2 = S[i];
			for (int j = i; j < len; j++) {
				if (S[j] == c2)S[j] = c1;
				else if (S[j] == c1)S[j] = c2;
			}
		}
	}
	cout << "Yes";
	return 0;
}



Measured memory_bytes: 900
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}

const string YES = "YES";
const string NO = "NO";

void solve(std::string S){
    if(S=="keyence"){
                cout<<YES<<endl;
                return;
            }
    for(int i=1; i<S.size(); i++){
        for(int j=0; j<S.size()-i; j++){
            string str=S;
            str.erase(j,i);
            // debug(str);
            if(str=="keyence"){
                cout<<YES<<endl;
                return;
            }
        }
    }
    cout<<NO<<endl;return;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])

if a[0][0] != b[0][0]:
  print(n-(a[0][1]+b[0][1]))
else:
  print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))
         

    
   

Measured memory_bytes: 20572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication58
{
    class Program
    {
        static void Main()
        {
            int a = int.Parse(Console.ReadLine());
            for (int d = 1; d <=a; d++)
            { int b = d;
                if (b % 3 == 0) { Console.Write(" " + d);continue; }
                while (b!=0)
                {
                    if (b % 10 == 3) { Console.Write(" "+d); break; }
                    b /= 10;
                }
            }
            Console.WriteLine();
        }
    }
}



Measured memory_bytes: 17904
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N, K = mis()
    B, R = K, N-K
    fs = factorials_list(N+10, N1097)
    invs = invs_list(N+10, fs, N1097)
    for i in range(1, K+1):
        if R+1 >= i and B-1 >= i-1:
            print(comb_from_list(R+1, i, N1097, fs, invs) * comb_from_list(B-1, i-1, N1097, fs, invs) % N1097)
        else:
            print(0)

main()



Measured memory_bytes: 9776
#include<iostream>
#include<algorithm>
#include<iomanip>

std::string to2(char c16){
	if(c16 == '0')return "0000";
	if(c16 == '1')return "0001";
	if(c16 == '2')return "0010";
	if(c16 == '3')return "0011";
	if(c16 == '4')return "0100";
	if(c16 == '5')return "0101";
	if(c16 == '6')return "0110";
	if(c16 == '7')return "0111";
	if(c16 == '8')return "1000";
	if(c16 == '9')return "1001";
	if(c16 == 'a')return "1010";
	if(c16 == 'b')return "1011";
	if(c16 == 'c')return "1100";
	if(c16 == 'd')return "1101";
	if(c16 == 'e')return "1110";
	if(c16 == 'f')return "1111";
}

int main(){
	int n;
	std::cin >> n;
	for(;n--;){
		std::string s16, s2 = "";
		std::cin >> s16;
		for(int i=0;i<s16.size();i++){
			s2 += to2(s16[i]);
		}
		std::reverse(s2.begin(), s2.end());
		long double res = 0, _d = 1;
		for(int i=7;i<=30;i++){
			res += (s2[i] - '0') * _d;
			_d *= 2.0;
		}
		_d = 0.5;
		int st = 1;
		for(int i=6;i>=0;i--){
			if(s2[i] == '1'){
				res += _d;
				st = 7-i;
			}
			_d /= 2.0;
		}
		res *= (s2[31]-'0'==1)?(-1):1;
		std::cout.setf(std::ios_base::fixed,std::ios_base::floatfield);
		std::cout << std::setprecision(st) << res << std::endl;
	}
}

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



int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n;
    vector<long long int> arr(n);
    for(int i=0; i<n; i++){
        cin>>arr[i];
        if(i>0)
            arr[i] += arr[i-1];
    }
    vector<vector<long long>> dp(n+1,vector<long long>(n+1));
    for(int i=n-1; i>=0;i--){
        for(int j=i;j<n;j++){
            if(j==i)
                dp[i][j] = 0;
            else{
                long long int s = arr[j]-(i==0? 0: arr[i-1]);
                dp[i][j] = 1e18;
                for(int k=i;k<j;k++)
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + s);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using ll = int64_t;

int main() {
  int a, b;
  cin>>a>>b;
  cout << max(a, b) + max(max(a, b)-1, min(a, b)) << endl;
  return 0;
}


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

typedef long long ll;

const ll mod = (int)1e9 + 7;
int main() {
	int n, k; cin >> n >> k;
	vector< vector<ll> > comb(2005, vector<ll>(2005));
	for(int i = 0; i <2001;i++)
		for (int j = 0; j <= i; j++) {
			if (j == 0 || j == i)comb[i][j] = 1;
			else comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % mod;
		}
	for (int i = 1; i <= k; i++) {
		cout << comb[n - k + 1][i] * comb[k - 1][i - 1] % mod << endl;
	}

	return 0;
}

Measured memory_bytes: 31744
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

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

	int x0, y0;
	char** input = new char* [H];
	int** output = new int* [H];
	for (int i = 0; i < H; i++) {
		input[i] = new char[W];
		output[i] = new int[W];
		for (int j = 0; j < W; j++) {
			cin >> input[i][j];
			if (input[i][j] == '#') {
				x0 = i; y0 = j;
			}
			output[i][j] = -1;
		}
	}

	int c = 0;
	int counter = 1;
	for (int j = 0; j < W; j++) {
		if (input[x0][j] == '#') {
			c++; if (c != 1) { counter++; }
		}
		output[x0][j] = counter;
	}
	counter++;

	for (int i = x0 + 1; i < H; i++) {
		bool flag = false;
		for (int j = 0; j < W; j++) {
			if (input[i][j] == '#') { flag = true; break; }
		}
		if (flag) {
			c = 0;
			for (int j = 0; j < W; j++) {
				if (input[i][j] == '#') {
					c++; if (c != 1) { counter++; }
				}
				output[i][j] = counter;
			}
			counter++;
		}
		else {
			for (int j = 0; j < W; j++) {
				output[i][j] = output[i - 1][j];
			}
		}
	}
	for (int i = x0 - 1; i >= 0; i--) {
		bool flag = false;
		for (int j = 0; j < W; j++) {
			if (input[i][j] == '#') { flag = true; break; }
		}
		if (flag) {
			c = 0;
			for (int j = 0; j < W; j++) {
				if (input[i][j] == '#') {
					c++; if (c != 1) { counter++; }
				}
				output[i][j] = counter;
			}
			counter++;
		}
		else {
			for (int j = 0; j < W; j++) {
				output[i][j] = output[i + 1][j];
			}
		}
	}




	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << output[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

/**
 *
 * @author k17075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int i = 0;
        int[] Case = new int[10000];
        Scanner sc = new Scanner(System.in);
        while(true){
            int x = sc.nextInt();
            if (x == 0) break;
            System.out.println("Case " + (i+1) + ": " + x);
            i++;
        }
    }
}


Measured memory_bytes: 41596
object Scanner {
  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}

object Main extends App {
  def devidablity(x:Int) = {
    var num = x
    var count = 0
    while (num%100==0){
      count = count + 1
      num = num / 100
    }
    count
  }
  val d,n = Scanner.nextInt()
  val step = if (d == 0){
    1
  } else if (d == 1){
    100
  } else {
    10000
  }
  var i = 0
  var count = 0
  while (count < n){
    i = i + step
    if (devidablity(i)==d){
      count = count + 1
    }
  }
  println(i)
}

Measured memory_bytes: 27212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define dl double long
const int INF=0x3fffffff;
const ll MOD=1000000007;
const ll MODD=998244353;
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }

ll cnt[2020];

int main()
{
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  ll ans=0, now=0, keta=1;
  cnt[0]=1;
  rep(i, S.size()){
    now = (now + (S[i] - '0') * keta) % 2019;
    keta = (keta * 10) % 2019;
    ++cnt[now];
  }
  rep(i, 2020){
    ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  cout << ans << "\n";
}


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

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


int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    char ch;
    cin >> ch;
    if(isupper(ch)){
        cout << "A" << endl;
    }
    else{
        cout << "a" << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();
		
		System.out.println(Math.min(p + q, Math.min(q + r, r + p)));
	}	
}

Measured memory_bytes: 22740
import sys
sys.setrecursionlimit(1000000)

def rec(n):
    if n == 0: return 0
    if memo[n] != -1: return memo[n]
    
    res = n
    i = 1
    while 6**i <= n:
        res = min(res, rec(n - 6**i) + 1)
        i += 1
    
    i = 1
    while 9**i <= n:
        res = min(res, rec(n - 9**i) + 1)
        i += 1
    
    memo[n] = res
    return res

n = int(input())
memo = [-1]*(n+10)
print(rec(n))

Measured memory_bytes: 18036
def getval():
    s = input()
    return s
    
def main(s):
    #dp for "a","ab","abc"
    mod = 10**9 + 7
    dp = [0,0,0,0]
    p3 = [1]
    for i in range(len(s)):
        p3.append((3*p3[i])%mod)
    for i in s:
        if i=="A":
            dp[0] += p3[dp[3]]
            dp[0] %= mod
        elif i=="B":
            dp[1] += dp[0]
            dp[1] %= mod
        elif i=="C":
            dp[2] += dp[1]
            dp[2] %= mod
        else:
            temp1 = dp[0]*2
            temp2 = dp[1]*2
            temp3 = dp[2]*2
            dp[2] += dp[1]
            dp[1] += dp[0]
            dp[0] += p3[dp[3]]
            dp[2] += temp3
            dp[1] += temp2
            dp[0] += temp1
            dp[3] += 1
            for j in range(3):
                dp[j] %= mod
            #print(dp)
    print(dp[2])

if __name__=="__main__":
    s = getval()
    main(s)

Measured memory_bytes: 73604
#include<stdio.h>

int n,A[50];

int solve(int i, int m){
  if(m == 0)return 1;
  if(i >= n)return 0;
  int res = solve(i + 1, m) || solve(i + 1,m - A[i]);
  return res;
}

int main(){
  int q,M,i;

  scanf("%d",&n);
  for(i = 0; i < n; i++)scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&M);
    if(solve(0,M))printf("yes\n");
    else printf("no\n");
  }

  return 0;
}



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

s1 = input()
s2 = input()

h = 0
mod = 10**9 + 7

ans = 1
prev_pat = 0
while h < len(s1):

    # pattern 1
    if s1[h] == s2[h]:
        if h == 0:
            ans *= 3
        elif prev_pat == 1:
            ans *= 2
        else:  #prev_pat == 2
            ans *= 1
        h += 1
        prev_pat = 1
    elif s1[h] == s1[h + 1]:  # pattern 2
        if h == 0:
            ans *= 6
        elif prev_pat == 1:
            ans *= 2
        else:  #prev_pat == 2
            ans *= 3
        h += 2
        prev_pat = 2
    else:
        print("this line should not be reached")
        exit(0)
    ans %= mod

print(ans)

Measured memory_bytes: 38384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int k = sc.nextInt();
    String s = sc.next();
    if (s.length() <= k) System.out.println(s);
    else System.out.println(s.substring(0, k) + "...");
  }
}

Measured memory_bytes: 36560
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  int a, b, c ;
  cin >> a >> b >> c;
  if (a+b >= c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    vector <int> A;
    vector <int> Z;

    int cnt=0,mx=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            A.push_back(i);
        }
        if(s[i]=='Z'){
            Z.push_back(i);
        }
    }
    sort(A.begin(),A.end());
    sort(Z.begin(),Z.end());
    cout<<((Z[Z.size()-1]+1)-(A[0]+1))+1;
}


Measured memory_bytes: 1364
def main():
    N, K = map(int, input().split())
    A = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append([a, b])
    A = sorted(A, key = lambda x: x[0])

    i = 0
    while i < N and K > 0:
        a, b = A[i]
        K -= b
        i += 1
    return a

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 22144
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	char s[3];
	scanf("%s",s);
	// printf("%s",s);
	int c=0;
	if(s[0]=='S' && s[1]=='S' && s[2]=='S'){
		printf("0\n");
	}
	else if((s[0]=='S' && s[1]=='S' && s[2]=='R') || (s[0]=='S' && s[1]=='R' && s[2]=='S') || (s[0]=='R' && s[1]=='S' && s[2]=='S') || (s[0]=='R' && s[1]=='S' && s[2]=='R')){
		printf("1\n");
	}
	else if((s[0]=='R' && s[1]=='R' && s[2]=='S') || (s[0]=='S' && s[1]=='R' && s[2]=='R')){
		printf("2\n");
	}
	if(s[0]=='R' && s[1]=='R' && s[2]=='R'){
		printf("3\n");
	}
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

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

    int N;
    cin >> N;

    Vi a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    Vi sums(N + 1);
    for (int i = 0; i < N; ++i) {
        sums[i + 1] = sums[i] + a[i];
    }

    int ans = I_INF;
    for (int i = 0; i < N; ++i) {
        ans = min(ans, abs((sums[N] - sums[i + 1]) - (sums[i + 1] - sums[0])));
    }

    cout << ans << endl;

    return 0;
}

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

int main() {

  int n;
  cin >> n;

  vector<int> dp(n+1);

  dp[0] = 1;
  dp[1] = 1;
  
  for (int i = 2; i <= n; i++) {
    dp[i] = dp[i - 2] + dp[i - 1];
  }

  cout << dp[n] << endl;

  return 0;

}


Measured memory_bytes: 3080