akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
     
    N = int(readline())
    m = map(int,read().split())
    ABC = zip(m,m,m)
     
    x,y,z = 0,0,0 # 最後の活動 -> 幸福度のmax
    for a,b,c in ABC:
        x,y,z = max(y,z)+a,max(x,z)+b,max(x,y)+c
     
    answer = max(x,y,z)
    print(answer)
main()

Measured memory_bytes: 20320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 123456789012345678;
const ll mod = 998244353;
#pragma GCC optimize("Ofast")
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define sz(x) ((int)(x).size())

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

    int n;
    cin >> n;
    vl a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    vl b(n);
    for(int i = 1; i < n; i++){
        b[i] = a[i-1]-b[i-1];
    }
    int f = (a[n-1]-b[n-1])/2;
    for(int i = 0; i < n; i++){
        cout << (b[i] + f * (i%2==0?1:-1)) * 2 << " ";
    }
}

Measured memory_bytes: 2944
Module Module1

sub Main(ByVal args() as String)
    dim A as integer = Console.ReadLine()
    dim B as integer = Console.ReadLine()
    dim C as integer = Console.ReadLine()
    dim X as integer = Console.ReadLine()

    dim cnt as integer = 0
    for i as integer = 0 to A
    for j as integer = 0 to B
    for k as integer = 0 to C
        if 500 * i + 100 * j + 50 * k = X then
            cnt += 1
        end if
    next k
    next j
    next i

    Console.WriteLine(cnt)
end sub

end Module

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main () {
  long long n,a,b;
  cin >> n >> a >> b;
  long long c = 0;
  long long d = 0;
 c = n / (a+b) * a;
  d = n % (a+b);
  if (d > a) {
    cout << c + a << endl; }
  else {
    cout << c + d << endl; } }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 312;
int n, k, mod;
int mul(long long a, long long b){
	return a * b % mod;
}
int comb[maxn][maxn], f[2][maxn][maxn];
int calc_tree(int r, int sons);
int calc_sub(int r, int sons){
	if(r > k) return 0;
	int & v = f[0][r][sons];
	if(~v) return v;
	v = calc_sub(r + 1, sons) + calc_tree(r, sons);
	if(v >= mod) v -= mod;
	return v;
}
int calc_tree(int r, int sons){
	if(sons == 0) return 1;
	int & v = f[1][r][sons];
	if(~v) return v;
	v = 0;
	for(int i = 0; i < sons; i++){
		v += mul(calc_sub(r + 1, i), mul(calc_tree(r, sons - i - 1), comb[sons - 1][i]));
		if(v >= mod) v -= mod;
	}
	return v;
}
int main(){
	cin >> n >> k >> mod;
	for(int i = 0; i <= n; i++){
		comb[i][0] = comb[i][i] = 1;
		for(int j = 1; j < i; j++){
			comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
			if(comb[i][j] >= mod) comb[i][j] -= mod;
		}
	}
	memset(f, -1, sizeof(f));
	cout << calc_tree(0, n) << endl;
	return 0;
}



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

int main() {
    int n,a,k,count;
    cin>>n;
    count=0;
    a=1;
    while(n--)
    {
        cin>>k;
        if(a%2==1&&k%2==1)
        {
            count++;
        }
        a++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cerr << x << endl
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    V<ll> a(n), as(n);
    rep(i,n) cin >> a[i];
    as = a;
    partial_sum(as.begin(), as.end(), as.begin());
    as.insert(as.begin(), 0);
    // debug(as);
    auto dp = make_vec(n+1, n+1, LINF); //[l,r]のスライムを作るための最小コスト
    auto rec = [&](auto self, int l, int r) -> ll
    {
        if(l == r)
        {
            dp[l][r] = 0;
            return 0;
        }
        if(dp[l][r] < LINF)
        {
            return dp[l][r];
        }
        ll res = LINF;
        for(int i = l; i < r; i++)
        {
            ll p = self(self, l, i) + self(self, i+1, r) + as[r+1] - as[l];
            chmin(res, p);
        }
        // chmin(dp[l][r], res);
        dp[l][r] = res;
        return res;
    };
    cout << rec(rec, 0, n-1) << endl;
    // debug(dp);
    return 0;
}

Measured memory_bytes: 4524
#include<stdio.h>
int main(){
	
int a,b;
 
while(scanf("%d %d",&a,&b),a||b){
	
	if(a<b)printf("%d %d\n",a,b);
	else printf("%d %d\n",b,a);
	//printf("%d %d\n",(a<b)?a:b,(a<b)?b:a);
}

return 0;
}


Measured memory_bytes: 2024
#include <stdio.h>

const int pow2[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144};

int num[18], u[18];
int n, k;

void run(int m)
{
  static char buf[64] = {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,'\n',0};
  //  buf[63]=0;
  //  buf[62]='\n';

  if (m==k) {
    int d, v, o=61;
    d = 0;
    for (int i=0; i<k; i++) {
      v = num[i];
      d += pow2[v];
      if (v==0) {
	buf[o--]='0';
      }
      for (; v>0; o--, v/=10)   buf[o] = '0' + (v%10);
      buf[o--]=' ';
    }
    buf[o--] = ':';
    for (; d>0; o--, d/=10)
      buf[o] = '0' + (d%10);
    fputs(buf+o+1, stdout);
    
  } else {
    for (int i=0; i<n; i++) {
      if (m>0 && num[m-1]<i) continue;
      if (u[i]) continue;
      num[m] = i;
      u[i]=1;
      run(m+1);
      u[i]=0;
    }
  }
}

int main()
{
  char buf[8];
  char *p=buf;
  fgets(p, 8, stdin);
  if (p[2]==' ') {
    n = (p[0]-'0')*10+p[1]-'0';
    p += 3;
  } else {
    n = p[0]-'0';
    p += 2;
  }
  k = (*(p+2)=='\n') ? (*p-'0')*10+*(p+1)-'0' : *p-'0';

  run(0);

  return 0;
}



Measured memory_bytes: 2048
/*
 * SAD
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define S second
#define F first
#define pb push_back
const int inf = 1e9;
using ii = pair<int, int>;
using ll = long long;
using db = long double;

const int N = 2e5 + 5, M = 1000 * 1000 * 10 + 5, K = 55, Base = 27, MOD = 1e9
		+ 7, MOD2 = 998244353;
const ll MX = 1e15;
const int blkSz = 200;
const db EPS = 1e-7;
const int PI = 3;
int B, W;

ll fast(ll b, ll e) {
	if (!e)
		return 1;
	if (e & 1)
		return 1ll * b * fast(b, e - 1) % MOD;
	return fast(1ll * b * b % MOD, e >> 1);
}
ll F[N], iF[N], pwr[N];
ll C(ll n, ll k) {
	if (k > n)
		return 0;
	return 1ll * F[n] * iF[k] % MOD * iF[n - k] % MOD;
}
ll q[N], p[N];
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	ll INV2 = fast(2, MOD - 2);
	cin >> B >> W;
	F[0] = iF[0] = 1;
	pwr[0] = 1;
	for (ll i = 1; i < N; i++) {
		F[i] = 1ll * F[i - 1] * i % MOD;
		iF[i] = fast(F[i], MOD - 2);
		pwr[i] = 1ll * pwr[i - 1] * INV2 % MOD;
	}

	for (ll i = 1; i < N; i++) {
		p[i] = p[i - 1] + 1ll * C(i - 1, B - 1) * pwr[i] % MOD;
		q[i] = q[i - 1] + 1ll * C(i - 1, W - 1) * pwr[i] % MOD;
		p[i] %= MOD;
		q[i] %= MOD;
	}
	for (ll i = 0; i < B + W; i++) {
		cout << 1ll * (1 + MOD - p[i] + q[i]) % MOD * INV2 % MOD << '\n';
	}
	return 0;
}


Measured memory_bytes: 9984
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	public static void main(String[] args) {
		
		int N = sc.nextInt();
		int[] x = new int[N + 1];
		x[0] = sc.nextInt();
		
		for(int i = 1; i <= N; i++) {
			x[i] = sc.nextInt();
		}
		
		Arrays.sort(x);
		
		long ans = 0;
		for(int i = 1; i <= N; i++) {
			long diff = x[i] - x[i - 1];
			ans = gcd(ans, diff);
		}
		
		System.out.println(ans);
	}
	
	static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
}

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

int main() {
    int A,B,C;
    cin >> A>> B>>C;
   if (A==B){
     cout<<C<<endl;
   }
   if (A==C){
     cout<<B<<endl;
   }
   if (B==C){
     cout<<A<<endl;
   }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
const ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}
 
#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll n,ans=0;

    cin >> n;

    for(ll i=0; i<n; i++){
        ll a;
        cin >> a;
        if((i+1)%2==1&&a%2==1){
            ans++;
        }
    }

    cout << ans << endl;
 
    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
  int n, m, Nco = 0, Mco = 0;
  cin >> n >> m;
  if (n > 1) {
    Nco = n*(n-1)/2;
  }
  if (m > 1) {
    Mco = m*(m-1)/2;
  }
  cout << Nco + Mco << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7+5;
priority_queue<int> q;
int main(){	 
	ll n,m,sum=0;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		q.push(x);
	}
	while(!q.empty()){
		if(m<=0) break;
		int x=q.top();
		q.pop();
		x=x/2;
		q.push(x);
		m--;	
	}
	while(!q.empty()){
		int x=q.top();
		q.pop();
		sum+=x;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 892
#include<iostream>

int main(){

    size_t r, g, b, n;
    std::cin >> r >> g >> b >> n;

    size_t cnt = 0;

    for(size_t i = 0; i <= 3000; i++){
        for(size_t j = 0; j <= 3000; j++){
            if(i * r + j * g <= n){
                if((n - (i * r + j * g)) % b == 0){
                    cnt++;
                }
            }
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int S=s.size(),T=t.size();
  vector<char> ss(S),tt(T);
  
  for(int i=0;i<S;i++) ss[i]=s[i];
  for(int i=0;i<T;i++) tt[i]=t[i];
  
  sort(ss.begin(),ss.end());
  sort(tt.begin(),tt.end());
  reverse(tt.begin(),tt.end());
  
  for(int i=0;i<S;i++) s[i]=ss[i];
  for(int i=0;i<T;i++) t[i]=tt[i];

  
  if(s<t) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cstdio>


using namespace std;

#define int long long

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

    int w, h, x, y;
    cin >> w >> h >> x >> y;

    double ans = ((double)w * (double)h) / 2;

    signed a = (w%2 == 0) && (w / 2 == x) && (h%2 == 0) && (h / 2 == y);

    cout << ans << " " << a << endl;
}

Measured memory_bytes: 256
# D - Sum of Large Numbers
import numpy as np

n, k = map(int, input().split())
mod = 10**9+7

r = np.cumsum(np.arange(n+1))
rr = np.cumsum(np.arange(n+1)[::-1])

ans = 0
for i in range(k, n+1+1):
    ans += rr[i-1] - r[i-1] + 1
    ans = ans%mod

print(ans)

Measured memory_bytes: 31356
#include<bits/stdc++.h>
using namespace std;
double a[200005],sum,b[200005],c[200005],x,y,ans=0;
int main()
{
    int i,j,k,l,m,n;

    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        x=a[i]*(a[i]+1)/(2*1.0);
        a[i]=x/a[i];
        sum+=a[i];
        m=i-k;
        if(m>=0)
            sum-=a[m];
        if(sum>ans)ans=sum;
    }
    printf("%.10lf\n",ans);
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

bool cmp(P x, P y) {
	return x.second < y.second;
}

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

	int n, m;
	cin >> n >> m;
	vector<P> d(m);
	rep(i, m) cin >> d[i].first >> d[i].second;

	sort(all(d), cmp);

	int ans = 0;
	int ed = 0;

	rep(i, m) {
		if(d[i].first >= ed) {
			ed = d[i].second;
			ans++;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        int maxWeight = scanner.nextInt();

        int[] weights = new int[count];
        int[] values = new int[count];
        int sumValue = 0;
        for (int i = 0; i < count; ++i) {
            weights[i] = scanner.nextInt();
            values[i] = scanner.nextInt();
            sumValue += values[i];
        }

        long[] dp = new long[sumValue + 1];
        for (int v = 1; v <= sumValue; ++v) {
            dp[v] = maxWeight + 1;
        }

        for (int i = 0; i < count; ++i) {
            for (int v = sumValue; v >= values[i]; --v) {
                dp[v] = Math.min(dp[v], dp[v - values[i]] + weights[i]);
            }
        }

        int res = 0;
        for (int v = 0; v <= sumValue; ++v) {
            if (dp[v] <= maxWeight) {
                res = v;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 22484
import Control.Applicative
import Data.List

main = do
  [h,w] <- map read . words <$> getLine :: IO [Int]
  s <- getContents

  let count = [length $ filter (==c) s | c <- ['a'..'z']]
  
  putStrLn $ if solve h w count then "Yes" else "No"
  
  where
    solve h w count
      | even h && even w = all ((==0) . (`mod`4)) count
      | odd h && odd w =
        (length . filter ((==2) . (`mod`4))) count <= (h `div` 2 + w `div` 2) &&
        (length . filter odd) count == 1
      | odd h = all even count && (length . filter ((==2) . (`mod`4))) count <= w `div` 2
      | odd w = all even count && (length . filter ((==2) . (`mod`4))) count <= h `div` 2


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

int main() {
  long int anum, bnum, m, x, y, c, result, min;
  cin >> anum;
  cin >> bnum;
  cin >> m;
  long int A[anum], B[bnum];
  for (long int i = 0; i < anum; i++) {
    cin >> A[i];
  }
  for (long int i = 0; i < bnum; i++) {
    cin >> B[i];
  }
  cin >> x;
  cin >> y;
  cin >> c;
  result = A[x - 1] + B[y - 1] - c;
  for (long int i = 1; i < m; i++) {
    cin >> x;
    cin >> y;
    cin >> c;
    result = (result > (A[x - 1] + B[y - 1] - c)) ? (A[x - 1] + B[y - 1] - c) : result;
  }
  min = *min_element(A, A + anum) + *min_element(B, B + bnum);
  if (min < result) {
    cout << min << endl;
  } else {
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt(),b=s.nextInt();
        if(b%a==0) System.out.println(a+b);
        else System.out.println(b-a);

    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
typedef long long ll;

const ll mod = 1e9+7;
const ll inf = 2e18;

vector<string> v;
ll n,m,x;

void genpos(ll idx,string &s)
{
	if(idx==n)
	{
		v.pb(s);
		return;
	}

	s+='0';
	genpos(idx+1,s);
	s.pop_back();

	s+='1';
	genpos(idx+1,s);
	s.pop_back();
}

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

	cin>>n>>m>>x;
	string aux="";
	genpos(0,aux);
	ll c[n];
	
	vector<ll> a[n+5];
	ll inimax = 0;

	for(ll i=0;i<n;i++)
	{	
		ll ele;
		cin>>c[i];
		inimax+=c[i];
		for (ll j = 0; j < m; ++j)
		{
			cin>>ele;a[i].pb(ele);
		}
	}



	ll res = INT_MAX;
	for(string s:v)
	{

		vector<ll> check(m,0);
		ll sum = 0;
		for(ll i=0;i<s.size();i++)
		{	

			if(s[i]=='1')
			{	
				sum+=c[i];
				for(ll j=0;j<a[i].size();j++)
				{
					check[j]+=a[i][j];
				}
			}
		}

		bool flag = true;
		for(ll i=0;i<m;i++)
		{
			if(check[i]<x)
			{
				flag=false;break;
			}
		}
		if(flag)
		{
			res=min(res,sum);
		}
	}	
	if(res==INT_MAX)
		cout<<-1<<'\n';
	else	
	cout<<res<<'\n';
	return 0;
}	

Measured memory_bytes: 3788
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    vector<vector<int> > nn;
    nn.resize(n);
    for(int i = 0; i < m; ++i){
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        nn.at(x-1).push_back(y-1);
        nn.at(y-1).push_back(x-1);
    }

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

    for(int i = 1; i < n; ++i){
        if(nn.at(i).size() == 0){
            visited.at(i) = true;
            ans++;
        }
    }

    stack<int> s;
    visited.at(0) = true;
    s.push(0);
    ans++;
    while(!s.empty()){
        while(!s.empty()){
            int x = s.top(); s.pop();
            for(int y : nn.at(x)){
                if(visited.at(y)){ continue; }
                visited.at(y) = true;
                s.push(y);
            }
        }

        for(int i = 0; i < n; ++i){
            if(!visited.at(i)){
                s.push(i);
                visited.at(i) = true;
                ans++;
                break;
            }
        }
    }

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


Measured memory_bytes: 6520
#include<stdio.h>
int main(void)
{
	int n,i,j,r,x;
	char s[111],t[111];
	scanf("%d %s %s",&n,s,t);
	r=2*n;
	for(i=1;i<=n;i++){
		x=n-i;
		for(j=0;j<i;j++){
			if(s[j+x]!=t[j])
				break;
			if(j==i-1)
				r=2*n-i;
		}
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 128
import math
A, B, H, M = map(int, input().split())  
c = abs(0.5*(60*H+M) - 6*M)
if (c>180):
  c = 360 -c
C = A**2 + B**2 - 2*A*B*math.cos(math.radians(c))
print(math.sqrt(C))

Measured memory_bytes: 9500
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	string s;
	cin >> s;
	int ans = 700;
	if (s[0] == 'o')ans += 100;
	if (s[1] == 'o')ans += 100;
	if (s[2] == 'o')ans += 100;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	while(1){
		int n,a=0,f=0;
		cin>>n;
		if(n==-1) break;
		if(n==0){
			cout<<0<<endl; continue;
		}
		string s;
		rep(i,0,10){
			a=n/(int)pow(4,9-i);
			n%=(int)pow(4,9-i);
			if(a){
				cout<<a; f=1;
			}
			else if(a==0&&f==1) cout<<0;
			if(i==9) cout<<endl;
		}
	}
}

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

int main(void){
    int n, x;
    while(true){
        int ans=0;
		cin >> n >> x;
        if (n==0 && x==0) break;
        for (int i=1; i<=n ; i++) {
            for (int j=i+1; j<=n ; j++){
                for (int k=j+1; k<=n ; k++) {
                    if( i+j+k == x) ans++;
                }
            }
        }
        
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
A, B, C, D = map(int, input().split())

def battle(player):
    global A
    global C

    if player == 1:
        C = C - B
    else:
        A = A - D

    return None

def main():
    while True:
       battle(1) 
       if C <= 0:
           print("Yes")
           break

       battle(2)
       if A <= 0:
           print("No")
           break

    return None

main()

Measured memory_bytes: 61744
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main()
{
	int A, B, K;
	cin >> A >> B >> K;

	int i, cnt = 0, ans = 1;
	for (i = min(A, B); i > 0; i--) {
		if ((A%i == 0) && (B%i == 0)) {
			cnt++;
//			printf("[%d] : %d / %d\n", i, A, B);
			if (cnt == K) {
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>

using namespace std;

using namespace std;

int main(void)
{
	int n, h;
	int a, b;
	int res = 2000000000;
	int wield = 0;
	vector <int> v;

	scanf("%d %d", &n, &h);

	for (int i = 0; i < n; i++)
	{
		scanf("%d %d", &a, &b);
		wield = max(wield, a);
		v.push_back(b);
	}

	sort(v.rbegin(), v.rend());

	for (int i = 0; i < v.size(); i++)
	{
		if (h <= 0)
		{
			break;
		}
		int count = (i + 1);
		a = v[i];
		h -= a;
		int c = ceil((h*1.0) / wield);
		if(h<=0)
		{
			c = 0;
		}
		count += c;
		res = min(res, count);
	}

	cout << res << '\n';
	return 0;

}

Measured memory_bytes: 892
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;
void solve(){
    int a,b; cin>>a>>b;
    if(b%a==0) cout<<a+b;
    else cout<<b-a;
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
  int m,f,r;
  int judge;
 
  scanf("%d%d%d",&m,&f,&r);
  while(m!=-1 || f!=-1 || r!=-1){
    judge=0;
     
    if(m==-1 || f==-1){
      printf("F\n");
    } else {
      judge=m+f;
      if(judge>=80)  printf("A\n");
      else if(65<=judge && judge<80)  printf("B\n");
      else if(50<=judge && judge<65)  printf("C\n");
      else if(30<=judge && judge<50){
        if(r>=50)  printf("C\n");
        else printf("D\n");
      }
      else printf("F\n");
    }
 
    scanf("%d%d%d",&m,&f,&r);
  }
 
  return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
map <int ,int> mpa,mpb;

int a[100];
int n;

void trace(int N){
  for(int i=0;i<N;i++){
    cout << a[i];
    if(i!=N-1){
      cout << " ";
    }
  }
  cout << endl;
}

void insertionSort(int N){
  for(int i=1;i<N;i++){
    int v=a[i];
    int j=i-1;
    while(j>=0 && a[j]>v){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
    trace(N);
  }
}

int main (){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  trace(n);
  insertionSort(n);
  return 0;
}


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

int main(void)
{
    int n;
    int a[1000][1000];

    int i, j;
    int b[1000];
    int b_temp[1000];
    int match;
    int days;

    cin >> n;

    for(i=0;i<n;i++){
        for(j=0;j<n-1;j++){
            cin >> a[i][j];
        }
    }

    for(i=0;i<n;i++){
        b[i] = 0;
        b_temp[i] = 0;
    }

    days = 0;
    while(1){
        match = 0;
        for(i=0;i<n;i++){
            if(b_temp[i] == 1 || b[i] == n-1){
                // cout << "continue" << endl;
                continue;
            }
            // cout << a[i][b[i]] << endl;
            // cout << b[a[i][b[i]]] << endl;
            // cout << a[ a[i][b[i]] - 1 ][ b[a[i][b[i]] - 1] ] << endl;
            if(a[ a[i][b[i]] - 1 ][ b[a[i][b[i]] - 1] ] == i+1 && b_temp[a[i][b[i]] - 1] == 0){
                // cout << "match" << endl;
                b_temp[ i ] = 1;
                b_temp[ a[i][b[i]] - 1] = 1;
                b[ a[i][b[i]] - 1]++;
                b[i]++;
                match++;
            }
        }

        if(match == 0){
            for(i=0;i<n;i++){
                if(b[i] != n-1){
                    break;
                }
            }
            if(i != n){
                days = -1;
            }
            break;
        }else{
            for(i=0;i<n;i++){
                b_temp[i] = 0;
            }
            days++;
        }
        // cout << "day: " << days << endl;
        // cout << "num_match: " << match << endl;
        // cout << "" << endl;
    }

    cout << days;

    return 0;

}

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

int main(void) {
    int a, b, c;
    int cnt = 0;
    cin >> a >> b >> c;

    for(int i = a; i <= b; i++) {
        if(c % i == 0) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

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

typedef long long ll;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define MP make_pair
#define INT(n) int n;assert(0<scanf("%d",&n))

int main(){
  INT(n); INT(m);
  int cnt = 0;
  ll ans = 0;
  priority_queue<pair<int, int>> pq;
  REP(n){
    INT(a); INT(b);
    pq.push(MP(-a, b));
  }
  while (cnt < m){
    pair<int, int> p = pq.top(); pq.pop();
    int a = -p.first, b = p.second;
    ans += (ll) a * min(b, m - cnt);
    cnt += b;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,agaa;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rrep(i,1,9){
        rrep(j,1,9){
            rrep(k,1,9){
                vector<ll> p(i+j+k);
                if(i+j+k>10)continue;
                cnt=0;
                rep(z,i)p[cnt++]=7;
                rep(z,j)p[cnt++]=5;
                rep(z,k)p[cnt++]=3;
                sort(all(p));
                do{
                    /*
                    int se=0,fi=0,th=0;
                    rep(z,cnt){
                        //cout<<p[z];
                        if(p[z]==7)se=1;
                        if(p[z]==5)fi=1;
                        if(p[z]==3)th=1;
                    }
                    //cout<<"\n";
                    if(!se||!fi||!th)continue;
                    */
                    pos=1;
                    rep(z,cnt-1)pos*=10;
                    rep(z,cnt){
                        ans+=pos*p[z];
                        pos/=10;
                    }
                    if(ans<=n)agaa++;
                    ans=0;
                }while(next_permutation(all(p)));
            }
        }
    }
    Cout(agaa);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,0,n-1) cin>>a[i];
    rep(i,0,n-1) a[i]--;
    vector<int> cnt(n);
    rep(i,0,n-1) cnt[a[i]]++;
    ll tot = 0;
    rep(i,0,n-1) tot += choose2(cnt[i]);
    rep(i,0,n-1){
        ll ans = tot;
        ans -= choose2(cnt[a[i]]);
        ans += choose2(cnt[a[i]] - 1);
        cout<<ans<<endl;
    }   
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (b % a == 0)
        cout << a + b << endl;
    else
    {
        cout << b - a << endl;
    }

    return 0;
}

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


int main()
{
    int M, K;
    cin >> M >> K;


    if( K >= pow(2, M) or (M == 1 and K == 1) ) cout << -1 << endl;
    else if( M == 1 and K == 0 ) cout << "0 0 1 1" << endl;
    else
    {
        // K 0 1 2 ..(K飛ばし).. 2^M-1 K 2^M-1 ..(K飛ばし).. 1 0 と出力すれば良い
        cout << K << " ";
        for( int i = 0; i <= pow(2, M)-1; ++i ){
            if( i != K ) cout << i << " ";
        }
        cout << K << " ";
        for( int i = pow(2,M)-1; i >= 0; --i ){
            if( i != K ) cout << i << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 1792
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split("");
	var dev_tmp = new Array();
	var i=1;
	var j=1;
	dev_tmp[0] = tmp[0];
  while(i<=tmp.length){
    dev_tmp[j] = tmp[i];
    if(dev_tmp[j-1] === dev_tmp[j]){
       if(tmp[i+1] === undefined){
          tmp[i+1] = "";
          dev_tmp[j] = tmp[i]+tmp[i+1];
          break;
       }
       dev_tmp[j] = tmp[i]+tmp[i+1];
       i = i+2;
    }else{       
      dev_tmp[j] = tmp[i];
      i++;
    }
    j++;
  }
  dev_tmp.pop();
  console.log(dev_tmp.length);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

int main()
{
    #define int long long int
   int a,b,k;
   cin>>a>>b>>k;

   int min_a=min(a,k);
   k-=min_a;
   int min_b=min(b,k);
   k-=min_b;
   cout<<a-min_a<<" "<<b-min_b<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<tuple>
using namespace std;


typedef pair<int, int> P;
typedef long long ll;

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}



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

	ll ans = 0;
	if(n % 2 == 1)	ans = 0;
	else {
		while(n > 0){

			ans += n/2 / 5;
			n /= 5;

		}
	}

	cout << ans  << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,s[1005],sum=0,flag=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s[i];
    sum+=s[i];
  }
  sort(s,s+n);
  if(sum%10!=0){
    cout<<sum<<'\n';
    flag=1;
  }
  else{
    for(int i=0;i<n;i++){
      if((sum-s[i])%10!=0){
	cout<<sum-s[i]<<'\n';
	flag=1;
	break;
      }
    }
  }
  if(flag==0)
    cout<<0<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

#define MAXV 1000000000
#define MOD 1000000007
using ll = long long;

bool operator<(const pair<int, int>& a, const pair<int, int>& b) {
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return a.first < b.first;
}

int main() {
	
	ll N, W; cin >> N >> W;

	vector<ll> v1, v2, v3, v4;

	ll w1, V1; 
	cin >> w1;
	cin >> V1;
	v1.push_back(V1);
	for (int i = 0; i < N-1; ++i) {
		ll w, v; cin >> w >> v;
		if (w == w1) {
			v1.push_back(v);
		}
		else if (w == w1 + 1) {
			v2.push_back(v);
		}
		else if (w == w1 + 2) {
			v3.push_back(v);
		}
		else if (w == w1 + 3) {
			v4.push_back(v);
		}
	}

	sort(v1.begin(), v1.end(), greater<ll>());
	sort(v2.begin(), v2.end(), greater<ll>());
	sort(v3.begin(), v3.end(), greater<ll>());
	sort(v4.begin(), v4.end(), greater<ll>());

	
	ll r1[110] = { 0 }, r2[110] = { 0 }, r3[110] = { 0 }, r4[110] = { 0 };
	for (int i = 0; i < v1.size(); ++i) {
		r1[i + 1] = r1[i] + v1[i];
	}
	for (int i = 0; i < v2.size(); ++i) {
		r2[i + 1] = r2[i] + v2[i];
	}
	for (int i = 0; i < v3.size(); ++i) {
		r3[i + 1] = r3[i] + v3[i];
	}
	for (int i = 0; i < v4.size(); ++i) {
		r4[i + 1] = r4[i] + v4[i];
	}

	ll ans = 0;
	for (int i = 0; i <= v1.size(); ++i) {
		ll t = r1[i];
		for (int j = 0; j <= v2.size(); ++j) {
			t += r2[j];
			for (int k = 0; k <= v3.size(); ++k) {
				t += r3[k];

				if (W - w1 * i - (w1 + 1)*j - (w1 + 2)*k < 0) continue;
				int ind = (W - w1 * i - (w1 + 1)*j - (w1 + 2)*k) / (w1 + 3);

				if (ind > v4.size()) {
					t += r4[v4.size()];
				}
				else {
					t += r4[ind];
				}
				ans = max(ans, t);
				t = r1[i] + r2[j];
				
			}
			t = r1[i];
		}
	}
	cout << ans << endl;
}

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

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

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

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int h, w, k; cin >> h >> w >> k;
  char c[h][w];

  rep(i, h) rep(j, w) cin >> c[i][j];

  int ans = 0;
  rep(i, 1<<h) rep(j, 1<<w) {
    int cnt = 0;

    rep(k, h) rep(l, w) {
      if (i & (1<<k) || j & (1<<l)) continue;
      if (c[k][l] == '#') ++cnt;
    }

    if (cnt == k) ++ans;
  }

  cout << ans << endl;
  
  return (0);
}

Measured memory_bytes: 3660
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int W = scan.nextInt();
        int[] w = new int[N];
        long[] v = new long[N];
        for (int i = 0; i < N; i++) {
            w[i] = scan.nextInt();
            v[i] = scan.nextInt();
        }
        long[] dp = new long[W+1];
        Arrays.fill(dp, Long.MIN_VALUE);
        dp[0] = 0;
        for (int i = 0; i < N; i++) {
            for (int j = W-w[i]; 0 <= j; j--) {
                if (dp[j] == Long.MIN_VALUE) {
                    continue;
                }
                dp[j + w[i]] = Math.max(dp[j + w[i]], dp[j] + v[i]);
            }
        }
        System.out.println(Arrays.stream(dp).max().getAsLong());
    }
}


Measured memory_bytes: 28500
a,b,k = map(int,input().split())
list_a = []
list_b = []
for i in range(1,a+1):
    if a%i == 0:
        list_a.append(i)
for i in range(1,b+1):
    if b%i == 0:
        list_b.append(i)
list_c = []
n = max(len(list_a),len(list_b))
if len(list_b) >= len(list_a):
    for i in range(n):
        if list_b[i] in list_a:
            list_c.append(list_b[i])
else:
    for i in range(n):
        if list_a[i] in list_b:
            list_c.append(list_a[i])
print(list_c[-k])

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

int main()
{
	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i]; --A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N - 1; i++) {
		cin >> C[i];
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		res += B[A[i]];
	}
	for (int i = 1; i < N; i++) {
		if (A[i - 1] == A[i] - 1) {
			res += C[A[i - 1]];
		}
	}
	cout << res << endl;
	return 0;
}


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

#define int long long

int32_t main(){
    int N;
    cin >> N;
    int happy[N][3];
    for(int row=0; row<N; row++)
        for(int col=0; col<3; col++)
            cin>>happy[row][col];
    int max_points[N][3];
    for(int activity=0; activity<3; activity++) max_points[0][activity] = happy[0][activity];
    for(int row=1; row<N; row++){
        for(int col=0; col<3; col++){
            int max_happy = -1;
            for(int prev_day=0; prev_day<3; prev_day++){
                if(col != prev_day){
                    max_happy = max(max_happy, happy[row][col]+max_points[row-1][prev_day]);
                }
            }
            max_points[row][col] = max_happy;
        }
    }
    int ans = max(max_points[N-1][0], max(max_points[N-1][1], max_points[N-1][2]));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define F first
#define S second
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define all(vec) vec.begin(), vec.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
const int N = 2e5 + 10;
const int INF = 1LL << 60;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int RANDOM_GEN = uniform_int_distribution<int>(0, 10000)(rng);
int t = 1;


void solve()
{
	int n;
	cin>>n;
	map<string, int> mp;
	int ans = 0;
	for(int i=0; i<n; i++){
		string s;
		cin>>s;
		if(mp[s] == 0) ans ++;
		mp[s]++;
	}
	cout << ans << '\n';
}


signed main()
{
    FAST
    int Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
		//cout<<"Case #"<<(t++)<<": ";  
        solve();
    }
    return 0;
}


Measured memory_bytes: 19200
N,K = map(int,input().split())

A = list(map(int,input().split()))

A.sort()

cnt = []

if N ==1:
    print(1)
    exit()

tmp = 1
for i in range(1,len(A)):
    if (A[i-1] == A[i]):
        tmp+=1
    else:
        cnt.append(tmp)
        tmp=1

    if (i == (len(A)-1)):
        cnt.append(tmp)
    
cnt.sort()

#print(cnt)

if N > K:
    print(sum(cnt[:(len(cnt)-K)]))
else:
    print(0)

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

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  //std::vector<int> v(5);
  std::vector<int> v(5);
  int cnt = 0;
  int mnum = 10;
  int mi = 10000;
  bool flag = false;
  rep(i,5) {
    cin >> v[i];
    if ((v[i]%10) <= mnum && (v[i]%10) != 0) {
      mnum = v[i]%10;
      mi = v[i];
      flag = true;
    }
  }
  bool mflag = false;
  rep(i,5) {
    int snum = v[i]/10;
    int anum = v[i]%10;
    if (mflag == true || v[i] != mi) {
      if (snum == 0) cnt += 10;
      else if (anum == 0) {
        cnt += snum*10;
      } else {
        cnt += (snum+1)*10;
      }
    } else {
      mflag = true;
    }
  }

  cout << ((flag) ? cnt + mi : cnt) << endl;
}


Measured memory_bytes: 384