akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  c = min(c, a + b + 1);
  P(b + c);
  return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt
  as <- getIntList
  print $ sum as - n


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

int main() {
  int n, l;
  cin >> n >> l;
  vector<string>v;
  string s;
  string t;
  for (int i = 0; i < (n); ++i){
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < (n); ++i){
    t += v[i];
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=input().split()
p=a.pop();c=1;d=[]
while a:
    if a[-1]==p:d+=[c];c=1
    else:c+=1
    p=a.pop()
d+=[c]
if len(d)<=3:print(sum(d))
else:
    print(max(sum(d[i:i+3]) for i in range(len(d)-2)))

Measured memory_bytes: 8924
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        while A[i] % 2 == 0:
            ans += 1
            A[i] //= 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40560
X = input()

x_length = len(X)
stack = []

for i in range(x_length):
    x = X[i]
    if x == "S":
        stack.append(x)

    elif x == "T" and stack and stack[-1] == "S":
        stack.pop()

    else:
        stack.append(x)
print(len(stack))

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



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

long long N, K;
long long A[2000002];
long long F[2000002];

long long max_af() {
    long long max = 0;
    for (long long i = 1; i <= N; ++i) {
        long long af = A[i] * F[i];
        if (max < af) max = af;
    }
    return max;
}

bool x_af(long long x) {
    long long k = 0;
    for (long long i = 1; i <= N; ++i) {
        long long af = A[i] * F[i];
        if (af > x) k += (af - x - 1) / F[i] + 1;
    }
    return k <= K;
}

long long bin_search(long long min, long long max) {
    if (min == max || max - min == 1) {
        return x_af(min) ? min : max;
    }
    long long mid = (min + max) / 2;
    return x_af(mid) ? bin_search(min, mid) : bin_search(mid, max);
}

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

    for (long long i = 1; i <= N; ++i) cin >> A[i];
    for (long long i = 1; i <= N; ++i) cin >> F[i];

    sort(&A[1], &A[N + 1]);
    sort(&F[1], &F[N + 1], greater<long long>());

    long long ans = bin_search(0, max_af());
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ab = a + b, cd = c + d;
  if (ab > cd)
    cout << "Left" << endl;
  else if (ab == cd)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define mod 1000000007
#define am 998244353
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){ 
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}	    
signed main(){
// __builtin_ctz(N);      Nを２で何回割り切れるかを返す
//(n+1)*n/2;              １からNまでの総和を求める式
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,c=0;
    int b[10000];
    cin>>a;
    for(int i=0;i<a*2;i++) cin>>b[i];
    sort(b,b+(a*2));
    for(int i=0;i<a*2;i++){
	if(i%2==0) c+=b[i];
    }
    cout<<c<<"\n";
}



Measured memory_bytes: 256
class UnionFindWithRank
  def initialize(n)
    @parent = Array.new(n, -1)
    @rank = Array.new(n, 0)
  end

  def root(x)
    return x if @parent[x] == -1
    @parent[x] = root(@parent[x])
    return @parent[x]
  end

  def same?(x, y)
    return root(x) == root(y)
  end

  def merge(x, y)
    x, y = root(x), root(y)
    return false if x == y
    x, y = y, x if @rank[x] < @rank[y]
    @rank[x] += 1 if @rank[x] == @rank[y]
    @parent[y] = x
    return true
  end
end

N, M = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
uf = UnionFindWithRank.new(N)
M.times do
  x,y = gets.split.map(&:to_i).map{|e| e-1}
  uf.merge(p[x]-1,p[y]-1)
end
ans = 0
N.times do |i|
  ans += 1 if uf.same?(i, p[i]-1)
end
puts ans

Measured memory_bytes: 12292
import java.io.*;
import java.util.*;
 
public class Main{
	
	int[] sum = new int[1001];
	public void solve(){
		for(int i = 999; i > 0; i--){
			if(i % 3 == 0){
				sum[i] = sum[i + 1] + 20 * 10;
			}else{
				sum[i] = sum[i + 1] + 20 * 5 + 19 * 5;
			}
		}
		
		int N = nextInt();
		
		for(int i = 0; i < N; i++){
			int y = nextInt();
			int m = nextInt();
			int d = nextInt();
			
			if(y % 3 == 0){
				int ans = 20 - d + 1;
				for(; m < 10; m++){
					ans += 20;
				}
				ans += sum[y + 1];
				out.println(ans);
			}else{
				int ans = m % 2 == 1 ? 20 - d + 1 : 19 - d + 1;
				for(int j = m + 1; j <= 10; j++){
					ans += j % 2 == 1 ? 20 : 19;
				}
				ans += sum[y + 1];
				out.println(ans);
				
			}
		}
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

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

using namespace std;

typedef long long ll;

int main(){
  ll K;  cin >> K;
    if( K <= 49){
      //exception when N == 1
      if( K == 0){ cout << 4 << endl;  for(int i = 0; i < 4; i++){ cout << 3 << " ";}
                  cout << endl; return 0;}
      
      ll N = K + 1;
      cout << N << endl;
      for(ll i = 0; i < N; i++){
        if( i == 0){ cout<< K*N + N - 1<<" ";}
        else{
          cout << 0 <<" ";} }
      
      cout <<endl; return 0;}
  else{
    // in the case of K is large enough
    
       ll N = 50;
    
       vector<ll> A(50,0);
      ll a = K / N; ll b = K % N;
      
      for(int i = 0; i < N; i++){ A[i] = a + (ll)i;}
    
    for(int i = 0; i < N; i++){
     
      if( i <= b - 1){ A[i] += N - b + 1;}
      else{ A[i] -= b;}}
    
         cout << N << endl;
         for(int i = 0; i < N; i++){ cout << A[i] <<" ";}
                                cout << endl; return 0;
    
    
    
    
       }
  
  return 0;}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define N 100005
#define ll long long
#define db double
#define dbg(x) cout<<#x<<"="<<x<<"\n"
int n,m;ll ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=m+1;i<=n;i++)
	{
		ans+=n/i*(i-m);
		if(n%i>=m) ans+=n%i-m+1;
//		cout<<i<<" "<<ans<<"\n";
	}
	if(!m) ans-=n;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        if (n == 1) {
            System.out.println(1);
            return;
        }
        Set<Integer> set = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        Set<Integer> set3 = new HashSet<>();
        List<Integer> list = new ArrayList<>();
        int max = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            max = Math.max(max, a);
            list.add(a);
            if (!set.contains(a)) {
                set.add(a);
            } else {
                set2.add(a);
            }
        }
        Collections.sort(list);
        for (int i = 1; i <= max; i++) {
            set3.add(i);
        }
        int ans = 0;
        for (int a : list) {
            if (!set2.contains(a) && set3.contains(a)) {
                ans++;
            }
            int idx = 1;
            while (a * idx <= max) {
                set3.remove(a * idx);
                idx++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 134676
/*
* @author:  codancer
* @createTime:  2020-08-22, 20:43:13
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
#define deb(x) cerr<<#x<<" = "<<(x)<<"\n"
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll B) {
	return (ull)rng() % B;
}
const int N = 1e6+100;
int n,m,k;
int x[N],y[N];
ll col[N],row[N];
map<pair<int,int>,int> mps;
int main(){
	cin>>n>>m>>k;
	rep(i,1,k){
		cin>>x[i]>>y[i];
		row[x[i]]++;
		col[y[i]]++;
	}

	ll maxr=-1,maxc=-1;
	rep(i,1,n) maxr=max(maxr,row[i]);
	rep(j,1,m) maxc=max(maxc,col[j]);

	map<int,int> mr,mc;
	ll A=0,B=0;
	rep(i,1,n){
		if(row[i]==maxr) mr[i]=1,++A;
	}
	rep(j,1,m){
		if(col[j]==maxc) mc[j]=1,++B;
	}

	ll cnt=0;

	rep(i,1,k){
		if(mr[x[i]]&&mc[y[i]]) ++cnt;
	}

	if(cnt>=A*B){
		// cout<<"B"<<endl;
		cout<<maxr+maxc-1<<endl;
	}else{
		// cout<<"A"<<endl;
		cout<<maxr+maxc<<endl;
	}
	return 0;
}

Measured memory_bytes: 38708
S = input()
Q = int(input())
reverse = False
front = ""
end = S

for _ in range(Q):
    I = input().split()
    if I[0] == "1":
        reverse = not reverse
    else:
        if (I[1] == "1") ^ reverse:
            front =front + I[2]
        else:
            end = end + I[2]


if reverse:
    print(end[::-1]+front)
    #print("".join(list(reversed(end)))+front)
else:
    print(front[::-1]+end)
    #print("".join(list(reversed(front)))+end)


Measured memory_bytes: 4596
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n,t,a;
    cin >> n >> t >> a;
    int h[n],m=0;
    double p[n];
    rep(i,n){
        cin >> h[i];
        p[i] =abs(a-(t-h[i]*0.006));
        if(p[i]<p[m]) m=i;
    }
    cout << m+1 << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll K;
    cin >> K;

    vec A;
    REP(i,1,10) A.pb(i);
    ll c = 0;
    while(SZ(A) < K) {
        ll a = A[c];
        if(a % 10 == 0) {
            A.pb(a*10);
            A.pb(a*10+1);
        }
        else if(a % 10 == 9) {
            A.pb(a*10+8);
            A.pb(a*10+9);
        }
        else {
            A.pb(a*10+(a%10)-1);
            A.pb(a*10+(a%10));
            A.pb(a*10+(a%10)+1);
        }
        ++c;
    }
    PR(A[K-1]);

    return 0;
}

/*



*/

Measured memory_bytes: 4292
#include<bits/stdc++.h>
#define int long long
using namespace std;

template<typename T>
void read(T &ans){T f = 1; char c = getchar();ans = 0;while(!isdigit(c)){if(c == '-')f = -1;c = getchar();}while( isdigit(c)){ans = ans*10 + c - '0';c = getchar();}ans*=f;}

map<int,int> mp;
int n, k, sum, ans;
signed main(){
	read(n);
	mp[0] = 1; sum = 0; ans;
	for(int i = 1; i <= n; i++){
		read(k);
		sum += k;
		mp[sum]++;
	}
	for(map<int,int>::iterator it = mp.begin(); it != mp.end(); it++){
		ans += (it->second)*(it->second-1) / 2;
	}
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll n;
  cin>>n;
  string s;
  while(n){
    n--;
    ll tmp=n%26;
    s.push_back(tmp+'a');
    n/=26;
  }
  reverse(s.begin(),s.end());
  cout<<s<<endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long N,i;
    cin>>N;
    long long A[N],B[N];
    for(i=0;i<N;i++){
        cin>>A[i];
        B[i]=A[i];
    }
    sort(B,B+N);
    for(i=0;i<N;i++){
        if(A[i]==B[N-1]){
            cout<<B[N-2]<<endl;
        }else{
            cout<<B[N-1]<<endl;
        }
    }
}


Measured memory_bytes: 4736
# coding: utf-8
# Your code here!

A, B, C = map(int, input().split())

d = 0
cnt = 0
while True:
   d += 1
   if d % 7 == 0:
      cnt += (A + B)
   else:
      cnt += A
   if cnt >= C:
      print(d)
      break



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

int main() {
int N,M;
  cin >> N >> M;
  int count = 0;
  int sum = 0;
  vector<int> suuji(N);
  for (int i = 0; i < N; i++){
  	cin >> suuji[i];
    sum += suuji[i];
  }
  for(int i=0; i < N; i++){
  	if(suuji[i]*4*M >= sum){
    	count ++;
    }
  }
  if(count >= M){
  	cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

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

int main(){
    int n,x;
    cin >> n;
    for(int i=1;i<=n;i++){
        x = i;
        if(i % 3 == 0){
            cout << " " << i;
            continue;
        }
        while(x){
            if(x % 10 == 3){
                cout << " " << i;
                break;
            }
            x /= 10;
        }
        
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int k, x, y, n;
  scanf("%d %d %d %d", &n, &k, &x, &y);

  int ans;
  if(n <= k) ans = x * n;
  else ans = x * k + y * (n - k);

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

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n,m,i,sum=0;
        cin>>n>>m;
       priority_queue<int> a;
       while(cin>>i&&a.size()<n)
       {
           a.push(i);
       }
       while(a.size()>(n-m))
       {
           sum+=a.top();
           a.pop();

       }
        cout<<sum;

        return 0;
    }


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
int  a[100];
int b[100];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    if(n==1)
    {
        cout<<a[1]<<endl;
        return 0;
    }
    int min1=1e9;
    int min2=1e9;
    b[0]=0;
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
    {
        if(i%2==0)
            b[i]=24-a[i];
        else
            b[i]=a[i];
    //cout<<b[i]<<endl;
    }
    sort(b,b+1+n);
    for(int i=1;i<=n;i++)
    {
         min1=min(min1,abs(b[i]-b[i-1]));
         //cout<<b[i]<<endl;
    }
     for(int i=1;i<=n;i++)
    {
        if(i%2==1)
            b[i]=24-a[i];
        else
            b[i]=a[i];
            //cout<<b[i]<<endl;
    }
    sort(b,b+1+n);
    for(int i=1;i<=n;i++)
    {
        min2=min(min2,abs(b[i]-b[i-1]));
    }
    cout<<min(min1,min2)<<endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  int n, a, b;

  cin >> n >> a >> b;

  ll sum = 0;

  REP(i, n + 1)
  {
    int t = i, s = 0;
    while (0 < t)
    {
      s += t % 10;
      t /= 10;
    }
    if (a <= s && s <= b)
      sum += i;
  }

  cout << sum << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 1e9;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
int main() {
    int n ,m;
    cin >> n >> m;
    priority_queue<pair<long, int>> card;
    REP(i, n) {
        ll tmp;
        cin >> tmp;
        card.push(make_pair(tmp, 1));
    }

    REP(i, m) {
        ll b, c;
        cin >> b >> c;
        card.push(make_pair(c, b));
    }
    ll ans = 0;
    REP(i, n) {
        pair<long, int> t;
        t = card.top();
        card.pop();
        ans += t.first;
        t.second--;
        if(t.second > 0) card.push(t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6256
#include <iostream>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int s[10][10];
    int k[10];
    int p[10];
    for(int i = 0; i < M; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    for(int i = 0; i < M; i++) cin >> p[i];
    int n = (1<<N);
    int ans = 0;
    for(int i = 0; i < n; i++){
        bool allON = true;
        for(int j = 0; j < M; j++){
            int cnt = 0;
            for(int l = 0; l < k[j]; l++){
                int m = (1<<s[j][l]);
                if(m&i) cnt++;
            }
            if(cnt%2 != p[j]) allON = false;
        }
        if(allON) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    
    int[] lst = new int[6];
    
    void shake(char x){
        switch (x){
            case 'W':
                lst = new int[]{lst[2],lst[1],lst[5],lst[0],lst[4],lst[3]};break;
            case 'S':
                lst = new int[]{lst[4],lst[0],lst[2],lst[3],lst[5],lst[1]};break;
            case 'E':
                lst = new int[]{lst[3],lst[1],lst[0],lst[5],lst[4],lst[2]};break;
            case 'N':
                lst = new int[]{lst[1],lst[5],lst[2],lst[3],lst[0],lst[4]};break;
        }
    } 
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        Main dice = new Main();
        for(int i=0;i<6;i++){
            dice.lst[i]=sc.nextInt();
        }
        
        String s = sc.next();
        
        for(int i=0;i<s.length();i++){
            dice.shake(s.charAt(i));
        }
        
        System.out.println(dice.lst[0]);
    }
}


Measured memory_bytes: 26264
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n,k;
  cin>>n>>k;
  long long ans=1;
  REP(i,n){
    if(i==0){
      ans *= k;
    }else{
      ans *= (k-1);
    }
  }
  cout<<ans<<endl;
  return 0;
}



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

#define N 20
#define Q 200

int A[N], M[Q];

int is(int n, int m) {
    if (m == 0) return 1;
    if (n > N - 1) return 0;
    return is(n + 1, m) || is(n + 1, m - A[n]);
}


int main(void){
    int n, q, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);
    
    for (i = 0; i < q; i++) {
        scanf("%d", &M[i]);
    }
    
    for (i = 0; i < q; i++) {
        if (is(0, M[i])) {
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }
    
    return 0;
}


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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N,L;
  cin>>N>>L;
  vector<ll> v(N);
  for(ll i = 0; i < N; i++) cin>>v[i];
  bool can = false;
  ll t;
  for(ll i = 0; i < N-1; i++){
    if(v[i]+v[i+1]>=L) {
      t=i;
      can = true;
      break;
    }
  }
  if(can) {
    cout<<"Possible"<<endl;
    for(ll i = 0; i < t; i++){
      cout<<i+1LL<<endl;
    }
    for(ll i = N-2; i>t;i--){
      cout<<i+1LL<<endl;
    }
    cout<<t+1LL<<endl;
  }
  if(!can)  cout<<"Impossible"<<endl;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    while (true) {
        for (int j = 0; j < W; j++) {
            cout << "#";
        }
        cout << endl;
        for (int i = 1; i < H-1; i++) {
            cout << "#";
            for (int j = 1; j < W-1; j++) {
                cout << ".";
            }
            cout << "#" << endl;
        }
        for (int j = 0; j < W; j++) {
            cout << "#";
        }
        cout << endl << endl;
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll n;

int main(){
  cin >> n;
  cout << n*n*n << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,A[2020][2020],pt[2020],T[330];
bool Ban[2020];
int main(){
	scanf("%d %d",&n,&m);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) scanf("%d",&A[i][j]);
	
	for (int i=1;i<=n;i++) pt[i]=1;
	int ans=n;
	for (int i=1;i<m;i++){
		memset(T,0,sizeof(T));
		for (int j=1;j<=n;j++)
			T[A[j][pt[j]]]++;
		int pos=0;
		for (int j=1;j<=m;j++)
			if (T[j]>T[pos]) pos=j;
		ans=min(ans,T[pos]);	
		
		Ban[pos]=1;
		for (int j=1;j<=n;j++)
			while (Ban[A[j][pt[j]]]) pt[j]++;
		
		
		memset(T,0,sizeof(T));
		for (int j=1;j<=n;j++)
			T[A[j][pt[j]]]++;
		pos=0;
		for (int j=1;j<=m;j++)
			if (T[j]>T[pos]) pos=j;
		ans=min(ans,T[pos]);
	}
	cout<<ans;
}

Measured memory_bytes: 3584
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)// for macro
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define CIN2(x,y) int x,y;cin>>x>>y;
#define CIN3(x,y,z) int x,y,z;cin>>x>>y>>z;
#define SCIN(x) string x;cin>>x;
#define SCIN2(x,y) string x,y;cin>>x>>y;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i];
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())


#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    CIN(n);V a(n);VECCIN(a);
    sort(ALL(a));
    int ans=0;ll acc=a[0];
    FOR(i,1,n){
        if(acc*2<a[i])ans=i;
        acc+=a[i];
    }
    COUT(n-ans);

    return 0;
}


Measured memory_bytes: 640
n = int(input())

adj_mat = [[0 for i in range(n + 1)] for j in range(n)]

for i in range(n):
    adj_list = list(map(int, input().split()))
    for j in adj_list[2:]:
        adj_mat[i][j] = 1

for a_l in adj_mat:
    print(*a_l[1:])

Measured memory_bytes: 8476
#include<bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fr first
#define sc second
#define M_PI           3.14159265358979323846
using namespace std;
ll n,w,A[101],B[101],Dp[101][100100];
ll Solve(int i,int val){

    if(val>w||i>n)
        return -1e9;
    if(i==n||val==w)
        return 0;

    if(Dp[i][val]!=-1)
        return Dp[i][val];
    Dp[i][val]=max(Solve(i+1,val+A[i])+B[i],Solve(i+1,val));
    return Dp[i][val];

}
int main()
{
    Start;
    cin>>n>>w;
    for(int i=0;i<n;i++)
        cin>>A[i]>>B[i];
    memset(Dp,-1,sizeof(Dp));
    cout<<Solve(0,0);



}


Measured memory_bytes: 79232
#include <iostream>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int aaa[n];
    for(int i=1;i<=n;i++){
        aaa[i] = true;
    }
    for(int j=0;j<k;j++){
        int d;
        cin >>d;
        for(int i=0;i<d;i++){
            int a;
            cin >> a;
            aaa[a] = false;
        }
    }
    int c = 0;
    for(int i=1;i<=n;i++){
        if(aaa[i]){
            c++;
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3192
N = int(input())
A = list(map(int, input().split()))
n = [0] * N
#A_2 A_3 ... A_N とA_1をのぞいて続くのでN-1となる
for i in range(N-1):
    n[A[i]-1] += 1

for j in range(N):
    print(n[j])

Measured memory_bytes: 32300
#include <stdio.h>

int main(void){

	int a,b;
	char op,none;
	
	while(1){
		scanf("%d", &a);
		scanf("%c", &none);
		scanf("%c", &op);
		scanf("%d", &b);
		
		if(op=='?'){
			break;
		}
		
		switch(op){
			case '+':
				printf("%d\n", a+b);
				break;
			case '-':
				printf("%d\n", a-b);
				break;
			case '*':
				printf("%d\n", a*b);
				break;
			case '/':
				printf("%d\n", a/b);
				break;
			default:
				printf("invalid\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 2744
def main():
    s = input()
    n = len(s)
    s = int(s, 2)
    p = [
        int(('10'*int(((10**5))/2))[:n], 2),
        int(('01'*int(((10**5))/2))[:n], 2),
    ]
    print(min(bin(s ^ p[0]).count('1'), bin(s ^ p[1]).count('1')))

if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific

using namespace std;

typedef unsigned long long ull;
 
int main(int argc, char* argv[])
{
    ull x;
    cin >> x;
    
    ull a = (x%11 > 6 ? 2 : 1);
    if (x%11 == 0) --a;

    cout << ((x/11)*2 + a) << endl;

    return 0;
}


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

int gcd(int x, int y){

  if( (x % y) != 0 )
    return gcd(y, (x % y));
  else
    return y;

}


int main(){

  int x, y;

  std::cin >> x >> y;

  std::cout << gcd(x, y) << std::endl;

  return 0;

}

Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<b){
        if(b<c){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stack>
using namespace std;
char num[40005];
int main()
{
	int  n;
	while(scanf("%d",&n)!=EOF)
	{
		stack <int> s;
		int a;
		if(n == 0)
		printf("0\n");
		else
		{
			while(n!=0)
		{
		a = abs(n%(-2));
		s.push(a);
		n = (n-a) / (-2);
		}
		}
		while(!s.empty())
		{
			cout<<s.top();
			s.pop();
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int main()
{
    int n, s[100], i;
    int max, min, ava, sum;
    while (1)
    {
        max = 0;
        min = 1000;
        sum = 0;
        scanf("%d", &n);
        if (n == 0)
        {
            break;
        }
        for (i = 0; i < n; i++)
        {
            scanf("%d", &s[i]);
            if (max < s[i])
            {
                max = s[i];
            }
            if (min > s[i])
            {
                min = s[i];
            }
            sum += s[i];
        }
        sum -= max;
        sum -= min;
        ava = sum / (n - 2);
        printf("%d\n", ava);
    }
    return 0;
}



Measured memory_bytes: 2568
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lb long double
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >

using namespace std;

const int N = 100005;
const int M = 1000000007;
const lb PI = acos(-1);

int t , n , q , l , r;
int a[N];
char s[N];

void Test()
{
    int i;

    cin >> n >> q;
    cin >> s + 1;

    for(i = 1 ; i <= n ; i++)
    {
        if(s[i] == 'C' && s[i - 1] == 'A')
            a[i] = a[i - 1] + 1;
        else a[i] = a[i - 1];
    }

    for(i = 1 ; i <= q ; i++)
    {
        cin >> l >> r;
        cout << a[r] - a[l - 1] - (s[l - 1] == 'A' && s[l] == 'C' ? 1 : 0) << '\n';
    }
}

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

	t = 1;

	while(t--)
		Test();

    return 0;
}


Measured memory_bytes: 1280
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (h, w) = (v[0], v[1]);
    let mut ans = std::i64::MAX;

    for &(h, w) in &[(h, w), (w, h)] {
        let h1 = h / 3;
        let h2 = h - h1 * 2;
        ans = min(ans, (h2 - h1).abs() * w);
    }
    for &(h, w) in &[(h, w), (w, h)] {
        let h1 = (h + 1) / 3;
        let h2 = h - h1 * 2;
        if h2 >= 0 {
            ans = min(ans, (h2 - h1).abs() * w);
        }
    }
    for &(h, w) in &[(h, w), (w, h)] {
        let w1 = w / 2;
        let w2 = w - w1;
        for h1 in 0..h + 1 {
            let h2 = h - h1;
            let area1 = h1 * w;
            let area2 = h2 * w1;
            let area3 = h2 * w2;
            ans = min(
                ans,
                [area1, area2, area3].iter().max().unwrap()
                    - [area1, area2, area3].iter().min().unwrap(),
            );
        }
    }
    println!("{:?}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main() {
  int N, M, x;
  cin >> N >> M;
  vector<int> s(N);
  for (int i = 0; i < M * 2; i++) {
    cin >> x;
    s.at(x - 1) += 1;
  }
  for (int j = 0; j < N; j++) {
    cout << s.at(j) << endl;
  }
}

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

static const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    map<int, int> m;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        m[a]^=1;
    }
    int ans = 0;
    for (auto &&i : m) {
        ans += i.second;
    }
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::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 debug(...)
#endif

const int N = 13;

LL n , m , x;
LL cost[N];
LL grid[N][N];
LL ex[N],money;

LL ans = 1e18;
void rec(LL pos)
{
    if(pos == n + 1){
        bool ok = 1;
        for(LL i = 1;i <= m;i++){
            if(ex[i] < x)ok = 0;
        }
        if(ok){
            ans = min(ans,money);
        }
        return;
    }
    rec(pos + 1);

    money += cost[pos];
    for(LL i = 1;i <= m;i++)ex[i] += grid[pos][i];
    rec(pos + 1);
    for(LL i = 1;i <= m;i++)ex[i] -= grid[pos][i];
    money -= cost[pos];

}
int main()
{
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cin >> n >> m >> x;

    for(LL i = 1;i <= n;i++){
        cin >> cost[i];
        for(LL j = 1;j <= m;j++){
            cin >> grid[i][j];
        }
    }
    rec(1);
    if(ans == 1e18)ans = -1;
    cout << ans << "\n";
    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}


Measured memory_bytes: 3628
#include <stdio.h>

struct data {int score[100],n;} table[20];
struct data *d;

void sort(int *a,int n){
  int i,j,t;
  for(i=0; i<n-1; i++) for(j=n-1; j>i; j--)
  if(a[j-1]>a[j]) {t=a[j-1]; a[j-1]=a[j]; a[j]=t;}
}

int main(){
  int i,j,N,ave;
  for(i=0;; i++) {d=&table[i];
    scanf("%d",&d->n );
    if(d->n==0) break;
    for(j=0; j<d->n; j++) scanf("%d",&d->score[j] ); }
    N=i;
    for(i=0; i<N; i++) {d=&table[i];ave=0;
      sort(d->score,d->n);
      for(j=1; j<d->n-1; j++) ave+=d->score[j];
      ave/=d->n-2;
      printf("%d\n",ave);}
    }

Measured memory_bytes: 2640
#include <stdio.h>

int main()
{
    int a, b;
    int digit;
    const int div = 10;
    
    while (scanf("%d %d", &a, &b) != EOF) {
        digit = 0;
        a += b;
        do {
            digit++;
        } while (a /= 10);
        printf("%d\n", digit);
    }
        
    return 0;
} 


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

int main(void){
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i, n) cin>>h[i];
    int ans=0;
    int maxnum=1;
    while(maxnum>0){
        maxnum=0;
        int cnt=0;
        rep(i, n){
            maxnum=max(maxnum, h[i]);
        }
        rep(i, n){
            if(h[i]==maxnum&&(i==0 || h[i]!=h[i-1])) cnt++;
        }
        //cout<<cnt<<endl;
        ans+=cnt;
        rep(i, n){
            if(h[i]==maxnum) h[i]--;
        }
        //rep(i, n) cout<<h[i]<<", "; cout<<endl;
    }
    cout<<ans-1<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
#define inf 1000000000000
int main(){
    int N,W;
    cin >> N >> W;
    vector<ll>w(N),v(N);
    REP(i,N)cin >> w[i] >> v[i];
    ll dp[N+1][100100];
    REP(i,N+1)REP(j,100100)dp[i][j]=inf;
    dp[0][0]=0;
    FOR(i,1,N+1){
        FOR(j,0,100100){
            if(j>=v[i-1])dp[i][j]=min(dp[i-1][j-v[i-1]]+w[i-1],dp[i-1][j]);
            else dp[i][j]=dp[i-1][j];
        }
    }

    /*FOR(i,0,N+1){
        FOR(j,0,20){
            printf("%10lld ",dp[i][j]);
        }
        cout << endl;
    }*/
    
    
    FORR(i,100100,0){
        if(dp[N][i]<=W){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 82620
function prime(max){
   var arr=[];
   for(var i=0;i<=max;i++)arr[i]=i;
   arr[0]=false;
   arr[1]=false;
   var sqrt=Math.floor(Math.sqrt(max));
   for(var i=2;i<=sqrt;i++){
      if(arr[i]==false)continue;
         for(var j=i+i;j<=max;j+=i){
            arr[j]=false;
         }
   }
   var result=[];
   for(var i=0;i<=max;i++){
      if(arr[i]!==false)result.push(arr[i]);
   }
   return result;
}
var p=prime(10000);

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n").map(Number);
var cnt=[];
for(var i=0;i<=10000;i++)cnt[i]=0;
p.forEach(function(v,index){
   cnt[v]++;
   for(var i=index+1;i<p.length;i++){
      v+=p[i];
      if(v>10000)break;
      cnt[v]++;
   }
});
arr.some(function(v){
   if(v==0)return true;
   console.log(cnt[v]);
});

Measured memory_bytes: 16824
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define N 100003
#define inf (ll)1e9+1
#define warmup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7; 
int cnt[N];

signed main()
{
    warmup
    
    int n,m;
    cin>>n>>m;
    int p,pen=0,ac=0,i,j;
    string s;
    for(i=1;i<=m;++i)
    {
        cin>>p>>s;
        if(s[0]=='W' and cnt[p]>-1)
            ++cnt[p];
        else if(s[0]=='A' and cnt[p]>-1)
            pen+=cnt[p], cnt[p]=-1, ++ac;
    }   
    cout<<ac<<' '<<pen;
    
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define PI pair<int,int>
#define ff first
#define ss second
#define int long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)

const int N=3333;
const int M=998244353;

int n,s;
int a[N],dp[N][N];

int okk(int id,int cur){
	if(cur==0)
		return n-id+2;
	if(id>n or cur<0)
		return 0;
	int &tmp = dp[id][cur];
	if(tmp != -1)
		return tmp;
	tmp=okk(id+1,cur);
	tmp+=okk(id+1,cur-a[id]);
	tmp%=M;
	return tmp;
}

int32_t main() { 
	boost;
 	cin>>n>>s;
	
	for(int i=1;i<=n;i++)
		cin>>a[i];
	memset(dp,-1,sizeof dp);
	int ans=0;

	for(int i=1;i<=n;i++){
		ans=(ans+okk(i,s))%M;
		ans+=M;ans%=M;
	}
	cout<<ans<<endl;
}		    

Measured memory_bytes: 87168
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<set>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
#define ms(f,x) memset(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);
		putchar('\n');
		return;
    }
}
using IO::read;
using IO::write;
using namespace std;
#define gi(x) read(x)
int a[233333];
long long sum;
int n;
int main(){
    gi(n);
    rep(i,1,n+n)
        gi(a[i]);
    sort(a+1,a+n+n+1);
    for(int i=1;i<=n+n;i+=2)
        sum+=a[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, h, w = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]

ans = 0
for i in range(n):
    if A[i][0] >= h and A[i][1] >= w:
        ans += 1
print(ans)

Measured memory_bytes: 38896