akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
typedef long long ll;
//const int maxn=1e9;
const int maxn=4e5+10;
int main()
{
    string s;
    cin>>s;
    int q;
	cin>>q;
    vector<char> v1,v2;
    int x=0;
    while(q--){
        int t;cin>>t;
        if(t==1)x^=1;
        else{
            int f;
            char c;
            cin>>f>>c;
            if(f==1){
                if(!x)v1.pb(c);
                else v2.pb(c);
            }
            else{
                if(!x)v2.pb(c);
                else v1.pb(c);
            }
        }
    }
    if(!x){
        for(int i=v1.size()-1;i>=0;i--)
            cout<<v1[i];
        cout<<s;
        for(auto c:v2)cout<<c;
    }
    else{
        for(int i=v2.size()-1;i>=0;i--)
            cout<<v2[i];
        reverse(all(s));
        cout<<s;
        for(auto c:v1)cout<<c;
    }
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <ctype.h>

int main()
{
    char ch;
    int i, count[26] = {};
    
    while(scanf("%c", &ch) != EOF){
        ch = tolower(ch);
        if ('a' <= ch && ch <= 'z') count[ch - 'a']++;
    }
    for (i = 0; i < 26; i++)
        printf("%c : %d\n", 'a' + i, count[i]);
    
    return 0;
}

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

int main() {
	ll n,k;
	cin>>n>>k;
	vector<ll>ch;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		ch.push_back(x);
	}
	sort(ch.begin(),ch.end());
	ll left = 1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll right =10000000005; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    ll zan=0;
    while (right - left > 1) {
        ll mid = left + (right - left) / 2;
        ll cnt=0;
        for(ll i=0;i<n;i++){
        	ll now=ch[i];
        	ll ser=mid-now;
        	auto itr=lower_bound(ch.begin(),ch.end(),ser);
        	ll dx=itr-ch.begin();
        	cnt+=n-dx;
        }
        if (cnt<=k) right = mid;
        else left = mid;
        if(k-cnt>=0){
        zan=k-cnt;
        }
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
 //   cout << right<<endl;
    ll ans=(right-1)*zan;
    ll ch2[100010]={};
    for(ll i=n-1;i>=0;i--){
    	ch2[i]=ch2[i+1]+ch[i];
  // 	cout << ch2[i]<<endl;
    }
    for(ll i=n-1;i>=0;i--){
    	ll now=ch[i];
    	ll ser=right-now;
    	auto itr=lower_bound(ch.begin(),ch.end(),ser);
    	ll dx=itr-ch.begin();
  //  	cout << dx<<endl;
    	if(n-dx>0){
    		ans+=(n-dx)*now+ch2[dx];
    	}
    }
//    cout <<zan<<endl;
    cout <<ans;
	// your code goes here
	return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, b[5];
string s[100000], m = "MARCH";


int main() {
	cin >> n;
	inc(i, n) { cin >> s[i]; }
	
	inc(i, n) {
	inc(j, 5) {
		if(s[i][0] == m[j]) { b[j]++; }
	}
	}
	
	LL ans = 0;
	inc(i, 5) {
	inc(j, i) {
	inc(k, j) {
		ans += b[i] * b[j] * b[k];
	}
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 6144
C = [0] * 3
A = [0] * 3
B = [0] * 3
# a_0=0と考える
for j in range(3):
    C[j] = [int(x) for x in input().split()]
#print(C)
B[0], B[1], B[2] = C[0][0], C[0][1], C[0][2]
A[1], A[2] = C[1][0]-B[0], C[2][0]-B[0]
flag = 0
for i in range(3):
    for k in range(3):
        if C[i][k] != A[i] + B[k]:
            flag = 1
            break
if flag == 1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define rep(i, a, b) for(__typeof(a) i = a;i < b;i++)
#define repo(i, a, b) for(__typeof(a) i = a;i<=b;i++)
#define REPITER(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define eps 1e-6
#define pi 3.141592653589793
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ca(a) cout << a << "\n";
#define a(a) for(auto i:a) cout << i << " ";
using namespace std;
template<class T> inline T gcd(T a, T b) { while(b) b ^= a ^= b ^= a %= b; return a; }
template<class T> inline T mod(T x) { if(x < 0) return -x; else return x; }
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII > PPII;
typedef vector< PII > VPII;
typedef vector< PPII > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main(){
     
     ll n;
     cin>>n;
     priority_queue<double,vector<double>,greater<double> > q;
     double x;
     rep(i,0,n){
         cin>>x;
         q.push(x);
     }
     rep(i,0,n-1){
         double x=q.top();
         q.pop();
         double y=q.top();
         q.pop();
         q.push((x+y)/2);
     }
     ca(q.top());
    return 0;
}

Measured memory_bytes: 256
n=int(input())
t_l,x_l,y_l=[0],[0],[0]
for i in range(n):
    t,x,y=map(int,input().split())
    t_l.append(t)
    x_l.append(x)
    y_l.append(y)

for i in range(n):
    a = (t_l[i+1]-t_l[i]) - (abs(x_l[i+1]-x_l[i]) + abs(y_l[i+1]-y_l[i]))
    if a<0 or a%2!=0:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 11820
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define MOD 1000000007;

int main(){
  ll n,k,ans=MOD;cin>>n>>k;
  vll h(n);
  rep(i,0,n){
    cin>>h[i];
  }
  sort(h.begin(),h.end());
  rep(i,0,n-k+1){
    ans=min(ans,h[i+k-1]-h[i]);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
int n[100];
int i,j,s,t,x,z;
int sum=0;


i=0;
do{
scanf("%d",&n[i]);
i++;
}while(n[i-1]!=0);

for(i=0;n[i]!=0;i++){
	s=n[i];
	t=n[i]/10+1;
	z=0;
		for(j=1;j<t;j++){
			if(s%j==0) sum+=j;
		}
		for(j=2;j<10;j++){
			if(s%j==0){
				x=s/j;
				if(s%x==0) sum+=x;
			}
		}
    if(sum==n[i]) printf("perfect number\n");
    else if(sum>n[i]) printf("abundant number\n");
    else if(sum<n[i]) printf("deficient number\n");
    sum=0;
}

return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
v fact(3e6+1,1);
int ncr(int n,int r)
{
    // cout<<
    return MOD(power(MOD(fact[n-r]*fact[r]),mod-2,mod)*fact[n]);
}
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int k;cin>>k;
    string s;cin>>s;
    int l=sz(s);
    int N=l+k;
    for(int i=1;i<=3e6;i++)
        {
            fact[i]=MOD(fact[i-1]*i);
        }
        int ans=0;
    for(int i=l;i<=N;i++)
    {
        ans+=MOD(power(25,N-i,mod)*ncr(N,i));
        ans=MOD(ans);
    }
    cout<<ans<<endl;
    // int n=sz(s);
    // int N=n+k;
    // vv dp(N+1,v(n+1,0));
    // dp[N][n]=1;

    // for(int i=N-1;i>=0;i--)
    // {

    //     dp[i][n]=power(26,N-i,mod);
    //     for(int j=0;j<n;j++)
    //     {
    //         dp[i][j]=MOD(dp[i+1][j+1]+dp[i+1][j]*25);
    //     }
    // }
    // cout<<dp[0][0]<<endl;
    return 0;
}

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

typedef long long ll;

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

    vector <int> A(N);
    bool even = false;
    bool res = true;

    if(N % 2 == 0){
        even = true;
    }

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

    sort(A.begin(),A.end());
    
    for(int i=0;i<N;i+=2){
        if(!even){
            if(i == 0 && A[0] != 0){
                res = false;
                break;
            }
            else{
                if(A[i-1] != i || A[i] != i){
                    res = false;
                    break;
                }
            }
        }
        else {
            if(i>N){
                break;
            }
            if(A[i] != i+1 || A[i+1] != i+1){
                res = false;
                break;
            }
        }
    }

    if(res){
        ll ans=1;
        for(int i=0;i<N/2;i++){
            ans*=2;
            ans%=1000000007ll;
        }
        cout << ans << endl;
    }

    else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
string a=        Console.ReadLine();
        Console.WriteLine("2018"+a.Substring(4));
        Console.ReadLine();
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                // 素数ではない
                return false;
            }
        }

        // 素数である
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 11092
n = int(input())
for i in range(100):
  if n == 1<<i:
    print("No")
    exit()
print("Yes")
l = (n+1).bit_length()-1
ans = []
for i in range(2,2**l):
  ans.append((i-1,i))
  ans.append((n+i-1,n+i))
ans.append((2**l-1,n+1))
m = n-1+(n%2)
for i in range(2**l+1,m+1):
  ans.append((i-1,i))
  ans.append((n+i-1,n+i))
if n != 2**l-1:
  if (m+1)%4 == 0:
    ans.append((1,2**l))
    ans.append((m,n+2**l))
  else:
    ans.append((m+n,1))
    ans.append((1,2**l))
if n>m and (m+1)%4 == 0:
  ans.append((n-2**l,n))
  ans.append((2**l,2*n))
elif n>m:
  ans.append((2,n))
  ans.append((2*n,2*n-1))
for edge in ans:
  print(*edge)

Measured memory_bytes: 57684
s = input()
k=0
i=0
itimoji=0
while i <len(s):
  if i==0:
    k+=1
    i+=1
    itimoji=1
    continue
  if itimoji==0:
    k+=1
    i+=1
    itimoji=1
  else: #itimoji
    if s[i]==s[i-1]:
      if i==len(s)-1:
        break
      else:
        i+=2
        k+=1
        itimoji=0
    else:
      i+=1
      k+=1

print(k)

Measured memory_bytes: 3500
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val L = readLine()!!.split(" ").map {it.toInt()}.sorted()

    var res = 0L

    for (i in L.indices) for (j in i + 1 until L.size) {
        val l = Math.abs(L[i] - L[j])
        val u = L[i] + L[j]

        val a = Math.max(upperBound(L, l), j + 1)
        val b = lowerBound(L, u)

        if (b < a) {
            continue
        }

        res += (b - a)

        if (i in a until b) {
            res -= 1L
        }
        if (j in a until b) {
            res -= 1L
        }
    }

    println(res)
}

private fun lowerBound(list: List<Int>, v: Int): Int {
    if (list.last() < v) {
        return list.size
    }

    var l = -1
    var u = list.size - 1

    while (u - l > 1) {
        val c = (u + l) / 2
        if (list[c] >= v) {
            u = c
        } else {
            l = c
        }
    }

    return u
}

private fun upperBound(list: List<Int>, v: Int): Int {
    var l = 0
    var u = list.size

    while (u - l > 1) {
        val c = (u + l) / 2
        if (list[c] > v) {
            u = c
        } else {
            l = c
        }
    }

    return u
}


Measured memory_bytes: 41004
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define int long long
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

struct uf {
private:
	vector<int> par, ran, siz;
public:
	void init(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		siz.resize(n, 1);
		rep(i, n) {
			par[i] = i;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y;
			siz[y] += siz[x];
		}
		else {
			par[y] = x;
			siz[x] += siz[y];
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N; cin >> N;

    const int MAX = 100100;
    uf u; u.init(2 * MAX);
    rep(i, N) {
        int x, y; cin >> x >> y;
        u.unite(x, y + MAX);
    }
	int res = 0;
	map<int, int> mpx, mpy;
	rep(i, MAX) {
		mpx[u.find(i)] ++;
	}
	Rep(i, MAX, 2 * MAX) {
		mpy[u.find(i)] ++;
	}
	rep(i, 2 * MAX) {
		res += mpx[i] * mpy[i];
	}
	cout << res - N << endl;
	return 0;
}

Measured memory_bytes: 30080
#include<stdio.h>
int main(void){
    int n,k,q;
    scanf("%d %d %d",&n,&k,&q);
    int a[1000000];
    for(int i=0;i<q;i++){
        scanf("%d",&a[i]);
    }

    int p[100000]={};
   
    int sa=q-k;
    if(sa<0){
        for(int i=0;i<n;i++){
            printf("Yes\n");
        }
        return 0;
    }else{
          for(int i=0;i<q;i++){
              p[a[i]-1]++;
          }
    }

    for(int i=0;i<n;i++){
        if(p[i]>sa){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }
  
    return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
 
int main(void){
  int N;
  scanf("%d",&N);
  if(N >= 10 && N <= 99){
  if(N%10 == 9 || N/10==9){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  }
  return 0;
}

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

signed main(void)
{
	string s;
	int k;
	cin >> s >> k;
	if (k < s.size() && s[k - 1] == '1')
		cout << 1 << endl;
	else
	{
		rep(i, s.size())
		{
			if (s[i] != '1')
			{
				cout << s[i] << endl;
				return 0;
			}
		}
		cout << 1 << endl;
	}
	return 0;
}


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

#define PI acos(-1)

void textIO()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

}

vector<long long> arr(1e5+5);

int main()
{
    textIO();
    fastIO();

    set<long long> st;
    long long n, m;
    cin >> n >> m;

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

    for(int i=0;i<m;i++){
        long long a, b;
        cin >> a >> b;

        if(arr[a] == arr[b]){
            st.insert(a);
            st.insert(b);
        }
        else if(arr[a] < arr[b]){
            st.insert(a);
        }
        else{
            st.insert(b);
        }

    }

    cout << n-st.size() << '\n';

    return 0;
}


Measured memory_bytes: 6632
N,a,b,c,d=map(int,input().split())

def fprice(n,p):
    count=0
    price=0
    while N>count:
        count+=n
        price+=p
    return price
if fprice(a,b)>=fprice(c,d):
    print(fprice(c,d))
else:
    print(fprice(a,b))


Measured memory_bytes: 5600
from collections import deque, defaultdict

N, X, Y = map(int, input().split())
# 全探索でいけるのでは？
# 有向グラフとしてN回幅優先すれば良いのでは？
tree = [[] for _ in range(N)]
for i in range(N-1):
    tree[i].append(i+1)
    tree[i+1].append(i)
tree[X-1].append(Y-1)
tree[Y-1].append(X-1)
ans = defaultdict(int)
q = deque()
# 更新されない時はqに追加しない
for i in range(N):
    distant = [N]*N
    q.append(i)  # 始まりのノード
    distant[i] = 0
    while len(q):
        # vは数字, 親のノードのインデックス
        v = q.pop()
        for e in tree[v]:
            if distant[e] < distant[v]+1:  # 到達済みなら次のノードへ
                continue
            distant[e] = min(distant[v]+1, distant[e])
            q.append(e)
    for d in distant:
        ans[d] += 1
for i in range(1, N):
    print(ans[i]//2)


Measured memory_bytes: 50268
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
template <class T> inline void chmax(T &a, T b) { a < b ? a = b : a; };
template <class T> inline void chmin(T &a, T b) { a > b ? a = b : a; };
int dp[100000];
int main() {
    int n;
    cin >> n;
    rep(i, n + 1) dp[i] = 1 << 30;
    dp[0] = 0;
    REP(i, 1, n + 1) {
        rep(j, 10) {
            if(pow(6, j) > i)
                continue;
            dp[i] = min(dp[i], dp[i - (int)pow(6, j)] + 1);
        }
        rep(j, 8) {
            if(pow(9, j) > i)
                continue;
            dp[i] = min(dp[i], dp[i - (int)pow(9, j)] + 1);
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		call(new Scanner(System.in).nextInt());
	}

	static void call(int n) {
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				while (true) {
					if (x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					
					x /= 10;
					if (x == 0) {
						break;
					}
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 28788
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s) qsort(s,strlen(s),sizeof(char),cmp)
#define chsort_r(s) qsort(s,strlen(s),sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int n=in(),a=in(),b=in();
	print(min(n*a,b));
	return 0;
}

Measured memory_bytes: 128
n,m=map(int,input().split())
xy = [list(map(int, input().split())) for _ in range(m)]
l=[1]*n
out_=[0]*n
in_=[0]*n#入れられたことがある履歴。0番目だけは初期値1
c=1
#print(in_)
check=0
for i in range(m):
    if check==0:
        if xy[i][0]==1:#箱1に入ってくる前に初めて箱1から赤いボールを移す場合
            in_[xy[i][1]-1]+=1
            check=1
        else:#箱１から赤いボールを移す前に白いボールが入ってくる場合
            if xy[i][1]==1:
                in_[xy[i][1]-1]+=1
                check=1
        l[xy[i][0]-1]-=1
        l[xy[i][1]-1]+=1
        #print(l,in_)
    else:
        l[xy[i][0]-1]-=1
        l[xy[i][1]-1]+=1
        if l[xy[i][0]-1]==0 and in_[xy[i][0]-1]!=0:#移した後、空になる場合
            in_[xy[i][0]-1]=0
            in_[xy[i][1]-1]+=1
        elif l[xy[i][0]-1]!=0 and in_[xy[i][0]-1]!=0:#移した後、残っている場合
            in_[xy[i][1]-1]+=1
        #print(l,in_)
#print(l,in_)
ans=0
for i in range(n):
    if in_[i]!=0:
        ans+=1
print(ans)

Measured memory_bytes: 29400
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define MIN(a,b) ((a) < (b) ? (a) : (b))
struct node {
  int id;
  int cap;
  struct node *next;
};
struct node **list;
int **flow, *iter, *dist, *prev, *queue;
void Insert(int, int, int);
void Init_bfs(int, int);
int Maxflow_dfs(int, int, int, int);
int main(void)
{
  int i, v, e, s, t, c, maxflow = 0;
  scanf("%d %d", &v, &e);
  list = (struct node**)malloc(sizeof(struct node*) * v);
  flow = (int**)malloc(sizeof(int*) * v);
  iter = (int*)malloc(sizeof(int) * v);
  dist = (int*)malloc(sizeof(int) * v);
  prev = (int*)malloc(sizeof(int) * v);
  queue = (int*)malloc(sizeof(int) * v);
  for (i = 0; i < v; i++) {
    list[i] = NULL;
    flow[i] = (int*)calloc(v, sizeof(int));
  }
  for (i = 0; i < e; i++) {
    scanf("%d %d %d", &s, &t, &c);
    Insert(s, t, c);
  }
  while (1) {
    Init_bfs(0, v);
    if (dist[v-1] < 0) break;
    for (i = 0; i < v; i++) iter[i] = 0;
    while (1) {
      int f = Maxflow_dfs(0, v - 1, v, INT_MAX);
      if (!f) break;
      maxflow += f;
    }
  }
  printf("%d\n", maxflow);
  for (i = 0; i < v; i++) {
    free(list[i]);
    free(flow[i]);
  }
  free(list);
  free(flow);
  free(iter);
  free(dist);
  free(prev);
  free(queue);
}
void Insert(int a, int b, int c)
{
  struct node *p = (struct node*)malloc(sizeof(struct node));
  p->id = b;
  p->cap = c;
  p->next = list[a];
  list[a] = p;
  p = (struct node*)malloc(sizeof(struct node));
  p->id = a;
  p->cap = 0;
  p->next = list[b];
  list[b] = p;
}
void Init_bfs(int s, int size)
{
  struct node *n;
  int i, head = 0, tail = 0;
  for (i = 0; i < size; i++) dist[i] = -1;
  dist[s] = 0;
  queue[tail++] = s;
  while (head != tail) {
    i = queue[head++];
    for (n = list[i]; n != NULL; n = n->next) {
      int v = n->id;
      if (dist[v] < 0 && flow[i][v] < n->cap) {
        dist[v] = dist[i] + 1;
        queue[tail++] = v;
      }
    }
  }
}
int Maxflow_dfs(int s, int t, int size, int f)
{
  struct node *n = list[s];
  if (s == t) return f;
  while (n != NULL && iter[s]) {
    n = n->next;
    iter[s]--;
  }
  for (; n != NULL; n = n->next) {
    int v = n->id;
    iter[s] = v;
    if (dist[s] < dist[v] && flow[s][v] < n->cap) {
      int d = Maxflow_dfs(v, size - 1, size, MIN(f, n->cap - flow[s][v]));
      if (d > 0) {
        flow[s][v] += d;
        flow[v][s] -= d;
        return d;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 2104
import numpy as np
from functools import reduce
n,m,c=map(int,input().split())
a=np.array(list(map(int,input().split())))
b=np.empty((n,m),dtype=int)
for i in range(n):
  b[i,:]=np.array(list(map(int,input().split())))
d=np.dot(b,a)

def func(a,b):
  return a+1 if b>-c else a

answer=reduce(func,d,0)
print(answer)

Measured memory_bytes: 12500
#include <stdio.h>
#include <math.h>

int main(void) {
  int n, h[100000], c[100000], i, a, b;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &h[i]);
  }
  c[0]=0;
  c[1]=abs(h[1]-h[0]);
  for(i=2;i<n;i++){
    a=c[i-2]+abs(h[i]-h[i-2]);
    b=c[i-1]+abs(h[i]-h[i-1]);
    if(a<b){
      c[i]=a;
    }else{
      c[i]=b;
    }
  }
  printf("%d", c[n-1]);
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;


int main() {
	cout << fixed << setprecision(14);
	while (true) {
		int N, T, L, B;
		cin >> N >> T >> L >> B;
		if (N == 0)break;
		vc b(N + 1, 'N');
		vector<vvd> p(T + 1, vvd(N + 1, vd(2, 0)));
		p[0][0][0] = 1;
		rep(i, L) {
			int n;
			cin >> n;
			b[n] = 'L';
		}
		rep(i, B) {
			int n;
			cin >> n;
			b[n] = 'B';
		}
		rep(t, T) {
			rep(i, N) {
				if (b[i] == 'N') {
					repl(j, 1, 7) {
						int nx = (i + j > N ? 2 * N - i - j : i + j);
						if (b[nx] == 'B') {
							p[t + 1][0][0] += p[t][i][0] / 6.0;
						}
						else {
							p[t + 1][nx][0] += p[t][i][0] / 6.0;
						}
					}
				}
				else if (b[i] == 'L') {
					repl(j, 1, 7) {
						int nx = (i + j > N ? 2 * N - i - j : i + j);
						if (b[nx] == 'B') {
							p[t + 1][0][0] += p[t][i][1] / 6.0;
						}
						else {
							p[t + 1][nx][0] += p[t][i][1] / 6.0;
						}
					}
					p[t + 1][i][1] = p[t][i][0];
				}
			}
			p[t + 1][N][0] += p[t][N][0];
		}
		cout << p[T][N][0] << endl;
	}


	return 0;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
 
typedef long long int ll;
const ll N = 1ll<<21;
const ll p = 31;
// const ll m = 1e9 + 7;
const ll inf= 1e14;
const ll mod = 1e9 +7;
#define x first
#define y second
#define pb push_back
#define mp make_pair
using pii = pair<ll, ll>;
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
std::vector<pii> adj[N];
ll dp[N];
ll n;
bool is_pos[25][25];
ll rec(ll mask,ll ct){
     if(dp[mask]!=-1){
          return dp[mask];
     }
     else{
          dp[mask] = 0;
          for(int i = 0;i<n;i++){
               if((mask&(1<<i)) && is_pos[ct-1][i]){
                    dp[mask]+=rec(mask-(1ll<<i),ct-1);
                    dp[mask]%=mod;
               }
          }
          return dp[mask];
     }
}
int main()
{   
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);                     
     ll T= 1;
     // cin>>T;
     memset(dp,-1,sizeof(dp));
     dp[0] = 1;

     while(T--){
          cin>>n;
          for(int i = 0;i<n;i++){
               for(int j = 0;j<n;j++){
                    cin>>is_pos[i][j];
               }
          }
          ll m = (1ll<<n) -1;
          cout<<rec(m,n)<<'\n';

     }
    return 0;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
#define VL vector<lol>
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    lol n; cin >> n;
    //lol k; cin >> k;
    /*
    VL a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */
    if(n == 1) result = 0;
    else result = 1;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int inf = 1000000007;
signed main() {
	int n, k;
	cin >> n >> k;
	int ans = k;
	for(int i=1;i<n;i++){
		ans *= (k - 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define repn(i,s,n) for (int i=int(s); i < int(n); i++)
#define rep(i,n) repn(i,0,n)
#define repd(i,n) for (int i=int(n)-1; i >= 0; i--)


struct Node {
  int val;  // この区間に足される値
  int min;  // この区間の最小値（valを含む）
  int sum;  // この区間の値の和（valを含む）
  Node() : min(0), val(0), sum(0) {}
};

#define LC(k) (k * 2 + 1)  // 左の子
#define RC(k) (k * 2 + 2)  // 右の子

const int INF = INT_MAX;

struct RMQRangeAddSumSegTree {
  vector<Node> tree;
  int n;
  RMQRangeAddSumSegTree(int n) : n(n), tree(n*2 - 1) {}  // nは2のべき乗でなければならない

  // 区間[l,r)内の要素にvalを足す
  void addRange(int l, int r, int val) {
    addRange(l, r, 0, 0, n, val);
  }

  // a,b: クエリ対象の範囲[a,b)
  // k: 現在のノードの番号
  // l,r: 現在のノードkの範囲[l,r)
  // val: [a,b)に追加する値
  void addRange(int a, int b, int k, int l, int r, int val) {
    if (r <= a || b <= l) return;  // 対象区間とノードの区間が交わらないなら処理をしない
    process_lazy(k, r-l);
    if (a <= l && r <= b) {
      tree[k].val += val;
    }
    else {
      addRange(a, b, LC(k), l, (l + r) / 2, val);
      addRange(a, b, RC(k), (l + r) / 2, r, val);
    }
    update_node(k, r-l);
  }

  // 遅延評価の実行。根ノード側の更新分を下へ伝搬していく
  void process_lazy(int k, int size) {
    if (size > 1 && tree[k].val != 0) {
      tree[LC(k)].val += tree[k].val;
      tree[RC(k)].val += tree[k].val;
      tree[LC(k)].min += tree[k].val;
      tree[RC(k)].min += tree[k].val;
      tree[LC(k)].sum += tree[k].val * (size / 2);
      tree[RC(k)].sum += tree[k].val * (size / 2);
      tree[k].val = 0;
    }
  }

  // 頂点情報の更新。葉ノード側の更新を上へ伝搬していく
  void update_node(int k, int size) {
    if (size > 1) {  // kは葉でない
      tree[k].min = tree[k].val + min(tree[LC(k)].min, tree[RC(k)].min);
      tree[k].sum = tree[k].val*size + tree[LC(k)].sum + tree[RC(k)].sum;
    }
    else {  // kは葉
      tree[k].min = tree[k].sum = tree[k].val;
    }
  }

  // 区間[l,r)内の要素の最小値を返す
  int minRange(int l, int r) {
    return minRange(l, r, 0, 0, n);
  }

  int minRange(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INT_MAX;
    process_lazy(k, r-l);
    if (a <= l && r <= b) return tree[k].min;
    return min(
      minRange(a, b, LC(k), l, (l + r) / 2),
      minRange(a, b, RC(k), (l + r) / 2, r)
    );
  }

  // 区間[l,r)内の要素の和を返す
  int sumRange(int l, int r) {
    return sumRange(l, r, 0, 0, n);
  }

  int sumRange(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return 0;
    process_lazy(k, r-l);
    if (a <= l && r <= b) return tree[k].sum;
    return sumRange(a, b, LC(k), l, (l + r) / 2) +
           sumRange(a, b, RC(k), (l + r) / 2, r);
  }
};


int main() {

  int n, q;
  cin >> n >> q;
  int nPow2 = n-1;
  nPow2 |= nPow2 >> 1;
  nPow2 |= nPow2 >> 2;
  nPow2 |= nPow2 >> 4;
  nPow2 |= nPow2 >> 8;
  nPow2 |= nPow2 >> 16;
  nPow2++;

  RMQRangeAddSumSegTree segtree(nPow2);
  rep(qi, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      // add(x,y)
      x--;
      segtree.addRange(x, x+1, y);
    }
    else {
      // getSum(x,y)
      x--;
      y--;
      cout << segtree.sumRange(x, y+1) << endl;
    }
  }
  return 0;
}

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

#ifdef LOCAL 
#include "e:/Codes/lib/prettyprint.hpp"
#else
#define debug(...) 
#endif

int32_t main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  
  int n, x, m;
  cin >> n >> x >> m;
  
  x %= m;
  int cnt = 1, ans = 0;
  map<int, int> mp;
  vector<int> vals;
  vals.push_back(0);

  while (1) {
    if (mp[x]) break;
    mp[x] = cnt++;
    vals.push_back(vals.back() + x);
    x = x * x % m;
  }

  if (n < cnt) ans += vals[n];
  else {
    int cy = cnt - mp[x];
    debug(cy, cnt, mp[x], x);
    n -= mp[x] - 1;
    ans += (n / cy) * (vals.back() - vals[mp[x]-1]);
    n %= cy;
    n += mp[x] - 1;
    ans += vals[n];
    debug(n);
  }

  cout << ans << '\n';
}


Measured memory_bytes: 6732
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
 
long long quick_power(long long x, long long y, long long p) {
    long long ans=1;
    while (y) {
        if (y&1) {
            ans=(ans*x)%p; 
        }
        y>>=1;
        x=(x*x)%p;
    }
    return ans%p;
}
 
int main() {
    long long n;
    long long zeros = 0;
    long long ans=1;
 
    map<pair<long long,long long>,long long> m;
    map<pair<long long,long long>,long long>::iterator it;
 
    scanf("%lld", &n);
    for (long long i=1; i<=n; i++) {
        long long u,v,now;
        scanf("%lld%lld", &u, &v);
 
        if (u==0&&v==0) {
            zeros++;
            continue;
        }
 
        now=__gcd(u,v);
        u/=now;
        v/=now;
 
        if (u<0) {
            u=-u;
            v=-v;
        }
        m[make_pair(u,v)]++;
    }
 
    for (it=m.begin();it!=m.end();it++) {
        if (it->second==0) {
            continue;
        }
 
        long long x=it->first.first,y=it->first.second;
        long long p=quick_power(2, m[make_pair(x,y)], MOD);
 
        y=-y;
        if (y<0) {
            x=-x;
            y=-y;
        } 
 
        if (m.count(make_pair(y,x))) {
            p=(p+quick_power(2, m[make_pair(y,x)], MOD)-1);
            m[make_pair(y,x)]=0;
        }
        ans=(ans*p)%MOD;
    }
 
    printf("%lld\n", ((ans+zeros-1)%MOD+MOD)%MOD);
	
    return 0;
}

Measured memory_bytes: 16192
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

H, W = mi()
h, w = mi()

print((W-w)*(H-h))

Measured memory_bytes: 3064
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for i in range(M)]
waribiki_nasi = min(a)+min(b)
ans = waribiki_nasi
for i in range(len(xyc)):
    waribiki = a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2]
    ans = min(ans,waribiki)
print(ans)

Measured memory_bytes: 38500
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll mod;
ll dp[100005] , ans[100005];
vector < int > adj[100005];
vector < ll > preffix[100005] , suffix[100005];

void dfs(int i = 0 , int p = -1)
{
    ll c = 1;
    for(auto u : adj[i]) {if(u != p) dfs(u,i) , c = (c * (dp[u]+1)%mod)%mod; preffix[i].push_back(c);}
    c = 1;
    for(int j = adj[i].size()-1 ; j >= 0 ; j--) {if(adj[i][j] != p) c = (c * (dp[adj[i][j]]+1)%mod)%mod; suffix[i].push_back(c);}
    reverse(suffix[i].begin(),suffix[i].end());
    dp[i] = c;
}
void calc(int i = 0 , int p = -1 , ll R = 0)
{
    ans[i] = (dp[i]*((R+1)%mod)%mod);
    for(int j = 0 ; j < adj[i].size() ; j++)
        if(adj[i][j] != p)
            calc(adj[i][j],i,( ((j ? preffix[i][j-1] : 1) * (j+1 < adj[i].size() ? suffix[i][j+1] : 1))%mod *((R+1)%mod))%mod );
}
int main()
{
    scanf("%d%lld",&n,&mod);
    for(int i = 0 ; i < n-1 ; i++)
    {
        int x, y;   scanf("%d%d",&x,&y);    x--;y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs();
    calc();
    for(int i = 0 ; i < n; i++) printf("%lld\n",ans[i]);
    return 0;
}


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

int main() {
  int A, B, count;
  count = 0;
  cin >> A >> B;
  
  for (int i = A; i <= B; i++) {
    int i1 = (i % 10);
    int i2 = (i % 100) / 10;
    int i4 = (i % 10000) / 1000;
    int i5 = i / 10000;
    
    if (i1 == i5 && i2 == i4) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
N = int(input())
A = [0] * (N + 1)
for i in range(1, 102):
    for j in range(1, 102):
        for k in range(1, 102):
            t = i ** 2 + j ** 2 + k ** 2 + i * j + j * k + i * k
            if t <= N:
                A[t] += 1
for n in range(1, N + 1):
    print(A[n])

Measured memory_bytes: 74412
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string Yes[2] = {"Yes", "No"};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;

/*------------------------------------------------------------------*/


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s, t; cin >> s >> t;

    int n = s.size();
    int m = t.size();
    int MIN = 10000;
    rep(i, n - m + 1){
        int sum = 0;
        rep(j, m){
            if(s[j + i] != t[j]) sum++;
        }
        MIN = min(sum, MIN);
    }
    cout << MIN << endl;
}

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

using namespace std;

#define ll long long

ll a1, a2, a3, a4, n, ans;

int main () {

cin >> a1 >> a2 >> a3 >> a4 >> n;

a4 = min(min(min(a1 * 8, a2 * 4), a3 * 2), a4);
a3 = min(min(a1 * 4, a2 * 2), a3);
a2 = min(a1 * 2, a2);

while(n != 0){
    if (n >= 2){
        ans += a4;
        n -= 2;
    }
    else {ans += a3; n -= 1;}
}


cout << ans;


return 0;

}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final int INF = 1 << 30;
	static long[][][] hash = new long[4][9][32];
	static long finish;

	public static void main(String[] args) {
		Random rnd = new Random();
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 9; ++j) {
				for (int k = 0; k < 32; ++k) {
					hash[i][j][k] = rnd.nextLong();
				}
			}
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 2; j <= 7; ++j) {
				finish ^= hash[i][j - 1][i * 8 + j];
			}
		}
		int T = sc.nextInt();
		for (int i = 0; i < T; ++i) {
			System.out.println(solve());
		}
	}

	static int solve() {
		ArrayList<Board> cur = new ArrayList<Board>();
		HashSet<Long> hashes = new HashSet<Long>();
		cur.add(new Board());
		hashes.add(cur.get(0).h);
		int i = 0;
		for (; !cur.isEmpty(); ++i) {
			ArrayList<Board> next = new ArrayList<Board>();
			for (Board b : cur) {
				if (b.h == finish) {
					return i;
				}
				for (int j = 0; j < 4; ++j) {
					for (int k = 1; k < 8; ++k) {
						if (b.f[j][k] == INF && b.f[j][k - 1] != INF && (b.f[j][k - 1] & 7) != 7) {
							Board created = new Board(b, j, k);
							if (hashes.contains(created.h)) continue;
							hashes.add(created.h);
							next.add(created);
						}
					}
				}
			}
			cur = next;
		}
		return -1;
	}

	static class Board {
		int[][] f = new int[4][8];
		long h;

		Board() {
			for (int i = 0; i < 4; ++i) {
				for (int j = 0; j < 7; ++j) {
					int v = sc.nextInt();
					int suit = v / 10 - 1;
					int num = v % 10;
					int card = (suit << 3) + num;
					if (num == 1) {
						f[i][j + 1] = INF;
						f[suit][0] = card;
					} else {
						f[i][j + 1] = card;
						h ^= hash[i][j + 1][card];
					}
				}
			}
		}

		Board(Board orig, int r, int c) {
			this.h = orig.h;
			for (int i = 0; i < 4; ++i) {
				for (int j = 0; j < 8; ++j) {
					this.f[i][j] = orig.f[i][j];
					if (orig.f[i][j] == orig.f[r][c - 1] + 1) {
						this.f[i][j] = INF;
						this.h ^= hash[i][j][orig.f[r][c - 1] + 1];
					}
				}
			}
			this.f[r][c] = orig.f[r][c - 1] + 1;
			this.h ^= hash[r][c][orig.f[r][c - 1] + 1];
		}

		void print() {
			for (int j = 0; j < 4; ++j) {
				for (int k = 0; k < 8; ++k) {
					if (f[j][k] == INF) {
						System.out.print("-1 ");
					} else {
						System.out.print((f[j][k] >> 3) + "" + (f[j][k] & 7) + " ");
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    string a;

    cin >> a;

    string b;

    cin >> b;

    b+=a;

    cout << b << '\n';

    return 0;

}



Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
int main()
{
	int i,j, l;
	char s[101], t[101];
	scanf("%s %s", s, t);
	l=strlen(s);
	for(i=0; i<l; i++)
	{
		if(s[i]==t[0])
		{
			j=i;
			break;
		}
	}
	if(i==l)
	{
		printf("No\n");
		return 0;
	}
	for(i=1, j++; j<l; j++,i++)
		if(s[j] != t[i])
		{
			printf("No\n");
			return 0;
		}
	for(j=0; i<l; i++, j++)
		if(s[j] != t[i])
		{
			printf("No\n");
			return 0;
		}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 384
n = int(input())
ans = 1e18
for i in range(1, n):
    a = i
    b = n-i
    tmp = 0
    while a:
        tmp += a%10
        a //= 10
    while b:
        tmp += b%10
        b //= 10
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  double r;
  cin >> r;
  cout << fixed << setprecision(10) << 2*r*M_PI << endl;
}

Measured memory_bytes: 3760