akhauriyash/Code-Regression huggingface dataset:
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    int N; cin >> N;
    VI A(100, 0);
    
    REP(i, N) 
    {
        int n;
        cin >> n;
        A.at(n-1) = 1;
    }

    cout << accumulate(ALL(A), 0) << endl;
    

    return 0;
}


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

int main() {
	//cout<<"GfG!";
	int n, m, num, sum;
    vector <int> vac;
    cin>>n>>m;
    for (int i = 0; i < m; i++)
    {
        cin>>num;
        vac.push_back(num);
    }
    sum = accumulate(vac.begin(),vac.end(),0);
    if (sum > n)
        cout<<"-1";
    else
        cout<<(n - sum);
	return 0;
}

Measured memory_bytes: 3704
import math
A, B, H, M = map(int, input().split())
hour = H/12 + M/(12*60)
mi = M/60
D = min(abs(hour - mi), 1 - abs(hour - mi))
print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(D*2*math.pi)))

Measured memory_bytes: 62196
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long ll;

const ll INF = LONG_MAX / 3;

class tree {
public:
  vector<vector<int>> nb;
  vector<pair<ll,ll>> in;
  vector<int> val;
  int s;
  tree(int N) : nb(N+1), in(N+1,{-INF,INF}), val(N+1) {
    REP(i,0,N-1) {
      int a, b;
      cin >> a >> b;
      nb[a].push_back(b);
      nb[b].push_back(a);
    }
    int K;
    cin >> K;
    REP(i,0,K) {
      int a, b;
      cin >> a >> b;
      in[a] = {b,b};
      s = a;
    }
  }
  bool assign(int x, bool odd, int from) {
    for(int v: nb[x]) {
      if(v == from) continue;
      if(!assign(v, !odd, x)) {
        return false;
      }
      in[x].first = max(in[x].first, in[v].first-1);
      in[x].second = min(in[x].second, in[v].second+1);
    }
    if(in[x].first % 2 != odd) {
      in[x].first++;
    }
    if(in[x].second % 2 != odd) {
      in[x].second--;
    }
    return in[x].first <= in[x].second;
  }
  void write(int x, int p, int from) {
    if(in[x].first <= p-1 && p-1 <= in[x].second) {
      val[x] = p-1;
    } else {
      val[x] = p+1;
    }
    for(int v: nb[x]) {
      if(v == from) continue;
      write(v, val[x], x);
    }
  }
};

int main() {
  int N;
  cin >> N;
  tree t(N);
  if(t.assign(t.s, t.in[t.s].first % 2, -1)) {
    cout << "Yes\n";
    t.write(t.s, t.in[t.s].first - 1, -1);
    REP(i,1,N+1) {
      cout << t.val[i] << "\n";
    }
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 12800
#include<stdio.h>
int main(void){
  char s[200001];
  int i,a,z;
  scanf("%s",s);
  for(i=0;i<strlen(s);i++)if(s[i]=='A'){
      a=i;
      break;
  }
  for(i=strlen(s)-1;i>=0;i--)if(s[i]=='Z'){
      z=i;
      break;
  }
  printf("%d",z-a+1);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int, int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
	in >> p.first >> p.second;
	return in;
}
signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const int MOD = 1000000007;
	int n;
	cin>>n;
	vector<int> a(n),b(n);
	rep(i,n){
		int in;
		cin>>in;
		a[i]=in+i;
		b[i]=in-i;
	}
	map<int,int> mp;
	int ans=0;
	for(int i=n-1;i>=0;i--){
		ans+=mp[-a[i]];
		mp[b[i]]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 28972
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

s = s()
for i in range(len(s)):
	if s[i] == "A":
		m1 = i
		break
for i in range(-1,-len(s)-1,-1):
	if s[i] == "Z":
		m2 = i
		break
print(len(s) + m2 - m1 + 1)

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    ll p_sum = 0;
    rep(i,k) p_sum += p[i];
    ll max_sum = p_sum;
    rep(i,n-k){
        p_sum = p_sum-p[i]+p[i+k];
        max_sum = max(p_sum, max_sum);
    }
    printf("%.6f\n",(double)(max_sum+k)/2);
    
    return 0;
}


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

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int main() 
{
    int N;
    cin >> N;
    int *array = new int[N];
	for (int i = 0; i < N; ++i) {
		scanf("%d", &array[i]);
	}
  
    std::sort(array, array + N);
    
    for(int i = 0; i < N-1; i++){
    	if(array[i] == array[i+1]){
		    cout << "NO";
		    goto end;
    	}
    }

    cout << "YES";
    
end:
    delete[] array;
    return 0;
}

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

int main() {
  int n, k, q;
  scanf("%d %d %d", &n, &k, &q);
  vector<int> a(n, k - q);
  for (int i = 0; i < q; i++) {
    int x;
    scanf("%d", &x);
    a[--x]++;
  }
  for (int i = 0; i < n; i++)
    puts(a[i] > 0 ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
template <typename T>
class TopologicalSort {
  struct Edge {
    int src, dst;
    T cost;
    Edge(int dst_, T cost_ = -1) : src(-1), dst(dst_), cost(cost_) {}
    Edge(int src_, int dst_, T cost_) : src(src_), dst(dst_), cost(cost_) {}
    inline bool operator < (const Edge &rhs) { return cost < rhs.cost; }
    inline bool operator <= (const Edge &rhs) { return cost <= rhs.cost; }
    inline bool operator > (const Edge &rhs) { return cost > rhs.cost; }
    inline bool operator >= (const Edge &rhs) { return cost >= rhs.cost; }
  };

  int sz;

  bool dfs(int ver, vector<int> &state) {
    state[ver] = 1;
    for (Edge e : graph[ver]) {
      if (state[e.dst] == 1) return false;
      if (state[e.dst] == 0 && !dfs(e.dst, state)) return false;
    }
    order.emplace_back(ver);
    state[ver] = -1;
    return true;
  }

public:
  vector<vector<Edge> > graph;
  vector<int> order;

  TopologicalSort(int sz_) : sz(sz_), graph(sz) {}

  void add(int src, int dst, T cost = -1) { graph[src].emplace_back(Edge(dst, cost)); }

  bool build() {
    order.clear();
    vector<int> state(sz, 0);
    REP(i, sz) if (state[i] == 0 && !dfs(i, state)) return false;
    reverse(ALL(order));
    return true;
  }
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  TopologicalSort<int> ts(n);
  REP(i, n-1+m) {
    int a, b; cin >> a >> b;
    --a;
    --b;
    ts.add(a, b);
  }
  ts.build();
  vector<int> toposo = ts.order, ans(n, -1);
  reverse(ALL(toposo));
  for (int i : toposo) {
    for (auto e : ts.graph[i]) if (ans[e.dst] == -1) ans[e.dst] = i;
  }
  REP(i, n) {
    if (ans[i] == -1) cout << 0 << '\n';
    else cout << ans[i]+1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int x;
    cin >> x;
    int dig = 0;
    REP(i, 32) if ((x >> i) & 1) dig = i+1;
    cout << ((1 << (dig))-1 == x ? dig : dig-1) << endl;
    return 0;
}




Measured memory_bytes: 3172
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : September 08, 2020 2:24 PM
 *    Problem Name  : E - Crested Ibis vs Monster
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc153/tasks/abc153_e
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
#define ll long long int
#define INF 1000000000
using namespace std;

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

    ll h,n;
    cin >> h >> n;

    ll a[n+1], b[n+1];

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

    ll dp[n+1][h+1];
    dp[0][0] = 0;

    for(ll i=1; i<=h; i++) {
        dp[0][i] = INF;
    }

    for(ll i=1; i<=n; i++) {
        for(ll j=0; j<a[i-1]; j++) {
            if(dp[i-1][j] > b[i-1]) {
                dp[i][j] = b[i-1];
            }
            else dp[i][j] = dp[i-1][j];

            if(j == h){
                break;
            }
        }

        for(ll j=a[i-1]; j<=h; j++) {
            if(dp[i-1][j] > dp[i][j-a[i-1]]+b[i-1]){
                dp[i][j] = dp[i][j-a[i-1]]+b[i-1];
            }
            else dp[i][j] = dp[i-1][j];
        }
    }

    cout << dp[n][h] << endl;

    return 0 ;
}


Measured memory_bytes: 81828
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    vector<int> c(s.size());
    for(int i=0;i<s.size();++i){
        s[i]+= n;
        if(s[i]>'Z') s[i]-=26;
        
}

    cout << s << endl;
    



   

    return 0;
}

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

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

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
long long INF = 1LL<<60;
int n;
int main(){
    int d;
    cin>>d>>n;
    int count=0;
    if(n==100)cout<<llpow(100,d)*(n+1)<<endl;
    else{
        cout<<llpow(100,d)*(n)<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int N,M; cin >>N >>M;
  rep(i, M){ int a; cin >>a; N -= a;}
  cout <<(N >= 0 ? N : -1) <<endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        int mod = (int) 1e9 + 7;
        int[][] dp = new int[s.length() + 1][13];
        
        dp[0][0] = 1;
        
        for( int i = 1; i <= s.length(); i++){
            char c = s.charAt(i-1);
            
            for(int j = 0; j < 13; j++){
                if ( c == '?' ) {
                    for ( int k = 0; k <= 9; k++){
                        int next = (j * 10 + k) % 13;
                        dp[i][next] = (dp[i][next] + dp[i-1][j]) % mod;
                    }
                } else {
                    int num = c - '0';
                    int next = (j * 10 + num) % 13;
                    dp[i][next] = (dp[i][next] + dp[i-1][j]) % mod;
                }
            }
        }
       
        System.out.println(dp[s.length()][5]);
        
    }
}

Measured memory_bytes: 33152
n = gets.to_i

ary = []
 n.times do |i|
 c, s = gets.split
ary[i] = {number: i + 1, city: c, score: s.to_i*-1 }
end

arr = ary.sort_by! do |a|
    [a[:city], a[:score],]
    
end



arr.each do |a|
	 puts a[:number]
	end

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

int k;
int f(int n)
{
	if(n%k==0)return n/k;
	int d=n/k+1;
	return f( n-d*((n%k-1)/d+1)  );
}

int main()
{
	//freopen("1.in","r",stdin);
	int ans=0;
	int n;
	cin>>n;
	while(n--)
	{
		int a;
		cin>>a>>k;
		ans^=f(a);
	}
	if(ans)puts("Takahashi");
	else puts("Aoki");	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main()
{
  map<string, int> unit;
  unit["yotta"] = 24;
  unit["zetta"] = 21;
  unit["exa"] = 18;
  unit["peta"] = 15;
  unit["tera"] = 12;
  unit["giga"] = 9;
  unit["mega"] = 6;
  unit["kilo"] = 3;
  unit["hecto"] = 2;
  unit["deca"] = 1;
  unit["deci"] = -1;
  unit["centi"] = -2;
  unit["milli"] = -3;
  unit["micro"] = -6;
  unit["nano"] = -9;
  unit["pico"] = -12;
  unit["femto"] = -15;
  unit["ato"] = -18;
  unit["zepto"] = -21;
  unit["yocto"] = -24;

  string s;
  getline(cin, s);
  int n = atoi(s.c_str());
  while (n--) {
    getline(cin, s);
    int e = 0;
    string num = s.substr(0, s.find_first_of(" "));
    s = s.substr(s.find_first_of(" ")+1);

    string::size_type dot = num.find_first_of(".");
    if (num[0] == '0') {
      string::size_type nonzero = num.find_first_of("123456789");
      e -= nonzero-dot;
      num = num.substr(nonzero);
    } else {
      if (dot == string::npos) {
	e += num.size()-1;
      } else {
	e += dot-1;
	num.erase(dot, 1);
      }
    }

    if (num.size() >= 2)
      num.insert(1, ".");

    if (s.find_first_of(" ") != string::npos) {
      e += unit[s.substr(0, s.find_first_of(" "))];
      s = s.substr(s.find_first_of(" ")+1);
    }

    cout << num << " * 10^" << e << " " << s << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(void){

    string a, b, c;
    cin >> a >> b >> c ;
    
    //*
    if(a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    //*/
    
    //cout << a.at(0) - 'a' + 'A' << b.at(0) - 'a' + 'A' << c.at(0) - 'a' + 'A' << endl;

    return 0; 
}


Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

int n;

i64 c[1010];
i64 w[1010];

i64 sum[1010];

int dp[1010][1010];

int main()
{
	cin >> n;
	rep(i,0,n - 1)
		cin >> c[i] >> w[i];

	rep(i,1,n)
	{
		sum[i] = sum[i - 1] + w[i - 1];
	}

	auto getsum = [&](int l,int r){
		return sum[r] - sum[l];
	};

	rep(i,0,1000) rep(j,0,1000) dp[i][j] = 1e9;

	rep(i,0,1000)
		dp[i][i + 1] = 1;
	
	rep(w,2,n)
	{
		rep(l,0,n - 1)
		{
			//[l,r)
			int r = l + w;
			if(r > n) continue;

			rep(mid,l + 1,r - 1)
			{
				dp[l][r] = min(dp[l][r] , dp[l][mid] + dp[mid][r]);
			}

			//left is mighty
			{

				i64 w_s = getsum(l + 1,r);
				if(c[l] >= w_s && dp[l + 1][r] == 1)
				{
					dp[l][r] = 1;
				}
			}
			{
				i64 w_s = getsum(l,r - 1);
				if(c[r - 1] >= w_s && dp[l][r - 1] == 1)
				{
					dp[l][r] = 1;
				}
			}
			/*
			rep(i,0,n)
			{
				if(l <= i && i < r)
					cout << "=";
				else
					cout << " ";
			}
			cout << dp[l][r] << endl;
			*/
		}

	}

	cout << dp[0][n] << endl;

}



Measured memory_bytes: 7108
#include<bits/stdc++.h>
using namespace std ;
int a[5][110] , dp[5][110] ;
int main(){
    int N ;
    cin >> N ;
    for( int i = 1 ; i <= 2 ; i++ )
        for( int j = 1 ; j <= N ; j++ )
            cin >> a[i][j] ;
    for( int i = 1 ; i <= 2 ; i++ )
        for( int j = 1 ; j <= N ; j++ )
            dp[i][j] = max( dp[i - 1][j] , dp[i][j - 1] ) + a[i][j] ;
    cout << dp[2][N] << endl ;
    return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
// cout << "YES\n";
// cout << "NO\n";
int main()
{
    ll n;
    cin >> n;
    ll a[n + 5] = {0}, sfx[n + 5] = {0}, sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = n - 1; i > 0; i--)
    {
        sfx[i] = sfx[i + 1] + a[i];
        sum += (sfx[i] % mod * a[i - 1] % mod);
    }
    cout << sum % mod << endl;
    return 0;
}

Measured memory_bytes: 6760
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <list>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define xx first
#define yy second
#define $1 first
#define $2 second

void solveCase() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll a, b, n; cin >>a>>b>>n;
	ll x = (n / b)*b;
	ll mx = 0;
	for (ll i = min(b - 1, n); i >= 0; i--) {
		if (i <= n && i%b != 0) {
			mx = max(mx, i);
			break;
		}
	}
	cout << ((a*mx) / b) - a*(mx / b);

}

int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	solveCase();
}

Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  vector<ll> C(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (ll i = 0; i < N; ++i) {
    cin >> B[i];
  }
  for (ll i = 0; i < N; ++i) {
    cin >> C[i];
  }
  ll ans = 0;
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  for (ll i_b = 0; i_b < N; ++i_b) {
    auto itr_a = lower_bound(A.begin(), A.end(), B[i_b]);
    ll ab = itr_a - A.begin();
    auto itr_c = upper_bound(C.begin(), C.end(), B[i_b]);
    ll bc = C.end() - itr_c;
    if (ab != 0 and bc != 0) {
      ans += ab * bc;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
n = int(input())
t, a = map(int, input().split())
h = input().split()
ans = 0
temp = []
for i in range(n):
    temp .append(t - 0.006 * int(h[i]))
    if abs(temp[ans] - a) > abs(temp[i] - a):
        ans = i
print(ans+1)


Measured memory_bytes: 3060
void main() {
	auto ip = readAs!(int[]), r = ip[0], D = ip[1], x = ip[2];
	auto tmp = x;
	foreach(i; 1..11) {
		x = r*x - D;
		x.writeln;
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		String s1=sc.next();
		String s2=sc.next();
		int dp[][]=new int[s1.length()+1][s2.length()+1];
		for(int i=1;i<=s1.length();i++)
		{
			for(int j=1;j<=s2.length();j++)
			{
				if(s1.charAt(i-1)==s2.charAt(j-1))
				{
					dp[i][j]=dp[i-1][j-1]+1;
				}else {
					dp[i][j]=Math.max(dp[i-1][j], dp[i][j-1]);
				}
			}
		}
	
		//finding the string
		String ans="";
		int n=s1.length();
		int m=s2.length();
		int i=n;
		int j=m;
		while(i>0&&j>0)
		{
			if(s1.charAt(i-1)==s2.charAt(j-1))
			{
				ans+=s1.charAt(i-1);
				i--;
				j--;
			}else {
				if(dp[i-1][j]>dp[i][j-1])
				{
					i--;
					
				}else {
					j--;
				}
			}
		}
		char reverse[]=ans.toCharArray();
		for( i=reverse.length-1;i>=0;i--)
		{
			System.out.print(reverse[i]);
		}
	}
}


Measured memory_bytes: 89016
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	string s;
	while (1) {
		cin >> s;
		if (s == "0") break;
		int sum = 0;
		REP(i, s.size()) {
			sum += atoi(s.substr(i, 1).c_str());
		}
		cout << sum << endl;
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}



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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

int A, B, C;

map<pair<PII,int>, bool> h;

int cnt = 0;

int main()
{
	giii(A, B, C);
	while (1)
	{
		if ((A & 1) || (B & 1) || (C & 1))
		{
			printf("%d\n", cnt);
			return 0;
		}
		if (h.count(mp(mp(A, B), C)))
		{
			puts("-1");
			return 0;
		}
		++cnt;
		int a = A, b = B, c = C;
		h[mp(mp(A, B), C)] = 1;
		A = (b + c) >> 1;
		B = (a + c) >> 1;
		C = (a + b) >> 1; 
	}
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long ans = 0;
		
		for(int i = 1; i < n + 1; i++) {
			if((i % 3) == 0 || (i % 5) == 0) {
				ans += 0;
			}
			else {
				ans += i;
			}
		}
		
		System.out.println(ans);
	}

}


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

int main() {
    double a, b, x;
    cin >> a >> b >> x;

    double border = b * a * a / 2;
    double theta;

    if (x <= border) {
        theta = atan2(b, (2*x)/(b*a));
    } else theta = atan2(2*b-(2*x)/(a*a),a);

    double pai = acos(-1);
    double kakudo;
    kakudo = theta / pai * 180;

    printf("%.10f\n",kakudo);

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int i;
  char str[1001],buff;
  scanf("%s",&str);
  printf("%s",str);
  for(i=0;str[i]!='\0';i++);
  if(str[i-1]=='s')
    printf("es");
  else
    printf("s");
  
}

Measured memory_bytes: 1732
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		for(int i = 0; i < N; i++){
			String X = sc.next();
			String Y = sc.next();
			System.out.println(solve(X, Y));
		}
	}
	
	public static int solve(String X, String Y){
		int[][] dp = new int[X.length()+1][Y.length()+1];
		
		for(int i = 0; i <= X.length(); i++)
			dp[i][0] = 0;
		for(int j = 0; j <= Y.length(); j++)
			dp[0][j] = 0;
		
		for(int i = 1; i <= X.length(); i++){
			for(int j = 1; j <= Y.length(); j++){
				if(X.charAt(i-1) == Y.charAt(j-1)){
					dp[i][j] = dp[i-1][j-1] + 1;
				}else{
					dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]);
				}
			}
		}
		
		return dp[X.length()][Y.length()];
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}



Measured memory_bytes: 64536
from sys import stdin
from collections import deque
H, W = map(int, stdin.readline().split())
C = [list(map(int, stdin.readline().split())) for i in range(H)]
prev = [0] * W
def height(C):
    global prev
    P = [0 if C[-1][i] == 1 else prev[i] + 1 for i in range(W)]
    prev = P[:]
    return P
def square(C):
    P = height(C)
    G = deque()
    L = deque()
    for i, v in enumerate(P):
        if not L or v > L[-1][1]:
            L.append((i, v))
        elif v < L[-1][1]:
            k = i - 1
            while L and v < L[-1][1]:
                a = L.pop()
                G.append((k - a[0] + 1) * a[1])
            L.append((a[0], v))
    len_P = len(P)
    while L:
        a = L.pop()
        G.append((len_P - a[0]) * a[1])
    return max(G)
print(max([square(C[:i + 1]) for i in range(H)]))

Measured memory_bytes: 24904
N = int(input())
nt, nx, ny = 0, 0, 0
for k in range(N):
    t, x, y = map(int,input().split())
    if abs(ny-y)+abs(nx-x) > t-nt or (abs(ny-y)+abs(nx-x))%2 != (t-nt)%2:
        print("No")
        exit(0)
    else:
        nt, nx, ny = t, x, y
print("Yes")


Measured memory_bytes: 46312
from collections import deque
n, m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

graph = [[] for _ in range(n)]
out_deg = [0] * n
dp = [0]*n

for x, y in xy:
    graph[y-1].append(x-1)
    out_deg[x-1] += 1

stack = deque([i for i in range(n) if out_deg[i] == 0])

while stack:
    node = stack.popleft()
    for i in graph[node]:
        dp[i] = max(dp[i], dp[node]+1)
        out_deg[i] -= 1
        if out_deg[i] == 0:
            stack.append(i)

print(max(dp))

Measured memory_bytes: 42832
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
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; }
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N, M;
    cin >> N >> M;
    vec2 f(M + 1, vec(1 << N, 1e18));
    f[0][0] = 0;

    rep1(i, M){
        ll a, b;
        cin >> a >> b;
        ll state = 0;
        rep(j, b){
            ll c;
            cin >> c;
            --c;
            state += 1 << c;
        }

        rep(j, 1 << N) chmin(f[i][j | state], f[i - 1][j] + a);
        rep(j, 1 << N) chmin(f[i][j], f[i - 1][j]);
    }

    if(f[M][(1 << N) - 1] == 1e18) drop(-1);
    print(f[M][(1 << N) - 1]);

    return 0;
}

Measured memory_bytes: 32384
n = input()
a = input().split()
n = int(n)
a = [int(s) for s in a]
a.sort()
#print(a)
s=0

for i in range(len(a)-1):
    #print(a[i],a[i+1])
    
    if a[i]==a[i+1]:
        print("NO")
        s=s+1
        break
        
if s == 0: print("YES")

Measured memory_bytes: 25812
N = int(input())
A = list(map(int, input().split()))

A = sorted(A, reverse=True)

counter = 1
edge1 = 0
flag = 0

for i in range(len(A)-1):
    if edge1 == 0:
        edge1 = A[i]
    if counter == 4:
        print(edge1*edge1)
        break
    elif A[i] == A[i+1] and counter < 4:
        counter = counter + 1
    elif A[i] != A[i+1] and counter >= 2:
        flag = 1
        start = i
        break
    else:
        edge1 = 0
else:
    print(0)
if flag == 1:
    for i in range(start+1, len(A)-1):
        if A[i] == A[i+1]:
            print(edge1*A[i])
            break
    else:
        print(0)


Measured memory_bytes: 14480
// Walk on Multiplication Table.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
int main()
{

	ll n;

	cin >> n;

	ll ans = 4e18;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0)
		{
			ans = min( (i - 1)+((n / i) - 1), ans );
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
using namespace std;
typedef long long   llong;
typedef vector<int> vi;

//BS.
//itr.
int main(){
	int n;
	cin>>n;
	
	vi l(n);
	REP(i,n) cin>>l[i];
	sort(ALL(l));
	
	llong ans=0;
	REP(i,n-1)for(int j=i+2;j<n;++j){
		auto itr=upper_bound(l.begin()+i+1,l.begin()+j,abs(l[i]-l[j]));
		auto itr2=lower_bound(l.begin()+i+1,l.begin()+j,l[i]+l[j]);
		int num=itr2-itr;
		if(num>0) ans+=num;
	}
	
	cout<<ans<<endl;
}


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

if N%10 == 2 or N%10 == 4 or N%10 == 5 or N%10 == 7 or N%10 == 9:
    print('hon')
if N%10 == 0 or N%10 == 1 or N%10 == 6 or N%10 == 8:
    print('pon')
if N%10 == 3:
    print('bon')

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

int main() {
    long long a, b; cin >> a >> b;
    if (a * b <= 0) { puts("Zero"); return 0; }
    else if (a > 0 && b > 0) { puts("Positive"); return 0; }
    else { 
        if ((b - a + 1) % 2) puts("Negative");
        else puts("Positive");
    }
}

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

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

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

	int A,B; cin >> A >> B;

	cout << ((A*B)%2 == 0? "Even":"Odd") << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
inline int fastpow(int x,int y)
{
	int res=1;
	while (y)
	{
		if (y&1) res=1LL*res*x%mod;
		x=1LL*x*x%mod;
		y>>=1;
	}
	return res;
}
inline int inverse(int x){return fastpow(x,mod-2);}
int n,a[100005],ans;
int main()
{
	cin>>n;
	for (int i=1;i<n;i++) a[i]=(a[i-1]+inverse(i+1))%mod;
	for (int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		ans=(ans+1LL*x*a[i]%mod)%mod;
		ans=(ans+1LL*x*a[n-1-i]%mod)%mod;
		ans=(ans+1LL*x)%mod;
	}
	for (int i=0;i<n;i++) ans=1LL*ans*(i+1)%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
n = int(input())
an= list(map(int, input().split()))

datas = [0] * (n+1)
for a in an:
    datas[a] += 1

ans = 0
for i in range(1,n+1):
    if datas[i] > 1:
        ans += datas[i] * (datas[i]-1)/2
ans = int(ans)

for k in range(0,n):
    if datas[an[k]] > 1:
        print(int(ans - datas[an[k]] * (datas[an[k]]-1)/2 + (datas[an[k]]-1) * (datas[an[k]]-2)/2))
    else:
        print(ans)


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

ans = 0
for i in range(1, N+1):
    if i % 3 == 0 and i % 5 == 0:
        continue
    elif i % 3 == 0:
        continue
    elif i % 5 == 0:
        continue
    else:
        ans += i
print(ans)


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
typedef pair<int, int> P;
typedef long long ll;
long long MOD = 998244353;
long long modpow(long long a, long long n)
{
    if (n == 0)
        return 1;
    if (n % 2 == 0)
    {
        long long t = modpow(a, n / 2);
        return t * t % MOD;
    }
    return a * modpow(a, n - 1) % MOD;
}

class Combination
{
    vector<long long> fact;
    vector<long long> factinv;
    long long MOD = 998244353;
    long long modpow(long long a, long long n)
    {
        if (n == 0)
            return 1;
        if (n % 2 == 0)
        {
            long long t = modpow(a, n / 2);
            return t * t % MOD;
        }
        return a * modpow(a, n - 1) % MOD;
    }

    long long modinv(long long a)
    {
        // mod is prime
        return modpow(a, MOD - 2);
    }

public:
    Combination(int n) : fact(n), factinv(n)
    {
        fact[0] = 1;
        for (int i = 1; i < n; i++)
        {
            fact[i] = fact[i - 1] * i % MOD;
        }
        factinv[n - 1] = modinv(fact[n - 1]);
        for (int i = n - 2; i >= 0; i--)
        {
            factinv[i] = factinv[i + 1] * (i + 1) % MOD;
        }
    }

    long long ncr(long long n, long long r)
    {
        if (r < 0 || r > n)
            return 0;
        return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
    }

    long long npr(long long n, long long r)
    {
        if (r < 0 || r > n)
            return 0;
        return fact[n] * factinv[n - r] % MOD;
    }

    long long nhr(long long n, long long r)
    {
        if (n == 0 && r == 0)
            return 1;
        return ncr(n + r - 1, r);
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    Combination c(1000000);
    for (int i = 0; i <= k; i++)
    {
        ans += (((modpow(m - 1, n - 1 - i) * m) % MOD) * c.nhr(n - i, i)) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 18780
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N=0;
    
    
    cin>>N;
    
    while(N!=0){ 
        vector<string> S(N);
        int ans=0;

        bool rf=false,lf=false,next_up=true;

        for(auto &&x:S){
            cin>>x;
        }

        for(int i=0;i<N;i++){

            if(S[i]=="lu")lf=true;
            if(S[i]=="ld")lf=false;
            if(S[i]=="ru")rf=true;
            if(S[i]=="rd")rf=false;

            if(next_up&&rf&&lf){
                next_up=false;
                ans++;
            }
            if(next_up==false&&rf==false&&lf==false){
                next_up=true;
                ans++;
            }
        }
        cout<<ans<<endl;
        cin>>N;
    }




}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=1000000000;
ll INF=10000000000000000;

int main(){
    ll n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    ll u=min(a,b);
    u=min(u,c);
    u=min(u,d);
    u=min(u,e);
    if (n%u==0) cout << 4+n/u << endl;
    else cout << 4+n/u+1 << endl;
    
}


Measured memory_bytes: 256
using System;
using CompLib.Util;

public class Program
{
    private const int MaxA = 10000006;
    private int N;
    private int[] A;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.IntArray();
        var flag = new int[MaxA + 1];
        foreach (int i in A)
        {
            flag[i]++;
        }

        int ans = 0;
        foreach (int i in A)
        {
            bool f = true;
            for (int d = 1; d * d <= i; d++)
            {
                if (i % d == 0)
                {
                    int j = i / d;
                    if (flag[d] >= (d == i ? 2 : 1))
                    {
                        f = false;
                        break;
                    }

                    if (flag[j] >= (j == i ? 2 : 1))
                    {
                        f = false;
                        break;
                    }
                }
            }

            if (f) ans++;
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 46688
open Printf
open Scanf

class unionfind size =
  object(self)
  val mutable forest = [|(0,0)|]
  initializer begin
    forest <- Array.init size (fun x -> (x,1))
  end
  method forest () = begin
    forest
  end
  method print_forest () = begin
    let _ = Array.iter (fun x -> Printf.printf "(%d,%d);" (fst x) (snd x)) forest in
    print_newline()
  end
  method find i = begin
      let (index, size) = forest.(i) in
      if (i = index) then (i, size)
      else
       let (nxt_index, nxt_size) = self#find index in
       forest.(i) <- (nxt_index, nxt_size);
       (nxt_index, nxt_size)
  end

  method union i j = begin
    let (x, x_size) = self#find i in
    let (y, y_size) = self#find j in

    if (x = y) then ()
    else
      let () = forest.(x) <- (y, x_size + y_size) in
      forest.(y) <- (y, x_size + y_size)
  end
end

let (n,m) = sscanf (read_line ()) " %d %d" (fun a b -> (a,b))
let query = Array.make m (0,0);;
for i = 0 to m-1 do
    query.(i) <- sscanf (read_line ()) " %d %d" (fun a b-> (a-1,b-1))
done

let ans = Array.make m 0;;
ans.(m-1) <- n*(n-1)/2;;
let forest = new unionfind n;;

for i = m-2 downto 0 do
  (*let _ = forest#print_forest() in*)
  let a,b = query.(i+1) in
  let ain,asi = forest#find a in
  let bin,bsi = forest#find b in
  if (ain = bin) then
    ans.(i) <- ans.(i+1)
  else
    let () = ans.(i) <- ans.(i+1) - (asi * bsi) in
    forest#union ain bin
done;;

for i = 0 to m-1 do
  printf ("%d\n") ans.(i)
done


Measured memory_bytes: 17024
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  ll N,M;cin>>N>>M;
  vi A(N);rep(i,N)cin>>A[i];
  sort(all(A));
  reverse(all(A));
  bool ok=true;
  double tot =0;
  rep(i,N)tot+=A[i];
  double in =tot/(4*M);
  ll cnt =0
  rep(i,N){
    if((double)A[i]>=in){cnt++;}
  }
  if(cnt>=M)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
int n,m,i,j,k,count1=0,count2=0;
using namespace std;
void ABC110(void);
void ABC111(void);
void ABC112(void);
void ABC113(void);
void ABC114(void);
void ABC115(void);
void ABC116(void);
void ABC117(void);
void ABC118(void);
void ABC119(void);

int main(void){
    ABC118();
}

void ABC118(){
    int x;
    cin>>n>>m;
    vector<int> vec(m);
    for(i=0;i<n;i++){
        cin>>k;
        for(j=0;j<k;j++){
            cin>>x;
            vec[x-1]++;
        }
    }
    cout<<count(vec.begin(),vec.end(),n)<<endl;
}

Measured memory_bytes: 256