akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var abt = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(abt[1] * (abt[2] / abt[0]));
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include<algorithm>
#include<stack>
#include<string>
#include<cstdlib>

int search(int a[],int n,int key){
    int i=0;
    a[n]=key;
    while(a[i]!=key)i++;
    return i!=n;
}
using namespace std;
int main(){
    int i,n,a[10001],q,key,sum=0;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>a[i];
    }
    cin>>q;
    for(i=0; i<q; i++){
        cin>>key;
        if(search(a,n,key))sum++;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3092
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define mp make_pair
#define MAX 20000
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<ii> vii;
#define EPS 1e-9
#define LSOne(S) (S & (-S))
#define INF 1000*1000*1000+889
const int N = 1e5+10;
int h[N];
int dp[N];
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    for(int i = 1; i <= n; ++i)
    {
        cin>>h[i];
    }
    for(int i = 2; i <= n; ++i)
    {
        int ans = INT_MAX;
        for(int j = 1; j <= k; ++j)
        {
            if(i-j>0)
            {
                ans = min(ans,dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
        dp[i] = ans;
    }
    cout<<dp[n];
}


Measured memory_bytes: 1024
//g++ -std=gnu++14 a.cpp
//#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;


vector<ll> sum(1000000, INFL);
vector<ll> h(1000000);


ll rec(ll i){
  if(sum[i] < INFL) return sum[i];

  if(i == 0) return 0;

  ll ans = INFL;
  ans = min(ans,rec(i-1)+abs(h[i]-h[i-1]));
  if(i > 1) ans = min(ans,rec(i-2)+abs(h[i]-h[i-2]));

  return sum[i] = ans;
}
/*
ll rec(ll i){
  if(sum[i] < INFL) return sum[i];

  if(i == 0) return 0;

  ll ans = INFL;
  ans = min(ans,rec(i-1)+abs(h[i]-h[i-1]));
  if(i > 1) ans = min(ans,rec(i-2)+abs(h[i]-h[i-2]));

  return sum[i] = ans;
}
*/

int main(){
  ll N;
  cin >> N;
  for(int  i = 0;i < N; i++) cin >> h[i];
  //sum[0] = INFL;
  //sum[1] = 0;
/*
  for(int i = 1; i <= N; i++){
    //sum[i] = min( abs(h[i]-h[i-1])+sum[i-1] , abs(h[i]-h[i-2])+sum[i-2]);
    sum[i+1] = min(sum[i+1], sum[i]+abs(h[i+1]-h[i]));
    sum[i+2] = min(sum[i+2], sum[i]+abs(h[i+2]-h[i]));
  }
  */
  cout << rec(N-1) << endl;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	
  	Int(a); char b; cin >> b; Int(c);
  if (b == '+') cout << a + c << endl;
  else cout << a - c << endl;
  
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    double a,b,x;
    cin>>a>>b>>x;
     double c;
    double d;
     double e;
     double f;
     
    if(a*a*b/x<=2.0){
    c=(2*a*a*b-2*x)/(a*a*a);
    d=atan(c);
    e=3.14159265358979323846264338/d;
    f=180/e;
    cout<<setprecision(15) <<f;
    }else{
        c=a*b*b/(2*x);
        d=atan(c);
    e=3.14159265358979323846264338/d;
    f=180/e;
    cout<<setprecision(15) <<f;}
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
using namespace std;
ll a[114]; ll n;
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	ll sanada = 1, ans = 1;
	for (int i = 0; i < n; i++)sanada *= 3;
	rep(i, n) {
		if (a[i] % 2 == 0)ans *= 2;
	}
	cout << sanada - ans << endl;
	getchar(); getchar(); return 0;
}

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

using namespace std;

#define DIM 1000009
#define INF ((long long)1e18+9ll)
#define pairll pair<long long,long long>
#define fi first
#define se second
#define ld long double
#define amen exit(0)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define endl '\n'
#define y1 trymax_lox
#define y2 sijgkvdfbo
#define eps 1000000

long long i,j,k,l,n,m,res;

long long cnt[10][10];

int main(){

   // freopen("boards.in","r",stdin);
   // freopen("boards.out","w",stdout);
    fast;

    cin>>n;

    for(i=1;i<=n;i++){
        k=i;
        while(k){
            l=k%10;
            k/=10;
        }

        cnt[l][i%10]++;
    }

    for(i=0;i<10;i++){
        for(j=0;j<10;j++){
            res+=cnt[i][j]*cnt[j][i];
        }
    }

    cout<<res<<endl;

    amen;
}

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

using namespace std;

inline int abs(int a, int b)
{
    return ((a - b) >= 0 ? (a - b):-1*(a - b));
}

const int Nmax = 1e5 + 1;
int a[Nmax];
int N,K,Dif_min;

int main()
{
    cin >> N >> K;
    for(int i = 1; i <= N; ++i)
        cin >> a[i];
    sort(a + 1,a + N + 1);
    Dif_min = (1 << 30);
    for(int i = 1; i <= N - K + 1; ++i)
        Dif_min = min(Dif_min,abs(a[i] - a[i + K - 1]));
    cout << Dif_min;
    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    n = n % 10;
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 7 || n == 9) {
        cout << "hon";
    } else if (n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon";
    } else {
        cout << "bon";
    }
}


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

int main() {
    int N;
    cin >> N;
    vector<float> v(N);
    for(int i =0; i < N; i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    float result = v[0];
    for(int i = 1;i < N; i++){
        result = (result + v[i]) / 2;
    }
    cout << result << endl;
}

Measured memory_bytes: 256
import math
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
D=[0,0,0,0]
p=[1,2,3]
for k in range(4):
    if k==3:
        D[k]=max(abs(x[i]-y[i])for i in range(n))
    else:
        D[k]=math.pow(sum(abs((x[i]-y[i])**p[k])for i in range(n)),1/p[k])
    print("{:.6f}".format(D[k]))



Measured memory_bytes: 5712
#include <iostream>

using namespace std;


int main()
{
    long long n;
    cin>>n;
    long long v[n];
    for(long long i=0; i<n; i++){
        cin>>v[i];
    }
    int rest;
    
    while(v[0]!=0&&v[1]!=0){
        if(v[0]>v[1]){
            v[0]=v[0]%v[1];
        }
        else{
            v[1]=v[1]%v[0];
        }
    }
    
    if(v[0]!=0)
        rest=v[0];
    else
        rest=v[1];
        
    for(int i=0; i<n; i++){
        while(rest!=0&&v[i]!=0){
            if(rest>v[i]){
                rest=rest%v[i];
            }
            else{
                v[i]=v[i]%rest;
            }
        }
        if(rest==0){
            rest=v[i];
        }
    }
    
    cout<<rest;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream&o,const pair<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
template<typename T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
//V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 2e5;
int n, a[N], b[N];
queue<int> q;
inline bool check(int m){
  int s=b[(m-1+n)%n]+b[(m+1)%n];
  return s<b[m] && (b[m]%s>=a[m] || (b[m]-a[m])%s==0);
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> a[i];
  FOR(i, 0, n) cin >> b[i];
  FOR(i, 0, n) {
    if(a[i]>b[i]){
      cout << -1 << endl;
      return 0;
    }
    if(check(i)) q.push(i);
  }
  ll ans = 0;
  while(!q.empty()){
    int m=q.front(), l=(m-1+n)%n, r=(m+1)%n, s=b[l]+b[r];
    q.pop();
    int c = max(b[m]%s, a[m]);
    ans += (b[m]-c)/s;
    b[m] = c;
    if(check(l)) q.push(l);
    if(check(r)) q.push(r);
  }
  FOR(i, 0, n) if(a[i]!=b[i]){
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main(){
  double x,y,z;
  cin>>x>>y;
  z=2*x-y/2;
  bool a=true;
  bool b=true;
  bool c=true;
  if(z<0) a=false;
  if((int)y%2!=0) b=false;
  if(x-z<0) c=false;
  if(a&&b&&c) puts("Yes");
  else puts("No");
}

Measured memory_bytes: 3724
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
using namespace std;

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

// マクロ
#define repr(itr, bgn, end) for (ll itr = (ll)bgn; itr < (ll)end; itr++)
#define rep(itr, end) repr(itr, 0, end)
#define reprrev(itr, bgn, end) for (ll itr = (ll)end - 1; itr >= (ll)bgn; i--)
#define reprev(itr, end) reprrev(i, 0, end)
#define all(container) container.begin(), container.end()
#define yn(cond) cond ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(cond) cond ? (cout << "YES" << endl) : (cout << "NO" << endl)

// 定数
#define LLONG_MAX 9223372036854775807i64
constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 15;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;

// よく使うもの
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };
struct edge { ll to; ll cost; };


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    for (T& x : vec) os << x << endl;
    return os;
}

// ***<ここから>****************************************************************

int main(void) {

    int N;
    cin >> N;
    vi A(N);
    cin >> A;

    sort(all(A));
    cout << A[N - 1] - A[0] << endl;
 
    return 0;
}

Measured memory_bytes: 256
import Control.Monad

main = do
  k <- readLn :: IO Int
  print . f $ k

f :: Int -> Int
f k
  | gcd k 10 /= 1 = -1
  | otherwise = g l 10 1
  where
    l
      | k `mod` 7 == 0 = 9 * k `div` 7
      | otherwise = 9 * k

g :: Int -> Int -> Int -> Int
g l a i
  | m == 1 = i
  | otherwise = g l (10 * m) (i + 1)
  where
    m = a `mod` l

Measured memory_bytes: 4016
def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(n**0.5)+1):
        if n % k == 0:
            return False
    return True


N = int(input())
ans = []
t = 11
while len(ans) < N:
    if is_prime(t):
        ans.append(t)
    t += 5
print(*ans)


Measured memory_bytes: 9428
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
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);
}

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//距離
double dis(double xa, double ya, double xb, double yb) {
	return pow(pow(xa - xb, 2.0) + pow(ya - yb, 2.0), 0.5);
}



//提出コード↓

int n, w[100], sm,D = 100000;




int main() {
	cin >> n;
	rep(i, n) {
		cin >> w[i];
		sm += w[i];
	}
	rep(i,n){
		int S = 0;
		rep(j, i + 1) {
			S += w[j];
		}
		D = min(D, abs(S - (sm - S)));
	}
	cout << D << endl;


	return 0;
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl


template<typename T> struct bit1 {
    T add(T x, T y) {
	return x+y;
    }
    int n;
    vector<T> t;
    void init(int n) {
	this->n=n;
	t.resize(n+10);
    }
    T qry(int i) {
	T res=0;
	for (; i>0; i-=i&-i) res=add(res,t[i]);
	return res;
    }
    void upd(int i, T dx) {
	for (; i<=n; i+=i&-i) t[i]=add(t[i],dx);
    }
};


using ll = long long;
const ll mod = 998244353;
const ll inf = 1e18;

const int maxn = 1e6 + 5;


ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}

void add(ll& x, ll y) {
    if (x>=mod) x%=mod;
    if (y>=mod) y%=mod;
    x += y;
    if (x>=mod) x%=mod;
}

void mul(ll& x, ll y) {
    if (x>=mod) x%=mod;
    if (y>=mod) y%=mod;
    x *= y;
    if (x>=mod) x%=mod;
}



bit1<ll> bitL, bitR;
vector<ll> ord;
int N;

int getcc(int i) {
    return lower_bound(ord.begin(),ord.end(),i)-ord.begin();
}

void upd(bit1<ll>& bit, ll i, ll dx) {
    i = getcc(i);
    bit.upd(i, dx);
}

ll below(bit1<ll>& bit, ll i) {
    i = getcc(i);
    return bit.qry(i-1);
}

ll above(bit1<ll>& bit, ll i) {
    i = getcc(i);
    return bit.qry(N) - bit.qry(i);
}

ll n;
vector<pair<ll,ll>> pts;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    ord.push_back(-inf);
    ord.push_back(inf);

    cin>>n;
    
    for (int i=0; i<n; i++) {
	ll x,y;
	cin>>x>>y;
	ord.push_back(x);
	ord.push_back(y);
	pts.push_back({x,y});
    }

    sort(ord.begin(),ord.end());
    ord.erase(std::unique(ord.begin(),ord.end()),ord.end());
    N = (int)ord.size();
    bitL.init(N+10);
    bitR.init(N+10);
    
    sort(pts.begin(),pts.end());


    // initially, all points are on right
    for (auto p: pts) {
	upd(bitR, p.second,1);
    }


    ll res = n*pw(2,n-1)%mod; // every point is in 2^(n-1) subsets


    for (auto p: pts) {
	ll y = p.second;
	upd(bitR, y, -1);

	ll Q1 = above(bitR, y);
	ll Q2 = above(bitL, y);
	ll Q3 = below(bitL, y);
	ll Q4 = below(bitR, y);

	ll d24 = (pw(2,Q2)-1)*(pw(2,Q4)-1)%mod;
	ll d13 = (pw(2,Q1)-1)*(pw(2,Q3)-1)%mod;
	ll d1234 = d24*d13%mod;

	ll cur = (pw(2,Q1+Q3)*d24%mod + pw(2,Q2+Q4)*d13%mod - d1234)%mod;

	add(res, cur);
	upd(bitL, y, +1);
    }


    res %= mod;
    res += mod;
    res %= mod;
    cout<<res<<endl;
    
    
    return 0;
}


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

struct union_find{
    vector<int> par;
    vector<int> price;
    vector<int> rank;
    union_find(int sz){
        par.resize(sz);
        price.resize(sz);
        rank.assign(sz,0);
        for(int i = 0;i < sz;++i) par[i]=i;
    }
    int find(int a){
        if(par[a]==a) return a;
        else return par[a] = find(par[a]);
    }
    void unite(int a,int b){
        int root_a,root_b;
        root_a = find(a),root_b = find(b);
        if(rank[root_a]>rank[root_b]){
            par[root_b] = root_a;
        }else if(rank[root_a]<rank[root_b]){
            par[root_a] = root_b;
        }else{
            rank[root_a]++;
            par[root_b] = root_a;
        }
        price[root_a]=min(price[root_a], price[root_b]);
        price[root_b]=min(price[root_a], price[root_b]);
    }
    bool same(int a,int b){return find(a)==find(b);}
};

int main(){
	int n; cin >> n;
    union_find tree(n);
    map<string, int> a;
    string tmp;
    for(int i=0; i<n; i++){
        cin >> tmp >> tree.price[i];
        a[tmp]=i;
    }
    int m; cin >> m;
    string tmp1, tmp2;
    for(int i=0; i<m; i++){
        cin >> tmp1 >> tmp2;
        tree.unite(a[tmp1], a[tmp2]);
    }

    int ans=0;
    for(int i=0; i<n; i++){
        ans += tree.price[tree.find(i)];
    }
	cout << ans << endl;
}


Measured memory_bytes: 3852
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#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() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
template<typename T>
bool all_same(vector<T> v1,vector<T> v2)
{
    sort(ALL(v1));
    sort(ALL(v2),greater<T>());
    return v1 == v2;
}
   
// g++ -std=c++11 prac.cpp
ll Max=-1e9,Min=1e9+1;

int main(){
    ll a,b,d,x,y,z,n,m,l,w,sum=0,sum2=0,ans=0;
    string s,t;
    char c[5]={'K','I','H','B','R'};
    VI cn(5,0);
    bool ok=true;
    cin >> s;
    if(s.size() > 9){
        cout << "NO" << endl;
        return 0;
    }

    int j=0;
    rep(i,s.size()){
        if(s[i] == c[j]){
            j++;
        }
        else if (s[i]!='A'){
            cout << "NO" << endl;
            return 0;
        }   
        rep(k,5){
            if(s[i]==c[k]){
                cn[k]++;
            }
        }
    }
    rep(i,5){
        if(cn[i]!=1){
            j=0;
        }
    }
    if(j!=5){
        cout << "NO" << endl;
        return 0;
    }

    rep(i, s.size()){
        if(s[i]=='A'){
            if(i==0){
                continue;
            }
            if(s[i-1]!='H' && s[i-1]!='B' && s[i-1]!='R'){
                ok=false;
            }
        }
    }

    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
//Write From this Line

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
mint f(int n) {
	if(n==0) return 1;
	mint res = f(n/2) ;
	res *= res;
	if ( n % 2 ) res *= 2;
	return res  ;
}
mint choose(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= ( n - i ) ;
		y *= ( i + 1 );
	}
	return x / y; 
}
int main()
{
//繰り返し２乗法O(log N)
	int n ;
	cin >> n ;
	int a, b;
	cin >> a>> b;
	//２のｎ乗を求める
	mint all_cases = f(n);	
	all_cases -=1 ;
	all_cases -= choose(n,a);
	all_cases -= choose(n,b);
	cout << all_cases.x << endl;
	

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int H = sc.nextInt();
			final int N = sc.nextInt();
		
			long sum = 0;
			for(int i = 0; i < N; i++) {
				sum += sc.nextLong();
			}
			
			
			System.out.println(H <= sum ? "Yes" : "No");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 35132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int ans = 0;

		for(int i = 0; i <= A; i++) {
			for(int j = 0; j <= B; j++) {
			  int tmp = X - i*500 - j*100;
				if (0 <= tmp && tmp <= C*50) {
						ans++;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 25300
h = []
w = []

while True:
    indata = list(map(int, input().split()))
    if indata[0] == 0 and indata[1] == 0:
        break
    h.append(indata[0])
    w.append(indata[1])

k = 0

while k != len(h):
    for i in range(h[k]):
        for j in range(w[k]):
            print("#", end="")
        print("\n", end="")
    print("\n", end="")
    k += 1

Measured memory_bytes: 8964
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

long int combination(long int n, long int r);

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)

long int combination(long int n, long int r)
{
	if(r>n-r) r = n-r;
	if(r == 0) return 1;
	else if(r == 1) return n;
	return (combination(n-1, r) + combination(n-1, r-1));
	//大きくなるとき
	/*
	long int tmp1, tmp2, tmp3;
	tmp1 = combination(n-1, r);
	if(tmp1>=MOD) tmp1 = tmp1%MOD;
	tmp2 = combination(n-1, r-1);
	if(tmp2>=MOD) tmp2 = tmp2%MOD;
	tmp3 = tmp1+tmp2;
	if(tmp3>=MOD) tmp3 = tmp3%MOD;
	return (tmp3);
	*/
}


int main(){
	int x;
	scanf("%d", &x);

	int happy=0;
	int tmp= x/500;
	happy += tmp*1000;
	x -= tmp*500;
	happy += (x/5)*5;
	printf("%d\n", happy);
	
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
import collections
import itertools
 
def main():
    input = sys.stdin.readline
    h, w = map(int, input().split())
    ch, cw = map(lambda x:int(x) - 1, input().split())
    dh, dw = map(lambda x:int(x) - 1, input().split())
    s = [list(input().rstrip()) for _ in range(h)]
    
    que = collections.deque()
    que.append((ch, cw))
    cost = [[float("INF")] * w for _ in range(h)]
    cost[ch][cw] = 0
    
    while que:
        py, px = que.popleft()
        for dy, dx in itertools.product(range(-2, 3), repeat = 2):
            ny, nx = py + dy, px + dx
            if 0 <= ny < h and 0 <= nx < w and s[ny][nx] == ".":
                if dy == dx == 0:
                    continue
                if (dy, dx) in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
                    if cost[ny][nx] > cost[py][px]:
                        cost[ny][nx] = cost[py][px]
                        que.appendleft((ny, nx))
                else:
                    if cost[ny][nx] > cost[py][px] + 1:
                        cost[ny][nx] = cost[py][px] + 1
                        que.append((ny, nx))
                        
    if cost[dh][dw] == float("INF"):
        print(-1)
    else:
        print(cost[dh][dw])
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 145584
import numpy as np
import sys

input = sys.stdin.readline

N,M = map(int,input().split())

cnt = [1]*(M+1)
cnt[0] = 0

res = M
for _ in range(N):
    a = list(map(int,input().split()))
    a = a[1:]
    for x in range(1,M+1):
        if x not in a and cnt[x] == 1:
            cnt[x] = 0
            res-=1

print(res)


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

int main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    int n = N;
    vector<int> v(n), w(n);
    for (int i = 0; i < N; i++)
        cin >> v[i], --v[i];
    for (int i = 0; i < N; i++)
        cin >> w[i];

    ll ans = -1e18;
    for (int i = 0; i < n; i++)
    {
        vector<int> temp;
        int p = v[i];
        ll sum = 0, max_sum = w[p];
        ll sum_cycle = 0;
        while (p != i)
        {
            temp.push_back(w[p]);
            sum_cycle += w[p];
            max_sum = max(max_sum, sum_cycle);
            p = v[p];
        }
        temp.push_back(w[i]);
        sum_cycle += w[i];
        max_sum = max(max_sum, sum_cycle);
        int len = temp.size();
        if (sum_cycle <= 0)
            sum = max_sum;
        else
        {
            int number_cycle = K / len;
            int rem = K - number_cycle * len;
            ll temp_sum = 0;
            ll maxx = 0;
            for (int t = 0; t < rem; t++)
            {
                temp_sum += temp[t];
                maxx = max(temp_sum, maxx);
            }
            sum += maxx + sum_cycle * number_cycle;
            ll next_sum = 0;
            if (number_cycle > 1)
            {
                next_sum = (number_cycle - 1) * sum_cycle;
                next_sum += max_sum;
            }
            sum = max(sum, next_sum);
        }
        ans = max(sum, ans);
    }
    cout << ans;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll n,m,p;
const ll maxn=2505;
vector<tuple<ll,ll,ll>> es;
ll dist[maxn];

vll G[maxn], rG[maxn];
bool reachable[maxn], rReachable[maxn];
void dfs(ll v){
  reachable[v]=true;
  for(auto nv: G[v]){
    if(reachable[nv]) continue;
    dfs(nv);
  }
}
void rdfs(ll v){
  rReachable[v]=true;
  for(auto nv: rG[v]){
    if(rReachable[nv]) continue;
    rdfs(nv);
  }
}

bool bellmanford(ll s){
  fill(dist,dist+n,LINF);
  dist[s]=0;
  bool ok[n];
  rep(i,n) ok[i]=reachable[i]&&rReachable[i];
  bool update=true;
  ll cnt=0;
  while(update){
    update=false;
    for(auto e: es){
      ll a,b,c;
      tie(a,b,c)=e;
      if(!ok[a]||!ok[b]) continue;
      if(chmin(dist[b],dist[a]+c)) update=true;
    }
    if(cnt>=n){
      return true;
    }
    cnt++;
  }
  return false;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m>>p;
  rep(i,m){
    ll a,b,c; cin>>a>>b>>c;
    a--,b--; c-=p;
    es.emplace_back(a,b,-c);
    G[a].push_back(b);
    rG[b].push_back(a);
  }
  dfs(0);
  rdfs(n-1);
  if(bellmanford(0)){
    cout<<-1<<endl;
  }else{
    ll ans=-dist[n-1];
    if(ans<0) cout<<0<<endl;
    else cout<<ans<<endl;
  }
}

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

#define pii pair<int,int>

int main() {
  int n;
  while(cin>>n,n) {
    vector<pii> v;
    for (int i=0;i<n;i++) {
      int a, b;
      cin >> a >> b;
      v.push_back(pii(b,a));
    }
    sort(v.begin(),v.end());
    int x=0;
    int i;
    for (i=0; i<n; i++) {
      x += v[i].second;
      if (x>v[i].first) break;
    }
    if (i==n)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 0
from operator import mul
from functools import reduce
 
N = int(input())
A = list(map(int,input().split()))
 
def cmb(n, r):
    if n < r:  return 0
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

dic = {}
for i in range(N):
    if A[i] in dic:  dic[A[i]] += 1
    else:  dic[A[i]] = 1
        
sum_ = 0
for i in dic: sum_ += cmb(dic[i], 2)

    
for i in range(N):
    ans = sum_ - (dic[A[i]] - 1)
    print(ans)

Measured memory_bytes: 111800
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)










int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
        a[i] %= k;
    }
    REP(i, n - 1){
        a[i + 1] += a[i];
        a[i + 1] %= k;
    }
    map<ll, ll> mp;
    mp[1] = 1;
    ll ans = 0;
    REP(i, n){
        if(i >= k - 1){
            if(i == k - 1){
                mp[1]--;
            }
            else{
                ll idx = i - k;
                mp[((ll)1e9 * k + a[idx] - idx) % k]--;
            }
        }
        ans += mp[((ll)1e9 * k + a[i] - i) % k];
        mp[((ll)1e9 * k + a[i] - i) % k]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 14336
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (b) - 1;i >=a;--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}


using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

int clamp(int n, int a, int b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

int Fib[100001];

int fib(int N) {
    if (Fib[N] > 0)return Fib[N];
    if (N == 0 || N == 1)return Fib[N] = 1;
    return Fib[N] = (fib(N - 1) + fib(N - 2)) % mod;
}

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

    int N, M;
    cin >> N >> M;

    vector<vector<int>> Switch(N);
    REP(i, M) {
        int k;
        cin >> k;
        REP(j, k) {
            int input;
            cin >> input;
            input--;
            Switch[input].emplace_back(i);
        }
    }

    vector<int> p(M);
    cin >> p;

    int ans = 0;
    //スイッチの数分ループ
    REP(i, pow(2, N)) {
        //押された回数記憶
        map<int, int> m;
        REP(j, N) {
            //スイッチが押されている
            if (i & (1 << j)) {
                REP(k, Switch[j].size()) {
                    m[Switch[j][k]]++;
                }
            }
        }

        bool flag = true;
        REP(j, M) {
            if (m[j] % 2 != p[j]) {
                flag = false;
            }
        }
        if (flag) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
   cin >> s;
   if(s=="Sunny") printf("Cloudy");
   if(s=="Rainy") printf("Sunny");
   if(s=="Cloudy") printf("Rainy");
    return 0;
}


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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == (b + c) || b == (a + c) || c == (a + b)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	long long a, b, k;
	cin>>a>>b>>k;
	if (a <= k) {
		k -= a;
		a = 0;
		if (b <= k) {
			k -= b;
			b = 0;
		} else b -=k;
	} else a -=k;
	cout<<a<<" "<<b;
}


Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import sys
import math

y =input()
x = int(y)
num = 0
a = []
n=3
l = ["3","5","7","9"]
list = [["3","5","7"],["3","7","5"],["5","3","7"],["5","7","3"],["7","5","3"],["7","3","5"]]
s = [357,375,537,573,753,735]
for i in range(6):
    if s[i] <= x :num+=1



def rup(b,n):
    b[n] = '3'
    p = l.index(b[n-1])
    b[n-1] = l[p + 1]
    if b[n-1] == '9':
        b = rup(b, n-1)
    return b
st =0
b = []
d = []
while x >= pow(10,n):
    b = []
    for i in range(n+1):
        b.append('3')
    while "3" in b or "5" in b:
  #      st+=1
        p = l.index(b[n])
        b[n] = l[p+1]
        if b[n] == '9':
            b = rup(b,n)
        c = b
        if "3" in b and "5" in b and "7" in b:
 #           print(b)
            a = ''.join(b)
            if int(a) <= x:
                num += 1
 #               print(a)
    n+=1

print(num)


Measured memory_bytes: 5596
import math
x, k, d = [int(i) for i in input().split()]
def f(i):
    return int(math.fabs(x + (2 * i - k) * d))
def ts(l, r):
    while l + 3 <= r:
        m1 = l + (r - l) // 3
        m2 = r - (r - l) // 3
        if f(m1) < f(m2):
        	r = m2
        elif f(m1) > f(m2):
        	l = m1
        else:
            l = m1
            r = m2
    sol = f(r)
    for i in range(l, r):
      sol = min(sol, f(i))
    return sol
print(ts(0, k))

Measured memory_bytes: 9212
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

result = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    discount = a[x-1] + b[y-1] - c
    result = min(result, discount)

print(result)

Measured memory_bytes: 24768
N = int(input())
A = list(map(int,input().split()))
Sum = 0
Min = float("inf")
cnt = 0
zero = 0

for i in A:
    Min = min(Min,abs(i))
    Sum  += abs(i)
    if i < 0:
        cnt += 1
    elif i == 0:
        zero += 1

if cnt % 2 == 0:
    print(Sum)
elif zero > 0:
    print(Sum)
else:
    print(Sum-2*Min)

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

int main(){
  long long a,b,n;
  cin >> a >> b >> n;
  long long x=min(b-1,n);
  long long ans = 0;
  long long i=1;
     
    long long tmp = floor(a*x/b) - a*floor(x/b);
    ans = max(ans,tmp);
    i ++;
    x = b*i-1;
  
  cout << ans << endl;
      return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
ll n, k, arr[100005], dp[100005];
//multiset<ll> s;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> k;
	for (ll i = 1; i <= n; i++)cin >> arr[i];
	if (k >= n){
		cout << arr[n]-arr[1]; return 0;
	}
	//for (ll i = 1; i <= mini; i++)s.insert(arr);
	for (ll i = 2; i <= n; i++)dp[i] = 1e18;
	for (ll i = 2; i <= n; i++){
		for (ll j = max(i-k, 1ll); j < i; j++){
			dp[i] = min(abs(arr[i]-arr[j])+dp[j], dp[i]);
		}
	}
	cout << dp[n];
}


Measured memory_bytes: 1792
<?php
[$N, $M, $K] = ints();
$A = ints();
$B = ints();
$A = array_reverse($A);
$C = array_merge($A,$B);
$sum = 0;
$j = 0;
$max = -1;
foreach($C as $i => $c){
  $sum += $c;
  while($sum > $K){
    $sum -= $C[$j] ?? 0;
    $j++;
  }
  if($i >= count($A)-1 && $j <= count($A)){
    chmax($max, $i-$j);
  }
}
echo $max+1;

function ints($n = false){
  if($n===false){
    return array_map('intval',explode(' ',trim(fgets(STDIN))));
  }else{$ret = [];for($i = 0; $i < $n; $i++)foreach(array_map('intval',explode(' ',trim(fgets(STDIN)))) as $j => $v)$ret[$j][] = $v;return $ret;}
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}


Measured memory_bytes: 50680
#include<bits/stdc++.h>
using namespace std;
int dp[5][50][50][1 << 12];
int H, W, K;
char mas[50][50];
int dy[] = { 0, 1, 0, -1}, dx[] = { 1, 0, -1, 0};
int mask;
 
int getdir(int bit, int i){
  return bit >> (i << 1) & 3;
}
bool isover(int y, int x){
  return y < 0 || y >= H || x < 0 || x >= W;
}
bool check(int y, int x, int bit){
  if(mas[y][x] == '.') return false;
  for(int i = 0, my = y, mx = x; i < 2 * K; i++){
    my -= dy[getdir( bit, i)], mx -= dx[getdir( bit, i)];
    if(my == y && mx == x) return false;
  }
  return true;
}
int main()
{
  cin >> H >> W >> K;
  mask = (1 << (K * 2 * 2)) - 1;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> mas[i][j];
    }
  }
  fill_n( ***dp, 5 * 50 * 50 * 1 << 12, -1);
  dp[K][0][0][0] = 0;

  for(int mul = K ; mul >= 0; mul--){
    for(int y = 0; y < H; y++){
      for(int x = 0; x < W; x++){
        for(int bit = 0; bit < 1 << (K * 4) ; bit++){ // 前の街
          if(dp[mul][y][x][bit] == -1 || mas[y][x] == '#') continue;
          int cost = check( y, x, bit) * (mas[y][x] - '0');
          for(int i = 0; i < 4; i++){
            int ny = y + dy[i], nx = x + dx[i];
            if(isover(ny,nx) || mas[ny][nx] == '#') continue;
            if(mul == 0 && i >= 2) break;
            int& next = dp[mul - (i > 1)][ny][nx][(bit << 2 | i) & mask];
            next = max( next, dp[mul][y][x][bit] + cost);
          }
        }
      }
    }
  }
  cout << *max_element(dp[0][H-1][W-1],dp[0][H-1][W]) << endl;
  return 0;
}

Measured memory_bytes: 201160
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> G[214514];
int ans[214514];
signed main(){
  int h,w,n;
  cin>>h>>w>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++) cin>>a[i]>>b[i];
  for(int i=0;i<n;i++) G[a[i]-1].push_back(b[i]-1);
  deque<int> ev,od;
  for(int i=0;i<w;i+=2) ev.push_back(i);
  for(int i=1;i<w;i+=2) od.push_back(i);
  for(int i=0;i<h;i++){
    int k;
    for(int j=0;j<(int)G[i].size();j++){
      if(i%2==0){
	//cout<<ev[G[i][j]/2]<<"-"<<od[G[i][j]/2]<<endl;
	swap(ev[G[i][j]/2],od[G[i][j]/2]);
	//cout<<ev[G[i][j]/2]<<"-"<<od[G[i][j]/2]<<endl;
	//cout<<G[i][j]/2<<" "<<G[i][j]/2<<endl;
      }else{
	//cout<<ev[G[i][j]/2]<<"-"<<od[G[i][j]/2]<<endl;
	swap(ev[G[i][j]/2],od[G[i][j]/2+1]);
	//cout<<ev[G[i][j]/2]<<"-"<<od[G[i][j]/2+1]<<endl;
	//cout<<G[i][j]/2<<" "<<G[i][j]/2+1<<endl;
      }
    }
    if(i%2){
      k=od.front();
      od.pop_front();
      ev.push_front(k);
    }
    if((w+i)%2){
      k=ev.back();
      ev.pop_back();
      od.push_back(k);
    }
  }
  int cnt=0;
  if(h%2){
    while(!ev.empty()||!od.empty()){
      if(!od.empty()){
	//cout<<od.front()+1<<endl;
	ans[od.front()]=++cnt;
	od.pop_front();
      }
      if(!ev.empty()){
	//cout<<ev.front()+1<<endl;
	ans[ev.front()]=++cnt;
	ev.pop_front();
      }
    }
  }else{
    while(!ev.empty()||!od.empty()){
      if(!ev.empty()){
	//cout<<ev.front()+1<<endl;
	ans[ev.front()]=++cnt;
	ev.pop_front();
      }
      if(!od.empty()){
	//cout<<od.front()+1<<endl;
	ans[od.front()]=++cnt;
	od.pop_front();
      }
    }
  }
  for(int i=0;i<cnt;i++) cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 18372
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char s[1000000];
	scanf("%s",s+1); int n = strlen(s+1), ans = n; 
	for(int i=1;i<=n-1;i++) {
		if(s[i]!=s[i+1])
			ans = min(ans,max(i,n-i));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
import numpy as np
import sys
from itertools import chain, combinations

N, M, X = [int(n) for n in input().split()]

matrix = np.zeros((N,M+1))
for i in range(N):
    matrix[i] = np.array([int(n) for n in input().split()])

total = np.sum(matrix[:,1:],axis=0)
if not all(i >= X for i in total):
    print(-1)
    sys.exit(0)

def checkthresh(A, thresh):
    return all(i >= thresh for i in A)

def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(1,len(s)+1))

cost = N*10**5
for subset in powerset(range(N)):
    sum_subset = np.zeros((1,M+1))
    for i in subset:
        sum_subset += matrix[i,:]
    sum_subset = sum_subset[0]
    if checkthresh(sum_subset[1:], X):
        cost = min(cost, sum_subset[0])

print(int(cost))


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

vector<int> g[2010];
int n, k;

void dfs(int v, int p, int d, vector<bool>& visited)
{
    if (d>k/2) return;
    visited[v]=true;
    for(int u: g[v]) if (u!=p) dfs(u, v, d+1, visited);
}

int main()
{
    cin>>n>>k;
    for(int i=0; i+1<n; ++i) {
        int a, b; cin>>a>>b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int res=n;
    for(int i=0; i<n; ++i) {
        vector<bool> visited(n);
        dfs(i, -1, 0, visited);
        if (k%2) dfs(g[i][0], -1, 0, visited);
        res=min<int>(res, count(begin(visited), end(visited), false));
    }
    cout<<res<<endl;
}


Measured memory_bytes: 384