akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
	int ans = 0;
	string s;
	cin >> s;
	rep(i,s.size()){
		if(s[i] == '+') ans++;
		if(s[i] == '-') ans--;
	}
	cout << ans << endl;
    return 0;
}



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


int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==5&&b==5)||(a==5&&c==5)||(c==5&&b==5)&&((a==7)||(b==7)||(c==5))){
        cout<<"YES"<<endl;
    }
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
res = 0
if K == 0:
    print(N*N)
else:
    for i in range(K+1, N+1):
        res += (i-K) * int(N/i)
        if N % i - K >= 0:
            res += (1 + N % i - K)
    print(res)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int r;
	cin >> r;
	cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans_1 = max($a);
$diff = PHP_INT_MAX;
for ($i = 0; $i < $n; $i++) {
    if ($a[$i] === $ans_1) continue;
    $tmp = abs($ans_1 / 2 - $a[$i]);
    if ($diff > $tmp) {
        $ans_2 = $a[$i];
        $diff = $tmp;
    }
}
printf("%d %d", $ans_1, $ans_2);


Measured memory_bytes: 17012
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M, X, Y = sc.nextInt()
  val x = X :: List.fill(N)(sc.nextInt())
  val y = Y :: List.fill(M)(sc.nextInt())
  println(if (x.max < y.min) "No War" else "War")
}


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

int main(){
  int a,b,c,d,e;
  vector<int> l;

  while(cin>>a>>b>>c>>d>>e){

    l.push_back(a);
    l.push_back(b);
    l.push_back(c);
    l.push_back(d);
    l.push_back(e);

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

    for(int i=4; i>=0; i--){
      cout<<l[i];
      if(i) cout<<" ";
    }
    cout<<endl;
    l.clear();
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int read(){
	int f=1,x=0; char c=getchar();
	while (c>'9' || c<'0') {if (c=='-') f=-1; c=getchar();}
	while (c>='0'&&c<='9') {x=x*10+c-'0'; c=getchar();}
	return f*x;
}
int h,w;
bool flag=1;
char map[55][55];
int main(){
	cin>>h>>w;
	for(int i=1;i<=h;i++) scanf("%s",map[i]+1);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(map[i][j]=='#'){
				if((map[i][j+1]=='.')&&(map[i][j-1]=='.')&&
					(map[i-1][j]=='.')&&(map[i+1][j]=='.'))	{
						flag=0;
						break;
					}
			}
	if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;
#define pai 3.141592653589793238462643383279




int main(){
  int N; cin >> N; ll a[N];
  rep(i, N){
    cin >> a[i];
  }
  sort(a, a+N, greater<>()); ll check = (ll)1e18;
  ll ans = 1;
  for(int i=N-1; i>=0; i--){
    if(a[i]==0){
      cout << 0 << endl; return 0;
    }
    if(ans<=(check+a[i]-1)/a[i]){
      ans*=a[i];
    }
    else{
      cout << -1 << endl; return 0;
    }
    if(ans>check){
      cout << -1 << endl; return 0;
    }
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 4368
def solve():
  n,k=[int(i) for i in input().split()]
  step=[int(i) for i in input().split()]
  dp=[0]*n
  for i in range(1,n):
    dp[i]=min([dp[j] + abs(step[i]-step[j]) for j in range(max(i-k,0),i)])
  return dp[n-1]
print(solve())


Measured memory_bytes: 13976
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int a[4];
int main()
{
	cin >> a[1] >> a[2] >> a[3];
	sort(a + 1, a + 4);
	cout << a[1] << " " << a[2] << " " << a[3] << endl;
	return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<vector<int>> E(N);
	for (int i = 0; i < N - 1; i++){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	vector<int> c(N);
	for (int i = 0; i < N; i++){
		cin >> c[i];
	}
	sort(c.begin(), c.end());
	reverse(c.begin(), c.end());
	vector<int> d(N, 0);
	d[0] = c[0];
	int ans = 0;
	int cnt = 1;
	queue<int> Q;
	Q.push(0);
	while (!Q.empty()){
		int v = Q.front();
		Q.pop();
		for (int w : E[v]){
			if (d[w] == 0){
				d[w] = c[cnt];
				ans += d[w];
				cnt++;
				Q.push(w);
			}
		}
	}
	cout << ans << endl;
	for (int i = 0; i < N; i++){
		cout << d[i];
		if (i < N - 1){
			cout << ' ';
		}
	}
	cout << endl;
}

Measured memory_bytes: 4128
import java.util.*;
import java.io.*;

class Point {

    final int x;
    final int y;

    Point( int x, int y ) {
	this.x = x;
	this.y = y;
    }    
}

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);
	boolean first = true;
	
	while ( stdin.hasNextLine() ) {
	    if ( !first ) {
		stdin.nextLine();
	    }
	    
	    char[][] map = new char[8][];
	    for ( int i = 0; i < 8; i++ ) {
		map[i] = stdin.nextLine().toCharArray();
	    }

	    final Point p = getUpLeftPoint( map );

	    if ( isA( map, p ) ) {
		System.out.println( "A" );
	    } else if ( isB( map, p ) ) {
		System.out.println( "B" );
	    } else if ( isC( map, p ) ) {
		System.out.println( "C" );
	    } else if ( isD( map, p ) ) {
		System.out.println( "D" );
	    } else if ( isE( map, p ) ) {
		System.out.println( "E" );
	    } else if ( isF( map, p ) ) {
		System.out.println( "F" );
	    } else {
		System.out.println( "G" );
	    }
	    first = false;
	}
    }

    static boolean isA( char[][] map, Point p ) {
	if ( p.x < 7 && p.y < 7 ) {
	    return map[p.y][p.x] == '1' && map[p.y + 1][p.x] == '1' &&
		map[p.y][p.x + 1] == '1' && map[p.y + 1][p.x + 1] == '1';			 
	} else {
	    return false;
	}
    }
    
    static boolean isB( char[][] map, Point p ) {
	if ( p.y < 5 ) {
	    return map[p.y][p.x] == '1' && map[p.y + 1][p.x] == '1' &&
		map[p.y + 2][p.x] == '1' && map[p.y + 3][p.x] == '1';
	} else {
	    return false;
	}
    }
    
    static boolean isC( char[][] map, Point p ) {
	if ( p.x < 5 ) {
	    return map[p.y][p.x] == '1' && map[p.y][p.x + 2] == '1' &&
		map[p.y][p.x + 2] == '1' && map[p.y][p.x + 3] == '1';
	} else {
	    return false;
	}
    }
    
    static boolean isD( char[][] map, Point p ) {
	if ( p.x > 0 && p.y < 6 ) {
	    return map[p.y][p.x] == '1' && map[p.y + 1][p.x] == '1' &&
		map[p.y + 1][p.x - 1] == '1' && map[p.y + 2][p.x - 1] == '1';							     
	} else {
	    return false;
	}
    }
    
    static boolean isE( char[][] map, Point p ) {
	if ( p.x < 6 && p.y < 7 ) {
	    return map[p.y][p.x] == '1' && map[p.y][p.x + 1] == '1' &&
		map[p.y + 1][p.x + 1] == '1' && map[p.y + 1][p.x + 2] == '1';			     
	} else {
	    return false;
	}
    }
    
    static boolean isF( char[][] map, Point p ) {
	if ( p.x < 7 && p.y < 6 ) {
	    return map[p.y][p.x] == '1' && map[p.y + 1][p.x] == '1' &&
		map[p.y + 1][p.x + 1] == '1' && map[p.y + 2][p.x + 1] == '1';  
	} else {
	    return false;
	}
    }
    
    static Point getUpLeftPoint( char[][] map ) {

	for ( int c = 0; c < map.length; c++ ) {
	    for ( int r = 0; r < map[c].length; r++ ) {
		if ( map[c][r] == '1' ) {
		    return new Point( r, c );
		}
	    }
	}
	return new Point( -1, -1 );
    }    
}

Measured memory_bytes: 21600
/*
    AUTHOR : TANMAY SINHA
    INFORMATION TECHNOLOGY
    BIT MESRA ,RANCHI
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007ll
#define rep(i,L,R) for(i=L;i<R;i++)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
const ll INF = 1e18l+10,N = 1e5+10,MAX = 5000000;
#define sq(X) ((X)*(X))

int main()
{
    ll k,n,i;
    cin>>k>>n;
    ll a[n];
    for(i=0;i<n;i++)cin>>a[i];
    ll ans = INF;
    for(i=0;i<n-1;i++)
    {
        ans = min(ans,abs(k-a[i+1]+a[i]));
    }
    ans = min(ans,abs(a[n-1]-a[0]));
    if(n==2)
    ans = a[1]-a[0];
    cout<<ans<<"\n";
}

Measured memory_bytes: 1792
#include<iostream>
#include<functional>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	char A[52][52];

	for (int i = 1; i <= H; i++) {
		for (int K = 1; K <= W; K++) {
			cin >> A[i][K];
		}
	}
	int Y = 0;



	for (int s = 1; s <= H; s++) {
		for (int d = 1; d <= W; d++) {
			if (A[s][d] == '#') {
				if ((A[s][d - 1] == '#') || (A[s][d + 1] == '#') || (A[s - 1][d] == '#') || (A[s + 1][d] == '#')) {

				}
				else {
					Y++;
				}
			}
		}
	}



	if (Y > 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
    for(int i = 0; i < (int)v.size(); i++)
        os << (i ? " " : "") << v[i];
    return os;
}
/*-------------------------------------------*/

int D;
int c[26];
ll s[365][26];

int last[26];

set<int> st[26];
vector<int> ret;
vector<int> ans;

ll sum = 0, MAX;

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

    srand((unsigned)time(NULL));

    rep(i, 26) st[i].insert(-1);

    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D) rep(j, 26) cin >> s[i][j];

    rep(d, D) {
        ll a = -1, mx = -1;
        rep(i, 26) if(chmax(mx, (d - *st[i].rbegin()) * c[i] + s[d][i])) a = i;
        ans.push_back(a);
        st[a].insert(d);
        sum += s[d][a];
        rep(i, 26) sum -= c[i] * (d - *st[i].rbegin());
    }

    MAX = sum;
    ret = ans;

    rep(i, 26) st[i].insert(D);

    while(clock() < CLOCKS_PER_SEC * 1.9) {
        int x = rand() % D;
        ll a = -1, mx = -inf;
        rep(i, 26) if(i != ans[x]) {
            auto it1 = st[i].upper_bound(x);
            auto it2 = st[i].lower_bound(x);
            it2--;
            ll y = s[x][i] + (*it1 - *it2) * (*it1 - *it2 - 1) / 2 * c[i];
            y -= (*it1 - x) * (*it1 - x - 1) / 2 * c[i];
            y -= (x - *it2) * (x - *it2 - 1) / 2 * c[i];
            if(chmax(mx, y)) a = i;
        }
        auto it1 = st[ans[x]].upper_bound(x);
        auto it2 = st[ans[x]].lower_bound(x);
        it2--;
        ll y = s[x][ans[x]] + (*it1 - *it2) * (*it1 - *it2 - 1) / 2 * c[ans[x]];
        y -= (*it1 - x) * (*it1 - x - 1) / 2 * c[ans[x]];
        y -= (x - *it2) * (x - *it2 - 1) / 2 * c[ans[x]];
        if(mx >= y) {
            st[a].insert(x);
            st[ans[x]].erase(x);
            ans[x] = a;
            sum += mx - y;
            if(chmax(MAX, sum)) ret = ans;
        } else if(rand() % 100 == 0) {
            sum += mx - y;
            st[a].insert(x);
            st[ans[x]].erase(x);
            ans[x] = a;
        }
        if(sum * 51 < MAX * 50) {
            sum = MAX;
            ans = ret;
            rep(i, 26) {
                st[i].clear();
                st[i].insert(-1);
                st[i].insert(D);
            }
            rep(i, D) st[ans[i]].insert(i);
        }
    }

    rep(i, D) cout << ret[i] + 1 << endl;

    return 0;

    cout << endl;

    sum = 0;
    rep(d, D) {
        int x = ret[d];
        last[x] = d + 1;
        sum += s[d][x];
        rep(i, 26) sum -= (d + 1 - last[i]) * (c[i]);
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3772
import sys
n, m = map(int, input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
for i in range(n-m+1):
  for j in range(n-m+1):
    flag = False
    tmp = [a[f][j:j+m] for f in range(i, i+m)]
    for k in range(m):
      for l in range(m):
        if tmp[k][l] != b[k][l]:
          flag = True
          break
      if flag:
        break
    if flag:
      continue
    print("Yes")
    sys.exit()
print("No")

Measured memory_bytes: 9220
// 22:45~

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

inline int popcount(uint x)
{
	x=(x&0x55555555)+(x>>1&0x55555555);
	x=(x&0x33333333)+(x>>2&0x33333333);
	x=(x&0x0f0f0f0f)+(x>>4&0x0f0f0f0f);
	x=(x&0x00ff00ff)+(x>>8&0x00ff00ff);
	return (x&0x0000ffff)+(x>>16&0x0000ffff);
}

int dfs(const vvi& g,int u)
{
	int res=1<<u;
	for(int v:g[u]) res|=dfs(g,v);
	return res;
}

int main()
{
	//clock_t t0=clock();
	for(int n,m;~scanf("%d%d",&n,&m) && n|m;){
		array<int,20> cs;
		vvi g(n);
		rep(i,n){
			scanf("%d",&cs[i]);
			int k; scanf("%d",&k);
			rep(j,k){
				int r; scanf("%d",&r);
				g[i].push_back(r);
			}
		}
		
		array<int,20> bs;
		rep(i,n) bs[i]=dfs(g,i);
		
		static array<int,1<<20> sums; sums.fill(0);
		
		rep(i,n) sums[1<<i]=cs[i];
		rep(i,1<<n) sums[i]=sums[i&-i]+sums[i-(i&-i)];
		
		int res=INF;
		rep(i,1<<n) if(popcount(i)<res){
			int b=0;
			rep(j,n) b|=(i>>j&1)*bs[j];
			if(sums[b]>=m) res=min(res,popcount(b));
		}
		printf("%d\n",res);
	}
	//clock_t t1=clock();
	//printf("%.3f[s]\n",1.*(t1-t0)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 5292
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF (1LL<<50)

struct edge{int from,to; int silver; int wait;};
struct vertex{int silver, wait;};

int N, M, S;
vertex V[50];
vector<edge> E[50];

int dp[50][5100];

signed main() {
  cin >> N >> M >> S;
  S = min(2500LL, S);
  for(int i=0; i<M; i++) {
    int u,v,a,b;
    cin >> u >> v >> a >> b;
    u--, v--;
    edge uv, vu;
    uv.from = u;
    uv.to = v;
    uv.silver = a;
    uv.wait = b;
    vu.from = v;
    vu.to = u;
    vu.silver = a;
    vu.wait = b;
    E[u].push_back(uv);
    E[v].push_back(vu);
  }
  for(int i=0; i<N; i++) { 
    cin >> V[i].silver >> V[i].wait;
    V[i].silver = min(2500LL, V[i].silver);
  }

  for(int i=0; i<N; i++) for(int j=0; j<5000; j++) { dp[i][j] = INF; }

  dp[0][S] = 0;
  for(int s=S+V[0].silver, wait=V[0].wait; s<=2500; s+=V[0].silver) {
    dp[0][s] = wait;
    wait += V[0].wait;
    //cerr << s << "\t" << dp[0][s] << endl;
  }

  queue<int> q;
  q.push(0);
  while(q.size()) {
    int v = q.front(); q.pop();

    for(int s=0; s<=2500; s++) {
      for(int s2=s+V[v].silver, w=V[v].wait; s2<=2500; s2+=V[v].silver) {
        dp[v][s2] = min(dp[v][s2], dp[v][s] + w);
        w += V[v].wait;
      }
    }

    for(auto e : E[v]) {
      bool mada = true;
      for(int s=0; s+e.silver<=2500; s++) {
        if(dp[e.to][s] > dp[e.from][s + e.silver] + e.wait) {
          dp[e.to][s] = min(dp[e.to][s], dp[e.from][s + e.silver] + e.wait);
          if(mada) {
            q.push(e.to);
            mada=false;
          }
        }
      }
    }
  }

  for(int v=1; v<N; v++) {
    int ans = INF;
    for(int s=0; s<=2500; s++) {
      ans = min(ans, dp[v][s]);
    }
    cout << ans << endl;
  }

}


Measured memory_bytes: 5640
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n, m = MI()
p = LI()
pair = [LI() for _ in range(m)]
uf = UnionFind(n)
for x, y in pair:
    uf.unite(x - 1, y - 1)
ans = 0
for i in range(n):
    if uf.same(p[i] - 1, i):
        ans += 1
print(ans)


Measured memory_bytes: 124060
#!/usr/bin/perl -w

use strict;

my $N = <>;
chomp($N);
my %list = ();
my $word;
my $ans = 0;

for (my $i = 0; $i < $N; $i++) {
  chomp($word = <>);
  if (!exists($list{"$word"})) {
    $ans++;
    $list{$word} = $word;
  }
}

print $ans;


Measured memory_bytes: 40016
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>	
using namespace std;
typedef long long ll;
#define bay_bay return 0;
#define fori(n) for(int i=0;i<n;++i)
#define for1(n) for(int i=1;i<=n;i+=3)
#define all(v) ((v).begin()), ((v).end())	
#define sz(v) v.size()
#define endl "\n"
constexpr auto EPS = 1e-9;
#define ff fflush(stdout);
const int mod = 1000000007;
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
}
int main()
{

	//GOAT();
	int h, n;

	cin >> h >> n;
	ll ans = 0;
	fori(n) { int x; cin >> x; ans += x; }

	(h-ans <= 0) ?cout<< "Yes" :cout<< "No";
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sc = new Scanner();
            int n = sc.NextInt();

            int max = sc.NextInt();
            int count = 1;
            for (int i = 0; i < n - 1; i++)
            {
                int h = sc.NextInt();
                if (max <= h) count++;
                if (h > max) max = h;
            }

            Console.WriteLine(count);
        }
    }

    class Scanner
    {
        int index = -1;
        string[] buf;

        public Scanner()
        {
        }

        public int NextInt()
        {
            CheckNext();
            return int.Parse(buf[index++]);
        }

        public string NextString()
        {
            CheckNext();
            return buf[index++];
        }

        private void CheckNext()
        {
            if (index >= 0 && index < buf.Length) return;

            buf = Console.ReadLine().Split(' ');
            index = 0;
        }
    }
}


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

int main(){
  int i, n;
  cin >> n;
  
  for( i=0; i<=n/7; i++ ){
    if( (n-7*i)%4==0 ){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

Int ans;
Int a[300005];

int main(){
    cin.tie(0);
    
    int N;
    cin >> N;
    N *= 3;
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a, a+N);
    int left = 0;
    int mid = N-2;
    int right = N-1;
    while (left < mid && mid < right){
        ans += a[mid];
        mid -= 2;
        right -= 2;
        left += 1;
    }
    cout << ans << endl;
} 


Measured memory_bytes: 2560
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,T = mint()
t = lint()+[INF]
ans = 0
for i in range(N):
    ans += min(t[i+1]-t[i], T)
print(ans)

Measured memory_bytes: 105812
#!/usr/bin/env python3
import sys
from itertools import chain
from collections import Counter

# form bisect import bisect_left, bisect_right, insort_left, insort_right
# import numpy as np


def solve(N: int, S: "List[str]"):
    d = Counter(S)
    for key in ("AC", "WA", "TLE", "RE"):
        print(f"{key} x {d.get(key, 0)}")


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, S = map(int, line.split())
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 33088
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    string ans;
    while (n) {
        char ch = (n%k) + '0';
        ans = ch + ans;
        n /= k;
    }
    cout << ans.length() << "\n";
    return 0;
}

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

#define ll long long



void solve(){
    char a,b;
    cin>>a>>b;
    if(a=='H'&&b=='D')cout<<'D'<<endl;
    if(a=='D'&&b=='D')cout<<'H'<<endl;
    if(a=='H'&&b=='H')cout<<'H'<<endl;
    if(a=='D'&&b=='H')cout<<'D'<<endl;      
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
fun main (args : Array<String>) {
	val n = readLine()
	val N : Double = n!!.toDouble()
	var count : Double = 0.0
	var result : Double = 0.0
	for (i in 1..N.toInt()) {
		if (i % 2 == 1) {
			count += 1.0
		}
	}
	result = count / N
	println("${result}")
}

Measured memory_bytes: 31736
n , p = map(int, input().split())
a = list(map(int,input().split()))
b = [0]*n

for i in range(n):
    b[i]=a[i]%2

ans=2**(n-1)
if p==1 and sum(b)==0:
    ans = 0
if p==0 and sum(b)==0:
    ans *= 2
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm> // to use min_element

using namespace std;


int main(){
	int n;
	vector<int> numlst;

	cin >> n;
	int m, i, j;
	for (i=0;i<n;i++){
		cin >> m;
		numlst.push_back(m);	
	} 
	sort(numlst.begin(), numlst.end());
    numlst.erase( unique(numlst.begin(), numlst.end()), numlst.end() );

	cout << numlst.size()<<endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n; ll k; cin >> n >> k;
  k *= n;
  vector<int> a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  map<int, multiset<int>> mp;
  for(int i=0;i<n;++i) {
    mp[a[i]].insert(i);
    mp[a[i]].insert(i + n);
  }
  vector<int> v(n);
  for(int i=0;i<n;++i) {
    auto it = upper_bound(mp[a[i]].begin(), mp[a[i]].end(), i);
    int pos = *it;
    v[i] = pos - i;
  }
  ll su = v[0]+1;
  ll now = (v[0]+1) % n;
  while(now != 0) {
    su += v[now]+1;
    now = (now + v[now] + 1) % n;
  }
  k %= su;
  su = 0;
  now = 0;
  while(su + v[now] + 1 < k) {
    su += v[now]+1;
    now = (now + v[now] + 1) % n;
  }
  ll rem = k - su;
  vector<ll> ans;
  for(int i=0;i<rem;++i) {
    if(v[(now+i)%n] < rem - i) {
      i += v[(now+i)%n];
    } else {
      ans.push_back(a[(now+i)%n]);
    }
  }
  printv(ans);
}


Measured memory_bytes: 42228
#include <iostream>
#include <math.h> 
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int N,D; 
	cin >> N >> D;
	int X[10][10];
	
	for(int i=0;i<N;i++){
		for(int j=0;j<D;j++) cin >> X[i][j];
	}
		
	int d[100];
	int count=0;

	for(int i = 0; i < N-1; i++){
		for(int j = i + 1; j<N; j++){
			int a=0;
			for(int k=0;k<D;k++)
				a += (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
			d[count] = a;
			count++;
		}
	}
	int ans = 0;
	for(int i = 0;i <count; i++){
		int b = sqrt(d[i]);
		if(d[i]==b*b)ans++;
	}
	
	cout << ans;
}

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

using namespace std;

double ruizyo(double m){
	double ret=1;
	for(double i=0;i<m;i++){
		ret*=2;
	}

	return ret;
}

int main(){
	double n,m;
	cin>>n>>m;
	double r=ruizyo(m);

	cout<<100*(n-m)*r + 1900*m*r<<endl;

	return 0;
}


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

#define ll long long
const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll n,m,k;
string s;
int main() {
    INIT();

    cin >> n;
    n--;
    while(n >= 0) {
        int a = n % 26;
        s.push_back('a' + a);
        n /= 26;
        n--;
    }
    reverse(s.begin(), s.end());
    cout << fixed << std::setprecision(20) << s;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

double f(double a, double b, double theta) {
    if (theta > PI/2.0 - EPS) return 0.0;
    double res = 0.0;
    if (tan(theta) <= b/a) {
        res = (a*a*b - a*a*a*tan(theta)/2.0);
    }
    else {
        res = a*b*b/tan(theta)/2.0;
    }
    return res;
}

int main(){
    double a, b, x;
    cin >> a >> b >> x;
    double ok = PI / 2.0, ng = 0.0;
    rep(i, 1e6) {
        double mid = (ok+ng) / 2.0;
        if (f(a, b, mid) < x) ok = mid;
        else ng = mid;
    }
    cout << fixed << setprecision(10) << (ok/PI*180.0) << endl;
    return 0;
}


Measured memory_bytes: 4252
package main

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

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

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	A := nextInts(N)
	B := nextInts(N)
	C := nextInts(N - 1)
	ans := 0
	for i := 0; i < N; i++ {
		ans += B[i]
		if i+1 < N && A[i]+1 == A[i+1] {
			ans += C[A[i]-1]
		}
	}
	fmt.Fprintln(out, ans)
}

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

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

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    string s;

    cin >> s;

    ll hugs = 0;
    REP(i, s.length()/2){
        if (s[i] != s[s.length() - 1 - i]){
            hugs++;
        }
    }

    cout << setprecision(20) << hugs << endl;

    return 0;
}

Measured memory_bytes: 256
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    std::ifstream in(string(argv[0]) + ".txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    string s;
    cin >> s;

    rep(i, s.length()) {
        cout << 'x';
    }
    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

ll MOD = 1e9+7;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        res %= MOD;
        a = a * a;
        a %= MOD;
        b >>= 1;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	string S; cin >> S;
	map<char, ll> occ;

	ll ans = 0;
	for (char c : S) {
		ll combs = 1;
		for (pair<char, ll> p : occ) if (p.first != c) {
			combs *= p.second + 1; combs %= MOD;
		}
		ans += combs; ans %= MOD;
		occ[c]++;
	}
	print(ans);
}

Measured memory_bytes: 512
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int P = sc.nextInt();
		int Q = sc.nextInt();
		int R = sc.nextInt();

		int case_1 = P +Q;
		int case_2 = P +R;
		int case_3 = R +Q;;
		int case_4 = Q +R;
		//int min = 0;

		//if(min>case_1)min=case_1;
		if(case_1>case_2)case_1=case_2;
		if(case_1>case_3)case_1=case_3;
		if(case_1>case_4)case_1=case_4;

		System.out.println(case_1);
	}

}


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

typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  bool play = true;
  while (a > 0 && c > 0) {
    if (play) 
      c -= b;
    else
      a -= d;
    play = !play;
  }
  cout << (play? "No\n":"Yes\n");
  return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 3001;

int N, A[MX];
vi adj[MX];

bool dfs(int a, int b) {
    for (int i: adj[a]) if (i != b && A[i] < A[a] && !dfs(i,a)) return 1;
    return 0;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    FOR(i,1,N+1) cin >> A[i];
    F0R(i,N-1) {
        int a,b; cin >> a >> b;
        adj[a].pb(b), adj[b].pb(a);
    }
    FOR(i,1,N+1) if (dfs(i,0)) cout << i << " ";
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 512
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int tmp;
    rep(i,5){
        cin>>tmp;
        if(tmp==0){
            cout<<i+1;
            return 0;
        }
    }

    return 0;
}

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

typedef unsigned long long ull;

int main()
{
    ull n, x;
    vector<ull> a, b;
    ull count = 0;

    cin >> n;

    for (ull i = 0; i < n+1; i++)
    {
        cin >> x;
        a.push_back(x);
    }
    
    for (ull i = 0; i < n; i++)
    {
        cin >> x;
        b.push_back(x);
    }

    for (ull i = 0; i < n; i++)
    {
        if (b[i] <= a[i]) // more monsters
        {
            count += b[i];
        }
        else // can kill more
        {
            count += a[i];
            b[i] -= a[i];

            if (b[i] <= a[i+1])
            {
                count += b[i];
                a[i+1] -= b[i];
            }
            else
            {
                count += a[i+1];
                a[i+1] = 0;
            }
        }
    }

    cout << count << endl;

}


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

int cnt(int x) {
	if (x == 1) return 1;
	int ret = 0;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) {
			ret += 2;
			if (i * i == x) ret--;
		}
	}
	ret += 2;
	return ret;
}

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i += 2) {
		if (cnt(i) == 8) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import copy
n = int(input())
list_x = list(map(int, input().split()))
list_a = copy.deepcopy(list_x)
list_a.sort()
mid_up = list_a[n//2]
mid_do = list_a[n//2 - 1]
for i in range(n):
    if list_x[i] < mid_up:
        print(mid_up)
    else:
        print(mid_do)


Measured memory_bytes: 26416
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0)puts("Alice");
	else puts("Borys");
	ll
}

Measured memory_bytes: 256
/////////////////////////   _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <time.h>
#include <stack>
#include <string>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>

using namespace std;

const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n;
long long c;
long long x[N] , v[N];
long long pref1[N] , pref2[N];
long long mx1[N] , mx2[N];

int main(){
    scanf("%d%lld",&n,&c);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&x[i],&v[i]);
    }
    long long answ = 0;
    for(int i=1;i<=n;i++){
        pref1[i] = pref1[i - 1] + v[i];
        mx1[i] = max(mx1[i - 1] , pref1[i] - x[i]);
        ///
        pref2[i] = pref2[i - 1] + v[n - i + 1];
        mx2[i] = max(mx2[i - 1] , pref2[i] - (c - x[n - i + 1]));
        ///
        answ = max(answ , pref1[i] - x[i]);
        answ = max(answ , pref2[i] - (c - x[n - i + 1]));
    }
    for(int i=1;i<=n;i++){
        long long X = pref1[i] - 2 * x[i] + mx2[n - i];
        answ = max(answ , X);
    }
    for(int i=1;i<=n;i++){
        long long X = pref2[i] - 2 * (c - x[n - i + 1]) + mx1[n - i];
        answ = max(answ , X);
    }
    cout<<answ<<endl;
	return 0;
}


Measured memory_bytes: 4992
void main()
{
    long k = rdElem - 1;

    long[] a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
    a[k].writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 256
import math
import sys 
n,m = map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
cnt = 0
# 奇数+奇数
if n>=2:
    cnt += combinations_count(n,2)
# 偶数*偶数
if m>=2:
    cnt += combinations_count(m,2)
print(cnt)

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int X;
    cin >> X;
    int res = 1;
    FOR(i, 2, X + 1) {
        for(int p = i*i;p <= X;p *= i) {
            res = max(res, p);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256