akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int main(){
	string str;
	while (cin >> str) {
		int J = 0, I = 0;
		for (int i = 1; i < str.size() - 1; i++) {
			if (str[i] == 'O' && str[i + 1] == 'I') {
				if (str[i - 1] == 'J') J++;
				if (str[i - 1] == 'I') I++;
			}	
		}	
		cout << J << endl;
		cout << I << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <climits>

#define INF INT_MAX

using namespace std;

vector <int> D;
int n=0;

void initRMQ(int n_){

  n = 1;
  while(n <= n_) n *= 2;
 
  D.resize(2*n-1);

  for(int i=0; i<2*n-1-1; i++) D[i] = INF;
}


void update(int k, int a){

  k += n - 1;
  D[k] = a;

  while(k > 0){
    k = (k-1) / 2;
    D[k] = min(D[k*2+1], D[k*2+2]);
  }
}


int query(int a, int b,int k, int l, int r){

  if(r <=a || b <= l) return INF;
  if(a <= l && r <= b) return D[k];
   
  int vl = query(a, b, k*2+1, l, (l+r)/2);
  int vr = query(a, b, k*2+2,(l+r)/2, r);
  return min(vl, vr);
  
}


int findMin(int a, int b){

  return query(a, b+1, 0, 0, n);
}


int main(){
  int N, q, com, x, y;

  cin >> N >> q;

  //  D.resize(N);
  initRMQ(N);

  for(int i=0; i<q; i++){
    cin >> com >> x >> y;

    if(com == 0) update(x, y);
    else if(com == 1){ cout << findMin(x, y); cout << endl;}
  }
}



Measured memory_bytes: 3812
import java.util.*;

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

        String s = sc.next();
        int n = s.length();

        System.out.print(s.charAt(0));
        System.out.print(n-2);
        System.out.println(s.charAt(n-1));
    }
}



Measured memory_bytes: 23124
# frozen_string_literal: true

class Node
  attr_accessor :id, :parent, :left, :right

  def initialize(id)
    @id = id
  end

  def root?
    parent ? false : true
  end
end

n = gets.to_i
array = readlines.map { |s| s.split.map(&:to_i) }

nodes = []
array.each do |e|
  nodes << Node.new(e[0])
end

array.each do |e|
  node = nodes.find { |node| node.id == e[0] }

  if e[1] != -1
    node.left = e[1]
    nodes.find { |node| node.id == e[1] }.parent = node.id
  end

  if e[2] != -1
    node.right = e[2]
    nodes.find { |node| node.id == e[2] }.parent = node.id
  end
end

def print_order_by_preorder(node, nodes)
  return unless node

  print ' '
  print node.id
  print_order_by_preorder(nodes.find { |n| n.id == node.left }, nodes)
  print_order_by_preorder(nodes.find { |n| n.id == node.right }, nodes)
end

def print_order_by_inorder(node, nodes)
  return unless node

  print_order_by_inorder(nodes.find { |n| n.id == node.left }, nodes)
  print ' '
  print node.id
  print_order_by_inorder(nodes.find { |n| n.id == node.right }, nodes)
end

def print_order_by_postorder(node, nodes)
  return unless node

  print_order_by_postorder(nodes.find { |n| n.id == node.left }, nodes)
  print_order_by_postorder(nodes.find { |n| n.id == node.right }, nodes)
  print ' '
  print node.id
end

root_index = nodes.find_index(&:root?)
puts 'Preorder'
print_order_by_preorder(nodes[root_index], nodes)
puts "\n"
puts 'Inorder'
print_order_by_inorder(nodes[root_index], nodes)
puts "\n"
puts 'Postorder'
print_order_by_postorder(nodes[root_index], nodes)
puts "\n"



Measured memory_bytes: 6896
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((LL) (r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, system("pause")
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, system("pause")
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, system("pause")
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, system("pause")
#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

const int N = 105;

int n;
int a[N * 2];

int main() {
    int ans;
    while (~scanf("%d", &n)) {
        rep (i, 2 * n) scanf("%d", &a[i]);
        sort(a, a + 2 * n);
        ans = 0;
        for (int i = 0; i < 2 * n; i += 2) ans += min(a[i], a[i + 1]);
        printf("%d\n", ans);
    }
    return 0;
}


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

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

#define MAXN 1001
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FAIL {cout << -1 << endl; return 0;}

int dp[10][1001];
int P[10], C[10];

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);

    int D, G;
    scanf("%d %d", &D, &G);
    for (int i = 0; i < D; i++)
        scanf("%d %d", &P[i], &C[i]);

    int T = 0;
    for (int i = 0; i < D; i++)
        T += P[i];


    for (int t = 1; t <= P[0]; t++) {
        dp[0][t] = 100 * t;
        if (t == P[0]) dp[0][t] += C[0];
    }

    for (int i = 1; i < D; i++) {
        for (int t = 0; t <= T; t++) {
            for (int k = 0; k <= min(t, P[i]); k++) {
                int tmp = 100 * (i + 1) * k;
                if (k == P[i]) tmp += C[i];
                dp[i][t] = max(dp[i][t], dp[i - 1][t - k] + tmp);
            }
        }
    }

    for (int t = 0; t <= T; t++) {
        if (dp[D - 1][t] >= G) {
            printf("%d\n", t);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    string ST;
    cin>>ST;
    ll ans=INF;
    for(char c='a';c<='z';c++){
        string st=ST;
        ll cnt=0;
        while(st.size()){
            bool end=true;
            REP(i,st.size()){
                if(st[i]!=c){
                    end=false;
                }
            }
            if(end){
                break;
            }
            string t;
            REP(i,(int)st.size()-1){
                if(st[i]==c||st[i+1]==c){
                    t.pb(c);
                }else{
                    t.pb(st[i]);
                }
            }
            st=t;
            cnt++;
        }
        chmin(ans,cnt);
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const int MAX = 510000;
const int MOD = 998244353;

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

ll 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 main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    COMinit();

    ll N, A, B, K;
    cin >> N >> A >> B >> K;

    ll ans = 0;
    for (ll i = 0; i <= N; i++) {
        if ((K-A*i)%B == 0) {
            ll j = (K-A*i)/B;
            ans += COM(N, i) * COM(N, j) % MOD;
            ans %= MOD;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 12160
comfortable x y = (abs $ x - y) <= 1

lunlun :: Integer -> [Integer]
lunlun 1 = [1,2,3,4,5,6,7,8,9]
lunlun n = let prev = lunlun (n-1)
            in concat (map (\x -> let one = x `mod` 10 in filter (\n -> (x*10+one)`div`10 == n`div` 10) [x*10+one-1,x * 10 +one,x*10+one+1]) prev)

lunlun_k :: Integer -> Integer -> Integer
lunlun_k n m = if toInteger(length $ lunlun m) >= n
                  then if n<0 then error $ show n ++ " " ++ show m else (lunlun m)!!fromInteger(n-1)
                  else lunlun_k (n-toInteger (length $ lunlun m)) (m+1)

main = do
  k <- read <$> getLine
  print $ lunlun_k k 1

Measured memory_bytes: 1020
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace ARC086C
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var K = ss.Next(int.Parse);
            var A = ss.Next(int.Parse, N);

            sw.WriteLine(A.GroupBy(x => x).OrderByDescending(g => g.Count()).Skip(K).Sum(g => g.Count()));
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

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

void solved(){
	string s,t;cin>>s>>t;
	if(s == t.substr(0,t.size() - 1)){
		cout<<"Yes"<<endl;
	}else cout<<"No"<<endl;
}
int main(){
	solved();
	return 0;
} 

Measured memory_bytes: 3628
N = int(input())
K = int(input())
lst = input().split()

ans = 0

for i in range(N):
   x = int(lst[i])
   if abs(x) < abs(K - x):
      ans += 2 * abs(x)
   else:
      ans += 2 * abs(K - x)

print(ans)

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

int main() {
  
  int n;
  cin >> n;
  vector<string> s(n);
  vector<long> march(5);
  for(int i = 0; i < n; i++) {
    cin >> s.at(i);
    if(s.at(i).at(0) == 'M') {
      march.at(0)++;
    }
    else if(s.at(i).at(0) == 'A') {
      march.at(1)++;
    }
    else if(s.at(i).at(0) == 'R') {
      march.at(2)++;
    }
    else if(s.at(i).at(0) == 'C') {
      march.at(3)++;
    }
    else if(s.at(i).at(0) == 'H') {
      march.at(4)++;
    }
  }
  
  long sum = 0;
  for(int i = 0; i < 3; i++) {
    for(int j = i+1; j < 4; j++) {
      for(int k = j+1; k < 5; k++) {
        sum += march.at(i) * march.at(j) * march.at(k);
      }
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 6144
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>;
using namespace std;
char s[100010];
inline void w(int k){
	if(k%2!=0){ 
        printf("No");
        return;
    }
    for(int i=0;i<k/2;i++){
    	int u=abs(s[i]-s[k-i-1]);
        if(u!=1&&u!=2){
        	printf("No");
            return;
        }
    }
	printf("Yes");
}
int main(){
    scanf("%s",&s);
    int k=strlen(s);
    w(k);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int32_t main(){
    fastio;
    int n,cont=0;
    cin >> n;
    vector<int> v(n);
    int maior = 0;
    for(int i=0;i<n;i++){
        cin >> v[i];
        if(v[i] >= maior){
            cont ++;
        }
        maior = max(v[i],maior);
    }
    cout << cont << endl;
} 

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

int main(){
  int h,w,x,y;
  cin>>h>>w>>x>>y;
  if(h%x==0&&w%y==0){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  if(w%y!=0){
    int vec[w];
    int big=10000*(y-1)-1,small=-10000;
    for(int i=0;i<w;i++){
      if(i%y==0){
        vec[i]=big;
      }
      else{
        vec[i]=small;
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cout<<vec[j]<<" ";
      }
      cout<<endl;
    }
    return 0;
  }
  int vec[h];
  int big=10000*(x-1)-1,small=-10000;
  for(int i=0;i<h;i++){
    if(i%x==0){
      vec[i]=big;
    }
    else{
      vec[i]=small;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<vec[i]<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=2e5+5;

int n, m;
set<int> g[N];

int32_t main()
{
	IOS;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u, v;
		cin>>u>>v;
		g[u].insert(v);
		g[v].insert(u);
	}
	for(int i=1;i<=n;i++)
	{
		if(g[i].find(1)!=g[i].end() && g[i].find(n)!=g[i].end())
		{
			cout<<"POSSIBLE";
			return 0;
		}
	}
	cout<<"IMPOSSIBLE";
	return 0;
}


Measured memory_bytes: 28416
#include <iostream>
#include <vector>

using namespace std;

#define M 1000000007

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<char>> grid(h, vector<char>(w, '.'));
    vector<vector<int>> dp(h, vector<int>(w, 0));

    for(int i=0; i<h; ++i) for(int j=0; j<w; ++j) cin >> grid[i][j];

    dp[0][0] = 1;
    for(int i=1; i<w; ++i) dp[0][i] = (grid[0][i] == '#') ? 0 : dp[0][i-1];
    for(int i=1; i<h; ++i) dp[i][0] = (grid[i][0] == '#') ? 0 : dp[i-1][0];

    for(int i=1; i<h; ++i)
    {
        for(int j=1; j<w; ++j)
        {
            if(grid[i][j] == '#') dp[i][j] = 0;
            else dp[i][j] = (dp[i-1][j]%M) + (dp[i][j-1]%M) % M;
        }
    }

    cout << dp[h-1][w-1]%M << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const ll MOD = 1e9+7;

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

  ll N, M;
  cin >> N >> M;
  ll ans = 0;
  if(N < M){
    swap(N, M);
  }

  if(N - M > 1){
    ans = 0;
  }else if(N==M){

    ll tmp = 1;
    for(int i = 1; i <= N; i++){
      tmp = (tmp * i) % MOD;
    }

    ans = ((2 * tmp) % MOD) * tmp % MOD;

  }else{
    ans = 1;
    for(int i = 1; i <= N; i++){
      ans = (ans * i) % MOD;
    }

    for(int i = 1; i <= M; i++){
      ans = (ans * i) % MOD;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
s=int(input())
def calc(n):
  if n % 2 == 0:
    return n / 2
  else:
    return 3*n +1
ans = [s]
for i in range(1000001):
  if calc(ans[i]) in ans:
    print(len(ans) +1)
    exit()
  else:
    ans.append(int(calc(ans[i])))

Measured memory_bytes: 9124
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let _n: usize = get_input().parse().unwrap();

    let (_, j): (i64, i64) = get_input().split_whitespace().fold((0, 0), |max, a| {
        let ia = a.parse().unwrap();
        if ia >= max.0 {
            (ia, max.1 + 1)
        } else {
            max
        }
    });

    println!("{}", j);
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>

int main(){
    int N;
    std::cin >> N;
    std::vector<int> A(N, 0);
    for(int i = 0; i < N; i++) std::cin >> A[i];

    for(int i = 0; i < N; i++){
        if(A[i] % 2 == 0){
            // 偶数
            if(A[i] % 3 == 0 || A[i] % 5 == 0){
                // pass
            }else{
                std::cout << "DENIED" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "APPROVED" << std::endl;
    return 0;
}

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

#define ff              first
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


const int N = 3e5, M = N;
//=======================


void solve() {
  int i, j, n, m;
  string str;
  cin>>str;
  n=str.length();
  if(str[n-1]=='s'){
    str+="es";
  }
  else{
    str+="s";
  }
  cout<<str;
}

int32_t main()
{
  FIO;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  
  solve();
  return 0;
}


Measured memory_bytes: 3664
// https://atcoder.jp/contests/abc044/tasks/abc044_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    unordered_map<char, int> mp;
    for (auto &x : s)
        mp[x]++;
    bool flag = true;
    for (auto &x : mp) {
        if (x.second % 2 == 1) {
            flag = false;
            break;
        }
    }
    if (flag) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    int n, m, tmp1, tmp2;
    cin >> n >> m;

    Graph G(n);

    for (int i = 0; i < m; i++) {
        cin >> tmp1 >> tmp2;
        G[tmp1-1].push_back(tmp2-1);
        G[tmp2-1].push_back(tmp1-1);
    }

    vector<int> dist(n, -1);
    vector<int> ans(n, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (int nv : G[v]) {
            if (dist[nv] != -1) continue;

            dist[nv]++;
            que.push(nv);
            if (ans[nv] == -1) ans[nv] = v + 1;
        }

    }
    ans[0] = 1;
    for (int i = 0; i < n; i++) {
        if (ans[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << ans[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 10748
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    
    vector<int> Time{A, B, C, D, E};
    vector<int> NextTime(5);
    
    for(int i = 0; i < 5; i++){
        if (Time[i] % 10 == 0) NextTime[i] = Time[i];
        else{
            NextTime[i] = Time[i] - Time[i] % 10 + 10;
        }
    }
    
    int BestTime = 99999;
    
    for (int i = 0; i < 5; i++){
        int SumTime = 0;
        for (int j = 0; j < 5; j++){
            if (i == j){
                SumTime += Time[i];
            }
            else{
                SumTime += NextTime[j];
            }
        }
        BestTime = min(BestTime, SumTime);
    }
    
    cout << BestTime << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

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

    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    REP(i, N) cin >> h[i];

    int dp[N + 1];

    dp[0] = 0;
    FOR(i, 1, N) {
        dp[i] = INF32;
        FOR(j, 1, K + 1) {
            if (i - j >= 0)
                chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            else
                break;
        }
    }

    cout << dp[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int onum= sc.nextInt();

		for(int i=0; i<onum; i++) {
			String order = sc.next();
			if(order.equals("replace")) {
				int ini=sc.nextInt(),end=sc.nextInt();
				String rep=sc.next();
				str=str.substring(0,ini) + rep + str.substring(end+1,str.length());
			}else if(order.equals("print")) {
				int ini = sc.nextInt(),end=sc.nextInt();
				System.out.println(str.substring(ini,end+1));
			}else if(order.equals("reverse")) {
				int ini= sc.nextInt(),end=sc.nextInt();
				char[] sub= str.substring(ini,end+1).toCharArray();
				String rev="";
				for(int j=sub.length-1; j>=0; j--) {
					rev+=sub[j];
				}
				str = str.substring(0,ini) + rev + str.substring(end+1,str.length());
			}
		}
	}
}


Measured memory_bytes: 46748
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>

using namespace std;


int main() {
	int N, Answer = 0;
	cin >> N;
	int A;
	for (int i = 0; i < N; i++) {
		cin >> A;
		while (A % 2 == 0) {
			A /= 2;
			Answer++;
		}	
	}
	cout << Answer << endl;
	return 0;
}

Measured memory_bytes: 256
rows, cols = (int(x) for x in input().split())

table = []
for r in range(rows):
    line = input().split()
    row = [int(x) for x in line]
    table.append(row)

final_row = [0] * (cols + 1)
for r in range(rows):
    table[r].append(sum(table[r]))
    for c in range(cols + 1):
        final_row[c] += table[r][c]
table.append(final_row)

for r in range(rows+1):
    line = ""
    for c in range(cols+1):
        line += str(table[r][c]) + " "
    print(line.strip())


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

def primes(n):
    from math import sqrt
    p = [1] * (n + 1)
    for x in range(2, int(sqrt(n)) + 1):
        if p[x]:
            p[x * 2:n + 1:x] = [0] * ((n - x) // x)
    return (i for i in range(2, n + 1) if p[i])

prime_numbers = list(primes(1000))

from collections import defaultdict

cs = defaultdict(int)

for x in range(1, N + 1):
    for n in prime_numbers:
        while x % n == 0:
            cs[n] += 1
            x //= n

result = 1

MOD = 10**9 + 7

for x in cs.values():
    result = result * (x + 1) % MOD

print(result)



Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	int N,M,K;
	cin>>N>>M>>K;
	bool pos=false;
	rep(i,N+1)rep(j,M+1)if(K==i*(M-j)+(N-i)*j)pos=true;
	if(pos)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
int n,m;
vector<P> e[111];
int f[111][111];

int d[111];
bool vi[111];
void ff(int k){
  if(vi[k]) return;
  vi[k] = true;
  for(int i = 0; i < (int)e[k].size(); i++){
    int v = e[k][i].F;
    int c = e[k][i].S;
    if(d[k]-c == d[v]){
      f[k][v] = f[v][k] = 0;
      ff(k);
    }
  }
}


void dij(int x){
  for(int i = 0; i < n; i++) d[i] = 1<<28;
  priority_queue<P,vector<P>,greater<P> > que;
  
  d[x] = 0;
  que.push(make_pair(0,x));
  while(!que.empty()){
    int c = que.top().F;
    int v = que.top().S;
    que.pop();
    if(d[v] < c) continue;
    for(int i = 0; i < (int)e[v].size(); i++){
      int u = e[v][i].F;
      int cc = e[v][i].S;
      if(d[u] > d[v]+cc){
	d[u] = d[v]+cc;
	que.push(make_pair(d[u],u));
      }
    }
  }

  memset(vi,false,sizeof(vi));
  for(int i = 0; i < n; i++){
    ff(i);
  }
}

int main(void){
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    e[a].push_back(make_pair(b,c));
    e[b].push_back(make_pair(a,c));
    f[a][b] = f[b][a] = 1;
  }

  for(int i = 0; i < n; i++)
    dij(i);
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      ans += f[i][j];
      //if(f[i][j]) cout << i << "  " << j << endl;
    }
  }


  cout << ans/2 <<endl; 
}


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

int main(){
    int c[3];

    while(cin >> c[0] >> c[1] >> c[2]){
        int sum = c[0] + c[1];
        int safe = 0;
        for(int i=1; i<=10; ++i){
            if(i==c[0]||i==c[1]||i==c[2]) continue;
            if((sum + i) <= 20) ++safe;
        }
        cout << ((safe/7.0 >= 0.5)?"YES":"NO") << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define ll long long
using namespace std;

const ll MOD = 1e9 + 7;

ll tousa(ll a, ll l, ll n)
{
    return n * (a + l) / 2;
}

int main()
{
    ll ans = 0;
    ll mis_ans = 0;
    ll r = 0, g = 0, b = 0;
    ll N;
    cin >> N;
    string S;
    cin >> S;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == 'R')
            r++;
        if (S[i] == 'G')
            g++;
        if (S[i] == 'B')
            b++;
    }
    ans = r * g * b;
    for (int i = 1; i <= N - 2; i++)
    {
        for (int j = i + 1; j <= N - 1; j++)
        {
            int k = 2 * j - i;
            if (k <= N)
            {
                if (S[i - 1] != S[j - 1] && S[k - 1] != S[j - 1] && S[i - 1] != S[k - 1])
                {
                    mis_ans++;
                }
            }
        }
    }
    cout << ans - mis_ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>

using namespace std;

const int MOD = 998244353;

int main(){
    int N; cin >> N;
    string X; cin >> X;
    vector<long long> div;
    for(int i=1;i<=N;i++) if(N%i == 0 && N/i%2 == 1) div.push_back(i);
    vector<long long> cnt(N+1, 0);
    long long res = 0;
    for(auto& d : div){
        string s[2] = {"", ""};
        long long num = 0;
        for(int i=0;i<d;i++){
            num = (2 * num + X[i] - '0') % MOD;
            s[0] += X[i];
            s[1] += X[i] == '0' ? '1' : '0';
        }
        bool ok = true;
        for(int i=0;i<N;i++){
            if(X[i] < s[i/d%2][i%d]) { ok = false; break; }
            if(X[i] > s[i/d%2][i%d]) break;
        }
        cnt[d] = (num + (ok ? 1 : 0)) % MOD;
        for(auto& d2 : div){
            if(d2 >= d) break;
            if(d%d2 == 0) cnt[d] = (cnt[d] + MOD - cnt[d2]) % MOD;
        }
        res = (res + cnt[d] * 2 * d) % MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 2556
//Keep working hard :)
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

const int N = 1e5+5;
int a[N];

void fileIO()
{
        #ifndef ONLINE_JUDGE
        freopen("int.txt","r",stdin);
        freopen("out.txt","w",stdout);
        #endif
}
int main()
{
	IOS;
    //fileIO();
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(a+b,min(b+c,c+a));
	return 0;
}


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

int main(){
  vector<int64_t> L(87);
  for (int i = 0; i <= 86; i++){
    if (i == 0){
      L.at(i) = 2;
    }
    if (i == 1){
      L.at(i) = 1;
    }
    if (i > 1){
      L.at(i) = L.at(i-1) + L.at(i-2);
    }
  }
  
  int N;
  cin >> N;
  cout << L.at(N) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define llint long long
#define pii pair<int, int>
#define UNVISITED -1


template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}
 
template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

const ll mod = 1000000007;

// i + 1, i - 1 + s

const int MAX = 2020;
ll C[MAX][MAX];
void init() {
    REP(i, MAX) {
        C[i][0] = C[i][i] = 1;
        for(int j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j])%mod;
    }
}

int main() {
    init();
    int S; scanf("%d", &S);
    int i = 1;
    ll ans = 0;
    while(3*i <= S) {
        ll s = S - 3*i;
        ll c = C[i - 1 + s][s];
        ans = (ans + c)%mod;
        i++;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 26792
#include<iostream>

using namespace std;

int main(){
	int q_lower,bud,c_aizu,c_normal,q_aizuupper;
	while(cin>>q_lower>>bud>>c_aizu>>c_normal>>q_aizuupper){
		int q_aizu=0,q_normal=0;
		q_aizu+=q_aizuupper;
		bud-=q_aizu*c_aizu;
		if(bud<0){
			while(bud<0){
				q_aizu--;
				bud+=c_aizu;
			}
			if(q_aizu<=0){
				cout<<"NA"<<endl;
				continue;
			}
		}
		q_normal+=bud/c_normal;
		bud-=q_normal*c_normal;

		while(q_aizu+q_normal<q_lower && q_aizu>0){
			q_aizu--;
			bud+=c_aizu;
			q_normal+=bud/c_normal;
			bud-=(bud/c_normal)*c_normal;
		}
		if(q_aizu<=0){
			cout<<"NA"<<endl;
			continue;
		}
		if(q_aizu+q_normal>=q_lower)	cout<<q_aizu<<' '<<q_normal<<endl;
		else	cout<<"NA"<<endl;
	}

	return 0;
}

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

using namespace std;

#define LL long long

#define MAX_N 55
#define MAX_M MAX_N*MAX_N
int N;
int A;
int X[MAX_N];

LL dp[MAX_N][MAX_N][MAX_M];

void calc()
{
  memset(dp, 0, sizeof(dp));
  dp[0][N][0] = 1;
  for (size_t i = 0; i < N; i++) {
    for (size_t j = 0; j < MAX_M; j++) {
      for (size_t k = 0; k <= N; k++) {
        dp[i+1][k][j] += dp[i][k][j];
        if(k > 0){
          dp[i+1][k-1][j+X[i]] += dp[i][k][j];
        }
      }
    }
  }
}

LL DP(int k, int n)
{
  return dp[N][N-k][n];
}

int main()
{
  cin >> N >> A;
  for (size_t i = 0; i < N; i++) {
    cin >> X[i];
  }

  calc();

  LL ans = 0;
  for (size_t i = 1; i <= N; i++) {
    ans += DP(i, i*A);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 71680
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        // long K = sc.nextLong();
        // int[] A = new int[N];
        int max = -1;
        int min = 1000000001;
        for(int i=0; i<N; i++){
            int a = sc.nextInt();
            if(a>max){
                max = a;
            }
            if(a<min){
                min = a;
            }
        }

        System.out.println(max - min);
        
        sc.close();

    }
}      

Measured memory_bytes: 23892
#include<iostream>
#include<algorithm>
#include<vector>

#define rep(i,n) for(int i = 0; i < n; ++i)
#define reps(i,f,n) for(int i = f; i <= n; ++i)
#define eb emplace_back
#define all(x) x.begin(), x.end()

using namespace std;
using PII=pair<int,int>;
using PPI=pair<int,PII>;

class UF{
public:
  vector<int> p; //parent->マイナスだとルート． 
  UF(int n){p.resize(n, -1);}
  int root(int x){return p[x] < 0 ? x : p[x] = root(p[x]);}

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

  void unite(int x, int y){
    x = root(x);y = root(y);
    if(x == y) return;
    if( p[y] < p[x]) swap(x,y); //p[x] < p[y]にする xの方が絶対値がおっきい
    p[x] += p[y];
    p[y] = x;
  }
  int size(int x){
    return -p[root(x)];
  }
};

vector<PPI> edges;

int main(void){
  int n;
  vector<PII> X;
  vector<PII> Y;
  int x, y;

  cin >> n;
  rep(i, n){
    cin >> x;
    cin >> y;
    X.eb(PII(x, i));
    Y.eb(PII(y, i));
  }

  sort(all(X));
  sort(all(Y));

  rep(i,n-1){
    edges.eb(PPI(X[i+1].first - X[i].first, PII(X[i].second, X[i+1].second)));
    edges.eb(PPI(Y[i+1].first - Y[i].first, PII(Y[i].second, Y[i+1].second)));
  }

  sort(all(edges));
  UF uf(n);
  int ans = 0;
  rep(i, edges.size()){
    x = edges[i].second.first;
    y = edges[i].second.second;
    if(!uf.same(x,y)){
      uf.unite(x, y);
      ans += edges[i].first;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7144
#include<bits/stdc++.h>
#define Open(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout);
#define inl inline
#define reg register
#define i64 long long 
using namespace std;
inl int read(){int x=0,f=0;char ch=0;while(!isdigit(ch))f|=(ch=='-'),ch=getchar();while(isdigit(ch))(x*=10)+=(ch^48),ch=getchar();return f?-x:x;}
inl void Ot(reg int x){if(x<0)x=-x,putchar('-');if(x>=10)Ot(x/10);putchar(x%10+'0');}
inl void Print(reg int x,char til='\n'){Ot(x);putchar(til);}
inl int Max(reg int x,reg int y){return x>y?x:y;}
inl int Min(reg int x,reg int y){return x<y?x:y;}
inl int Abs(reg int x){return x<0?-x:x;}
const int MAXN=22;
int n,m;
char mp[MAXN][MAXN];
bool mark[MAXN][MAXN];
int mv[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct Node{
	int x,y;
	int step;
};
bool check(int x,int y){
	if(mark[x][y]||mp[x][y]=='#')return 0;
	if(x<1||x>n||y<1||y>m)return 0;
	return 1;
}
int bfs(int x,int y){
	queue<Node>que;
	que.push((Node){x,y,0});
	mark[x][y]=1;
	int ans=0;
	while(!que.empty()){
		Node h=que.front();
		que.pop();
		// printf("(%d %d) %d\n",h.x,h.y,h.step);
		ans=Max(ans,h.step);
		for(reg int i=0;i<4;i++){
			int nx=h.x+mv[i][0];
			int ny=h.y+mv[i][1];
			if(check(nx,ny)){
				mark[nx][ny]=1;
				que.push((Node){nx,ny,h.step+1});
			}
		}
	}
	return ans;
}
signed main(){
	#ifndef ONLINE_JUDGE
		//freopen("../../data.in","r",stdin);
	#endif
	n=read(),m=read();
	for(reg int i=1;i<=n;i++)
		for(reg int j=1;j<=m;j++)
			cin>>mp[i][j];
	int ret=0;
	// printf("%d\n",bfs(3,1));
	for(reg int i=1;i<=n;i++)
		for(reg int j=1;j<=m;j++){
			memset(mark,0,sizeof(mark));
			if(mp[i][j]=='.')
			ret=Max(ret,bfs(i,j));
		}
	Print(ret);
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;

//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(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

inline ll floor(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return a / llb;
	}
	else
	{
		return - ( (-a + llb - 1) / llb);
	}
}

inline ll ceil(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return (a + llb - 1) / llb;
	}
	else
	{
		return - (-a / llb);
	}
}

inline ll getLowestOneBit(ll a)
{
	return a & (-a);
}

inline ll getHighestOneBit(ll a)
{
	while ((a & (a - 1)) != 0)
	{
		a = a & (a - 1);
	}
	return a;
}

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getSpecifiedBit(ll a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, ull exponential)
{
	Integer result = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			result = result * base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return result;
}

ll get_value(ll i, vector<ll>& results, const vector<pair<ll, ll>>& keys) {
	if (results[i] != -2) return results[i];

	ll res = 1LL << 62, val;
	bool can_open = false;
	for (ll j = 0; j < keys.size(); ++j)
	{
		ll cost = keys[j].first;
		ll mask = keys[j].second;
		
		if (i == (i & ~mask) || (val = get_value(i & ~mask, results, keys)) == -1) continue;
				
		can_open = true;
		res = min(res, cost + val);
	}
	if (can_open) results[i] = res;
	else results[i] = -1;

	return results[i];
}

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

	ll N, M;
	cin >> N >> M;

	vector<pair<ll, ll>> keys;
	keys.reserve(M);
	ll a, b, c, mask;
	for (ll i = 0; i < M; ++i)
	{
		cin >> a >> b;
		mask = 0;
		for (ll j = 0; j < b; ++j)
		{
			cin >> c;
			mask |= 1 << (c - 1);
		}
		keys.emplace_back(a, mask);
	}

	vector<ll> results(1 << N, -2);
	results[0] = 0;

	cout << get_value((1 << N) - 1, results, keys) << endl;

	return 0;
}


Measured memory_bytes: 256
import itertools
import numpy as np
n,m,q=map(int, input().split())  
a=[list(map(int, input().split())) for i in range(m)]
b=[list(map(int, input().split())) for i in range(q)]

x=[[0]*(501) for i in range(501)]

for i in range(m):
    x[a[i][0]][a[i][1]]+=1



for i in range(501):
    x[i] = list(itertools.accumulate(x[i]))
  
x=np.array(x)
for i in range(501):
    x[:,i] = list(itertools.accumulate(x[:,i]))



for i in range(q):
    v1=b[i][0]
    v2=b[i][1]
    
    a1=x[v2,v2]
    a2=x[v2,v1-1]
    a3=x[v1-1,v2]
    a4=x[v1-1,v1-1]
    print(a1-a2-a3+a4)


 







Measured memory_bytes: 81548
#include <bits/stdc++.h>
using namespace std;
bool strFind(vector<string> str, string word, int n)
{
    for(int i = 0; i < n; i++){
        if(str[i] == word){
            return false;
        }
    }
    return true;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    vector<string> str(n);
    bool found = true;
    for(int i = 0; i < n; i++){
        cin >> str[i];
        //found = true;
        if(i > 0){
            //found = strFind(str, str[i], i);
            if(strFind(str, str[i], i) == false) {
                //cout << "in1" << endl;
                found = false;
                //break;
            }
            string wordLast = str[i-1], wordCurrent = str[i];
            if(wordCurrent[0] != wordLast[wordLast.length()-1]){
                found = false;
                //cerr << wordLast[wordLast.length()-1] << endl;
            }
        }

    }
    if(found == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
//    sort(str.begin(), str.end());
//    for(auto x : str){
//        auto a = lower_bound(str.begin(), str.end(), x) - str.begin();
//        if(a >= n){
//            cout << "not found" << endl;
//        }else{
//            cout << a << endl;
//        }
//    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int gcd(int a, int b)
{
    int tmp;
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(void)
{
    int K;
    scanf("%d", &K);
    int S = 0;
    int x;
    int i,j,k;
    for (i = 1; i <= K; i++) {
        for (j = 1; j <= K; j++) {
            for (k = 1; k <= K; k++) {
                x = gcd(i,j);
                S += gcd(x,k);
            }
        }
    }

    printf("%d", S);

    return 0;
}

Measured memory_bytes: 1732
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE TypeApplications #-}
-- {-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Control.Monad
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn @Int
  xs <- U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let m = U.maximum xs
  let vec :: U.Vector Int
      vec = U.create $ do
        vec <- UM.replicate (m+1) 0
        U.forM_ xs $ \x -> do
          UM.modify vec (+ 1) x
          forM_ [2*x,3*x..m] $ \i -> do
            UM.modify vec (+ 2) i
        return vec
  print $ length [ () | x <- U.toList xs, vec U.! x <= 1 ]


Measured memory_bytes: 18600
x = int(input())
if 400<= x and x<=599:
    print(8)
if 600<= x and x<=799:
    print(7)
if 800<= x and x<=999:
    print(6)
if 1000<= x and x<=1199:
    print(5)
if 1200<= x and x<=1399:
    print(4)
if 1400<= x and x<=1599:
    print(3)
if 1600<= x and x<=1799:
    print(2)
if 1800<= x and x<=1999:
    print(1)



Measured memory_bytes: 9184
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)    {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for((i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(int,n,k);
  int i;
  int l[1000]={};
  rep(i,n)cin>>l[i];
  sort(l,l+n);
  int sum=0;
  int j=0;
  for(i=n-1;j++<k;i--)
    sum+=l[i];
  cout<<sum<<endl;
  return 0;
}


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

// main.cpp

int main() {
  std::int_fast64_t N, C, K;
  std::cin >> N >> C >> K;
  std::vector<std::int_fast64_t> T;
  T.reserve(N);
  std::copy_n(std::istream_iterator<std::int_fast64_t>(std::cin), N, std::back_inserter(T));

  std::sort(T.begin(), T.end());
  std::int_fast64_t front = 0;
  std::int_fast64_t answer = 0;
  while (front < N) {
    const std::int_fast64_t waiting = std::distance(std::lower_bound(T.rbegin(), T.rend(), T[front] + K, std::greater<std::int_fast64_t>()), T.rend()) - front;
    front += std::min(waiting, C);
    ++answer;
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i=1;;i++){
            int x = sc.nextInt();
            if(x == 0)break;
            System.out.printf("Case %d: %d\n",i,x);
        }
    }
}


Measured memory_bytes: 66716