akhauriyash/Code-Regression huggingface dataset:
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b;
	cin>>a>>b;
	ll gg=gcd(a,b);
	ll ans=1;
	for(ll i=2;i*i<=gg;i++)
	{
	    if(gg%i==0)
	    {
	        ans++;
	        while(gg%i==0)
	        {
	            gg/=i;
	        }
	    }
	}
	if(gg>1)
	    ans++;
	cout<<ans;
    return 0;
}


//252908XL

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define sz size()
#define pb push_back
#define print(x) cout << x << endl
int ans = 0;
int n,m;
int a,b,c;
int d[10000];
int dp[1001][1001];
vector<int> v;

int main(){
  string s;
  cin >> s;
  if(s[0] == s[2])print("Yes");
  else print("No");
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int a, b[1002], d[1002], c[1002], ca1, ca2, ca3, caa;
	scanf("%d", &a);
	for (int i = 1; i <= a; i++)
	{
		scanf("%d %d %d", &ca1, &ca2, &ca3);
		while (1)
		{
			if (ca2>ca1)
			{
				caa = ca1;
				ca1 = ca2;
				ca2 = caa;
			}
			if (ca3>ca2)
			{
				caa = ca2;
				ca2 = ca3;
				ca3 = caa;
			}
			if (ca1 >= ca2&&ca2 >= ca3)break;
		}
		b[i] = ca1; c[i] = ca2; d[i] = ca3;
	}
	for (int i = 1; i <= a; i++)
	{
		if (b[i] * b[i] == (c[i] * c[i]) + (d[i] * d[i]))
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1020
/*raghav0307 - Raghav Gupta*/

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int ll

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;

signed main(){
	fast_io();
	int n, m;
	cin >> n >> m;
	pii a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i].ff >> a[i].ss;
	}
	sort(a, a+n);
	priority_queue<int> pq;
	int pos = 0;
	int ans = 0;
	for(int i = 1; i <= m; i++){
		while(a[pos].ff <= i){
			pq.push(a[pos].ss);
			pos++;
		}
		if(!pq.empty()){
			auto x = pq.top(); pq.pop();
			ans += x;
		}
	}
	cout << ans;
	return 0;
}

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

int main()
{
  int a,b,c;
  cin >>a>>b>>c;
  cout << min(a*b,c) << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define MAXN 200005
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;
    cin>>n;
    ll res=0;
    if(n>=500){
    	res+=1000*(n/500);
    }
    n%=500;
    res+=5*(n/5);
    cout<<res;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

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

    bool ans=true;
    vector<ll> a(n);

    rep(i,n){
        cin>>a[i];
        if(a[i] != 0) ans=false;
    }
    sort(all(a));
    
    if(ans==true){
        cout<<"Yes"<<endl;
        return 0;
    }//OK
    
    if(n%3 != 0){//OK
        cout<<"No"<<endl;
    }else{//OK
        if(a[0]==a[-1+ n/3] && a[n/3]==a[2*n/3 -1] && a[2*n/3]==a[n-1] && (a[0]^a[n-1])==a[n/3] && (a[0]^a[n/3])==a[n-1] && (a[n-1]^a[n/3])==a[0]){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

Measured memory_bytes: 1024
N, M, X=map(int, input().split())
mat=[[int(i) for i in input().split()] for _ in range(N)]
cost=-1

for i in range(1, 1 << N):
    cst=0
    x=[0]*M
    for j in range(N):
        if i & (1 << j) != 0:
            cst+=mat[j][0]
            for k in range(M):
                x[k]+=mat[j][k+1]
    all=True
    for j in x: 
        if j < X:
            all=False
            break
    if all:
        if cost<0:
            cost=cst
        else:
            cost=min(cost, cst)
print(cost)

Measured memory_bytes: 68724
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] x = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int[] cntm = new int[m];
		int[] cntx = new int[100001];
		for (int i = 0; i < n; i++) {
			cntm[x[i] % m]++;
			cntx[x[i]]++;
		}

		int ans = cntm[0] / 2;
		int m2 = (m + 1) / 2;
		if (m % 2 == 0) {
			ans += cntm[m2] / 2;
		}
		for (int i = 1; i < m2; i++) {
			if (cntm[i] < cntm[m - i]) {
				ans += cntm[i];
				int d = cntm[m - i] - cntm[i];
				d /= 2;
				int same = 0;
				for (int j = m - i; j < cntx.length; j+=m) {
					same += cntx[j] / 2;
				}
				ans += Math.min(same, d);
			} else {
				ans += cntm[m - i];
				int d = cntm[i] - cntm[m - i];
				d /= 2;
				int same = 0;
				for (int j = i; j < cntx.length; j+=m) {
					same += cntx[j] / 2;
				}
				ans += Math.min(same, d);
			}
		}
		System.out.println(ans);
	}
}


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

#define F first
#define S second
#define PB push_back
#define all(x) x.begin(), x.end()

typedef long long ll; 
typedef long double ld;

const int N = 200 * 1000 + 10, L = 20, mod = 998244353; 

vector<int> adj[N], ver[N];
int sum[N], mx[N];
int cnt[N];
int h[N];
int par[L][N], mxx[L][N];

int ipar(int x, int y)
{
	for(int i = 0; i < L; i++)
		if(y&(1<<i))
			x = par[i][x];
	return x;
}

int imax(int x, int y)
{
	int mx = x;
	for(int i = 0; i < L; i++)
		if(y&(1<<i))
			mx = max(mx, mxx[i][x]), x = par[i][x];
	return mx;
}

void dfs(int u, int p)
{
	par[0][u] = p;
	mxx[0][u] = u;
	for(int i = 1; i < L; i++)
	{
		par[i][u] = par[i-1][par[i-1][u]];
		mxx[i][u] = max(mxx[i-1][u], mxx[i-1][par[i-1][u]]);
	}
	for(auto v : adj[u])
	{
		if(v==p) continue;
		h[v] = h[u] + 1;
		mx[v] = max(mx[u], v);
		dfs(v, u);
	}
	if(mx[u] != u && mx[par[0][mx[u]]] < imax(u, h[u] - h[mx[u]]))
		mx[u] = ipar(u, h[u] - h[mx[u]] - 1);
	cnt[mx[u]]++;
}

void gfs(int u, int p)
{
	sum[u] += cnt[u];
	for(auto v : adj[u])
	{
		if(v==p) continue;
		sum[v] = sum[u];
		gfs(v, u);
	}
}

int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin>> n;
	for(int i = 1; i < n; i++)
	{
		int x, y;
		cin>> x >> y;
		adj[x].PB(y);
		adj[y].PB(x);
	}
	dfs(1, -1);
	gfs(1, -1);

	for(int i = 2; i <= n; i++) cout<< sum[i] << ' ';
	cout<< endl;
}


Measured memory_bytes: 61056
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
*/

main:-
    get_number(N),
    X is (N + 1) div 2 / N,
    writeln(X).


Measured memory_bytes: 8088
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int a[n],b[n];
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    vector<ll>sa(n);
    rep(i,n)sa[i] = a[i] - b[i];
    sort(all(sa));
    ll les = 0;
    int lcnt = 0;
    rep(i,n){
        if(sa[i] < 0){
            les += abs(sa[i]); 
            lcnt++;
        }
    }
    reverse(all(sa));
    ll yo = 0;
    int cnt = 0;
    while(yo < les){
        if(cnt >= n){
            cout << -1 << endl;
            return 0;
        }
        if(sa[cnt] < 0){
            cout << -1 << endl;
            return 0;
        }
        yo += sa[cnt];
        cnt++;
    }
    cout << lcnt + cnt << endl;
    //cout << les << ' ' << yo << endl;
    return 0;
}

Measured memory_bytes: 4752
#12653415
#わからんが、とてもきれいですね

N, M, Q = list(map(int, input().split()))
 
conditions = [list(map(int, input().split())) for _ in range(Q)]
 
def dfs(A, max_a):
    if len(A) == N:
        num = 0
        for a, b, c, d in conditions:
            if A[b-1] - A[a-1] == c:
                num += d
        return num
    ans = 0
    for i in range(max_a, M+1):
        ans = max(ans, dfs(A + [i], i))
    return ans
 
print(dfs([1], 1))

Measured memory_bytes: 9132
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<list>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
ll n, m, a, b, c;

int main() {
   cin >> s;
   if (s == "Sunny")cout << "Cloudy" << endl;
   if (s == "Cloudy")cout << "Rainy" << endl;
   if (s == "Rainy")cout << "Sunny" << endl;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
li = []
for n in range(M):
    A,B = map(int, input().split())
    li.append([A,B])
p = []
q = []
for i in li:
    if i[0]==1:
        p.append(i[1])
for i in li:
    if i[1]==N:
        q.append(i[0])
if set(p) &set(q):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE ')

Measured memory_bytes: 45468
import java.util.*;

public class Main {
    public static void main(String[] args){
        
        Scanner cin = new Scanner(System.in);
        
        int N = cin.nextInt();
        int M = cin.nextInt();
        cin.close();
        long result = 0;
        long tmp =1;
        long mod = (long)(Math.pow(10,9)+7);
        
        if(N-M>1||N-M<-1){
            tmp = 0;
        }else if(N==M){
            for(int i=2;i<=N;i++){
                tmp = (tmp*i)%mod;
                tmp = (tmp*i)%mod;
            }
            tmp = tmp*2;
        }else{
            int big = Math.max(N,M);
            int small = Math.min(N,M);
            for(int j=1;j<=big;j++){
                if(j<=small){
                    tmp = (tmp*j)%mod;
                    tmp = (tmp*j)%mod;
                }else{
                    tmp = tmp*j%mod;
                }
            }
        }
        result = tmp%mod;
        System.out.println(result);
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=1000005;
#define M 1000000007
#define double long double
#define init(arr,val) memset(arr,val,sizeof(arr))
#define BINF 1000000000001
const int LG = 22;




#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);
    


    int n;
    cin >> n;
    vector<pair<int,int>>v;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v.pb(mp(x, i));
    }

    sort(v.begin(), v.end());
    for(int i = 0; i < n; i++)
        cout << v[i].S + 1<< ' ';



    

return 0;  
}


Measured memory_bytes: 2544
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pi 3.14159265358979323846
#define INF 100000000000000000

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

int main(){
	ll n;cin>>n;
	vector<vector<ll>> abc(n,vector<ll>(3));
	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++){
			cin>>abc[i][j];
		}
	}

	vector<vector<ll>> dp(n+1,vector<ll>(3,0));//dp[i][j]...i日目に(a+'j')のactivityを行う

	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++){//前に(a+'j')のactivityを行ったら、次の日はそれ以外のactivityしかできない
			chmax(dp[i+1][(j+1)%3],dp[i][j]+abc[i][j]);
			chmax(dp[i+1][(j+2)%3],dp[i][j]+abc[i][j]);
		}
	}

	ll MAX=-1;
	for(ll j=0;j<3;j++){
		chmax(MAX,dp[n][j]);
	}

	cout<<MAX<<endl;
	return 0;
}

Measured memory_bytes: 11136
import java.io.*;

/**
 * Copyright © 2018 Chris. All rights reserved.
 *
 * @author Chris
 * 2018/6/23 11:55
 * @see meituan.n2018.Bturn
 */
public class Main {


    private static BufferedReader br;
    private static StreamTokenizer st;
    private static PrintWriter pw;

    
    private static void solve() throws IOException {
        int n = nextInt();
        int i = nextInt();
        
        pw.print(n - i + 1);
    }

    public static void main(String args[]) throws IOException {
//        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
//        if (!oj) {
//            System.setIn(new FileInputStream("src/in.txt"));
//        }
        br = new BufferedReader(new InputStreamReader(System.in));
        st = new StreamTokenizer(br);
        pw = new PrintWriter(new OutputStreamWriter(System.out));
        st.ordinaryChar('\''); //指定单引号、双引号和注释符号是普通字符
        st.ordinaryChar('\"');
        st.ordinaryChar('/');

        long t = System.currentTimeMillis();
        solve();
//        if (!oj) {
//            pw.println("[" + (System.currentTimeMillis() - t) + "ms]");
//        }
        pw.flush();
    }


    private static int nextInt() throws IOException {
        st.nextToken();
        return (int) st.nval;
    }

    private static long nextLong() throws IOException {
        st.nextToken();
        return (long) st.nval;
    }

    private static double nextDouble() throws IOException {
        st.nextToken();
        return st.nval;
    }

    private static String[] nextSS(String reg) throws IOException {
        return br.readLine().split(reg);
    }

    private static String nextLine() throws IOException {
        return br.readLine();
    }
}

Measured memory_bytes: 21076
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

template<typename M, typename N>
istream& operator>>(istream&is, pair<M,N> & p){is >> p.first >> p.second; return is;}
template<typename M>
istream& operator>>(istream&is, vector<M> & v){for(auto &it:v) is >> it; return is; }
template<typename M>
istream& operator>>(istream&is, vector<vector<M>> & v){for(auto &it:v) is >> it; return is; }
template<typename M, typename N>
ostream& operator<<(ostream&os, const pair<M,N> &p){os << p.fi << ' ' << p.se << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<M> &v){for(auto it: v)os << it << ' ';cout << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<vector<M>> &v){for(auto it: v)os << it;return os;}

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
#define acc(x) accumulate((x).begin(),(x).end(),0ll)
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ld pi=acos(-1);
const ll inf=(ll)1e9+10;
//const int mod=1000000007;
const int mod=998244353;

int n,m,k;
const int N=3e5+10;




int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s;
    cin >> s;
    if(s.back()=='s'){
        s+="es";
    }
    else{
        s+='s';
    }
    cout << s << el;
    return 0;
}








Measured memory_bytes: 3656
#include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const int MOD=(1e9)+7;
const int mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>n>>m;
  if(-n==m) cout <<"0\n";
  else if(m+n>0) cout <<"1\n";
  else cout <<"-1\n";
  return (0);
}


Measured memory_bytes: 3148
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, Z: int):
    print(Z,X,Y)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    solve(X, Y, Z)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int ans = 0, tmp = 0;
  for(int i=0; i<3; ++i){
    if(S[i] == 'R') ++tmp;
    else tmp = 0;
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
#!/usr/bin/env python3
import sys



def solve(H: int, W: int, A: "List[str]"):
    current = set()
    for i in range(H):
        for j in range(W):
            if not A[i][j]:
                current.add((i,j))
    def appendIfPossible(i,j,s):
        if i >= 0 and i < H and j >=0 and j < W and A[i][j]:
            s.add((i,j))
            A[i][j] = False
    count = 0
    while True:
        next = set()
        for c in current:
            appendIfPossible(c[0]-1,c[1],next)
            appendIfPossible(c[0]+1,c[1],next)
            appendIfPossible(c[0],c[1]-1,next)
            appendIfPossible(c[0],c[1]+1,next)
        current = next
        count+= 1
        if len(next) == 0:
            break
    print(count-1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [list(map(lambda x:x=='.',next(tokens))) for _ in range(H)]  # type: "List[str]"
    solve(H, W, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 130520
#include <bits/stdc++.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) FOR(i,0,n)

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, x;
	cin >> n >> x;
	int m[n];
	int min = 1000;
	int sum = 0;
	rep(i, n){
		cin >> m[i];
		if (min > m[i])
		{
			min = m[i];
		}
		sum += m[i];
	}

	x -= sum;
	int q;
	q = x/min;

	cout << n + q << endl;
	return 0;
}

Measured memory_bytes: 256
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fill(x,c) memset(x,c,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int SIZE = 1e6+10;
ll a[SIZE];
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin>>n;
	rep(i,0,n){
		cin>>a[i];
	} 
	ll ans=0,mx = mod;
	for(int i=0;i<n;i++){
		mx = min(mx,a[i]);
		if(a[i]<=mx)ans++;
	}
	cout<<ans;
  	return 0;
}


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

int main(){
  long int A,B;
  cin>>A>>B;
  int tmp,r;
  long int x=A*B;
  if(A<B){
    tmp=A;
    A=B;
    B=tmp;
  }
 
  r=A%B;
  while(r!=0){
    A=B;
    B=r;
    r=A%B;
  }
  
  long int res=x/B;
  cout<<res<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
vector<P> v1,v2,v3,v4;
ll r,c,n;
ll last_idx[100005]={0};
bool judge(ll x1,ll y1,ll x2,ll y2){
  if((x1!=0&&x1!=r)&&(y1!=0&&y1!=c)) return false;
  if((x2!=0&&x2!=r)&&(y2!=0&&y2!=c)) return false;
  return true;
}
void add(ll x,ll y,ll z){
  if(y==0) v1.push_back(P(x,z));
  else if(y==c) v3.push_back(P(-x,z));
  else if(x==r) v2.push_back(P(y,z));
  else if(x==0) v4.push_back(P(-y,z));
}
int main(){
  cin>>r>>c>>n;
  for(int i=1;i<=n;i++){
    ll x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    if(judge(x1,y1,x2,y2)){
      add(x1,y1,i);
      add(x2,y2,i);
    }
  }
  sort(v1.begin(),v1.end());
  sort(v2.begin(),v2.end());
  sort(v3.begin(),v3.end());
  sort(v4.begin(),v4.end());
  vector<ll> vec;
  for(int i=0;i<v1.size();i++) vec.push_back(v1[i].second);
  for(int i=0;i<v2.size();i++) vec.push_back(v2[i].second);
  for(int i=0;i<v3.size();i++) vec.push_back(v3[i].second);
  for(int i=0;i<v4.size();i++) vec.push_back(v4[i].second);

  for(int i=0;i<vec.size();i++) last_idx[vec[i]]=i;
  stack<ll> que;
  priority_queue<P,vector<P>,greater<P>> pque;
  for(int i=0;i<vec.size();i++){
    if(i!=last_idx[vec[i]]){
      que.push(vec[i]);
      pque.push(P(last_idx[vec[i]],vec[i]));
    }
    else{
      ll num=que.top();
      que.pop();
      P p=pque.top();
      pque.pop();
      if(num!=p.second){
        cout<<"NO"<<endl;
        return 0;
      }
    }
  }
  cout<<"YES"<<endl;
  return 0;
}


Measured memory_bytes: 7984
#include <stdio.h>

int main(void){
  
  int A, H, ATK;
  
  scanf("%d%d", &H, &A);
  if(H % A == 0){
    ATK = H / A;
  }
  else
  {
    ATK = H / A + 1;
  }
  printf("%d", ATK);
  
  return(0);
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  string S; cin >> S;
  cout << S.substr(0, 3) << endl;
}

Measured memory_bytes: 3616
s = input()
res = [0] * len(s)
cnt = 0
for i in range(len(s)):
    if s[i] == "R":
        cnt += 1
    else:
        res[i-1] += (cnt+1)//2
        res[i] += cnt//2
        cnt = 0
cnt = 0
for i in range(1, len(s)+1):
    if s[-i] == "L":
        cnt += 1
    else:
        res[-i] += cnt//2
        res[-i+1] += (cnt+1)//2
        cnt = 0
print(*res)

Measured memory_bytes: 47676
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a = Is()
print(sum(a)-max(a))


Measured memory_bytes: 4584
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
//int dx[]={+1,-1,+0,+0};///Four Directions
//int dy[]={+0,+0,+1,-1};///Four directions
//int dx [] = {+1,-1,+0,+0,-1,-1,+1,+1};///Eight Directions
//int dy [] = {+0,+0,+1,-1,+1,-1,-1,+1};///Eight Directions

//int mark[10007];vi prime;void seive(){for(int i=2;i<10000;i++){if(mark[i]==0){prime.pb(i);for(int j=i+i;j<=10000;j+=i)mark[j]=1;}}}

//freopen("input.txt", "r", stdin);

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

   int n,m; cin>>n>>m;

   vi v(m+3);
   for(int i=0;i<m;i++) cin>>v[i];

   for(int i=0;i<m;i++) n-=v[i];

   if(n<0) cout<<-1<<endl;
   else cout<<n<<endl;
   End;
}


Measured memory_bytes: 3700
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define repe(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repi(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
void out(pair<int, int> a) {
	rep(i, abs(a.first)) {
		if (a.second == 'U') {
			cout << (a.first >= 0 ? "U" : "D");
		}
		else {
			cout << (a.first >= 0 ? "R" : "L");
		}
	}
}
int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	list<pair<int, char>>a;
	int dy = ty - sy;
	int dx = tx - sx;
	a.push_back({ -1, 'L' });
	a.push_back({ dy+1, 'U' });
	a.push_back({ dx + 1, 'L' });
	a.push_back({ -1, 'U' });
	a.push_back({ -dx, 'L' });
	a.push_back({ -dy, 'U' });
	a.push_back({ dx, 'L' });
	a.push_back({ dy, 'U' });
	a.push_back({ 1, 'L' });
	a.push_back({ -dy-1, 'U' });
	a.push_back({ -dx - 1, 'L' });
	a.push_back({ 1, 'U' });
	for (auto v : a) {
		out(v);
	}
	return 0;
}

Measured memory_bytes: 256
use std::cmp;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let h: usize = sc.read();
    let w: usize = sc.read();
    let n: usize = sc.read();
    let m = cmp::max(h, w);
    let ans = (n + m - 1) / m;
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()


void solve(){
  std::cout << std::fixed << std::setprecision(20);
  int n, m; cin >> n >> m;
  vector<pair<int,int>> edge(m); vector<int>  from(n+5,0), to(n+5,0);
  vector<vector<int>> egf(n+1), egt(n+1);
  FOR(i,0,m) {
    cin >> edge[i].first >> edge[i].second;
    --edge[i].first;
    --edge[i].second;
    ++from[edge[i].first];
    ++to[edge[i].second];
    egf[edge[i].second].push_back(edge[i].first);
    egt[edge[i].first].push_back(edge[i].second);
  }
  auto check = [&](){
    int cnt = 0;
    FOR(i,0,n-1){
      cnt += from[i];
      cnt -= to[i];
      if(to[i]>0 && from[i] == 0) return false;
      if(cnt==0) return false;
    }
    return true;
  };
  auto e_cal = [&](int x){
    ld ret=1e30; int a=-1, b=-1;
    vector<ld> dp(n+1,0);
    IFOR(i,0,n){
      if(i!=x){
        for(auto y: egt[i]){
          dp[i] += dp[y]+1;
        }
        if(from[i])dp[i] /= from[i];
      }
      else{
        bool flg = true; int notto = -1;
        if(x<n-1){
          ld tmp = -1;
          for(auto y: egt[x]){
            if(tmp<dp[y]){
              notto = y;
              tmp = dp[y];
            }
          }
        }
        for(auto y: egt[i]){
          if(y!=notto) dp[i] += dp[y]+1;
        }
        if(notto>-1) from[i]--;
        if(!check()) {from[i]++;return (ld)1e30;}
        if(from[i]) dp[i] /= from[i];
        if(notto>-1) from[i]++;
      }
    }
    if(dp[0]>0.9)return dp[0];
    else return (ld)1e30;
  };
  ld ans = 1e30;
  vector<ld> edp(n,0);
  IFOR(i,0,n){
    ld ans_ = e_cal(i); //cout << ans_ << ' ';
    ans = min(ans, ans_ );
  }
  cout << ans << endl;
}

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




Measured memory_bytes: 3968
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };

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

	string s; cin >> s;
	int r = 0, b = 0;
	rep(i, s.size()) {
		if (s[i] == 'R')r++;
		else b++;
	}
	if (r > b)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
int a[N], b[N];
int main(int argc, char const *argv[]) {
  int n = read();
  for (int i = 1; i <= n; ++ i) {
    b[i] = a[i] = read();
  }
  sort(b + 1, b + n + 1);
  int *end = unique(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++ i) {
    a[i] = lower_bound(b + 1, end, a[i]) - b;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++ i) {
    ans += (a[i] & 1) ^ (i & 1);
  }
  printf("%d\n", ans >> 1);
  return 0;
}

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

using namespace std;

int N;
int h[100005];
int dp[100005];

int solve(int idx)
{
    int &ret = dp[idx];
    if(~ret)
        return ret;
    ret = 0;
    if(idx<=N-2)
        ret = abs(h[idx+1]-h[idx])+solve(idx+1);
    if(idx<=N-3)
        ret = min(ret,abs(h[idx+2]-h[idx])+solve(idx+2));
    return ret;
}



int main()
{

    memset(dp , -1 , sizeof(dp));
    cin>>N;
    for(int i=0; i<N; i++)
    {
        cin>>h[i];
    }

    cout<<solve(0);

    return 0;
}


Measured memory_bytes: 4096
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int compare_int(const void *a, const void *b)
{
//    return *(int*)a - *(int*)b;
    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

//long long  factorial(long long n) {
//    if (n > 0) {
//        return n * factorial(n - 1);
//    } else {
//        return 1;
//    }
//}
long long  factorial(long long n, long long depth) {
    if (n > 1) {
        depth++;
        return factorial(n / 2, depth);
    } else {
        return depth;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}



//int ()
/*
int triangle(int a, int b, int c){
  if(a<b+c){
    if(b<c+a){
      if(c<a+b){
        printf("1\n");
        return 1;
      }
    }
  }
  printf("1\n");
  return 0;
}
*/

int main()
{
  int  a ,b, c, d, e, X, Y ,r;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
 long long  A[200003]={};
//  int  A[100003]={};
  int  B[100003]={};
  long long  C[100003][100001]={};

  int  flg=0;

//  char s[101][101]={};
  char s[100001]={};
  char t[100001]={};
  char u[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p=0,q=0;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int min =100000001;
  int len=0;
  int l=0;
//  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans_ac=0;
  int ans_wa=0;
  int max=0;
  long long sum=0;
  int addr=0;
  int ptn=0;
  int  tmp=0;
  double per=0; 
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;

  scanf("%s", &s);
  
  len=strlen(s);
  for(i=0;i<len;i++){
    printf("x");
  }
  
  printf("\n");
  
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c);
	if(a <= b && b <= c){
		printf("%d %d %d\n" , a,b,c);
	}

	else if(a <= c && c <= b){
		printf("%d %d %d\n" , a,c,b);
	}

	else if(b <= a && a <= c){
		printf("%d %d %d\n" , b,a,c);
	}

	else if(b <= c && c <= a){
		printf("%d %d %d\n" , b,c,a);
	}

	else if(c <= a &&  a<= b){
		printf("%d %d %d\n" , c,a,b);
	}

	else if(c <= b &&  b<= a){
		printf("%d %d %d\n" , c,b,a);
	}

	return 0;

}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  string a,b,c;cin>>a>>b>>c;
  cout<<a[0]<<b[1]<<c[2]<<endl;
}	





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

x = {}
for _ in range(N):
    a = input()
    if a not in x:
        x[a] = 0
    x[a] += 1

mx = max(x.values())

ans = []
for k in x.keys():
    if x[k] == mx:
        ans.append(k)
ans.sort()
for a in ans:
    print(a)

Measured memory_bytes: 32096
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

#define DEBUG 0
#define REP(i, n) for (int i = 0; i < (n); i++) 
typedef long long ll;
typedef pair<int,int> pint;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//n個の宝箱(c[i],c[i])
//a[i]円でb[i]種類
//
int main() { 
    ll n,m;

    cin >> n >> m;
    //どの鍵を買うかのdpな気がする
    //Mのmaxは10^3なので、全bit探索はできない
    //NのbitをたててNについてのdp

    //c,c,cの組み合わせの最小をつくる??
    ll a[m],b[m];
    ll cnt[m] = {};
    REP(i,m)
    {
        cin >> a[i] >> b[i];
        
        ll tmp = 0;
        REP(j,b[i])
        {
            ll c;
            cin >> c;
            --c;
            tmp += (1 << c);
        }
        cnt[i] = tmp;
    }

 
    ll dp[1100][5000];
    
    //dp[i][N+N-1+N-2...+1]
    REP(i,1100)
    {
        REP(j,5000)
        {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for(int i = 0; i < m; ++i)
    {
        //すべての組合せにcnt[i]を足したときの最小値がとれる
        for(int j = 0; j < (1 << n); ++j)
        {
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
            dp[i+1][j | cnt[i]] = min(dp[i+1][j | cnt[i]], dp[i+1][j] + a[i]);
        }
    }

    ll res = dp[m][(1 << n)-1];

    if(res >= INF)res = -1;

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

Measured memory_bytes: 43264
#include <bits/stdc++.h>
using namespace std;
 
int main() {

	char S[3];
	for(int i=0; i<3; i++){
		cin >> S[i];
	}

	int count = 0;
	for(int i=0; i<3; i++){

		if(S[i]=='S'){
			continue;
		} 
		else{
			count++;
		}
	}
	if(S[1]=='S' && S[2]=='R'){
		count = 1;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>

typedef struct List {
	struct List *next;
	int v;
} list;

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[100001];
	int size;
} max_heap;

void push(data x, max_heap* h)
{
	int i = h->size;
	data tmp;
	h->obj[(h->size)++] = x;
	while (1) {
		if (i == 0) break;
		else if (h->obj[i].key > h->obj[(i-1)/2].key) {
			tmp = h->obj[(i-1)/2];
			h->obj[(i-1)/2] = h->obj[i];
			h->obj[i] = tmp;
			i = (i - 1) / 2;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 0, j;
	data output = h->obj[0], tmp;
	h->obj[0] = h->obj[--(h->size)];
	while (1) {
		if (i * 2 + 1 >= h->size) break;
		else if (i * 2 + 2 >= h->size) j = i * 2 + 1;
		else if (h->obj[i*2+1].key > h->obj[i*2+2].key) j = i * 2 + 1;
		else j = i * 2 + 2;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
		} else break;
	}
	return output;
}

int main()
{
	int i, u, w, N;
	list *adj[100001] = {}, e[100001];
	scanf("%d", &N);
	for (w = 2; w <= N; w++) {
		scanf("%d", &u);
		e[w].v = w;
		e[w].next = adj[u];
		adj[u] = &(e[w]);
	}
	
	int depth[100001] = {}, q[100001], head, tail;
	list *p;
	q[0] = 1;
	depth[1] = 1;
	for (head = 0, tail = 1; head < tail; head++) {
		u = q[head];
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			if (depth[w] == 0) {
				depth[w] = 1;
				q[tail++] = w;
			}
		}
	}
	
	data d;
	max_heap h;
	h.size = 0;
	for (head--; head >= 0; head--) {
		u = q[head];
		depth[u] = 0;
		for (p = adj[u], i = 0; p != NULL; p = p->next, i++) {
			d.key = depth[p->v];
			push(d, &h);
		}
		while (h.size > 0) {
			d = pop(&h);
			if (d.key + i - h.size > depth[u]) depth[u] = d.key + i - h.size;
		}
	}
	
	printf("%d\n", depth[1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 5552
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>

#define NUM_S 6
#define SIZE 100

using namespace std;

class Dice {
public:
	Dice(const int n[NUM_S]);

	int roll(char);
	int rollF();
	int rollR();
	int rollL();
	int rollB();
	int rollCwise();

	int getTop();
	int getF();
	int getR();
	int getL();
	int getB();
	int getBottom();

	void show();

private:
	int top, front, right, left, back, bottom;
};

bool sameDice(Dice, Dice);
bool checkDice(Dice, Dice);
bool inDice(int, Dice);


int main(void){
	int n, s[SIZE][NUM_S];
	vector<Dice> d;
	bool different = true;

	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < NUM_S; j++) {
			cin >> s[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		d.emplace_back(s[i]);
	}

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (checkDice(d[i], d[j])) {
				different = false;
				break;
			}
		}
	}

	if (different) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return 0;
}


Dice::Dice(const int n[NUM_S]) {
	top = n[0];
	front = n[1];
	right = n[2];
	left = n[3];
	back = n[4];
	bottom = n[5];
}

int Dice::roll(char c) {
	if (c == 'S') {
		return rollF();
	}
	else if (c == 'E') {
		return rollR();
	}
	else if (c == 'W') {
		return rollL();
	}
	else if (c == 'N') {
		return rollB();
	}
	else {
		return 0;
	}
}

int Dice::rollF() {
	int buf = top;
	top = back;
	back = bottom;
	bottom = front;
	front = buf;
	return top;
}

int Dice::rollR() {
	int buf = top;
	top = left;
	left = bottom;
	bottom = right;
	right = buf;
	return top;
}

int Dice::rollL() {
	int buf = top;
	top = right;
	right = bottom;
	bottom = left;
	left = buf;
	return top;
}

int Dice::rollB() {
	int buf = top;
	top = front;
	front = bottom;
	bottom = back;
	back = buf;
	return top;
}

int Dice::rollCwise() {
	int buf = left;
	left = front;
	front = right;
	right = back;
	back = buf;
	return top;
}

int Dice::getTop() {
	return top;
}

int Dice::getF() {
	return front;
}

int Dice::getR() {
	return right;
}


int Dice::getL() {
	return left;
}


int Dice::getB() {
	return back;
}


int Dice::getBottom() {
	return bottom;
}


void Dice::show() {
	cout << "Top:" << top << "\n";
	cout << "Front:" << front << "\n";
	cout << "Right:" << right << "\n";
	cout << "Left:" << left << "\n";
	cout << "Back:" << back << "\n";
	cout << "Bottom:" << bottom << "\n";
	cout << "===\n";
}

bool sameDice(Dice d1, Dice d2) {
	if (d1.getTop() == d2.getTop() && d1.getF() == d2.getF() && d1.getR() == d2.getR() && d1.getL() == d2.getL() && d1.getB() == d2.getB() && d1.getBottom() == d2.getBottom()) {
		return true;
	}
	else {
		return false;
	}
}

bool checkDice(Dice d1, Dice d2) {
	for (int j = 0; j < 4; j++) {
		for (int k = 0; k < 4; k++) {
			for (int l = 0; l < 4; l++) {
				if (sameDice(d1, d2)) {
					return true;
				}
				d2.rollR();
			}
			d2.rollF();
		}
		d2.rollCwise();
	}
	return false;
}

bool inDice(int n, Dice d) {
	if (n == d.getTop() || n == d.getF() || n == d.getR() || n == d.getL() || n == d.getB() || n == d.getBottom()) {
		return true;
	}
	else {
		return false;
	}
}

Measured memory_bytes: 3104
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
int kaijo(int n){
	int ans = 1;
	if (n != 0){
		for (int i = 0; i < n; i++){
			ans *= (n - i);
		}
	}
	else{
		ans = 1;
	}
	return ans;
}

int main(){
	int n;
	int a, b;
	int flag = 0;
	cin >> n;
	a = n / 10;
	b = n - n / 1000;
	if ((a / 111) * 111 == a){
		flag = 1;
	}
	if ((b / 111) * 111 == b){
		flag = 1;
	}
	if (flag == 1){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}


	return 0;
}


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

#define MAX 1000000

int main()
{
  int a,d,n,cnt;

  int b[MAX+1]={0},i,j;
  b[0]=b[1]=1;
  for(i=4;i<=MAX;i+=2)b[i]=1;
  for(i=3;i*i<=MAX;i+=2)
    if(!b[i])for(j=i+i;j<=MAX;j+=i)b[j]=1;

  while(cin>>a>>d>>n,a|d|n){
    for(cnt=0;a<MAX;a+=d){
      if(!b[a])cnt++;
      if(cnt==n)break;
    }
    cout<<a<<endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long 
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int ans, N;
vector<int> col[4];
void compute(int a, int b, int c){
	for (auto i:col[a]){
		for (auto j:col[b]){
			if (j<=i) continue;
			int idx1 = upper_bound(col[c].begin(),col[c].end(),j)-col[c].begin();
			ans+=sz(col[c])-idx1;
			int idx2 = lower_bound(col[c].begin(),col[c].end(),2*j-i)-col[c].begin();
			if (idx2!=sz(col[c]) && col[c][idx2]==2*j-i) ans--;
		}
	}
}

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	string S;cin>>S;
	FOR(i,0,(int)S.length()-1){
		if(S[i]=='R')col[1].push_back(i);
		if(S[i]=='G')col[2].push_back(i);
		if(S[i]=='B')col[3].push_back(i);
	}
	compute(1,2,3);
	compute(1,3,2);
	compute(2,1,3);
	compute(2,3,1);
	compute(3,1,2);
	compute(3,2,1);
	cout<<ans;
}


Measured memory_bytes: 3740
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, N) for(i = 0; i < N; i++)
#define ll long long
ll i, j, k;
int main() {
  int N;
  cin >> N;
  int count[4] = {0, 0, 0, 0};
  rep(i, N) {
    string str;
    cin >> str;
    if(str == "AC") {
      count[0]++;
    }
    if(str == "WA") {
      count[1]++;
    }
    if(str == "TLE") {
      count[2]++;
    }
    if(str == "RE") {
      count[3]++;
    }
  }

  cout << "AC x " << count[0] << "\n";
  cout << "WA x " << count[1] << "\n";
  cout << "TLE x " << count[2] << "\n";
  cout << "RE x " << count[3] << "\n";

  return 0;
}

Measured memory_bytes: 3628