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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

int N, M;
int now = 0;

int main(){
	cin>>N>>M;
	now = 1;
	for(int i=0; i<=100; i++){
		if(now>=M){
			printf("%d", i);
			return 0;
		}
		now = now + (N-1);
	}
	return 0;
}


Measured memory_bytes: 256
n,m = [int(i) for i in input().split()]
ck = []
for i in range(n):
    ck.append(list(map(int,input().split())))

co1=co2=co3=-1

scores = []
maxi = 0
for i in range(2):
    co1 *= -1
    for j in range(2):
        co2 *= -1
        for k in range(2):
            co3*= -1
            scores = []
            score = 0
            for a,b,c in ck:
                scores.append(a*co1 + b*co2 + c*co3)
            scores.sort()
            for x in range(1,m+1):
                score += scores[-x]
            maxi = max(maxi,score)

print(maxi)

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



int main(){
   
  long long N,K;
  long long ans,now1,now2;
  cin>>N>>K;

  now1=abs(N-(N/K+1)*K);
  now2=abs(N-(N/K)*K);


   cout<<min(now1,now2)<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

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

    string S, T, U;
    int A, B;
    cin >> S >> T >> A >> B >> U;
    if(S==U)
        A--;
    else
        B--;
    cout << A << " " << B << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7') Yes();
    else No();
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;


int main(void) {
	int h,w;
	cin >> h >> w;
	int majic[10][10];
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			cin >> majic[i][j];
		}
	}
	for(int k=0; k<10; k++){
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				majic[i][j]=min(majic[i][j],majic[i][k]+majic[k][j]);
			}
		}
	}
	long long ans=0,temp; 
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin >> temp;
			if(temp!=-1)ans+=majic[temp][1];
		}
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;

struct ans
{
    int i;
    vector<vector<ll>> dp;
    vector<ll> w;
    ans(ll n): dp(n+1, vector<ll>(n+1,-1)), w(n){}
    ll rec(ll l, ll r){
        int i;
        if(dp.at(l).at(r) != -1){
            return dp.at(l).at(r);
        }
        if(abs(l-r) <= 1){
            return 0;
        }
        ll tmp = 0;
        if(abs(w.at(l) - w.at(r-1)) <= 1 && rec(l+1,r-1) == r-l-2){
            tmp = r - l;
        }else{
            for(i = l+1; i <= r-1;++i){
                tmp = max(tmp, rec(l,i) + rec(i,r));
            }
        }
        return dp.at(l).at(r) = tmp;
    }
};



int main()
{
    ll i,j;
    while(true){
        ll n;
        cin >> n;
        if(n == 0){
            return 0;
        }else{
            ans ans(n);
            for(i = 0;i < n;++i){
                cin >> ans.w.at(i);
            }
            cout << max((ll)0,ans.rec(0, n)) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3680
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long A, long long B){
  cout << (B-1+A-2)/(A-1) << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int num[2020];
int cor[2020];
int rank[2020];

void bubble_sort(int n){

  for( int i = 0 ; i < n - 1 ; i++ ){
    for( int j = n - 1 ; j > i ; j-- ){
      
      if( cor[j-1] < cor[j] ){
	int temp = cor[j-1];
	cor[j-1] = cor[j];
	cor[j] = temp;

	temp = num[j-1];
	num[j-1] = num[j];
	num[j] = temp;
      }
    }
  }


}

int main(void){

  char ten;
  int cnt = 0;
  for( int i = 0 ; i < 2020 ; i++ ){
    cin >> num[i] >> ten >> cor[i];
    if( num[i] == cor[i] && cor[i] == 0 )break;
    cnt++;
  }
  bubble_sort(cnt);


  int n;
  int I = 1;

  for( int i = 0 ; i < cnt ; i++ ){
    if( cor[i] == cor[i+1] ){
      rank[i] = rank[i+1] = I;
      continue;
    }
    else{
      rank[i] = I;
      I++;
    }
  }
  //   for( int i = 0 ; i < cnt ; i++ )cout << num[i] << "-" << cor[i] << "--" << rank[i] << endl;
  while( cin >> n ){
    for( int i = 0 ; i < 2020 ; i++ ){
      if( n == num[i] ){
	cout << rank[i] << endl;
	break;
      }
    }
  }
  return 0;
}

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

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int X, Y;
  cin >> X >> Y;
  cout << X + Y/2 << endl;

  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n, k;cin>>n>>k;
  vector<int> a(n);
  rep(i, n)cin>>a[i];

  vector<bool> dp(k+1);

  rep(i, k+1)dp[i]=false;

  rep1(i, k)for(auto c:a){
    if(c>i || dp[i])continue;
    dp[i] = !dp[i-c];
  }

  if(dp[k])cout<<"First"<<endl;
  else cout<<"Second"<<endl;

  return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

int main(void){
  long long int N,A,B;
  long long int i;
  long long int h[100000];
  long long int K;
  long long int left,right;
  long long int sum;

  scanf("%lld %lld %lld",&N,&A,&B);
  //printf("%d\n", N);

  for(i=0;i<N;++i){
    scanf("%lld",&h[i]);
  }

  left=0;
  right=1000000000;

  while(left!=right){
    K=(right+left)/2;
    sum=0;
    for(i=0;i<N;i++){
      if(h[i]-K*B > 0){
        // sum += (h[i]-K*B)%(A-B) ? (h[i]-B*K)/(A-B)+1 : (h[i]-B*K)/(A-B);
        if((h[i]-K*B)%(A-B)==0){
          sum += (h[i]-B*K)/(A-B);
        }else{
          sum += (h[i]-B*K)/(A-B)+1;
        }
      }
    }
    if(sum <= K){
      right=K;
    }else{
      left=K+1;
    }
  }

  printf("%lld\n", left);

  return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
int main()
{
  int N,p,a = 0;
  
  scanf("%d",&N);
 
  for(int i=1;i<=N;i++){
    scanf("%d" ,&p);
    if( p != i )
      a++;
  }
 
  if( a == 0 || a == 2)
    printf("YES\n");
  else
    printf("NO\n");
  
  return 0;
}

Measured memory_bytes: 1636
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i;
	ll ans = 0;
	cin >> num;
	vector<ll> d(num), a(num, 0);
	rep(i, num) {
		cin >> d[i];
		a[i] = d[i];
	}
	rep(i, num - 1) {
		a[i + 1] += a[i];
	}
	rep(i, num) {
		ans += d[i] * ((a[num - 1] - a[i]) % MOD) % MOD;
	}
	ans %= MOD;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 6376
def solve(s, p=2019):
    s = s[::-1]
    memo = [0] * p
    memo[0] = 1
    ans = 0
    q = 0
    r = 1
    for c in s:
        q = (q + int(c)*r) % p
        ans += memo[q]
        r = 10*r % p
        memo[q] += 1
    return ans

s = input()
print(solve(s))

Measured memory_bytes: 9264
import java.util.*;
import java.io.*;

public class Main {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};

    void solve() throws IOException {
        char[] arr = nextString().toCharArray();

        String input = new String(arr);
        for (int i = arr.length - 1; i >= -1; i--) {
            String pref = input.substring(0, i + 1);
            boolean[] has = new boolean[26];
            for (int j = 0; j < pref.length(); j++) {
                has[pref.charAt(j) - 'a'] = true;
            }

            char low = i == arr.length - 1 ? 'Z' : input.charAt(i + 1);
            for (int j = 0; j < 26; j++) {
                if (!has[j]) {
                    if (low < (char) (j + 'a')) {
                        String res = pref + (char) (j + 'a');
                        outln(res);
                        return;
                    }
                }
            }
        }

        outln(-1);
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public Main() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new Main();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


Measured memory_bytes: 23252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		for (int i = 0; i < N; i++) {
			long A = sc.nextLong();
			long B = sc.nextLong();
			long C = sc.nextLong();
			long D = sc.nextLong();
			boolean yes = true;
			if (D < B || A < B) yes = false;
			if (yes && C < B - 1) {
				long gcd = gcd(B, D);
				yes = C >= (A % gcd) + B - gcd;
			}
			out.println(yes ? "Yes" : "No");
		}
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 21076
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main(){
	int a, b;
	cin >> a >> b;
	cout << a-b+1 << endl;
	return;
}

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


Measured memory_bytes: 256
data = input().split()
A = int(data[0])
B = int(data[1])
ans = 0
if A < B:
    ans += B
    B -= 1
else:
    ans += A
    A -= 1

if A < B:
    ans += B
    B -= 1
else:
    ans += A
    A -= 1
 
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

#define MAX 101
#define GRAY -3
#define WHITE -2
#define BLACK -1
 
int temp[MAX],d[MAX],f[MAX];
int time,N;
int A[MAX][MAX];
 
void DFS();
 
void DFSvisit(int u){
  int v;
 
  temp[u] = GRAY;
  time++;
  d[u]=time;
 
  for(v=1;v<=N;v++){
    if(A[u][v]==0){
      continue;
    }
    if(temp[v]==WHITE){
      DFSvisit(v);
    }
  }  
   
  temp[u] = BLACK;
  f[u] = ++time;
}
 
void DFS(){
  int i;
  for(i=1;i<=N;i++){
    temp[i] = WHITE;
  }
 
  time=0;
 
  for(i=1;i<=N;i++){
    if(temp[i]==WHITE){
      DFSvisit(i);
    }
  }
}
 
int main (){
 
  int i,j,k,n,u;
 
  for(i=1;i<101;i++){
    for(j=1;j<101;j++){
      A[i][j] = 0;
    }
  }
 
  scanf("%d",&N);
 
  for(i=1;i<=N;i++){ 
    scanf("%d %d",&n,&k); 
    for(j=1;j<=k;j++){
      scanf("%d",&u);
      A[n][u] = 1;
    }
  }
 
  DFS();
   for(i=1;i<=N;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
 
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
 
const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
 
int main()
{
  cout << fixed << setprecision(10);
  string A,B;
  cin >> A >> B;
  int a = A.size();
  int b = B.size();
  if(a>b)
  {
    cout << "GREATER" << endl;
    return 0;
  }
  else if(b>a)
  {
    cout << "LESS" << endl;
    return 0;
  }
  else
  {
    rep(i,a)
    {
      if(A[i]>B[i])
      {
        cout << "GREATER" << endl;
        return 0;
      }
      else if(A[i]<B[i])
      {
        cout << "LESS" << endl;
        return 0;
      }
    }
  }
  
  cout << "EQUAL" << endl;
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N;
    cin >> N;
    vector<ll> d(N);
    rep(i, 0, N) cin >> d[i];
    sort(d.begin(), d.end());
    cout << d[N/2] - d[N/2-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
cnt_1=0
cnt_2=0
cnt_3=0
for i in range(n):
	if p[i]<=a:
		cnt_1+=1
	elif p[i]<=b:
		cnt_2+=1
	else:
		cnt_3+=1
print(min(cnt_1,cnt_2,cnt_3))

Measured memory_bytes: 3064
import sys

input = sys.stdin.readline

n = int(input())
cs, ss, fs = [], [], []
for _ in range(n - 1):
    c, s, f = map(int, input().split())
    cs.append(c)
    ss.append(s)
    fs.append(f)

res = []
for i in range(n):
    t = 0
    for j in range(i, n - 1):
        s = ss[j]
        f = fs[j]
        if t < s:
            t = s
        elif t % f > 0:
            t += f - t % f
        t += cs[j]
    res.append(t)
for x in res:
    print(x)

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

int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;

  int i,j,k;
  int total=0,ans=0;

  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      for(k=0;k<=c;k++){
	total=500*i+100*j+50*k;
	if(total==x) ans++;
      }
    }
  }
  cout << ans << endl;
}
	


Measured memory_bytes: 256
N = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]

fact = []
f = 1
for i in range(1,N+1):
    fact.append(f)
    f *= i
fact.reverse()

def dicNum(L):
    ans = 0
    block = N
    l = [i+1 for i in range(N)]
    for i in range(N-1):
        inde = 0
        for j in l:
            if L[i]==j:
                l.pop(inde)
                break
            else:
                inde += 1
        
        ans += fact[i]*inde
    return ans
    
print(abs(dicNum(P)-dicNum(Q)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define fin(ans) cout << ans << endl

int main(void) {
  int a, b;
  cin >> a >> b;
  if (a >= 10 || b >= 10) {
    fin(-1);
  } else {
    fin(a * b);
  }
  return 0;
}


Measured memory_bytes: 256
N, K = input().split()

N = int(N)
K = int(K)

xList = [int(x) for x in input().split()]

cache = 99999999999
for a, b in zip(xList, xList[K-1:]):
    if min(a,b) < 0 and 0 <= max(a,b):
        if (max(a,b) - min(a,b) + min(abs(a),abs(b))) < cache:
            cache = (max(a,b) - min(a,b) + min(abs(a),abs(b)))
    elif a < 0 and b < 0:
        if abs(a) < cache:
            cache = abs(a)
    else:
        if abs(b) < cache:
            cache = abs(b)

print(cache)


Measured memory_bytes: 14564
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	string s;cin>>s;
	string t;
	for(auto c:s){
		if(c=='B'){
			if(t.length()){
				t.pop_back();
			}
		}
		else {
			t.push_back(c);
		}
	}
	cout<<t;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[100005];

int main(void){
	scanf("%d",&n);
	bool flag=false;
	bool zero=false;
	ll res=1;
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if(res>0 && (INF/res)<a[i]){
			flag=true;
		}
		if(a[i]==0LL){
			zero=true;
		}
		res=res*a[i];
	}
	if(flag && !zero){
		printf("-1\n");
	}else{
		printf("%lld\n",res);
	}
	return 0;
}


Measured memory_bytes: 4516
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

typedef struct
{
  int val;
  int ind;
} hoge;

int ssort(const void *a, const void *b)
{
  int p = (*(hoge *)a).val, q = (*(hoge *)b).val;
  return p <= q ? 1 : -1;
}

int main()
{
  int n;
  hoge a[200005];
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    a[i].ind = i;
    scanf("%d", &a[i].val);
  }
  qsort(a, n, sizeof(hoge), ssort);
  for (int i = 0; i < n; i++)
  {
    if (a[0].ind != i)
      printf("%d\n", a[0].val);
    else
      printf("%d\n", a[1].val);
  }
  return 0;
}

Measured memory_bytes: 3324
import sys
def input():
	return sys.stdin.readline()[:-1]

s = input()
#n = len(s)
q = int(input())
front = ""
back = ""
sgn = 0
for _ in range(q):
	query = input().split()
	if query[0] == "1":
		sgn ^= 1
	else:
		f, c = int(query[1])-1, query[2]
		if f ^ sgn == 0:
			front += c
		else:
			back += c
if not sgn:
	print(front[::-1] + s + back)
else:
	print(back[::-1] + s[::-1] + front)

Measured memory_bytes: 4340
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>

using namespace std;

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

	int color[8];
	int free = 0;

	for (int i = 0; i < n; i++) {
		int ai;
		cin >> ai;
		if (ai < 3200) {
			color[ai / 400]=1;
		}
		else free++;
	}
	int ans=0;
	for (int i = 0; i < 8; i++) {
		if (color[i] ==1)ans++;
	}
	int max, min;
	if (ans > 0)min = ans;
	else min = 1;
	
	max = ans + free;

	cout << min<<" "<< max << endl;

	return 0;

}


Measured memory_bytes: 256
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
const bool debug = 0;
//----------------------//
 
int main() {
	ll q, h, s, d;
	ll n;
	cin >> q >> h >> s >> d;
	cin >> n;
	
	chmin(h, q * 2);
	chmin(s, h * 2);
	chmin(d, 2 * s);
	
	ll cnt = n / 2;
	n -= cnt * 2;
	
	ll ans = cnt * d;
	
	ans += s * n;
	
	cout << ans << endl;
	
	return 0;
}

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

int n, amo;
vector<pair<int, int>> adj[111111];
int ans[111111];
bool visited[111111];

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

	cin >> n;
	int u, v;
	for (int i = 1; i < n; i++)
	{
		cin >> u >> v;
		adj[u].push_back({ v, i });
		adj[v].push_back({ u, i });
	}


	queue<pair<int, int>> q;
	q.push({ 1, 0 });
	visited[1] = true;

	while (!q.empty())
	{
		int cur = q.front().first, prohibit = q.front().second;
		int c = 1;
		q.pop();

		for (int i = 0; i < adj[cur].size(); i++)
		{
			int next = adj[cur][i].first;
			int num = adj[cur][i].second;

			if (visited[next])
				continue;

			if (c == prohibit)
				c++;

			amo = max(amo, c);
			ans[num] = c;
			q.push({ next, c });
			visited[next] = true;
			c++;
		}
	}

	cout << amo << '\n';
	for (int i = 1; i < n; i++)
		cout << ans[i] << '\n';
}

Measured memory_bytes: 7424
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	int N, H;
	scanf("%d %d", &N, &H);
	int max_a = 0, b[N];
	for (int i = 0; i < N; ++i){
		int tmp;
		scanf("%d %d", &tmp, b + i);
		if(max_a < tmp) max_a = tmp;
	}
	sort(b, b + N);
	int begin = distance(b, lower_bound(b, b + N, max_a));
	int answer = 0;
	while(H > 0 && N > begin){
		H -= b[--N];
		answer++;
	}
	if(H > 0) answer += (H - 1)/max_a + 1;
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 512
n, m = gets.split.map(&:to_i)

ans = 0

n.times.map { gets.split.map(&:to_i) }
  .sort_by! { |a, b| a }
  .each do |a, b|
  if b >= m
    ans += a * m
    break
  end

  ans += a * b
  m -= b
end

puts ans


Measured memory_bytes: 12664
#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;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    rep(i, b) cout << a;
    cout << endl;
    return 0;
}

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

#define MAXC 1000000007

int n,k;
int h[100005];
int dp[100005];

int solve(int x){
    if (x >= n-1) return 0;
    else if (dp[x] != -1) return dp[x];
    else {
        int aux = MAXC;
        for (int i = 1; i <= k; i++){
            if (x+i < n){
                aux = min(aux,abs(h[x]-h[x+i])+solve(x+i));
            }
        }
        return dp[x] = aux;
    }
}

int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    memset(&dp,-1,sizeof(dp));
    for (int i = 0; i < n; i++){
        cin >> h[i];
    }
    cout << solve(0) << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int stone[n];
    int cam[n];
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        stone[i]=a;
    }
    cam[0]=0;
    for(int i=1; i<n; i++){
        int g=1;
        int c2=1000000000;
        while(g<=k && i-g>=0){
        int c1=abs(stone[i]-stone[i-g])+cam[i-g];
        if(c1<c2){
            cam[i]=c1;
            c2=c1;
        }
        g++;
        }
    }
    cout<<cam[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)

const int N = 2e6 + 5;
const int M = 1e9 + 7;


int mod(int m){
   m%=M;
   return (m+M)%M;
}

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

int f[N],invf[N];
void fact(){
   f[0]=f[1]=1;
   for(int i=2;i<N;i++)
      f[i]=mod(f[i-1]*i);

   invf[N-1]=power(f[N-1],M-2);
   for(int i=N-1;i>0;i--)
      invf[i-1]=mod(invf[i]*i);

}

int nCr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   ans = mod(ans*invf[r]);
   return ans;
}

int nPr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   return ans;
}

int32_t main(){
	fact();
	boost;
	int k;
	cin>>k;
	string s;
	cin>>s;
	int m = s.size();
	int n = m + k;
	int ans = power(26,n);
	for(int i=0;i<m;i++)
		ans = mod(ans - mod(nCr(n,i)*power(25,n-i)));
	cout<<ans<<endl; 
}

Measured memory_bytes: 35472
#include<stdio.h>
int main(){
  char s[5];
  int i;
  scanf("%s",s);
  for(i=0;i<3;i++)
    if(s[i]==s[i+1]){
      printf("Bad\n");
      return 0;
    }
  printf("Good\n");
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for(int i=0; i<n; i++) {
            for(int j=0; j<d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int ans = 0;
        for(int i=0; i<n; i++) {
            for(int j=i+1; j<n; j++) {
                double total = 0;
                for(int k=0; k<d; k++) {
                    int sub = (x[i][k]) - (x[j][k]);
                    total += Math.pow(sub, 2);
                }
                total = Math.sqrt(total);
                if(total == Math.floor(total)) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35988
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

def is_square(integer):
    root = math.sqrt(integer)
    return integer == int(root + 0.5) ** 2

ans = 0
[n,d] = inpl()
Xmatrix = [inpl() for _ in range(n)]
npXmatrix = np.array(Xmatrix)
for i in range(n):
    for j in range(i+1,n):
        if is_square(((npXmatrix[i]-npXmatrix[j])**2).sum()):
            ans += 1
print(ans)

Measured memory_bytes: 13404
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5100+10;
const ll inf = 1e9+7;
int main(){
    ios::sync_with_stdio(0);
    ll n,t=100,ans;
    cin>>n;
    for(int i=1;i<=5000;i++){
        if(t>=n){
            ans = i;
            break;
        }
        t+=t/100;
    }
    cout<<ans-1<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  char c;
  cin >> c;
  if ('A' <= c && c <= 'Z') cout << 'A' << endl;
  else cout << 'a' << endl;
  return 0;
}

Measured memory_bytes: 3628
//
// Created by yamunaku on 2019/12/09.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 2000000007
#define IINF 2000000000
#define LINF 2000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int h, w;
    cin >> h >> w;
    mti a(h, vi(w)), b(h, vi(w));
    rep(i, h){
        rep(j, w){
            cin >> a[i][j];
        }
    }
    rep(i, h){
        rep(j, w){
            cin >> b[i][j];
            a[i][j] -= b[i][j];
        }
    }
    vector<vector<bitset<40000>>> dp(h, vector<bitset<40000>>(w, bitset<40000>(0)));
    dp[0][0][20000 - a[0][0]] = dp[0][0][20000 + a[0][0]] = true;
    rep(i, h){
        rep(j, w){
            if(i > 0){
                dp[i][j] |= dp[i - 1][j] << abs(a[i][j]);
                dp[i][j] |= dp[i - 1][j] >> abs(a[i][j]);
            }
            if(j > 0){
                dp[i][j] |= dp[i][j - 1] << abs(a[i][j]);
                dp[i][j] |= dp[i][j - 1] >> abs(a[i][j]);
            }
        }
    }
    int ans = IINF;
    rep(i, 40000){
        if(dp[h - 1][w - 1][i]) ans = min(ans, abs(20000 - i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 32000
#include <cstdio>
#include <algorithm>
#include <numeric>
using namespace std;

int main() {
  for(int tci = 0; ; tci++) {
    int N; scanf("%d", &N); if(N==0) break;
    int l13[13],l17[17],l19[19],l23[23],l[55440];
    fill(l13,l13+13,0); fill(l17,l17+17,0);
    fill(l19,l19+19,0); fill(l23,l23+23,0);
    fill(l,l+55440,0);
    int *ls[25], lens[25];
    fill(ls+1,ls+25,(int*)l); ls[13]=l13,ls[17]=l17,ls[19]=l19,ls[23]=l23;
    fill(lens+1,lens+25,55440); lens[13]=13,lens[17]=17,lens[19]=19,lens[23]=23;
    for(int i = 0; i < N; i++) {
      int d,t; scanf("%d%d", &d, &t);
      int q[24];
      for(int j = 0; j < d; j++) scanf("%d", q+j);
      for(int j = 0; j < lens[d]; j++) {
        ls[d][j] += q[(j+t)%d];
      }
    }
    printf("%d\n",
           accumulate(l13,l13+13,0,max<int>)+
           accumulate(l17,l17+17,0,max<int>)+
           accumulate(l19,l19+19,0,max<int>)+
           accumulate(l23,l23+23,0,max<int>)+
           accumulate(l,l+55440,0,max<int>));
  }
  return 0;
}

Measured memory_bytes: 1244
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
using namespace std;

int main(){
	int N, C[100][2], dp[100][100];
	cin >> N;
	for(int i = 0; i < N; i++) cin >> C[i][0] >> C[i][1];
	for(int i = 2; i <= N; i++){
		for(int j = 0; j + i - 1 < N; j++){
			int *dp_p = &dp[j][j + i - 1];
			*dp_p = INT_MAX;
			for(int k = j; k < j + i - 1; k++){
				*dp_p = min( *dp_p, 
					dp[j][k] + dp[k+1][j+i-1]
					+ C[j][0]*C[k][1]*C[k+1][0]*C[j+i-1][1] );
			}
		}
	}
	printf("%d\n", dp[0][N-1] );
	return 0;
}

Measured memory_bytes: 1180
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    p, q, r = get_li()
    print(min(p + q, q + r, r + p))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 65516
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




ll N,S;

int main(){

	scanf("%lld %lld",&N,&S);

	if(S == N){

		printf("%lld\n",N+1);
		return 0;
	}

	for(ll b = 2; b*b <= N; b++){

		ll sum = 0,num = 1;

		while(num <= N){

			sum += (N/num)%b;
			num *= b;
		}
		if(sum == S){

			printf("%lld\n",b);
			return 0;
		}
	}

	ll ans = -1;

	for(ll p = 1; p*p <= N; p++){

		ll b = ((N-S)/p)+1;
		if(b < sqrt(N))continue;

		ll sum = 0,num = 1;

		while(num <= N){

			sum += (N/num)%b;
			num *= b;
		}
		if(sum == S){

			ans = b;
		}
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

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

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

	ll N, K;
	cin >> N >> K;
	vector<bool> have_sweet(N, false);

	ll d, a;
	for (ll i = 0; i < K; ++i) {
		cin >> d;
		for (ll j = 0; j < d; ++j) {
			cin >> a;
			--a;
			have_sweet[a] = true;
		}
	}

	ll res = 0;
	for (ll i = 0; i < N; ++i) {
		if (!have_sweet[i]) {
			++res;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3644
d,n=map(int,input().split())
if d==0:
  if n==100:
    print(101)
  else:
    print(n)
elif d==1:
  if n==100:
    print(10100)
  else:
    print(n*100)
else:
  if n==100:
    print(101*10000)
  else:
    print(n*10000)

Measured memory_bytes: 3060
import math
N, K = map(int,input().split())
for i in range(1,K+1):
    if N-K+1-i >= 0:
        ans = (math.factorial(K-1) // (math.factorial(K-1-i+1)*math.factorial(i-1))) * (math.factorial(N-K+1) // (math.factorial(N-K+1-i)*math.factorial(i)))
        tans = int(ans % (10**9+7))
        print(tans)
    else:
        print(0)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<int> A(N);
    REP(i,N)A[i] = in();
    sort(ALL(A));
    UNIQUE(A);
    cout << (A.size()%2 == 0?A.size()-1:A.size()) << "\n";
}

Measured memory_bytes: 640
H, W, K = gets.split.map(&:to_i)

q = Array.new(H) do
  gets.chomp.split('').map{ |v| v == '#' } # . #
end

ans = 0
[false, true].repeated_permutation(H) do |h|
  [false, true].repeated_permutation(W) do |w|
    count = 0
    H.times do |i|
      W.times do |j|
        count += 1 if q[i][j] && !h[i] && !w[j]
      end
    end
    ans += 1 if count == K
  end
end

puts ans


Measured memory_bytes: 14368
#include "bits/stdc++.h"

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define en '\n'
#define pb push_back
#define P pair<int, int>

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;

void chmin(ll &a, ll b) {
	if (a > b) a = b;
}

template <class T>
int former(const vector<T> &v, T x) {
	return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}

template <class T>
int latter(const vector<T> &v, T x) {
	return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int main() {
	int A, B, Q;
	cin >> A >> B >> Q;
	vector<ll> s(A), t(B);
	for (int i = 0; i < A; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < B; i++) {
		cin >> t[i];
	}

	s.push_back(inf); s.push_back(-inf); sort(s.begin(), s.end());
	t.push_back(inf); t.push_back(-inf); sort(t.begin(), t.end());

	for (int i = 0; i < Q; i++) {
		ll x;
		cin >> x;
		
		ll res = inf;

		for (int i = 0; i < 2; i++) {
			ll first = (i ? s[former(s, x)] : s[latter(s, x)]);

			for (int j = 0; j < 2; j++) {
				ll second = (j ? t[former(t, first)] : t[latter(t, first)]);
				chmin(res, abs(x - first) + abs(first - second));
			}
		}

		for (int i = 0; i < 2; i++) {
			ll first = (i ? t[former(t, x)] : t[latter(t, x)]);

			for (int j = 0; j < 2; j++) {
				ll second = (j ? s[former(s, first)] : s[latter(s, first)]);
				chmin(res, abs(x - first) + abs(first - second));
			}
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 2912
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1e18) + 1;

int main(void)
{
    int a1, a2, a3;

    cin >> a1 >> a2 >> a3;

    if (a1 + a2 + a3 >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > p(n);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(all(p));

  int cnt = 0;
  ll sum = 0;
  rep(i, n){
    while(p[i].second != 0){
      sum += (ll)p[i].first;
      p[i].second--;
      cnt++;
      if(cnt == m){
        cout << sum << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 1024
import java.io.File;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		sc.nextInt();
		
		int r0 = sc.nextInt();
		int r1 = sc.nextInt();
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		while (sc.hasNextInt()) {
			int r = sc.nextInt();
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	}
}

Measured memory_bytes: 94712
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = [0]*X*Y
i = 0
for a in A:
    for b in B:
        AB[i] = a + b
        i += 1
AB.sort(reverse=True)

ans = [0]*min(K, len(AB))*Z
i, j = 0, 0
for i in range(min(K, len(AB))):
    for c in C:
        ans[j] = AB[i] + c
        j += 1
ans.sort(reverse=True)

for i in range(K):
    print(ans[i])

Measured memory_bytes: 135288
#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 repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    string s; cin >> s;
    for(int i = 0; i < s.size(); i += 2) cout << s[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    long long int now = -1000000010;
    int ans = 0;
    vector<pair<long long int,long long int>> v;

    cin >> n;

    for (int i = 0; i < n; i++) {
        int x, l;
        cin >> x >> l;
        v.push_back(make_pair(x+l,x-l));
    }

    sort(v.begin(), v.end());

    for (int i = 0; i < v.size(); i++) {
        if (now <= v[i].second) {
            ans++;
            now = v[i].first;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <string>
#define endl '\n'
#define ll unsigned long long
using namespace std;

string N;

string Solution(string N) {

	for (auto x : N) if (x == '7') return "Yes";
	return "No";
}

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

	cin >> N;
	string s = Solution(N);
	cout << s << endl;
	
	system("pause");
	return 0;
}

Measured memory_bytes: 3672
def main():
    N, W = map(int, input().split())
    wv = [
        list(map(int, input().split()))
        for _ in range(N)
    ]

    ans1 = f(N, W, wv)
    ans2 = simple(N, W, wv)

    # assert ans == ans2

    print(ans2)


def simple(N, W, wv):
    dp = [[0] * (W + 1) for _ in range(N + 1)]
    for i, (w, v) in enumerate(wv, 1):
        for _w in range(1, W + 1):
            bef = dp[i-1][_w]
            dp[i][_w] = bef

            # 入れ替え
            if _w - w >= 0:
                changed = dp[i-1][_w - w] + v
                dp[i][_w] = max(bef, changed)

    ans = dp[N][W]
    return ans


def f(N, W, wv):
    """
    品物100を入れる入れないの 2^100 試せばOKだが、無理

    Nの入れる個数
        0から100
        正確にはN個までの選択なので、N個入れていないときもある
    最終容量     
        0から10^5
        正確にはWまでの重さなので、W以下のときもある
    10^7なら間に合いそう

    追加できるならば、追加してみる
    追加するものと入れ替えを試してみる
        追加の重さを引いたときの価値
        前の価値まま
            の大きい方
    """
    dp = [[-float("inf")] * (W + 1)
          for _ in range(N + 1)]

    # 品物を入れていないならば、価値はない
    # 品物を入れていないならば、重さはないので、価値はない
    # wi, vi >= 1 より
    dp[0] = [0] * (W + 1)
    for i in range(1, N + 1):
        dp[i][0] = 0

    for i, (w, v) in enumerate(wv, 1):
        for _w in range(1, W + 1):
            # まずは1つ前で補完, 価値は品物追加すれば単調増加なのでOK
            bef = dp[i-1][_w]
            dp[i][_w] = bef

            # 追加
            # 品物ループの内側にある重さのループではあるが、
            # このループでは何回も追加しないようになっている
            if _w + w <= W:
                changed = dp[i-1][_w] + v
                bef = dp[i-1][_w + w]
                # 補完と入れ替えを合わせると追加も兼ねている？
                # dp[i][_w + w] = max(bef, changed)

            # 入れ替え
            if _w - w >= 0:
                changed = dp[i-1][_w - w] + v
                bef = dp[i-1][_w]
                dp[i][_w] = max(bef, changed)

    # 補完により必ず[N][W] で最大
    # ans = max(dp[N])
    ans = dp[N][W]

    # from pprint import pprint
    # import sys
    # pprint(dp, stream=sys.stderr)
    return ans


if __name__ == "__main__":
    main()


Measured memory_bytes: 423640