akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (n, x) = get!(usize, usize);

    if x == 1 || x == 2 * n - 1 {
        println!("No");
        return;
    }

    let mut unused: HashSet<usize> = (1..2 * n).collect();
    let mut ans = vec![None; 2 * n - 1];

    if x == 2 {
        ans[n - 1] = Some(x);
        ans[n] = Some(1);

        unused.remove(&x);
        unused.remove(&1);
    } else {
        ans[n - 1] = Some(x);
        ans[n] = Some(x + 1);
        ans[n - 2] = Some(x - 1);
        ans[n + 1] = Some(x - 2);

        unused.remove(&x);
        unused.remove(&(x + 1));
        unused.remove(&(x - 1));
        unused.remove(&(x - 2));
    }

    for (e, &a) in ans.iter_mut().filter(|e| e.is_none()).zip(unused.iter()) {
        *e = Some(a);
    }

    println!("Yes");
    for a in ans {
        println!("{}", a.unwrap());
    }
}


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

int main() {
  int n;
  cin >> n;
  int ans = 0, cnt = 0;
  for (int i = 0; i < n; i ++) {
    int t; cin >> t;
    t --;
    if (t == i) cnt ++;
    else if (cnt % 2 == 1) ans += cnt / 2 + 1, cnt = 0;
    else if (cnt % 2 == 0) ans += cnt / 2, cnt = 0;
  }
  if (cnt % 2 == 1) ans += cnt / 2 + 1;
  else if (cnt % 2 == 0) ans += cnt / 2;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main(void)
{
	int i,a,b,cnt,mx,n;
	P pp[200000];
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		scanf("%d %d",&a,&b);
		pp[i*2].first=a;
		pp[i*2].second=1;
		pp[i*2+1].first=b+1;
		pp[i*2+1].second=-1;
	}
	sort(pp,pp+n*2);
	cnt=0;	mx=0;
	for(i=0;i<n*2;i++)	{
		cnt+=pp[i].second;
		mx=max(mx,cnt);
	}
	printf("%d\n",mx);
	return 0;
}



Measured memory_bytes: 4320
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
  
/*------------------------------------------------------------------*/
  
int main(){
    int a, b; cin >> a >> b;
    cout << max(a - b * 2, 0) << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,i=0,j,c=0,p,m=1,max=0;
    string s[100000];
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s,s+n);
    for(i=0;i<n;i++)
    {
        if(s[i]==s[i+1])
        {
            m++;
        }
        else
        {
            c+=(m*(m-1))/2;
            m=1;
        }
    }
    cout << c << endl;
    return 0;

}


Measured memory_bytes: 6716
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

int main() {

    int N; cin >> N;

    int MAX = 2000000;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int p; cin >> p;
        if (p <= MAX) {
            ans++;
            MAX = p;
        }
    }
    cout << ans << '\n';

}


Measured memory_bytes: 256
left=gets.to_i
out,runner,score=0,0,0
while left>0
  judge=gets.chomp
  case judge
  when "HIT" then
    runner+=1
    if runner>3 then
      runner-=1
      score+=1
    end
  when "OUT" then
    out+=1
    if out>=3 then
      puts score
      runner,score,out=0,0,0
      left-=1
    end
  when "HOMERUN" then
    score+=(runner+1)
    runner=0
  end
end

Measured memory_bytes: 8544
/*
 * FileName:     reverse
 * CreatedDate:  2020-05-24 15:57:26 +0900
 * LastModified: 2020-05-24 16:15:36 +0900
 */

#include <stdio.h>
#include <stdlib.h>
int main(void){
    int n;
    scanf("%d",&n);
    long int *a = malloc(n*sizeof(long int));
    for(int i=0;i<n;i++){
        scanf("%ld",a+i);
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        int b,e;
        scanf("%d %d",&b,&e);
        for(int j=b;j<(b+e)/2;j++){
            long int tmp = a[j];
            a[j] = a[e+b-j-1];
            a[e-1+b-j] = tmp;
        }
    }
    printf("%ld",a[0]);
    for(int i=1;i<n;i++){
        printf(" %ld",a[i]);
    }printf("\n");
    free(a);
    return 0;
}



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

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

    int N, X;
    cin >> N >> X;
    int D = 0, ans = 1;
    rep(i, N) {
        int L;
        cin >> L;
        D += L;
        if (D > X) {
            break;
        }
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
	int n, a[100000], min = 100000001, ans = 0;
	cin >> n;
	ans = n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int j = 1; j < n; j++) {
		if (a[j] == a[j - 1]) {
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int parity(int n){
  if(n*n*n*n%10 == 1)
    return 1;
  else
    return 0;
}

long long power(int x, int y){
  if(y < 0)
    return 0;
  else{
    int64_t n = 1ll;
    for(int i = 0; i < y; i++)
      n *= x;
    return n;
  }
}
int digit(int x, int y){
  return x%power(10,y+1)/power(10,y);
}
int card(int n){
  int cnt = 0;
  while(n > 0){
    int n0 = n%10;
    n /= 10;
    if(n0 <= 3 && n%10 == 1){
      cnt++;
      n /= 10;
    }
  }
  return cnt;
}

long long bnps(int n, int a, int d){
  long long an = 0;
  for(int i = 0; i < d; i++){
    an += a%power(n,i+1)/power(n,i)*power(10,i);
  }
  return an;
}

int left(vector<int> vec, int k){
  int a = 0;
  int b = vec.size()-1;
  if(vec.at(a) > k)
    return 0;
  else if(vec.at(a) == k)
    return a;
  else if(vec.at(b) < k)
    return -1;
  else{
    bool bk = true;
    while(bk){
      int c = (a+b)/2;
      if(vec.at(c-1) < k && vec.at(c) == k){
        return c;
        bk = false;
      }
      else if(vec.at(c-1) >= k)
        b = c;
      else if(vec.at(c) < k)
        a = c;
      else{
        return c;
        bk = false;
      }
    }
  }
}

int right(vector<int> vec, int k){
  int a = 0;
  int b = vec.size()-1;
  if(vec.at(a) > k)
    return -1;
  else if(vec.at(b) == k)
    return b;
  else if(vec.at(b) < k)
    return b;
  else{
    bool bk = true;
    while(bk){
      int c = (a+b)/2;
      if(vec.at(c) == k && vec.at(c+1) > k){
        return c;
        bk = false;
      }
      else if(vec.at(c+1) <= k)
        a = c;
      else if(vec.at(c) > k)
        b = c;
      else{
        return c;
        bk = false;
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  vector<int>x(n);
  vector<int>y(n);
  for(int i = 0; i < n; i++){
    cin >> x.at(i) >> y.at(i);
  }
  double sum = 0.0;
  double s = 0.0;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      double lij = sqrt((x.at(i)-x.at(j))*(x.at(i)-x.at(j))+(y.at(i)-y.at(j))*(y.at(i)-y.at(j)));
      sum += lij;
    }
  }
  cout << fixed << setprecision(10);
  cout << sum*2.0/n << endl;
}

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



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

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    
    int h,w;
    cin>>h>>w;

    vector<vector<char>> p(h+2,vector<char>(w+2,'#'));

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>p[i][j];
        }
    }
    
    for(int i=0;i<=h+1;i++){
        for(int j=0;j<=w+1;j++){
            cout<<p[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3596
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::complex;

long long min(long long a, long long b) {return a < b ? a : b;}
long long min(int a, long long b) {return a < b ? a : b;}
long long min(long long a, int b) {return a < b ? a : b;}
long long min(int a, int b) {return a < b ? a : b;}

long long max(long long a, long long b) {return a > b ? a : b;}
long long max(int a, long long b) {return a > b ? a : b;}
long long max(long long a, int b) {return a > b ? a : b;}
long long max(int a, int b) {return a > b ? a : b;}

#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

int n, N;
int a[500000];
int b[500000];
int c[500000];

void kek()
{
    fill(c, c + N, -1);
    c[0] = b[0], c[N - 1] = b[N - 1];
    for (int i = 0; i + 1 < N; i++)
    {
        if (b[i] == b[i + 1])
        {
            c[i] = b[i], c[i + 1] = b[i + 1];
        }
    }
    for (int i = 0; i < N; i++)
    {
        if (c[i] == -1)
        {
            int j = i;
            while (c[j + 1] == -1) j++;
            if (i % 2 == j % 2)
            {
                for (int k = i; k <= j; k++) c[k] = c[i - 1];
            }
            else
            {
                int m = (i + j) / 2;
                for (int k = i; k <= m; k++) c[k] = c[i - 1];
                for (int k = m + 1; k <= j; k++) c[k] = c[j + 1];
            }
            i = j;
        }
    }
}

signed main()
{
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    N = 2 * n - 1;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    int l = 0, r = N + 1;
    while (l + 1 < r)
    {
        int mid = (l + r) / 2;
        for (int i = 0; i < N; i++)
        {
            if (a[i] >= mid) b[i] = 1;
            else b[i] = 0;
        }
        kek();
        //cout << mid << endl;
        //for (int i = 0; i < N; i++) cout << c[i] << " ";
        //cout << endl;
        if (c[n - 1] == 1)
        {
            l = mid;
        }
        else
        {
            r = mid;
        }
    }
    cout << l;
}


Measured memory_bytes: 9984
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
signed main(){
	string s;
	cin>>s;
	int n;
	cin>>n;
	reverse(s.begin(),s.end());
	while(n){
		char c=s.back();
		if(c=='1' && n){
			n--;
			s.pop_back();
			continue;
		}
		else{
			cout<<c;
			return 0;
		}
	}
	cout<<1;
	return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 200000;
int n;
int p[MAX_N];

int main() {
    fastio();

    cin >> n;
    forn(i, n) cin >> p[i];

    int mn = INT_MAX;

    int ans = 0;
    forn(i, n) {
        chmin(mn, p[i]);
        if (mn >= p[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
n, m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

t = (1..n).to_a.map{|i| [i, true]}.to_h
(1..m).each do |_|
  (a, b) = gets.split.map(&:to_i)
  if h[a-1] < h[b-1]
    t.delete(a)
  elsif h[a-1] > h[b-1]
    t.delete(b)
  else
    t.delete(a)
    t.delete(b)
  end
end

p t.length

Measured memory_bytes: 27020
from itertools import groupby

N, K = [int(i) for i in input().split()]
S = input()

A = [(int(k), len(tuple(v))) for k, v in groupby(S)]
M = len(A)

ans, count = 0, 0
r = 0
for l, (kl, al) in enumerate(A):
    bound = 2 * K + kl
    while r < M and r - l < bound:
        count += A[r][1]
        r += 1
    ans = max(ans, count)
    count -= al

print(ans)

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

int main(){
  int N, K;
  const int p_size = 1010;
  int p[p_size];
  int sum = 0;
  cin >> N >> K;
  for(int i = 0; i < N;i++){
    cin >> p[i];
  }
  sort(p, p+N);

for(int i = 0; i < K; i++){
  sum += p[i];
}

cout << sum << endl;
  
  
}

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

int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    if(a.at(i) == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  
  __int128_t ans = 1;
  for(int i = 0; i < n; i++){
    ans *= a.at(i);
    if(ans > 1000000000000000000){
      ans = -1;
      break;
    }
  }
  
  cout << (long long)ans << endl;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
using namespace std;
 
const ll N =(1e5+5);
const ll MOD = 10243;
const ll INF = 1e16;
const ll LOG = 29;

long long binpow(long long a, long long b) {
     a %= MOD;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD ;
        a = (a * a)%MOD ;

        
        b >>= 1;
    }
    res%=MOD;
    return res;
}
void solve(){
    ll n;
    cin>>n;
    ll a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    queue<ll> q;
    q.push(1);
    vll dis(n+1,-1);
    dis[1] = 0;
    while(!q.empty()){
        ll u = q.front();
        q.pop();
        ll v = a[u];
            if(dis[v] == -1){
                dis[v] = dis[u]+ 1;
                q.push(v);
            }
        
    }
    cout<<dis[2]<<endl;
}



int main()
{
    ios_base::sync_with_stdio(0);
     cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }
     
 
 
    return 0;     
    
        
}

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

int top = 0, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop(void) {
  top--;
  return S[top+1];
}

int main(void) {
  int a, b;
  top = 0;
  char s[100];
  while(scanf("%s",s) != EOF) {
    if(s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if(s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if(s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());

  return 0;
}



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


int main(){
  int a,b,c,d,totala=0,totalb=0;
  cin>>a>>b>>c>>d;
  totala=a+b+c+d;
  cin>>a>>b>>c>>d;
  totalb=a+b+c+d;
  if(totala>totalb){
    cout<<totala<<endl;
  }else if(totala<totalb){
    cout<<totalb<<endl;
  }else if(totala==totalb){
    cout<<totala<<endl;
  }


  return 0;
}

Measured memory_bytes: 1160
from collections import deque
n,m = map(int,input().split())
tuna = [[] for i in range(n+1)]
ans = [0 for i in range(n+1)]
for _ in range(m):
    a,b = map(int,input().split())
    tuna[a].append(b)
    tuna[b].append(a)
q = deque()
q.append(1)
while q:
    now = q.popleft()
    saki = tuna[now]
    for i in saki:
        if ans[i] == 0:
            q.append(i)
            ans[i] = now
print("Yes")
for i in range(2,n+1):
    print(ans[i])

Measured memory_bytes: 33916
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define fo(i,j,k) for(int i=j;i<=k;++i)
#define fd(i,j,k) for(int i=j;i>=k;--i)
#define rep(i,x) for(int i=ls[x];i;i=nx[i])
#define ll long long
using namespace std;
const int N=1e5+10,M=2e5+10,inf=1e9;
int to[M],nx[M],ls[N],vl[M],num=0;
void link(int u,int v,int w){
	to[++num]=v,nx[num]=ls[u],ls[u]=num;
	vl[num]=w;
}
int rt,mn,n;
int sz[N];
ll ans=0;
int dfs(int x,int fr){
	int s=1,w=0;
	rep(i,x){
		int v=to[i];
		if(v==fr) continue;
		int t=dfs(v,x);
		if(w<t) w=t;
		s+=t;
	}
	if(n-s>w) w=n-s;
	if(mn>w) mn=w,rt=x;
	return s;
}
void calc(int x,int fr,ll t){
	sz[x]=1,ans+=t;
	rep(i,x){
		int v=to[i];
		if(v==fr) continue;
		calc(v,x,t+vl[i]);
		sz[x]+=sz[v];
	}
}
int main()
{
	scanf("%d",&n),mn=n;
	fo(i,2,n){
		int u,v,w;
		scanf("%d %d %d",&u,&v,&w);
		link(u,v,w),link(v,u,w);
	}
	dfs(1,0);
	calc(rt,0,0);
	mn=inf;
	rep(i,rt){
		if(sz[to[i]]==(n+1)/2) {mn=vl[i];break;}
		mn=min(mn,vl[i]);
	}
	printf("%lld",ans*2-mn);
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

vector<int> manacher(const string &s) {
  int n = s.size();
  vector<int> rad(n);
  int i = 0, j = 0;
  while (i < n) {
    while (i - j >= 0 && i + j < n && s[i - j] == s[i + j]) ++j;
    rad[i] = j;
    int k = 1;
    while (i - k >= 0 && i + k < n && k + rad[i - k] < j) rad[i + k] = rad[i - k], ++k;
    i += k;
    j -= k;
  }
  return rad;
}

int main()
{
  string s;
  cin>>s;
  vecll cnt(26, 0);
  for(auto&& ch:s) {
    ++cnt[ch-'a'];
  }
  ll n=s.size();
  ll ans = n*(n-1)/2+1;
  for(auto&& e:cnt) {
    ans -= e*(e-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=4e3+5,M=1e6+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
ll fac[M],ifac[M],n;
ll f[N][N],x[M],y[M];
il void ad(ll&x,ll y){(x+=y)%=mod;}
ll C(ll n,ll m){
	if(n<0||m<0||n-m<0)return 0;
	return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main(){
	read(n);
	fac[0]=1;rep(i,1,8000)fac[i]=i*fac[i-1]%mod;
	ifac[8000]=qpow(fac[8000],mod-2,mod);
	repd(i,8000-1,0)ifac[i]=ifac[i+1]*(i+1)%mod;
	rep(i,1,n){read(x[i],y[i]);f[-x[i]+2000][-y[i]+2000]++;}
	rep(i,0,4000)rep(j,0,4000){
		if(i)ad(f[i][j],f[i-1][j]);
		if(j)ad(f[i][j],f[i][j-1]);
	}ll res=0;
	rep(i,1,n){
		ad(res,f[x[i]+2000][y[i]+2000]);
		ad(res,mod-C(x[i]+y[i]+x[i]+y[i],x[i]+x[i]));
	}cout<<res*qpow(2,mod-2,mod)%mod;
}

Measured memory_bytes: 134912
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
//#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,MOD;


//moddivとnCk
ll moddiv(ll a,ll b){
	ll x0=MOD,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0LL) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%MOD;
      if (x2==1LL){
        ans=(n2+MOD)%MOD;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%MOD)*b-t)/b;
}
//剰余の割ざん

//aのn乗 mod c
ll expmod(ll a,ll n){
  ll ans=1LL,aa=a,beki=n;
  for(int i=0;i<64;i++){
    if (beki%2==1LL) ans=ans*aa%MOD;
    aa=aa*aa%MOD;
    beki/=2LL;
    if (beki==0LL)break;
  }
  return ans;
}

//nCk
vi mulmod(500001);//0!,1!,2!,3!,4!,,,,
void first_nCk(){
  mulmod[0]=1LL;
  for(ll i=1;i<500001;i++){
    mulmod[i]=mulmod[i-1]*i%MOD;
  }
}
ll nCk(ll nn,ll kk){
  return moddiv(mulmod[nn],mulmod[kk]*mulmod[nn-kk]%MOD);
}





int bitnum(int x)
{
  int a=0;
  for(ll i=0;i<32;i++){
    a+=x%2;
    x/=2;
  }
  return a;

}


int calc(int in)
{
  int b=0;
  for(ll i=0;i<100;i++){
    if (bitnum(in)==0)break;
    in=in%bitnum(in);
    b++;
  }
  return b;
}



int main(){
  ll ans=0;
  cin >> n ;
  string s;cin>>s;
  ll btnum=0;
  for(ll i=0;i<n;i++){
    if (s[i]=='1')btnum++;
  }

  ll mod1,mod2;
  mod1=btnum-1;
  mod2=btnum+1;
  if (n==btnum){
    mod2=mod1;
  }
  if (btnum==0){
    mod1=mod2;
  }




  ll val1=0,val2=0;
  for(ll i=0;i<n;i++){
    if (s[i]=='1'){
      if (mod1!=0){
        MOD=mod1;
        val1=(expmod(2LL,n-i-1)+val1)%mod1;
      }
      
      if (mod2!=0)
      {
        MOD=mod2;
        val2=(expmod(2LL,n-i-1)+val2)%mod2;
      }
    }
  }





  
  REP(i,n){
    if (s[i]=='1'){
      if (mod1==0){
        ans=-1;
        cout<<(ans+1)<<endl;
        continue;
      }
      MOD=mod1;
      ans=val1-expmod(2LL,n-i-1);
      ans=(ans+mod1)%mod1;
      if (ans!=0){
        ans=calc(ans);
      }

    }else{
      MOD=mod2;
      ans=val2+expmod(2LL,n-i-1);
      ans=(ans+mod2)%mod2;
      if (ans!=0){
        ans=calc(ans);
      }
    }

    cout<<(ans+1)<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 7564
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	ll n;
	cin >> n;
	
	ll ans = ll(10e18);
	for(ll i = 1; i * i <= n; ++i) {
		if( n % i == 0 ) {
			if( i + n / i - 2 < ans ) ans = i + n / i - 2;
		}			
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */

  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  for(i=0;i<VMAX+1;i++)
    C[i] = 0;

  for(j=0;j<n;j++)
    C[A[j]]++;

  for(i=1;i<VMAX+1;i++)
    C[i] = C[i] + C[i-1];

  for(j=n-1;j>=0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=0;i<n;i++){
    if(i)printf(" ");
    printf("%d",B[i+1]);
  }

  printf("\n");

  return 0;
}



Measured memory_bytes: 9712
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();

    if ((b % a) == 0) {
      System.out.println(a + b);
    } else {
      System.out.println(b - a);
    }

  }
}

Measured memory_bytes: 35640
import Data.Bool
import qualified Data.ByteString.Char8 as C
import qualified Data.Vector.Unboxed as U

main = C.interact $ put . sol . get

get = U.unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . bool "No" "Yes"

sol v = 2*q+max 1 e>=U.head v
  where
  (q,e) = U.foldl' f (0,0) (U.tail v)

f (q,e) a
  | a`mod`4==0  = (q+1,e)
  | even a      = (q,e+1)
  | otherwise   = (q,e)

Measured memory_bytes: 8400
#include "bits/stdc++.h"
using namespace std;


int main() {

	int N;
	cin >> N;
	vector<int> A(N+1);
	for (int i = 1;i < N+1;i++) {
		cin >> A.at(i);
	}

	int count = 0;
	int su = 1;
	while (count <= N + 1) {
		su = A.at(su);
		count++;
		if (su == 2)
			break;
	}

	if (count <= N)
		cout << count;
	else
		cout << -1;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
int n,m,a[2*MAXN],b[MAXN],c[2*MAXN],d[MAXN],nx[MAXN],bl[MAXN],ans[MAXN];
int main () {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {scanf("%d",&a[i]);}
	for (int i=1;i<=n;i++) {scanf("%d",&b[i]);}
	for (int i=n+1;i<=n+n;i++) {a[i]=a[i-n];}
	m=n;
	n=m+m; 
	for (int ii=0;ii<30;ii++) {
		memset(bl,0,sizeof(bl));
		int tmp1=0,tmp2=0,flg=0;
		for (int j=1;j<=n;j++) {c[j]=((a[j]>>ii)&1);tmp1+=c[j]*(j<=m);}
		for (int j=1;j<=m;j++) {d[j]=((b[j]>>ii)&1);tmp2+=d[j];}
		if (tmp1==tmp2) {
			nx[1]=0;
		    for (int i=2,j=0;i<=m;i++) {
    		    while (j>0&&d[i]!=d[j+1]) {j=nx[j];}
        		if (d[i]==d[j+1]) {j++;}
        		nx[i]=j;
    		}
    		for (int i=1,j=0;i<=n;i++) {
	        	if (j==m) {j=nx[j];}
		        while (j>0&&c[i]!=d[j+1]) {j=nx[j];}
    		    if (c[i]==d[j+1]) {j++;}
        		if (i>=m&&j!=m) {bl[i-m]++;}
    		}
    		flg=1;
		}
		if (m-tmp1==tmp2) {
			for (int j=1;j<=m;j++) {d[j]^=1;}
			nx[1]=0;
		    for (int i=2,j=0;i<=m;i++) {
    		    while (j>0&&d[i]!=d[j+1]) {j=nx[j];}
        		if (d[i]==d[j+1]) {j++;}
        		nx[i]=j;
    		}
    		for (int i=1,j=0;i<=n;i++) {
	        	if (j==m) {j=nx[j];}
		        while (j>0&&c[i]!=d[j+1]) {j=nx[j];}
    		    if (c[i]==d[j+1]) {j++;}
        		if (i>=m&&j!=m) {bl[i-m]++;}
    		}
    		flg=1;
		}
		if (!flg) {
			return 0;
		}
		if (tmp1==tmp2&&m-tmp1==tmp2) {
			for (int j=0;j<=m;j++) {
				if (bl[j]==2) {ans[j]=1;}
			}
		} else {
			for (int j=0;j<=m;j++) {
				if (bl[j]==1) {ans[j]=1;}
			}
		}
	}
	for (int i=0;i<m;i++) {
		if (!ans[i]) {printf("%d %d\n",i,a[i+1]^b[1]);}
	}
	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する


int main(){
    int64_t n;
    cin>>n;
    int64_t count=0;
    set<int64_t> s;
    s.insert(n);
    if(n>=3){
    s.insert(n-1);
    }
    for(int64_t i=2;i*i<=n;i++){
        if(n%i==0){
            s.insert(i);
            s.insert(n/i);
        }
    }
    for(int64_t i=2;i*i<=n;i++){
        if((n-1)%i==0){
            s.insert(i);
            s.insert((n-1)/i);
        }
    }
    for(auto c:s){
        //cout<<c<<endl;
        int64_t k = c;
        int64_t N = n;
        if(N%k==0){
            while(N%k==0){
                N = N/k;
            }
            if(N%k==1){
                count++;
            }
        }
        else if(N%k==1){
            count++;
        }
    }
    //cout<<count<<endl;
    cout<<count<<endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

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

Node treeSearch(Node u, int k){
  
  while(u != NIL && k != u->key){
    if(k < u->key){
      u = u->left;}
    else u = u->right;
  }
  return u;
}
Node treeSuccessor(Node x){
Node y;
 
 if(x->right != NIL){
   return  treeMinimum(x->right);
 }
 y = x->parent;
 while(y != NIL && x == y->right){
   x = y;
   y = y->parent;
 }
 return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y


printf("treeDelete");
  if(z->left == NIL || z->right == NIL){
    y = z;
  }else{ y = treeSuccessor(z);}
    if(y->left != NIL){
      x = y->left;
    }else{x = y->right;}
    if(x !=NIL){
      x->parent = y->parent;
    }
    if(y->parent == NIL){
      root = x;//
    } else if(y == y->parent->left){
      y->parent->left = x;
    }else{y->parent->right = x;}
    if(y != z){
      z->key = y->key;
      
    }
}





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

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


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


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int x,y,z; cin >> x >> y >> z;
    cout << (x - z) / (y + z) << endl;
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;

ll fact[1000006], inv[1000006] , mod = 998244353;

ll mul(ll a, ll b)
{
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (1ll * a * b) % mod;
}

ll add(ll a, ll b)
{
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (a + b) % mod;
}

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv()
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i < N; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

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

    ll n , m , k;
    cin >> n >> m >> k;
    calcFacAndInv();

    ll ans = 0 , tmp;
    for(int i=0; i<=k; i++)
    {
        tmp = mul(m , fp(m-1 , n-i-1));
        tmp = mul(tmp , ncr(n-1 , i));
        ans = add(ans , tmp);
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 6820
#include<iostream>
#include<cmath>

using namespace std;

int main(){

    long long int n;

    cin >> n;

    long long int a[n];

    for(int i=0;i<n;i++) cin >> a[i];

    long long int s[n]={};

    for(int i=0;i,i<n;i++){
        s[a[i]-1]++;
    }

    long long int m=0;

    for(int i=0;i<n;i++){
        m += s[i]*(s[i]-1)/2;
    }

    for(int i=0;i<n;i++){
        cout << m-s[a[i]-1]+1 << endl;
    }






}

Measured memory_bytes: 5760
#include <cstdio>
#include <cstdlib>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>
#define L64 long long
#define MOD (1000000007LL)

std::vector<L64> getprimes(L64 x)
{
  std::vector<L64> primes;
  std::vector<bool> allnums(x, true);
  for (L64 i = 2; i <= x; i++){
    if(allnums[i]){
      primes.push_back(i);
      L64 lim = x / i;
      for(L64 j = 2; j <= lim; j++){
        allnums[i * j] = false;
      }
    }
  }
  return primes;
}

void getdivisorparts(L64 x, const std::vector<L64>& primes, std::vector<L64>& ret_p, std::vector<L64>& ret_cnt)
{
  L64 prime_num = (L64)primes.size();
  L64 lim = 1LL + std::sqrt(x);
  L64 primepos = 0;
  L64 dv = primes[primepos];
  while(primepos < prime_num && dv <= lim){
    if(x % dv == 0){
      L64 p = dv;
      L64 cnt = 1;
      x /= dv;
      while(x % dv == 0){
        cnt++;
        x /= dv;
      }
      ret_p.push_back(p);
      ret_cnt.push_back(cnt);
    }
    if(primepos + 1 == prime_num){
      break;
    }
    primepos = primepos + 1;
    dv = primes[primepos];
  }
  if(x != 1){
    ret_p.push_back(x);
    ret_cnt.push_back(1);
  }
}
std::vector<L64> getdivisor(const std::vector<L64>& ret_p, const std::vector<L64>& ret_cnt)
{
  std::vector<L64> t;
  L64 pat = 1LL;
  L64 len = (L64)ret_p.size();
  L64 allpat = 1;
  for (L64 i = 0; i < len; i++){
    allpat = allpat * (1LL + ret_cnt[i]);
  }
  for(L64 t_i_pat = 0; t_i_pat < allpat; t_i_pat++){
    L64 div = allpat;
    L64 i_pat = t_i_pat;
    L64 ret = 1LL;
    for (L64 i = 0; i < len; i++){
      div = div / (ret_cnt[i] + 1);
      L64 mul = i_pat / div;
      i_pat = i_pat % div;
      for(L64 j = 0; j < mul; j ++){
        ret = ret * ret_p[i];
      }
    }
    t.push_back(ret);
  }
  // std::sort(t);
  return t;
}

int main(void)
{
  L64 sum = 0;
  L64 n;
  std::cin >> n;
  std::vector<L64> primes = getprimes(1LL + std::sqrt(n));
  std::vector<L64> p, cnt;
  getdivisorparts(n, primes, p, cnt);
  std::vector<L64> divisors = getdivisor(p, cnt);
  L64 sz = (L64)divisors.size();
  for(L64 i = 0; i < sz; i++){
    L64 mp1 = divisors[i];
    L64 k = n / mp1;
    if(mp1 > k + 1){
      sum = sum + mp1 - 1LL;
    }
  }
  std::cout << sum << std::endl;
}


Measured memory_bytes: 1528
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for(i=0; i<n; i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    string s,t;
    int i;
    int cnt = 0;
    cin >> s >> t;
    int n = s.length();
    for(i = 0;i < n;++i)
    {
        if(s[i] != t[i])
            cnt++;
    }
    cout << cnt;
    
    
    

}


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

int main(){
    int H,W,N;
    int a[10002]={};
    int c[102][102];
    cin >> H >> W;
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> a[i];
    }

    int h=1;
    int w=1;
    for(int i=1;i<=N;i++){
        while(a[i]>0){
            c[h][w]=i;
            if(h%2!=0){
                if(w==W){
                    h++;
                }
                else{
                    w++;
                }
            }
            else{
                if(w==1){
                    h++;
                }
                else{
                    w--;
                }
            }
            a[i]--;
        }
    }

    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(j!=1) cout << " ";
            cout << c[i][j];
        }
        cout << "\n";
    }

    return 0;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    string s; cin >> s;
    if(s.size()%2!=0) {
            cout << "No" << endl;
            return 0;
    }
    for(int i = 0; i < s.size(); i+=2) {
        if(s[i] != 'h' || s[i + 1] != 'i') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

}


Measured memory_bytes: 256
//#include "stdafx.h"
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

/*-----------------------------------------------------------------------------
定義
-------------------------------------------------------------------------------*/
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define INF			2e9
#define MOD			1e9+7
#define MIN(a, b)	((a) < (b) ? a : b)
#define MAX(a, b)	((a) > (b) ? a : b)

typedef long long int QWORD;
typedef long long int ll;

/*-----------------------------------------------------------------------------
処理
-------------------------------------------------------------------------------*/
int main()
{
	int H, W, A, B;

	cin >> H;
	cin >> W;
	cin >> A;
	cin >> B;

	vector<vector<int>> matrix(H, vector<int>(W, 0));
	vector<int> yokoCnt(W, 0);
	vector<int> tateCnt(H, 0);

	REP(i, H) {
		REP(j, W) {
			int val;
			if (i < B) {
				val = (j < A) ? 0 : 1;
			} else {
				val = (j < A) ? 1 : 0;
			}
			cout << val;
		}
		cout << '\n';
	}

	return 0;
}

Measured memory_bytes: 5120
from collections import defaultdict


n, m = map(int, input().split())
e = [list(map(int, input().split())) for _ in range(m)]
g = defaultdict(set)

for dep, dest in e:
    g[dep].add(dest)
    g[dest].add(dep)

def dfs(i, visited=[]):
    if len(visited) == n:
        return 1
    res = 0
    for node in g[i]:
        if node not in visited:
            visited.append(node)
            res += dfs(node, visited)
            visited.pop()
    return res

ans = dfs(1, visited=[1])
print(ans)





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

#define ll long long

int main()
{
  map<ll,ll,greater<ll>> mp;
 int n;
  cin>>n;
  ll arr[n];
  for(int i=0;i<n;i++)
  {
    
    cin>>arr[i];
    mp[arr[i]]++;
    
    
  }
  int flag1=0;
  int flag2=0;
  ll breadth,len;
  auto itr=mp.begin();
  for(;itr!=mp.end();itr++)
  {
    if(itr->second>=2)
    {
     	len=itr->first;
        flag1=1;
      	itr->second=itr->second-2;
      break;
    }
  }
  for(;itr!=mp.end();itr++)
  {
    if(itr->second>=2)
    {
     	breadth=itr->first;
        flag2=1;
      	itr->second=itr->second-2;
      break;
    }
   }
  
  
  if(flag1==0 ||flag2==0)
    cout<<"0"<<endl;
  else
    cout<<len*breadth<<endl;
  
  
}

Measured memory_bytes: 7296
import numpy as np
N = int(input())
h = np.array([int(i) for i in input().split()])
counter = 0

'''
ゼロでないhのクラスタを見つけ、そのクラスタの最小値を引いていく

e.g.
[3 1 2 3 1]ならば、まず全てゼロでは無いので、最小値1を全体に対して引く。
すると、[2 0 1 2 0]となる。
このとき、[{2} 0 {1 2} 0]といった具合に、ゼロでない部分をまとめていく。
まとめた部分に対しても、同様の処理を行なっていく。
'''


def clustering(h):
    cluster = []
    cluster_pos = []
    small_cluster = []
    small_cluster_pos = []
    for index, value in enumerate(h):
        if(value != 0):
            small_cluster.append(value)
            small_cluster_pos.append(index)
        else:
            cluster.append(small_cluster)
            cluster_pos.append(small_cluster_pos)
            small_cluster = []
            small_cluster_pos = []
    if(value != 0):
        cluster.append(small_cluster)
        cluster_pos.append(small_cluster_pos)

    return cluster, cluster_pos

while(np.sum(h)>0):
    cluster, cluster_pos = clustering(h)
    for i in range(len(cluster)):
        if(len(cluster[i])==0):
            continue

        minimum = np.min(cluster[i])
        counter += minimum
        h[cluster_pos[i]]-= minimum

print(counter)

Measured memory_bytes: 12968
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _dbg(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _dbg(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_dbg(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}
const int N=11;
#define sqr(x) ((x)*(x))
int x[N][N];
int32_t main(){
    int n,d;cin>>n>>d;forn(i,n)forn(j,d)cin>>x[i][j];
    int ans=0;
    forn(i,n)forn(j,i){
        int z=0;
        forn(k,d)z+=sqr(x[i][k]-x[j][k]);
        int sz=sqrtl(z)+0.001;
        if(sz*sz==z)ans++;
    }
    cout<<ans<<'\n';
    return 0;
}


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

const int mod = 1e+9 + 7;

int main(){
    int n;
    cin >> n;
    int x = 0, y = 0, z = 0;
    ll ans = 1;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        ans = ans * ((a == x) + (a == y) + (a == z)) % mod;
        if(x == a){
            x++;
        } else if(y == a){
            y++;
        } else {
            z++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;

int inf = 4e18, mod = 1e9+7;

void rot(vi& val){
    rotate(val.begin(),val.begin()+1,val.end());
}

map<vi, int> mp;

void upd(vi &p, bool f){
    for(int i=0;i<4;i++, rot(p)){
        if(f) ++mp[p];
        else --mp[p];
    }
}

int check(vi u, vi d){
    int ans = 1;
    vector<vi> rem;
    reverse(d.begin()+1,d.end());
    for(int i=0;i<4;i++, rot(u), rot(d)){
        vi can(4);
        can[0] = u[1];
        can[1] = u[0];
        can[2] = d[0];
        can[3] = d[1];

        if(mp.find(can) == mp.end()){
            ans = 0;
            break;
        }
        rem.pb(can);
        ans *= mp[can];
        upd(can, false);
    }
    for(auto &p:rem) upd(p,true);
    return ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    int n,sum = 0,hol = 0, num = 1; cin >> n;
    for(int i=0;i<8;i++) num *=24;
    vi val(4);
    for(int i=0;i<n;i++){
        for(auto &v:val) cin >> v;
        upd(val,true);
    }
    for(auto &up:mp){
        vi curUp = up.first;
        int valUp = up.second;
        upd(curUp,false);

        for(auto &down : mp){
            int valDown = down.second;
            vi curDown = down.first;
            upd(curDown,false);
            int res = check(curUp,curDown);
            hol += res * valUp / num * valDown;
            sum += check(curUp, curDown) * valUp % num * valDown;
            upd(curDown,true);
        }
        upd(curUp,true);
    }
    cout << hol * (num / 24) + sum / 24<< endl;
    return 0;
}


Measured memory_bytes: 512