akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,a,b) for(register int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(register int i=(a),i##_st=(b);i>=i##_st;--i)
#define For(i,a,b) for(register int i=(a),i##_end=(b);i<=i##_end;++i)
#define rpg(i,x) for(register int i=fir[x];i;i=e[i].nxt)
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define bin(i) (1<<i)
#define cls(x,y) memset(x,y,sizeof x)
typedef pair<int,int> PII;
typedef long long LL;
const int INF = 0x7fffffff;
/*const int _L = 1e6+5;
char ibuf[_L],*ih=ibuf+_L;
inline char gc(){return (ih==ibuf+_L?fread(ibuf,1,_L,stdin),ih=ibuf:0),*ih++;}
#define  getchar() gc() //*/
template <typename T> inline void rd(T &x) {
    x = 0; int f = 1; char CH = getchar();
    while(!isdigit(CH)) {if(CH=='-')f=0;CH=getchar();}
    while(isdigit(CH)) {x=((x+(x<<2))<<1)+(CH-48);CH=getchar();}
    x=(f==1)?x:-x;  return;
}
const int MXN = 5e5 + 5;
int n,a[MXN];
LL ans=1e19;
inline LL calc(int x) {
	LL tmp=0;
	rep(i,1,n) tmp+=abs(x-a[i]);
	return tmp; 
}
int main() {
#ifdef iloi
//	   freopen("test.in","r",stdin);
#endif
	rd(n);rep(i,1,n) rd(a[i]);
	rep(i,1,n) a[i]-=i;
	sort(a+1,a+1+n);
	int l=a[1],r=a[n]; 
	while(r-l>3) {
		int mid1=l+(r-l)/3,mid2=r-(r-l)/3;
		LL tmp1=calc(mid1),tmp2=calc(mid2);
		if(tmp2<tmp1) {
			l=mid1;
		} else {
			r=mid2;
		}
	}
	rep(i,l-1,r+1) {
		ans=min(ans,calc(i));
	}
	cout<<ans;
#ifdef iloi
	debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
}


Measured memory_bytes: 1024
s = input()
n = len(s)

o1 = "10" * (n // 2) + "1" * (n % 2 == 1)
o2 = "01" * (n // 2) + "0" * (n % 2 == 1)

count1 = 0
count2 = 0
for i in range(n):
	if s[i] != o1[i]:
		count1 += 1
	if s[i] != o2[i]:
		count2 += 1
		
print(min(count1,count2))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <list>
#include <string.h>
using namespace std;
#define fo(i,l,r) for(int i=l;i<=r;++i)
#define fi(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define po pop_back
#define INF 1e9+9
void input(vector<int>& arr,int n){
  fo(i,0,n-1){
    cin>>arr[i];
  }
}
void solve(){
  int n;
  cin>>n;
  int last = n%10;
  if(last==2||last==4||last==5||last==7||last==9){
    cout<<"hon";
  }else if(last==0||last==1||last==6||last==8){
    cout<<"pon";
  }else{
    cout<<"bon";
  }
  cout<<endl;
}
int main(){
  solve();
  return 0;
}


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

using ll = long long;
#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, n, m) for(int (i)=(n); (i)<(m); ++i)
#define INF 1e9
//constexpr ll INF = 1LL << 62;
constexpr int mod = 1e9+7;

int main(){
  string s;
  cin >> s;
  int x, y;
  cin >> x >> y;
  vector<int> odds(1, 0), evens;
  int cnt =1;
  REP(i, s.size()){
    if(s[i]=='T'){
      cnt++;
      if(cnt % 2){
        odds.push_back(0);
      }
      else{
        evens.push_back(0);
      }
    }
    else{
      if(cnt % 2){
        odds.back()++;
      }
      else{
        evens.back()++;
      }
    }
  }
  set<int> st;
  st.insert(odds[0]);
  FOR(i, 1, odds.size()){
    set<int> st2;
    for(auto v : st){
       st2.insert(v+odds[i]);
       st2.insert(v-odds[i]);
    }
    st = st2;
  }
  bool ansx = false;
  for(auto v : st){
    if(v == x){
      ansx = true;
    }
  }
  st.clear();
  st.insert(0);
  REP(i, evens.size()){
    set<int> st2;
    for(auto v : st){
      st2.insert(v+evens[i]);
      st2.insert(v-evens[i]);
    }
    st = st2;
  }
  bool ansy = false;
  for(auto v : st){
    if(v == y){
      ansy = true;
    }
  }
  if(ansx && ansy){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

long int gcd(long int x, long int y){
    if (y == 0) return x;
    return gcd(y, x % y);
}

long int lcm(long int x, long int y){
    return (x / gcd(x, y)) * y;
}

int main(){
    long int a, b, c, d;
    cin >> a >> b >> c >> d;
    // cout << lcm(c, d) << endl;
    long int sm = ((b / c - (a - 1) / c) + (b / d - (a - 1) / d) - (b / lcm(c, d) - (a - 1) / lcm(c, d)));
    long int ans = (b - a + 1) - sm;
    // cout << b - a + 1 << endl;
    cout << ans << endl; 
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
dp[1] = abs(h[0] - h[1])
if n == 2:
    print(dp[1])
else:
    dp[2] = abs(h[0] - h[2])
    for i in range(3, n):
        dp[i] = min(abs(h[i - 1] - h[i]) + dp[i - 1], abs(h[i - 2] - h[i]) + dp[i - 2])
    print(dp[n - 1])


Measured memory_bytes: 13928
import java.util.Scanner;

class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int f = scanner.nextInt(); 
        int r =  scanner.nextInt();
        
        while(m != -1 || f != -1 || r != -1){
            if(m == -1 || f == -1){
                System.out.println("F");
            } else if(80 <= m + f)  {
                System.out.println("A");
            } else if(65 <= m + f && m + f < 80)  {
                System.out.println("B");
            } else if((50 <= m + f && m + f < 65) || (30 <= m + f && m + f < 50 && 50 <= r))  {
                System.out.println("C");
            } else if(30 <= m + f && m + f < 50)  {
                System.out.println("D");
            } else if (m + f < 30) {
                System.out.println("F");
            }
            
            m = scanner.nextInt();
            f = scanner.nextInt(); 
            r =  scanner.nextInt();
        }
    }
}


Measured memory_bytes: 26300
//二叉搜索树的插入 
#include<iostream>
#include<cstdlib>
using namespace std;
struct node{
	int key;
	node *p,*l,*r;
};
node *root,*nil;
void Insert(int key)
{
	node *tt=(node*)malloc(sizeof(node));
	tt->key=key;
	tt->l=nil;
	tt->r=nil;
	node *t=root;   //  x
	node *y=nil; 
	while(t!=nil)
	{
		y=t;
		if(tt->key<t->key)
			t=t->l;
		else
			t=t->r;
	}
	tt->p=y;
	if(y==nil)
		root=tt;
	else
	{
		if(tt->key<y->key)
		{
			y->l=tt;
		}
		else
			y->r=tt;
	}
}

void Preorder(node* u)
{
	if(u==nil)
		return;
	cout<<" "<<u->key;
	Preorder(u->l);
	Preorder(u->r);
}

void Inorder(node* u)
{
	if(u==nil)
		return;
	Inorder(u->l);
	cout<<" "<<u->key;
	Inorder(u->r); 
}
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		string s;
		cin>>s;
		if(s[0]=='i')
		{
			int num;
			cin>>num;
			Insert(num);
		}
		else{
			Inorder(root);
			cout<<endl;
			Preorder(root);
			cout<<endl;
		}	
	} 
	return 0;
}


Measured memory_bytes: 26588
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
ll A[5000001],bin[5000001];
vector<ll>v;
map<int,int>myMap;
set<int>mySet;
vector<pair<ll,ll> >vp;
/* Precode Start Here *\



     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
 vector<char>ch;
 for(char i='A';i<='Z';i++)
    ch.push_back(i);
 ll n;
 cin>>n;
 string s;
 cin>>s;
 for(int i=0;i<s.size();i++)
 {
     ll d=s[i]-'A';
     s[i]=ch[(d+n)%26];
 }
 cout<<s<<endl;
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// 0112d
vector<ll> divisor_list(ll n){
    vector<ll> ans;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0){
            ll tmp = n/i;
            ans.push_back(tmp);
            ans.push_back(i);
        }
    }
    return ans;
}

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> dd = divisor_list(m);
    sort(dd.begin(), dd.end(), greater<ll>());
    rep(i, n){
        ll tmp = dd[i];
        if (tmp * n<=m){
            cout << tmp << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
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() {
    ll N, A, B;
    cin >> N >> A >> B;

    ll k = N / (A + B);
    ll ans = k*A;
    ans += min(N - k*(A + B), A);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
side = []
check = 4
A = sorted(set(A), reverse=True)
for i in A:
    if cnt[i] != 1:
        side.append(i)
        check -= cnt[i]
    if check <= 0:
        break
try:
    print(side[0]*side[1])
except IndexError:
    try:
        print(side[0]**2)
    except IndexError:
        print(0)


Measured memory_bytes: 20772
// https://atcoder.jp/contests/abc116/tasks/abc116_c

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 100;
const int H_I_MAX = 100;

int N;
int h[N_MAX];

int dfs(int l, int r, int h0) {
  int hi = *min_element(h + l, h + r);
  int ret = hi - h0;
  int f = l;
  while (true) {
    while (f < r && h[f] == hi) f++;
    if (f >= r) break;
    int t = f + 1;
    while (t < r && h[t] > hi) t++;
    ret += dfs(f, t, hi);
    f = t;
  }
  return ret;
}

void solve() {
  int ans = dfs(0, N, 0);
  printf("%d\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", h + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {

  long long i,j,k,n,m,l,a,b,c;
  long long A[101][101] = {0};
  long long B[101][101] = {0};
  long long C[101][101] = {0};

  scanf("%lld %lld %lld",&n,&m,&l);

  for(j=0; j<n; j++) {
    for(i=0; i<m; i++) {

      scanf("%lld", &a);
      A[j][i] = a;
    
    }
  }

  for(j=0; j<m; j++){
    for(i=0;i<l;i++){
      scanf("%lld",&b);
      B[j][i] = b;
    }
  }

    for(i=0 ;i<n; i++) {
      for(j=0; j<l; j++){
	C[i][j] = 0;
	for(k=0;k<m; k++) {
	   C[i][j] += A[i][k]*B[k][j];  
	   /*    printf("%d ",C[i][j]); */
	}
	/* printf("\n"); */
      }
    }


     for(i=0; i<n; i++) {
      for(j=0; j<l; j++) {
	printf("%lld",C[i][j]);
	if(j !=l-1) {
	  printf(" ");
	}
      }
      printf("\n");
      } 

    return 0;

  }



Measured memory_bytes: 2148
A, B, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

min_a = min(a)
min_b = min(b)
min_std = min_a + min_b
#print(f'最小値：{min_std}')
work = []
cnt = 0
while True:
    cnt += 1
    work.append([int(i) for i in input().split()])
    #print(cnt)
    if cnt == M:
        break
waribiki_list = []
for xyc in work:
    x, y ,c = xyc[0], xyc[1], xyc[2]
    #print(x, y, c)
    waribiki_list.append(a[x-1] + b[y-1] - c)

#print(f'割引の最小値：{min(waribiki_list)}')
if min_std > min(waribiki_list):
    print(min(waribiki_list))
else:
    print(min_std)


Measured memory_bytes: 36468
import java.io.*;
import java.util.*;
 
public class Main{
 
    public static void main(String[] args) {

        ArrayList<Integer> intAry = new ArrayList<Integer>();
 
        int intAnswer = 0;

        try {
            BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
 
            while(true) {
                String strLine = insBR.readLine();

                if(strLine.equals("0")) {
                    break;
                }
 

                char[] chaAryLine = strLine.toCharArray();
 
                for(int i = 0; i < chaAryLine.length; i++) {
                    int intNum = Integer.parseInt("" + chaAryLine[i]);
 
                    intAnswer += intNum;
                }
                intAry.add(intAnswer);

                intAnswer = 0;
 
            }
            int intSize = intAry.size();

            for(int i = 0; i < intSize; i++) {
                System.out.println(intAry.get(i));
            }
 
        } catch (IOException e) {
            System.out.println(e);
        }
 
    }
}

Measured memory_bytes: 17196
#include <stdio.h>
#define INF 1000000000

int main()
{
    int m = 0, n, i, j = 0, k, l = -INF, x = -INF, y = -1;
    int max = -INF, min2 = INF, min1 = INF;
    int s[200000] = {0};
    
    scanf ("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%d", &s[i]);
    }
    
    for (i = 0; i < n; i++) {
        if (s[i] < min1) {
            min2 = min1;
            min1 = s[i];
            k = min1 - min2;
            if (k > l) {
                l = k;
            }
            m = i;
            max = min1;
            for ( j = m + 1; j < n; j++) {
                if (max <= s[j]) {
                    max = s[j];
                    y = max - min1;
                }
            }
            if (y > x) {
                x = y;
            }
        }
    }
    
    if (x < 0) {
        x = l;
    }
    
    printf ("%d\n", x);
    
    return 0;
}

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

#define MAX 100

int main()
{
    // cout << "Chokudai Contest 004" << endl;

    int N = 0;
    int B[MAX] = { 0 };
    // 入力
    scanf("%d", &N);
    for( int count = 0; count < N-1; count++ ) {
        scanf("%d", &B[count]);
    }


    int maxSum = B[0];
    int tmp = 0;

    // 計算
    // 左から順番に探索する
    for( int count = 0; count < (N-1); count++ ) {
        if( B[count] < B[count+1] ) {
            maxSum += B[count];
        }
        else {
            maxSum += B[count+1];
        }
    }

    maxSum += B[N-2];

    cout << maxSum << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ab = sorted(ab, key=lambda x:x[1])
deleted = ab[0][1]-1
ans = 1
for a, b in ab:
    if a <= deleted < b:
        pass
    else:
        deleted = b - 1
        ans += 1

    
print(ans)

Measured memory_bytes: 29852
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b;
cin >> a >> b;
if(a<=9&&b<=9) {
  cout << a*b << endl;
} else {
  cout << "-1" << endl;
}
return 0;
}


Measured memory_bytes: 256
n = int(input())

k = 0
for i in range(1, 2*n+1):
    if i*(i-1) == 2*n:
        k = i

#print(k)
if not k:
    print('No')
    exit()

S = [[] for _ in range(k)]
import itertools
C = list(itertools.combinations(range(k),2))
for i in range(n):
    j = i+1
    c1, c2 = C[i]
    S[c1].append(j)
    S[c2].append(j)

print('Yes')
print(k)
for i in range(k):
    print(len(S[i]), *S[i])


Measured memory_bytes: 50556
S = input()
result = [0]*len(S)
index = -1
pre = -1
while True:
    index = S.find('RL', index + 1)
    if index == -1:
        break
    result[index] += (index-pre-1)//2+1
    result[index+1] += (index-pre)//2
    pre = index
    index = S.find('LR', index + 1)
    if index == -1:
      index = len(S)-1
    result[pre] += (index-pre)//2
    result[pre+1]  += (index-pre-1)//2+1
    pre = index
print(' '.join(map(str,result)))

Measured memory_bytes: 10484
/**
 * いやなんでこれでサンプルと合わないのか全然分からない
**/
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

const int MAX = 910000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();

    int X, Y;
    cin >> X >> Y;

    if(X == Y*2 || X*2 == Y){
        cout << 1 << "\n";
        return 0;
    }
    if((X%3 == 1 && Y%3 == 2) || (X%3 == 2 && Y%3 == 1) || (X%3 == 0 && Y%3 == 0)){
        ll A = abs(X - Y);
        ll B = (min(X, Y) - A)/3;
        A += B;
        cout << COM(A + B, A) << "\n";
        return 0;
    }
    cout << 0 << "\n";
    return 0;
}


Measured memory_bytes: 21632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		String str = sc.next();
		
		int count = 0;
		for(int i = 0; i < str.length() / 2; i++) {
			if(str.charAt(i) != str.charAt(str.length() - i -1)){
				count++;
			}
		}
		
		System.out.println(count);
	}

}


Measured memory_bytes: 21972
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <climits>
#include <cfloat>
#include <algorithm>
using namespace std;

class Bit
{
	int n;
	vector<long long> data;
public:
	Bit(int n){
		this->n = n;
		data.assign(n+1, 0);
	}
	void add(int k, long long x){
		++ k;
		while(k <= n){
			data[k] += x;
			k += k & -k;
		}
	}
	long long sum(int k){
		++ k;
		long long ret = 0;
		while(k > 0){
			ret += data[k];
			k -= k & -k;
		}
		return ret;
	}
	long long sum(int a, int b){
		return sum(b) - sum(a-1);
	}
};

int main()
{
	int n, m, l;
	cin >> n >> m >> l;

	vector<int> k(n);
	for(int i=0; i<n; ++i){
		cin >> k[i];
		-- k[i];
	}
	sort(k.begin(), k.end());

	Bit s(m);
	for(int i=0; i<m; ++i){
		int a;
		cin >> a;
		s.add(i, a);
	}

	vector<long long> dp(1);
	dp[0] = s.sum(k[0], k[1]) / l;
	for(int i=2; i<n; ++i){
		vector<long long> nextDp(i, LLONG_MAX);
		for(int j=0; j<i-1; ++j){
			nextDp[i-1] = min(nextDp[i-1], dp[j] + s.sum(k[j], k[i]) / l);
			nextDp[j] = min(nextDp[j], dp[j] + s.sum(k[i-1], k[i]) / l);
		}
		dp.swap(nextDp);
	}

	long long ret = LLONG_MAX;
	for(int i=0; i<n-1; ++i)
		ret = min(ret, dp[i] + s.sum(k[i], k[n-1]) / l);
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 1716
import math


def comb(n, r):
    if n < r or r < 0:
        return 0
    nume = 1
    deno = 1
    for i in range(1, r + 1):
        nume *= (n - i + 1)
        deno *= (i)
    return nume//deno


def solve(N, K):
    if N < K:
        return 0
    if K == 0:
        return 1
    keta = math.floor(math.log(N, 10)) + 1
    x = N//pow(10, keta-1)
    ret = 0
    if K > keta:
        return 0
    # ptn1: 最大の桁は0
    if keta != K:
        ret += comb(keta - 1, K) * (9 ** K)
    # ptn2: 最大の桁はNのその桁の値未満
    ret += (x-1)*comb(keta-1, K-1)*pow(9, K-1)
    # ptn3: 最大の桁はNのその桁の値
    ret += solve(N % pow(10, keta-1), K - 1)
    return ret


N = int(input())
K = int(input())
ans = solve(N, K)
print(ans)


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

int main() {
    vector<int> c(9);
    for (int i = 0; i < 9; i++) cin >> c[i];
    
    int n = (c[3]+c[4]+c[5]) - (c[0]+c[1]+c[2]);
    if (n%3 != 0) {cout << "No" << endl; return 0;}
    n /= 3;

    int m = (c[6]+c[7]+c[8]) - (c[3]+c[4]+c[5]);
    if (m%3 != 0) {cout << "No" << endl; return 0;}
    m /= 3;

    if (c[3]-c[0] != n) {cout << "No" << endl; return 0;}
    if (c[6]-c[3] != m) {cout << "No" << endl; return 0;}

    if (c[4]-c[1] != n) {cout << "No" << endl; return 0;}
    if (c[7]-c[4] != m) {cout << "No" << endl; return 0;}

    if (c[5]-c[2] != n) {cout << "No" << endl; return 0;}
    if (c[8]-c[5] != m) {cout << "No" << endl; return 0;}

    cout << "Yes" << endl;
}

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

ll knapsack(int N,int W,int* wts,int* vals,ll** dp){
	if(N == 0) return 0;
	if(W<=0) return 0;
	if(dp[N][W]> -1) return dp[N][W];
	ll inc = 0;
	if(W>=wts[0])inc = vals[0] + knapsack(N-1,W-wts[0],wts+1,vals+1,dp);
	//int inc = vals[0] + knapsack(N-1,W-wts[0],wts+1,vals+1,dp);
	ll exc = knapsack(N-1,W,wts+1,vals+1,dp);
	dp[N][W] = max(inc,exc);
	//cout << N << " " << W << " " << inc << " " << exc << "\n";
	return dp[N][W];
}

int main() {
	int N,W; cin>>N>>W;
	int* wts = new int[N];
	int* vals = new int[N];
	
	for(int i=0;i<N;i++){
		cin >> wts[i] >> vals[i];
	}
	
	ll** dp = new ll*[N+1];
	for(int i=0;i<=N;i++) dp[i] = new ll[W+1];
	
	for(int i=0;i<=N;i++){
		for(int j=0;j<=W;j++) dp[i][j] = -1;
	}
	
	cout << knapsack(N,W,wts,vals,dp) << "\n";
	
	for(int i=0;i<=N;i++) delete[] dp[i];
	delete[] dp;
	return 0;
}

Measured memory_bytes: 82344
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    for p in (0..).filter(|&x| is_prime(x) && x % 5 == 1).take(n) {
        println!("{}", p);
    }
}

fn is_prime(p: i32) -> bool {
    if p == 1 {
        false
    } else {
        for i in 2..p {
            if p % i == 0 {
                return false;
            }
        }
        true
    }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

const string D = "ENSW";
const int f[] = {2, 4, 5, 3};
int t[6];
int p, q;
int L;

bool ok(int a, int b, int c) {
  return (a <= b + c) && (b <= 1 + c + a) && (c <= 1 + a + b);
}

int main() {
  while(1) {
    for (int i = 0; i < 6; ++i) {
      cin >> t[i];
    }
    L = accumulate(t, t+6, 0);
    if (L == 0) return 0;
    cin >> p >> q;

    string res;
    do {
      string s;
      int num[6] = {};
      int id[6] = {0, 1, 2, 3, 4, 5};
      
      while (s.size() < L) {
        bool flag = false;
        for (int k = 0; k < 4; ++k) {
          int b = id[f[k]];
          if (num[b] + 1 > t[b]) continue;
          int A = (t[0] + t[1]) - (num[0] + num[1]);
          int B = (t[2] + t[3]) - (num[2] + num[3]);
          int C = (t[4] + t[5]) - (num[4] + num[5]);
          switch (b / 2) {
          case 0: --A; break;
          case 1: --B; swap(A, B); break;
          case 2: --C; swap(A, C); break;
          }
          if (!ok(A, B, C)) continue;

          s += D[k];
          num[b] += 1;
          switch (k) {
            int a;
          case 0:
            a = id[2];
            id[2] = id[1];
            id[1] = id[3];
            id[3] = id[0];
            id[0] = a;
            break;
          case 1:
            a = id[4];
            id[4] = id[1];
            id[1] = id[5];
            id[5] = id[0];
            id[0] = a;
            break;
          case 2:
            a = id[5];
            id[5] = id[1];
            id[1] = id[4];
            id[4] = id[0];
            id[0] = a;
            break;
          case 3:
            a = id[3];
            id[3] = id[1];
            id[1] = id[2];
            id[2] = id[0];
            id[0] = a;
            break;
          }
          flag = true;
          break;
        }
        if (!flag) break;
      }

      if (s.size() == L) {
        if (res.empty() || res > s) res = s;
      }

    } while(next_permutation(t, t+6));
    if (res.empty()) cout << "impossible" << endl;
    else cout << res.substr(p-1, q-p+1) << endl;
  }
  return 0;
}

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

int main(){
int A,B;
cin>>A>>B;
if(A==1&&B!=1)cout<<"Alice"<<endl;
else if(B==1&&A!=1)cout<<"Bob"<<endl;
else if (A>B)cout<<"Alice"<<endl;
else if (A<B)cout<<"Bob"<<endl;
else if (A==B)cout<<"Draw"<<endl;
}


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

using namespace std;

struct point {
    int typ;
    int x, y;
    bool operator<(point o) {
        if (x < o.x) return true;
        if (x > o.x) return false;
        if (y < o.y) return true;
        if (y > o.y) return false;
    }
};

int main() {
    int n; scanf("%d", &n);
    point v[2 * n];
    for (int i = 0; i < n; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        v[i] = {0, a, b};
    }

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

    sort(v, v + 2 * n);
    int ans = 0;
    set <int> ys;
    for (int i = 0; i < 2 * n; i++) {
        if (v[i].typ == 0) ys.insert(v[i].y);
        else {
            auto it = ys.upper_bound(v[i].y);
            if (it == ys.begin()) continue;
            it--;
            ans++;
            ys.erase(it);
        }
    }

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

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

vi es[4];
bool used[4];

bool dfs(int a)
{
  used[a] = true; 

  bool ret = true;
  rep(i, 4) if(!used[i]) ret = false;
  if(ret){
    used[a] = false;
    return true;
  }

  foreach(e, es[a]){
    if(!used[e]){
      ret |= dfs(e);
    }
  }

  used[a] = false;
  return ret;
}

int main()
{
  rep(i, 3){
    int a, b;
    cin >> a >> b;
    a--; b--;
    es[a].pb(b);
    es[b].pb(a);
  }

  bool ans = false;
  rep(i, 4){
    if(dfs(i)) ans = true; 
  }

  cout << (ans ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
/*
    Problem 34
    https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_10_A
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n;
    cin >> n;
    vector<ll> fib(n+1);
    fib[0] = 1, fib[1] = 1;
    for (int i = 2; i <= n; i++) fib[i] = fib[i-1] + fib[i-2];
    cout << fib[n] << '\n';
}


Measured memory_bytes: 3092
#include<stdio.h>
#include<string.h>

#define M 1000000//M種類の単語入れられる /* your task*/
#define L 14//１単語12文字まで+\0

char H[M][L]; /* Hash Table */

int getChar(char ch) { //文字(列)を整数値に変換します
	if ( ch == 'A') return 1;
	else if ( ch == 'C') return 2;
	else if ( ch == 'G') return 3;
	else if ( ch == 'T') return 4;
}

/* convert a string into an integer value *///文字列を整数値に変換します
long long getKey(char str[]) {
	long long sum = 0, p = 1, i;
	for ( i = 0; i < strlen(str); i++ ) {
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;//0*1+0*5+0*25
}

int h1(int key) {
	return key%M; /* your task */;
}
int h2(int key) {
	return 1+(key%(M-1));/* your task */;
}

int find(char str[]) {

	/* your task */
	long long key, h;
	key=getKey(str);
	for(int i=0; ; i++){
		h = (h1(key)+i * h2(key)) %M;
		if(strcmp(H[h], str)==0)return 1;
		else if(strlen(H[h])==0)return 0;
	}
	return 0;
}

int insert(char str[]) {
	/* your task */
	long long key, h;
	key=getKey(str);
	for(int i=0; ; i++){
		h = (h1(key)+i * h2(key)) %M;
		if(strcmp(H[h],str)==0) return 1;
		else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main() {
	int i, n, h;
	char str[L], com[9];
	for ( i = 0; i < M; i++ ) H[i][0] = '\0';

	scanf("%d", &n);

	for ( i = 0; i < n; i++ ) {
		scanf("%s %s", com, str);

		if ( com[0] == 'i' ) {
			insert(str);
		} else {
			if (find(str)) {
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}

	return 0;
}


Measured memory_bytes: 15404
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> 
new_data_set;
const LL MOD = 1000003;

int main() {
	int N;
	scanf("%d", & N);
	int H[N + 5];
	for (int i = 0; i < N; i++) {
		scanf("%d", & H[i]);
	}	
	int awal = H[0];
	bool ans = 1;
	for (int i = 1; i < N; i++) {
		if (H[i] < awal - 1) ans = 0;
		awal = max(awal, H[i]);
	}
	if (ans) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int N;

int main(){
  int r;
  cin >> r;
  cout << 3*r*r << endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

East = [0] * N
West = [0] * N

for i,s in enumerate(list(S)):
    if s == 'W' : 
        if i==0:
            East[i] = 1
        else:
            East[i] = East[i-1] + 1
    else:
        if i == 0:
            East[i] = 0
        else:
            East[i] = East[i-1]
i = N-1
for s in reversed((list(S))):
    if s == 'E' : 
        if i==N-1:
            West[i] = 1
        else:
            West[i] = West[i+1] + 1
    else:
        if i == N-1:
            West[i] = 0
        else:
            West[i] = West[i+1]
    i -= 1
            
ans = 2**31-1

for i in range(N):
    if i == 1:
        ans2 = West[1]
    elif i == N-1:
        ans2 = East[N-2]
    else:
        ans2 = East[i-1]+West[i+1]
    ans = min(ans,ans2)
    
print(ans)
    

Measured memory_bytes: 20088
function main(input) {
  const args = input.split('\n');
  const N = parseInt(args[0], 10);
  const sorted = args[1].split(' ').map(v => parseInt(v)).sort((a, b) => b - a);
  var alice = 0;
  var bob = 0;
  
  sorted.forEach((v, i) => {
    if ((i + 1) % 2 == 0) {
      bob += v;
    } else {
      alice += v;
    }
  });
  console.log(alice - bob);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
using System.IO;
using System;

class Program
{
    static void Main()
    {
        string value = Console.ReadLine();
        string[] v = value.Split();
        var va = int.Parse(v[0]);
        var vb = int.Parse(v[1]);
        var vc = int.Parse(v[2]);
        
        if(va < vb && vb < vc)
        {
            Console.WriteLine("Yes");
        }

        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 8892
#include<bits/stdc++.h>
using namespace std;
string s;
int sum[26];
bool check(){
    for (int i=0;i<26;i++)
        if (sum[i]>1)return 0;
    return 1;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>s;
    for (int i=0;i<s.size();i++)
        sum[s[i]-'a']++;
    s+='a'-1;
    for (int i=s.size()-1;i>=0;i--){
        for (int j=s[i]+1;j<='z';j++){
            sum[j-'a']++;
            s[i]=j;
            if (check()){
                for (int k=0;k<=i;k++)cout<<s[k];
                return 0;
            }
            sum[j-'a']--;   
        }
        if (i!=0)
            sum[s[i-1]-'a']--;
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================


	string N;
	cin >> N;

	for (int i = 0; i < N.length(); i++)
	{
		if (N[i] == '7')
		{
			cout << "Yes";
			return 0;
		}
	}

	cout << "No";


}





Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(void){
   
  int N;
  cin >> N;
 
  for(int i=1;i<=9;i++){
     for(int j=1;j<=9;j++){
         if(i*j == N){
             cout << "Yes" <<endl;
             return 0;
         }
     } 
  }
  
  cout << "No" <<endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <map>

using namespace std;
#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int MOD = 1000000007;

void solve() {
    int N, M;
    cin >> N >> M;

    map<int, bool> map;
    int prev = -1;
    for (int i = 0; i < M; i++) {
        int x; cin >> x;
        map[x] = true;
        if (x == prev + 1) {
            cout << 0 << endl;
            return;
        }
    }

    vector<int> v(N + 10, 0);
    v[0] = 1;
    for (int i = 0; i < N; i++) {
        if (map[i]) {
            continue;
        }
        v[i + 1] = (v[i + 1] + v[i]) % MOD;
        v[i + 2] = (v[i + 2] + v[i]) % MOD;
    }

    cout << v[N] << endl;

}

signed main() {
    solve();
    return 0;
}


Measured memory_bytes: 7296
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int N,M,a,b,ans=0;
priority_queue<int> que;

int main(){
    cin>>N>>M;
    vector<int> fjk[M];
    rep(i,N){
        cin>>a>>b;
        if(a>M)continue;
        a--;
        fjk[a].push_back(b);
    }
    rep(i,M){
        if(fjk[i].size()>0){
            for(int x:fjk[i]){
                que.push(x);
            }
        }
        if(que.size()==0)continue;
        ans+=que.top();
        que.pop();
    }
    out(ans);  
}


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

int count;
struct tree
{
    int h;
    vector<int> next;
    bool seen;
    bool check;
};

void dfs(int i,tree* T){
    if(T[i].seen ==true){
        return;
    }
    T[i].seen=true;
    T[i].check=false;
    for(auto r:T[i].next){
        if(T[i].h<=T[r].h){
            T[i].check=true;
            dfs(r,T);
        }
    }
    if(!T[i].check){
        count++;
    }
}


int main(){
    int N,M;
    count=0;
    cin >> N >> M;
    tree T[N];
    for(int i=0;i<N;i++){
        cin >> T[i].h;
        T[i].seen=false;
    }
    for(int i=0;i<M;i++){
        int a,b;
        cin >>a>>b; a--,b--;
        T[a].next.push_back(b);
        T[b].next.push_back(a);
    }

    for(int i=0;i<N;i++){
        dfs(i,T);
    }
    cout << count <<endl;
    return 0;
}

Measured memory_bytes: 10300
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    S = S[::-1]
    word = ['dream', 'dreamer', 'erase', 'eraser']
    word = [w[::-1] for w in word]

    ok = True
    i = 0
    while i < len(S):
        j = i
        for w in word:
            if all(w[j] == S[i + j] for j in range(len(w))):
                j += len(w)
                break
        if i == j:
            ok = False
            break
        i = j

    if ok:
        print('YES')
    else:
        print('NO')

    return


if __name__ == '__main__':
    main()


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


int main() {
    int a, b;
    cin >> a >> b;
    if (a <= 8 && b <= 8) {
        cout << "Yay!" << endl;

    } else {
        cout << ":(" << endl;
    }
}




Measured memory_bytes: 256
import fractions

N = int(input())
a = list(map(int, input().split()))

lcm = a[0]

for i in range(1, N):
    lcm = (lcm * a[i]) // fractions.gcd(lcm, a[i])

ans = 0

for i in range(N):
    ans = ans + (lcm - 1) % a[i]
print(ans)


Measured memory_bytes: 5344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;

void trace(vector<int> A){
    rep(i,A.size()){
        cout << A[i];
        if (i != A.size()-1) cout << " ";
    }
    cout << endl;
}

void insertion_sort(vector<int> A, int N){
    for(int i = 1; i < N; ++i){
        int j = i - 1;
        int tmp = A[i];
        while(j >= 0 && A[j] > tmp){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = tmp;
        trace(A);
    }
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    trace(A);
    insertion_sort(A, N);
}


Measured memory_bytes: 3148
using System;
using System.Linq;

class AtCoder {
  public static void Main() {
    var inputs = Console.ReadLine().Trim().Split(' ');
    var S = inputs[0];
    var T = inputs[1];
    var inputs2 = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToList();
    var A = inputs2[0];
    var B = inputs2[1];
    var U = Console.ReadLine().Trim();
    if(U == S) {
      A--;
    } else {
      B--;
    }
    Console.WriteLine(A + " " + B);
  }
}

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

using namespace std;

typedef long long int lli;

int main() {
    string s;

    cin >> s;
    int A = 0, BC = 0;
    lli ans = 0;
    for (int i=0, len=s.size(); i<len-1; i++) {
        // cout << i << " ";
        if (s[i] == 'A') {
            ans += (lli)A * BC;
            A++; BC = 0;
        }
        else if (s[i] == 'B' && s[i+1] == 'C') {
            BC++; i++;
        }
        else {
            ans += (lli)A * BC;
            A = 0; BC = 0;
        }
        // cout << A << " " << BC << " " << ans << endl;
    }
    ans += (lli)A * BC;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect

n=int(input())
a=list(map(int,input().split()))
c=[0]*n
for i in range(n):
    c[i]=a[i]-(i+1)
c.sort()
ans=0
if n%2==1:
  p=(n+1)//2-1
  b=c[p]
  for i in range(n):
    ans+=abs(c[i]-b)
  print(ans)
else:
  p=n//2
  b=(c[p-1]+c[p])/2
  b=round(b)
  for i in range(n):
    ans+=abs(c[i]-b)
  print(ans)

Measured memory_bytes: 88148
def merge(a, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  _L = Array.new(n1+1)
  _R = Array.new(n2+1)
  0.upto(n1-1){|i|
    _L[i] = a[left+i]
  }
  0.upto(n2-1){|i|
    _R[i] = a[mid+i]
  }
  _L[n1] = _R[n2] = 1.0 / 0.0
  i = j = 0
  left.upto(right-1){|k|
    if _L[i] <= _R[j] then
      a[k] = _L[i]
      i += 1
    else
      a[k] = _R[j]
      j += 1
    end
  }
  return right - left
end

def mergeSort(a, left, right)
  count = 0
  if left+1 < right then
    mid = (left + right) / 2
    count += mergeSort(a, left, mid)
    count += mergeSort(a, mid, right)
    count += merge(a, left, mid, right)
  end
  return count
end

n = gets.to_i
a = gets.split.map(&:to_i)

count = mergeSort(a, 0, n)

puts a.join(" ")
puts count

Measured memory_bytes: 69768
def main():
    word = input()
    repeat = int(input())
    count_succession = 1
    before = word[0]
    base = 0
    for w in word[1:] + " ":
        if before == w:
            count_succession += 1
        else:
            before = w
            base += count_succession // 2
            count_succession = 1
    answer = repeat * base
    if len(set(list(word))) == 1:
        answer = repeat * len(word) // 2
    elif word[-1] == word[0]:
        succession_begin = 0
        succession_end = 0
        for i in range(1, len(word)):
            if word[i] != word[0]:
                succession_begin = i
                break
        for i in range(-2, -len(word) - 1, -1):
            if word[i] != word[-1]:
                succession_end = -i - 1
                break
        answer -= (succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2) * (repeat - 1)
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(text){console.log(text);}//standard output
//[no]param
//0:noConvert	1:singleNum	2:spaceList	3:newLineList	4:spaceNumList	5:newLineNumList
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],4)[0];
  var K = myconv(input[0],4)[1];
  input.shift();
  var list = input.map((a)=>Number(a)).sort(function(a,b){
  	return a - b;
  });
  var output = 1000000007;
  for(var i = 0; i < N - K + 1; i++){
    output = Math.min(output, list[i + K - 1] - list[i]);
  }
  myout(output);
}

Main(myin());


Measured memory_bytes: 28752
require 'prime'

g = Prime::EratosthenesGenerator.new
h = Hash.new(0)
a = 2
while a < 100000
  h[a] = 1
  a = g.next
end
k = Hash.new(0)
h.keys.each do |x|
  k[x] += 1 if h[(x + 1) / 2] == 1
end
p = Array.new(100001, 0)
1.upto(100000) do |i|
  p[i] = p[i - 1] + k[i]
end
gets.to_i.times do
  l, r = gets.split.map(&:to_i)
  puts p[r] - p[l - 1]
end

Measured memory_bytes: 4304
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  cin >> N;

  map<LL, int> mp;
  rep(i, N) {
    int a;
    cin >> a;
    mp[a]++;
  }

  if (mp.size() > 3) {
    puts("No");
    return 0;
  }

  if (mp.size() == 1 && mp[0] == N) {
    puts("Yes");
    return 0;
  }

  if (mp.size() == 3) {
    LL tot = 0;
    for (auto p : mp) {
      if (p.Y != N/3) {
        puts("No");
        return 0;
      }
      tot ^= p.X;
    }
    assert(N%3 == 0);
    if (tot != 0) {
      puts("No");
      return 0;
    }
    puts("Yes");
    return 0;
  }
  assert(mp.size() == 2);

  if (N%3 == 0 && mp[0] == N/3) {
    puts("Yes");
    return 0;
  }

  puts("No");
  return 0;
}


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

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if(a - b >= 0){
		cout << "delicious" << endl;
		return 0;
	}else if(a - b < 0 && a - b + x >= 0 ){
		cout << "safe" << endl;
	}else{
		cout << "dangerous" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  string s, t;
  int res=0;
  cin >> s >> t;
  int dict1[26], dict2[26];

  rep(i,26) dict1[i] = -1;
  rep(i,26) dict2[i] = -1;

  rep(i,s.size()){
    int idx1 = s[i] - 'a';
    int idx2 = t[i] - 'a';
    if(dict1[idx1]==-1 && dict2[idx2]==-1){
      dict1[idx1] = idx2;
      dict2[idx2] = idx1;
    }
    else{
      if(dict1[idx1]!= idx2|| dict2[idx2]!=idx1){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

}


Measured memory_bytes: 776