akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string s;
cin >> s;
int cntA = 0,cntB = 0;
for(int i=0;i<s.size();i++){
if(s[i] == '\0')break;
else if(i % 2 == 0){
if(s[i] == '0')cntA++;
else cntB++;  
}else{
if(s[i] == '0')cntB++;
else cntA++;
}
}
int ans = min(cntA,cntB);
cout << ans << endl;
    return 0;
}

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

int main() {
	int n,m;
	cin>>n>>m;
	
	int a=0,w=0;
	
	vector<int> ac(n);//正解の時-1を格納する
	rep(i,m){
		int p;
		string s;
		cin>>p>>s;
		
		if(s=="WA"){
			ac[p]++;
		}else{
			if(ac[p]>=0){
				w+=ac[p];
				a++;
				ac[p]=-1000000;
			}
		}
		
		
	}
	cout<<a<<" "<<w<<endl;
}


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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	int ans = 0, status = 0;
	for (int i = 0; i < n - 1; i++) {
		if (status == 0) {
			if (a[i + 1] - a[i] > 0)status = 1;
			else if (a[i + 1] - a[i] < 0)status = 2;
		}
		if (status == 1 && a[i + 1] - a[i] < 0) {
			ans++; status = 0;
		}
		else if (status == 2 && a[i + 1] - a[i] > 0) {
			ans++; status = 0;
		}
	}
	cout << ans+1 << endl;

	return 0;
}

Measured memory_bytes: 3716
#入力が2つ0なら処理を終わる
while True:
    a,b = map(int,input().split())
    if a == 0 and b == 0:break

    #2つの数の中で大きい方をa小さい方をbに入れる
    a,b = max(a,b),min(a,b)
    
    #カウンタ変数の初期化
    i = 0
    
    #bが0になったらユークリッドの互除法を終わる
    while True:
        
        #カウンタ変数の更新
        i += 1
        
        #a/bのあまりをaに代入、aとbの値を交換する
        a = a % b
        a,b = b,a
        if b == 0:break
    
    #公約数と回数を出力する
    print(a,i)


Measured memory_bytes: 5612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	int k, x;
	cin >> k >> x;

	int mi = max(-1000000, x - k + 1);
	int ma = min(1000000, x + k - 1);
	for (int i = mi; i <= ma; i++) {
		cout << i << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
<?php
//ABC_C問題
//Otoshidama

list($N,$Y) = array_map('intval',explode(" ",trim(fgets(STDIN))));

for ( $i=0; $i<=$N; $i++ ) {
    for ( $j=0; $j<=$N; $j++ ) {
        $k = $N - ($i+$j);
        $value = $i*10000+$j*5000+$k*1000;
        if ( $k < 0 ) {
            continue;
        }
        //var_dump($value);
        if ( $value == $Y ) {
            echo ($i);
            echo (' ');
            echo ($j);
            echo (' ');
            echo ($k)."\n";
            exit;
        }
    }
}
echo (-1);
echo (' ');
echo (-1);
echo (' ');
echo (-1)."\n";
?>

Measured memory_bytes: 16032
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
 
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int board[12][12], mo[12];
signed main() {
    int N, M; cin >> N >> M;
    for(int i=0; i<M; i++) {
        int K; cin >> K;
        for(int j=0; j<K; j++) {
            int id; cin >> id; id--;
            board[i][id] = true;
        }
    }
    for(int i=0; i<M; i++) {
        cin >> mo[i];
    }
 
    int ans = 0;
    for(int bit=0; bit<(1<<N); bit++) {
        int sum = 0;
        for(int i=0; i<M; i++) {
            int cnt = 0;
            for(int j=0; j<N; j++) {
                if(!board[i][j]) continue;
                cnt += (bit >> j & 1);
            }
            cnt %= 2;
            if(mo[i] == cnt) sum++;
        }
        if(sum == M) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
#include <queue>
#include <sstream>
#include <map>
#include <unordered_map>
#include <cmath>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i = 0; i < N; i++)


int main(int argc, char *argv[])
{
    int N, M;
    cin >> N >> M;
    priority_queue<int> A;
    Rep(i, N) {
        int a;
        cin >> a;
        A.push(a);
    }

    for (int i=0; i<M; i++) {
        int t = A.top();
        A.pop();
        A.push(t / 2);
    }

    LLI s = 0;
    while (!A.empty()) {
      s += A.top();
      A.pop();
    }

    cout << s << endl;

    return 0;
}

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


int main()
{
	string s;
	cin>>s;
	int one=0;
	int zero=0;
	for(char c : s)
	{
		if(c=='0') zero++;
		else one++;
	}
	cout<<min(zero,one)*2<<endl;
	return 0;
}


Measured memory_bytes: 3736
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else cout << "Impossible" << endl;
}

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

using namespace std;

#define ll long long
#define ii pair<int ,int>
#define iii tuple<int ,int, int>
#define vi vector<int>
#define vii vector<int, int>
#define fo(i,a,n) for(int i = (a); i < (n); i++)
#define pb push_back
#define newl cout<<"\n"
#define mp make_pair
#define mt make_tuple
#define f first
#define s second
#define N1 100000

//int visited[N1]={};
//int st[4*N1 + 10]={};
const ll MAXN=1e+3+7;
ll n;
ll a[MAXN];

int main(){
	cin>>n;
	long double res=0;
	fo(i,0,n){
		cin>>a[i];
		res+=1.0/(long double)a[i];
	}

	res=1/res;

	cout<<res;




}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#define For(i, a, b) for (int i = a; i < b; ++i)
#define Out(i, a, b) for (int i = a - 1; i >= b; --i)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define files(FileName) read(FileName); write(FileName)
#define read(FileName) freopen((FileName + ".in").c_str(), "r", stdin)
#define write(FileName) freopen((FileName + ".out").c_str(), "w", stdout)
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }

using namespace std;

typedef long long base;

const string FILENAME = "input";
const int MAXN = 1e5 + 1, RAME = 10;

int n, m;
int clr[MAXN];

int main() {
    //read(FILENAME);
    ios::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        clr[a] ^= 1;
        clr[b] ^= 1;
    }
    for (int i = 0; i < n; ++i) {
        if (clr[i] != 0) {
            cout << "NO\n" << endl;
            return 0;
        }
    }
    cout << "YES\n" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include<cstdio> 
#include<vector>
#include<string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
	string str;
	cin>>str;
	vector<char> v;
	for(int i=0;i<str.size();i++)
	{
		if(str[i]=='T'&&!v.empty()){
			char a=v.back();
			if(a=='S') v.pop_back();
			else v.push_back(str[i]);
		}
		else v.push_back(str[i]);
	}
	cout<<v.size()<<endl;
	return 0;
}

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

using namespace std;

#define sp << " " <<
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define int long long
#define double long double
#define INF 1e18
#define PI 3.14159265359

int power(int p,int y)
{
    int res=1;
    p=p%mod;
    while(y>0)
    {
        if(y&1)
            res=(res*p)%mod;
        y=y>>1;
        p=(p*p)%mod;
    }
    return res;
}

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int dice()
{
    uniform_int_distribution<int> uid(0,1);//specify l and r.
    return uid(rng) ;
}

int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int dp = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          dp = dp * 10 + cc - '0';
          cc = getc(stdin);
       }
      return dp;
}

inline void print(int n)
{
  if (n == 0)
  {
    putchar('0');
    putchar('\n');
  }
  else if (n == -1)
  {
    putchar('-');
    putchar('1');
    putchar('\n');
  }
  else
  {
    char buf[20];
    buf[19] = '\n';
    int i = 18;
    while (n)
    {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n')
      putchar(buf[++i]);
  }
}

int n;

vector<vector<int>> mat_mul(vector<vector<int>> a,vector<vector<int>> b)
{
	vector<vector<int>> t(n,vector<int>(n,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				t[i][j]+=((a[i][k]*b[k][j])%mod);
				t[i][j]%=mod;
			}
		}
	}
	return t;
}

vector<vector<int>> pow_mat(vector<vector<int>> mat_a,int p)
{
	if(p==1)
        return mat_a;
	vector<vector<int>> temp=pow_mat(mat_a,p/2);
	vector<vector<int>> res=mat_mul(temp,temp);
	if(p&1)
        res=mat_mul(res,mat_a);
	return res;
}
*/

int t[1000000];

int dp(int v,int tl,int tr,int l,int r)
{
    if(l>r)
        return 0;
    if(l==tl&&r==tr)
        return t[v];
    int tm=(tl+tr)/2;
    return max(dp(v*2,tl,tm,l,min(r,tm)),dp(v*2+1,tm+1,tr,max(l,tm+1),r));
}

void update(int v,int tl,int tr,int pos,int new_val)
{
    if(tl==tr)
        t[v]=new_val;
    else
    {
        int tm=(tl+tr)/2;
        if(pos<=tm)
            update(v*2,tl,tm,pos,new_val);
        else
            update(v*2+1,tm+1,tr,pos,new_val);
        t[v]=max(t[v*2],t[v*2+1]);
    }
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    int a[n+1],h[n+1];
    for(int i=1;i<n+1;i++)
        cin >> h[i];
    for(int i=1;i<n+1;i++)
        cin >> a[i];
    h[0]=a[0]=0;
    int p[n+1];
    for(int i=0;i<n+1;i++)
        p[h[i]]=i;
    for(int i=0;i<n+1;i++)
    {
        int k=dp(1,0,n,0,p[i]);
        update(1,0,n,p[i],k+a[p[i]]);
    }
    cout << dp(1,0,n,0,n);
	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
int main(){
    while(1){
        cin>>n;
        if(n==0)break;
        ll t=0;
        for(int i=1;i<=sqrt(n);i++){
            if(n%i==0){
                if(i!=n/i)t+=(i+(n/i));
                else t+=i;
            }
        }
        t-=n;
        if(n==t){
            cout<<"perfect number"<<endl;
        }else if(n>t){
            cout<<"deficient number"<<endl;
        }else{
            cout<<"abundant number"<<endl;
        }
    }
    return 0;
}


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

int main() {
  int X;cin>>X;
  if(X>=400&&X<=599) cout<<"8"<<endl;
  else if(X>=600&&X<=799) cout<<"7"<<endl;
  else if(X>=800&&X<=999) cout<<"6"<<endl;
  else if(X>=1000&&X<=1199) cout<<"5"<<endl;
  else if(X>=1200&&X<=1399) cout<<"4"<<endl;
  else if(X>=1400&&X<=1599) cout<<"3"<<endl;
  else if(X>=1600&&X<=1799) cout<<"2"<<endl;
  else if(X>=1800&&X<=1999) cout<<"1"<<endl;  
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> product(N);
  for (int i = 0; i < N; i++) {
    cin >> product.at(i);
  }
  
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum+=product.at(i);
  }
  
  
  sort(product.begin(), product.end()); 
  reverse(product.begin(), product.end());
  
  for (int j = 1; j <= M; j++) {
  
      
    if (product.at(j-1) <= (sum-1)/(4* M)) {
      cout << "No" << endl;
      break; 
    }
    
    else if (j==M) {
      cout << "Yes" << endl;
      
    }
    
  }
  
      
    
      
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
using namespace std;

int main(){
  int A, B; cin >> A >> B;
  string S; cin >> S;
  bool ok = true;
  if(S.size() != A + B + 1) ok = false;
  else{
    for(int i = 0; i < A + B + 1; i++){
      if(i == A){
        if(S[i] != '-') ok = false;
      }else{
        if(S[i] < '0' || S[i] > '9') ok = false;
      }
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
function main(input) {
    var s = input[0];
    var k = input[1]-0;
    var list = [];
    for(var i=0;i<s.length;i++){
        for(var j=0;j<5;j++){
            list.push(s.substring(i, i+j+1));
        }
    }
    var newList = [];
    list.sort();
    for(var i=0;i<list.length;i++){
        if(list[i]!=newList[newList.length-1]){
            newList.push(list[i]);
        }
        if(newList.length >= k) break;
    }
    console.log(newList[k-1]);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


//1 2 3 4 5 6


Measured memory_bytes: 8876
# AtCoder
S = input()
even = set(S[1::2])
odd = set(S[0::2])
ans = 'Yes'

for i in odd:
    if i not in ['R', 'U', 'D']:
        print('No')
        exit()
for i in even:
    if i not in ['L', 'U', 'D']:
        print('No')
        exit()

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define F first
#define S second
#define pb push_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<ll, null_type, less<ll>, rb_tree_tag, 
tree_order_statistics_node_update> 
new_data_set; 

const ll N=1000005;
ll a[N];

int main()
{
    // ios_base:: sync_with_stdio(false);
    // cin.tie(NULL); cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    // ll t;
    // cin>>t;
    // while(t--)
    {
        ll i,j,k,n,m,ans=0,cnt=0,sum=0;  
        cin>>n;
        a[1]=1;
        for(i=2;i<N;i++){
            ll x=i*i;
            while(x<N){
                a[x]=x;
                x*=i;
            }
        }
        for(i=1;i<N;i++){
            if(a[i]<a[i-1]){
                a[i]=a[i-1];
            }
        }
        cout<<a[n];
    }
}

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

int main() {
	int i,j,flag=0;
	int row[101],col[101];
	char a[101][101];

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);

	cin>>i>>j;
	for(int m=1;m<=i;m++){
			cin>>a[m]+1;
	}
	
	for(int m=1;m<=i;m++){
		for(int n=1;n<=j;n++){
			if(a[m][n]=='#'){
			row[m]=-1;
			col[n]=-1;				
			}
		}
	}
	
	for(int m=1;m<=i;m++){
		int flag=0;
		if(row[m]!=-1) continue;
		for(int n=1;n<=j;n++){
			//printf("%c",a[m][n]);
			if(col[n]!=-1) continue;
			cout<<a[m][n];
			flag=1;
		}
		if(flag==1) cout<<"\n";
		//printf("\n");
	}
	

    return 0;
} 


Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define ll long long
int main(){
    int n;
    cin >> n;
    ll ans=0;
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a>>b;
        ans+=(b-a)+1;
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    int N,M;
    cin >> N >> M;
    vector<ll> state(N+1),wa(N+1);
    ll p;
    string S;
    ll ans_ac,ans_wa;
    ans_ac = ans_wa = 0;
    for(int i = 0; i < N+1;i++){
        state[i] = 0;
        wa[i] = 0;
    }

    for(int i = 0; i < M;i++){
        cin >> p >> S;
        if(state[p] == 0){
            if(S  == "WA"){
                wa[p]++;
            }else{
                state[p] = 1;
                ans_ac++;
            }
        }
    }

    for(int i = 0; i < N+1;i++){
        if(state[i] == 1){
            ans_wa += wa[i];
        }
    }

    cout << ans_ac << " " << ans_wa << endl;


    return 0;
}

Measured memory_bytes: 1792
#! /usr/bin/env python3

def main():
    H, W = map(int, input().split())
    def f(H, W):
        ret = H * W
        left = 1
        up = 1
        t = True
        for i in range(1, H):
            a = W * i
            b = (H - i) * (W // 2)
            c = (H - i) * (W // 2 + W % 2)
            maxv = max(a, b, c)
            minv = min(a, b, c)
            ret = min(ret, maxv - minv)
        if H > 2:
            i = 1
            j = 2
            while 1:
                a = W * i
                b = W * j - a
                c = H * W - b - a
                maxv = max(a, b, c)
                minv = min(a, b, c)
                ret = min(ret, maxv - minv)
                if a == minv:
                    if j == H-1 : break
                    i += 1
                    j += 1
                elif b == minv:
                    j += 1
                else:
                    break
        return ret
    print(min(f(H, W), f(W, H)))
main()

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()

void uniqueVector(vector< int >& vec) {
	sort(allof(vec));
	vec.erase(unique(allof(vec)), vec.end());
}

void solve(
	int n, int m,
	const vector< int >& tx, const vector< int >& ty,
	const vector< int >& lft, const vector< int >& bot,
	const vector< int >& rgt, const vector< int >& top
	) {
	vector< int > x_sort = tx, y_sort = ty;
	uniqueVector(x_sort);
	uniqueVector(y_sort);
	
	vector< vector< int > > imos(n + 1, vector< int >(n + 1, 0));
	for_(i,0,n) {
		int x = lower_bound(allof(x_sort), tx[i]) - x_sort.begin() + 1;
		int y = lower_bound(allof(y_sort), ty[i]) - y_sort.begin() + 1;
		++imos[y][x];
	}
	
	for_(y,0,n+1) for_(x,0,n) imos[y][x + 1] += imos[y][x];
	for_(x,0,n+1) for_(y,0,n) imos[y + 1][x] += imos[y][x];
	
	for_(i,0,m) {
		int lx = lower_bound(allof(x_sort), lft[i]) - x_sort.begin() + 1;
		int by = lower_bound(allof(y_sort), bot[i]) - y_sort.begin() + 1;
		int rx = upper_bound(allof(x_sort), rgt[i]) - x_sort.begin();
		int ty = upper_bound(allof(y_sort), top[i]) - y_sort.begin();
		
		printf("%d\n", imos[ty][rx] - imos[ty][lx - 1] - imos[by - 1][rx] + imos[by - 1][lx - 1]);
	}
}

int main() {
	int n, m;
	assert(scanf("%d %d", &n, &m) == 2);
	
	vector< int > tx(n), ty(n);
	for_(i,0,n) assert(scanf("%d %d", &tx[i], &ty[i]) == 2);
	
	vector< int > lft(m), bot(m), rgt(m), top(m);
	for_(i,0,m) assert(scanf("%d %d %d %d", &lft[i], &bot[i], &rgt[i], &top[i]) == 4);
	
	solve(n, m, tx, ty, lft, bot, rgt, top);
}

Measured memory_bytes: 108716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

int main() {
	int n, m, s;
	char c;
	cin >> n >> m;
	string t = string(n, ' ');
	while (m--) {
		cin >> s >> c;
		s--;
		if (t[s] != ' ' && t[s] != c) {
			cout << -1 << endl;
			return 0;
		}
		t[s] = c;
	}
	if (n > 1 && t[0] == '0') {
		cout << -1 << endl;
		return 0;
	}
	if (t[0] == ' ') {
		t[0] = '0' + (n > 1);
	}
	for (int i = 1; i < n; i++) {
		if (t[i] == ' ') t[i] = '0';
	}
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*n
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
  dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(i,k)+1)])
  
print(dp[-1])

Measured memory_bytes: 52448
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int x, y; cin >> x >> y;
    if (x == 2 || y == 2) cout << "No"  << endl;
    else {
        if ((x == 4 || x == 6 || x == 9 || x == 11)
         && (y != 4 && y != 6 && y != 9 && y != 11))
                          cout << "No"  << endl;
        else              cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int num1,num2,max1,min1,max2,min2,n;
	cin>>num1>>num2;
	cin>>max1>>max2;
	min1=max1;min2=max2;
	for(int i=1;i<=num1;i++){
		cin>>n;
		max1=max(max1,n);
		min1=min(min1,n);
	}
	for(int i=1;i<=num2;i++){
		cin>>n;
		max2=max(max2,n);
		min2=min(min2,n);
	}
	if(min2<=max1&&max2>=min1||min1<=max2&&max1>=min2)cout<<"War";
	else cout<<"No War";
	return 0;
} 

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    cout << setprecision(20);
    ll n, m;
    cin >> n >> m;
    string s;
    cin >> s;

    vll p;
    ll c = n;
    while(c>0){
        bool found = false;
        REP(i, max(c-m, 0ll), c){
            if(s[i]=='0'){
                p.push_back(c-i);
                found = true;
                c = i;
                break;
            }
        }
        if(!found){
            cout << -1 << endl;
            return 0;
        }
    }
    irep(i, p.size()){
        cout << p[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    long n, a, min = 10000000, max = -10000000, sum = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if (a < min){
            min = a;
        }
        if (a > max){
            max = a;
        }
        sum = sum + a;
    }
    cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    rep(i,n){
        int d1, d2;
        cin >> d1 >> d2;
        if(d1 == d2) cnt++;
        else{
            cnt = 0;
        }
        if(cnt == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int k2 = max({A ,B, C});
    int ans = k2 * 9 + A + B + C;
    cout << ans << endl;
}

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

int main() {
   int N, K;
   cin >> N >> K;
   vector<int> lvec(N);
   for (int i=0; i<N; i++) {
       cin >> lvec.at(i);
   } 
   sort(lvec.begin(), lvec.end(), greater<int>());
   int sum = 0;
   for (int i=0; i<K; i++) {
       sum += lvec.at(i);
   }
   cout << sum << endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long f(int n) {
	long abc = 1;
	for (int i = n; i > n - 2; --i) {
		abc = abc * i;
	}
	abc = abc / 2;
	return abc;
}
int main() {
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) cin >> A[i];
	long ans = 0;
	vector<long long> sum(n);
	sum[0]= A[0];
	for (int i = 1; i < n; i++) {
		sum[i] = sum[i - 1] + A[i];
	}
	for (int i = 0; i < n; i++) {
		if (sum[i] == 0) ans++;
	}
	sort(sum.begin(), sum.end());
	int ptr = 0;
	long cc;
	while (ptr < n) {
		cc = sum[ptr];
		int e = 0;
		while (ptr < n&&sum[ptr] == cc) e++, ptr++;
		ans += f(e);
	}
	cout << ans << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

map<string, int> mp;

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
vector<vector<ll>> G;
vector<vector<ll>> H;
vector<ll> topo;
vector<int> visited;
void topologicalSort(ll v){
    visited[v] = 1;
    for(ll i=0; i<G[v].size(); i++){
        ll nv = G[v][i];
        if(!visited[nv]) topologicalSort(nv);
    }
    topo.push_back(v);
}
signed main(){
    ll N, M;
    cin >> N>>M;
    G.resize(N);
    H.resize(N);
    visited.resize(N, 0);
    for(long long i=0; i<N-1+M; i++){
        ll a, b; cin >> a >> b;
        G[--a].push_back(--b);
        H[b].push_back(a);
    }
    ll root=-1;
    REP(i, N) if(H[i].size()==0) root = i;
    topologicalSort(root);
    reverse(ALL(topo));
    vector<ll> cmp(N);
    REP(i, N){
        cmp[topo[i]] = i;
    } 
    vector<ll> res(N);
    REP(i, N){
        if((int)H[i].size()==1) res[i] = H[i][0]+1;
        else if(H[i].size()==0) res[i] = 0;
        else{
            ll pid = -1;
            for(ll j=0; j<H[i].size(); j++){
                if(pid< cmp[H[i][j]]){
                    pid = cmp[H[i][j]];
                    res[i] = H[i][j]+1;
                } 
            }
        }
    }
    REP(i, N) cout << res[i] << endl;
    return 0;
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, lli> pi;


int main()
{
    lli n, a, b;
    cin >> n >> a >> b;
    if((b-a) % 2 == 0){
        cout << (b-a)/2 << "\n";
    }
    else{
        cout << min({b-1, n-a, (a-1)+(b-(a-1))/2, (n-b+1)+(n-(a+(n-b)+1))/2}) << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		Vertex[] graph=new Vertex[N+1];
		int[] distance=new int[N+1];
		int[] to=new int[N+1];	//頂点に入っていく矢印の数
		int[] ans=new int[N+1];
		for(int i=0; i<=N; i++) {
			graph[i]=new Vertex();
			distance[i]=0;
			to[i]=0;
			ans[i]=0;
		}
		for(int i=0; i<N+M-1; i++) {
			int graph_from=sc.nextInt();
			int graph_to=sc.nextInt();
			graph[graph_from].add(graph_to,1);
			to[graph_to]++;
			if(to[graph_to]==1) {
				ans[graph_to]=graph_from;		//確定候補は確定させておく（入ってくる矢印の数が1）
			}
			else if(to[graph_to]>1) {
				ans[graph_to]=0;		//入ってくる数が2以上なら実はまだ親が確定していないので、確定しないやつは確定権利を剥奪させる
			}
		}
		Queue<Integer> q=new LinkedList<Integer>();
		for(int i=0; i<=N; i++) {
			if(to[i]==0) {
				q.add(i);		//根の頂点をキューに追加する
			}
		}
		while(!q.isEmpty()) {
			int tansaku=q.poll();	//探索する頂点
			for(int i=0; i<graph[tansaku].size(); i++) {
				int mukau=graph[tansaku].getKey(i);	//どこに向かうかの情報を取得
				to[mukau]--;	//辺を調べたので 頂点の入ってくる数を減らす
				distance[mukau]=Math.max(distance[mukau], distance[tansaku]+1);		//最長を更新できるかを確認　できたらその矢印の出た頂点が親
				if(distance[mukau]==distance[tansaku]+1) {
					ans[mukau]=tansaku;	//最長を更新したら親を更新
				}
				if(to[mukau]==0) {	//入ってくる数が0ならキューに追加
					q.add(mukau);
				}
			}
		}
		for(int i=1; i<=N; i++) {
			System.out.println(ans[i]);
		}
		sc.close();
	}
	public static final class Pair<K, V> {		//powered by mikit
		public K key;
		public V value;
		public Pair(K key, V value) {
			this.key = key;
			this.value = value;
		}
		public static int getKey(Pair<Integer,Integer> a) {
			return a.key;
		}
	}
	public static class Vertex{		//今回は2つの頂点の矢印が向いている方のリストに矢印のソースが来る
		ArrayList <Pair<Integer,Integer>> rinsetu=new ArrayList<Pair<Integer,Integer>>();
		public void add(int V,int cost) {
			rinsetu.add(new Pair<Integer, Integer>(V,cost));
		}
		public int getKey(int i) {
			return Pair.getKey(rinsetu.get(i));	//Valueを取り出す
		}
		public int size() {		//次数（無向なら）　でていく数（有向なら）を返す
			return rinsetu.size();
		}
	}
}

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

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

  for (int i = A; i < B + 1; i++) {
    if(i / 10000!=i % 10){
    continue;
    }
    int N = i;
    int M = i;
    N -= (N / 10000) * 10000;
    N /= 1000;
    M /= 10;
    M %= 10;
    if(N!=M){
    continue;
    }
    ans++;
  }
  cout << ans << endl;
}


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

typedef struct Node Node;

struct Node{
    int data;
    Node *parent;
    Node *left;
    Node *right;
};

void initNode(Node*);
Node copyNode(Node*,Node*);
void insert(Node*,Node*[],int);
void printTree(Node*);
int find(Node*,int);
void inorder(Node*);
void preorder(Node*);


int main(int argc, char** argv) {
    int commandSize;
    scanf("%d",&commandSize);
    Node *tree[commandSize-1];
    for(int i = 0; i < commandSize; i++)
        tree[i] = NULL;
    int loc = 0;
    int j;
    int findVal;
    Node temp[commandSize-1];
    char cmd[7];
    for(int i = 0; i < commandSize; i++){
        initNode(&temp[i]);
        scanf("%s",cmd);
        if(!strcmp(cmd,"insert")){
            scanf("%d", &temp[i].data);
            insert(&temp[i],tree,loc++);
        }
        else if(!strcmp(cmd,"print")){
            if(tree[0]==NULL){
                j = 0;
                while(j < 4){
                    if(tree[j]==NULL)
                        tree[j] = &temp[j];
                    j++;
                }
            }
            printTree(tree[0]);
        }
        else{
            scanf("%d",&findVal);
            if(find(tree[0],findVal))
                printf("yes\n");
            else
                printf("no\n");
        }
    }
    return (EXIT_SUCCESS);
}

void initNode(Node *n){
    n->data = NULL;
    n->parent = NULL;
    n->left = NULL;
    n->right = NULL;
}

void insert(Node *node, Node *tree[], int loc){
    Node *parent = NULL;
    Node *current = tree[0];
    while(current != NULL){
        parent = current;
        if(node->data < current->data)
            current = current->left;
        else
            current = current->right;
    }
    node->parent = parent;
    if(parent == NULL){
        tree[loc] = node;
    }
    else if(node->data < parent->data){
        tree[loc] = node;
        parent->left = tree[loc];
    }
    else{
        tree[loc] = node;
        parent->right = tree[loc];
    }
}

Node copyNode(Node *dest, Node *orig){
    dest->data = orig->data;
    dest->parent = orig->parent;
    dest->left = orig->left;
    dest->right = orig->right;
}

void printTree(Node *root){
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
}

int find(Node *root, int val){
    if(root != NULL){
        if(val < root->data)
            return find(root->left,val);
        else if(val > root->data)
            return find(root->right,val);
        else if(val == root->data)
            return 1;
    }
    else
        return 0;
}

void inorder(Node *root){
    if(root->left != NULL)
        inorder(root->left);
    printf(" %d", root->data);
    if(root->right != NULL)
        inorder(root->right);
}

void preorder(Node *root){
    printf(" %d", root->data);
    if(root->left != NULL)
        preorder(root->left);
    if(root->right != NULL)
        preorder(root->right);
}



Measured memory_bytes: 21228
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
const int INF = INT_MAX;
const ll MOD = 998244353;

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    ll N,W;
    cin >> N >>W;
    vector<ll> value[4];
    ll w0=0;
    repeat(i, N){
        ll w,v;
        cin >> w >> v;
        if(i==0) w0 = w;
        value[w-w0].push_back(-v);
    }
    repeat(i, 4){
        sort(value[i].begin(),value[i].end());
    }
    vector<ll> sumvalue[4];
    repeat(i, 4){
        sumvalue[i].assign(value[i].size()+1, 0);
        repeat(j, value[i].size()){
            sumvalue[i][j+1] += sumvalue[i][j] + value[i][j];
        }
    }
    ll sumw = 0;
    ll ans = 0;
    repeat(c0, value[0].size()+1){
        sumw = c0*w0;
        repeat(c1, value[1].size()+1){
            sumw += c1*(w0+1);
            repeat(c2, value[2].size()+1){
                sumw += c2*(w0+2);
                if(sumw > W) {
                    sumw -= c2*(w0+2);
                    break;
                }
                ll c3 = (W-sumw)/(w0+3);
                ll v = -sumvalue[0][c0] - sumvalue[1][c1] - sumvalue[2][c2] - sumvalue[3][c3];
                ans = max(ans,v);
                sumw -= c2*(w0+2);
            }
            sumw -= c1*(w0+1);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s,ans="AC";
    cin>>s;
    if(s[0]!='A') ans="WA";
    int cnt=0;
    for(int i=1;i<s.size();i++){
        if(isupper(s[i])){
            if(i==1||i==s.size()-1||s[i]!='C') ans="WA";
            cnt++;
        }
    }
    if(cnt!=1) ans="WA";
    cout<<ans;
}

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

using namespace std;

int N;
double v[50], ans;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> N;
    
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }
    
    sort(v, v+N);
    
    for (int i = 0; i < N; i++) {
        ans = (ans + v[i]) / (i?2:1);
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pl = pair<ll,ll>;

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

    vector<ll> a(n);
    rep(i,n) cin >>a[i];

    vector<pl> v;
    rep(i,m){
        ll b,c;
        cin >>b >>c;
        v.pb({c,b});
    }
    sort(all(v), greater<pl>());

    int ct = 0;
    for(const auto &p:v){
        ll val = p.fi, num = p.se;
        rep(i,num){
            a.pb(val);
            ++ct;
            if(ct == n) break;
        }
        if(ct == n) break;
    }

    sort(all(a), greater<ll>());

    ll ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3552
N = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

if N % 10 == 3:
    print("bon")

elif N % 10 == 0 or N % 10 == 1 or N % 10 == 6 or N % 10 == 8:
    print("pon")

else:
    print("hon")


Measured memory_bytes: 9100
N, W = map(int, input().split())
values = [0 for i in range(W)]
for i in range(N):
#  print(values)
  w, v = map(int, input().split())
  values = values[:w-1] + [max(values[j], v + values[max(0, j-w)]) for j in range(w-1, W)]

print(values[-1])

Measured memory_bytes: 130564
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<2*n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+2*n);
    int sum=0;
    for(int i=0;i<2*n;i+=2)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<map>
#include<iostream>
using namespace std;
map<string,int>m;
int main(){
	string s;
	cin>>s;
	m["SUN"]=7;
	m["MON"]=6;
	m["TUE"]=5;
	m["WED"]=4;
	m["THU"]=3;
	m["FRI"]=2;
	m["SAT"]=1;
	cout<<m[s];
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
typedef long long ll;

using namespace std;

const int INF = 1001001001;

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> key;
    
    for(int i(0);i<m;i++){
        int a,b;
        cin >> a >> b;
        int s(0);
        for(int j(0);j<b;j++){
            int c;
            cin >> c;
            --c;
            s |= 1<<c;
        }
        key.emplace_back(s,a);
    }
    vector<int> dp(1<<n, INF);
    dp[0]=0;
    for(int s(0);s<(1<<n);s++){
        for(int i(0);i<m;i++){
            int t = s | key[i].first;
            int cost = dp[s] + key[i].second;
            dp[t] = min(dp[t],cost);
        }
    }
    int ans = dp.back();
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}


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

long long LCM(int a, int b) {
    return a * 1ll * b / __gcd(a, b);
}

int main() {
    int n, m;
    cin >> n >> m;
    long long lcm = 1;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        lcm = LCM(lcm, a[i] / 2);
    }
    for (int i = 0; i < n; ++i) {
        if ((2 * lcm / a[i]) % 2 == 0) {
            return cout << 0, 0;
        }
    }
    int cnt = m / lcm;
    cout << (cnt + 1) / 2;
}

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

int d[20][20][1<<10];
char s[40][40];
int id[40][40];
int dx[]{1,-1,0,0},dy[]{0,0,1,-1};
struct st{int a,b,c;};

int main(){
	int w,h;
	while(scanf("%d%d",&w,&h),w){
		int sx,sy;
		int cnt=0;
		rep(i,h){
			scanf("%s",s[i]);
			rep(j,w){
				if(s[i][j]=='o')sx=i,sy=j;
				if(s[i][j]=='*'){
					id[i][j]=cnt++;
				}
			}
		}
		memset(d,0x3f,sizeof(d));
		d[sx][sy][0]=0;
		queue<st>que;
		que.push({sx,sy,0});
		while(!que.empty()){
			st p=que.front();que.pop();
			rep(i,4){
				int nx=p.a+dx[i],ny=p.b+dy[i];
				if(nx<0||nx>=h||ny<0||ny>=w||s[nx][ny]=='x')continue;
				int c=p.c;if(s[nx][ny]=='*')c|=1<<id[nx][ny];
				if(d[nx][ny][c]==INF){
					d[nx][ny][c]=d[p.a][p.b][p.c]+1;
					que.push({nx,ny,c});
				}
			}
		}
		int Min=INF;
		rep(i,h)rep(j,w){
			Min=min(Min,d[i][j][(1<<cnt)-1]);
		}
		if(Min==INF)Min=-1;
		printf("%d\n",Min);
	}
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

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

    ll ans = 1000;
    ll kabu = 0;

    for (ll i = 0; i < n - 1; ++i) {
        if (a[i] < a[i + 1] && kabu == 0) {
            // 買う
            kabu = ans / a[i];
            ans -= ans / a[i] * a[i];
            continue;
        }

        if (a[i] > a[i + 1] && kabu > 0) {
            // 売る
            ans += kabu * a[i];
            kabu = 0;
            continue;
        }
    }

    if (kabu > 0) {
        ans += kabu * a[n - 1];
    }

    cout << ans << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main(){

    int n,x;
    cin >> n >> x;
    int l[n];
    for(int i=0; i<n; i++){
        cin >> l[i];
    }

    int c = 0;
    int d[n];
    d[0] = 0;

    for(int i=1; i<n+1; i++){
        d[i] = d[i-1] + l[i-1];
        if(d[i] <= x){
            c++;
        }
    }

    cout << c+1 << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int H, W;
  cin >> H >> W;
  string A;
  
  for (int i = 0; i < W+2; i++) {
    cout << "#";
  }

    cout <<endl;
  
  for (int i = 0; i < H; i++) {
    cin >> A;
    cout << "#" << A << "#" << endl;
  }
  
    for (int i = 0; i < W+2; i++) {
    cout << "#";
  }
  
    cout <<endl;
  
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n, m;
		cin >> n >> m;
		vector<vector<int>> a(n);
		for(int i=0; i < m; i++){
			int s, t;
			cin >> s >> t;
			s--, t--;
			a[s].emplace_back(t);
		}
		vector<double> e(n, 0), p(n, 0);
		for(int i=n-2; i >= 0; i--){
			for(auto x: a[i])e[i] += e[x] + 1;
			e[i] /= a[i].size();
		}
		p[0] = 1.0;
		for(int i=0; i < n; i++){
			for(auto x: a[i]){
				p[x] += p[i]/a[i].size();
			}
		}
		double d = 0.0;
		for(int i=0; i < n; i++){
			if(a[i].size()==1)continue;
			double s = 0.0;
			double f = 0.0;
			for(auto x: a[i]){
				s += e[x];
				updmax(f, e[x]);
			}
			updmax(d, p[i] * (-s+a[i].size()*f)/(a[i].size()*(a[i].size()-1)));
		}
		cout << setprecision(12) <<e[0]-d << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 1408
import math
import collections
import fractions
import itertools

def solve():
    n = int(input())
    d = list(map(int, input().split()))
    m = int(input())
    t = list(map(int, input().split()))
    t = collections.Counter(t)
    d = collections.Counter(d)
    for i in t:
        if t[i] > d[i]:
            print("NO")
            break
    else:
        print("YES")
    return 0

if __name__ == "__main__":
    solve()

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

#define endl "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)

int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) {
        if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1;
    } return res;
}

int now() {
    return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now()
    .time_since_epoch()).count();
}

bool isPalin(string s) {
    int n = s.length();
    int i = 0, j = n - 1;
    while (i < j) {
        if (s[i] != s[j]) {
            return false;
        }
        i++; j--;
    }
    return true;
}

int32_t main() { fastio;
    time_t start = now();

    string s; cin >> s;
    int n= s.length();
    if (isPalin(s) and isPalin(s.substr(0, n / 2)) and isPalin(s.substr((n + 1) / 2, n / 2))) {
        cout << "Yes" << endl; 
    } else {
        cout << "No" << endl;
    }

    cerr << "TIME => " << now() - start << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll A, B, K;
    cin >> A >> B >> K;
    ll a = max((ll)0, A-K);
    K -= (A-a);
    ll b = max((ll)0, B-K);
    cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256