akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,a[2000],b[2000],dp[2000][2000];
int main(){
	for(int i=0;i<4000000;i++)dp[i/2000][i%2000]=1000000007;
	cin>>n>>m;for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<m;i++)cin>>b[i];
	dp[0][0]=0;
	for(int i=0;i<m;i++){
		for(int j=0;j<=n;j++){
			dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+a[j]*b[i]);
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
		}
	}
	cout<<dp[m][n]<<endl;
	return 0;
}

Measured memory_bytes: 18720
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_T = 20000;
const int INT_T = 1000;

const int MAX_M = 100;
const int MAX_N = 100;

const int PKT_HDR = 3;

/* typedef */

struct Answer {
  int p, t, size;
  Answer() {}
  Answer(int _p, int _t, int _size) { p = _p, t = _t, size = _size; }
  bool operator<(const Answer& a0) const { return t < a0.t; }
  void print() { printf("Answer:p=%d,t=%d,size=%d\n", p, t, size); }
};

typedef vector<Answer> va;

/* global variables */

int m, n, l;
int ds[MAX_M];
int ssent, srecv, csents[MAX_M], crecvs[MAX_M];
va vans;
int ansed[MAX_M], newansed[MAX_M];

/* subroutines */

/* main */

int main() {
  for (bool first = true;; first = false) {
    cin >> m >> n;
    if (m == 0) break;

    ssent = srecv = 0;
    memset(csents, 0, sizeof(csents));
    memset(crecvs, 0, sizeof(crecvs));

    for (int i = 0; i < m; i++)
      cin >> ds[i];

    while (n--) {
      vans.clear();
      
      cin >> l;
      for (int i = 0; i < l; i++) {
	int p, t;
	string ans;
	cin >> p >> t >> ans;
	vans.push_back(Answer(p, t + 2 * ds[p], ans.length()));
      }
      sort(vans.begin(), vans.end());

      // problem-start
      for (int i = 0; i < m; i++) {
	ssent += PKT_HDR;
	crecvs[i] += PKT_HDR;
      }

      int ai = 0;
      int nansed = 0, sum = 0;
      memset(ansed, 0, sizeof(ansed));
      
      for (int t = 0; t <= MAX_T; t += INT_T) {
	//printf("t=%d\n", t);
	int nnewansed = 0, newsum = 0;
	memset(newansed, 0, sizeof(newansed));

	// receive Answer
	while (ai < l && vans[ai].t < t) {
	  Answer& vai = vans[ai];
	  //vai.print();
	  
	  int data = 2 + vai.size;
	  csents[vai.p] += PKT_HDR + data;
	  srecv += PKT_HDR + data;
	  ansed[vai.p] = newansed[vai.p] = data;
	  nansed++;
	  nnewansed++;
	  sum += data;
	  newsum += data;
	  ai++;
	}

	// notification
	if (nnewansed > 0) {
	  for (int i = 0; i < m; i++) {
	    if (ansed[i] == 0) {	// type A
	      int pkt = PKT_HDR + 1 + nnewansed;
	      ssent += pkt;
	      crecvs[i] += pkt;
	      //printf("  t=%d: type A->%d, %d byte\n", t, i, pkt);
	    }
	    else if (newansed[i] > 0 && nansed > 1) {	// type B (exclude)
	      int pkt = PKT_HDR + 1 + sum - newansed[i];
	      ssent += pkt;
	      crecvs[i] += pkt;
	      //printf("  t=%d: type B(excl)->%d, %d byte\n", t, i, pkt);
	    }
	    else if (newansed[i] == 0 && ansed[i] > 0) {	// type B
	      int pkt = PKT_HDR + 1 + newsum;
	      ssent += pkt;
	      crecvs[i] += pkt;
	      //printf("  t=%d: type B->%d, %d byte\n", t, i, pkt);
	    }
	  }
	}
      }

      // problem-end
      for (int i = 0; i < m; i++) {
	ssent += PKT_HDR + 1;
	crecvs[i] += PKT_HDR + 1;
      }
    }

    if (! first) cout << endl;
    
    printf("%d %d\n", ssent, srecv);
    for (int i = 0; i < m; i++)
      printf("%d %d\n", csents[i], crecvs[i]);
  }

  return 0;
}

Measured memory_bytes: 1228
class UnionFind():
    def __init__(self, n):
        self.parents = [-1]*n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.root(self.parents[x])
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            if x > y:
                x, y = y, x
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            return

n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]

u = UnionFind(n)
f = [set() for _ in range(n)]
l = [set() for _ in range(n)]
for a, b in ab:
    a, b = a-1, b-1
    f[a].add(b)
    f[b].add(a)
    u.unite(a, b)
for c, d in cd:
    c, d = c-1, d-1
    l[c].add(d)
    l[d].add(c)
ans = [0] * n
for i in range(n):
    r = u.root(i)
    bl = 0
    for j in l[i]:
        if u.root(j) == r:
            bl += 1
    ans[i] = -u.parents[r] - len(f[i]) - bl - 1
print(*ans)

Measured memory_bytes: 136236
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
//配列の添字ズレに注意
//=に注意

int main(){
  long n,ans=0;  cin>>n;
  //string s; cin>>s;
  
  long L[n];
  rep(i,n) cin>>L[i];
  
  for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)for(int k=j+1;k<n;k++){
    if(L[i]==L[j]||L[i]==L[k]||L[j]==L[k])continue;
    
    if(abs(L[j]-L[k])<L[i]&&L[i]<L[j]+L[k])ans++;
  
  
  }
  
  cout<< ans<<endl;
}


Measured memory_bytes: 3628
h,w=map(int,input().split())
m=[list(map(int,input().split())) for i in range(h)]
pre=0
ans=0
ret=[]
l=[[0,w,1],[w-1,-1,-1]]
for i in range(h):
    a,s,d=l[i%2]
    for j in range(a,s,d):
        if (pre+m[i][j])%2:
            pre=1
            x,y=(i,j+d) if 0<=j+d<=w-1 else (i+1,j) 
            if 0<=x<h and 0<=y<w:
              ans+=1
              ret.append([i+1,j+1,x+1,y+1])
        else:pre=0
print(ans)
for g in range(ans):
    print(*ret[g])


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

#define ll long long int
#define str string

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Max = INF, Min = -1;
ll a = 0, b = 0, c = 0, n = 0, sum = 0;
ll A[500000] = {}, B[500000] = {}, rui[500000] = {}, dp[100][10] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
str S, T;
bool check = true, check2 = false;

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

int main() {

	//Code Line
	cin >> n >> a >> b;
	for (int i = 0; i < b; i++)cin >> A[i];
	for (int i = 0; i < b; i++)B[A[i]]++;
	for (int i = 1; i <= n; i++) {
		if (a - b + B[i] > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 8832
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();

        ll A, B, C;
        cin >> A >> B >> C;

        ll ans = 0ll;

        ll dec = min(B, C);
        ans += 2 * dec;
        B -= dec;
        C -= dec;

        if (C > 0) {
            dec = min(A, C);
            ans += dec;
            A -= dec;
            C -= dec;
            if(C > 0) ans++;
        } else if (B > 0) {
            ans += B;
        }

        cout << ans << endl;
    }
};


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

    Solve().solve();


    return 0;
}


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

const int mod = 1000000007;
const int MAX_N = 1000000;

int func(int n){
    if(n%2){
        return 3*n+ 1;
    }else{
        return n/2;
    }
}

int main(){
    int s;
    cin >> s;
    map<int,int> mp;
    
    //mp[s]の初期値は０だった。
    //一度登場するとインクリメントが行われる。
    mp[s]++;
    //最短で一致するとa2となるので。
    int count = 2;

    while(1){
        //この時点でｓは別物のｓとなる。
        s = func(s);

        //なるほど、同じ数字が出てくると同じ配列？の通し番号
        //にアクセスすることを利用しているのか。
        if(mp[s]){
            cout << count << endl;
            return 0;
        }
        //一度登場するとインクリメントが行われる。
        mp[s]++;
        count++;
        
    }
    


    

}


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

#define MIN(a, b) (a > b ? b : a)

const char WHITE = '.';
const char BLACK = '#';

int main(void) {
  ll N; cin >> N;
  vector<pair<ll, ll> > S;
  ll b = 0;
  ll w = 0;
  int state = 0;
  for (int i = 0; i < N; i++) {
    char stone; cin >> stone;
    if (state == 0 && stone == BLACK) {
      state = 1;
      b = 1;
    } else if (state == 1) {
      if (stone == BLACK) b++;
      else {
        state = 2;
        w = 1;
      }
    } else if (state == 2) {
      if (stone == BLACK) {
        if (!S.empty()) S.push_back(make_pair(b+S.back().first, w+S.back().second));
        else S.push_back(make_pair(b, w));
        state = 1;
        b = 1;
      } else w++;
    }
  }
  if (state == 2) {
    if (!S.empty()) S.push_back(make_pair(b+S.back().first, w+S.back().second));
    else S.push_back(make_pair(b, w));
  }

  ll a = N;
  if (!S.empty() && S.back().second < a) a = S.back().second;
  for (ll i = 0; i < S.size(); i++) {
    ll tmp = S.at(i).first + S.back().second-S.at(i).second;
    if (tmp < a) a = tmp;
  }
  if (S.empty()) a = 0;
  cout << a << endl;

  return 0;
}


Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC052_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            int ans = 0;
            int x = 0;
            for(int i = 0; i < n; i++)
            {
                if(s[i] == 'I')
                {
                    x += 1;
                }
                else
                {
                    x -= 1;
                }
                ans = Math.Max(ans, x);
            }
            Console.WriteLine(ans);
            Console.Read();
        }
    }
}


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

using namespace std;

typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    int n; cin >> n;
    int a[n];
    int ans = 1;
    int even = 1;
    for (int i = 0; i < n; i++)
    	{
    		cin >> a[i];
    		if (!(a[i] % 2))
    		{
    			even *= 2;
    		}
    		ans *= 3; 
    	}
    ans -= even;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];

  vector<ll> dp(n, INF);
  dp[0] = 0;

  rep(i, n-1) {
    chmin(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
    if (i < n-2) chmin(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
  }

  cout << dp[n-1] << endl;


  return 0;
}


Measured memory_bytes: 1792
#include <tuple>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
using ll	= long long;
using ull	= unsigned long long;
using ld	= long double;
using pii	= pair<int,int>;
using pll	= pair<ll,ll>;
using vi	= vector<int>;
using vb	= vector<bool>;
using vc	= vector<char>;
using vvi	= vector<vi>;
using vvb	= vector<vb>;
using vpii	= vector<pii>;
using vpll	= vector<pll>;
using vll	= vector<ll>;
using vull	= vector<ull>;
using vvll	= vector<vll>;
#define ever (;;)
#define f first
#define s second
#define pb emplace_back
#define sz size()
#define graph vector<vertex>
#define deg(X) (int)G[X].e.size()
#define INF 1234567890
#define INFll 2000000000000000000
#define maxe(X, Y) if((Y) > (X)) (X) = (Y)
#define mine(X, Y) if((Y) < (X)) (X) = (Y)
#define rep(i, begin, end) for(__typeof(end) i = (begin); i < (end); ++i)
#define repr(i, begin, end) for(__typeof(end) i = (begin)-1; i >= (end); --i)
#define bend(X) X.begin(), X.end()
pii operator+(const pii& A, const pii& B) { return {A.f+B.f, A.s+B.s}; }
pii operator-(const pii& A, const pii& B) { return {A.f-B.f, A.s-B.s}; }
pii operator-(const pii& A) { return {-A.f, -A.s}; }

//
// END OF DEFINES
//

int n;
vll T;
vvll DP;
vll P;

bool in() {
	scanf("%d", &n);
	T.resize(n);
	P.resize(n+1);
	DP.resize(n, vll(n, INFll));
	rep(i, 0, n)
		scanf("%lld", &T[i]);
	
	return true;
}

ll get(int a, int b) {
	return P[b+1]-P[a];
}

ll solve() {
	rep(i, 0, n)
		P[i+1] = P[i]+T[i];
	
	rep(i, 0, n)
		DP[i][i] = 0;
	
	/*rep(i, 0, n-1)
		rep(j, i+1, n)
			rep(k, i, j-1)*/
	rep(l, 1, n) {
		rep(i, 0, n-l) {
			int j = i+l;
			rep(k, i, j)
				mine(DP[i][j], DP[i][k]+get(i, k)+DP[k+1][j]+get(k+1, j));
		}
	}
	
	return DP[0][n-1];
	
	return -INF;
}

int main() {
	int noOfTests = 1;
	//scanf("%d", &noOfTests);
	
	while(noOfTests --> 0) {
		if(!in()) {
			printf("popsute wejscie\n");
			continue;
		}
		ll result = solve();
		if(result == ll(-'t'))
			printf("TAK\n");
		else if(result == ll(-'n'))
			printf("NIE\n");
		else if(result != -INF)
			printf("%lld\n", result);
	}
	
	return 0;
}


Measured memory_bytes: 1536
/*  -*- coding: utf-8 -*-
 *
 * f.cc: F: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

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

  ll ssum = 0, minb = 0, maxsum = 0;
  for (int i = 0; i < n; i++) {
    ll xi;
    int si;
    scanf("%lld%d", &xi, &si);

    ll b = ssum - xi;
    ssum += si;
    ll a = ssum - xi;
    if (minb > b) minb = b;
    ll sum = a - minb;
    if (maxsum < sum) maxsum = sum;
  }

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


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

int main() {
    map<string, int> dict; 

    int n; cin >> n; 
    for (string x; n--; dict[x]++) { 
        cin >> x; 
    }
    
    ll aa=-1;
    
    auto begin = dict.begin(), end = dict.end();
    for (auto iter = begin; iter != end; iter++) {
        ll x=iter->second;
        aa=max(aa,x);
    }
    
    
    for (auto iter = begin; iter != end; iter++) {
        ll x=iter->second;
        if(aa==x){
            cout << iter->first << endl;
        }
    }
    
    
    
    return 0;
}





Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 50;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N;
vector<vi> G;
int used[101010];
int Size[101010];

void solve() {
    queue<int> que;
    FOR(N) {
        if (G[i].size() == 1)
            que.push(i);
        Size[i] = G[i].size();
    }
    while (!que.empty()) {
        int idx = que.front();
        que.pop();
        if (used[idx])
            continue;
        used[idx] = 1;
        if (Size[idx] == 0) {
            cout << "First" << endl;
            return;
        }
        int nxt;
        for (auto& tmp : G[idx]) {
            if (!used[tmp]) {
                nxt = tmp;
                used[tmp] = 1;
                break;
            }
        }
        for (auto& v : G[nxt]) {
            Size[v]--;
            if (!used[v] && Size[v] <= 1)
                que.push(v);
        }
    }
    cout << "Second" << endl;
    return;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    G.resize(N);
    FOR(N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].pb(b);
        G[b].eb(a);
    }


    solve();
    return 0;
}


Measured memory_bytes: 8320
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

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

    loop {
        let n: String = sc.read();
        if n == "0" {
            break;
        }
        let ans = n.bytes().map(|c| c as u32 - '0' as u32).sum::<u32>();
        println!("{}", ans);
    }
}



Measured memory_bytes: 5024
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll N;
char s[10010][20] = {};
ll counter = 0;
ll type[5] = {};

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> s[i];
		for (int j = 0; j <= 10; j++) {
			if (s[i][j] == NULL) {
				if (s[i][0] == 'B') {
					if (s[i][j - 1] == 'A') {
						type[4]++;
					}
					else {
						type[2]++;
					}
				}
				else {
					if (s[i][j - 1] == 'A') {
						type[3]++;
					}
					else {
						type[1]++;
					}
				}
				break;
			}
			if (i > 0 && s[i][j] == 'B' && s[i][j - 1] == 'A')counter++;
		}
	}
	if (type[2] == 0 && type[3] == 0 && type[4] != 0) {
		counter += min(type[2] + type[4], type[3] + type[4]) - 1;
	}
	else {
		counter += min(type[2] + type[4], type[3] + type[4]);
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl

using namespace std;

using ll = int64_t;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

template <class T>
ostream &operator<<(ostream &os, vector<T> const &vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math {
ll gcd(ll u, ll v) {
    while (v != 0) {
        ll r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;

    return ((m / math::gcd(m, n)) * n);
}
}  // namespace math

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) {}
    bool unionSet(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) { return root(x) == root(y); }
    ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    ll size(ll x) { return -data[root(x)]; }
};

template <class T, class U>
pair<T, U> operator+(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first + b.first, a.second + b.second);
}

template <class T, class U>
pair<T, U> operator-(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first - b.first, a.second - b.second);
}

ll bound(function<bool(ll)> f, ll ng, ll ok) {
    while (abs(ng - ok) > 1) {
        ll mid = (ng + ok) / 2;
        if (f(mid))
            ok = mid;
        else
            ng = mid;
    }

    return ok;
}

int main(void) {
    ll N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    K--;
    if (S[K] == 'A')
        S[K] = 'a';
    if (S[K] == 'B')
        S[K] = 'b';
    if (S[K] == 'C')
        S[K] = 'c';

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 888
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    ll M,D;
    cin>>M>>D;
    ll count=0;
    REPi(i,1,D+1){
        int D10,D1;
        D1=i%10;
        D10=(i-D1)/10;
        //cout<<"D10= "<<D10<<","<<"D1= "<<D1<<endl;
        if(D1*D10<=M&&D1>=2&&D10>=2){
            count+=1;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
import numpy as np
N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))
dp=np.array([0 for i in range(N)])
dp[0]= 0
dp[1]=abs(h[1]-h[0])
if N<=K:
    dp[N-1]=abs(h[0]-h[N-1])
else:  
    for i in range(2,N):
      j=max(0,i-K)
      dp[i]=np.min(dp[j:i]+np.abs(h[i]-h[j:i]))
      #dp[i]=min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(k+1,i+1))])
print(int(dp[-1]))

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

const int MAXN = 1e5+5;
int f[MAXN];
int n, m, x, y, z, cnt;

int find(int x)
{
	if(x != f[x])
		f[x] = find(f[x]);
	
	return f[x];
}

int main()
{
	cin >> n >> m;
	
	for(int i = 1; i <= n; ++i)
		f[i] = i;
	for(int i = 1; i <= m; ++i)
	{
		cin >> x >> y >> z;
		
		x = find(x);
		y = find(y);
		
		if(x != y)
			f[y] = x;
	}
	
	for(int i = 1; i <= n; i++)
		if(f[i] == i)
			cnt++;
	
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long r = 0, g = 0, b = 0;
  for(int i = 0; i < n; ++i){
    if(s[i] == 'R') r++;
    else if(s[i] == 'G') g++;
    else b++;
  }
  long long ans = r * g * b;
  for(int i = 0; i < n; ++i){
    for(int j = 1; ; ++j){
      if( i - j < 0 || i + j >= n) break;
      if(s[i] != s[i + j] && s[i - j] != s[i] && s[i - j] != s[i + j]) ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
a.sort(reverse = True)

N = n+2
P = mod
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

base = 1
for item in range(n-k+1, n):
    base = (base * item) % mod
for i in range(1, k):
    base = (base * inv_t[i]) % mod
base2 = base

ans = 0
top = n - 1
for ai in a:
    if top < k-1:
        break
    ans += base * ai
    ans %= mod

    base = base * inv_t[top] * (top - k + 1)  % mod
    top -= 1

top = n-1
for ai in reversed(a):
    if top < k-1:
        break
    ans -= base2 * ai
    ans %= mod
    base2 = base2 * inv_t[top] * (top - k + 1)  % mod
    top -= 1
print(ans % mod)


Measured memory_bytes: 14044
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        double[] arr = new double[n];

        for(int i = 0; i < n;i++){
            arr[i] = in.nextInt();
        }

        double sum = 0;

        for(int i = 0; i < arr.length;i++){
            sum += 1/arr[i];
        }

        System.out.println(1/sum);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,a;
	cin>>s>>a;
	for(int i=0;i<s.size();i++){
		cout<<s[i];
		if(i<a.size()){
			cout<<a[i];
		}
	}
	return 0;
}

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

int main(){
    int N;
    cin>>N;
    int num[N];
    for(int i=0;i<N;i++){
        cin>>num[i];
    }
    double ans,bass;
    for(int j=0;j<N;j++){
        bass+=1/(double)num[j];
    }
    ans=1/bass;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(n); ++i)
#define REP(i, d, n) for(long long i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() {//言語変えろ言語変えろ言語変えろ言語変えろ言語変えろ
            
int a,b,k; cin>>k>>a>>b;
  int sa=b-a; int h; h=a; int ans=0;
  rep(i,sa+1){if(h%k==0){ans=1;} h++; }
  if(ans==1){cout<<"OK"<<endl;}
  else{cout<<"NG"<<endl;}
  
}

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

using namespace std;

int main() {
    
    long long x,a,b,c;
    cin>>x>>b>>c;
    a=abs(x);
   
    long long temp=a/c;
    
    if(temp>b)
    {
      unsigned long long t1=(a-(b*c));
      cout<<t1<<endl;
    }
    else
    {
        if(temp==b)
        {  
            if(a%c)
            {
                cout<<(a%c)<<endl;
            }
            else
            {
            cout<<0<<endl;
            }
        }
        else
        {
            if(a%c==0)
            {  
                b-=temp;
                
                    if(b%2==0)
                    {
                        cout<<(0)<<endl;
                    }
                    else
                    {
                        cout<<(c)<<endl;
                    }
                
            }
            else
            {
              b-=temp;
              if(b%2==0)
              {
                  cout<<(a%c)<<endl;
              }
              else
              {
              long long t1=(a%c)+c;
              long long t2=(a%c)-c;
              if(abs(t1>abs(t2)))
              {
                  cout<<(abs(t2))<<endl;
              }
              else
              {
                  cout<<(abs(t1))<<endl;
              }
              }
              
            }
        }
    }
    
}


Measured memory_bytes: 3620
N = int(input())
H = list(map(int,input().split()))
f = True
for i in reversed(range(1,N)):
    if H[i-1]<=H[i]:
        continue
    elif H[i-1]-H[i] == 1:
        H[i-1] -= 1
    else:
        f = False
        break

if f:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14396
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
int main() {
	ll x, y;
	cin >> x >> y;
	if (x > 0 && y == 0)cout << x + 1 << endl;
	else if (x < 0 && y == 0)cout << abs(x) << endl;
	else {
		if (x < 0) {
			if (y < 0) {
				if (abs(x) - abs(y) < 0) {
					cout << abs(y) - abs(x) + 2 << endl;
				}
				else cout << abs(x) - abs(y) << endl;
			}
			else {
				if (abs(x) - y < 0) {
					cout << y - abs(x) + 1 << endl;
				}
				else cout << abs(x) - y + 1 << endl;
			}
		}
		else {
			if (y < 0) {
				if (abs(y) - x < 0) {
					cout << x - abs(y) + 1 << endl;
				}
				else {
					cout << abs(y) - x + 1 << endl;
				}
			}
			else {
				if (y - x < 0) {
					cout << x - y + 2 << endl;
				}
				else {
					cout << y - x << endl;
				}
			}
		}
	}
	return 0;
}

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

int main()
{
    long long a,b,k;
    cin>>a>>b>>k;
    if(a>=k)
    {
        a-=k;
        k=0;
    }
    else
    {
        k-=a;
        a=0;
    }
    if(k!=0)
    {
        if(b>=k) b-=k;
        else b=0;
    }
    cout<<a<<" "<<b;
}

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

int main(){
  int N;
  cin>>N;
  
  string s[N];
  int t[N];
  
  for(int i=0;i<N;i++){
    cin>>s[i]>>t[i];
  }
  
  string title;
  cin>>title;
  
  int sum=0;
  int index;
  for(int i=0;i<N;i++){
    if(s[i]==title){
      index=i; break;
    }
  }

  for(int i=index+1;i<N;i++){
    sum=sum+t[i];
  }
  
  cout<<sum;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<double> a(n);for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  for(int i=1;i<n;i++){
    a[i]=(a[i]+a[i-1])/2;
  }
  cout<<a.back()<<endl;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict,deque

input = sys.stdin.readline
def inar():
    return [int(el) for el in input().split()]
def find(a,b,c):
    gc=math.gcd(a,b)
    return math.gcd(gc,c)
def main():
    k=int(input())
    ans=0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for k in range(1,k+1):
                ans+=find(i,j,k)
    print(ans)


if __name__ == '__main__':
    main()





Measured memory_bytes: 73860
#include <stdio.h>
#include <algorithm>
using namespace std;

#define MAX_N (200010)
#define INF (1e9 + 10)


int n;

int main()
{
    int i;
    int ans = -INF;
    int min_v;
    scanf( "%d", &n );

    for ( i = 0; i < n; i++ ) {
	int r;
	scanf("%d", &r);
	if ( i == 0 ) {
	    min_v = r;
	}
	else {
	    ans = max( ans, r - min_v );
	    min_v = min( min_v, r );
	}
    }

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

    return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

vector<int> as;

int memo[100000 + 1];
bool canWin(int num){
    if(num == 0){ return false; }
    if(memo[num]){ return memo[num] == 1; }
    for(auto& a : as){
        if(num >= a && !canWin(num - a)){
            memo[num] = 1;
            return true;
        }
    }
    memo[num] = -1;
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    as.resize(n); cin >> as;
    cout << (canWin(k) ? "First" : "Second") << '\n';
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,r,count;
  while(1){
    count = 0;
    cin >> a >> b;
    if(a==0 && b==0) break;
    if(a<b) swap(a,b);
    while(b>0){
      r = a % b;
      a = b;
      b = r;
      count++; 
    }
    cout << a << " " << count << endl;
  }
  return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
using namespace std;



int main() {
	int a, b, c, x, y,cpiz;
	cin >> a >> b >> c >> x >> y;
	if (a + b < 2*c) {
		cout << a * x + b * y << endl;
		return 0;
	}
	else {
		cpiz = min(x, y) * 2;
		if (a > c * 2) {
			cpiz += (x - (cpiz / 2)) * 2;
		}
		if (b > c * 2 && y - (cpiz / 2) > 0) {
			cpiz += (y - (cpiz / 2)) * 2;
		}
	}
	cout << cpiz * c + max(0, x - cpiz / 2)*a + max(0, y - cpiz / 2)*b << endl;
	return 0;
	
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const ll MOD=1e9+7;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
const int MAXN=2e5+10;
int N;
int A[MAXN];
bool vis[MAXN];
ll K;
void solve()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>K;
    ++K;
    for(int u=1;u<=N;u++){
        cin>>A[u];
    }
    vector<int>seq;
    int p=1;
    while(!vis[p]){
        vis[p]=true;
        seq.push_back(p);
        p=A[p];
    }
    ll head=0;
    while(seq[head]!=p)++head;
    if(K<=head){
        cout<<seq[K-1];
        return;
    }
    K-=head;
    int sz=seq.size()-head;
    if(K%sz==0)cout<<seq.back();
    else cout<<seq[K%sz+head-1];
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();    
}

Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

const int w=13;
const int k=100;
const int n=26;

VI c(n);
VVI s(365,VI(n));

struct st{
	VI a;
	ll score;
	bool operator<(const st &another) const {return score < another.score;};
};

vector<st> f(st p){
	VI a=p.a; ll score=p.score;
	int now=a.size()+1;
	VI last(n,0);
	REP(i,a.size())
		last[a[i]]=i+1;
	VI down(n); ll downsum=0;
	REP(i,n){
		down[i]=c[i]*(now-last[i]);
		downsum+=down[i];
	}
	a.push_back(-1);
	vector<st> tmp;
	REP(i,n){
		a[now-1]=i;
		tmp.push_back({a,score-downsum+down[i]+s[now-1][i]});
	}
	sort(ALL(tmp));
	vector<st> ret;
	REP(i,w)
		ret.push_back(tmp[n-1-i]);
	return ret;
}


int main(){
	int d; cin >> d;
	REP(i,n) cin >> c[i];
	REP(i,d)REP(j,n) cin >> s[i][j];
	priority_queue<st> q;
	VI a(0);
	q.push({a,0});
	REP(i,d){
		priority_queue<st> next;
		REP(j,k){
			if(q.empty())
				break;
			for(auto nx:f(q.top()))
				next.push(nx);
			q.pop();
		}
		q=next;
	}
	REP(i,d)
		cout << q.top().a[i]+1 << endl;
	return 0;
}

Measured memory_bytes: 12904
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    double b = 0.0;
    for (auto aa : a) {
        b += 1.0 / aa;
    }

    cout << setprecision(6) << 1 / b << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    int d, n;
    cin >> d >> n;
    ll ans = 1;
    if (d == 1) ans = 100;
    if (d == 2) ans = 100 * 100;
    if (n == 100) n = 101;
    cout << ans * n << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  int num = 0;
  for (int i = 0; i < N; i++)
  {
    if (S[i] == 'I')
      num++;
    else
      num--;
    if (ans < num)
      ans = num;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <string>
#include <map>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define LargeNum 1000000007
typedef pair <double, double> P;

int main(){
    int N, ans = -1000000001, tmp;
    cin >> N;
    bool F[N][5][2];
    int P[N][11];
    int count[N];
    bitset<10> b;
    rep(i, N){
        rep(j, 5){
            cin >> F[i][j][0] >> F[i][j][1];
        }
    }
    rep(i, N){
        rep(j, 11){
            cin >> P[i][j];
        }
    }
    for (int i=1; i<pow(2, 10); i++){
        rep(mise, N) count[mise] = 0;
        b = i;
        rep(yo, 5){
            rep(ji, 2){
                if(b[yo*2 + ji]==1){
                    rep(mise, N){
                        if(F[mise][yo][ji] == 1) count[mise] ++;
                    }
                }
            }
        }
        tmp = 0;
        rep(mise, N){
            tmp += P[mise][count[mise]];
        }
        if (ans < tmp) ans = tmp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]
    total = 0
    for i in range(len(A)-1):
        total += abs(A[i+1] - A[i])

    for i in range(N):
        print(total - abs(A[i+1] - A[i]) - abs(A[i+2] - A[i+1])+ abs(A[i+2] - A[i]))



if __name__ == '__main__':
    main()


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


#define bug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << ' ' ;err(++it, args...);}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{os << "[";for (int i = 0; i < v.size(); ++i) {os << v[i];if (i != v.size() - 1)os << ", ";}os << "]\n";return os;}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{os << "[";for (auto it : v) {os << it;if (it != *v.rbegin())os << ", ";}os << "]\n";return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << it.first << " : "<< it.second << "\n";return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(";os << v.first << ", "<< v.second << ")";return os;}
//long long powr(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;}return res;}





int main(){
    int n;

    string s,s1,s2;
    char c;

    scanf("%d",&n);

    for(int i=0;i<n;i++){
            c='1'+i;
            s.push_back(c);

    }

    for(int i=0;i<n;i++){
      cin>>c;
      s1.push_back(c);
    }

    for(int i=0;i<n;i++){
       cin>>c;
      s2.push_back(c);
    }

    long long i=0,inx1=0,inx2=0;


    do{
        i++;
        if(s==s1)inx1=i;
        if(s==s2)inx2=i;
    }while(next_permutation(s.begin(),s.end()));
    //bug(inx1,inx2)

    cout<<abs(inx2-inx1)<<endl;

}


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

int main() {
    int k,x;cin>>k>>x;
    int tmp;
    
    for(int i=0;i<2*(k-1);++i){
    tmp=x-k+1+i;
    cout<<tmp<<" ";
    }
    tmp=x+k-1;
    cout<<tmp<<endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * Calculate the greatest common divisor of `x` and `y` with Euclidean algorithm
 */
tailrec fun gcd(x: Long, y: Long): Long = if (y == 0L) x else gcd(y, x % y)

fun main(args: Array<String>) {
    readLine()
    val A = readLine()!!.split(" ").map{it.toLong()}
    println(A.fold(0L, ::gcd))
}


Measured memory_bytes: 52008
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int[] price;
	static int[] stock;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int[] r1 = new int[26];
		int[] r2 = new int[26];
		Arrays.fill(r1, -1);
		Arrays.fill(r2, -1);
		
		for (int i = 0; i < s.length(); i++) {
			char cs = s.charAt(i);
			char ct = t.charAt(i);
			int si = cs - 'a';
			int ti = ct - 'a';
			
			if (r1[si] < 0) {
				r1[si] = ct;
			} else if (r1[si] != ct) {
				System.out.println("No");
				return;
			}
			if (r2[ti] < 0) {
				r2[ti] = cs;
			} else if (r2[ti] != cs) {
				System.out.println("No");
				return;
			}
		}
		
		System.out.println("Yes");
		
	}
	
}


Measured memory_bytes: 26244
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int ans[2010][2010];
char s[2010][2010];
int main()
{
    int n, m;
    while(cin>>n>>m)
    {
        int x, tmp;
        for(int i=0; i<n; ++i)
        {
            scanf("%s",s[i]);
            tmp=-1;
            for(int j=0; j<m; ++j)
            {
                if(s[i][j]=='#')
                {
                    tmp=j;
                }
                ans[i][j]+=j-tmp;
            }
            tmp=m;
            for(int j=m-1; j>=0; --j)
            {
                if(s[i][j]=='#')
                {
                    tmp=j;
                }
                ans[i][j]+=tmp-j;
            }
        }
        for(int i=0; i<m; ++i){
            tmp=-1;
            for(int j=0; j<n; ++j){
                if(s[j][i]=='#'){
                    tmp=j;
                }
                ans[j][i]+=j-tmp;
            }
            tmp=n;
            for(int j=n-1; j>=0; --j){
                if(s[j][i]=='#'){
                    tmp=j;
                }
                ans[j][i]+=tmp-j;
            }
        }
        int mx=0;
        for(int i=n-1; i>=0; --i)
        {
            for(int j=0; j<m; ++j){
                mx=max(mx, ans[i][j]-3);
            }
        }
        cout<<mx<<endl;
    }
    return 0;
}




Measured memory_bytes: 19840
S = input()
abc = [chr(i) for i in range(ord("a"), ord("z")+1)]

if len(S) == 26:
    for i in range(24, -1, -1):
        #後ろから文字に注目
        cand = list(S[i+1:])
        # print(f"cand {cand}")
        cand.sort()
        for c in cand:
            #大きい文字があった場合、挿げ替える
            if ord(c) > ord(S[i]):
                print(S[:i]+c)
                exit()
    print(-1)
else:
    for l in abc:
        if l not in S:
            print(S+l)
            exit()

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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  
  int ans = 0;
  
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if (500 * i + 100 * j + 50 * k == x) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
		vector<int> mochi(100);
		int n, count = 1;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> mochi.at(i);
		}

		sort(mochi.begin(), mochi.end());
		reverse(mochi.begin(), mochi.end());
		for (int i = 1; i < n; i++) {
			if (mochi.at(i - 1) > mochi.at(i)) {
				count++;
			}
		}
		cout << count;
}


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

#define PI 4*atan(1)
#define INF 1e8

typedef long long ll;

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++)cin >> A[i];
  
  vector<int> cnt(100000 + 2, 0);
  for(auto a : A){
    if(a - 1 >= 0)cnt[a - 1]++;
    cnt[a]++;
    cnt[a + 1]++;
  }
  int ans = 0;
  for(int i = 0; i < cnt.size(); i++){
    ans = max(ans, cnt[i]);
  }
  cout << ans << endl;
}


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

using namespace std;

int n;
int a[N];
map<int,int>b;

bool ok(int mij)
{
    int i , k;

    b.clear();

    for(i = 2 ; i <= n ; i++)
        if(a[i]<=a[i - 1])
        {
            b.erase(b.upper_bound(a[i]) , b.end());
            k = a[i];
            ++b[k];

            while(k > 0 && b[k] == mij)
            {
                b.erase(k);
                ++b[--k];
            }

            if(!k) return false;
        }

    return true;
}

int main()
{
    int f = 0 , i; cin >> n;
    for(i = 1 ; i <= n ; i++)
        cin>>a[i], f |= (a[i] <= a[i - 1]);
    if(!f)
    {
        cout<<1;
        return 0;
    }

    int st=2,dr=n,mij=0,ans=0;

    while(st<=dr)
    {
        mij=(dr-st)/2+st;

        if(ok(mij))
        {ans = mij;
         dr = mij - 1;}
        else st=mij+1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024