akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

// belik's shit
ll const mod = 1e9 + 7;
namespace {
	ll mult(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) {
			val += mod;
		}
		if (val >= mod) {
			val -= mod;
		}
		return val;
	}
	ll poww(ll a, ll b)
	{
		ll val = 1;
		a %= mod;
		while (b > 0){
			if (b % 2) val = mult(a, val);
			a = mult(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 2e5 + 5;
ll dp[maxn][2];
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s; cin >> s;
	ll n = s.size();
	dp[0][1] = 2;
	dp[0][0] = 1;
	for (ll i = 0; i < n - 1; i++) {
		if (s[i+1] == '1') {
			dp[i + 1][1] = (dp[i][1] * 2) % mod;
			dp[i + 1][0] = ((dp[i][0] * 3) % mod + dp[i][1]) % mod;
		}
		else {
			dp[i + 1][1] = (dp[i][1]);
			dp[i + 1][0] = (dp[i][0] * 3) % mod;
		}
	}
	cout << (dp[n - 1][0] + dp[n - 1][1]) % mod;

	return 0;

}
/*

*/

Measured memory_bytes: 2000
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	int u, v;
	ll cost;
};

bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

#define N 100010

int par[N];
int urank[N];

void init(int n) {
	REP(i, n) {
		par[i] = i;
		urank[i] = 0;
	}
}

int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (urank[x] < urank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (urank[x] == urank[y]) urank[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

edge es[N];

bool used[N];
int V, E;

ll kruskal() {
	sort(es, es + E, comp);
	init(V);
	ll res = 0;
	REP(i, E) {
		edge e = es[i];
		if (!same(e.u, e.v) && !used[e.u] && !used[e.v]) {
			unite(e.u, e.v);
			res += e.cost;
			used[e.u] = used[e.v] = true;
		}
	}
	return res;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a * 100 + b * 10 + c) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


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

struct Edge {
    int to;
    ll dist;
};

bool solve() {
    ll N, M;
    cin >> N >> M;
    vector<vector<Edge>> G(N);
    int l, r;
    ll d;
    for ( int i = 0; i < M; i++ ) {
        cin >> l >> r >> d;
        l--, r--;
        G[l].push_back(Edge{r,d});
        G[r].push_back(Edge{l,-d});
    }

    vector<ll> pos(N, -INF);
    function<bool(int,int,ll)> dfs = [&](int v ,int p, ll x) {
        if ( pos[v] != -INF ) {
            if ( pos[v] != x ) return false;
            else return true;
        }
        pos[v] = x;
        for ( auto e : G[v] ) {
            if ( e.to == p ) continue;
            if ( !dfs(e.to, v, x + e.dist) ) return false;
        }
        return true;
    };
    
    for ( int i = 0; i < N; i++ ) {
        if ( pos[i] != -INF ) continue;
        if ( !dfs(i, -1, 0) ) return false;
    }

    return true;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 18304
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
#define ld long double
using namespace std;
int read(){int x;scanf("%d",&x);return x;}
int a[1005];
int main(){
	int n=read(),sum=0;
	for(int i=1;i<=n;i++) a[i]=read(),sum+=a[i];
	sort(a+1,a+n+1);
	sum-=a[n];
	if(a[n]<sum) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	char c;
	int st = -1, gl = 0;
	for(int i = 0; ; i++){
		c = getchar();
		if(c == '\n')break;
		if(st == -1 && c == 'A')st = i;
		if(c == 'Z')gl = i;
	}
	printf("%d\n", gl - st + 1);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

constexpr double INF = (1 << 29);

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    double maxi = -INF;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) continue;
            int C = a[i], D = a[j];
            int x[2];
            if (C - D < 0) {
                for (int k = 0, l = 0; k < N; k++) {
                    if (i != k && j != k) {
                        x[l] = a[k];
                        if (++l == 2) break;
                    }
                }
            } else {
                for (int k = N - 1, l = 0; k >= 0; k--) {
                    if (i != k && j != k) {
                        x[l] = a[k];
                        if (++l == 2) break;
                    }
                }
            }
                
            maxi = max(maxi, (double)(x[0] + x[1]) / (C - D));
        }
    }
    printf("%.10f\n", maxi);
    return 0;
}

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

long max(long a, long b){
  if(a>b)return a;
  else return b;
}

int main(){
  int x,y,a,b,c;
  scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
  long p[a+1],q[b+1],r[c+1];
  rep(i,a)cin >> p[i];
  rep(i,b)cin >> q[i];
  rep(i,c)cin >> r[i];
  sort(p,p+a,greater<>());
  sort(q,q+b,greater<>());
  sort(r,r+c,greater<>());
  int pi=0,qi=0,ri=0;
  p[x]=-1;
  q[y]=-1;
  r[c]=-1;
  long ans=0;
  int sum=x+y;
  while(sum>0){
    long tmp=max(p[pi],max(q[qi],r[ri]));
    if(tmp==p[pi])pi++;
    else if(tmp==q[qi])qi++;
    else ri++;
    ans += tmp;
    sum--;
  }

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

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

void _main(istream &inp){
	ll N,x;
	inp >>N >> x;
	vl a(N);
	rep(j,N) inp >> a[j];
	ll ret = 1LL<<62;
	vl b=a;
	rep(k,N){
		ll sum=0;
		rep(i,N) sum+=b[i];
		ret = min(ret, sum+x*k);
		rep(i,N) b[i] = min(b[i], a[(i+k+1)%N]);
	}
	cout << ret << endl;
}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int iseven(int ara[],int n)
{
  int flag=0;
  for(int i=0;i<n;i++)
  {
     if(ara[i]%2==1)
     {
       flag=1;
     }
  }
  if(flag)
  return 0;
  else
    return 1;
}
int main()
{
   int n,c=0;

   cin>>n;int ara[n];
   for(int i=0;i<n;i++)
   {
     cin>>ara[i];
   }
   
   while(1)
   {
     if(iseven(ara,n)==1)
     {
       c++;
       for(int i=0;i<n;i++)
       {
         ara[i]/=2;
       }
     }
     else
     {
       break;
     }

   }
  cout<<c<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <string.h>
    #include <iomanip>
    using namespace std;
    #define endl '\n'
    #define int long long int
    //https://www.youtube.com/watch?v=zlJDTxahav0--ps -Still miss you !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1


      int fac[1000000];

    int power(int x, int y, int p)
    {
        int res = 1;      // Initialize result

        x = x % p;  // Update x if it is more than or
                    // equal to p

        while (y > 0)
        {
            // If y is odd, multiply x with result
            if (y & 1)
                res = (res*x) % p;

            // y must be even now
            y = y>>1; // y = y/2
            x = (x*x) % p;
        }
        return res;
    }

    // Returns n^(-1) mod p
    int modInverse(int n, int p)
    {
        return power(n, p-2, p);
    }

    // Returns nCr % p using Fermat's little
    // theorem.
    int nCrModPFermat(int n, int r, int p)
    {
       // Base case
       if (r==0)
          return 1;

        // Fill factorial array so that we
        // can find all factorial of r, n
        // and n-r

        fac[0] = 1;
        for (int i=1 ; i<=n; i++)
            fac[i] = fac[i-1]*i%p;

        return (fac[n]* modInverse(fac[r], p) % p *
                modInverse(fac[n-r], p) % p) % p;
    }

    signed main()
    {
        int ans=0;
      int x; int y;
      cin>>x>>y;
      int maxi,mini;
      maxi=max(x,y);
      mini=min(x,y);
      if(maxi>2*mini){
        cout<<"0";
      }
      else{
        int xx,yy=0;
        ans=maxi-mini;
        xx=ans;
        mini=mini-ans;
        if(mini%3==0){
        ans+=(mini/3)*2;
        xx+=mini/3;
        yy+=mini/3;
       // cout<<xx<<endl<<yy<<endl;
        cout<<nCrModPFermat(xx+yy, xx, 1000000007);
        }
        else{
            cout<<"0";
        }

      }
    }


Measured memory_bytes: 6400
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

//bool flag = __builtin_add_overflow(a , b , &tmp);
//bool flag = __builtin_mul_overflow(a , b , &tmp);
//bool flag3= __builtin_sub_overflow(a , b , &tmp);

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-12;
const long long inf = 2e12 + 12;
const int MAXN = 2000006, MAXM = 102, Mod = 1000000007 , MAXLog = 20;


int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i].second >> arr[i].first;
    }
    sort(arr.rbegin(), arr.rend());
    set<int> st;
    for (int i = 1; i <= m; ++i) {
        st.insert(i);
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        if (st.lower_bound(arr[i].second) != st.end()) {
            st.erase(st.lower_bound(arr[i].second));
            ans += arr[i].first;
        }
    }

    cout << ans << '\n';

    return 0;
}


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

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    ll N, M;
    cin >> N >> M;
    map<ll,vector<ll>> A;
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        A[a-1].push_back(b-1);
        A[b-1].push_back(a-1);
    }
    deque<ll> deq;
    vector<ll> visited(N, -1);
    deq.push_back(0);
    visited[0] = 0;
    while(!deq.empty()){
        ll v = deq.front();
        deq.pop_front();
        for(ll nv : A[v]){
            if (visited[nv] != -1) continue;
            visited[nv] = v;
            deq.push_back(nv);
        }
    }
    for(ll i : visited){
        if(i == -1){
            out("No");
            return;
        }
    }
    out("Yes");
    FOR(i, 1, N) out(visited[i]+1);
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 19256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll n, d, a[15], b[25], res;
vector<ll> memo;
const ll INF = 1000000000;

void dfs(ll x){
    if (x == memo.size()){
        vector<ll> vec;
        ll sma = INF;
        for (ll i = 0; i <= 24; i++){
            if (b[i] == 0) continue;
            vec.push_back(i);
        }
        for (ll i = 1; i < vec.size(); i++){
            sma = min(sma, vec[i] - vec[i - 1]);
        }
        res = max(res, sma);
    } else {
        b[memo[x]] = 1;
        dfs(x + 1);
        b[memo[x]] = 0;
        b[24 - memo[x]] = 1;
        dfs(x + 1);
        b[24 - memo[x]] = 0;
    }
}

int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++){
        cin >> d;
        a[d]++;
    }
    if (a[0] || a[12] > 1){
        cout << 0 << endl;
        return 0;
    }
    b[0] = 1, b[24] = 1;
    if (a[12] == 1) b[12] = 1;
    for (ll i = 1; i < 12; i++){
        if (a[i] > 2){
            cout << 0 << endl;
            return 0;
        } if (a[i] == 2){
            b[i] = 1;
            b[24 - i] = 1;
        } if (a[i] == 1){
            memo.push_back(i);
        }
    }
    dfs(0);
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[101];
int minn=0X7fffffff;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=100;i++)
    {
        int s=0;
        for(int j=1;j<=n;j++)
        {
            s+=pow(a[j]-i,2);
        }
        minn=min(minn,s);
    }
    cout<<minn<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
      int a,b,c,m,n=0;
      scanf("%d",&m);
      a=m/100;
      b=m%100/10;
      c=m%100%10;
      if(a==1)
        n++;
      if(b==1)
        n++;
      if(c==1)
        n++;
      printf("%d",n);
      return 0;
      }


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

int main() {
    int N;
    cin >> N;
    vector<string> S(N);

    for(int i = 0; i < N; i++) cin >> S[i];

    map<string, int> p;

    for(int i = 0; i < N; i++) {
        p[S[i]] += 1;
    }

    cout << p.size();
    return 0;

}

Measured memory_bytes: 25168
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int a=(s[0]-'0')*10+(s[1]-'0'),b=(s[2]-'0')*10+(s[3]-'0');
	if(a>=1&&a<=12&&b>=1&&b<=12)
		cout<<"AMBIGUOUS"<<endl;
	else if(a>=1&&a<=12)
		cout<<"MMYY"<<endl;
	else if(b>=1&&b<=12)
		cout<<"YYMM"<<endl;
	else
		cout<<"NA"<<endl;
	return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	
	//文字列から10進数に変換するときはparseIntを使います
	
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
	if(a>9||b>9){console.log('-1');}
	else{console.log(a*b);}
	//出力
	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << vec.at(K-1) << endl;
}


Measured memory_bytes: 256
#python3
from fractions import gcd

def lcm(a, b):
    return (a*b)//gcd(a, b)


def main():
    a, b, c, d = map(int, input().split())
    p = b - ((b//c + b//d) - b//lcm(c, d))
    q = (a-1) - (((a-1)//c + (a-1)//d) - (a-1)//lcm(c, d))
    print(p-q)
main() 

Measured memory_bytes: 5052
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int mask[58];
vector<pint> gr[58];
lint dp[52][(1<<20)+10];
lint dfs(int v,int u,int g){
	if(v==g) return 0;
	rep(i,gr[v].size()){
		pint p=gr[v][i];
		if(p.fi==u) continue;
		lint x=dfs(p.fi,v,g);
		if(x>=0L) return x+(1LL<<p.se);
	}
	return -1;
}
int main()
{
	int n,a,b,m;
	cin>>n;
	rep(i,n-1){
		cin>>a>>b;gr[a].pb(mp(b,i));gr[b].pb(mp(a,i));
	}
	cin>>m;
	memset(mask,false,sizeof(mask));
	rep(i,m){
		cin>>a>>b;
		lint ma=dfs(a,-1,b);
		rep(j,n-1){
			if((ma&(1LL<<j))) mask[j]+=(1<<i);
		}
		//cout<<ma<<endl;
	}
	//rep(i,n-1) cout<<i<<' '<<mask[i]<<endl;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	rep(i,n-1) rep(j,(1<<m)){
		dp[i+1][j]+=dp[i][j];
		dp[i+1][(j|mask[i])]+=dp[i][j];
	}
	cout<<dp[n-1][(1<<m)-1]<<endl;
}


Measured memory_bytes: 426368
N,W=map(int,input().split())
k=[[0,0] for i in range(N)]
dp=[[W+1]*(1001*101+1) for j in range(N+1)]
R=set()
for i in range(N):
    k[i][0],k[i][1]=map(int,input().split())
dp[0][:k[0][1]]=[k[0][0]]*(k[0][1]+1)
dp[0][0]=0
for i in range(1,N):
    for v in range(1001*101):
        if v - k[i][1]>=0:
         dp[i][v] = min(dp[i-1][v-k[i][1]]+k[i][0],dp[i-1][v])
        else:
            dp[i][v]=min(dp[i-1][v],dp[i][v])

        if dp[i][v]<W:
             R.add(v)


for v in reversed(range(1001*101+1)):
    if dp[N-1][v]<=W:
        print(v)
        exit()

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

ll bigmod(ll b,ll p)
{
    if(p==0)
        return 1;
    ll res=bigmod(b,p/2);
    res=(mod+(((res+mod)%mod)*((res+mod)%mod)))%mod;
    if(p%2)
        res=(mod+(res*b))%mod;
    return res;
}
int main()
{
    ll a,b,c,d;
    cin>>a;
    if(a==1)
    {
          cout<<0<<endl;
          return 0;

    }
    if(a==2)
    {
             cout<<2<<endl;
          return 0;
    }
    b=bigmod(10LL,a);
    c=(mod+(2LL*bigmod(9LL,a)))%mod;
    d=bigmod(8LL,a);
    c=(mod+(c-d))%mod;
    cout<<(mod+(b-c))%mod<<endl;

    return 0;
}



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

using namespace std;

int n,m;
vector<int>a[200001];
long long ans[200001];
int flag[200001];
int pos,val;
queue<int>s;

struct node
{
    int l,r;
}e[200000];

bool cmp(node a,node b)
{
    if(a.l == b.l)
        return a.r < b.r;
    return a.l < b.l;
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= n - 1;i++)
    {
        scanf("%d%d",&e[i].l,&e[i].r);
    }
    sort(e + 1,e + n,cmp);
    for(int i = 1;i <= n - 1;i++)
    {
        a[e[i].l].push_back(e[i].r);
    }
    for(int i = 1;i <= m;i++)
    {
        scanf("%d%d",&pos,&val);
        ans[pos] += val;
    }
    s.push(1);
    while(!s.empty())
    {
        int t = s.front();
        s.pop();
        int len = a[t].size();
        for(int i = 0;i < len;i++)
        {
            ans[a[t][i]] += ans[t];
            s.push(a[t][i]);
        }
    }
    for(int i = 1;i < n;i++)
        printf("%lld ",ans[i]);
    printf("%lld\n",ans[n]);
    return 0;
}


Measured memory_bytes: 16768
#include<stdio.h>
int f(int n,int k){
	if(n==1)return 0;
	return (f(n-1,k)+k)%n;
}
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a+b+c){
		int t=f(a-1,b);
		printf("%d\n",(t+c)%a+1);
	}
}

Measured memory_bytes: 0
//Md Fahad
// CSE 18

#include<bits/stdc++.h>


using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);
#define Infi                0x3f3f3f3f

const int fx[] = {+1,-1,+0,+0};                         // 4 X directions
const int fy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int fx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int fy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif


typedef long long int           ll;
typedef unsigned long long int  llu;

int main(void)
{
    //READ_IN;
    int n;
    cin >> n;

    vector<ll> keep(n);

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

    map<ll,ll> cnter;

    for(int i=0;i<n;i++){
        cnter[keep[i]]++;
    }

    ll sum = 0;

    for(auto it:cnter){
        ll f = it.second;
        sum +=((f*(f-1))/2);
        //trace(sum);
    }

    for(int i=0;i<n;i++){
        ll ff = cnter[keep[i]];

        ll val = ff-1;

        ll ans = sum - (ff*(ff-1))/2 + (val*(val-1))/2;
        cout << ans <<endl;
    }


    return 0;
}



Measured memory_bytes: 11008
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

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

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int n, k;
    cin >> n >> k;

    vector<ll> dp(k + 1);
    dp[0] = 1;
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        vector<ll> dp2(k + 1);
        ll tmp = 0;
        for(int j = 0; j <= k; j++){
            tmp += dp[j];
            if(j - a - 1 >= 0) tmp -= dp[j - a - 1];
            tmp = (tmp % MOD + MOD) % MOD;
            dp2[j] = tmp;
        }
        dp = dp2;
    }

    cout << dp[k] << "\n";

    return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**7)
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
memo = [0]*n
for i in range(1, n):
    min_k = float('inf') 
    min_k=min([memo[j] +abs(h[i]-h[j]) for j in range(max(0, i-k), i)])
    memo[i] = min_k

print(memo[-1])


Measured memory_bytes: 20480
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, M, Q; cin  >> N >> M >> Q;
    int CS[550][550] = {0};
    for(int i=0; i<M; ++i){
        int l, r;
        cin >> l >> r;
        CS[l][r]++;
    }
    for(int i=0; i<=N; ++i){
        for(int j=0; j<N; ++j){
            CS[i][j+1] += CS[i][j];
        }
    }
    for(int i=0; i<Q; i++){
        int p, q; cin >> p >> q;
        int res = 0;
        for(int j=p; j<=q; ++j){
            res += CS[j][q] - CS[j][p-1];
        }
        cout << res << endl;
    }
    return 0;
}

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

int main()
{
	ll a, b, c, d; cin >> a >> b >> c >> d;

	ll ansA[4];
	ansA[0] = a * c;
	ansA[1] = a * d;
	ansA[2] = b * c;
	ansA[3] = b * d;

	ll mansB[2];
	mansB[0] = max(ansA[0], ansA[1]);
	mansB[1] = max(ansA[2], ansA[3]);

	ll ans = max(mansB[0], mansB[1]);

	if (ans < 0)
	{
		if (((a <= 0) && (b >= 0)) || ((c <= 0) && (d >= 0)))
		{
			cout << 0 << endl;
			return 0;
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1000010, M = 25;

int n, k, a[N];

int main()
{
	scanf("%d%d", &k, &n);
	for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
	sort(a, a + n);
	a[n] = a[0] + k;
	
	int res = -1;
	for (int i = 0; i < n; i ++ ) res = max(res, a[i + 1] - a[i]);
	
	printf("%d\n", k - res);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define r(i,n) for(int i=0;i<n;i++)
const ll MN=2005;ll md=1e9+7;ll n,sz[MN],p[MN];vector<ll>g[MN];ll d[MN][MN][2];ll f[MN];ll a[MN][3],x[MN][3];
int main(){f[0]=1;
for(ll i=1;i<MN;i++)f[i]=f[i-1]*i%md;
cin>>n;for(ll i=2;i<=n;i++){cin>>p[i];g[p[i]].push_back(i);}
for(ll i=n;i;i--){memset(a,0,sizeof(a));a[0][0]=1;for(auto &j:g[i]){memset(x,0,sizeof(x)); 
r(k,sz[j]+1)r(l,sz[i]+1)r(m,3){x[k+l][m]+=d[j][k][0]*a[l][m]%md;if(m<2) x[k+l+1][m+1]+=d[j][k][1]*a[l][m]%md;}
sz[i]+=sz[j];
r(j,sz[i]+1)r(k,3){a[j][k]=x[j][k]%md;}}
r(j,sz[i]+1){
d[i][j][0]=a[j][0]+a[j][1]*2+a[j][2]*2;
d[i][j][1]=a[j][0]+a[j][1];d[i][j][0]%=md;d[i][j][1]%=md;}
sz[i]++;}
ll rt=0;r(i,n+1){ll cr=d[1][i][0]*f[n-i]%md;if(i & 1) cr=md-cr;rt+=cr;}
cout<<rt%md<<endl;}

Measured memory_bytes: 42508
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        int K = sc.nextInt();

        System.out.println( solve(s, K) );
    }

    private static String solve(String s, int K) {
        int k = K;
        for (int i = 0; i < 26; i++) {
            char c = (char)('a' + i);
            List<Integer> indice = findIndice(c, s);

            if( indice.isEmpty() ) continue;

            k -= 1;
            if( k == 0 ) {
                return "" + c;
            }

            Set<String> set = new HashSet<>();
            for (Integer index : indice) {
                set.addAll(findSub(s, index, k));
            }
            List<String> list = new ArrayList<>(set);
            list.sort(Comparator.naturalOrder());

            if( list.size() < k ) {
                k-= list.size();

            } else {
                return list.get(k - 1);
            }
        }
        throw new RuntimeException("oops");
    }

    private static List<String> findSub(String s, int index, int k) {
        List<String> strs = new ArrayList<>();

        int i = 2;
        while(true) {
            try {
                strs.add(s.substring(index, index + i));
                i++;
            } catch( Exception e ) {
                return strs;
            }

            if( strs.size() == k ) {
                return strs;
            }
        }
    }

    private static List<Integer> findIndice(int c, String s) {
        List<Integer> indice = new ArrayList<>();
        int index = 0;
        while(index != -1) {
            index = s.indexOf(c, index);
            if( index != -1 ) {
                indice.add( index );
                index ++;

            } else {
                break;
            }
        }
        return indice;
    }
}


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

const int N = 200005;
const int md = 1e9 + 7;
const int inf = 1e9 + 123;

int n, X, Y;
int c[N], w[N];
int mn[N], start[N];
int ft[N], inv[N];
int par[N];
vector< pair<int,int> > vec;
map <int,int> cnt[N];

int pw(int a, int b) {
	int res = 1;
	for (int i = 0; (1LL << i) <= b; ++i) {
		if (b & (1LL << i)) res = 1LL * res * a % md;
		a = 1LL * a * a % md;
	}
	return res;
}

void prep() {
	for (int i = 1; i < N; ++i) mn[i] = inf;
	ft[0] = 1; 
	for (int i = 1; i < N; ++i) ft[i] = 1LL * ft[i-1] * i % md;
	for (int i = 0; i < N; ++i) inv[i] = pw(ft[i], md - 2);
	for (int i = 1; i <= n; ++i) par[i] = i;
}

int anc(int p) { return p == par[p] ? p : par[p] = anc(par[p]); }
void join(int p, int q) { p = anc(p), q = anc(q); if (p != q) par[p] = q; }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> X >> Y;
	prep();
	for (int i = 1; i <= n; ++i) {
		cin >> c[i] >> w[i], mn[c[i]] = min(mn[c[i]], w[i]);
	}

	for (int i = 1; i <= n; ++i) if (w[i] <= X - mn[c[i]]) {
		w[i] = mn[c[i]];
		if (start[c[i]] == 0) start[c[i]] = i; else join(i, start[c[i]]);
	}

	for (int i = 1; i <= n; ++i) vec.push_back(make_pair(w[i], i));
	sort(vec.begin(), vec.end());
	
	int tmp = -1;
	for (int i = 1; i < (int)vec.size(); ++i) {
		if (c[vec[i].second] != c[vec[0].second]) { tmp = i; break; }
	}
	for (int i = 1; i < (int)vec.size(); ++i) {
		int val = vec[i].first;
		if (c[vec[i].second] != c[vec[0].second]) {
			if (val + vec[0].first > Y) continue;
			join(vec[0].second, vec[i].second);
		} else {
			if (tmp == -1) continue;
			if (val + vec[tmp].first > Y) continue;
			join(vec[tmp].second, vec[i].second);
		}
	}

	for (int i = 1; i <= n; ++i) cnt[anc(i)][c[i]]++;

	int ans = 1;
	for (int i = 1; i <= n; ++i) if (i == anc(i)) {
		int res = 1;
		int sum = 0;
		for (map<int,int>::iterator it = cnt[i].begin(); it != cnt[i].end(); ++it) {
			sum += it->second;
			res = 1LL * res * inv[it->second] % md;
		}
		res = 1LL * res * ft[sum] % md;
		ans = 1LL * res * ans % md;
	}

	cout << ans << '\n';
}

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

using namespace std;

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	int count = 0;
	for(int i = 0; i < N; i++){
		cin >> a.at(i);
		if(a.at(i) % 2 != 0 && (i+1) % 2 != 0) count++;
	}
	cout << count << endl;
	
}

Measured memory_bytes: 3628
from bisect import bisect

n = int(input())
l = sorted(map(int, input().split()))
linv = l[::-1]

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        x = linv[i] - linv[j]
        ans += max((n - j - 1) - bisect(l, x), 0)
print(ans)


Measured memory_bytes: 74540
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)1e5+100;

ll dp[MAX];

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(void) {
   ll Q;
   cin>>Q;
   dp[0] = 0;
   rep(i,1,MAX) {
      if (i%2==0) dp[i] = dp[i-1];
      else {
         if (IsPrime(i) && IsPrime((i+1)/2)) dp[i] = dp[i-1]+1;
         else dp[i] = dp[i-1];
         // if (i<=100)cout<<dp[i]<<endl;
      }
   }

   vector<ll> ans;
   rep(i,0,Q) {
      ll r,l;
      cin>>r>>l;
      ans.push_back(dp[l] - dp[r-1]);
   }
   for (auto el:ans) cout<<el<<endl;




   return 0;
}

Measured memory_bytes: 2296
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int n;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==n){
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
long long a[1000000],b[1000000],n;


int main()
{
	long long x=0,temp,s;
	scanf("%lld",&n);
	for(long long i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	if(n%2)
	{
		for(long long i=n-1;i>=0;i--)
		{
			if(i%2==0)printf("%lld ",a[i]);
		}
		for(long long i=0;i<n;i++)
		{
			if(i%2==1)printf("%lld ",a[i]);
		}			
	}
	else
	{
		for(long long i=n-1;i>=0;i--)
		{
			if(i%2) printf("%lld ",a[i]);
		}
		for(long long i=0;i<n;i++)
		{
			if(i%2==0) printf("%lld ",a[i]); 
		}
	}
	return 0;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define md 1000000007
#define inf 1e18
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;
#define M 1000010


int32_t main(){
	
	
	int n,x,t;cin>>n>>x>>t;
	int y=n/x;
	if(n%x!=0)y++;
	cout<<y*t;	
	
	
	
	
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tlll tuple<ll, ll, ll>

int main() {
    ll n, k, s;
    cin >> n >> k >> s;

    for (int i = 0; i < k; i++) {
        if (i != 0) cout << " ";
        cout << s;
    }
    for (int i = k; i < n; i++) {
        if (s == 1e9) cout << " " << 1000000000 - 1;
        else cout << " " << 1000000000;
    }
    cout << endl;

}


Measured memory_bytes: 1280
using System;

    class Program
    {
        static void Main()
        {
            string line;
            while (true)
            {
                if ((line = Console.ReadLine()) == "0")
                    break;

                int sum = 0;
                char[] charArray = line.ToCharArray();
                foreach (int num in charArray)
                {
                    sum += num - '0';
                }
                Console.WriteLine(sum.ToString());
            }
        }
    }

Measured memory_bytes: 5576
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return


# inputs
N, M, C = 0, 0, 0
B = []
A = []


def set_inputs():
    global N, M, C, B, A
    N, M, C = get_list_of_int()
    B = get_list_of_int()
    for _ in range(N):
        a = get_list_of_int()
        A.append(a)
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    ans = 0
    for i in range(N):
        sum = C
        for j in range(M):
            sum += A[i][j] * B[j]
        if sum > 0:
            ans += 1
    print(ans)
    return


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define pause system("pause")


signed main() {
	int N, count = 0;
	cin >> N;
	vector<int> di(N);
	REP(i, N) {
		cin >> di.at(i);
	}
	sort(di.begin(), di.end());
	REP(i, N - 1) {
		if (di.at(i) == di.at(i + 1)) {
			count++;
		}
	}
	cout << N - count << endl;
	pause;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll a, k;
	vector<ll> v(5, 0);

	REP(i, 5) {
		cin >> v[i];
	}

	cin >> k;

	REP(i, 4) {
		FOR(j, i, 5) {
			if (v[j] - v[i] > k) {
				cout << ":(" << endl;
				return 0;
			}
		}
	}

	cout << "Yay!" << endl;
}

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

const int inf = 1e9;
const ll linf = 1e18;

template <typename T>
class BIT
{
public:
    BIT(int size, T unity = 0) : bit(++size, unity), _unity(unity) {}

    // [a, b)の和を計算する
    T sum(int a, int b) {
        return _sum(b - 1) - _sum(a - 1);
    }

    // i番目の要素にxを加算
    void add(int i, T x) {
        for (++i; i < (int)bit.size(); i += i & -i) bit[i] += x;
    }

private:
    vector<T> bit;
    T _unity;

    T _sum(int i) {
        T s = _unity;
        for (++i; i > 0; i -= i & -i) s += bit[i];
        return s;
    }
};


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

    int n, q; cin >> n >> q;
    BIT<int> bit(n);
    for (int i = 0; i < q; i++) {
        int c, x, y; cin >> c >> x >> y;
        if (!c) bit.add(x - 1, y);
        else    cout << bit.sum(x - 1, y) << endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;
const long long INF = 1LL << 60;


int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];
    int ans = 0;
    for(int hi = 0; hi < (1<<h); hi++){
        for(int wi = 0; wi < (1<<w); wi++){
            int cnt = 0;
            rep(i, h){
                rep(j, w){
                    if(hi & (1<<i) || wi & (1<<j)) continue;
                    else if(c[i][j] == '#') cnt++;
                }
            }
            if(cnt == k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        int i, j;
        Scanner sa = new Scanner(System.in);
        int n = sa.nextInt();
        int m = sa.nextInt();
        int a[][] = new int [n][m];
        int b[] = new int [m];
        int c[] = new int [n];
        
        for(i = 0; i < n; i++){
            for(j = 0; j < m; j++){
                a[i][j] = sa.nextInt();
            }
        }
        for(i = 0; i < m; i++){
            b[i] = sa.nextInt();
        }
        
        for(i = 0; i < n; i++){
            for(j = 0; j < m; j++){
                c[i] += a[i][j] * b[j];
            }
        }
        for(i = 0; i < n; i++){
            System.out.printf("%d\n", c[i]);
        }
        sa.close();
    }
}



Measured memory_bytes: 40492
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}
void printvec(vector<int> a){
    rep(i, a.size()-1){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[a.size()-1]);
}


vector<int> primes(100000);
int num_prime = 0; 

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

    double root_m = sqrt(m);

    for(int i=3; i<=root_m; i+=2){
        if(m%i==0) return false;
    }

    return true;
}

void updatePrimes(int st, int max_v){
    for(int i=st;i < max_v+1; i+=2){
        if(IsPrime(i)){
            num_prime++;
            primes[num_prime] = i;
            // printf("%dは素数 ", i);
        }
    }
}
 
int main()
{
    primes[0] = 0;
    primes[1] = 2;
    primes[2] = 3;
    num_prime = 2;
    updatePrimes(5, 1000000);
    int num, id;

    while(scanf("%d", &num) != EOF){
        auto it = lower_bound(primes.begin(), primes.begin()+num_prime, num);
        if(*it > num) it--;
        id = it - primes.begin();
        printf("%d\n", id);
    }
    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n;
	cin >> n;
	vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		cin >> ans[i];
	}
	int cnt = 0;
	for (int i = 1; i < n - 1; i++) {
		if (ans[i - 1] < ans[i] && ans[i] < ans[i + 1]) cnt++;
		else if (ans[i - 1] > ans[i] && ans[i] > ans[i + 1]) cnt++;
	}
	cout << cnt << "\n";
	return 0;
}


Measured memory_bytes: 256
import re
import functools

class IO_for_Contest(object):
    @staticmethod
    def my_input():
        #return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        #TODO: impl this for each problem
        pass

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(int, re.split(' ', IO_for_Contest.my_input().strip())))[ : n]


def solve():
    a, b = IO_for_Contest.read_n_int(2)
    result = get_result(a, b)
    print(result)

def get_result(a, b):
    if a * b == 0:
        return 'Zero'
    if a * b < 0:
        return 'Zero'
    if a > 0:
        return 'Positive'
    if abs(b - a) % 2 == 0:
        return 'Negative'
    return 'Positive'

if __name__ == '__main__':
    solve()


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

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

int main(void) {
  long a, b;
  cin >> a >> b;
  cout << a / gcd(a, b) * b << endl;
  return 0;
}


Measured memory_bytes: 256