akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
    int r, c, i, j;
    
    scanf("%d %d", &r, &c);

    int rcarray[r + 1][c + 1];
    
    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            scanf("%d", &rcarray[i][j]);
        }  
    }

    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            rcarray[i][c] = 0;
            rcarray[r][j] = 0;
        }
    }
    rcarray[r][c] = 0;
    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            rcarray[r][j] += rcarray[i][j];
            rcarray[i][c] += rcarray[i][j];
        }
    }
    for(i = 0; i < r; i++){
        rcarray[r][c] += rcarray[i][c];
    }

    for(i = 0; i < r + 1; i++){
        for(j = 0; j < c + 1; j++){
            printf("%d", rcarray[i][j]);
            if(j >= 0 && j < c){
                printf(" ");
            }
        }    
        printf("\n");
        
    }   

    return 0;
}


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

const int maxN = 2e5 + 10, mod = 1e9 + 7, inf = 1e9 + 100;

int n, x, y, mn1, mn2;
int fac[maxN + 1], inv[maxN + 1], pa[maxN + 1];
int c[maxN + 1], w[maxN + 1];
int sum[maxN + 1], mn[maxN + 1], t[maxN + 1];

inline int read()
{
	int num = 0, f = 1;
	char ch = getchar();
	while( !isdigit( ch ) ) { if(ch == '-') f = -1; ch = getchar(); }
	while( isdigit( ch ) ) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar();
	return num * f;
}

inline int mpow(int a, int x)
{
	int ans = 1;
	while(x)
	{
		if(x & 1) ans = 1ll * ans * a % mod;
		a = 1ll * a * a % mod;
		x >>= 1;
	}
	return ans;
}

inline int find(int x) { return pa[x] == x ? x : pa[x] = find(pa[x]); }

inline void merge(int x, int y)
{
	x = find(x), y = find(y);
	if(x == y) return;
	pa[x] = y;
	sum[y] += sum[x];
}

int main()
{
	n = read();
	x = read(), y = read();
	
	w[0] = inf;
	fac[0] = 1;
	for(int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[n] = mpow(fac[n], mod - 2);
	for(int i = n - 1; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
	
	for(int i = 1; i <= n; i++) pa[i] = i, sum[i] = 1;

	for(int i = 1; i <= n; i++)
	{
		c[i] = read(), w[i] = read();
		if(w[i] < w[ mn[ c[i] ] ]) mn[ c[i] ] = i;
		if(w[i] < w[mn1]) mn1 = i;
	}
	for(int i = 1; i <= n; i++)
		if(c[i] != c[mn1] && w[i] < w[mn2]) mn2 = i;
	for(int i = 1; i <= n; i++)
	{
		if(i != mn[ c[i] ] && w[i] + w[ mn[ c[i] ] ] <= x) merge(i, mn[ c[i] ]);
		if(c[i] != c[mn1] && w[i] + w[mn1] <= y) merge(i, mn1);
		if(c[i] == c[mn1] && w[i] + w[mn2] <= y) merge(i, mn2);
	}

	int root = find(mn1);
	for(int i = 1; i <= n; i++)
		if(find(i) == root) t[ c[i] ] ++;

	int ans = 1;
	for(int i = 1; i <= n; i++)
		if(t[i]) ans = 1ll * ans * inv[ t[i] ] % mod;
	ans = 1ll * ans * fac[ sum[ find(mn1) ] ] % mod;
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;

int main(){
  bool a[100010] = {0};
  int b[100010] = {0};
  a[1] = true;
  for(int i=2; i<=100005; i++){
    for(int j=2*i; j<=100005; j+=i){
      a[j]=true;
    }
  }
  for(int i=1; i<=100005; i++){
    int tmp=(i+1)/2;
    if(!(a[i]) && !(a[tmp])) b[i] = 1;
  }
  int C[100010]={0};
  for(int i=0; i<=100005; i++){
    C[i+1] = C[i]+b[i];
  }
  int Q;
  cin >> Q;
  int l[Q], r[Q];
  rep(i, Q){
    cin >> l[i] >> r[i];
    r[i]++;
    int ans = C[r[i]]-C[l[i]];
    cout << ans << endl;
  }
}

Measured memory_bytes: 2304
/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 02-Aug-2020 18:02:19
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void INT(T &n) {
    n = 0; int f = 1; int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void INT(T &x, W &y) {INT(x), INT(y);}
template <TN T, TN W, TN Q> inline void INT(T &x, W &y, Q &z) {INT(x, y), INT(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

long long sq(long long x) {
    return x * x;
}

int solve() {
    int n; long long d;
    INT(n, d);

    d *= d;

    int res = 0;
    for (int i = 0; i < n; ++i) {
        long long x, y; INT(x, y);
        if (sq(x) + sq(y) <= d) {
            ++res;
        }
    }

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

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0;
    // INT(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}

Measured memory_bytes: 3800
def clc(num):
  return int(1+num*(num-1)/2 +num-1)

n =int(input())
cnt=0
pr=0
s=[None]*n
ans=[0]*n
for i in range(n):
  s[i]=sorted(input())
s.sort()
for j in range(0, n-1, 1):
  if s[j] == s[j+1]:
    ans[cnt] += 1
  else:
    cnt +=1
clcnums = [clc(n) for n in ans if n!= 0]
print(sum(clcnums))

Measured memory_bytes: 25420
n = gets.to_i
aArr = gets.split.map(&:to_i).sort.reverse
q = gets.to_i
mArr = gets.split.map(&:to_i)

ans = [0]
aArr.each do |a|
  ans += ans.map{|x| x+a}
  ans = ans.select{|x| x<=2000}.uniq
end
mArr.each do |m|
  printf("%s\n",ans.include?(m) ? "yes" : "no")
end


Measured memory_bytes: 7228
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
using namespace std;
 
int main(void){
    string s, t;
    
    cin >> s >> t;
    
    bool complete = false;
    
    vector<int> okIndex;
    
    
    for(int i = 0; i < s.size(); i++){
        if(s.size()- i < t.size()) break;
        if(s.size() < t.size()) break;
        string tmp = s.substr(i, t.size());
        bool ok = true;
        for(int j = 0; j < tmp.size(); j++){
            if(tmp[j] != t[j] && tmp[j] != '?'){
                // if(tmp[j] == '?') continue;
                ok = false;
                break;
            }
        }
        if(!ok) continue;
        okIndex.push_back(i);
        complete = true;
    }
    
    int largestIndex = 0;
    for(int i= 0; i < okIndex.size(); i++){
        if(largestIndex < okIndex[i]){
            largestIndex = okIndex[i];
        }
    }
    
    
    for(int i = 0; i < t.size(); i++){
        if(s[largestIndex + i]  == '?'){
            s[largestIndex + i] = t[i];
        }
    }
    
    
    if(complete){
        for(int i = 0; i < s.size(); i++){
            if(s[i] == '?'){
                s[i] = 'a';
            }
        }
        cout << s << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

from collections import Counter
counter=Counter(a)

# すべての組み合わせを事前に計算しておく
combi_sum=0
for num,cnt in counter.items():
    combi_sum+=cnt*(cnt-1)//2

for i in range(n):
    print(combi_sum - counter[a[i]] + 1)

Measured memory_bytes: 24748
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

void print_rec(int h, int w){
	for(int i = 0; i < h; i++){
		if(i % 2 == 0){
			for(int j = 0; j < w; j++){
				if(j % 2 == 0) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		else{
			for(int j = 0; j < w; j++){
				if(j % 2 == 0) cout << ".";
				else cout << "#";
			}
			cout << endl;
		}
	}
	cout << endl;
}

int main(void){

	int h,w;
	while(1){
		cin >> h >> w;
		if(h == 0 && w == 0) break;
		print_rec(h, w);
	}
	return 0;
}

Measured memory_bytes: 1156
import * as fs from 'fs';

namespace AtCoder {
    export interface Paramable {
        readonly args: string[][];
    }

    export interface Task {
        main(this: Task): void;
    }
}

namespace AtCoder.abc001 {
    export class TaskA implements AtCoder.Task, AtCoder.Paramable {
        public constructor(public readonly args: string[][]) {
        }

        public main(this: TaskA): void {
            const [n, k]: number[] = this.args[0].map(Number);
            const set = new Set();

            for (let i = 2; i < k * 2+1; i = i + 2) {
                const val: number[] = this.args[i].map(Number);
                val.forEach(x => {
                    set.add(x)
                })
            }
            console.log(n - set.size);
        }
    }

    const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
    const task: AtCoder.Task = new TaskA(args);
    task.main();
}



Measured memory_bytes: 29844
l = []
ans = 0

for s in input():
    if s == "0":
        if l and l[-1] == "1":
            l.pop()
            ans += 2
        else:
            l.append(s)
    else:
        if l and l[-1] == "0":
            l.pop()
            ans += 2
        else:
            l.append(s)

print(ans)

Measured memory_bytes: 3956
#include <stdio.h>

int main()
{
	
	int  n;
	scanf("%d", &n);
	for(;;){
		n %= 10;
		if(0 <= n && n <= 9){
			break;
		}
	}
	
	if(n == 3){
		printf("bon");
	}else if(n == 0 || n == 1 || n == 6 || n == 8){
		printf("pon");
	}else{
		printf("hon");
	}
}

Measured memory_bytes: 1704
#include <iostream>

using namespace std;

int main()
{
    long long H,W;
    cin >> H >> W;
    long long h_c;
    long long w_c;
    if(H == 1 || W == 1){
        cout << 1 << endl;
        return 0;
    }
    if(H % 2 == 0){
        h_c = H / 2;
    } else {
        h_c = H /2 + 1;
    }
    if(W % 2 == 0){
        w_c = W / 2;
    } else {
        w_c = W / 2 + 1;
    }
    long long  ans = h_c * w_c + (H - h_c) * (W - w_c);
    cout << ans << endl;
}

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

long long dp[110][25]={};

int main(){
	long long n,a[110],ans;
	cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>a[i];
	}
	cin>>ans;
	dp[1][a[0]]=1;
	for(int i=2;i<=n-1;i++){
		for(int k=0;k<=20;k++){
			if(k-a[i-1]>=0)dp[i][k]+=dp[i-1][k-a[i-1]];
			if(k+a[i-1]<=20)dp[i][k]+=dp[i-1][k+a[i-1]];
		}
	}
	cout<<dp[n-1][ans]<<endl;
	return 0;
}



Measured memory_bytes: 3096
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-12 20:03:59
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int n, m; cin >> n >> m;
  map<int, int> mp;

  int ac = 0, wa = 0;

  bool d[n + 1] = {};

  for (int i = 0; i < m; ++i) {
    int p; string s; cin >> p >> s;
    if (s == "AC") {
      if (d[p]) {
        ;
      } else {
        d[p] = 1;
        ++ac;
        wa += mp[p];
      }
    } else {
      ++mp[p];
    }
  }

  cout << ac << " " << wa << endl;

  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2*1e9

int main()
{
    int r;
    cin >> r;
    cout <<fixed << setprecision(5) <<  6.28318530717958623200*r  << endl;
}

Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

using namespace std;

int board[610][610];
int board2[610][610];

bool bboard[610][610];

int N, D1, D2;

bool inBoard(int x, int y) {
	return x >= 0 && x < 2 * N && y >= 0 && y < 2 * N;
}

void dfs(int x, int y, int value, int board[610][610], vector<pair<int, int>> &P) {
	if (board[y][x]) return;
	board[y][x] = value;
	for (auto &pr : P) {
		int nx = x + pr.first;
		int ny = y + pr.second;
		if (!inBoard(nx, ny)) continue;
		if (board[ny][nx]) continue;
		dfs(nx, ny, 3 - value, board, P);
	}
}

int main() {
	cin >> N >> D1 >> D2;
	
	vector<pair<int, int>> P1, P2;
	
	for (int d = 0; d <= sqrt(D1); d++) {
		int a = D1 - d * d;
		int b = sqrt(a);
		if (b * b != a) continue;
		P1.push_back(make_pair(d, b));
		P1.push_back(make_pair(d, -b));
		P1.push_back(make_pair(-d, b));
		P1.push_back(make_pair(-d, -b));
	}
	
	for (int d = 0; d <= sqrt(D2); d++) {
		int a = D2 - d * d;
		int b = sqrt(a);
		if (b * b != a) continue;
		P2.push_back(make_pair(d, b));
		P2.push_back(make_pair(d, -b));
		P2.push_back(make_pair(-d, b));
		P2.push_back(make_pair(-d, -b));
	}
	
	
	for (int y = 0; y < 2 * N; y++) {
		for (int x = 0; x < 2 * N; x++) {
			dfs(x, y, 1, board, P1);
			dfs(x, y, 1, board2, P2);
		}
	}
	
	vector<pair<int, int>> v[4];
	for (int y = 0; y < 2 * N; y++) {
		for (int x = 0; x < 2 * N; x++) {
			pair<int, int> p(x, y);
			if (board[y][x] == 1 && board2[y][x] == 1) v[0].push_back(p);
			if (board[y][x] == 1 && board2[y][x] == 2) v[1].push_back(p);
			if (board[y][x] == 2 && board2[y][x] == 1) v[2].push_back(p);
			if (board[y][x] == 2 && board2[y][x] == 2) v[3].push_back(p);
		}
	}
	
	
	for (int i = 0; i < 4; i++) {
		if (v[i].size() < N * N) continue;
		
		for (int j = 0; j < N * N; j++) {
			cout << v[i][j].first << " " << v[i][j].second << endl;
			bboard[v[i][j].second][v[i][j].first] = 1;
		}
		
		break;
	}
	
	
	return 0;
}

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

int main()
{
	int n;
	
	cin >> n;
	
	int a[n+5];
	
	int idx = -1, val, flag = 0, cnt = 0;
	
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		
		if(a[i] == i) continue;
		if(idx == -1) {idx = i; cnt++;}
		else if(cnt == 1){
			cnt++;
			swap(a[i], a[idx]);
		}
	}
	
	for(int i = 1; i <= n; i++){
		if(a[i] != i) {flag = 1; break;}
	}
	
	if(!flag) cout << "YES" << "\n";
	else cout << "NO" << "\n";
	
	return 0;
}


Measured memory_bytes: 256
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n, p;
ll a[MAXN], dp[2], ndp[2];

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	cin >> n >> p;
	for (int i=0; i<n; i++) cin >> a[i];
	
	dp[0] = 1;
	
	for (int i=0; i<n; i++) {
		ndp[0] = dp[0], ndp[1] = dp[1];
		if (a[i] % 2) {
			ndp[0] += dp[1];
			ndp[1] += dp[0];
		}
		else {
			ndp[0] += dp[0];
			ndp[1] += dp[1];
		}
		dp[0] = ndp[0];
		dp[1] = ndp[1];
//		cout << dp[0] << " " << dp[1] << endl;
	}
	
	cout << dp[p];


}


Measured memory_bytes: 256
#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 reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

P f(int a) {
  int x = a % 10;
  int y = a;
  while(a) {
    y = a;
    a /= 10;
  }
  return P(x, y);
}
int main()
{
  int n;
  cin >> n;
  ll ans = 0;
  map<P, int> mp;
  for (int i = 1; i <= n; i++) {
    P p = f(i);
    mp[p]++;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ans += it->second * mp[make_pair(it->first.second, it->first.first)];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <map>

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator &itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() {return i;}
  Iterator &end() {return n;}
};

template<class T> T at(vector<T> v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

const long long MOD = 100000;

class Inverse {
private:
	vector<long long> inv;
  
public:
	Inverse(int n) {
    inv = vector<long long>(n, 1);
		for (int i : range(2, n)) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
  }
  
	long long operator()(long long a) const {
		if (a < (int)inv.size()) return inv[a];
		long long b = MOD, x = 1, y = 0;
		while (b) {
			long long t = a / b;
			swap(a -= t * b, b);
			swap(x -= t * y, y);
		}
		return (MOD + x % MOD) % MOD;
	}
};

Inverse inv(1000000);

class Mint {
private:
  long long val;
	
public:
	Mint() : val(0) {}
	Mint(long long val) : val(val % MOD) {}
	
	Mint operator+=(const Mint &m) {
		val += m.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
  
	Mint operator-=(const Mint &m) {
		val -= m.val;
		if (val < 0) val += MOD;
		return *this;
	}
  
	Mint operator*=(const Mint &m) {
		val *= m.val;
		val %= MOD;
		return *this;
	}
  
	Mint operator/=(const Mint &m) {
		val *= inv(m.val);
		val %= MOD;
		return *this;
	}
	
	Mint operator+(const Mint &m) const {
		Mint res = *this;
		res += m;
		return res;
	}
	
	Mint operator-(const Mint &m) const {
		Mint res = *this;
		res -= m;
		return res;
	}
	
	Mint operator*(const Mint &m) const {
		Mint res = *this;
		res *= m;
		return res;
	}
	
	Mint operator/(const Mint &m) const {
		Mint res = *this;
		res /= m;
		return res;
	}
	
	Mint operator++() {return val += 1;}
	
	operator long long() {
		return val;
	}
};

ostream &operator<<(ostream &os, Mint a) {
	os << (long long)a;
	return os;
}

istream &operator>>(istream &is, Mint &a) {
	long long n;
	is >> n;
	a = Mint(n);
	return is;
}

int main() {
  int m, n;
  cin >> m >> n;
  vector<string> s(m);
  for (auto &i : s) cin >> i;
  vector<map<pair<int, int>, Mint>> dp(2);
  dp[0] = {{make_pair(0, 0), 1}};
  int mask = (1 << n) - 1;
  for (int y : range(m)) for (int x : range(n)) {
    for (const auto &t : dp[0]) {
      int bit = t.first.first;
      int pre = t.first.second;
      Mint num = t.second;
      int nbit = 2 * bit & mask;
      if (s[y][x] == 'J' || s[y][x] == '?') {
        dp[1][make_pair(nbit, 0)] += num;
      }
      if (s[y][x] == 'O' || s[y][x] == '?') {
        if (x > 0 && pre == 0) dp[1][make_pair(nbit | 1, 1)] += num;
        else dp[1][make_pair(nbit, 1)] += num;
      }
      if (s[y][x] == 'I' || s[y][x] == '?') {
        if ((bit & 1 << (n - 2)) == 0) dp[1][make_pair(nbit, 2)] += num;
      }
    }
    dp[0] = dp[1];
    dp[1].clear();
  }
  Mint res = 1;
  for (const auto &i : s) for (const auto &j : i) if (j == '?') res *= 3;
  for (const auto &t : dp[0]) res -= t.second;
  cout << res << endl;
}

Measured memory_bytes: 12412
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size() / 2; ++i) {
    if (s[i] != s[s.size() - i - 1]) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n,q;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++)
  {
    cin >> s[i];
  }

  cin >> q;
  vector<int> t(q);
  for (int i = 0; i < q; i++)
  {
    cin >> t[i];
  }
  
  int ans = 0;
  for (int i = 0; i < q; i++)
  {
    if(*lower_bound(s.begin(),s.end(),t[i])==t[i]) ans++;
  }
  cout << ans << endl;  
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for(auto& i:mp)

const int INF = 1001001001;

int main() {
  string t;
  cin >> t;
  string ans;
  int n = t.size();
  if (n==1) {
    ans.push_back('D');
    cout << ans << '\n';
    return 0;
  }
  repr(i, 0, n){
    // ans.push_back(t[i];
    ans.push_back(t[i]);
    // if (i == 0) {
    //
    //   continue;
    // }
    if (t[i] == '?' && ans[i-1] == 'P' && i != 0) {
      ans.pop_back();
      ans.push_back('D');
    }
    else if (t[i] == '?' && t[i+1] == 'P' && i != n-1) {
      ans.pop_back();
      ans.push_back('D');
    }
    else if (t[i] == '?' && t[i+1] == 'D' && i != n-1) {
      ans.pop_back();
      ans.push_back('P');
    }
    else if (t[i] == '?' && i == n-1) {
      ans.pop_back();
      ans.push_back('D');
    }
    else if (t[i] == '?' && t[i+1] == '?' && i != n-1) {
      ans.pop_back();
      ans.push_back('P');
    }
    // cout << i << ans[i]<<'\n';
  }
  // ans[0] = 'P';
  // ans = "kjdkj";
  cout << ans << '\n';
  // cout << ans[0] << '\n';
  return 0;
}


Measured memory_bytes: 3928
#include <bits/stdc++.h>
#include <functional>
#include<stdio.h>
using namespace std;
#define ll       	long long int
#define dd      	long double
#define pb          push_back
#define pf          push_front
#define pi         pair<ll,ll>
#define vi          vector<ll>
#define vpi        vector<pi>
#define mi          map<ll,ll>
#define vvi         vector<vector<ll>>
#define mpi         map<pi,ll>
#define pipi        pair<ll,pair<ll,ll> >
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x         first
#define y         second
#define sz(x)       (ll)x.size()
#define u        	'\n'
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define rf(s)       for(auto &c : s)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++) //use Iterator
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define ef          else if
#define yes       cout<<"YES"<<'\n';
#define no        cout<<"NO"<<'\n';
#define C         continue;
#define wa(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
#define debug(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<'\n'
#define debugp(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i.x<<","<<i.y<<" | "; cout<<'\n'
#include <ext/pb_ds/tree_policy.hpp>     
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>     
using namespace __gnu_pbds;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define fbo find_by_order
#define ook order_of_key
const ll N = 350;
 
ll gcd(ll a, ll b) {  if (a == 0)  return b; return gcd(b % a, a); } 
/*
ll power(ll x, ll y) 
{ 
    ll res = 1;  
	x=x%M; 
    while (y > 0) 
    { 
        if (y & 1) 
        res = (res*x)%M; 
        y = y>>1; 
        x = (x*x)%M;  
    } 
    return res; 
}
*/

signed main()
{
	tezz
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll n,i,j;
		cin>>n;
		vi s(n+1,0);
		s[0]=1;
		fo(i,3,n+1)
		{
		    fo(j,3,i-2)
		    {
		        s[i]=(s[i]+s[j])%M;
		    }
		    s[i]=(s[i]+1)%M;
		}
		cout<<s[n]<<u;
	}
	return 0;
} 

Measured memory_bytes: 3584
// finish date: 2018/08/13
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;

string solve(int N) {
    if (N == 0) return "0";
    string s = "";
    int i = 0;
    while (N != 1) {
        if (abs(N) % 2 == 0) {
            s = '0' + s;
            N /= -2;
        } else {
            s = '1' + s;
            N = (N - 1) / -2;
        }
    }
    return '1' + s;
}

int main() {
    int N;
    cin >> N;
    cout << solve(N) << endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
//#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   


int32_t main() 
{ 
    fastio
    int n, m, k;
    cin>>n>>m>>k;
    vector<ll> vec(n), vec2(m);
    for(auto& it : vec) cin>>it;
    for(auto& it : vec2) cin>>it;

    vector<ll> pref(n+1), pref2(m+1);
    for(int i = 1; i<=n; ++i) {
        if(i==1) pref[i] = vec[i-1];
        else pref[i] = pref[i-1]+vec[i-1];
    }
    for(int i = 1; i<=m; ++i) {
        if(i==1) pref2[i] = vec2[i-1];
        else pref2[i] = pref2[i-1]+vec2[i-1];
    }

    int ans = 0;
    for(int i = 0; i<=n; ++i) {
        ll sum = pref[i];
        if(sum>k) continue;
        ll now = k - sum;
        auto it = upper_bound(all(pref2), now);
        if(it==pref2.begin()) {
            ans = max(ans, i);
            continue;
        }
        else {
            it = prev(it);
            ans = max(ans, i+(int)(it-pref2.begin()));
        }
    }
    
    cout<<ans<<endl;
}

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

class UF{
public:
  int V;
  vector<int> par,rnk,sz;
  UF(){}
  UF(int V):V(V),par(V),rnk(V,0),sz(V,1){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rnk[x]<rnk[y])par[x]=y, sz[y] += sz[x];
    else{
      par[y]=x;
      sz[x] += sz[y];
      if(rnk[x]==rnk[y])rnk[x]++;
    }
  }
  
  bool same(int x,int y){return find(x)==find(y);}
  
  int size(int x){return sz[find(x)];}
};

typedef tuple<int,int,int> T;

int MST(int V, int E, vector<T> G){
  
  sort( G.begin(), G.end() );
  
  UF uf = UF( V );
  
  int res = 0;
  
  for(int i=0;i<E;i++){
    
    int s, t, w;
    tie( w, s, t ) = G[i];
    
    if( uf.same( s, t ) ) continue;
    
    uf.unite( s, t );
    
    res += w;
    
  }
  
  return res;
}

signed main(){
  
  int V, E;
  cin >> V >> E;
  
  vector<T> G;
  
  for(int i=0;i<E;i++){
    
    int s, t, w;
    cin >> s >> t >> w;
    
    G.push_back( T( w, s, t ) );
    
  }
  
  cout << MST( V, E, G ) << endl;
  
  return 0;
}



Measured memory_bytes: 7732
import java.util.*;
import java.io.*;
public class Main{

     public static void main(String []args) throws IOException{
       
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       
       String a = br.readLine();
       
       if(a.compareTo("ABC") == 0)
       System.out.println("ARC");
       else System.out.println("ABC");
     }
}

Measured memory_bytes: 32444
#include<iostream>
using namespace std;
int main()
{
    int i,k,l=0,m,n;
    cin>>n>>m;
    int a[m];
    for(i=0;i<m;i++){
        cin>>a[i];
        l+=a[i];
    }
    k=n-l;
    if(k<0) cout<<"-1"<<endl;
    else cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include<cstdio>
int L,N,X[200010];
long long S[200010];
int main(){
	scanf("%d%d",&L,&N);
	for(int i=1;i<=N;i++)scanf("%d",X+i);
	long long ans=0;
	for(int T=2;T--;){
		for(int i=1;i<=N+1;i++)S[i]=S[i-1]+X[i];
		for(int i=1;i<=N;i++){
			int lt=i-1,rt=N-i;
			if(lt>rt)lt=rt+1;
			else if(rt>lt)rt=lt;
			long long tmp=(S[i-1]-S[i-1-lt])*2+(1ll*L*rt-S[i+rt]+S[i])*2+L-X[i];
			if(tmp>ans)ans=tmp;
			//printf("T=%d i=%d ans=%lld\n",T,i,ans);
		}
		for(int i=1;i<=N;i++)X[i]=L-X[i];
		for(int i=1,j=N,t;i<j;i++,j--)t=X[i],X[i]=X[j],X[j]=t;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;


int main() {

	long long N;
	long long M;
	cin >> N >> M;

	vector<long long> p;

	long long a, b;

	for (long long i = 0; i < M; i++) {
		cin >> a >> b;
		if (a == 1) {
			p.push_back(b);
		}
		else if (b == N) {
			p.push_back(a);
		}
	}

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

	bool jdg = false;
	for (long long i = 0; i < p.size() - 1; i++) {
		if (p[i + 1] == p[i]) {
			jdg = true;
			break;
		}
	}

	if (jdg == true) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}

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

int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  int count = 0;
  while (A >= B){
    B *= 2;
    count++;
  }
  while (B >= C){
    C *= 2;
    count++;
  }

  if (count <= K){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3612
require 'pp'

# 入力値を文字列で返却する
def gets_s()
  gets.chomp
end

S = gets_s

keys = [
  ["", "keyence"],
  ["k", "eyence"],
  ["ke", "yence"],
  ["key", "ence"],
  ["keye", "nce"],
  ["keyen", "ce"],
  ["keyenc", "e"],
  ["keyence", ""],
]

keys.each do |left, right|
  if S.index(left) == 0 && S.reverse.index(right.reverse) == 0
    puts "YES"
    exit
  end
end
puts "NO"


Measured memory_bytes: 4092
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int a,b;
	char c;
	cin >> a >> c >> b;
	if(c=='+'){
		cout << a + b << endl;
	}
	else{
		cout << a - b << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Test01
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力1(H, W)
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int H = input[0];
            int W = input[1];
            
            char[,] map = new char[H, W];  //グリッド情報
            for(int i = 0; i < H; i++)
            {
                //入力2(row)
                string row = Console.ReadLine();
                for(int j = 0; j < W; j++)
                {
                    map[i, j] = row[j];
                }
            }

            //それぞれ(i, j)において(左右上下)いくつまで明るくなるか、(i, j)を含む
            int[,] L = new int[H, W];
            int[,] R = new int[H, W];
            int[,] D = new int[H, W];
            int[,] U = new int[H, W];

            //L
            for(int i = 0; i < H; i++)
            {
                for(int j = 0; j < W; j++)
                {
                    if (map[i, j] == '#') L[i, j] = 0;
                    else if (j == 0) L[i, j] = 1;
                    else L[i, j] = L[i, j - 1] + 1;
                }
            }

            //R
            for(int i = 0; i < H; i++)
            {
                for(int j = W - 1; j >= 0; j--)
                {
                    if (map[i, j] == '#') R[i, j] = 0;
                    else if (j == W - 1) R[i, j] = 1;
                    else R[i, j] = R[i, j + 1] + 1;
                }
            }

            //U
            for(int j = 0; j < W; j++)
            {
                for(int i = 0; i < H; i++)
                {
                    if (map[i, j] == '#') U[i, j] = 0;
                    else if (i == 0) U[i, j] = 1;
                    else U[i, j] = U[i - 1, j] + 1;
                }
            }

            //D
            for(int j = 0; j < W; j++)
            {
                for(int i = H - 1; i >= 0; i--)
                {
                    if (map[i, j] == '#') D[i, j] = 0;
                    else if (i == H - 1) D[i, j] = 1;
                    else D[i, j] = D[i + 1, j] + 1;
                }
            }

            //L, R, U, Dから各マスでの明りマスを計算、maxを更新
            int max = 0;  //明るくできるマスの最大数
            for(int i = 0; i < H; i++)
            {
                for(int j = 0; j < W; j++)
                {
                    max = Math.Max(max, L[i, j] + R[i, j] + U[i, j] + D[i, j] - 3);
                }
            }

            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 85448
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> II;

// From The Programming Contest Challendge Book
vector<int> G[2000];
int match[2000];
bool used[2000];

void add_edge(int u, int v) {
	G[u].push_back(v);
	G[v].push_back(u);
}

bool dfs(int v) {
	used[v] = true;
	int i;
	for (i = 0; i < (int)G[v].size(); ++i) {
		int u = G[v][i];
		int w = match[u];
		if (w < 0 || !used[w] && dfs(w)) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int main(int argc, char *argv[]) {
	int n;
	vector<II> red, blue;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		red.push_back(II(a, b));
	}
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		blue.push_back(II(a, b));
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (red[i].first < blue[j].first && red[i].second < blue[j].second) {
				add_edge(i, j + n);
			}
		}
	}

	fill(match, match + 2 * n, -1);
	int ans = 0;
	for (int v = 0; v < n; ++v) {
		if (match[v] < 0) {
			fill(used, used + 2 * n, false);
			if (dfs(v)) {
				++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
main = do
    _ <- fmap (map read . words)getLine :: IO [Int]
    xs <- fmap (map read . words)getLine :: IO [Int]
    putStrLn $ solve xs

solve :: [Int] -> String
solve xs = case m xs of
    (four, two, one) | two == 0 && one <= four + 1 -> "Yes"
                     | two /= 0 && one <= four -> "Yes"
                     | otherwise -> "No"
m = foldl f (0, 0, 0)
  where
    f (four, two, one) x | x `mod` 4 == 0 = (four + 1, two, one)
                         | x `mod` 2 == 0 = (four, two + 1, one)
                         | otherwise      = (four, two, one + 1)


Measured memory_bytes: 59772
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, k): (usize, usize) = parse!(it, 2);
    if k > (n - 1) * (n - 2) / 2 {
        println!("{}", -1);
        return;
    }
    let mut e: Vec<(usize, usize)> = (1..n).map(|i| (0, i)).collect();
    let mut k = (n - 1) * (n - 2) / 2 - k;
    let mut l = 1;
    let mut r = 2;
    while k > 0 {
        e.push((l, r));
        r += 1;
        if r >= n {
            l += 1;
            r = l + 1;
        }
        k -= 1;
    }
    println!("{}", e.len());
    for (i, j) in e {
        println!("{} {}", i + 1, j + 1);
    }
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_main() {
        test();
    }
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] s = scanner.nextLine().split(" ", 3);
        char c1 = s[0].charAt(0);
        char c2 = s[1].charAt(0);
        char c3 = s[2].charAt(0);
        int diff = 'A' - 'a';
        System.out.printf("%c%c%c\n", c1 + diff, c2 + diff, c3 + diff);
    }
}


Measured memory_bytes: 21588
h, w = map(int, input().split())
tizu = [input() for _ in range(h)]
h_s = [False for _ in range(h)]
w_s = [False for _ in range(w)]
for i in range(h):
  for j in range(w):
    if tizu[i][j] == "#":
      h_s[i] = True
      w_s[j] = True

for i in range(h):
  if not h_s[i]:
    continue
  row = ""
  for j in range(w):
    if w_s[j]:
      row += tizu[i][j]
  print(row)

Measured memory_bytes: 67608
n=int(input())
w=list(map(int,input().split()))
r=[0]*(n-1)
rw=0
l=[0]*(n-1)
lw=0
ans=[]
for i in range(n-1):
    r[i]=rw+w[i]
    rw+=w[i]
    l[n-2-i]=lw+w[n-1-i]
    lw+=w[n-1-i]
for i in range(len(r)):
    ans.append(abs(r[i]-l[i]))
print(min(ans))

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

signed main() {
	int a ; 
	long double b ; 
	cin >> a >> b; 
	long double x = a*b ; 
	int ans = floor(x) ; 
	cout << ans << endl ; 
	return 0 ; 
}

Measured memory_bytes: 3728
n,k = map(int,input().split())
MOD = 10**9+7

FAC = [1]
INV = [1]
for i in range(1,2*n+1):
  FAC.append((FAC[i-1]*i) % MOD)
  INV.append(pow(FAC[-1],MOD-2,MOD))

def nCr(n,r):
  return FAC[n]*INV[n-r]*INV[r]

ans = 0
for i in range(min(n-1,k)+1):
  ans += nCr(n,i)*nCr(n-1,n-i-1)
  ans %= MOD
print(ans)


Measured memory_bytes: 98672
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    ll ans = 0;
    for (ll i = 0; i < s.size() / 2; i++)
    {
        if (s[i] != s[s.size() - 1 - i])
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
ll convert(string s){
    ll res = 0;
    ll t = 1e9;
    bool flag = false;
    for(auto x: s){
        if(x != '.'){
            if(flag)t/=10;
            res = res * 10 + x - '0';
        }else{
            flag = true;
        }
    }
    return res * t;
}
int get(ll x, ll d){
    int cnt = 0;
    while(x%d==0){
        cnt++;
        x/=d;
    }
    return cnt;
}
int cnt[100][100];
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    ll ans = 0;
    rep(i,n){
        string s;
        cin >> s;
        a[i] = convert(s);
        int x = get(a[i], 2);
        int y = get(a[i], 5);
        rep(j,60)rep(k,60){
            if(min(x + j, y + k) >= 18){
                ans += cnt[j][k];
            }
        }
        cnt[x][y]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
 

int main() {
    map<int,int> m;
    int n,k;
    cin >> n>>k;
    ll sum=0;
    vector<int> h(n);
    rep(i,n){
        cin >> h[i];
    }
    sort(ALL(h));
    if(n<=k) {
        cout << 0 << endl;
        return 0;
    }
    rep(i,n-k){
        sum += h[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e5+10,mod=1e9+7;

int main ()
{
    FASTIO
    ll n;
    cin >> n;
    map<string,bool> Map;
    while(n--){
        string s;
        cin >> s;
        Map[s];
    }
    cout << Map.si << endl;
    return 0;
}
/**

*/


Measured memory_bytes: 19228
#include <bits/stdc++.h>
using namespace std;
 
bool cmp(char a, char b)
{
	return a>b;
}
 
int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), cmp);
    
    if(s<t)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
      
    return 0;
}

Measured memory_bytes: 256
n = int(input())
arr = list(map(int,input().split()))

cnt = {}
for a in arr:
    if a not in cnt:
        cnt[a] = 1
    else:
        cnt[a] += 1

comb = {}

sums = 0
for key in cnt.keys():
    t1 = cnt[key]*(cnt[key]-1)
    t2 = (cnt[key]-2)*(cnt[key]-1)
    comb[key] = [t1//2,t1//2-t2//2]
    sums += t1//2

for i in range(n):
    print(sums-comb[arr[i]][1])



Measured memory_bytes: 39968
import sys
import fractions

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def main():
    A, B, C, D = MAP()
    E = lcm(C, D)
    nc = (B // C) - ((A - 1) // C)
    nd = (B // D) - ((A - 1) // D)
    ne = (B // E) - ((A - 1) // E)
    print(B - A + 1 - (nc + nd - ne))
if __name__ == '__main__':
    main()


Measured memory_bytes: 66156
#include<iostream>
#include<vector>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	return b % a ? gcd(b % a, a) : a;
}

vector<pair<ll, int>> soinsu(ll g) {
	vector<pair<ll, int>> res; //戻り値vector:res
	for (ll i = 2; i * i <= g; i++) {
		if (g % i == 0) {
			res.emplace_back(i, 0); //iという素因数がresに格納される
			while (g % i == 0) {
				g = g / i;
				res.back().second++;
			}
		}
	}
	if (g != 1) res.emplace_back(g, 1);
	return res;
}

int main() {
	ll a, b;
	cin >> a >> b;
	ll g = gcd(a, b);
	//vector<pair<ll, int>> soinsu_v = soinsu(g);
	cout << soinsu(g).size() + 1 << endl;
	return 0;
}

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

using namespace std;

int ctoi(char ch)
{
	if ('0' <= ch && ch <= '9')
	{
		return (int)(ch - '0');
	}
	else
	{
		return -1;
	}
}

int N_in(string s)
{
	return ctoi(s[1]);
}

bool isStable(vector<string> after, vector<string> before)
{
	vector<char> a_suitseq;
	vector<char> b_suitseq;
	vector<int> countval(10, 0);
	for (int i = 0; i < after.size(); i++)
	{
		countval[N_in(after[i])]++;
	}
	for (int i = 0; i < 10; i++)
	{
		if (countval[i] > 1)
		{
			a_suitseq.resize(countval[i], '\0');
			b_suitseq.resize(countval[i], '\0');
			for (int j = 0; j < after.size(); j++)
			{
				for (int k = 0; k < countval[i]; k++)
				{
					if (i == N_in(after[j]))
					{
						a_suitseq[k] = after[j][0];
					}
					if (i == N_in(before[j]))
					{
						b_suitseq[k] = before[j][0];
					}
				}
			}
			if (a_suitseq != b_suitseq)
			{
				return false;
			}
		}
	}
	return true;
}

vector<string> bubbleSort(vector<string> a)
{
	string tmp;
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = a.size() - 1; j > i; j--)
		{
			if (N_in(a[j - 1]) > N_in(a[j]))
			{
				tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
			}
		}
	}
	return a;
}

vector<string> selectionSort(vector<string> a)
{
	int min;
	string tmp;
	for (int i = 0; i < a.size(); i++)
	{
		min = i;
		for (int j = i; j < a.size(); j++)
		{
			if (N_in(a[j]) < N_in(a[min]))
			{
				min = j;
			}
		}
		if (min != i)
		{
			tmp = a[i];
			a[i] = a[min];
			a[min] = tmp;
		}
	}
	return a;
}

int main()
{
	int n;
	cin >> n;
	vector<string> a(n);
	vector<string> bubble(n);
	vector<string> selection(n);
	double tmp;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	bubble = bubbleSort(a);
	selection = selectionSort(a);
	for (int i = 0; i < n; i++)
	{
		cout << bubble[i];
		if (i == n - 1)
		{
			cout << endl;
		}
		else
		{
			cout << " ";
		}
	}
	if (isStable(bubble, a))
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}
	for (int i = 0; i < n; i++)
	{
		cout << selection[i];
		if (i == n - 1)
		{
			cout << endl;
		}
		else
		{
			cout << " ";
		}
	}
	if (isStable(selection, a))
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}
}


Measured memory_bytes: 3240