akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 2005;
string s[MAXN];
ll dp[4][MAXN][MAXN];

void solve(){
    ll H,W; cin>>H>>W;

    FOR(i,1,H){
        cin>>s[i]; s[i] = '{'+s[i];
    }

    FOR(i,1,H){
        FOR(j,1,W){
            if(s[i][j] == '#') continue;

            dp[0][i][j] = 1 + dp[0][i-1][j];
            dp[1][i][j] = 1 + dp[1][i][j-1];
        }
    }

    RFOR(i,1,H){
        RFOR(j,1,W){
            if(s[i][j] == '#') continue;

            dp[2][i][j] = 1 + dp[2][i+1][j];
            dp[3][i][j] = 1 + dp[3][i][j+1];
        }
    }

    ll ans = 0;

    FOR(i,1,H){
        FOR(j,1,W){
            if(s[i][j] == '#') continue;

            ans = max(ans,dp[0][i][j] + dp[1][i][j] + dp[2][i][j] + dp[3][i][j] - 3);
        }
    }

    cout<<ans<<endl;
}       

signed main(){

   FastRead;    

    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}


Measured memory_bytes: 129792
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

import sys

N, M = MI()
ans = ""
num = [[] for _ in range(N)]

for _ in range(M):
    s, c = MI()
    num[s - 1].append(str(c))

    if (N != 1 and (s, c) == (1, 0)) or len(set(num[s - 1])) != 1:
        print(-1)
        sys.exit()

if num[0] == []:
    ans += str(int(N != 1))
else:
    ans += num[0][0]

for n in num[1:]:
    if n == []:
        ans += "0"
        continue
        
    ans += n[0]

print(ans)

Measured memory_bytes: 61948
import sys
import math
import itertools
import numpy
import collections

rl = sys.stdin.readline

n = int(rl())

li = []
for _ in range(n):
    li.append(rl().rstrip())
c = collections.Counter(li)
max_cnt = 0
li = []
for k, v in c.items():
    if v < max_cnt:
        continue
    elif v == max_cnt:
        li.append(k)
    else:
        max_cnt = v
        li = [k]
li.sort()
for i in li:
    print(i)






Measured memory_bytes: 44480
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 1010 , P = 1e9 + 7;
int n , A , B , C , D;
int f[N] , g[N];
int Pow(int x,int t){
    int ret=1;for(;t;t>>=1,x=1ll*x*x%P) if(t&1)ret=1ll*ret*x%P;return ret;
}

void pp(int &x,int d){
    x += d;if(x >= P) x -= P;
}

int a[N]={1},r[N];
int cb(int x,int y){
    return 1ll * a[x] * r[y] % P * r[x-y] % P;
}

int main(){
    rep(i,1,N) a[i] = 1ll * a[i-1] * i % P;
    rep(i,0,N) r[i] = Pow(a[i] , P - 2);
    cin >> n >> A >> B >> C >> D;
    f[0] = 1;
    rep(i,A,B+1){
        for(int j=n;j>=0;--j){
            int cof = Pow(r[i] , C);
            for(int k=C;k<=D && j-k*i>=0;++k,cof = 1ll * cof * r[i] % P)
                pp(f[j] , 1ll * f[j-k*i] * cb(n - j + k * i , k * i) % P * a[k * i] % P * r[k] % P * cof % P);
        }
    }
    printf("%d\n",f[n]);
    return 0;
}


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

int main() {

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll ans=0;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		ans+=x-1;
	}
	cout << ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;

///これでは解けない

int main(int argc, char* argv[])
{
	int N;
	scanf("%d", &N);
	char S[N];
	scanf("%s", S);

	int S_num[N];
	long long len_RGB[3] = {0, 0, 0};

	for(int i=0; i<N; i++){
		if(S[i] == 'R'){
			S_num[i] = 0;
			len_RGB[0]+=1;
		}else if(S[i] == 'G'){
			S_num[i] = 1;
			len_RGB[1]+=1;
		}else{
			S_num[i] = 2;
			len_RGB[2]+=1;
		}
	}
	long long count=0;
	for(int i=0; i<N; i++){
		for(int d=1; d<N; d++){
			int j = i+d;
			int k = j+d;
			if(k > N-1){
				break;
			}
			if(S_num[i]!=S_num[j] && S_num[j]!=S_num[k] && S_num[k]!=S_num[i]){
//				printf("%d %d %d\n", i,j,k);
				count++;

			}
		}
	}
	long long y = len_RGB[0]*len_RGB[1]*len_RGB[2] - count;
	printf("%lld", y);

	return 0;
}





Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int score[100005] = {0};

  int n, k, q;
  cin >> n >> k >> q;

  for (int i = 0; i < q; ++i) {
    int p;
    cin >> p;
    score[p]++;
  }

  for (int i = 1; i <= n; ++i) {
    if ((k+score[i])-q <= 0) {
      cout << "No";
    } else {
      cout << "Yes";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
/*************************************************/
//abc154D
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  int n, k, i, sum=0, max=0;
  scanf(" %d %d", &n, &k);
  int p[n];
  for(i=0; i < n; i++) scanf(" %d", &p[i]);
  for(i=0; i < k; i++) sum+=p[i];
  max=sum;
  for(i=0; i < n - k; i++){
    sum=sum - p[i] + p[k + i];
    if(sum > max) max=sum;
    //printf("sum=%d max=%d\n", sum, max);
  }
  printf("%f", (float)max/2+0.5*k);
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	int A[3], K;
	cin >> A[0] >> A[1] >> A[2] >> K;
	sort(A, A + 3);
	int ans = A[0] + A[1];
	for (int i = 0; i < K; i++) A[2] *= 2;
	ans += A[2];
	cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,t,a;
  cin >> n >> t >> a;
  int x,y,j=100000000,ans;
  for(int i=1; i<=n; i++) {
    cin >> x;
	int y = (t*1000-x*6)-a*1000;
    y = abs(y);
	if(j > y) {
      j = y;
      ans = i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, a[100005], b[100005], c[100005];
ll ans; 
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    rep(i, 0, n) cin >> c[i];
    sort(a, a+n);
    sort(c, c+n);
    rep(i, 0, n) {
        ll a_itr, c_itr;
        a_itr = lower_bound(a, a+n, b[i]) - a;
        c_itr = upper_bound(c, c+n, b[i]) - c;
        ans += (a_itr * (n - c_itr)); 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
	int a[11];	int i,j;
	for(i=1;i<=10;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=9;i++)
		for(j=1;j<=10-i;j++)
		{
			int t;
		
			if(a[j]<a[j+1])
			{
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
		}
     for(i=1;i<=3;i++)
		 printf("%d\n",a[i]);
	 return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (a*b)/gcd(a, b);}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a[3][3];
    for(int i=0;i<3;++i)
        for(int j=0;j<3;++j) cin>>a[i][j];
    int n;
    cin>>n;
    set<int> x;
    for(int i=0;i<n;++i){
        int lol; cin>>lol;
        x.insert(lol);
    }
    for(int i=0;i<3;++i)
    for(int j=0;j<3;++j){
        if(x.find(a[i][j])!=x.end()) a[i][j] = 0;
    }
    for(int i=0; i<3; i++)
    if(a[i][0] == a[i][1] && a[i][0] == a[i][2] || a[0][i] == a[1][i] && a[0][i] == a[2][i]){
        cout<<"Yes"; return 0;
    }
    if(a[0][0] == a[1][1] && a[0][0] == a[2][2] || a[0][2] == a[1][1] && a[0][2] == a[2][0]){
        cout<<"Yes"; return 0;
    }
    cout<<"No";
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		if(i%2==0)
			if(a[i]%2==1)
				cnt++;
	}
	cout << cnt << endl;





}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, M;
  cin >> N >> M;
  int flag = 0;
  if(abs(N - M) == 0 || abs(N - M) == 1) flag++;
  long ans = 0, a = 1, b = 1;
  if(flag == 1) {
    for(int i = N; i != 0; i--) {
      a *= i;
      a %= 1000000007;
    }
    for(int i = M; i != 0; i--) {
      b *= i;
      b %= 1000000007;
    }
    if (abs(N - M) == 0) a *= 2;
    ans = (a * b) % 1000000007;
    
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int ac = 0, wa = 0, tle = 0, re = 0;
        int n = in.nextInt();
        String[] arr = new String[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.next();
        }
        for (String arr1 : arr) {
            if (arr1.contains("AC")) {
                ac++;
            } else if (arr1.contains("WA")) {
                wa++;
            } else if (arr1.contains("TLE")) {
                tle++;
            } else if (arr1.contains("RE")) {
                re++;
            }
        }
        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);

    }
}

Measured memory_bytes: 64304
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
map<int, int> vis, mp;
int fa[N], a[N], b[N];

int find(int now) { return fa[now] == now ? now : fa[now] = find(fa[now]); }

int main()
{
//	#ifndef ONLINE_JUDGE
//	freopen("duliu.in", "r", stdin);
//	freopen("duliu.out", "w", stdout);
//	#endif
	int n, t = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i), vis[a[i]]++, t ^= a[i];
	vis[a[n + 1] = t]++; t = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", b + i), vis[b[i]]--, t ^= b[i];
		if (vis[b[i]] < 0) return puts("-1"), 0;
	}
	vis[b[n + 1] = t]--; if (vis[t] < 0) return puts("-1"), 0;
	int cnt = 0, lop = 0, all = 0;
	for (int i = 1; i <= n + 1; i++) if (a[i] != b[i])
	{
		all++;
		if (!mp.count(a[i])) mp[a[i]] = ++cnt, fa[cnt] = cnt;
	}
	for (int i = 1; i <= n + 1; i++) if (a[i] != b[i]) fa[find(mp[a[i]])] = find(mp[b[i]]);
	for (int i = 1; i <= cnt; i++) if (fa[i] == i) lop++;
	int ans = all + lop;
	if (a[n + 1] != b[n + 1]) ans -= 2;
	else if (mp.count(a[n + 1])) ans--;
	cout << ans << endl;
//	#ifndef ONLINE_JUDGE
//	fclose(stdin);
//	fclose(stdout);
//	#endif
	return 0;
}

Measured memory_bytes: 12416
#include <functional>
#include <random>
#include <cassert>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;

long long L1(long long a, long long b, long long c, long long d) {
    return abs(a - c) + abs(b - d);
}

long long L1(pair<long long, long long> p, pair<long long, long long> q) {
    return L1(p.first, p.second, q.first, q.second);
}

bool check(int x, int y, int k, vector<pair<int, int> > &ans) {
    for (int i = 0; i < ans.size(); i++) {
        auto prev = i > 0 ? ans[i-1] : make_pair(0, 0);
        if (L1(prev, ans[i]) != k) return false;
    }
    return ans.back() == make_pair(x, y);
}

vector<pair<int, int> > construct(int x, int y, long long k) {
    vector<pair<int, int> > ans;
    int a = 0, b = 0;
    while (L1(a, b, x, y) > 2 * k) {
        if (a + k <= x) a += k;
        else if (a < x) {
            b += k - (x - a);
            a = x;
        } else {
            b += k;
        }
        ans.emplace_back(a, b);
    }

    if (L1(a, b, x, y) % 2 == 1) {
        assert (L1(a, b, x, y) % 2 == 1);
        if (x - a > y - b) a += k;
        else b += k;
        ans.emplace_back(a, b);
    }

    function<pair<int, int>(long long)> getpoint = [&](long long i) {
        long long q = i / k, r = i % k;
        switch (q) {
        case 0: return make_pair(a + k - r, b + r);
        case 1: return make_pair(a - r, b + k - r);
        case 2: return make_pair(a - k + r, b - r);
        case 3: return make_pair(a + r, b - k + r);
        default: assert(false);
        }
    };
    function<int(long long)> dist = [&](long long i) {
        return L1(getpoint(i), {x, y});
    };
    long long lb = -1, ub = -1;
    for (int i = 0; i < 4; i++) {
        if (dist(i * k) > k) ub = i * k;
        else lb = i * k;
    }
    assert(lb >= 0);
    assert(ub >= 0);
    while (abs(lb - ub) > 1) {
        long long m = (lb + ub) / 2;
        if (dist(m) > k) ub = m;
        else lb = m;
    }
    ans.emplace_back(getpoint(lb));
    ans.emplace_back(x, y);
    return ans;
}

int main() {
    int k, x, y; cin >> k >> x >> y;
    const int d = abs(x) + abs(y);
    if (k % 2 == 0 && d % 2 == 1) {
        cout << "-1\n";
        return 0;
    }
    if (L1(0, 0, x, y) == k) {
        cout << "1\n" << x << " " << y << endl;
        return 0;
    }
    bool negx = x < 0, negy = y < 0;
    x = abs(x); y = abs(y);
    vector<pair<int, int> > ans = construct(x, y, k);
    cout << ans.size() << endl;
    for (auto [a, b] : ans)
        cout << (negx ? -a : a) << " " << (negy ? -b : b) << endl;
    assert(check(x, y, k, ans));
}


Measured memory_bytes: 4768
import Data.List

solve n k = foldl' step (0.0) [1..n]
    where
        step acc x
            | x >= k = acc + base
            | otherwise = acc + (base * additional)
                where
                    base = 1 / (fromIntegral n)
                    additional = 1 / (fromIntegral (2 ^ (f k x)))
        f aim v
            | v >= aim = 0
            | otherwise = 1 + f aim (v*2)

main = do
    [n,k] <- map read . words <$> getLine :: IO [Int]
    print $ solve n k

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int n,a[1000005],vst[1000005],cnt[1000005];
vector<int> vec[1000005];
int main() {
	scanf("%d",&n);
	int gcd;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(i==1)gcd=a[i];
		else gcd=__gcd(gcd,a[i]);
	}
	if(gcd>1)return printf("not coprime"),0;
	for(int i=2;i<=1000000;i++){
		if(vst[i])continue;
		for(int j=i;j<=1000000;j+=i)vec[j].push_back(i),vst[j]=1;
	}
	for(int i=1;i<=n;i++){
		for(int j:vec[a[i]]){
			cnt[j]++;
			if(cnt[j]>1)return printf("setwise coprime"),0;
		}
	}
	printf("pairwise coprime");
	return 0;
}

Measured memory_bytes: 67340
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	rep(i, n)
	{
		int h;
		cin >> h;
		ans += h >= k ? 1 : 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}

int n;
int memo[10000000];

int fib(int i){
    if(i <= 1) return i;
    if(memo[i] != 0) return memo[i];
    return memo[i] = fib(i-1)+fib(i-2);
}

ll dig(ll n){
    ll d = 0;
    while(n != 0){
        n/=10;
        d++;
    }
    return d;
}

void solve() {
    ll n,k,x,y;
    cin >> n >> k >> x >> y;
    ll p;
    if(n > k) p = n-k;
    cout << min(n,k)*x+p*y << endl;
}


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}


Measured memory_bytes: 256
use std::cmp::max;
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//usage
//input! {
//  h: i32;
//  v: [i32; n]
//  x: [[i32; n]; m]
//  f: chars <- Vec<char>
//}

fn main() {
    input!(n: i32, d: [(i32, i32, i32); n]);
    let mut dp_table = Vec::new();
    for _ in 0..n {
        dp_table.push([0, 0, 0]);
    }
    dp_table[0][0] = d[0].0;
    dp_table[0][1] = d[0].1;
    dp_table[0][2] = d[0].2;

    for i in 1..n {
        dp_table[i as usize][0] = max(dp_table[(i - 1) as usize][1], dp_table[(i - 1) as usize][2]) + d[i as usize].0;
        dp_table[i as usize][1] = max(dp_table[(i - 1) as usize][0], dp_table[(i - 1) as usize][2]) + d[i as usize].1;
        dp_table[i as usize][2] = max(dp_table[(i - 1) as usize][0], dp_table[(i - 1) as usize][1]) + d[i as usize].2;

    }
    println!("{}", max(dp_table[(n - 1) as usize][0], max(dp_table[(n - 1) as usize][1], dp_table[(n - 1) as usize][2])));
}

Measured memory_bytes: 6396
#include <iostream>
using namespace std;
signed main(){
    long long n , ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        if(i%5 > 0 && i%3 > 0){
            ans+=i;
        }
    }
    cout<<ans<<endl;
    return(0);
}


Measured memory_bytes: 3624
#include<iostream>    //I
#include<cstdio>
#include<map>
#include<string>
#include<list>
#include<vector>
#include<cstring>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<set>
#include<functional>
using namespace std; 
typedef long long  ll;
const ll maxn=1e5+5;
struct node{
	int mon;
	int a[15];
}book[15];
int m,n,x;
int b[15];
int main(){
	cin>>n>>m>>x;
	for(int i=0;i<n;i++){
		cin>>book[i].mon;
		for(int j=0;j<m;j++){
			cin>>book[i].a[j];
		}
	}
	int ans=2e9;
	for(int i=0;i<(1<<n);i++){
		memset(b,0,sizeof(b));
		int sum=0;
		for(int j=0;j<n;j++){
			if(i>>j&1){
				sum+=book[j].mon;
				for(int k=0;k<m;k++) b[k]+=book[j].a[k];
			}
		}
		bool flag=1;
		for(int j=0;j<m;j++) if(b[j]<x) flag=0;
		if(flag) ans=min(ans,sum);
	}
	if(ans==2e9) cout<<"-1\n";
	else cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 3508
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int k, a, b;
    cin >> k >> a >> b;
    if (b > a + 2) {
        int ans = 1;
        int tmp = min(k, a - 1);
        ans += tmp;
        k -= tmp;
        tmp = k / 2;
        ans += tmp * (b - a);
        k %= 2;
        ans += k;
        cout << ans << "\n";
    } else {
        cout << 1 + k << "\n";
    }
}

Measured memory_bytes: 256
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    l = [[0]*10 for i in range(10)]
    for i in range(1,n+1):
        s = str(i)
        head = int(s[0])
        tail = int(s[-1])
        l[head][tail] += 1
    ans = 0

    for i in range(1,10):
        for j in range(i,10):
            if i == j:
                ans += l[i][j]**2
            else:
                one = l[i][j]
                two = l[j][i]
                ans += one*two*2
    print(ans)



if __name__=="__main__":
    main()


Measured memory_bytes: 73936
#include<bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision;
// #define int cpp_int
using namespace std;

#define fastio 			ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int 			long long
#define ll 				long long
#define ld 				long double
#define vi 				vector<int>
#define pii 			pair<int,int>
#define vpii 			vector< pair<int,int> >
#define uset			unordered_set
#define umap 			unordered_map
#define maxpq 			priority_queue<int>
#define minpq			priority_queue<int,vi,greater<int>()>

#define all(v) 			v.begin(),v.end()
#define part(v,s,e)		v.begin()+s,v.begin()+e
#define rev(v)			reverse(v.begin(),v.end())
#define sz(x)			(int)x.size()
#define def(v)			memset(v,-1,sizeof(v));
#define def0(v)			memset(v,0,sizeof(v));
#define minv(a)			*min_element(all(a))
#define maxv(a)			*max_element(all(a))
#define sumv(a)			accumulate(all(a),0)

#define	lb				lower_bound
#define	ub				upper_bound
#define	desc			greater<int>()
#define	pb				emplace_back
#define	mp				make_pair
#define	F				first
#define	S				second

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";

#define gcd(a,b)		__gcd(a,b)
#define lcm(a,b)		(a/(__gcd(a,b)))*b

#define setbits(x) 		__builtin_popcountll(x)
#define zerobits(x)		__builtin_ctzll(x)

#define ip(v)	 		for(auto& i:v)	cin>>i;
#define op(v) 			for(auto i:v)	cout<<i<<" ";cout<<endl;
#define deb(x) 			cout <<"Value of " #x << " : " << x << endl;


void solve()
{	

	int a,b;
	cin>>a>>b;
	b--;
	int ans=ceil(double(b)/(double)(a-1.0));
	cout<<ans<<endl;

}	

int32_t main()
{

	fastio
	cout<<setprecision(15)<<fixed;


	int t=1;
	// cin>>t;
	
	for(int i=1;i<=t;i++)
	{
		// cout<<"Case "<<i<<" : "<<endl;
		solve();
	}
	
	#ifndef ONLINE_JUDGE	
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	#endif

	return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

struct table{
    int s,t,c;
};

bool tablefight( table a , table b ){
    // if( a.c != b.c )
    //     return a.c < b.c;
    return a.t < b.t;
    return a.s < b.s;
}

int main() {

    int N,C;
    Scd2(N,C);
    vector< table > q(N);
    int a,b,c;
    Rep(i,N){
        Scd3(a,b,c);
        q[i] = {a,b,c};
    }
    // いもす法 「S、Tが小さいので十分間に合う」

    vector<int> tt(200002);
    vector<int> mt(200002);

    Repe(i,C+1,1){
        Rep(j,200002) tt[j] = 0;
        Rep(j,N) if(q[j].c==i) tt[q[j].s*2-1]++ , tt[q[j].t*2]--;
        Rep(j,200001) tt[j+1] += tt[j];
        Rep(j,200002) if( tt[j]>0 ) mt[j]++;
    }

    int ans = 0;
    Rep(i,200002) ans = max(mt[i],ans);
    printf ("%d\n", ans );


    return 0;
}



Measured memory_bytes: 2944
A,B,K=list(map(int,input().split()))
L=[]
k=0
for i in range(A,B+1):
    L.append(i)
    k+=1
    if(k>=K):
        break

k=0
for i in range(B,A-1,-1):
    L.append(i)
    k+=1
    if(k>=K):
        break

S=set(L)
for s in sorted(list(S)):
    print(s)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main (void){
    char str[11];
    scanf("%s",str);

  	int i;
    int length = 0;
    int length_max = 0;
    for(i=0;i<strlen(str);i++){
        if(str[i] != 'A' &&
            str[i] != 'C' &&
            str[i] != 'G' &&
            str[i] != 'T'){
              length = 0;  
        }else{
            length++;
            if(length >length_max){
                length_max = length;
            }
        }
    }
    printf("%d",length_max);
    
}

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

int main(){
    string s; cin >> s;
    string tmp="", left="", right="";
    int ans = 0;
    int n = s.length();
    for(int i=1; i<n; i++){
        tmp = s.substr(0, n-i);
        if(tmp.length()%2 != 0){
            continue;
        }else{
            int t_len = tmp.length();
            left = tmp.substr(0, t_len/2);
            right = tmp.substr(t_len/2, t_len/2);
            if(left == right){
                ans = t_len;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 3628
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

// vars
int x, y, z;
void input(){
    cin >> x >> y >> z;
}

void solve(){
    cout << z << " " << x << " " << y << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f first
#define int long long
#define INTMAX 1e15+5
#define mp make_pair
#define N 1000005
#define pb push_back
#define pencho ios_base::sync_with_stdio(false);cin.tie(NULL);
#define s second
/*STL:
       (1) PRIORITY_QUEUE pq:
       -> priority_queue < int > pq; // max_heap
       -> priority_queue < int , vector < int > , greater < int > > pq; // min_heap
       -> pq.top()   --> returns the maximum or minimum element
       -> pq.push()  --> push element into the queue
       -> pq.pop()   --> remove top most element
       -> pq.empty() --> checks whether queue is empty or not

       (2) set / multiset  ss;
       --> ss.insert(key); (insertion)
       --> ss.erase(ss.find(key)) .. (deletion)
       --> ss.find(key) != ss.end() ..existence check
       --> ss.lower_bound(x) -> smallest value which is greater than or equals to x
       --> ss.upper_bound(x) --> first value strictly greater than x
       --> multiset< data_type , greater<data_type> > ms; // for max ordering

       (3) common functions
       lower_bound(v.begin(),v.end(),x) - v.begin() --> smallest value greater than or equals to x
       upper_bound(v.begin(), v.end(),x)- v.begin() --> smallest value greater than x
       memset(dp , val , sizeof(dp)) -> sets the value of array dp to val

       (4)    Comparator for set
                     struct comp {
                            bool operator()(pair<int, int>a, pair<int, int>b) {
                     };
};
*/
int mod = 1000000007;
int bp(int x, int y) {int ans = 1; x %= mod; while (y) {if (y & 1) ans = ans * x % mod; x = x * x % mod; y >>= 1;} return ans;}
int mod_inverse(int x) {return bp(x, mod - 2); }
int gcd (int a, int b) { while (b) {a %= b; swap(a, b);} return a;}
int max(int a, int b) {     if (a < b)    swap(a, b);   return a;}
int min(int a, int b) { if (a > b) swap(a, b); return a;}
int countSetBits(int n) {int count = 0; while (n) {count += n & 1; n >>= 1;} return count;}



void solve() {
       int n, k;  cin >> n >> k;
       int h[n], dp[n];
       for (int i = 0; i < n; i++)  cin >> h[i], dp[i] = INTMAX;
       dp[0] = 0;
       for (int i = 0; i < n - 1; i++) {
              for (int j = i + 1; j < min(n, i + k + 1); j++)
                     dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
       }
       cout << dp[n - 1] << endl;
}




signed main()
{
#ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("o.txt", "w", stdout);
#endif

       solve();
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

template<class T>
class Union_Find {
private:
  T n;
  vector<T> parent;
public:
  Union_Find(T v){
    n=v;
    parent.resize(n,-1);
  }
  T root(T v){
    if(parent[v]<0)return v;
    return parent[v]=root(parent[v]);
  }
  T size(T v){
    return -parent[root(v)];
  }
  bool connect(T a,T b){
    a=root(a);
    b=root(b);
    if(a==b)return false;
    if(size(a)<size(b)) swap(a,b);
    parent[a]+=parent[b];
    parent[b]=a;
    return true;
  }
  bool same(T a,T b){
    return root(a)==root(b);
  }
  T operator[](T a){
    return root(a);
  }
  bool operator()(T a,T b){
    return connect(a,b);
  }
};

int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,m,k;
  cin>>n>>m>>k;
  vector<vector<int>> adj(n);
  Union_Find<int> uni(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    adj[a].emplace_back(b);
    adj[b].emplace_back(a);
    uni(a,b);
  }
  rep(i,k){
    int c,d;
    cin>>c>>d;
    c--;d--;
    if(!uni.same(c,d))continue;
    adj[c].emplace_back(d);
    adj[d].emplace_back(c);
  }
  rep(i,n){
    int ans = uni.size(i)-1;
    ans -= adj[i].size();
    cout<<ans<<" ";
  }
  cout<<endl;


}

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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

const int N = 23;

int n,a[N][N],dp[N][1<<N],mod=1e9+7;
vector <int> v[N];

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            scanf("%d",&a[i][j]);

    for(int i=0;i<(1<<n);i++)
    {
        dp[n][i] = 1;
        v[__builtin_popcount(i)].push_back(i);
    }

    for(int i=n-1;i>=0;i--)
        for(auto j:v[i])
            for(int k=0;k<n;k++)
                if( !(j&(1<<k)) && a[i][k] )
                    dp[i][j] = ( dp[i+1][j|(1<<k)] + dp[i][j] )%mod;

    printf("%d\n",dp[0][0]);
}


Measured memory_bytes: 111032
class UnionFind
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end
end

n, m = gets.chomp.split().map(&:to_i)

hen = Array.new(m)
m.times do |i|
  hen[i] = gets.chomp.split().map(&:to_i)
end

ans = 0
m.times do |i|
  uf = UnionFind.new(n+1)

  hen_minus = hen.dup
  hen_minus.delete_at(i)
  hen_minus.each do |a,b|
    uf.unite(a,b)
  end

  flg = false
  1.upto(n-1).each do |j|
    (j+1).upto(n).each do |k|
      if !uf.same_parent?(j,k)
        ans += 1
        flg = true
        break
      end
    end
    break if flg
  end
end

puts ans


Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

    long long int a[n];
    int num[n];

    for (int i = 0; i < n; i++) {
        num[i] = 0;
    }

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

    long long int ans = 0;
    bool ok = true;
    if (n % 2 == 0) {
        if (num[0] == 0) {
            for (long long int i = 1; i < n; i += 2) {
                if (num[i] != 2) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                ans = 1;
                for (long long int i = 0; i < n / 2; i++) {
                    ans *= 2;
                    ans %= 1000000007;
                }
            } else { ans = 0; }
        }
    } else {
        if (num[0] == 1) {
            for (long long int i = 2; i < n; i += 2) {
                if (num[i] != 2) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                ans = 1;
                for (long long int i = 0; i < (n - 1) / 2; i++) {
                    ans *= 2;
                    ans %= 1000000007;
                }
            } else { ans = 0; }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int V,E;
int s[1000],t[1000];


bool check(int start){
  int flag[100];
  for(int i=0;i<V;i++){
    flag[i]=0;
  }
  
  flag[start]=1;
  for(int a=0;a<V;a++){
    for(int i=0;i<E;i++){
      int from=s[i];
      int to=t[i];
      if(flag[from] > 0){
        flag[to]++;
      }
    }
  }
  if(flag[start]>1)return true;
  else return false;
}

int main(){
  cin>>V>>E;
  for(int i=0;i<E;i++){
    cin>>s[i]>>t[i];
  }
  int ans=0;
  for(int i=0;i<V;i++){
    if( check(i) ){
      ans=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3128
N,P=map(int,input().split())
S=[int(i) for i in list(input())][::-1]
if P==2 or P==5:
    ans=0
    for i in range(N):
        if S[i]%P==0:
            ans+=N-i
    print(ans)
else:   
    X=[0 for i in range(N+1)]
    tmp=1
    for i in range(N):
        X[i+1]=X[i]+tmp*S[i]
        X[i+1]%=P
        tmp=tmp*10
        tmp%=P
    #print(X)
    D=dict()
    for i in range(N+1):
        if X[i] in D:
            D[X[i]]+=1
        else:
            D[X[i]]=1
    ans=0
    for k in D:
        ans+=(D[k]*(D[k]-1))//2
    #print(D)
    print(ans)


Measured memory_bytes: 13032
#include <stdio.h>

int main(void){
	int n, a;
	int min = 1000001;
	int max = -1000001;
	char str[100000], *ch;
	long long sum = 0;
	scanf("%d\n", &n);
	
	for (int i = 1; i <= n; i++) {
		scanf("%d ", &a);
		if (a < min) min = a;
		if (a > max) max = a;
		sum += a;
	}

	printf("%d %d %lld\n", min, max, sum);
	return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    int A[N], B[N - 1];
    rep(i, N - 1) cin >> B[i];

    A[N - 1] = B[N - 2];

    for (int i = N - 2; i >= 1; i--) {
        A[i] = min(B[i], B[i - 1]);
    }
    A[0] = B[0];

    int ans = 0;
    rep(i, N) ans += A[i];

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

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

int main(){
    int L,R,d; cin>>L>>R>>d;

    int ans=0;
    rep(i,L,R+1){
        if(i%d==0) ans++;
    }
    cout<<ans<<endl;
}

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

class Main{
	public static void main(String args[]) {

		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";
		int[] syugo;
		int youso_kazu;

		try {
			str=bfr.readLine();
			youso_kazu=Integer.parseInt(str);
			syugo=new int[youso_kazu];

			for(int i=0; i<youso_kazu; i++) {
				str=bfr.readLine();
				syugo[i]=Integer.parseInt(str);
			}

			int[] rank=new int[3];
			for(int i=0; i<3; i++) {
				rank[i]=2000000000;
			}
			int kekka=0;
			String combine="";
			int tmp1,tmp2=0;
			for(int i=0; i<youso_kazu; i++) {
				for(int j=0; j<youso_kazu; j++) {

					if(i==j) {
						// 何もしない
					}
					else {
						combine=String.valueOf(syugo[i])+String.valueOf(syugo[j]);
						kekka=Integer.parseInt(String.valueOf(combine));

						if(kekka<=rank[0] && kekka<=rank[1] && kekka<=rank[2]) {
							tmp1=rank[0];
							tmp2=rank[1];
							rank[1]=tmp1;
							rank[2]=tmp2;
							rank[0]=kekka;
						}

						else if(kekka>rank[0] && kekka<=rank[1] && kekka<=rank[2]) {
							tmp1=rank[1];
							tmp2=rank[2];
							rank[2]=tmp1;
							rank[1]=kekka;
						}

						if(kekka>rank[0] && kekka>rank[1] && kekka<=rank[2]) {
							rank[2]=kekka;
						}
					}
				}
			}
			System.out.println(rank[2]);

			if(str=="") {
				System.exit(0);
			}
		}catch(IOException e) {

		}
	}
}


Measured memory_bytes: 434880
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int age = Integer.parseInt(sc.next());

		String s = (age == 3) || (age == 5) || (age == 7) ? "YES" : "NO";

		System.out.println(s);
		sc.close();
	}
}

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

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  int h, w;
  cin >> h >> w;
  rep(i,h){
    string s;
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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

ll a[201000];
ll s[201000];
unordered_map<ll, ll> mp;

int main(){
    ll N, K;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    s[0] = (a[0]-1) % K;
    for(int i = 1; i < N; i++){
        s[i] = (a[i] + s[i-1] + K * N - 1) % K;
    }
    for(int i = 0; i < min(N, K-1); i++){
        if(mp.find(s[i]) == mp.end()){
            mp[s[i] % K] = 1;
        }
        else{
            mp[s[i] % K]++;
        }
    }

    ll res = 0;
    ll index = 0;
    for(int i = 0; i < N; i++){
        res += mp[index];
//        cout << i << " " << mp[index] << " " << index << endl;
        mp[s[i]]--;
        if(i + K-1 < N){
            if(mp.find(s[i+K-1] % K) == mp.end()){
                mp[s[i+K-1] % K] = 1;
            }
            else{
                mp[s[i+K-1] % K]++;
            }
        }
        index = (s[i]) % K;
    }

    cout << res << endl;


    return 0;
}




Measured memory_bytes: 11592