akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>

using namespace std;

int main() {
    string str;
    cin >> str;
    int next[26][str.length()];
    memset(next,-1,sizeof(next));
    int now[26];
    memset(now,0,sizeof(now));
    for(int i = 0;i < str.length();i++){
        int c = str[i]-'a';
        for(int j = now[c];j <= i;j++){
            next[c][j] = i;
        }
        now[c] = i+1;
    }
    int dp[str.length()+1];
    dp[str.length()] = 1;
    for(int i = str.length()-1;i >= 0;i--){
        int mini = 1000000;
        for(int j = 0;j < 26;j++){
            if(next[j][i] == -1){
                mini = 0;
                break;
            }
            if(mini > dp[next[j][i]+1]){
                mini = dp[next[j][i]+1];
            }
        }
        dp[i] = mini+1;
    }
    string ans = "";
    int p = 0;
    while(p <= str.length()){
        if(p == str.length()){
            ans += 'a';
            break;
        }
        for(int i = 0;i < 26;i++){
            char c = i + 'a';
            if(next[i][p] == -1){
                p = str.length() + 1;
                ans = ans + c;
                break;
            }
            if(dp[p] == dp[next[i][p]+1]+1){
                p = next[i][p]+1;
                ans = ans + c;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 21636
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  int x=1;
  while(x*2<=n) x*=2;
  pr(x);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<deque>
#define jio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
//#define mp make_pair
#define pb push_back
#define lld long long int
#define clr clear()
#define ff first
#define ss second
#define N 1000005
//#define M 1000
#define endl '\n'
#define c_s_b() __builtin_popcount()

#define sze 10000009
#define pii pair<int,int>
#define big 100009
#define int long long

using namespace std;

int n,k;
vector<int>v1;
int ht[big];
 int dp[big];

int fun(int step){

   if(step>=n){
       return INT_MAX;
   }
   if(dp[step]!=-1){
       return dp[step];
   }
   if(step==n-1){
     return 0;
   }
   int val=(((step+1)<n)?abs(ht[step+1]-ht[step]):INT_MAX)+fun(step+1);
   for(int i=2;i<=k;i++)
    val= min(val,(((step+i)<n)?abs(ht[step+i]-ht[step]):INT_MAX)+fun(step+i));
    // cout<<d<<endl;
    return dp[step]=val;


}


int32_t main(){
   jio;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>ht[i];
    }
     memset(dp,-1,sizeof(dp));
     int minm_cst=fun(0);


    cout<<minm_cst<<endl;






    return 0;


}


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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define eof !cin.eof()
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define ull unsigned long long
#define ll long long
#define ld long double
#define sz(a) a.size()
#define all(s) s.begin(), s.end()
#define rall(s, n) s, s + n
#define x first
#define y second
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ii pair <int, int>
#define iii pair <int, ii>
#define vi vector <int>
#define vit vector <int> :: iterator
#define vlt vector <ll> :: iterator
#define vl vector <ll> 
#define vii vector <ii>
#define viii vector <iii>
#define vd vector <double>
#define vull vector <ull>
#define vc vector <char>
#define vs vector <string>
#define vb vector <bool>
#define vvi vector <vector <int>>
#define vvl vector <vector <ll>>
#define EPS 1e-10
#define INF 1000000000
#define mod 1000000007
#define reset(a, nilai) memset(a, nilai, sizeof(a))
#define minof min_element
#define maxof max_element
using namespace std;

const int nax = 3e3 + 5;
int n;
ll dp[nax][nax];
int main () {
	IOS;
	
	scanf("%d", &n);
	vi a(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int L = n - 1; L >= 0; L--) {
		for (int R = L; R < n; R++) {
			if (L == R) {
				dp[L][R] = a[L];
			} else {
				dp[L][R] = max(a[L] - dp[L + 1][R], a[R] - dp[L][R - 1]);
			}
		}
	}
	printf("%lld\n", dp[0][n - 1]);
	return 0;
}

Measured memory_bytes: 70016
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
template<class T> int size(T &&x) {
  return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
  out << '{';
  for(auto it = x.begin(); it != x.end(); ++it)
    out << *it << (it == prev(x.end()) ? "" : ", ");
  return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
  cerr << x << ";  ";
  dump(args...);
}
struct Nl{~Nl(){cerr << '\n';}};
# define print(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#define int long long

bool check(int n){
  if(n==1) return false;
  for(int i=2;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}


int32_t main(){
    
  fast;
  int a,b; cin >> a >> b;
  int minn = min(a,b);
  int maxx = max(a,b);

  set<int> se;

  for(int i=2;i<=sqrt(minn);i++){
    int p = i;
    int q = minn/i;
    // print(p,q);
    if(minn%p==0&&maxx%p==0&&check(p)){
      se.insert(p);
    }
    if(minn%q==0&&maxx%q==0&&check(q)){
      se.insert(q);
    }
  }

  cout << se.size()+1 + check(minn);


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <vector>
#include <string.h>
#define mem(x,b) memset(x,b,sizeof(x))
#define mp(a,b) make_pair(a,b)
#define debug(a) cout<<a<<endl
#define maxn 200005
#define pi 3.1415926535898
using namespace std;
typedef long long ll;
typedef double db;
const int mod=1e9+7;
int main()
{
    int a,b,h,m;scanf("%d%d%d%d",&a,&b,&h,&m);
    double ho=(h*60+m)/720.0;
    double mi=m/60.0;
    double ans=(max(mi,ho)-min(mi,ho))*2*pi;
    if(ans>pi){
    	ans=2*pi-ans;
    }
    double res;
    res=sqrt(a*a+b*b-2*a*b*cos(ans));
    printf("%.10f\n",res);
    return 0;
}


Measured memory_bytes: 4164
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int arr[3][3];
    
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>arr[i][j];
        }
    }
    
    
    int n;
    cin>>n;
    
    while(n--)
    {
        int x;
        cin>>x;
       
       for(int i=0;i<3;i++)
      {
        for(int j=0;j<3;j++)
        {
            if(x==arr[i][j])
            arr[i][j]=0;
        }
      }    
    }
    
    int flag=0;
    
    for(int i=0;i<3;i++)
    {
        int cnt=1;
       
       if(arr[i][0]==0)
       {
           for(int j=1;j<3;j++)
           {
               if(arr[i][j]==0)
               cnt++;
           }
       }
       
       if(cnt==3)
       {
           flag=1;
           break;
       }
    }
    
    if(flag==0)
    {
        for(int j=0;j<3;j++)
       {
            int cnt1=1;
          if(arr[0][j]==0)
          {
          
           for(int i=1;i<3;i++)
           {
               if(arr[i][j]==0)
               cnt1++;
           }
         }
       
         if(cnt1==3)
         {
           flag=1;
           break;
         }
        }
        
    }
    
    if(flag==0)
    {
        if((arr[0][0]==0 && arr[1][1]==0 && arr[2][2]==0) || (arr[0][2]==0 && arr[1][1]==0 && arr[2][0]==0))
        flag=1;
    }
    
    
    if(flag==1)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int n;cin>>n;
    vector<int> a(n);
    int cnt=0;
    REP(i,n){
        cin>>a[i];
        if((i+1)%2 != 0 && a[i]%2 != 0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>

using namespace std;
int n,sol,secer[1000000+100],voda[1000000+100],res,ss,a,b,c,d,e,f;
double maxx;
string s;
int main()
{
    scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
    secer[c] = 1;
    secer[0] = 1;
    for (int i = c+1;i<=5000;i++)
    {
        if (i==d){secer[i] = 1;continue;}
        if (secer[i-c]==1)secer[i] =1;
        if (i>d&&secer[i-d]==1)secer[i] = 1;
    }
    voda[100*a]=1;
    voda[0] = 1;
    for (int i=100*a+1;i<=5000;i++)
    {
        if (i==b*100){voda[i] = 1;continue;}
        if (voda[i-100*a]==1)voda[i] = 1;
        if (i>b*100&&voda[i-100*b]==1)voda[i] = 1;
    }
    res = a*100;
    for (int i=1;i<=f;i++)
    {
        for (int sec=0;sec<=i;sec++)
        {
            if (secer[sec]==1&&voda[i-sec]==1)
            {
                int p = e*(i-sec)/100;
                if (sec>p)continue;
                if (maxx<1.0*sec/i){maxx = 1.0*sec/i;res = i;ss = sec;}
            }
        }
    }
    cout<<res<<" "<<ss<<endl;
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,l;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>l;
    Vi v;
    rep(i,n){
        v.pb(l+i);
    }
    ll ans = 0;
    ll tmp = INF;
    ll sum = 0;
    rep(i,n){
        sum += v[i];
    }
    rep(i,n){
        if(chmin(tmp,abs(sum-v[i]-sum))){
            ans = sum-v[i];
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string> 
using namespace std;
int main()
{
	string a;
	int num=1,len;
	cin >> len;
	cin >> a;
	for(int i=1;i<len;i++)
	{
		if(a[i]!=a[i-1]) num+=1;
	}
	cout << num;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
const int mod=1000000007;
long long power(long long a,int k){
    long long ans=1,y=a;
    while(k){
        if(k%2)
            ans=ans*y%mod;
        y=y*y%mod;
        k=k/2;
    }
    return ans;
}
long long fun[1<<17],ans=1;
int main(){
    long long n,m;
    scanf("%lld%lld",&n,&m);
    fun[0]=1;
    for(int i=1;i<1<<17;i++){
        fun[i]=fun[i-1]*i%mod;
    }
    for(int i=2;i*i<=m;i++){
        if(m%i==0){
            long long s=0;
            while (m%i==0) {
                m=m/i;
                s++;
            }
            ans=ans*fun[n+s-1]%mod*power(fun[n-1], mod-2)%mod*power(fun[s], mod-2)%mod;
        }
    }
    if(m>1)
        ans=ans*n%mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1280
def main():
    N = int(input())
    *A, = map(int, input().split())

    if 0 in A:
        print(0)
        return

    t = 1
    for x in A:
        t *= x
        if t > 10 ** 18:
            print(-1)
            return
    print(t)


if __name__ == '__main__':
    main()


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

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);    
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a, b, n;
    cin >> a >> b >> n;
    if (a == b)
        cout << a * n / b - a * (n / b);
    else
        cout << a * min(b - 1, n) / b - a * (min(b - 1, n) / b);
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(void) {
  int i, j, n, ans = 1e9;
  scanf("%d", &n);
  int a[n];
  for(i = 0; i < n; ++i) scanf("%d", &a[i]);
  for(i = -100; i <= 100; ++i) {
    int now = 0;
    for(j = 0; j < n; ++j) now += (i - a[j]) * (i - a[j]);
    if(now < ans) ans = now;
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
def cin():  return list(map(int,input().split()))

S = input()
k = cin()[0]
s = set()
length = len(S)
for i in range(length):
    tmp = ""
    for j in range(5):
        if i + j < length:
            tmp += S[i + j]
            s.add(tmp)
        
s = sorted(s)
ans = s[k - 1]
print(ans)

Measured memory_bytes: 80308
#include<bits/stdc++.h>
using namespace std;
#define very_slow       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define inf             1e18
#define MAX             1e9
#define MIN            -1e9
#define no_of_test(x)   int x; cin>>x; while(x--)
const double pi=3.14159265359;
const int mod = 1e9 + 6;
//Actual Code Is At The Top
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}
int nodes,edges;
vector<int>adj[100001];
int vis[100001];
void dfs(int node)
{
    if(vis[node]) return;
    vis[node]=1;
    for(auto child:adj[node])
    {
        dfs(child);
    }
}
int32_t main()
{   
	very_slow
//	no_of_test(x)
	{  
	   cin>>nodes>>edges;
       for(int i=1;i<=edges;i++)
       {    int x,y;
            cin>>x>>y;
            adj[x].push_back(y);
            adj[y].push_back(x);
       }
       int cc=0;
       for(int i=1;i<=nodes;i++)
       {
           if(!vis[i])
           {
               dfs(i);cc++;
           }
       }
       cout<<cc-1<<'\n';
	}
	return 0;
}

Measured memory_bytes: 11068
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PP pop_back()
#define set(x,y) memset(x,y,sizeof(x))
#define MIN3(x,y,z) min(min(x,y),z)
#define MAX3(x,y,z) max(max(x,y),z)
#define ALL(x) x.begin(),x.end()
#define sz(x) (int) x.size()
#define sag(x) 2*x+1
#define sol(x) 2*x
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define ROF(i,j,k) for(int i=j;i>=k;i--)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pii pair<int,int>
#define st first
#define nd second
#define ll long long
#define llu long long unsigned
#define lf double
#define orta (bas+son)/2
#define MOD 1000000007
#define inf 1000000000
#define N 200005
using namespace std;
int main() {
    ll n,m,x,y,t;
    scanf("%lld",&t);
    scanf("%lld %lld",&n,&m);
    ll q=__gcd(n,m);
    n/=q,m/=q;
    FOR(i,2,t) {
        scanf("%lld %lld",&x,&y);
        ll gcd=__gcd(x,y);
        x/=gcd;y/=gcd;
        ll dv=max(n/x+((n%x)?1:0),m/y+((m%y)?1:0));
        n=x*dv;
        m=y*dv;
    }
    printf("%lld",n+m);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,n;
    cin>>n>>a>>b;
        ll k=0;
        if(n%(a+b)<=a)
            k=n%(a+b);
            else k=a;
        cout<<((n/(a+b))*a)+k<<"\n";
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

//const ll MOD = 1e9+7;
//const ll MOD = 998244353;
//const ll MAX = 3e5+1;
//const ll INF = 1e18;
//const ld PI = acos(-1L);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int h, m, h2, m2, k;
    cin >> h >> m >> h2 >> m2 >> k;
    int t1 = h * 60 + m;
    int t2 = h2 * 60 + m2;
    out(t2-t1-k);


    return 0;
}


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

int main() {
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> c(n);
  vector<vector<int>> avi(n,vector<int>(m));
  rep(i,n){
    cin>>c[i];
    rep(j,m){
      cin>>avi[i][j];
    }
  }
  int min_cost = 1200010;
  bool ch = false;
  for(int tmp=0; tmp<(1<<n); tmp++){ 
    bitset<12> b(tmp);
    int tmp_cost = 0;
    vector<int> tmp_avi(m,0);
    rep(i,n){ 
      if(b.test(i)){
        tmp_cost+=c[i];
        rep(j,m){
          tmp_avi[j]+=avi[i][j];
        }
      }
    } 
    bool suc =true;
    rep(i,m){
      if(tmp_avi[i]<x){
        suc = false;
      }
    }
    if(suc){
      min_cost=min(min_cost,tmp_cost);
      ch = true;
    }
  }
  if(ch){
    cout<<min_cost<<endl;
  }else{
    cout<<-1<<endl;
  }
}



Measured memory_bytes: 3604
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k;
  cin >> n >> k;
  ll ans = (ll)k;
  if(n>1){
    REP(i,n-1) ans *= (ll)(k-1);
  }
  cout << ans << '\n';
  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 aa[][] = new int[10][10];
    int n = sc.nextInt();
	for (int i=1;i<=n;i++){
      int a = i % 10;
      int b = i;

      while (b >= 10) {
        b = b/10;
      }
      aa[b][a]++;
    }    
    int ans = 0;
    for (int i=1;i<=9;i++){
      for (int j=1;j<=9;j++){
        ans += aa[i][j]*aa[j][i];
      }
    }
    System.out.println(ans);
  }
}



Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,k,ans = 0;
    cin >> n >> k;

    for(int i = 0;i < n;i++){
        int x;
        cin >> x;

        ans += min(2*x,2*abs(x-k));
    }    

    cout << ans << endl;

    return 0;
}

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

multiset<long long> hmax, hmin;
int q;
long long qi = 0,med = -1,sum = 0,bs = 0;

int main(){
    scanf("%d",&q);
    for(int i = 0; i < q; ++i){
        int opt;
        scanf("%d",&opt);
        if(opt == 1){
            long long a, b;
            scanf("%lld%lld",&a,&b);
            ++qi,bs += b;
            if(qi == 1)
                hmax.insert(a),
                med = a;
            else if(qi == 2){
                long long w = *hmax.begin();
                if(w <= a) hmin.insert(a);
                else
                    hmax.clear(),
                    hmax.insert(a),hmin.insert(w);
                med = *hmax.begin(),sum = *hmin.begin() - med;
            } else {
                unsigned vs1_size = hmax.size(), vs2_size = hmin.size();
                if(*hmax.rbegin() >= a){
                    hmax.insert(a);
                    if(hmax.size()-2 >= hmin.size()){
                        long long w = *hmax.rbegin();
                        hmax.erase(--hmax.end()),hmin.insert(w);
                    }
                } else {
                    hmin.insert(a);
                    if(hmin.size() > hmax.size()){
                        long long w = *hmin.begin();
                        hmin.erase(hmin.begin()),hmax.insert(w);
                    }
                }
                long long tmp = *hmax.rbegin();
                sum += abs(tmp - a), sum += abs(static_cast<long long>((tmp - med) * (vs1_size - vs2_size))), med = tmp;
            }
        } else printf("%lld %lld\n",med,sum+bs);
    }
    return 0;
}

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

A_dict = dict()
for i in range(len(A)):
    if A[i] in A_dict:
        A_dict[A[i]] += 1
    else:
        A_dict[A[i]] = 1
        
if len(A_dict) == 2:
    print("Yes")
else:
    print("No")

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

int main() {
  string S, ans;
  cin >> S;

  for(int i = 0; i < S.size(); i++) {
    if (!(S[i] == 'R' || S[i] == 'U' || S[i] == 'D')) {
      cout << "No" << endl;
      return 0;
    } 
    i++;
    if (i >= S.size()) break;
    if (!(S[i] == 'L' || S[i] == 'U' || S[i] == 'D')) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void)
{
    int N,K,i,total;
    int l[110];
    cin>>N>>K;
    for(i=0;i<N;i++){
        cin>>l[i];
    }
    sort(l,l+N,greater<int>());
    for(int j=0;j<K;j++){
        total+=l[j];
    }
    cout<<total;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int n, k, cur;

int main() {
	scanf("%d%d", &n, &k);
	cur = 1;
	for(int i=0;i<n;i++)
		if(cur>k) cur += k;
		else cur *= 2;
		printf("%d\n", cur);
	
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
LL dp[105][100005];
int mod=1e9+7;
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    MEM(dp);
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        int a;
        scanf("%d",&a);
        LL sum=0;
        for(int j=0;j<=k;j++){
            sum+=dp[i-1][j];
            dp[i][j]=sum%mod;
            if(j>=a)
            sum-=dp[i-1][j-a];
           // printf("%d ",dp[i][j]);
        }
     //   printf("\n");
    }
    printf("%lld\n",dp[n][k]);
}


Measured memory_bytes: 82304
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  lli n;
  double ans,sum;
  cin>>n;
  vector<double> a(n);
  rep(i,0,n){
    cin>>a.at(i);
    sum+=1/a.at(i);    
  }
  cout<<1/sum<<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
int main(int argc, char const *argv[])
{
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a + 3);
	printf("%d\n",a[0] * a[1] / 2); 
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;

LL n,m,k;
LL ma = INF,mb = INF;
LL ans = INF,a[500005],b[500005],u,v,w;

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m >> k;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i];
		ma = min(ma,a[i]);
	} 
	for(LL i = 1;i <= m;i ++){
		cin >> b[i];
		mb = min(mb,b[i]);
	}
	ans = ma + mb;
	while(k --){
		cin >> u >> v >> w;
		ans = min(ans,a[u] + b[v] - w);
	}
	cout << ans << endl;
	return 0;
}
//

Measured memory_bytes: 5120
#include<stdio.h>
int main(){
    int a,b,tempRes;
    double tRes;
    scanf("%d %d", &a,&b);
    tRes = (a+b)/2.0;
    tempRes = (a+b)/2;
    if(tRes == tempRes){
        printf("%d\n", tempRes);
    }
    else{
        printf("IMPOSSIBLE\n");
    }
    return 0;
}


Measured memory_bytes: 128
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

void insertMatrix(int x, int arr[3][3], bool checkMatrix[3][3]){
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(arr[i][j]==x){
				checkMatrix[i][j]=true;
			}
		}
	}
}

bool checkfunc(bool checkMatrix[3][3]){
	bool flag;

	for(int i=0;i<3;i++){
		flag = true;
		for(int j=0;j<3;j++){
			flag&=checkMatrix[i][j];
		}
		if(flag) return true;
	}

	for(int j=0;j<3;j++){
		flag = true;
		for(int i=0;i<3;i++){
			flag&=checkMatrix[i][j];
		}
		if(flag) return true;
	}

	flag = true;
	for(int i=0;i<3;i++){
		flag&=checkMatrix[i][i];
	}
	if(flag) return true;

	flag = true;
	for(int i=0;i<3;i++){
		flag&=checkMatrix[i][2-i];
	}
	if(flag) return true;
	return false;
}

int main()
{
	fast;
	int arr[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>arr[i][j];
		}
	}
	int q,x;
	cin>>q;
	bool checkMatrix[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            checkMatrix[i][j] = false;
        }
    }
	for(int i=0;i<q;i++){
		cin>>x;	
		insertMatrix(x,arr,checkMatrix);
	}
    bool flag = checkfunc(checkMatrix); 
	if(flag)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

n,k=list(map(int,input().split()))
ans=Base_10_to_n(n,k)

print(len(ans))


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int N, d, num[110] = {0};
	cin >> N;
	int t = N, MAX = INT32_MIN;
	while (t--) {
		cin >> d;
		num[d]++;
		MAX = MAX < d ? d : MAX;
	}

	int ans = 0;
	while(MAX) {
		if (num[MAX])
			ans++;
		MAX--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        static void Main(string[] args)
        {
            double n = double.Parse(Console.ReadLine());
            string[] data = Console.ReadLine().Split();
            double sum = 0;
            double ans = 0;


            for(long i = 0; i < n; i++)
            {
                sum += double.Parse(data[i]);
            }

            

            double p = sum / n;
            

            p = Math.Round(p,MidpointRounding.AwayFromZero);
           

            

            for (long i = 0; i < n; i++)
            {
                ans += (double.Parse(data[i]) - p) * (double.Parse(data[i]) - p);
            }


                Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 13140
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for(int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
  return 0;
}

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

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};


struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
int main() {
    int x, y;
    cin >> x >> y;
    if((x+y)%3){
        cout << 0 << endl;
        return 0;
    }
    int n = (x+y)/3;
    x-=n; y-=n;
    if(x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }
    combination c(x+y);
    mint ans = c(x+y, x);
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,K; cin>>N>>K;
    vector<int> A(N);
    rep(n,0,N) cin>>A.at(n);

    map<int,int> mapA;
    for(auto a:A) mapA[a]++;

    vector<vector<int>> V(N+1);
    for(auto _mapa:mapA) V.at(_mapa.second).push_back(_mapa.first);

    int s=mapA.size();
    int64_t ans=0;
    rep(i,0,s-K){
        rep(v,0,N){
            if(V.at(v).size()){
                ans+=v;
                V.at(v).pop_back();
                break;
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 18984
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
	for(int q;cin>>q;) while(q--){
		string n; cin>>n;
		int i;
		for(i=0;n.size()>1;i++){
			int x=-1;
			for(int k=1;k<n.size();k++)
				x=max(x,atoi(n.substr(0,k).c_str())*atoi(n.substr(k).c_str()));
			char buf[9]; sprintf(buf,"%d",x);
			n=buf;
		}
		cout<<i<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>

using namespace std;

struct State {
  int x, y, d, cost;
  State(){}
  State(int x_, int y_, int d_, int cost_) : x(x_), y(y_), d(d_), cost(d_) {}
  bool operator>(const State& s) const {
    return cost>s.cost;
  }
};

const int SIZE = 31;
const int INF = 1<<27;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

int H, W;
int G[SIZE][SIZE], C[4];

bool inField(int x, int y) {
  return 0<=x && x<W && 0<=y & y<H;
}

int dijkstra() {
  int cost[4][SIZE][SIZE];
  
  priority_queue<State, vector<State>, greater<State> > pq;
  
  fill(cost[0][0], cost[4][0], INF);
  pq.push(State(0,0,0,0));
  cost[0][0][0] = 0;

  while(!pq.empty()) {
    const State s = pq.top(); pq.pop();
    if(s.x == W-1 && s.y == H-1) return s.cost;
    
    for(int i=0; i<4; i++) {
      State t = s;
      t.d = (s.d + i) % 4;
      t.x += dx[t.d], t.y += dy[t.d];
      t.cost += i == G[s.y][s.x] ? 0 : C[i];
      if(inField(t.x, t.y) && cost[t.d][t.y][t.x] > t.cost) {
	pq.push(t);
	cost[t.d][t.y][t.x] = t.cost;
      }
    }
  }
  
  return -1;
}

int main() {
  
  while( cin >> W >> H, W+H ) {
    
    for(int i=0; i<H; i++) {
      for(int j=0; j<W; j++) {
	cin >> G[i][j];
      }
    }
    for(int i=0; i<4; i++) cin >> C[i];
    
    cout << dijkstra() << endl;
  }
  return 0;
}

Measured memory_bytes: 1328
#include<stdio.h>
#define Max 1000000
#define Oya -1


void setDepth(int,int);
void print(int);

typedef struct{
  int parent,left,right;
}Node;

Node T[Max];
int n, D[Max], H[Max];

void setDepth(int u, int d){
  D[u] = d;

  if(T[u].right != Oya)
    setDepth(T[u].right, d);
  if(T[u].left != Oya)
    setDepth(T[u].left, d+1);
}

int main(){

  int i,j,d,v,c,left,right,root;
    scanf("%d",&n);

    for(i = 0; i<n; i++){
      T[i].parent = T[i].left = T[i].right = Oya;
    }
    
    for(i=0; i<n; i++){
      scanf("%d %d",&v,&d);
      for(j=0; j<d; j++){
	scanf("%d",&c);
	if(j==0)
	  T[v].left = c;
	else
	  T[left].right = c;
	left = c;
	T[c].parent = v;
      }
    }

    for(i=0; i<n; i++){
      if(T[i].parent == Oya) root = i;
    }

    setDepth(root,0);
   

    for(i=0; i<n; i++) print(i);

    return 0;
}

void print(int u){
  int i,c;

  printf("node %d: ",u);
  printf("parent = %d, ", T[u].parent);
  printf("depth = %d, ",D[u]);

  if(T[u].parent == Oya){
    printf("root, ");
  }
  else if(T[u].left == Oya){
    printf("leaf, ");
  }
  else{
    printf("internal node, ");
  }

  printf("[");

  for(i=0, c=T[u].left; c!=Oya; i++,c=T[c].right){
    if(i)
      printf(", ");
    printf("%d",c);
}

  printf("]\n");
}

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


int main(){
    int N, K;
    int R, S, P;
    string T, tmp="";
    long long ans=0;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    for(int i=0; i<N; i++){
	if(i>=K && tmp[i-K]==T[i]){
	    tmp += "j";
	    continue;
	}
	if(T[i]=='r'){
	    tmp += "r";
	    ans += P;
	}
	else if(T[i]=='s'){
	    tmp += "s";
	    ans += R;
	}
	else if(T[i]=='p'){
	    tmp += "p";
	    ans += S;
	}
    }

    cout << ans << endl;
}


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

bool judge(int N, int M, int K){
    for(int line = 0; line <= M; line++){
        int black = N * line;
        int diff = M - 2*line;
        for(int i = 0; i <= N; i++){
            int result = black + diff * i;
            if(result == K){
                return true;
            }
        }
    }
    return false;
}

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    if(judge(N, M, K) || judge(M, N, K)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main() {
  char s;
  cin >> s;
  if(s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
  
  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long a, long long b, long long c, long long d) {
  cout << max({a*c, b*d, a*d, c*b}) << endl;
}

signed main() {
  long long a;
  scanf("%lld", &a);
  long long b;
  scanf("%lld", &b);
  long long c;
  scanf("%lld", &c);
  long long d;
  scanf("%lld", &d);
  solve(a, b, c, d);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 300005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;




int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string s;
    cin>>s;
    int sum = 0;
    for(int i=0; i<s.length(); i++)sum+=s[i]-'0';
    cout<<(sum%9?"No":"Yes")<<endl;


}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int n;cin>>n;
    pair<int,int>p[n];
    rep(i,n){
        cin>>p[i].first;
        p[i].second = i;
    }
    sort(p,p+n);
    rep(i,n){
        cosp(p[i].second+1);
    }
    printf("\n");

}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int& i : a) cin >> i;
  sort(a.begin(), a.end());
  cout << accumulate(a.begin(), a.end() - min(n, k), 0LL) << endl;
}

Measured memory_bytes: 1024
program answer
  implicit none
  integer(8) :: i, count1, count2, n
  character(len=200000) :: s
  read(*,*) s
  n=len_trim(s)
  do i = 1, N
     if(s(i:i)=='A') then
        count1=i
        exit
     end if
  end do

  do i = 1, N
     if(S(i:i)=='Z') then
        count2=i
     end if
  end do

  write(*,*) count2-count1+1
  stop
 end program answer

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> paths(n, vector<int>());
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        paths[b].push_back(a);
    }

    string im = "IM";
    for (int a : paths[n - 1])
    {
        for (int start : paths[a])
        {
            im = start == 0 ? "" : im;
        }
    }

    cout << im << "POSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 8576
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
typedef pair<int, int> P;

bool pairsort1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool pairsort2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool pairsort3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool pairsort4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}

int main() {
	int n;
	cin >> n;
	vector <pair<int, int>>ab(n), cd(n);
	vector<vi>map(2 * n, vi(2 * n));
	rep(i, n) {
		cin >> ab[i].first >> ab[i].second;
		map[ab[i].F][ab[i].S]++;
	}
	rep(i, n) {
		cin >> cd[i].first >> cd[i].second;
	}
	sort(all(cd), pairsort1);
	sort(all(ab),pairsort1);
	vector<pair<int,int>>pair(n);
	int atmp = 0 , btmp = 0;
	int count = 0;
	rep(i, n) {
		int j = 0;
		int atmp = 0;
		int btmp = -1;
		bool flag = false;
		while (ab[j].first < cd[i].first){
			if (ab[j].second<cd[i].second&&
				ab[j].second >btmp&&
				map[ab[j].first][ab[j].second] > 0) {
				atmp = ab[j].first;
				btmp = ab[j].second;
				flag = true;
			}
			j++;
			if (j == n) {
				break;
			}
		}
		if (flag) {
			count++;
			map[atmp][btmp] = 0;
		}
	}
	cout << count << endl;
}



Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s ;
		if(n % 10 == 3) s = "bon";
		else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) s = "pon";
		else s = "hon";
		System.out.println(s);
	}
}

Measured memory_bytes: 35804
let _ =
  let n, m = Scanf.scanf "%d %d\n" (fun n m -> n, m) in
  let aa = Array.make n [] in
  for i = 0 to n - 1 do
    let k = Scanf.scanf "%d " (fun k -> k) in
    for j = 1 to k do
      Scanf.scanf (if j <> k then "%d " else "%d\n") 
        (fun a -> aa.(i) <- a::aa.(i)) 
    done
  done;
  let reslist = ref aa.(0) in
  for i = 1 to n - 1 do
    reslist := List.filter (fun e -> List.mem e aa.(i)) !reslist
  done;
  List.length !reslist
  |> print_int

Measured memory_bytes: 768
/**
 *    author:  FromDihPout
 *    created: 2020-06-21
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s, t;
    cin >> s;
    int n = (int) s.length(), index = n;
    vector<string> words = {"eraser", "dreamer", "erase", "dream"};
    while (index > 0) {
        bool ok = false;
        for (string w : words) {
            int len = (int) w.length();
            if (index - len < 0) continue;
            if (s.substr(index - len, w.length()) == w) {
                ok = true;
                index -= w.length();
                break;
            }
        }
        if (!ok) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3748
//#pragma comment(linker, "/STACK:1024000000,1024000000")
/* vim: set fdm=marker */
//{{{
#define __ return
int ATTENTION() {
	/* pls IGNORE this function and go down and HACK me
	 * read this AFTER contest
	 * this function is empty and it will not be called !
	 */

	http://codeforces.com/group/Pmz2A2x7ES
	/* I created a group there.
	 * I hope with the group, people can finish
	 * past contests, which is important for 
	 * increasing rating.
	 * I am still getting familiar with this function.
	 */
	 __ 0;
}
// deprecated because mac doesn't support this...
/* #include <bits/stdc++.h> */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int iinf = 0x7fffffff;
const ll linf = ~(1LL<<63);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;
template<typename T>
inline T gcd(T a, T b) {
	if(a < 0) return gcd(-a, b);
	if(b < 0) return gcd( a,-b);
	if(a < b) return gcd(b, a);
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll qpow(ll a, ll n, ll mod) {
	a %= mod;
	ll ans = 1LL;
	while(n) {
		if(n & 1) ans = (ans*a % mod);
		a = (a*a % mod);
		n >>= 1;
	}
	return ans;
}

inline ll rev(ll a, ll p) {
	return qpow(a, p - 2, p);
}

#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define rep(x, st, en) for(int x = st; x < en; x++)
#define rer(x, st, en) for(int x = st; x >= en; x--)
#define pb push_back
#define mp make_pair
#define dbgm(msg, var) cerr<<#msg<<" "<<#var<<" = "<<var<<endl; 
#define dbg(var) cerr<<#var<<" = "<<var<<endl;
#define X first
#define Y second
// build prefix sum
template<typename T>
inline void BPS(T* DST, T* SRC, int N, int s = 0) {
	DST[s] = SRC[s];
	rep(i, 1, N) DST[s + i] = DST[s + i - 1] + SRC[s + i];
}
inline int in() { int x; cin>>x; return x; }
#ifdef ALNDBG
namespace alndbg {
	clock_t s, e;
}
#endif

inline void tic() {
#ifdef ALNDBG
	alndbg::s = clock();
#endif
}

inline void toc() {
#ifdef ALNDBG
	alndbg::e = clock();
	cerr<<1000.0 * (alndbg::e - alndbg::s) / CLOCKS_PER_SEC<<" ms"<<endl;
#endif
}



//}}}

// -------------------- Spliters ------------------------
// BFS求最短路小心vis可能访问过
const int maxn = 300001;
const int mod = 998244353;

ull ncr[maxn];

int main() {
  ull N, A, B, K;
  scanf("%llu%llu%llu%llu", &N, &A, &B, &K);
  ull res = 0;
  ncr[0] = 1;
  for(ull i=1;i<=N;i++) {
    ncr[i] = ((ncr[i-1]*(N-i+1)) % mod * rev(i,mod)) % mod;
  }
  for(ull a = 0; a <= N; a++) {
    if(K < A * a) continue;
    ull numerator = K - A * a;
    if(numerator % B != 0) continue;
    ull b = numerator / B;
    if(b > N) continue;
    res = res + (ncr[a] * ncr[b]) % mod;
    res %= mod;
  }
  printf("%llu\n", res);
	return 0;
}
// --USE C++11
// *-USE O2



Measured memory_bytes: 2560