akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

int main (){

  int N = 0, K = 0;
  scanf("%d %d", &N, &K);

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

  int check[N];
  for( i = 0; i < N; i++ ){
    check[i] = 0;
  }

  int res = 0;
  for( i = 0; i < K; i++ ){
    for( j = 0; j < d[i]; j++ ){
      check[A[i][j] - 1]++;
    }
  }

  for( i = 0; i < N; i++ ){
    if( check[i] == 0 ){
      res++;
    }
  }

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

  return 0;

}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,c,k;cin>>n>>c>>k;
  ll t[n];
  for(ll i=0;i<n;i++)cin>>t[i];
  sort(t,t+n);
  ll ans=0;
  ll now=t[0];
  ll sum=1;
  for(ll i=1;i<n;i++){
    if(sum==c){
      ans++;
      now=t[i];
      sum=1;
      continue;
    }
    if(now+k>=t[i])sum++;
    if(now+k<t[i]){
      ans++;
      now=t[i];
      sum=1;
      continue;
    }
  }
  cout<<ans+1<<endl;
}

Measured memory_bytes: 1024
using System;

namespace ABC069
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            Console.WriteLine(B_i18n.charCount(s));
        }
    }
    
  	public class B_i18n
    {
        public static string charCount(string s)
        {
            var cnt = s.Length - 2;
            return s[0] + cnt.ToString() + s[^1];
        }
    }
}

Measured memory_bytes: 25784
/*
    AUTHOR : TANMAY SINHA
    INFORMATION TECHNOLOGY
    BIT MESRA ,RANCHI
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define rep(i,L,R) for(i=L;i<R;i++)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
const ll INF = 1e18l+10,N = 1e5,MAX = 5000000;
#define sq(X) ((X)*(X))

int main()
{
    ll a[3][3];
    ll i,j,k;
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    cin>>a[i][j];
    ll b,t;
    ll arr[3][3];
    memset(arr,0,sizeof(arr));
    cin>>b;
    while(b--)
    {
        cin>>t;
        for(i=0;i<3;i++)
        for(j=0;j<3;j++)
        {
            if(t==a[i][j])
            arr[i][j]=1;
        }
    }
    ll f = 0;
    if(arr[0][0]==1&&arr[1][1]==1&&arr[2][2]==1)
    f=1;
    else if(arr[0][2]==1&&arr[1][1]==1&&arr[2][0]==1)
    f=1;
    for(i=0;i<3;i++){
    if(arr[0][i]==1&&arr[1][i]==1&&arr[2][i]==1)
    f=1;
    if(arr[i][0]==1&&arr[i][1]==1&&arr[i][2]==1)
    f=1;
    }
    if(f==1)
    cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    if(k <= a){
        cout << k << endl;
    }else if(k <= a+b){
        cout << a << endl;
    }else{
        cout << a - (k-a-b) << endl;
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 3588
a, b, c, x, y = map(int, input().split())
price = float("inf")
max_iter = max(x, y)*2

for i in range(max_iter):
    a_num = max(x-i, 0)
    b_num = max(y-i, 0)
    price = min(price, a_num*a + b_num*b + 2*i*c)

print(price)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define push_back pb
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<string> s(N);
	rep(i,N)cin>>s[i];
	ll ans = 0;
	int len = 0;
	//並べる前にある文字列を数え上げ（O(N*10))
	for (int i = 0; i < N; ++i){
		len = s[i].size();
		for (int j = 0; j+1 < len ; ++j){
			if(s[i][j] == 'A' && s[i][j+1] == 'B'){
				ans++;
			}
		}
	}
	ll c = 0;
	ll a = 0;
	ll b = 0;
	for (int i = 0; i < N; ++i){
		len = s[i].size();
		if(s[i][len-1] == 'A'&&s[i][0] =='B'){
			c++;
		}
		else if(s[i][len-1] == 'A'){
			a++;
		}
		else if(s[i][0] == 'B'){
			b++;
		}
	}
	if(c>0){
		ans += c-1;
		if(a>0){
			ans += 1;
			a--;
		}
		if(b>0){
			ans += 1;
			b--;
		}
		ans += min(a,b);
	}
	else{
		ans += min(a,b);
	}
	cout<<ans<<endl;
}

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

#define MAX_SIZE 300

int T[MAX_SIZE];

int parent(int i) { return i / 2; }
int left(int i) { return i * 2; }
int right(int i) { return i * 2 + 1; }

int main() {
    int H;
    cin >> H;
    for (int i = 1; i <= H; i++) cin >> T[i];

    for (int i = 1; i <= H; i++) {
        cout << "node " << i << ": key = " << T[i] << ", ";
        if (parent(i) > 0) cout << "parent key = " << T[parent(i)] << ", ";
        if (left(i) <= H) cout << "left key = " << T[left(i)] << ", ";
        if (right(i) <= H) cout << "right key = " << T[right(i)] << ", ";
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3100
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        k: usize,
        a: usize,
        b: usize,
    }

    for i in a..=b {
        if i % k == 0 {
            println!("OK");
            return;
        }
    }

    println!("NG");
}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 1000000007
bool compare(int a, int b) {
    return a > b;
}
int main() {
    fio;
    int n;
    cin >> n;
    vector<int>v;
    for (int i = 0; i < n; i++) {
        int s, e;
        cin >> s >> e;
        if (s == e) {
            v.push_back(1);
        }
        else {
            v.push_back(0);
        }
    }
    int flag = 0;
    for (int i = 0; i < n; i++) {
        //cout << v[i] << " ";
        if (v[i] == 1) {
            for (int j = i; j < i + 3; j++) {
                if (v[j] == 1) {
                    flag++;
                    continue;
                }
                else {
                    break;
                }
            }
            if (flag == 3) {
                cout << "Yes" << endl;
                return 0;
            }
            flag = 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    b+=a*3;
    cout << b/2<<endl;
    return 0;
}



Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    X, K, D = map(int, input().split())
    X = abs(X)
    if X - K * D >= 0:
        print(X - K * D)
    else:
        k = X // D
        if (K-k)%2 == 0:
            print(X - k * D)
        else:
            print(-(X - (k+1)*D))


if __name__ == '__main__':
    main()


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

int main() {
	int N,K; cin >>N>>K;
	string S;cin >> S;
	int z=0,o=0;
	vector<int> X;
	for(int i = 0 ; i < N ; i++){
		if(S[i] == '0'){
			z++;
			if(i == 0)X.push_back(0);
			if(o > 0) X.push_back(o);
			o = 0;
		}
		if(S[i] == '1'){
			o++;
			if(z > 0) X.push_back(z);
			z = 0;
		}
	}
	X.push_back(max(z,o));
	if(o == 0)X.push_back(0);
	//for(int k : X)cout << k << endl;
	//return 0;
	int Y=0;
	K = min(K,((int)X.size()-1)/2);
	for(int i = 0 ; i < 2*K + 1 ; i++){
		Y += X[i];
	}
	vector<int> ans(1,Y);
	for(int i = 0 ; i + 2*K + 1 < X.size() ; i += 2){
		Y += X[i + 2*K + 1];
		Y += X[i + 2*K + 2];
		Y -= X[i];
		Y -= X[i + 1];
		ans.push_back(Y);
	}
	sort(ans.begin(),ans.end());
	//for(int k : ans)cout << k << endl;
	//return 0;
	cout << ans[ans.size() - 1] << endl;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int n; cin >> n;
    vll a(n);
    FOR(i, 0, n - 1)
        cin >> a[i];
    ll s = a[0] + a[1], x = 0;
    FOR(i, 2, n - 1)
        x ^= a[i];
    if ((s - x) & 1 || s - x < 0) return cout << -1 << endl, 0;
    ll d = (s - x) / 2;
    ll b = 0, c = 0;
    // cout << d << ' ' << x << endl;
    ROF(i, 39, 0) {
        ll p = 1LL << i;
        if ((d & p) && (x & p)) return cout << -1 << endl, 0;
        if ((d & p) && !(x & p)) b += p, c += p;
    }
    ROF(i, 39, 0) {
        ll p = 1LL << i;
        if (!(d & p) && (x & p)) {
            if (b + p <= a[0]) b += p;
            else c += p;
        }
    }
    if (b == 0 || b > a[0]) cout << -1 << endl;
    else cout << a[0] - b << endl;
}

Measured memory_bytes: 3584
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define p 1000000007
using namespace std;

long long fac[200010],inv[200010],n,m,aa,bb,ans;

long long kasumi(long long a,long long b)
{
	long long ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=(ans*a)%p;
		}
		a=(a*a)%p;
		b>>=1;
	}
	return ans;
}

long long cc(int a,int b)
{
//	printf("%d %d\n",a,b);
	if(a==b||b==0)
	{
		return 1;
	}
	return ((fac[a]*inv[b])%p*inv[a-b]%p);
}

long long get_(int x1,int y1,int x2,int y2)
{
//	printf("x1:%d y1:%d x2:%d y2:%d\n",x1,y1,x2,y2);
	return cc(x2-x1+y2-y1,x2-x1);
}

int main()
{
    fac[1]=1;
    for(int i=2;i<=200000;i++)
    {
    	fac[i]=(fac[i-1]*i)%p;
	}
	inv[200000]=kasumi(fac[200000],p-2);
	for(int i=199999;i>=1;i--)
	{
		inv[i]=(inv[i+1]*(i+1))%p;
	}
    scanf("%d%d%d%d",&n,&m,&aa,&bb);
    
    for(int i=1;i<=n-aa;i++)
    {
//    	cout<<"sum:"<<(get_(1,1,i,bb+1)*get_(i,bb+1,n,m))%p<<endl;
    	ans+=(get_(1,1,i,bb)*get_(i,bb+1,n,m))%p;
    	ans%=p;
	}
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#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(){
    ll D, N;
    cin >> D >> N;
    ll ans;
    if(N != 100) ans = N;
    else ans = 101;
    rep(i, 0, D){
        ans *= 100;
    }
    cout << ans << endl;
    return 0;
}

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

#define ii pair<int, int>
#define lli long long int
#define ll pair<lli, lli>
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

int h, w, b[85][85], memo[85][85][12800];

int dp(int x, int y, int val) {
	int ret = 1000000000;
	if ((x == h - 1) && (y == w - 1))
		return min(abs(val - b[x][y]), val + b[x][y]);
	if (memo[x][y][val] != -1)
		return memo[x][y][val];
	if (x < h - 1) {
		ret = min(ret, dp(x + 1, y, abs(val - b[x][y])));
		ret = min(ret, dp(x + 1, y, val + b[x][y]));
	}
	if (y < w - 1) {
		ret = min(ret, dp(x, y + 1, abs(val - b[x][y])));
		ret = min(ret, dp(x, y + 1, val + b[x][y]));
	}
	memo[x][y][val] = ret;
	return ret;
}

int main() {
	int a[85][85];
	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			scanf("%d", &a[i][j]);
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			scanf("%d", &b[i][j]);
			b[i][j] = abs(a[i][j] - b[i][j]);
		}
	memset(memo, -1, sizeof memo);
	printf("%d\n", dp(0, 0, 0));
	return 0;
}

Measured memory_bytes: 361600
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll A, B, K;
  cin >> A >> B >> K;

  map<ll, ll> m;
  rep2(i, A, A + K) {
    if (i < A || B < i) continue;
    m[i]++;
  }

  rep2(i, B - K + 1, B + 1) {
    if (i < A || B < i) continue;
    m[i]++;
  }

  for (auto mm : m) {
    COUT(mm.first);
  }
  return 0;
}

Measured memory_bytes: 3660
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, m, c ] <- readInts
	bs <- readInts
	ass <- replicateM n readInts
	print $ length $ filter ( solve bs c ) ass

solve bs c as = 0 < c + sum ( zipWith (*) as bs )

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

int main() {
  long long l, r;
  cin >> l >> r;
  bool check[2019];
  for ( int i = 0; i < 2019; i++ ) { check[i] = false; }
  for ( long long i = l; i <= r; i++ ) {
    int t = i%2019;
    if ( check[t] ) { break; }
    check[t] = true;
  }

  int ans;
  if ( check[0] ) {
    ans = 0;
  } else {
    ans = 2018;
    for ( int i = 1; i < 2018; i++ ) {
      if ( ! check[i] ) { continue; }
      for ( int j = i+1; j < 2019; j++ ) {
        if ( ! check[j] ) { break; }
        ans = min(ans, (i*j)%2019);
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
const int N=15;
int n,m,tot_v,sval[1<<N],fir[N],val[N][N],lg2[1<<N];
int dp[1<<N][N];

namespace utils{
	inline int nxi(FILE *fd=stdin){
		int x=0;
		char c;
		while(((c=fgetc(fd))>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=fgetc(fd));
		while(x=x*10-48+c,(c=fgetc(fd))>='0'&&c<='9');
		return f?-x:x;
	}
	template <class T> inline void apx(T &x,const T y){
		x<y?x=y:0;
	}
	template <class T> inline void apn(T &x,const T y){
		x>y?x=y:0;
	}
}
using namespace utils;

int main(){
	memset(dp,-63,sizeof(dp));
	n=nxi(),m=nxi();
	for(int i=0; i<n; ++i){
		lg2[1<<i]=i;
	}
	for(int i=1; i<=m; ++i){
		const int a=nxi()-1,b=nxi()-1;
		tot_v+=(val[a][b]=val[b][a]=nxi());
	}
	for(int i=1; i<1<<n; ++i){
		int lbit=i&-i,prev=i^lbit;
		sval[i]=sval[prev];
		int x=lg2[lbit];
		for(int j=0; j<n; ++j){
			if(i>>j&1) sval[i]+=val[x][j];
		}
	}
	for(int i=1; i<1<<n; i+=2){
		dp[i][0]=sval[i];
	}
	for(int i=1; i<1<<n; ++i){
		for(int j=0; j<n; ++j){
			if((i>>j&1)==0||dp[i][j]<-1e9) continue;
			for(int k=0; k<n; ++k){
				if(i>>k&1||val[j][k]==0) continue;
				apx(dp[i|1<<k][k],dp[i][j]+val[j][k]);
			}
			for(int k=(i+1)|i; k<1<<n; k=(k+1)|i){
				apx(dp[k][j],dp[i][j]+sval[(k^i)|1<<j]);
			}
		}
	}
	printf("%d\n",tot_v-dp[(1<<n)-1][n-1]);
	return 0;
}


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

int main(){
  int h, w;
  string s;
  int ansi, ansj;
  
  cin >> h >> w;
  for ( int i = 0; i < h; i++ ){
    for ( int j = 0; j < w; j++){
      cin >> s;
      if ( s == "snuke" ){
        ansi = i;
        ansj = j;
      }
    }
  }
  char c = 'A' + ansj;
  cout << c << ansi + 1 << endl;
}

Measured memory_bytes: 256
module.exports=function(e){var r={};function n(t){if(r[t])return r[t].exports;var o=r[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)n.d(t,o,function(r){return e[r]}.bind(null,o));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=0)}([function(e,r,n){n(1)(n(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){var r=e.split("\n"),n=(Number(r[0]),{});r[1].split(" ").map(function(e){var r=Number(e);n[r]||(n[r]=0),n[r]+=1}),Number(r[2]);var t={};for(var o in r[3].split(" ").map(function(e){var r=Number(e);t[r]||(t[r]=0),t[r]+=1}),t)if(!n[o]||t[o]>n[o])return void console.log("NO");console.log("YES")}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 139384
let sum_of_digits n =
  let rec aux n' tmp =
    if n' < 1 then tmp else aux (n' / 10) (tmp + n' mod 10)
  in
  aux n 0

let solve n a b =
  let rec aux i ans =
    if i > n then ans
    else match sum_of_digits i with
      | x when a <= x && x <= b -> aux (i + 1) (ans + i)
      | _ -> aux (i + 1) ans
  in
  aux 1 0

let () = Scanf.scanf "%d %d %d" solve |> Printf.printf "%d\n"

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

using namespace __gnu_pbds;
using namespace std;

template <class T>
using ordered_set =
       tree <T,null_type,less <T>,rb_tree_tag,tree_order_statistics_node_update> ;
///find_by_order()
///order_of_key()

template <class T,class U>
void maximize(T &x,U y){
    if(x < y)x=y;
}
template <class T,class U>
void minimize(T &x,U y){
    if(x > y)x=y;
}
template <class T>
T Abs(T x){
    return (x < (T)0 ? -x : x);
}
template <class T>
T safe_sqrt(T x){
    return sqrt(max(x,(T)0));
}
template <class T,class U,class V>
T addmod(T x,U k,V MOD){
    return ((x+k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T submod(T x,U k,V MOD){
    return ((x-k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T mul(T x,U y,V MOD){
    return ( (x % MOD) * (y % MOD) ) % MOD;
}

#define ll long long
#define pll pair <ll,ll>
#define pii pair <int,int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define emp emplace_back
#define MASK(i) ((1LL)<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)((c).size())
#define fn "test"    ///FILE_NAME_HERE

/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/

namespace task{

	const int N = 3e3 + 2;
	double p[N];
	double f[N][N];
	int n;

    void solve(){
    	cin>>n;
    	for(int i = 1;i <= n;++i){
    		cin>>p[i];
    	}
    	f[1][1] = p[1];
    	f[1][0] = 1.0 - p[1];
    	for(int i = 2;i <= n;++i){
    		for(int j = 0;j <= i;++j){
    			if(j){
    				f[i][j] += f[i - 1][j - 1] * p[i];
    			}
    			f[i][j] += f[i - 1][j] * (1.0 - p[i]); 
    		}
    	}
    	double ans = 0.0;
    	for(int j = 0;j <= n;++j){
    		if((j << 1) > n){
    			ans += f[n][j];
    		}
    	}
    	cout<<setprecision(20)<<fixed<<ans;
    }
}

int main(void){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    task::solve();
}


Measured memory_bytes: 68992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n, x, ways;
		while (true) {
			ways = 0;
			String[] num = in.readLine().split(" ");
			n = Integer.parseInt(num[0]);
			x = Integer.parseInt(num[1]);
			if (n == 0 && x == 0) {
				break;
			}
			for (int i = 1; i <= n; i += 1) {
				for (int j = 1; j <= n; j += 1) {
					for (int k = 1; k <= n; k += 1) {
						if (i == j || j == k || i == k) {
							continue;
						} else if (i + j + k == x) {
							ways++;
						}
					}
				}
			}
			System.out.println(ways / 6);
		}
	}
}

Measured memory_bytes: 19216
#include <bits/stdc++.h>
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    vv<int> left = vvec(N + 1, 3, 0), right = left;
    rep(i, N) {
        rep(j, 3) left[i + 1][j] = left[i][j];
        if (S[i] == 'R') left[i + 1][0]++;
        else if (S[i] == 'G') left[i + 1][1]++;
        else left[i + 1][2]++;
    }
    for (int i = N - 1; i >= 0; --i) {
        rep(j, 3) right[i][j] = right[i + 1][j];
        if (S[i] == 'R') right[i][0]++;
        else if (S[i] == 'G') right[i][1]++;
        else right[i][2]++;
    }

    ll ans = 0;
    rep(i, 1, N - 1) {
        if (S[i] == 'R') {
            ans += left[i][1] * right[i + 1][2];
            ans += left[i][2] * right[i + 1][1];
            for (int j = i - 1, k = i + 1; j >= 0 && k < N; --j, ++k) {
                if (S[j] == 'G' && S[k] == 'B') ans--;
                else if (S[j] == 'B' && S[k] == 'G') ans--;
            }
        }
        else if (S[i] == 'G') {
            ans += left[i][0] * right[i + 1][2];
            ans += left[i][2] * right[i + 1][0];
            for (int j = i - 1, k = i + 1; j >= 0 && k < N; --j, ++k) {
                if (S[j] == 'R' && S[k] == 'B') ans--;
                else if (S[j] == 'B' && S[k] == 'R') ans--;
            }
        }
        else {
            ans += left[i][0] * right[i + 1][1];
            ans += left[i][1] * right[i + 1][0];
            for (int j = i - 1, k = i + 1; j >= 0 && k < N; --j, ++k) {
                if (S[j] == 'R' && S[k] == 'G') ans--;
                else if (S[j] == 'G' && S[k] == 'R') ans--;
            }
        }
    }
    write(ans);
}

Measured memory_bytes: 4052
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-(x)))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd(){static uint seed=416;return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());bool f(false);while(!isdigit(ch)) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch)) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	f&&(x=-x);
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp,typename... Args>Finline _Tp min(const _Tp &a,const _Tp &b,const Args &...args){return a<b?min(a,args...):min(b,args...);}
template <typename _Tp,typename... Args>Finline _Tp max(const _Tp &a,const _Tp &b,const Args &...args){return a<b?max(b,args...):max(a,args...);}
Finline int read_str(char *s)
{
	char ch(getchar());while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;*tar=ch,ch=getchar();while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=505;
int a[N*N],tag[N*N];
int main()
{
	int n;read(n);int x;
	for(int i=1;i<=n;++i) read(x),tag[x]=i;
	for(int i=1;i<=n*n;++i)
	{
		if(tag[i])
		{
			a[i]=tag[i];
			int cnt=tag[i]-1;
			for(int j=1;cnt&&j<i;++j) if(!a[j]) --cnt,a[j]=tag[i];
			if(cnt)
			{
				printf("No\n");
				return 0;
			}
		}
	}
	for(int i=n*n;i>=1;--i)
	{
		if(tag[i])
		{
			int cnt=n-tag[i];
			for(int j=i+1;cnt&&j<=n*n;++j) if(!a[j]) --cnt,a[j]=tag[i];
			if(cnt)
			{
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	for(int i=1;i<=n*n;++i) printf("%d%c",a[i]," \n"[i==n*n]);
	return 0;
}


Measured memory_bytes: 5304
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for ii in range(1, n - 1):
    if (p[ii - 1] < p[ii] and p[ii] < p[ii + 1]) or (p[ii - 1] > p[ii] and p[ii] >p[ii + 1]):
        cnt += 1

print (cnt)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main() {
  long H;
  cin >> H;
  
  long enemy = 1;
  long cnt = 0;
  
  while(H != 0) {
    cnt += enemy;
    H /= 2;
    enemy *= 2;
  }
  
  cout << cnt << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint R; cin >> R;
    if      (R<1200){ cout << "ABC" << endl;
    }else if(R<2800){ cout << "ARC" << endl;
    }else           { cout << "AGC" << endl; }
    
    return 0;
}

Measured memory_bytes: 256
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 1005
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) printf("Case %lld:\n",i)
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,ll>mpp;
map<pair<ll,ll>,bool>mb;
map<ll,bool>mp;
ll itr,n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,ok=0;
bool flag=0;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>adj[MAX+19];
bool visited[MAX+19];
ll start_time[MAX+10],finish_time[MAX+10],deep[MAX+10],parent[MAX+12];
ll dp[MAX][MAX];
char grid[MAX][MAX];
int main()
{
    fast;
    cin>>n;
    FOR(i,n)
    {
        cin>>a;
        v.p_b(a);
    }
    sort(v.begin(),v.end());
    ll x=(n/2);
    cout<<v[x]-v[x-1]<<endl;
    return 0;
}
 /*1 10 9 9
 6 9 9 9
 6 9 9 9
 8 9 9 9
 1 2 5 10 3 4 6 7 8 9
10 4 9 10 3 4 9 7 9 9*/


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

using namespace std;

int main(){
    int h; cin >> h;
    int h_lst[h+0];
    for(int i=0;i<h+0;i++) cin >> h_lst[i];


    for(int i=0;i<h+0;i++){
        cout << "node " << i+1 << ": key = " << h_lst[i] << ", ";
        if(i>0)
            cout << "parent key = " << h_lst[(i-1)/2] << ", ";
        if((2*i+1) < h){
            cout << "left key = " << h_lst[2*i+1] << ", ";
            if((2*i+2) < h)
                cout << "right key = " << h_lst[2*i+2] << ", ";
        }
        cout << endl;

    }

}


Measured memory_bytes: 3104
#include <bits/stdc++.h> 
using namespace std; 
  
bool isPrime(int n) 
{ 
    // Corner case 
    if (n <= 1) 
        return false; 
  
    // Check from 2 to n-1 
    for (int i = 2; i < n; i++) 
        if (n % i == 0) 
            return false; 
  
    return true; 
} 
  
int main() 
{ 
    int x;
    cin >> x;
    
    while (isPrime(x) == false)
	{
		x ++;
	}
    
    cout << x;
    return 0; 
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#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++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct edge {ll from, to, cost;};


// ----------------------------------
// いつでも使える O(|V|x|E|)
// ----------------------------------

int main(){
    // V:頂点 E:辺
    ll V, E, r;
    cin >> V >> E >> r;
    // 最短距離
    vector<ll> d(V, INF);
    // 辺
    vector<edge> es(E);

    rep(i, E){
        int a,b,c;
        cin >> a >> b >> c;
        es.at(i) = (edge){a, b, c};
    }

    fill(d.begin(), d.begin() + V, INF);
    d[r] = 0;
    rep(j, V){
        bool update = false;
        rep(i, E){
            edge e = es.at(i);
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;

                // 負閉路をチェック
                if(j == V-1){
                    cout << "NEGATIVE CYCLE" << endl;
                    return 0;
                }
            }
        }
        if(!update) {
            break;
        }
    }

    
    rep(i, V) {
        if(d[i] == INF) cout << "INF" << endl;
        else cout << d[i]<< endl;
    }
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N,H, n,m , M, K,a;

vector<ll> v;
int main(){
    cin >> N;
    vector<vector<ll>> dp(N+1, vector<ll> (3,0));
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    ll a,b,c;
    for(int i = 1; i <= N; ++i){
        cin >> a >> b >> c;
        dp[i][0] = max(b + dp[i-1][1], c + dp[i-1][2]);
        dp[i][1] = max(a + dp[i-1][0], c + dp[i-1][2]);
        dp[i][2] = max(a + dp[i-1][0], b + dp[i-1][1]);
    }
    cout << max(dp[N][0], max(dp[N][1], dp[N][2]));
    return 0;
}



Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int h,n;
	cin>>h>>n;
	
	vector<pii> vp(n);
	REP(i,n){
		int a,b;
		cin>>a>>b;
		vp[i]=pii(b,a);
	}
	sort(ALL(vp));
	
	vi dp(h+1,INF);
	dp[h]=0;
	for(int i=h;i>0;--i){
		if(dp[i]==INF){}
		else{
			REP(j,n){
				if(i-vp[j].second<0){
					dp[0]=min(dp[0],dp[i]+vp[j].first);
					break;//REP(j).
				}else{
					dp[i-vp[j].second]=min(dp[i-vp[j].second],dp[i]+vp[j].first);
				}
			}
		}
	}
	
	cout<<dp[0]<<endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    ll N,C; cin >> N >> C;
    vector<pair<ll,ll>> sushi(2*N+1);
    sushi[N] = make_pair(0,0);
    FOR(i,1,N+1){
        ll x,v;
        cin >> x >> v;
        sushi[N-i] = make_pair(x,v);
        sushi[2*N+1-i] = make_pair(C-x,v);
    }

    vector<ll> memo_return(2*N+1, 0);
    vector<ll> memo(2*N+1, 0);
    FOR(i,1,N+1){
        memo[N-i] += memo[N-i+1] + sushi[N-i+1].first - sushi[N-i].first + sushi[N-i].second;
        memo[N+i] += memo[N+i-1] + sushi[N+i-1].first - sushi[N+i].first + sushi[N+i].second;
    }
    FOR(i,1,N+1){
        memo[N-i] = max(memo[N-i+1], memo[N-i]);
        memo[N+i] = max(memo[N+i-1], memo[N+i]);
        memo_return[N-i] = max(memo_return[N-i+1], memo[N-i]-sushi[N-i].first);
        memo_return[N+i] = max(memo_return[N+i-1], memo[N+i]-sushi[N+i].first);
    }

    
    ll ans = 0;
    REP(i,N+1){
        ans = max(ans, memo[i]+memo_return[N+i]);
        ans = max(ans, memo_return[i]+memo[N+i]);
    }

    cout << ans << endl;
    return 0;
}

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

int H, W, K;
vector<string> v;
void input() {
  cin >> H >> W >> K;
  v.resize(H);
  for (auto &s : v) { cin >> s; }
}

void solve() {
  int ans = 0;
  for (int h = 0; h < (1 << H); h++) {
    for (int w = 0; w < (1 << W); w++) {
      int cnt = 0;
      rep(i, 0, H) {
        rep(j, 0, W) {
          if (h >> i & 1) continue;
          if (w >> j & 1) continue;
          if (v[i][j] == '#') cnt++;
        }
      }
      if (cnt == K) ans++;
    }
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 3612
x = int(input())
max=round(x**0.5)+1

index=1
maxA=0
while index<max:
    index2=2
    while True:
        if index**index2<=x:
            if index**index2>maxA:
                maxA=index**index2
            index2+=1
            if index==1:
                break
        else:
            break
    index+=1
print(maxA)

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


void dfs(int source, vector<int> adj[], vector<bool> &visited)
{
    visited[source] = true;
    
    for(auto v : adj[source])
    {
        if(!visited[v])
        {
            dfs(v,adj,visited);
        }
    }
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	
	int n = 0,m = 0;
	cin>>n>>m;
	
	vector<int> adj[n+1];
	
	while(m--)
	{
	    int a = 0, b = 0;
	    cin>>a>>b;
	    adj[a].push_back(b);
	    adj[b].push_back(a);
	}
	
	
	vector<bool> visited(n+1, false);
	int components = 0;
	
	for(int i=1;i<=n;i++)
	{
	    if(!visited[i])
	    {
	        components++;
	        dfs(i, adj, visited);
	    }
	}
	
	cout<<components-1<<"\n";
	  
	return 0;
}


Measured memory_bytes: 10004
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, m;
string s, t;
int ans, a, b, c;

signed main() {
	cin >> n >> m >> s >> t;
	ans = lcm(n, m);
	a = ans / m;
	b = ans / n;
	c = n / a;
	rep(i, c) {
		if (s[a*i] != t[b*i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#define neko 200010
#define cmax(a,b) ((a)>(b)?(a):(b))
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~(i)))
int n,ans,t,dgr[neko],head[neko],siz[neko],dp[neko],ansflag;
struct node
{int v,nex;}e[neko<<1];
void add(int x,int y)
{
	e[++t].v=y,e[t].nex=head[x],head[x]=t;
	e[++t].v=x,e[t].nex=head[y],head[y]=t;
}
void dfs(int u,int fa)
{
	//dp[u]=dgr[u]-2<0?0:dgr[u]-2;
	int flag=-1,flag2=0;
	//printf("%d %d\n",u,dp[u]);
	for(register int i=head[u],v=e[i].v;i;i=e[i].nex,v=e[i].v)
	{
		if(v^fa){dfs(v,u),dp[u]+=dp[v];if(!dp[v])++flag;else ++flag2;}
	}
	if(flag>0)dp[u]+=flag;
	if(flag2<2)ansflag=1;
	else ansflag=0;
	if(u==0)if(flag<=0&&ansflag)++dp[u];
	//printf("%d %d\n",u,dp[u]);
}
int main()
{
	int x,y;
	scanf("%d",&n);
	f(i,1,n-1)scanf("%d%d",&x,&y),add(x,y),++dgr[x],++dgr[y];
	dfs(0,0);
	printf("%d\n",dp[0]);
	return 0;
}

Measured memory_bytes: 13568
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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 (b<a) { a=b; return 1; } return 0; }

int N,now,pos;
set<string> city;
bool flag=true;

int main(){
    cin>>N;
    bool d[N];
    string S[N];
    int score[N];
    rep(i,N){
        cin>>S[i]>>score[i];
        d[i]=0;
        city.insert(S[i]);
    }
    for(auto name : city){
        while(true){
            flag=false;
            now=-10;
            rep(i,N){
                if(name==S[i]&&!d[i]){
                    flag=true;
                    if(now<score[i]){
                        pos=i;
                        now=score[i];
                    }
                }
            }
            if(!flag)break;
            out(pos+1);
            d[pos]=1;
        }
        flag=true;
    }

    
    
}


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

int p[25],sib[26],lft[26],rht[26],deg[26],dep[26],hei[26];
string type[26];
int n;

void Search(int,int);//now,prev
void PrintNode();

int main(int argc,char* argv[]){
  int id,left,right,cnt,rnode;
  bool flag[26];
  memset(flag,0,sizeof(flag));
  
  cin>>n;

  for(int i=0;i<n;i++){
    p[i]=-1;
    sib[i]=-1;
    lft[i]=-1;
    rht[i]=-1;
    deg[i]=0;
    dep[i]=0;
    hei[i]=0;
  }
  
  for(int i=0;i<n;i++){
    cin>>id>>left>>right;
    cnt=0;
    
    if(left!=-1){
      cnt++;
      flag[left]=true;
      lft[id]=left;
      if(right!=-1)
	sib[left]=right;
    }
    if(right!=-1){
      cnt++;
      flag[right]=true;
      rht[id]=right;
      if(left!=-1)
	sib[right]=left;
    }

    deg[id]=cnt;
  }

  for(int i=0;i<n;i++)
    if(!flag[i]){
      rnode=i;
      break;
    }

  //探索
  Search(rnode,-1);
  type[rnode]="root";
  
  PrintNode();

  return 0;
}

void Search(int now,int prev){
  int l,r;
  l=r=-1;
  
  if(prev!=-1){
    p[now]=prev;
    dep[now]=dep[prev]+1;
  }

  if(lft[now]==-1 && rht[now]==-1)
    type[now]="leaf";
  else{
    type[now]="internal node";
    if(lft[now]!=-1){
      Search(lft[now],now);
      l=hei[lft[now]];
    }
    if(rht[now]!=-1){
      Search(rht[now],now);
      r=hei[rht[now]];
    }
  }

  hei[now]=max(l,r)+1;
}

void PrintNode(){
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<p[i]<<", sibling = "<<sib[i]<<", degree = "<<deg[i];
    cout<<", depth = "<<dep[i]<<", height = "<<hei[i]<<", "<<type[i]<<endl;
  }
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  // |i-j| = Xi + Xj
  // i < j, Xi + i = j - Xj

  map<ll, ll> m;

  int N; cin >> N;
  ll ans  = 0;

  for(ll i = 0; i < N; i++){
    ll now; cin >> now;
    ans += m[i - now];

    m[i+now]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 26068
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def get_max_min_mod(a, minp, maxp):
    if minp % a == 0:
        minp_new = (minp // a) * a
    else:
        minp_new = (minp // a + 1) * a
    maxp_new = (maxp // a) * a
    return minp_new, maxp_new

def main():
    k = int(input())
    ak = list(map(int, reversed(input().split())))
    assert len(ak) == k
    minp = maxp = 2
    for j in range(k):
        minp, maxp = get_max_min_mod(ak[j], minp, maxp)
        if minp > maxp:
            print(-1)
            sys.exit(0)
        maxp += ak[j] - 1
    print(minp, maxp)

main()


Measured memory_bytes: 14940
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    double x , h;

    while(scanf("%lf%lf",&x,&h),x,h){
        double ans = 0;
        ans += x*x;

        double y;
        y = x/2;

        double a;
        a = hypot(y,h);

        ans += x*a*2;
        printf("%lf\n",ans);
    }

    return 0;
}

Measured memory_bytes: 1080
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d;
	int x, y;

	cin >> a >> b >> c >> d;

	if (a > b) {
		x = b;
	}
	else {
		x = a;
	}

	if (c > d) {
		y = d;
	}
	else {
		y = c;
	}

	cout << x + y << endl;

	return 0;
}

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

int main() {
	int N; cin >> N;
	int a[200010];
	long S=0;
	for(int i=0; i<N; ++i){
	    cin >> a[i];
	    S += a[i];
	}
	long M=abs(a[0]-(S-a[0]));
	long P=a[0];
	for(int i=1; i<N-1; ++i){
	    P += a[i];
	    M=min(M, abs(P-(S-P)));
	}
	cout << M << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,cnt=0;
    cin>>n>>m;
    for(int i=0;;i++){
        n/=m;
        cnt++;
        if(n==0){
            break;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
N, P = map(int, input().split())
S = list(map(int, input()))
ans = 0
if P == 2:
    for i in range(N):
        if S[i]%2 == 0:
            ans +=i+1
    print(ans)

elif P ==5:
    for i in range(N):
        if S[i]%5 == 0:
            ans +=i+1
    print(ans)
else:
    data =[0]*P
    tens = 1
    k = 0
    for i in range(N-1,-1,-1):
        k += S[i] *tens %P
        k = k%P
        data[k] += 1
        tens *=10
        tens %=P

    for i in data:
        ans += i*(i-1)/2
    ans +=data[0]
    print(int(ans))

Measured memory_bytes: 48076
// ABC_061_A
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define forn(i, n) for(int i = 0; i < (int)n; ++i)

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if(a<=c && c<=b) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), M = sc.nextInt();
    int arr[] = new int[M];
    for(int i = 0; i<M; i++){
      arr[i] = sc.nextInt(); 
    }
    Arrays.sort(arr);
    int dif[] = new int[M-1];
    for(int i = 0; i<M-1; i++){
      dif[i] = arr[i+1] - arr[i];
    }
    Arrays.sort(dif);
    int ans = arr[M-1] - arr[0];
    for(int i = M-2; i>M-2-N+1 && i >= 0; i--){
      //System.out.println(dif[i]);
      ans -= dif[i];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 59584
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int a, b;
	cin >> a >> b;

	if ((a + b) % 2 == 0) {
		cout << (a + b) / 2 << endl;
	}
	else {
		cout << (a + b) / 2 + 1 << endl;

	}
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			String type = scanner.nextLine();
			if (type.equals("#")) {
				break;
			}

			int now = 0;// 今いる場所左が-1で右が1で最初は0
			int sum = 0;// 移動回数の合計
			for (int i = 0; i < type.length(); i++) {
				String letter = type.substring(i, i + 1);// 1文字ずつ取り出す
				int position = 0;// 文字が属す側
				if ("qwertasdfgzxcvb".indexOf(letter) != -1) {
					// 取り出した文字が左側に属する時
					position = -1;
				} else {
					// 取り出した文字が右側に属する時
					position = 1;
				}
				if (now != position) {
					now = position;
					sum++;
				}
			}
			System.out.println(sum - 1);// 最初のタイプも移動と見なしているので1回多い

		}

	}

}

Measured memory_bytes: 20108
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(){

    int n;

    cin >> n;

    int l[n];

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

    int max = l[0];
    int maxN = 0;
    int r = 0;

    for(int i=0; i<n; i++){
        if(max < l[i]){
            max = l[i];
            maxN = i;
        }
        r += l[i];
    }

    r -= l[maxN];

    if(r <= max){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    


}

Measured memory_bytes: 256