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

using ll = long long;

constexpr int mod = 1e9 + 7;

int main() {
    ll n;
    cin >> n;
    vector<vector<ll>> dp(64, vector<ll>(3));
    dp[0][0] = 1;
    for(int i = 0; i < 63; ++i) {
        const int s = 62 - i;
        for(int j = 0; j < 3; ++j) {
            // ai == bi == 1
            if(j != 0) {
                if(j == 1) (dp[i + 1][(n >> s) & 1] += dp[i][j]) %= mod;
                if(j == 2) (dp[i + 1][2] += dp[i][2]) %= mod;
            }
            // ai == 0 && bi == 1 || ai == 1 && bi == 0
            if(j >= 1 || (n >> s) & 1) {
                if(j == 0)      (dp[i + 1][0] += dp[i][j]) %= mod;
                else if(j == 1) (dp[i + 1][1 + ((n >> s) & 1)] += dp[i][j]) %= mod;
                else            (dp[i + 1][2] += dp[i][j]) %= mod;
            }
            // ai == 0 && bi == 0
            (dp[i + 1][min((j << 1) | (int)((n >> s) & 1), 2)] += dp[i][j]) %= mod;
        }
    }

    int ans = 0;
    for(int i = 0; i < 3; ++i) {
        (ans += dp[63][i]) %= mod;
    }

    cout << ans << 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 reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

signed main(){
    int k; cin >> k;
    cout << (int)(ceil(k/2.0)*floor(k/2.0)) << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let b = get!([usize]);

    let mut sum = b[0]+b[n-2];
    for i in 0..n-2 {
        sum += min!(b[i], b[i+1]);
    }
    println!("{}", sum);
}


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

using namespace std;

int getTop(int v){
  int order = log10(v);
  return v / pow(10, order);
}

int getBot(int v){
  return v%10; 
}

int main(){
  int N;
  cin >> N;
  
  vector<vector<int>> nums(10, vector<int>(10,0));
  
  for(int i=1; i<=N; i++){
    int top = getTop(i);
    int bot = getBot(i);
    ++nums[top][bot];
  }
  
  long count = 0;
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
       count+= nums[i][j] * nums[j][i];
    }
  }
  
  cout << count;
  return 0; 
}

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

const int mod = 1e9 + 7;

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n,m;
    cin >> n >> m;
    
    ll ans_n;
    ll ans_m;
    
    
    if(abs(n-m)>1){
        cout << 0 << endl;
        return 0;
    } else{
        ans_n = n;
        ans_m = m;
        
        for(ll i = n - 1; i >= 1; i--){
            ans_n = ans_n % mod * i;
        }
        
        for(ll i = m - 1; i >= 1; i--){
            ans_m = ans_m % mod * i;
        }
        
        if(abs(n-m)==1) cout << ans_n * ans_m % mod << endl;
        else cout << 2 * ans_n * ans_m % mod << endl;
        
    }

}


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

int main() {
  string S, T, Scopy;
  cin >> S >> T;
  vector<string> ans(0);
  bool flg;
  for (int i=0; i<S.length()-T.length()+1;i++) {
    flg=true;
    Scopy=S;
    for (int j=0; j<T.length(); j++) {
      if(Scopy[i+j]=='?') Scopy[i+j]=T[j];
      else if(Scopy[i+j]==T[j]) continue;
      else {
        flg=false;
        break;
      }
    }
    if(flg) {
      for (int k=0; k<S.length(); k++) {
        if(Scopy[k]=='?') Scopy[k]='a';
      }
      ans.push_back(Scopy);
    }
  }  
  if(ans.size()>0) {
    sort(ans.begin(), ans.end());
    cout << ans[0] << "\n";
  }
  else cout << "UNRESTORABLE\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
using namespace std;
const double EPS = 1e-10;
typedef complex<double> P;
inline bool eql(double a, double b) { return abs(b - a) < EPS; }
inline bool eql(P a, P b) { return eql(a.real(), b.real()) && eql (a.imag(), b.imag());}
inline double dot(P a, P b) { return a.real()*b.real() + a.imag()*b.imag(); }
inline bool orthogp(P a, P b) { return eql(dot(a, b), 0.0); }

int main(int argc, char **argv)
{
  double xa, ya, xb, yb, xc, yc, xd, yd;
  while (cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd) {
    if (orthogp(P(xa, ya) - P(xb, yb), P(xc, yc) - P(xd, yd)))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
//AtCoder ABC096 B - Maximum Sum
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll K;
    vector<ll> abc(3);
    cin>>abc[0]>>abc[1]>>abc[2];
    cin>>K;
    sort(abc.begin(),abc.end());
    ll ans=abc[2];
    for(ll i=0;i<K;++i){
        ans *= 2;
    }
    cout<<ans+abc[0]+abc[1]<<endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l = [tuple(input().split()) for _ in range(m)]
subs = [[] for _ in range(n)]

for i in range(m):
    subs[int(l[i][0])-1].append(l[i][1])

ac, p = 0, 0

for j in range(n):
    if 'AC' in subs[j]:
        ac += 1
        for k in range(len(subs[j])):
                if subs[j][k] == 'WA':
                    p += 1
                else:
                    break

print(ac, p)

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


int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a.at(i);
  }
  vector<int> sorteda, consta;
  consta = a;
  sort(a.begin(),a.end());
  sorteda = a;

  for(int i=0; i<n; i++){
    if(consta.at(i) == sorteda.at(n-1)){
      cout << sorteda.at(n-2) << endl;
    }else{
      cout << sorteda.at(n-1) << endl;
    }
  }
}


Measured memory_bytes: 3968
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

template<ull mod,ull phi_mod=mod-1>
class basic_mod_int{
    private:
        using mod_int=basic_mod_int<mod,phi_mod>;
        ull num;
        static ull pow_mod(ull x,ull y){x%=mod;return(y==0?1:y%2==0?pow_mod(x*x%mod,y/2):x*pow_mod(x,y-1))%mod;}
    public:
        basic_mod_int()=default;
        basic_mod_int(ull num):num(num%mod){}
        explicit operator ull()             const{return num;}
        bool    operator==(const mod_int&mi)const{return num==mi.num;}
        bool    operator!=(const mod_int&mi)const{return !operator==(mi);}
        mod_int operator~ ()                const{return pow_mod(num,phi_mod-1);}
        mod_int operator+ (const mod_int&mi)const{return num+mi.num;}
        mod_int operator- (const mod_int&mi)const{return num-mi.num+mod;}
        mod_int operator* (const mod_int&mi)const{return num*mi.num;}
        mod_int operator/ (const mod_int&mi)const{return num*(~mi).num;}
        mod_int&operator= (const mod_int&mi)     {num=mi.num;       return*this;}
        mod_int&operator+=(const mod_int&mi)     {num=operator+(mi);return*this;}
        mod_int&operator-=(const mod_int&mi)     {num=operator-(mi);return*this;}
        mod_int&operator*=(const mod_int&mi)     {num=operator*(mi);return*this;}
        mod_int&operator/=(const mod_int&mi)     {num=operator/(mi);return*this;}
};
template<ull mod,ull phi_mod=mod-1>
class combination_modulo:public basic_mod_int<mod,phi_mod>{
    private:
        using mod_int=basic_mod_int<mod,phi_mod>;
        vector<mod_int>factorial_mod;
    public:
        combination_modulo(ull max_n):factorial_mod(max_n+1)
        {
            factorial_mod[0]=1;
            for(ll i=1;i<=max_n;++i)factorial_mod[i]=factorial_mod[i-1]*i;
        }
        mod_int operator()(ull n,ull r)
        {
            return n<r?0:factorial_mod[n]/(factorial_mod[r]*factorial_mod[n-r]);
        }
};

int main()
{
    ll n=in();
    vector<ll>a(n+1);for(auto&i:a)i=in();

    ll d=accumulate(a.begin(),a.end(),0LL)-n*(n+1)/2;
    ll d1_idx=find(a.begin(),a.end(),d)-a.begin();
    ll d2_idx=a.rend()-find(a.rbegin(),a.rend(),d)-1;

    auto cm=combination_modulo<1000000007>(n+1);
    for(ll i=1;i<=n+1;++i)cout<<static_cast<ull>(cm(n+1,i)-cm(n+1-(d2_idx-d1_idx+1),i-1))<<endl;
}


Measured memory_bytes: 2816
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e1 + 10;
LL gcd(LL n, LL m)
{
	return m == 0 ? n : gcd(m, n%m);
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	LL lcm = 1;
	int n;
	cin >> n;
	while (n--)
	{
		LL x;
		cin >> x;
		lcm *= x / gcd(x, lcm);
	}
	cout << lcm << endl;
	return 0;
}

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

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

    vector<int> X(N);
    rep(i, N){
        cin >> X.at(i);
    }

    int ans = 10010010;

    rep(i, 101){
        int total = 0;
        rep(j, N){
            total += pow(X.at(j) - i, 2);
        }
        if (ans > total){
            ans = total;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll a[200005];
int main()
{
  ll n;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++)
    scanf("%lld", a + i);
  sortup(a, n);
  printf("%lld\n", a[n / 2] - a[n / 2 - 1]);
  return 0;
}

Measured memory_bytes: 1788
#include<stdio.h>
int main(void)
{
	long long int i,n,kin,goukei,heikin,cnt;
	scanf("%lld",&n);
	goukei=0;
	for(i=1;i<=n;i++) {
		scanf("%lld",&kin);
		goukei+=kin;
	}
	heikin=goukei/n;
	printf("%lld\n",heikin);
	return 0;
}

Measured memory_bytes: 596
#include<cstdio>
 
using namespace std;
 
int main(){
int a, b, c, k,sum;
 
scanf("%d%d%d%d", &a, &b, &c, &k);
 
if(a <= b && b <= c){
goto maxc;
}else if(b <= a && a <= c){
goto maxc;
}else if(a <= c && c <= b){
goto maxb;
}else if(c <= a && a <= b){
goto maxb;
}else if(b <= c && c <= a){
goto maxa;
}else if(c <= b && b <= a){
goto maxa;
}
 
maxa:
for(int i=1; i <= k; i++){
a = a * 2;
}
goto total;
 
maxb:
for(int i=1; i <= k; i++){
b = b * 2;
}
goto total;
 
maxc:
for(int i=1; i <= k; i++){
c = c * 2;
}
goto total;
 
total:
sum = a + b + c;
printf("%d", sum);
 
return 0;
}

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

int main(){
  
  int K, A, B;
  cin >> K >> A >> B;
  for(int i=A; i<=B; i++){
    if(i % K == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    FOR(i, (ll)s.size())
    {
        s[i] =(char) ((s[i] - 'A' + n) % 26 + 'A');
    }
    cout << s << '\n';
}



Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    int yotei = (n*(l+l+n-1)/2);
    if(l<=0&&(l+n)>=1){
      System.out.println(yotei);
    }else if(l>0){
      System.out.println(yotei-l);
    }else if(l<=0&&(l+n)<1){
      System.out.println(yotei-(l+n-1));
    }else{
    }
    
      
    
      
  }
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define show(i); cout<<i<<" ";
#define tr1(i); cout<<i<<endl;
#define tr2(i,j); cout<<i<<" "<<j<<endl;
#define tr3(i,j,k); cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<lli> >
#define all(st) st.begin(),st.end()
#define vpll vector<pair<lli,lli> >
#define vpii vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<lli,lli>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<lli>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ulli unsigned long long int
#define eb emplace_back
#define pb push_back
#define lli long long int
#define inf INT_MAX
#define minf INT_MIN
#define f first
#define se second
#define mod 1000000007
#define mx 500001
using namespace std;
void add_me(lli &a,lli b){
    a+=b;
    if(a>=mod) a-=mod;
}   
void sub_me(lli &a,lli b){
    a-=b;
    if(a<0) a+=mod;
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){
	if(a.se==b.se) return a.f<b.f;
    return (a.se < b.se); 
}
struct disjointset{
    int parent[mx];
   	disjointset(){
        for(int i=1;i<mx;i++) parent[i]=i;
    }
    int find(int x){
      	int par=parent[x];
        if(par==x) return x;
        return parent[x]=find(parent[x]);
    }
    void union_(int x,int y){
   	    int par1=find(x);
     	int par2=find(y);
       	if(par1==par2) return;
       	parent[par2]=par1;
    }
};
lli mi(lli n,lli m){
	lli pw=n;
	lli ex=m-2;
	lli ans=1;
	while(ex){
		if(ex&1) ans = ans*pw%m;
		pw = pw*pw%m;
		ex>>=1;
	}
	return ans%m;
}
// const int pm = 1000000;
// int spf[pm+1];
// bool is_prime[pm+1];
// int ETF[pm+1];
// void prime_solver(){
// 	memset(is_prime,true,sizeof(is_prime));
// 	for(int i=1;i<=pm;i++) spf[i]=i;
// 	for(int i=2;i*i<=pm;i++){
// 		if(is_prime[i]){
// 			for(int j=i*i;j<=pm;j+=i){
// 				is_prime[j]=false;
// 				if(spf[j]==j) spf[j]=i;
// 			}
// 		}
// 	}
// 	for(int i=1;i<=pm;i++) ETF[i]=i;
// 	for(int i=2;i*i<=pm;i++){
// 		if(ETF[i]==i){
// 			for(int j=i;j<=pm;j+=i){
// 				ETF[j]/=i;
// 				ETF[j]*=(i-1);
// 			}
// 		}
// 	}
// }
int target;
int n;
vector<vi> vec(21,vi(21));
int dp[1<<21];
int solve(int p,int mw){
	if(mw==target) return 1;
	if(dp[mw]!=-1) return dp[mw];
	int ans=0;
	int i,j;
	for(int j=0;j<n;j++){
		if((mw&(1<<j))==0 && vec[p][j]){
			ans+=solve(p+1,(mw|(1<<j)));
			ans%=mod;
		}
	}
	return dp[mw]=ans;
}
int main(){
	FIO;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	rep(i,0,n){
		rep(j,0,n) cin>>vec[i][j];
	}
	target=((1<<n)-1);
	int ans=solve(0,0);
	cout<<ans<<endl;
}

Measured memory_bytes: 8448
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, S):
    s1 = list(map(lambda x: len(x), filter(lambda x: x != '', S.split('0'))))
    s0 = list(map(lambda x: len(x), filter(lambda x: x != '', S.split('1'))))


    if len(s0) <= K:
        return N
    # error_print(N, K)
    # error_print(S)
    # error_print(s1)
    # error_print(s0)

    ans = 0
    s0_top = None
    if S[0] == '0':
        s0_top = s0.pop(0)
        ans = s0_top + sum(s1[:K]) + sum(s0[:K-1])
    
    l1o = 1
    l0o = 0
    l1 = sum(s1[:K+l1o])
    l0 = sum(s0[:K+l0o])
    k = 0
    
    while True:
        tmp = l1 + l0
        # if k == 0 and S[0] == '0':
        #     tmp -= s1[K]
        ans = max(ans, tmp)
        if k+K < len(s1) and k+K < len(s0):
            l1 -= s1[k]
            if k+K+l1o < len(s1):
                l1 += s1[k+K+l1o]
            l0 -= s0[k]
            if k+K+l0o < len(s0):
                l0 += s0[k+K+l0o]
        else:
            break
        k += 1
    

    return ans


def main():
    N, K = read_int_n()
    S = read_str()
    rS = ''.join(['0' if c == '1' else '1' for c in S])
    print(max(slv(N, K, S), slv(N, K-1, rS)))

    # N = 20
    # K = random.randint(1, 10)
    # S = ''.join(random.choices('01', k=N))
    # rS = ''.join(['0' if c == '1' else '1' for c in S])
    # print(max(slv(N, K, S), slv(N, K-1, rS)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 7092
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	for(int i=1;i<=d-b;i++)
		cout << "U";
	for(int i=1;i<=c-a;i++)
		cout << "R";
	for(int i=1;i<=d-b;i++)
		cout << "D";
	for(int i=1;i<=c-a+1;i++)
		cout << "L";
	for(int i=1;i<=d-b+1;i++)
		cout << "U";
	for(int i=1;i<=c-a+1;i++)
		cout << "R";
	cout << "D";
	cout << "R";
	for(int i=1;i<=d-b+1;i++)
		cout << "D";
	for(int i=1;i<=c-a+1;i++)
		cout << "L";
	cout << "U";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;


void Solve() {
	UL n; cin >> n;
	UL y[15][15] = {};
	rep(i, n) {
		UL a; cin >> a;
		rep(j, a) {
			UL x, yij; cin >> x >> yij;
			y[i][x - 1] = yij + 1;
		}
	}
	UL ans = 0;
	for (UL b = 0; b < 1 << n; b++) {
		bool broken = false;
		rep(i, n) {
			if (!((b >> i) & 1)) continue;
			rep(j, n) {
				if (y[i][j] == 0) continue;
				if (y[i][j] - 1 != ((b >> j) & 1)) broken = true;
			}
		}
		if (broken) continue;
		UL buf = 0;
		rep(i, n) if ((b >> i) & 1) buf++;
		ans = max(buf, ans);
	}
	cout << ans << endl;
}

int main() {
	Solve();
	return 0;
}


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

#define ll long long

using namespace std;

vector<ll> v;
vector<ll> w;

ll knapsack(ll x, ll n,vector<vector<ll>> &dp){
	
	if(x == 0 || n < 0)
		return 0;
	
	if(dp[n][x] > 0){
		return dp[n][x];
	}
	if(w[n] > x){
		dp[n][x] = knapsack(x,n-1,dp);	
	}
	else{
		dp[n][x] = max(knapsack(x-w[n], n-1,dp) + v[n], knapsack(x,n-1,dp));
	}
	return dp[n][x];
}

int main(){
	ll n,x;
	cin >> n >> x;
	v.assign(n,0);
	w.assign(n,0);
	vector<vector<ll>> dp;
	for(int i = 0; i < n; i++){
		vector<ll> row(x+1);
		dp.push_back(row);
	}

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

	cout << knapsack(x,n-1,dp) << "\n";
	
}

Measured memory_bytes: 81856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;
    vector<string> p;
    rep (i, s.size()) {
        rep (j, 1, 6) {
            if (i + j > s.size()) {
                break;
            } else {
                p.push_back(s.substr(i, j));
            }
        }
    }
    sort(all(p));
    unique(all(p));
    cout << p[k - 1] << endl;
}

Measured memory_bytes: 1660
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        if (str.equals("Sunny")) {
            System.out.println("Cloudy");
        } else if (str.equals("Cloudy")) {
            System.out.println("Rainy");
        } else if (str.equals("Rainy")) {
            System.out.println("Sunny");
        }
    }
}


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

using ll = long long;
const ll MOD = 998244353;
const ll INF = 1e18;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N));
    vector<vector<int>> r(0, vector<int>(3));
    rep(i, N) rep(j, N) {
        cin >> A[i][j];
        r.push_back({A[i][j], i, j});
    }
    sort(r.begin(), r.end());
    /*rep(i, r.size()) {
        cout << r[i][0] << " " << r[i][1] << " " << r[i][2] << endl;
    }*/
    vector<vector<ll>> d(N, vector<ll>(N, INF));
    ll ans = 0;
    rep(i, r.size()) {
        int x = r[i][0], y = r[i][1], z = r[i][2];
        if (x > d[y][z]) {
            //cout << x << y << z << d[x][y] << endl;
            cout << -1 << endl;
            return 0;
        }
        if (x < d[y][z]) {
            ans += x;
            d[y][z] = x;
            d[z][y] = x;
            rep(j, N) rep(k, N) {
                ll p = d[j][y] + x + d[z][k];
                if (d[j][k] > p) {
                    if (p < A[j][k]) {
                        //cout << "p=" << p << j << k << A[j][k] << endl;
                        cout << -1 << endl;
                        return 0;
                    }
                    d[j][k] = p;
                    d[k][j] = p;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6964
n=input()
lenlen=len(n)
if lenlen%2==0:
  res=0
  for i in range(0,lenlen//2):
    res+=10**(2*i+1)-10**(2*i)
else:
  res=0
  for i in range(0,lenlen//2):
    res+=10**(2*i+1)-10**(2*i)
  res=res+int(n)-10**(lenlen-1)+1
print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int read();
void Add(int &x, int y) { (x += y) >= mod ? x -= mod : x; }
int f[302][302][302];
struct P {
    int l, x;
};
vector<P> p[302];

bool check(int a, int b, int c) {
    for (int i = 0; i < p[a].size(); ++i)
        if (1 + (b >= p[a][i].l) + (c >= p[a][i].l) != p[a][i].x) return 0;
    return 1;
}

int main() {
    int n = read(), m = read();
    for (int i = 1, l, r, x; i <= m; ++i) {
        l = read(), r = read(), x = read();
        if (r - l + 1 < x) return puts("0"), 0;
        p[r].push_back((P){l, x});
    }

    f[1][0][0] = 1;
    for (int i = 1; i < n; ++i) {
        if (check(i, 0, 0))
            Add(f[i + 1][0][0], f[i][0][0]), Add(f[i + 1][i][0], f[i][0][0]);
        for (int j = 1; j < i; ++j) {
            for (int k = 0, x; k < j; ++k) {
                if (!check(i, j, k)) continue;
                Add(f[i + 1][j][k], f[i][j][k]);
                Add(f[i + 1][i][k], f[i][j][k]);
                Add(f[i + 1][i][j], f[i][j][k]);
            }
        }
    }
    long long c[4];
    c[0] = 6, c[1] = 6;
    int res = 0;
    if (check(n, 0, 0)) res = 3ll * f[n][0][0] % mod;
    for (int j = 1; j < n; ++j)
        for (int k = 0; k < j; ++k)
            if (check(n, j, k)) Add(res, c[(!j) + (!k)] * f[n][j][k] % mod);
    printf("%d\n", res);
    return 0;
}

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

Measured memory_bytes: 105472
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#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 drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

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

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll total = 0;
    rep(i,N) total += A[i];

    ll tmp = 0;
    int lim = 0;
    while (tmp < (total / 2)) {
        tmp += A[lim];
        ++lim;
    }
    ll res = 0;
    for (int i = lim; i<N; ++i) {
        res += A[i];
    }
    ll ans = abs(tmp-res);

    tmp = 0;
    lim = N-1;
    while (tmp < (total / 2)) {
        tmp += A[lim];
        --lim;
    }
    res = 0;
    for (int i = lim; i>=0; --i) {
        res += A[i];
    }

    ans = min(ans, abs(tmp-res));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include<vector>
#include <algorithm>
using namespace std;

int main(){
    int W, H, N;
    cin >> W >> H >> N;
    int x[N] , y[N] , a[N];
    for(int i=0;i<N;i++){
        cin >> x[i] >> y[i] >> a[i];
    }

	vector< vector<int> > arr;
	arr.resize(2);		// ()内の数字が要素数になる
	for( int i=0; i<2; i++ ){
		arr[i].resize(2);
	}
    //xの変域の左端
    arr[0][0] = 0;
    //xの変域の右端
    arr[0][1] = W;
    //yの変域の下端
    arr[1][0] = 0;
    //yの変域の上端
    arr[1][1] = H;

    for(int i=0;i<N;i++){
        if(a[i]==1){
            if(arr[0][0]<x[i]){
                arr[0][0] = x[i];
            }
        }else if(a[i] == 2){
            if(arr[0][1]>x[i]){
                arr[0][1] = x[i];
            }
        }else if(a[i] == 3){
            if(arr[1][0]<y[i]){
                arr[1][0] = y[i];
            }
        }else if(a[i] == 4){
            if(arr[1][1]>y[i]){
                arr[1][1] = y[i];
            }
        }
    }
    int width = arr[0][1] - arr[0][0];
    int height = arr[1][1] - arr[1][0];
    if(width > 0 && height >0){
        cout << width * height << endl;
    }else{
        cout << 0 << endl;
    }
//    cout << arr[0][1] - arr[0][0] << endl;
//    cout << arr[1][1] - arr[1][0] << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  string S;
  cin>>S; 
  if(S.at(0)==S.at(1)&&S.at(0)==S.at(2)){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
 
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int Par[100002];
void init(){for(int i = 0;i<100002;i++)Par[i]=i;}

int find(int x)
{
	if(x==Par[x])return x;
	return Par[x] = find(Par[x]);
}

void unite(int x,int y)
{
	x = find(x);
	y = find(y);
	if(x==y)return;
	Par[y] = x;
}


int main()
{
	init();
	int n,m;
	cin >> n >> m;
	vector<vector<int>> l(n);
	for(int i =0;i<n;i++)
	{
		int k;
		cin >> k;
		for(int j  = 0;j<k;j++)
		{
			int x;
			cin >> x;
			x--;
			l[i].push_back(x);
		}
	}
	for(int i = 0;i<n;i++)
	{
		int now = l[i][0];
		for(int j = 1;j<l[i].size();j++)
		{
			unite(now,l[i][j]);
		}
	}
	bool yes = true;
	int p = find(l[0][0]);
	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<l[i].size();j++)
		{
			if(find(p)!=find(l[i][j]))yes = false;
		}
	}
	cout << (yes?"YES":"NO")<< endl;
}


Measured memory_bytes: 8828
#include <iostream>
using namespace std;
int main(void){
   int A,B,C,D,E,a,b;
   cin >> A >> B >> C >> D >> E;
   if(A<0){
       a=-(A*C);
       b=B*E;
       cout << a+D+b << endl;
   }else if(A>0){
       a=B-A;
       b=a*E;
       cout << b << endl;
   }else if(A==0){
       a=B*E;
       cout << D+a << endl;
   }
 }


Measured memory_bytes: 3088
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=999999;
int a[1100];
int main()
{
	int n;
	int ans=0;
	cin>>n;
	int t=maxn;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=1;i<n;i++)
	{
		if(a[i]!=a[i-1])
			continue;
		a[i]=t--;
		ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner stdin = new Scanner(System.in);

        int N = stdin.nextInt();
        String S = stdin.next();
        String copy = S.substring(0,1);
        int cnt = 1;

        for(int i=1;i<S.length();i++) {
        	if(!(copy.equals(S.substring(i,i+1)))) {
        		copy =  S.substring(i,i+1);
        		cnt+=1;
        	}
        }
        System.out.println(cnt);
    }
}


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

int main(){
  int L,R,d;
  int count=0;
  cin >> L >> R >> d;
  for(int i=L;i<=R;i++){
    if(i%d==0){
      count++;
    }
  }
  cout << count <<endl;
  return(0);
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

ll dp[100100][13];
// dp[i][j] 

int main(){
  string S; cin>> S; memset( dp, 0, sizeof(dp));
  
  dp[0][0] = 1;
  
  for(ll i = 0; i < (ll)S.size(); i++){
    char c = S[i];
    
    if( c == '?'){ 
      
      for(int  j = 0; j < 10; j++){
       for(int ki = 0; ki < 13; ki++){
        dp[i+1][( 10 * ki + j) % 13] += dp[i][ki];}}
    }
    
    else{ int d = c - '0';
      
      for(int ki = 0; ki < 13; ki++){
        dp[i+1][(10 * ki + d) % 13]  += dp[i][ki];}
        }
    
    for(int ki = 0; ki < 13; ki++){
      dp[i+1][ki] %= MOD;}
  }
    
    
    cout << dp[(ll)S.size()][5] << endl;
    
    return 0;}
          
    

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

// clang-format off
#define forn(i, x, y) for(int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
#define printVector(a) for(auto it = a.begin() ; it != a.end(); it++) {cout << *it << endl;}

using VI = vector<int>;
using VVI = vector<VI>;
// clang-format on

const long long MOD = 1000000007;

int main()
{
  IOS;

  int H, W;
  cin >> H >> W;

  VVI dp(H, VI(W));
  dp[0][0] = 1;
  string line;
  forn(i, 0, H)
  {
    cin >> line;
    forn(j, 0, W)
    {
      if (line[j] == '#')
        continue;
      if (i > 0)
        dp[i][j] += dp[i - 1][j];
      if (j > 0)
        dp[i][j] += dp[i][j - 1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[H - 1][W - 1] << endl;

  return 0;
}


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

int main() {
  int max = 50;
  char a[max];
  int m, f, r;

  for (int i = 0; i < max; i++) {
    cin >> m >> f >> r;

    if (m == -1 && f == -1 && r == -1) break;

    int sum = m + f;
    if (m == -1 || f == -1) a[i] = 'F';
    else if (80 <= sum) a[i] = 'A';
    else if (65 <= sum) a[i] = 'B';
    else if (50 <= sum) a[i] = 'C';
    else if (30 <= sum) {
      if (50 <= r) a[i] = 'C';
      else a[i] = 'D';
    }
    else a[i] = 'F';

    cout << a[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include <set>
#include <vector>
#include <map>

#define MAX_NM int(1e5+10)

int n, m;
std::pair<int, int> bridges[MAX_NM];
std::vector<int> islands_s[MAX_NM];
std::vector<int> islands_e[MAX_NM];

int main() {
    std::cin >> n >> m;

    for(int i = 0; i < m; ++i) {
        std::cin >> bridges[i].first >> bridges[i].second;        
        --bridges[i].second;

        islands_s[bridges[i].first].push_back(i);
        islands_e[bridges[i].second].push_back(i);
    }

    std::set<int> stack;
    int cnt = 0;
    for(int i = 1; i < n; ++i) {
        for(auto& a : islands_s[i]) {
            stack.insert(a);
        }

        for(auto& a : islands_e[i]) {
            if (stack.count(a)) {
                ++cnt;
                stack.clear();
                break;
            }
        }
    }

    std::cout << cnt << std::endl;
}

Measured memory_bytes: 12668
n ,m = map(int,input().split())
ok = [False] * n
wa = [0] * n
for i in range(m):
    p,s = input().split()
    if s == 'AC':
        ok[int(p)-1] = True
    elif not(ok[int(p)-1]):
        wa[int(p)-1] += 1
wa_sum = sum([wa[i] * ok[i] for i in range(n)])
print(sum(ok),wa_sum)


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

int main(void){
    int hour, min, sec;
    int input;
    cin >> input;
    
    hour = input / 3600;
    input %= 3600;
    
    min = input / 60;
    input %= 60;
    
    sec = input;
    cout <<  hour << ":" << min << ":" << sec << endl;
    
    return 0;
}



Measured memory_bytes: 3100
#import heapq
#import itertools
#import math
#import numpy as np
#import sys

S = input()
#A = list(map(int, input().split()))
#S = [input() for _ in range(H)]
#T = [list(map(int,input().split())) for _ in range(N)]
if S == 'Sunny' :
    print('Cloudy')
elif S == 'Cloudy' :
    print('Rainy')
elif S == 'Rainy' :
    print('Sunny')
    

Measured memory_bytes: 2940
import math

A,B,X = map(int, input().split())

x=X/(A*A)
x2=X/A

if(x2>=((A*B)/2)):
    #b2=B-(2*x2-A*B)/A
    #print(90*(b2/A))
    tmp=(2*A*A*B-2*X)
    tmp2=A*A*A
    print(round(math.degrees(math.atan(tmp/tmp2)),10))
else:
    tmp=(A*B*B)
    tmp2=2*X
    print(round(math.degrees(math.atan(tmp/tmp2)),10))
#    print(90*(B/a2))
#    print(math.degrees(math.tan(B/a2)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];
  int ans = 0;
  for (int i = 0; i < N; i++)
    for (int j = i+1; j < N; j++)
      for (int k = j+1; k < N; k++)
        if (v[i] != v[j] && v[j] != v[k] && v[k] != v[i])
          if (abs(v[i]-v[j]) < v[k] && v[k] < v[i]+v[j])
            ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if((a + b) % 2 == 1){
        cout << (a + b) / 2 + 1 << endl;
    }else{
        cout << (a + b) / 2 << endl;
    }

    return 0;
}

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

int main(){
  int X,Y;
  cin >> X >> Y;
  for(int i=0;i<=X;i++){
    int j = X-i;
    if(2*i + 4*j == Y){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}

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

int main(){
    while(1){
        int n,x;
        int cnt = 0;
        cin >> n >> x;
        if(n==0 && x==0) break;
        for(int i=1;i<=n-2;i++){
            for(int j=i+1;j<=n-1;j++){
                for(int k=j+1;k<=n;k++){
                    if(i + j + k == x) cnt++;
                
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


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

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;
const ll MOD = 998244353;

const ll MAX = 1100000;
long long fac[MAX], finv[MAX], inv[MAX];

ll table[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){


    ll N, M, K;
    cin >> N >> M >> K;


    ll ans = 1;
    // 全体の個数
    for(ll i = 0; i < N; i++){
        ans *= M;
        ans %= MOD;
    }

    if(DEBUG) cout << "all is " << ans << endl;

    if(DEBUG){
        ll tmp = M;
        for(ll i = 0; i < 99; i++ ){
            tmp *= (M - 1);
            tmp %= MOD;
        }
        cout << "g : " << tmp << endl;
    }

    table[0] = M;
    for(int i = 1; i <= N; i++){
        table[i] = table[i - 1] * (M - 1);
        table[i] %= MOD;
    }
    COMinit();
    // i:しきりの数
    for(ll i = 0; i < N; i++){
        if(N - 1 - i > K){
            ll tmp = 0;
            if(i == 0){
                tmp = M;
            }
            else{
                tmp = table[i];
                tmp %= MOD;
                tmp *= COM( N - 1, i );
                tmp %= MOD;
            }
    
            if(DEBUG){
                cout << "i :" << i << " tmp :" << tmp << endl;
            }
            ans -= tmp;
            if(ans < 0) ans += MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 30976
#include <iostream>
#include <string>

using namespace std;

int main() {
    unsigned long long N; cin >> N;
    unsigned long long res = 0;
    
    for (long long i = 1; i < N; ++i) {
        long long tmp = N / i - 1;
        if (tmp == 0) break;
        if (N % tmp == N / tmp) {
            res += tmp;
        }
        if (tmp < (N / tmp)) {
            break;
        }
    }
    cout << res << endl;
    return 0;
}


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

struct Edge{
    int to;
};
using Graph = vector<vector<Edge>>;
 
// 深さ優先探索
vector<bool> seen;  // 探索したか記録
vector<int> s;
void dfs(const Graph &G, int v, int cnt) {
    seen[v] = true;
    s[cnt]++;
    for(auto e : G[v]) {
        if (!seen[e.to]) {  // 訪問済みでなければ探索
            dfs(G, e.to, cnt);
        }
    }
}
 
int main() {
    int n, m;
    cin >> n >> m;
 
    Graph G(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back({b});
        G[b].push_back({a});
    }

    seen.assign(n, false);  // 初期化
    s.resize(n, 0);
    int cnt = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!seen[i]) {
            dfs(G, i, cnt);
            cnt++;// dfsした回数をカウント
        }
    }
    rep(i, n){
        ans = max(ans, s[i]);
    }
    cout << ans << endl;
    return 0;
}


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

ans = 0
for v in range(1, N + 1):
    ans += v * (N - v + 1)

for _ in range(N - 1):
    u, v = map(int, input().split())
    u, v = min(u, v), max(u, v)
    ans -= u * (N - v + 1)

print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n; cin >> n;
	//vector<double> av;
	long double sum = 0;
	for(int i = 0; i < n; i++){
		long double a;cin >> a;
		sum += 1/a;
	}
	printf("%Lf\n", 1/sum);
}

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

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();

        long answer = 0;

        answer += (long)(n / 500 * 1000);
        n = n % 500;
        answer += (long)(n / 5 * 5);

        Console.WriteLine(answer);
    }

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

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

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

            return _line[_index++];
        }

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

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

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

Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<string>
#include<cmath>


using namespace std;



int main() {
	string s;
	cin >> s;
	int count = 0;

	for (int i = 0; i < s.size(); i+=2)
	{
		if (s[i] == 'L') {
			count++;
		}
	}

	for (int i = 1; i < s.size(); i+=2)
	{
		if (s[i] == 'R') {
			count++;
		}
	}

	if (count == 0) {
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
flag = 0
ans = 1
n = int(input())
num_list = list(map(int, input().split()))
for num in num_list:
    if num == 0:
        ans = 0
        
for num in num_list:
    ans = ans*num

    if ans > 1000000000000000000:
        print(-1)
        flag = 1
        break;
if flag == 0:
    print(ans)

Measured memory_bytes: 21788
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b;
    cin >> a >> b;
    int res = 0;
    for (int i = 1; i <= 12; ++i) {
        if (i < a || (i == a && i <= b)) {
            ++res;
        } else {
            break;
        }
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256