akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<ll> a(n);
    ll sum =0;
    for(auto &x:a){
        cin >> x;
        sum += x;
    }

    ll summod=0;
    for(int i=0;i<n;i++){
        sum-=a[i];
        summod+=a[i]*(sum%(1000000007));
        summod%=MOD;
    }

    cout << summod << endl;

    return 0;
}


Measured memory_bytes: 4832
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define llin(a) cin >> a
#define llpr(a) cout << a << " "
#define llout(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define M 1000000007
#define N 100005  //check the limits, man
typedef long long int ll;
// read the constraint properly (ll vs int)
int main()
{
    int i,n,a,last;
    in(n);
    vi v(n);
    read(v,i,n);
    vi ar(n);
    read(ar,i,n);
    vi sat(n-1);
    read(sat,i,n-1);
    int ans=0;
    last=-2;
    rep(i,n)
    {
        a=v[i]-1;
        ans+=ar[a];
        if(a-last==1)
            ans+=sat[last];
        last=a;
    }
    out(ans);
}


Measured memory_bytes: 256
from collections import Counter
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
p = prime_factorize(n)
c = Counter(p)
ans = 0
for i in c.keys():
    ans += 1
    x = c[i]
    y = 3
    i = 3
    if x > 2:
        while True:
            if x < y:
                break
            else:
                ans += 1
                y += i
                i += 1
print(ans)


Measured memory_bytes: 9464
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n;
    rep(i,n){
        cin>>a[i];
        a[i]-=(i+1);
    }
    sort(a,a+n);
    rep(i,n)b[i]=a[i];
    tmp=a[n/2]*-1;
    if(n%2==1){
        rep(i,n){
            a[i]+=tmp;
        }
        rep(i,n){
            ans+=abs(a[i]);
        }
        Cout(ans);
    }
    else{
        rep(i,n){
            a[i]+=tmp;
        }
        rep(i,n){
            ans+=abs(a[i]);
        }
        tmp=a[n/2-1]*-1;
        rep(i,n){
            b[i]+=tmp;
        }
        rep(i,n){
            cnt+=abs(b[i]);
        }
        Cout(min(ans,cnt));
    }
    return 0;
}


Measured memory_bytes: 5888
x,y=z=[0,1].map{[0]*2e5}
`sed 1d`.split.map{|v|z[1&$.+=1][v.to_i]-=1}
a,b=x.sort
c,d=y.sort
p$..+a!=x[y.index c]?a+c:[a+=d||0,c+=b||0].min

Measured memory_bytes: 16072
#include <iostream>

using namespace std;

const int M = 1e9 + 7;

int n, a[200000];
long long ans, sum;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n;
	for (int i = 0; i < n; ++i) {
		scanf("%d", a + i);

		sum += a[i];
		// sum %= M;
	}

	for (int i = 0; i < n; ++i) {
		sum -= a[i];
		ans += (a[i] * (sum % M)) % M;
		ans %= M;
	}

	cout << ans << endl;
}


Measured memory_bytes: 4464
#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while(t--){
        int n;
        cin >> n;
        vector<vector<long long int>> in(n,vector<long long int>(3));
        for(int i=0 ; i<n ; i++){
            cin >> in[i][0] >> in[i][1] >> in[i][2];
        }
        
        vector<vector<long long int>> dp(n,vector<long long int>(3));
        dp[0] = in[0];
        for(int i=1 ; i<n ; i++){
            dp[i][0] = in[i][0] + max(dp[i-1][1],dp[i-1][2]);
            dp[i][1] = in[i][1] + max(dp[i-1][0],dp[i-1][2]);
            dp[i][2] = in[i][2] + max(dp[i-1][1],dp[i-1][0]);
        }
        cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << "\n";
    }
    return 0;
}



Measured memory_bytes: 14272
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n;
    cin >> n;
    ll a[n];
    ll cnt[100010] = {};
    ll sum = 0;
    rep(i, n){
        cin >> a[i];
        cnt[a[i]]++;
        sum += a[i];
    }
    ll q;
    cin >> q;
    rep(i, q){
        ll b, c;
        cin >> b >> c;
        cout << sum + (c - b)*cnt[b] << endl;
        sum = sum + (c - b)*cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
    }
}


Measured memory_bytes: 5204
#include <stdio.h>
#include <stack>
#include <string.h>
#include <stdlib.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repm(i, f, l) for(int i = f; i < l; ++i)

int main(void) {
  char s[100];
  std::stack<int> st;
  while(scanf("%s", s) != EOF) {
    if(s[0] == '+') {
      int n, m;
      n = st.top();
      st.pop();
      m = st.top();
      st.pop();
      st.push(n + m);
    } else if(s[0] == '-') {
      int n, m;
      n = st.top();
      st.pop();
      m = st.top();
      st.pop();
      st.push(-n + m);
    } else if(s[0] == '*') {
      int n, m;
      n = st.top();
      st.pop();
      m = st.top();
      st.pop();
      st.push(n * m);
    } else {
      int t = atoi(s);
      st.push(t);
    }
  }
  printf("%d\n", st.top());
  return 0;
}


Measured memory_bytes: 2692
#include <stdio.h>
int main(void){
    int s[100][100],t[100][100],n,m,l,a,b,c;
    long  u[100][100]={{0}};
    scanf("%d %d %d",&n,&m,&l);
    for(a=1;a<=n;a++){
      for(b=1;b<=m;b++){
          scanf("%d",&s[a-1][b-1]);
      };      };
      
      for(a=1;a<=m;a++){
      for(b=1;b<=l;b++){
          scanf("%d",&t[a-1][b-1]);
      };      };
    for(a=1;a<=n;a++){
      for(b=1;b<=l;b++){
         for(c=1;c<=m;c++){
        u[a-1][b-1]+=s[a-1][c-1]*t[c-1][b-1];     
         }; }; };
         
    for(a=1;a<=n;a++){
        for(b=1;b<l;b++){
            printf("%ld ",u[a-1][b-1]);
            };printf("%ld\n",u[a-1][b-1]);
        };
        return 0;
}



Measured memory_bytes: 2124
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    string S;
    cin >> S;
    if (4 <= S.length() && S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n,k;
  cin>>n>>k;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  rep(i,n-k){
    if(a[i]<a[i+k])puts("Yes");
    else puts("No");
  }
  return(0);
}

Measured memory_bytes: 4040
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    int ans = 1;
    char X; cin >> X;
    F0R(i, N-1) {
        char Y; cin >> Y;
        if (X != Y) ans++;
        X = Y;
    }
    cout << ans << endl;

	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {

	int n, k, num = 1, a, b;

	cin >> n >> k;

	for (int i = 0; i < n; i++)
	{
		a = num * 2;
		b = num + k;
		num = min(a, b);
	}

	cout << num << "\n";

	return 0;
}

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

typedef struct{
  char mark;
  int number;
}Card;


int main(){
  Card array[52]={};
  bool flags[52]={0};
  int n;
  char Marks[4]={'S','H','C','D'};
  for(int i=0;i<4;i++){
    for(int j=0;j<13;j++){
      array[13*i+j].mark=Marks[i];
      array[13*i+j].number=j+1;
    }
  }
  cin>>n;
  for(int i=0;i<n;i++){
    char a;
    int b;
    cin>>a>>b;
    for(int j=0;j<52;j++){
      if(array[j].mark == a && array[j].number == b){
	flags[j] = true;
      }
    }
  }
  for(int i=0;i<52;i++){
    if(flags[i] == false)
      cout<<array[i].mark<<" "<<array[i].number<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

MinHeap<llong> que;
map<llong, llong> mp;
llong ans = 0;

int main() {
    llong n, k;
    llong a;

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

    for (auto x:mp) {
        que.push(x.second);
    }

    while(que.size() > k) {
        ans += que.top();
        que.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 14964
n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=sum(p[:k])
pre=ans
for i in range(1,n-k+1):
    pre+=p[i+k-1]
    pre-=p[i-1]
    ans=max(ans,pre)
print((ans+k)/2)

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


int main () {
    int n ;
    cin >> n ;
    vector<double> a(n) ;
    rep(i, n){
        cin >> a[i] ;
    }
    double ans ; 
    double bunshi = 1;
    rep(i, n){
        bunshi *= a[i] ;
    }
    double bunbo = 0 ;
    rep(i, n){
        double kobun = 1 ;
        rep(j, n){
            if(i != j){
                kobun *= a[j] ;
            }
        }
        bunbo += kobun ;
    }
    ans = bunshi / bunbo ;
    cout << fixed << setprecision(8) ;
    cout << ans << endl ;
}

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

int main(){
  char b;
  cin>>b;
  if(b=='A')cout<<'T'<<endl;
  else if(b=='T')cout<<'A'<<endl;
  else if(b=='C')cout<<'G'<<endl;
  else cout<<'C'<<endl;
}


Measured memory_bytes: 256
using System;

class a
{
	static void Main()
	{
		var s = int.Parse(Console.ReadLine());
		int h = s/3600;
		int m = (s%3600)/60;
		s = (s%3600)%60;
		Console.WriteLine("{0}:{1}:{2}",h,m,s);
	}
}

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] + N - 'A' > 25) S[i] = char(S[i] + N -26);
    else S[i] = char(S[i] + N);
  }
  
  cout << S << endl;
}

Measured memory_bytes: 256
implicit none

integer,parameter :: PRECINT = 8
integer(PRECINT) :: k
character(100) :: s
integer :: n, i, a
integer(PRECINT) :: m

read *,s
read *,k

n = len_trim(s)

m = 0
do i = 1, n
   read(s(i:i),*) a
   if (a == 1) then
      m = m + 1
      if (m >= k) then
         write(6,'(i0)') 1
         exit
      endif
   else
      write(6,'(i0)') a
      exit
   endif
enddo
stop
end

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while (sc.hasNext()) {
      double a = sc.nextDouble();
      double sum = 0;
      for (int i = 0; i < 5; i++) {
        sum += a;
        a *= 2;
        sum += a;
        a /= 3;
      }
      System.out.println(sum);
    }
  }
}

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

int main(){
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    vector<string> key = {"maerd", "remaerd", "esare", "resare"};
    ll i = 0;
    while(i < S.size()){
        bool f = false;
        for(auto k : key){
            if(i + k.size() > S.size()) continue;
            if(S.substr(i, k.size()) == k){
                f = true;
                i += k.size();
                break;
            }
        }
        if(!f){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void){
	int H[1000],W[1000];
	int n,h,w,k;

	for(n=0;;n++){
		scanf("%d %d",&H[n],&W[n]);
		if (H[n]==0 && W[n]==0 ) {
			break;
		}
	}

	for(k=0;k < n;k++){
		for (h = 0; h < H[k]; h++) {
			for (w = 0; w < W[k]; w++) {

				if ( (h%2==0 && w%2==0)  ||  (h%2==1 && w%2==1) ) {
					printf("#");
				}else{
					printf("." );
				}

			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 1996
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> x(n);
    int64_t s;
    for (auto&& xx : x) {
        cin >> xx;
        s += xx;
    }

    int64_t p1 = s / n, p2 = p1 + 1;
    int64_t k1 = 0, k2 = 0;
    for (auto&& xx : x) {
        k1 += (xx - p1) * (xx - p1);
        k2 += (xx - p2) * (xx - p2);
    }

    cout << min(k1, k2) << endl;
}

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

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> A(n);
    for (int &a: A)
        scanf("%d", &a);
    vector<int> B(n);
    for (int i=0; i<n; i++)
        B[i%2==0 ? i/2 : n-i/2-1] = A[n-i-1];
    for (int i=0; i<n; i++)
        printf("%d%s", B[i], i==n-1 ? "\n" : " ");
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;

int n;
long long dp[100005][2]={0};
int vis[100005]={0},par[100005]={0};

void dfs1(vector<int> adj[],int s)
{	
	for(int i=0;i<adj[s].size();i++)
	{
		if(vis[adj[s][i]]==0)
		{
			vis[adj[s][i]]=s;
			par[s]=1;
			dfs1(adj,adj[s][i]);
		}
	}
}

void dfs2(vector<int> adj[],int s)
{	
	dp[s][0]=1;
	dp[s][1]=1;
	for(int i=0;i<adj[s].size();i++)
	{
		if(vis[adj[s][i]]==0)
		{
			vis[adj[s][i]]=s;
			dfs2(adj,adj[s][i]);
			dp[s][0]=(dp[adj[s][i]][1]*dp[s][0])%MOD;
			dp[s][1]=((dp[adj[s][i]][1]+dp[adj[s][i]][0])*dp[s][1])%MOD;
		}
	}
}

main()
{
	cin>>n;
	
	vector<int> adj[n+1];
	int x,y;
	
	for(int i=0;i<n-1;i++)
	{
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	
	vis[1]=1e5+3;
	dfs1(adj,1);
	
	for(int i=1;i<=n;i++)
	{
		if(par[i]==0)
		{
			dp[i][0]=1;
			dp[i][1]=1;
			//cout<<i<<endl;
		}
	}
	
	memset(vis,0,(n+1)*sizeof(int));
	vis[1]=1e5+3;
	dfs2(adj,1);
	
	cout<<(dp[1][1]+dp[1][0])%MOD;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string s;
    bool ans = true;
    cin >> s;
    rep(i, s.size()) {
        if (i % 2 == 0) {
            if (s[i] == 'L')ans = false;
        }
        else {
            if (s[i] == 'R')ans = false;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
using namespace std;

const int N = 49;

int w, h;
vector<vector<int>> field;
int size;
vector<vector<int>> vertex;
vector<vector<int>> edge;
bitset<N> visited;
set<unsigned long long> memo;

void make_graph() {
    enum {Y, X};
    const int NEXT[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
    const int NIL = -1;
    size = 0;
    vertex = vector<vector<int>>(h, vector<int>(w, NIL));
    for(int y = 0; y < h; ++y) for(int x = 0; x < w; ++x) if(!field[y][x]) vertex[y][x] = size++;
    edge = vector<vector<int>>(h * w, vector<int>());
    for(int y = 0; y < h; ++y) for(int x = 0; x < w; ++x) {
        if(vertex[y][x] == NIL) continue;
        for(const auto &d: NEXT) {
            int ny = y + d[Y];
            int nx = x + d[X];
            if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
            if(vertex[ny][nx] == NIL) continue;
            edge[vertex[y][x]].push_back(vertex[ny][nx]);
        }
    }
};

void reachability(const int &from, bitset<N> &visited) {
    visited.set(from);
    for(const auto &to: edge[from]) if(!visited[to]) reachability(to, visited);
}
bool cut_vertex(const int &from) {
    auto dup = visited;
    dup.set(from);
    for(const auto &to: edge[from]) {
        if(dup[to]) continue;
        reachability(to, dup);
        return dup.count() != size;
    }
    return dup.count() != size;
}

bool dfs(const int &start, int from) {
    unsigned long long m = visited.to_ullong() * N + from;
    if(memo.count(m)) return false;
    memo.insert(m);

    // startの四方が囲まれていたらダメ
    bool deadend = true;
    for(const auto &v: edge[start]) deadend &= visited[v];
    if(deadend) return false;

    // cut vertexはダメ
    if(cut_vertex(from)) return false;

    // 現在地とstart以外で次数1の頂点があるとダメ
    for(int u = 0; u < size; ++u) {
        if(u == from) continue;
        if(u == start) continue;
        if(visited[u]) continue;
        int degree = 0;
        for(const auto& v: edge[u]) if(v == start || !visited[v]) ++degree;
        if(degree < 2) return false;
    }

    visited.set(from);
    for(const auto &to: edge[from]) {
        if(to == start && visited.count() == size) return true;
        if(visited[to]) continue;
        if(dfs(start, to)) return true;
    }
    visited.reset(from);
    return false;
}

bool solve() {
    visited = bitset<N>(0);
    make_graph();
    memo.clear();
    for(int y = 0; y < h; ++y) for(int x = 0; x < w; ++x) if(!field[y][x]) return dfs(vertex[y][x], vertex[y][x]);
    return false;
}

int main() {
    while(cin >> w >> h, w | h) {
        field = vector<vector<int>>(h, vector<int>(w));
        for(auto &line: field) for(auto &v: line) cin >> v;
        cout << (solve() ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 15324
#include <stdio.h>

int parent[25];
int left[25];
int right[25];

int degree(int node){
    int d = 0;
    if(left[node] != -1) d++;
    if(right[node] != -1) d++;
    return d;
}

int depth(int node){
    if(parent[node] == -1)
        return 0;
    else
        return depth(parent[node]) + 1;
}

int height(int node){
    int l = left[node];
    int r = right[node];
    int hl = l == -1 ? -1 : height(l);
    int hr = r == -1 ? -1 : height(r);
    return (hl < hr ? hr : hl) + 1;
}

int sibling(int node){
    int p = parent[node];
    if(p == -1)
        return -1;
    if(left[p] == node)
        return right[p];
    else
        return left[p];
}

int main(void){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        parent[i] = -1;
    for(int i=0; i<n; i++){
        int id, l, r;
        scanf("%d%d%d", &id, &l, &r);
        left[id] = l;
        right[id] = r;
        if(l != -1) parent[l] = id;
        if(r != -1) parent[r] = id;
    }
    for(int i=0; i<n; i++){
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, "
               "height = %d, ",
               i, parent[i], sibling(i), degree(i), depth(i), height(i));
        if(parent[i] == -1)
            printf("root\n");
        else if(degree(i) == 0)
            printf("leaf\n");
        else
            printf("internal node\n");
    }
}



Measured memory_bytes: 2100
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000000000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<vector<int>> a(n+1,vector<int>(n+1,inf));
  rep1(i,n){
      rep1(j,n){
          cin>>a[i][j];
      }
  }
  vector<vector<int>> dp(a);
  vector<vector<int>> memo(a);
  int sum=0;
  rep1(k,n){
      rep1(i,n){
          rep1(j,n){
              if(k==i||k==j)continue;
              if(dp[i][j]>=dp[i][k]+dp[k][j]){
                dp[i][j]=dp[i][k]+dp[k][j];
                  memo[i][j]=0;
              }
          }
      }
  }
  rep1(i,n){
      rep1(j,n){
          if(i>=j)continue;
          if(a[i][j]!=dp[i][j]){
              cout<<-1<<endl;
              return 0;
          }
          else{
              sum+=memo[i][j];
          }
      }
  }
  cout<<sum<<"\n";
  return 0;
}

Measured memory_bytes: 2432
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final char []s = sc.next().toCharArray();
        int r = 0, g = 0, b = 0;
        for (int i = 0;i < n;++i)
        {
            if (s[i] == 'R') ++r;
            if (s[i] == 'G') ++g;
            if (s[i] == 'B') ++b;
        }

        long ans = (long) r*g*b;
        long sub = 0;
        for (int i = 0;i < n;++i)
        {
            for (int j = i+1;j < n;++j)
            {
                int k = 2*j-i;
                if (s[i] == s[j]) continue;
                if (k >= n) continue;

                if (s[i] != s[k] && s[j] != s[k]) ++sub;
            }
        }

        System.out.println(ans-sub);
        sc.close();
    }
}

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

typedef vector<int> vi;
typedef pair<int,int> pii;
#define For(i,n) for(int i = 0; i < (int) n; ++i)
#define Rep(i,n) for(int i = 1; i <= (int) n; ++i)
#define ll long long
#define lld long double
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define ar array
#define INF 1e18;
#define all(v) (v).begin(),(v).end()
const int N=2e6+1,mod=1e9+7;
vi adj[N];
int cnt[N],p[N];
int ans=0;

int find(int x){
    return x^p[x]?p[x]=find(p[x]):x;
}

bool join(int x,int y){
    if((x=find(x))==(y=find(y)))
        return 0;

    p[x]=y;
    cnt[y]+=cnt[x];
    //ans=max(ans,cnt[y]);
    return 1;

}


void solve(){
    int n,m;
    cin>>n>>m;
    //for(int i=0;i<=n;i++)cnt[i]=1;
    iota(p,p+n+1,0);
    fill(cnt,cnt+n+1,1);
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v,--u,--v;
        if(join(u,v)){
            ans=max(ans,cnt[find(u)]);
        }
    }
    cout<<*max_element(cnt,cnt+n+1)<<endl;



}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
    t=1;
    while(t--){
        //cout<<"Case #"<<a<<": ";
        solve();
        //a+=1;
    }
}


Measured memory_bytes: 52096
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    ll n, m;
    cin >> n >> m;
    if(n ==2 || m == 2){
        cout << 0 << endl;
        return 0;
    }
    if(n==1 || m == 1){
        if(n == 1 && m == 1){
            cout << 1 << endl;
            return 0;
        }else{
            int mx = max(n, m);
            cout << mx -2 << endl;
            return 0;
        }
    }
    cout << (n-2)*(m-2) << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>

int main(void)
{
	int n,a,i,x=0,y=10000;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		x=0;
		while(a%2==0){
			x++;
			a=a/2;
		}
		if(x<y){
			y=x;
		}
	}
	printf("%d\n",y);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>

using namespace std;

typedef long long ll;

string k;
int d, n;
ll dp[100005][105][2];
const ll mod = (ll)1e9 + 7;

ll rek(int x, int sad, bool p){
	if(x == n)
		return (sad == 0);
	ll &ret = dp[x][sad][p];
	if(ret != -1)
		return ret;
	ret = 0;
	int gr = (p ? k[x] - '0' : 9);
	for(int i = 0 ; i <= gr ; ++i){
		ret = (ret + rek(x + 1, (sad + i) % d, (i == gr ? p : 0))) % mod;
	}
	return ret;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> k;
cin >> d;
n = (int)k.size();
memset(dp, -1, sizeof(dp));
ll t = (rek(0, 0, 1) - 1 + mod) % mod; 
cout << t << endl;

return 0;
}



Measured memory_bytes: 165120
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;

ll cmb(ll a){
    if(a < 2) return 0;
    return a*(a-1)/2;
}


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> s(n+1,0),A(n);

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

    ll sum = 0;
    for(ll i = 0; i < s.size();i++){
        sum += cmb(s[i]);
    }

    for(ll i = 0; i < n;i++){
        cout << sum - (s[A[i]]-1) << endl;
    }

    

    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

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

	gcd(b, a % b);
}

int main()
{
	/*int a, b;
	cin >> a >> b;
	int ans = 6 - a - b;
	cout << ans;*/


	/*int n;
	string s, t;
	cin >> n >> s >> t;
	string ans;
	rep(i, n) {
		ans += s[i];
		ans += t[i];
		
	}
	cout << ans;*/


	ll a, b;
	cin >> a >> b;
	ll ans = a * b / gcd(a, b);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
ans=0
for i,j in enumerate(a):
    b.append(i+j)
    c.append(i-j)
d=Counter(c)
for i in b:
    ans+=d.get(i,0)

print(ans)

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

int main() {
  int n, x;
  cin >> n >> x;

  vector<int> a(n);
  rep(i, n) cin >> a[i];

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

  int sum = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (sum + a[i] <= x) {
      sum += a[i];
      if (i < n - 1 || i == n - 1 && sum == x) 
        ans++;
    } else break;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

int a[505][505];
void solve(){  
    int n;
    cin>>n;
    rep(i,0,n){
        rep(j,i+1,n){
            rep(k,0,12){
                if(((i>>k)&1)!=((j>>k)&1)){
                    a[i][j]=k+1;
                    break;
                }
            }
        }
    }  
    rep(i,0,n){
        rep(j,i+1,n){
            cout<<a[i][j]<<' ';
        }
        cout<<endl;
    }
    cout<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        
        switch (str){
            case "SSS":
                System.out.println("0");
                break;
            case "SSR":
                System.out.println("1");
                break;
            case "SRR":
                System.out.println("2");
                break;
            case "RRR":
                System.out.println("3");
                break;
            case "RRS":
                System.out.println("2");
                break;
            case "RSS":
                System.out.println("1");
                break;
            case "RSR":
                System.out.println("1");
                break;
            case "SRS":
                System.out.println("1");
                break;
        }
    }
}

Measured memory_bytes: 26952
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)

int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	ini(n);
	int  morty = INF;
	int one = 0;
	int tmp = 0;
	int one1= 0;
	FOR(i,0,n){
		ini(x);
		if(x<0)one++;
		if(x == 0)one1++;
		tmp+=abs(x);
		morty = min(morty,abs(x));
	}
	if(one%2 == 0)out(tmp);
	else{
		if(one1){
			out(tmp);
		}
		else{
			out(tmp-2*morty);
		}
	}














	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long w[1001],v[1001],f[107][100007];
#define ll long long 
#define F(i,a,b) for(long long i=a;i<=b;i++)
int main()
{
        ll i,j,n,W,s=0;
            cin>>n>>W;
        F(i,1,n)
        {   cin>>w[i]>>v[i]; s+=v[i]; }
       F(i,1,s)
            f[0][i]=30000000000;
        F(i,1,n)
                F(j,1,s)
                {
                        f[i][j]=f[i-1][j];
                        if(j>=v[i])
                        f[i][j]=min(f[i][j],f[i-1][j-v[i]]+w[i]);
                }
        for(i=s;i>=1;i--)
                if(f[n][i]<=W)
                { cout<<i;  break;}
}

Measured memory_bytes: 80128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 2019

L, R = map(int, input().split())

R = min(R, L + 2019)

ans = 2019
for l in range(L, R + 1):
    for r in range(l + 1, R + 1):
        ans = min(ans, l * r % MOD)

print (ans)

Measured memory_bytes: 3188
def pushBack(vec,x):
    vec.append(x)
    return vec

def randomAccess(vec, p):
    return vec[p]

def popBack(vec):
    vec= vec[0:len(vec)-1]    
    return vec

n = int(input())
num_list = []
for i in range(n):
    num_list.append(list(map(int,input().split())))

num_of_operations = num_list[0][0]
vec = []
for i in range(len(num_list)):
    operation = num_list[i][0]
    if(operation == 2):
        vec = popBack(vec)
    else:
        n = num_list[i][1]
        
        if(operation == 0):
            vec = pushBack(vec,n)

        if(operation == 1):
            value = randomAccess(vec,n)
            print(value)
                    


Measured memory_bytes: 35636
import numpy as np

d,g=[int(c) for c in input().split(" ")]

p=[0]*(d+1)
c=[0]*(d+1)

for i in range(1,d+1):
    pp,cc=[int(c) for c in input().split(" ")]
    p[i]=pp
    c[i]=cc

def rec(i,g,flag):
    if i==d+1:
        cnt=0
        if g<=0:
            return 0

        for j in range(d,0,-1):
            bit=flag%2
            flag//=2

            if bit==0:
                ptsperprob=j*100
                psolved=min(p[j]-1,int(np.ceil(g/ptsperprob)))

                g-=psolved*ptsperprob
                cnt+=psolved

                if g<=0:
                    return cnt
        
        return 10000

    return min(p[i]+rec(i+1,g-c[i]-p[i]*100*i,2*flag+1),rec(i+1,g,2*flag))

print(rec(1,g,0))


Measured memory_bytes: 12512
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;


    bool ok = true;
    int num1 = 0;
    rep (i, n + 1) {
        if (s[i] == '0') {
            num1 = 0;
            continue;
        }
        if (s[i] == '1') num1++;
        if (num1 >= m) ok = false;
    }
    if (!ok) {
        cout << -1 << endl;
        return 0;
    }

    
    int startPos = n;
    int nowPos = n;
    nowPos -= m;
    bool fir = false;

    vector<int> ans;
    for (; startPos > 0; ) {
        if (nowPos < 0) {
            nowPos++;
            continue;
        }

        if (s[nowPos] == '0') {
            ans.pb(startPos - nowPos);
            startPos = nowPos;
            nowPos -= m;
            fir = true;
        }
        else {
            nowPos++;
            fir = false;
        }

    }

    for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1144
#include <stdio.h>

int main(){
	int A, B, K;

	scanf("%d", &K);
	scanf("%d %d", &A, &B);

	if(A%K==0 || B%K==0) printf("OK");
	else if(A%K + B - A < K) printf("NG");
	else printf("OK");

	return 0;
}


Measured memory_bytes: 1736
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a >>b;
    if(a>b){
        cout<<"a > b"<<endl;
    }else if(a==b){
        cout<<"a == b"<<endl;
    }else{
        cout<<"a < b"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
from sys import stdin
import math
a, b, x = [int(x) for x in stdin.readline().rstrip().split()]

box = a*a*b
air = box-x
if air * 2 > box:
    # 水が少ない 複雑
    h = 2*x/b/a
    l = (h**2 + b**2)**0.5
    degree = math.degrees(math.acos(h/l))
else:
    # air が三角
    hight = air/a/a*2
    l = (a**2 + hight**2)**0.5
    degree = math.degrees(math.acos(a/l))

print(degree)


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

int main()
{
    long long N;
    string S;
    cin >> N >> S;
    S = " " + S;

    vector<vector<long long>> count(N + 1, vector<long long>(3, 0));
    map<char, long long> m;
    m['R'] = 0;
    m['G'] = 1;
    m['B'] = 2;
    for (long long i = 1; i <= N; i++)
    {
        for (long long j = 0; j < 3; j++)
        {
            count[i][j] = count[i - 1][j];
        }
        count[i][m[S[i]]]++;
    }

    long long ans = 0;
    for (long long i = 1; i <= N - 2; i++)
    {
        for (long long j = i + 1; j <= N - 1; j++)
        {
            if (S[i] == S[j])
            {
                continue;
            }
            long long other = 3 - m[S[i]] - m[S[j]];
            long long sum = 0;
            long long k = j + (j - i);
            sum += count.back()[other] - count[j][other];
            if (k <= N && m[S[k]] == other)
            {
                sum--;
            }
            ans += max(0ll, sum);
        }
    }
    cout << ans << endl;
}


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

// @author: pashka

const long MOD = 1000000007;

long mult(long a, long b) {
    return a * b % MOD;
}

long power(long a, long b) {
    long res = 1;
    while (b > 0) {
        if (b & 1) res = mult(res, a);
        a = mult(a, a);
        b /= 2;
    }
    return res;
}

long inv(long a) {
    return power(a, MOD - 2);
}

vector<long> fact, inv_fact;

long calc_c(long n, long k) {
    long res = mult(fact[n], inv_fact[n - k]);
    res = mult(res, inv_fact[k]);
    return res;
}

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

    long n, k;
    cin >> n >> k;

    fact.resize(n + 1);
    inv_fact.resize(n + 1);
    fact[0] = inv_fact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = mult(fact[i - 1], i);
        inv_fact[i] = inv(fact[i]);
    }

    long res = 0;
    for (int z = 0; z < n; z++) {
        if (z > k) break;
        long s = calc_c(n, z);
        s = mult(s, calc_c(n - 1, n - z - 1));
        res += s;
        res %= MOD;
    }
//    if (res < 0) res += MOD;
    cout << res;

    return 0;
}

Measured memory_bytes: 3328
h,w=map(int,input().split())
List=[]
alphabet=[chr(i) for i in range(65,65+26)]
for i in range(h):
    line=list(input().split())
    List.append(line)
for i in range(h):
    for j in range(w):
        if List[i][j]=="snuke":
            print(alphabet[j]+str(i+1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int n = 200000;

int pr(int i) {
  return i > 0 ? i - 1 : n - 1;
}

int nx(int i) {
  return i + 1 < n ? i + 1 : 0;
}

vi added(200001);

void f(const vi& a, const vi& b, vi& q, int i) {
  if (added[i]) return;
  if (b[i] >= a[i] + b[nx(i)] + b[pr(i)]) {
    q.push_back(i);
    added[i] = 1;
  }
}

const int DEBUG = 0;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  if (!DEBUG) cin >> n;
  vi a(n), b(n);
  for (int i = 0; i < n; ++i) {
    if (!DEBUG) cin >> a[i];
    else a[i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    if (!DEBUG) cin >> b[i];
    else b[i] = rand() % (int)(1e9);
  }
  vi q;
  for (int i = 0; i < n; ++i) f(a, b, q, i);
  ll c = 0;
  while (!q.empty()) {
    int i = q.back();
    added[i] = 0;
    q.pop_back();
    ll s = b[pr(i)] + b[nx(i)];
    ll t = max(0LL, (b[i] - a[i]) / s);
    c += t;
    b[i] -= t * s;
    f(a, b, q, nx(i));
    f(a, b, q, pr(i));
//    for (int x : b) cerr << x << ' '; cerr <<endl;
  }
  if (a == b) cout << c << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
	int n;scanf("%d",&n);
	LL ans=0;
	for(int i=1;i<=n;i++){
		ans+=1ll*(i+n/i*i)*(n/i)/2;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3836
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

// check if the aregument is a prime number
template<typename T> bool isPrime(const T N) {
	if (N < 2)      return false;
	if (N == 2)     return true;
	if (N % 2 == 0) return false; // remove even numbers
	T sqrtN = static_cast<T>(std::sqrt(N));
	for (int i = 3; i <= sqrtN; i += 2) { if (N % i == 0) return false; }
	return true;
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const int X = inputVal<int>();
	int pr;
	int MXNB = 99992;
	int MXPR = 100003;

	if (X >= MXNB) {
		cout << MXPR << endl;
		return;
	}

	for (int i = X; i <= MXNB; ++i) {
		if (isPrime<int>(i)) {
			pr = i;
			break;
		}
	}
	outputVal(pr);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	return 0;
}


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

int main(){
  string n; 
  int a[1000]={};
  cin >> n;
  bool flag=true;
  for(int i=0;i<4;i++){
     a[(int)n[i]]++;
    //cout<<a[(int)n[i]]<<endl;
  }
  for(int i=0;i<1000;i++){
    if(a[i]!=0&&a[i]!=2){
       //cout<<a[i]<<endl;
       flag=false;
       break;
    }
  }
    if(flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int d,cnt=1;
	long long s;
	cin>>d;
	for(int i=1;i<=d;i++){
		cin>>s;
		cout<<"Case "<<cnt++<<":"<<endl;
		for(int j=0;j<10;j++){
			s=((s*s)/100)%10000;
			cout<<s<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3080