akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <map>
using namespace std;

int getSuite(string suite){
  if( suite == "S")
  return 0;
  else if(suite ==  "H")
    return 1;
  else if(suite ==  "C")
    return 2;
  else
    return 3;
  }

  string getStr(int suite){
    switch(suite){
    case 0:
      return "S";
    case 1:
      return "H";
    case 2:
      return "C";
    case 3:
      return "D";
    default:
      return "";
    }
  }

int main()
{
  cout << setprecision(6);
  cout << setiosflags(ios::scientific);
  cout.flags(ios::fixed);

  int n;
  cin >> n;

  bool cards[4][13];
  memset(cards, 0, sizeof(cards));

  for(int i=0; i<n; i++)
    {
      string suite;
      int num;
      cin >> suite;
      cin >> num;

      cards[getSuite(suite)][num]=true;
    }

  for(int i=0; i<4; i++){
    for(int j=1; j<=13; j++){
      if(cards[i][j]==false){
	cout << getStr(i) << " " << j << endl; 
      }
    }
  }
}

Measured memory_bytes: 1212
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

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

    return a;
}

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

    vector<int> as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    vector<int> gcdl(n);
    gcdl[0] = as[0];
    vector<int> gcdr(n);
    gcdr[n - 1] = as[n - 1];
    for (int i = 1; i < n; i++) {
        gcdl[i] = gcd(gcdl[i - 1], as[i]);
        gcdr[n - i - 1] = gcd(gcdr[n - i], as[n - i - 1]);
    }

    int maxGcd = gcdr[1];
    for (int i = 1; i < n - 1; i++) {
        maxGcd = max(maxGcd, gcd(gcdl[i - 1], gcdr[i + 1]));
    }
    maxGcd = max(maxGcd, gcdl[n - 2]);
    cout << maxGcd << endl;
}


Measured memory_bytes: 1408
const main = stdin => {
  const input = stdin.trim().split('\n')
  const [M, N] = input[0].split(' ').map(x => parseInt(x))

  M === N ? console.log('Yes') : console.log('No')
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 29576
H,W = list(map(int,input().split()))

a = [input() for i in range(H)]

b = [[] for i in range(H)]
r = [[] for i in range(H)]
for i in range(H):
    for j in range(W):
        if i==0:
            b[i].append("#")
            r[i].append(".")
        elif i==H-1:
            b[i].append(".")
            r[i].append("#")
        elif a[i][j]=="#":
            b[i].append("#")
            r[i].append("#")
        elif j%2==0:
            b[i].append(".")
            r[i].append("#")
        elif j%2==1:
            b[i].append("#")
            r[i].append(".")

for i in range(H):
    ans = ""
    for j in range(W):
        ans = ans+b[i][j]

    print(ans)
print("")

for i in range(H):
    ans = ""
    for j in range(W):
        ans = ans+r[i][j]

    print(ans)


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

int main(){
  int n,m;
  cin>>n>>m;
  if(n<=1 && m<=1){
    cout<<0<<endl;
  }else if(n==1 && m>1){
    cout<<m*(m-1)/2<<endl;
  }else if(n>1 && m==1){
    cout<<n*(n-1)/2<<endl;
  }else{
    cout<<m*(m-1)/2 + n*(n-1)/2<<endl;
  }

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> T(N + 1), X(N + 1), Y(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> T.at(i) >> X.at(i) >> Y.at(i);
  }
  
  bool A = true;
  for (int i = 1; i <= N; i++) {
    int dT, dX, dY;
    dT = T.at(i) - T.at(i - 1);
    dX = abs(X.at(i) - X.at(i - 1));
    dY = abs(Y.at(i) - Y.at(i - 1));
    if (dX + dY > dT) {
      A = false;
      break;
    }
    else if ((dX + dY) % 2 != dT % 2) {
      A = false;
      break;
    }
  }
  
  if (A) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;




int main() {
    char s[100005],t[100005];
    int q;
    scanf("%s %s",s,t);
    int ss[100005],tt[100005];
    ss[0]=0;
    tt[0]=0;
    for(int i=0;i<=strlen(s)-1;i++){
        if(s[i]=='A')ss[i+1]=ss[i]+1;
        else ss[i+1]=ss[i]+2;
    }
    for(int i=0;i<=100005-1;i++){
        if(t[i]=='A')tt[i+1]=tt[i]+1;
        else tt[i+1]=tt[i]+2;
    }
    
    scanf("%d",&q);
    for(int i=1;i<=q;i++){
        int a,b,c,d;
        scanf("%d %d %d %d",&a,&b,&c,&d);
        if((399999+(ss[b]-ss[a-1])-(tt[d]-tt[c-1]))%3==0)printf("YES\n");
        else printf("NO\n");
    }
    
    return 0;
}


Measured memory_bytes: 1536
import itertools
import operator
import functools

EOL = '0 0'

for line in iter(input, EOL):
    n, x = map(int, line.split())
    combinations = list(itertools.combinations(list(range(1, n + 1)), 3))
    print(len(list(filter(functools.partial(operator.eq, x), map(sum, combinations)))))



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

int main(){
    char enki,ans;
    cin >> enki;

    switch (enki)
    {
        case 'A':
            ans = 'T';
            break;
    
        case 'T':
            ans = 'A';
            break;
        case 'C':
            ans = 'G';
            break;
        case 'G':
            ans = 'C';
            break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
tf=list(map(str,input().split()))
tf_r=tf[::-1]
while n!=1:
    if tf_r[-1]=="T" and tf_r[-2]=="F":
        del tf_r[-2:]
        tf_r.append("F")
        n-=1
    else:
        del tf_r[-2:]
        tf_r.append("T")
        n-=1
print(tf_r[0])


Measured memory_bytes: 7180
<?php
$n=trim(fgets(STDIN));
$i=0;
while($i<$n){
  $x=str_split(trim(fgets(STDIN)));
  sort($x);
  $s[]=implode($x);
  ++$i;
}
sort($s);
$a=array_count_values($s);
rsort($a);
$n=count($a);
$ans=0;
$i=0;
while($i<$n){
  if($a[$i]==1){
    break;
  }
  $ans+=(int)(($a[$i]-1)*$a[$i]/2);
  ++$i;
}
echo $ans;

Measured memory_bytes: 20980
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    unsigned a, b;
    cin >> a >> b;
    cout << bitset<32>(a & b) << "\n";
    cout << bitset<32>(a | b) << "\n";
    cout << bitset<32>(a ^ b) << "\n";
}



Measured memory_bytes: 3236
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
using namespace std;

int main() {
  int H,W;
  cin>>H>>W;
  
  vector<string> a(H);
  for(int i=0;i<H;++i){
    cin>>a[i];
  }
  
  // 黒いマスが含まれる行と列を記録
  vector<bool> row_ok(H,false);
  vector<bool> col_ok(W,false);
  
  for(int i=0;i<H;++i){
    for(int j=0;j<W;++j){
      if(a[i][j]=='#'){
        row_ok[i]=true;
        col_ok[j]=true;
      }
    }
  }
  
  // 黒いマスがある行と列の出力
  for(int i=0;i<H;++i){
    if(row_ok[i]){
      for(int j=0;j<W;++j){
        if(col_ok[j])
          cout<<a[i][j];
      }
      cout<<endl;
    }
  }
  
}

Measured memory_bytes: 256
N = int(input())
S = input()

ans = N
b_list = [0]
w_list = [0]
for i, s in enumerate(S):
    if s == '#':
        b_list.append(b_list[i]+1)
    else:
        b_list.append(b_list[i])
for i, s in enumerate(reversed(S)):
    if s == '.':
        w_list.append(w_list[i]+1)
    else:
        w_list.append(w_list[i])

for i in range(1,N+1):
    ans = min(ans, b_list[i]+w_list[N+1-i]-1)
print(ans)

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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<


#define int long long 

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;


int mai[300000];

int a[300000];
int h[300000];

int seg[1000000];

void update(int l,int r,int v,int pos,int val)
{
	if(l>r)
		return;
	if(l==r)
	{
		if(seg[v]<val)
		{
		  seg[v] = val;
		  mai[l] = val;
		}
		  return;
	}
	int mid = (l + r)/2;
	if(pos<=mid)
		update(l,mid,v<<1,pos,val);
	else
		update(mid+1,r,v<<1|1,pos,val);
	seg[v] = max(seg[v<<1],seg[v<<1|1]);
	return;
}

int query(int l,int r,int v,int s,int e)
{
	if(l>r)
		return 0;
	if(r<s||e<l)
		return 0;
	if(s<=l&&r<=e)
		return seg[v];
	int mid = (l+r)/2;
	return max(query(l,mid,v<<1,s,e),query(mid+1,r,v<<1|1,s,e));
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>h[i];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
	{
		int val = query(0,n,1,0,h[i]-1);
		val+=a[i];
		update(0,n,1,h[i],val);
	}
	cout<<query(0,n,1,0,200010);
	return 0;
}

Measured memory_bytes: 14592
#include <cstdio>

int main()
{
	long long int a,b;
	char c;
	scanf ("%lld",&a);
	getchar();
	scanf ("%c",&c);
	getchar();
	scanf ("%lld",&b);
	
	if (c == '+')
	 printf("%lld\n",a+b);
	else
	 printf("%lld\n",a-b);
	
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int _I(){ int x ; scanf("%d", &x); return x; }
int mp[ 10005 ];
int ar[ 200005 ];
void solve()
{
    int n = _I();
    int k = _I();
    long long sum = 0;
    for( int i = 0 ; i < n ;i++ ){
            ar[ i ] = _I();
    }
    sort( ar , ar + n );
    for( int i = 0 ;i < max( 0 , n-k) ; i++ )
    {
        sum += ar[ i ];
    }
    cout<<sum<<"\n";
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main() {
    
    int N;
    int a[100001];
    int count = 0;
    int i;
    
    scanf("%d\n", &N);
    
    for (i = 1; i <= N; i++) {
        scanf("%d ", &a[i]);
    }
    
    for (i = 1; i <= N; i++) {
        if (a[i] != 0 && i == a[a[i]]) {
            count++;
            a[i] = 0;
            a[a[i]] = 0;
        }
    }
    
    printf("%d\n", count);
    
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
#define For(i,a,b) for (register int i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define GO(u) for (register int j=f[u];j!=-1;j=nxt[j])
#define fi first
#define se second
#define pii pair<int,int>
#define MP make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int N=205;
const int mod=998244353;
int n,x[N],y[N],ans=0,er[N];
inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
inline void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
	return;
}
int main()
{
	n=read();
	FOR(i,1,n) x[i]=read(),y[i]=read();
	er[0]=1;
	FOR(i,1,n) er[i]=2LL*er[i-1]%mod;
	ans=(1LL*er[n]-1-n+mod)%mod;
	FOR(i,1,n) FOR(j,1,i-1) 
	{
		int cnt=0;
		FOR(k,1,j-1) if (1LL*((y[i]-y[j])*(x[j]-x[k]))==1LL*((x[i]-x[j])*(y[j]-y[k]))) cnt++;
		ans=(1LL*ans-er[cnt]+mod)%mod;
	}
	write(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;

inline bool valid(int x, int y){
    return 0 <= x && x < 8 && 0 <= y && y < 8;
}

struct state {
    vi score;
    vs g;
};

state flip(int x, int y, state s, bool turn){
    const char cs[] = "xo";
    bool update = false;
    for (size_t i = 0; i < 8; i++){
        const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
        const int dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
        int cx = x + dx[i];
        int cy = y + dy[i];
        if (!valid(cx, cy) || s.g[cy][cx] == cs[turn]) continue;
        while (valid(cx, cy) && s.g[cy][cx] == cs[!turn]){
            cx += dx[i];
            cy += dy[i];
        }
        if (valid(cx, cy) && s.g[cy][cx] == cs[turn]){
            update = true;
            for (int ix = x + dx[i], iy = y + dy[i];
                !(ix == cx && iy == cy);
                ix += dx[i], iy += dy[i]){
                s.g[iy][ix] = cs[turn];
                s.score[turn]++;
                s.score[!turn]--;
            }
        }
    }
    if (update){
        s.g[y][x] = cs[turn];
        s.score[turn]++;
        s.score[!turn]--;
    }
    return s;
}

int main(){
    state cur;
    cur.score = vector < int > {0, 0};
    for (size_t i = 0; i < 8; i++){
        string s; cin >> s;
        cur.g.push_back(s);
        cur.score[0] += count(s.begin(), s.end(), 'x');
        cur.score[1] += count(s.begin(), s.end(), 'o');
    }

    for (int turn = 1; turn <= 64; turn++){
        state next = cur;
        for (int y = 0; y < 8; y++){
            for (int x = 0; x < 8; x++){
                if (cur.g[y][x] == '.'){
                    state cand = flip(x, y, cur, turn & 1);
                    if (((turn & 1) == 1 && next.score[1] < cand.score[1]) ||
                        ((turn & 1) == 0 && next.score[0] <= cand.score[0])){
                        next = cand;
                    }
                }
            }
        }

        cur = next;
    }

    for (int i = 0; i < 8; i++){
        cout << cur.g[i] << endl;
    }
}

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

int main(){

	int A,B, C, sum = 0;
	scanf("%d %d %d", &A, &B, &C);

	if (A < B && A < C){
		sum += A;
		if (B < C)
			sum += B;
		else 
			sum += C;
	}
	else if (B < A && B < C){
		sum += B;
		if (A < C)
			sum += A;
		else 
			sum += C;
	}
	else{
		sum += C;
		if (B < A)
			sum += B;
		else 
			sum += A;
	}


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

	return 0;
	
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

void out(){cout << "\n";}
template<class T,class... Args>
void out(const T &x,const Args &... args){
	cout << x << " ";
	out(args...);
}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	cin >> n;
	for(ll i=-120;i<=120;i++){
		for(ll j=-120;j<=120;j++){
			if(i*i*i*i*i-j*j*j*j*j==n){
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3632
import java.util.*;

 class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long R = sc.nextLong();
        long ans = 9999;
        if (R-N>=2018) {
        	ans = 0;
        } else {
            N = N % 2019;
            R = R % 2019;
            if(N<R) {
            	long wk = 0;
            	for(long i=N; i<=R; i++) {
            		for(long j=i+1; j<=R; j++) {
            			wk = i*j%2019;
            			if(wk<ans) {
            				ans = wk;
            			}
            		}            		
            	}
            }else {
            	ans = 0;
            }
        }
        
        System.out.println(ans);
    }
}


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

int main()
{
	int N,minv,*Ap,sw=0;
	cin >> N;
	Ap = new int[N];
	for(int i=0;i<N;i++) cin >> Ap[i];

	for(int i=0;i<N-1;i++){
		minv = i;
		for(int j=i;j<N;j++){
			if(Ap[j] < Ap[minv]){
				minv = j;	
			}
		}
		if(minv != i){
			swap(Ap[i],Ap[minv]);
			sw++;
		}
		
	}
	for(int i=0;i<N;i++){
		if(i>0) cout << ' ';
		cout << Ap[i];
	}
	cout << endl;
	cout << sw << endl;
}

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

using namespace std;

using ll = long long;
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 << " ";
  }
}

string sed(string s, string a, string b) {
  // cout << a << " -> " << b << endl;
  // cout << "in :" << s << endl;
  int prev = 0, sz = s.size();
  string now = "";
  for(int i=0;i<(int)(s.size());++i) {
    // cout << i << ":" << prev << ":" << now << endl;
    now.push_back(s[i]);
    if(a == now) {
      s.erase(s.begin() + prev, s.begin() + i + 1);
      s.insert(prev, b);
      prev += b.size();
      i = prev-1;
      now = "";
    }
    if(i == (int)(s.size())-1) {
      now = "";
      prev++;
      i = prev - 1;
      if(prev == (int)(s.size())) break;
    }
  }
  // cout << "out:" << s << endl;
  return s;
}

int solve(int n, const vector<string> &a, const vector<string> &b, string s, string t) {
  // cout << "init:" << s << endl;
  int res = INF;
  for(int i=0;i<n;++i) {
    string s1 = sed(s, a[i], b[i]);
    if(s1 == t) {
      return 1;
    } else if((int)(s1.size()) > (int)(t.size())) {
      continue;
    } else if(s != s1) {
      res = min(res, solve(n, a, b, s1, t) + 1);
    }
  }
  return res;
}

int main() {
    cin.tie(0);
    cout << fixed << setprecision(10);

    while(1) {
      int n; cin >> n;
      if(n == 0) break;
      vector<string> a(n), b(n);
      string s, t;
      for(int i=0;i<n;++i) {
        cin >> a[i] >> b[i];
      }
      cin >> s >> t;

      if(s == t) return 0;
      else {
        int res = solve(n, a, b, s, t);
        if(res == INF) {
          cout << -1 << endl;
        } else {
          cout << res << endl;
        }
      }

    }
}


Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	int A,P;
	cin>>A>>P;
	cout<<(A*3+P)/2;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	while (cin >> n, n != -1) {
		string ans = "";
		if (n == 0) ans.push_back('0');
		while (n > 0) {
			ans.push_back(n % 4 + '0');
			n = n / 4;
		}
		reverse(ans.begin(), ans.end());
		cout << ans << endl;
	}
	return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    string s;
    cin>>s;
    int c=0;
    int n=s.size();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            c++;
    }
    cout<<c;

    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin >> N;
	vector<int> B(N), srt(N), ans(N);
	for (int i=0; i<N; i++) {
		cin >> B.at(i);
		srt.at(i) = B.at(i);
	}
	
	int counter = 0;
	bool found = false;
	int Max = N-1;
	
	START:
	int i = Max;
	while (i >= 0) {
		if (B.at(i) == i+1) {
			ans.at(counter) = B.at(i);
			counter = counter+1;
			found = true;
			break;
		}
		i = i-1;
	}
	if (found == false) {
		cout << -1 << endl;
		goto END;
	}
	else if(Max != 0) {
		Max = Max -1;
		B.erase(B.begin()+i);
		found = false;
		goto START;
	}
	
	reverse(ans.begin(), ans.end());
	for (int i=0; i<N; i++) {
		cout << ans.at(i) << endl;
	}
	END: ;
}


Measured memory_bytes: 256
#include<stdio.h>
 int main(void)
 {
     int a,b,c;
     int P;

     scanf("%d%d%d",&a,&b,&c);

     if((a<b)&&(a<c)) P+=a;
     else if((b<a)&&(b<c)) P+=b;
     else if((c<a)&&(c<b)) P+=c;
     else P+=a;

     if(P==a){
       if(b<c) P+=b;
       else P+=c;
     }

     else if(P==b){
       if(a<c) P+=a;
       else P+=c;
     }

     else if(P==c){
       if(a<b) P+=a;
       else P+=b;
     }

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

     return 0;
 }



Measured memory_bytes: 128
import collections

def topological():
    """トポロジカルソート (有向グラフ) O(V+E)

    Vars:
        n (int):     頂点数
        edge (list): 辺に関するリスト (edge[i]: iを始点に持つ辺の終点のリスト)
    
    Returns:
        list/bool: トポロジカル順序 (閉路が存在する場合はFalse)
    """
    in_degree = [0] * n
    for i in range(n):
        for v in edge[i]:
            in_degree[v] += 1
    
    nodelist = collections.deque()
    for i in range(n):
        if in_degree[i] == 0:
            nodelist.append(i)
    
    res = []
    while nodelist:
        p = nodelist.popleft()
        for q in edge[p]:
            in_degree[q] -= 1
            depth[q] = max(depth[q], depth[p] + 1)
            if in_degree[q] == 0:
                nodelist.append(q)
        
        res.append(p)
    
    if len(res) == n:
        return res
    else:
        return False


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

n = m * (m - 1) // 2

num = 0
table = [[-1] * m for _ in range(m)]
for i in range(m):
    for j in range(i+1, m):
        table[i][j] = num
        table[j][i] = num
        num += 1

edge = [[] for _ in range(n)]
for i in range(m):
    for j in range(m-2):
        edge[table[i][a[i][j]-1]].append(table[i][a[i][j+1]-1])

depth = [0] * n
l = topological()

if not l:
    print(-1)
else:
    print(max(depth) + 1)

Measured memory_bytes: 178948
import math
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '+':
        print(a+b)
    if op == '-':
        print(a-b)
    if op == '*':
        print(a*b)
    if op == '/':
        w = math.floor(a/b)
        print(w)
    if op == '?':
        break


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

using ll=long long;
const ll MOD=1000000007;

int main() {
  string ALP="ABC";
  string alp="abc";
  int n,k;
  string s;
  cin >> n >> k >> s;
  for(int i=0;i<3;i++){
    if(ALP[i]==s[k-1])
      s[k-1]=alp[i];
  }
  cout << s << endl;
}

Measured memory_bytes: 256
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

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

def check(n):
	b = [False]*(len(a))
	for i in range(1, len(a)):
		if a[i] >= n:
			b[i] = True
		else:
			b[i] = False

	r = int(1e9)
	l = int(1e9)
	rb = b[N]
	lb = b[N]
	for i in range(1, N):
		if lb == b[N-i]:
			l = i
			break
		else:
			lb = b[N-i]
		
	for i in range(1, N):
		if rb == b[N+i]:
			r = i
			break
		else:
			rb = b[N+i]
	if r == int(1e9) and l == int(1e9):
		if N % 2 == 1:
			return b[N]
		else:
			return not b[N]
	else:
		if r < l:
			return rb
		else:
			return lb

# 条件を満たす最小の値を返す
def binarySearch(small, big):
	mid = (big + small) // 2
	if big - small <= 1:
		if check(small): return small
		else:            return big
	else:
		if not check(mid):
			return binarySearch(small, mid)
		else:
			return binarySearch(mid, big)

print(binarySearch(2, 2*N-2))


Measured memory_bytes: 25864
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b ;
  cin >> a >> b ;
  int c, d ;
  c = max(a,b) ;
  d = min(a,b) ;
  REP(i,c){
    cout << d ;
  }
  cout <<endl ;
  
  
  
  return 0 ;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

const LLI mod = 1e9+7;

LLI power(LLI n, LLI p, LLI m){
  LLI ret = 1;
  while(p>0){
    if(p&1) (ret *= n) %= m;
    (n *= n) %= m;
    p /= 2;
  }
  return ret;
}

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

  int N;
  string s;
  while(cin >> N >> s){
    LLI ans = 1;

    vector<LLI> cnt(26);
    
    REP(i,N){
      ++cnt[s[i] - 'a'];
    }
    dump(cnt);

    REP(i,26) (ans *= (cnt[i]+1)) %= mod;
    ((ans -= 1) += mod) %= mod;
    cout << ans << endl;
    
  }
  
  return 0;
}


Measured memory_bytes: 512
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(ll, A, N);
    ll ans = 1;
    ll a = 0;
    REP(i, N - 1)
    {
        ll d = A[i + 1] - A[i];
        if (a == 0)
        {
            a = d;
        }
        if (d > 0 and a < 0 or d < 0 and a > 0)
        {
            ++ans;
            a = 0;
        }
    }
    OUT(ans);
}

Measured memory_bytes: 1024
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific

using namespace std;

int main(void) {
    size_t n;
    unsigned long k;
    cin >> n >> k;
    unsigned long a = k;
    --k;
    for(size_t i = 0; i < n-1; ++i)
        a *= k;
    
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
import Data.Array

solve :: Int -> Int -> Mint
solve n k = sum $ map (\(i,a)->M i*a) $ assocs arr where
  arr = array (1, k) [ (i, M (div k i) ^ n - sum ext) |
    i <- [k, k-1 .. 1],
    let ext = [arr!(i*m) | m <- [2..div k i] ] ]

main = do
  [n, k] <- map read.words <$> getLine
  print $ solve n k

modulus = 10^9 + 7
newtype Mint = M Int
instance Num Mint where
  (M a) + (M b)
    | a + b < modulus = M $ a + b
    | otherwise = M $ a + b - modulus
  (M a) * (M b) = M $ mod (a * b) modulus
  negate (M 0) = M 0
  negate (M a) = M $ modulus - a
  fromInteger a = M $ mod (fromInteger a) modulus
  abs = id
  signum _ = M 1
instance Show Mint where
  show (M a) = show a



Measured memory_bytes: 15248
import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
  public static void main(String args[]){

    int id, k, l, r,p;
    StringBuilder build = new StringBuilder();
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Node node[] = new Node[n+1];

    for(int i = 1; i<n+1; i++){
      node[i] = new Node();
      node[i].key = sc.nextInt();
    }

    for(int i = 1; i<n+1; i++){
      System.out.print("node "+i+": key = "+node[i].key+", ");
      l = i*2;
      r =  i*2+1;
      p = i/2;
      if(p>=1)System.out.print("parent key = "+node[p].key+", ");
      // build.append("parent key = ").append(node[i].pk).append(", ");
      if(l<=n)System.out.print("left key = "+node[l].key+", ");
      // build.append("left key = ").append(node[i].lk).append(", ");
      if(r<=n)System.out.print("right key = "+node[r].key+", ");
      System.out.println("");
      // if(l<=n)node[i].lk = node[l].key;
      // if(r<=n)node[i].rk = node[r].key;
      // if(p>1)node[i].pk = node[p].key;

    }

    for(int i = 1 ; i < n; i++){
      // build.append("node ").append(node[i].id).append(": key =  ").append(node[i].key).append(", ");


      // build.append("right key = ").append(node[i].rk).append(", ");
      // build.append("\n");
    }

    // System.out.print(build);

  }
}

class Node{
  int id;
  int key;
  int pk = -1;
  int lk = -1;
  int rk = -1;
}



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

int main()
{
  int dish[5];
  for(int i = 0; i < 5; i++)
  {
    cin >> dish[i];
  }
  
  for(int j = 0; j < 4; j++)
  {
    for(int k = j + 1; k < 5; k++)
    {
      if(dish[k] % 10 == 0)
      {
        int tmp = dish[j];
        dish[j] = dish[k];
        dish[k] = tmp;
      }
    }
  }
  
  for(int l = 0; l < 4; l++)
  {
    for(int m = l + 1; m < 5; m++)
    {
      if(dish[l] % 10 != 0 && dish[l] % 10 < dish[m] % 10)
      {
        int tmp = dish[l];
        dish[l] = dish[m];
        dish[m] = tmp;
      }
    }
  }
  
  int sum = 0;
  for(int a = 0; a < 4; a++)
  {
    if(dish[a] % 10 == 0)
    {
      sum += dish[a];
    }
    else
    {
      sum += dish[a] - dish[a] % 10 + 10;
    }
  }
  sum += dish[4];
  cout << sum << '\n';
  return 0;
}


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

int main() {
	
  string a;
  cin >> a;
  int b, c, d;
  if(a[0]=='1'){
    b=1;
  }
  else{
    b=0;
  }
   if(a[1]=='1'){
    c=1;
  }
  else{
    c=0;
  }
   if(a[2]=='1'){
    d=1;
  }
  else{
    d=0;
  }
  cout << b+c+d <<endl;
}


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

#define int long long
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

signed main(){
    string s;
    cin>>s;
    int ans=0;
    for(int bit = 0; bit < (1<<(s.size()-1)); ++bit){
        string formula = s;
        int j=1;
        for(int i=0;i<(s.size()-1);i++){
            if(bit & (1<<i)){
                formula.insert(i+j,"+");
                j++;
            }
        }
        int digit = 0;
        int part = 0; 
        for(int i=0;i<formula.size();i++){
            if(formula[i] != '+'){
                part *= 10;
                part += formula[i] - '0';
            }
            else if(formula[i] == '+'){
                ans += part;
                part = 0;
            }     
        }
        ans += part;

    } 

    put(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
    cin>>n;
    ll sum=0;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            sum+=i;
        }
    }
    cout<<sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3644
from fractions import gcd

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

def main():
    n = int(input())
    a = input_ints()
    x = [a[0]]
    y = [a[-1]]
    for i in range(n-1):
        x.append(gcd(x[-1], a[i + 1]))
        y.append(gcd(y[-1], a[n - i - 2]))
    ans = max(x[-2],y[-2])
    for i in range(1, n-1):
        ans = max(ans,gcd(x[i-1],y[-i-2]))
    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 16148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int y = in.nextInt();
		int[] largeArray = { 1, 3, 5, 7, 8, 10, 12 };
		int[] smallArray = { 4, 6, 9, 11 };
		String str = "Yes";
		if (x == 2 || y == 2 || isNotIncludingSameArrays(x, y, smallArray)) {
			str = "No";
		}
		if(isNotIncludingSameArrays(x, y, largeArray)){
			str = "No";
		}
		if(isNotIncludingSameArrays(x, y, smallArray)){
			str = "No";
		}
		System.out.println(str);
	}

	static boolean isNotIncludingSameArrays(int x, int y, int[] numArrays) {

		boolean xflag = false, yflag = false;
		for (int i = 0; i < numArrays.length; i++) {
			if (x == numArrays[i]) {
				xflag = true;
			}
			if (y == numArrays[i]) {
				yflag = true;
			}
		}
		return xflag ^ yflag;
	}

}


Measured memory_bytes: 22996
import sys
input = sys.stdin.readline
N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]
XH.sort()
X = [XH[i][0] for i in range(N)]
ans = 0
res = 0
from bisect import bisect_left
cnt = [0]*(N+1)
for i in range(N):
    x, h = XH[i]
    res-=cnt[i]
    h-=res
    if h<=0:
        continue
    n = ((h-1)//A+1)
    j = bisect_left(XH, [x+D*2+1, -1])
    cnt[j] += n*A
    res += n*A
    ans+=n
print(ans)
    





Measured memory_bytes: 88428
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
using namespace std;
const ll MOD = 1000000007;
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod)
{
  return modpow(a, mod - 2, mod);
}

ll modnCr(ll n, ll r, ll mod)
{
  ll ans = 1;
  FOR(i, 1, n + 1)
  {
    ans = (ans * i) % mod;
  }
  ll inv = 1;
  FOR(i, 1, r + 1)
  {
    inv = (inv * i) % mod;
  }
  FOR(i, 1, n - r + 1)
  {
    inv = (inv * i) % mod;
  }
  ans = (ans * modinv(inv, mod)) % mod;
  return ans;
}

int main()
{
  ll count[26] = {};
  int n;
  string s;
  cin >> n >> s;
  REP(i, n)
  {
    count[s[i] - 'a']++;
  }

  ll ans = 1;

  REP(i, 26)
  {
    ans = (ans * (count[i] + 1)) % MOD;
  }
  cout << (ans + MOD - 1) % MOD << endl;
}


Measured memory_bytes: 512
a,b,c,d=map(int,input().split())
"""
if b<=0 and d<=0:
    print(a*c)
elif b<=0 and d>=0:
    print(a*d)
elif b>=0 and d<=0:
"""
A=abs(a)
B=abs(b)
C=abs(c)
D=abs(d)

check_1 = a*c
check_2=a*d
check_3=b*c
check_4=b*d

if check_1<=check_2:
    check_1=check_2

if check_3<=check_4:
    check_3=check_4

if check_1<=check_3:
    print(check_3)
else:
    print(check_1)


Measured memory_bytes: 9128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();
    int n = sc.nextInt();
    if(d == 0){
      if(n != 100){
        System.out.println(n);
      }else{
        System.out.println(n+1);
      }
    }
    if(d == 1){
      if(n != 100){
        System.out.println(n*100);
      }else{
        System.out.println((n+1)*100);
      }
    }
    if(d == 2){
      if(n != 100){
        System.out.println(n*10000);
      }else{
        System.out.println((n+1)*10000);
      }
    }
  }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int A, B; cin >> A >> B;
    int cnt = 0;
    for(int i = A; i <= B; i++){
        int a = (i / 10) % 10;
        int b = (i / 1000) % 10;
        if ((i % 10) == (i / 10000) and a == b) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007

using namespace std;
using ll = long long;
using ldb = long double;

typedef struct {
	ll x, y, z;
}cake_t;

int main() {
	ll N, M; cin >> N >> M;
	vector<cake_t> cake(N);
	for (int i = 0; i < N; i++) {
		cin >> cake[i].x >> cake[i].y >> cake[i].z;
	}
	ll ans = -1e14;
	for (int i = 0; i < 8; i++) {
		ll an = 0;
		int temp = i;
		vector<int> bit(3);
		vector<ll> scr(N);
		for (int j = 0; temp > 0; j++) {
			bit[j] = temp % 2;
			temp /= 2;
		}
		for (int k = 0; k < N; k++) {
			if (bit[0]) scr[k] += cake[k].x;
			else scr[k] -= cake[k].x;

			if (bit[1]) scr[k] += cake[k].y;
			else scr[k] -= cake[k].y;

			if (bit[2]) scr[k] += cake[k].z;
			else scr[k] -= cake[k].z;
		}
		sort(scr.begin(), scr.end(), greater<ll>());
		for (int k = 0; k < M; k++) {
			an += scr[k];
		}
		ans = max(ans, an);
	}

	cout << ans << endl;
}


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

using namespace std;
using ll=long long;

#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){for(int i=0;i<n;i++) cin>>f[i];}

template<typename T,typename U> void Printarray(T f,U n){for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];}
template<typename T,typename U> void Printarray2(T f,U n){for(int i=0;i<n;i++) cout<<f[i]<<endl;}
template<typename T,typename U,typename V> void Printarray3(T f,U a,V b){ rep(i,a){ rep(j,b){ cout<<f[i][j]; } cout<<endl; } }
template<typename T,typename U> void Printarray4(T f,U n){ rep(i,n){ rep(j,n){ cout<<f[i][j]; } cout<<endl; } }
void flagfunc(bool flag,string A,string B){flag ? cout<<A<<endl : cout<<B<<endl;}
void flag2func(bool flag){flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;}
void flag3func(bool flag){flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string s;cin>>s;
  bool flag=true;
  rep(i,s.size()/2){
    //cout<<"s[i] "<<s[i]<<" s[s.size()-i-1] "<<s[s.size()-i-1]<<endl;
    if(s[i]!=s[s.size()-i-1]){
      flag=false;
      break;
    }
  }
  rep(i,s.size()/2){
    //cout<<"s[i] "<<s[i]<<" s[i+s.size()/2-1] "<<s[i+(s.size()+1)/2]<<endl;
    if(s[i]!=s[i+(s.size()+1)/2]){
      flag=false;
      break;
    }
  }
  flag2func(flag);
}


Measured memory_bytes: 256
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, M = in.nextInt
  val As = Array.fill(N)(in.nextLong)

  println(As.map(java.lang.Long.lowestOneBit).distinct.size match {
    case 1 => As.reduceLeft(lcm) match {
        case 0 => 0
        case m => (M / (m / 2) + 1) / 2
      }
    case _ => 0
  })

  def lcm(l: Long, r: Long): Long = {
    val ret = (l * r / gcd(l, r))
    if (ret > M * 2) 0 else ret
  }

  def gcd(l: Long, r: Long): Long = if (l % r == 0) r else gcd(r, l % r)
}

Measured memory_bytes: 62372
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

string s; 

int main()
{
	cin>>s;
	
	bool chk=false;
	for(int i=0;i<s.size()-1;i++)
		if(s[i]=='A'&&s[i+1]=='C')
			chk=true;
			
	cout<<(chk?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
# 最小公倍数(mathは3.5以降) fractions
from functools import reduce
import fractions #(2020-0405  fractions→math)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
lcm         =lcm_list(A)
harf_lcm     =lcm//2             # 最小公倍数の半分
harf_lcm_num =M//harf_lcm          # Mの中の半公倍数の個数
harf_lcm_num =(harf_lcm_num +1)//2 # 偶数を除く

#半公倍数がA自身の中にある時は✖
#if harf_lcm in A:
 #   harf_lcm_num =0

#半公倍数がaiで割り切れるときは✖
for a in A:
    if harf_lcm % a ==0:
        harf_lcm_num =0
        break

print(harf_lcm_num)

Measured memory_bytes: 16272
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<int,int>
#define iil pair<ll,ll>
#define se second
#define ld long double
#define mod 1000000007
#define popcount __builtin_popcountll
#define x0 zxcxzcsacasd
#define x1 ghfghujfgfg
#define y0 olkjhdnncvcv
#define y1 bhvgrewm345345435
#define debug(x) std::cerr<<#x<<": "<<(x)<<'\n'
#define all(x) x.begin(), x.end()
using namespace std;

int main(){
	int x;
	cin>>x;
	cout<<1-x<<endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.begin(),a.end());
	cout<<a[n-1]-a[0]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){

    vector<int> v;
    int n;
    int cnt = 0;

    cin >> n;

    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        v.emplace_back(tmp);
    }

    for(int i = 0; i < n; i++){
        while(v[i] % 2 == 0){
            v[i] /= 2;
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 384