akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        String s = in.next();

        int x = 0;
        char prev = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (prev != c) {
                prev = c;
                x++;
            }
        }

        int y = 0;
        prev = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            char c = s.charAt(i);
            if (prev != c) {
                prev = c;
                y++;
            }
        }

        out.println(Math.min(x, y) - 1);
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

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

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

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fori(s,n) for(ll i=s;i<=n;i++)
#define ford(s,n) for(int i=n;i>=s;i--)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define TEST(t) for(int T=1;T<=t;T++)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,i,k,j;
    ll ans=0,r=0,b=0,g=0;
    string a;
    cin>>n>>a;
    vector <int> v(n);
    fori(0,n-1){
      if(a[i]=='R')
      {   r++; v[i]=1;}
      else if(a[i]=='B')
      {   b++; v[i]=2; }
      else if(a[i]=='G')
      {  g++; v[i]=3;}
    }
    ans=r*b*g;
    for(i=1;i<=n;i++)
      for(j=i+1;(2*j)-i<=n;j++){
         k=(2*j)-i;
         if(v[i-1]!=v[j-1]&&v[j-1]!=v[k-1]&&v[i-1]!=v[k-1])
            ans--;
      }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

const int MOD = 1000000007;
typedef long long ll;

const int MAX = 110000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FAC(int n){
  return fac[n];
}

int main() {
  COMinit();
  int N,M;
  cin>>N>>M;
  if(N==M){
    cout<<2*FAC(N)*FAC(M)%MOD<<endl;
  }else if(N-1==M){
    cout<<FAC(N)*FAC(M)%MOD<<endl;
  }else if(N+1==M){
    cout<<FAC(N)*FAC(M)%MOD<<endl;
  }else{
    cout<<0<<endl;
  }

}


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

#define int long long int
#define MOD 1000000007
#define N 103
#define pii pair<int,int>
#define MAX 1000000000000000000
#define _mp make_pair
#define pb push_back
#define _sort(v) sort(v.begin(),v.end())
#define _rsort(v) sort(v.rbegin(),v.rend())
using namespace std;

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

int32_t main(){

int x,n,a;
cin>>x>>n;
vector<bool> v(N,false);
for(int i=0;i<n;i++){
    cin>>a;
    v[a]=true;
}
int j=INT_MAX,k=INT_MAX;
for(int i=x;i<N;i++){
    if(!v[i]){
        k=i;
        break;
    }
}
for(int i=x;i>=0;--i){
    if(!v[i]){
        j=i;
        break;
    }
}

if(abs(x-j)<=abs(k-x)){
    cout<<j;
}else cout<<k;
    
    // end_timer = std::chrono::high_resolution_clock::now();
    // ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_timer - start_timer).count();

return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define vi vector <int>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	ll n; cin>>n;
    ll ans = 0 ;
    for(ll i=1;i<=n;i++)
    {
        ans += i*(n-i+1);
    }
    forn(i,n-1)
    {
        ll u,v; cin>>u>>v;
        if(u>v) swap(u,v);
        ll g = u*(n-v+1);
        ans -= g;
    }
    cout<<ans;

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
using namespace std;    
const int N = 2010, mod = int(1e9)  + 7; 
int n,m,q, a[N][N], b[N][N], c[N][N];
char s[N][N];

int geta(int x1,int y1,int x2,int y2){
	if(x2 < x1) return 0;
	if(y2 < y1) return 0;
	return a[x2][y2] - a[x2][y1 - 1] - a[x1 - 1][y2] + a[x1 - 1][y1 - 1];
}

int getb(int x1,int y1,int x2,int y2){
	if(y2 < y1) return 0;
	if(x2 < x1) return 0;
	return b[x2][y2] - b[x2][y1 - 1] - b[x1 - 1][y2] + b[x1 - 1][y1 - 1];
}

int getc(int x1,int y1,int x2,int y2){
	return c[x2][y2] - c[x2][y1 - 1] - c[x1 - 1][y2] + c[x1 - 1][y1 - 1];
}
int main () {
	scanf("%d%d%d",&n,&m,&q);
	for(int i = 1; i <= n; i++){
		scanf("\n%s",s[i] + 1);
		for(int j = 1; j <= m; j++){
			if(s[i][j] == '1'){
				c[i][j]++;
				if(s[i - 1][j] == '1') b[i][j]++;
				if(s[i][j - 1] == '1') a[i][j]++;
			}
			a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
			b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
			c[i][j] += c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1];
		}
	}
	while(q--){
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		printf("%d\n", getc(x1,y1,x2,y2) - geta(x1,y1 + 1,x2,y2) - getb(x1 + 1,y1,x2,y2));
	}

return 0;
}

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

#define ll long long
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

const int N =100;

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
bool ispalindrome(string s)
{
    int n = s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);

}
ll f(ll n) {
	return n * (n - 1) / 2;
}
bool cmp(const tuple<int, string, string>& a,
               const tuple<int, string, string>& b)
{
    return (get<0>(a) < get<0>(b));
}

void solve()
{
    string s;
    cin>>s;
    ll r=0;
    for(int i=0;i<s.length();i++)
    {
        r = r + s[i]-'0';
        r = r%9;
    }
    if(r%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3728
/**
 *    author:  DFLMKWR
 */

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

const int INF = 0x3f3f3f3f;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int lt = t.size(), cnt = 0, ans = INF;
  for (int i = 0; s[i + lt - 1]; i++) {
    for (int j = 0; t[j]; j++)
      if (t[j] != s[i + j]) cnt++;
    ans = min(ans, cnt);
    cnt = 0;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3568
#include <iostream>
using namespace std;
#define ll long long
signed main()
{
    ll N, M;
    cin >> N >> M;

    // a1~aN の最大公約数がd => a1~aNがすべてd*i(i:自然数)の形で表される
    for (ll i = M / N; i >= 1; --i) {
        if ((M - i * N) % i == 0) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
   int N;
   while (cin >> N){
      if (N == 0) return 0;
      int ans = 0;
      for (int a = 1; a <= N/2+1; a++){
         for (int b = a+1; b <= N/2+1; b++){
            if (N == (b-a+1)*(a+b)/2) ans++;
         }
      }
      cout << ans << endl;
   }
}



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

int K;

void Input(){
	cin>>K;
}

void Solve(){
	while(K--){
		cout<<"ACL";
	}
	cout<<'\n';
}

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

Measured memory_bytes: 3636
N = raw_input()
keys = ['+','-']
x = 0
check = True
ans = ''
for key1 in keys:
    if key1 == '+' and check:
        x1 = int(N[0]) + int(N[1])
    elif(key1 == '-' and check):
        x1 = int(N[0]) - int(N[1])
    for key2 in keys:
        if key2 == '+' and check:
            x2 = x1  + int(N[2])
        elif(key2 == '-' and check):
            x2 = x1  - int(N[2])
        
        #print x
        for key3 in keys:
            if key3 == '+' and check:
                #print x
                #print int(N[3])
                x3 = x2  + int(N[3])
                #print x
                if (x3 == 7):
                    ans = N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    check = False


            elif(key3 == '-' and check):

                x3 = x2  - int(N[3])

                if (x3 == 7):
                    ans =  N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    check = False

            #print x
print ans

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

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

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (to_string(i).length() % 2 == 1) ans++;
    }

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


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int c[3][3];
for (int i = 0; i < 3; i++) {
  for (int j = 0; j < 3; j++) {
   scanf("%d", &c[i][j]);
  }
}
int a[2][3];
for (int i = 0; i < 2; i++) {
 for (int j = 0; j < 3; j++) {
   a[i][j] = c[i][j]-c[i+1][j];
 }
}

int b[3][2];
for (int i = 0; i < 3; i++) {
 for (int j = 0; j < 2; j++) {
   b[i][j] = c[i][j]-c[i][j+1];
 }
}

int flaga = 0;
if (a[0][0] != a[0][1] || a[0][1] != a[0][2]) flaga = 1;
if (a[1][0] != a[1][1] || a[1][1] != a[1][2]) flaga = 1;

int flagb = 0;
if (b[0][0] != b[1][0] || b[1][0] != b[2][0])  flagb = 1;
if (b[0][1] != b[1][1] || b[1][1] != b[2][1])  flagb = 1;

if (flaga == 0 && flagb == 0) printf("Yes");
else  printf("No");

return 0;

}

Measured memory_bytes: 128
R,G,B,N=map(int, input().split())
r=N//R
cnt=0
for i in range(r+1):
  NN=N-R*i
  g=NN//G
  for j in range(g+1):
    NNN=NN-G*j
    if NNN%B==0:
      cnt+=1
print(cnt)

Measured memory_bytes: 2940
#include <iostream>
#define N 100001
using namespace std;
typedef long long ll;
int func(int);
int n,q,e,k,edge[N];
bool marked[N];

int main(){
  char c;
  ll cnt;
  while(1){
    cin>>n>>q;
    if(!n&&!q) break;
    for(int i=0;i<n-1;i++) cin>>e,edge[i+2]=e;
    for(int i=0;i<n-1;i++) marked[i+2]=false;
    marked[1]=true;
    cnt=0;
    while(q--){
      cin>>c>>k;
      if(c=='M') marked[k]=true;
      else cnt+=func(k);
    }
    cout<<cnt<<endl;
  }
  return 0;
}

int func(int x){
  if(marked[x]) return x;
  return func(edge[x]);
}

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

long long int l[90]={0};

int main(){
    int n;
    cin >> n;
    l[0] = 2;
    l[1] = 1;
    for(int i=2;i<=n;++i){
        l[i] = l[i-1] + l[i-2];
    }

    cout << l[n] << endl;

    return 0;
}


Measured memory_bytes: 256
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes;
var
  a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,min:Integer;
  l:array of Integer;
  s,s123,s1,s2,s3:string;
  tf:Boolean;
  nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(n);
    Write('ABC');
    Writeln(n);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	int n,k,card[500][500];
	cin >> n >> k;
	rep(i,0,k){
		rep(j,0,n/2){
			cin >> card[i][j];
		}
	}

	random_device rd;
	mt19937 eng(rd());
	while(true){
		int seq[1001];
		rep(i,1,n+1) seq[i]=eng()%2;

		bool ok=true;
		rep(i,0,k){
			int cnt=0;
			rep(j,0,n/2){
				cnt+=seq[card[i][j]];
				if(cnt>n/8*3){
					ok=false;
					break;
				}
			}
			if(cnt<n/8) ok=false;
			if(!ok) break;
		}

		if(ok){
			rep(i,1,n+1) cout << seq[i];
			cout << endl;
			break;
		}
	}
}

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

Measured memory_bytes: 2228
#include <stdio.h>
#include <stdlib.h>

int m, n;
int w[100];

int IsStorable( int width ) {

    int row = 0, c = 0, i = 0;

    while ( i < n ) {
	if ( c + w[i] <= width ) {
	    c += w[i];
	    ++i;
	}
	else if ( ++row < m ) c = 0;
	else return 0;
    }

    return 1;
}

int main() {
    int i, minw, maxw, mid;

    while ( scanf("%d %d", &m, &n) == 2 && m && n ) {

	for ( i=0; i<n; ++i ) scanf("%d", &w[i]);

	minw = 1;
	maxw = 1500000;
	if ( !IsStorable( maxw ) ) printf("NA\n");

	while ( maxw > minw ) {
	    mid = (maxw + minw)/2;
	    if ( IsStorable(mid) ) maxw = mid;
	    else                   minw = mid + 1;
	}

	printf("%d\n", minw);
    }
    
    return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
 
/*てんぷれぞーん！*/
struct edge {int to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<edge> VE;
//static const int INF = 2147483647;
static const int INF = 1000000000;
static const long long llINF = 9223372000000000000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
/* t y p o っ て 知 っ て る ゥ ！ ？ */
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
//#define int ll
//#define INF llINF

const int NMAX = 60;
int n,m;
int d[NMAX];    //始点(0)からの最短距離を記録、clear()でINFに初期化

bool rinsetsu[NMAX][NMAX];

void initializer(){
    for(int i=0;i<NMAX;i++){
        for(int j=0;j<NMAX;j++) rinsetsu[i][j] = false;
    }
}

void clear(){
    for(int i=0;i<NMAX;i++) d[i] = INF;
}

void debug(){
    for(int i=0;i<n;i++) printf("%d ",d[i]);
    printf("\n\n");
}

void debug2(){
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) printf("%d ",rinsetsu[i][j]);
        printf("\n");
    }
    printf("\n");
}

void bfs(int s){
    d[s] = 0;
    queue<int> que;
    que.push(s);
    while(!que.empty()){
        int u = que.front();que.pop();
        for(int i=0;i<n;i++){
            if(rinsetsu[u][i] && d[i]==INF){
                d[i] = d[u] + 1;
                que.push(i);
            }
        }
    }
}

bool search(){  //非連結成分の検出
    for(int i=0;i<n;i++){
        if(d[i]==INF) return true;
    }
    return false;
}


signed main(){
    int ans=0;

    initializer();

    scanf("%d%d",&n,&m);

    P road[m];

    for(int i=0;i<m;i++){
        int tmp1,tmp2;
        scanf("%d%d",&tmp1,&tmp2);
        tmp1--; tmp2--; //0-index
        road[i].fi = tmp1, road[i].se = tmp2;
        rinsetsu[tmp1][tmp2] = rinsetsu[tmp2][tmp1] = true;
    }

    for(int i=0;i<m;i++){
        clear();
        /*辺を一つ取り除く*/
        rinsetsu[road[i].fi][road[i].se] = rinsetsu[road[i].se][road[i].fi] = false;
        bfs(0);
        //debug2();
        //debug();
        if(search()) ans++;
        /*辺をもとに戻す*/
        rinsetsu[road[i].fi][road[i].se] = rinsetsu[road[i].se][road[i].fi] =  true;
    }

    printf("%d\n",ans);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		decimal sum = 0.0M;
		for(long i = 0; i < N; i++)
		{
			var x = GetDecimal();
			if(GetString().Equals("JPY"))
				sum += x;
			else
				sum +=  380000M * x;
		}
		WriteLine(sum);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<ll, ll> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 100 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    string s;
    cin >> s;
    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (s == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main()
{
    // int n;
    // cin >> n;
    // vector<vector<vector<int>>> a();
    // rep(i, n)
    // {
    //     int ai;
    //     cin >> ai;
    //     rep(j, ai)
    //     {
    //         cin >> a[i][j][0] >> a[i][j][1];
    //     }
    // }
    vector<int> a(5);
    rep(i, 5)
    {
        cin >> a[i];
    }

    int n;
    cin >> n;

    sort(a.begin(), a.end());

    if (a[4] - a[0] > n)
    {
        cout << ":(" << endl;
    }
    else
    {
        cout << "Yay!" << endl;
    }

    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int64_t func(int64_t &n, int64_t &x){
  if(n == -1) return 0;
  return n/x + 1;
}

int main() {
  int64_t a, b, x;
  cin >> a >> b >> x;
  a--;
  cout << func(b, x) - func(a, x) <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    vector<int> cnt(N,0);
    for(int i=0; i<K; i++){
        int k;
        cin >> k;
        for(int j=0; j<k; j++){
            int a;
            cin >> a;
            cnt[a-1]++;
        }
    }
    int ans = 0;
    for(int i=0; i<N; i++){
        if(cnt[i] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353 
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'



int main()
{
    fastio;
    #ifdef APNA_IO
        start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);    
    #endif

    ll a,b;cin>>a>>b;
    a+=b;
    if(a%2) cout<<"IMPOSSIBLE";
    else cout<<a/2;


    #ifdef APNA_IO
        end_routine();
    #endif
}


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

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

	int k;cin>>k;
	int num=7;
	vector<bool>vis(k);
	for(int i=0;i<k;i++){
		if(num%k==0){
			cout<<i+1<<'\n';
			return 0;
		}
		if(vis[num])break;
		vis[num]=true;

		num=10*num+7;
		num%=k;
	}

	cout<<"-1\n";

	return 0;
}

Measured memory_bytes: 3708
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = 0;
		int i = 1;
		while (true) {
			x = sc.nextInt();
			if (x == 0)break;
			System.out.println("Case " + i + ": " + x);
			i++;
		}
	}
}


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

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

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
constexpr char ZERO = '0';
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while(ZERO <= *pos) n = n * 10 + *pos++ - ZERO;
    pos++;
    while(ZERO <= *pos) m = m * 10 + *pos++ - ZERO;
    pos++;
    while(ZERO <= *pos) k = k * 10 + *pos++ - ZERO;
    nn = n;
    pos++;
    rep(i, n) {
        while(ZERO <= *pos) a[i + 1] = a[i + 1] * 10 + *pos++ - ZERO;
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while(ZERO <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while(ZERO <= *pos) b[i + 1] = b[i + 1] * 10 + *pos++ - ZERO;
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + ZERO;
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7804
to_middle = set()           #  島1から渡ることのできる島
from_middle = set()         #  島Nへ渡ることのできる島
N, M = map(int, input().split())
for _ in range(M):
    f, t = map(int, input().split())
    if f == 1:
        to_middle.add(t)
    elif t == N:
        from_middle.add(f)

if to_middle & from_middle:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 19024
lst = [set(map(int, input().split())) for _ in range(6)]
rec = []
while lst:
  x = lst[0]
  count = lst.count(x)
  if count % 2 == 1:
    print("no")
    break
  rec.append((count, x))
  for _ in range(count):
    lst.pop(lst.index(x))
else:
  if len(rec) == 1:
    if len(rec[0][1]) == 1:
      print("yes")
    else:
      print("no")
  elif len(rec) == 2:
    rec.sort()
    if rec[0][1] & rec[1][1] == rec[0][1]:
      print("yes")
    else:
      print("no")
  elif len(rec) == 3:
    if len(rec[0][1]) == len(rec[1][1]) == len(rec[2][1]) == 2 and (rec[2][1] & (rec[0][1] | rec[1][1]) == rec[2][1]):
      print("yes")
    else:
      print("no")


Measured memory_bytes: 5612
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize)(list:[usize]));
    let mut vec = Vec::<usize>::with_capacity(n);
    vec.resize(n, 0);
    for x in list {
        vec[x] += 1;
    }
    if vec[0] > 1 || (n % 2 == 0 && vec[0] != 0) {
        0
    } else {
        let mut res = 1;
        for x in vec.into_iter().skip(1) {
            res = mul(
                res,
                if x == 2 {
                    2
                } else if x == 0 {
                    1
                } else {
                    0
                },
            );
        }
        res
    }.to_string()
}

fn mul(a: usize, b: usize) -> usize {
    let g = 1000000007;
    ((a % g) * (b % g)) % g
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "5\n2 4 4 0 2" => "4",
    test2: "7\n6 4 0 2 4 0 2" => "0",
    test3: "8\n7 5 1 1 7 3 5 3" => "16",
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007
#define MAX 510000

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

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

ll	MPl(ll x, ll y) {
	return ((x+y)%MOD+MOD)%MOD;
}

ll	MMi(ll x, ll y) {
	return ((x-y)%MOD+MOD)%MOD;
}

ll	MMul(ll x, ll y) {
	return ((x*y)%MOD+MOD)%MOD;
}

// Array
vector<ll> fac(MAX, 0);
vector<ll> finv(MAX, 0);
vector<ll> inv(MAX, 0);

void	DivInit() { // fac, finv, inv
	fac.at(0) = 1;
	fac.at(1) = 1;
	finv.at(0) = 1;
	finv.at(1) = 1;
	inv.at(1) = 1;
	for (int i=2; i<MAX; i++) {
		fac.at(i) = (fac.at(i-1)*i) %MOD;
		inv.at(i) = MOD - (inv.at(MOD%i)*(MOD/i)) %MOD;
		finv.at(i) = (finv.at(i-1)*inv.at(i)) %MOD; 
	}
}

ll	MDiv(ll x, ll y) {
	if (1!=inv.at(1))
		DivInit();
	if (y<0) {
		x=-x;
		y=-y;
	}
	return ((x*inv.at(y))%MOD+MOD)%MOD;
}

ll	MComb(ll N, ll K) {
	if (1!=inv.at(1))
		DivInit();
	if (N<K)
		return 0;
	if ((N<0)||(K<0))
		return 0;
	return (fac.at(N) * ((finv.at(K)*finv.at(N-K)) %MOD)) %MOD;
}

int	main() {
	ll S;
	cin >>S;
	vector<ll> DP(S+10, 0);
	DP.at(0)=1;
	for (auto i=0; i<=S; i++) 
		for (auto j=3; i+j<=S; j++) 
			DP.at(i+j)=MPl(DP.at(i+j), DP.at(i));
	cout <<DP.at(S) <<endl;
	return 0;
}



Measured memory_bytes: 14920
import collections

n = int(input())
l = [input() for _ in [0] * n]

counted = collections.Counter(l)
#print(counted)
# 最頻値を求める
m = max(counted.values())
#print(m)
# 頻出数の文字を集める
chars = [key for key, value in counted.items()
             if value == m]

print(*sorted(chars),sep='\n')



Measured memory_bytes: 35936
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	ll n,k; cin>>n>>k;
	map<ll,ll> mp;
	ll ans=1,p=k;
	for(ll i=2;i*i<=k;i++){
		while(p%i==0){
			mp[i]++;
			p/=i;
		}
	}
	if(p!=1)mp[p]++;
	for(auto c:mp){
		ll add=1;
		ll j=c.second/n;
		rep(i,0,j)add*=c.first;
		ans*=add;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3576
import sys,bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    # 区間加算、上書き、一点取得
    class SegmentTree:
        def __init__(self, n, ele, segfun):
            #####単位元######要設定0or1orinf
            self.ide_ele = ele
            self.segfun = segfun
            ####################
            self.n = n
            self.N0 = 1 << n.bit_length()
            self.data = [self.ide_ele] * (self.N0 * 2)
 
        def update_add(self, l, r, val):
            l += self.N0
            r += self.N0
            while l < r:
                if l & 1:
                    self.data[l] += val
                    l += 1
                if r & 1:
                    self.data[r - 1] += val
                    r -= 1
                l //= 2
                r //= 2
 
        def update(self, l, r, val):
            l += self.N0
            r += self.N0
            while l < r:
                if l & 1:
                    self.data[l] = self.segfun(self.data[l], val)
                    l += 1
                if r & 1:
                    self.data[r - 1] = self.segfun(self.data[r - 1], val)
                    r -= 1
                l //= 2
                r //= 2
 
        def query(self, i):
            i += len(self.data) // 2
            ret = self.data[i]
            while i > 0:
                i //= 2
                ret = self.segfun(ret, self.data[i])
            return ret
 
    N, D, A = map(int,readline().split())
    X = [list(map(int,readline().split())) for _ in range(N)]
    X.sort()
    L = [0]*N
    for i in range(N):
        L[i] = X[i][0]
    S = SegmentTree(N,0,lambda a, b: a+b)
    ans = 0
    for i,[x,h] in enumerate(X):
        H = h - S.query(i)
        if H<=0:
            continue
        ind = bisect.bisect(L,x+2*D)
        need = (H-1)//A + 1
        S.update(i,ind,need*A)
        ans += need
    print(ans)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 84828
n=int(input())
cnt=[[0]*10 for i in range(10)]
for i in range(1,n+1):
  x=str(i)
  cnt[int(x[0])][int(x[-1])]+=1
ans=0
for i in range(10):
  for j in range(10):
    ans+=cnt[i][j]*cnt[j][i]
print(ans)

Measured memory_bytes: 3188
def s_in():
    return input()

def n_in():
    return int(input())

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

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

N = n_in()
A = l_in()
if all(map(lambda a: (a%2 == 1) or (a%3 == 0) or (a%5 == 0),A)):
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3064
'use strict'

function main(input) {
  const n = Number(input.split('\n')[0])
  const arr = input.split('\n')[1].split('')

  let max = 0
  let i = 1 //number
  let setA = new Set()
  //   let setB = new Set()
  // 初期のsetBはあらかじめ作っておく？ 
  //   for (let i in att) {
  //     setB.add(arr[i])
  //   }

  while (i < arr.length) {
    let cnt = 0

    const A = arr.slice(0, i)
    const B = arr.slice(i, n)
    // console.log(A,B)
    //新たに追加された分だけSetに追加する
    setA.add(A[i - 1])

    let setB = new Set()
    for (let i in B) {
      setB.add(B[i])
    }

    for (let item of setA) {
      if (setB.has(item)) cnt += 1
    }
    max = Math.max(max, cnt)
    i++
  }
  console.log(max)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7964
a, b, c = map(int, input().split())

if a==b and b==c and a%2==0:
    print(-1)
else:
    f = 1
    ans = 0
    while 1:
        if a%2==1 or b%2==1 or c%2==1:
            break
        else:
            a2 = b//2 + c//2
            b2 = a//2 + c//2
            c2 = a//2 + b//2
            a = a2
            b = b2
            c = c2
            ans = ans+1
        
    print(ans)

Measured memory_bytes: 3064
N, A, B, C = map(int, input().split())
l = []
for i in range(N):
    l.append(int(input()))

import itertools
import copy

MP = []
l_temp=[]

for abc_perm in list(itertools.permutations([A,B,C])):
    l_temp = copy.deepcopy(l)
    MP_consumption = 0
    for i,j in enumerate(abc_perm):
        c_list = []
        MP_consumption_list = []
        min_index = 0
        for k in range(1,len(l_temp)-(2-i)+1):
            for c in list(itertools.combinations(l_temp,k)):
                c_list.append(c)
                MP_consumption_list.append( abs(j - sum(c)) + 10*(len(c)-1 ) )
        MP_consumption += min(MP_consumption_list)
        min_index = MP_consumption_list.index(min(MP_consumption_list))
        [l_temp.remove(a) for a in c_list[min_index]]
    MP.append(MP_consumption)
print(min(MP))

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

using namespace std;

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

bool ispal(string t) {
  int n = (int) t.size();
  for (int i = 0; i < n - 1 - i; i++) {
    if (t[i] != t[n - 1 - i]) {
      return 0;
    }
  }
  return 1;
}

pair<string, string> shrink(string s, string t) {
  string a, b;
  int l = min((int) s.size(), (int) t.size()), i = 0;
  while (i < l && s[i] == t[(int) t.size() - 1 - i]) {
    i++;
  }
  for (int j = i; j < (int) s.size(); j++) {
    a += s[j];
  }
  for (int j = 0; j < (int) t.size() - i; j++) {
    b += t[j];
  }
  return {a, b};
}

void print(pair<string, string> a) {
  cout << " : " << a.first << " " << a.second << "\n";
}

const int N = 50 + 7;
const ll INF = (ll) 1e18;
int n;
string a[N];
ll c[N];
set<pair<string, string>> cur;
map<pair<string, string>, ll> dp;

ll solve(string s, string t) {
  if (dp.count({s, t})) {
    return dp[{s, t}];
  }
  if (s == "" && t == "") {
    dp[{s, t}] = 0;
    return dp[{s, t}];
  }
  if (s != "" && t != "") {
    cout << "what is going on??\n";
    exit(0);
  }
  if ((int) s.size() == 1 || (int) t.size() == 1) {
    dp[{s, t}] = 0;
    return dp[{s, t}];
  }
  dp[{s, t}] = INF;
  ll x = INF;
  for (int i = 1; i <= n; i++) {
    if (ispal(s + a[i] + t)) {
      x = min(x, c[i]);
    }
  }
  cur.insert({s, t});
  if (s == "") {
    for (int i = 1; i <= n; i++) {
      pair<string, string> it = shrink(a[i], t);
      if (!it.first.empty() && !it.second.empty()) {
        continue;
      }
      if (cur.count({it.first, it.second})) {
        continue;
      }
      x = min(x, solve(it.first, it.second) + c[i]);
    }
  }
  if (t == "") {
    for (int i = 1; i <= n; i++) {
      pair<string, string> it = shrink(s, a[i]);
      if (!it.first.empty() && !it.second.empty()) {
        continue;
      }
      if (cur.count({it.first, it.second})) {
        continue;
      }
      x = min(x, solve(it.first, it.second) + c[i]);
    }
  }
  cur.erase({s, t});
  dp[{s, t}] = x;
  return x;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
 // freopen ("input", "r", stdin);
  ll sol = INF;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> c[i];
    if (ispal(a[i])) {
      sol = min(sol, c[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    sol = min(sol, solve(a[i], "") + c[i]);
    sol = min(sol, solve("", a[i]) + c[i]);
  }
  if (sol == INF) {
    sol = -1;
  }
  cout << sol << "\n";
  return 0;
}


Measured memory_bytes: 3688
from itertools import combinations
class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		while self.table[x] >= 0:
			x = self.table[x]
		return x

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
		return

n, m = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(m)]

ans = 0
for i in range(m):
	if i == 0:
		new_edges = edges[1:]
	elif i == m - 1:
		new_edges = edges[:m - 1]
	else:
		new_edges = edges[:i] + edges[i + 1:]
	uf = UnionFind(n)
	for e in new_edges:
		uf.union(e[0] - 1, e[1] - 1)
	for a, b in combinations(range(n), r=2):
		if uf.find(a) != uf.find(b):
			ans += 1
			break

print(ans)

Measured memory_bytes: 3064
/* author : akshatjai258 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define mod int(1e9 + 7)
#define inf int(1e9)
#define endl "\n"
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define fi first
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define memf(a) memset(a, false, sizeof(a))
#define all(v) v.begin(), v.end()
#define se second
#define mp make_pair
#define pb push_back
#define w(x)  \
	int x;    \
	cin >> x; \
	while (x--)
#define ps(x, y) fixed << setprecision(y) << x
void prep()
{
	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*/
}
int main()
{
	prep();
  	int n,m;
  	cin>>n>>m;
  	int ans=0;
  	if(n>=2){
      ans+=(n*(n-1))/2;
      }
  	if(m>=2){
      ans+=(m*(m-1))/2;
      }
  cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main(){
    ll A,B,K;
    cin>>A>>B>>K;
    ll  x = min(A,K);
        A = A-x;
        K = K-x;
    ll  y = min(B,K);
        B = B-y;
        cout<<A<<" "<<B<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
  int H, i, A[MAX + 1];

  cin >> H;
  for ( i = 1; i <= H; i++ ) cin >> A[i];

  for ( i = 1; i <= H; i++ ) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if ( parent(i) >= 1 ) cout << "parent key = " << A[parent(i)] << ", ";
    if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
    if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3112