akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0)
        cout << "Even" << endl;
    else
        cout << "Odd" << endl;
    return 0;
}

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

using namespace std;

int main(void){

    int c[3][3];
    
    for(int x=0; x<3; x++) {
        for(int y=0; y<3; y++) {
            cin >> c[x][y];
        }
    }

    int a1 = 0;
    int b1 = c[0][0] - a1;
    int b2 = c[0][1] - a1;
    int b3 = c[0][2] - a1;
    
    int a2 = c[1][0] - b1;
    int a3 = c[2][0] - b1;
    
//    cout << a1 << " " << a2 << " " << a3 << " " << b1 << " " << b2 << " " << b3 << endl;
    

    if(a1+b1==c[0][0] && a2+b1 == c[1][0] && a3+b1 == c[2][0] &&
       a1+b2==c[0][1] && a2+b2 == c[1][1] && a3+b2 == c[2][1] &&
       a1+b3==c[0][2] && a2+b3 == c[1][2] && a3+b3 == c[2][2]) {
        cout << "Yes" << endl;       
    } 
    else {
        cout << "No" << endl;
    }
    return 0;
    
}


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

int main(){
  long long int a, b, ans = 0;
  cin >> a >> b;
  if(a % 2 == 0){
    if(b % 2 == 0) ans = b + ((b-a)/2) % 2;
    else ans = ((b-a+1)/2) % 2;
  }
  else{
    if(b % 2 == 1) ans = a - ((b-a)/2) % 2;
    else{
      long long int s;
      a++;
      s = b + ((b-a)/2) % 2;
      a--;
      for(int i = 100; i >= 0; --i){
        if((b+1) < pow(2, i)) continue;
        long long int z = pow(2, i);
        if((a/z + s/z) % 2 == 1) ans += z;
        if(a / z == 1) a -= z;
        if(s / z == 1) s -= z;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <stack>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)
template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
vector<string> split(const string &s, char c);
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
    int w,h;
    cin >> h >> w;
    char state[h][w];
    rep(i,h)rep(j,w){
        cin >> state[i][j];
    }

    int ans[h][w];
    fill_n(*ans, w*h, 0);
    rep(y,h)rep(x,w){
        if(state[y][x] != '#')continue;
        for(int i = -1; i <= 1; i++){
            for(int j = -1; j <= 1; j++){
                int nowx = x + j;
                int nowy = y + i;
                if(nowx == -1 || nowx == w || nowy == -1 || nowy == h)continue;
                ans[nowy][nowx]++;
            }
        }
    }

    rep(y,h){
        rep(x,w){
            if(state[y][x]=='#')cout << '#';
            else cout << ans[y][x];
        }cout << endl;
    }
    return 0;
}

int StrToInt(string s){
    stringstream ss;
    ss << s;
    int val;
    ss >> val;
    return val;
}
string IntToStr(int i){
    stringstream ss;
    ss << i;
    return ss.str();
}

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (int i = 0; i < s.size(); i++) {
        char ch = s[i];
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <list>
using namespace std;
#include <stdio.h>
#include <map> 
#include <algorithm>
#include <functional>
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <cstdio>
#include <cinttypes>


int main()
{
	int N;
	cin >> N;
	std::vector<int> table;
	table.resize(N);

	for (int i = 0; i < N; ++i) {
		char c;
		cin >> c;
		if (c == 'W') {
			table[i] = 1;
		}
	}
	//r = 0
	//w = 1
	int r = 0;
	int last = N-1;
	for (int i = 0; i < N; ++i) {
		if (table[i] == 0) {
			continue;
		}
		bool b = false;
		for (int j = last; i < j; --j) {
			if (table[j] == 0) {
				table[j] = 1;
				table[i] = 0;
				b = true;
				last = j;
				++r;
				break;
			}
		}
		if (b) {
			continue;
		}

		break;
	}

	printf("%d\n", r);
	return 0;
}





Measured memory_bytes: 3608
import collections 
n,k=map(int,input().split())
p=[str(input()) for _ in range(n)]
for i in range(n):
    p[i]=p[i][0:1]
#print(p)
c=collections.Counter(p)
#print(c)
a=[]
for v in c.values():
    a.append(v)
#print(a)
a.sort(reverse=True)
ans=0


#print(a)
while True:
    a.sort(reverse=True)
    if k<=len(a):
        ans+=1
        for i in range(k):
            a[i]-=1
        for i in range(k-1,-1,-1):
            #print(a[i])
            if a[i]==0:
                a.pop(i)
        #print(a)
    else:
        break

print(ans)


Measured memory_bytes: 4084
#include<bits/stdc++.h>
#define ll long long
#define N 90000000
using namespace  std;
int arr[30][30];
bool issq(int a,int b,int d){
     ll temp = 0;
      for(int i=0;i<d;i++){
         temp += (arr[a][i] - arr[b][i])*(arr[a][i] - arr[b][i]);
      }

      int u = sqrt((double)temp);
     // cout<<u*u<<" "<<temp<<endl;
      if(u*u == temp){return true;}
      else return false;
}


int main(){
    int n,d;
    cin>>n>>d;
    for(int i=0;i<n;i++)
        for(int j=0;j<d;j++)
            cin>>arr[i][j];
        ll cnt  = 0;
     for(int i=0;i<n-1;i++){
         for(int j=i+1;j<n;j++){
            if(issq(i,j,d))cnt++;
         }
     }

    cout<<cnt<<endl;

return 0;
}


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

int main(){
string a,b;
 cin>>a>>b;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
if(a<b){
  cout<<"Yes"<<endl;
}
  else{
  cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int n, min=1000001, max=-1000001, i, j;
    long long sum=0;
    scanf("%d", &n);
    for (i =0; i < n; i++) {
        scanf("%d", &j);
        if (min > j) min=j;
        if (max < j) max=j;
        sum+=j;
    }
    printf("%d %d %lld\n", min, max, sum);
}



Measured memory_bytes: 2076
n,x=map(int,input().split())
#ls=[0]+[int(x) for i in input().split()]
ls=list(map(int,input().split()))

#d=[]
#d.append(0)
ans=0
d=0
for i in ls:
	d=d+i
	if d>x:
		break
	ans +=1
	
print(ans+1)

Measured memory_bytes: 2940
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();

    let ans = if a <= 5 {
        0
    } else if a <= 12 {
        b / 2
    } else {
        b
    };

    return ans.to_string();
}


Measured memory_bytes: 2136
import java.util.Scanner;
import java.util.Arrays;
public class Main { 
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
      	int N = reader.nextInt();
      	int K = reader.nextInt();
      	int[] h = new int[N];
      	for (int i = 0; i < N;i++) {
        	h[i] = reader.nextInt();
        }
      Arrays.sort(h);
      int min = h[N-1] - h[0];
      for (int i = 0; i < N - K + 1;i++) {
        	int gap = h[i + K -1] - h[i];
        	if (min > gap) {
            	min = gap;
            }
        }
      
      System.out.print(min);
      
      
		
    }
}

Measured memory_bytes: 49288
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 

vector<bool> seen;
void dfs(const VVI &G, int v) {
    seen[v] = true; 

    for (auto nv : G[v]) { 
        if (seen[nv]) continue; 
        dfs(G, nv); 
    }
}

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

int N, M; cin >> N >> M;
VVI G(N+1);
seen.assign(N+1, false);
rep(i, 0, M){
    int x, y, z; cin >> x >> y >>  z;
    G[x].push_back(y);
    G[y].push_back(x);
}

int magic = 0;
rep(i, 1, N+1){
    if (seen[i]) continue;
    ++magic;
    dfs(G, i);
}
cout << magic << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 10368
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (unfoldr)

main :: IO ()
main = do
  let
    primeFactors :: Int -> [(Int, Int)]
    primeFactors n = filter ((/= 0) . snd) . unfoldr next $ Just (n, 2, 0)
      where
        next (Just (m, d, c)) | m < d     = Just ((d, c), Nothing)
                              | r == 0    = next (Just (m', d, succ c))
                              | m < d ^ 2 = Just ((d, c), Just (m, m, 0))
                              | otherwise = Just ((d, c), Just (m, succ d, 0))
          where
            (m', r) = m `divMod` d
        next _                            = Nothing
    f :: Int -> Int
    f m = head . dropWhile ((2 * m <) . ((*) <$> id <*> succ)) $ [8, 7..0] :: Int
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  print . sum . map (f . snd) . primeFactors $ n

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

int main()
{
  long long n;
  cin >> n;
  vector<long long> l(n);
  for(auto& i : l) cin >> i;
  
  sort(l.begin(), l.end(), greater<long long>());
  long long ans = 0;
  for(int x = 0; x < n - 2; ++x)
  {
    for(int y = x + 1; y < n - 1; ++y)
    {
      for(int z = y + 1; z < n; ++z)
      {
        if(l[x] < l[y] + l[z]) ++ans;
        else break;
      }
      if(l[x] >= l[y] * 2) break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    int t, h, s, max = 2*60*60;
    while (scanf("%d %d %d", &t, &h, &s) && t != -1) {
        int ss = max - (s + h*60 + t*60*60);
        printf("%02d:%02d:%02d\n", ss/60/60, ss/60%60, ss%60);
        ss *= 3;
        printf("%02d:%02d:%02d\n", ss/60/60, ss/60%60, ss%60);
    }

    return 0;
}

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

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef long long ll;

#define maxn 200000

int a[maxn],b[maxn],c[maxn],d[maxn];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n; cin >> n;
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];

  int ans = 0;

  rep(k,29){ // k bit目
    ll tmp = 0; // k bit目が1の数
    ll t = 1ll << k;
    rep(i,n){
      c[i] = a[i] % (2 * t);
      d[i] = b[i] % (2 * t);
    }
    sort(d, d + n);
    rep(i,n){ // a_i
      tmp += lower_bound(d,d+n,2*t-c[i]) - lower_bound(d,d+n,t-c[i]);
      tmp += lower_bound(d,d+n,4*t-c[i]) - lower_bound(d,d+n,3*t-c[i]);
    }
    if(tmp % 2 == 1) ans += t;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int dig=n%10;
  if(dig==2||dig==4||dig==5||dig==7||dig==9)
    cout<<"hon\n";
  else if(dig==0||dig==1||dig==6||dig==8)
    cout<<"pon\n";
  else
    cout<<"bon\n";
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long

using namespace std;

void nxt(string &s) {
    for (int i = s.size() - 1; i >= 0; --i) {
        if (i == 0 && s[i] == '9') {
            string s1 = "1";
            for (int j = 0; j < s.size(); ++j) s1 += "0";
            s = s1;
            return;
        }
        else if (i == 0) {
                //cout << s << endl;
            s[i] = s[i] + 1;
        //cout << s << endl;
            for (int j = i + 1; j < s.size(); ++j) {
                s[j] = max(48, s[j - 1] - 1);
            }
            return;
        }
        else if ((abs(s[i - 1] - s[i] - 1) <= 1) && s[i] != '9') {
            s[i] = s[i] + 1;
            for (int j = i + 1; j < s.size(); ++j) {
                s[j] = max(48, s[j - 1] - 1);
            }
            return;
            return;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    string s = "1";
    for (int i = 1; i < n; ++i) {
        nxt(s);
        //cout << s;
    }
    cout << s;
    return 0;
}


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

int main()
{
int n;
cin >> n;
int R[n];
int i,j,minn,rieki=-999999999;
for(i=0;i<n;i++)cin >> R[i];
minn = R[0];
for(i=1;i<n;i++)
{
rieki= max(rieki,R[i]-minn);
minn = min(minn,R[i]);
}
cout << rieki << endl;
return 0;
}


Measured memory_bytes: 3884
ARGF.each_line do |line|
  h, w = line.split.map(&:to_i)
  break if [h, w].eql? [0, 0]
  1.upto(h) { |i|
    if i.odd?
      w.times{|n| print n.odd? ? "." : "#"}
      puts
    else
      w.times{|n| print n.odd? ? "#" : "."}
      puts
    end
  }
  puts
end

Measured memory_bytes: 6104
import java.util.*;
public class Main {
	Scanner sc;
	String[] type ={"A", "B", "AB", "O"};
	
	void run() {
		sc = new Scanner(System.in);
		HashMap<String,Integer> map = new HashMap<String, Integer>();
		while (sc.hasNext()) {
			String str = sc.next().split(",")[1];
			if(map.containsKey(str)) map.put(str, map.get(str)+1);
			else map.put(str, 1);
		}
		for(int i=0;i<4;i++) {
			if(map.containsKey(type[i]) )System.out.println(map.get(type[i]));
			else System.out.println(0);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
	
}

Measured memory_bytes: 12000
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))


n, m = map(int, input().split())
con = []
for i in range(n):
    k = [int(x) for x in input().split()]
    for j in range(1, k[0]+1):
        con.append(k[j])
ans = 0
for i in range(m):
    if con.count(i+1) == n:
        ans += 1
print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

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

        String S = sc.next();
        sc.close();
        boolean judge = false;

        if(S.charAt(0) != 'A')
            System.out.println("WA");
        else{
            if((S.charAt(1) >= 'A' && S.charAt(1) <= 'Z') || (S.charAt(S.length() - 1) >= 'A' && S.charAt(S.length() - 1) <= 'Z')){
                System.out.println("WA");
                return;
            }
            for(int i = 2; i < S.length() - 1; i++){
                if(S.charAt(i) == 'C'){
                    if(judge){
                        System.out.println("WA");
                        return;
                    }
                    else
                        judge = true;
                }
            }
            if(judge)
                System.out.println("AC");
            else
                System.out.println("WA");
        }
    }
}


Measured memory_bytes: 23764
n,x,m=map(int,input().split())

a=list(map(int,input().split()))
ans1=0
ans2=0
for i in range(m,n+1):
    #print(i)
    if i in a:
        ans1+=1
for i in range(0,m+1):
    if i in a:
        ans2+=1
#print(ans1,ans2)
print(min(ans1,ans2))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
	int n,d;
    cin>>n>>d;
    cout<<(n+2*d)/(2*d+1)<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = 10**10
rightW = s.count('W')
rightE = len(s) - rightW
leftW = 0
leftE = 0

for i in range(len(s)):
    if s[i] == 'W':
        rightW -= 1
    else:
        rightE -= 1

    if i > 0:
        if s[i-1] == 'W':
            leftW += 1
        else:
            leftE += 1
    ans = min(ans, rightE + leftW)

print(ans)

Measured memory_bytes: 42584
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
	int a, b;
	cin >> a >> b;

	vector<int> h(999);

	h[0] = 1;
	for(int i = 1; i < 999; i++){
		h[i] = h[i - 1] + i + 1;
	}

	for(int i = 0; i < 998; i++){
		int diff = h[i + 1] - h[i];
		if(diff == b - a){
			cout << h[i + 1] - b << endl;
			return 0;
		}
	}


}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
typedef long long ll;
using namespace std;
int main(){
	string s;
	cin >> s;
	int n = s.size();
	//下の桁から見て,それが最下位の桁となる連続文字列を考えれば良い.
	ll ans = 0;

	vector<int> digit_mod(n+1);

	digit_mod[0] = 1;
	digit_mod[1] = 1;
	for(int i = 1;i < n;i++){
		digit_mod[i+1] = digit_mod[i] * 10 % 2019;
	}

	vector<int> digit_mod_sum(n+1);
	map<int,int> mp;
	digit_mod_sum[0] = 0;
	reverse(s.begin(),s.end());
	for(int i = 1;i <= n;i++){
		int now = (int)(s[i-1] - '0'); 
		digit_mod_sum[i] = (now * digit_mod[i] + digit_mod_sum[i-1]) % 2019;
		ans += mp[digit_mod_sum[i]];
		if(digit_mod_sum[i] == 0)ans += 1;
		mp[digit_mod_sum[i]]++;
	}

	cout << ans << endl;
}




Measured memory_bytes: 5112
import numpy as np
from copy import copy

def red(l, r, prefix):
    for index, i in enumerate(r):
        i = int(i)
        if i:
            if prefix == 0:
                l[index] = 'r'
            else:
                l[:, index] = 'r'

    return l

def main():
    h, w, k = map(int, input().split())
    cnt = 0
    list_ = []
    box = []
    for _ in range(h):
        l = list(input())
        list_.append(l)
    list_ = np.array(list_)
    x = copy(list_)
    for i in range(2**h):
        x1 = copy(x)

        r = format(i, f'0{h}b')
        x1 = red(x1, r, 0)
        for j in range(2**w):
            x2 = copy(x1)
            r = format(j, f'0{w}b')
            x2 = red(x2, r, 1)
            if np.count_nonzero(x2 == '#') == k:
                cnt += 1

    print(cnt)

if __name__ == "__main__":
    main()


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

int N, M, P, Q, R;

int sign(int x) {
  if (x >= 0) return 1;
  else        return -1;
}

void div(vector<int> &s, int x, int y, vector<int> &a, vector<int> &b, vector<int> &c) {
  int i = 0, h = 0;
  for (; i<s.size(); i++) {
    h += abs(s[i]);
    if (h >= x) {
      int fa = x - (h-abs(s[i])),
          fb = h - x;
      if (fa > 0) a.push_back(sign(s[i]) * fa);
      if (fb > 0) {
        h -= fb;
        s[i] = sign(s[i]) * fb;
      }
      else i++;
      break;
    }
    a.push_back(s[i]);
  }
  for (; i<s.size(); i++) {
    h += abs(s[i]);
    if (h >= y) {
      int fa = y - (h-abs(s[i])),
          fb = h - y;
      if (fa > 0) b.push_back(sign(s[i]) * fa);
      if (fb > 0) {
        h -= fb;
        s[i] = sign(s[i]) * fb;
      }
      else i++;
      break;
    }
    b.push_back(s[i]);
  }
  for (; i<s.size(); i++) {
    c.push_back(s[i]);
  }
}

int main() {
  while (cin >> N) {
    if (N == 0) break;
    cin >> M >> P >> Q >> R;

    vector<int> s;
    s.push_back(R), s.push_back(R-N);

    for (int k=0; k<M; k++) {
      int x, y;
      cin >> x >> y;
      vector<int> a, b, c;
      div(s, x, y, a, b, c);
      s.clear();
      s.insert(s.end(), c.begin(), c.end());
      s.insert(s.end(), b.begin(), b.end());
      s.insert(s.end(), a.begin(), a.end());
    }

    vector<int> a, b, c;
    div(s, P-1, Q, a, b, c);
    int ans = 0;
    for (auto x : b) ans += max(x, 0);
    cout << ans << "\n";
  }
  return 0;
}

Measured memory_bytes: 3184
#include "bits/stdc++.h"

using namespace std;

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

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
inline int xt(int a,int b,int c){
	if(a!=b&&a!=c&&b!=c)
		return 3;
	if(a==b&&a==c)
		return 1;
		else return 2;
}
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int ans=xt(a,b,c);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
num = [int(_) for _ in input().split()]
exp = num[:]
order = sorted(num)
found = False
for i in range(n):
    for j in range(1,n):
        exp[i] = num[j]
        exp[j] = num[i]
        if exp == order:
            print("YES")
            found = True
            break
        exp = num[:]
    if found:
        break

if not found:
    print("NO")

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {
    /**
     * Iterate through each line of input.
     */

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        char[] input = sc.next().toCharArray();

        for(int i=input.length-1; i>=0; i--){
            char[] array = new char[i];
            for(int j=0; j<i; j++){
                array[j] = input[j];
            }
            if(check(array)){
                System.out.println(array.length);
                break;
            }
        }
    }

    boolean check(char[] array){
        int leftNum = array.length / 2;
        int rightNum = array.length - leftNum;

        if(leftNum != rightNum){
            return false;
        } else {
            char[] left = new char[leftNum];
            char[] right = new char[rightNum];
            int count = 0;

            for(int i=0; i<leftNum; i++){
                if(array[i] == array[i+leftNum]){
                    count++;
                }
            }
            if(count == leftNum){
                return true;
            }

            return false;
        }
    }
}


Measured memory_bytes: 22996
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int X;
  cin >> X;
  if (X >= 30)
    cout << "Yes\n";
  else
    cout << "No\n";
}

Measured memory_bytes: 3628
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<dyn Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    let n: i32 = input.trim().parse()?;
    input.clear();

    println!("{}", n + n * n + n * n * n);
    Ok(())
}


Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, a[MAXN];
int main() {
	read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]);
	ll l = 2, r = 2;
	for (int i = n; i >= 1; i--) {
		ll ql = (l - 1) / a[i] + 1, qr = r / a[i];
		if (ql > qr) {
			puts("-1");
			return 0;
		}
		l = ql * a[i], r = (qr + 1) * a[i] - 1;
	}
	printf("%lld %lld\n", l, r);
	return 0;
}

Measured memory_bytes: 640
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;


void main() {
    char[] s = readln.chomp.to!(char[]);
    int k; scan(k);

    foreach (i ; 0 .. s.length.to!int - 1) {
        if (s[i] == 'a') continue;
        int t = 26 - (s[i] - 'a');
        if (t <= k) {
            k -= t;
            s[i] = 'a';
        }
    }

    k %= 26;
    s[$ - 1] = (s[$ - 1] - 'a' + k) % 26 + 'a';

    writeln(s);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 2584
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >>n;
    map<long,int> mp;
    for(int i = 0; i<n; i++){
        long t;
        cin>>t;
        if(mp.find(t)==mp.end())
            mp[t]=1;
        else if(mp[t] == 1)
            mp[t]--;
        else
            mp[t]++;
    }
    int count=0;
    for(auto x:mp)
        count+=x.second;
    cout<<count;
}

Measured memory_bytes: 6528
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }


int solve()
{
    int N, M, L;
    std::cin >> N >> M >> L;
    if (N + M + L >= 22)
        cout << "bust" << endl;
    else
        cout << "win" << endl;


    return 0;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

int main(){
    int N, u, v;
    cin >> N >> u >> v;
    int A[N-1], B[N-1];
    vector<int> edge[N+1];
    rep(i, N-1){
        cin >> A[i] >> B[i];
        edge[A[i]].push_back(B[i]);
        edge[B[i]].push_back(A[i]);
    }
    queue<int> que1, que2;
    int dist1[N+1], dist2[N+1];
    dist1[u] = 0, dist2[v] = 0;
    bool used1[N+1], used2[N+1];
    fill_n(used1, N+1, false);
    fill_n(used2, N+1, false);
    que1.push(u);
    used1[u] = true;
    que2.push(v);
    used2[v] = true;
    while(!que1.empty()){
        int i = que1.front();
        que1.pop();
        rep(j, edge[i].size()){
            int k = edge[i][j];
            if(!used1[k]){
                used1[k] = true;
                dist1[k] = dist1[i]+1;
                que1.push(k);
            }
        }
    }
    while(!que2.empty()){
        int i = que2.front();
        que2.pop();
        rep(j, edge[i].size()){
            int k = edge[i][j];
            if(!used2[k]){
                used2[k] = true;
                dist2[k] = dist2[i]+1;
                que2.push(k);
            }
        }
    }
    int ans = 0;
    rep2(i, 1, N){
        int a = dist1[i], b = dist2[i];
        if(a >= b) continue;
        else{
            if(edge[i].size() >= 2) ans = max(ans, b);
            else ans = max(ans, b-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7680
en='ABCDEFGHIJKLMNOPQRSTUVWXYZ'+' .,-\'?'
de={
'101':' ','000000':'\'','000011':',','10010001':'-','010001':'.','000001':'?',
'100101':'A','10011010':'B','0101':'C','0001':'D','110':'E','01001':'F',
'10011011':'G','010000':'H','0111':'I','10011000':'J','0110':'K','00100':'L',
'10011001':'M','10011110':'N','00101':'O','111':'P','10011111':'Q','1000':'R',
'00110':'S','00111':'T','10011100':'U','10011101':'V','000010':'W','10010010':'X',
'10010011':'Y','10010000':'Z'
}
while 1:
    try:s=input()
    except:break
    a=b=c=''
    for x in s:a+=str(bin(en.index(x)))[2:].zfill(5)
    for x in a:
        b+=x
        if b in de:c+=de[b];b=''
    print(c)

Measured memory_bytes: 7364
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    int diff=abs(a-b);
    diff--;
    if(diff%2==1)
    {
        cout<<"Alice"<<endl;
    }
    else
    {
        cout<<"Borys"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];


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

    int N;
    cin>>N;

    int A[N],B[N];
    int ans=0;
    int c0=0;
    map<pair<int,int>,int> m;
    rep(i,N) {
        cin>>A[i]>>B[i];
        if(B[i]<0){
            A[i]*=-1;
            B[i]*=-1;
        }

        if(A[i]==0&&B[i]==0) c0++;
        else if(B[i]==0) m[make_pair(1,0)]++;
        else if(A[i]==0) m[make_pair(0,1)]++;
        else m[make_pair(A[i]/__gcd(abs(A[i]),B[i]),B[i]/__gcd(abs(A[i]),B[i]))]++;
    }
    
    int sum=1;
    for(auto p:m){
        int de=1;
        int d=1;
        int na=p.first.first;
        int nb=p.first.second;
        int nx=p.second;
        if(nx==0) continue;
        if(na<0 && m[make_pair(nb,-na)]>0)continue;
        if(na==0&&m[make_pair(1,0)]>0) continue;
        
        
        int x=m[make_pair(-nb,na)];
        rep(i,nx){
            d*=2;
            d%=MOD;
        }
        if(x!=0){
            rep(i,x){
                de*=2;
                de%=MOD;
            }
        }
        int w=(d+de-1)%MOD;
        sum=sum*w;
        sum%=MOD;

    }
    ans=(sum+c0-1)%MOD;
    while(ans<0) ans+=MOD;
    cout << ans << endl;
    







}


Measured memory_bytes: 37920
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    FOR(i, 0, n)cin >> a[i].first >> a[i].second;
    rSORT(a, [](auto a, auto b) {return a.second < b.second; });

    int now = 0;
    FOR(i, 0, n) {
        now += a[i].first;
        if (now > a[i].second) {
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
}

Measured memory_bytes: 1792
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m, p = na()

def bf(es, n, start):
    d = [999999999999] * n
    d[start] = 0

    for r in range(n-1):
        updated = False
        for e in es:
            if d[e[0]] == 999999999999:
                continue
            if d[e[0]] + e[2] < d[e[1]]:
                d[e[1]] = d[e[0]] + e[2]
                updated = True
        if not updated:
            break

    for e in es:
        if d[e[0]] < 999999999999 and d[e[0]] + e[2] < d[e[1]]:
            return None

    return d

es = []
for i in range(m):
    a, b, c = na()
    es.append((a-1, b-1, -(c-p)))

import collections
q = collections.deque()
q.append(n-1)

valid = [False] * n
valid[n-1] = True
while len(q) > 0:
    cur = q.popleft()
    for e in es:
        if e[1] == cur and not valid[e[0]]:
            valid[e[0]] = True
            q.append(e[0])

nes = []
for e in es:
    if valid[e[0]] and valid[e[1]]:
        nes.append(e)
es = nes

d = bf(es, n, 0)
if not d:
    print(-1)
else:
    print(max(0, -d[n-1]))

Measured memory_bytes: 44400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll d[4];
vector<ii> dt;
int main(){
  IOS();
  REP (i,4) cin >> d[i];
  ll n;
  cin >> n;
  dt.eb(d[0]*8,0);
  dt.eb(d[1]*4,1);
  dt.eb(d[2]*2,2);
  dt.eb(d[3],3);
  sort(ALL(dt));
  ll ans = (n/2) * dt[0].X;
  debug(ans);
  n %= 2;
  if (dt[0].Y == 0) ans += n*4*d[0];
  else if (dt[0].Y == 1) ans += n*2*d[1];
  else if (dt[0].Y == 2) ans += n*d[2];
  else {
    if (dt[1].Y == 0) ans += n*4*d[0];
    else if (dt[1].Y == 1) ans += n*2*d[1];
    else if (dt[1].Y == 2) ans += n*d[2];
  }
  cout << ans << endl;
}


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

int main() {
    string S, T; cin >> S >> T;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define sb __builtin_popcount
#define MOD (ll)1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;

int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll n;
     cin >> n;
     string s;
     cin >> s;
     set<ll> mprt;
     set<ll> mpgt;
     set<ll> mpbt;
     for (ll i = 0; i < n; i++)
     {
          if (s[i] == 'R')
          {
               mprt.insert(i);
          }
          if (s[i] == 'G')
          {
               mpgt.insert(i);
          }
          if (s[i] == 'B')
          {
               mpbt.insert(i);
          }
     }
     ll sum = 0;
     for (ll i = 0; i < n; i++)
     {
          mprt.erase(i);
          mpgt.erase(i);
          mpbt.erase(i);
          set<ll> mpr = mprt;
          set<ll> mpg = mpgt;
          set<ll> mpb = mpbt;
          for (ll j = i + 1; j < n; j++)
          {
               mpr.erase(j);
               mpg.erase(j);
               mpb.erase(j);
               if (s[i] != s[j])
               {
                    set<char> ba;
                    ba.insert('R');
                    ba.insert('G');
                    ba.insert('B');
                    ba.erase(s[i]);
                    ba.erase(s[j]);
                    if (*ba.begin() == 'R')
                    {
                         if (mpr.count(2 * j - i))
                         {
                              sum += ((ll)mpr.size() - 1);
                         }
                         else
                         {
                              sum += mpr.size();
                         }
                    }
                    else if (*ba.begin() == 'G')
                    {
                         if (mpg.count(2 * j - i))
                         {
                              sum += ((ll)mpg.size() - 1);
                         }
                         else
                         {
                              sum += mpg.size();
                         }
                    }
                    else
                    {
                         if (mpb.count(2 * j - i))
                         {
                              sum += ((ll)mpb.size() - 1);
                         }
                         else
                         {
                              sum += mpb.size();
                         }
                    }
               }
          }
     }
     cout << sum << endl;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
#define mo 998244353
 
using namespace std ;
 
#define MAXN 305 

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

lli dp[1<<22];

int main()
{
///////////////////////////////////////////
    fastio;

    lli n;
    cin>>n;

    dp[0] = 1;

    lli a[n][n];

    loopl(i,0,n)
    {
        loopl(j,0,n)
        cin>>a[i][j];
    }

    for(lli i=1 ; i< (1<<n) ; i++)
    {
        lli x = __builtin_popcount(i);

        loopl(j,0,n)
        {
            if((1<<j)&i)
            {
                lli curr = i^(1<<j) ;

                if(a[x-1][j])
                    dp[i] = (dp[i] + dp[curr])%mod ;
            }
        }

    }

    cout<<dp[(1<<n) - 1]<<endl;



}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

ll k;
ll solve(){
   if(k%2==0)return -1;
   ll ans=1;
   
   ll cur=7;
   int i=0;
   for(;i<1e8;i++){
       if(cur%k==0)break;
       ans++;
       cur%=k;
       cur*=10;
       cur+=7;
   }
   if(i==1e8)return -1;
   return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>k;
    
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 3648
S = input()

avi = False
if len(S) != 7:
    for i in range(len(S)):
        w = S[:i] + S[(i + (len(S) - 7)):]
#        print(w)
        if w == "keyence":
            avi = True
            break
elif S == "keyence":
    avi = True

if avi:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, K, X, Y = [int(input()) for _ in range(4)]

ans = min(N, K) * X

print(min(N, K) * X + (N - min(N, K)) * Y)

Measured memory_bytes: 9472
import math


def solve():
    A, B, H, M = map(int, input().split())
    theta = abs((H+(M/60))*30-M*6)
    x = abs(math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(theta))))
    print(x)


if __name__ == '__main__':
    solve()


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

int insu[1001]={0};

void soinsubunkai(int num){
  int n = 2;
  while(n <= num){
    if(num % n == 0){
      insu[n] +=1;
      num/=n;
    }
    else{
      n++;
    }
  }
}


int main(){

  int N;
  cin >> N;
  for(int i = 0; i < N+1; i++){
    soinsubunkai(i);
  }

  long long ans = 1;
  for(int i = 2; i< N+1; i++){
    if(insu[i] != 0){
      ans *=(insu[i] + 1);
      ans %= 1000000007;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256