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

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const double PI=acos(-1.0);

int main()
{   
    int x;
    cin >> x;
    Yn(x>=30);

    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
int main()
{
  char w[11],t[1000][1000];
  int x=0,i,j;
  int wl,tl[1000],r;
  for(i=0;;i++)
    {
      scanf("%c",&w[i]);
      if(w[i]=='\n') break;
      else if((w[i]>='A')&&(w[i]<='Z')) w[i]+='a'-'A';
    }
  wl=i;
  for(i=0;;i++)
    {
      for(j=0;;j++)
	{
	  scanf("%c",&t[i][j]);	  
	  if((t[i][j]==' ')||(t[i][j]=='\n')||(t[i][j]=='\t'))
	    {
	      tl[i]=j;
	      break;
	    }
	}
      if((t[i][0]=='E')&&(t[i][1]=='N')&&(t[i][2]=='D')&&(t[i][3]=='_')&&(t[i][4]=='O')&&(t[i][5]=='F')&&(t[i][6]=='_')&&(t[i][7]=='T')&&(t[i][8]=='E')&&(t[i][9]=='X')&&(t[i][10]=='T')) break;
      else
	{
	  for(j=0;j<tl[i];j++)
	    {
	      if((t[i][j]>='A')&&(t[i][j]<='Z')) t[i][j]+='a'-'A';
	    }	
	}
    }
  r=i;
  for(i=0;i<r;i++)
    {
      if(wl!=tl[i]) continue;
      for(j=0;j<tl[i];j++)
	{
	  if(w[j]!=t[i][j]) break;
	}
      if(j==tl[i]) x++;
    }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 740
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  string s;
  cin>>s;
  int n=s.size();
  int i=0,j=n-1,cnt=0;
  while(i<j){
    if(s[i]==s[j]){i++;j--;}
    else if(s[i]=='x'){cnt++;i++;}
    else if(s[j]=='x'){cnt++;j--;}
    else{cout<<-1<<endl;return 0;}
  }
  cout<<cnt<<endl;



  return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    ll n; cin >> n;
    if(n % 2 != 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    ll div = 5;
    while(true){
        ans += (n / div) / 2;
        div *= 5;
        if(n < div) break;
    }
    cout << ans << endl;
}

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

using namespace std;
int main()
{
    int X,J,K,sum;
    scanf("%d",&X);
    if(X==1)
    {
        printf("Hello World");
    }
    else if(X==2)
    {
        scanf("%d%d",&J,&K);
        sum=J+K;
        printf("%d",sum);
      
    }


}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>


int main(){
    int buff[100];
    int counter,num=0,min,l,tmp;

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

    for(int j=0;j<counter;j++){
        min=j;
        for(int k=j;k<counter;k++){
            if(buff[k]<buff[min]){
                min=k;
            }
        }
        tmp=buff[j];
        buff[j]=buff[min];
        buff[min]=tmp;
        if(j!=min)
            num++;
    }

    for(l=0;l<counter-1;l++){
        printf("%d ",buff[l]);
    }
    printf("%d\n",buff[l]);

    printf("%d\n",num);

    return 0;

}



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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    ll n; cin >> n;
    int n25, n10, n5, n1;
    n25 = n / 25; n %= 25;
    n10 = n / 10; n %= 10;
    n5 = n / 5; n %= 5;
    n1 = n;
    cout << n25 + n10 + n5 + n1 << endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll MOD = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    vector<ll> a(5);
    rep(i,5) cin>>a[i];
    ll ans=INF;
    vector<ll> p={0,1,2,3,4};
    do{
        ll tmp=0;
        rep(i,5){
            tmp+=a[p[i]];
            while(tmp%10!=0){
                if(i==4) break;
                tmp++;
            }
        }
        ans=min(tmp,ans);
    }while(next_permutation(p.begin(),p.end()));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int beki(int a){
  if(a==1)return 1;
  int flag;
  for(int i=2; i<=a-1; i++){
    int tmp = a;
    int num = 0;
    while(1){
      if(a%i!=0) break;
      if(a==1) break;
      a /= i;
      num++;
    }
    if(a == 1){
      //      printf("%d = %d^%d\n", tmp, i,num);
      flag = 1;
      return 1;
    }
    else{
      flag = 0;
      a = tmp;
    }
  }

  return 0;
}

int main(){
  int a;

  scanf("%d", &a);

  if(a==1){
    printf("1\n");
    return 0;
  }

  for(int i=a; i>=1; i--){
    if(beki(i)){
      printf("%d\n", i);
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define maxn 200005
#define ll long long
using namespace std;
int read(){
	int x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
int mi[maxn],n,a[maxn],cnt[maxn];
int main(){
	n=read();ll ans=0;
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1,r=0,tmp=0;i<=n;i++){
		if(r<i)r=i,tmp=a[i];
		while(r<n&&((tmp&a[r+1])==0))r++,tmp^=a[r];
		ans+=(r-i+1);tmp^=a[i];
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e8
typedef long long ll;
typedef long double ld;

int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(u == s){
        a--;
    }else{
        b--;
    }
    cout << a << " " << b << endl;
}



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

const int MAX_N = 7369791 + 1;
int table[MAX_N];
void sieve(int x) {
    int tmp = 1;
    while (tmp * x <= MAX_N) {
        table[tmp++ * x] = 1;
    }
}

int main() {
    int m, n;
    while (cin >> m && m) {
        fill_n(table, MAX_N, 0);
        cin >> n;
        int cnt = 0; //何個とったか
        int now = m - 1;
        
        while (1) { //O(N)
            now++;
            while (table[now] == 1) now++;
            sieve(now); //out(now);
            
            cnt++;
            
            if (cnt == n + 1) {
                cout << now << endl;
                break;
            }
        }
        
    }
}





Measured memory_bytes: 31840
N = int(input())
DUMMY = -1
B = [DUMMY] + list(map(int, input().split()))

# 右から見ていって正しい位置にある数字が最後に挿入したもの
def last_insert_elem():
    for b,i in zip(reversed(B), reversed(range(len(B)))):
        if b==i:
            return B.pop(i)
    return DUMMY

ans = []
for _ in range(N):
    e = last_insert_elem()
    if e == -1:
        print(-1)
        exit()
        
    ans.append(e)

print(*reversed(ans), sep='\n')

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,v) VL v(n);rep(i,n)cin>>v[i]
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define LINE puts("------------------")
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
typedef struct{ll to;ll cost;} Graphs;
typedef V<V<Graphs>> AdjList;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}

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;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T center(T a,T b,T c){
  if( (a<=b&&b<=c)||(a>=b&&b>=c) )return b;
  if( (b>=a&&a>=c)||(b<=a&&a<=c) )return a;
  return c;
}
void print(){}
template<class Head,class... Tail>
void print(Head&& head, Tail&&... tail){
  cout<<head<<endl;
  print(forward<Tail>(tail)...);
}
void input(){}
template<class Head,class... Tail>
void input(Head&& head, Tail&&... tail){
  cin>>head;
  input(forward<Tail>(tail)...);
}
template<typename T>
ostream &operator<<(ostream&out,const vector<T>&v){
  if(!v.empty()){
    copy(v.begin(),v.end(),ostream_iterator<T>(out,", "));
    out<<"\b\b";
  }
  return out;
}
template<typename T1, typename T2>
ostream &operator<<(ostream&out,const pair<T1,T2>&p){
  out<<p.first<<", "<<p.second;
  return out;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  str s;
  cin>>s;

  rep(i,SZ(s)-1){
    if(s[i]==s[i+1]){
      cout<<i+1<<" "<<i+2<<endl;
      return 0;
    }
    if(i+2<SZ(s) && s[i]==s[i+2]){
      cout<<i+1<<" "<<i+3<<endl;
      return 0;
    }
  }
  out("-1 -1");
  


  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#include <cstring>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


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

	cout << ( 48 - M ) << endl;

	return ( 0 );
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const ll MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }
template<int mod>
struct ModInt {
    using ll = long long; ll x;
    ModInt() : x(0) {}
    ModInt(int y) : x(y >= 0 ? ll(y % mod) : (ll)((mod - (-y) % mod))) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod)) {}
    ModInt &operator+=(const ModInt &rhs) { if((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &rhs) { if((x += mod - rhs.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &rhs) { x = x * rhs.x % mod; return *this; }
    ModInt &operator/=(const ModInt &rhs) { *this *= rhs.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; }
    ModInt operator==(const ModInt &rhs) const { return x == rhs.x; }
    ModInt operator!=(const ModInt &rhs) const { return x != rhs.x; }
    friend ostream &operator<<(ostream &os, const ModInt &rhs) { return os << rhs.x; }
    friend istream &operator>>(istream &is, ModInt &rhs) { ll t; is >> t; rhs = ModInt<mod> (t); return (is); }
private:
    ModInt inverse() const { ll a = x, u = 1LL, v = 0LL, t, b = (ll)mod; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return  ModInt(u); }
};
using mint = ModInt<MOD>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    if(N < 3){
        cout << 0 << endl;
        return 0;
    }else if(N == 3){
        cout << 2 << endl;
        return 0;
    }
    vector<ll> divs;
    ll i = 1;
    while (i*i <= N){
        if(N % i == 0){
            divs.push_back(i);
            if(i != N/i) divs.push_back(N/i);
        }
        i += 1;
    }
    ll ans = 0;
    for(ll &d : divs){
        ll a = d-1LL;
        if(a != 0 && (N/a == N%a)) ans += a;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
int gcd(int a,int b){
	while(a){
		b%=a;
		int c=a;a=b;b=c;
	}
	return b;
}
set<pair<int,int> > S;
set<pair<int,int> > T;
int main(){
	int a,b,c,d,e,f;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	int row=0;
	int col=0;
	long long cnt=1;
	S.insert(make_pair(row,col));
	while(1){
		row=(row+c)%a;
		col=(col+d)%b;
		if(col==0)break;
		cnt++;
		S.insert(make_pair(row,col));
	}
	int g=gcd(row,a);
	long long ret=a/g*cnt;
	if(ret<110000){
		S.clear();
		swap(c,e);
		swap(d,f);
		row=0;col=0;cnt=1;
		S.insert(make_pair(row,col));
		while(1){
			row=(row+c)%a;
			col=(col+d)%b;
			if(col==0)break;
			cnt++;
			S.insert(make_pair(row,col));
		}
		g=gcd(row,a);
		ret=a/g*cnt;
	}
	for(set<pair<int,int> > ::iterator it=S.begin();it!=S.end();it++){
		pair<int,int>tmp=(*it);
		T.insert(make_pair(tmp.first%g,tmp.second));
	}
	//printf("%lld\n",ret);
	row=0;col=0;cnt=1;
	  while(1){
        row=(row+e)%a;
        col=(col+f)%b;
        if(T.count(make_pair(row%g,col)))break;
        cnt++;
    }
	//printf("%lld %lld\n",ret,cnt);
	printf("%lld\n",ret*cnt-1);
}

Measured memory_bytes: 10400
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int N,W;
	cin >> N >> W;

	vector<int> w(N), v(N);
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}

	vector<vector<long long>> dp(N+1, vector<long long>(W+1,0));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= W; j++) {
			if (w[i] > j) {
				dp[i + 1][j] = dp[i][j];
			}
			else {
				dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
			}
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}

Measured memory_bytes: 80256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n, p = LI()
    s = S()
    ans = 0
    if p == 2 or p == 5:
        for i in range(n):
            if int(s[i]) % p != 0:
                pass
            else:
                ans += i + 1
    else:
        tmp = 0
        d = defaultdict(int)
        d[0] = 1
        for i in range(n - 1, -1, -1):
            tmp += int(s[i]) * pow(10,n-i-1,p)
            tmp %= p
            ans += d[tmp]
            d[tmp] += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 62064
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	input = input.map(e => toIntArr(e.split(' ')));
	var n = input[0][0];
	var x = input[0][1];
	var ans = 0;
	var ls = [1];
	var ps = [1];
	for(var i = 1; i < 51; i++){
		ls[i] = 2*ls[i-1] + 3;
		ps[i] = 2*ps[i-1] + 1;
	}

	function eatP(n,k){
		if(n < 0) return 0;
		if(k >= ls[n]) return ps[n];
		if(k <= 0) return 0;
		var l = ls[n-1];

		return eatP(n-1,k-1) + eatP(0,k-l-1) + eatP(n-1,k-l-2);

	}

	ans = eatP(n,x);
	
	console.log(ans);
}

Measured memory_bytes: 9420
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    int mx = 0, res = 1;
    FOR(i, 1, N+1) {
        int temp = i;
        int cnt = 0;
        while(temp%2 == 0) {
            temp /= 2;
            cnt++;
        }
        if(cnt > mx) {res = i; mx = cnt;}
    }

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for( auto &k : a ) cin >> k;
	a.push_back(inf);
	int ans = 0, cnt = 0;
	for( int i = 0; i < n; ++i ){
		if( a[i] >= a[i+1] ){
			++cnt;
			ans = max(ans, cnt);
		} else {
			cnt = 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
typedef pair<int,int>pii;
const int mxN=2e5,M=1e9+7;
int n,k;
string s;
// LONG LONG CASE
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;
    cin>>s;
    if(s[k-1]=='A')s[k-1]='a';
    if(s[k-1]=='B')s[k-1]='b';
    if(s[k-1]=='C')s[k-1]='c';

    cout<<s;
}   

Measured memory_bytes: 256
n = int(input())
ans = ['a'] # 最初の一文字は'a'で固定

for i in range(n-1): # 'a'に'n-1'文字分ループで足す
    tmp = [] # リセット
    for j in ans:
        l = len(set(j)) # 'j'の使用文字種の数をカウント
        for k in range(l+1): # 'j'の使用文字種の数 '+1'回ループして...
            tmp.append(j + chr(ord('a') + k)) # 'j'に appendする
    ans = tmp[:] # 'ans'を書き換える

for i in ans:
    print(i)


Measured memory_bytes: 19580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    cin >> n;
    if(100 <= n && n <= 111){
        cout << 111;
    }
    else if(112 <= n && n <= 222){
        cout << 222;
    }
    else if(223 <= n && n <= 333){
        cout << 333;
    }
    else if(334 <= n && n <= 444){
        cout << 444;
    }
    else if(445 <= n && n <= 555){
        cout << 555;
    }
    else if(556 <= n && n <= 666){
        cout << 666;
    }
    else if(667 <= n && n <= 777){
        cout << 777;
    }
    else if(778 <= n && n <= 888){
        cout << 888;
    }
    else if(889 <= n && n <= 999){
        cout << 999;
    }
    return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


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

    return 0;
}


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

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

    int pt1 = 0;
    int pt2 = 0;
    rep(i, s.size()) {
        if(i % 2 == 0) {
            if(s.at(i) == '0') pt1++;
            if(s.at(i) == '1') pt2++;
        }
        else {
            if(s.at(i) == '1') pt1++;
            if(s.at(i) == '0') pt2++;
        }
    }
    cout << min(pt1, pt2) << endl;
    return 0;
}

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

int main()
{
	int n;
	while (cin >> n)
	{
		long long int dp[5][5001] = {};
		dp[0][0] = 1;
		for (int i = 0; i < 4; i++)
		{
			for (int j = 0; j <= n; j++)
			{
				if (dp[i][j] == 0) continue;
				for (int k = 0; k <= 1000; k++)
				{
					dp[i + 1][j + k] += dp[i][j];
				}
			}
		}

		cout << dp[4][n] << endl;
	}

	return 0;
}

Measured memory_bytes: 3288
Imports System.Console
Module Module1
    Dim ans As Integer
    Dim n, k As Integer
    Sub Main()
        Dim s As String = ReadLine()
        Dim c() As Char = s.ToCharArray
        Dim max As Integer = 0
        Dim ren As Integer
        For i = 0 To c.Length - 1
            If c(i) = "R" Then
                ren += 1
            Else
                If ren >= max Then
                    max = ren
                End If
                ren = 0
            End If
        Next
        If ren >= max Then
            max = ren
        End If
        ren = 0
        WriteLine(max)
        ReadLine()
    End Sub
End Module


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

int main(){
	int r, c, A[101][101] = {0};
	cin >> r >> c;
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			cin >> A[i][j];
			A[i][c] += A[i][j];
		}
	}
	for(int j = 0; j <= c; j++){
		for(int i = 0; i < r; i++){
			A[r][j] += A[i][j];
		}
	}
	for(int i = 0; i <= r; i++){
		for(int j = 0; j < c; j++){
			cout << A[i][j] << ' ';
		}
		cout << A[i][c] << endl;
	}	
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int h,w,n;
   cin >> h >> w >> n;
   int m = max(h,w);
   cout << (n+m-1)/m << '\n';
   return 0;
} 

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

int main(){
  int N; cin>>N;
  int h = N+1;
  int p;
  int r = 0;
  REP(i,N){
    cin >>p;
    if(p<=h){
      r++;
      h = p;
    }
  }
  cout << r;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,mod=1000000007,dp[100009],dp2[100009];
vector <long long> v[100009];
void dfs(long long q, long long w){
	if(v[q].size()==1&&q!=1){
		return;
	}
	for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
      if((*it)==w) continue;
      dfs((*it),q);
		dp2[q]*=dp[(*it)];
      dp2[q]%=mod;
		dp[q]*=dp[(*it)]+dp2[(*it)];
      dp[q]%=mod;
	}
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	for(b=1; b<a; b++){
		cin>>c>>d;
		v[c].push_back(d);
		v[d].push_back(c);
	}
	for(b=1; b<=a; b++){
		dp[b]=1;dp2[b]=1;
	}
	dfs(1,0);
	cout<<(dp[1]+dp2[1])%mod;
	return 0;
}

Measured memory_bytes: 11520
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            int atA = 200001;

            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == 'A') {
                    atA = i;
                    break;
                }
            }

            int atZ = -1;

            for (int i = s.length() - 1; 0 <= i; i--) {
                if (s.charAt(i) == 'Z') {
                    atZ = i;
                    break;
                }
            }

            System.out.println(atZ - atA + 1);
        }
    }
}


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


def solve(N: int, K: int, S: str):
    k = K-1
    print(S[0:k],end="")
    print(S[k].lower(),end="")
    print(S[k+1:])
    return


# Generated by 1.1.4 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()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


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

#define ll long long 
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define pl pair<long long ,long long >
#define pi pair<int ,int >
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define ct(i) cout<< i << "\n"
#define sv(v) sort(v.begin(),v.end())
#define mod 1000000007
#define M 100005
#define endl "\n"


void solve(){
    ll n,m,ans=0,x,y;
    cin>>n>>m>>x;
    y = ceil(n*1.0/m);
    
    cout<<x*y<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int q;
    //cin>>q; while(q--)
        solve();
    return 0;
}


Measured memory_bytes: 3736
MAX_INT = int(10e10)

N, M = list(map(int,input().split()))
Val = [0 for _ in range(M)]
Key = [0 for _ in range(M)]
for i in range(M):
  v, b = list(map(int,input().split()))
  k =  list(map(int,input().split()))
  Val[i] = v
  tmp = 0
  for num in k:
    tmp += 2**(num-1)
  Key[i] = tmp
#print(Val)
#print(Key)

dp = [MAX_INT for _ in range(1<<N)]
dp[0] = 0
for i in range(1<<N):
  for x in range(M):
    #print(i, i|Key[x])
    dp[i|Key[x]] = min(dp[i|Key[x]], dp[i] + Val[x])
#print(dp)
if dp[-1] == MAX_INT:
  print(-1)
else:
  print(dp[-1])

Measured memory_bytes: 46312
#include<iostream>
#include<vector>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=1; i<=n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX 3000

ll n;
double arr[MAX];
double dp[MAX][MAX];

double solve(int coins, int req_head){
    if(req_head == 0) return 1;
    if(coins == 0) return 0;

    if(dp[coins][req_head] > -1) return dp[coins][req_head];

    double opt1 = arr[coins]*solve(coins-1, req_head-1);
    double opt2 = (1-arr[coins])*solve(coins-1, req_head);

    dp[coins][req_head] = opt1+opt2;
    return dp[coins][req_head];
}

void topDown(){
    memset(dp, -1, sizeof(dp));
    cout<<fixed<<setprecision(11)<<solve(n, (n+1)/2)<<endl;
}

int main(){
    cin>>n;
    ip(arr, n);
    topDown();
    return 0;
}

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

#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define FOR(i,a,b) for(long long i=(a);i<=(b);i++)

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> ans;
  REP(i, max(A, B)) {
    if(A % (i + 1) == 0 && B % (i + 1) == 0) {
      ans.push_back(i + 1);
    }
  }
  cout << ans[ans.size()-K] << endl;
  return 0;
}


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

class UnionFind {
    vector<int> data;
    ll num;
public:
    UnionFind(int size) : data(size, -1), num(size) { }
    bool unite(int x, int y) {//xとyの集合を統合する
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        num -= (x != y);
        return x != y;
    }
    bool findSet(int x, int y) {//xとyが同じ集合か返す
        return root(x) == root(y);
    }
    int root(int x) {//xのルートを返す
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    ll size(int x) {//xの集合のサイズを返す
        return -data[root(x)];
    }
    ll numSet() {//集合の数を返す
        return num;
    }
};
 int main(){
   ll n,m,k;
   cin>>n>>m>>k;
   UnionFind tomodati(n);
   vector<ll> to[n];
   rep(i,m){
     ll a,b;
     cin>>a>>b;
     a--;b--;
     tomodati.unite(a,b);
     to[a].push_back(b);
     to[b].push_back(a);
   }
   vector<ll> kirai[n];
   rep(i,k){
     ll c,d;
     cin>>c>>d;
     c--;d--;
     kirai[c].push_back(d);
     kirai[d].push_back(c);
   }
   rep(i,n){
     int honntonikirai=0;
     for (auto x: kirai[i]){
      if(tomodati.findSet(i,x)){
        honntonikirai++;
      }
     }
        
       
     cout<<tomodati.size(i)-1-to[i].size()-honntonikirai<<" ";
   }
 }


Measured memory_bytes: 15576
import scala.util.control.Breaks.{ break, breakable }

object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val lines = scala.collection.mutable.MutableList.empty[String]
    val word = sc.next().toUpperCase()

    breakable {
      while (true) {
        val input = sc.next()
        if (input == "END_OF_TEXT") {
          println(lines.count(_ == word))
          break
        } else lines += input.toUpperCase()
      }
    }
  }
}

Measured memory_bytes: 45092
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, D;
    cin >> N >> D;
    D = D * 2 + 1;
    cout << N / D + (N % D != 0) << endl;
}


Measured memory_bytes: 256
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int ar[N], st[4*N];
vector <pii> v;
void build(int v, int l, int r)
{
    if(l==r)
    {
        st[v]=l-1;
        return;
    }
    int m=(l+r)/2;
    build(v*2, l, m);
    build((v*2)+1, m+1, r);
    st[v]=max(st[v*2], st[(v*2)+1]);
    //cout<<l<<" "<<r<<" "<<t[v].o<<" "<<t[v].c<<" "<<t[v].ans<<"\n";
}
void update(int v, int l, int r, int pos, int x)
{
    if(l==r)
    {
        st[v]=x;
        return;
    }
    int m=(l+r)/2;
    if(pos<=m)
    update(v*2, l, m, pos, x);
    else
    update((v*2)+1, m+1, r, pos, x);
    st[v]=max(st[v*2], st[(v*2)+1]);
    //cout<<l<<" "<<r<<" "<<t[v].o<<" "<<t[v].c<<" "<<t[v].ans<<"\n";
}
int query(int v, int tl, int tr, int l, int r)
{
    if(l>r)
    return 0;
    if(tl==l&&tr==r)
    return st[v];
    int tm=(tl+tr)/2;
    return max(query((2*v), tl, tm, l, min(tm, r)), query((2*v)+1, tm+1, tr, max(tm+1, l), r));
}

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x,d;
        cin>>x>>d;
        v.pb({x, d});
    }
    sort(all(v));
    int lim[n],dp[n+1];
    build(1, 1, n);
    for(int i=n-1;i>=0;i--)
    {
        pii p={v[i].ff+v[i].ss, -1};
        int pos=(int)(lower_bound(all(v), p)-v.begin());
        lim[i]=query(1, 1, n, i+1, pos);
        update(1, 1, n, i+1, lim[i]);
        //cout<<i<<" "<<lim[i]<<"\n";
    }
    dp[n]=1;
    for(int i=n-1;i>=0;i--)
    dp[i]=(dp[i+1]+dp[lim[i]+1])%mod;
    cout<<dp[0]<<"\n";
}


Measured memory_bytes: 13692
#include<iostream>
using namespace std;
char q[2][110];
int main(){
	int n;
	cin >> n;
	cin >> q[0];
	cin >> q[1];
	for (int i = 0; i < 2 * n; i++)
		printf("%c", q[i % 2][i / 2]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,a;
  cin >> n >> a;
  vector<int>x(n);
  rep(i,n) cin >> x[i];
  ll dp[n+10][n+10][50*n+100]={};
  dp[0][0][0]=1;
  
  rep(i,n){
    for(int j=0;j<=n;j++){
      for(int k=0;k<=50*n;k++){
        dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
        dp[i+1][j][k]+=dp[i][j][k];
      }
    }
  }
  ll res = 0;
  for(int i=1;i<=n;i++){
    res+=dp[n][i][i*a];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 73344
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int K;
    cin >> K;
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[K-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,m;
int a[1000010],ans[1000010];
int gcd(int x,int y){
	if(y==0)return x;
	else return gcd(y,x%y);
}
int f[1000010];
int main(){
	cin>>n;
	int sumgcd=0;
	for(int i=1;i<=n;i++)cin>>a[i],sumgcd=gcd(sumgcd,a[i]);
	bool flg=1;
	for(int i=1;i<=n;i++){
		int x=a[i];
		for(int ii=2;ii*ii<=x&&x>1;ii++){
			if(x%ii==0){
				if(f[ii]){flg=0;break;}
				f[ii]=1;
				while(x%ii==0)x/=ii;
			}
		}
		if(x>1){
			if(f[x]){flg=0;break;}
			f[x]=1;
		}
//		while(x>1){
////			cout<<x<<endl;
//			ii++;
//		}
		if(flg==0)break;
	}
	if(flg==1){
		puts("pairwise coprime");
	}else{
		if(sumgcd==1)puts("setwise coprime");
		else puts("not coprime");
	}
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Rolling Hash
//-------------------------------------------------
using ull = unsigned long long;
using Hash = vector<ull>;

const int M_NUM = 3;
const ull mod[4] = {(ull)1e9+33,(ull)1e9+87,(ull)1e9+93,(ull)1e9+97};
const ull base = 9973;

class RollingHash
{
private:
    int n;
    vector<ull> _hash[4], _pow[4];
public:
    RollingHash(const string &s){
        n = s.size();
        for(int i=0; i<M_NUM; i++){
            _hash[i].resize(n+1); _hash[i][0] = 0;
            _pow[i].resize(n+1); _pow[i][0] = 1;
            for(int j=0; j<n; j++){
                _pow[i][j+1] = (_pow[i][j]*M_NUM)%mod[i];
                _hash[i][j+1] = (_hash[i][j]*M_NUM+s[j])%mod[i];
            }
        }
    }
    bool match(int l, int r, Hash h){
        bool ret=true;
        for(int i=0; i<M_NUM; i++){
            ull value = _hash[i][r]-(_hash[i][l]*_pow[i][r-l])%mod[i];
            value = (value+mod[i])%mod[i];
            ret&=(value==h[i]);
        }
        return ret;
    }
    vector<int> matches(Hash h, int w){
        vector<int> ret;
        for(int i=0; i<n-w+1; i++)
            if (match(i,i+w,h)) ret.push_back(i);
        return ret;
    }
    static Hash hash(const string &s){
        Hash ret(M_NUM);
        for(int i=0; i<M_NUM; i++)
            for(int j=0; j<s.size(); j++)
                ret[i]=(ret[i]*M_NUM+s[j])%mod[i];
        return ret;
    }
};


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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t; cin>>s>>t;
    int w = t.size();
    RollingHash rh(s);
    Hash pat = RollingHash::hash(t);
    auto ms = rh.matches(pat,w);
    for(auto e:ms){
        cout<<e<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3272
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>
using namespace std;
int main(){

  string tmp;
  stack <int> a;
  int tmp1;

  while(cin>>tmp){
    if(tmp=="+"){
      tmp1=a.top(); a.pop();
      tmp1+=a.top(); a.pop();
      a.push(tmp1);
    } else if(tmp=="*"){
      tmp1=a.top(); a.pop();
      tmp1*=a.top(); a.pop();
      a.push(tmp1);
    } else if(tmp=="-"){
      tmp1=-a.top(); a.pop();
      tmp1+=a.top(); a.pop();
      a.push(tmp1);
    } else a.push(atoi(tmp.c_str()));
  }

  cout<<a.top()<<endl;

  return 0;
}



Measured memory_bytes: 3172
import sys
sys.setrecursionlimit(10 ** 9)

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

edges = [[] for _ in range(N)]
for _ in range(M):
    x,y = map(int,input().split())
    edges[y-1].append(x-1)
    
used = [0 for _ in range(N)]
dp = [0 for _ in range(N)]

def dfs(pos):
    if not edges[pos]:
        dp[pos] = 0
        return
    for n_pos in edges[pos]:
        if not used[n_pos]:
            dfs(n_pos)
        used[n_pos] = 1
        dp[pos] = max(dp[pos],dp[n_pos]+1)

    
for i in range(N):
    if used[i]:
        continue
    used[i] = True
    dfs(i)

print(max(dp))

Measured memory_bytes: 199592
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int a, b, n;
	vector<int*> scores;

	while (cin >> n) {
		if (n == 0)
			break;
		int *score = new int(2);
		score[0] = 0;
		score[1] = 0;
		for (int i = 0; i < n; i++) {
			cin >> a >> b; 
			if (a > b)
				score[0] += a + b;
			if (a < b)
				score[1] += a + b;
			if (a == b) {
				score[0] += a;
				score[1] += b;
			}
		}
		scores.push_back(score);
	}

	for (int i = 0; i < scores.size(); i++) {
		cout << scores[i][0] << " " << scores[i][1] << endl;
	}

	return 0;
}

Measured memory_bytes: 0