akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

int rate2step(int r)
{
  if(3200 <= r) {
    r = 3200;
  }
  return r / 400;
}

int main()
{
  int N;
  constexpr int N_STEP = 9;
  std::vector<int> num(N_STEP);
  std::cin >> N;
  for(int i=0; i<N; i++) {
    int rate;
    std::cin >> rate;
    num[rate2step(rate)]++;
  }

  int fixed_colors = 0;
  for(int i=0; i<N_STEP-1; i++) {
    fixed_colors += num[i] > 0 ? 1 : 0;
  }

// over 3200 member selects fixed_colors
  int min = fixed_colors;
  if(min == 0 && num[N_STEP-1] > 0) {
    min = 1;
  }
  int max = fixed_colors + num[N_STEP-1];

  std::cout << min << " " << max << std::endl;

  return 0;
}


Measured memory_bytes: 3636
n = int(input())
a = [int(x) for x in input().split()]
s = [0]*(n+1)
count = dict()
for i in range(n):
  s[i+1] = s[i]+a[i]
  if s[i+1] not in count:
    count[s[i+1]] = 1
  else:
    count[s[i+1]] += 1
ans = 0
for k, c in count.items():
  if k == 0:
    ans += c
  ans += (c)*(c-1)//2
print(ans)

Measured memory_bytes: 40384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N;cin>>N;
    map<ll,ll> count;
    rep(i,N){
        ll A;cin>>A;
        count[A]++;
    }
    ll ans=0;
    for(auto p:count)ans+=p.se-1;
    cout<<N-(ans+1)/2*2<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define maxN 200002
using namespace std;

int n, k;

int frq[maxN], sz;
priority_queue < int > q;

int ans;

int main()
{
    scanf("%d%d", &n, &k);
    ans = n;
    for (int i = 1; i <= n; ++ i)
    {
        int x;
        scanf("%d", &x);
        ++ frq[x];
    }
    for (int i = n; i >= 1; -- i)
        if (frq[i])
    {
        q.push(-frq[i]);
        ++ sz;
        if (sz > k)
            {
                q.pop();
                -- sz;
            }
    }
    while (!q.empty())
    {
        ans += q.top();
        q.pop();
    }
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

int a[100005];

int main(){

	int n;
	cin >> n;
	map<int,int> mp;
	double s=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		s+=a[i];
		if(mp.find(a[i])==mp.end())
			mp[a[i]] = i;
	}

	sort(a,a+n);
	s/=n;
	double e=1e9;
	int ans=0;
	for(int i=0;i<n;i++){
		if(abs(s-a[i])<e){
			e=abs(s-a[i]);
			ans=mp[a[i]];
		}else if(abs(s-a[i])==e && mp[a[i]]<ans){
			ans = mp[a[i]];
		}
	}
	cout << ans;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void func()
{
    ll x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<"\n";

}

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

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r" , stdin);
    // freopen("output.txt", "w" , stdout);
    // #endif


    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }

}

Measured memory_bytes: 256
N=int(input())
P=list(map(float, input().split()))

# N<=3000だから全探索は日が暮れる
# dp[i][j]:i枚目までのコインを投げて表がj回出る確率

dp=[[0 for j in range(N+1)] for i in range(N)]

dp[0][0]=1-P[0]
dp[0][1]=P[0]
for i in range(1,N):
    dp[i][0]=dp[i-1][0]*(1-P[i])
    for j in range(1,N+1):
        dp[i][j]=dp[i-1][j-1]*P[i] + dp[i-1][j]*(1-P[i])
    # print(dp[i])
print(sum(dp[N-1][j] for j in range(N+1) if j > N//2))

Measured memory_bytes: 224284
s = list(input())
k = int(input())
A = 'abcdefghijklmnopqrstuvwxyz'
Da = {a:i for i,a in enumerate(A)}

c = 0
for i in range(len(s)):
    if s[i]!='a' and 26-Da[s[i]]<=k:
        k -= 26-Da[s[i]]
        s[i] = 'a'
if k:
    s[i] = A[Da[s[i]]+k%26]
print("".join(s))

Measured memory_bytes: 9968
# ABC051C - Back and Forth
def main():
    sx, sy, tx, ty = list(map(int, input().rstrip().split()))
    X, Y = abs(sx - tx), abs(sy - ty)
    move = ""
    move += "U" * Y + "R" * X + "D" * Y + "L" * X
    move += "L" + "U" * (Y + 1) + "R" * (X + 1) + "D"
    move += "R" + "D" * (Y + 1) + "L" * (X + 1) + "U"
    print(move)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<stdio.h>
int A,B,C,X[105][105],Y[105][105],i,j,k;
long long t;
int main()
{
	scanf("%d%d%d",&A,&B,&C);
	for(i=0;i<A;i++)
		for(j=0;j<B;j++)
			scanf("%d",&X[i][j]);
	for(i=0;i<B;i++)
		for(j=0;j<C;j++)
			scanf("%d",&Y[i][j]);
	for(i=0;i<A;i++)
	{
		for(j=0;j<C;j++)
		{
			for(k=t=0;k<B;k++)
				t+=X[i][k]*Y[k][j];
			printf("%lld%s",t,j==C-1?"\n":" ");
		}
	}
	return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    int n;
    cin >> n;
    int k;
    cin >> k;
    map<int,int> quiz;
    int q;
    cin >> q;
    for (int i=0;i<n;i++){
        quiz[i] = k-q;
    }

    vector<int> a(q);
    for (int i=0;i<q;i++){
        cin >> a.at(i);
    }
    for (int i=0;i<q;i++){
        quiz[a.at(i)-1]++;
    }
    for (int i=0;i<n;i++){
        if(quiz[i]<=0)  cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int main() {
	int N, X, T;
	int m = 0;
	cin >> N >> X >> T;
	while (1) {
		m += T;
		if (N - X > 0) {
			N -= X;
		}
		else {
			break;
		}
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
vector<vector<int>>adj; vector<int> vis,d;
void solve()
{
    int n,m; cin>>n>>m;
    int x,y;adj.assign(n+1,vector<int>());
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    vis.assign(n+1,0); d.assign(n+1,0);queue<int> q;
    q.push(1);
    vis[1]=1;
    d[1]=1;
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        for(auto u:adj[v])
        {
            if(vis[u]==0)
            {
                d[u]=v;vis[u]=1;
                q.push(u);
            }
        }
    }
    for(int i=2;i<=n;i++)
    {
        if(d[i]==0)
        {
            cout<<"No";
            return;
        }
    }
    cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++)
    {
        cout<<d[i]<<endl;
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1; //cin>>test;
    int x=1;
    while(test--)
    {
        //cout<<"Case #"<<x++<<": ";
        solve();
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            return false;
        }
    }
    return true;
}

int main()
{
	ll n,a,b,c;
	deque<ll> d;
	vll v;
	cin >> n;
	rep(i,n){
		cin >> a;
		if(a==0){
			cin >> b >> c;
			if(b==0) d.pf(c);
			else if(b==1) d.pb(c);
		}
		else if(a==1){
			cin >> b;
			v.pb(d[b]);
		}
		else if(a==2){
			cin >> b;
			if(b==0) d.pop_front();
			else if(b==1) d.pop_back();
		}
	}
	rep(i,SIZE(v)) cout << v[i] << endl;
	return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b) cout << c << endl;
  else if(b == c) cout << a << endl;
  else cout << b << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int count = 0;
    for(int i = 0;i < C;i++){
      if(B >= A){
        B-=A;
        count++;
      }else{
        break;
      }
    }
    
    System.out.println(count);
  }
}


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

void solve( int w, int* g, bitset<10> b, int i )
{
    if( i == 10 )
    {
        int sum = 0;
        int p;                              //prsentation error回避
        for( int j = 0; j < 10; j++ )
        {
            if( b[j] == 1 )
            {
                sum += g[j];
                p = j;
            }
        }
        if( w == sum )
        {
            for( int j = 0; j < 10; j++ )
            {
                if( b[j] == 1 )
                {
                    cout << g[j];
                    if( p != j )
                        cout << " ";
                }
            }
        }
        return;
    }
    b[i] = 0;
    solve( w, g, b, i + 1 );

    b[i] = 1;
    solve( w, g, b, i + 1 );

}

int main()
{
    int a = 1, w, g[10];
    bitset<10> b;

    for( int i = 0; i < 10; i++ )
    {
        g[i] = a;
        a *= 2;
    }

    while( cin >> w )
    {
        solve( w, g, b, 0 );
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3108
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

string s;

int main()
{
  s = GetString();
  int L = 0;
  int R = SIZE(s)-1;
  int ans = 0;
  while (L < R)
  {
    if (s[L] == s[R])
    {
      ++L;
      --R;
    } else if (s[L] == 'x')
    {
      ++ans;
      ++L;
    } else if (s[R] =='x')
    {
      ++ans;
      --R;
    } else 
    {
      puts("-1");
      return 0;
    }
  }
  printf("%d\n",ans);
  return 0;
}










Measured memory_bytes: 512
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return 1;}return 0;}

int n,a,b,c;
vector<int> l(8);
int res = INT_MAX;

int dfs(int d,int e,int f,int i){
    if(i<n){
        return min({dfs(d,e,f,i+1),dfs(d+l[i],e,f,i+1)+10,dfs(d,e+l[i],f,i+1)+10,dfs(d,e,f+l[i],i+1)+10});
    }else{
        if(d&&e&&f)return abs(d-a)+abs(e-b)+abs(f-c);
        else return 1e6;
    }
}

int main(){
    cin >> n;
    cin >> a >> b >> c;
    REP(i,n){
        cin >> l[i];
    }
    put(dfs(0,0,0,0)-30);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t

using namespace std;

const int N = 2505;
const int oo = (ll)1e15;
typedef tuple<int, int, int> TEdge;

int n, m, p, u, v, c;
vector<int> d[2];
TEdge e[N * 2];

void BellmanFord(int s, vector<int>& d, bool rev) {
    d.resize(n + 1); fill(d.begin(), d.end(), oo); d[s] = 0;
    for(int i = 1; i < n; ++i) {
        for(int j = 1; j <= m; ++j) {
            tie(u, v, c) = e[j];
            if(rev && d[v] < oo) d[u] = min(d[u], d[v] + c);
            else if(!rev && d[u] < oo) d[v] = min(d[v], d[u] + c);
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m >> p;
    for(int i = 1; i <= m; ++i) {
        cin >> u >> v >> c;
        e[i] = make_tuple(u, v, p - c);
    }
    BellmanFord(1, d[0], 0);
    BellmanFord(n, d[1], 1);
    for(int i = 1; i <= m; ++i) {
        tie(u, v, c) = e[i];
        if(d[0][v] > d[0][u] + c && d[1][v] < oo && d[0][u] < oo) return cout << -1, 0;
    }
    if(d[0][n] > 0) cout << 0;
    else cout << -d[0][n];
}


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

using namespace std;

int main(void) {
    int n;
    cin >> n;
    unordered_set<string> s;
    for(int i=0; i<n; ++i) {
        string temp;
        cin >> temp;
        s.insert(temp);
    }

    cout << s.size() << '\n';
}

Measured memory_bytes: 17704
#include <stdio.h>
int main()
{
    int a,b,x,y,m;
    scanf("%d%d",&a,&b);
    x=a+b;
    y=a-b;
    m=a*b;

    if(x>=y && x>=m)
        printf("%d\n",x);
    else if(y>=x && y>=m)
        printf("%d\n",y);
    else if(m>=x && m>=y)
        printf("%d\n",m);

    return 0;
}




Measured memory_bytes: 128
face = list(map(int, input().split()))
order = input()

for j in range(len(order)) :
  if(order[j] == "S") :
    key = face[4]
    face[4] = face[5]
    face[5] = face[1]
    face[1] = face[0]
    face[0] = key
  elif(order[j] == "N") :
    key = face[1]
    face[1] = face[5]
    face[5] = face[4]
    face[4] = face[0]
    face[0] = key
  elif(order[j] == "E") :
    key = face[3]
    face[3] = face[5]
    face[5] = face[2]
    face[2] = face[0]
    face[0] = key
  else :
    key = face[2]
    face[2] = face[5]
    face[5] = face[3]
    face[3] = face[0]
    face[0] = key

print(face[0])


Measured memory_bytes: 5608
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX (1 << 29)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x);
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x);
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i) cin >> vec[i];
}

int main() {
  int W, H;
  cin >> W >> H;
  ll ans = 0;
  priority_queue<Pi, vector<Pi>, greater<Pi>> q;
  FOR(i, W) {
    int a;
    cin >> a;
    q.push(Pi(a, 0));
  }
  FOR(i, H) {
    int a;
    cin >> a;
    q.push(Pi(a, 1));
  }
  int hor = H + 1, ver = W + 1;
  while (!q.empty()) {
    Pi p = q.top();
    q.pop();
    if (p.second == 0) {
      ans += (ll)p.first * hor;
      ver--;
    } else {
      ans += (ll)p.first * ver;
      hor--;
    }
  }
  print(ans);
  return 0;
}

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

using db = long double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

struct poi {
	db x, y;
	poi op -(poi p) {
		return {x - p.x, y - p.y};
	}
	db cross(poi p) {
		return x * p.y - y * p.x;
	}
}p[53];

int main() {
	cout << fixed << setprecision(1);
	ios :: sync_with_stdio(0);

	int _ = 0;
	for(int n; cin >> n && n; ) {
		for(int i = 0; i < n; i ++)
			cin >> p[i].x >> p[i].y;
		p[n] = p[0];
		db ans = 0;
		for(int i = 0; i < n; i ++)
			ans += p[i].cross(p[i + 1]);
		cout << ++ _ << ' ' << -ans / 2 << '\n';
	}

	return 0;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	long long A[100000];
	long long cnt = 0;
	long long ans = 0;
	long long tmp;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (i == 0) tmp = abs(A[0]);
		else if (abs(A[i]) < tmp) tmp = abs(A[i]);
		if (A[i] < 0) cnt++;
		ans += abs(A[i]);
	}
	if (cnt % 2 == 1) ans = ans - 2 * tmp;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int32 i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int32 i = (b) - 1; i >= (a); --i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define C(x) cout << #x << ":" << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;

template<typename Monoid, typename Operand>
class SegTree {
public:
	Monoid* tree;
	size_t size;
	int32 i;
	//?????????????????????
	SegTree(size_t length) {
		--length;
		size = length;
		if (size & 0xffff0000) { size = size & 0xffff0000; }
		if (size & 0xff00ff00) { size = size & 0xff00ff00; }
		if (size & 0xf0f0f0f0) { size = size & 0xf0f0f0f0; }
		if (size & 0xcccccccc) { size = size & 0xcccccccc; }
		if (size & 0xaaaaaaaa) { size = size & 0xaaaaaaaa; }
		if (length) { size <<= 1; }
		else { size = 1; }
		tree = (Monoid *)calloc(size << 1, sizeof(Monoid));
	}
	//?????????
	void set(bool merge) {
		i = size << 1;
		while (--i) { tree[i].set(); }
		if (merge) {
			i = size;
			while (--i) { tree[i] = tree[i << 1] + tree[i << 1 | 1]; }
		}
	}
	//tree[index]???data????§????´????°
	void update(size_t index, Operand &data) {
		index += size;
		tree[index] = tree[index] * data;
		while (index >>= 1) tree[index] = tree[index << 1] + tree[index << 1 | 1];
	}
	//[begin,end)??????????????????
	Monoid range(size_t begin, size_t end) {
		Monoid retL, retR;
		for (begin += size, end += size; begin < end; begin >>= 1, end >>= 1) {
			if (begin & 1) retL = retL + tree[begin++];
			if (end & 1)  retR = tree[end - 1] + retR;
		}
		return retL + retR;
	}
};
struct SUB {
	uint32 e;
	SUB() { set(); }
	SUB(uint32 x) { e = x; }
	void set() { e = 1000000000; }
	SUB operator*(const SUB &other) {
		return other;
	}
};
struct MIN {
	uint32 e;
	MIN() { set(); }
	MIN(uint32 x) { e = x; }
	void set() { e = 2147483647; }
	MIN operator+(const MIN &other) {
		if (e < other.e) return *this;
		return MIN(other.e);
	};
	MIN operator*(const SUB &other) {
		return MIN(other.e);
	}
};

int main() {
	uint32 n, l;
	cin >> n >> l;
	if (n > 1000000) { return 0; }
	SUB a;
	SegTree<MIN, SUB> t(n);
	rep(i, 0, n) {
		cin >> a.e;
		t.update(i, a);
	}
	printf("%d", t.range(0, l).e);
	rep(i, 1, n - l + 1)
		printf(" %d", t.range(i, i + l).e);
	printf("\n");
	return 0;
}

Measured memory_bytes: 18848
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A,B=[],[]
for _ in range(n):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
A.sort()
B.sort()
if n%2==1:
  l=A[n//2]
  r=B[n//2]
  print(r-l+1)
else:
  l=A[n//2-1]+A[n//2]
  r=B[n//2-1]+B[n//2]
  print(r-l+1)


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    int N; cin >> N;
    vec p(N);
    rep(i, N) cin >> p[i];
    int res = 0;
    rep(i, N-2){
        if(p[i] < p[i+1] && p[i+1] < p[i+2]) res++;
        if(p[i] > p[i+1] && p[i+1] > p[i+2]) res++;
    }
    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main(void){
    int a,b,h;cin>>a>>b>>h;
    cout<<double(a+b)*h/2<<endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	ll N,M;
	cin>>N>>M;
	ll ans = 0;

//先にsを使い切ろうとする
	//cが余るならcを4で割った商を追加
	if(2*N<=M){
		ans+=N;
		M-=2*N;
		ans+=M/4;
	}
	//sが余るならそれで終わり
	else{
		if(2*N>M){
			ans+=M/2;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!
N = int(input())
W = list(map(int,input().split()))
S = sum(W)
ans = float('inf')
for i in range(1,N):
    l = sum(W[:i+1])
    r = S - l
    ans = min(ans, abs(l-r))

print(ans)

Measured memory_bytes: 9196
#include <iostream>

using namespace std;

int main()
{
	int A, B, C;
	bool flag = false;

	cin >> A >> B >> C;

	for(int i = 0; i < A * B; i++)
	{
		if (A * i % B == C)
		{
			flag = true;
			break;
		}
	}

	if (flag == true)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

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

typedef long long LL;

const int N=128,C=62;
const char s[C+9]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

void Print(string s){cout<<"? "<<s<<endl;}

void Print(char c,int n){
  cout<<"? ";
  for (int i=1;i<=n;++i) cout<<c;
  cout<<endl;
}

int cnt[C+9],sum;

string Divide_ans(int l,int r){
  string res;
  if (l==r){
	for (int i=1;i<=cnt[l];++i) res=res+s[l];
	return res;
  }
  int mid=l+r>>1;
  string a,b;
  a=Divide_ans(l,mid);
  b=Divide_ans(mid+1,r);
  if (a.empty()) return b;
  if (b.empty()) return a;
  string suf=a;
  int i=0,j=0;
  for (;i<a.size();++i){
	for (;j<b.size();++j){
	  Print(res+b[j]+suf);
	  int x;
	  cin>>x;
	  if (x^sum-(res+b[j]+suf).size()) break;
	  res=res+b[j];
	}
	res=res+a[i];
	suf.erase(suf.begin());
  }
  for (;j<b.size();++j) res=res+b[j];
  return res;
}

void Get_cnt(){
  for (int i=0;i<C;++i){
	Print(s[i],N);
	cin>>cnt[i];
	sum+=cnt[i]=N-cnt[i];
  }
}

string ans;

void Get_ans(){
  ans=Divide_ans(0,C-1);
  cout<<"! "<<ans<<endl;
}

void getans(){
  Get_cnt();
  Get_ans();
}

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

Measured memory_bytes: 3804
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    h.append(int(input()))

def enough(t):
    tmp=0
    for i in range(n):
        if h[i]>b*t:
            tmp+=(h[i]-b*t)//(a-b)+(1 if (h[i]-b*t)%(a-b)>0 else 0)
    return True if tmp<=t else False

ok=max(h)
ng=0
mid=(ok-ng)//2
while abs(ok-ng)>1:
    if enough(mid):
        ok=mid
    else:
        ng=mid
    mid=(ok+ng)//2
print(ok)

Measured memory_bytes: 13108
#include <bits/stdc++.h>
#define NMAX 200020
using namespace std;
unsigned long long k,n,i,dist,sum,max1;
unsigned long long v[NMAX];
int main()
{
    cin>>k>>n;
    for(i=1; i<=n; i++)
        cin>>v[i];
    for(i=2; i<=n; i++)
    {
        dist=v[i]-v[i-1];
        if(dist>=max1)
            max1=dist;
        sum+=dist;
    }
    dist=k-v[n]+v[1];
    if(dist>=max1)
        max1=dist;
    sum+=dist;
    cout<<sum-max1<<' ';
    return 0;
}


Measured memory_bytes: 1792
($n,$m)=glob<>;$"for@a=<>;for$i(0..$n-1){($a,$b)=glob$a[$i];$d=1e9;for$j(1..$m){$a[$n+$j-1]=~$",$d>($k=abs($a-$`)+abs($b-$'))&&($d=$k,$p=$j)}print$p,$/}

Measured memory_bytes: 768
#include <stdio.h>

int main(void){
	double seq[11] , sum;
	int i;
	while(scanf("%lf" , &seq[1])!=EOF){
		i = 2;
		while(i<=10){
			if(i%2==0){
				seq[i] = seq[i-1] * 2;
			}else{
				seq[i] = seq[i-1] / 3;
			}
			i++;
		}
		sum = 0;
		for(i=1;i<=10;i++){
			sum += seq[i];
		}
		printf("%.8f\n" , sum);
	}
	return 0;
}

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

int main() {
  int a,b,c; cin>>a>>b>>c;
  bool frag = false;
  rep(i, 101) if ((b*i+c)%a==0) frag = true;
  if (frag) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        long[] a = cin.arrayLong();
        long[] b = new long[N];

        for (int i = 1; i <= N; i++)
        {
            b[i - 1] = a[i - 1] - i;
        }

        Array.Sort(b);
        long m = 0;
        if (N % 2 == 0)
        {
            m = (b[N / 2 - 1] + b[N / 2]) / 2;
        }
        else
        {
            m = b[N / 2];
        }


        long ret = 0;
        for (int i = 0; i < N; i++)
        {
            ret += Math.Abs(b[i] - m);
        }
        Console.WriteLine(ret);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

Measured memory_bytes: 34780
from itertools import product
def solve():
    N,A,B,C = map(int,input().split())
    models = [A,B,C]
    l = [int(input()) for _ in range(N)]

    comb = list(product([-1,0,1,2],repeat=N))

    mn = float('inf')
    for c in comb:
        sm = 0
        for i in range(3):
            elements = []
            for j in range(N):
                if c[j] == i:
                    elements.append(l[j])
            
            if len(elements) == 0:
                break
            sm += (len(elements) - 1) * 10
            sm += abs(models[i] - sum(elements))
        else:
            mn = min(mn, sm)
    
    print(mn)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 50868
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }

    ll res = 0, right = 0, sum = 0;
    for (int left = 0; left < N; left++) {
        while (right < N && (sum ^ A[right]) == (sum + A[right])) {
            sum += A[right];
            right++;
        }

        res += right - left;
        if (left == right)
            right++;
        else
            sum -= A[left];
    }

    cout << res << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int mod = 1000000007;
  ll sum = 0;
  rep(i,n) {
    cin >> a[i];
    sum += a[i];
    sum %= mod;
  }

  ll ans = 0;

  rep(i,n) {
    sum -= a[i]%mod;
    if (sum < 0) sum += mod;
    ans += a[i]*sum;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4044
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll n,k,x,y;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>n>>k>>x>>y;
	if(n<=k)
	cout<<x*n;
	else
	cout<<((x*k)+(y*(n-k)));
	return 0;
}


Measured memory_bytes: 256
//     THE ONLY WAY IS UP

#include<bits/stdc++.h>

#define ll              long long int
#define ld              long double
#define f1(i, a, b)     for(ll i = a; i < b; i++)
#define f2(a, b)        for(auto a : b)
#define ar(v, i)        v[i]
#define in_(x)          ll x; cin >> x;
#define ino_(type, x)   type x; cin >> x;
#define pb              push_back

using namespace std;

int main()
{
    string s;
    cin >> s;
    
    if(s[2] == ar(s, 3) && ar(s, 4) == ar(s, 5))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

using namespace std;

//#define int long long

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define DEL(v, n) v.erase(v.begin() + (n))

struct ipt
{
    int a;
    int b;
    int c;
};

//0-?
//1-OK
//2-NO
int D[310];

signed main()
{
    while(true)
    {
        int A,B,C,N;
        cin >> A >> B >> C;

        if(A == 0 && 
        B == 0 &&
        C == 0)
        {
            break;
        }

        cin >> N;

        memset(D, 0, 310 * 4);

        vector<ipt> ipts;
        REP(i, N)
        {
            int a,b,c,d;
            cin >> a >> b >> c >> d;
            a--;
            b--;
            c--;
            if(d)
            {
                D[a] = 1;
                D[b] = 1;
                D[c] = 1;
            }
            else
            {
                ipts.push_back({a,b,c});
            }
        }

        REP(i, ipts.size())
        {
            if(D[ipts[i].a] == 1 &&
            D[ipts[i].b] == 1)
            {
                D[ipts[i].c] = 2;
            }
            if(D[ipts[i].c] == 1 &&
            D[ipts[i].b] == 1)
            {
                D[ipts[i].a] = 2;
            }
            if(D[ipts[i].a] == 1 &&
            D[ipts[i].c] == 1)
            {
                D[ipts[i].b] = 2;
            }
        }

        REP(i, A + B + C)
        {
            cout << (2 - D[i]) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <vector>
using namespace std;
enum Card { S, H, C, D };
char pic[4] = { 'S','H','C','D' };
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	vector<vector<bool>> card(4, vector<bool>(13,false));
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		char c; int v; cin >> c >> v;
		int key = c == 'S' ? S : c == 'H' ? H : c == 'C' ? C : D;
		card[key][v - 1] = true;
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (!card[i][j]) { cout << pic[i] << " " << j + 1 << endl; }
		}
	}
}

Measured memory_bytes: 3088
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main(){
   int N,M;
   cin>>N>>M;
   int sum=0;
   for(int i=0;i<M;i++){
      int A;
      cin>>A;
      sum+=A;
    }
    if(N>=sum){
        cout<<N-sum<<endl;
    }
    else{
        cout<<"-1"<<endl;
    }
}


Measured memory_bytes: 3644
from itertools import product
N = int(input())
G = {i:[] for i in range(1,N+1)}
for i in range(1,N+1):
    K = int(input())
    for j in range(K):
        G[i].append(list(map(int,input().split())))
cmax = 0
for z in product((0,1),repeat=N):
    flag = 0
    for i in range(N):
        if z[i]==1:
            ind = i+1
            for [x,y] in G[ind]:
                if z[x-1]==y:continue
                else:
                    flag=1
                    break
            if flag==1:
                break
    if flag==0:
        cmax = max(cmax,sum(z))
print(cmax)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

    ll n;cin >> n;
    string str;cin >> str;
    REP(i, str.size()){
        cout << (char)('A' + (str[i] - 'A' + n) % 26);
    }
    cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 驍ｨ・ｶ陝・ｽｾ陋滂ｽ､雎弱ｅ・∫ｹｧ繝ｻ笆ｽ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;

int main(){
  int n;
  cin>>n;
  vector<int> A(n);
  rep(i,n){
    cin>>A[i];
  }
  vector<int> B(n+1);
  rep(i,n){
    int a = A[i];
    //i+1番目の生徒はa番目に登校した
    B[a]=i+1;
  }
  for(int i = 1; i<n+1; i++){
    cout<<B[i]<<" ";
  }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
int main(){
  int n; cin>>n;
  vector<int> a(n); rep(i,n) cin>>a[i];
  int q; cin>>q;
  bool dp[40100];
  rep(i,40100) dp[i]=false;
  dp[0]=true;
  rep(i,1<<n){
    int sum=0;
    rep(j,n){
      if(i>>j&1) sum+=a[j];
    }
    dp[sum]=true;
  }
  vector<int> m(q);
  rep(i,q){
    int m; cin>>m;
    if(dp[m]) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
}



Measured memory_bytes: 3136
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; }
#define rndf(d) (ll)((double)(d) + (d >= 0 ? 0.5 : -0.5))
#define floorsqrt(x) ((ll)sqrt((double)x) + ((ll)sqrt((double)x) * (ll)sqrt((double)x) <= (ll)(x) ? 0 : -1))
#define ceilsqrt(x) ((ll)sqrt((double)x) + ((ll)x <= (ll)sqrt((double)x) * (ll)sqrt((double)x) ? 0 : 1))
#define rnddiv(a, b) ((ll)(a) / (ll)(b) + ((ll)(a) % (ll)(b) * 2 >= (ll)(b) ? 1 : 0))
#define ceildiv(a, b) ((ll)(a) / (ll)(b) + ((ll)(a) % (ll)(b) == 0 ? 0 : 1))
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)

/*******************************************************/

int main() {
	int n; cin >> n;
	vll a(n); Loop(i, n) cin >> a[i];
	ll sum = 0;
	int l = 0;
	int r = 0;
	ll ans = 0;
	while(l < n) {
		if (r < n && (sum & a[r]) == 0) {
			sum += a[r];
			r++;
		}
		else {
			ans += r - l;
			sum -= a[l];
			l++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(){

	int n; 
	scanf("%d", &n);
	int i;
		long long int sum=0;
		
		for (i = 1;i <= n; i++){
			if (i % 3 != 0 && i % 5 !=0){
				sum +=i;
			}
		}

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

Measured memory_bytes: 1712
import java.util.*;

class Main
{
    public  static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        int[] array = new int[n];
        for (int i = 0; i < array.length; i++) {
            array[i] = sc.nextInt();
        }
        
        Arrays.sort(array);
        
        int money = 0;
        for (int i = 0; i < k; i++) {
            money += array[i];
        }
        
        System.out.println(money);
    }
}

Measured memory_bytes: 38748
#include <iostream> // cout, endl, cin
#include <cmath>    //sin, cos, tan
#include <vector>   // vector
#include <iomanip>  //setprecsion
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
using namespace std;
const double PI = acos(-1.0);

int main(void)
{
  int n;
  long long int M = -900000000, m = 900000000, sum = 0;
  cin >> n;
  for(int i = 0;i < n;i++)
  {
    long long int a;
    cin >> a;
    sum += a;
    M = max(M, a);
    m = min(m, a);
  }
  cout << m << " " << M << " " << sum << endl;
  return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>

using namespace std;

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

int main(){
	int k, x;
	cin >> k >> x;
	for(int i = max(-1000000, x - k + 1); i <= min(1000000, x + k - 1); i++){
		cout << i << " ";
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n,m,c[20];
int dp[20][50001];

int rec(int coin,int money) {
	if(coin == -1) return money;
	if(dp[coin][money] == -1) {
		dp[coin][money] = rec(coin-1,money);
		if(money >= c[coin]) dp[coin][money] = min(dp[coin][money],1+rec(coin,money-c[coin]));
	}
	return dp[coin][money];
}

int main() {
	cin >> n >> m;
	for(int i = 0;i < m;i++) cin >> c[i];
	for(int i = 0;i < 20;i++)for(int j = 0;j < 50001;j++) dp[i][j] = -1;
	cout << rec(m-1,n) << endl;
}



Measured memory_bytes: 9340
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll r,d,x;cin>>r>>d>>x;
    ll a[11];
    a[0]=x;
    for(int i=1;i<=10;i++){
        a[i]=r*a[i-1]-d;
        cout<<a[i]<<"\n";
    }
}


Measured memory_bytes: 3652