akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
	freopen("filename.in", "r", stdin);
	freopen("filename.out", "w", stdout);
}

int n, m, p, q, a[20005];

int main() {
	//file_put();

	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", &p, &q);
		a[p]++;
		a[q]++;
	}
	for (int i = 1; i <= n - 1; i++) printf("%d\n", a[i]);
	printf("%d\n", a[n]);

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <queue>

using namespace std ;

priority_queue<double,deque<double>,greater<double> >Q;
int n , a ;
int main ()
{
	int i ;
	scanf("%d",&n);
	for ( i=1 ; i<=n ; i++ ) scanf("%d",&a),Q.push(1.0*a);
	for ( i=1 ; i<n ; i++ )
	{
		double A=Q.top(); Q.pop();
		double B=Q.top(); Q.pop();
		Q.push((A+B)/2.0);
	}
	printf("%.6lf\n",Q.top());
	return 0 ;
}


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

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

vector<int> A(100010, 0);

void gather_children(string S) {
    int N = S.length() - 1;
    int left = 1;
    int right = 2;
    for (int i = 1; i <= N; i++) {
        if (S[i] == 'R') {
            chmin(left, i);
        }
        if (S[i] == 'L' && S[i - 1] == 'R') {
            if (i == N) right = N + 1;
            for (int j = i + 1; j <= N; j++) {
                if (S[j] == 'R') {
                    right = j;
                    break;
                } else if (j == N) {
                    right = N + 1;
                }
            }
            A[i]++;
            A[i] += (i - left) / 2;
            A[i] += (right - i - 1) / 2;
            A[i - 1]++;
            A[i - 1] += (i - 1 - left) / 2;
            A[i - 1] += (right - (i - 1) - 1) / 2;
            left = MAX;
        }
    }
}

void print_children(string S) {
    gather_children(S);
    int N = S.length() - 1;
    for (int i = 1; i <= N; i++) {
        printf("%d ", A[i]);
    }
    printf("\n");
}

int main() {
    string S;
    cin >> S;
    S.insert(0, " ");

    print_children(S);

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;
constexpr int MAX = 2000200;
constexpr double EPS = 1E-11;

using namespace std;

int main() {
	ll a, b, x; cin >> a >> b >> x;

	ll a_waru = a / x;
	ll b_waru = b / x;

	ll ans = b_waru - a_waru;
	
	if (a % x == 0)ans++;

	cout << ans << endl;
}

Measured memory_bytes: 256
S,Q=input(),int(input())
l,r='',''
reverse=0
for i in range(Q):
    T=input().split()
    if T[0]=='1':reverse=0 if reverse else 1
    else:
        if T[1]=='1':
            if reverse:r=r+T[2]
            else:l=T[2]+l
        else:
            if reverse:l=T[2]+l
            else:r=r+T[2]
if reverse:
    s=list(l+S+r);s.reverse()
    print(''.join(s))
else:
    print(l+S+r)

Measured memory_bytes: 12160
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 99999999999999999;
const long long MOD = 1e9 + 7;
const double pi = 3.1415926535897932384626;
const int SIZE = 1 << 17;

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

	if (n < 4) cout << "No" << endl;
	else {
		if (n % 4 == 0 || n % 7 == 0) cout << "Yes" << endl;
		else {
			while (n >= 11) {
				n -= 11;
				if (n % 4 == 0 || n % 7 == 0) {
					cout << "Yes" << endl;
					return 0;
				}
			}
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 256
import numpy as np
h, w, k = map(int, input().split())
_map = np.zeros((h, w), dtype = int)
ans = 0
for i in range(h):
  _str = list(input())
  for j in range(w):
    if (_str[j] == "#"):
      _map[i, j] = 1
      
for i in range(2**(h + w)):
  _array = np.copy(_map)
  for j in range(h + w):
    if ((i >> j) & 1):
      if j < h:
        _array[j, :] = 0
      else:
        _array[:, j - h] = 0
  if np.sum(_array) == k:
    ans += 1
print(ans)

Measured memory_bytes: 27060
from math import factorial
N, M = map(int, input().split())
DIV = 10**9 + 7
diff = abs(N - M)
if diff > 1:
    print(0)
    exit()
ans = 1
ans *= factorial(N) % DIV
ans *= factorial(M) % DIV
if diff == 0:
    ans *= 2
print(ans % DIV)


Measured memory_bytes: 4092
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int arr[5],ans=0,m=-1;
  for(int i=0;i<5;i++) cin>>arr[i];
  for(int i=0;i<5;i++)
  {
    int x=(int)ceil(arr[i]/10.0)*10;
    ans+=x;
    m=max(m,x-arr[i]);
    // cout<<x<<endl;
  }
  cout<<ans-m<<endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// https://beta.atcoder.jp/contests/arc065/tasks/arc065_b

fn node_to_list(node_num: usize, link_num: usize, sc: &mut Scanner) -> Vec<Vec<usize>> {
    let mut ret: Vec<Vec<usize>> = vec![Vec::new(); node_num];
    for i in 0..link_num {
        let (p, q): (usize, usize) = (sc.read(), sc.read());
        ret[p-1].push(q-1); ret[q-1].push(p-1);
    }
    ret
}

fn dfs(
    paths: &Vec<Vec<usize>>,
    cnct: &mut Vec<i32>,
    p: usize,
    num: i32
) {
    cnct[p] = num;
    for next in paths[p].iter() {
        if cnct[*next] == -1 {
            dfs(paths, cnct, *next, num);
        }
    }
}

fn main() {
    let cin = stdin(); let cin = cin.lock(); let mut sc = Scanner::new(cin);

    let (n, k, l): (usize, usize, usize) = (sc.read(), sc.read(), sc.read());
    let pqs: Vec<Vec<usize>> = node_to_list(n, k, &mut sc);
    let rss: Vec<Vec<usize>> = node_to_list(n, l, &mut sc);
    
    let mut c1: Vec<i32> = vec![-1; n];
    let mut cnt = 0;
    for i in 0..n {
        if c1[i] == -1 {
            cnt += 1;
            dfs(&pqs, &mut c1, i, cnt);
        }
    }
    cnt = 0;
    let mut c2: Vec<i32> = vec![-1; n];
    for i in 0..n {
        if c2[i] == -1 {
            cnt += 1;
            dfs(&rss, &mut c2, i, cnt);
        }
    }

    let mut cncts = HashMap::new();
    for i in 0..n {
        let num = cncts.entry((c1[i], c2[i])).or_insert(0);
        *num += 1;
    }
    for i in 0..n {
        if i < n-1 { print!("{} ", cncts.get(&(c1[i], c2[i])).unwrap()); }
        else { println!("{}", cncts.get(&(c1[i], c2[i])).unwrap()); }
    }
}



Measured memory_bytes: 39164
s = input()
n = len(s)
for i in range(n-1):
    if s[i] == s[i+1]:
        print(i+1,i+2)
        exit()
for i in range(n-2):
    if s[i] == s[i+2]:
        print(i+1, i+3)
        exit()
print(-1,-1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < (n) ; i++ )
using ll = long long;

using namespace std;
int main(){
    int n,k,d;cin>>n>>k;
    map<int,int> m;
    rep(i,n+1){
        m[i+1]--;
    }
    rep(i,k){
        cin>>d;
        rep(j,d){
            int a; cin>>a;
            m[a]++;
        }
    }
    int ans=0;
    for(int i=1;i<n+1;i++){
        if(m[i] < 0){ans++;}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
k, n = map(int, input().split())
aa = list(map(int, input().split()))
 
mdiff = 0
for i in range(n):
    mdiff = max(mdiff, abs(k + aa[i] - aa[i - 1]) % k)
if n == 2:
    print(mdiff)
else:
    print(k - mdiff)


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

int main(){//main_program
  int N;
  int64_t sum = 0;
  int64_t kei = 0;
  cin >> N;
  vector<int> A(N);
  vector<int64_t> B(N);
  
  for(int i = 0;i<N;i++){
    cin >> A.at(i);
    B.at(i) = A.at(i)%1000000007;
  }
  
  for(int i = N-1;i>0;i--){
    kei += B.at(i);
    kei %= 1000000007;
    sum += (B.at(i-1) * kei);
    sum %= 1000000007;
  }
  
  cout << sum <<endl;
  
}

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

int main() {
    int A, B;
    cin >> A >> B;

    string S;
    cin >> S;

    if (S.size() != A+B+1) {
      cout << "No" << endl;
      return 0;
    }
  
    try {
        int num1 = stoi(S.substr(0, A));
        int num2 = stoi(S.substr(A+1, B));
    }
    catch (const invalid_argument& e) {
        cout << "No" << endl;
        return 0;
    }

    if (S[A]!='-') {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3764
"use strict"
function Main(input) {
  input = input.trim().split('\n');
  let WHN = input[0].split(' ').map(Number);
  let minX = 0;
  let minY = 0;
  let maxX = WHN[0];
  let maxY = WHN[1];
  const N = WHN[2];
 
  for(let i=1; i<=N; i++){
    let tmp = input[i].trim().split(' ').map(Number)
    let A = tmp[2];
    if(A === 1){
      if(tmp[0] > minX){
        minX = tmp[0];
      }
    } else if (A === 2) {
      if(tmp[0] < maxX){
        maxX = tmp[0];
      }
    } else if (A === 3) {
      if(tmp[1] > minY) {
        minY = tmp[1];
      }
    } else if (A === 4) {
      if(tmp[1] < maxY) {
        maxY = tmp[1];
      }
    }
  }
 
  const X = maxX - minX;
  const Y = maxY - minY;
  if(X <= 0 || Y <= 0){
    console.log(0);
  } else {
    console.log(X*Y);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ff first
#define ss second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define loopf(i,a,b) for(int i = a;i < b;i++)
#define loopb(i,a,b) for(int i = a;i >= b;i--)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;


int32_t main()
{
    fast

   int test=1;
   //cin>>test;

  
  while(test--)
  {
    int n,x;
    cin>>n;
    vi freq(n+1,0);
 
    for(int i=1;i<n;i++)
    {
      cin>>x;
      freq[x]++;
    }
    for(int i=1;i<=n;i++)cout<<freq[i]<<endl;

  // while loop ending
   }
  

return 0;
}

Measured memory_bytes: 4780
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;

class UnionFind{
public:
	vector<ll> par;
	vector<ll> d;
	//0-indexed
	UnionFind(ll n){
		init(n);
	}
	void init(ll n = 1) {
		par.resize(n);
		d.resize(n,0);
		for (ll i = 0; i < n; ++i) par[i] = i;
	}
	ll len1(ll x){
		if(par[x]==x)return 0;
		ll ans = d[x];
		ans += len1(par[x]);
		return ans;
	}
	ll root(ll x = 1){
		if(par[x]==x)return x;
		else{
			d[x] = len1(par[x]) + d[x];
			return par[x] = root(par[x]);
		}
	}
	ll length(ll x,ll y){
		return len1(y) - len1(x);
	}
	void unite(ll x,ll y,ll dd){
		dd += len1(x);x=root(x);
		dd -= len1(y);y=root(y);
		if(x==y)return;
		if(dd>=0){
			d[y] = dd;
			par[y] = x;
		}else{
			d[x] = -dd;
			par[x] = y;
		}
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	//ifstream in("input.txt");
	//cin.rdbuf(in.rdbuf());
	ll n,m;
	cin >> n >> m;
	UnionFind uf(n+1);
	ll l,r,d;
	FOR(i,0,m){
		cin >> l >> r >> d;
		if(uf.root(l)==uf.root(r)){
			if(uf.length(l,r)!=d){
				cout << "No" << endl;
				return 0;
			}
		}else{
			uf.unite(l,r,d);
			//cout << uf.length(l,r) << endl;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353

ll lcm(ll x, ll y){
	return x/__gcd(x,y)*y;
}

ll powe(ll a, ll b){ //aのb乗のmod
	ll ret = 1;
	while(0 < b){
		if((b%2) == 0){
			a = (a*a);
			b >>= 1;
		}
		else{
			ret = (ret*a);
			b--;
		}
	}
	return ret;
}

int main(){
	ll n, m, x, y; cin >> n >> m;
	vector<ll> a(110000);
	REP(i,n){
		cin >> x;
		a.at(i) = x/2;
	}
	bool jud = true;ll cnt = 0; x = a.at(0);
	while (x>1){
		if (x%2==0){
			x/=2;
			cnt++;
		}
		else{
			break;
		}
	}
	REP(i,n){
		y = a.at(i);
		if (y%(powe(2,cnt))!=0) jud=false;
		else if ((y/powe(2,cnt))%2==0) jud=false;
	}

	if (jud==false){
		cout << 0 << endl;
	}
	else{
		ll minans = a.at(0);
		FOR(i,1,n-1) minans = lcm(minans,a.at(i));
		cout << ((m/minans)+1)/2 << endl;
	}
}

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

bool compare(string a, string b) {
    if (a.length() == b.length()) {
        for (int i = 0; i < a.length(); i++) {
            if (a[i] == b[i]) continue;
            else return a[i] < b[i];
        }
    } else {
        return a.length() < b.length();
    }
    return true;
}

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> match = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    vector<vector<string>> dp(20, vector<string>(N + 5, ""));
    vector<int> use(M);
    for (int i = 0; i < M; i++) cin >> use[i];
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < M; j++) {
            for (int k = 0; k < M; k++) {
                if (match[use[k]] > i) continue;
                // cout << i << " " << j << " " << k << endl;
                if (dp[use[k]][i - match[use[k]]] != "" || i - match[use[k]] == 0) dp[use[j]][i] = max(dp[use[j]][i], dp[use[k]][i - match[use[k]]] + to_string(use[k]), compare);
            }
        }
    }
    string ans = "";
    for (int i = 1; i <= 10; i++) ans = max(ans, dp[i][N], compare);
    cout << ans << endl;
}



Measured memory_bytes: 286208
def m():
    x = int(input())

    if 400 <= x <=599:
        return 8
    if 600 <= x <=799:
        return 7
    if 800 <= x <=999:
        return 6
    if 1000 <= x <=1199:
        return 5
    if 1200 <= x <=1399:
        return 4
    if 1400 <= x <=1599:
        return 3
    if 1600 <= x <=1799:
        return 2
    if 1800 <= x <=1999:
        return 1

print(m())


Measured memory_bytes: 9176
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <cmath>
#include <ctime>
#include <iostream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forv(i, v) forn(i, v.size())
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back

const int P2 = 1e5 + 10;
const int P3 = 3.2e3;

const ll NOP = 5e18;

int main() {
#ifdef NEREVAR_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vl a(n);
    forn(i, n) {
        scanf("%lld", &a[i]);
    }
    vi used(P2);
    vi primes;
    for (int i = 2; i < P2; i++) {
        if (!used[i]) {
            primes.pb(i);
            for (int j = i + i; j < P2; j += i) {
                used[j] = true;
            }
        }
    }
    
    map<ll, int> cnt;
    map<ll, ll> opp;
    
    forn(i, n) {
        ll x = a[i];
        ll dir = 1, rev = 1;
        for (int p : primes) {
            if (p > P3) break;
            
            int deg = 0;
            while (x % p == 0) {
                x /= p;
                deg++;
            }
            
            if (deg) {
                deg %= 3;
                forn(j, deg) dir *= p;
                forn(j, (3 - deg) % 3) rev *= p;
            }
        }
        
        if (x > 1) {
            ll y = (ll)(sqrt(x + 0.5));
            dir *= x;
            if (y * y == x) {
                rev *= y;
            } else {
                if (rev * 1.0 * x * x <= 4e18) {
                    rev *= x * x;
                } else {
                    rev = NOP;
                }
            }
        }
        
        //cerr << a[i] << " " << dir << " " << rev << endl;
        
        opp[dir] = rev;
        cnt[dir]++;
    }
    
    int ans = 0;
    
    for (auto& p : cnt) {
        ll x = p.first;
        if (opp[x] == NOP) {
            ans += cnt[x];
        } else {
            ll y = opp[x];
            if (cnt.count(y) == 0) {
                ans += cnt[x];
            } else if (x < y) {
                ans += max(cnt[x], cnt[y]);
            }
        }
    }
    
    if (cnt.count(1ll)) ans++;
    
    cout << ans << endl;
    
    return 0;
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

typedef pair<int, int> ii;

int A[25];
int B[25];

int perm[25];

int set1[25];
int set2[25];

const int INF = 1012345678;

long long nxs(long long r){
    long long ls1 = r&(-r);
    long long rest = r+ls1;
    return rest|(((rest^r)/ls1) >> 2);
}

int main(){
    int N;
    scanf("%d", &N);

    for(int i = 0; i < N; i ++){
        scanf("%d", &A[i]);
    }

    for(int i = 0; i < N; i ++){
        scanf("%d", &B[i]);
    }

    int ans = INF;
    int noBits = (N+1)>>1;
    for(int i = (1<<noBits)-1; i < (1<<N); i = nxs(i)){
        //printf("i=%d\n", i);
        int size1 = 0;
        int size2 = 0;
        for(int j = 0; j < N; j ++){
            if(i&(1<<j)){
                // Place in first set, parity is even (0-indexed)
                if((j&1) == 0){
                    set1[size1++] = (A[j]<<6)|j;
                }else{
                    set1[size1++] = (B[j]<<6)|j;
                }
            }else{
                // Place in second set, parity is odd
                if((j&1) == 0){
                    set2[size2++] = (B[j]<<6)|j;
                }else{
                    set2[size2++] = (A[j]<<6)|j;
                }
            }
        }

        sort(set1, set1+size1);
        sort(set2, set2+size2);

        bool boleh = true;
        for(int j = 0; j < (int)size2; j ++){
            //printf("set1[%d]=ii(%d, %d), set2[%d]=ii(%d, %d)\n", j, set1[j].first, set1[j].second, j, set2[j].first, set2[j].second);
            if((set1[j]>>6) > (set2[j]>>6)){
                boleh = false;
                break;
            }

            if( ((N&1) == 0) && j == (int)size2-1 ){
                break;
            }

            if( (set1[j+1]>>6) < (set2[j]>>6) ){
                boleh = false;
                break;
            }
        }

        if(boleh){
            for(int j = 0; j < size2; j ++){
                perm[j<<1] = set1[j]&63;
                perm[(j<<1)|1] = set2[j]&63;
            }
            if(N&1){
                perm[N-1] = set1[size2]&63;
            }

            int inv = 0;
            for(int j = 0; j < N; j ++){
                for(int k = j+1; k < N; k ++){
                    if(perm[j] > perm[k]){
                        inv ++;
                    }
                }
            }

            ans = min(ans, inv);
        }
    }

    if(ans == INF){ans = -1;}
    printf("%d", ans);
    return 0;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    int ans = 700;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'o') ans += 100;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
 
struct Node{ int p, l, r;};
struct Node T[MAX];
int n, H, D[MAX];
 
int getDepth(int u){
  int d = 0;
  int i = 0;
  while(1){
    if(T[u].p == NIL) break;
    d++;
    u = T[u].p;
  }
  return d;
}
 
void print(int u){
  int a;
   
  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);
   
  if( T[u].p == NIL) printf("root, [");
  else if(T[u].l == NIL) printf("leaf, [");
  else printf("internal node, [");
   
  a = T[u].l;
  if( a != NIL){
    while(1){
      if(T[a].r == NIL){
    printf("%d",a);
    break;
      }
      else {
    printf("%d, ",a);
    a = T[a].r;
      }
    }
  }
 
    printf("]\n");
}
 
main(){
  int i, j, d, v, c, l;
  int pre;
  scanf("%d", &n);
   
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
   
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
       
      if(j == 0){
    T[v].l = c;
    T[c].p = v;
    pre = c; 
      }
      else if(j != 0){
    T[pre].r = c;
    T[c].p = v;
    pre = c;
      }
    }
  }
   
  for ( i = 0; i < n; i++ ){
    D[i] = getDepth(i);
  }
 
  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}

Measured memory_bytes: 2172
use std::io::Read;
use std::collections::HashMap;

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

    let answer = solve(&buf);

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

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

    let n: u32 = iterator.next().unwrap().parse().unwrap();

    let mut map = HashMap::new();
    for i in 1..(n + 1) {
        let pair = pair(i);
        let count = map.entry(pair).or_insert(0_u32);
        *count += 1;
    }

    let mut ans: u64 = 0;
    for i in 1..(n + 1) {
        let pair = pair(i);
        let count = map.get(&(pair.1, pair.0));
        if let Some(u) = count {
            ans += *u as u64
        }
    }

    return ans.to_string();
}

fn pair(i: u32) -> (u32, u32) {
    let last: u32 = i % 10;
    let first: u32 = i.to_string().chars().nth(0).unwrap().to_digit(10).unwrap();
    return (first, last);
}

#[test]
fn test() {
    assert_eq!(
        solve(
            r"25"
        ),
        "17"
    );
    assert_eq!(
        solve(
            r"1"
        ),
        "1"
    );
    assert_eq!(
        solve(
            r"100"
        ),
        "108"
    );
    assert_eq!(
        solve(
            r"200000"
        ),
        "400000008"
    );
}


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

int n, d; 
int main()
{
    cin >> d >> n;
    int ans = pow(100, d) * n;
    if (n == 100) 
        ans += pow(100, d);
    cout << ans << endl;
	return 0;
}

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

int main() {
	int X;
	cin >> X;
	int res=0;
	for (int b = 1; b <= sqrt(X); b++) {
		for (int p = 2; p <= 10; p++) {
			int bp = pow(b, p);
			if (bp <= X&&bp > res) res = bp;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// #define endl "\n"

ll recurse(ll i, ll k, vector<ll>& height, vector<ll>& dp) {
    ll n = dp.size();

    if (i == n - 1) {
        return 0;
    }

    if (i == n - 2) {
        return abs(height[n - 1] - height[n - 2]);
    }

    if (dp[i] != -1) {
        return dp[i];
    }

    ll ans = INT_MAX;
    for (ll next = i+1; next <= min(i+k, n-1); next++) {
        ll cost = abs(height[next] - height[i]) + recurse(next, k, height, dp);
        ans = min(ans, cost);
    }

    dp[i] = ans;
    return dp[i];
}

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

    ll n, k;
    cin >> n >> k;
    vector<ll> arr(n);
    for (ll i = 0; i < n; i++) {
        cin >> arr[i];
    }

    vector<ll> dp(n, -1);
    cout << recurse(0, k, arr, dp);

    return 0;
}

Measured memory_bytes: 11136
#include <iostream>

using namespace std;

int main()
{
    int w, h, x, y, r;
    cin>>w>>h>>x>>y>>r;
    if((x+r)>w || (x-r)<0 || (y+r)>h || (y-r)<0 || x<0 || y<0) cout<<"No";
    else cout<<"Yes";
    cout<<"\n";
    return 0;
}



Measured memory_bytes: 3076
n = int(input())
s = input()

ans = 0
tmp = s[0]
cnt = 1
pos = 0

while True:
    if cnt >= n:
        ans += 1
        break

    if s[cnt] != tmp:
        pos = cnt
        ans += 1
    
    tmp = s[cnt]
    cnt += 1

print(ans)


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

int main(){
  while(true){ 
    int h, w;
    cin >> h >> w;
    if(h == 0 && w == 0){ 
      break;
    }
    for(int i = 1; i < h + 1; i++){
      if(i % 2 != 0){
      //奇数行目は＃から始まる
        for(int j = 1; j <= w + 1; j++){
          if(j % 2 != 0 && j != w + 1){
            cout << "#";
          }
          else if(j % 2 == 0 && j != w + 1){
            cout << "." ;
          }
          else if(j == w + 1){
            cout << endl;
          }
        }
      }
      else if(i % 2 == 0){
      //偶数行は.になる
        for(int j = 1; j <= w + 1; j++){
          if(j % 2 != 0 && j != w + 1){
            cout << ".";
          }
          else if(j % 2 == 0 && j != w + 1){
            cout << "#" ;
          }
          else if(j == w + 1){
            cout << endl;
          }
        }
      }
      if(i == h){
        cout << endl;
      }
    }
    
  }

}




Measured memory_bytes: 3092
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextLineInt() int {
	b, _ := strconv.Atoi(nextLine())
	return b
}

func nextLineIntSlice() []int {
	a := strings.Split(nextLine(), " ")
	var b []int
	for _, v := range a {
		t, _ := strconv.Atoi(v)
		b = append(b, t)
	}
	return b
}

func main() {
	n := nextLineInt()
	m := nextLineIntSlice()

	var min, max int
	for i := 0; i < n; i++ {
		if min == 0 || min > m[i] {
			min = m[i]
		}
		if max < m[i] {
			max = m[i]
		}
	}
	fmt.Println(max - min)

}

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


using namespace std;


void white_cells()
{
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  cout << (H * W) - (h * W) - (H * w) + (h * w) << "\n";
}


void double_helix()
{
  char b;
  cin >> b;

  if (b == 'A') cout << "T\n";
  else if (b == 'T') cout << "A\n";
  else if (b == 'C') cout << "G\n";
  else  cout << "C\n";

}


int main()
{
  //white_cells();
  double_helix();
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
import collections
import heapq


G_INF = 2 ** 31


class Dijkstra(object):

    def __init__(self, number_of_vertices, adjacency_list, costs, start):
        self.max_v = number_of_vertices
        self.adj = adjacency_list
        self.costs = costs
        self.start = start
        self.dist = None

    def initialize_dist(self):
        self.dist = collections.defaultdict(lambda: G_INF)
        self.dist[self.start] = 0

    def single_source_shortest_path(self):
        self.initialize_dist()
        pq = [(self.dist[v], v) for v in range(self.max_v)]
        heapq.heapify(pq)
        while pq:
            (_, v) = heapq.heappop(pq)
            for u in self.adj[v]:
                new_length = self.dist[v] + self.costs[(v, u)]
                if new_length < self.dist[u]:
                    self.dist[u] = new_length
                    heapq.heappush(pq, (new_length, u))
        return self.dist


def main():
    max_v, max_e, start = map(int, input().split())
    adjacency_list = collections.defaultdict(lambda: array.array("L"))
    costs = collections.defaultdict(lambda: G_INF)
    for _ in range(max_e):
        s, t, d = map(int, input().split())
        adjacency_list[s].append(t)
        costs[(s, t)] = d
    dij = Dijkstra(max_v, adjacency_list, costs, start)
    dist = dij.single_source_shortest_path()
    for v in range(max_v):
        result = dist[v]
        if result < G_INF:
            print(result)
        else:
            print("INF")


if __name__ == '__main__':
    main()

Measured memory_bytes: 161584
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

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

  if(n == 1) {
    ans = 1.0;
  }
  else if(n % 2 == 0) {
    ans = 0.5;
  }
  else {
    ans = (n / 2 + 1) / (double)n;
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for(int i = (int)(s); i < (int)(e); ++i)
#define rep(i, n) REP(i, 0, n)
#define fi first
#define se second

#define LINE /*cout << "LINE : " << __LINE__ << endl*/
#define dumpln(X) /*cout << "LINE:" << __LINE__ << ", "<<#X << " : " << X << endl*/
#define dumpVln(X) /*{cout << "LINE:" << __LINE__ << ", " << #X << " [";for(auto&& x : X) cout << x << ", "; cout << "]" << endl;}*/


using ll = long long;

bool isNum(char c) {
    return c >= '0' && c <= '9';
}
bool isAlpha(char c) {
    return c >= 'A' && c <= 'Z';
}

string S;
ll L;

struct Node {
    int id;
    vector<int> chils;
    string s;
    int num = 1;
    bool isLeaf() {return chils.empty();};
    Node() : num(1), id(-1) {}
};

const int MAX_NODE_SIZE = 101;
Node nodes[MAX_NODE_SIZE];
int nodes_sz;

ll dp[MAX_NODE_SIZE];
ll None = -1e18;

int getNum(int& idx) {
    int num = 0;
    while (isNum(S[idx])) {
        num *= 10;
        num += (S[idx] - '0');
        ++idx;
    }
    return num;
}

Node calc(int& idx) {
    int id = nodes_sz++;
    Node& node = nodes[id];
    node.id = id;
    if (isAlpha(S[idx])) {
        while (idx < S.size() && isAlpha(S[idx])) {
            node.s += S[idx];
            ++idx;
        }
    } else {
        node.num = getNum(idx);
        if (S[idx] == '(') {
            ++idx;
            while (S[idx] != ')') {
                node.chils.push_back(calc(idx).id);
            }
            ++idx;
        } else {
            node.chils.push_back(calc(idx).id);
        }
    }
    return nodes[id];
}


ll dfs(int idx) {
    if (dp[idx] != None) return dp[idx];
    ll& ret = dp[idx];
    Node& node = nodes[idx];
    ll len = 0;
    if (node.isLeaf()) {
        len = node.s.size();
    } else {
        for (auto && id : node.chils) {
            ll tmp = dfs(id);
            if (tmp == -1) return ret = -1;
            len += tmp;
        }
        if (len * node.num > L) return ret = -1;
        len *= node.num;
    }
    return ret = len;
}

string getStr(int id) {
    Node& node = nodes[id];
    if (node.isLeaf()) {
        return node.s;
    }
    string ret, s;
    for (auto && id : node.chils) {
        s += getStr(id);
        if(s.size() > L) return s;
    }
    rep(i, node.num) {
        ret += s;
        if(ret.size() > L) return ret;
    }
    return ret;
}

char dfs2(int idx) {
    char ret;
    Node& node = nodes[idx];
    if(node.chils.size() > 0 && dfs(node.chils.front()) == -1) {
        return dfs2(node.chils.front());
    }
    auto s = getStr(idx);
    return s[L%s.size()];
}

char solve() {
    rep(i, MAX_NODE_SIZE) dp[i] = None;
    int idx = 0;
    while (idx < S.size()) {
        int par = calc(idx).id;
        auto len = dfs(par);
        if (len == -1 || len > L) return dfs2(par);
        else L -= len;
    }
    return '0';
}

int main() {
    while (cin >> S >> L) {
        if (S == "0" && L == 0) break;
        dumpln(S);
        dumpln(L);
        nodes_sz = 0;
        rep(i, MAX_NODE_SIZE) nodes[i] = Node();
        cout << solve() << endl;
        LINE;
    }
    return 0;
}



Measured memory_bytes: 7308
# frozen_string_literal: true

def main
  def check(table, queue, idx)
    return if table[idx].empty?

    opponent = table[idx][0]
    return if table[opponent].empty?

    return unless table[opponent][0] == idx

    idx, opponent = opponent, idx if idx > opponent
    queue << [idx, opponent]
  end
  n = gets.to_i

  a = []

  n.times do
    a << gets.chomp.split(' ').map(&:to_i).map { |i| i - 1 }
  end

  queue = []

  n.times do |i|
    check(a, queue, i)
  end

  day = 0
  until queue.empty?
    day += 1
    queue.uniq!

    prev_q = []
    prev_q, queue = queue, prev_q

    prev_q.each do |pair|
      first, second = pair

      a[first].shift
      a[second].shift

      check(a, queue, first)
      check(a, queue, second)
    end

  end

  a.each do |elem|
    unless elem.empty?
      puts '-1'
      return 0
    end
  end

  puts day
end
main


Measured memory_bytes: 11516
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int a,b,k;
  cin >> a >> b >> k;
  
  if((b-a+1)/2 < k) {
    for(int i = a; i <= b; i++) {
      cout << a << endl;
      a++;;
    }
  }
  else {
    for(int i = 0; i < k; i++) {
      cout << a << endl;
      a++;
    }
    for(int i = 0; i < k; i++) {
      cout << b-k+1 << endl;
      b++;
    }
  }
}

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

int main(){
  int N; cin >> N;
  string S; cin >> S;
  
  int sol = 0;
  
  for(int i=0; i<N-2; i++){
    if(S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C'){
      sol++;
      i += 2;
    }
  }

  cout << sol << endl;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
long long Abs(long long qaq)
{
	if(qaq<0)return -qaq;
	return qaq;
} 
int main()
{
	long long X,K,D;
	scanf("%lld%lld%lld",&X,&K,&D);
	long long Y=X;
	long long Z=K;
	long long tmp=X/D; 
	X=X-tmp*D;
	K=K-Abs(tmp);
	if(K<=0)
	{
		if(Y>=0)
		{
			printf("%lld\n",Abs(Y-Z*D));
		}
		else
		{
			printf("%lld\n",Abs(Y+Z*D));
		}
		return 0;
	}
	if(K%2==0)
	{
		printf("%lld\n",Abs(X));
	}
	else
	{
		if(X<0)
		{
			printf("%lld\n",Abs(X+D));
		} 
		else
		{
			printf("%lld\n",Abs(X-D));
		}
	}
	return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    vector<vector<int>> d(c, vector<int>(c));
    for(int ic=0;ic<c;++ic) {
        for(int jc=0;jc<c;++jc) {
            cin >> d[ic][jc];
        }
    }
    int color;
    vector<vector<int>> grid(c, vector<int>(3, 0));
    for(int in=0;in<n;++in) {
        for(int jn=0;jn<n;++jn) {
            cin >> color; --color;
            ++grid[color][(in+jn+2)%3];
        }
    }

    int ans = 1e9, anstmp;
    for(int c1=0;c1<c;++c1) {
        for(int c2=0;c2<c;++c2) {
            for(int c3=0;c3<c;++c3) {
                if(c1==c2||c2==c3||c3==c1) continue;
                anstmp = 0;
                for(int ic=0;ic<c;++ic) {
                    if(ic!=c1) anstmp += grid[ic][0]*d[ic][c1];
                    if(ic!=c2) anstmp += grid[ic][1]*d[ic][c2];
                    if(ic!=c3) anstmp += grid[ic][2]*d[ic][c3];
                }
                chmin(ans, anstmp);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3560
# frozen_string_literal: true

a, b, c, x, y = gets.split.map(&:to_i)

ans = x * a + y * b

if a + b > c * 2
  tmp = [x, y].min
  ans -= a * tmp + b * tmp
  ans += c * tmp * 2
end

if a > c * 2
  tmp = [x - [x, y].min, 0].max
  ans -= a * tmp
  ans += c * tmp * 2
end

if b > c * 2
  tmp = [y - [x, y].min, 0].max
  ans -= b * tmp
  ans += c * tmp * 2
end

puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD (ll) (1e9+7)
int main()
{
	ll n;
	cin>>n;
	ll ar[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i];
	}
	sort(ar,ar+n);
	ll cnt = 0;
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(ar[i]!=ar[j] && ar[j]!=ar[k] && ar[i]!=ar[k] && ar[i]+ar[j]>ar[k])
				{
					cnt++;
				}
			}
		}
	}
	cout<<cnt<<"\n";
}

Measured memory_bytes: 3608
a = input().split()
n = int(a[0])
m = int(a[1])
qq = int(a[2])
ll = list()
rr = list()

for _ in range(m):
    a = input().split()
    ll.append(int(a[0]))
    rr.append(int(a[1]))

p = list()
q = list()

for _ in range(qq):
    a = input().split()
    p.append(int(a[0]))
    q.append(int(a[1]))

c = [[0 for _ in range(n)] for _ in range(n)]

for i in range(m):
    c[ll[i] - 1][rr[i] - 1] += 1

for i in range(2):
    for j in range(i, n):
        for k in range(1 - i, n):
            c[j][k] += c[j - i][i + k - 1]

for i in range(qq):
    r = 0

    if 0 < q[i]:
        r += c[q[i] - 1][q[i] - 1]

    if 0 < q[i] and 1 < p[i]:
        r -= c[q[i] - 1][p[i] - 2] + c[p[i] - 2][q[i] - 1]

    if 1 < p[i]:
        r += c[p[i] - 2][p[i] - 2]

    print(r)


Measured memory_bytes: 27776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    string S;
    cin >> S;
    ll N = S.size();

    vvc<ll> C(N + 1, vl(26));
    repr(i, N) C[i] = C[i + 1], C[i][S[i] - 'a']++;

    ll ans = 1;
    rep(i, N) ans += accumulate(all(C[i]), 0ll) - C[i][S[i] - 'a'];

    cout << ans << endl;
}

Measured memory_bytes: 51888
#include<stdio.h>
int main(void){
    char map[110][110]={{0}};
    int x,y,i,j,k,sun;
    scanf("%d %d",&y,&x);
    for(i=0;i<y;i++){
        for(j=0;j<x;j++){
            scanf(" %c",&map[j][i]);
        }
    }
    for(i=0;i<y;i++){
        for(j=0;j<x;j++){
            sun=0;
            for(k=j;k>=0;k--){
                if(map[k][i]=='c'){
                    break;
                }else if(k==0){
                    sun=1;
                }
            }
            if(sun==1){
                printf("-1");
            }else{
                printf("%d",j-k);
            }
            if(j==x-1){
                printf("\n");
            }else{
                printf(" ");
            }
        }
    }

    return 0;
}

Measured memory_bytes: 620
//#pragma GCC optimize("Ofast")

#ifdef LOCAL
#include "debug.h"
#else
#include <bits/stdc++.h>
#define debug(x...)
#endif

//#define int ll

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define sz(x) int((x).size())

#ifdef ONLINE_JUDGE
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#else
mt19937 rng(1000 - 7);
#endif

const int N = 2e5 + 10;
const int M = 1e6 + 10;
const int MOD = 998244353;
//const int MOD = 1e9 + 7;
const ld eps = 1e-6;
const pii dir[] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };

const int K = 2;
const ll primes[] = { 227, 229 };
ll pw[M][K];

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    inline size_t operator()(pair <ll, ll> x) const {
        return splitmix64(x.first ^ x.second);
    }
};

int n;
vector <string> v[M], a;
unordered_map <pair <ll, ll>, int, custom_hash> t[26];

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout << fixed << setprecision(9);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;
    a.reserve(n);

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

        v[sz(s)].push_back(s);
    }

    for (int i = 0; i < M; i++) {
        for (string& s : v[i]) {
            a.push_back(s);
        }
    }

    for (int i = 0; i < K; i++) {
        pw[0][i] = 1;
    }

    for (int i = 1; i < M; i++) {
        for (int j = 0; j < K; j++) {
            pw[i][j] = (pw[i - 1][j] * primes[j]) % MOD;
        }
    }

    for (int i = 0; i < 26; i++) {
        t[i].max_load_factor(0.25);
        t[i].rehash(M);
    }

    ll ans = 0;
    for (string s : a) {
        debug(s);

        int p[26] = { 0 };
        for (char c : s) {
            p[c - 'a']++;
        }

        for (int j = 0; j < 26; j++) {
            if (p[j]) {
                ans += t[j][make_pair(0LL, 0LL)];
            }
        }

        ll h[K] = { 0 };
        for (int i = sz(s) - 1; i > 0; i--) {
            for (int j = 0; j < K; j++) {
                h[j] = (h[j] + (s[i] - 'a' + 1) * pw[sz(s) - i - 1][j]) % MOD;
            }

            p[s[i] - 'a']--;
            auto curH = make_pair(h[0], h[1]);
            for (int j = 0; j < 26; j++) {
                if (p[j] && t[j].count(curH)) {
                    ans += t[j][curH];
                }
            }
        }

        t[s.front() - 'a'][make_pair(h[0], h[1])]++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 278812
//
// Created by Hideaki Imamura on 2020-03-22.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll N;
vector<ll> A;
vector<ll> B;

int main() {
    cin >> N;
    A.resize(N);
    B.assign(N + 1, 0);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        B[A[i]]++;
    }

    ll ans = 0;
    for (int i = 1; i <= N; ++i) {
        ans += B[i] * (B[i] - 1) / 2;
    }
    for (int k = 0; k < N; ++k) {
        cout << ans - B[A[k]] * (B[A[k]] - 1) / 2 + (B[A[k]] - 1) * (B[A[k]] - 2) / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

route_lists = [a1, b1, a2, b2, a3, b3]
cnt_lists = []

for i in range(1, 5, 1):
    cnt = route_lists.count(i)
    cnt_lists.append(cnt)

if 3 in cnt_lists:
    ans = 'NO'
else:
    ans = 'YES'

print(ans)

Measured memory_bytes: 9080
n=input()
a=list(map(int,input().split()))
b=[]
c="DENIED"
d=[]

for i in a:
  if i%2 == 0:
    b.append(i)
    
for j in b:
  if j%3 == 0 or j%5 == 0:
    d.append(j)
    
if b == d:
  c = "APPROVED"

print(c)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long Q, H, S, D;
	long N;
	cin >> Q >> H >> S >> D >> N;
	S = min({ S, 4 * Q, 2 * H, (H + 2 * Q) });
	long long ans = min(S * N, D * (N / 2) + S * (N % 2));
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	private static void solve(int q,int digit) {
    	ArrayList<Integer> memo= new ArrayList<Integer>();
    	char[] num= new char[digit];
    	
    	Integer tmp= q;
    	Integer next= q;
		do{
			tmp= next;
			memo.add(tmp);
			
			String buf= tmp.toString();
	    	Arrays.fill(num,'0');
			for(int i=0;i<buf.length();i++){
				num[i]= buf.charAt(i);
			}
			Arrays.sort(num);

			StringBuilder sb_min= new StringBuilder().append(num);
			StringBuilder sb_max= new StringBuilder().append(num).reverse();
			Integer int_min= Integer.valueOf(sb_min.toString());
			Integer int_max= Integer.valueOf(sb_max.toString());
			next= int_max-int_min;
		} while( !memo.contains(next) );
		
		int idx= memo.indexOf(next);
		System.out.println(idx+" "+next+" "+(memo.size()-idx));
	}
	
    public static void main(String args[]) throws Exception{
    	Scanner sc= new Scanner(System.in);
    	int q,digit;
    	while(true){
    		q= sc.nextInt();
    		digit= sc.nextInt();
    		if( q!=0 || digit!=0 ){
    			solve(q,digit);
    		} else{ break; }
    	}
    }
}

Measured memory_bytes: 21052