akhauriyash/Code-Regression huggingface dataset:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

x, a, b = na()
if a >= b:
    print("delicious")
elif b - a > x:
    print('dangerous')
else:
    print('safe')


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

#define POS(i,j) ((i)*w+(j))
#define MIN(a,b) ((a)<(b)?(a):(b))

typedef struct point2d{
  int x,y;
} point;

int calc(point p,int h,int w,int k){
  int a=(p.x+k-1)/k;
  int b=(h-1-p.x+k-1)/k;
  int c=(p.y+k-1)/k;
  int d=(w-1-p.y+k-1)/k;
  return MIN(a,MIN(b,MIN(c,d)));
}

void run(void){
  int h,w,k;
  scanf("%d%d%d",&h,&w,&k);
  char *board=(char *)calloc(h*w+1,sizeof(char));
  int i,j;
  for(i=0;i<h;i++) scanf("%s",board+i*w);
  point s={0,0};
  for(i=0;i<h*w;i++){
    if(board[i]=='S'){
      s=(point){i/w,i%w};
      break;
    }
  }
  int min=h*w;
  point *now=(point *)calloc(h*w,sizeof(point));
  point *next=(point *)calloc(h*w,sizeof(point));
  int top=0;
  now[top++]=s;
  board[POS(s.x,s.y)]='#';
  for(i=0;i<=k;i++){
    int ntop=0;
    while(top>0){
      point t=now[--top];
      min=MIN(min,calc(t,h,w,k)+1);
      int d[]={1,0,-1,0};
      for(j=0;j<4;j++){
	int x=t.x+d[j];
	int y=t.y+d[j^1];
	if(0<=x && x<h && 0<=y && y<w && board[POS(x,y)]!='#'){
	  board[POS(x,y)]='#';
	  next[ntop++]=(point){x,y};
	}
      }
    }
    point *swap=now;
    now=next;
    next=swap;
    top=ntop;
  }
  printf("%d\n",min);
}

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


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

int main(){
  int a,b;
  cin >>a >>b;
  if(a+b>=10) cout << "error" << endl;
  else cout << a+b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long n,W,w[102],v[102],f[102][100005];
int main()
{
    cin >> n >> W;
    for (int i=1;i<=n;i++)
        cin >> w[i] >> v[i];
    for (int i=1;i<=n;i++)
        for (int j=1;j<=W;j++)
            f[i][j]=(w[i]>j)?f[i-1][j]:max(f[i-1][j],f[i-1][j-w[i]]+v[i]);
    cout << f[n][W];
    return 0;
}

Measured memory_bytes: 81752
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)

int main(){
 
 
  ll k,n;
  cin>>k>>n;
 
  vector<ll> A(n);
  rep(i,n){
      cin>>A[i];
  }
 ll ma=0;
  Rep(i,n){
    ma=max(ma,A[i]-A[i-1]);
  }
  ma=max(ma,k-A[n-1]+A[0]);
  cout<<k-ma<<endl;

 
}



Measured memory_bytes: 4772
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List

solve :: [String] -> [String]
solve [] =[]
solve (x:xs) = x:x:(solve xs)

main :: IO ()
main = do
    [h, w] <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    c <- replicateM h (BS.unpack <$> BS.getLine)
    let s = solve c
    forM_ s putStrLn


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

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

const int MAX_N = 10000010;

int n, quad[MAX_N], max_q;
bool sieve[MAX_N];


void solve() {
  int res = 0;
  for(int i=1;i<max_q;i++) {
    if (quad[i] > n) {
      res = quad[i-1];
      break;  
    }
  }
  if (res == 0) res = quad[max_q-1];
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  memset(sieve, true, sizeof sieve);
  for(int i=4;i<MAX_N;i+=2) sieve[i] = false;

  for(int i=3;i<MAX_N;i+=2) if(sieve[i]) for(int j=i+i;j<MAX_N;j+=i)
  sieve[j] = false;
  
  memset(quad, 0, sizeof quad);
  quad[0] = 13; quad[1] = 19;
  int ii = 2;
  for(int i=23;i<MAX_N;i+=2) {
    if (sieve[i-8] && sieve[i-6] && sieve[i-2] && sieve[i]) {
      quad[ii] = i;
      ii++;
    }
  }
  
  max_q = ii;
  //rep(i,ii) cout<<quad[i]<<endl;
  
  while (cin>>n, n) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		sc.close();
		long mod = (long)Math.pow(10, 9) + 7;
		long[] cnt = new long[26];
		for(int i = 0; i < N; i++) {
			cnt[S.charAt(i) - 'a']++;
		}
		long ans = 1;
		for(long i : cnt) {
			ans = (i + 1) * ans % mod;
		}
		ans -= 1;
		ans %= mod;
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

long long int binary(long long int x,long long int k, long long int d) {
    long long int low =0;
    long long int high = x;

    while(low<high) {
        long long int mid = (low+high)/2LL;
        if (((x - mid) / k) < d) {
            high = mid;
        }
        else {
            low = mid+1;
        }
    }
    return low;

}
int main() {

    jaldi

    long long int x;
    long long int k;
    long long int d;
    cin>>x;
    cin>>k;
    cin>>d;
    x=abs(x);
    long long int temp = x/d;
    if(temp > k) { // doesnt even cross zero
        long long int ans = x - k*d;
        cout<<ans<<'\n';
    }
    else if(temp ==k && x%d==0){
        cout<<0<<'\n';
    }
    else if(temp ==k && x%d!=0){
        long long int ans1 = (x%d);
        cout<< ans1<<'\n';
    }
    else {
        long long int temp1 = (x%d);
        long long int temp2 = (x%d) - d;
        long long int num = (x/d);
        long long int rem = (k-num);
        if(rem%2==0) {
            cout<<temp1<<'\n';
        }
        else {
            cout<<abs(temp2)<<'\n';
        }
    }

}


Measured memory_bytes: 3568
/*#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>*/
#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);


typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = {1,0,-1,0};
ll dy[4] = {0,1,0,-1};
int main(){
    ll a=0,b=0,c=0,d=0,ans=0,ret=M,n,m;
	string s;
	bool x = false;
	vi v(4);
	rep(i,4) cin >> v[i];
	sort(all(v));
	if(v[0] == 1){
		if(v[1] == 4){
			if(v[2] == 7){
				if(v[3] == 9){
					cout << "YES\n";
					return 0;
				}
			}
		} 
	}
	cout << "NO\n";
    return 0;
}  


Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())
if a + b >= 2*c:
	if x >= y:
		ans = 2*y*c + (x-y)*min(a,2*c)
	else:
		ans = 2*x*c + (y-x)*min(b,2*c)
else:
	ans = (x*a + y*b)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7;
ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}


int main(){
 
  ll N;
  cin>>N;
  
  vector<string>S(N);
  vector<ll>date(5);

  ll max=0;
  
  for(ll i=0;i<N;i++){
cin>>S[i];
   if(S[i][0]=='M'){
     date[0]++;
   }
    else if(S[i][0]=='A'){
     date[1]++;
    }
    else if(S[i][0]=='R'){
     date[2]++;
    }
else if(S[i][0]=='C'){
  date[3]++;
}
    else if(S[i][0]=='H'){
date[4]++;
    }
    
  }
  
  for(ll i=0;i<power(2,5);i++){
    bitset<5>A(i);
    
    string B=A.to_string();
    
    ll sum=0;
    ll ans=1;
   
    
    for(ll i=0;i<5;i++){
      if(B[i]=='1'){
        
        sum++;
      ans*=date[i];
      }
    }
    if(sum==3){
      max+=ans;
    }

  
  }
  
  
  

  cout<<max<<endl;
}
  
  

Measured memory_bytes: 6144
#include <stdio.h>

#define MAX 100000000

struct NODE {
    int distance;
    int state;
} vertex[101];

int W[101][101];
int V, n, sum;

int min(int a, int b) {
    return (a > b ? b : a);
}

void prim(int start) {
    int x, p, step;

    for (x = 0; x < V; x++) {
	vertex[x].distance = MAX; vertex[x].state = 0;
    }
    vertex[start].distance = 0; 
    for (step = 1; step <= V; step++) {
	int minimum = MAX;
	for (x = 0; x < V; x++)
	    if (vertex[x].state == 0 && vertex[x].distance < minimum) {
		p = x; minimum = vertex[x].distance;
	    }
	vertex[p].state = 1;
	sum += minimum;
	for (x = 0 ; x < V; x++)
	    if (vertex[x].state == 0)
		vertex[x].distance = min(vertex[x].distance, W[p][x]);
    }
}

int main(void) {
    int i, j;
    int from, to, m;
     
    while (1) {
	scanf("%d", &V);
        if (V == 0) break;
	scanf("%d", &n);
         
        for (i = 0; i <= V; i++)
            for (j = 0; j <= V; j++)
                W[i][j] = MAX;
         
	for (i = 0; i < n; i++) {
            scanf("%d,%d,%d", &from, &to, &m);
            W[from][to] = (m / 100) - 1;
	    W[to][from] = (m / 100) - 1;
        }

	sum = 0;

        prim(0);

	printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 640
/*
* @Author: _dp95
* @Date:   2019-11-09 01:20:19
*/
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

const int MAX = 2*1000*100 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

ll dp[ MAX ][ 100 ], w[ MAX ], v[ MAX ], n, m ;

ll sol( int i, ll m ){  
  if( m < 0 )
    return -INF ;
  if( i>=n )
    return 0 ;
  if( !m )
    return 0 ;
  if( dp[m][i] + 1 )
    return dp[m][i] ;
  ll inc = v[i] + sol( i+1, m-w[i] ) ;
  ll exc = sol( i+1, m ) ;
  return dp[m][i] = max( inc, exc ) ;
}

int main( ){
  timesaver ;
  mem( dp, -1 ) ;
  cin >> n >> m ;
  for( int i = 0 ; i < n ; i++ )
    cin >> w[i] >> v[i] ;
  cout << sol( 0, m ) << nl ;
}

Measured memory_bytes: 157568
#include<stdio.h>

int main(void)
{
  int n, m, x, y, z, i, max, min;
  scanf("%d %d %d %d", &n, &m, &x, &y);
  max = x; min = y;
  for(i = 0; i < n; i++){
    scanf("%d", &x);
    if(x > max) max = x;
  }
  for(i = 0; i < m; i++){
    scanf("%d", &y);
    if(y < min) min = y;
  }
  if(max < min){
    printf("No War\n");
  }else{
    printf("War\n");
  }

  return 0;
}

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



int cd=100000;

int d,c[26],s[366][26];
int t[366];
ll r;

void init(){
    cin>>d;
    REP(i,26)cin>>c[i];
    REP(i,d)REP(j,26)cin>>s[i][j];
}

void greedy(){
    REP(i,d)REP(j,26)t[i]=s[i][j]>s[i][t[i]]?j:t[i];
}

ll score(int *t){
    ll ans=0;vector<int>cnt(26,0);
    REP(i,d){
        cnt[t[i]]=-1;
        ans+=s[i][t[i]];
        REP(j,26)cnt[j]++,ans-=cnt[j]*c[j];
    }
    return ans;
}

void crt_new(){
    int idx=rand()%d;
    int q=rand()%26;
    while(q==t[idx])q=rand()%26;
    int tmp=t[idx];
    t[idx]=q;
    ll res=score(t);
    if(res>r)r=res;
    else t[idx]=tmp;
}

void solve()
{

    init();
    // ll begin_t=clock();
    greedy();
    r=score(t);
    while(cd--)crt_new();
    // REP(i,d)cout<<t[i]<<" ";cout<<endl;
    REP(i,d)cout<<t[i]+1<<endl;
    // cout<<r<<endl;

    // ll end_t=clock();cout<<end_t-begin_t<<"ms"<<endl;
}

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

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

using namespace std;
using ll = long long;

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

    ll N, D;
    cin>>N>>D;

    int cnt = 0;
    for(int i=0;i<N;i++){
        ll x, y;
        cin>>x>>y;
        if(x*x + y*y <= D*D){
            cnt++;
        }
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    unsigned int x; cin >> x;
    unsigned int total = 0;
    int b = x/500;
    total = 1000*b; x -= 500*b;
    x -= x%5;
    total += x;
    cout << total << endl;
    return 0;
}


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

int main(){
  int N, X, L[100];
  int pos = 0;
  cin >> N >> X;
  for(int i=0;i<N;i++) {
    cin >> L[i];
  }
  int n = 0;
  while(n < N){
    if(pos + L[n] > X) break;
    pos += L[n];
    n++;
  }
  cout << n + 1 << endl;
  return 0;
}


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

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    int T=1;//; cin >> T;
    while(T--){
        int n; cin >> n;
        if(n>=30) cout << "Yes";
        else cout << "No";
        cout << '\n';
        
    }
    return 0;
}

Measured memory_bytes: 3648
import sys


N = int(input())
W = [input() for _ in range(N)]

for i in range(1, N):
    if W[i] in W[:i]:
        print('No')
        sys.exit()
    else:
        if W[i][0] != W[i-1][-1]:
            print('No')
            sys.exit()
print('Yes')


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<list>
using namespace std;
static const int MAX = 100000;
static const int INFTY = (1<<29);

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s){
    queue<int> q;
    q.push(s);
    V[s] = true;
    while( !q.empty() ){
        int u = q.front(); q.pop();
        out.push_back(u);
        for(int i=0; i<G[u].size(); i++){
            int v = G[u][i];
            indeg[v]--;
            if(indeg[v] == 0 && !V[v]){
                V[v] = true;
                q.push(v);
            }
        }
    }    
}

void tsort(){
    for(int i=0; i<N; i++){
        indeg[i] = 0;
    }

    for(int u=0; u<N; u++){
        for(int i=0; i<G[u].size(); i++){
            int v = G[u][i];
            indeg[v]++;
        }
    }

    for(int u=0; u<N; u++)
        if(indeg[u] == 0 && !V[u]) bfs(u);

    for(auto x : out){
        cout << x << endl;
    }
}

int main(){
    int s, t, M;

    cin >> N >> M;

    for(int i=0; i<N; i++) V[i] = false;

    for(int i=0; i<M; i++){
        cin >> s >> t;
        G[s].push_back(t);
    }

    tsort();

    return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#define Nmax 200005
#define OFF 100001
using namespace std;

int n,m,lst;
string a[Nmax], b[Nmax];

int main()
{
    cin >> n >> m;
    for (int i=1;i<=n;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    for (int i=1;i<=n;i++) a[i][0] = b[i].back() = '#';
    for (int i=1;i<=n;i++){
        for (int j=1;j<m-1;j++){
            if (i%2) a[i][j] = '#';
            else b[i][j] = '#';
        }
    }

    for (int i=1;i<=n;i++) cout << a[i] << '\n';
    cout << '\n';
    for (int i=1;i<=n;i++) cout << b[i] << '\n';
    return 0;
}


Measured memory_bytes: 4352
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		Console.WriteLine(3 * input[0] * input[0]);
	}
}

Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


void PrimeFact(ll n,map<ll,ll>& mp){
    while(n!=1){
        if(n == 2 || n == 3){
            mp[n]++; n/=n;
            continue;
        }
        bool prime_flag = false;
        for(ll i = 2;i*i <= n;i++){
            if(n%i==0){
                mp[i]++; n/=i;
                prime_flag = true;
                break;
            }
        }
        if(!prime_flag){mp[n]++; n/= n;}
    }
}

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    vector<ll> A(N); for(auto& in:A) cin >> in;
    
    { // check pairwise
        bool prime[1000000] = {false};
        bool ok = true;
        for(int i = N-1; i >= 0; i--){
            map<ll,ll> mp;
            PrimeFact(A[i], mp);
            
            for(auto p:mp){
                if(prime[p.first]){
                    ok = false;
                    break;
                }else{
                    prime[p.first] = true;
                }
            }
        }
        if(ok){
            return "pairwise coprime";
        }
    }
    {
        // check setwise
        ll GCD = 0;
        for(auto a:A) GCD = gcd(GCD,a);
        if(GCD == 1){
            return "setwise coprime";
        }
    }
    return "not coprime";
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


Measured memory_bytes: 11888
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define MOD 1000000007
using ll=long long;

int main(){
  int N,Q;
  cin>>N;
  vector<int> V(N),W(N);
  for(int i=0;i<N;i++){
    cin>>V[i]>>W[i];
  }
  cin>>Q;
  vector<int> v(Q),L(Q);
  for(int i=0;i<Q;i++){
    cin>>v[i]>>L[i];
    v[i]--;
  }

  vector<vector<int>> dp(min(N,(1<<11)-1),vector<int>(100001,0));
  for(int i=0;i<min(N,(1<<11)-1);i++){
    if(i==0){
      for(int j=100000;j-W.at(i)>=0;j--){
        dp[i][j]=max(dp[i][j],dp[i][j-W[i]]+V[i]);
      }
    }else{
      int x=(i-1)/2;
      for(int j=0;j<=100000;j++){
        dp[i][j]=dp[x][j];
        if(j-W[i]>=0){
          dp[i][j]=max(dp[i][j],dp[x][j-W[i]]+V[i]);
        }
      }
    }
  }

  for(int i=0;i<Q;i++){
    if(v[i]<((1<<11)-1)){
      cout<<dp[v[i]][L[i]]<<endl;
    }else{
      vector<int> pre;
      int x=v[i];
      while(x>=((1<<11)-1)){
        pre.push_back(x);
        x=(x-1)/2;
      }
      int ans=dp[x][L[i]];
      int n=pre.size();
      for(int j=0;j<(1<<n);j++){
        int value=0;
        int weight=0;
        for(int k=0;k<n;k++){
          if(((j>>k)&1)==1){
            value+=V[pre[k]];
            weight+=W[pre[k]];
          }
          if(weight<=L[i]){
            ans=max(ans,value+dp[x][L[i]-weight]);
          }
        }
      }
      cout<<ans<<endl;
    }
  }
}


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

int main(){
  int N, Y;
  cin >> N >> Y;
  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= N; j++){
      if(N - i - j < 0){
        continue;
      }
      int sum = 10000 * i + 5000 * j + 1000 * (N - i - j);
      if(sum == Y){
        cout << i << " " << j << " " << N - i - j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
# ABC085C - Otoshidama
n, total = list(map(int, input().split()))

for i in range(n + 1):
    for j in range(n + 1 - i):
        k = n - i - j
        if i * 10000 + j * 5000 + k * 1000 == total:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

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

using namespace std;

typedef long long int ll;

const int N = (int) 1e3 + 10;
const int mod = (int) 1e9 + 7;

int n, m;
int memo[N][N];
string grid[N];

int dp(int i, int j) {
    if(i == n || j == m) return 0;
    if(i == n - 1 && j == m - 1) return 1;
    int &ans = memo[i][j];
    if(ans != -1) return ans;
    ans = 0;
    int right = dp(i + 1, j);
    int down = dp(i, j + 1);
    if(i + 1 < n && grid[i + 1][j] != '#') {
        ans += right;
        ans %= mod;
    }
    if(j + 1 < m && grid[i][j + 1] != '#') {
        ans += down;
        ans %= mod;
    }
    return ans;
}

void solve() {
    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
        cin >> grid[i];
    }
    memset(memo, -1, sizeof(memo));
    cout << dp(0, 0) << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    solve();
    return 0;
}

Measured memory_bytes: 5504
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll  Q,L,R,U,D,H,W,N,M,X,Y,Z,A,B,C;
string S,T;
ll PP[10];

int main(){
  cin >> X >> Y >> Z;
  cout << Z <<" " <<  X << " "<< Y << endl;
}

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

#define ll long long int
#define ull unsigned long long int
#define lld long double
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vull vector<ull>
#define all(v) v.begin(),v.end()
#define mp make_pair
#define bitcount(x) __builtin_popcountll(x)
#define charcount(s,c) count(s.begin(), s.end(), c)
#define each(a,b) memset(a,b,sizeof a) //for b=0/-1, all pos,s for multidim arr too;
#define tofsi(s,c,t) memset(s,c,t) // for char s[n],first t;
#define tofs(s,pos,c,t) fill_n(s.begin()+pos, t, c);
#define fi first
#define se second


ll e_bit=0xAAAAAAAA;
ll o_bit=0x55555555;
lld pi = acos(-1.0);
ll gprime=402653189;
ll pprime=1610612741;
ll dulo=1000000007;

bool is_power2(ll n){
	return (n&&!(n&(n-1)));
}
ll power(ll x, ll y){
    ll temp;
    if( y == 0)
       return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return (temp*temp);
    else
    {
        if(y > 0)
            return (((x*temp))*temp);
        else
            return (temp*temp)/x;
    }
}

long long int mul_inv(long long int n,long long int p,long long int m){
	if(p==1){
		return n%m;
	}
	else if(p%2==0){
		long long int t= mul_inv(n,p/2,m);
		return ((t)*(t))%m;
	}
	else{
		long long int t= mul_inv(n,p/2,m);
		return ((((n%m)*t)%m)*t)%m;
	}
}

bool isprime(ll n){
	if(n==1){
		return false;
	}
	if(n==2){
		return true;
	}
	if(n%2==0){
		return false;
	}
	for(ll i=3;i<=sqrt(n);i+=2){
		if(n%i==0){
			return false;
		}
	}
	return true;
}


// getline(cin,s), cin.ignore() if cin>>p b4;


/*
struct compare {
    bool operator() (pair<int,int> a,pair<int,int> b) const{
        return a.se<b.se;
    }
};
*/


/*
---------------------Priority Queue Compare Operator------------------------

priority_queue<int, std::vector<int>, compare> pq;

*/


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	/*freopen("fbh.in","r",stdin);
    freopen("B-large.out","w",stdout);*/
	/*float ans;
	std::cout << std::fixed;
    std::cout << std::setprecision(9);
    std::cout << ans;
	*/
	vi v(3);
	for(int i=0;i<3;i++){
		cin>>v[i];
	}
	sort(all(v));
	if(v[1]==v[0])cout<<v[2];
	else cout<<v[0];
	return 0;
}

Measured memory_bytes: 256
#include<forward_list>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<iterator> 
#include<sstream>
#include<fstream>
#include<istream>
#include<utility>
#include<vector>
#include<stack>
#include<cmath>
#include<queue>
#include<deque>
#include<list>
#include<map> 
#include<set>
#define NinjaTurtle ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define infile freopen(".txt", "r", stdin);
#define outfile freopen(".txt", "w", stdout);
#define all(v) v.begin(),v.end()
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define ll long long 
#define endl "\n"
using namespace std;
int frq[10];
int main()
{
	NinjaTurtle
		map<string, int>m;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		string s;
		cin >> s;
		m[s]++;
	}
	cout << m.size() << endl;
}

Measured memory_bytes: 19232
#include <iostream>

using namespace std;

string input;
int length;
int cnt;
int main() {
  cin >> length;
  cin >> input;
  for(int i = 0; i < length; ++i) {
    if(input[i] != input[i-1] && i -1 >= 0) cnt++;
  }
  cout << cnt + 1;
}


Measured memory_bytes: 512
import itertools
import math
d,g=map(int,input().split())
x=[list(map(int,input().split())) for i in range(d)]
y=[]
z=[x[i][0]-1 for i in range(d)]
zz=[]
ans=10**10

pin=0
for i in range(d):
  pin+=100
  y.append(x[i][0]*pin+x[i][1])
  zz+=[pin]

for lst in itertools.product(range(2),repeat=d):
  sum=0
  cnt=0
  for i in range(d):
    if lst[i]==1:
      cnt+=x[i][0]
      sum+=y[i]
  if sum>=g:
      ans=min(ans,cnt)
  else:
    lack=g-sum
    for j in range(d-1,-1,-1):
      if lst[j]==0:  
        if z[j]*zz[j]>=lack:
            cnt+=math.ceil(lack/zz[j])
            ans=min(ans,cnt)         
            break
        else:
            cnt+=z[j]
            lack-=z[j]*zz[j]
    

print(ans)

Measured memory_bytes: 73712
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	ans := 0
	for i := 0; i < n; i++ {
		x := nextInt()
		ans += 2 * min(x, abs(k-x))
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int S = 100010;

struct UnionFind {
  vector<int> node;
  vector<ll> weight;
  UnionFind() : node(S, -1), weight(S, 0) {}
  void unite(int u, int v, ll w) {
    int ov = v, ou = u;
    u = find(u), v = find(v);
    int wa = weight[ov], wb = weight[ou];
    if(u == v) return;
    
    // (v ??????) ??? (u ??????) ???????????????
    node[u] += node[v];
    node[v] = u;
    weight[v] += w + wb - wa;
  }
  
  int find(int u) {
    if(node[u] < 0) return u;
    int par = node[u], root = find(node[u]);
    weight[u] += weight[par];
    return node[u] = root;
  }
};

int main() {
  int N, M;
  while(cin >> N >> M, N) {
    UnionFind uf;
    for(int i=0; i<M; i++) {
      char c; cin >> c;
      if(c == '!') {
	int a, b, d; cin >> a >> b >> d;
	a--; b--;
	uf.unite(a, b, d);
      }
      else {
	int a, b; cin >> a >> b;
	a--; b--;
	if(uf.find(a) != uf.find(b)) cout << "UNKNOWN" << endl;
	else {
	  ll wa = uf.weight[a];
	  ll wb = uf.weight[b];
	  cout << wb - wa << endl;
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 5712
#include<stdio.h>
int a[]={61, 230, 865, 3247, 12185, 45719, 171531, 643550, 2414454, 9058467, 33985227, 127504505, 478366600, 794717734, 733354121, 261943303, 776803305, 580025381, 51688048, 44657419, 737209731, 604119499, 159693437, 858533109, 639056669, 549054109, 996291083, 531294469, 23314687, 783022045, 855462856, 649970414, 68697295, 409213624, 604356692, 88638656, 978442997, 534833116, 763737161, 785892908, 123883652, 639213333, 181836645, 998121103, 124885216, 501575626, 39816123, 113468411, 799008836, 775465589, 256852905, 664630886, 971550783, 751629411, 51018086, 702530485, 725438992, 696683714, 792638194, 221791721, 149602322, 414054379, 986519078, 981760191, 305799096, 515140586, 406959393, 975058685, 245601370, 324759692, 673385295, 191483611, 570246669, 427196161, 781042769, 569725155, 842176273, 25328739, 847501730, 206282374, 353770801, 323137024, 371653459, 940737264, 123820509, 915711339, 847205021, 252858375, 718889563, 866398347, 738390145, 133009077, 333099663, 170591295, 329869205, 616680192, 597534442, 388130742};
int main(void){
  int n;
  scanf("%d",&n);
  printf("%d\n",a[n-3]);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
    long long a,b,p,q,i;
    cin>>a>>b;
    p=max(a,b);
    q=min(a,b);
    for(i=1;i<=p;i++)
    {
        cout<<q;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
    int n, x;
    cin >> n >> x;
    
    int count = 1;
    int d = 0;
    int l;
    for (int i = 0; i < n; i++) {
      cin >> l;
      d += l;
      if (d <= x) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (a, b, c) = readInputLine().split(" ").map { it.toInt() }
 
    var ans = 0
    
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
        val newA = b / 2 + c / 2
        val newB = a / 2 + c / 2
        val newC = a / 2 + b / 2
        
        a = newA
        b = newB
        c = newC
        
        ans++
        
        if (ans == 100000000) {
            println(-1)
            return
        }
    }
    
    println(ans)
}
 
fun readInputLine(): String {
    return readLine()!!
}

Measured memory_bytes: 37876
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define VECV(a,n,m) vector<vector<int>> a(n, vector<int>(m));
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N;
  int A[N];
  string ANS="APPROVED";
  rep(i,N){
    cin>>A[i];
  }
  rep(i,N){
    if(A[i]%2==0){
      if(A[i]%3!=0&&A[i]%5!=0){
        ANS="DENIED";
      }
    }
  }
  cout<<ANS<<endl;
        
  
}


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

int main(){
    long long n, d;
    cin >> n;
    d = sqrt((double)n) + 1;
    for(long long i=d; i>0; i--){
        if(n%i == 0){
            cout << i + n/i - 2;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#coding: UTF-8

i = raw_input().split()
l = raw_input().split()

#l = [1, 2, 65, 3, 5,8]

l. reverse()

l_int = map (int, l)

print " ".join(l)

#a = [1,2,3,4,5]
#a_str = map(str,a)
#print ",".join(a_str)

Measured memory_bytes: 6420
class Node:
    key = None
    parent = None
    left = None
    right = None

    def __init__(self, key):
        self.key = key


def insert(key):
    global T
    global root

    new_node = Node(key)
    T.append(new_node)

    if root is None:
        root = new_node

    else:
        y = None  # 親
        x = root  # 子

        while x is not None:
            y = x
            if key < x.key:
                x = x.left
            else:
                x = x.right

        new_node.parent = y
        if new_node.key < y.key:
            y.left = new_node
        else:
            y.right = new_node


def find(key):
    global T
    global root

    x = root

    while x is not None and key != x.key:
        # print(key, x.key)

        if key < x.key:
            x = x.left
        else:
            x = x.right
    return x  # マッチしなければNONEが戻る。


def in_order(node, order):
    if node is None:
        return

    in_order(node.left, order)
    order.append(node.key)
    in_order(node.right, order)


def pre_order(node, order):
    if node is None:
        return

    order.append(node.key)
    pre_order(node.left, order)
    pre_order(node.right, order)


m = int(input())
T = []
root = None

for i in range(m):
    order = input()

    if order.startswith('print'):
        output = []
        in_order(root, output)
        # print(output)
        print(' ' + ' '.join(map(str, output)))

        output = []
        pre_order(root, output)
        # print(output)
        print(' ' + ' '.join(map(str, output)))

    elif order.startswith('find'):
        order, value = order.split()
        value = int(value)
        _ = find(value)
        if _ is None:
            print('no')
        else:
            print('yes')

    else:
        order, value = order.split()
        value = int(value)
        insert(value)



Measured memory_bytes: 172484
from typing import List


def answer(h: int, w: int, a: List[str]) -> List[str]:
    top_bottom_line = '#' * (w + 2)

    result = [top_bottom_line]
    for line in a:
        result.append(f'#{line}#')
    result.append(top_bottom_line)

    return result


def main():
    h, w = map(int, input().split())
    a = [input() for _ in range(h)]
    for i in answer(h, w, a):
        print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10140
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int S = sc.nextInt();
			if (S == 0) break;
			for (int i = 0; i < 9; ++i) {
				S -= sc.nextInt();
			}
			System.out.println(S);
		}
	}

}

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

int main(){
  int D;
  cin>>D;
  int C[26];
  map<int,int>mp;
  for(int i=0;i<26;i++){
    cin>>C[i];
    if(C[i]>10){
      mp[i]++;
    }   
  }
  int S[365][26];
  for(int i=0;i<365;i++){
    for(int j=0;j<26;j++){
      cin>>S[i][j];
    }
  }
  
  int flag=1;
  int temp=0;
  int now=0;
  int maxans=0;
  while(temp<365){
    maxans=0;
    now=0;
    for(int i=0;i<26;i++){
      if(S[temp][i]>maxans){
        now=i;
        maxans=S[temp][i];
      }
    }
    if(maxans>2600){
      cout<<now+1<<endl;
      temp++;
      continue;
    }
    cout<<temp%26+1<<endl;
    temp++;
  }
  return 0;
}



Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;

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


Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
for k in range(n-1):
    if p[k+1]-p[k]!=1:
        break
    if k==n-2:
        print("YES")
        exit()
for i in range(n-1):
    for j in range(i+1,n):
        pn=p.copy()
        x=pn[i]
        pn[i]=pn[j]
        pn[j]=x
        for k in range(n-1):
            if pn[k+1]-pn[k]!=1:
                break
            if k==n-2:
                print("YES")
                exit()
print("NO")


Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let mut a: Vec<u64> = (0..n).map(|_| read()).collect();
    a.sort();
    let mut ret = 0;
    let l = a.len();
    if n < k {
        println!("{}", 0);
        return;
    }
    for i in 0..l {
        if i < n - k {
            ret += a[i];
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
typedef pair<ll , ll > pii;
ll mod=998244353;
ll p=1e9+7;

 
int  main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,x; cin>>n>>m>>x;
    int c[n];
    int s[n][m];
    for(int i=0; i<n;i++){
        cin>>c[i];
        for(int j=0; j<m; j++){
            cin>>s[i][j];
        }
    }
    int cost=1e9;
    
    bool found=false;
    
    for(int bit=0; bit< (1<<n); bit++){
        int price=0;
        int sum[m];
        bool flag=true;
        memset(sum,0,sizeof(sum));
        for(int i=0; i<n; i++){
            if( (bit& (1<<i) ) != 0 ){
                price+=c[i];
                for(int j=0; j<m; j++){
                    sum[j]+=s[i][j];
                }
            }
        }
        for(int j=0; j<m;j++){
            if(sum[j]<x) flag=false;
        }
        if(flag){
            found=true;
            cost=min(price,cost);
        }
    }
    if(found){
        cout<<cost;
    }
    else cout<<-1;
    return 0;
}

Measured memory_bytes: 3656
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int n;
int w[100];
int v[100];
int W;
int dp[101][10001];
int main() {
	cin >> n >> W;
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= W; j++) {
			if (j >= w[i]) {
				dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
			}
			else {
				dp[i + 1][j] = dp[i][j];
			}
		}
	}
	cout << dp[n][W] << endl;
}

Measured memory_bytes: 7032
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 102,M = 100002;
ll i,j,n,W;
struct S{
    ll c[2];
} w[N];
ll dp[N][M];
ll solve(ll i,ll j)
{
    if(dp[i][j] != -1) return dp[i][j];
    
    if(i == 0 || j == 0)
        return dp[i][j] = 0;
    
    ll res = solve(i - 1,j);
    if(j >= w[i].c[0])
        res = max(res,solve(i - 1,j - w[i].c[0]) + w[i].c[1]);
    
    return dp[i][j] = res;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin>>n>>W;
    rep(i,1,n + 1) rep(j,0,2) cin>>w[i].c[j];
    cout<<solve(n,W);
    return 0;
}

Measured memory_bytes: 80000
S = input()
Q = int(input())
rev = False
ends = [[], []]
for _ in range(Q):
    parts = input().split()
    if parts[0] == "1":
        rev = not rev
    else:
        _, end, s = parts
        ends[(int(end) - 1) ^ rev].append(s)
res = list(reversed(ends[0])) + list(S) + ends[1]
if rev:
    res = reversed(res)
print("".join(res))


Measured memory_bytes: 84056
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint X, Y; cin >> X >> Y;
    map<lint, lint> score = {{1, 300000}, {2, 200000}, {3, 100000}};
    lint res = score[X] + score[Y];
    if (X == 1 and Y == 1) res += 400000;
    cout << res << "\n";
}

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

using namespace std;

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define all(v) (v).begin(), (v).end()

int main() {
    int q; cin >> q;
    multiset<int> s;
    while (q--) {
        int a, x; cin >> a >> x;
        if (a == 0) {
            s.insert(x); cout << s.size() << endl;
            
        } else if (a == 1) {
            cout << s.count(x) << endl;
        } else if (a == 2) {
            s.erase(x);
        } else {
            int y; cin >> y;
            auto b = s.lower_bound(x);
            auto e = s.upper_bound(y);
            for (auto i = b; i != e; i++) {
                cout << *i << endl;
            }
        }
    }
}


Measured memory_bytes: 12348