akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using vec_int = vector<int>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using ll = long long;
using vec_ll = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int charToInt(char c)
{
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

int set_num_of_1(vec_int &num_of_1, ll A)
{
    bitset<20> s(A);
    rep(i, 20)
    {
        if (s[i]== 1)
        {
            num_of_1.at(i)++;
        }
    }
    return 0;
}
bool check_num_of_1(vec_int &num_of_1, ll A)
{
    bitset<20> s(A);
    rep(i, 20)
    {
        if (s[i] == 1)
        {
            if (num_of_1.at(i) == 1)
            {
                return false;
            }
        }
    }
    return true;
}

int remove_num_of_1(vec_int &num_of_1, ll A)
{
    bitset<20> s(A);
    rep(i, 20)
    {
        if (s[i] == 1)
        {
            num_of_1.at(i)--;
        }
    }
    return 0;
}

int main()
{
    //この問題でやるべきなのは、2進法で書いたときに、各桁で1の数が1以下であることが成立の条件である。
    //したがって、r, lの区間で各桁の1の数が2つ以上にならないlの範囲をとってくればおｋ

    int N;
    cin >> N;
    vec_ll A(N);
    rep(i, N)
    {
        cin >> A[i];
    }

    vec_int num_of_1(20, 0);
    ll tot_num = 0;
    int r=0;
    for (int l = 0; l < N; l++)
    {
        if (r == l)
        {
            set_num_of_1(num_of_1, A[r]);
            r++;
        }

        if (r < N)
        {
            while (check_num_of_1(num_of_1, A.at(r)))
            {
                set_num_of_1(num_of_1, A.at(r));
                    r++;
                if (r == N)
                    break;
            }
        }
        //この時、l,...,r-1までok
        tot_num += r-l;
        remove_num_of_1(num_of_1, A[l]);

    }
    cout<<tot_num<<endl;

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << H*W - w*H - h*W + w*h << endl;
    return 0;
}

Measured memory_bytes: 256
import math


a, b, c = map(float, input().split())

if c == 90:
    h = b
    S = a * h / 2
    L = a + b + math.sqrt(a**2 + b**2)

elif c > 90:
    h = b * math.sin(math.radians(180-c))
    S = a * h / 2
    L = a + b + math.sqrt(h**2 + (a + b * math.cos(math.radians(180 - c)))**2)

elif c < 90:
    h = b * math.sin(math.radians(c))
    S = a * h / 2
    L = a + b + math.sqrt(h**2 + (a - b * math.cos(math.radians(c)))**2)

print(S)
print(L)
print(h)




Measured memory_bytes: 5672
def solve(s):
    stack = [s]
    while stack:
        word = stack.pop()
        if len(word) == 0:
            return True
        for prefix in ('dreamer', 'dream', 'eraser', 'erase'):
            if word.startswith(prefix):
                stack.append(word[len(prefix):])

print('YES' if solve(input()) else 'NO')

Measured memory_bytes: 110516
use std::io;
use std::str::FromStr;

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let x_vec = input_vec();
    for i in 0..5 {
        if x_vec[i] == 0 {
            println!("{}", i + 1);
            return;
        }
    }
}


Measured memory_bytes: 2072
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;

#define ll long long

struct Data
{
    ll num;
    ll index;
    ll groupindex = 0;
};

bool cmpindex(const Data &a, const Data &b)
{
    return a.index < b.index;
}

bool cmpnum(const Data &a, const Data &b)
{
    return a.num < b.num;
}

ll nc2(ll n)
{
    if (n == 0)
    {
        return 0;
    }
    else if (n == 1)
    {
        return 0;
    }
    else
    {
        return (n * (n - 1)) / 2;
    }
}

void solve()
{
    ll N;
    cin >> N;
    vector<Data> A(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> A.at(i).num;
        A.at(i).index = i;
    }

    sort(A.begin(), A.end(), cmpnum);

    ll prevCount = 0;
    ll groupindex = 0;
    vector<ll> G;
    G.push_back(1);
    groupindex++;
    ll count = 0;
    for (ll i = 1; i < N; i++)
    {
        if (A.at(i - 1).num == A.at(i).num)
        {
            A.at(i - 1).groupindex = groupindex;
            A.at(i).groupindex = groupindex;
            prevCount++;
        }
        else if (prevCount != 0)
        {
            count += nc2(prevCount + 1);
            G.push_back(prevCount + 1);
            groupindex++;
            prevCount = 0;
        }
    }

    if (prevCount != 0)
    {
        count += nc2(prevCount + 1);
        G.push_back(prevCount + 1);
        groupindex++;
        prevCount = 0;
    }

    sort(A.begin(), A.end(), cmpindex);
    for (ll i = 0; i < N; i++)
    {
        ll gnum = G.at(A.at(i).groupindex);
        cout << count - nc2(gnum) + nc2(gnum - 1) << endl;
    }
    // cout << count << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

int h,w;

void bfs(){
  vector<vector<int>> v(h*w);
  vector<int> d(h*w,-1);
  rep(i,0,2*h-1){
    if(i%2==0){
      rep(j,0,w-1) {
        int c;
        cin >> c;
        if(c==0){
          v[(i/2)*w+j].push_back((i/2)*w+j+1);
          v[(i/2)*w+j+1].push_back((i/2)*w+j);
        }
      }
    }else{
      rep(j,0,w){
        int c; cin >> c;
        if(c==0){
          v[(i/2)*w+j].push_back(((i/2)+1)*w+j);
          v[(i/2+1)*w+j].push_back((i/2)*w+j);
        }
      }
    }
  }
  queue<int> q;
  q.push(0);
  d[0] = 1;
  while(!q.empty()){
    int u = q.front();q.pop();
    for(int nt : v[u]) if(d[nt] == -1){
      d[nt] = d[u]+1;
      q.push(nt);
    }
  }
  cout << max(0,d[h*w-1]) << endl;
}


int main(){
  for(;;){
    cin >> w >> h;
    if(h==0 && w==0)break;
    bfs();
  }

  return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <string>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;

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

  vector<int> P(N);

  REP(i, N) {
    cin >> P[i];
  }

  int ans = 1;
  int imin = P[0];

  for(int i = 1; i < N; i++) {
    if(imin > P[i]) {
      ans++;
      imin = P[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=a;i>=b;i--)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.14159265358979323
#define sz(a) (int)((a).size())
#define len(a) (int)(a.length())
#define FOR(i,j,k,l) for(ll i=j;i<k;i+=l)

void Fast_IO() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   #ifndef ONLINE_JUDGE
   freopen("input.in","r",stdin);
   freopen("output.out","w",stdout); 
   #endif
} 

int main(){
   //Fast_IO();
   ll n;
   cin>>n;
   vector<ll>v;
   map<ll,ll>m;
   ll sum=0;
   f(i,0,n){
      ll x;
      cin>>x;
      v.pb(x);
      m[x]++;
      sum+=x;
   }
   ll q;
   cin>>q;
   while(q--){
      ll a,b;
      cin>>a>>b;
      sum-=m[a]*a;
      m[b]+=m[a];
      sum+=b*m[a];
      m[a]=0;
      cout<<sum<<endl;
   }
   //cout<<m[4];
}






Measured memory_bytes: 9904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

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

    for (int i = 1; i <= n; i++)
    {
        ll tmp = i * 1.08;
        if (tmp == n)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":("<<endl;
}

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

#define Mod 1000000007

using namespace std;


typedef long long ll;


inline int read() {
	int out = 0;
	bool flag = false;
	register char cc = getchar();
	while (cc < '0' || cc > '9') {
		if (cc == '-') flag = true;
		cc = getchar();
	}
	while (cc >= '0' && cc <= '9') {
		out = (out << 3) + (out << 1) + (cc ^ 48);
		cc = getchar();
	}
	return flag ? -out : out;
} 

int N, x, y, rt;


int head[200010], nxt[400010], to[400010], cnt;

void add_edge(int u, int v) {
	to[++cnt] = v;
	nxt[cnt] = head[u];
	head[u] = cnt;
}


ll fac[200010], inv[200010];

int ksm(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y & 1) res = res * x % Mod;
		x = x * x % Mod;
		y >>= 1;
	}
	return res;
}
 
ll com(int x, int y) {
	return 1ll * fac[x] * inv[y] % Mod * inv[x - y] % Mod;
}

ll inverse(int t) {
	return ksm(t, Mod - 2);
}


int f[200010], siz[200010], dp[200010];

void dfs(int u, int fa) {
	f[u] = 1;
	for (int i = head[u]; i; i = nxt[i]) {
		int v = to[i];
		if (v == fa) continue;
		dfs(v, u);
		siz[u] += siz[v];
		f[u] = com(siz[u], siz[v]) * f[u] % Mod * f[v] % Mod;
	}
	siz[u]++;
}

void change(int u, int fa) {
	for (int i = head[u]; i; i = nxt[i]) {
		int v = to[i];
		if (v == fa) continue;
		dp[v] = dp[u] * inverse(com(N - 1, siz[v]) % Mod) % Mod * com(N - 1, N - siz[v]) % Mod % Mod;
		change(v, u);
	}
}

int main() {
	N = read();
	fac[0] = inv[0] = 1;
	for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % Mod;
	inv[N] = ksm(fac[N], Mod - 2);
	for (int i = N - 1; i; i--) inv[i] = inv[i + 1] * (i + 1) % Mod;
	for (int i = 1; i < N; i++) {
		x = read(), y = read();
		add_edge(x, y);
		add_edge(y, x);
	}
	rt = 1;
	dfs(rt, 0);
	dp[rt] = f[rt];
	change(rt, 0);
	for (int i = 1; i <= N; i++) printf("%d\n", dp[i]);
	return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

// warshall_floyd
template<class T>
struct warshall_floyd {
    vector<vector<T>> dis;
    int n;
    T init_v;
    warshall_floyd(int n, T init_v) :init_v(init_v), n(n) {init(n);}

    void init(int n) {
        dis.assign(n,vector<T>(n,init_v));
        rep(i,n) dis[i][i] = 0;
    }

    void add_dis(int s, int t, T cost) {
        dis[s][t] = dis[t][s] = cost;
    }

    void run() {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (dis[j][i] == init_v || dis[i][k] == init_v) continue;
                    dis[j][k] = min(dis[j][k],dis[j][i]+dis[i][k]);
                }
            }
        }
    }
};


int main() {
    int n, m, l; cin >> n >> m >> l;
    warshall_floyd<ll> wf_1(n,inf_l);
    rep(i,m) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        wf_1.add_dis(a,b,c);
    }
    wf_1.run();
    warshall_floyd<int> wf_2(n,inf);
    rep(i,n) {
        rep(j,i) {
            if (i == j) continue;
            if (wf_1.dis[i][j] <= l) wf_2.add_dis(i,j,1);
        }
    }
    wf_2.run();
    int q; cin >> q;
    rep(i,q) {
        int s, t; cin >> s >> t;
        s--; t--;
        int ans = wf_2.dis[s][t];
        if (ans != inf) cout << ans-1 << endl;
        else cout << -1 << endl;
    }
}

Measured memory_bytes: 1664
//https://atcoder.jp/contests/dp/tasks/dp_g

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

vector<vector<ll>>  adj(100100);
vector<bool> visited(100100);
vector<ll> dp(100100,-1);
void ingraph(ll N,ll M){
    for(ll i=0;i<M;i++){
        ll u,v;
        cin>>u>>v;
        adj[u-1].push_back(v-1);
    }
}

ll dfs(ll v){
    visited[v]=1;
    ll mx=0;
    for(auto u : adj[v]){
        if(!visited[u]){
            dp[u] = dfs(u);
        }
        mx = max(mx,dp[u]);
    }
    return mx+1;
}

int main() {
    fastio
    ll N,M;
    cin>>N>>M;
    ingraph(N,M);
    for(int i=0;i<N;i++){
        if(!visited[i]){
            dp[i] = dfs(i);
        }
    }
    // for(int i=0;i<N;i++){
    //     cout<<dp[i]<<" ";
    // }
    cout<<*max_element(dp.begin(),dp.end())-1<<"\n";
    return 0;
}

Measured memory_bytes: 12836
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int A,B,ans=0;
    cin >> A >> B;
    
    ans += max(A,B);
    if(ans==A){
        A--;
    }else{
        B--;
    }
    ans += max(A,B);
    cout << ans << endl;
    
return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define stop char nyaa;cin>>nyaa;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

using P = pair<int, int>;

int cnt[1 << 17];
void solve() {
	int n; cin >> n;
	rep(i, n) {
		int a; cin >> a;
		cnt[a]++;
	}
	int ma = 0;
	for (int i = 1; i <= 100000; i++) {
		ma = max(ma, cnt[i - 1] + cnt[i] + cnt[i + 1]);
	}
	cout << ma << endl;
}


int main() {
	solve();
	stop
	return 0;
}


Measured memory_bytes: 640
import sys
import itertools
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = list(map(lambda x: int(x) - 1, readline().split()))
    a = [0] + [i % k for i in list(itertools.accumulate(a))]
    d = collections.defaultdict(int)
    cnt = 0
    for i in range(n + 1):
        cnt += d[a[i]]
        d[a[i]] += 1
        if i >= k - 1:
            d[a[i-k+1]] -= 1
    print(cnt)


if __name__ == '__main__':
    solve()


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

int main()
{
	int d,t,s;
  cin >> d >> t >> s;
	
	if( s*t >= d ) {
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
    
  return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main(void)
{
  int n, cnt = 0;
  scanf("%d", &n);
  
  for (int i = 0; i < n; i++)
  {
    int p;
    scanf("%d", &p);
    if (p != i + 1) cnt++;
  }
  
  if (cnt < 3) printf("YES"); else printf("NO");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;




int main() {

	int n;
	cin >> n;
	vector<vector<int>> f(n, vector<int>(10));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> f[i][j];
		}
	}

	vector<vector<int>> p(n, vector<int>(11));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 11; j++) {
			cin >> p[i][j];
		}
	}

	int benefit = -1000000000;

	for (int i =1; i < (1 << 10); i++) {
		int b = 0;
		for (int j = 0; j < n; j++) {
			int cnt = 0;
			for (int k = 0; k < 10; k++) {
				bool isOpen = (i >> k) & 1;

				if (isOpen && (f[j][k] ==1)) {
					cnt++;
				}
			}

			b += p[j][cnt];
			
		}

		
		if (benefit < b) {
			
			
			benefit = b;
		}
	}

	cout << benefit << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll INF = 2000000001;

ll lcm(ll x, ll y)
{
    ll ret = x/__gcd(x,y)*y;
    return min(INF,ret);
}

ll s(ll a, ll n)
{
    return n*(n+1)/2*a;
}

double solve(ll n, int m)
{
    vector<ll> p(m);
    rep(i,m) cin >>p[i];

    ll num = 0;
    rep(mask,1<<m)
    {
        ll L = 1;
        rep(i,m)if(mask>>i&1) L = lcm(L,p[i]);

        ll x = n/L;
        if(__builtin_popcount(mask)%2==1) num-=x;
        else num+=x;
    }

    if(num==0) return 0;

    double d = num;
    double ret = 0;
    rep(mask,1<<m)
    {
        ll L = 1;
        rep(i,m)if(mask>>i&1) L = lcm(L,p[i]);

        if(L>n) continue;

        ll x = n/L;
        if(__builtin_popcount(mask)%2==1) ret -= s(L,x)/d;
        else ret += s(L,x)/d;
    }

    return ret;
}

int main()
{
    int n,m;
    while(cin >>n >>m,n) printf("%.10f\n", solve(n,m));
    return 0;
}

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

long long n,v[1000005];
bool ok,zero;
map<int,int> us;
vector<int> num;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

	cin>>n;
	zero=true;
	
	for(int i=0;i<n;i++){
	    cin>>v[i];
	    
	    if(us[v[i]]==0){
	        num.push_back(v[i]);
        }
        us[v[i]]++;
	    if(v[i]!=0){
	        zero=false;
        }
    }
    
    if(n%3!=0){
        if(zero==false)ok=false;
        else ok=true;
    }
    else{
        
        if(num.size()==3){
        if(((num[0]^num[1]^num[2])!=0) || us[num[0]]!=n/3 || us[num[1]]!=n/3 || us[num[2]]!=n/3)ok=false;
        else ok=true;
        }
        else{
            if(zero==true)ok=true;
            else{
                if(num.size()!=2)ok=false;
                else{
                    if(num[0]!=0)swap(num[0],num[1]);
                    if(num[0]==0 && us[num[0]]==(n/3))ok=true;
                    else ok=false;
                }
            }
        }
    }
    
    if(ok)cout<<"Yes\n";
    else cout<<"No\n";

return 0;
}


Measured memory_bytes: 4856
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(a, b, c, k) = in.readLine().split("\\s+").map(_.toInt)

    out.println(
      if (k < a) {
        k
      } else if (k < a + b) {
        a
      } else if (k < a + b + c) {
        a - (k - a - b)
      } else {
        a - c
      }
    )
    out.flush()
  }
}


Measured memory_bytes: 54756
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <list>
#include <vector>
#include <map>

#pragma warning(disable:4996)

using namespace std;
#define FUNC(string) cout<<str<<endl 

int main(void) {
	long int a, b, c;
	double d;
	long int ans;
	cin >> a >> b >> c;
	if (a > b) {
		if (a > c) {
			if (a % 2 == 0)
				ans = 0;
			else
				ans =b*c;
		}
		else {
			if (c % 2 == 0)
				ans = 0;
			else
				ans = b*a;
		}
	}
	else if (b > c) {
		if (b % 2 == 0)
			ans = 0;
		else
			ans = a*c;
	}
	else {
		if (c % 2 == 0)
			ans = 0;
		else
			ans = b*a;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
h,w,m=map(int,input().split())
a=[[] for i in range(m)]
g=[0 for i in range(h)]
r=[0 for i in range(w)]

for i in range(m):
    x,y=map(int,input().split())
    a[i].append(x)
    a[i].append(y)
    g[x-1]+=1
    r[y-1]+=1
G=[]
R=[]
d=max(g)
e=max(r)
for i in range(h):
    if g[i]==d:
        G.append(i+1)
for i in range(w):
    if r[i]==e:
        R.append(i+1)
f=0
for i in range(m):
    q=0
    p=0
    x=a[i][0]
    y=a[i][1]
    k=len(G)-1
    l=0
    j=(k+l)//2
    while k-l>1:
        j=(k+l)//2
        if G[j]>=x:
            k=j
        else:
            l=j
    if G[l]==x or G[k]==x:
        p=1

    k = len(R) - 1
    l = 0
    j = (k + l) // 2
    while k - l > 1:
        j = (k + l) // 2
        if R[j] >=y:
            k = j
        else:
            l = j
    if R[l] == y or R[k] == y:
        q = 1

    if p==q==1:
        f+=1
v=1
if f!=len(G)*len(R):
    v=0
ans=max(g)+max(r)
print(ans if v==0 else ans-1)


Measured memory_bytes: 152956
n = int(input())
h = 30000

if n == 3:
    print("2 5 63")
    exit()
if n == 4:
    print("2 5 20 63")
    exit()
if n == 5:
    print("2 5 20 30 63")
    exit()


pret = [2, 3, 4]
it_count = int(n/4) + 1
pret.extend([6*i for i in range(1, it_count)])
pret.extend( [6*i + 2 for i in range(1, it_count)])
pret.extend([6*i +3 for i in range(1, it_count)])
pret.extend(  [6*i + 4 for i in range(1, it_count)])

pret.sort()
ret = pret[:n]


sum_of_ret = sum(ret) % 6
if sum_of_ret == 2:
    ret.remove(8)
    ret.append(6* (it_count))
if sum_of_ret == 3:
    ret.remove(9)
    ret.append(6* (it_count))
if sum_of_ret == 5:
    ret.remove(9)
    if not 6* (it_count - 1) + 4 in ret:
        ret.append(6* (it_count - 1) + 4)
    else:
        ret.append(6* (it_count) + 4)


print(" ".join(list(map(str,ret))))



Measured memory_bytes: 5364
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    int N;  cin >> N;
    vector<pair<int, int>> A(N);
    for(int i=1; i<=N; i++) {
        int a;  cin >> a;
        A[i-1] = {a, i};
    }
    sort(A.begin(), A.end());
    for(pair<int,int> p : A){
        cout << p.second << endl;
    }
}

Measured memory_bytes: 1664
// Remember...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=2e5+10,mod=998244353;
const ll inf=1e18;

int ans=1;

void Do(int &a,int b,int c){
    if(a>=b && a>=c){
    }
    else if(a<b && a<c){
	ans=1ll*ans*(min(b,c)-a) %mod;
    }
    else{
	ans=1ll*ans*(max(b,c)-a) %mod;
    }
    a++;
}

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

    int n; cin>>n;
    string s; cin>>s;
    int A=0,B=0,C=0;
    for(int i=0;i<3*n;i++){
	if(s[i]=='R') Do(A,B,C);
	if(s[i]=='G') Do(B,A,C);
	if(s[i]=='B') Do(C,A,B);
    }
    for(int i=1;i<=n;i++){
	ans=1ll*ans*i %mod;
    }
    return cout<<ans<<endl,0;
}
// Deathly mistakes:
//  * Read the problem carefully.
//  * Check maxn.
//  * Overflows.


// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

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

fn main(){
    let n = ModInt(read());
    let ModInt(n1) = n;
    let m = ModInt(read());
    let k: u64 = read();
    let mut ret: ModInt = ModInt(0);
    let mut comb: Vec<ModInt> = (0..n1).map(|_| ModInt(1)).collect();

    for i in 0..k {
        comb[i as usize + 1] = comb[i as usize].clone() * ModInt(n1 - i - 1) / ModInt(i + 1);
    }

    for i in 0..(k + 1) {
        ret += comb[i as usize].clone() * m * (m - ModInt(1)).pow(n1 - i - 1);
    }
    println!("{}", ret);
}

#[derive(Clone, Copy)]
struct ModInt(u64);
const MOD: u64 = 998244353;

impl std::ops::Add for ModInt {
    type Output = ModInt;

    fn add(self, other: ModInt) -> ModInt {
        let ModInt(a) = self;
        let ModInt(b) = other;
        ModInt((a + b) % MOD)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, other: ModInt) {
        let ModInt(a) = self;
        let ModInt(b) = other;
        *a = (*a + b) % MOD;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;

    fn sub(self, other: ModInt) -> ModInt {
        let ModInt(a) = self;
        let ModInt(b) = other;
        ModInt((a + MOD - b) % MOD)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, other: ModInt) {
        let ModInt(a) = self;
        let ModInt(b) = other;
        *a = (*a + MOD - b) % MOD;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;

    fn mul(self, other: ModInt) -> ModInt {
        let ModInt(a) = self;
        let ModInt(b) = other;
        ModInt((a * b) % MOD)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, other: ModInt) {
        let ModInt(a) = self;
        let ModInt(b) = other;
        *a = (*a * b) % MOD;
    }
}

impl ModInt {
    fn pow(&self, n: u64) -> ModInt {
        if n == 0 {
            return ModInt(1);
        }
        let prev = self.pow(n / 2);
        if n % 2 == 1 {
            prev.clone() * prev * self.clone()
        } else {
            prev.clone() * prev
        }
    }

    fn inverse(&self) -> ModInt {
        self.pow(MOD - 2)
    }

    fn comb(&self, k1: &ModInt) -> ModInt {
        let mut ret = ModInt(1);
        let ModInt(k) = k1;
        for i in 0..(*k) {
            ret = ret * ModInt(k - i) / ModInt(i + 1);
        }
        ret
    }
}

impl std::ops::Div for ModInt {
    type Output = ModInt;

    fn div(self, other: ModInt) -> ModInt {
        self * other.inverse()
    }
}

impl std::fmt::Display for ModInt {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let ModInt(a) = self;
        write!(f, "{}", a)
    }
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstring>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
int main () {
  int n;
  cin >> n;
  if (n/100 == 7 || (n%100)/10==7 || n%10==7){
    cout << "Yes";
  }else{
    cout << "No";
  }
 
  return 0;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a;
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputDoubleArray(a,N) double a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
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; }

//参考


int main(){
  long long int N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  long long int m = min({A, B, C, D, E}); 
  cout << (N+m-1)/m + 4 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
    #include <bits/stdc++.h>
         
    #define uint unsigned int
    #define ll long long
    #define ull unsigned long long
    #define ld long double
    #define rep(i, l, r) for (int i = l; i < r; i++)
    #define repb(i, r, l) for (int i = r; i > l; i--)
    #define sz(a) (int)a.size()
    #define fi first
    #define se second
    #define mp(a, b) make_pair(a, b)
     
    using namespace std;
     
    const int N = 200000;
    const int inf = (int)1e9 + 1;
    const ll big = (ll)1e18 + 1;
    const int P = 239;
    const int MOD = (int)1e9 + 7;
    const int MOD1 = (int)1e9 + 9;
    const double eps = 1e-6;
    const double pi = atan2(0, -1);
    const int ABC = 26;
     
    int main()
    {
        //freopen("a.in", "r", stdin);
        //freopen("a.out", "w", stdout);
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.precision(20);
        cout << fixed;
        //ll TL = 1.95 * CLOCKS_PER_SEC;
        //clock_t time = clock();
        int n, m;
        cin >> n >> m;
        vector<int> g[n];
        rep(i, 0, m)
        {
            int a, b;
            cin >> a >> b;
            a--; b--;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        rep(i, 0, n)
        {
            bool ok1 = false, ok2 = false;
            for (int j : g[i])
            {
                if (j == 0)
                    ok1 = true;
                if (j == n - 1)
                    ok2 = true;
            }
            if (ok1 && ok2)
            {
                cout << "POSSIBLE\n";
                return 0;
            }
        }
        cout << "IMPOSSIBLE\n";
        return 0;
    }

Measured memory_bytes: 12016
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val bList = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    val aList = mutableListOf<Int>()
    bList.add(0, bList.first())
    bList.add(bList.last())
    for(i in (1 until bList.size)) {
        aList.add(Math.min(bList[i-1], bList[i]))
    }
    println(aList.sum())
}



Measured memory_bytes: 37748
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
 
//#define mp make_pair
#define bug(v) cerr<<#v<<" = "<<(v)<<endl;
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define pb emplace_back
#define vii vector<int>
#define vll vector<ll>
#define vpll vector< pair <ll,ll> >
#define pll pair <ll,ll>
#define pii pair <int,int>
#define pq priority_queue< int >
#define khtm "\n"
#define F first
#define S second
#define fr(i,a,n) for(i=a;i<n;i++)
#define mem(arr,l) memset(arr,l,sizeof arr)
#define ALL(x) x.begin(), x.end()
#define frr(i,a,n) for(i=n-1;i>=a;i--)
//#define mod 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase ll T; cin>>T; while(T--)
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;

const int mod=1e9+7;
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}


/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 

ll i,j,k,m,l,r,n;
ll a[MAX];


int main()
{
 
  #ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//cout << setprecision(15) << fixed;
fast

map<string,ll> mp;
cin >> n;
fr(i,0,n){
	string s;
	cin >> s;
	mp[s] = 1;
}
cout << mp.size();

  #ifndef ONLINE_JUDGE
  cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  #endif
 
  return 0;
 
}

Measured memory_bytes: 19168
x, y = map(int, input().split())

a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
z = "No"

if x in a and y in a:
    z = "Yes"
if x in b and y in b:
    z = "Yes"
if x == 2 and y == 2:
    z = "Yes"
print(z)

Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
P x[100010];
P y[100010];
vector<pair<ll,P>> edges;
class UnionFind {
  vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
  void init(ll n) {
    par.resize(n, 1); rank.resize(n, 0);
  }
  ll getSize(ll x) {
    return par[find(x)];
  }
  ll find(ll x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(ll x, ll y) {
    return find(x) == find(y);
  }
};
int main(){
    cin>>N;
    for(ll i=0;i<N;i++){
        x[i].second=i;
        y[i].second=i;
        cin>>x[i].first>>y[i].first;
    }
    sort(x,x+N);
    sort(y,y+N);
    for(ll i=0;i<N-1;i++){
        ll u=x[i].second,v=x[i+1].second;
        edges.push_back(make_pair(x[i+1].first-x[i].first,P(u,v)));
        u=y[i].second,v=y[i+1].second;
        edges.push_back(make_pair(y[i+1].first-y[i].first,P(u,v)));
    }
    sort(edges.begin(),edges.end());
    UnionFind UF;
    UF.init(N);
    ll ans=0;
    
    for(auto e:edges){
        ll u=e.second.first,
           v=e.second.second;
        if(UF.isSame(u,v))continue;
        ans+=e.first;
        UF.merge(u,v);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11632
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans = -LINF;
int z;

int main(void) {
  int N;
  int K;
  cin >> N >> K;
  vector<int> P(N, 0);
  vector<ll> C(N, 0);
  rep(i, 0, N) {
    cin >> P[i];
    P[i]--;
  }
  rep(i, 0, N) cin >> C[i];

  rep(i, 0, N) {
    int size = 0;
    ll sum = 0;
    int pos = i;
    do {
      sum += C[P[pos]];
      pos = P[pos];
      size++;
    } while (pos != i);

    if (sum<=0 || K<=size) {
      
      int p = i;
      ll x = 0;
      rep(j, 0, min(size,K)) {
        x += C[P[p]];
        p = P[p];
        ans = max(ans, x);
      }

    } else {
      int q = K/size, r = K%size+size;
      sum = sum*(q-1);
      if (q!=0) ans = max(ans, sum);
      pos = i;
      rep(j, 0, r) {
        sum += C[P[pos]];
        pos = P[pos];
        ans = max(ans, sum);
      }
    }
  }
    
  
    
  cout << ans << endl;
  return 0;
}





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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    vector<vector<int>> g(4);
    for (int i = 0; i < 3; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> cnt(4, 0);
    for (int i = 0; i < 4; i++)
    {
        cnt[g[i].size()]++;
    }
    if (cnt[1] == 2 && cnt[2] == 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    if (a < b){
        for (int i=0; i<b; i++) {
            cout << a;
        }
    } else {
        for (int i=0; i<a; i++) {
            cout << b;
        }
    }
}

Measured memory_bytes: 3636
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iterator> 
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);


#define PI 3.14159265

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)1e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

struct node{
	int x, y, z;
	mutable int w;
	node() {
		x = -1, y = -1, z = -1;
	}
	bool operator<(const node& nod) const{
		if (this->x == nod.x) {
			if (this->y == nod.y){
				return this->z < nod.z;
			}
			return this->y < nod.y;
		}
		return this->x < nod.x;
	}
};


int main() {
	int a, b, c, k; cin>>  a >> b >> c >> k;
	if (a + b + c <= k) {
		cout<< a*1 + b*0 + c*-1;
	}
	else if (a + b <= k) {
		int x = a + b;
		cout<< a*1 + b*0 + (k - x)*-1;
	}
	else if (a <= k) {
		int x = a;
		cout<< a*1 + (k - x)*0;
	}
	else{
		cout<< k;
	}
	
	return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

      public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        
        int num = scan.nextInt();
          String str = Integer.toString(num); 
          
          int count = 0;
        char[] c = str.toCharArray();
        for(char c1 : c) {
            if(c1 == '1') {
            	count++;
            }
        }
          System.out.println(count);
        }

}

Measured memory_bytes: 21332
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){

	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	int ret;
	ret = (b == 0) ? a : gcd(b, a % b);
	return ret;
}

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

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[]){
	char string[] = "aiueo";
	char ch;
	scanf("%c",&ch);
	for (int i = 0; i < 5; ++i)
	{
		if(ch == string[i]){
			puts("vowel");
			return 0;
		}
	}
	puts("consonant");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int LL
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "


int32_t main()
  {
  ios_base::sync_with_stdio(0); 
  int n, k;
  cin >> n >> k;
  VI V;
  FOR(i, 1, n)
    {
    int a;
    cin >> a;
    V.PB(a);
    }
  sort(ALL(V));
  LL res = 0;
  REP(i, k)res += V[i];
  cout << res << endl;
  }


Measured memory_bytes: 3668
#include <stdio.h>

int main(){
  int p,q,r;
  scanf("%d %d %d",&p,&q,&r);
  int answer = p + q + r;
  int num = p;
  if(num < q) num = q;
  if(num < r) num = r;
  answer -= num;
  printf("%d",answer);
  return 0;
}

Measured memory_bytes: 128
seq = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
       1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(seq[K-1])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
string s,t;
int a,b,ans=1111,res;
int main()
{
	cin>>s>>t;
	a=s.length();
	b=t.length();
	for (int i=0;i<a-b+1;i++) 
	{
		res=0;
		for (int j=0;j<b;j++) if (s[i+j]!=t[j]) res++;
		ans=min(ans,res);
	} 
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

#define M 1777771

class Dictionary{
    private:
        vector<string> data;
        map<int, string> m;
    public:
        void insert(string str);
        void hash_Insert(string str);
        bool find(string str);
        bool hash_Find(string str);
        int get_Kay(string str);
        int hash_1(int kay);
        int hash_2(int kay);
};

int Dictionary::hash_1(int kay){ return kay%M; }
int Dictionary::hash_2(int kay){ return 1+(kay%(M-1)); }

int Dictionary::get_Kay(string str){
    int k = 0;
    REP(i, (int)str.length()){
        k += (int)str[i] * pow(5, i);
    }
    return k;
}

void Dictionary::insert(string str){
    if (!Dictionary::find(str)) data.PB(str);
}
void Dictionary::hash_Insert(string str){
    int i = 0;
    int hashed_Kay;
    int kay = get_Kay(str);
    while(true){
        hashed_Kay = hash_1(kay) + i*hash_2(kay);
        if(m[hashed_Kay] == "" or m[hashed_Kay] == str) break;
        i++;
    }
    m[hashed_Kay] = str;
}

bool Dictionary::find(string str){
    if(std::find(ALL(data), str) != data.end()) return true;
    else return false;
}
bool Dictionary::hash_Find(string str){
    int i = 0;
    int hashed_Kay;
    int kay = get_Kay(str);
    while(true){
        hashed_Kay = hash_1(kay) + i*hash_2(kay);
        if(m[hashed_Kay] == str) return true;
        else if(m[hashed_Kay].length() == 0) return false;
        i++;
    }
}

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

    int n;
    cin >> n;

    string op, word;
    Dictionary dic;

    REP(_, n){
        cin >> op >> word; 
        if (op[0] == 'i') dic.hash_Insert(word);
        else if(dic.hash_Find(word)) cout << "yes" << "\n";
        else cout << "no" << "\n";
    }  
}


Measured memory_bytes: 41308
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define endl '\n'
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , pair<int , int> > piii;
const int MAXN = 1e5 + 10;
int n , m , a , b , d[MAXN] , par[MAXN];
vector<int> adj[MAXN] , vec[MAXN];
void dfs(int u)
{
	for(auto v : adj[u])
		d[v] --;
	for(auto v : adj[u])
		if(!d[v])
			vec[u].pb(v);
	for(auto v : vec[u])
		par[v] = u , dfs(v);
	return;
}
void input()
{
	cin >> n >> m;
	for(int i = 0 ; i < n + m - 1 ; i ++)
		cin >> a >> b , a -- , b -- , adj[a].pb(b) , d[b] ++;
	return;
}
int32_t main()
{
	input();
	for(int i = 0 ; i < n ; i ++)
		if(!d[i])
		{
			par[i] = -1 , dfs(i) ; break;
		}
	for(int i = 0 ; i < n ; i ++)
		cout << par[i] + 1 << endl;
	return 0;
}


Measured memory_bytes: 19584
#include<iostream>
using namespace std;
int main()
{
    int x, y;
    int q1 = 0,q2 = 0;
    cin >> x >> y;
    if(x == 11 || x == 9 || x == 6 || x == 4)
        q1 = 2;
    else if(x == 2)
        q1 = 3;
    else q1 = 1;
    if(y == 11 || y == 9 || y == 6 || y == 4)
        q2 = 2;
    else if(y == 2)
        q2 = 3;
    else q2 = 1;
    if(q1 == q2)
        cout << "Yes";
    else
        cout << "No";

     return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int> >pref, suff;
int main(){
	int n; cin>>n;
	for(int i=0; i<n; i++){
		string s="";
		char c=getchar();
		while(c!='(' && c!=')') c=getchar();
		int fi=0, se=0;
		for(;c=='(' || c==')';){
			if(c=='(') se++;
			else{
				if(se==0) fi++;
				else se--;
			}
		//	cout<<c<<" "<<fi<<" "<<se<<endl;
			c=getchar();
		}
	//	cout<<endl;
		if(se>fi) pref.push_back({fi, se});
		else suff.push_back({se, fi});
	}
	sort(pref.begin(), pref.end());
	sort(suff.begin(), suff.end());
	int tot1=0, tot2=0;
	for(pair<int, int>i:pref){
		if(i.first>tot1){
			cout<<"No\n"; return 0;
		}
		tot1+=i.second-i.first;
	}
	for(pair<int, int>i:suff){
		if(i.first>tot2){
			cout<<"No\n"; return 0;
		}
		tot2+=i.second-i.first;
	}
	if(tot1!=tot2){
		cout<<"No\n"; return 0;
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 11272