akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
import itertools
import sys

N, M, X  = map(int, input().split())
money = []
A = []
ans = []
for _ in range(N):
    nums = [int(x.strip()) for x in input().split(' ') ]
    money.append(nums[0])
    nums.pop(0)
    A.append(nums)
num_money = []
for index, num in enumerate(money):
    num_money.append(index)
    
def run(lis, num, A, X, M, ans, money):
    ans_list = []
    for team in itertools.combinations(lis, num):
        count = 0
        for i in range(M):
            tmp = 0
            for j in list(team):
                tmp += A[j][i]
            if tmp >= X:
                count += 1
        if count == M:
            tmp_ans = []
            for n in list(team):
                tmp_ans.append(money[n])
            ans_list.append(sum(tmp_ans))
    if not len(ans_list) == 0:
        ans.append(min(ans_list))
    
    return ans
        
for i in range(1, N+1):
    ans = run(num_money, i, A, X, M, ans, money)
    
if not len(ans) == 0:
    print(min(ans))
    
else:
    print(-1)

Measured memory_bytes: 9276
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;
int main(){
  ll n,m,ans=1; cin>>n >>m;
  if(abs(n-m)>1){
    cout<<0<<endl;
    return 0;
  }
  if(n==m)ans=2;
  for(int i=1;i<=n;i++){
    ans*=i;
    ans%=mod;
  }
  for(int i=1;i<=m;i++){
    ans*=i;
    ans%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

struct edge{
  ll to, cost;
};

int MAX_V = 2020;
vector<vector<edge>> G(MAX_V);
vector<ll> ans(2020, 0);

void dijkstra(int s, vector<ll> d) {
	priority_queue<P, vector<P>, greater<P>>que;
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		rep(i, G[v].size()) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
                if(s < e.to)ans[d[e.to]]++;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
int main() {
    ll n, x, y;
    cin >> n >> x >> y;
    rep(i, n-1){
        G[i].push_back({i+1, 1});
        G[i+1].push_back({i, 1});
    }
    G[x-1].push_back({y-1, 1});
    G[y-1].push_back({x-1, 1});
    rep(i, n){
        vector<ll> d(n+1, inf);
        dijkstra(i, d);
    }
    rep(i, n-1)cout << ans[i+1] << endl;
}      

Measured memory_bytes: 384
#S=10^9y3-x3
S=int(input())
X1=0
Y1=0

X2=10**9
Y2=1

X3=S%X2
Y3=S//X2

#小さい数字で確認しておこう
if X3!=0:
    Y3+=1
    X3=X2-X3

#print(X2*Y3-Y2*X3)
print(X1,Y1,X2,Y2,X3,Y3)

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n,n){
        vector<pair<int,int> > rec(n);
        int l=0,r=0,u=0,b=0;
        rec[0].fr=0;rec[0].sc=0;
        int nn,d;
        REAP(i,1,n){
            cin >> nn >> d;
//            cout << nn <<" " << d<<endl;
            int x=rec[nn].fr;
            int y=rec[nn].sc;
            if(d==0)x--;
            if(d==1)y--;
            if(d==2)x++;
            if(d==3)y++;
            rec[i].fr=x;
            rec[i].sc=y;
            l=min(l,x);
            r=max(r,x);
            u=max(u,y);
            b=min(b,y);
        }
        cout << r+1-l <<" "<<u+1-b<<endl;
//        cout << r <<" "<<l << endl;
    }
}



Measured memory_bytes: 3032
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const lines = input.trim().split('\n');

while (line = lines.shift()) {

    const numbers = line.split(' ').map(Number);
    // Edit from here
    let a = numbers[0];
    let b = numbers[1];

    if ( a === 0 && b === 0 ) { break; }

    if ( a > b ) {
        const tmp = a;
        a = b;
        b = tmp;
    } 

    const output = a + ' ' + b;

    console.log(output);
    // to here
}




Measured memory_bytes: 18840
//ProblemB

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <memory>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

//ProblemB

#define MAXN 100

class Solve {
private:
	struct Point {
		int no;
		int x, y;
		double a;
	} p[MAXN];
	int n;

	double get_cos(const Point& a, const Point& b) {
		return double(b.x - a.x)
			/ sqrt((double(a.x - b.x) * double(a.x - b.x)
				+ double(a.y - b.y) * double(a.y - b.y)));
	}

	double get_cos(int x1, int y1, int x2, int y2) {
		return (double(x1) * x2 + double(y1) * y2)
			/ sqrt((double(x1) * x1 + double(y1) * y1) * (double(x2) * x2 + double(y2) * y2));
	}

	long long outer_prodect(int x1, int y1, int x2, int y2) {
		return (long long)(x1)* y2 - (long long)(x2)* y1;
	}

	void solve() {
		cin >> n;
		int mi = 0;
		for (int i = 0; i < n; i++) {
			cin >> p[i].x >> p[i].y;
			p[i].no = i;

			if (p[i].y < p[mi].y
				|| p[i].y == p[mi].y && p[i].x < p[mi].x) {
				mi = i;
			}
		}
		swap(p[0], p[mi]);

		if (n == 2) {
			cout << 0.5 << endl;
			cout << 0.5 << endl;
			return;
		}

		for (int i = 1; i < n; i++) {
			p[i].a = get_cos(p[0], p[i]);
		}
		sort(p + 1, p + n, [this](const Point& a, const Point& b) {
			if (abs(a.a - b.a) < 1e-7) return a.x < b.x;
			return a.a > b.a;
		});

		stack<Point> st;
		st.push(p[0]);
		st.push(p[1]);

		auto cur_x = p[1].x - p[0].x;
		auto cur_y = p[1].y - p[0].y;
		stack<pair<int, int>> st_xy;

		int ii = 2;
		while (ii < n) {
			auto top = st.top();
			auto outer = outer_prodect(cur_x, cur_y, p[ii].x - top.x, p[ii].y - top.y);

			if (outer >= 0) {
				st.push(p[ii]);
				st_xy.push({ cur_x, cur_y });
				cur_x = p[ii].x - top.x;
				cur_y = p[ii].y - top.y;
				ii++;
			}
			else {
				st.pop();
				cur_x = st_xy.top().first;
				cur_y = st_xy.top().second;
				st_xy.pop();
			}
		}

		vector<Point> v;
		while (!st.empty()) {
			v.push_back(st.top());
			st.pop();
		}
		v.push_back(v[0]);
		v.push_back(v[1]);

		for (int i = 0; i < n; i++) {
			p[i].a = 0;
		}
		double pi = acos(0) * 2;
		for (size_t i = 1; i < v.size() - 1; i++) {
			auto cos = get_cos(v[i].x - v[i - 1].x, v[i].y - v[i - 1].y,
				v[i].x - v[i + 1].x, v[i].y - v[i + 1].y);
			p[v[i].no].a = acos(- cos) / pi / 2;
		}

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

public:
	Solve() { solve(); }
};

int main(int argc, char* argv[]) {
	unique_ptr<Solve> solve = make_unique<Solve>();
	return 0;
}


Measured memory_bytes: 256
s = input()

s1 = int(s[0:2])
s2 = int(s[2:4])

check1 = ((s1 <= 12) & (s1 != 0))
check2 = ((s2 <= 12) & (s2 != 0))

if(check1):
    if(check2):
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if(check2):
        print('YYMM')
    else:
        print('NA')

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

template <int n>
struct UnionFind{
    UnionFind(){
        for(int i=0;i<n;i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int find(int x){
        if(x == par[x])return x;
        return par[x] = find(par[x]);
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y){return;}
        
        if(rank[x] > rank[y]){
            par[y] = x;
        }else{
            par[x] = y;
            if(rank[x] == rank[y]){rank[y]++;}
        }
    }
    int rank[n], par[n];
};

UnionFind<410*410> uf;
int cnt[410][410][2];
int H, W;
std::string S[410];

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

    std::cin >> H >> W;

    for(int i=0;i<H;++i){
        std::cin >> S[i];
    }

    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            for(int k=0;k<4;++k){
                int s = i + dy[k],
                    t = j + dx[k];
                if(0 <= s && s < H && 0 <= t && t < W &&
                   S[i][j] != S[s][t]){
                    uf.unite(i * W + j, s * W + t);
                }
            }
        }
    }

    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            int k = uf.find(i * W + j),
                s = k / W, t = k % W;
            if(S[i][j] == '#'){
                cnt[s][t][0] += 1;
            }else{
                cnt[s][t][1] += 1;
            }
        }
    }

    ll res = 0;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            res += 1ll * cnt[i][j][0] * cnt[i][j][1];
        }
    }

    std::cout << res << std::endl;
}


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

using namespace std;

bool count(int a){
	int c = 0;
	while(a){
		a /= 10;
		c++;
	}
	if(c%2 == 0) return false;
	else return true;
}
int
main(void){
	int n; cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(count(i)) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
n,q=map(int,input().split())
s=input()+" "
A=[0]*(n+1)
cnt=0
for i in range(1,n+1):
    if s[i-1]+s[i]=="AC":
        cnt +=1
    A[i]=cnt

for i in range(q):
    l,r=map(int,input().split())
    print(A[r-1]-A[l-1])

Measured memory_bytes: 6084
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {			cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

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


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

int kx[] = {0, -1, +1, -2, +2};
int ky[] = {0, -1, +1, -2, +2};

const int mx = 1e3+123;
char c[mx][mx];
int dist[mx][mx], n, m;

void dijkastra ( int sx, int sy )
{
	for ( int i = 1; i <= n; i++ ) {
		for ( int j = 1; j <= m; j++ ) dist[i][j] = inf;
	}

	priority_queue<pair<int, pair<int,int>>, vector<pair<int, pair<int,int>>>, greater<pair<int, pair<int,int>>>> q;

	q.push ( { 0, { sx, sy } } );
	dist[sx][sy] = 0;


	while ( !q.empty() ) {
		int cost = q.top().F;
		int x = q.top().S.F;
		int y = q.top().S.S;
		q.pop();

		if ( cost > dist[x][y] ) continue;

		for ( int i = 0; i < 4; i++ ) {
			int x1 = x + dx[i];
			int y1 = y + dy[i];

			if ( x1 >= 1 && x1 <= n && y1 >= 1 && y1 <= m && c[x1][y1] != '#' && cost < dist[x1][y1] ) {
				dist[x1][y1] = cost;
				q.push ( { dist[x1][y1], {x1, y1} } );
			}
		}

		for ( int i = 0; i < 5; i++ ) {
			for ( int j = 0; j < 5; j++ ) {
				int x1 = x + kx[i];
				int y1 = y + ky[j];

				if ( x1 >= 1 && x1 <= n && y1 >= 1 && y1 <= m && c[x1][y1] != '#' && cost+1 < dist[x1][y1] ) {
					dist[x1][y1] = cost+1;
					q.push ( { dist[x1][y1], {x1, y1} } );
				}
			}
		}

	}
}

int main()
{
	optimize();

	cin >> n >> m;

	int sx, sy, ex, ey;
	cin >> sx >> sy >> ex >> ey;

	for ( int i = 1; i <= n; i++ ) {
		for ( int j = 1; j <= m; j++ ) {
			cin >> c[i][j];
		}
	}

	dijkastra ( sx, sy );
	if ( dist[ex][ey] == inf ) dist[ex][ey] = -1;
	cout << dist[ex][ey] << endl;


	return 0;
}

















Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
typedef long long int i64;
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(__attribute__((unused)) istream_iterator<string> it) {}
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl; err(++it, args...); }
template<typename T1,typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& buf) {
  return os << "(" << buf.first << ": " << buf.second << ")"; }
#define DefOut(Con) template<typename T>ostream&operator<<(ostream&os,Con<T>&A){ bool f = false; os << "{"; \
  for (auto &e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
#define DefOut2(Con) template<typename K,typename V>ostream&operator<<(ostream&os,Con<K,V>&A) \
{ bool f = false; os << "{"; for (auto &e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
template<typename T>ostream &operator << (ostream &os,vector<vector<T>>& A) {
  for (auto &B: A) os << '\n' << B; return os; }
DefOut(vector) DefOut(set) DefOut(multiset) DefOut2(map) 
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1000000007;
long long const INF = 1e18;
#define PI 3.14159265358979323846
/***********************************************************************/
struct DSU {
  vector<int> par;
  int num;
  DSU(int n) {
    par.resize(n);
    iota(par.begin(), par.end(), 0);
    num = n;
  }
  inline int find(int u) {
    return (u == par[u] ? u : par[u] = find(par[u]));
  }
  inline bool merge(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return false;
    if (rand() % 2) swap(u, v);
    par[v] = u;
    num--;
    return true;
  }
};

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;
  auto uf = DSU(n);
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    --x; --y;
    uf.merge(x, y);
  }
  cout << uf.num << '\n';
  
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <queue>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n,q,w,i;
  cin>>n;
  while(n--){
    string a,b;
    cin>>a;
    if(a[2]=='p'){
      int c=0;
      cin>>q>>w>>b;
      for(i=q;i<=w;i++)s[i]=b[c++];
    }
    else if(a[2]=='v'){
      int c=0;
      cin>>q>>w;
      for(i=q;i<=w;i++)b[c++]=s[i];
      for(c=0,i=w;i>=q;i--)s[i]=b[c++];
    }
    else{
      cin>>q>>w;
      for(i=q;i<=w;i++)cout<<s[i];
      cout<<endl;
    }
  }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define ll long long int
#define N 5005
using namespace std;
int vis[N];
ll dp[N],per[N],col[N],dist[N];
ll ans=-1e18;
void solveD(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>per[i];
    for(int i=1;i<=n;i++){
        cin>>col[i];
        ll here=col[i];
        if(per[i]==i) here*=k;
        ans=max(ans,here);
    }
    for(int i=1;i<=n;i++){
        queue<int>q;
        q.push(i);
        fill(vis,vis+n+1,0);
        fill(dist,dist+n+1,0);
        fill(dp,dp+n+1,0);
        ll mx=-1e18,sum=0;
        dist[i]=0;
        int node=i;
        while(1){
            int x=q.front();
            q.pop();
            int y=per[x];
            if(vis[y]) break;
            dist[y]=dist[x]+1;
            sum+=col[y];
            dp[y]=dp[x]+col[y];
            q.push(y);
            vis[y]=1;
            if(sum>mx){
                mx=sum;
                node=y;
            }
        }
        int mxd=dist[i];
        if(k<=mxd){
            for(int j=1;j<=n;j++){
                if(dist[j]<=k && dist[j]>0) ans=max(ans,dp[j]);
            }
            continue;
        }
        ans=max(ans,mx);
        int steps=k/mxd;
        for(int j=1;j<=n;j++){
            if(dist[j]>0) ans=max(ans,dp[j]);
        }
        ll tot=0;
        if(dp[i]>0) tot=(steps*1LL)*dp[i];
        int kk=k%mxd;
        ll here=0;
        for(int j=1;j<=n;j++){
            if(dist[j]<=kk && dist[j]>0) here=max(here,dp[j]);
        }
        tot+=here;
        tot=max(tot,(steps-1)*dp[i]+mx);
        ans=max(ans,tot);
    }
    cout<<ans;
}
int main()
{
    solveD();
    return 0;
}


Measured memory_bytes: 3812
#include <cstdio>

using namespace std;

const int MAX_N = 10000;
const int MAX_Q = 500;
int n, S[MAX_N], q, T[MAX_Q];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &S[i]);
  scanf("%d", &q);
  int answer = 0;
  for (int i = 0; i < q; i++) {
    scanf("%d", &T[i]);
    for (int j = 0; j < n; j++) {
      if (S[j] == T[i]) {
        answer++;
        break;
      }
    }
  }

  printf("%d\n", answer);
}

Measured memory_bytes: 2704
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
ll hist[4][4][4][100];
//0:A 1:G 2:C 3:T
ll dp(int _1,int _2,int _3,ll num,ll maxnum){
  ll n=0;
  if(maxnum==num)return 1;
  ll h=hist[_1][_2][_3][num];
  if(h!=-1)return h;
  //A追加
  n+=dp(_2,_3,0,num+1,maxnum);
  //G
  if(!(_2==0&&_3==2)){
    n+=dp(_2,_3,1,num+1,maxnum);
  	n%=1000000007ll;
  }
  //C
  if(!((_1==0&&_3==1)||(_1==0&&_2==1)||
       (_2==0&&_3==1)||(_2==1&&_3==0))){
    n+=dp(_2,_3,2,num+1,maxnum);
  	n%=1000000007ll;
  }
  //T
  n+=dp(_2,_3,3,num+1,maxnum);
  hist[_1][_2][_3][num]=n;
  return n%1000000007ll;
}
int main(){
  ll N;
  cin>>N;
  for(int i=0;i<4;i++){
  for(int ii=0;ii<4;ii++){
  for(int iii=0;iii<4;iii++){
  for(int iiii=0;iiii<100;iiii++){
    hist[i][ii][iii][iiii]=-1;
  }}}}
    
  cout<<dp(3,3,3,0,N)<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        System.out.println(IntStream.range(0, scanner.nextInt()).map(i -> scanner.nextInt()).filter(i -> i % 2 == 1).count() % 2 == 0 ? "YES" : "NO");
    }
}

Measured memory_bytes: 52596
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec) {
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

#define solvsh
//#define multi
#ifdef solvsh

#define LOG(FMT...) fprintf(stderr, FMT)

const int INF = 1e9;

ll mod = 1e9 + 7;

ll ml(ll a, ll b){
    return(a * b) % mod;
}

ll add(ll a, ll b) {
    return (a + b) % mod;
}

const int MAXN = 1e7 + 20;

int cnts[MAXN];

bool is_prime[MAXN];

int l_p[MAXN];

void prec() {


    for (int i = 2; i < MAXN; ++i) {
        is_prime[i] = true;
    }

    l_p[1] = 1;

    for (int i = 2; i < MAXN; ++i) {
        if (!is_prime[i])
            continue;

        l_p[i] = i;

        for (int j = 2 * i; j < MAXN; j += i) {
            is_prime[j] = false;
            l_p[j] = i;
        }
    }


    for (int i = 1; i < MAXN; ++i) {
        int cnt = 1;

        int x = i;

        while (x != 1) {
            int deg = 0;
            int p = l_p[x];
            while (x % p == 0) {
                ++deg;
                x /= p;
            }

            cnt *= 1 + deg;
        }
        cnts[i] = cnt;
    }
}

void solve() {

    prec();

    ll n;
    cin >> n;

    ll answr = 0;

    for (ll i = 1; i <= n; ++ i){
        answr += i * cnts[i];
    }

    cout << answr;
}


#else

void solve() {

}

#endif


void multisolve() {
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Mission #" << (i++) << ": \n";

        solve();
//        cout << "\n";
    }
}



#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);


#ifdef multi
//    gen();

//    doo();

    multisolve();
#else
    solve();
    //    gen();
#endif

}


Measured memory_bytes: 91540
N = int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

num_li = make_divisors(N)
n = len(num_li)

if n == 2: #素数の時
    print(num_li[1]-1)
elif n%2 == 1:
    print((num_li[(n-1)//2]-1)*2)
else:
    print((num_li[n//2]-1)+(num_li[n//2-1]-1))

Measured memory_bytes: 3344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

	ll sum = 0;
	for (int i = 0; i < N.length(); i++) {
		sum += N[i] - '0';
	}
	if (sum % 9 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int Mergesort(int *v, int left, int right)
{
    if(right - left <= 1) return 0;
    int res = 0, n = right - left - 1;
    int mid = (left + right) / 2;
    res += Mergesort(v, left, mid);
    res += Mergesort(v, mid, right);
    int buf[n];
    int idx = 0;
    for(int i = left; i < mid; i++) { buf[idx] = v[i], idx++; }
    for(int i = right - 1; i >= mid; i--) { buf[idx] = v[i], idx++; }
    int posL = 0, posR = n;
    for(int i = left; i < right; i++)
    {
        if(buf[posL] <= buf[posR]) { v[i] = buf[posL++]; }
        else { v[i] = buf[posR--]; }
    }
    return res + right - left;
} 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int A[n + 1];
    for(int i = 0; i < n; i++) cin >> A[i];
    int res = Mergesort(A, 0, n);
    for(int i = 0; i < n; i++)
    {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << "\n" << res << "\n";
    return 0;
}




Measured memory_bytes: 6984
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

bool solve(vector<int> &A, int m, ll K) {
  int N = A.size();
  vector<int> B(N);
  REP(i,N) B[i] = A[i] % m;
  sort(B.begin(), B.end());
  ll suml = 0, sumr = 0;
  int left = 0, right = N-1;
  while(left <= right) {
    if(suml <= sumr) {
      suml += B[left++];
    } else {
      sumr += m - (B[right--]);
    }
  }
#ifdef DEBUG
  pp(B, B.size());
  cout << m << " " << suml << " " << sumr << " " << K << endl;
#endif
  return suml + sumr <= 2LL * K;
}

int main() {
  int N; cin>>N;
  ll K ; cin>>K;
  vector<int> A(N); 
  int sum = 0;
  REP(i,N) {
    cin>>A[i];
    sum += A[i];
  }
  vector<int> p;
  for(int i = 1; i * i <= sum; i++) {
    if(sum % i == 0) {
      p.push_back(i);
      int r = sum / i;
      if(i != r) p.push_back(r);
    }
  }
  sort(p.begin(), p.end());
#ifdef DEBUG
  pp(p, p.size());
#endif
  for(int i = p.size() - 1; i >= 0; i--) {
    if(solve(A, p[i], K)) {
      cout << p[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  if (k > (n - 1) * (n - 2) / 2) return cout << -1 << '\n', 0;
  V< pair<int, int> > res;
  for (int j = 0; j < n; ++j) for (int i = 0; i < j; ++i) {
    res.emplace_back(i, j);
  }
  cout << n * (n - 1) / 2 - k << '\n';
  for (int i = k; i < n * (n - 1) / 2; ++i) {
    cout << res[i].first + 1 << ' ' << res[i].second + 1 << '\n';
  }
}

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

using namespace std;

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

    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            if (n == i * j) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>

int dp[201][201][201];

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    int k;
    std::cin >> k;
    long long sum = 0;
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
                if(dp[a][b][c] != 0){
                    sum += dp[a][b][c];
                }else if(dp[a][c][b] != 0){
                    sum += dp[a][c][b];
                }else if(dp[b][a][c] != 0){
                    sum += dp[b][a][c];
                }else if(dp[b][c][a] != 0){
                    sum += dp[b][c][a];
                }else if(dp[c][a][b] != 0){
                    sum += dp[c][a][b];
                }else if(dp[c][b][a] != 0){
                    sum += dp[c][b][a];
                }else{
                    int tmp = euclidean_gcd(a, b);
                    dp[a][b][c] = euclidean_gcd(tmp, c);
                    sum += dp[a][b][c];
                }
            }
        }
    }

    std::cout << sum << std::endl;

    return 0;
}


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


int main(){
    int mod=1e9+7;
    string s;
    cin>>s;
    ll dp[110000][4];
    
    dp[0][0]=1;
    rep(i,s.size()){
        if(s[i]=='A')
            dp[i+1][1]+=dp[i][0];
        
        if(s[i]=='B')
            dp[i+1][2]+=dp[i][1];
        
        if(s[i]=='C')
            dp[i+1][3]+=dp[i][2];
        
        if(s[i]=='?'){
            dp[i+1][1]+=dp[i][0];
            dp[i+1][2]+=dp[i][1];
            dp[i+1][3]+=dp[i][2];
            rep(j,4)dp[i+1][j]+=3*dp[i][j];
        }
        else rep(j,4)dp[i+1][j]+=dp[i][j];
        dp[i+1][0]%=mod;
        dp[i+1][1]%=mod;
        dp[i+1][2]%=mod;
        dp[i+1][3]%=mod;
    }
    cout<<dp[s.size()][3]<<endl;
    
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#define debug freopen("1.in","r",stdin),freopen("1.out","w",stdout);
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int n, k;

int main(){
    ios;
    cin >> n >> k;
    cout << n - k + 1;

    return 0;
}

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

int main(){
  string s,t;
  bool flag = 1;
  cin >> s;
  t=s;
  reverse(t.begin(),t.end());
  if (s!=t) flag=0;
  int n = s.size();
  string a,b,c,d;
  a = s.substr(0,(n-1)/2);
  b = a;
  reverse(b.begin(),b.end());
  c = t.substr(0,(n-1)/2);
  d = c;
  reverse(c.begin(),c.end());
  if(a!=b) flag = 0;
  if(c!=d) flag = 0;
  cout << (flag?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
#define mod (1000000007)
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
void solve() 
{
    int n;cin>>n;
    ll sum0=0,sum=1;
    map<Pll,P>cnt;
    for(int i=0;i<n;i++){
        ll a,b;cin>>a>>b;
        if(a==0&&b==0){
            sum0++;
            continue;
        }
        ll G=gcd(a,b);
        a/=G;b/=G;
        if(b<0)a=-a,b=-b;
        if(a<=0)cnt[{b,-a}].second++;
        else cnt[{a,b}].first++;
    }
    for(auto it:cnt)(sum*=(mod+power(2,it.second.first)+power(2,it.second.second)-1)%mod)%=mod;
    cout<<(sum+sum0+mod-1)%mod<<endl;
}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

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


int ak[200010];
int si[200010];

signed main(){
	int n;
	cin >> n;
	string s;
	cin >> s;

	for(int i = 0;i < n;i++){
		if(s[i] == 'R') ak[i+1]++;
		else si[i+1]++;
		ak[i+1] += ak[i];
		si[i+1] += si[i];
	}

	int ans = LLONG_MAX;
	for(int i = 0;i <= n;i++){
		chmin(ans, max(si[i], ak[n]-ak[i]));
	}

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


Measured memory_bytes: 6804
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

int pf[2][100010];

main(){
    #define task "TrBBnsformBBtion"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    fasty;

    forinc(i,0,1){
        string s; cin>>s;
        forinc(j,1,s.size()){
            pf[i][j]=(pf[i][j-1]+(s[j-1]=='A'?1:2))%3;
        }
    }
    int q; cin>>q; while(q--){
        int x,y,u,v; cin>>x>>y>>u>>v;
        cout<<((pf[0][y]-pf[0][x-1]+3)%3==(pf[1][v]-pf[1][u-1]+3)%3 ? "YES\n" : "NO\n");
    }
}



Measured memory_bytes: 1644
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N;
    cin >> N;
    ll A[N+1];
    ll S[N+1];
    S[0] = 0;
    ll len = 0;
    for(int i = 1; i < N + 1; i++){
        cin >> A[i];
        len += A[i];
        S[i] = S[i-1] + A[i];
    }
    ll mid = len; //中心に一番近い切れ目の地点（0からの長さ）
    for(int i = 1; i < N + 1; i++){
        mid = min(mid, abs(S[i] - (len - S[i])));
    }
    
    cout << mid << endl;
    return 0;
}

Measured memory_bytes: 3328
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left
from itertools import product
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def LF(): return list(map(float, input().split()))
def LC(): return [c for c in input().split()]
def LLI(n): return [LI() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]

def array2d(N, M, initial=0):
    return [[initial]*M for _ in range(N)]

def copy2d(orig, N, M):
    ret = array2d(N, M)
    for i in range(N):
        for j in range(M):
            ret[i][j] = orig[i][j]
    return ret


INF = float("inf")
MOD = 10**9 + 7


def main():
    N, K = MAP()
    P = LI_()
    C = LI()

    # サイクルとは閉路のことである。順列の性質として、有向グラフで記述した時、必
    # ずサイクルの集合となる。
    ans = -INF
    for i in range(N):
        v = i
        cycle_sum = 0
        cycle_cnt = 0

        # iを始点とし、閉路の和と長さを求める
        while True:
            cycle_cnt += 1
            cycle_sum += C[v]
            v = P[v]
            if v == i:
                break

        path = 0
        cnt = 0

        while True:
            cnt += 1
            path += C[v]
            if cnt > K:
                break

            # サイクルを可能な限りまわる。サイクルの総和が負の場合は回らない
            num = (K-cnt)//cycle_cnt
            score = path + max(0, cycle_sum)*num
            ans = max(ans, score)

            v = P[v]
            if v == i:
                break

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74068
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(int i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(int i=(a);i<(n);i++)cout<<(arr)[i]<<' ';

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

int main(){
	fast;
	ll k, s;
	cin >> k >> s;
	ll x;
	// map<pair< ll, pair<ll, ll> >, ll > m;

	ll ans = 0;
	forn(i, 0, k+1){
		forn(j, 0, k+1){
			x = s-(i+j);
			
			if(x<=k && x>=0){
				// cout<<i<<' '<<j<<' '<<x<<endl;
				ans++;
				// m[mp(i, mp(j, x))]++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3624
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if A[i] >= B[i]:
            ans += B[i]
            A[i] -= B[i]
            B[i] = 0
        else:
            ans += A[i]
            B[i] -= A[i]
            if A[i+1] >= B[i]:
                ans += B[i]
                A[i+1] -= B[i]
                B[i] = 0
            else:
                ans += A[i+1]
                B[i] -= A[i+1]
                A[i+1] = 0
    print(ans)


if __name__ == '__main__':
    main()


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

// void debug(vector<int> *v)
// {
// 	cout << "debug :";
// 	for (int i = 0; i<v->size(); i++)
// 		cout << " " << v->at(i);
// 	cout << endl;
// }

int vector_finder(vector<int> vec, int number) {
	//auto itr = find(vec.begin(), vec.end(), number);
	//size_t index = distance(vec.begin(), itr);
	for (int i = 0; i < vec.size(); i++) {
		if (number == vec.at(i))
			return 1;
	}
	return -1;
}

int main() {
	vector<int> group1{ 1,3,5,7,8,10,12 };
	vector<int> group2{ 4,6,9,11 };
	vector<int> group3{ 2 };

	int x, y;
	cin >> x >> y;

	if (vector_finder(group1, x) == 1 && vector_finder(group1, y) == 1) {
		cout << "Yes" << endl;
	}
	else if (vector_finder(group2, x) == 1 && vector_finder(group2, y) == 1) {
		cout << "Yes" << endl;
	}
	else if (vector_finder(group3, x) == 1 && vector_finder(group3, y) == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	//debug(&group1);
	//debug(&group2);
	//debug(&group3);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));



void solve(long long N){
	vector<vector<ll>> v(10, vector<ll>(10));
	repn(i, N) {
		ll now = i;
		ll s, m;
		m = now%10;
		if (m == 0) continue;
		
		while(now/10 != 0) {
			now /= 10;
		}
		s = now;

		v[s][m]++;
	}
	ll res = 0;
	repn(i, 9) {
		repn(j, 9) {
			res += v[i][j]*v[j][i];
		}
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	solve(N);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N,K;
    cin >> N >> K;
    vector<ll> count(N);
    for (int i = 0; i < K; ++i) {
        ll d;
        cin >> d;
        for (int j = 0; j < d; ++j) {
            ll tmp;
            cin >> tmp;
            count[tmp-1]++;
        }
    }
    ll sum = 0;
    for (int k = 0; k < N; ++k) {
        if(count[k] == 0){
            sum++;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    vector<char> vowels{ 'a', 'e', 'i', 'o', 'u' };
    char c; cin >> c;
    for (const auto& vowel : vowels)
    {
        if (c == vowel)
        {
            cout << "vowel" << "\n";
            return 0;
        }
    }

    cout << "consonant" << "\n";

    return 0;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    ll a, b;
    cin >> a >> b;

    int ans;
    for(int n = 1; n <= 999; n++){
        int ax, bx;
        ax = n*(1+n)/2 - a;
        bx = (n+1)*(1+(n+1))/2 - b;
        if(ax == bx){
            ans = ax;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
const ll INF = 4e18;
const ll MOD = 1e9+7;

int n, m;
int a[10] = {0,2,5,5,4,5,6,3,7,6};
int b[10];
pair<int,int> dp[100010];


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> b[i];
  for (int i = 0; i <= n; i++) {
    dp[i] = make_pair(-1,-1);
  }
  dp[0] = make_pair(0,0);
  for (int i = 0; i < n; i++) {
    if (dp[i].first == -1) continue;
    for (int j = 0; j < m; j++) {
      dp[i+a[b[j]]] = max(dp[i+a[b[j]]], make_pair(dp[i].first+1, b[j]));
    }
  }
  vector<int> ans;
  int now = dp[n].second;
  int p = n;
  while (now) {
    ans.push_back(now);
    p -= a[now];
    now = dp[p].second;
  }
  sort(ans.rbegin(), ans.rend());
  for (auto p: ans) cout << p;
  cout << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
	int n;
	int m;
	int a,b,c,d;
	int result;
	while(scanf("%d",&n)!=EOF){
		result = 0;
		if(n>36){
			printf("0\n");
		}else{
			if(n>9){
				m = 10;
			}else{
				m = n+1;
			}
			for(a=0;a<m;a++){
				for(b=0;b<m;b++){
					for(c=0;c<m;c++){
						for(d=0;d<m;d++){
							if(a+b+c+d==n){
								result += 1;
								continue;
							}
						}
					}
				}
			}
			printf("%d\n",result);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;

int MOD=1000000007;

int main()
{
  ll N,ans=MOD,mi=0;
  cin >> N;
  ll X[N+10];
  for(ll i=0; i<N; i++) cin >> X[i];
  for(ll i=0; i<=100; i++){
    for(ll j=0; j<N; j++){
      mi+=abs((X[j]-i)*(X[j]-i));
    }
    ans=min(ans,mi);
    mi=0;
      }
      cout << ans << endl;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]

    ans = sum(B)
    for i in range(N-1):
        if A[i]+1 == A[i+1]:
            ans += C[A[i]-1]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
from collections import deque

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

g = tuple(set() for _ in range(N))
for _ in range(M):
    a, b = (int(x) - 1 for x in input().split())
    g[a].add(b)
    g[b].add(a)

print('Yes')

ret = [-1] * N
ret[0] = 0

dq = deque()
dq.append(0)

while dq:
    v = dq.popleft()
    for u in g[v]:
        if ~ret[u]: continue
        ret[u] = v
        dq.append(u)

print(*(x + 1 for x in ret[1:]), sep='\n')


Measured memory_bytes: 67620
#include<bits/stdc++.h>
//#define Mx 1000000000005 
#define ll long long  
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll,ll>
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define vii vector<pair<ll,ll> > 
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a,x) memset(a,x,sizeof(a))
using namespace std;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
  return a.second<b.second;
}
/*vi b=v;
   sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  ll t; cin>>t; fr(f,0,t){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 */
const long long Mx = 1e15 + 7;
int main()
{
  ll n; cin>>n;
  ll a[n];
  fr(i,0,n)
    cin>>a[i];

  vector<vector<ll>> dp(n,vector<ll>(n,Mx));
  ll p[n];
  p[0]=a[0];
  fr(i,1,n)
    p[i]=p[i-1]+a[i];

  fr(i,0,n)
    dp[i][i]=0;

  fr(l,2,n+1)
  {
    fr(i,0,n-l+1)
    {
      ll j=i+l-1;

      if(l==2)  { dp[i][j]=a[i]+a[j]; continue; }

      fr(k,i,j)
      {
        if(i>0)
          dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[j]-p[i-1]);
        else 
          dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[j]);
      }

    }
  }

  cout<<dp[0][n-1];


}

Measured memory_bytes: 4852
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    v = math.ceil(n / 1.08)
    vv = v * 1.08
    #print(v,vv)
    if n == math.floor(vv):
        print(v)
    else:
        print(":(")


    


if __name__ == '__main__':
    main()


Measured memory_bytes: 5560
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0;
  cin >> N;
  vector<ll>A(N);
  vector<ll>B(N);
  vector<ll>C(N-1);
  ll ans = 0;
  rep(i,N){
    cin >> A[i];
  }
  rep(i,N){
    cin >> B[i];
    ans += B[i];
  }
  rep(i,N-1){
    cin >> C[i];
  }
  rep(i,N-1){
    if(A[i+1] - A[i] == 1){
      ans += C[A[i]-1];
    }
  }
  cout << ans;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define inf 1e9
using namespace std;

struct activity
{
	int A, B, C;
};

int find(vector<activity> &ar, int n) {
	int dp[n][3];
	dp[0][0] = ar[0].A;
	dp[0][1] = ar[0].B;
	dp[0][2] = ar[0].C;

	for (int i = 1; i < n; i++) {
		dp[i][0] = ar[i].A + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = ar[i].B + max(dp[i - 1][2], dp[i - 1][0]);
		dp[i][2] = ar[i].C + max(dp[i - 1][0], dp[i - 1][1]);
	}

	return max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

}

int main() {



	fio

	ll n;

	cin >> n ;

	vector<activity> ar(n);

	for (int i = 0; i < n; i++)
		cin >> ar[i].A >> ar[i].B >> ar[i].C;

	cout << find(ar, n) << "\n";

}



Measured memory_bytes: 2560