akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>

using namespace std;

bool check(string s,vector<string> x){
    for(int i=0;i<x.size();i++){
	if(s == x[i]) return false;
    }
    return true;
}
string split(string s,int i){
    string temp="";
    for(int j=0;j<=i;j++){
	temp += s[j];
    }
    for(int j=s.length()-1;j>i;j--){
	temp += s[j];
    }
    return temp;
} 
string split1(string s,int i){
    string temp="";
    for(int j=s.length()-1;j>i;j--){
	temp += s[j];
    }
    for(int j=0;j<=i;j++){
	temp += s[j];
    }
    return temp;
}
string rsplit(string s,int i){
    string temp="";
    for(int j=i;j<s.length();j++){
	temp += s[j];
    }
    for(int j=i-1;j>=0;j--){
	temp += s[j];
    }
    return temp;
}
string rsplit1(string s,int i){
    string temp="";
    for(int j=i-1;j>=0;j--){
	temp += s[j];
    }
    for(int j=i;j<s.length();j++){
	temp += s[j];
    }
    return temp;
}
string bsplit(string s,int i){
    string temp="";
    for(int j=i-1;j>=0;j--){
	temp += s[j];
    }
    for(int j=s.length()-1;j>=i;j--){
	temp += s[j];
    }
    return temp;
}
string osplit(string s,int i){
    string temp="";
    for(int j=i;j<s.length();j++){
	temp += s[j];
    }
    for(int j=0;j<i;j++){
	temp += s[j];
    }
    return temp;
}

int def(string s){
    int size;
    vector<string> x;
    size = s.length();
    x.push_back(s);

    for(int i=0;i<size;i++){
	string t = split(s,i);
	if(check(t,x)) x.push_back(t);
	t = rsplit(s,i);
	if(check(t,x)) x.push_back(t);
	t = split1(s,i);
	if(check(t,x)) x.push_back(t);
	t = rsplit1(s,i);
	if(check(t,x)) x.push_back(t);
	t = bsplit(s,i);
	if(check(t,x)) x.push_back(t);
	t = osplit(s,i);
	if(check(t,x)) x.push_back(t);
    }
    return x.size();
}
        

int main(){

    int n;
    cin >> n;
    for(int i=0;i<n;i++){
	string s;
	cin >> s;
	cout << def(s) << endl;
    }
    return 0;
}

Measured memory_bytes: 1312
from math import *

def Prime_Factorization(M):
    factor_count_list = []
    root_M = int(sqrt(M))

    while root_M > 1:
        root_M = int(sqrt(M))

        for i in range(2, root_M + 1):
            e = 0
            while M % i == 0:
                e += 1
                M = M // i
            if e > 0:
                factor_count_list.append(e)
                break
        else:
            break

    if M > root_M:
        factor_count_list.append(1)

    return factor_count_list

def comb(num_object, num_bar):
    numerator = 1

    for i in range(num_bar):
        numerator = (numerator * (num_object - i))

    return  numerator // factorial(num_bar)

def all_comb(N, factor_count_list):
    ans = 1
    for factor in factor_count_list:
        ans = (ans * comb(factor + N - 1, factor)) % (10 ** 9 + 7)
    return ans

def main():
    N, M = map(int, input().split())
    factor_count_list = Prime_Factorization(M)

    print(all_comb(N, factor_count_list))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n;
    cin>>n;
    vector<ll> v(n);
    REP(i,n){
        cin>>v[i];
    }
    ll sum=0;
    REP(i,n){
        sum+=v[i]-1;
    }
    cout<<sum;
    return 0;
}


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

int main(){
  int N,c=0,ans=0;
  string s;
  cin>>N>>s;

  for(int i=0;i<N;i++){
    if(s.at(i)=='A'){
      c=1;
      continue;
    }
    else if(s.at(i)=='B'&&c==1){
      c=2;
      continue;
    }
    else if(s.at(i)=='C'&&c==2){
      c=0;
      ans++;
      continue;
    }
    else
      c=0;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=12;
const int mod=998244353;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,m,f[2][N][N],C[N][N],r[N],c[N];
char s[N];

int sgn(int x) {
	return x&1?1:mod-1;
}

int main() {
	for(int i=0;i<N;i++) {
		C[i][0]=1;
		for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	for(int t=0;t<2;t++) {
		for(int i=0;i<N;i++)
			for(int j=0;j<N;j++) if(!i||!j) f[t][i][j]=1<<((i+j)*t);
		for(int i=1;i<N;i++)
			for(int j=1;j<N;j++) {
				for(int k=1;k<=i;k++) f[t][i][j]=(f[t][i][j]+1ll*C[i][k]*f[t][i-k][j]%mod*sgn(k)%mod*(1<<k))%mod;
				for(int k=1;k<=j;k++) f[t][i][j]=(f[t][i][j]+1ll*C[j][k]*f[t][i][j-k]%mod*sgn(k)%mod*(1<<k))%mod;
				for(int k=1;k<=i;k++)
					for(int l=1;l<=j;l++) f[t][i][j]=(f[t][i][j]+2ll*C[i][k]*C[j][l]%mod*f[t][i-k][j-l]%mod*sgn(k+l))%mod;
			}
	}
	cin>>n>>m;
	for(int i=0;i<n;i++) {
		scanf("%s",s);
		for(int j=0;j<m;j++) if(s[j]=='#') r[i]|=1<<j,c[j]|=1<<i;
	}
	int ans=0;
	for(int i=1;i<(1<<n);i++)
		for(int j=1;j<(1<<m);j++) {
			bool fl=0;int a=0,b=0;
			for(int k=0;k<n;k++) if(i>>k&1) ++a,fl|=((r[k]&j)==j||(~r[k]&j)==j);
			for(int k=0;k<m;k++) if(j>>k&1) ++b,fl|=((c[k]&i)==i||(~c[k]&i)==i);
			if(!fl) ans=(ans+f[1][n-a][m-b])%mod;
		}
	ans=(ans+f[0][n][m])%mod;cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

int main(){
    llong A,B;
    cin >> A >> B;
    string S;
    cin >> S;
    for(int i=0; i<(A+B+1); i++){
        if(i==A){
            if(S[i]!='-'){
                cout << "No" << endl;
                exit(0);
            }
            continue;
        }
        if(!isdigit(S[i])){
            cout << "No" << endl;
            exit(0);
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >>n>>m;
  vector<int>a(n),b(n),c(m),d(m),kyori(n),kotae(n);
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    kyori[i]=INT_MAX;
    kotae[i]=0;
  }
  for(int i=0;i<m;i++){
    cin>>c[i]>>d[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(kyori[i]>abs(a[i]-c[j])+abs(b[i]-d[j])){
        kyori[i]=abs(a[i]-c[j])+abs(b[i]-d[j]);
        kotae[i]=j+1;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<kotae[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld;
#define has_bit(bit_mask, x) ((bit_mask) & (1Uint << (x)))
#define turn_on_bit(bit_mask, x) (bit_mask |= (1Uint << (x)))
#define turn_off_bit(bit_mask, x) (bit_mask &= (~(1Uint << (x))))
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
#define MOD 1000000007

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll a, b, k;
    cin >> a >> b >> k;
    ll x = min(a, k);
    a -= x, k -= x, b -= min(b, k);
    cout << a << " " << b << '\n';
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    int x, y;
    cin >> x >> y;
    cout << x+y/2 << endl;

    return 0;
}

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

int bisearch(int *a,int key, int left, int right){
    int mid = (left + right) /2;
    if(a[mid] == key) return key;
    if(left >= right) return -1;
    if(key<a[mid]){
        return bisearch(a,key,left,mid-1);
    }else{
        return bisearch(a,key,mid+1,right);
    }
}

int main(int argc, char const *argv[])
{
    int n,q, s[100000],key,cnt=0;
    cin >> n;
    
    for(int i = 0; i < n; i++) cin >> s[i];

    cin >> q;
    for(int i = 0;i<q;i++){
        cin >> key;
        if (bisearch(s,key,0,n) != -1) cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3464
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
inline int read()
{
	int num=0, w=0;
	char ch=0;
	while (!isdigit(ch))
	{
		w|=ch=='-';
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = (num<<3) + (num<<1) + (ch^48);
		ch = getchar();
	}
	return w? -num: num;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=2e6+10;
int a[N];
void solve()
{
	int ans=0;
	int n;
	cin>>n;
	string str;
	cin>>str;
	int l=0,r=n-1;
	while(l<r)
	{
		while(l<=n-1&&str[l]=='R')
			l++;
		while(r>=0&&str[r]=='W')
			r--;
		if(l<r)
		{
			ans++;
			swap(str[l],str[r]);
		}
	}
	cout<<ans<<endl;
}
signed main()
{
	int t=1; 
	while(t--)
		solve();
	return 0;
}



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

using namespace std;

using ll = long long;

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

    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+') cout << a + b << endl;
    else cout << a - b << endl;

    return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

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

    int p, m, c;
    cin >> p >> m >> c;

    cout << p + m + c << endl;    

    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 2, 0);
  FOR(i, 1, n + 1) cin >> a[i];

  int res = 0;
  rep(i, n + 1) res += abs(a[i + 1] - a[i]);

  rep(i, n) {
    cout << res - abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i]) << endl;
  }




  
  return 0;
}

Measured memory_bytes: 1664
S = input()
ans = 0
for i in range(2 ** (len(S) - 1)):
	bit = bin(i)[2:].rjust(len(S) - 1, "0")
	start = 0
	tmp = 0
	for j in range(len(bit)):
		if bit[j] == "1":
			tmp += int(S[start: j + 1])
			start = j + 1
		if j == len(bit) - 1:
			tmp += int(S[start:])
	ans += tmp
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define EPS 1e-8
#define INF 1e9+10
#define INFL 1e18
typedef long long ll;
using namespace std;
ll dp[100010][13];
int main()
{
   int N;
   cin >> N;
   vector<double>v(N,0);
   rep(i,N)cin >> v[i];

   sort(v.begin(),v.end());
   double ans=v[0];
   for(int i=1;i<N;i++){
       ans+=v[i];
       ans/=2;
   }
   cout << ans << endl;
}



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

int main() {
  int H,W;
  cin >> H >> W;
  vector<char> A(H*W);
  
  for(int i=0;i<W*H;i++){
  cin >> A.at(i);
  }
  //1
  for(int k=0;k<W+2;k++){
  cout << "#";
  }
  cout << endl;
  //2~H+1
  int p = 0;
  for (int i=0;i<H;i++){
    cout << "#";
    for(int j=0;j<W;j++){
    cout << A.at(p);
    p ++;
    }
    cout << "#" << endl;
    }
  //H+2
  for(int k=0;k<W+2;k++){
  cout << "#";
  }
  cout << endl;
}

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

int main() {
    long N;
    cin >> N;
    if (N == 1) cout << 0 << endl;
    else {
        long num = N;
        int res = 0;
        for (long i = 2; i * i <= N; i++) {
            int cnt = 0;
            while (num % i == 0) {
                num /= i;
                cnt++;
            }
            int j = 1;
            while (cnt - j >= 0) {
                cnt -= j;
                res++;
                j++;
            }
        }
        if (num != 1) 
          res++;
        cout << res << endl;
    }
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main()
{
    IOS;
   //freopen("inputfile.txt","r",stdin);
   ll n,m;cin>>n>>m;
   ll ar[n];
   for(ll i=1;i<=n;i++)cin>>ar[i];
   ll count = 0;
   set<ll> v[n+1];
   while(m--)
   {
       ll a,b;cin>>a>>b;
       v[a].insert(b);
       v[b].insert(a);
   }
    for(ll i=1;i<=n;i++)
   {
       bool flag = true;
      for(auto x:v[i])
      {

          if(ar[i]<=ar[x])
          {
              flag = false;
             break;
          }
      }
      if(flag==true)count++;
   }
   cout<<count<<endl;
    return 0;
}
//<!...........ALHAMDULILLAH.............!!>>



Measured memory_bytes: 18496
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;



int main(){
	int n;
	int dp[40];
	
	dp[0] = 1, dp[1] = 1, dp[2] = 2, dp[3] = 4;
	for(int i=4; i<35; i++){
		dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
	}

	while(cin >> n){
		if(!n) break;
		cout << (dp[n] + 3649) / 3650  << endl;
	}


    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int w, n, l, r;
    cin >> w >> n;

    vector<int>a(w+1);
    for(int i=0; i<w+1; i++) a[i] = i;

    for(int i=0; i<n; i++){
        scanf("%d,%d", &l,&r);
        swap(a[r], a[l]);
    }

    for(int i=1; i<w+1; i++) cout << a[i] << endl;

    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
vector<int> adj1[maxn];
vector<int> adj2[maxn];
vector<bool> seen(maxn,0);
void dfs(int u){
 seen[u]=1;
 for(int v:adj1[u]){
  if(!seen[v]) {
   dfs(v);
  }
 }
 for(int v:adj2[u]){
  if(!seen[v]){
   dfs(v);
  }
 }
}
int main(){
 int n,m;
 cin >> n >> m;
 for(int i=0;i<m;i++){
  int x,y,z;
  cin >> x >> y >> z;
  if(z&1){
   adj1[x].push_back(y);
   adj1[y].push_back(x);
  }
  else{
   adj2[x].push_back(y);
   adj2[y].push_back(x);
  }
 }
 int ans=0;
 for(int i=1;i<=n;i++){
  if(!seen[i]){
   dfs(i);
   ans++;
  }
 }
 cout<<ans<<endl;

 return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ std::cin >> head; _cin(std::forward<Tail>(tail)...); }
void _cout(){ std::cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ std::cout << head; _cout(std::forward<Tail>(tail)...); }
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; For(i, n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__);
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

using namespace std;
using ll = long long;

int main(void){
    Cin(int, h, w);
    Rep(w+2) cout << "#"; cout << "\n";
    Rep(h){
        cout << "#";
        Rep(w){
            Cin(char, c); cout << c;
        }
        cout << "#\n";
    }
    Rep(w+2) cout << "#"; cout << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    if(abs(c-a) <= d || (abs(b-a) <= d && abs(c-b) <= d))
        cout << "Yes" << endl;
    else
    cout << "No" << endl;
    
    return 0;

}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DModSum solver = new DModSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class DModSum {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            long n = s.nextInt();
            w.println(n * (n - 1) >> 1);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 23252
#include<cstdio>
#include<cmath>

#include<iostream>
using namespace std;
int main()
{
int m=-1,q;
long long n, t, sum = 0;
scanf("%d %d", &n, &t);
for(int i = 1 ; i <= n ; i ++ ){
cin>>q;
m=max(m,q);
sum+=q;
if( t >= sum ) printf("%lld\n", (t - sum ) /m + 2);
else printf("1\n");
}
}



Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  int N=S.size();
  int count=0;
  for(int i=0;i<N/2;i++){
    if(S.at(i)!=S.at(N-1-i)){
      count=count+1;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
S = input()

N = len(S)
dist = [[N for i in range(N)] for j in range(26)]
dist[ord(S[-1]) - 97][-1] = 0
for i in range(26):
    for j in reversed(range(N - 1)):
        if ord(S[j]) == 97 + i:
            dist[i][j] = 0
        else:
            dist[i][j] = dist[i][j + 1] + 1

ans = N - 1
for i in range(26):
    for j in range(1, N + 1):
        ans = min(ans, max(N - j, max(dist[i][0:j])))
print(ans)

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

int main() {
    using pii = pair<int, int>;
    int n; cin >> n;
    vector<pii> r(n), b(n);
    for (int i = 0; i < n; i++) cin >> r[i].first >> r[i].second;
    for (int i = 0; i < n; i++) cin >> b[i].first >> b[i].second;
    sort(r.begin(), r.end(), [](const pii &a, const pii &b) {
        if (a.second == b.second) return a.first > b.first;
        else return a.second > b.second;
    });
    sort(b.begin(), b.end());
    vector<int> used(n);
    for (int ib = 0; ib < n; ib++) {
        for (int ir = 0; ir < n; ir++) if (!used[ir]) {
            if (r[ir].first < b[ib].first && r[ir].second < b[ib].second) {
                used[ir] = true;
                break;
            }
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) cnt += used[i];
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import math
a,b,h,m=map(int,input().split())
h=h+m/60
htheta=h*math.pi/6
mtheta=m*math.pi/30
theta=abs(htheta-mtheta)
print(math.sqrt(a*a+b*b-2*a*b*math.cos(theta)))

Measured memory_bytes: 9472
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

typedef pair<int,int> pii;

const int M = 1400;
const int C = 700;
const int S = 1111111;

int board[M][M];
pii dp[M][M];

int sosu[S];

pii saiki(int x,int y){
	if(dp[y][x].first!=0)return dp[y][x];
	if(board[y][x]==-1)return pii(0,0);
	
	int dx[] = {1,0,-1};
	pii ret = pii(0,0);
	rep(i,3)ret = max(ret, saiki(x+dx[i], y+1));
	
	if(sosu[board[y][x]]==0){
		ret.first++;
		if(ret.second==0)ret.second = board[y][x];
	}
	
//	printf("[%d %d]->%d %d %d\n",y,x,board[y][x],ret.first,ret.second);
	
	return dp[y][x]=ret;
}

int main(){
	
	sosu[0]=sosu[1]=1;
	rep(i,S){
		if(sosu[i]==1)continue;
		for(int j=i*2; j<S; j+=i)sosu[j]=1;
	}
	
	B:;
	
	int n,m;
	cin>>n>>m;
	
	if(n==0 && m==0)return 0;
	
	rep(i,M)rep(j,M){
		board[i][j]=-1;
		dp[i][j]=pii(0,0);
	}
	
	pii st;
	{
		pii pos = pii(C,C);
		int dir = 0;
		int len = 1;
		int cnt = 1;
		int dx[]={1,0,-1,0};
		int dy[]={0,-1,0,1};
		while(1){
			rep(i,len){
				if(cnt>n)goto A;
				board[pos.second][pos.first]=cnt;
				if(cnt==m)st = pos;
				cnt++;
				pos.first+=dx[dir];
				pos.second+=dy[dir];
			}
			dir = (dir+1)%4;
			if(dir%2==0)len++;
		}
		A:;
	}
	
	
	pii ans = saiki(st.first, st.second);
	printf("%d %d\n",ans.first,ans.second);
	
	goto B;
}

Measured memory_bytes: 28560
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, ans;
ll cnt[1100000];
bool used[1100000];
int main() {
    cin >> n;
    vector<ll> s(n);
    REP(i, n){
        cin >> s[i];
        cnt[s[i]]++;
    }
    sort(ALL(s));
    REP(i, n){
        bool ok = true;
        for (ll j = 1; j <= sqrt(s[i]); j++)
        {
            if (s[i] % j == 0){
                if(used[s[i] / j]) ok = false;
                if(used[j]) ok = false;
            }
        }
        used[s[i]] = true;
        if (ok and cnt[s[i]] == 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 13520
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	cout << (1000 - (N % 1000 == 0 ? 1000 : N % 1000)) << endl;

	return 0;
}

Measured memory_bytes: 3156
#include <iostream>

using namespace std;
using ll = long long;

int
main(void){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a = a*b;
  c = c*d;
  if(a < c){
    cout << c << endl;
  }else{
    cout << a << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long mod = 1000000007;

int n;
string s[500];

bool empty() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (s[i][j] == '#') return false; 
    }
  }
  return true;
}

bool fullCol(int j) {
  for (int i = 0; i < n; ++i) {
    if (s[i][j] == '.') return false;
  }
  return true;
}

int sub(int i) {
  int rem = 0;
  for (int j = 0; j < n; ++j) {
    if (s[i][j] == '.') ++rem;
  }

  bool exists = false;
  for (int k = 0; k < n; ++k) {
    if (s[k][i] == '#') exists = true;
  }
  if (!exists) ++rem;
  return rem;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> s[i];
  if (empty()) {
    cout << -1 << endl;
    return 0;
  }
  
  int mn = 1e9;
  for (int i = 0; i < n; ++i) {
    mn = min(mn, sub(i));
  }
  
  int ans = mn;
  for (int j = 0; j < n; ++j) {
    if (!fullCol(j)) ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
C = [[int(x) for x in input().split()] for _ in range(3)]
ans = C[0][0]+C[1][1]+C[2][2]
if(ans == C[0][2]+C[1][0]+C[2][1] and ans == C[0][1]+C[1][2]+C[2][0]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> P(m),Y(m);
    rep(i,m){
        cin>>P[i]>>Y[i];
        P[i]--;
    }

    vector<vector<int>> vals(n);
    rep(i,m) vals[P[i]].push_back(Y[i]);

    rep(i,n){
        sort(all(vals[i]));
    }

    rep(i,m){
        int v=P[i];
        printf("%06d",v+1);

        int id=lower_bound(all(vals[v]),Y[i])-vals[v].begin();
        printf("%06d\n",id+1);
    }
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    bool f=true;
    if(x+r>w)f=false;
    if(y+r>h)f=false;
    if(r>x)f=false;
    if(r>y)f=false;
    if(f==true)printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 3156
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N = int(input())
    X = [[-1 for j in range(N)] for i in range(N)]
    for i in range(N):
        a = int(input())
        for j in range(a):
            xx, yy = map(int, input().split())
            X[i][xx-1] = yy
    mx = 0
    for i in range(1<<N):
        flag = True
        for j in range(N):
            if (i>>j) & 1 == 1:
                for k in range(N):
                    if (i>>k)&1 != X[j][k] and X[j][k] != -1:
                        flag = False
                        break
        if flag == True:
            mx = max(mx, bin(i)[2:].count('1'))
    print(mx)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N, K = map(int, input().split())
A = [int(_) for _ in input().split()]
num = len(set(A))
cnt = [0]*(N+1)
ans = 0

for i in A:
    cnt[i] += 1

for i in range(N+1):
    if cnt[i] == 0:
        cnt[i] = N+1
        
cnt = sorted(cnt)
for i in range(max(0, num-K)):
    ans += cnt[i]

print(ans)

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

struct Pt { int x, y; };

const int fld = 8;
const vector<vector<Pt>> fig = { // offset
	{ {0,0},{1,0},{-1,1},{1,0} },
	{ {0,0},{0,1},{0,1},{0,1} },
	{ {0,0},{1,0},{1,0},{1,0} },
	{ {0,0},{0,1},{-1,0},{0,1} },
	{ {0,0},{1,0},{0,1},{1,0} },
	{ {0,0},{0,1},{1,0},{0,1} },
	{ {0,0},{1,0},{-2,1},{1,0} }
};

bool match( const vector<string>& a, int x, int y, int fig_i ) {
	for( int i = 0; i < 4; ++i ) {
		x += fig[fig_i][i].x;
		y += fig[fig_i][i].y;

		if( x < 0 || y < 0 || x >= fld || y >= fld || a[y][x] == '0' ) {
			return false;
		}
	}

	return true;
}

int check( const vector<string>& a ) {
	for( int i = 0; i < fld; ++i ) {
		for( int j = 0; j < fld; ++j ) {
			for( int k = 0; k < fig.size(); ++k ) {
				if( match( a, j, i, k ) ) { return k; }
			}
		}
	}

	return -1;
}

int main() {
	ios_base::sync_with_stdio( false );

	vector<string> a;
	string s;
	while( cin >> s ) {
		a.push_back( s );

		if( a.size() == fld ) {
			cout << (char)('A' + check( a )) << '\n';
			a.clear();
		}
	}

	return 0;
}



Measured memory_bytes: 3044
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int B = 0, W = 0;
            char[] s = Console.ReadLine().ToCharArray();

            for(int i=0;i<s.Length;i++)
            {
                if(i%2==0)
                {
                    if (s[i] == '0')
                        B++;
                    else
                        W++;
                }
                else
                {
                    if (s[i] == '0')
                        W++;
                    else
                        B++;
                }
            }

            if(W>B)
                Console.WriteLine(B.ToString());
            else
                Console.WriteLine(W.ToString());

        }
    }
}


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

namespace ABC141
{
    class Program
    {
        static void Main(string[] args)
        {
            //b();
            c();
        }

        public static void a()
        {
            string s = Console.ReadLine();
            if (s == "Sunny")
                Console.WriteLine("Cloudy");
            else if (s == "Cloudy")
                Console.WriteLine("Rainy");
            else
                Console.WriteLine("Sunny");
        }

        public static void b()
        {
            string s = Console.ReadLine();
            for (int i = 0; i < s.Length; i++)
            {
                if (i % 2 == 1)
                {
                    if (s[i] == 'R')
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                else if (i % 2 == 0)
                {
                    if (s[i] == 'L')
                    {
                        Console.WriteLine("No");
                        return;
                    }

                }
            }
            Console.WriteLine("Yes");
        }

        public static void c()
        {
            var dic = new Dictionary<int, int>();
            int[] nkq = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            for(int i = 0; i < nkq[0]; i++)
            {
                dic.Add(i, nkq[1] - nkq[2]);
            }    
            for(int i = 0; i < nkq[2];i++)
            {
                int q = int.Parse(Console.ReadLine());
                dic[q - 1]++;
            }
            foreach(var x in dic)
            {
                //Console.WriteLine("{0}  {1}", x.Key, x.Value);
                if (x.Value > 0)
                    Console.WriteLine("Yes");
                else
                    Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 23648
import heapq
n, m = map(int, input().split())
a = list(map(lambda x: -1 * (int(x)), input().split()))
heapq.heapify(a)

for _ in range(m):
    item = heapq.heappop(a)
    item = -item // 2
    heapq.heappush(a, -item)

print(-(sum(a)))



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

int main(){
    int n,m,x; cin>>n>>m>>x;
    int ans = 0;
    vector<vector<int>> books(n,vector<int>(m+1));
    for(int i=0; i<n; i++){
        for(int j=0; j<m+1; j++){
            cin >> books[i][j];
        }
        ans += books[i][0];
    }
    bool flag=0;

    for(int i=0; i< (1<<12); i++){
        bitset<12> s(i);
        int sum=0;
        bool enough=1;
        vector<int> skill(m+1);
        for(int i=0; i<n; i++){
            if(s.test(i)){
                for(int j=0; j<m+1; j++){
                    skill[j]+=books[i][j];
                }
            }
        }
        for(int k=1; k<m+1; k++){
            if(skill[k]<x) enough=0;
        }
        if(enough){
            flag=1;
            ans = min(ans,skill[0]);
        }
    }
    cout << (flag?ans:-1) << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
char process(char c,int k){
    int u = int(c);
    u+=k;
    if(u>int('Z')){
        u-=26;
    }
    return char(u);
}
void solve(){
    int k = 0;
    string s;cin>>k>>s;
    for(long long int i=0;i<s.size();i++){
        s[i]=process(s[i],k);
    }
    cout<<s<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


Measured memory_bytes: 256
/**


三角形の２辺 a, b とその間の角 C から、
その三角形の面積 S、周の長さ L, a を底辺としたときの高さ h を求めるプログラムを作成して下さい。

 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);
		// 3つの数字を受け取る
		double dbA = sc.nextDouble();
		double dbB = sc.nextDouble();
		double dbC = sc.nextDouble();

		//3つの数字の面積、周、高さを求める計算式
		double dbS = dbA * dbB * Math.sin(Math.toRadians(dbC)) / 2;
		double dbL = dbA + dbB + Math.sqrt(dbA*dbA + dbB * dbB - 2*dbA * dbB * Math.cos(Math.toRadians(dbC)));
		double dbH = dbB * Math.sin(Math.toRadians(dbC));
		//表示
		System.out.println(dbS);
		System.out.println(dbL);
		System.out.println(dbH);

	}
}

Measured memory_bytes: 18188
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    int N = ReadInt();
    double sum = 0;
    for (int i = 0; i < N; i++) {
      string[] xu = ReadStringArray();
      if (xu[1] == "JPY") {
        sum += double.Parse(xu[0]);
      } else {
        sum += double.Parse(xu[0]) * 380000;
      }
    }
    Console.WriteLine(sum);
  }

  private static string ReadStr() { return Console.ReadLine(); }
  private static int ReadInt() { return int.Parse(Console.ReadLine()); }
  private static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  private static long ReadLong() { return long.Parse(Console.ReadLine()); }
  private static char ReadChar() { return Console.ReadLine()[0]; }
  private static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  private static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  private static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  private static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  private static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}


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

int main() {
  int64_t N, C;
  int64_t kcal_max = numeric_limits<int64_t>::min();
  cin >> N >> C;
  vector<int64_t> x(N + 2), v(N + 2);
  for (int i = 1; i <= N; ++i) {
    cin >> x[i];
    cin >> v[i];
  }
  vector<int64_t> v_right = v;
  for (int i = 2; i <= N; ++i) v_right[i] += v_right[i - 1];
  vector<int64_t> f_right = v_right;
  for (int i = 1; i <= N; ++i) f_right[i] -= x[i];
  vector<int64_t> g_right = f_right;
  for (int i = 1; i <= N; ++i)
    g_right[i] = max(g_right[i - 1], g_right[i]);
  kcal_max = max(kcal_max, g_right[N]);
  
  vector<int64_t> v_left = v;
  for (int i = N - 1; i >= 1; --i) v_left[i] += v_left[i + 1];
  vector<int64_t> f_left = v_left;
  for (int i = 1; i <= N; ++i) f_left[i] -= C - x[i];
  vector<int64_t> g_left = f_left;
  for (int i = N; i >= 0; --i)
    g_left[i] = max(g_left[i], g_left[i + 1]);
  kcal_max = max(kcal_max, g_left[0]);
  
  for (int a = 0; a < N - 1; ++a) {
    const int64_t kcal = v_right[a] - 2 * x[a] + g_left[a + 1];
    kcal_max = max(kcal_max, kcal);
  }
  for (int b = 1; b <= N; ++b) {
    const int64_t kcal = v_left[b] - 2 * (C - x[b]) + g_right[b - 1];
    kcal_max = max(kcal_max, kcal);
  }
  cout << kcal_max << endl;
}


Measured memory_bytes: 6528
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<iostream>
#include<iterator>
#include<math.h>
#include<cmath>
#include<sstream>
#include<vector>
#include<iomanip>
#include<string>
#include<fstream>
#include<algorithm>
#include<map>
#include<thread>
#include<stack>
#include<numeric>
#include<functional>
#include<queue>
#include<set>
#include<list>
#include<bitset>
#include <cassert>

typedef long long ll;

using namespace std;

const ll MOD = (ll)1000000007;
const ll inf = (ll)1e18;
const long double eps = 0.0000001;

struct th
{
	ll first = -1, second = -1;
	ll third = -1;
};


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << setprecision(30);

#ifdef _DEBUG
	/*freopen("sorting.in", "r", stdin);
	freopen("sorting.out", "w", stdout);*/

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;

	vector<long double> a(n);
	for (auto &i : a)
	{
		cin >> i;
	}


	long double ans = 0;
	for (auto i : a)
	{
		i = 1.0 / i;

		ans += i;
	}

	ans = 1.0 / ans;
	cout << ans;

	return 0;
}

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

using namespace std;

const int N = 100100;

int n;
vector<int> g[N];

int dfs(int u, int p) {
   int ans = 0;
   for (int v : g[u]) {
      if (v != p) {
         ans ^= (dfs(v, u) + 1);
      }
   }
   return ans;
}

int main() {
   scanf("%d", &n);
   for (int i = 0; i < n - 1; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      g[u].push_back(v);
      g[v].push_back(u);
   }
   puts(dfs(1, -1) ? "Alice" : "Bob");
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	string S;
	cin >> S;
	int r = 0, b = 0;
	for (int i = 0; S[i]; i++)
	{
		S[i] == '0' ? r++ : b++;
	}
	cout << min(r, b) * 2 << endl;
}



Measured memory_bytes: 512
N = int(input())
d = list(map(int, input().split()))
ans = 0
while len(d) > 1:
    current = d[0]
    for y in range(len(d)):
        ans += current * d[y]
#         print(ans)
    ans -= current ** 2
    d.pop(0)
print(ans)

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

int main(){ 
  string s; cin >> s;
  int n = (int)s.size();
  
  if( n % 2 == 0 ){
    if( s.front() == s.back() ){ cout << "First" << endl;}
    else{ cout << "Second" << endl;}
    
  }
  else{
    if(s.front() == s.back() ){ cout << "Second" << endl;}
    else{ cout << "First" << endl;}
    
  }
  return 0;
} 

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
 
int main() {
 
    ll N=0;
    cin >> N;
 
    ll tmp = 998244353;
    ll answer = 1;
    ll cnt = 1;
    vector<ll> D(N, -1);
    for(ll i=0; i<N; i++) cin >> D.at(i);
 
    if(D.at(0) != 0) {
        cout << "0" << endl;
        return 0;
    }
 
    if(N==1){
        cout << "0" << endl;
        return 0;
    }
 
    for(ll i=1; i<N; i++){
        if(D.at(i) == 0){
            cout << "0" << endl;
            return 0;
        }
    }
 
    sort(D.begin(), D.end());
 
    for(int i=0; i<N-1; i++){
        if(D.at(i) == D.at(i+1) || D.at(i+1) == D.at(i)+1){
            continue;
        }
        else{
            cout << "0" << endl;
            return 0;
        }
    }
 
    D.push_back(-1);
 
    vector<ll> path_n(D.at(N-1)+1, 0);
    for(ll i = 1; i < N; i++){
        if(D.at(i) == D.at(i+1)){
            cnt++;
            cnt = cnt % tmp;
        }
        else{
            path_n.at(D.at(i)-1) = cnt;
            cnt = 1;
        }
    }
    
//    rep(i,D.at(N-1)) cout << "path = " << path_n.at(i) << endl;
 
    for(ll i = 0; i < D.at(N-1); i++){
        for(ll j=0; j<path_n.at(i+1); j++){
            answer *= path_n.at(i) % tmp;
            answer  = answer % tmp;
        }
    } 
 
    cout << answer % tmp << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
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 ci[cm];
char *cn = ci + cm;
inline char getcha() {
	if (cn - ci == cm) { fread(ci, 1, cm, stdin); cn = ci; }
	return *cn++;
}

inline int getint() {
	char C = getcha();
	int A = C - '0';
	while ((C = getcha()) >= '0') A = A * 10 + C - '0';
	return A;
}

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


	int N;
	N = getint();
	int A[200000];
	ll B[200001], C;
	B[0] = 0;
	C = 0;

	vector<int> V;
	V.pb(0);
	rep(i, N) A[i] = getint();
	ll mae = A[0];
	rep(i, N) {
		ll a = A[i];
		B[i + 1] = B[i];
		if (mae >= a) {
			a *= 4;
			while (mae >= a) {
				V.pb(0);
				a *= 4;
			}
			V.back()++;
		}
		else {
			while (mae < a) {
				int kari = V.back();
				B[i + 1] += kari;
				if (V.size() > 1) {
					V.pop_back();
					V.back() += kari;
				}
				mae *= 4;
			}
			V.back()++;
		}
		mae = A[i];
	}
	V.clear();
	mae = A[N - 1];
	V.pb(0);
	ll kotae = 2 * B[N] + N;
	for (int i = N - 1; i >= 0; i--) {
		ll a = A[i];
		if (mae >= a) {
			a *= 4;
			while (mae >= a) {
				V.pb(0);
				a *= 4;
			}
			V.back()++;
		}
		else {
			while (mae < a) {
				int kari = V.back();
				C += kari;
				if (V.size() > 1) {
					V.pop_back();
					V.back() += kari;
				}
				mae *= 4;
			}
			V.back()++;
		}
		mae = A[i];
		kotae = min(kotae, B[i] + B[i] + C + C + i);
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	for(int i=0;i<k;i++){
		if(a>=b) b*=2;
		else if(a<b&&b>=c) c*=2;
	}
	if(a<b&&b<c) cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

vector<int> g[101010];
int dist[101010], ans[101010];

void dfs1(int v, int p) {
    for (int u : g[v]) {
        if (u == p) continue;
        dfs1(u, v);
        dist[v] = max(dist[v], dist[u] + 1);
    }
}

void dfs2(int v, int d_p, int p) {
    vector<pair<int, int>> d_c;
    d_c.emplace_back(0, -1);
    for (int &u : g[v]) {
        if (u == p) d_c.emplace_back(d_p + 1, u);
        else d_c.emplace_back(dist[u] + 1, u);
    }
    sort(d_c.rbegin(), d_c.rend());
    ans[v] = d_c[0].first;
    for (int &u : g[v]) {
        if (u == p) continue;
        dfs2(u, d_c[d_c[0].second == u].first, v);
    }
}

int main() {
    int N;
    cin >> N;
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs1(0, -1);
    dfs2(0, 0, -1);
    rep(i, N) {
        cout << (N-1)*2 - ans[i] << endl;
    }
}



Measured memory_bytes: 28084
import math
import sys

A  = int(input())

C = [[0 for _ in range(10)] for _ in range(10)]
# print(C)

def count(n):
    for x in range(1,n+1):
        xj = x % 10 
        s = x; 
        while True:
            if s < 10:
                xi = s
                C[xi][xj] = C[xi][xj] + 1
                break
            s = s// 10 


count(A)
# print(C)
ans = 0 
for i in range(1,10):
    for j in range(1,10):
        ans = ans + C[i][j] * C[j][i]

print(ans)
         

Measured memory_bytes: 3064
n = gets.to_i
a = gets.split.map(&:to_i).sort
past = 0
tmp = 0
result = 0
until a.empty? do
  b = a.pop
  if b == past
    if tmp == 0
      tmp = b
    else
      result = tmp * b
      break
    end
    past = 0
  else
    past = b
  end
end

puts result


Measured memory_bytes: 10112