akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}


ll N,M;
const ll limit=28;
ll a[limit];
ll b[limit];

bool G[limit][limit];


ll dfs(ll v,bool visited[limit]){
  bool ALL=true;
  
  rep(i,N){
    if(visited[i]==false){
      ALL=false;
    }
  }

  if(ALL){
return 1;//本体に1を足す
  }

  
  ll ret=0;
  
  rep(i,N){
    if(G[v][i]==true&&visited[i]==false){
      
      visited[i]=true;
      ret+=dfs(i,visited);
      visited[i]=false;
    }
  }

  return ret;
}

      
int main(){
    cin>>N>>M;
 
  
  rep(i,M){
    cin>>a[i]>>b[i];
    G[a[i]-1][b[i]-1]=G[b[i]-1][a[i]-1]=true;
  }
  bool visited[limit];
rep(i,N){
  visited[i]=false;
  
}
 
  visited[0]=true;
  
  cout<<dfs(0,visited)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<limits>

using namespace std;

int main(){
  int A, B, Q, N;
  long a;
  vector<long> s, t;
  vector<pair<long, int>> x;
  vector<long> ans;
  cin >> A >> B >> Q;
  N = A + B + Q;
  ans.resize(Q);
  for( int i = 0; i < A; ++i ){
    cin >> a;
    s.emplace_back(a);
  }
  for( int i = 0; i < B; ++i ){
    cin >> a;
    t.emplace_back(a);
  }
  for( int i = 0; i < Q; ++i ){
    cin >> a;
    x.emplace_back(a,i);
  }
  s.emplace_back(numeric_limits<long>().min()/16);
  t.emplace_back(numeric_limits<long>().min()/16);
  s.emplace_back(numeric_limits<long>().max()/16);
  t.emplace_back(numeric_limits<long>().max()/16);
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  sort(x.begin(), x.end());
  auto ss = s.begin();
  auto tt = t.begin();
  vector<long> cand(6, 0);
  for( int i = 0; i < Q; ++i ){
    auto xx = x[i].first;
    ss = lower_bound(ss, s.end(), xx);
    tt = lower_bound(tt, t.end(), xx);
    long sa = xx - *(ss-1);
    long ta = xx - *(tt-1);
    long sb = *ss - xx;
    long tb = *tt - xx;
    cand[0] = sa + ta - (sa<ta ? sa : ta);
    cand[1] = sb + tb - (sb<tb ? sb : tb);
    cand[2] = 2 * sa + tb;
    cand[3] = sa + 2 * tb;
    cand[4] = 2 * sb + ta;
    cand[5] = sb + 2 * ta;
    sort(cand.begin(), cand.end());
    ans[x[i].second] = cand[0];
  }
  for( auto &aa : ans ){
    cout << aa << endl;
  }
  return 0;
}

Measured memory_bytes: 5876
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
#define int long long
#define mod 1000000007
using namespace std;

int a[100000];
signed main() {
	int ans = 1;
	int b; cin >> b;
	for (int c = 0; c < b; c++)cin >> a[c];
	int sum = 1;
	for (int c = 1; c < b; c++) {
		sum++;
		if (sum*2-1>a[c]) {
			ans = ans*sum%mod;
			sum--;
		}
	}
	for(int i=1;i<=sum;i++)ans = ans*i%mod;
	cout << ans << endl;
}

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

int main(void){

  int N,M;
  scanf("%d %d\n", &N, &M);

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

  int *C;
  C = (int*)malloc((N+1)*sizeof(int));
  int sum = 0;
  C[0] = 0;

  for(int i=0; i<N; i++){
    sum = (sum + A[i]) % M;
    C[i+1] = sum;
  }

  long long ans=0;

  for(int i=1; i<=N; i++){
    for(int j=0; j<i; j++){
      if(C[i]==C[j]) ans++;
    }
  }

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 896
input_line1 = input()
str_list = input_line1.split(" ")

Alice = int(str_list[0])
Bob = int(str_list[1])

if Alice == 1:
    Alice = 15
if Bob == 1:
    Bob = 15
    
if Alice > Bob:
    print("Alice")
if Bob > Alice:
    print("Bob")
if Alice == Bob:
    print("Draw")

Measured memory_bytes: 3060
#include <iostream>
#include <list>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

typedef long long ll;
#define MOD 1000000007;

using namespace std;
int main(){
    int N;
    ll ans = 1;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
    	cin >> A[i];
    }
    sort(A.begin(), A.end());

    if (N % 2 == 0) {
	    for (int i = 0; i < N; i += 2) {
	    	if (A[i] == i+1 && A[i+1] == i+1) {
	    		ans = ans * 2 % MOD;
	    	}
	    	else {
	    		ans = 0;
	    		break;
	    	}
	    }
	}
	else {
		if (A[0] == 0) {
		    for (int i = 1; i < N; i += 2) {
		    	if (A[i] == i+1 && A[i+1] == i+1) {
		    		ans = ans * 2 % MOD;
		    	}
		    	else {
		    		ans = 0;
		    		break;
		    	}
		    }
		}
	}

    cout << ans << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
    string S, T;
    cin >> S >> T;

    int Max = 0, cnt;

    for(int i = 0; i <= S.size()-T.size(); i++){
        cnt = 0;

        for(int j = 0; j < T.size(); j++){
            if(S.at(i+j) == T.at(j)){
                cnt++;
                Max = max(Max, cnt);
            }
        }
    }

    cout << T.size() - Max << endl;
}



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

typedef long long ll;

ll mypow(int n, int a) {
    if (a == 0) {
        return 1;
    } else {    
        ll r = n;
        for (int i = 0; i < a - 1; i++) {
            r *= n;
        }
        return r;
    }
}

int main() {
    int M, K; cin >> M >> K;
    if (K >= mypow(2, M)) {
        cout << -1 << endl;
    } else if (M == 0) {
        cout << "0 0" << endl;
    } else if (M == 1 && K == 0) {
        cout << "1 1 0 0" << endl;
    } else if (M == 1 && K == 1) {
        cout << -1 << endl;
    } else {
        for (int i = 0; i < mypow(2, M); i++) {
            if (i != K) printf("%d ", i);
        }
        printf("%d ", K);
        for (int i = mypow(2, M) - 1; 0 <= i; i--) {
            if (i != K) printf("%d ", i);
        }
        printf("%d", K);
    }
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	map<ll, ll> mp;
	rep(i, n) mp[a[i] - i - 1]++;
	ll ans = 0;
	rep(i, n) {
		ans += mp[-i - 1 - a[i]];
		mp[a[i] - i - 1]--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 27328
#include <stdio.h>
 
int main(void){
  char s[4];
 
  scanf("%s",s);
 
  if(s[0]!=s[1]){
    if(s[1]!=s[2]){
      if(s[2]!=s[0]){
        puts("Yes");
      }else{puts("No");}
 
    }else{puts("No");}
 
  }else{puts("No");}
 
 
  return 0;
}

Measured memory_bytes: 128
s = int(input())

def f(A):
    if A%2 == 0:
        return A//2
    else:
        return 3*A+1
    
a = []
a.append(s)
for i in range(1, 10000001):
    a.append(f(a[i-1]))
    if a.count(a[i]) == 2:
        print(i+1)
        break

Measured memory_bytes: 3060
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def modinv2(x,r):
  return pow(x,r-2,r)

def comb(n,a):
    dend = n
    for i in range(1,a):
        dend = (dend*(n-i))%R
    sor = 1
    for i in range(2,a+1):
        sor = (sor*i)%R
    return (dend*modinv2(sor,R))%R

n,k = inm()
if n-1<=k:
    print(comb(2*n-1,n-1))
    exit()
c = [1]*(k+1)
d = [1]*(k+1)
for i in range(1,k+1):
    m = modinv2(i,R)
    c[i] = (c[i-1]*(n-i+1)*m)%R
    d[i] = (d[i-1]*(n-i)*m)%R
ddprint("c,d")
ddprint(c)
ddprint(d)
sm = 0
#for j in range(n-k,n+1):
#    sm = (sm+comb(n,j)*comb(n-1,j-1))%R
for j in range(k+1):
    sm = (sm+c[j]*d[j])%R
if k==1:
    sm = (sm-1)%R
print(sm)


Measured memory_bytes: 78260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
 
int main() {
  ll N;
  cin >> N;

  double T, A;
  cin >> T >> A;

  vector<pair<double, int>> H(N);
  for (int i = 0; i < N; i++) {
    double h;
    cin >> h;
    h = abs(T - h * 0.006 - A);
    H[i] = make_pair(h, i + 1);
  }
  sort(H.begin(), H.end());
  cout << H[0].second << "\n";
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin>>a[i];
  }
  sort(a,a+n);

  int cnt = 1;
  int tmp = a[0];
  ll sum = 0;
  for(int i = 1; i < n; i++){
    if(tmp == a[i]){
      cnt++;
    }
    else{
     
      if(tmp < cnt){
        sum+=cnt-tmp;
      }
      else if(tmp > cnt){
        sum+=cnt;
      }
      tmp = a[i];
      cnt=1;
    }
  }
  if(tmp < cnt){
        sum+=cnt-tmp;
      }
  else if(tmp > cnt){
        sum+=cnt;
        }
  
  cout<<sum<<endl; 
 return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n;
    vector<int> a;
    Problem(LL n):n(n),a(1){};

    void solve(){
        cin >> a[0];
        for(int i=1; i<n; ++i){
            int tmp;
            cin >> tmp;
            if(tmp!=a.back())a.push_back(tmp);
        }
        if(a.size()==1){cout << 1 <<"\n";return;}
        int ans=1,dir=a[1]>a[0]?1:-1;
        for(int i=2; i<a.size(); ++i){
            if(dir==0){
                dir=a[i]>a[i-1]?1:-1;
            }else if((a[i]-a[i-1])*dir<0){
                ++ans;
                dir=0;
            }
        }
        cout << ans <<"\n";

    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin  >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 892
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
int main(){
  cpp_int N,K;
  cin>>N>>K;
  map<long,long>m;
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    m[a]+=b;
  }
  cpp_int now=0;
  // for(auto e:m)cout<<e.first<<" "<<e.second<<endl;
  for(auto e:m){
    now+=e.second;
    if(now>=K){
      cout<<e.first<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4224
N = int(input())
A = list(map(int, input().split()))

A.sort()
ans = [0] * N
m = -1

for i in range(N-1):
    if i == N-2:
        ans[A[i]-1] = i - m
    elif A[i] != A[i+1]:
        ans[A[i]-1] = i - m
        m = i
for i in range(N):
    print(ans[i])

Measured memory_bytes: 32188
// inputに入力データ全体が入る
function Main(input) {
  var N, r, c, rabbits, ref;
  ref = input.split("\n"), N = ref[0], r = ref[1];
  rabbits = r.split(" ").map(i=>parseInt(i));
  c = 0;
  rabbits.forEach((r, i,s) => c += s[r-1] === i + 1 ? 1 : 0);
  console.log(c/2);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

typedef long long ll;

int main(){
   ll n;  cin >> n;
  vector<ll> A(n); for(ll i = 0; i < n; i++){ cin >> A[i];}
   ll sum = 0;
   ll res = 0;
   ll right = 0;     
for (ll left = 0; left < n; ++left) {
    while (right < n && (sum ^ A[right]) == (sum + A[right])) {
        /* 実際に right を 1 進める */
        // ex: sum += a[right];
        sum += A[right];
        ++right;
    }
    res += right - left;
  
    /* break した状態で right は条件を満たす最大なので、何かする */
    // ex: res += (right - left);

    /* left をインクリメントする準備 */
    if (right == left) ++right;
    else sum -= A[left];
}
  
  cout << res << endl; return 0;}



Measured memory_bytes: 1920
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let n: i32 = s.trim().parse().unwrap();

    let mut number: Vec<Vec<Vec<i32>>> = vec![];
    for i in 0..4 {
        number.push(vec![]);
        for j in 0..3 {
            number[i].push(vec![]);
            for _ in 0..10 {
                number[i][j].push(0);
            }
        }
    }

    for _ in 0..n {
        let (b, f, r, v) = input();
        number[b - 1][f - 1][r - 1] += v;
    }

    for i in 0..4 {
        if i > 0 {
            println!("####################");
        }

        for j in 0..3 {
            for k in 0..10 {
                print!(" {}", number[i][j][k]);
            }
            println!("");
        }
    }
}

fn input() -> (usize, usize, usize, i32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();

    let b: usize = iter.next().unwrap().parse().unwrap();
    let f: usize = iter.next().unwrap().parse().unwrap();
    let r: usize = iter.next().unwrap().parse().unwrap();
    let v: i32 = iter.next().unwrap().parse().unwrap();

    (b, f, r, v)
}



Measured memory_bytes: 5036
#![allow(unused)]

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Self {
        Self { reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get_str(&mut self) -> &str {
        if let Some(t) = self.iter.next() {
            return t;
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get_str()
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        self.get_str().parse().ok().expect("Parse error")
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let a: f64 = sc.get();
    let b: f64 = sc.get();
    let h: f64 = sc.get();
    let m: f64 = sc.get();

    let r = 2. * std::f64::consts::PI * (h / 12. + (m / 60. / 12.) - m / 60.);
    let ans = (a * a + b * b - 2. * a * b * r.cos()).sqrt();
    println!("{}", ans);
}


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

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

    map<int, int> memo;

    int A;
    for(int i = 0; i < N; i++){
        cin >> A;
        memo[A]++;
    }

    int flag = 0;
    for(auto i = memo.begin(); i != memo.end(); i++){
        if(i->second != 1) flag = -1;
    }

    if(flag == 0) cout << "YES" <<endl;
    if(flag == -1) cout << "NO" <<endl;
}

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

#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
 
using namespace std;

int32_t main(){
    int h, w;
    cin >> h >> w;
    string s[h];
    REP(i, h) cin >> s[i];

    REP(i, h){
        REP(j, w){
            bool f=0;
            FOR(k, j+1, w){
                if(s[i][k]=='#') f=1;
            }
            FOR(k, i+1, h){
                if(f && s[k][j]=='#'){
                    cout << "Impossible" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Possible" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string str;
    cin >> str;
    replace(ALL(str), ',', ' ');
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int an[200100],bn[200100];
bool sumi[200100];
vector<int> gr[200100];
queue<int> q;
int main()
{
	string s;int n,m,a,b;
	cin>>n>>m;cin>>s;
	rep(i,m){
		cin>>a>>b;a--;b--;
		if(s[a]=='A') an[b]++;else bn[b]++;
		if(s[b]=='A') an[a]++;else bn[a]++;
		gr[a].pb(b);gr[b].pb(a);
	}
	rep(i,n){
		if(an[i]<1 || bn[i]<1){
			q.push(i);
			sumi[i]=true;
		}
	}
	while(!q.empty()){
		int p=q.front();q.pop();
		//cout<<p<<endl;
		//if(!sumi[p]) cout<<"hoge"<<endl;
		rep(i,gr[p].size()){
			int v=gr[p][i];
			if(sumi[v]) continue;
			//cout<<v<<'a'<<endl;
			if(s[p]=='A') an[v]--;else bn[v]--;
			if(an[v]<1 || bn[v]<1){
				sumi[v]=true;q.push(v);
			}
		}
	}
	rep(i,n){
		if(!sumi[i]){
			cout<<"Yes"<<endl;return 0;
		}
	}
	cout<<"No"<<endl;
}


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

int fac(int k) {
	int sum = 1;
	for (int i = 1; i <= k; i++) {
		sum *= i;
	}
	return sum;
}


int main(void) {
	int n; cin >> n;
	vector<int> P(n), Q(n);
	rep(i, n) cin >> P[i];
	rep(i, n) cin >> Q[i];

	int a = 0, b = 0;
	for (int i = 0; i < n-1; i++) {
		if (P[i] != 1) {
			a += (P[i] - 1) * fac(n - i - 1);
		}
		for (int j = i + 1; j < n; j++) {
			if (P[i] < P[j]) {
				P[j]--;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (Q[i] != 1) {
			b += (Q[i] - 1) * fac(n - i - 1);
		}
		for (int j = i + 1; j < n; j++) {
			if (Q[i] < Q[j]) {
				Q[j]--;
			}
		}
	}

	cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;
int n;
string s;
int main(){
	cin>>n;
	cin>>s;
	int ans=n;
	for(int i=1;i<n;i++)
	if(s[i-1]==s[i])
	ans--;
	cout<<ans;
	re 0;
}


Measured memory_bytes: 512
package main

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

var si = bufio.NewScanner(os.Stdin)

func readInt() int {
	si.Scan()
	r, _ := strconv.Atoi(si.Text())
	return r
}
func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}
func main() {
	si.Split(bufio.ScanWords)
	si.Buffer(make([]byte, 0), 10000000)
	N, T := readInt(), readInt()
	ret := 0
	l := readInt()

	for i := 1; i < N; i++ {
		t := readInt()
		ret += min(t, l+T) - l
		l = t
	}

	fmt.Println(ret + T)

}


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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const {
    return mint(-x);
  }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    return mint(*this) += a;
  }
  mint operator-(const mint a) const {
    return mint(*this) -= a;
  }
  mint operator*(const mint a) const {
    return mint(*this) *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a) {
    return *this *= a.inv();
  }
  mint operator/(const mint a) const {
    return mint(*this) /= a;
  }
};
istream &operator>>(istream &is, const mint &a) {
  return is >> a.x;
}
ostream &operator<<(ostream &os, const mint &a) {
  return os << a.x;
}

void solve(long long N) {
  cout << (mint(10).pow(N) - mint(9).pow(N) * 2 + mint(8).pow(N)) << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3772
import java.util.Scanner;

public class Main {

	// a～zの文字数を記録する配列
	static int[] CharCount = new int[26];

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

		// Ctrl+Zが押されるまで繰り返す
		while (sc.hasNext()) {
			// 入力と文字カウント
			CountingCharacters(sc.next());
		}
		// 表示
		Print();

	}

	// 文字列からa~zの文字をカウントする（大小文字区別なし）
	static void CountingCharacters(String str) {

		char[] c = str.toCharArray();
		for (int i = 0; i < c.length; i++) {
			for (int a = (int) 'A'; a < 1 + (int) 'Z'; a++) {
				if (Character.toUpperCase(c[i]) == (char) a) {
					CharCount[a - (int) 'A']++;
					break;
				}
			}
		}
	}

	// 表示処理
	static void Print() {
		for (int i = 0; i < CharCount.length; i++) {
			System.out.println((char) (i + (int) 'a') + " : " + CharCount[i]);
		}
	}

}


Measured memory_bytes: 26628
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int N;
  cin >> N;
  vector<ll> in;
  rep(i,N){
    ll a;
    cin >> a;
    in.push_back(a);
  }

  ll ret = 1e18;
  {
    ll tmp = 0;
    vector<ll> v = in;
    ll sum = 0;
    rep(i,v.size()){
      sum += v[i];
      if(i%2==0){
        if(sum >= 0){
          tmp += sum+1;
          sum = -1;
        }
      }else{
        if(sum <= 0){
          tmp += -sum + 1;
          sum = 1;
        }
      }
    }
    ret = min(ret, tmp);
  }
  {
    ll tmp = 0;
    vector<ll> v = in;
    ll sum = 0;
    rep(i,v.size()){
      sum += v[i];
      if(i%2==0){
        if(sum <= 0){
          tmp += -sum+1;
          sum = 1;
        }
      }else{
        if(sum >= 0){
          tmp += sum + 1;
          sum = -1;
        }
      }
    }
    ret = min(ret, tmp);
  }


  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair


using namespace std;

int main(){

    string s,t;
    cin >> s;
    cin >> t;

    bool ansb = false;
    string anss;

    for(int i = s.size() - t.size(); i >= 0; i--){
        string sub = s.substr(i,t.size());

        bool tmpb = true;

        rep(j,t.size()){
            tmpb = tmpb && (sub[j] == '?' || sub[j] == t[j]);
        }

        if(tmpb){
            ansb = true;
            anss = s;
            int c = 0;
            rep(j,s.size()){
                if(i <= j && j <= i + t.size() - 1){
                    anss[j] = t[c];
                    c++;
                }else{
                    if(anss[j] == '?'){
                        anss[j] = 'a';
                    }
                }
            }
            break;
        }
    }

    cout << (ansb ? anss : "UNRESTORABLE") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
  int t[4][3][10]={0};
  int b,f,r,v,i,j,k,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d%d%d%d",&b,&f,&r,&v);
t[b-1][f-1][r-1]=t[b-1][f-1][r-1]+v;

      
    
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	printf(" %d",t[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3)printf("####################\n");
  }
  return 0;
}


Measured memory_bytes: 2112
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define End return 0;
int main ()
{
    string s;
    cin>>s;
    ll r=s.size();
    for(ll i=0; i<r; i++){
        cout<<"x";
    }
    cout<<endl;
    End;
}
/* pray for me
All is well
*/




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 1 << 17;

// セグメント木を持つグローバル配列
int n, dat[2 * MAX_N - 1];

// 初期化
void init(int n_){
    // 簡単のため要素数を2のべき乗に
    n = 1;
    while(n < n_)n *= 2;

    // 全ての値をINT_MAXに
    for(int i = 0; i < 2 * n - 1; i++)dat[i] = INT_MAX - 1001001001;
}

// k番目の値(0-indexed)をaに変更
void update(int k, int a){
    // 葉の接点
    k += n - 1;
    dat[k] = a;
    // 登りながら更新
    while(k > 0){
        k = (k - 1) / 2;
        dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

// [a,b)の最小値を求める
// 後ろのほうの引数は、計算の簡単のための引数。
// kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。
// したがって、外からはquery(a, b, 0, 0, n)として呼ぶ。
int query(int a, int b, int k, int l, int r){
    // [a, b)と[l, r)が交差しなければ、INT_MAX
    if (r <= a || b <= l)return INT_MAX;

    // [a, b)が[l, r)を完全に含んでいれば、この節点の値
    if (a <= l && r <= b)return dat[k];
    else {
        // そうでなければ、2つの子の最小値
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
}


int main(){
    int m;
    cin >> n >> m;
    
    int nn = n;
    if(n < 100)n = 100;
    init(n);


    string s; cin >> s;
    update(0, 0);
    srep(i,1,nn+1){
        
        if(s[i] == '1')continue;
        int l = max(0, i - m);
        int cnt = query(l, i, 0, 0, n);
        // cout << i  << ' ' << cnt << endl;
        update(i, cnt + 1);
    }

    int ans = query(nn, nn+1, 0, 0, n);
    // cout << ans << endl;
    if(ans > 1001001)ans = -1;
    if(ans == -1){
        cout << ans << endl;
        return 0;
    }
    int v[ans+1];
    v[ans] = nn;
    drep(i,nn+1){
        int tmp = query(i, i+1, 0, 0, n);
        if(tmp < ans){
            if(v[tmp + 1] - i <= m){
                v[tmp] = i;
            }
        }
    }
    // rep(i,ans+1)cout << v[i] << ' ';
    // cout << endl;
    rep(i, ans){
        cout << v[i+1] - v[i];
        if(i == ans - 1){
            cout << endl;
        }else{
            cout << ' ';
        }
    }
    return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll N;cin>>N;
  //vector<pair<ll,ll> > pairs(N);
  P pairs[N];
  ll i,j,k,l;
  ll x,y,tmp=0;
  rep(i,N){
    cin>>pairs[i].first>>pairs[i].second;
  }
  //sort(pairs.begin(), pairs.end());
  sort(pairs,pairs+N);
  ll cnt;
  rep(i,N){
    for(j=i+1;j<N;j++){
      cnt=0;
      x=pairs[j].first-pairs[i].first;
      y=pairs[j].second-pairs[i].second;
      //cout<<x<<y<<endl;
      for(k=0;k<N;k++){
        for(l=k+1;l<N;l++){
          if(pairs[l].first-pairs[k].first==x and pairs[l].second-pairs[k].second==y){
            cnt++;
          }
        }
      }
      //cout<<cnt<<endl;
      tmp=max(cnt,tmp);
    }
  }
  ll ans=N-tmp;
  if(N==1) ans=1;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n + 1) { sc.nextInt() }
    val b = Array(n) { sc.nextInt() }
    var ans = 0L
    for (i in 0 until n) {
        val d = Math.min(a[i], b[i])
        ans += d
        b[i] -= d
        val e = Math.min(a[i + 1], b[i])
        ans += e
        a[i + 1] -= e
    }
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 57516
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    map<int, int> mEven, mOdd;
    for(int i = 0; i < n; i += 2) mEven[v[i]]++;
    for(int i = 1; i < n; i += 2) mOdd[v[i]]++;

    vector<pair<int, int>> evenCnt, oddCnt;
    for (auto mi = mEven.begin(); mi != mEven.end(); mi++){
        evenCnt.push_back(make_pair(mi->second, mi->first));
    }
    for (auto mi = mOdd.begin(); mi != mOdd.end(); mi++){
        oddCnt.push_back(make_pair(mi->second, mi->first));
    }

    int ans;
    sort(rall(evenCnt));
    sort(rall(oddCnt));
    if (evenCnt[0].first == oddCnt[0].first){
        if (evenCnt[0].second == oddCnt[0].second){
            if (evenCnt[1].first > oddCnt[1].first){
                ans = n - oddCnt[0].first - evenCnt[1].first;
            }
            else{
                ans = n - evenCnt[0].first - oddCnt[1].first;
            }
        }
        else{
            ans = n - evenCnt[0].first - oddCnt[0].first;
        }
    }
    else if (evenCnt[0].first > oddCnt[0].first){
        if (evenCnt[0].second == oddCnt[0].second){
            ans = n - evenCnt[0].first - oddCnt[1].first;
        }
        else{
            ans = n - evenCnt[0].first - oddCnt[0].first;
        }
    }
    else if (evenCnt[0].first < oddCnt[0].first){
        if (evenCnt[0].second == oddCnt[0].second){
            ans = n - oddCnt[0].first - evenCnt[1].first;
        }
        else{
            ans = n - oddCnt[0].first - evenCnt[0].first;
        }
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
	string input;
	int N,x = 0,answer = -1;
	cin >> N >> input;
	for(int i=0;i<N;i++){
		answer = max(answer,x);
		if(input[i] == 'I'){
			x++;
		}else if(input[i] == 'D'){
			x--;
		}
		answer = max(answer,x);
	}
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	int n,m;
	cin>>n>>m;
	ll k;
	cin>>k;
	ll a[n],b[m];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<m;i++)
		cin>>b[i];
	ll cur = 0;
	int i = 0, j = 0;
	while(i<n){
		if(cur+a[i] <= k)
			cur += a[i];
		else
			break;
		i++;
	}

	while(j<m){
		if(cur +b[j] <= k)
			cur += b[j];
		else
			break;
		j++;
	}
		
	int best = i+j;
	for(int idx = i-1; idx>=0;idx--){
		cur -= a[idx];
		while(j<m && cur+b[j] <= k){
			cur += b[j];
			++j;
		}

		best = max(best,idx+j);
	}

	cout<<best<<endl;
}

Measured memory_bytes: 6736
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int n,k;
    cin >> n >> k;
    string t,s;
    cin >> t;
    s = "1";
    s += t;
    int res = 0;
    int l = 1;
    int r = 0;
    int num = 0;
    FOR(i,1,n+1){
        if(s[i] == '0' and s[i-1] == '1'){
            num ++;
            if(num == k + 1){
                res = max(res, i - l );
                while(s[l] == '1') l ++;
                while(s[l] == '0') l ++;
                num --;

            }

        }
    }



    
    cout << max(res , n+ 1 - l) << endl;;

}


Measured memory_bytes: 512
import java.util.Scanner;

	class Main{
		public static void main(String[]args){
            
            
        Scanner sc=new Scanner(System.in);
            int x,i=0;
            x=sc.nextInt();
            if(x!=0){
          	  do{
                  i++;
                System.out.println("Case "+i+": "+x);
                  x=sc.nextInt();
          	  }while(x!=0);
            sc.close();
            }
        }
    }


Measured memory_bytes: 41132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll n;
    cin>>n;
    vector<pair<ll,ll>> a(n);
    rep(0,i,n){
        cin>>a[i].second>>a[i].first;
        a[i].first=a[i].first;
    }
    sort(a.begin(),a.end());
    ll x=0;
    rep(0,i,n){
        ll co=a[i].second;
        ll de=a[i].first;
        x+=co;
        if(de<x){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e8
typedef long long ll;
typedef long double ld;

int main() {
    int h, n;
    cin >> h >> n;
    vector<int> dp(h+1, INF);
    dp[0] = 0;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        rep(j, h){
            int nj = min(j+a, h);
            dp[nj] = min(dp[nj], dp[j]+b);
        }
    }
    cout << dp[h] << endl;
}



Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define each(i, ctn) for (auto &&i : (ctn))
#define all(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(12);*/ } } pre__;

int main(void) {
	string S;
	cin >> S;
	S[3] = '8';
	OUT(S);
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<map>
#include<string>
#include<vector>
using namespace std;
 
int main(){
  string S;
  cin>>S;
  map<char, int> amap;
  vector<char> arr;
  for(int i=0;i<4;++i){
    if(amap[S[i]]==0) arr.push_back(S[i]);
    amap[S[i]]++;
  }
  bool ok = true;
  if(arr.size()!=2) ok = false;
  else{
    if(amap[arr[0]]!=amap[arr[1]]) ok = false;
  }
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

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

    sc.close();

    int d = 0;

    if (a < b) {
      d = b - (a + W);      
    } else {
      d = a - (b + W); 
    }

    if (0 < d) {
      System.out.println(d);
    } else {
      System.out.println(0);
    }

  }

}

Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main():
    N,M=mis()
    print(N*(N-1)//2 + M*(M-1)//2)


main()







Measured memory_bytes: 5676
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String t = scan.next();
    int maxCnt = 0;
    int currentCnt = 0;
    for (int i = 0; i < t.length(); i++){
      if(t.charAt(i) == 'R'){
        currentCnt++;
      }else{
        currentCnt = 0;
      }
      maxCnt = Math.max(maxCnt, currentCnt);
    }
    System.out.println(maxCnt);
  }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int sum = 0;
  int x;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x < K - x) {
      sum += x * 2;
    } else {
      sum += (K - x) * 2;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define limit (long long int )1e18
using namespace std;
int main()
{
  long long  n;
  cin>>n;
  string b;
  cin>>b;
  long long  n2 = ((b[0]-'0')*100 + (b[2]-'0')*10 + b[3]-'0');
  long long ans = n2 * n / 100;
  cout<<ans;
}

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

int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int ti = (60*H2+M2)-(60*H1+M1);
    int ans=0;
    while(true) {
        if ((ans+K)>=ti) {
            cout << ans;
            return 0;
        }
        else ans+=1;
    }
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			cout << v[i][j] << "   ";
		}
		cout << endl;
	}
}




int main(){
	ll N;
	cin >> N;
	//N--;
	//cout << N << endl;
	string abc = "zabcdefghijklmnopqrstuvwxyz";
	//cout << " abc.size(): " << abc.size() << endl;
	string ans = "";
	while(N!=0){



		if(N%26==0){
			int num = 26;
			char c = abc[num];
			//cout << num << "   c: " << c << endl;
			ans.push_back(c);
			//if(N==26) break;
			N /= 26;
			N--;
			//if(N==1) break;
			continue;
		}

		int num;
		num = N % 26;
		//char c = (char)num;// + "a";
		char c = abc[num];
		//cout << num << "   c: " << c << endl;
		ans.push_back(c);
		//if(N==26) break;
		N /= 26;
		
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;

}


Measured memory_bytes: 3600
#include<iostream>
#include<queue>

using namespace std;

int main(){
    int n,t,p,c=0;
    string s;
    cin >> n >> t;
    queue<pair<string,int> >a;
    while(n--){
        cin >> s >> p;
        a.push(make_pair(s,p));
    }
    while(!a.empty()){
        pair<string,int>b=a.front();
        a.pop();
        if(b.second<=t){
            c+=b.second;
            cout<<b.first<<' '<<c<<endl;
            
        }
        else{
            b.second-=t;
            c+=t;
            a.push(b);
        }
    }
    
}


Measured memory_bytes: 6168
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int t, n, s, f;
    while(cin >> t && t)
    {
        int sum = 0;
        cin >> n;
        REP(n){cin >> s >> f; sum += (f-s);}
        
        if(sum>=t){cout << "OK" << endl;}
        else cout << t - sum << endl;
    }

    return 0;
}

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

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

    if (a % x == 0) {
        cout << (b/x) - (a/x) + 1 << endl;
    } else {
        cout << (b/x) - (a/x) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int *ufp, *ufr;
int UF_find(int);
void UF_union(int, int);
int main(void)
{
  int i, n, q, com, x, y;
  scanf("%d %d", &n, &q);
  ufp = (int*)malloc(sizeof(int) * n);
  ufr = (int*)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++){
    ufp[i] = i;
    ufr[i] = 0;
  }
  for (i = 0; i < q; i++) {
    scanf("%d %d %d", &com , &x, &y);
    if (!com) UF_union(x, y);
    else if (UF_find(x) == UF_find(y)) printf("1\n");
    else printf("0\n");
  }
  free(ufp);
  free(ufr);
}
int UF_find(int a)
{
  if (ufp[a] == a) return a;
  else {
    ufp[a] = UF_find(ufp[a]);
    return ufp[a];
  }
}
void UF_union(int a, int b)
{
  a = UF_find(a);
  b = UF_find(b);
  if (a == b) return;
  if (ufr[a] < ufr[b]) ufp[a] = b;
  else {
    ufp[b] = a;
    if (ufr[a] == ufr[b]) ufr[a]++;
  }
}


Measured memory_bytes: 2104
import java.util.Scanner;
import java.io.IOException;
class Main {
  	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int H = scan.nextInt();
		int[] A = new int[H + 1];
		
		for(int i = 1; i < H + 1; i++){
			A[i] = scan.nextInt();
		}
		
		for(int i = 1; i < H + 1; i++){
			System.out.print("node " + i);
			System.out.print(": key = " + A[i] + ", ");
			
			//2????????§????????????????????????????????????
			if(i / 2 > 0){
				System.out.print("parent key = " + A[i / 2] + ", ");
			}
			//???????????????2?????¢????????¨??????????????´???????????????
			if(i * 2 < H + 1){
				System.out.print("left key = " + A[i * 2] + ", ");
			}
			//???????????????2??? + 1??¢????????¨??????????????´???????????????
			if(i * 2 + 1 < H + 1){
				System.out.print("right key = " + A[i * 2 + 1] + ", ");
			}
			
			System.out.println();
		}
	}
}

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

int main(){
    int a, b;
    cin >> a >> b;
    int dis = abs(b - a);
    int A = 0;
    for(int i = 0; i < dis; i++)A += i;
    cout << A - a << endl;
    return 0;
}

Measured memory_bytes: 256