akhauriyash/Code-Regression huggingface dataset:
string = input()
n = len(string)
R = [idx for idx in range(len(string)) if string[idx] == 'R']
L = [idx for idx in range(len(string)) if string[idx] == 'L']
ans = [0]*n
r_idx = 0
l_idx = 0
while r_idx < len(R):
    r = R[r_idx]
    l = L[l_idx]
    if l < r:
        l_idx += 1
    else:
        if (l-r)%2 == 0:
            ans[l] += 1
        else:
            ans[l-1] += 1
        r_idx += 1

r_idx = len(R) - 1
l_idx = len(L) - 1
while l_idx >= 0:
    r = R[r_idx]
    l = L[l_idx]
    if l < r:
        r_idx -= 1
    else:
        if (r-l)%2 == 0:
            ans[r] += 1
        else:
            ans[r+1] += 1
        l_idx -= 1
print(' '.join(map(str, ans)))

Measured memory_bytes: 14460
from collections import defaultdict

def gcd(x,y):
    if x > y:
        x,y = y,x
    if y % x == 0:
        return x
    else:
        return gcd(y % x, x)

A, B = map(int,input().split())

d = defaultdict(int)
g = gcd(A,B)
tmp = g
for i in range(2, int(g ** 0.5) + 1):
    if tmp % i == 0:
        while tmp % i == 0:
            d[i] += 1
            tmp //= i
if tmp != 1:
    d[tmp] += 1

print(len(d)+1)

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

int main()
{
	int h1, h2, k1, k2, a, b, c, d;
	int H, K;

	cin >> h1 >> h2;
	cin >> k1 >> k2;
	cin >> a >> b >> c >> d;

	H = h1 * a + h2 * b;
	H += (h1 / 10) * c + (h2 / 20) * d;

	K = k1 * a + k2 * b;
	K += (k1 / 10) * c + (k2 / 20) * d;

	if (H > K)
	{
		cout << "hiroshi" << endl;
	}
	else if (H < K)
	{
		cout << "kenjiro" << endl;
	}
	else
	{
		cout << "even" << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
S = input()
N = len(S)

def sol():
    for i in range(N - 1):
        T = list(S[i: i + 2])
        if len(set(T)) == 1:
            return (i + 1, i + 2)
    for i in range(N - 2):
        T = list(S[i: i + 3])
        if len(set(T)) <= 2:
            return (i + 1, i + 3)
    return (-1, -1)

print(*sol())


Measured memory_bytes: 3188
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

const int Mod = 1e9 + 7;
inline int Add(int x, int y) {
  x += y;
  return x >= Mod ? x - Mod : x;
}
inline int Sub(int x, int y) {
  x -= y;
  return x < 0 ? x + Mod : x;
}
inline int Mul(int x, int y) {
  return 1LL * x * y % Mod;
}
int Pow(int x, int y = Mod - 2) {
  if (y < 0) return 0;
  int res = 1;
  while (y) {
    if (y & 1) res = Mul(res, x);
    x = Mul(x, x);
    y >>= 1;
  }
  return res;
}

const int maxn = 16;
int n, m, a[maxn + 2];
int fac[1 << (maxn + 1)], inv[1 << (maxn + 1)];
int f[maxn + 2][1 << maxn];

inline void upd(int &x, int y) { x = Add(x, y); }
inline int C(int x, int y) {
  if (x < y) return 0;
  return Mul(fac[x], Mul(inv[y], inv[x - y]));
}

int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i)
    scanf("%d", &a[i]);
  reverse(a + 1, a + 1 + m);

  fac[0] = 1;
  for (int i = 1; i < 1 << 17; ++i)
    fac[i] = Mul(fac[i - 1], i);
  inv[(1 << 17) - 1] = Pow(fac[(1 << 17) - 1]);
  for (int i = (1 << 17) - 1; i; --i)
    inv[i - 1] = Mul(inv[i], i);

  memset(f, 0, sizeof f);
  f[0][0] = 1;
  for (int i = 1; i <= m; ++i) {
    for (int state = 0; state < 1 << n; ++state) {
      if (!f[i - 1][state]) continue;
      upd(f[i][state], f[i - 1][state]);
      for (int j = 0; j < n; ++j)
        if (!(state & (1 << j))) {
          int tmp = C((1 << n) - state - a[i], (1 << j) - 1);
          tmp = Mul(tmp, fac[1 << j]);
          upd(f[i][state | (1 << j)], Mul(f[i - 1][state], tmp));
        }
    }
  }

  int ans = 0;
  for (int state = 0; state < 1 << n; ++state) {
    int cnt = 0;
    for (int i = 0; i < n; ++i)
      if (state & (1 << i)) ++cnt;
    f[m][state] = Mul(f[m][state], fac[(1 << n) - 1 - state]);
    if (cnt & 1) ans = Sub(ans, f[m][state]);
    else ans = Add(ans, f[m][state]);
  }
  ans = Mul(ans, 1 << n);
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 5760
#include <algorithm>
#include <iostream>
#include <vector>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

//テ」ツδ榲」ツつッテ」ツδュテ・ツョツ堙ァツセツゥ
#define ALL(v) (v).begin(),(v).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); ++i)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define SORT(x) sort(begin(x),end(x))
#define SELECT_SORT(x, n) sort(begin(x),begin(x)+n)
#define SWAP(type, a, b) do {type tmp = a; a = b; b = tmp;} while (0)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))

//テ・ツョツ堙ヲツ閉ー
#define INF 2000000000000
#define MAX 10

//DEBUGテァツ板ィ
#define BAR() cout << "----------------------------" << endl;
#define DUMP(v) (cerr << #v << ": " << v << endl)
#define PRINT(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

bool check(string input){
	int len = input.length();
	if(len % 2 == 0)
	{
		
		for(int i=0; i<len; i+=2)
		{
			int x = input[i] - '0';
			int y = input[i+1] - '0';
			if(x==0 || x > 6){return false;}
			if(y==0 || y > 5){return false;}
		}
		return true;
	}else{
		return false;
	}
}

int main()
{
	string table[10][10] = {{},
		                 {" ", "a", "b", "c", "d", "e"},
						 {" ", "f", "g", "h", "i", "j"},
						 {" ", "k", "l", "m", "n", "o"},
						 {" ", "p", "q", "r", "s", "t"},
						 {" ", "u", "v", "w", "x", "y"},
						 {" ", "z", ".", "?", "!", " "}};
	
	string input="0";
	while(cin >> input)
	{
		int len = input.length();
		if(check(input))
		{
			
			for(int i=0; i<len; i+=2)
			{
				int x = input[i] - '0';
				int y = input[i+1] - '0';
				cout << table[x][y];
			}
			cout << endl;
		}
		else{
			cout << "NA" << endl;
		}
	}
}

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

typedef long long int ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e9 + 5;
double PI = 3.14159265358979323846;

const int mxn = 3e5 + 7;
int n, m, k;
vi bombs_in_row[mxn];
vi col(mxn, 0);
multiset<int> best;

void update(int pos, int x) {
    best.erase(best.find(col[pos]));
    col[pos] += x;
    best.insert(col[pos]);
}

void solve() {

    cin >> n >> m >> k;
    for (int i = 0; i < m; i++) {
        best.insert(0);
    }

    for (int i = 0; i < k; i++) {
        int x, y;
        cin >> x >> y;
        --x;--y;
        bombs_in_row[x].pb(y);
        update(y,1);
    }
    int ans = 0;
    for(int i = 0;i < n;i++){
        int total = bombs_in_row[i].size();
        for(int y : bombs_in_row[i]){
            update(y,-1);
        }
        if(best.size()){
            total += *best.rbegin();
        }
        ans = max(ans, total);
        for(int y : bombs_in_row[i]){
            update(y,1);
        }
    }
    cout << ans << endl;

}

int32_t main()
{
    IOS
    // int T; cin >> T; while (T--)
    solve();
    return 0;
}


Measured memory_bytes: 34776
use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}
static MOD: i64 = 1_000_000_000 + 7;

pub fn mod_pow(mut x: i64, mut n: i64) -> i64 {
    let mut res = 1i64;
    while n > 0 {
        if n % 2 == 1 {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n /= 2;
    }
    res
}
 
pub fn inv(x: i64) -> i64 {
    mod_pow(x, MOD - 2)
}


fn main() {
    let h = input::<usize>();
    let w = input::<usize>();
    let a = input::<usize>();
    let b = input::<usize>();
    let n = 200_000;

    let mut fact = vec![1; n];
    for i in 1..n {
       fact[i]  = fact[i-1] * i as i64 % MOD;
    }
    let f = |x: usize, y: usize| -> i64 {
        fact[x + y] * inv(fact[x])  % MOD * inv(fact[y]) % MOD
    };

    let mut cnt = 0;
    for i in 0..w - b {
        cnt += f(h-a-1, b+i) * f(a-1, w-b-1-i);
        cnt %= MOD;
    }
    println!("{}", cnt);
}


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

int main(){
  int n,l; cin>>n>>l;
  vector<pair<int, bool> > fla;
  for (size_t i = 0; i < n; i++)
  {
    int tmpfl = l + i;
    if (tmpfl< 0)
    {
      tmpfl *= -1;
      fla.push_back(make_pair(tmpfl , true));
      continue;
    }
    fla.push_back(make_pair(tmpfl , false));
    
  }
  sort(fla.begin(), fla.end());
  
  fla.erase(fla.begin());
  ll ans =0;
  for (auto &&i : fla)
  {
    ans += i.second ? -1 * i.first : i.first ;
  }
  cout << ans << endl;
}

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

int main()
{
    int n,a,j=0,o=0;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a);
        if(a%2==0)
            o++;
        else j++;
    }
    int k=1;
    while(n--)
    {
        k*=3;
    }
    printf("%d\n",k-(1<<o));
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,m;
char a[102][102];
bool line[102],column[102];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%s",a[i]+1);
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=m;++j) {
			if(a[i][j]=='#') {line[i]=true;column[j]=true;}
		}
	}
	for(int i=1;i<=n;++i) {
		if(!line[i]) continue;
		for(int j=1;j<=m;++j) {
			if(!column[j]) continue;
			printf("%c",a[i][j]);
		}
		printf("\n");
	}
	return 0;
} 

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

int	main() {
	int N, M;
	cin >>N >>M;
	vector<int> ab(N+1, 0);
	for (int i=0; i<M; i++) {
		int c;
		cin >>c;
		ab.at(c)++;
		cin >>c;
		ab.at(c)++;
	}
	for (int i=1; i<=N; i++)
		if (1==ab.at(i)%2) {
			cout <<"NO" <<endl;
			return 0;
		}
	cout <<"YES" <<endl;
	return 0;
}


Measured memory_bytes: 640
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let mut a=read::<i32>();
    let b=read::<i32>();
    let mut c=1;
    while b>=c{c*=10}
    a=a*c+b;
    c=0;
    for i in 1..1000{
        if i*i==a{c+=1}
    }
    println!("{}",if c>0{"Yes"}else{"No"})
}


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

/*============================ DEBUGGING =============================*/

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

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

/*============================= DEFINES ==============================*/

#define eps 1e-9
#define mod  998244353
#define pi 2*acos(0)
#define pb push_back
#define mp make_pair
#define B begin()
#define E end()
#define F first
#define S second
#define tostr(x) to_string(x)
#define SZ(x) ((int)x.size())
#define ins insert
#define rep(i,x,y) for(int i=x;i<y;i++)
#define per(i,x,y) for(int i=x;i>y;i--)
#define repi(i,x,y) for(int i=x;i<=y;i++)
#define peri(i,x,y) for(int i=x;i>=y;i--)
#define inf (ll)LLONG_MAX
#define ds1(i,x) for(auto i=x.begin();i!=x.end();i++)
#define ds2(i,x) for(auto i:x)
#define fib(n) ceil(pow((1+sqrt(5),n)-pow((1-sqrt(5),n)/(float)(pow(2,n)*sqrt(5)
#define FIO {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define dig(n) (int)(log10(n)+1)
#define ss(x,k) substr(x,k)  // x is the start pos and k is the length of substr.
#define set(x,k) memset(x,k,sizeof x)

/*============================== TYPEDEFS ============================*/

typedef long long ll;
typedef long double ld;
typedef long l;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<bool> vb;
typedef queue<int> qi;
typedef vector<pair<int,int> > vpii;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;

/*============================ START FROM HERE =======================*/
ld d(pii a,pii b){
	return (ld)sqrt((a.F-b.F)*(a.F-b.F)+(a.S-b.S)*(a.S-b.S));
}
int main(){
	FIO
	
	int n;cin>>n;
	int a[n];
	rep(i,0,n)a[i]=i+1;
	map<int,pii> m;
	rep(i,0,n){
		int a,b;cin>>a>>b;
		m[i+1]={a,b};
	}
	vector<ld> res;
	do{
		ld tres=0;
		rep(i,0,n-1){
			tres+=(d(m[a[i]],m[a[i+1]]));
		}
		res.pb(tres);
	}while(next_permutation(a,a+n));
	debug(res);
	int x=SZ(res);
	ld ans=0;
	rep(i,0,x)ans+=res[i];
	cout<<fixed<<setprecision(10)<<ans/x;
}


Measured memory_bytes: 1652
#   C



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


mini, maxi = map(int, input().split())

for i in range(1, M):
    L, R = map(int, input().split())
    if L > mini:
        mini = L
    if R < maxi:
        maxi = R
    if mini > maxi:
        break
#    print(mini, L, R, maxi)
if mini > maxi:
    print(0)
else:
    print(maxi - mini + 1)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		ArrayList<Integer> primes = prime(104740);
		Scanner sc = new Scanner(System.in);

			while (sc.hasNext()) {
				int n = sc.nextInt();

					if (n == 0) {
						break;
					}

				long sum = 0;

					for (int i = 0; i < n; i++) {
						sum += primes.get(i);
					}

				System.out.println(sum);
			}

		sc.close();

	}

	public static ArrayList<Integer> prime(int n) {
		boolean[] arr = new boolean[n];
		ArrayList<Integer> primes = new ArrayList<Integer>();
		int limit = (int)Math.sqrt(arr.length);

		for (int j = 2 ; j <= limit; j++) {
			for(int k = 2; k * j < arr.length; k++) {
				arr[k * j] = true;
			}
		}

		arr[0] = arr[1] = true;

		for (int i = 0; i < arr.length; i++) {
			if (!arr[i]) {
				primes.add(i);
			}
		}

		return primes;
	}
}


Measured memory_bytes: 27420
#include<bits/stdc++.h>
using namespace std;
char s[100001];
int main() {
	scanf("%s",s);
	bool x=false;
	for(int i=0; i<strlen(s); i++) {
		if(s[i]=='C') {
			//cout<<"YES"<<endl;
			for(int j=i+1; j<strlen(s); j++) {
				if(s[j]=='F') {
					x=true;
					break;
				}
			}
		}
	}
	if(x==true) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())


def dfs(s):
    if int(s) > n:
        return 0
    if s.count('7') > 0 and s.count('5') > 0 and s.count('3') > 0:
        ret = 1
    else:
        ret = 0
    for c in '753':
        ret += dfs(s+c)
    return ret


print(dfs('0'))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
queue<P>que[100009];
bool f[100009];

int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    que[a].push(P(b,i));
    que[b].push(P(a,i));
  }
  
  for(int j=1;j<=n;j++){
    int p=j;
    while(!que[p].empty()){
      P now=que[p].front();que[p].pop();
      int next=now.first;
      int i=now.second;
      if(f[i]==true)continue;
      f[i]=true;
      p=next;
    }
    if(p!=j){
      cout<<"NO"<<endl;
      return(0);
    }
  }
  
  for(int i=0;i<m;i++){
    if(!f[i]){
      cout<<"NO"<<endl;
      return(0);
    }
  }

  cout<<"YES"<<endl;

  return(0);
}


Measured memory_bytes: 69504
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;

# define INF ((int)(1<<30))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12

template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 };

int main()
{
	vector<string> a, b;
	for (int i = 1; i <= 100; i++)
	{
		string s = ">\'";
		for (int j = 0; j < i; j++)s += "=";
		s += "#";
		for (int j = 0; j < i; j++)s += "=";
		s += "~";
		a.push_back(s);
	}
	for (int i = 1; i <= 100; i++)
	{
		string s = ">^";
		for (int j = 0; j < i; j++)s += "Q=";
		s += "~~";
		b.push_back(s);
	}
	
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		if (find(ALL(a), s)!=a.end())cout << "A" << endl;
		else if (find(ALL(b), s) != b.end())cout << "B" << endl;
		else cout << "NA" << endl;
	}

}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> V;
const long long MOD=1000000007LL;
const long long INFL=1LL << 60;
const int INF=1<<29;


int main() {
    int N,M;
    cin >>N>>M;
    int MAXL=0,MAXR=N-1;
    for(int i=0;i<M;i++){
        int L,R;
        cin >>L>>R;
        L--;R--;
        if(MAXL<L)MAXL=L;
        if(R<MAXR)MAXR=R;
    }
    if(MAXR-MAXL+1>0)cout <<MAXR-MAXL+1<<endl;
    else cout<<0<<endl;
    return 0;
}

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

int main()
{
    int n, A[200], v;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> A[i];
    }
    for(int i=0; i<n; i++)
    {
        v = A[i];
        int j=i-1;
        while(j>=0 && A[j]>v)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(int k=0; k<n-1; k++)
            cout << A[k] << " ";
        cout << A[n-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3060
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [INT() for _ in range(N)]

index = A.index(max(A))
A_sort = sorted(A)

for i in range(N):
	if i == index:
		print(A_sort[N - 2])
	else:
		print(A_sort[N - 1])

Measured memory_bytes: 82520
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#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 double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll X;
  cin >> X;
  ll sum = 0;
  sum += (X/500)*1000;
  X = X%500;
  sum += (X/5)*5;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n; 
    cin>> n;
    ll preva,prevb,prevc;
    cin>>preva>>prevb>>prevc;
    ll curra,currb,currc;
    for(ll i=1;i<n;i++)
    {
      cin>>curra>>currb>>currc;
      curra +=max(prevb,prevc);
      currb +=max(preva,prevc);
      currc +=max(preva,prevb);

      preva = curra;
      prevb = currb;
      prevc = currc;

    }

    cout<<max(preva,max(prevb,prevc))<<endl;
}
              

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#define MAX 1e9
using namespace std;


int main()
{
double N,T,A;
cin>>N;
cin>>T;
cin>>A;
double H,diff;
double min=MAX;
int num;
for(int i=0;i<N;i++){
  cin>>H;
  diff=fabs(A-(T-H*0.006));
if(min>diff){
  num=i+1;
  min=diff;
 }
}
cout<<num<<endl;
return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}


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


	int N = getint();

	int A[301][301];
	rep1(i, N) {
		rep1(ii, N) {
			A[i][ii] = getint();
		}
	}

	int shouryaku[301][301] = {};
	rep1(k, N) {
		rep1(i, N) {
			if (k == i) continue;
			rep1(j, N) {
				if (k == j) continue;
				if (A[i][j] > A[i][k] + A[k][j]) {
					printf("-1");
					return 0;
				}
				else if (A[i][j] == A[i][k] + A[k][j]) {
					shouryaku[i][j] = 1;
				}
			}
		}
	}

	ll goukei = 0;
	rep1(i, N) {
		rep1(ii, i - 1) {
			if (shouryaku[i][ii] == 0) goukei += A[i][ii];
		}
	}

	printf("%lld", goukei);

	Would you please return 0;
}

Measured memory_bytes: 1024
N = int(input())
A_list = list(map(int, input().split()))
two_list = [2 ** i for i in range(32)]

count = 0
items = {}
for a in A_list:
    if a in items.keys():
        items[a] += 1
    else:
        items[a] = 1
A_list.sort(reverse=True)
import bisect

for a in A_list:
    if items[a] >= 1:
        index = bisect.bisect_left(two_list, a)
        for t in two_list[index:]:
            m = t - a
            if m in items.keys():
                if m == a and items[a] >= 2:
                    count += 1
                    items[a] -= 2
                    break

                elif m != a and items[m] >= 1 and items[a] >= 1:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
print(count)


Measured memory_bytes: 33424
import java.io.*;

class Main
{
   public static void main(String[] args) throws IOException
   {
   
      BufferedReader br =
       new BufferedReader(new InputStreamReader(System.in));
       
       String str = br.readLine();
       int x = Integer.parseInt(str);
       
       System.out.println( x*x*x );
   }
}

Measured memory_bytes: 24312
#include <stdio.h>

int main(void) {

  int P, Q, R;
  do {
    scanf("%d %d %d", &P, &Q, &R);
  } while (P < 1 || P > 100 || Q < 1 || Q > 100 || R < 1 || R > 100);

  int min;
  int time[3];

  time[0] = P + Q;
  time[1] = Q + R;
  time[2] = R + P;

  min = time[0];
  for (int i = 1; i < 3; i++) {
    if (min > time[i]) {
      min = time[i];
    }
  }

  printf("%d\n", min);

  return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <algorithm>
#include <tuple>
#include <utility>
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;
using ll = long long int;
using Graph = vector< vector<int> >;

/*
void chmax(ll &A, const ll B) {
  A = max(A, B);
}
*/

ll N, K, dp[100010][2][2], sz[100010];

void dfs(Graph &G, int cur, int par=-1) {
  sz[cur] = 1;
  for(auto to : G[cur]) {
    if(to == par) continue;
    dfs(G, to, cur);
    sz[cur] += sz[to];
  }
}

int solve(Graph &G, int cur, int f1, int f2, int par=-1) {
  if(dp[cur][f1][f2] >= -1) return dp[cur][f1][f2];

  ll val = -1;
  if(f1 == 0) {
    if(f2 == 0) {
      val = 0;
      for(auto to : G[cur]) {
        if(to == par) continue;
        val += (sz[to] >= K);
      }
    }

    if(f2 == 1) {
      for(auto to : G[cur]) {
        if(to == par) continue;
        ll tmp = solve(G, to, 0, 1, cur);
        if(tmp >= 0) val = max(val, tmp);

        tmp = solve(G, to, 1, 1, cur);
        if(tmp >= 0) {
          tmp += (N - sz[to]) >= K;
          val = max(val, tmp);
        }
      }
    }

    return dp[cur][f1][f2] = val;
  }
  if(f1 == 1) {
    int M = G[cur].size();
    vector<ll> dpcur(3, -1);
    dpcur[0] = 0;
    for(size_t i=0; i<G[cur].size(); i++) {
      int to = G[cur][i];
      if(to == par) continue;
      
      vector<ll> dpnxt(3, -1);
      for(int j=0; j<=2; j++) {
        if(dpcur[j] < 0) continue;
        
        // take
        if(j < 2) {
          ll tmp = solve(G, to, 1, 0, cur);
          if(tmp >= 0) {
            dpnxt[j+1] = max(dpnxt[j+1], dpcur[j] + tmp);
          }
        }

        // do not take
        dpnxt[j] = max(dpnxt[j], dpcur[j] + (sz[to] >= K));
      }
      swap(dpcur, dpnxt);
    }

    if(f2 == 0) {
      return dp[cur][f1][f2] = (val = max(dpcur[0], dpcur[1]));
    }
    if(f2 == 1) {
      return dp[cur][f1][f2] = (val = max(dpcur[1], dpcur[2]));
    }
  }
}

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

  Graph G(N);
  for(int i=0; i<N-1; i++) {
    int u, v; cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  fill(dp[0][0], dp[N+1][0], -2);
  dfs(G, 0);
  cout << max(solve(G, 0, 0, 1), solve(G, 0, 1, 1)) << endl;

  /*
  for(int i=0; i<N; i++) {
    for(int f1=0; f1<2; f1++) {
      for(int f2=0; f2<2; f2++) {
        fprintf(stderr, "dp[%d][%d][%d] = %lld\n", i, f1, f2, dp[i][f1][f2]);
      }
    }
  }
  */
  return 0;
}



Measured memory_bytes: 23400
#include <functional>
#include <cassert>
#include <vector>
#include <iostream>
using namespace std;

int main() {
    int R, C, N; cin >> R >> C >> N;
    int X[N], Y[N], A[N];
    vector<int> px[R], py[C];
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i] >> A[i];
        X[i]--;
        Y[i]--;
        px[X[i]].push_back(i);
        py[Y[i]].push_back(i);
    }
    vector<int> adj[N];
    for (int x = 0; x < R; x++) {
        for (int i = 1; i < px[x].size(); i++) {
            adj[px[x][0]].push_back(px[x][i]);
            adj[px[x][i]].push_back(px[x][0]);
        }
    }
    for (int y = 0; y < C; y++)
        for (int i = 1; i < py[y].size(); i++) {
            adj[py[y][0]].push_back(py[y][i]);
            adj[py[y][i]].push_back(py[y][0]);
        }
    vector<bool> visited(N, false);
    vector<long long> b(R, -1), c(C, -1);
    function<void(int, vector<int>&)> dfs = [&](int i, vector<int> &nodes) {
        visited[i] = true;
        nodes.push_back(i);
        int x = X[i], y = Y[i], a = A[i];
        if (b[x] == -1) {
            if (c[y] == -1) { b[x] = a; c[y] = 0; }
            else b[x] = a - c[y];
        } else {
            if (c[y] == -1) c[y] = a - b[x];
            else if (a != b[x] + c[y]) {
                cout << "No\n";
                exit(0);
            }
        }
        for (int j : adj[i])
            if (!visited[j]) dfs(j, nodes);
    };

    for (int i = 0; i < N; i++) {
        if (!visited[i]) {
            vector<int> nodes;
            dfs(i, nodes);
            long long bmin = 1LL<<60, cmin = 1LL<<60;
            for (int j : nodes) {
                assert (b[X[j]] + c[Y[j]] == A[j]);
                bmin = min(bmin, b[X[j]]);
                cmin = min(cmin, c[Y[j]]);
            }
            if (bmin + cmin < 0) { cout << "No\n"; return 0; }
        }
    }
    cout << "Yes\n";
}


Measured memory_bytes: 26320
using System;
using System.Linq;

namespace abc089_c
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] name = new char[] { 'M','A','R','C','H' };
            long[] people = new long[5];
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                if (name.Contains(s[0]))
                {
                    people[Array.IndexOf(name,s[0])]++;
                }
            }
            long ret = 0;
            for (int i = 0; i < 5; i++)
            {
                for (int j = i + 1; j < 5; j++)
                {
                    for (int k = j + 1; k < 5; k++)
                    {
                        ret += people[i] * people[j] * people[k];
                    }
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 17356
#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 each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        int a,b; cin>>a>>b;
        cout<<(a+b)%24<<endl;
}

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

using namespace std;

typedef long long LL;

string long_division(string number, LL divisor)
{
    string ret = "";
    LL temp = 0;
    queue<LL>q;

    for(int i=0; i<number.size(); i++)
    {
        temp = (temp * 10) + (number[i] - '0');
        q.emplace(temp/divisor);
        temp %= divisor;
    }

    if(q.empty()) return "0";

    while(q.front()==0) q.pop();
    while(!q.empty())
    {
        ret += q.front() + '0';
        q.pop();
    }
    return ret;
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen("error.txt", "w", stderr);

    /*for(int i=0; i<=9; i++) cout<<"value["<<i<<"] = "<<i<<";\n";
    for(int i=10; i<=32; i++) cout<<"value["<<i<<"] = '"<<(char)(i+55)<<"';\n";*/

    //int t; cin>>t; while(t--) {
        int n;
        cin>>n;
        while(n)
        {
            if(n%10==7)
            {
                cout<<"Yes\n";
                return 0;
            }

            n /= 10;
        }

        cout<<"No\n";
    //}

    return 0;
}


Measured memory_bytes: 3648
#!/usr/bin/env python
# coding: utf-8

# In[25]:


N,M = map(int, input().split())
ab = []
mylist = [[] for _ in range(N)]
for _ in range(M):
    ab.append(list(map(int, input().split())))
    mylist[ab[-1][0]-1].append(ab[-1][1])
    mylist[ab[-1][1]-1].append(ab[-1][0])


# In[27]:


ans = [len(cities) for cities in mylist]
for x in ans:
    print(x)


# In[ ]:






Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N,M;
    cin >> N >> M;
    vector<int>X(M);
    for(int i = 0; i < M; i++) {
        cin >> X[i];
    }
    sort(X.begin(),X.end());
    vector<int>Y(M-1);
    for(int i = 0; i < M-1; i++) {
        Y[i] = X[i+1]-X[i];
    }
    sort(Y.begin(),Y.end());
    int ans = X[M-1]-X[0];
    for(int i = 0; i < min(N-1,M-1); i++) {
        ans-=Y[M-2-i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 1792
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val (n, m) = sc.nextLine().split(" ").map { it.toInt() }
    val asum = sc.nextLine().split(" ").map { it.toInt() }.sum()

    println(if(asum>n) -1 else n-asum)
}

Measured memory_bytes: 41764
import Data.Char

solve :: String->Int
solve [] = 0
solve (x:xs)
    | isDigit x = num + (solve xs')
    | otherwise = solve xs
        where digits = takeWhile isDigit (x:xs)
              num = read digits :: Int
              xs' = drop (length digits) (x:xs)
main = do
    ss <- getContents
    print $ solve ss

Measured memory_bytes: 3880
if __name__ == '__main__':
    N = input()
    heap_array = [int(i) for i in input().split()]

    for i in range(len(heap_array)):
        print("node {}: key = {}, ".format(i+1, heap_array[i]), end='')
        if (i-1)//2 != -1 :
            print("parent key = {}, ".format(heap_array[(i-1)//2]), end='')
        if 2*i+1 < len(heap_array):
            print("left key = {}, ".format(heap_array[2*i+1]), end='')

        if 2*i+2 < len(heap_array):
            print("right key = {}, ".format(heap_array[2*i+2]), end='')
        print('')

Measured memory_bytes: 7728
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  string s;
  cin >> s;
  vector<int> v(s.size());
  int i = 0;
  while(i < s.size()) {
	int a = 0, b = 0;
	while(i < s.size() && s[i] == 'R') { a++; i++; }
	int r = i - 1;
	int l = i;
	while(i < s.size() && s[i] == 'L') { b++; i++; }
	if(a >= b) {
	  if((a - b) % 2 == 0) {
		v[r] = v[l] = (a + b) / 2;
	  } else {
		v[r] = v[l] = (a + b) / 2;
		if(a % 2 == 0) v[l]++;
		else v[r]++;
	  }
	} else {
	  if((b - a) % 2 == 0) {
		v[r] = v[l] = (a + b) / 2;
	  } else {
		v[r] = v[l] = (a + b) / 2;
		if(b % 2 == 0) v[r]++;
		else v[l]++;
	  }
	}
  }
  rep(i, v.size()) {
	cout << v[i];
	if(i != v.size() - 1) cout << ' ';
  }
  cout << endl;
}


Measured memory_bytes: 1088
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int n, s;
int memo[11][1024][400];

int solve( int t, int state, int sum ) {
    if ( sum < 0 ) return 0;
    if ( t == n + 1 ) return sum == 0;
    if ( memo[t][state][sum] != -1 ) return memo[t][state][sum];
    int answer = 0;
    for ( int i = 0; i < 10; ++ i ) {
        if ( state & ( 1 << i ) ) continue;
        answer += solve( t + 1, state | ( 1 << i ), sum - i * t );
    }
    return memo[t][state][sum] = answer;
}

int main() {
    int prev = -1;
    while ( scanf( "%d%d", &n, &s ) != EOF ) {
        if ( prev == n ) goto output;
        for ( int i = 0; i < 11; ++ i ) {
            for ( int j = 0; j < 1024; ++ j ) {
                for ( int k = 0; k < 400; ++ k ) {
                    memo[i][j][k] = -1;
                }
            }
        }
    output:;
        printf( "%d\n", ( s > 400 ? 0 : solve( 1, 0, s ) ) );
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cassert>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
// nice job //
ll n;
const ll mod = 998244353;
const ll N = 1e7 + 5;
ll fac[N];
ll ifac[N];
ll ME(ll x, ll P, ll m)
{
        ll res = 1LL;
        ll cur = x;
        while(P) {
                if(P&1) res = (res * cur)%mod;
                cur = (cur * cur)%mod;
                P >>= 1;
        }
        return res;
}
ll inv(ll x)
{
        return ME(x , mod-2, mod);
}
int main() {
        cin >> n;
        fac[0] = 1LL;
        ifac[0] = 1LL;
        for(ll i=1;i<=n+2;i++) {
                fac[i] = (fac[i-1] * i)%mod;
                ifac[i] = inv(fac[i]);
        }
        ll ans = 1LL;
        vector< ll > pw;
        pw.push_back(1LL);
        for(ll i=1;i<=n;i++) {
                pw.push_back(((pw.back())*2LL)%mod);
        }
        for(ll i=1;i<=n;i++) {
                ans = (ans * 3LL)%mod;
        }
        for(ll i = (n/2) + 1 ; i <= n ; i++) {
                ll h  = (fac[n] * ifac[i])%mod;
                h = (h * ifac[n-i])%mod;
                h = (h * pw[n-i+1])%mod;
                ans = (ans - h + mod)%mod;
        }
        cout << ans << endl;
}


Measured memory_bytes: 289628
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    k,x=MI()
    if 500*k>=x:print("Yes")
    else:print("No")
main()

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

namespace AtCoder.Abc
{
    class A_alphabet_171
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();

            string result;

            if (Regex.IsMatch(s, "[a-z]"))
            {
                result = "a";
            }
            else
            {
                result = "A";
            }



            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 26876
# https://atcoder.jp/contests/abc071/tasks/arc081_a
# C - Make a Rectangle
import collections

N = int(input().split()[0])
a_list = list(map(int, input().split()))

counter = collections.Counter(a_list)
count_dict = {k: v for k, v in counter.items() if v >= 2}
if count_dict:
    length_list = sorted(list(count_dict.keys()), reverse=True)

    if len(length_list) == 1 and counter[length_list[0]] < 4:
        area = 0
    elif counter[length_list[0]] >= 4:
        area = length_list[0] ** 2
    else:
        area = length_list[0] * length_list[1]
else:
    area = 0

print(area)


Measured memory_bytes: 18600
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string n;
    int k;
    cin >> n >> k;
    int s=n.size();
    ll dp[2][s+1][k+2];//kk==1ならn未満が保証される
    rep(kk,2){
        rep(i,s+1){
          	rep(j,k+1){
              	dp[kk][i][j]=0;
            }
        }
    }
    dp[0][0][0]=1;
    rep(i,s){
        int N=n[i]-'0';
        rep(kk,2){
            int T=9;
            if(kk==0){
                T=N;
            }
            rep(j,k+1){
                rep(d,T+1){
                    int NZ=0;
                    if(d!=0){
                        NZ++;
                    }
                    dp[kk||(d<T)][i+1][j+NZ]+=dp[kk][i][j];
                }
            }
        }
    }
    cout << dp[0][s][k] + dp[1][s][k] << endl;
}

Measured memory_bytes: 3656
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
    b[i]=a[i]+i+1
    a[i]=i+1-a[i]
A=Counter(a)
B=Counter(b)
ans=0
for i in A:
    if i in B:
        ans+=A[i]*B[i]
print(ans)

Measured memory_bytes: 125688
n, m = map(int, input().split())
d = [[float("inf")] * n for _ in range(n)]
d_org = [[float("inf")] * n for _ in range(n)]
for _ in range(m):
	a, b, c = map(int, input().split())
	d[a - 1][b - 1] = c
	d[b - 1][a - 1] = c
	d_org[a - 1][b - 1] = c
	d_org[b - 1][a - 1] = c

for k in range(n):
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if d[i][k] + d[k][j] < d[i][j]:
				d[i][j] = d[i][k] + d[k][j]

ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if d_org[i][j] < float("inf") and d_org[i][j] > d[i][j]:
			ans += 1

print(ans)

Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
double a,b,h,m;
const double pi=3.14159265358979323;
int main(){
	scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
//	printf("%.6lf\n",a);
//	printf("%.6lf\n",b);
//	printf("%.6lf\n",h);
//	printf("%.6lf\n",m);
	double hour=h*30+m*0.5;
//	printf("%.6lf\n",hour);
	double ang=hour-m*6;
	ang=abs(ang);
	if(ang>=180)ang=360-ang;
//	printf("%.12lf\n",ang);
	double ans=sqrt(a*a+b*b-cos(ang*pi/180.0)*2*a*b);
	printf("%.12lf\n",ans);
	return 0;
}


Measured memory_bytes: 4136
from collections import deque
def solve():
    H,W = map(int,input().split())
    A = [list(input()) for _ in range(H)]

    q = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                q.append((h,w))
    
    q.append((-1,-1))
    ans = 0
    while len(q) > 0:
        h,w = q.popleft()
        if h == -1 and w == -1:
            if len(q) > 0:
                q.append((-1,-1))
                ans += 1
            continue

        d = ((0,1),(0,-1),(1,0),(-1,0))
        for dh, dw in d:
            if 0 <= h+dh < H and 0 <= w+dw < W and A[h+dh][w+dw] == '.':
                A[h+dh][w+dw] = '#'
                q.append((h+dh,w+dw))
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 114268
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int x,y,tmp;
    cin>>x>>y;
    int ses=inf;
    if(x==y)
    {
        cout<<"0"<<endl;
        return 0;
    }
    int nx=-x;
    int ny=-y;
    if(x<=y)
    {
        ses=min(ses,y-x);
    }
    if(x<=ny)
    {
        ses=min(ses,ny-x+1);
    }
    if(nx<=y)
    {
        ses=min(ses,y-nx+1);
    }
    if(nx<=ny)
    {
        ses=min(ses,ny-nx+2);
    }
   cout<<ses<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int w,h,n;
    cin>>w>>h>>n;
    vector<int>x(n),y(n),a(n);
    rep(i,n)cin>>x[i]>>y[i]>>a[i];
    pair<int,int>c(0,0),d(w,h);
    rep(i,n){
        if(a[i]==1)c.first=max(c.first,x[i]);
        if(a[i]==2)d.first=min(d.first,x[i]);
        if(a[i]==3)c.second=max(c.second,y[i]);
        if(a[i]==4)d.second=min(d.second,y[i]);
    }
    if(d.first-c.first<=0||d.second-c.second<=0){
        cout<<0<<endl;
    }
    else{
        cout<<(d.first-c.first)*(d.second-c.second)<<endl;
    }
    return 0;
}

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

struct Happy {
    ll takahashi, aoki, takahashi_value;
};

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

    vector<Happy> happiness(n);
    rep(i, n) cin >> happiness[i].takahashi >> happiness[i].aoki;
    rep(i, n) happiness[i].takahashi_value = happiness[i].takahashi + happiness[i].aoki;

    sort(happiness.rbegin(), happiness.rend(), [](Happy &h, Happy &i) {
        return h.takahashi_value < i.takahashi_value;
    });

    ll takahashi = 0, aoki = 0;
    rep(i, n) {
        if (i % 2 == 0) {
            takahashi += happiness[i].takahashi;
        } else {
            aoki += happiness[i].aoki;
        }
    }

    cout << takahashi - aoki << endl;


}

Measured memory_bytes: 2560
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class BPalindromePhilia {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        int ans=0;
        for(int i=0;i<(int)s.size()-i-1;i++){
            if(s[i]!=s[(int)s.size()-i-1]){
                ans++;
            }
        }
        out << ans << endl;
	}
};


int main() {
	BPalindromePhilia solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import sys

S = input()

# S = 'akasaka'

N = len(S)

S_rev = S[::-1]
if S != S_rev:
    print('No')
    sys.exit(0)

sub_S = S[:int((N - 1)/2)]
sub_S_rev = S[int((N + 3)/2)-1:]
if sub_S != sub_S_rev:
    print('No')
    sys.exit(0)

print('Yes')

Measured memory_bytes: 3060