akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<ll> b(n), c(n);
    for (int tt = 0; tt < 2; tt++) {
        stack<int> st;
        st.push(0);
        for (int i = 1; i < n; i++) {
            b[i] = b[i - 1];
            if (a[i - 1] >= a[i]) {
                ll tmp = a[i];
                while (a[i - 1] >= tmp * 4) {
                    st.push(i);
                    tmp *= 4;
                }
            } else {
                ll tmp = a[i - 1];
                while (tmp < a[i]) {
                    tmp *= 4;
                    b[i] += i - st.top();
                    if (st.top() != 0) {
                        st.pop();
                    }
                }
            }
        }
        swap(b, c);
        reverse(a.begin(), a.end());
    }
    reverse(c.begin(), c.end());
    for (int i = 0; i < n; i++) {
        b[i] *= 2;
        c[i] *= 2;
    }
    debug(b, c);
    ll ans = min(c[0], b[n - 1] + n);
    for (int i = 0; i < n - 1; i++) {
        ll tmp = b[i] + c[i + 1] + i + 1;
        ans = min(ans, tmp);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4992
import math
A, B, H, M = map(int, input().split())
tmp_h = 360*((H*60+M)/720)
tmp_m = 360*(M/60)
target = max(tmp_h,tmp_m)-min(tmp_h,tmp_m)
target = min(target,360-target)
ans = math.sqrt(A**2+B**2-2*A*B*(math.cos(math.radians(target))))
print(ans)

Measured memory_bytes: 9520
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <iomanip>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdlib>

using namespace std;

#define PB push_back
#define MP make_pair
#define L first
#define R second

typedef pair<int, int> pie;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    while (n > 0) {
        int x = n % 10;
        if (x == 9) {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
    return 0;
}

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

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

typedef long long int ll;

int SURP = 1000000007;

int ceil(int a,int b){
	return (a+b-1)/b;
}

int main(){
	int D,G;
	cin >> D >> G;
	int p[D];
	int c[D];
	REP(i,D) cin >> p[i] >> c[i];

	int score;
	int result = 10000;
	int max_unsolve;
	int solved;

	for(ll i = 0; i < (1 << D); i++ ){
		max_unsolve = -1;
		solved = 0;
		score = 0;
		for(int j=0; j < D;j++){
			if(i >> j & 1){
				score += (j+1)*100 * p[j] + c[j];
				solved += p[j];
			}else{
				max_unsolve= j+1;
			}
		}

		if (score >= G){
			if(result > solved) result = solved;
		}else{
			int p_p = ceil( G - score, max_unsolve * 100);
			if(p_p < p[max_unsolve-1]){
				solved += p_p;
				if(result > solved) result = solved;
			}
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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 (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#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 ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{

    int n;
    string s;
    cin >> n >> s;

    if (n%2 != 0) {
        cout << "No" << endl;
        return 0;
    }

    string s1 = s.substr(0, n/2);
    string s2 = s.substr(n/2);
    // cout << s1 << endl;
    // cout << s2 << endl;

    if (s1 == s2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n,k = [int(i) for i in input().split()]
ans = 0
if k != 0:
  for i in range(k+1,n+1):
    m = (n+1)//i
    ans += (i-k)*m
    if m*i+k <= n:
      ans += n+1
      ans -= m*i
      ans -= k
else:
  ans = n**2
print(ans)

Measured memory_bytes: 39152
#include <iostream>

int main() {
    int n;
    std::cin >> n;
    char prev_c;
    std::cin >> prev_c;
    int n_slime = 1;
    for (int i = 1; i < n; ++i) {
        char c;
        std::cin >> c;
        if (prev_c != c)
            ++n_slime;
        prev_c = c;
    }
    std::cout << n_slime << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    int b1 = abs(a2-a3);
    int b2 = abs(a1-a3);
    int b3 = abs(a2-a1);
    cout << b1 + b2 + b3 - max(b1, max(b2, b3)) << endl;
}


Measured memory_bytes: 256
//g++  7.4.0
     
    #include <iostream>
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
     
    int main()
    {
      	ios_base::sync_with_stdio(false);
      	cin.tie(NULL);
        
        ll N; cin>>N;
        ll ver = 0;
        ll edg = 0;
        if(N==1){
          cout<<"1";
          return 0;
        }
        ll vis[N + 5];
        memset(vis,0,sizeof(vis));
        
        for(ll i=0;i<(N - 1);++i)
        {
            ll u,v; cin>>u>>v;
            
            if(u > v)
                swap(u,v);
            
            edg += (u * (N - v + 1LL));
            
            if(!vis[u])
                ver += (u * (N - u + 1LL));
            
            if(!vis[v])
                ver += (v * (N - v + 1LL));
            
            vis[u] = 1;
            vis[v] = 1;
        }
        
        cout<<(ver - edg)<<endl;
    }


Measured memory_bytes: 5140
#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++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
typedef priority_queue<p> pq;
typedef priority_queue<p, vector<p>, greater<p>> gpq;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    FOR(i, 1, 10)
    {
        FOR(j, 1, 10)
        {
            if(n == i * j)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n)for(int i=0; i<n; i++)
using namespace std;

int main(){
    int n, ans=0;
    cin >> n;
    for(int i=1; i<=n; i++){
        int digit = 0;
        int x = i;
        while(x){
            digit++;
            x /= 10;
        }
        if(digit%2 != 0)ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3604
x, y, a, b, c = map(int, input().split())

p = sorted(list(map(int, input().split())), reverse = True)
q = sorted(list(map(int, input().split())), reverse = True)
r = sorted(list(map(int, input().split())))

ct1 = x - 1
ct2 = y - 1
ct3 = c - 1
ans = 0

while ct3 >= 0:
    if ct1 >= 0 and ct2 >= 0:
        if p[ct1] > r[ct3] and q[ct2] > r[ct3]:
            break
        elif p[ct1] < q[ct2]:
            p[ct1] = r[ct3]
            ct1 -= 1
            ct3 -= 1
        else:
            q[ct2] = r[ct3]
            ct2 -= 1
            ct3 -= 1
    elif ct1 >= 0:
        if p[ct1] > r[ct3]:
            break
        else:
            p[ct1] = r[ct3]
            ct1 -= 1
            ct3 -= 1
    elif ct2 >= 0:
        if q[ct2] > r[ct3]:
            break
        else:
            q[ct2] = r[ct3]
            ct2 -= 1
            ct3 -= 1
    else:
      break
for i in range(x):
    ans += p[i]
for i in range(y):
    ans += q[i]
print(ans)

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

int main(){
    int N, tmp;
    cin >> N;
    
    vector<int> a(N);
    for(int i=0; i<N; i++){
	cin >> tmp;
	tmp--;
	a[tmp] = i+1;
    }

    for(int i=0; i<N; i++){
	cout << a[i] << endl;
    }
}



Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		
		if(k%2==0)
		{
			long c = k;
			long pil = n/c;
			long an = pil * pil * pil;
			
			
			long off = n + (k/2);
			long pil2 = off/c;
			an += pil2 * pil2 * pil2;
			
			System.out.println(an);
		}
		else
		{
			long c = k;
			long pil = n/c;
			
			System.out.println(pil*pil*pil);
			
		}
		

	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int k,n;
  cin>>k>>n;
  vint kyo(n);
  vint a(n);
  rep(i,n){
    cin>>a[i];
  }
  ll sum=0;
  kyo[0]=a[0]+k-a[n-1];
  sum+=a[0]+k-a[n-1];
  REP(i,1,n){
    kyo[i]=(a[i]-a[i-1]);
    sum+=(a[i]-a[i-1]);
  }
  int max=0;
  rep(i,n){
    chmax(max,kyo[i]);
  }
  cout<<sum-max<<'\n';
  return(0);
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;


int main()
{

	long double a, b,c;
	cin >> a >> b >> c;
	c = c / 180.0 * 3.141592653589793;
	//求めるものは面積、周の長さ、高さ；
	double h,S,L;
	cout <<fixed<< a*b*sin(c)*0.5 << endl << a + b + abs(sqrt((a - b*cos(c))*(a - b*cos(c)) + (b*sin(c))*b*sin(c))) << endl << b*sin(c) << endl;
	//printf("%lf\n%lf\n%lf\n", a*b*sin(c)/2, a + b + abs(sqrt((a - b*cos(c))*(a - b*cos(c)) + (b*sin(c))*b*sin(c))), b*sin(c));
	return 0;
}

Measured memory_bytes: 1296
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define krep(n) for(ll k=0;k<(n);k++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } 


void solve(ll ts){
    //ll n; cin>>n; vector<ll>arr(n,0); rep(n) cin>>arr[i];
    ll a; cin>>a; cout<<1-a<<endl;
}

//
int main(){
    ffast
    ll t=1;
//    cin>>t;
    rep(t) solve(i+1);
}
 
 
// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvl std::vector<std::vector<ll> >
typedef long long int ll;
#include <stdio.h>
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, M, Q, l, r, p, q;
  std::cin >> N >> M >> Q;
  vvl dp = vv(N, N, 0, ll);
  vvl zahyo = vv(N, N, 0, ll);
  for(int i=0;i<M;i++) scanf("%lld %lld", &l, &r), zahyo[l-1][r-1]++;
  for(int i=0;i<N;i++)for(int j=0;j<N;j++) dp[i][j] = (j==0?0:dp[i][j-1]) + zahyo[i][j];
  for(int i=N-1;i>=0;i--) for(int j=0;j<N;j++) dp[i][j] += (i==N-1?0:dp[i+1][j]);
  for(int i=0;i<Q;i++) scanf("%lld %lld", &p, &q ), printf("%lld\n", dp[p-1][q-1]);
  return 0;
}


Measured memory_bytes: 4864
#include <stdio.h>
#define N 1000000

int prime(int num)
{
  int i;

  if(num==1||num==0)return 0;
  if(num==2)return 1;
  if(num!=2&&num%2==0)return 0;

  for(i=3;i*i<=num;i+=2){
    if(num % i == 0)return 0;
  }
  return 1;
}

int main(void){
  int n;
  int i,j,cnt;
  int num[N];
  num[0]=0;
  for(i=1;i<N;i++){
    num[i]=num[i-1];
    if(prime(i))num[i]++;
  }
  while(scanf("%d",&n) != EOF){
    printf("%d\n",num[n]);
  }

  return 0;
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,cnt=0,temp;
    cin>>n;
    ll a[n+1],b[n];
    for(ll i=0;i<n+1;i++)
        cin>>a[i];
    for(ll i=0;i<n;i++)
        cin>>b[i];
        
    if(b[0]>a[0])
    {
        b[0]-=a[0];
        cnt+=a[0];
    }
    else
    {
        cnt+=b[0];
        b[0]=0;
        
    }
    for(ll i=1;i<n;i++)
    {
        temp = b[i]+b[i-1];
        if(temp>a[i])
        {
            if(b[i-1]<a[i])
                b[i] = b[i] - (a[i]-b[i-1]);
            cnt+=a[i];
        }
        else
        {
            cnt+=temp;
            b[i]=0;
            
        }
    }
    if(b[n-1]>a[n])
    {
        cnt+=a[n];
    }
    else
    {
        cnt+=b[n-1];
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;



int main() {
  int K, X; cin >> K >> X;
  if(K*500 >= X) cout << "Yes" << endl;
  else cout << "No" << endl;

	return 0;
}



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

const int MAX = 1e5 + 5;

#define dbg(a) cout << "-> " << __LINE__ << ": " << #a << " = " << a << endl

int main() {
    string s;
	cin >> s;
	if (s == "SUN") {
		cout << 7 << endl;
	}
	else if (s == "MON") {
		cout << 6 << endl;
	}
	else if (s == "TUE") {
		cout << 5 << endl;
	}
	else if (s == "WED") {
		cout << 4 << endl;
	}
	else if (s == "THU") {
		cout << 3 << endl;
	}
	else if (s == "FRI") {
		cout << 2 << endl;
	}
	else if (s == "SAT") {
		cout << 1 << endl;
	}
    return 0;
}


Measured memory_bytes: 256
N,M,dp[5001],x,i,j,a;
main(){scanf("%d%d",&N,&M);dp[0]=1;for(;i<N-1;i++){x=i+1>N-i?N-i:i+1;for(j=x;j<=N;j++)dp[j]=(dp[j]+dp[j-x])%M;}for(;i+1;i--)a=(a+(N-i)*(long long)dp[i])%M;printf("%d\n",a);}

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

#define GET_BIT(n, i) (((n) & (1 << ((i)-1))) >> ((i)-1)) // i start from 1
#define SET_BIT(n, i) ((n) | (1 << ((i)-1)))
#define CLR_BIT(n, i) ((n) & ~(1 << ((i)-1)))
#define SHOW_A(x) {cout << #x << " = " << x << endl;}
#define SHOW_B(x, y) {cout << #x << " = " << x << ", " << #y << " = " << y << endl;}
#define SHOW_C(x, y, z) {cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;}
#define REACH_HERE {cout << "REACH_HERE! line: " << __LINE__ << endl;}

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

const int MAX_N = 100005, MAX_M = 10005;
const int MOD_BASE = 1000000007;

int baba[MAX_N];

int power_modulo(int n, int p, int M) {
    int result = 1;
    while (p > 0) {
        if (p % 2 == 1)
            result = ((long long)result*n) % M;
        p /= 2;
        n = ((long long)n*n) % M;
    }
    return result;
}

int find_baba(int i) {
    if (baba[i] != i) {
        int new_baba = find_baba(baba[i]);
        baba[i] = new_baba;
        return new_baba;
    }
    return i;
}

void solve(int n, int m) {
    for (int i = 1; i <= n; i++) {
        baba[i] = i;
    }
    bool unstable = false;
    int total = 0;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        baba[find_baba(b)] = find_baba(a);
        unstable = true;
    }
    int group = 0;
    for (int i = 1; i <= n; i++) {
        if (find_baba(i) == i) {
            group ++;
        }
    }
    int ans = unstable ? 1 : 0;
    ans += power_modulo(2, group, MOD_BASE);
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);

    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        solve(n, m);
    }

    return 0;
}

Measured memory_bytes: 1584
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

//-----end of template-----//

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int s;
	cin >> s;
	vector<bool> used(1000000, false);
	int cnt = 1;
	while(true){
		if(used[s]){
			cout << cnt << endl;
			break;
		}else{
			used[s] = true;
			if(s % 2 == 0) s /= 2;
			else s = 3 * s +  1;
			cnt++;
		}
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef tuple<ll,ll,ll> tup;

ll add(tup t, ll n0, ll n1, ll n2){
    return n0*get<0>(t) + n1*get<1>(t) + n2*get<2>(t);
}

int main(){
    int N, M;  cin >> N >> M;
    vector<tup> cake(N);
    for(int i=0; i<N; i++){
        ll x, y, z;
        cin >> x >> y >> z;
        cake[i] = make_tuple(x,y,z);
    }

    ll ans = 0;
    for(int i=0; i<8; i++){
        ll n0 = pow(-1,i%2),  n1 = pow(-1,(i/2)%2), n2 = pow(-1,(i/4)%2);
        sort(cake.begin(), cake.end(), [n0,n1,n2](const tup& a, const tup& b){
            return add(a,n0,n1,n2) > add(b,n0,n1,n2);
        });

        ll tmp = 0;
        for(int i=0; i<M; i++){
            tmp += add(cake[i],n0,n1,n2);
        }
        ans = max(ans,tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll n,a[110000],b[110000],c[110000],k,m,l;
  cin >> n;
  k=0;
  l=0;
  m=0;
  rep(i,n)cin >> a[i];
  rep(i,n)cin >> b[i];
  rep(i,n)c[i]=a[i]-b[i];
  sort(c,c+n);
  rep(i,n)if(c[i]>=0){k=i;
                     break;
                    }
  rep(i,k)if(c[i]<0)m+=c[i];
  per(i,n){m+=c[i];
           if(m>=0){l=n-i;
                   break;
                   }
          }
  if(k==0)printf("0");
  else if(m>0)printf("%lld",k+l);
  else printf("-1");
}

Measured memory_bytes: 2816
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int n,m,x,y;
int a[10005],b[10005];
int vis[1005];
int main(){
	cin>>n>>m>>x>>y;
	int minn=11111111,maxx=-1111111;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int j=1;j<=m;j++)scanf("%d",&b[j]);
	for(int i=1;i<=n;i++)maxx=max(a[i],maxx);
	for(int i=1;i<=m;i++)minn=min(b[i],minn);
	int ans=1;maxx++;
	//cout<<minn<<" "<<maxx<<" "<<x<<" "<<y<<endl;
	if(minn<maxx){
		printf("War\n");
		return 0;
	}
	minn+=100;maxx+=100;
	x+=100;y+=100; 
    for(int i=maxx;i<=minn;i++){
    	vis[i]=1;
	}
	for(int i=x+1;i<=y;i++){
		if(vis[i]==1){
			printf("No War\n");
			return 0;
		}
	}
	printf("War\n");
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    return 0;
}


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

struct point {
  unsigned time;
  int x;
  int y;
};

int main() {
  unsigned destinationCount;
  scanf("%u", &destinationCount);
  struct point source = { 0, 0, 0 };
  struct point destination;
  while (destinationCount--) {
    scanf("%u%d%d", &destination.time, &destination.x, &destination.y);
    int remainingTime = (destination.time - source.time) - (abs(destination.x - source.x) + abs(destination.y - source.y));
    if (remainingTime < 0 || remainingTime & 1) {
      puts("No");
      goto end;
    }
    source = destination;
  }
  puts("Yes");
  end:
  return 0;
}


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

int main(void)
{
    int n = 0;
    cin >> n;
    vector<double> x(n), y(n);
    int pat_num = 1;
    rep(i, n)
    {
        cin >> x.at(i) >> y.at(i);
        pat_num *= (i + 1);
    }
    double sum = 0.0;

    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            double sub = (x.at(i) - x.at(j)) * (x.at(i) - x.at(j));
            sub += (y.at(i) - y.at(j)) * (y.at(i) - y.at(j));
            sum += sqrt(sub);
        }
    }
    cout << std::setprecision(16) << sum * 2.0 / n << endl;
    return 0;
}



Measured memory_bytes: 764
import  heapq

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

heapq.heapify(A)
B_C_list = []
for i in range(M):
    B, C = map(int, input().split())
    B_C_list.append((B, C))

B_C_list.sort(reverse=True, key=lambda x: x[1])
# print(B_C_list)

for B_C in B_C_list:
    a = heapq.heappop(A)
    if a >= B_C[1]:
        heapq.heappush(A, a)
        break
    else:
        heapq.heappush(A, a)
        for j in range(B_C[0]):
            a = heapq.heappop(A)
            if a >= B_C[1]:
                heapq.heappush(A, a)
                break
            heapq.heappush(A, B_C[1])
print(sum(A))

Measured memory_bytes: 92340
using System;

namespace abc152_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            string a = input[0];
            string b = input[1];

            string ansa = "";
            string ansb = "";
            for(int i=0; i<Convert.ToInt32(b); i++)
            {
                ansa += a; 
            }

            for (int j = 0; j < Convert.ToInt32(a); j++)
            {
                ansb += b;
            }

            if(Convert.ToInt32(ansa) > Convert.ToInt32(ansb))
            {
                Console.Write(ansa);
            }
            else
            {
                Console.Write(ansb);
            }
            Console.Read();
        }
    }
}


Measured memory_bytes: 11220
let modulo = 1000000007
let (+@) a b = (a + b) mod modulo
let ( *@ ) a b = (a * b) mod modulo

let rec mod_pow a n =
  if n <= 0 then 1
  else if n mod 2 = 1 then a *@ mod_pow a (n-1)
  else let h = mod_pow a (n/2) in h *@ h
let mod_inv a = mod_pow a (modulo-2)

let lim = 200010

let fact =
  let res = Array.make lim 1 in
  for i = 1 to lim-1 do res.(i) <- i *@ res.(i-1) done;
  res

let inv_fact = Array.map mod_inv fact

let comb n k =
  if n < k then 0 else fact.(n) *@ inv_fact.(k) *@ inv_fact.(n-k)

let r h w = comb (h+w) h

let () =
  Scanf.scanf "%d %d %d %d" @@ fun h w a b ->
  Array.init (h-a) (fun i -> r i (b-1) *@ r (h-1-i) (w-b-1))
  |> Array.fold_left (+@) 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

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

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

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

    int A, B, T; cin >> A >> B >> T;
    int count = T / A; count = count * B;
    cout << count << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        flag = True
        for y in range(M):
            for x in range(M):
                if A[j+y][i+x] != B[y][x]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	printf("%lld",a+b+c+max(a,max(b,c))*9);
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def calcCost(P,X):
    sum = 0
    for x in X:
        sum+=(x-P)**2
    return sum

def solve(N: int, X: "List[int]"):
    minCost = 10**16
    m = -1
    for i in range(1,101):
        cost = calcCost(i,X)
        if cost < minCost:
            m = i
            minCost = cost
    print(str(minCost))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,k;
    cin >> n >> k;
    vector<int> sunu(n,0);
    int d;
    int a;
    for(int i = 0; i < k; i++) {
        cin >> d;
        for(int j = 0; j < d; j++) {
            cin >> a;
            sunu.at(a-1) = 1;
        }
    }
    int sum = 0;
    for(int i = 0; i < n; i++) {
        if(sunu.at(i) == 0) {
            sum++;
        }
    }
    cout << sum;
}


Measured memory_bytes: 3636
n, q = gets.split(" ").map(&:to_i)
s = gets.chomp.to_s

ary = []
q.times do
  ary << gets.split(" ").map(&:to_i)
end

ary_num = Array.new(n, 0)
cnt = 0

(n-1).times do |i|
  if s[i..i+1] == "AC"
    cnt += 1
  end
  ary_num[i+1] = cnt
end

ary.each do |x|
  puts ary_num[x[1]-1] - ary_num[x[0]-1]
end

Measured memory_bytes: 11132
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
int main(void){
    
    int N;
    scanf("%d",&N);
    long long A[N+1];
    A[0]=0;
    for(int i=1;i<=N;i++){scanf("%lld",&A[i]);A[i]+=A[i-1];}
    long long ans=1145141919810364;
    int B=1;
    int D=3;
    for(int C=2;C<=N-2;C++){
        while(1){
            if(abs((A[C]-A[B])-A[B]) > abs(A[C]-A[B+1]-A[B+1]) ) B++;
            else break;
        }
        while(1){
            if( abs( (A[N]-A[D])-(A[D]-A[C]) ) > abs( (A[N]-A[D+1])-(A[D+1]-A[C]) ) )D++;
            else break;
        }
        long long int P,Q,R,S;
        P=A[B];
        Q=A[C]-A[B];
        R=A[D]-A[C];
        S=A[N]-A[D];
        long long MAX,MIN;
        MAX=max({P,Q,R,S});
        MIN=min({P,Q,R,S});
        ans=min(ans,MAX-MIN);
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1792
W, H, count = map(int, input().split(" "))
W0 = 0
H0 = 0

li = [list(map(int, input().split(" "))) for s in range(count)]

for i in li:
  if i[2] == 1:
    if i[0] > W0:
      W0 = i[0]
  elif i[2] == 2:
    if i[0] < W:
      W = i[0]
  elif i[2] == 3:
    if i[1] > H0:
      H0 = i[1]
  elif i[2] == 4:
    if i[1] < H:
      H = i[1]
      
if W - W0 <= 0 or H - H0 <= 0:
  print(0)
else:
  print((W - W0) * (H - H0))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N; 
vector<int> X, Y;

double g(double x, double y){
  double ret = 0;
  REP(i, N){
    chmax(ret, hypot(X[i]-x, Y[i]-y));
  }
  return ret;
}
double f(double x){
  double y1 = 0;
  double y2 = 1000;
  REP(i, 100){
    double m1 = (y1*2+y2*1)/3;
    double m2 = (y1*1+y2*2)/3;
    if(g(x, m1) > g(x, m2)) y1 = m1;
    else y2 = m2;
  }
  return g(x, y1);
}
signed main() {
  cin >> N;

  X.resize(N); Y.resize(N);
  REP(i, N) cin >> X[i] >> Y[i];

  double x1 = 0;
  double x2 = 1000;
  REP(i, 100){
    double m1 = (x1*2+x2*1)/3;
    double m2 = (x1*1+x2*2)/3;
    if(f(m1) > f(m2)) x1 = m1;
    else x2 = m2;
  }

  cout << f(x1) << "\n";

  return 0;
}

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

const string S = "ACGT";

const int mod = 1e9 + 7;

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> dp(N + 1, vector<int>(1 << 6));
    for(int i = 0;i < (1 << 6);i++){
        string t;
        for(int j = 0;j < 3;j++){
            int v = (i >> (j * 2)) & 3;
            t += S[v];
        }
        dp[3][i] = t != "AGC" && t != "GAC" && t != "ACG";
    }
    for(int i = 3;i < N;i++){
        for(int j = 0;j < (1 << 6);j++){
            string t;
            for(int k = 0;k < 3;k++){
                int v = (j >> (k * 2)) & 3;
                t += S[v];
            }
            for(int c = 0;c < 4;c++){
                if(S[c] == 'C'){
                    if(t[1] == 'A' && t[2] == 'G') continue;
                    if(t[1] == 'G' && t[2] == 'A') continue;
                    if(t[0] == 'A' && t[2] == 'G') continue;
                    if(t[0] == 'A' && t[1] == 'G') continue;
                }
                else if(S[c] == 'G'){
                    if(t[1] == 'A' && t[2] == 'C') continue;
                }
                int x = (j >> 2) | (c << 4);
                dp[i + 1][x] += dp[i][j];
                if(dp[i + 1][x] >= mod) dp[i + 1][x] -= mod;
            }
        }
    }
    int res = 0;
    for(int i = 0;i < (1 << 6);i++){
        res += dp[N][i];
        if(res >= mod) res -= mod;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
 ll n,s;
 cin>>n>>s;
 if(s==n){cout<<n+1<<endl;return 0;}
 ll border=sqrt(n);
 for(int i=2;i<=sqrt(n)+100000;i++){
     ll res=0,rec=n;
     while(rec!=0){
          res+=rec%i;
          rec/=i;
     }
     if(res==s){cout<<i<<endl;return 0;}
 }
 vector<ll> tmp;
 for(ll i=2;i<=sqrt(n-s)+10000;i++){
     if((n-s)%(i-1)!=0)continue;
    tmp.push_back(i);
    tmp.push_back((n-s)/(i-1)+1);
     
 }
 sort(all(tmp));
 for(int i=0;i<tmp.size();i++){
     ll res=0,tm=tmp[i],rec=n;
    // cout<<tm<<endl;
     while(rec!=0){
          res+=rec%tm;
          rec/=tm;
     }
     if(res==s){cout<<tm<<endl;return 0;}
 }
 cout<<-1<<endl;
}




Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll h, w, a[310][310], d;
	P c[90010];
	cin >> h >> w >> d;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a[i][j];
			c[a[i][j]].first = i;
			c[a[i][j]].second = j;
		}
	}
	ll cos[90010];
	for (int i = 1; i <= d; i++) {
		cos[i] = 0;
		for (int j = i + d; j <= h * w; j += d) {
			cos[j] = cos[j - d] + abs(c[j - d].first - c[j].first) + abs(c[j - d].second - c[j].second);
		}
	}
	ll q, A, B;
	vector<ll> ans;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> A >> B;
		ans.push_back(cos[B] - cos[A]);
	}
	for (int i = 0; i < ans.size(); i++)cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 4852
def readinput():
    n = int(input())
    s = list(map(int,input().split()))
    q = int(input())
    t = list(map(int,input().split()))
    return n,s,q,t

def main(n,s,q,t):
    c = 0
    for j in t:
        for i in s:
            if(i == j):
                c += 1
                break

    return c

def main2(n,s,q,t):
    c=0
    for tj in t:
        s.append(tj)
        i=0
        while(s[i]!=tj):
            i+=1
        if(i<n):
            c+=1
        s.pop()
    return c

def main3(n,s,q,t):
    sets = set(s)
    sett = set(t)
    return (len((sets & sett)))

if __name__=='__main__':
    n,s,q,t = readinput()
    ans = main3(n,s,q,t)
    print(ans)



Measured memory_bytes: 6552
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=105;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll inv(ll a,ll p){return qpow(a,p-2);}
int main()
{
    std::ios::sync_with_stdio(false);
    int h,w;
    while(cin>>h>>w)
    {
        char a[N][N];
        for(int i=1;i<=h;i++)
        {
            cin>>a[i];
            cout<<a[i]<<endl<<a[i]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<pi> vpi;

#define debugone(x) cerr << #x << " " << x << endl;
#define debugtwo(x) cerr << #x << "-------------" << endl;for(auto &it: x) cerr << it << " ";cerr << endl;
#define debugthree(x, i, j) cerr << #x << "------------" << endl;cerr << "from " << i << " to " << j << endl;for(int k=i; k<=j; k++) cerr << x[k] << " ";cout << endl;


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

	ll n;
	cin >> n;
	ll numberOfPeople[5];
	for(int i = 0; i < 5; i++){
		cin >> numberOfPeople[i];
	}

	int minId = 0;
	ll mini = numberOfPeople[0];

	for(int i = 1; i < 5; i++){
		if(numberOfPeople[i] < mini){
			mini = numberOfPeople[i];
			minId = i;
		}
	}	

	ll ans = 5;
	if(n > mini){
		ll remain = n - mini;
		ans += (n - mini) / mini;
		if((n - mini) % mini != 0){
			ans++;
		}
	}

	cout << ans << endl;
}		

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

int main()
{
    int h, w, n;
    cin >> h;
    cin >> w;
    cin >> n;
    int i = 0;
    int count = 0;

    if (h < w)
    {
        count += w;
        i++;
        while (count < n)
        {
            count += w;
            i++;
        }
    }
    else
    {
        count += h;
        i++;
        while (count < n)
        {
            count += h;
            i++;
        }
    }
    cout << i;
    return 0;
}



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

using namespace std;

int main(){
    long long int a,b,x;
    cin >> a >> b >> x;
    if(a==0 && x!=1){
        cout << 1+b/x-(a-1)/x << endl;
    }else{
        cout << b/x-(a-1)/x << endl;
    }
}

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

int main(void){
    int N,M,X,i,j,cost=2147483647,count=0;
    scanf("%d%d%d",&N,&M,&X);
    int C[N],A[N][M],use[N],point[M];
    for(i=0;i<N;i++){
        use[i]=0;
        scanf("%d",&C[i]);
        for(j=0;j<M;j++){
            scanf("%d",&A[i][j]);
        }
    }
    use[N-1]=1;
    while(count<pow(2,N)){
        int counter=0,costcount=0;
        for(j=0;j<M;j++){
            int point=0;
            for(i=0;i<N;i++){
                point+=A[i][j]*use[i];
            }
            if(point>=X){
                counter++;
            }
        }
        if(counter==M){
            for(i=0;i<N;i++){
                costcount+=C[i]*use[i];
            }
            if(costcount<cost) cost=costcount;
        }
        int k=N-1;
        do{
            use[k]=1-use[k];
            k--;
        }while(use[k+1]==0);
        count++;
    }
    if(cost==2147483647){
        printf("-1\n");
    }else{
        printf("%d\n",cost);
    }    
    return 0;
}

Measured memory_bytes: 2600
/*input
4
141421356 17320508 22360679 244949
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _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 trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 
 
 
ll n,i,j,k,m,c;


unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 



void solve()
{
   cin>>n;

   int a[n];
   int sum=0;

   for(i=0;i<n;i++)
   {
    cin>>a[i];
    sum+= a[i];

   }
int ans=0;
   for(i=0;i<n;i++)
   {

    ans += (((sum-a[i])%modM)*a[i])%modM;

    ans%=modM;


   }
   int ale=modInverse(2,modM);

   cout<<(ans*ale)%modM;




    }

 
 
 
signed main()
{// inputFile;


    fast;
    int T = 1;
    // cin >> T;
    ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 5220
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int a[50][50], b[50][50], c[50][50];
int main() {
	int H, W;
	scanf("%d%d", &H, &W);
	rep(i, H) rep(j, W) scanf("%d", &a[i][j]);
	rep(i, H) rep(j, W) scanf("%d", &b[i][j]);
	int h, w;
	scanf("%d%d", &h, &w);
 	rep(i, h) rep(j, w) scanf("%d", &c[i][j]);
	int ans = -INF;
	rer(y, 0, H-h) rer(x, 0, W-w) {
		bool ok = true;
		int score = 0;
		rep(i, h) rep(j, w) {
			if(!(ok &= b[y+i][x+j] == c[i][j])) break;
			score += a[y+i][x+j];
		}
		if(ok) amax(ans, score);
	}
	if(ans == -INF) puts("NA");
	else printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1212
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main()
{
	int k, total=0;;
	cin >> k;
	for(int i=1; i<=k; i++)
	{
		for(int j=1; j<=k; j++)
		{
			for(int n=1; n<=k; n++)
			{
				total += __gcd(__gcd(i, j), n);
			}
		}
	}
	cout << total;
}



Measured memory_bytes: 3584
def main():
    from itertools import accumulate
    N, M, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    sA = list(accumulate([0] + A))
    sB = list(accumulate([0] + B))

    def is_ok(t, j):
        if t + sB[j] <= K:
            return True
        else:
            return False

    def binary_search_meguru(t):
        ng = M + 1
        ok = 0
        while abs(ok - ng) > 1:
            mid = ng + (ok - ng) // 2
            if is_ok(t, mid):
                ok = mid
            else:
                ng = mid
        return ok

    ans = 0
    for i in range(N+1):
        # A をi冊読むと決める
        if K < sA[i]:
            break
        v = i + binary_search_meguru(sA[i])
        ans = max(ans, v)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 129644
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=100111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

/*
vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}
*/
ll kaizyou(ll x){
	ll ans=0;
	rep(i,1,x+1)ans+=i;
	if(x==0)ans=1;
	return ans;
}

int main() {
	int n;
	cin>>n;
	string s[M];
	rep(i,0,n)cin>>s[i],sort(ALL(s[i]));
	sort(s,s+n);
	ll ans=0;
	rep(i,0,n-1){
		ll step=0;
		rep(j,i+1,n){
			if(s[i]==s[j])step++;
			else break;
		}
		i+=step;
		if(step)ans+=kaizyou(step);
	}
	print(ans);
}

Measured memory_bytes: 7296
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main()
{
	cin >> N >> A >> B;
	rep(i, 1001){
		if(A <= N*i&& N*i <= B){
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
}


Measured memory_bytes: 3616