akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
using namespace std;
const int Max_N = 300+10;

long double dp[Max_N][Max_N][Max_N];


int main() {
    long double n;
    cin >> n;
    cout<<setprecision(10)<<fixed;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int f;
        cin >> f;
        cnt[f]++;
    }
    dp[0][0][0] = 0;
    for (int d = 0; d < Max_N-1; d++) {
        for (int c = 0; c < Max_N-1; c++) {
            for (int b = 0; b < Max_N-1; b++) {
                if(b == 0 && c==0 && d ==0 ){
                    continue;
                }
                if ( d != 0) {
                    dp[b][c][d] += (d/(long double)(b+c+d))*(dp[b][c+1][d-1]);
                }
                if (c != 0) {
                    dp[b][c][d] += (c/(long double)(b+c+d))*(dp[b+1][c-1][d]);
                }
                if (b != 0) {
                    dp[b][c][d] += (b/(long double)(b+c+d))*(dp[b-1][c][d]);
                }
                dp[b][c][d] += ((n-b-c-d)/(long double)(b+c+d))+1;
            }
        }
    }
    cout << dp[cnt[1]][cnt[2]][cnt[3]];
    return 0;
}


Measured memory_bytes: 465152
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[100010],sum[100010]={},ans=1;
    cin>>n;
    rep(i,n) cin>>a[i];
    sort(a,a+n);
    rep(i,n){
        sum[i+1]=sum[i]+a[i];
    }
    for(ll i=n-1;i>0;i--){
        if(sum[i]*2>=a[i]){
            ans++;
        } else break;
    }
    cout<<ans<<endl;

    return 0;
}

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

#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using ll = long long int;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    int N; cin >> N;
    vi A(N);
    rep(i,N) cin >> A[i];
    
    map<int, int> mp;
    rep(i,N) mp[A[i]]++;
    auto itr = mp.begin();
    ll ans = 0;
    while(itr != mp.end()){
        ll tmp = itr->second;
        ans += tmp*(tmp-1)/2;
        itr++;
    }

    rep(i,N){
        cout << (ans - (mp[A[i]]-1)) << "\n";
    }
    //cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8320
n = list(map(int,input().split()))
ans = 0
count = 0
for i in range(n[0]+1):
    j = i
    ans = 0
    while(i is not 0):
        ans = ans + i%10
        i = int(i/10)
    if ans >= n[1] and ans <= n[2]:
        count = count +j
print(count)

Measured memory_bytes: 3060
#include<stdio.h>


 int main(){
     int b,f,r,v,i,n,j,k;
     int T[4][3][10]={0};
     scanf("%d",&n);

     for(i=0;i<n;i++){
            scanf("%d%d%d%d",&b,&f,&r,&v);
            T[b-1][f-1][r-1]+=v;
            }
     for(i=0;i<4;i++){
            for(j=0;j<3;j++){
                  for(k=0;k<10;k++){
                        printf(" %d",T[i][j][k]);
                        }
                  printf("\n");

                  }
            if(i==3)break;
            printf("####################\n");
            }
      return 0;
      }


Measured memory_bytes: 2120
n, k = [ int(_) for _ in input().split() ]
h = [ int(_) for _ in input().split() ]

h.sort(reverse=True)
flag = True
if h[n-1]>k:
	ans = n
	flag = False
elif h[0] < k:
	ans = 0
	flag = False
#k==max(h)とk==min(h)と合致する場合の分岐がなく、ans=0になっていた
elif h[n-1]==k:
	ans = n
elif h[0]==k:
	ans = h.count(h[0])
if flag == True:
	for i in range(0,n):
		if h[i] < k:
			ans = len(h[0:i])
			break

print(ans)

Measured memory_bytes: 11904
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define dl double
#define mod 1000000007
#define sz1 105
#define sz2 1005

using namespace std;

int main()
{
    ll n,x;

    scanf("%lld %lld",&n,&x);

    printf("%lld\n",(n*n)-x);

    return (0);
}



Measured memory_bytes: 256
import numpy as np
from copy import deepcopy
import math
import itertools

N = int(input())


## 入力整数Nの桁数を出力する
## 10**(out-1) <= in < 10**out
def int2digit(num):
  return(len(str(num)))

## k桁の753数を全て構成する
def mk753_digit(digit):
  lst_753_tuple = list(itertools.product([7,5,3], repeat=digit))
  lst_753_str = list(map(lambda x: ''.join(map(str, x)), lst_753_tuple))
  lst_753_contain7 = [s for s in lst_753_str if '7' in s]
  lst_753_contain75 = [s for s in lst_753_contain7 if '5' in s]
  lst_753_contain753 = [s for s in lst_753_contain75 if '3' in s]
  lst_753 = list(map(int, lst_753_contain753))
  return lst_753


ans = 0
digit = int2digit(N)
for k in range(digit):
  ans += len(mk753_digit(k))
lst_753_samedigit = mk753_digit(digit)
lst_753_samedigit_smaller = [x for x in lst_753_samedigit if x <= N]
ans += len(lst_753_samedigit_smaller)

print(ans)

Measured memory_bytes: 17664
#include <stdio.h>

int main(void) {

	int h, w;

	while (1) {

		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0) {
			break;
		}

		for (int h_i = 0; h_i < h; h_i++) {
			for (int w_i = 0; w_i < w; w_i++) {
				if (w_i == w - 1) {
					puts("#");
				}
				else {
					printf("#");
				}
			}
		}

		puts("");
	}

	return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k; cin>>n>>k;
  int a[n]; for(int i=0; i<n; i++) cin>>a[i]; 
  for(int i=k; i<n; i++) cout<<((a[i]>a[i-k])?"Yes":"No")<<endl;
}


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

int main()
{
	int n;
	int ans = 114514;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		int b = 0;
		cin >> a;
		while (a % 2 == 0) {
			a /= 2;
			b++;
		}
		if (ans > b) {
			ans = b;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
  long long n;  
  scanf("%lld",&n);
  int i,s=sqrtl(n)+2,a=log10l(10*n);
  for(i=1;i<s;i++){
    if(n%i)continue;
    a=fmin(a,fmaxl(log10l(i*10),log10l(n/i*10)));
  }
  printf("%d",a);
}

Measured memory_bytes: 2192
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n, a, b, c, d;
string s;

bool sim(int A, int B){
  
  if( A > B ) return false;
    
  for(int i=A;i<=B;i++){
    
    if( i && s[i] == '#' && s[i-1] == '#' ) return false;
    
  }
  
  return true;
}

void pon(int &A, int &B){
  
  int flg = 0;
  
  for(int i=B;i<n;i++){
    
    if( i && i < n-1 && s[i] == '.' && s[i-1] == '.' && s[i+1] == '.' ){
      flg = 1;
      B = i;
      break;
    }
    
  }
  
  if( !flg ){
    A = -1;
    return ;
  }
  
  if( sim( A, B ) == false ){
    A = -1;
    return ;
  }
  
  A = B + 1;
  
  return ;
}

signed main(){
  
  cin>>n>>a>>b>>c>>d;
  a--,b--,c--,d--;
  
  cin>>s;
  
  if( ( a < b && c < d ) || ( a > b && c > d ) ){
    
    if( sim( a, c ) && sim( b, d ) ) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
  }
  else if( a > b && c < d ){
    
    pon( b, a );
    
    if( b == -1 ) cout<<"No"<<endl;
    else{
      
      if( sim( a, c ) && sim( b, d ) ) cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
      
    }
    
  }
  else if( a < b && c > d ){
    
    pon( a, b );
    
    if( a == -1 ) cout<<"No"<<endl;
    else{
      
      if( sim( a, c ) && sim( b, d ) ) cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
      
    }

  
  }
  
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	//
  int H, W;
  cin >> H >> W;
  for(int i=0; i<W+2; i++)
    cout << '#';
  cout << endl;
  
  for(int i=0; i<H; i++){
    cout << '#';
    
    vector<char> pic(W);
     for(int i=0; i<W; i++){
      cin >> pic. at(i);
      cout << pic. at(i);
    }
    cout << "#" << endl;
  }
  
    for(int i=0; i<W+2; i++)
    cout << "#";
  cout << endl;
 }

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int a[1000]={0},c=0;
    getline(cin,s);
    int x=s.size();
    for(int i=0;i<x;i++)
        a[s[i]]++;
    for(int i=97;i<125;i++)
    if(a[i]>1){
          c=1;
          break;
    }
    if(c==0)
        cout<<"yes"<<endl;
    else
        cout<<"no"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define F first
#define S second
typedef vector<pli> vpli;
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end() 
#define tests int t; cin>>t; while(t--)
#define take(a,b,c) for(b=0;b<c;b++) cin>>a[b];
#define INF 1e18
// https://codeforces.com/problemset/page/3?tags=1500-1800
int main()
{	
  //auto start = std::chrono::high_resolution_clock::now();
    string s,t;
    cin>>s>>t;
    int flag=0;
    for(int i=0;i<s.size();i++){
      if(s[i]!=t[i]){
        flag=1;
        break;
      }
    }
    if(flag==0) cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
  //auto stop = std::chrono::high_resolution_clock::now(); 
  //auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
  //cout << duration.count() << endl; 

}

Measured memory_bytes: 3596
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let t1: i64 = scan(tokens);
    let t2: i64 = scan(tokens);
    let a1: i64 = scan(tokens);
    let a2: i64 = scan(tokens);
    let b1: i64 = scan(tokens);
    let b2: i64 = scan(tokens);
    if a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2 {
        println!("infinity");
        return;
    }
    let (v1, v2) = if a1 * t1 + a2 * t2 < b1 * t1 + b2 * t2 {
        (b1 - a1, b2 - a2)
    } else {
        (a1 - b1, a2 - b2)
    };
    if v1 > 0 {
        println!("0");
        return;
    }
    let x = v1 * t1 + v2 * t2;
    let y = v2 * t2;
    println!("{}", y / x * 2 - 1 - (y % x == 0) as i64);
}


Measured memory_bytes: 4352
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	int n;
	cin >> n;
	vector < pair < int, int > > a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	//~solve
	vector < int > ans(n);
	sort(all(a));
	int k = n / 2 - 1;
	for (int i = 0; i < n; i++)
	{
		if (i > k)
		{
			ans[a[i].second] = a[k].first;
		}		
		else
		{
			ans[a[i].second] = a[k + 1].first;
		}
	}
	for (int i = 0; i < n; i++)
		cout << ans[i] << endl;

	return 0;
}



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

#define ll long long int
#define print cout<<fixed<<setprecision(10)<<

int a[305], n;
double dp[305][305][305];

double f(ll x, ll y, ll z){

    if(x < 0 or y < 0 or z < 0 or (x == 0 and y == 0 and z == 0)) return 0.0;

    if(dp[x][y][z] >= 0.0) return dp[x][y][z];

    return dp[x][y][z] = (n + x * f(x-1, y, z) + y * f(x+1, y-1, z) + z * f(x, y+1, z-1)) / (x + y + z);
}

int main() {

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    cin>>n;

    ll x = 0,y = 0,z = 0;
    for(int i=0; i < n; i++) {
        cin>>a[i];
        if(a[i] == 1) x++;
        else if(a[i] == 2) y++;
        else z++;
    }

    memset(dp, -1.0, sizeof dp);

    print f(x,y,z);

    return 0;
}

Measured memory_bytes: 225472
/*
   AtCoder Submission
*/

#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

/* typedefs */
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <string,string> mss;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int A, B;
    cin >> A >> B;

    if(A <= 8 && B <= 8){
        cout << "Yay!" << endl;
    } else cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int qwq[100005];
int ans,a[100005];
int main(int argc, char** argv) {
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin >> u >> v;
		if(a[u]>=a[v]) qwq[v]=1;
		if(a[v]>=a[u]) qwq[u]=1;
	}
	for(int i=1;i<=n;i++) ans+=qwq[i]==0;
	cout << ans;
	return 0;
}

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

using namespace std;

int countDivisors(int n)
{
    int cnt = 0;
    for (int i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n;
    cin >> n;
    long long res = 0;
    for (int i = 1; i < n; i++) {
        res += countDivisors(n - i);
    }
    cout << res << endl;
    return 0;
}





Measured memory_bytes: 3664
# -*- coding: utf-8 -*-


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


def solve(n, x):
    if x < n - x:
        x = n - x
    w = n - x
    t = (w - (x % w)) % w
    res = (x + w - 1) // w * 3 * w - t * 3
    if t != 0:
        res += solve(w, w - t)
    return res


def main():
    n, x = rli()
    print(solve(n, x))


if __name__ == '__main__':
    main()


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

int main(){
	int a, b;
	int i;

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

	if(a > b){
		for(i=0; i<a; i++){
			printf("%d", b);
		}
	}else{
		for(i=0; i<b; i++){
			printf("%d", a);
		}
	}

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> vp[n];
    int u, v, w;
    for(int i = 1; i < n; i++){
        cin >> u >> v >> w;
        w %= 2;
        u--, v--;
        vp[u].push_back({v,w});
        vp[v].push_back({u,w});
    }
    vector<bool> visit(n, 0);
    queue<pair<int,int>> q;
    for(int i = 0; i < n; i++){
        if(vp[i].size() == 1){
            q.push({i, 0});
            break;
        }
    }
    vector<int> ans(n);
    while(!q.empty()){
        auto p = q.front(); q.pop();
        int i = p.first, col = p.second;
        if(visit[i])    continue;
        visit[i] = true;
        ans[i] = col;
        for(pair<int,int> pp : vp[i]){
            int j = pp.first, ww = pp.second;
            if(visit[j])    continue;
            int ncol = (ww == 1 ? 1-col : col);
            q.push({j, ncol});
        }
    }
    for(int i = 0; i < n; i++)  cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 6784
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
int main()
{
	int A, B, C, D = 0;
	cin >> A >> B >> C >> D;

	int Ans = min(A, B) + min(C, D);

	cout << Ans;

	return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
S = list(s())
w = [0]*N
e = [0]*N
for i in range(N):
    if S[i] == 'W':
        w[i] = 1
    if S[i] == 'E':
        e[i] = 1
w = [0]+list(itertools.accumulate(w))
e = [0]+list(itertools.accumulate(e[::-1]))
e.reverse()
ans = 10**9
for i in range(N+1):
    ans = min(ans,w[i]+e[i])
print(ans)


Measured memory_bytes: 41668
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int L = sc.nextInt();
    int R = sc.nextInt();
    int d = sc.nextInt();
    
    int ans = 0;
    for(int i = L; i <= R; i++) {
      if(i % d == 0) ans++;
    }
    System.out.println(ans);
  }
}

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

int main()
{
    int H, W;
    cin >> H >> W;
    string a;
    vector<string> b(H);
    for (int i = 0; i < H; i++)
    {
        cin >> a;
        b.at(i) = a;
    }
    for (int i = 0; i < W + 2; i++)
    {
        cout << '#';
    }
    cout << endl;
    for (int i = 0; i < H; i++)
    {
        cout << '#' + b.at(i) + '#' << endl;
    }
    for (int i = 0; i < W + 2; i++)
    {
        cout << '#';
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int henkan(int x){
	if (x == 1) x = 14;
	return x;
}

int main(){

	int a, b;

	cin >> a >> b;

	a = henkan(a);
	b = henkan(b);

	if (a > b) cout << "Alice" << endl;
	if (a < b) cout << "Bob" << endl;
	if (a == b) cout << "Draw" << endl;



	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
using LL=long long;

LL n,t,sum,maxv;

int main()
{
	scanf("%lld%lld",&n,&t);
	for(LL i=1,tmp;i<=n;i++)
	{
		scanf("%lld",&tmp);
		maxv=max(maxv,tmp);
		sum+=tmp;
		if(sum<t+0.5)
			printf("%lld\n",(LL)((0.5+t-sum)/maxv)+2);
		else
			puts("1");
	}
	return 0;
}


Measured memory_bytes: 2744
s=input()
temp = ''
for i in s:
    temp += i

if(temp[0] == temp[1] and temp[2] == temp[3] and temp[0] != temp[2]):
    print('Yes')
elif(temp[0] == temp[2] and temp[1] == temp[3] and temp[0] != temp[1]):
    print('Yes')
elif(temp[0] == temp[3] and temp[1] == temp[2] and temp[0] != temp[1]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<string>
#include<stack>
#include<algorithm>

using namespace std;


bool check(string str,int P,int Q,int R){
	for(int i=0;i<str.size();i++){
		if(str[i]=='P')str[i]=P+'0';
		if(str[i]=='Q')str[i]=Q+'0';
		if(str[i]=='R')str[i]=R+'0';
	}
	stack<int> sta[50];
	int rank=0;
	for(int i=0;i<str.size();i++){
		if(str[i]=='-')sta[rank].push(-1);
		if(str[i]=='+')sta[rank].push(-2);
		if(str[i]=='*')sta[rank].push(-3);
		if(str[i]=='(')rank++;
		if(str[i]==')'){
			int c=sta[rank].top(),flag2=0;
			sta[rank].pop();
			while(sta[rank].size()){
				int qd=sta[rank].top();
				sta[rank].pop();
				if(qd==-1)c=2-c;
				if(qd==-2)flag2=1;
				if(qd==-3)flag2=2;
				if(qd>=0){
					if(flag2==1)c=max(c,qd);
					if(flag2==2)c=min(c,qd);
				}
			}
			rank--;
			while(sta[rank].size()){
				int qd=sta[rank].top();
				sta[rank].pop();
				if(qd==-1)c=2-c;
				if(qd==-2)flag2=1;
				if(qd==-3)flag2=2;
				if(qd>=0){
					if(flag2==1)c=max(c,qd);
					if(flag2==2)c=min(c,qd);
				}
			}
			sta[rank].push(c);
		}
		if(str[i]>='0' && str[i]<='2'){
			int c=str[i]-'0',flag2=0;
			while(sta[rank].size()){
				int qd=sta[rank].top();
				sta[rank].pop();
				if(qd==-1)c=2-c;
				if(qd==-2)flag2=1;
				if(qd==-3)flag2=2;
				if(qd>=0){
					if(flag2==1)c=max(c,qd);
					if(flag2==2)c=min(c,qd);
				}
			}
			sta[rank].push(c);
		}
	}
	if(sta[0].top()==2)return true;
	return false;
}

int main(void){
	while(1){
		string str;
		cin >> str;
		if(str==".")break;
		int cnt=0;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<3;k++){
					if(check(str,i,j,k))cnt++;
				}
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1232
import numpy as np

N, M, C = map(int, input().split())
B_list = list(map(int, input().split())) 
A_list = [list(map(int, input().split())) for i in range(N)]

cnt = 0
for i in range(N):
    judge = sum(np.array(B_list) * np.array(A_list[i])) + C
    if judge > 0:
        cnt += 1
print(cnt)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
const ll MOD = (1E+9)+7;

const ll MAX = 1000000;
vll fac(MAX), finv(MAX), inv(MAX);

void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  FOR(i, 2, MAX){
    fac[i] = fac[i-1]*i%MOD;
    inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i] = finv[i-1]*inv[i]%MOD;
  }
}


ll COM(ll n, ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll comb(ll a, ll b){
  if(a<b) return 0;
  b = min(b, a-b);
  ll tmp=1;
  REP(i, b){
    tmp *= ((a-i)%MOD);
    tmp /= (i+1);
  }
  return tmp;
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  cin >> N >> M;

  ll K = (ll)(sqrt((long double)M)+EPS);
  vll primes(0);
  FOR(i, 2, K+1){
    ll tmp=0;
    while(M%i==0){
      tmp++;
      M /= i;
    }
    if(tmp>0){
      primes.push_back(tmp);
    }
  }
  if(M>1){
    primes.push_back(1);
  }

  COMinit();

  ll ans=1;
  REP(i, primes.size()){
    //ans *= comb(primes[i]+N-1, N-1);
    ans *= COM(primes[i]+N-1, N-1);
    ans %= MOD;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 23680
from sys import stdin, stdout
import math
import bisect
import queue
from collections import defaultdict

n = int(stdin.readline().strip())
d1 = defaultdict(int)
d2 = defaultdict(int)
arr = list(map(int,stdin.readline().strip().split()))

cur = 1
ans = 0

for each in arr:
    d1[each + cur] += 1
    d2[cur - each] += 1
    cur += 1

for key, value in d1.items():
    ans += d2[key]*value

stdout.writelines(str(ans) + '\n')


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

using namespace std;

#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)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int ans = 0;
    cin >> n;
    vector<int> b(n - 1);
    rep (i, n - 1) {
        cin >> b[i];
    }
    ans += b[0] + b[n - 2];
    rep (i, n - 2) {
        ans += min(b[i], b[i + 1]);
    }
    cout << ans << endl;
    
    return 0;
}



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

using namespace std;
typedef vector<string> vs;

void cat( vs &arr, int i, int j ) {
  int cur = i;
  while( 1 ) {
    if( ++cur >= arr.size() ) {
      break;
    }
    if( j > arr[ cur ].length() ) {
      break;
    }
    if( arr[ cur ][ j ] == '+' ) {
      for( int k = i + 1; k < cur; k++ ) {
        arr[ k ][ j ] = '|';
      }
      break;
    }
    if( arr[ cur ][ j ] != '.' &&
        arr[ cur ][ j ] != '|' &&
        arr[ cur ][ j ] != ' ' &&
        arr[ cur ][ j ] != '+' ) {
      break;
    }
  }
}

int main() {
  while( 1 ) {
    int n;
    cin >> n;
    if( !n ) { break; }
    vs arr;
    for( int i = 0; i < n; i++ ) {
      string line;
      cin >> line;
      for( int j = 0; j < line.length(); j++ ) {
        if( line[ j ] != '.' ) {
          if( j != 0 ) {
            line[ j - 1 ] = '+';
          }
          arr.push_back( line );
          break;
        }
      }
    }
    
    for( int i = 0; i < n; i++ ) {
      int j;
      for( j = 0; j < arr[ i ].length(); j++ ) {
        if( arr[ i ][ j ] == '+' ) {
          cat( arr, i, j );
        }
      }

    }

    for( int i = 0; i < n; i++ ) {
      for( int j = 0; j < arr[ i ].length(); j++ ) {
        if( arr[ i ][ j ] == '.' ) {
          arr[ i ][ j ] = ' ';
        }
      }
    }

    for( int i = 0; i < n; i++ ) {
      cout << arr[ i ] << endl;
    }
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1592
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n,m;
    cin>>n>>m;
    V height(n);
    rep(i,n)cin>>height[i];
    VV vec(n);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    ll res=0;
    rep(i,n){
        bool f=true;
        for(auto j:vec[i]){
            if(height[i]<=height[j]){
                f=false;
                break;
            }
        }
        if(f)res++;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 9796
#include <iostream>
#include <algorithm>
#include <fstream>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#define  endl "\n"
using namespace std;

void FastInput() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void OutputFile(){freopen("output.txt","w",stdout);}




int main()
{

   FastInput();
   
   int a,b;
   cin>>a>>b;
   cout<<a*b<<endl;
  
  

   return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	int year;
	cin>>year;
	int front=year/100;
	int back=year%100;

	if(front==0 || front>12){
		if(back>0 && back<=12){
			cout<<"YYMM"<<endl;
		}else{
			cout<<"NA"<<endl;
		}
	}else if(back==0 || back>12){
		cout<<"MMYY"<<endl;
	}else if(front>0 && front<=12 && back>0 && back<=12){
		cout<<"AMBIGUOUS"<<endl;
	}else{
		cout<<"NA"<<endl;
	}

	return 0;
}



Measured memory_bytes: 256
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
cnt = [0] * (10 ** 5)
for i in a:
    if i - 1 >= 0:
        cnt[i - 1] += 1
    cnt[i] += 1
    if i + 1 <= 10 ** 5 - 1:
        cnt[i + 1] += 1
print(max(cnt))



Measured memory_bytes: 16076
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a >= 0 && c >= 0) {
    a = abs(c - a);
  }else {
    a = abs(a - c);
  }
  if(b >= 0 && d >= 0) {
    b = abs(d - b);
  }else {
    b = abs(b - d);
  }

  for(int i = 0; i < b; i++) {
    cout << "U";
  }
  for(int i = 0; i < a; i++) {
    cout << "R";
  }
  for(int i = 0; i < b; i++) {
    cout << "D";
  }
  for(int i = 0; i < a; i++) {
    cout << "L";
  }
  cout << "D";
  for(int i = 0; i <= a; i++) {
    cout << "R";
  }
  for(int i = 0; i <= b; i++) {
    cout << "U";
  }
  cout << "L" << "U";
  for(int i = 0; i <= a; i++) {
    cout << "L";
  }
  for(int i = 0; i <= b; i++) {
    cout << "D";
  }
  cout << "R";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define UM unordered_map
#define MP map
#define ST set
#define US unordered_set
#define V vector
#define S string
#define D deque
#define L list
#define Q queue
#define PQ priority_queue
#define D deque
#define PII pair<int, int>
#define P pair
#define DB double
#define LDB long double
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define FFOR(i, n) for (int i = 0; i <= (n); ++i)
#define RFOR(i, n) for (int i = (n)-1; i >= 0; --i)
#define all(grid) (grid).begin(), (grid).end()
#define rall(grid) (grid).rbegin(), (grid).rend()

const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

template <typename T>
void read(T& a) {
  a = 0;
  char c;
  while ((c = cin.peek()) < 48 or c > 57) cin.get();
  while ((c = cin.get()) > 47 and c < 58) a = (a << 3) + (a << 1) + c - 48;
}

template <typename T, typename... Args>
void read(T& a, Args&&... args) {
  read(a);
  read(forward<Args>(args...)...);
}

template <typename T>
void write(const S& sep, const S& end, T n) {
  char c[128] = {0};
  int i = 0;
  for (; n; ++i, n /= 10) c[i] = n % 10;

  for (--i; i >= 0; --i) cout.put(c[i] + 48);

  cout.write(end.c_str(), end.size() * sizeof(char));
}

template <typename T, typename... Args>
void write(const S& sep, const S& end, T n, Args&&... args) {
  char c[128] = {0};
  int i = 0;
  for (; n; ++i, n /= 10) c[i] = n % 10;

  for (--i; i >= 0; --i) cout.put(c[i] + 48);

  cout.write(sep.c_str(), sep.size() * sizeof(char));
  write(sep, end, forward<Args>(args...)...);
}

void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  V<PII> a(n), b(m);
  ST<PII> s;
  FOR(i, n) a[i].second = i;
  FOR(i, m) b[i].second = i;
  FOR(i, q) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    ++a[x].first, ++b[y].first;
    s.emplace(x, y);
  }
  sort(all(a)), sort(all(b));
  int a_max = a.back().first, b_max = b.back().first;
  for (int i = n - 1; i >= 0 and a[i].first == a_max; --i) {
    for (int j = m - 1; j >= 0 and b[j].first == b_max; --j) {
      // cout << i << " " << j << endl;
      if (!s.count({a[i].second, b[j].second})) {
        cout << a_max + b_max;
        return;
      }
    }
  }
  cout << a_max + b_max - 1;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}


Measured memory_bytes: 21944
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

int fac[N], inv[N];
int get(int lx , int ly , int rx , int ry){
  int X = rx - lx , Y = ry - ly ;
  if(X < 0 || Y < 0) return 0; 
  int t =  (fac[X + Y] * inv[X]) % mod ;
  t = (t * inv[Y]) % mod ;
  return t ;
}
void solve()
{
  
  int h , w , a , b , ans = 0 ;
  cin >> h >> w >> a >> b ;
  fac[0] = 1; 
  for(int i = 1 ; i < N ; ++i) fac[i] = (i * fac[i-1]) % mod;
  inv[N-1] = po(fac[N-1] , mod - 2 , mod) ;
  for(int i = N - 2 ; i >= 0 ; --i) inv[i] = ((i + 1) *  inv[i + 1]) % mod ; 
  for(int j = b + 1 ; j <= w ; ++j){
    int t2 = get(1 , 1 , h - a , j) ;
    int t = (t2 * get(h - a + 1 , j , h , w)) % mod ;
    ans = (ans + t) % mod ;
  }
  cout << ans;

}   

     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
   // cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


Measured memory_bytes: 8304
/*
#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unrolong long-loops")
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
#define F first
#define S second
using namespace std;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s,k;
    cin>>s>>k;
    int a,b;
    cin>>a>>b;
    string h;
    cin>>h;
    if(h==s)a--;
    else if(h==k)b--;
    cout<<a<<' ' <<b;
    return 0;
}
/*
 1 - u
 2 - d
 3 - r
 4 - l
 
 
 9
 0 1 0 2
 1
 0 2 0 3 2
 0 3 0 4 3
 0 4 1 0 4
 1 0 1 1 5
 1 1 1 2 6
 1 2 1 3 7
 1 3 1 4 8
 1 4 2 0 9
 */


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main()
{
   int x,y,i, m,n ;
   scanf("%d", &x);
   scanf("%d", &y);

   for(i=0; i<= x || i<=y; i++ )
   {
       m= fabs(x-i);
       n= fabs(y-i);
       if(m==n)
        break;
   }
   if(m==n)
    printf("%d", i);
   else
    printf("IMPOSSIBLE");
    
    return 0;
}


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

#define MAX_N (100000)
#define MAX_M (100000)

int main(int argc, char *argv[]) {
  long N, M, n, m;
  char S[MAX_N + 2], T[MAX_N + 2];
  long len;
  scanf("%ld %ld", &N, &M);
  scanf("%s", S);
  S[N] = '\0';
  scanf("%s", T);
  T[M] = '\0';

  for (long i = N; i <= M*N; i += N) {
    if (i % M == 0) {
      len = i;
      n = i / N;
      m = i / M;
      break;
    }
  }

  int possible = 1;
  for (int i = 0; i < N; i++) {
    long index_S = i * n + 1;
    if ((index_S - 1) % m == 0) {
      int j = (index_S - 1) / m;
      if (j >= 0 && j < M && S[i] != T[j]) {
        possible = 0;
        break;
      }
    }
  }
  for (int j = 0; j < M; j++) {
    long index_T = j * m + 1;
    if ((index_T - 1) % n == 0) {
      int i = (index_T - 1) / n;
      if (i >= 0 && i < N && S[i] != T[j]) {
        possible = 0;
        break;
      }
    }
  }

  if (possible)
    printf("%ld\n", len);
  else
    printf("-1\n");
  
  return 0;
}


Measured memory_bytes: 384
/*
    Problem 73
    https://atcoder.jp/contests/abc145/tasks/abc145_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;

/* struct for mod Calculation*/
struct mint {
        ll x;
        mint(ll x = 0):x((x % mod + mod) % mod) {}
        mint operator-() const { return mint(-x); }
        mint& operator+=(const mint a) {
            if ((x += a.x) >= mod) x -= mod;
            return *this;
        }
        mint& operator-=(const mint a) {
            if ((x += mod - a.x) >= mod) x -= mod;
            return *this;
        }
        mint& operator*=(const mint a) {
            (x *= a.x) %= mod;
            return *this;
        }
        mint operator+(const mint a) const {
            mint res(*this);
            return res += a;
        }
        mint operator-(const mint a) const {
            mint res(*this);
            return res -= a;
        }
        mint operator*(const mint a) const {
            mint res(*this);
            return res *= a;
        }
        mint pow(ll t) const {
            if (!t) return 1;
            mint a = pow(t >> 1);
            a *= a;
            if (t & 1) a *= *this;
            return a;
        }
        // for prime mod
        mint inv() const {
            return pow(mod - 2);
        }
        mint& operator/=(const mint a) {
            return (*this) *= a.inv();
        }
        mint operator/(const mint a) const {
            mint res(*this);
            return res /= a;
        }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
        // vector size : n + 1
        vector<mint> fact, ifact;
        // precaliculation O(n)
        combination(int n):fact(n+1), ifact(n+1) {
            assert(n < mod);
            // 0! = 1;
            fact[0] = 1;
            // 1! = 0! * 1 ... n! = (n-1)! * n
            for (int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
            // 1/n! = n!^(-1)
            ifact[n] = fact[n].inv();
            // (n-1)!^(-1) = n!^(-1) * n ... 0!^(-1) = 1!^(-1) * 1
            for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i] * i;
        }
        // combination O(1)
        // nCk = n! / (k! * (n-k)!)
        //     = n! * k!^(-1) * (n-k)!^(-1)
        mint operator()(int n, int k) {
            if (k < 0 || k > n) return 0;
            return fact[n] * ifact[k] * ifact[n-k];
        }
};
/* global variables */
/* function */
/* main */
int main(){
    int X, Y;
    cin >> X >> Y;
    // 2n + m = X
    // n + 2m = Y
    // => (n, m) = {(2Y-X)/3, (2X-Y)/3}
    int dn = 2*Y - X;
    int dm = 2*X - Y;
    if (dn<0 || dm<0 || (dn%3) != 0 || (dm%3) != 0){
        cout << 0 << '\n';
        return 0;
    }
    int n = dn/3, m = dm/3;
    combination c = combination(m+n);
    cout << c.fact[m+n] * c.ifact[n] * c.ifact[m] << '\n';
}

Measured memory_bytes: 13804
#include<bits/stdc++.h>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<queue>
using namespace std;
#define  max 200

int main()
{
    int64_t a,b,t;
    int64_t aa,bb;
    cin>>a>>aa>>b>>bb>>t;
    int64_t zbc=b-a,bsc=aa-bb;
    if(zbc<0)
        zbc=-zbc;
    if(bsc<=0)
    {
        cout<<"NO";
        return 0;
    }
    int64_t numT=zbc/bsc;
    if(zbc%bsc!=0)
        numT++;
    if(numT<=t)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
int a[100005];
rep(i,0,n-1)cin>>a[i];
sort(a,a+n);
pii p[100005];
rep(i,0,n-2)p[i]=mp(min(a[i],a[n-1]-a[i]),a[i]);
sort(p,p+n-1);
o2(a[n-1],p[n-2].ss);
return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, Y;

int main(void){
    
    scanf("%d %d", &N, &Y);
    
    for(int i = 0; i <= N; ++i){
        for(int j = 0; i + j <= N; ++j){
            int k = (Y - (i * 10000 + j * 5000)) / 1000;
            if(i + j + k == N && 10000 * i + 5000 * j + 1000 * k == Y){ printf("%d %d %d\n", i, j, k); return 0; }
        }
    }
	printf("-1 -1 -1\n");
	
    return 0;
}


Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val N = nextInt()
    val S = Array<String>(N) {""}
    repeat(N) {
        S[it] = next().toCharArray().sorted().joinToString(separator = "")
    }
    val A = S.groupBy{ it }.map{ Pair(it.key, it.value.size) }
    var ans = 0L
    A.forEach { ans += ((it.second.toLong() * (it.second.toLong() - 1)) / 2) }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())


Measured memory_bytes: 79480