akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007
 
int main(){
	ll n,m;
	cin>>n>>m;
	vector<ll> va;
	vector<ll> vb;
	vector<ll> vc;
	vector<ll> vd;
	rep(i,0,n){
		ll a,b;
		cin>>a>>b;
		va.pb(a);
		vb.pb(b);
	}
	rep(i,0,m){
		ll c,d;
		cin>>c>>d;
		vc.pb(c);
		vd.pb(d);
	}
	rep(i,0,va.sz){
		ll mn = 1000000000000LL;
		rep(j,0,vc.sz){
			ll a = abs(va[i]-vc[j])+abs(vb[i]-vd[j]);
			mn = min(a,mn);
		}
		rep(j,0,vc.sz){
			ll a = abs(va[i]-vc[j])+abs(vb[i]-vd[j]);
			if(a==mn){
				cout << j+1 << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int C = 1;
  cin >> N;
  vector<int> M(N);
  
  for (int i = 0; i < N; i++) {
    cin >> M.at(i);
  }
  
  sort(M.begin(), M.end());
  for (int i = 0; i < N - 1; i++) {
    if (M.at(i) != M.at(i + 1)) {
      C++;
    }
  }
  
  cout << C << endl;
  
}

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

typedef long long ll;
const int mod = 998244353, N = 5e5;
int n, m, ans, fac[N + 3], inv[N + 3];

int qpow(int a, int b){
    int ret = 1;
    while(b){
        if(b & 1) ret = (ll)ret * a % mod;
        a = (ll)a * a % mod; b >>= 1;
    }
    assert(ret != 0);
    return ret;
}
void init(){
    fac[0] = 1;
    for(int i = 1; i <= N; i++) fac[i] = (ll)fac[i - 1] * i % mod;
    inv[N] = qpow(fac[N], mod - 2);
    for(int i = N - 1; i; i--) inv[i] = (ll)inv[i + 1] * (i + 1) % mod;
}
void upd(int &x, int add){
    x += add;
    if(x >= mod) x -= mod;
}
int C(int a, int b){
    if(a == b || b == 0) return 1;
    return (ll)fac[a] * inv[b] % mod * inv[a - b] % mod;
}

int main(){
    scanf("%d %d", &n, &m); init();
    for(int i = 0, k = 1; i <= min(n, m); i++, k = -k){
        upd(ans, ((ll)k * C(n, i) % mod * C(m, i) % mod * fac[i] % mod * qpow(m + 1, n - i) % mod * qpow(n + 1, m - i) % mod + mod) % mod);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 998244353
#define M 1000003
#define INF 1e9
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,q,i,j,t,k,l,r;
   	cin>>n>>k;
   	int a[n+5],dp[n+5];
   	for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<n;i++){
    	dp[i] = 1000000000;
	}
   	dp[0] = 0;
   	for(i=1;i<n;i++){
   	 for(j= i-1;j>=max(0,i-k);j--){
   	  dp[i] = min(dp[i], dp[j] + abs(a[j]-a[i]));	
	 }	
	}
	cout<<dp[n-1];
 }

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

typedef long long ll;

int main(){
  ll n,m;
  cin >> n >> m;
  ll a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  ll s[n];
  for(int i=0;i<n;i++){
    s[i]=a[i];
  }
  sort(s,s+n);
  ll t[n];
  for(int i=0;i<n;i++){
    t[i]=a[i]*2e5+b[i];
  }
  sort(t,t+n);
  ll r[n];
  for(int i=0;i<n;i++){
    r[i]=t[i]-s[i]*2e5;
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    if(m<r[i]&&0<m){
      ans+=m*s[i];
      m=0;
    }
    else if(m>=r[i]){
      ans+=r[i]*s[i];
      m-=r[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4096
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    X = list(map(int, input().split()))
    print(X.index(0) + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9040
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF (long long)1 << 61
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main() {
	string s,r;cin >> s >> r;
    int a = 0;
    REP(i,3) if(s[i]==r[i]) a++;
    cout << a << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def>pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
Def inf=1000000019;
int main(){
	ll n,m;
	cin>>n>>m;
	ll t=0;
	while(m--){
		ll a,b;
		cin>>a>>b;
		if(a){
			t+=b;
		}else{
			cout<<(t+b-1)%n+1<<endl;
		}
	}
}










Measured memory_bytes: 3136
def selection(l):
    count = 0
    for i in range(len(l)):
        minj = i
        for j in range(i,len(l)):
            if l[j] < l[minj]:
                minj = j
        if l[i] > l[minj]:
            a = l[i]
            l[i] = l[minj]
            l[minj] = a
            count += 1
    ans_l = map(str,l)
    return ans_l,count
n = int(input())
l = list(map(int,input().split()))
ans_l,count = selection(l)
print(' '.join(ans_l))
print(count)



Measured memory_bytes: 5600
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> b(n, 0);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int loc = 0;
  int f = 0, g = 0;
  for(int i = 0; i <= n + 10; i++) {
    b[loc]++;
    if(b[loc] == 2) {
      f = i;
      g = loc;
      break;
    }
    loc = a[loc];
  }
  if(k <= f) {
    loc = 0;
    for(int i = 0; i < k; i++) {
      loc = a[loc];
    }
    cout << loc + 1 << endl;
  } else {
    k -= f;
    loc = g;
    vector<int> c(n, 0);
    vector<int> road(n, 0);
    for(int i = 0; i <= n + 10; i++) {
      road[i] = loc;
      c[a[loc]]++;
      if(c[a[loc]] == 2){
        f = i;
        g = loc;
        break;
      }
      loc = a[loc];
    }
    k %= f;
    cout << road[k] + 1 << endl;
  }

  return 0;
}

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

using namespace std;

int main (void) {
    int N;
    cin >> N;
    int ans = 0;
    for ( int i=1; i<=N; i+=2 ) {
        int n = 0;
        for ( int j=1; j<=i; j++ ) {
            if ( i % j == 0 )
                n++;
        }
        if ( n == 8 )
            ans++;
    }

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


Measured memory_bytes: 256
/**
	������������ Author : Avi J Patel ������������
	������������ University : DA-IICT ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 1000005
#define large 10000000000000001

#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
/*
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}*/ 
int main()
{
	int n;
	cin>>n;
//	vector<ld> a(n);
	ld sum=0;
	for(int i=0;i<n;i++)
	{
		ld a1;
		cin>>a1;
		sum+=(1.0/a1);
	}
	std::cout<<std::setprecision(14);
	cout<<1.0/sum;
	return 0;
}







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

using namespace std;

using ll = long long;

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

    ll a, b, x;
    cin >> a >> b >> x;
    if (a == 0 && b == 0) cout << "1\n";
    else if (a == 0) cout << (b / x) + 1 << endl;
    else cout << (b / x) - ((a - 1) / x) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll n; cin >> n;
  vector<ll> l(2*n);
  REP(i, 2*n) cin >> l[i];

  sort(ALL(l));
  ll ans = 0;
  REP(i, n){
    ans += l[2*i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int s;
  cin >> s;

  int x = sqrt(s);
  while(x*x < s) x++;

  int a = x, b = x;

  int y = x*x-s;

  if(y > (int)1e9) a--, y -= x;

  cout << 0 SP 0 SP a SP 1 SP y SP b << endl;

  //cout << a*b-y << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>

int main() {
  int n;
  std::cin >> n;
  std::cin.ignore();

  std::string str;
  std::getline(std::cin, str);

  int idx = 0;
  int *a = new int [n];
  std::stringstream ss(str);
  std::string buf;
  while(std::getline(ss, buf, ' ')) {
    a[idx] = atoi(buf.c_str());
    ++idx;
  }

  int min;
  int max;
  long int sum;
  sum = 0;
  min = a[0];
  max = a[0];
  for(int i = 1; i < n; ++i) {
    if(max < a[i]) {
      max = a[i];
    }
    if(min > a[i]) {
      min = a[i];
    }
  }
  for(int i = 0; i < n; ++i) {
    sum += a[i];
  }

  std::cout << min << " " << max << " " << sum << std::endl;

  delete[] a;

  return 0;
}

Measured memory_bytes: 3300
#include "bits/stdc++.h"
using namespace std; 

#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define ll long long 

int main(){
    IOS;
    ll n;
    cin>>n;
    if(n>=30) cout<<"Yes\n";
    else cout<<"No\n"    ;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
using namespace std;

struct Node{
  //ノードの情報
  int num;//ノードの番号(あっても意味ない気はするが、一応)
  vector<pair<int,int>> edge;//各エッジの接続先のノード番号とコスト

  //ダイクストラ法用のデータ
  bool confirmed=false;
  int mincost=1000000000;//そのノードへの最小コスト
};

struct Node_comparision{
  bool operator()(const Node node1,const Node node2) const{
    return node1.mincost > node2.mincost;
  }
};

//添字は0にする
//vectorは参照渡しで基本はする(遅いので)
void dijkstra(vector<Node>& nodes,int r){
  //優先度の低いものを取りだす(popで)
  //取り出したものが接続するノードのmincostを取り出す
  //new演算子で新たに確保しないと、参照先を書き換えしてしまう
  Node* x= new Node;*x=nodes[r];
  priority_queue<Node,vector<Node>,Node_comparision> nodes_sub;nodes_sub.push(*x);
  while(nodes_sub.size()!=0){
    Node* y= new Node;*y=nodes_sub.top();
    while(nodes[y->num].confirmed==true){
      nodes_sub.pop();
      if(nodes_sub.size()==0) break;
      *y=nodes_sub.top();
    }
    if(nodes_sub.size()==0) break;
    nodes_sub.pop();
    nodes[y->num].confirmed=true;
    int l=y->edge.size();
    for(int i=0;i<l;i++){
      nodes[y->edge[i].first].mincost=min(nodes[y->edge[i].first].mincost,y->mincost+y->edge[i].second);
      Node* z= new Node;*z=nodes[y->edge[i].first];
      if(nodes[z->num].confirmed==false) nodes_sub.push(*z);
      delete z;
    }
    delete y;
  }
  delete x;
}

int main(){
  int n,m;cin >> n >> m;
  vector<Node> Nodes1(n);
  vector<Node> Nodes2(n);
  for(int i=0;i<n;i++){Nodes1[i].num=i;}
  for(int i=0;i<n;i++){Nodes2[i].num=i;}

  for(int i=0;i<m;i++){
    int a,b,c,d;scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    Nodes1[a-1].edge.push_back(make_pair(b-1,c));
    Nodes1[b-1].edge.push_back(make_pair(a-1,d));
    Nodes2[a-1].edge.push_back(make_pair(b-1,c));
    Nodes2[b-1].edge.push_back(make_pair(a-1,d));
  }

  int s,g,v,p;scanf("%d,%d,%d,%d",&s,&g,&v,&p);
  Nodes1[s-1].mincost=0;Nodes2[g-1].mincost=0;

  dijkstra(Nodes1,s-1);
  dijkstra(Nodes2,g-1);

  cout << v-p-(Nodes1[g-1].mincost+Nodes2[s-1].mincost) << endl;
}



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

typedef long long ll;

template<typename T>
T gcd(T a, T b){
    if (a < b) return gcd(b, a);
    T r = a % b;
    while (r){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

template<typename T>
T lcm(T a, T b){
    return a * b / gcd(a, b);
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = lcm(a, b);
    cout << ans << endl;
}


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

#define REP(i,s,n) for(register int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 500010

using namespace std;

long long depth[MAX],L[MAX],R[MAX],N,noSaveDp[MAX],saveDp[MAX],leaf[MAX];

int main(){
  scanf("%d",&N);
  depth[0] = leaf[N-1] = 1;
  rep(i,N-1){
    scanf("%d %d",&L[i],&R[i]);
    depth[--L[i]] = depth[--R[i]] = depth[i] + 1;
  }

  for(register int i = N-2;i>=0;i--){
    leaf[i] = leaf[L[i]] + leaf[R[i]];
    saveDp[i] = noSaveDp[i] = noSaveDp[L[i]] + noSaveDp[R[i]] + leaf[L[i]] + leaf[R[i]];
    saveDp[i] = min(saveDp[i],
		    min(noSaveDp[L[i]]+leaf[L[i]]+1+saveDp[R[i]],
			noSaveDp[R[i]]+leaf[R[i]]+1+saveDp[L[i]]));
    saveDp[i] = min(saveDp[i],
		    saveDp[L[i]]+1+depth[i]-1+1+saveDp[R[i]]);
  }
  printf("%d\n",saveDp[0]);
  return 0;
}

Measured memory_bytes: 24624
package main

import (
	"fmt"
)

func main() {
	var s string
	_, _ = fmt.Scan(&s)
	var ans int

	switch s {
	case "SSS":
		ans = 0
	case "RRS", "SRR":
		ans = 2
	case "RRR":
		ans = 3
	default:
		ans = 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1768
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextInt();
            }

            BigDecimal n = new BigDecimal(1);
            BigDecimal d = new BigDecimal(0);

            for (int i = 0; i < N; i++) {
                n = n.multiply(new BigDecimal(A[i]));
            }

            for (int i = 0; i < N; i++) {
                d = d.add(n.divide(new BigDecimal(A[i])));
            }

            BigDecimal ans = n.divide(d, 20, BigDecimal.ROUND_HALF_DOWN);
            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 22356
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;

string s;
map<char, int> m;

int main()
{
    while (cin >> s)
    {
        m.clear();
        for (int i = 0; s[i]; ++i)
        {
            ++m[s[i]];
        }
        bool flag = false;
        for (auto it: m)
        {
            if (it.second & 1)
            {
                flag = true;
                break;
            }
        }
        if (flag) puts("No");
        else puts("Yes");

    }
    return 0;
}


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

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	int N; cin >> N;
	int n = N / 2;
	vector<ll> A(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];
	vector<ll> acc(N + 1, 0);
	acc[1] = A[0];
	for (int i = 2; i <= N; ++i)
		acc[i] = acc[i - 2] + A[i - 1];

	ll res = 0;

	// A1 A3 A5 ...
	for (int i = 0; i <= 2 * n - 2; i += 2)
		res += A[i];

	// A2 A4 A6 ....
	ll tmp = 0;
	for (int i = 1; i < N; i += 2)
		tmp += A[i];

	res = max(tmp, res);

	if (N % 2) {
		// A3 A5 A7 ...
		tmp = 0;
		for (int i = 2; i < N; i += 2)
			tmp += A[i];
		res = max(res, tmp);
	}

	// A1 A3 ... A[2i-1],  A[j] A[j+2] ... A[j + (n-i-1) * 2]
	for (int i = 1; i < n; ++i) {
		tmp = acc[2 * i - 1];
		ll additional = -(1LL << 60);
		for (int j = 2 * i + 2; j <= N - 2 * n + 2 * i + 2; ++j) {
			ll add = acc[j + (n - i - 1) * 2] - (j >= 2 ? acc[j - 2] : 0);
			additional = max(additional, add);
		}
		tmp += additional;
		res = max(res, tmp);
	}

	// A2 A4 ... A[2i], A[j] A[j + 2] ... A[j + (n-i-1) * 2]
	for (int i = 1; i < n; ++i) {
		tmp = acc[2 * i];
		ll additional = -(1LL << 60);
		for (int j = 2 * i + 3; j <= N - 2 * n + 2 * i + 2; ++j) {
			ll add = acc[j + (n - i - 1) * 2] - (j >= 2 ? acc[j - 2] : 0);
			additional = max(additional, add);
		}
		tmp += additional;
		res = max(res, tmp);
	}

	if (N % 2) {
		vector<vector<ll>> dp(N, vector<ll>(3, 0));
		dp[0][0] = A[0];
		dp[0][2] = A[0];
		dp[1][0] = A[0];
		dp[1][1] = A[1];
		dp[1][2] = A[0];
		for (int i = 2; i < N; ++i) {
			// そのまま継続
			for (int j = 0; j < 3; ++j)
				dp[i][j] = dp[i - 1][j];
			if (i % 2) {
				dp[i][1] += A[i];
			}
			else {
				dp[i][0] += A[i];
				dp[i][2] += A[i];
			}
			if (i % 2) {
				// 0 -> 1移行
				if (i >= 3) {
					tmp = dp[i - 3][0] + A[i];
					dp[i][1] = max(dp[i][1], tmp);
				}
			}
			else {
				// 1 -> 2移行
				if (i >= 3) {
					tmp = dp[i - 3][1] + A[i];
					dp[i][2] = max(dp[i][2], tmp);
				}
			}
		}
		tmp = max({ dp[N - 1][0], dp[N - 1][1], dp[N - 1][2] });
		res = max(tmp, res);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 17224
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   char[] c = sc.next().toCharArray();
   int[] h = new int[2];
   for(int i = 0;i<N;i++)
   {
     if(c[i]=='R') h[0]++;
     else h[1]++;
   }
   String ans;
   if(h[0]>h[1]) ans = "Yes";
   else ans = "No";
   System.out.println(ans);
 }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

ll power(ll x, ll m){
    //繰り返し二乗法
    if(m == 0) return 1;
    if(m == 1) return x;
    if(m % 2 == 0){
        return power(x*x,m/2);
    }else{
        return power(x*x,m/2)*x;
    }
}

int main(){
    ll n; cin >> n;
    ll tmp = n;
    ll cnt = 1;
    ll ans = 0;
    while(tmp > 0){
        tmp = tmp / 10;
        if(tmp > 0) {
            if(cnt % 2 == 1) ans += power(10,cnt)-power(10,cnt-1);
        }
        else{
            if(cnt % 2 == 1) ans += n - power(10,cnt-1) + 1;
        }
        cnt++;
    }
    cout << ans << endl;
    //cout << power(10,0) << endl;
}

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

int main(){
  string s1,s2;
  cin >> s1 >> s2;
  
  s1 += s1;
  
  if(s1.find(s2) != string::npos)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))

dic=defaultdict(int)
ans=0
for i in range(n):
    ans+=dic[i-a[i]]
    dic[a[i]+i]+=1
print(ans)

Measured memory_bytes: 136924
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

ll A, B, N;

ll func(ll x) {
    return (A*x)/B - A*(x/B);
}

int main() {
    cin >> A >> B >> N;
    ll x = min(B - 1, N);
    cout << func(x) << endl;
    return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio

    st s ;
    cin >> s ;
    s[3] += 1 ;
    cout << s ;
    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
int main(){
  char s[101];
  scanf("%s",s);
  char a[51],b[51];
  int c = 0,d = 0;
  while(s[c]!='\0'){
    if (c%2 == 0){
      a[c/2]=s[c];
      if (a[c/2]=='L'){
      	d=1;
      }
    }else{
      b[c/2]=s[c];
      if (b[c/2]=='R'){
      	d=1;
      }
    }
    c++;
  }
  if (d == 1){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 128
#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>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,a,b; cin>>n>>a>>b;
  ll c=a+b;
  ll sum=0, bsum=0;
  string s; cin>>s;
  rep(i,n){
    if(s[i]=='c'){
      cout<<"No"<<endl;
    }else{
      if(s[i]=='a'){
        if(sum<c){
          cout<<"Yes"<<endl;
          sum++;
        }else{
          cout<<"No"<<endl;
        }
      }else{
        if(sum<c&&bsum<b){
          cout<<"Yes"<<endl;
          sum++,bsum++;
        }else{
          cout<<"No"<<endl;
        }
      }
    }
  }
}

Measured memory_bytes: 848
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>


using namespace std;
typedef long long 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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int res = 0;
	for (int i = 1; i <= n; i++) {
		res += (to_string(i).size() & 1);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using llong = long long;

int main() {
    uint N;
    cin >> N;
    vector<int> a(3*N, 0);
    for (auto &x: a) cin >> x;
    sort(a.begin(), a.end());
    size_t first = N;
    llong strength = 0;
    for (size_t i=first; i<a.size(); i+=2) {
        strength += a[i];
    }
    cout << strength << endl;
}


Measured memory_bytes: 4528
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <numeric>
#include <complex>
#include <iomanip>

using namespace std;

#define bitcount(n) __builtin_popcount(n)

#define debug(n) cout << n << endl;

#define PREC(n) setprecision(n)
#define DOTPREC(n) fixed << setprecision(n)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false); cin.tie(0)

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

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

const ll MOD = 1000000007;

int W, H, N;

int main(void)
{
    omajinai;

    cin >> W >> H >> N;

    int min_x = 0, max_x = W, min_y = 0, max_y = H;
    rep(i, N) {
        int x, y, a;
        cin >> x >> y >> a;

        switch (a) {
            case 1:
                chmax(min_x, x);
                break;
            case 2:
                chmin(max_x, x);
                break;
            case 3:
                chmax(min_y, y);
                break;
            case 4:
                chmin(max_y, y);
                break;
        }
    }

    int s = (max_x - min_x) * (max_y - min_y);
    if ((max_x - min_x) <= 0 || (max_y - min_y) <= 0) {
        debug(0);
    }
    else {
        debug(s);
    }

    return 0;
}


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

int main()
{
    int x,y,a[5];
    cin>>x>>y;
    a[0]=x+y;
    a[1]=x-y;
    a[2]=x*y;
    int max=a[0];
    for(int i=1;i<=2;i++)
    {
        if(max<a[i])
            max=a[i];
    }
    cout<<max<<endl;


    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	N := sc.nextInt()
	M := sc.nextInt()

	sum := 0
	for i := N - 1; i > 0; i-- {
		sum += i
	}
	for i := M - 1; i > 0; i-- {
		sum += i
	}
	fmt.Println(sum)

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 640
#include<algorithm>
#include<cassert>
#include<cstdio>
#include<complex>
#include<map>
#include<iomanip>
#include<sstream>
#include<queue>
#include<set>
#include<string>
#include<vector>
#include<iostream>
#include<cstring>
#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define fup FOR
#define fdo FORD
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define siz SZ
#define CLR(x) memset((x), 0, sizeof(x))
#define PB push_back
#define MP make_pair
#define X first
#define Y second 
#define FI X
#define SE Y
#define SQR(a) ((a)*(a))
#define DEBUG 1
#define debug(x) {if (DEBUG)cerr <<#x <<" = " <<x <<endl; }
#define debugv(x) {if (DEBUG) {cerr <<#x <<" = "; FORE(it, (x)) cerr <<*it <<", "; cout <<endl; }}
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int>P;
typedef vector<int>VI;
const int INF=1E9+7;
template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
	
int main(){
    int n,c,l;
    string k;
    cin>>n>>c;
    vector<bool> v(n+9,false);
    vector<int> wa(n+9,0);
    int ac=0,was=0;
    while(c--){
		cin>>l>>k;
		if(k=="AC" && !v[l]){
			ac++;
			was += wa[l];
			v[l]=true;
		}
		else if(!v[l] && k=="WA"){
			wa[l]++;
		}
	}
	cout<<ac<<" "<<was<<endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        long N = long.Parse(Console.ReadLine());

        int ans = 0;
        
        foreach(var x in xxxxx())
        {
            if (x > N) break;

            //候補が実際に753数か判定
            string s = x.ToString();
            if (s.Contains('7') && s.Contains('5') && s.Contains('3'))
            {
                ans++;
            }
        }

        Console.WriteLine(ans);
    }
    
    //753数候補を小さい方から列挙
    static IEnumerable<long> xxxxx()
    {
        IEnumerable<long> ddd = new long[] { 3, 5, 7 };
        IEnumerable<long> seq = new long[] { 3, 5, 7 };

        while(true)
        {
            foreach(var x in seq)
            {
                yield return x;
            }

            seq = seq.SelectMany(n => ddd.Select(d => n * 10 + d));
        }
    }
}


Measured memory_bytes: 17500
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9+8
#define OO 1e18
#define EPS 1e-9
#define Endl '\n'
#define all(v) (v).begin(),(v).end()
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=1e5+5;
const int N=1e4+5,M=N*2;
int A,B,T;
int main()
{
    scanf("%d%d%d",&A,&B,&T);
    printf("%d\n",(T/A)*B);
    re 0;
}

Measured memory_bytes: 256
import bisect

def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c,d=Csum(a),Csum(b)
d.pop(0)
ans=0
for i in range(n+1):
    if k-c[i]<0:
        break
    ans=max(ans,i+bisect.bisect_right(d,k-c[i]))
print(ans)

Measured memory_bytes: 47332
using System;


namespace FibonacciSample
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int p = int.Parse(str[1]);
            Console.WriteLine((3 * a + p) / 2);
        }
    }
}

Measured memory_bytes: 13140
from collections import Counter
from functools import reduce
from operator import mul


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


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

if P == 1:
    print(1)
else:
    c = Counter(prime_factorize(P))
    d = dict((factor, e // N) for factor, e in c.items())
    print(reduce(mul, [factor ** e for factor, e in d.items()]))


Measured memory_bytes: 3700
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	bool ok=false;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if( ( i*j+ (n-i)*(m-j) )==k)
				ok=true;
		}
	}
	if(ok)
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func f(a, b, t float64) float64 {
	if a*math.Sin(t) < b*math.Cos(t) {
		return a*a*b - a*a*a*math.Tan(t)/2
	}
	return a * b * b / (2 * math.Tan(t))
}

func main() {
	var a, b, x float64
	fmt.Scan(&a, &b, &x)

	var l, r float64
	l, r = 0, math.Pi/2
	for i := 0; i < 100; i++ {
		m := (l + r) / 2
		if f(a, b, m) < x {
			r = m
		} else {
			l = m
		}
	}
	ans := l * 360 / (2 * math.Pi)
	fmt.Println(ans)
}


Measured memory_bytes: 512
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
   
from functools import reduce

# gcdを求める
def findGCD(a:int, b:int) -> int:
    # ユークリッドの互除法
    while 1:
        if a%b == 0:
            return b
        else:
            a = a%b
        
        if b%a == 0:
            return a
        else:
            b = b%a
                
# lcmを求める
def findLCM(a:int, b:int) -> int:

    return (a//findGCD(a,b)) * b


n = ni()
ts = [ni() for _ in range(n)]

lcm = reduce(findLCM,ts)

print(lcm)

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

//a^b % modを求める
int64_t MODpow(int64_t a, int64_t b, int64_t mod) {
    int64_t result = 1;
    while (b) {
        if (b % 2 == 1) {
            result *= a;
            result %= mod;
        }

        b /= 2;
        a *= a;
        a %= mod;
    }

    return result;
}

int main() {
    int64_t N, P;
    string S;
    cin >> N >> P >> S;

    vector<int64_t> A(N);
    for (int64_t i = 0; i < N; i++) {
        A[i] = S[i] - '0';
    }

    int64_t ans = 0;

    if (P == 2 || P == 5) {
        for (int64_t i = 0; i < N; i++) {
            if (A[i] % P == 0) {
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }

    //num[i] := Sのi文字目以降を評価した整数をPで割った余りがiであるような個数
    vector<int64_t> num(P, 0);
    num[0] = 1;

    int64_t u = 0;
    for (int64_t i = N - 1; i >= 0; i--) {
        (u += A[i] * MODpow(10, N - 1 - i, P)) %= P;
        ans += num[u]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2180
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
 
map<string, int> dp;
int direction[4] = { 1, -1, 4, -4 };
 
//************************************
// Method:    bfs
// FullName:  bfs
// Access:    public 
// Returns:   void
// Qualifier: ???0????????´?????????
//************************************
void bfs()
{
	queue<string> que;
	que.push("01234567");
	dp["01234567"] = 0;
	while (!que.empty())
	{
		string now = que.front(); que.pop();
		// p???'0'?????????
		int p = 0;
		for (int j = 0; j < 8; ++j)
		{
			if (now[j] == '0')
			{
				p = j;
				break;
			}
		}
 
		for (int i = 0; i < 4; ++i)
		{
			int n = p + direction[i];
			if (0 <= n && n < 8 && 
				!(p == 3 && i == 0) && // ???????§???????????????????
				!(p == 4 && i == 1))   // ???????§???????????????????
			{
				string next = now;
				swap(next[p], next[n]);
				if (dp.find(next) == dp.end())
				{
					dp[next] = dp[now] + 1;
					que.push(next);
				}
			}
		}
	}
}
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
	bfs();
	string line;
	while (getline(cin, line))
	{
		line.erase(remove(line.begin(), line.end(), ' '), line.end());
		cout << dp[line] << endl;
	}
 
	return 0;
}

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

int main(){
  ll n; cin >> n;
  string s,t; cin >> s >> t;
  rep(i,n){
    cout << s[i] << t[i];
  }
  cout << endl;
}

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


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

    int ans=0;
    for(int i=1;i<N;i++){
        int kind=0;
        for(char a='a';a<='z';a++){
            bool right=false,left=false;

            for(int j=0;j<i;j++){
                if(S[j]==a)left=true;
            }
            for(int j=i;j<N;j++){
                if(S[j]==a)right=true;
            }
            if(left&&right)kind++;
        }
        ans=max(ans,kind);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
	



int main(){
   IOS
   	string s ,t;
	   cin>>s>>t;

	int n = sz(s), m = sz(t);

	int ans = 1e9;
	for(int i = 0; i < n - m + 1; i++){
		int j = i + m - 1;

		int cnt = 0;
		for(int k = i; k <= j; k++){
			if(s[k] != t[k - i]){
				cnt++;
			}
		}
		ans = min(ans, cnt);
	}

	cout<<ans<<'\n';


	







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
	if(b&1) res = res * a % mod;
		a = a * a % mod;
	b >>= 1;
	}

	return res;
}



Measured memory_bytes: 3640
n = int(input())
arr = [int(input()) for _ in range(n)]

primes = set(i for i in range(2, 10 ** 4))
for i in range(2, 101):
    if i in primes:
        primes.difference_update(range(i * i, 10 ** 4 + 1, i))

res = 0
for ele in arr:
    for p in primes:
        if ele > p and ele % p == 0:
            break
    else:
        res += 1

print(res)



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; string s; cin>>n>>s;
	vector<int>E(n),W(n);
	E.back()=(s.back()=='E');
	W.front()=(s.front()=='W');
	for(int i=1;i<n;++i){
		int j=abs(n-i-1);
		E.at(j)=E.at(j+1),W.at(i)=W.at(i-1);
		if(s.at(j)=='E')++E.at(j);
		if(s.at(i)=='W')++W.at(i);
	}
	int ans=1e9;
	for(int i=0;i<n;++i){
		ans=min(ans,E.at(i)+W.at(i)-1);
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 6112
use proconio::input;

#[allow(non_snake_case)]
#[allow(unused)]
fn main() {
    input! {
        N: usize,
        mut L: [usize; N],
    }

    L.sort();

    let mut ans = 0;

    for i in 0..N {
        for j in i+1..N {
            for k in j+1..N {
                if L[i] == L[j] || L[i] == L[k] || L[j] == L[k] { continue; }
                if L[k] >= L[i] + L[j] { continue; }

                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2136
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x, y, z := nextInt(), nextInt(), nextInt()
	puts(z, x, y)
}


Measured memory_bytes: 640
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		Integer[] A = new Integer[N];
		for (int i=0;i<N;i++) {
			A[i] = Integer.parseInt(sc.next());
		}
		List<Integer> A_list = Arrays.asList(A);
		Collections.reverse(A_list);
		Integer[] A_2 = (Integer[])A_list.toArray(new Integer[N]);
		System.out.println(LIS(A_2));
	}

	static int LIS (Integer[] A) {
		int N = A.length;
		Integer[] dp = new Integer[N];
		for (int i=0;i<N;i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		for (int i=0;i<N;i++) {
			int index = Arrays.binarySearch(dp, A[i], (x,y)->x.compareTo(y)>0?1:-1);
			if (index<0) {index = -index-2;}
			dp[index+1] = A[i];
		}
		int ans = 0;
		for (int i=0;i<N;i++) {
			if (dp[i] != Integer.MAX_VALUE) {
				ans++;
			}
		}
		return ans;
	}
}

Measured memory_bytes: 50520
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = breads >>= main'
    where
        main' [n, k] = getLine >> print (solve n k)

-- |
-- >>> solve 4 3 
-- 2
-- >>> solve 3 3
-- 1
-- >>> solve 8 3 
-- 4
solve :: Int -> Int -> Int 
solve n k
    | m == 0 = r
    | otherwise = r + 1
    where
        (r, m) = (n - 1) `divMod` (k - 1)

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 18812