akhauriyash/Code-Regression huggingface dataset:
fn main(){
    let n: usize = read();
    for i in 0..n {
        let arg = read_vec();
        q(arg[0], arg[1], arg[2], arg[3]);
    }
}

fn q(a: u64, b: u64, c: u64, d: u64){
    let mut result = "Yes";
    if a < b || d < b {
        result = "No";
    } else if c >= b - 1  {
        result = "Yes";
    } else {
        let gcd = euclidean_algo(b, d%b);
        let a_ = a % b;
        
        let max_zaiko = if gcd == 0 {a_} else {(b - 1) - (b - 1 - a_) % gcd};
        if max_zaiko > c {
            result = "No";
        }
    }
    println!("{}", result);
}

fn euclidean_algo(a: u64, b: u64) -> u64 {
    if b == 0 {
        return 0;
    }
    let d = a % b;
    if d == 0 {
        return b;
    } else {
        return euclidean_algo(b, d);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

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

using namespace std;

using P = pair<int, bool>;

int main() {
    vector<vector<P>> A(3, vector<P>(3));
    for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++){
        cin >> A[i][j].first;
        A[i][j].second = false;
    }
    int N; cin >> N;
    vector<int> B(N);
    for (auto& b:B) {cin >> b;}

    for (auto& b:B) {
        for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++) {
            if (b == A[i][j].first) A[i][j].second = true;
        }
    }

    for (int i = 0; i < 3; i++) {
        if (
            (A[i][0].second && A[i][1].second && A[i][2].second) ||
            (A[0][i].second && A[1][i].second && A[2][i].second) ||
            (A[0][0].second && A[1][1].second && A[2][2].second) ||
            (A[2][0].second && A[1][1].second && A[0][2].second)
        ){
            cout << "Yes" << endl;
            return 0;
        } 

    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  string a,b;
  cin>>a>>b;
  if(a>b) cout<<">"<<endl;
  else if(a==b) cout<<"="<<endl;
  else cout<<"<"<<endl;

}

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


Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

ll comb(ll n, ll k) {
    ll nume = 1;
    ll deno = 1;
    rep(i, k) {
        nume *= (n - i);
        deno *= (i + 1);
    }
    return nume / deno;
}

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

    vector<string> s(N);
    rep(i, N) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());

    map<string, ll> m;
    rep(i, N) { m[s[i]]++; }

    ll ans = 0;
    for (auto x : m) {
        if (x.second > 1) {
            ans += comb(x.second, 2LL);
        }
    }
    debug(s, ans, m);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

map<int, int> mp;
vector<pair<int, int>> vp;

int main()
{
  int n, k;
  cin>>n>>k;
  rep(i, 0, n)
  {
    int a;
    cin>>a;
    mp[a]++;
  }
  for(auto p: mp)
  {
    vp.pb({p.s, p.f});
  }
  sort(vp.begin(), vp.end());
  int ans = 0;
  if(vp.size() > k)
  {
    int i = 0;
    int z = vp.size() - k;
    while(z--)
    {
      ans += vp[i].f;
      //cout<<vp[i].s<<" "<<vp[i].f<<endl;
      i++;
    }
  }
  cout<<ans<<endl;
}


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

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

    if (k  <= a) {
        cout << k << endl;
        return 0;
    }

    int ans = 0;
    if (k  > a) {
        k -= a;
        ans = a;

        if (k > b) {
            k -= b;
        }else {
            cout << ans << endl;
            return 0;
        }

        ans -= k; 
    }

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

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

int gcd(int a, int b) {
	if(a>b)swap(a,b);
	int c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}

int main(void){
	int a,b;
	cin >> a >> b;
	cout << gcd(a,b) << endl;
	
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
#define rep(i,N) for(int i=0;i<(long)N;i++)
const long LINF=0x7fffffffffffffff;
int asc(const int*a,const int*b){return *a-*b;}
long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main(void)
{
  int A[200000]={},N=IN(),i=0,m=0,p=0,z=0,temp;
  long K=IN(),low=-LINF/2,mid,high=LINF/2,count;
  rep(i,N){A[i]=IN();if(A[i]<0)m++;else if(A[i]>0)p++;else z++;}
  qsort(A,N,sizeof(int),(int(*)(const void*,const void*))asc);
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;else temp=0;
  if(K<=1l*m*p)high=1l;else low=-1l;
  while(high-low>1)
  {
    mid=(low+high)/2,count=0;
    if(!mid)count=1l*m*p;
    else if(mid>0)
    {
      count=1l*m*p+1l*z*(m+p)+1l*z*(z-1)/2;temp=N-1;i=m+z;
      while(i<N)
      {
        while(1l*A[temp]*A[i]>=mid){temp--;}
        if(temp>i)count+=temp-i++;else break;
      }
      temp=0;i=m-1;
      while(i>=0)
      {
        while(1l*A[temp]*A[i]>=mid){temp++;}
        if(temp<i)count+=i-temp,i--;else break;
      }
    }
    else
    {
      temp=m-1;i=N-1;
      while(i>=m+z)
      {
        while(temp>=0&&1l*A[temp]*A[i]>=mid){temp--;}
        if(temp>=0){count+=temp+1;}i--;
      }
    }
    if(count<K)low=mid;else high=mid;
  }
  return printf("%ld\n",low),0;
}

Measured memory_bytes: 2972
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
  int n;cin>>n;
  int ans=1;
  rep(i,3){
    ans*=n;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n, t, e;
	cin >> n >> t >> e;
	int a[100];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int k1 = t - e, k2 = t + e;
	for (int i = 0; i < n; i++) {
		int c = t%a[i];
		int t2 = t - c;
		if (t2 >= k1&&t2 <= k2) {
			cout << i + 1 << endl;
			goto stop;
		}
		t2 += a[i];
		if (t2 >= k1&&t2 <= k2) {
			cout << i+1 << endl;
			goto stop;
		}
	}
	cout << -1 << endl;
stop:;
}

Measured memory_bytes: 3088
import Foundation

func main() {
    let n = Int(readLine()!)!
    let stones = Array(readLine()!)
    
    var rNum = 0
    var NotMovedRNum = 0
    
    for i in 1 ... n {
        let str = stones[i-1]
        if (str == "R") {
            rNum += 1
        } 
    }
    
    if (rNum == 0) {
        print(rNum)
        return
    }
    
    for i in 1 ... rNum {
        let str = stones[i-1]
        if (str == "R") {
            NotMovedRNum += 1
        } 
    }

    print(rNum -  NotMovedRNum)
}

main()

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

int N;
int a[2003];
int memo[2003][2];

int dfs(int op_hand, int is_x){
  if(memo[op_hand][is_x] != -1) return memo[op_hand][is_x];
  int ret = abs(a[op_hand] - a[N - 1]);
  for(int i=op_hand + 1;i<N-1;i++){
    if(is_x){
      ret = max(ret, dfs(i, 0));
    }else{
      ret = min(ret, dfs(i, 1));
    }
  }
  memo[op_hand][is_x] =	ret;
  return ret;
}

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

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

  memset(memo, -1, sizeof(memo));
  cout << dfs(0, 1) << endl;

  return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,m,n) for(int i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;

int main(){
  int n;
  cin >> n;
  vector<string>s(n);
  rep(i,n)cin >> s[i];
  sort(s.begin(),s.end());
  int sum=n;
  rep(i,n-1){
    if(s[i+1]==s[i])sum--;
  }
  cout << sum;
}


Measured memory_bytes: 9596
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
using namespace std;
#define max_n 100
#define INF 100000000



int main()
{
    char w[max_n];
    scanf("%s",w);
    size_t t=strlen(w);
    int count=0;
    for(int i=0;i<t-1;i++){
        if(w[i]=='0') continue;
        for(int j=i+1;j<t;j++){
            if(w[i]==w[j]){
                w[j]='0';
                count++;
            }
        }
        count++;
        if(count%2!=0) break;
    }
    if(count%2==0&&count!=0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int main(){
ll n,k;
cin >> n >> k;
double sum;
for(int i=1;i<=n;i++){
    ll now = i;
    double p;
    if(now>=k) p=1;
    else{
    p=1;
        while(now<k){
            now*=2;
            p/=2;
        }
    }
    sum+=p;
}
double ans = sum/n;
printf("%.10lf",ans);
return 0;
}

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

#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= b; --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second

const long long BIG = 1000000000000000000LL;

typedef long long ll;
typedef long double ld;

void cpr(string s, vector<int> v)
{ int i = 0; for (char c : s) { if (c == '$') cout << v[i++]; else cout << c; } cout << '\n'; }

void cpr(string s) { cpr(s, {}); }

void solve();
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	int rep = 0;
	int cb = 0;
	form(i, n) {
		if (s[i] == 'B') ++cb;
		else {
			rep += cb;
		}
	}
	cout << rep << "\n";
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n,a,b,c,d; cin>>n>>a>>b>>c>>d;
    rep(i,n){
        //iこmin
        if(-d*i + (n-1-i)*c <= b-a&& b-a <= -i*c + (n-1-i)*d ) {cout<<"YES"<<endl; return 0;}
    }
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
ll gcd (ll a, ll b) {
return b ? gcd (b, a % b) : a;
}

int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll k;
 	cin>>k;
 	ll ans=0;
 	for(ll i=1;i<=k;i++)
 	{
 		for(ll j=1;j<=k;j++)
 		{
 			for(ll l=1;l<=k;l++)
 			{
 				ans+=gcd(l,gcd(i,j));
 			}
 		}
 	}
 	cout<<ans<<endl;
    return 0;
}


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

int main() {
    int num_query; cin >> num_query;
    int command, x; string key;
    map<string, int> M;
    
    for (int i = 0; i < num_query; ++i) {
        cin >> command >> key;
        
        switch (command) {
            case 0:
                cin >> x;
                M[key] = x;
                break;
            case 1:
                cout << M[key] << endl;
                break;
            case 2:
                M[key] = 0;
                break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 27840
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define EPS 1e-9
#define SYNC std::ios::sync_with_stdio(false)
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int n, m, a, b;
ll c;
ll dist[1000 + 5];
vector<vector<pair<int,ll> > > graph(1000 + 5);
int main() {
	SYNC;
	cin >> n >> m;
	FOR0(i, m) {
		cin >> a >> b >> c;
		graph[a].pb(mp(b,-c));
	}
	FOR(u,1,n+1) dist[u] = 100000000000000000; dist[1] = 0;
	FOR(j,0,n-1) {
		FOR(u,1,n+1) {
			repi(i, graph[u]) dist[i->ff] = min(dist[i->ff], dist[u]+(ll)i->ss);
		}
	}
	ll val = dist[n];
	FOR(j,0,n-1) {
		FOR(u,1,n+1) {
			repi(i, graph[u]) dist[i->ff] = min(dist[i->ff], dist[u]+(ll)i->ss);
		}
	}
	if(dist[n] != val) cout << "inf" << endl;
	else cout << -dist[n] << endl;
}

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

int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    if(y%2){
        printf("No\n");
    }else if(y/2-x<0 || 2*x-y/2<0){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define scn(var)         cin >> var;
#define pYes()           prt("Yes")
#define pNo()            prt("No")
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"
//----------------------------------------------------------------

int main(void) {
  int k;
  cin >> k;
  priority_queue<ll, vector<ll>, greater<ll>> q;

  rep(i,9){
    q.push(i+1);
  }

  ll tmp=0;
  while(k){
    tmp=q.top();
    if(tmp%10!=0) q.push(tmp*10+(tmp%10-1));
    q.push(tmp*10+(tmp%10));
    if(tmp%10!=9) q.push(tmp*10+(tmp%10+1));
    k--;
    q.pop();
  }

  prt(tmp);
}


Measured memory_bytes: 2420
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

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

void solve();

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

    solve();
}

void solve() {
    ll n;
    std::cin >> n;

    std::unordered_map<str, ll> umap;
    for (ll i = 0; i < n; i++) {
        str s; std::cin >> s;
        umap[s]++;
    }

    std::cout << "AC x " << umap["AC"] << '\n';
    std::cout << "WA x " << umap["WA"] << '\n';
    std::cout << "TLE x " << umap["TLE"] << '\n';
    std::cout << "RE x " << umap["RE"] << '\n';
}


Measured memory_bytes: 3660
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll M1,D1,M2,D2;
	cin>>M1>>D1>>M2>>D2;
	if(M2==(M1+1) )
	{
	    if(D2==1)
		    cout<<1;
		else
		    cout<<0;
	}
	else
	{
		cout<<0;
	}
    return 0;
}


//252908XL

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -100000007;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]) * 6.4 + c[j] * 5.2;
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		cout << p << "\n"; l[p] = i;
	}
}

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

int mod = 1e9+7;

void solve()
{
    int n; cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    ll ans = 0, ss = 0;
    for (int i = n - 1; i >= 0; --i) {
        ans = (ans + (v[i] * ss % mod)) % mod;
        ss = (ss + v[i]) % mod;
    }
    cout << ans << '\n';
}

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

Measured memory_bytes: 3996
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long 
using namespace std;

signed main() {
	int H,W;
	cin >> H >> W;
	vector<vector<char>> vec(H + 2,vector<char>(W + 2));
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			cin >> vec.at(i + 1).at(j + 1);
		}
	} 
	vector<vector<char>> answer(H,vector<char>(W));
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			if(vec.at(i + 1).at(j + 1) == '#') {
				answer.at(i).at(j) = '#';
			}
			else {
			int count = 0;
			if(vec.at(i).at(j) == '#') {
				count++;
			}
			if(vec.at(i).at(j + 1) == '#') {
				count++;
			}
			if(vec.at(i).at(j + 2) == '#') {
				count++;
			}
			if(vec.at(i + 1).at(j) == '#') {
				count++;
			}
			if(vec.at(i + 1).at(j + 2) == '#') {
				count++;
			}
			if(vec.at(i + 2).at(j) == '#') {
				count++;
			}
			if(vec.at(i + 2).at(j + 1) == '#') {
				count++;
			}
			if(vec.at(i + 2).at(j + 2) == '#') {
				count++;
			}
			answer.at(i).at(j) = count + '0';
			}			
		} 
	}
	for(int i = 0;i < H;i++) {
		for(int j = 0;j < W;j++) {
			cout << answer.at(i).at(j);
			if(j == W - 1) {
				cout << endl;
			}
		}
	}
}

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

bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  int n;
  cin>> n;
  int b[n-1];
  int a[n];
  for(int i=0 ; i<n-1 ; i++){
    cin >>b[i];
  }
  a[0]=b[0];
  int sum =a[0];
  for(int i=1 ; i<n-1 ; i++){
    a[i] = b[i-1];
    if(a[i]>b[i]){
      a[i] = b[i];
    }
    sum += a[i];
  }
  sum += max(a[n-2],b[n-2]);
  cout << sum <<endl;
}

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

constexpr int MOD = 1e9 + 7;

int mod_pow(int x, int n, int m) {
  if (n == 0)
    return 1;
  int res = mod_pow(x * x % m, n / 2, m);
  if (n % 2 == 1)
    res = res * x % m;
  return res;
}

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

  int ans = 0;
  for (int i = 0; i < 60; i++) {
    int bit = (1LL << i);

    int cnt0 = 0, cnt1 = 0;
    for (int j = 0; j < N; j++) {
      if ((A[j] & bit)) {
        cnt1++;
      } else {
        cnt0++;
      }
    }

    ans += ((bit % MOD * cnt1) % MOD * cnt0) % MOD;
    ans %= MOD;
  }

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


Measured memory_bytes: 2560
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] map = new char[h][w];
        for(int i = 0; i < h; i++){
            map[i] = sc.next().toCharArray();
        }
        ArrayList<Integer> delCols = new ArrayList<Integer>();
        ArrayList<Integer> delRows = new ArrayList<Integer>();
        for(int i = 0; i < h; i++){
            boolean bool = true;
            for(int j = 0; j < w; j++){
                if(map[i][j] == '#'){
                    bool = false;
                    break;
                }
            }
            if(bool) delRows.add(i);
        }
        for(int i = 0; i < w; i++){
            boolean bool = true;
            for(int j = 0; j < h; j++){
                if(map[j][i] == '#'){
                    bool = false;
                    break;
                }
            }
            if(bool){
                delCols.add(i);
            }
        }
        for(int i = 0; i < h; i++){
            if(delRows.contains(i)){
                continue;
            }
            for(int j = 0; j < w; j++){
                if(delCols.contains(j)){
                    continue;
                }
                System.out.print(map[i][j]); 
            }
            System.out.println();
        }
        
    }
}


Measured memory_bytes: 22996
#include<iostream>
#include<cstdio>
//#include<cmath>
//#include<algorithm>
//#include<cstring>
//#include<map>
using namespace std;
inline int read()
{
    int p=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){p=p*10+c-'0';c=getchar();}
    return f*p;}
int main()
{
	int x=read();
	cout<<48-x;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int graph[100][100];

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

    rep(i, n) {
        int u, k;  
        cin >> u >> k;
        u--;
        rep(j, k) {
            int v;
            cin >> v;
            v--;
            graph[u][v] = 1;
        }
    }

    rep(i, n) {
        rep(j, n) {
            if(j) {
                cout << " ";
            }
            cout << graph[i][j];
        }
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  string s,t,u;
  int a,b;
  cin>>s>>t>>a>>b>>u;
  if (s == u){
    cout << a -1 <<" "<<b<< endl;
  }else{
    cout <<a<<" "<< b -1 << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<climits>
#include<cmath>
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

struct Edge{
	int cost;
	int x,y;
	bool asi; // true:left

	Edge(int c,int xx,int yy,bool a) : cost(c), x(xx), y(yy), asi(a){}

	bool operator <(const Edge &e) const
	{
		return cost < e.cost;
	}
	bool operator >(const Edge &e) const
	{
		return cost > e.cost;
	}
};

int mv[61][31];
int w,h;

vector<pii> start;
vector<pii> goal;

int solve(){
	vvvi dist(w , vvi(h, vi(2, INT_MAX)));
	priority_queue<Edge, vector<Edge>, greater<Edge> > que;
	for(int i=0;i<start.size();i++){
		dist[start[i].first][start[i].second][0] = 0;
		dist[start[i].first][start[i].second][1] = 0;
		Edge e1(0,start[i].first,start[i].second,true);
		Edge e2(0,start[i].first,start[i].second,false);
		que.push(e1);
		que.push(e2);
	}
	
	while(!que.empty()){
		Edge e = que.top();
		que.pop();

		for(int i=-2;i<=2;i++){
			for(int j=1;j<=3;j++){
				int dir = abs(i) + j;
				if(dir > 3){
					continue;
				}
				int nj = j;
				if(!e.asi){
					nj *= -1;
				}
				int yy = e.y+i;
				int xx = e.x+nj;
				if(xx < 0 || xx >= w || yy < 0 || yy >= h){
					continue;
				}
				if(mv[e.y+i][e.x+nj] == -1){
					continue;
				}

				int ncost = e.cost + mv[e.y+i][e.x+nj];
				int nasi = !e.asi;
				if(ncost < dist[e.x+nj][e.y+i][nasi]){
					dist[e.x+nj][e.y+i][nasi] = ncost;
					Edge ne(ncost,e.x+nj,e.y+i,nasi);
					que.push(ne);
				}
			}
		}
	}

	int ans = INT_MAX;
	for(int i=0;i<goal.size();i++){
		ans = min(ans,dist[goal[i].first][goal[i].second][0]);
		ans = min(ans,dist[goal[i].first][goal[i].second][1]);
	}

	if(ans == INT_MAX){
		ans = -1;
	}
	
	return ans;
}

int main(){
	while(true){
		start.clear();
		goal.clear();
		cin >> w >> h;
		if(w == 0){
			break;
		}

		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				char buf;
				cin >> buf;
				if(buf == 'S'){
					start.push_back(make_pair(j,i));
					mv[i][j] = 0;
				}else if(buf == 'T'){
					goal.push_back(make_pair(j,i));
					mv[i][j] = 0;
				}else if(buf == 'X'){
					mv[i][j] = -1;
				}else{
					mv[i][j] = buf - '0';
				}
			}
		}

		cout << solve() << endl;
	}
}

Measured memory_bytes: 1344
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int ds(int x) {
  int ret = 0;
  while(x > 0) {
    ret += x % 10;
    x /= 10;
  }
  return ret;
}

int main() {
  int N;
  cin >> N;
  int mi = 1 << 30;
  for (int i = 1; i < N; i++) {
    mi = min(mi, ds(i) + ds(N - i));
  }
  cout << mi << endl;
  return 0;
}

Measured memory_bytes: 256
# from math import factorial,sqrt
# from itertools import permutations as permus
from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
a,b,c,d = map(int,input().split())

def lcm(x:int, y:int)->int:
    """
    return Least common multiple (最小公倍数)
    """
    return (x * y) // gcd(x, y)

e = lcm(c,d)

if c == 1 or d ==1:
    ans = 0
else:
    ans = b-a+1
    minus1 = b//c - (a-1)//c
    minus2 = b//d - (a-1)//d
    plus = b//e - (a-1)//e
    ans = ans -minus1 -minus2 +plus

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 5048
N = int(input())
L = [input() for _ in range(N)]

flg = False
if len(L) != len(set(L)): flg = True
for i in range(1, N):
  if flg: break
  if i != 0:
    if L[i][0] != L[i-1][-1]:
      flg = True
print ("No" if flg else "Yes")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;

#define rep(i, a, b) for (int i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int root_tree(vector<int> &v, int i)
{
    if (v[i] == i)
        return i;
    return root_tree(v, v[i]);
}
void union_tree(vector<int> &v, vector<int> &rank, int i, int j)
{
    int x = root_tree(v, i);
    int y = root_tree(v, y);
    if (rank[x] < rank[y])
        v[x] = y;
    else
        v[y] = x;
    if (rank[x] == rank[y])
        rank[x]++;
}
bool check_tree(vector<int> &v, int i, int j)
{
    if (root_tree(v, i) == root_tree(v, j))
        return true;
    return false;
}
int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n, 0);
    rep(i, 0, n - 1)
    {
        int temp;
        cin >> temp;
        v[--temp]++;
    }
    rep(i, 0, n) cout << v[i] << endl;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    char c[110][110];
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
        }
        rep(j,w){
            cout << c[i][j];
        }
        cout << endl;
        rep(j,w){
            cout << c[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import fractions


def cnt(A, B, d):
    return B // d - (A - 1) // d


A, B, C, D = map(int, input().split())
E = C * D // fractions.gcd(C, D)
res = (B - A + 1) - cnt(A, B, C) - cnt(A, B, D) + cnt(A, B, E)
print(res)



Measured memory_bytes: 5048
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	string S;
	cin >> S;
	if (S == "keyence") {
		cout << "YES";
		return 0;
	}
	for (int i = 1; i <= S.size() - 7; i++) { //何文字減らすか
		for (int j = 0; j <= S.size() - i; j++) { //最初どこ
			string s;
			for (int k = 0; k < S.size(); k++) {
				if (k >= j && k < j + i)continue;
				else s.push_back(S[k]);
			}
			if (s == "keyence") {
				cout << "YES";
				return 0;
			}
		}
	}
	cout << "NO";
}

Measured memory_bytes: 256
/*** I came, I saw, I conquered. ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
#define sc(a) cin >> a
#define pf(a) cout << a << endl
#define forIn(arr, num) for(ll i = 0; i < num; i++) cin >> arr[i];
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define mod 1000000007
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define GET_SET_BITS(a) (__builtin_popcount(a))
#define GET_SET_BITSLL(a) ( __builtin_popcountll(a))
#define GET_TRAIL_ZERO(a) (__builtin_ctz(a))
#define GET_LEAD_ZERO(a) (__builtin_clz(a))
#define GET_PARITY(a) (__builtin_parity(a))
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
void go() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
/*----------------------------------------------------------------*/
void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll ans = 1;

    ans = max({a * c, a * d, b * c, b * d});

    pf(ans);
}

int main() {
    go();
    solve();
    return 0;
}

Measured memory_bytes: 3652
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
pii A[200];//firstは行secondを列とする
int dp[200][200];//dp[i][j]:=Ai...Ajの最小スカラー積とする
int n;
int f[200][200];//最適な括弧を挿入する位置
void solve(){
	for(int i =0;i < n;i++){
		for(int j =0;j < n;j++){
			if(i==j)dp[i][j]=0;
			else dp[i][j]=INF;
		}
	}
	
	for(int k =1;k <n;k++){//鎖の数
		for(int i =0;i <n-k;i++){//どこから始めるか
			for(int j =i;j <i+k;j++){//どこに括弧を挟むか
				int tmp =A[i].first*A[j].second*A[i+k].second;
				if(dp[i][i+k] >dp[i][j]+dp[j+1][i+k]+tmp){
					dp[i][i+k]=dp[i][j]+dp[j+1][i+k]+tmp;
					f[i][i+k] =j;
				}
			}
		}
	}
}

void print(int i,int j){//解を表示する
	if(i==j){
		cout <<"A"<<i;
	}else{
		cout <<"(";
		         print(i,f[i][j]);
		         print(f[i][j]+1,j);
		         cout <<")";
}
}


int main(){
	cin>>n;
	for(int i =0;i < n;i++){
		cin>>A[i].first>>A[i].second;
	}
	solve();
	cout <<dp[0][n-1]<<endl;
	//print(0,n-1);
	return 0;
}

Measured memory_bytes: 1320
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 300050


pll a[N];
ll fac[N],ifac[N];
ll dp[N];

ll power(ll a,ll b) {
    ll res = 1;
    while(b) {
        if(b&1) res=(res*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
}

ll fun(pll x,pll y) {
    ll n,m;
    n = y.ff-x.ff; m = y.ss-x.ss;
    if(n<0 || m<0) return 0;
    ll res = ( (fac[n+m] * ifac[n] )%mod * ifac[m] )%mod;
    return res;
}

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

    fac[0] = ifac[0] = 1;
    ifr(i,1,N) fac[i] = (1ll*fac[i-1]*i)%mod;
    ifr(i,1,N) ifac[i] = power(fac[i],mod-2);
    ll h,w,n;
    cin>>h>>w>>n;
    ifr(i,0,n) cin>>a[i].ff>>a[i].ss;
    a[n] = {h,w};
    sort(a,a+n+1);
    dp[0] = fun({1,1},a[0]);
    for(int i=1;i<n+1;i++) {
        dp[i] = fun({1,1},a[i]);
        for(int j=0;j<i;j++)
            dp[i] = (dp[i] - ( dp[j] * fun(a[j],a[i]) )%mod + mod )%mod;
    }
    cout<<dp[n]<<endl;
    return 0;
}

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

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

Measured memory_bytes: 256
import numpy as np
s=input()
wayA=np.array([0,0,0,0])
wayB=np.array([0,0,0,0])
wayC=np.array([0,0,0,0])
hatena=0
for c in s:
	if c=="A":
		wayA[0]+=1
	if c=="B":
		wayB+=wayA
	if c=='C':
		wayC+=wayB
	if c=='?':
		wayC[1]+=wayB[0]
		wayC[2]+=wayB[1]
		wayC[3]+=wayB[2]
		wayB[1]+=wayA[0]
		wayB[2]+=wayA[1]
		wayA[1]+=1
		hatena+=1
ans=0
for i in range(4):
	ans+=pow(3,hatena-i)*wayC[i]
print(int(ans%1000000007))

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;

long long a[N];
map<long long, long long> h;

void solve() {
  int n; scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", a+i);
    a[i] += a[i-1];
    ++h[a[i]];
  }
  ++h[0];
  long long ans = 0;
  for (const auto &e: h) {
    if (e.second < 2) continue;
    ans += (e.second-1)*(e.second)/2;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ggr getchar();getchar();return 0;
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int a[1000000];
signed main() {
	int s, ans;
	cin >> s;
	a[0] = s;
	if (s == 4 || s == 2 || s == 1)cout << 4 << endl;
	else if (s == 8)cout << 5 << endl;
	else {
		for (int i = 1; i < 1000000; i++) {
			if (a[i - 1] % 2 == 0)a[i] = a[i - 1] / 2;
			else a[i] = a[i - 1] * 3 + 1;
			if (a[i] == 4)break;
			ans = i;
		}
		cout << ans + 5 << endl;
	}
	ggr
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int S,h,m,s,amari;
    
    scanf("%d",&S);
    
    h=S/(60*60);
    amari=S%(60*60);
    
    m=amari/60;
    s=amari%60;
    
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
    
}


Measured memory_bytes: 2120
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;

bool ary[1010][1010];
bool sag[1010][1010];
int goalx[11],goaly[11];
int main(){
	queue<pair<pair<int,int>,int> > qu;
	pair<pair<int,int>,int> pa;
	int H,W,N,YY,XX,TT,keka;
	char ch;
	keka=0;
	cin>>H>>W>>N;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>ch;
			if(ch>='1'&&ch<='9'){
				goaly[ch-'0']=i;
				goalx[ch-'0']=j;
			}
			if(ch=='S'){
				goaly[0]=i;
				goalx[0]=j;
			}
			ary[i][j]=(ch=='X');
		}
	}

	for(int sta=0;sta<N;sta++){
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				sag[i][j]=false;
			}
		}
		qu.push(make_pair(make_pair(goaly[sta],goalx[sta]),0));
		while(!qu.empty()){
			pa=qu.front();
			qu.pop();
			YY=pa.first.first;
			XX=pa.first.second;
			TT=pa.second;
			if(YY==goaly[sta+1]&&XX==goalx[sta+1]){
				//cout<<sta<<" "<<TT<<endl;//
				keka+=TT;
				while(!qu.empty())qu.pop();
				break;
			}

			if(YY>0&&!ary[YY-1][XX]&&!sag[YY-1][XX]){
				qu.push(make_pair(make_pair(YY-1,XX),TT+1));
				sag[YY-1][XX]=true;
			}
			if(YY<H-1&&!ary[YY+1][XX]&&!sag[YY+1][XX]){
				qu.push(make_pair(make_pair(YY+1,XX),TT+1));
				sag[YY+1][XX]=true;
			}
			if(XX>0&&!ary[YY][XX-1]&&!sag[YY][XX-1]){
				qu.push(make_pair(make_pair(YY,XX-1),TT+1));
				sag[YY][XX-1]=true;
			}
			if(XX<W-1&&!ary[YY][XX+1]&&!sag[YY][XX+1]){
				qu.push(make_pair(make_pair(YY,XX+1),TT+1));
				sag[YY][XX+1]=true;
			}
		}
	}
	cout<<keka<<endl;
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define oo int(1e9)
using namespace std;
int n, k;

int main() {
	cin.tie(0); ios::sync_with_stdio(0); cout.tie(0);
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	vector<int> dp(n);
	for (int i = 1; i < n; i++) dp[i] = oo;
	for (int i = 0; i < n; i++)
	    if (dp[i] < oo){
	       for (int j = 1; j <= k && i + j < n; j++)
	        dp[i + j]  = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
	    }
	cout << dp[n - 1];    
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<ll> h(n);
	rep(i, 0, n - 1)cin >> h[i];
	--h[0];
	rep(i, 1, n - 1)
	{
		if (h[i - 1] < h[i])--h[i];
	}
	string ans = "Yes";
	rep(i, 1, n - 1)
	{
		if (h[i - 1] > h[i])ans = "No";
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;


int main() {
	int w, h;
	int a = 0;
	char b = 'A';
	string s[26][26];
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s[i][j];
			if (s[i][j] == "snuke") {
				a = i + 1;
				b += j;
			}
		}
	}
	cout << b << a << endl;
}

Measured memory_bytes: 256