akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,Q;
    int s,t,x;
    vector<int> D;
    set<tuple<int,int,int>> W,R;
    set<tuple<int,int,int>> C;
    cin >> N >> Q;
    REP(i,N){
        cin >> s >> t >> x;
        W.insert(make_tuple(s-x,t-x,x));
    }
    REP(i,Q){
        int d;
        cin >> d;
        D.push_back(d);
    }
    
    REP(i,Q){
        int s,t,x;
        while(W.size()>0 && get<0>(*W.begin())<=D[i]){
            s=get<0>(*W.begin());
            t=get<1>(*W.begin());
            x=get<2>(*W.begin());
            cerr << x << " ";
            R.insert(make_tuple(t,s,x));
            C.insert(make_tuple(x,s,t));
            W.erase(W.begin());
        }
        cerr << "|";
        while(R.size()>0 && get<0>(*R.begin())<=D[i]){
            s=get<1>(*R.begin());
            t=get<0>(*R.begin());
            x=get<2>(*R.begin());
            cerr << x << " ";
            C.erase(make_tuple(x,s,t));
            R.erase(R.begin());
        }
        cerr << "|   ";
        
        if(C.empty()){
            cout << -1 << endl;
            cerr << -1 << endl;
        }else{
            decltype(C)::iterator it=C.begin();
            cout << get<0>(*it) << endl;
            cerr << get<0>(*it) << endl;
        }
    }
  return 0;
}



Measured memory_bytes: 27760
import sys
input=sys.stdin.readline
import string
import bisect

def main():
    s = input().strip()
    t = input().strip()

    if not all(s.find(c) >= 0 for c in t):
        print(-1)
        exit()
    
    sa = [[] for _ in string.ascii_lowercase]
    ai = ord('a')
    for i,c in enumerate(s):
        sa[ord(c)-ai].append(i+1)
#    print(sa)

    ls = len(s)
    ans = 1 # 条件を満たす整数
    i = 1 # s の何番目の文字から探し始めるか
    for c in t:
        a = sa[ord(c)-ai]
        if len(a) == 0 or i > a[-1]:
            ans += ls-i+1
            i = 1
        bi = bisect.bisect_left(a,i)
        if bi < len(a):
            ans += a[bi]-i+1
            i = a[bi]+1
#        print("c,a,ans,i=", c, a, ans, i)
    print(ans-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8180
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll fast_exp(ll base, ll exp1) {
    base%=mod;
    ll res=1;
    while(exp1>0) {
       if(exp1&1) res=(res*base)%mod;
       base=(base*base)%mod;
       exp1/=2;
    }
    return res%mod;
} 

ll add(ll x,ll y)
{
    return (x+y+mod)%mod;
}

ll mul(ll x,ll y)
{
    return (x*y)%mod;
}

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    char c;
    cin>>c;
    if(c>='A' and c<='Z')
        cout<<"A\n";
    else
        cout<<"a\n";
	printclock;
	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int n,m;
    int cost[600][600];
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        rep(i,600)rep(j,600)cost[i][j]=999999999;
        rep(i,m){
            int a,b;
            cin>>a>>b;
            a--,b--;
            cost[a][b] = cost[b][a] = 1;
        }
        rep(k,n){
            rep(i,n){
                rep(j,n){
                    cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
                }
            }
        }
        int sum=0;
        rep(i,600){
            if(cost[0][i]<=2&&i!=0)sum++;
        }
        cout<<sum<<endl;
    }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, K;
    cin >> N >> K;

    ll ans = 0;
    
    if(K == 0){
        cout << N*N << endl;
        return 0;
    }
    for(ll i=1; i<=N; i++){
        if(i>K){
            ans += ll(N/i)*(i-K) + max(ll(0), (N%i-K+1));
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N,Q;
	string S;
	cin >>N >> S >> Q;
	vector<set<int>>Set(26);
	for (int n = 0;n<S.size();++n) {
		Set[S[n] - 'a'].insert(n);
	}
	vector<int>Ans;
	for (int n = 0;n<Q; ++n) {
		int q1;
		cin >> q1;
		if (1 == q1) {
			int q2;
			char q3;
			cin >> q2 >> q3; 
			Set[S[q2 - 1]-'a'].erase(q2 - 1); 
			S[q2 - 1] = q3;
			Set[S[q2 - 1]-'a'].insert(q2 - 1);
		}
		else
		{
			int q2, q3;
			cin >> q2 >> q3;
			int ans = 0;
			for (int m = 0;m < 26;++m) {
				set<int>::iterator it = Set[m].lower_bound(q2-1);
				if (it != Set[m].end() && *it <q3) {
					++ans;
				}
			}
			Ans.push_back(ans);
		}
	}
	for (int n = 0;n<Ans.size();++n) {
		cout << Ans[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 27400
S = input()

if S[0]=='A' and S[2:-1].count('C')==1:
    S=S.replace("A", "a")
    S=S.replace("C", "c")
    if S.islower()==True:
        print('AC')
    else:
        print('WA')
else:
    print('WA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b) // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main()
{
  int X;
  cin >> X;
  if (1 < X && X < 9 && X % 2 != 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
while True:
    x, y = tuple(map(int, raw_input().split()))
    if x + y == 0:
        break
    l = [0] * x
    s = y
    idx = 0

    while True:
        if y == 0:
            y = l[idx]
            l[idx] = 0
        else:
            y = y - 1
            l[idx] = l[idx] + 1
            if l[idx] == s:
                print idx
                break
        if idx == x - 1:
            idx = 0
        else:
            idx = idx + 1

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

using namespace std;
using ll = long long;
using pi = pair<int,int>;
using pii = pair<int,pi>;

int main() {
    int n;
    cin>>n;
    vector<int> vd={-n,+1,+n,-1};
    vector<bool> seki(n*n,true);
    ll ans=0;
    int p;
    vector<int> dp(n*n,n*n);
    for(int i = 0;i < n;++i) {
        for(int j = 0;j < n;++j) {
            dp[i*n+j]=min(i,dp[i*n+j]);
            dp[(n-1-i)*n+j]=min(i,dp[(n-1-i)*n+j]);
        }
    }
    for(int j = 0;j < n;++j) {
        for(int i = 0;i < n;++i) {
            dp[j*n+i]=min(i,dp[j*n+i]);
            dp[j*n+(n-1-i)]=min(i,dp[j*n+(n-1-i)]);
        }
    }
    int pp=-1;
    for(int i = 0;i < n*n;++i) {
        cin>>p;
        --p;
        ans+=dp[p];
        deque<pi> deq;
        --dp[p];
        deq.emplace_front(dp[p],p);
        int tans;
        while(!deq.empty()) {
            auto t=deq.front();
            deq.pop_front();
//cerr<<p<<" "<<t.first<<" "<<t.second<<endl;
            for(int i = 0;i < 4;++i) {
                int np=t.second+vd[i];
                int res=t.second%n;
                int nc=t.first;
                if(np<0||n*n<=np||(res==n-1&&i==1)||(res==0&&i==3)) {
                    continue;
                }
                if(seki[np])++nc;
                if(dp[np]<=nc)continue;
                dp[np]=nc;
                if(seki[np]) {
                    deq.emplace_back(nc,np);
                }
                else deq.emplace_front(nc,np);
            }
        }
        seki[p]=false;
    }
    cout<<ans<<"\n";
    return 0;
}


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

int main() {
	string s;
	cin >> s;
	
	cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
	
}

Measured memory_bytes: 3632
<?php
list($n,$x)=explode(" ",trim(fgets(STDIN)));
$l=explode(" ",trim(fgets(STDIN)));
$ans=1;
$d=0;
$i=0;
while($i<$n){
  $d+=$l[$i];
  if($d<=$x){
    ++$ans;
  }else{
    echo $ans;
    exit;
  }
  ++$i;
}
echo $ans;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

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

    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        ll start = i;
        ll end = n / i * i;
        ll now = (n / i ) * (start + end) / 2;
        ans += now;
    }
    cout << ans << endl;

}


Measured memory_bytes: 3600
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1LL << 60;
int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n), s(n), b(n), bs(n);
  rep(i, n) cin >> a[i];
  s[0] = a[0];
  REP(i, 1, n) { s[i] = s[i - 1] + a[i]; }
  rep(i, n) { b[i] = max(0LL, a[i]); }
  bs[0] = b[0];
  REP(i, 1, n) { bs[i] = bs[i - 1] + b[i]; }
  ll ans = 0;
  REP(i, k - 1, n) {
    rep(j, 2) {
      ll tmp = 0;
      if (j == 0) {
        // all black
        tmp = s[i];
        if (i - k >= 0) {
          tmp -= s[i - k];
        }
      }
      if (i - k >= 0) {
        tmp += bs[i - k];
      }
      tmp += bs[n - 1] - bs[i];
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
#define ll long long
int decimalsum(int x){
int sum=0;
while(x){
    sum+=x%10;
    x=x/10;
}
return sum;
}

int rec(vector<vector<int>>dp , int n , vector<vector<int>>a, int x , int p){
if(x==n)return 0;
if(dp[x][p]!=-1)return dp[x][p];
 return dp[x][p] = max(rec(dp , n , a ,x+1 , (p+1)%3) + a[x][(p+1)%3] , rec(dp , n , a ,x+1 , (p+2)%3) + a[x][(p+2)%3]);



}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//                int php[4000] , cdc[8000], cdm[8000];
//                for(int j=0;j<5;j++){
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//
//int t;
//cin>>t;
//while(t--)
{
   //solve();

  int n ;
  cin>>n;

  vector<vector<int>>dp(n , vector<int>(3 , -1));
  vector<vector<int>>a(n , vector<int>(3 , -1));
  for(int i=0;i<n;i++){
cin>>a[i][0]>>a[i][1]>>a[i][2];
  }
  int ans=0;
dp[0][0]=a[0][0];
dp[0][1]=a[0][1];
dp[0][2]=a[0][2];
for(int i=1;i<n;i++){
    dp[i][0]= a[i][0] + max(dp[i-1][1] ,dp[i-1][2]);
    dp[i][1]= a[i][1] + max(dp[i-1][0] ,dp[i-1][2]);
    dp[i][2]= a[i][2] + max(dp[i-1][1] ,dp[i-1][0]);
}
ans= max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2] ));
  cout<<ans<<endl;

}
    return 0;
}


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

int main()
{
 //   cout << "Hello world!" << endl;
    int N;

    cin>>N;

    long long int A[N],Side1=-1,Side2=-1;

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

    sort(A,A+N);
    int Flag=0;

    for(int i=N-1;i>=1;)
    {
        if(A[i]==A[i-1] && Flag==0)
        {
            Side1=A[i];
            i=i-2;
            Flag=1;
        }
        else
        {
            if(Flag==1 && A[i]==A[i-1])
            {
                Side2=A[i];
                break;
            }
            else
            {
                i--;
            }
        }
    }

    if(Side1==-1 || Side2==-1)
    {
        cout<<"0"<<endl;
    }
    else
    {
        cout<<Side1*Side2<<endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long

using namespace std;

int main()
{
	ll N;
	cin >> N;
	vector<ll> T(N), A(N);
	cin >> T[0] >> A[0];

	ll crtA = T[0], crtB = A[0];
	for (ll i = 1; i < N; i++) {
		cin >> T[i] >> A[i];
		ll n, nA, nB;
		if (crtA % T[i] == 0) nA = crtA / T[i];
		else nA = crtA / T[i] + 1;
		if (crtB % A[i] == 0) nB = crtB / A[i];
		else nB = crtB / A[i] + 1;
		n = max(nA, nB);
		crtA = n * T[i]; crtB = n * A[i];
	}
	cout << crtA + crtB << endl;
	
}

int dsum(ll a) {
	int ans = 0;
	while (a != 0) {
		ans += a % 10;
		a /= 10;
	}
	return ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;
using P = pair<ll, ll>;
using Graph = vector<vector<P>>;
const ll INF = 1LL<<60;

ll V, E, r;
Graph G;
vector<ll> dist;

void dijkstra(){
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, r)); // 最短距離, ノード番号
  while(!que.empty()){
    P now = que.top();
    que.pop();
    ll nowDist = now.first;
    ll nowNode = now.second;
    if (nowDist > dist[nowNode]) continue;
    for(P next : G[nowNode]){
      ll nextDir = next.first;
      ll nextWeight = next.second;
      if (dist[nextDir] <= dist[nowNode] + nextWeight) continue;
      dist[nextDir] = dist[nowNode] + nextWeight;
      que.push({dist[nextDir], nextDir});
    }
  }
}

int main(){
  cin >> V >> E >> r;
  G.resize(V);
  ll s, t, d;
  rep(i, E){
    cin >> s >> t >> d;
    G[s].push_back(P(t, d));
  }
  dist.resize(V, INF);
  dist[r] = 0;
  dijkstra();

  for(ll x : dist){
    if (x == INF)
      cout << "INF" << endl;
    else
      cout << x << endl;
  }
  
  return 0;
}


Measured memory_bytes: 19320
#include <cstdio>

int dump(int A[], int N){
    for (int i=0; i<N; i++){
        if(i > 0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

int insertionSort(int A[], int N){
    for (int i=1; i<N; i++){
        int v = A[i];
        int j = i-1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        dump(A,N);
    }
}

int main (){
    int N;
    scanf("%d",&N);
    int A[N];
    for (int i=0; i<N; i++){
        scanf("%d", &A[i]);
    }

    dump(A, N);
    insertionSort(A, N);
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////


#define INF 1e12

ll N, M;
vector<ll> abv[1010];
ll i, j, k;
vector<ll> ans;
ll ansck;
ll mk[1010],mk2[1010];

bool dfs(ll a,ll p){
    mk2[a] = 1;
    ll i = 0, f = 0;
    fornum(i,0,abv[a].size()){
        ll b = abv[a][i];
        if(b<p)
            continue;
        if(b==p){
            f++;
        }else if(mk2[b]){
            f +=99999;
        }
        mk[b]++;
    }
    //printf("<%lld>", f);
    if(f==1){
        ans.push_back(a);
        return true;
    }else if(f==0){
        fornum(i,0,abv[a].size()){
            ll b = abv[a][i];
            if(b<p)
                continue;
            if(mk[b]<2&&dfs(b,p)){
                ans.push_back(a);
                return true;
            }
        }   
    }
    fornum(i,0,abv[a].size()){
        ll b = abv[a][i];
        if(b<p)
        mk[b]--;
    }
    mk2[a] = 0;
    //printf("\n");
    return false;
}

int main(){
    scanf("%lld%lld", &N, &M);
    fornum(i,0,M){
        ll a, b;
        scanf("%lld%lld", &a, &b);
        abv[a].push_back(b);
    }
    fornum(i,0,N){
        fornum(j,0,N){
            mk[j + 1] = 0;
        }
        mk[i + 1] = 1;
        //printf("%lld\n", i + 1);
        if(dfs(i+1,i+1)){
            printf("%d\n", ans.size());
            fornum(i,0,ans.size()){
                printf("%lld\n", ans[i]);
            }
            return 0;
        }
    }
    printf("-1");
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(int argc, char const *argv[]) {
  int a,b;scanf("%d %d",&a,&b);
  long long money=0;
  if(a==1)money+=300000;
  if(a==2)money+=200000;
  if(a==3)money+=100000;
  if(b==1)money+=300000;
  if(b==2)money+=200000;
  if(b==3)money+=100000;
  if(a==1&&b==1)money+=400000;
  printf("%lld\n",money);
  return 0;
}


Measured memory_bytes: 128
import math
n = []
while True:
    try:
        n.append(int(raw_input()))
    except:
        break
 
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
 
for i in n:
     print sum(p[:i])

Measured memory_bytes: 37128
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

int n,d;
int check(vi &a, vi &b) {
	int tmp = 0;
	REP (i,(int)a.size()) {
		tmp += pow(a[i]-b[i],2);
	}
	if ((int)sqrt(tmp) * (int)sqrt(tmp) == tmp) {
		return 1;
	} else {
		return 0;
	}
}

bool solve() {
	cin >> n >> d;
	int ans = 0;
	vi c[n];
	REP (i,n) REP (j,d) {
		int x; cin >> x; c[i].pb(x);
	}
	REP (i,n) {
		REP (j,n) {
			if (i >= j) continue;
			ans += check(c[i],c[j]);
		}
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 256
def main():
    x, n = list(map(int, input().split()))
    if n > 0:
        p_list = list(map(int, input().split()))
    else:
        return x
    ans = 0
    diff = abs(p_list[0]-x)
    for i in range(n):
        diff_new = abs(p_list[i] - x)
        if diff_new < diff:
            ans =i
            diff=diff_new
    #print(p_list[ans])

    for i in range(200):
        if p_list[ans] - i not in p_list:
            return p_list[ans] - i
            break
        elif p_list[ans] + i not in p_list:
            return p_list[ans] + i
            break
            
if __name__=='__main__':
    print(main())

Measured memory_bytes: 9200
#include <stdio.h>

int main(int argc,char* argv[]){
  
  int year,month,day;

  while(scanf("%d %d %d",&year,&month,&day) != EOF){
    if(year < 1868 || (year == 1868 && month < 9) || (year == 1868 && month == 9 && day < 8)){
      printf("pre-meiji\n");
    }else if(year < 1912 || (year == 1912 && month < 7) || (year == 1912 && month == 7 && day < 30)){
      printf("%s %d %d %d\n","meiji",year-1867,month,day);
    }else if(year < 1926 || (year == 1926 && month < 12) || (year == 1926 && month == 12 && day < 25)){
      printf("%s %d %d %d\n","taisho",year-1911,month,day);
    }else if(year < 1989 || (year == 1989 && month < 1) || (year == 1989 && month == 1 && day < 8)){
      printf("%s %d %d %d\n","showa",year-1925,month,day);
    }else{
      printf("%s %d %d %d\n","heisei",year-1988,month,day);
    }
    
    
  }

  return 0;
  
}

Measured memory_bytes: 0
/*
    Yeah Nigga!
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ft first
#define sd second

typedef long long ll;

const ll INF = LLONG_MAX;
const ll mod = 1e9 + 7;
// #define int long long
const int N = 2e5 + 10;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<int> prefix_function(string &s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}

signed main() {
    int n;
    string s;
    cin >> n;
    cin.ignore();
    cin >> s;
    int mx = 0;
    for(int i=1; i<n; i++) {
        string temp = s.substr(i);
        string temp2 = s.substr(0, i);
        int id = temp.length();
        temp += '$';
        temp += temp2;
        vector<int> vc = prefix_function(temp);
        for(int j=id+1; j<vc.size(); j++) mx = max(mx, vc[j]);
    }
    cout << mx << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m; double pre[2009], dp[2009]; string s;
int main() {
	while (cin >> n >> m, n) {
		cin >> s;
		fill(pre, pre + n, 0.0); pre[0] = 1.0;
		for (int i = 0; i < m; i++) {
			fill(dp, dp + n, 0.0);
			for (int j = 0; j < n; j++) {
				int c = j;
				for (int k = 1; k <= 6; k++) {
					if (++c == n) c = 0;
					dp[c] += pre[j];
				}
			}
			for (int j = 0; j < n; j++) pre[j] = dp[j] / 6.0;
		}
		double ret = 0.0;
		for (int i = 0; i < n; i++) {
			double res = 0.0;
			int c = i;
			for (int j = 0; j < n; j++) {
				if (s[j] == 'R') res += pre[c];
				if (++c == n) c = 0;
			}
			ret = max(ret, res);
		}
		cout << fixed << setprecision(15) << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3188
N,K = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
  P[i]-=1
#print(P)
C = list(map(int,input().split()))
Flag = True
for c in C:
  if c >= 0:
    Flag = False
    break
if Flag:
  print(max(C))
  exit()
L = []
for i in range(N):
  #visited = set([])
  Flag = False
  now = i
  temp = []
  while True:
    if Flag and now == i:
      break
    nxt = P[now]
    Flag = True
    temp.append(C[nxt])
    now = nxt
  L.append(temp)
#print(L)
ans = 0
S = []
for X in L:
  start = [0]
  for i in range(len(X)):
    temp = start[-1]+X[i]
    start.append(temp)
  S.append(start)
#print(S)
for X,SS in zip(L,S):
  n = len(X)
  cycle_sum = SS[-1]
  if K <= n:
    kouho = max(SS[:K+1])
  elif cycle_sum < 0:
    kouho = max(SS)
  else:
    amari = K%n
    loop = K//n
    first = 0 #余りよりも後で最大
    second = 0 #余りよりも前で最大
    first = (loop-1)*cycle_sum + max(SS)
    second = loop*cycle_sum + max(SS[:amari+1])
    kouho = max(first,second)
  ans = max(ans,kouho)
print(ans)
  
    
  


Measured memory_bytes: 496184
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main()
	{
  bool[] isPrimes = makePrimeList(100000);//i-1が素数かどうか
  int[] trueCount = new int[100000];//i-1以下の条件を満たす数の個数

    int nowTrueCount = 0;
    for(int i=0; i<trueCount.Length; i+=2)//1以上i以下の素数の個数
    {
      if(isPrimes[i] && isPrimes[(i+1)/2]) nowTrueCount++;
      trueCount[i] = nowTrueCount;
    }
  
    int q = int.Parse(Console.ReadLine());
    for(int i = 0; i < q; i++)//q個のクエリに答える
    {
      int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
      int answer = trueCount[nums[1]-1];
      if(nums[0]-3 >= 0) answer -= trueCount[nums[0]-3];//偶数には0が入っているので-2でなく-2
      Console.WriteLine(answer);
    }

	}

  static bool[] makePrimeList(int maxPrime)//引数max以下の素数のリストを作成。エラトステネスの篩を用いる。
  {
    bool[] isPrimes = new bool[maxPrime];//素数リスト
    isPrimes[0] = false;
    for(int i = 1; i < maxPrime; i++) isPrimes[i] = true;
    
    for(int i = 2; i < Math.Sqrt(maxPrime); i++)
    {
      if(isPrimes[i-1])
      {
        for (int j = i*2; j <= maxPrime; j+=i)
        {
          isPrimes[j-1] = false;
        }
      }
    }

    return isPrimes;
  }
  
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  string a, b;

  cin >> a >> b;

  reverse(a.begin(), a.end());

  if (a == b)
    printf("YES\n");
  else
    printf("NO\n");
}


Measured memory_bytes: 256
n = list(map(int,input().split()))
m = list(map(int,input().split()))
k = int(input())

if n[0] < m[0]:
    if n[0] + n[1] * k >= m[0] + m[1] * k:
        print("YES")
        exit()
elif n[0] > m[0]:
    if n[0] - n[1] * k <= m[0] - m[1] * k:
        print("YES")
        exit()

print("NO")

Measured memory_bytes: 61840
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Read();
        }

        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadIntArray(3);
            int N = a[0];
            int A = a[1];
            int B = a[2];

            int sum=0;
            int result=0;
            int tmp=0;

            for (int i = 1; i <= N; i++)
            {
                sum = 0;
                tmp=i;
           
                for (int j = 0; j < i.ToString().Length; j++)
                {
                    sum += tmp % 10;
                    tmp /= 10;
                }
                if (sum >= A && sum <= B)
                {
                    result += i;
                }
            }

            Console.WriteLine(result);
            Console.Read();

        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        ///
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

const int N = 1e5 + 5;
const double inf = 1e18;
double x[N], y[N];
double dx[N], dy[N];
int n;

double f(double a) {
    double minx = inf, maxx = -inf, miny = inf, maxy = -inf;
    for (int i = 0; i < n; i++) { //n个点
        double nx = x[i] + a * dx[i];
        double ny = y[i] + a * dy[i];
        minx = min(minx, nx);
        maxx = max(maxx, nx);
        miny = min(miny, ny);
        maxy = max(maxy, ny);
    }
    return (maxx - minx) * (maxy - miny);
}

double ternary_search(double l, double r) {
   double ans = inf;
  int times = 200;
    while (times--) {
        double m1 = l + (r - l) / 3;
         double m2 = r - (r - l) / 3;
        //double m1 = (l*2+r) / 3;
        //double m2 = (r*2+l) / 3;
        double f1 = f(m1);
        double f2 = f(m2);
        ans = min(ans, f1);
         ans = min(ans, f2);
        if (f1 < f2) r = m2;
        else l = m1;
    }
    return ans;
}

int main() {
   // while (cin >> n) {
      cin>>n;
        //memset(dx, 0, sizeof(dx));
        //memset(dy, 0, sizeof(dy));

        string s;
        for (int i = 0; i < n; i++) {
            cin >> x[i] >> y[i] >> s;
            if (s == "R") dx[i] = 1;
            if (s == "L") dx[i] = -1;
            if (s == "U") dy[i] = 1;
            if (s == "D") dy[i] = -1;
        }


        //cout << ternary_search(0, 1e9) << endl;
      printf("%lf\n",ternary_search(0, 1e9));
   // }

    return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))
using namespace std;

typedef long long li;
typedef unsigned long long lu;
const li infl = ~0LLU >> 2;

template <class T>
inline void Min(T &x, T y) {
  if (y < x) x = y;
}
template <class T>
inline void Max(T &x, T y) {
  if (y > x) x = y;
}

int mod;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (int)((li)x * y % mod); }
inline int Mul(int x, int y, int z) { return Mul(x, Mul(y, z)); }
int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}
int Inv(int x) {
  return Pow(x, mod - 2);
}

// ----------------------------------------

const int maxn = 300;

int N, K;
int f[maxn + 2][maxn + 2], g[maxn + 2][maxn + 2], f_suf[maxn + 2][maxn + 2];
int binom[maxn + 2][maxn + 2];

int main(void) {
  scanf("%d%d%d", &N, &K, &mod);
  ++N;
  for (int i = 0; i <= N; ++i) {
    binom[i][0] = 1;
    for (int j = 1; j <= i; ++j) {
      binom[i][j] = Add(binom[i - 1][j - 1] + binom[i - 1][j]);
    }
  }

  g[0][K + 1] = 1;
  for (int k = K; k >= 0; --k) {
    for (int n = 1; n <= N; ++n) {
      f[n][k] = g[n - 1][k + 1];
      f_suf[n][k] = Add(f[n][k] + f_suf[n][k + 1]);
    }
    g[0][k] = 1;
    for (int n = 1; n <= N; ++n) {
      g[n][k] = f_suf[n][k];
      for (int s = 1; s < n; ++s) {
        Add(g[n][k], Mul(binom[n - 1][s - 1], f_suf[s][k], g[n - s][k]));
      }
    }
  }

  int ans = f[N][0];
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main() {
	int h;
	cin >> h;
	int w;
	cin >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
 
	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}
 
	for (int i = 0; i < h; i++) {
		if (row[i]) {
			for (int j = 0; j < w; j++) {
				if (col[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int n, q;
    cin >> n >> q;
    int a, b;
    vector<int> g[n];
    rep(i, n - 1) {
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int p, x;
    int count[n];
    fill(count, count + n, 0);
    rep(i, q) {
        cin >> p >> x;
        p--;
        count[p] += x;
    }
    int ans[n];
    fill(ans, ans + n, -1);
    ans[0] = count[0];
    queue<P> que;
    que.push(P(0, ans[0]));
    while(!que.empty()){
        P p = que.front();
        int e = p.first;
        int c = p.second;
        que.pop();
        rep(i, g[e].size()){
            int e1 = g[e][i];
            if (ans[e1] == -1){
                ans[e1] = c + count[e1];
                que.push(P(e1, ans[e1]));
            }
        }
    }
    rep(i, n) cout << ans[i] << " ";
    cout << endl;
}


Measured memory_bytes: 17140
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
  cin>>a>>b>>c;
  if((a==5||a==7)&&(b==5||b==7))
    if((a+b+c)==17)
    cout<<"YES\n";
    else
    cout<<"NO\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define lll __int128
#define ull unsigned long long
#define fi first
#define se second
#define db double
#define ld long double
#define lld __float128

/// order_of_key, find_by_order

template<class T, class COMP>
using custom_set = tree<T, null_type, COMP, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T, class U>
using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd_64(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = 1e9 + 7;
const int MAXN = 200005;

ll dp[MAXN], prv[MAXN], nxt[MAXN];

int main()
{
    int n; cin >> n;
    int dat[n];
    for(int i = 0; i < n; i++)
    {
        cin >> dat[i];
    }
    for(int i = n-1; i >= 0; i--)
    {
        if(prv[dat[i]]) nxt[i] = prv[dat[i]];
        else nxt[i] = -1;
        prv[dat[i]] = i;
    }
    dp[0] = 1;
    for(int i = 0; i < n; i++)
    {
        dp[i+1] = (dp[i+1] + dp[i]) % MOD;
        if(nxt[i] >= 0 && nxt[i] != i+1) dp[nxt[i]] = (dp[nxt[i]] + dp[i]) % MOD;
    }
    cout << dp[n] << '\n';
}






































/// shche ne vmerla Ykraina


Measured memory_bytes: 5760
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline
MOD = 1000000007


def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(op.mul, range(n, n - r, -1))
    under = reduce(op.mul, range(1,r + 1))
    return over // under


def H(n, r):
    return cmb(n+r-1, r)


def main():
    n, k = get_li()
    if k == 1:
        print(H(2, n-1))
        return
    if k == 2:
        if n - 2 < 0:
            print(0)
        else:
            print(H(2, n-2))
        if n - 4 < 0:
            print(0)
        else:
            print(H(3, n-4))
        return
    for i in range(1, k + 1):
        if n - k - (i - 1) < 0:
            print(0)
        else:
            print(H(i, k-i) * H(i+1, n-k-(i-1)) % MOD)
    return


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


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


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


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


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


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


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()


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

int main(){
  int n, div=0, count=0; cin >> n;
  for(int i=1;i<=n;i++){
    if(i % 2 == 1){
      for(int j=1;j<=i;j++){if(i % j == 0) div++;} 
      if(div == 8) count++;
      div = 0; 
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>

using namespace std;

int main(){
	string x;
	cin>>x;
	int ans = 0;
	for (int i = 0; i < 3; i++){
		if (x[i] == '1') ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    long a[] = new long[N];
    long b[] = new long[N];
    long c[] = new long[M];
    long d[] = new long[M];
    int ans[] = new int[N];
    for(int i=0;i<N;i++){
      a[i]=sc.nextLong();
      b[i]=sc.nextLong();
    }
    for(int i=0;i<M;i++){
      c[i]=sc.nextLong();
      d[i]=sc.nextLong();
    }
    long tmp = 100000000000L;
    for(int i=0;i<N;i++){
      tmp = 100000000000L;
      for(int j=0;j<M;j++){
        if(tmp>(Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]))){
          ans[i]=j+1;
          tmp=Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]);
        }
      }
    }
    for(int i=0;i<N;i++){
      System.out.println(ans[i]);
    }
  }
  

  
}

Measured memory_bytes: 23892
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>
using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"


///////////////////////////////////////////////////////////////////////////

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

	ll N;
	cin >> N;

	vector<ll> p (N);

	rep (i, N) {
		cin >> p[i];
	}
	ll ans = 0;

	for (ll i = 1; i < N - 1; ++i) {
		if ((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
			(p[i - 1] > p[i] && p[i] > p[i + 1])) {
			++ans;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
 
using namespace std;
 
const int P = 998244353;
const int N = 300010;
 
typedef long long ll;

 
int fpow(int a, int b) {
	int c = 1;
	for (;b; b >>= 1, a = a*1ll*a%P) {
		if (b & 1) {
			c = c*1ll*a%P;
		}
	}
	return c;
}
 

int fac[N], inv[N];

int comb(int n, int a){
	if(0 > a || a > n)  return 0;
	else return ((fac[n] * 1ll * inv[a]) % P * inv[n-a])% P;
}
 
 
int main() {
	ll n, a, b, k;
	cin >> n >> a >> b >> k;
 	ll ans = 0;
 
 	fac[0] = 1;
 	inv[0] = 1;
 
 	for (int i = 1; i <= n; ++i) {
 		fac[i] = fac[i-1]*1ll*i%P;
 		inv[i] = inv[i-1]*1ll*fpow(i, P-2)%P;	
 	}
 
	for (int i = 0; i <= n; ++i) {
		ll j = k - i * 1ll * a;
		if (j % b == 0) {
			j /= b;
			ll at = comb(n, j) * 1ll * comb(n, i) % P;
			ans += at;
			if(ans >= P) {
				ans -= P;
			}
			
 
		}
 
	}
	cout << ans << endl;
 
}

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

int main() {
    int n;
    while(cin >> n, n) {
        set<int> hand[2];
        for(int i = 0; i < n; ++i) {
            int x; cin >> x;
            hand[0].insert(x);
        }
        for(int i = 1; i <= 2 * n; ++i) {
            if(hand[0].count(i) == 0) {
                hand[1].insert(i);
            }
        }
        int field = 0;
        int turn = 0;
        while(hand[0].size() > 0 && hand[1].size() > 0) {
            auto it = hand[turn].lower_bound(field);
            if(it == hand[turn].end()) {
                field = 0;
            } else {
                field = *it;
                hand[turn].erase(it);
            }
            turn ^= 1;
        }
        cout << hand[1].size() << "\n" << hand[0].size() << endl;
    }
}


Measured memory_bytes: 3076
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd1 = readln.split, n = rd1[0].to!size_t, k = rd1[1].to!long;

  struct AB { int a, b; }
  auto ab = new AB[](n);
  foreach (i; 0..n) {
    auto rd2 = readln.splitter;
    auto a = rd2.front.to!int; rd2.popFront();
    auto b = rd2.front.to!int;
    ab[i] = AB(a, b);
  }

  ab.sort!"a.a < b.a";

  auto s = 0L;
  foreach (abi; ab) {
    s += abi.b;
    if (s >= k) {
      writeln(abi.a);
      break;
    }
  }
}


Measured memory_bytes: 3964
#!/usr/bin/env python3
import sys


def solve(S: str):
    if S == "ABC":
        print("ARC")
    else:
        print("ABC")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


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

int main() {
  int n, x;
  cin >> n >> x;
  int sum = 0, cnt = 1;
  for (; n--; cnt++) {
    int a;
    cin >> a;
    sum += a;
    if (sum > x) break;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256