akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

  int N,M,V,P; cin>>N>>M>>V>>P;
  vector<int> A(N); for (auto& a : A) cin>>a;
  sort(A.rbegin(), A.rend());
  vector<long> ca(N);
  for (int i = P; i < N; i++) {
    ca[i] = ca[i-1] + A[P-1]-A[i];
  }
  auto is_ok = [&](int n) {
    if (A[n-1]+M < A[P-1])
      return false;
    long buf = long((P-1)+(N-n+1))*M + ca[n-2] + long(A[n-1]+M-A[P-1])*(n-P);
    return buf >= (long)M*V;
  };
  int ok = P, ng = N+1;
  while (ng-ok > 1) {
    auto c = (ok+ng)/2;
    if (is_ok(c)) {
      ok = c;
    } else {
      ng = c;
    }
  }
  cout << ok << endl;

  return 0;
}


Measured memory_bytes: 1408
N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
kotae = 0
for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    kotae += C[A[i]-1]
kotae += sum(B)
print(kotae)

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,t; cin>>n>>t;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  ll r=0;
  map<ll,ll> m;
  rep(l,n){
    ll tmp=0;
    while(r<n&&a[l]<=a[r]){
      ll d=a[r]-a[l];
      m[d]++;
      r++;
    }
    if(l==r) r++;
  }
  ll ans=0, max=0;
  for(auto e:m){
    if(chmax(max,e.first)) ans=e.second;
  }
  cout<<ans<<endl;
}


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

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

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
    if(debug_flag){
        cout<<str;
    }
}

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

    long x, y;
    cin>>x>>y;
    int cnt=0;
    while(x<=y){
        x*=2;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
char a,b;
string x,y;
int main()
{
	while(a=getchar(),b=getchar(),a!='\n'&&b!='\n')
	{
		x+=a;
		y+=b;
	}
	if(a!='\n')x+=a;
	cout<<x<<endl;
	return 0;
}

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

inline void DFS(vector<int> edge[], vector<bool> &visited, int &c, int v)
{
	visited[v] = true;
	c += 1;
	for(auto x: edge[v])
	{
		if(!visited[x]) DFS(edge, visited, c, x);
	}
} 

int32_t main()
{
	//freopen("input.txt", "r", stdin);
	IOS;
	
	int n; cin >> n;
	int m; cin >> m;
	vector<int> edge[n];

	set<pair<int,int>> Hset;

	while(m--)
	{
		int x; cin >> x;
		int y; cin >> y;
		if(Hset.find({x-1, y-1}) != Hset.end()) continue;
		edge[x-1].push_back(y-1);
		edge[y-1].push_back(x-1);
		Hset.insert({x-1, y-1});
		Hset.insert({y-1, x-1});
	}

	vector<bool> visited(n, false);
	int ans = 0;

	for(int i = 0 ; i < n ; i++) 
	{
		if(visited[i]) continue;
		int c = 0;
		DFS(edge, visited, c, i);
		ans = max(ans, c);
	}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 51772
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
const int INF = (1e9);

vector<int> dijkstra(vector< vector< pair<int,int> > > &G, int s){
  vector<int> ret(G.size(),INF);
  priority_queue< pair<int,int> > wait;
  wait.emplace(0,s);
  while(!wait.empty()){
    int c = -wait.top().first, v = wait.top().second;
    wait.pop();
    if(ret[v] < c) continue;
    ret[v] = c;
    for(size_t i = 0; i < G[v].size(); ++i){
      int c_ = c + G[v][i].first, v_ = G[v][i].second;
      if(c_ < ret[v_]){
        ret[v_] = c_;
        wait.emplace(-c_,v_);
      }
    }
  }
  return ret;
}

int main(){
  int V, E, r;
  cin >> V >> E >> r;
  vector< vector< pair<int,int> > > G(V);
  for(int i = 0; i < E; ++i){
    int s, t, d;
    cin >> s >> t >> d;
    G[s].emplace_back(d,t);
  }
  vector<int> ans = dijkstra(G,r);
  for(int i = 0; i < V; ++i){
    if(ans[i] < INF) cout << ans[i] << endl;
    else cout << "INF" << endl;
  }
  return 0;
}



Measured memory_bytes: 12968
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n, m;

	cin>>n>>m;

	vvi l(n);

	rep(i, m){
		int a, b;
		cin>>a>>b;
		l[a-1].push_back(b-1);
		l[b-1].push_back(a-1);
	}
	rep(i, n){
		cout<<(int)l[i].size()<<endl;
	}
}

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

using namespace std;
#define BUF (1000)
#define ll long long 

ll n,m;

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

	if(n==1){
		n=3;
	}
	if(m==1){
		m=3;
	}

	cout << (n-2)*(m-2) << endl;

	return 0;
}


Measured memory_bytes: 256
# 入力
x1,y1,x2,y2=map(int,input().split())

x3=x2-(y2-y1)
y3=y2+(x2-x1)
x4=x3-(y3-y2)
y4=y3+(x3-x2)

# 出力
print(x3,y3,x4,y4)

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

using namespace std;

#define long long long
#define INF ((long) 1e18)
#define MOD ((long) 1e9 + 7)
#define mll map<long, long>
#define pll pair<long, long>
#define pb push_back
#define FOR(i, a, b) \
  for (long i = (a); i < (long) (b); i++)
#define PRINTV(v) \
  FOR (i, 0, v.size()) cout << v[i] << " "; cout << "\n";

vector<long> gera_primos(long n)
{
  vector<long> primos;
  vector<bool> crivo(n+1);
  primos.pb(2);
  for (long i = 3; i <= n; i += 2) {
    if (crivo[i]) continue;
    primos.pb(i);
    for (long j = i*i; j <= n; j += i) {
      crivo[j] = true;
    }
  }
  return primos;
}

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

  long n;
  cin >> n;

  auto primos = gera_primos(2e3);

  mll d;
  for (auto &p : primos) {
    for (long x = p; x <= n; x *= p) {
      d[p] += n / x;
    }
  }
  long total = 1;
  for (auto &z : d) {
    long x = z.second + 1;
    total = (total * x) % MOD;
  }
  printf("%lld\n", total);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=128;
void Main(){
    int x,n;
    cin>>x>>n;
    vector<int> p(n);
    For(i,0,n) cin>>p[i];
    For(i,0,102){
        if(count(ALL(p),i)>0) continue;
        if(abs(x-i)<abs(x-ans)) ans=i;
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define ll long long
#define inf (1ll<<60)
#define N 200005
#define mod 1000000007
#define rep(i,j,k) for (ll i=j;i<=k;++i)
#define per(i,j,k) for (ll i=j;i>=k;--i)
using namespace std;
inline ll read(){
	char ch=getchar(); ll x=0,f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}
ll n,m,ans=inf,a[N],sum1[N],sum2[N];
int main(){
	n=read();
	rep(i,1,n) a[i]=read();
	rep(i,1,n) sum1[i]=sum1[i-1]+a[i];
	per(i,n,1) sum2[i]=sum2[i+1]+a[i];
	rep(i,1,n-1) ans=min(ans,abs(sum1[i]-sum2[i+1]));
	printf("%lld",ans);
}

Measured memory_bytes: 4864
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int a, b;
 
 
    for (a = 1; a < 10; a++) {
        for (b = 1; b < 10; b++) {
            printf("%dx%d=%d\n", a, b, a*b);
        }
    }
    return 0;
}


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

int main()
{
    int num = 1, n, k;
    cin >> n >> k;
    for(int i=0; i<n; i++)
    {
        if(num * 2 < num + k) num *= 2;
        else num += k;
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class B {
    static final String YES = "Yes";
    static final String NO = "No";

    static long gcd(long x, long y) {
        return y == 0 ? x : gcd(y, x % y);
    }

    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while (T-- > 0) {
            final long A = sc.nextLong();
            final long B = sc.nextLong();
            final long C = sc.nextLong();
            final long D = sc.nextLong();
            if (B > D) {
                System.out.println(NO);
                continue;
            }
            final long aa = A - Math.max(A - C + B - 1, B) / B * B;
            if (aa < 0) {
                System.out.println(NO);
                continue;
            }
            final long gcd = gcd(D, B);
            System.out.println((C - aa + gcd) / gcd * gcd + aa >= B ? YES : NO);
        }
    }
}
public class Main {
    public static void main(String...args) {
        B.main();
    }
}


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

int main()
{
	int n;

	while(std::cin >> n)
	{

		int a=0,b=0,c=0,d=0;
		
		int count=0;
	
		for(a=0; a<=9; ++a)
		{
			for(b=0; b<=9; ++b)	
			{
				for(c=0; c<=9; ++c)
				{	
					for(d=0; d<=9; ++d)
					{
						if(a+b+c+d==n)
						{
							++count;
						}
					}
				}
			}
		}

		std::cout << count << '\n';
	}
}

Measured memory_bytes: 1164
#include "bits/stdc++.h"
using namespace std;
int main(){
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    int a, b, c;
    a = abs(A1 - A2);
    b = abs(A2 - A3);
    c = abs(A3 - A1);
    int ans = a + b + c - max(a, max(b, c));
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
inline int read(){
	int f=1,ans=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}
const int MAXN=2001;
vector<int> vec[MAXN];
priority_queue<int> que;
int N,A[MAXN],M[MAXN][MAXN],vis[MAXN],d[MAXN];
void dfs(int u){
	vis[u]=1;
	for(int i=1;i<=N;i++){
		if(!vis[i]&&M[u][i]){
			vec[u].push_back(i);
			vis[i]=1,d[i]++;dfs(i);
		}
	}return;
}
int main(){
	N=read();for(int i=1;i<=N;i++) A[i]=read();sort(A+1,A+N+1);
	for(int i=1;i<=N;i++) for(int j=2;j<=N;j++) if(__gcd(A[i],A[j])!=1) M[i][j]=M[j][i]=1;
	for(int i=1;i<=N;i++) if(!vis[i]) dfs(i);
	for(int i=1;i<=N;i++) if(!d[i]) que.push(i);
	while(!que.empty()){
		int xx=que.top();que.pop();printf("%d ",A[xx]);
		for(int i=0;i<vec[xx].size();i++){
			int v=vec[xx][i];
			d[v]--;if(!d[v]) que.push(v);
		}
	}printf("\n");return 0;
}


Measured memory_bytes: 16128
#include<bits/stdc++.h>
using namespace std;
int main(void){
	ios_base::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int a,b;
	cin >> a >> b;
	if(a > 9 || b > 9) cout << "-1";
	else cout << a*b;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

ll ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

ll powmod(ll a,ll n,ll m) {
    if(n == 0)
        return 1;

    if(n % 2 ==0){
        ll r = powmod(a,n/2,m);
        return r*r % m;
    }

    return a*powmod(a,n-1,m)%m;
}

int main(){

  string s;
  cin >> s;
  ll n=s.size();

  ll dp[n][13];
  memset(dp,0,sizeof(dp));


  if(s[n-1]!='?'){
    ll a;
    a=ctoi(s[n-1]);
    dp[n-1][a]=1;
  }
  else{
    for(int j=0;j<10;j++){
      ll a=j;
      dp[n-1][a]=1;
    }
  }

  
  for(int i=n-2;i>=0;i--){
    if(s[i]!='?'){
      ll a;
      a=ctoi(s[i]);
      a=a*powmod(10,n-i-1,13)%13;
      for(int k=0;k<13;k++){
        dp[i][(k+a)%13]+=dp[i+1][k];
        dp[i][(k+a)%13]%=mod;
      }
    }
    else{
      for(int j=0;j<10;j++){
        ll a=j;
        a=a*powmod(10,n-i-1,13)%13;
        for(int k=0;k<13;k++){
          dp[i][(k+a)%13]+=dp[i+1][k];
          dp[i][(k+a)%13]%=mod;
        }
      }
    }
  }

  cout << dp[0][5] << endl;
  


}

Measured memory_bytes: 13884
#include <stdio.h>
#include <string.h>

int main(void)
{
    int len, i;
    char str1[100000];
    char str2[100000];

    scanf("%s",str1);
    len = strlen(str1);

    if (len%2) {
        printf("No");
        return 0;
    }
    for (i = 0; i < len; i++) {
        str2[i] = str1[len-1-i];
        if (str2[i] == 'b') {
            str2[i] = 'd';
        } else if (str2[i] == 'd') {
            str2[i] = 'b';
        } else if (str2[i] == 'p') {
            str2[i] = 'q';
        } else if (str2[i] == 'q') {
            str2[i] = 'p';
        }
    }
    for (i = 0; i < len-1; i++) {
        if (str1[i] != str2[i]) {
            printf("No");
            return 0;
        }
    }
    printf("Yes");

    return 0;
}


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

int main(){
	int n, m;
	cin >> n >> m;
	
	int a[m], b[m], c[m];
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
		c[i];
	}
	
	const int MAX = 10000000;
	
	int dist[n][n];
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			dist[i][j] = MAX;
		}
		dist[i][i] = 0;
	}
	
	for(int i = 0; i < m; i++){
		dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
		dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
	}
	
	for(int k = 0; k < n; k++){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < m; i++){
		if(dist[a[i]][b[i]] < c[i]){
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    if (K > (N - 1) * (N - 2) / 2) cout << -1 << endl;
    else {
        cout << N * (N - 1) / 2 - K << endl;
        for (int i = 2; i <= N; i++)
            cout << 1 << " " << i << endl;
        int cnt = 0, limit = (N - 1) * (N - 2) / 2 - K;
        for (int i = 2; i <= N && cnt < limit; i++)
            for (int j = i + 1; j <= N && cnt < limit; j++, cnt++)
                cout << i << " " << j << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n, k, w[100000];
  int i;
  int sum = 0;
  int max = 0;

  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d", &w[i]);
    sum += w[i];
    if ( w[i] > max )
      max = w[i];
  }

  int low = sum / k + ((sum%k) ? 1 : 0);
  if (max > low)
    low = max;
  //  printf("low = %d\n", low);
  int P = low;
  int tmp = 0;
  int tmpk = 0;
  int j;
  for (;; P++) {
    i = 0;
    tmpk = 0;
    while (1) {
      for (; P >= tmp + w[i] && i != n; i++) {
	tmp += w[i];
      }
      tmp = 0;
      tmpk++;
      if (tmpk > k)
	break;
      if (i == n) {
	printf("%d\n", P);
	return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int h , w;
    cin >> h >> w;
    vector<string > s(h);
    for(int i=0;i<h;i++){
    	cin >> s[i];
    }
    int dx[8] = {-1, -1, -1, 0 ,0 , 1, 1, 1};
    int dy[8] = {-1, 0, 1, -1, 1, -1, 0 , 1};
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		int ret = 0;
    		if(s[i][j] == '#') continue;
    		for(int k=0;k<8;k++){
    			int x = j+ dx[k];
    			int y = i + dy[k];
    		    if(x < 0 or x >= w or y < 0 or y >= h) continue;
    		    if(s[y][x] == '#') ret++;
    		} 
    		s[i][j] = char(ret + '0');
    	}
    }
    for(int i=0;i<h;i++){
    	cout << s[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
import std.stdio,std.conv,std.string,std.algorithm;
void main(){
  auto ab=readln().chomp().split().map!(to!int);
  int a=ab[0],b=ab[1];
  
  if(a%2==0 || b%2==0) writeln("Even");
  else writeln("Odd");
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {

	int r, D, x2000;

	cin >> r >> D >> x2000;

	int x200i = x2000;

	for (int i = 1; i <= 10; ++i) {

		x200i = (r * x200i) - D;

		cout << x200i << endl; 
	}

	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll H, W;
  cin >> H >> W;
  if(H == 1 || W == 1) cout << 1 << endl;
  else cout << ((W+1)/2)*((H+1)/2) + (W/2)*(H/2) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int h, n;
    cin >> h >> n;
    int sum=0;
    rep(i, n){
        int x;
        cin >> x;
        sum += x;
    }
    if(sum>=h){
        cout << "Yes";
    }else{
        cout << "No";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int a, b, c;
    std::cin >> a >> b >> c;

    if (a <= b) {
        if (b <= c) {
            std::cout << a+b << std::endl;
        } else {
            std::cout << a+c << std::endl;
        }
    } else {
        if (a <= c) {
            std::cout << a+b << std::endl;
        } else {
            std::cout << c+b << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

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

    if ((N % 3 == 0) && (N >= 3)) {
        cout << N / 3 << endl;
        return 0;
    } else if ((N % 3 == 1) || (N % 3 == 2) && (N >= 3)) {
        cout << N / 3 << endl;
        return 0;
    }
    cout << 0<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll m;
    cin >> m;
    cout << (24-m) + 24<< endl;
    return 0;
}

Measured memory_bytes: 3188
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int g[20][20];
int dp[1<<15][15];
int t[1<<15];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int sum=0;
	for(int i=0;i<b;i++){
		int p,q,r;scanf("%d%d%d",&p,&q,&r);p--;q--;
		g[p][q]=g[q][p]=r;
		sum+=r;
	}
	for(int i=0;i<(1<<a);i++)for(int j=0;j<a;j++)dp[i][j]=-mod;
	dp[0][0]=0;
	for(int i=0;i<(1<<a);i++){
		for(int j=0;j<a;j++){
			if(i&(1<<j)){
				for(int k=j+1;k<a;k++){
					if(i&(1<<k))t[i]+=g[j][k];
				}
			}
		}
	}
	for(int i=0;i<(1<<a);i++){
		for(int j=0;j<a;j++){
			if(dp[i][j]<0)continue;
			//printf("%d %d: %d\n",i,j,dp[i][j]);
			int mask=(1<<a)-1-i;
			int at=mask;
			while(at){
				if(!((at&(1<<(a-1)))&&at!=mask)&&!(i==0&&at==(1<<a)-1)){
					for(int k=0;k<a;k++){
						if((at&(1<<k))&&(j==k||g[j][k]))dp[i+at][k]=max(dp[i+at][k],dp[i][j]+g[j][k]+t[at]);
						if(i==0)break;
					}
				}
				at=(at-1)&mask;
			}
		}
	}
	printf("%d\n",sum-dp[(1<<a)-1][a-1]);
}

Measured memory_bytes: 2304
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# 
# s = input()

N, R = list(map(int, input().split()))
if N >= 10:
    ans = R
else:
    ans = R + 100 * (10 - N)

print(ans)



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



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
    char date[4];
    cin>>date;
    int a =0;
    a+=date[0]-'0';
    a*=10;
    a+=date[1]-'0';
	int b =0;
    b+=date[2]-'0';
    b*=10;
    b+=date[3]-'0';

    bool c1=false;
    bool c2=false;

    if(a>=1 and a<=12)
    	c1=true;
    if(b>=1 and b<=12)
    	c2=true;
    if(c1 and c2)
    	cout<<"AMBIGUOUS";
    else if(c1)
    	cout<<"MMYY";
    else if(c2)
    	cout<<"YYMM";
    else
    	cout<<"NA";

}

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

#define Mod 1000003

typedef struct List {
	struct List *next;
	char s[20];
	int num[2];
} list;

int hash_string(char* s)
{
	int i;
	long long x = 0;
	for (i = 0; s[i] != 0; i++) {
		x += s[i] - 'a';
		x = x << 3;
	}
	return (int)(x % Mod);
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{	
	int N;
	char S[40];
	scanf("%d", &N);
	scanf("%s", S);
	
	int h, i, j, k, l, bit[19];
	for (i = 1, bit[0] = 1; i <= N; i++) bit[i] = bit[i-1] << 1;
	long long ans = 0;
	char T[20] = {};
	list *hash[Mod] = {}, *p, *d = (list*)malloc(sizeof(list) * bit[N] * 2);
	for (k = 0; k < bit[N]; k++) {
		for (i = 0, j = 0, l = N - 1; i < N; i++) {
			if ((k | bit[i]) == k) T[j++] = S[i];
			else T[l--] = S[i];
		}
		T[N] = 'a' + j;
		h = hash_string(T);
		for (p = hash[h]; p != NULL; p = p->next) if (lex_smaller(p->s, T) == 0) break;
		if (p != NULL) p->num[0]++;
		else {
			for (j = 0; j <= N; j++) d[k*2].s[j] = T[j];
			d[k*2].s[N+1] = 0;
			d[k*2].num[0] = 1;
			d[k*2].num[1] = 0;
			d[k*2].next = hash[h];
			hash[h] = &(d[k*2]);
		}
		
		for (i = 0, j = 0, l = N - 1; i < N; i++) {
			if ((k | bit[i]) == k) T[j++] = S[N*2-i-1];
			else T[l--] = S[N*2-i-1];
		}
		T[N] = 'a' + j;
		h = hash_string(T);
		for (p = hash[h]; p != NULL; p = p->next) if (lex_smaller(p->s, T) == 0) break;
		if (p != NULL) p->num[1]++;
		else {
			for (j = 0; j <= N; j++) d[k*2+1].s[j] = T[j];
			d[k*2+1].s[N+1] = 0;
			d[k*2+1].num[0] = 0;
			d[k*2+1].num[1] = 1;
			d[k*2+1].next = hash[h];
			hash[h] = &(d[k*2+1]);
		}
	}
	
	for (h = 0; h < Mod; h++) {
		for (p = hash[h]; p != NULL; p = p->next) ans += (long long)(p->num[0]) * p->num[1];
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 29984
import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
#from scipy.sparse.csgraph import dijkstra
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**8)

def main():
    n=int(input())
    grid=[list(map(int,input().split()))for i in range(n)]
    p=floyd_warshall(csgraph=csr_matrix(grid))
    q=[list(i) for i in p]
    
    if q!=grid:
        print(-1)
    else:
        for i in range(n):
            p[i][i]=float("inf")
        ans=0
        for i in range(n):
            for j in range(i):
                if p[i][j]<min(np.array(p[i])+np.array(p[j])):
                    
                    ans+=p[i][j]
        print(int(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 32144
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int A, B, Q;
    cin >> A >> B >> Q;
    vl s(A), t(B), X(Q);
    rep(i, A) cin >> s[i];
    rep(i, B) cin >> t[i];
    rep(i, Q) cin >> X[i];
    rep(q, Q) {
        vl a(2, INF), b(2, INF);
        {
            auto it = lower_bound(all(s), X[q]);
            if(it != s.end()) a[0] = *it;
            if(it != s.begin()) {
                --it;
                a[1] = *it;
            }
        }
        {
            auto it = lower_bound(all(t), X[q]);
            if(it != t.end()) b[0] = *it;
            if(it != t.begin()) {
                --it;
                b[1] = *it;
            }
        }
        ll ans = INF;
        ll x = X[q];
        rep(i, 2) rep(j, 2) {
            if(a[i] == INF || b[j] == INF) continue;
            if(min(a[i], b[j]) < x && x < max(a[i], b[j])) {
                ll L = max(a[i], b[j]) - min(a[i], b[j]);
                ll d = min(x - min(a[i], b[j]), max(a[i], b[j]) - x);
                ans = min(ans, L+d);
            }
            else ans = min(ans, max({a[i], b[j], x}) - min({a[i], b[j], x}));
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

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


int main() {
    ll N;
    cin >> N;
    vector<ll> ans(4);
    rep(i,N){
        string s;
        cin >> s;
        if(s == "AC"){
            ans[0]++;
        }else if(s == "WA"){
            ans[1]++;
        }else if(s == "TLE"){
            ans[2]++;
        }else{
            ans[3]++;
        }
    }

    cout << "AC x " << ans[0] << endl;
    cout << "WA x " << ans[1] << endl;
    cout << "TLE x " << ans[2] << endl;
    cout << "RE x " << ans[3] << endl;
}




Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> cards;
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    string s; cin >> s;
    cards[s]++;
  }
  int M; cin >> M;
  for (int i = 0; i < M; i++) {
    string s; cin >> s;
    cards[s]--;
  }
  int ans = 0;
  for (auto x: cards) {
    ans = max(ans, x.second);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31); // 2147483647
 
const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) { return (a % b + b) % b; }
 
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
 
int main(){
    cin.sync_with_stdio(false);
    string s, t;
    ll n,m;
    cin >> n >> m;
    cin >> s >> t;
    ll l = (n*m)/gcd(n,m);
    map<int, char> mem;
    rep(i,0,n){
        mem[i*(l/n)] = s[i];
    }
    rep(i,0,m){
        if(mem.find(i*(l/m)) != mem.end()){
            if(mem[i*(l/m)] != t[i]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(long long i=I;i<A;i+=B)
#define rep(I,A,B) for(long long j=I;j<=A;j+=B)
#define repp(I,A,B) for(long long j=I;j>=A;j-=B)
#define str(A) for(long long k=0;A[k]!='\0';k++)
#define pb push_back
#define mp make_pair
#define pii pair<long long,long long>
vector <int> adj[100001];
bool visit[100001];
const int mod = 1000000007;
ll dp[100002][4],a[100001],b[100001],c[100001];
ll func(ll i,ll j)
{
	if(i<0)
		return 0;
	if(dp[i][j]==-1)
	{
		if(j==0)
			dp[i][j]=max(func(i-1,1),func(i-1,2))+a[i];
		else if(j==1)
			dp[i][j]=max(func(i-1,2),func(i-1,0))+b[i];
		else
			dp[i][j]=max(func(i-1,0),func(i-1,1))+c[i];
	}
	return dp[i][j];
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,i;
	cin>>n;
	FOR(0,n,1)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	FOR(0,100002,1)
		rep(0,3,1)
			dp[i][j]=-1;
	cout<<max(func(n-1,2),max(func(n-1,0),func(n-1,1)));
	return 0;
}

Measured memory_bytes: 12800
# E - League
import sys
from collections import deque
from typing import Deque, List

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    A: List[Deque[int]] = [deque()] + [
        deque(map(int, line.split())) for line in readlines()
    ]
    matched_games_cnt = 0
    next_opponent, last_games_day = [0] * (N + 1), [0] * (N + 1)
    queue = deque(range(1, N + 1))
    while queue:
        player = queue.popleft()
        if not A[player]:  # The player has finished all games.
            continue
        opponent = A[player].popleft()

        # The opponent will have another game before playing against x.
        if next_opponent[opponent] != player:
            next_opponent[player] = opponent
            continue

        # The opponent's next game is against the player and vice versa.
        matched_games_cnt += 1
        last_games_day[player] = last_games_day[opponent] = (
            max(last_games_day[player], last_games_day[opponent]) + 1
        )
        # No next game is currently planned.
        next_opponent[player] = next_opponent[opponent] = 0
        queue.append(player), queue.append(opponent)

    print(max(last_games_day) if matched_games_cnt == N * (N - 1) // 2 else -1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 114276
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    vector<vector<char>> mat(3, vector<char>(3, 0));
    for (auto && i: irange(0U, 3U)){
        for (auto &&j: irange(0U, 3U)){
            cin >> mat.at(i).at(j);
        }
    }
    for (auto &&i: irange(0U, 3U)){
        cout << mat.at(i).at(i);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){
    int n;
    while(cin>>n&&n!=0){
        int cnt=0;
        int sum=0;
        for(int i=0;i*i<=n;i++){
            sum+=i*i;
            for(int j=i;j*j+sum<=n;j++){
                sum+=j*j;
                for(int k=j;k*k+sum<=n;k++){
                    sum+=k*k;
                    for(int l=k;l*l+sum<=n;l++){
                        sum+=l*l;
                        if(sum==n)
                            cnt++;
                        sum-=l*l;
                    }
                    sum-=k*k;
                }
                sum-=j*j;
            }
            sum-=i*i;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    int cnt=0;
    while(1){
        if(a%2==1||b%2==1||c%2==1){
            cout<<cnt<<endl;
            break;
        }
        if(a==b&&b==c){
            cout<<-1<<endl;
            break;
        }
        ll ta=b/2+c/2,tb=a/2+c/2,tc=a/2+b/2;
        a=ta,b=tb,c=tc;
        ++cnt;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=305;
char s[N];
int n,f,dp[N][N][N];
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    scanf("%d",&f);
    int ans=1;
    for(int i=1;i<=n;i++)
        for(int j=n;j>i;j--)
        for(int k=0;k<=f;k++)
    {
        dp[i][j][k]=max(dp[i-1][j][k],dp[i][j+1][k]);
        if(s[i]==s[j])
            dp[i][j][k]=max(dp[i][j][k],dp[i-1][j+1][k]+1);
        if(k>0)
            dp[i][j][k]=max(dp[i][j][k],dp[i-1][j+1][k-1]+1);
        ans=max(ans,dp[i][j][k]*2);
        if(i+1==j-1)
            ans=max(ans,dp[i][j][k]*2+1);
    }
    printf("%d\n",ans);
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long

const LL INF = (LL)1e18;



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	 int n, m;
    cin >> n >> m;
 
    vector<int> a(m), b(m), c(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
    }
 
    vector<long long> d(n, -INF);
    d[0] = 0;
 
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            d[b[j]] = min(max(d[b[j]], d[a[j]] + c[j]), INF);
        }
    }
    for (int j = 0; j < m; j++) {
        if (d[b[j]] < d[a[j]] + c[j]) {
            d[b[j]] = INF;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            d[b[j]] = min(max(d[b[j]], d[a[j]] + c[j]), INF);
        }
    }
 
    if (d[n - 1] == INF) {
        cout << "inf" << endl;
    } else {
        cout << d[n - 1] << 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++)

int main() {
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> c(n);
  vector<vector<int>> avi(n,vector<int>(m));
  rep(i,n){
    cin>>c[i];
    rep(j,m){
      cin>>avi[i][j];
    }
  }
  int min_cost = 1200010;
  bool ch = false;
  for(int tmp=0; tmp<(1<<n); tmp++){ 
    bitset<12> b(tmp);
    int tmp_cost = 0;
    vector<int> tmp_avi(m,0);
    rep(i,n){ 
      if(b.test(i)){
        tmp_cost+=c[i];
        rep(j,m){
          tmp_avi[j]+=avi[i][j];
        }
      }
    } 
    bool suc =true;
    rep(i,m){
      if(tmp_avi[i]<x){
        suc = false;
      }
    }
    if(suc){
      min_cost=min(min_cost,tmp_cost);
      ch = true;
    }
  }
  if(ch){
    cout<<min_cost<<endl;
  }else{
    cout<<-1<<endl;
  }
}



Measured memory_bytes: 3636
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn main() {
    input! {
        n: usize,
        av: [u128; n]
    };

    if av.contains(&0) {
        println!("0");
        std::process::exit(0);
    }

    let max = 1000000000000000000_u128;
    let mut cur = 1_u128;
    for a in av {
        cur *= a;
        if cur > max {
            println!("-1");
            std::process::exit(0);
        }
    }
    println!("{}", cur);
}


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

using namespace std;

typedef long long int64;

int main()
{
  int N, M, X[100000], Y[100000];
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
  }

  set< pair< int, int > > toA, toB;
  for(int i = 0; i < N; i++) toA.emplace(X[i], i);
  for(int i = 0; i < N; i++) toB.emplace(Y[i], i);

  typedef pair< int, int > Pi;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  int64 ret = 0;
  que.emplace(0, 0);
  bool used[100000] = {};
  while(!que.empty()) {
    int aa = que.top().first;
    int p = que.top().second;
    que.pop();
    if(used[p]++) continue;
    ret += aa;

    pair< int, int > qq(X[p], p);
    {

      auto s = toA.lower_bound(qq);
      if(s != toA.begin()) que.emplace(X[p] - prev(s)->first, prev(s)->second);
      ++s;
      if(s != toA.end()) que.emplace(s->first - X[p], s->second);
    }

    {
      qq.first = Y[p];
      auto s = toB.lower_bound(qq);
      if(s != toB.begin()) que.emplace(Y[p] - prev(s)->first, prev(s)->second);
      ++s;
      if(s != toB.end()) que.emplace(s->first - Y[p], s->second);
    }
  }

  cout << ret << endl;
}


Measured memory_bytes: 12664
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  ll X, Y;
  cin >> X >> Y;
  int ans = 1;
  while (X * 2 <= Y) {
    X *= 2;
    ans++;
  }
  print(ans);
  return 0;
}

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

int main()
{
  int64_t n, ans, i, dev;
  dev = 1;
  ans = 1;
  cin >>n;
  for(i=0; i<9; i++)
  {
    dev *= 10;
  }
  dev += 7;
  for(i=1; i<=n; i++)
  {
    ans *= i;
    ans %= dev;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char s[6];
    cin >> s;
    if (s[2]==s[3]&&s[4]==s[5]){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

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

int main() {
  int N, K,sum;
  sum =0;
  cin>>N>>K;
  
  for(int i=0;i<N;i++){
  	int x;
    cin >>x;
    if(x <= K-x){
    	sum += x*2;
    }
    else{
    	sum += 2*(K-x);
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)

#define mp make_pair
#define fi first
#define se second

#define bit(n) (1LL<<(n))

void Main()
{
  i64 N;
  cin >> N;

  vector<i64> h(N);
  rep(i,N) cin >> h[i];

  vector<i64> dp(N,INF);
  dp[0] = 0;

  rep(i,N-1){
    if(i+1 > N-1) continue;
    dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
    if(i+2 > N-1) continue;
    dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
  }
  cout << dp[N-1] << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fr first
#define se second
#define pb push_back

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N;cin>>N;
  string S;cin>>S;
  int ans=-1;
  REP(i,1,S.size()){
    string X=S.substr(0,i),Y=S.substr(i,S.size()-i);
    set<char> X_set,Y_set;
    each(x,X){
      X_set.insert(x);
    }
    each(y,Y){
      Y_set.insert(y);
    }
    set<char> XY_set;
    set_intersection(ALL(X_set),ALL(Y_set),std::inserter(XY_set, XY_set.end()));

    ans=max(ans,(ll)XY_set.size());

  }
  print(ans);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
void self_min(int &a,int b){
	a = min(a,b);
}
int main(){
	ll a,b,k;
	cin >> a >> b >> k;

	if(a >= k){
		cout << a-k <<" " << b << endl;
	}else if((a+b) >= k){
		cout << 0 << " " << (a+b) - k << endl;
	}else{
		cout << 0 << " " << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,t1,ans,a[500010],b[500010],cnt[500010];
void ins(int x){
	if(x<1)return;
	if(!cnt[x])ans++;
	cnt[x]++;
}
void dec(int x){
	if(x<1)return;
	if(cnt[x]==1)ans--;
	cnt[x]--;
}
int main(){
	int i,x,y;
	scanf("%d%d",&n,&t1);
	for(i=1;i<=n;i++){
		scanf("%d",&x);a[x]++;
		ins(x-a[x]+1);
		b[i]=x;
	}
	while(t1--){
		scanf("%d%d",&x,&y);
		dec(b[x]-a[b[x]]+1);a[b[x]]--;
		b[x]=y;a[y]++;
		ins(y-a[y]+1);
		printf("%d\n",n-ans);
	}
}

Measured memory_bytes: 4992
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#include "atcoder/all"
#else
#define NDEBUG
#include <atcoder/all>
#include <bits/stdc++.h>
#endif

using namespace std;
using namespace atcoder;

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

    auto f = fenwick_tree<unsigned long long>(n);
    for (int i = 0; i < n; ++i) {
        int ai;
        cin >> ai;
        f.add(i, ai);
    }

    for (int i = 0; i < q; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        if (a == 0) {
            f.add(b, c);
        }
        if (a == 1) {
            cout << f.sum(b, c) << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 8204
#include<stdio.h>
#include<algorithm>

using namespace std;

int main(){
	int n,a,b,c;
	int m=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a[3];
		for(int j=0;j<3;j++)scanf("%d",&a[j]);
		std::sort(a,a+3);
		
		m=max(m,a[2]);
		
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2])puts("YES");
		else{
			if(m<50)puts("NO");
			else puts("YES");
		}
	}
}

Measured memory_bytes: 0