akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#include<iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <cstring>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <map>
#include <unordered_map>
#include <vector> 
#include <bitset>
#include <cctype>
#include <set>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#include <random>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN = 200005;
const int MAXM = 20500;
const ll MOD = 1e9+7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template <typename T> inline T min(T a, T b, T c,T d) { return min(min(a, b), min(c,d)); }
template <typename T, typename T1> inline T qpower(T x, T p, T1 mod) { T re = 1; x %= mod; while (p) { if (p & 1)re = (re * x) % mod; x = (x * x) % mod; p >>= 1; }return re; }
#define mst(X,Y) memset(X,Y,sizeof(X)) 
#define rep(i, a, n) for (int i=(a); i<=(n); i++)
#define per(i, a, n) for (int i=(a); i>=(n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H);    debug_out(T...);}


// int solve(int l,int r)
// {
		
// }

ll a[MAXN];
ll sum[MAXN];
int main()
{//closeSync;
#ifdef DEBUG
	//freopen("C:/Users/86159/Desktop/input.txt", "r", stdin);
	//freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
	//clock_t c1 = clock();

	int n;
	cin>>n;
	rep (i,1,n)
		cin>>a[i];
	rep (i,1,n)
		sum[i] = (sum[i-1] + a[i])%MOD;
	ll ans = 0;
	rep (i,1,n-1)
	{// i + 1 -> n
		ans = (ans + a[i] * (sum[n] - sum[i] + MOD) % MOD) % MOD;
	}
	cout<<ans<<endl;
	//cerr << "Time:" << clock() - c1 << "ms" <<endl;
    return 0;
}

Measured memory_bytes: 6712
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
set<ll> st;
ll enum_divisors(long long N) {
    ll a = 1;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) {
            if (st.count(i))
                a = 0;
            if (N / i != i) {
                if (st.count(N / i))
                    a = 0;
            }
        }
    }
    return a;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
map<ll,ll> mp;
vector<ll> a(n);
rep(i,n){
    cin >> a[i];
    st.insert(a[i]);
    mp[a[i]]++;
}
ll ans = 0;
if(mp[1] == 1){
    cout << 1 << endl;
}
if(mp[1] > 2){
    cout << 0 << endl;
}
if(mp[1] == 0) {
    for (auto v : st) {
        if (mp[v] > 1)
            continue;
        ans += enum_divisors(v);
    }
    cout << ans << endl;

}
}


Measured memory_bytes: 26636
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  string S = "0";
  F0R(i, N) {
    char c;
    cin >> c;
    if (c != S.back()) {
      S += c;
    }
  }

  cout << (S.size() - 1);
}
#endif


Measured memory_bytes: 512
package main

import (
	"fmt"
	"sort"
)

func main() {
	arr := scanNums(1)
	N := arr[0]
	As := scanNums(N)
	if N == 0 {
		fmt.Print(0)
		return
	}
	MySort(As)
	max := As[len(As)-1]
	dpTable := make([]int, max+1)
	prev := 0
	for _, el := range As {
		dpTable[el]++
		if prev == el {
			continue
		}
		if dpTable[el] > 1 {
			prev = el
			continue
		}
		for i := 2 * el; i <= max; i += el {
			dpTable[i]++
		}
		prev = el
	}
	count := 0
	for _, el := range As {
		if dpTable[el] == 1 {
			count++
		}
	}
	fmt.Print(count)
}
func MySort(a []int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

}
func Abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}
func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 18736
#include <stdio.h>
#include <string.h>
int main() {
	char s[1001];
	scanf("%s", s);
	int ans;
	char a = s[0], b = s[1], c = s[2];
	if (a == 'R' && b == 'R' && c == 'R'){
		ans = 3;
	} else if (a == 'R' && b == 'R' || b == 'R' && c == 'R') {
		ans = 2;
	} else if (a != 'R' && b != 'R' && c != 'R'){
		ans = 0;
	}else{
		ans = 1;
	}
		printf("%d\n",ans);
	return 0;
}

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

using namespace std;

namespace {

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }

    typedef long long ll;

    int N, M, Q;
    vector<string> S, B;
    bool input() {
        scanf("%d %d %d\n", &N, &M, &Q);
        if (N == 0 && M == 0 && Q == 0) return false;
        B.clear(); B.resize(Q + 1);
        S.clear(); S.resize(Q);
        B[0] = "";
        for (int i = 0; i < M; i++) B[0].push_back('0');
        for (int q = 0; q < Q; q++) {
            cin >> S[q] >> B[q + 1];
        }
        return true;
    }

    void solve() {
        for (int i = 0; i < M; i++) {
            vector<bool> f(N, true);
            for (int j = 0; j < Q; j++) {
                bool x = (B[j + 1][i] == B[j][i]);
                for (int k = 0; k < N; k++) {
                    bool y = (S[j][k] == '0');
                    if (x != y) {
                        f[k] = false;
                    }
                }
            }
            if (count(f.begin(), f.end(), true) == 1) {
                for (int j = 0; j < N; j++) {
                    if (f[j]) {
                        cout << char(j + (j < 10 ? '0' : 'A' - 10));
                    }
                }
            } else {
                cout << '?';
            }
        }
        cout << endl;
    }
}

int main() {
    while (input()) solve();
    return 0;
}

Measured memory_bytes: 2412
X = input()
Tnum = len(X) // 2
Snum = len(X) // 2
num = 0
ans = 0
for i in X:
    if i == 'T':
        num -= 1
        Tnum -= 1
    else:
        num += 1
        Snum -= 1

    if num < 0:
        ans += 1
        num = 0
print(ans*2)

Measured memory_bytes: 3500
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int N; cin >> N;
	vector<long long>a(N),b(N);
	for (int i = 0; i < N; i++) { cin >> a[i]; }
	if (N % 2 == 0) {
		for (int i = 0; i < N / 2; i++) {
			b[i] = a[(N - 1) - 2 * i];
		}
		for (int i = N / 2; i < N; i++) {
			b[i] = a[2 * i-N];
		}
	}
	else {
		for(int i=0;i<=N/2;i++)b[i] = a[(N - 1) - 2 * i];
		for (int i = N / 2+1; i < N; i++) {
			b[i] = a[2 * i - N];
		}
	}
	for (int i = 0; i < N; i++)cout << b[i] << " ";
	
}



Measured memory_bytes: 5248
number = str(input())[::-1]
remainderDictionary = {0: 1}
digitDictionary = {'1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}

sum = 0
x = 1
for i in number:
  x = (x * 10) % 2019
  sum = (sum + digitDictionary[i] * x) % 2019 
  remainderValue = remainderDictionary.get(sum,0) + 1
  remainderDictionary[sum] = remainderValue
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

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

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxn = 3e5+35;
int main(){
    string s; cin >> s;
    cout << (s=="ABC"?"ARC":"ABC");
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define INF 100000000

const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;


int main(void) {
	ll k, tmp;
	cin >> k;
    queue<ll> q;
    for(int i=1;i<10;i++) q.push(i);
    for(int i=0;i<k;i++) {
        tmp = q.front();
        q.pop();
        if(tmp%10!=0) q.push(10*tmp+(tmp%10)-1);
        q.push(10*tmp+(tmp%10));
        if(tmp%10!=9) q.push(10*tmp+(tmp%10)+1);
    }
    cout << tmp << endl;
}


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


int main() {
  Int N, K, Q;
  cin >> N >> K >> Q;
  vector<Int> acs(N,0);
  rep(i,Q) {
    Int A;
    cin >> A;
    A--;
    acs[A]++;
  }
  
  rep(i,N) {
    if (Q-acs[i] < K) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 1408
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;

class Program
{
    static void Main(string[] args)
    {
        var X = long.Parse(Console.ReadLine());
        var syugo = SieveOfEratosthenes(100090).Where(n => n  >= X).Min();
        
        Console.WriteLine(syugo);
      
    }
  
    static List<long> SieveOfEratosthenes(long N){
  var Primes = new List<long>();
  if(N > 0){
    var IsPrime = new bool[N+1];
    for(long i = 0;i <= N ;i++){
      IsPrime[i] = true; 
    }
    //0と1は消しておく
    IsPrime[0] = false;
    IsPrime[1] = false;
    for(long i = 2; i <= (long)Math.Sqrt(N);i++){
      if(IsPrime[i]){
        long j = i*2;
        for(long k = j;k <= N;k+=i){
          IsPrime[k] = false;
        }
      }
    }
    for(long i = 1;i <= N ;i++){
      if(IsPrime[i]){
        Primes.Add(i);
      }
    }
  }
  return Primes;
}

}


Measured memory_bytes: 13536
#include <bits/stdc++.h>
#define rep( i, n ) for( int ( i ) = 0; ( i ) < ( n ); ( i )++ )
#define repr( i, n ) for( int ( i ) = ( n ); ( i ) >= 0; ( i )-- )
#define FOR( i, m, n ) for( int ( i ) = ( m ); ( i ) < ( n ); ( i )++ )
#define all( x ) ( x ).begin(), ( x ).end()
typedef long long lint;
using namespace std;

int main( void ){
	
	lint n, a, b;
	
	cin >> n;
	
	if( n == 1 ){
		cout << "Hello World" << endl;
	}else{
		cin >> a >> b;
		cout << a + b << endl;
	}
	
	return 0;
	
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 8
#define nf -1
#define f 10

int putQueen(int,int [N],int [N+N-1],int [N+N-1],int[N]);
void printBoard(int[N]);

char ban[N][N];
int rr[N];

int main(){
  int k;
  int i,r,c,j;
  int dpos[N+N-1];
  int dneg[N+N-1];
  int col[N];
  int row[N];

  scanf("%d",&k);

  for(i=0;i<N;i++){
    row[i] = f;
    rr[i] = f;
    for(j=0;j<N;j++){
      dpos[i+j] = f;
      dneg[i-j + N-1] = f;
      col[j] = f;
    }
  }

  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    row[r] = c;
    rr[r] = r;
    dpos[r+c] = nf;
    dneg[r-c + N-1] = nf;
    col[c] = nf;
  }

  putQueen(0,col,dpos,dneg,row);
  return 0;
}

int putQueen(int i,int col[N],int dpos[N+N-1],int dneg[N+N-1],int row[N]){
  int j;

  if(i==N){
    printBoard(row);
    return 0;
  }

  if(rr[i] == i){
    putQueen(i+1,col,dpos,dneg,row);
  }

  for(j=0; j<N; j++){
    if(rr[i] == i){
      break;
    }
    if(col[j] == nf || dpos[i+j] == nf || dneg[i-j+N-1] == nf){
      continue;
    }

    row[i] = j;
    col[j] = dpos[i+j]= dneg[i-j+N-1] = nf;
    putQueen(i+1,col,dpos,dneg,row);
    col[j] = dpos[i+j] = dneg[i-j+N-1] = f;
  }
}

void printBoard(int row[N]){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j){
	ban[i][j] = 'Q';
      }
      else
	ban[i][j] = '.';
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      printf("%c",ban[i][j]);
    }
    printf("\n");
  }
 
}



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

using ll = long long;

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

	vector<ll> av(n + 1);
	vector<ll> bv(n);

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

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> bv[i];
		ll m = min(av[i], bv[i]);
		ans += m;
		bv[i] -= m;
		if (bv[i] > 0) {
			ll mn = min(av[i + 1], bv[i]);
			ans += mn;
			av[i + 1] -= mn;
		}

	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
num = []
for i in range(1, N+1):
  if i % 3 == 5 and i % 5 == 0:
    continue
  elif i % 3 == 0:
    continue
  elif i % 5 == 0:
    continue
  num.append(i)
print(sum(num))

Measured memory_bytes: 29992
#include <stdio.h>

int main()
{
  int n;
  int ans = 0;
  
  scanf("%d", &n);
  
  for (int i = 1; i <= n; i += 2) {
    int cnt = 0;
    
    for (int j = 1; j <= n; j++) {
      if (i % j == 0) {
        cnt++;
      }
    }
    
    if (cnt == 8) {
      ans++;
    }
  }
  
  printf("%d\n", ans);
  
  return 0;
  
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  string s;
  cin >> s;
  vector<pair<char, int>> zip;
  for (int i = 0; i < s.size(); i++) {
    if (zip.empty() || zip.back().first != s[i])
      zip.push_back(pair<char, int>(s[i], 1));
    else
      zip.back().second++;
  }
  cout << zip.size() - 1 << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


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


class union_find
{
	int  _setnum;
	vector<int> par, nume, diff_weight;
public:
	union_find(){
	}
	
	union_find(int x){
		par.resize(x);
		nume.resize(x);
		diff_weight.resize(x);
		init();
	}
	
	~union_find(){
		//
		
	}
	
	void clear(){
		_setnum = 0;
		par.clear();
		nume.clear();
		diff_weight.clear();
	}
	
	void init(){
		_setnum = par.size();
		for(int i = 0; i < par.size(); i++){
			par[i] = i;
			nume[i] = 1;
			diff_weight[i] = 0;
		}
	}
	
	void resize(int x){
		
		par.resize(x);
		nume.resize(x);
		diff_weight.resize(x);
		init();
	}

	int find(int x){
		if(par[x] == x) {
				return x;
		} else {
			int p = find(par[x]);
			
			diff_weight[x] += diff_weight[par[x]];
			
			return par[x] = p;
		}
	}
	
	// weight(y) - weight(x) = w
	void unite(int x, int y, int w){
		
		w = -w;
		
		w -= weight(x);
		w += weight(y);
		
		x = find(x);
		y = find(y);
	
		if(x == y)return;
		
		_setnum--;
		
		if(nume[x] > nume[y]) std::swap(x,y), w = -w;
		
		par[x] = y;
		
		nume[y] += nume[x];
		
		diff_weight[x] = w;
	}
	
	int weight(int x){
		find(x);
		
		return diff_weight[x];
	}
	
	// find(x) == find(y)
	int diff(int x, int y){
		return weight(y) - weight(x);
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
	
	int numel(int x){
		return nume[find(x)];
	}
	
	int size(){
		return par.size();
	}
	
	int setnum(){
		return _setnum;
	}
};

signed main(){
	
	int n, q;
	union_find uf;
	
	cin>>n>>q;
	
	uf.resize(n);
	
	for(int i = 0; i < q; i++){
		int num, x, y, z;
		
		cin>>num;
		
		if(num == 0) {
			cin>>x>>y>>z;
			
			uf.unite(x, y, z);
			
		} else if(num == 1) {
			cin>>x>>y;
			
			if(uf.same(x, y)) {
				cout<<uf.diff(x, y)<<endl;
			} else {
				cout<<"?"<<endl;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
long long dp[2][3005][4]={0};
long long mm[3005][3005]={0};
int main()
{
    int r,c,k;
    cin >> r >>c >> k;
    //cout <<1 <<endl;
    int u,v,w;
    for(int i=0;i<k;i++)
    {
        cin >> u >>  v >> w;
        mm[u][v]=w;
    }
    //cout <<1 <<endl;

    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;++j){
            dp[i&1][j][0]=max({dp[(i+1)&1][j][0],dp[(i+1)&1][j][1],dp[(i+1)&1][j][2],dp[(i+1)&1][j][3]});
            dp[i&1][j][1]=max(dp[i&1][j-1][1],max(dp[i&1][j][0],dp[i&1][j-1][0])+mm[i][j]);
            dp[i&1][j][2]=max(dp[i&1][j-1][2],dp[i&1][j-1][1]+mm[i][j]);
            dp[i&1][j][3]=max(dp[i&1][j-1][3],dp[i&1][j-1][2]+mm[i][j]);
        //cout << dp[i&1][j][0] << " "  <<  dp[i&1][j][1] <<" " <<dp[i&1][j][2] << " "<<dp[i&1][j][3] <<endl;
        }
    }
    cout << max({dp[r&1][c][3],dp[r&1][c][2],dp[r&1][c][1],dp[r&1][c][0]}) ;
    return 0;
}


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

int main(){
	int N,T,A;
	cin>>N>>T>>A;
	int H[N];
	for(int i=0;i<N;i++)
		cin>>H[i];
	
	double h[N];//H[i]での気温h[i]
	for(int i=0;i<N;i++)
		h[i]=T-H[i]*0.006;
	
	double s[N];
	for(int i=0;i<N;i++){
		s[i]=h[i]-A;
	}
	
	for(int i=0;i<N;i++){
		if(s[i]<0)
			s[i]=-s[i];
	}
	
	int ans=1;
	double min=s[0];
	for(int i=1;i<N;i++){
		if(min>s[i]){
			min=s[i];
			ans=i+1;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import math
MOD =1000000007


def pow_k(x, n):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
        # print(K,x)
        x%=MOD
    return K * x


n = int(input())

a_b_d = {}

a_zero_cnt = 0
b_zero_cnt = 0
ab_zero_cnt = 0

for i in range(n):
    a, b = map(int, input().split()) 
    if a==0 and b!=0:
        a_zero_cnt += 1
    elif  a!=0 and b==0:
        b_zero_cnt += 1
    elif a == 0 and b == 0:
        ab_zero_cnt += 1
    else:
        gcd_ab = math.gcd(a,b)
        a = a//gcd_ab
        b = b//gcd_ab
        if a > 0 and b < 0:
            a *= -1
            b *= -1
        elif a < 0 and b < 0:
            a *= -1
            b *=-1
        a_b_d.setdefault((a,b),0)
        a_b_d[(a,b)] += 1


done_list = set()
pair_cnt = []
uniq_cnt = 0
for k,v in a_b_d.items():
    comp_pair1 = (-k[1], k[0])
    comp_pair2 = (k[1], -k[0])
    if k in done_list:
        continue
    if comp_pair1 in a_b_d:
        done_list.add(comp_pair1)
        pair_cnt.append((v,a_b_d[comp_pair1]))
    elif comp_pair2 in a_b_d:
        done_list.add(comp_pair2)
        pair_cnt.append((v,a_b_d[comp_pair2]))
    else:
        uniq_cnt += v

# print(a_b_d)

ans = pow_k(2,uniq_cnt) % MOD
for pair in pair_cnt:
    ans *= (pow_k(2,pair[0]) + pow_k(2,pair[1]) -1 )
    ans%=MOD

zero_m = max(pow_k(2,a_zero_cnt) + pow_k(2,b_zero_cnt) -1, 1)
ans *= zero_m
ans += ab_zero_cnt
ans -= 1
print(ans%MOD)

Measured memory_bytes: 49172
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node {
  int key;
  struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

Node * treeMinimum(Node *x) {
  while(x->left != NIL)
    x = x->left;
  return x;
}

Node * find(Node *u, int k) {
  while(u != NIL && k != u->key) {
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x) {
  if(x->right != NIL) return treeMinimum(x->right);
  Node *y = x->parent;
  while(y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node *z) {
  Node *y; // 削除する対象
  Node *x; // yの子

  // 削除する節点を決める
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  // yの子xを決める
  if(y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }

  if(x != NIL) {
    x->parent = y->parent;
  }

  if(y->parent == NIL) {
    root = x;
  } else {
    if(y == y->parent->left) {
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }

  if(y != z) {
    z->key = y->key;
  }
}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;
  
  z = (Node *)malloc(sizeof(Node));
  z->key   = k;
  z->left  = NIL;
  z->right = NIL;
  
  while(x != NIL) {
    y = x;
    if(z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  
  z->parent = y;
  if(y == NIL) {
    root = z;
  } else {
    if( z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
  
int main(void) {
  int n, i, x;
  char com[16];
  scanf("%d",&n);
  
  for(i=0;i<n;i++) {
    scanf("%s",com);
    if(!strcmp(com,"find")) {
      scanf("%d",&x);
      Node *t = find(root,x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    } else if(!strcmp(com,"insert")) {
      scanf("%d",&x);
      insert(x);
    } else if(!strcmp(com,"print")) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if(!strcmp(com,"delete")) {
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }

  return 0;
}


Measured memory_bytes: 20556
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -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;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int n, m;
    cin >> n >> m;

    bool ac[100100] = {false};

    int accnt = 0;
    int pcnt[100100] = {0};

    for(int i = 0; i < m; i++){
        int num;
        string j;
        cin >> num >> j;

        num--;

        if(j == "WA"){
            if(!ac[num]){
                pcnt[num]++;
            }
        } else {
            ac[num] = true;
        }
    }
    int ans1 = 0;
    int ans2 = 0;
    for(int i = 0; i < n; i++){
        if(ac[i]){
            ans1++;
            ans2 += pcnt[i];
        }
    }

    cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 768
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val s = sc.next()
  var ans = s.length
  for (i <- Seq('0', '1')) {
    var cnt = 0
    for (j <- 0 until s.length) {
      if (j % 2 == 0 && s(j) == i) cnt += 1
      if (j % 2 == 1 && s(j) != i) cnt += 1
    }
    ans = ans.min(cnt)
  }
  println(ans)

}

Measured memory_bytes: 55684
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

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

const int INF = 0x7fffffff;
const int maxn = 100;
int n, m, a, b;
int num[maxn];

int main() {
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%d %d", &n, &m);
    while (m--) {
        scanf("%d %d", &a, &b);
        ++num[a]; ++num[b];
    }
    for (int i = 1; i <= n; ++i) { printf("%d\n", num[i]); }
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;

typedef long long ll;

const int maxn = 2e5+1;
int n, m;
int a[maxn];
int cover[maxn];
int ptr[maxn];
int tot;
int x, y;
inline void print()
{
    for (int i = 1; i <= n; ++i)
        printf("%d ", cover[i]);
    puts("");
}
inline void add(int y)
{
    if (ptr[y] > 0)
    {
        cover[ptr[y]] += 1;
        if (cover[ptr[y]] == 1)
            --tot;
    }
    ptr[y] -= 1;
}
inline void revert(int y)
{
    ++ptr[y];
    if (ptr[y] > 0)
    {
        cover[ptr[y]] -= 1;
        if (!cover[ptr[y]])
            ++tot;
    }
}
int main()
{
    scanf("%d %d", &n, &m);
    tot = n;
    memset(cover, 0, (n+1)*sizeof(int));
    for (int i = 1; i <= n; ++i)
        ptr[i] = i;
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d", a+i);
        add(a[i]);
    }
    for (int i = 1; i <= m; ++i)
    {
        scanf("%d %d", &x, &y);
        add(y);
        revert(a[x]);
        a[x] = y;
        printf("%d\n", tot);
    }
}

Measured memory_bytes: 3712
N=int(input())
L=input()
L=L.rstrip().split()
list1=[]
for i in range(2*N):
    list1.append(int(L[i]))
list1.sort()
#print(list1)
ans=0
for j in range(2*N):
    if j%2==0:
        ans+=list1[j]
        
print(ans)

Measured memory_bytes: 3060
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
ans = 0
i = 0
while i < 60:
  mask = 2**i
  n = sum([1 if a&mask > 0 else 0 for a in A])
  ans += n*(N-n)*pow(2, i, mod)
  ans %= mod
  i += 1
print(ans)

Measured memory_bytes: 137784
#include <stdio.h>  
#include <math.h>  
#include <string.h>  
#include <stdlib.h>  
#include <iostream>  
#include <sstream>  
#include <algorithm>  
#include <set>  
#include <queue>  
#include <stack>  
#include <map>
#define MEC(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;

int n,ans = 0;
int a[10005];

int main(){
	cin>>n;
	int t = n;
	while(t--) cin>>a[t];
	for(int i = 0;i < n - 1;i++){
		if(a[i] == a[i + 1]){
			if(a[i +1] == a[i + 2]){
				ans++;
				i+=1;
			}
			else ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

struct Restaurant {
	string city;
	int score;
	int id;
	
	Restaurant(string _city, int _score, int _id) {
		city = _city;
		score = _score;
		id = _id;
	}

	bool operator<( const Restaurant& r) const {
		return city == r.city ? score > r.score : city < r.city;
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<Restaurant> R;
	REP(i, N) {
		string city;
		int score;
		cin >> city >> score;
		R.push_back(Restaurant(city, score, i+1));
	}
	so(R);
	REP(i, N) {
		cout << R[i].id << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

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

if N==2 and A==[0,2,1]:
    print(-1)
    sys.exit()


C=[0]*(N+1)

for i in range(1,N+1):
    if A[i]!=i:
        C[A[i]]+=1

import heapq

H=[]
for i in range(1,N+1):
    H.append((-C[i],i))

heapq.heapify(H)
NOUSE=list(range(N,0,-1))
USELIST=[0]*(N+1)
ANS=[0]

for rest in range(N-1,2,-1):
    #print(ANS,NOUSE,H,rest)
    
    if -H[0][0]==rest and rest!=0:
        x,y=heapq.heappop(H)
        ANS.append(y)
        C[y]=0
        C[A[y]]-=1
        USELIST[y]=1

    else:
        for i in range(len(NOUSE)-1,-1,-1):
            if USELIST[NOUSE[i]]==0 and A[ANS[-1]]!=NOUSE[i]:
                x=NOUSE.pop(i)
                ANS.append(x)
                USELIST[x]=1
                C[x]=0
                C[A[x]]-=1
                break
            

    while C[H[0][1]]!=-H[0][0]:
        x,y=heapq.heappop(H)
        heapq.heappush(H,(-C[y],y))

    while NOUSE and USELIST[NOUSE[-1]]==1:
        NOUSE.pop()


NOUSE=[i for i in range(N+1) if USELIST[i]==0]

from itertools import permutations
REST=list(permutations(sorted(NOUSE[1:])))

if len(REST)==2:
    for x,y in REST:
        if A[ANS[-1]]!=x and A[x]!=y:
            ANS.extend([x,y])
            break

else:    
    for x,y,z in REST:
        if A[ANS[-1]]!=x and A[x]!=y and A[y]!=z:
            ANS.extend([x,y,z])
            break

print(*ANS[1:])

Measured memory_bytes: 26628
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=1e7+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }



void solve() {
    
    int n;
    cin>>n;
    string s="";
    while(n--) {
		  s+=(char)('a'+n%26);
		  n/=26;		  
		}
		reverse(all(s));
		cout<<s<<endl;      					   
 }

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();


return 0;	   
}


Measured memory_bytes: 3640
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}



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

// lib/to_signed.hpp
#ifndef TO_SIGNED_HPP
#define TO_SIGNED_HPP


/*
usage:

std::uint_fast64_t i;
decltype(tools::to_signed(i)) // => std::int_fast64_t
*/

namespace tools {
  template <typename T>
  constexpr typename std::make_signed<T>::type to_signed(const T x) noexcept {
    return x;
  }
}

#endif

// main.cpp

int main() {
  std::string s;
  std::cin >> s;

  const std::int_fast64_t n = tools::to_signed(s.size());
  const char center = s[n / 2];
  std::int_fast64_t i;
  for (i = n / 2 - 1; i >= 0 && s[i] == center && s[n - i - 1] == center; --i);
  const std::int_fast64_t win = (n / 2 - 1) - i;
  std::cout << (n + 1) / 2 + win << std::endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  rep(snip_i, m) cin >> x.at(snip_i);
  if(n >= m){
    cout << 0 << endl;
    return 0;
  }
  sort(x.begin(), x.end());
  vector<int> diff(m-1);
  ll sum = 0;
  rep2(i, 1, m){
    diff.at(i-1) = x.at(i) - x.at(i-1);
    sum += diff.at(i-1);
  }
  sort(diff.rbegin(), diff.rend());
  rep(i, n-1){
    sum -= diff.at(i);
  }
  cout << sum << endl;
  return 0;
}

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

using namespace std;

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

    vector<long long> vals;
    vector<int> weights;
//    vals.push_back(0);
//    weights.push_back(0);

    vector<pair<int, long long>> all;
    for(int i = 0; i < N; i++)
    {
        long long val, weight;
        cin >> weight >> val;
//        vals.push_back(val);
//        weights.push_back(weight);
        all.push_back(make_pair(weight, val));
    }

//    cout << endl;
   // sort(all.begin(), all.end());
    for(int i = 0; i < (int)all.size(); i++)
    {
        weights.push_back(all[i].first);
        vals.push_back(all[i].second);
//        cout << weights[i] << " " << vals[i] << endl;
    }

//    dp[i][w]
//      dp[0][w] = 0
//      dp[i][w] = max(dp[][w-w1])

//    int pos = 0;
//    vector<bool> used(W, false);
//    vector<long long> dp(W+1, 0);
//    for(int i = 1; i <= W; i++)
//    {
//        long long m = 0;
//        for(int j = 0; j < weights.size(); j++)
//        {
//            if(i - weights[j] >= 0 && !used[j])
//            {
//                m = max({m, dp[i-weights[j]] + vals[j]});
//                used[j] = true;
//            }
//        }
//        dp[i] = m;
//    }

    vector<vector<long long>> dp(N+1, vector<long long>(W+1, 0));
    for(int i = 1; i <= N; i++)
    {
        for(int j = 0; j <= W; j++)
        {
            if(weights[i-1] > j)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-weights[i-1]] + vals[i-1]);
        }
    }

//    for(auto& v: dp)
//    {
//        for(auto& e: v)
//            cout << e << " ";
//        cout << endl;
//    }

    cout << dp[N][W] << endl;
    return 0;
}


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

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h) cin >> s[i];

    int ans=0;
    //1<<hは2のh乗を表している
    rep(is,1<<h)rep(ls,1<<w){
        int cnt=0;
        rep(i,h)rep(j,w){
            //2進数のi桁目を取り出すにはこうする
            if(is>>i&1)continue;
            if(ls>>j&1)continue;
            if(s[i][j]=='#') cnt++;
        }
        if(cnt==k) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

result=10**6
hantei=0

num_E=S.count('E')
num_W=S.count('W')

pr_E=0
pr_W=0

for i in range(N):
    if i==0:
        hantei=num_E-(S[i]=='E')*1
        pr_E+=(S[i]=='E')*1
        pr_W+=(S[i]=='W')*1
    elif i==N-1:
        hantei=num_W-(S[i]=='W')*1
    else:
        hantei=pr_W+num_E-(pr_E+(S[i]=='E')*1)
        pr_E+=(S[i]=='E')*1
        pr_W+=(S[i]=='W')*1
    
    result=int(min(result,hantei))

print(result)

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

int main(){
    string a, b, c;
    cin>>a>>b;
    vector<vector<pair<int, int>>> dp(a.length()+1, vector<pair<int, int>>(b.length()+1, {0, 1}));
    rep1(i, 1, a.length()+1){
        rep1(j, 1, b.length()+1){
            if(a[i-1]==b[j-1]){
                dp[i][j].first = dp[i-1][j-1].first+1;
                dp[i][j].second = 0;
            }
            else{
                if(dp[i-1][j].first < dp[i][j-1].first){
                   dp[i][j].first =  dp[i][j-1].first;
                   dp[i][j].second =  2;
                }
                else{
                    dp[i][j].first =  dp[i-1][j].first;
                    dp[i][j].second =  1;
                }
            }
            //  cout<<dp[i][j].second<<" ";
                // dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
        // cout<<endl;
}
    int i=a.length(), j=b.length();
    while(i>=0&&j>=0&&(i||j)){
        if(dp[i][j].second==2)
            j--;
        else if(dp[i][j].second==1)
            i--;
        else{
            i--;
            j--;
            c = c + a[i];
        }
    }
    for(int i=c.length()-1; i>=0; i--)
        cout<<c[i];
    
}

Measured memory_bytes: 70784
#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 N 200000 + 5 

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

lli dp[3005][3005] , pre[3005][3005] ;

int main()
{
///////////////////////////////////////////
    fastio;
  
    lli n;
    cin>>n;

    string s;
    cin>>s;

    dp[1][1] = 1;
    pre[1][1] = 1;

    loopl(i,2,n+1)
    {
        loopl(j,1,i+1)
        {
            lli ans=0;
            
            if(s[i-2] == '<')
            {
                ans = (ans + pre[i-1][j-1])%mod ;
            }

            else
            {
                ans = (ans + pre[i-1][i-1] - pre[i-1][j-1] + mod)%mod;
            }

            dp[i][j] = ans;
            pre[i][j] = (pre[i][j-1]+dp[i][j])%mod; 
        }
    }

    lli ans=0;

    loopl(i,1,n+1)
    ans = (ans+dp[n][i])%mod ;

    cout<<ans<<endl;


}

Measured memory_bytes: 139648
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def factorization(n: int):
    if n == 1:
        return []  # 1は素数ではない
    # 素因数分解
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 1):  # ここにバグがないか心配
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append((i, cnt))

    if temp != 1:
        arr.append((temp, 1))

    if arr == []:
        arr.append((n, 1))

    return arr


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
# https://atcoder.jp/contests/abc114/tasks/abc114_d

N = read_a_int()

# N!を素因数分解形式で表示する
# その結果ni>=74となる 因数の個数
# +
# ni >= 24 かつ nj >=2となる因数の組の個数
# +
# ni >= 14 かつ nj >=4となる因数の組の個数
# +
# ni >= 4 かつ nj >=4 かつ nk >=2 となる因数の組の個数
# が答えのはず
# 素数は少ないので全探索できそう

N_fact = defaultdict(lambda: 0)
for i in ra(1, N + 1):
    tmp = factorization(i)
    for k, v in tmp:
        N_fact[k] += v

ans = 0
values = list(N_fact.values())
for v in values:
    if v >= 74:
        ans += 1

# print(ans)
for i, j in product(range(len(values)), repeat=2):
    if i == j:
        continue
    if values[i] >= 24 and values[j] >= 2:
        ans += 1
    if values[i] >= 14 and values[j] >= 4:
        ans += 1


# ここまで多分ok

# print(ans)
for i, j in combinations(range(len(values)), r=2):  # i,jはダブらないように選ぶ
    for k in range(len(values)):
        if i == k or j == k:
            continue
        if values[i] >= 4 and values[j] >= 4 and values[k] >= 2:
            ans += 1

print(ans)


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

double dp[303][303][303];
int n;

void calc(int i, int j, int k)
{
    if (dp[i][j][k] >= 0)
        return;
    if (i)
        calc(i - 1, j, k);
    if (j)
        calc(i + 1, j - 1, k);
    if (k)
        calc(i, j + 1, k - 1);

    dp[i][j][k] = (i ? dp[i - 1][j][k] * i : 0) + (j ? dp[i + 1][j - 1][k] * j : 0) +
                  (k ? dp[i][j + 1][k - 1] * k : 0) + n;
    dp[i][j][k] *= 1.0 / (i + j + k);
}

int main()
{
    cin >> n;
    vector<int> cnt(5);
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        cnt[a]++;
    }

    memset(dp, -1, sizeof dp);
    dp[0][0][0] = 0.0;
    calc(cnt[1], cnt[2], cnt[3]);
    printf("%.10lf\n", dp[cnt[1]][cnt[2]][cnt[3]]);

    return 0;
}


Measured memory_bytes: 217600
import math
import itertools
from scipy.spatial import distance

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

d = 0
for i in itertools.permutations(l):
    for j in range(n-1):
        if j+1 < n:
            d += math.sqrt((i[j][0] - i[j+1][0]) ** 2 + (i[j][1] - i[j+1][1]) ** 2)

print(d/math.factorial(n))


Measured memory_bytes: 15856