akhauriyash/Code-Regression huggingface dataset:
n = input()
A=[]
for i in range(0,int(n)):
  a=input()
  A.append(int(a))
B=[]
B =sorted(A)
  
for i in range(0,int(n)):
  if ( B[-1] == A[i]):
  	print (B[-2])
  else:
    print(B[-1])

Measured memory_bytes: 14112
program sample
    implicit none
    character(200000)::s,t
    character(1)::a,b,x(26),y(26)
    integer(8) :: i,j,m,n,time,k
    
    read(*,*) s
    read(*,*) t
    n=len_trim(s)
    time=0
    x(:)='0'
    y(:)='0'
    do i=1,n
       
            
            a=s(i:i)
            b=t(i:i)
            call alfnumber(a,k)
            if(x(k) .eq. '0') then
                x(k)=b
            elseif(x(k) .ne. b)then
                write(*,*)'No'
                stop
            endif

            call alfnumber(b,k)
            if(y(k) .eq. '0') then
                y(k)=a
            elseif(y(k) .ne. a)then
                write(*,*)'No'
                stop
            endif
            
    enddo

    
    write(*,*)'Yes'
    stop
    contains
    subroutine alfnumber(st,a)
        implicit none
        character,intent(in) :: st
        integer(8),intent(out) ::  a
        integer::i
        character(1)::ch(26)
        ch=(/'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'/)
        do i=1,26
            if(st .eq. ch(i))then
                a=i
                return
            end if
        end do 
        end subroutine alfnumber
end program sample
  



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

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

    bool can = false;
    for (int i = 1; i <= B; i++) {
        if (A*i % B == C) can = true;
    }
    if (can) cout << "YES" << endl;
    else cout << "NO" <<endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <iostream>
using namespace std;
string s[100005], c;
int main()
{
	long long n, a, b, i, j, k;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> c;
		sort(c.begin(), c.end());
		s[i] = c;
	}
	sort(s, s + n);
	long long  sum = 1;
	k = 0;
	for (i = 1; i < n; i++)
	{
		if (s[i] != s[i - 1])
		{
			k += (sum * (sum - 1)) / 2;
			sum = 1;
			continue;
		}
		else
			if (i == n - 1)
			{
				if (s[i] == s[i - 1])
					sum++;
				k += (sum * (sum - 1)) / 2;
			}
		sum++;
	}
	cout << k;

	return 0;
}

Measured memory_bytes: 5760
/* ex6_2 melo */
#include <stdio.h>
#include<string.h> //文字列関数
#define SIZE 101 //文字列の大きさを定義
int main(void){
    char sente[SIZE];
    int length;
    scanf("%s",sente);
    length=(int)strlen(sente);
    printf("%c%d%c\n",sente[0],length-2,sente[length-1]);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	long n = sc.nextLong();
	long min = Long.MAX_VALUE;
	for (long i=1; i<=Math.sqrt(n); i++) {
	    if (n % i == 0) {
		if (n/i + i < min) {
		    min = n/i + i;
		}
	    }
	}
	System.out.print(min-2);
    }
}


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

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

using namespace std;
using lint=long long;

template<class T> struct edge{
	int to;
	T wt1,wt2;
	edge(int to,const T& wt1,const T& wt2):to(to),wt1(wt1),wt2(wt2){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

const long long INF=1LL<<61;

int main(){
	int n,m,k0; scanf("%d%d%d",&n,&m,&k0);
	k0=min(k0,2500);
	weighted_graph<lint> G(n);
	rep(i,m){
		int u,v,c1,c2; scanf("%d%d%d%d",&u,&v,&c1,&c2); u--; v--;
		G[u].emplace_back(v,c1,c2);
		G[v].emplace_back(u,c1,c2);
	}
	vector<int> c1(n),c2(n);
	rep(u,n) scanf("%d%d",&c1[u],&c2[u]);

	lint d[50][2501];
	rep(u,n) rep(k,2501) d[u][k]=INF;
	d[0][k0]=0;

	priority_queue<pair<lint,pair<int,int>>> Q;
	Q.emplace(0,make_pair(0,k0));
	while(!Q.empty()){
		lint d0=-Q.top().first;
		int u,k; tie(u,k)=Q.top().second; Q.pop();

		if(d0>d[u][k]) continue;

		// 換金
		int k2=min(k+c1[u],2500);
		lint d2=d0+c2[u];
		if(d2<d[u][k2]){
			d[u][k2]=d2;
			Q.emplace(-d2,make_pair(u,k2));
		}

		// 移動
		for(auto e:G[u]) if(e.wt1<=k) {
			int v=e.to;
			k2=k-e.wt1;
			d2=d0+e.wt2;
			if(d2<d[v][k2]){
				d[v][k2]=d2;
				Q.emplace(-d2,make_pair(v,k2));
			}
		}
	}

	for(int u=1;u<n;u++) printf("%lld\n",*min_element(d[u],d[u]+2501));

	return 0;
}


Measured memory_bytes: 6356
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
	ll a, b, d;
	while (cin >> a >> b >> d && a){
		ll xa, ya, s = 1e9;
		FOR(x,-1000000,1000000){
			ll p = d - a*x;
			if (p % b == 0){
				ll y = p/b;
				ll xx = abs(x);
				ll yy = abs(y);
				if (xx + yy < s || (xx + yy == s && a*xx+b*yy < a*xa+b*ya)){
					s = xx + yy;
					xa = xx;
					ya = yy;
				}
			}
		}
		printf("%lld %lld\n", xa, ya);
	}

    return 0;
}

Measured memory_bytes: 3076
#include <stdio.h>
#define Nmax 100000
#define Qmax 50000

int BinarySearch(int *,int,int );

int main(){
  int n,q,i;
  int T[Qmax], S[Nmax];
  int sum=0;
  int ans;

  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0 ; i<q ; i++){
    scanf("%d",&T[i]);
  }
  
  for(i=0 ; i<q ; i++){
    if(BinarySearch(S,T[i],n) == 1) sum++;
  }
  printf("%d\n",sum);

  return 0;
}

int BinarySearch(int *S,int key,int n){
  int left=0;
  int right;
  int mid;

  right = n;
  
  while(left < right){
    mid = (left + right) / 2;
    if (S[mid] == key) return 1;
    else if (key < S[mid])right = mid;
    else left = mid + 1;
  }
  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <limits>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

typedef pair<ll, ll> curr;
const int MOD = 998244353;


int gcd(int a, int b){
  if(b == 0) return a;
  return gcd(b, a%b);
}

int main()
{
  int N,a,b,sum=0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a >> b;
    sum += b-a+1;
  }
  cout << sum;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define inf 1000000000
#define MOD 1000000007 
#define N 300005
#define M 1000000
#define LOG 20
#define KOK 300
#define EPS 0.0000001
using namespace std;

int n=1407,k=38;
int go[1599],nxt[1599];
vector<int> v[1599];
int cnt;

int nn() {

	return ++cnt;

}

vector<int> has;

void dfs(int cur) {

	v[cnt].pb(cur);

	if(!go[cur]) return ;

	dfs(go[cur]);

	go[cur]=nxt[go[cur]];

}

int main() {

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

	function<int(int)> nx=[](int x) {

		if(x==k-1) return 1;

		return x+1;

	};

	for(int i=1;i<=k;i++) {

		nn();

		v[cnt].pb(1);

		for(int j=(i-1?v[cnt-1].back():1)+1;j<=n && sz(v[cnt])<k;j++) {

			v[cnt].pb(j);

		}

		for(int j=0;j<k;j++) {

			int to=v[cnt][nx(j)];

			nxt[v[cnt][j]]=to;

		}

	}

	for(int i=1;i<k;i++) {

		for(int j=0;j<k;j++) {

			go[v[i][j]]=v[i+1][j];

		}

	}
	
	for(int i=2;i<=k;i++) {

		for(int j=1;j<k;j++,go[i]=nxt[go[i]]) {

			v[nn()].pb(i);

			dfs(go[i]);

		}

	}

	for(int i=1;i<=cnt;i++) {

		assert(sz(v[i])==k);

		for(auto x:v[i]) printf("%d ",x);

		printf("\n");

	}

}

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

const u_int32_t TASK_TYPE_SIZE = 26;

class SatisfactionCoefficient {
public:
    SatisfactionCoefficient(u_int32_t D) {
        this->c = vector<u_int32_t>(TASK_TYPE_SIZE + 1);
        for (u_int32_t i = 1; i <= TASK_TYPE_SIZE; i++) {
            cin >> this->c[i];
        }

        this->s = vector<vector<u_int32_t>>(D + 1, vector<u_int32_t>(TASK_TYPE_SIZE + 1));
        for (u_int32_t i = 1; i <= D; i++) {
            for (u_int32_t j = 1; j <= TASK_TYPE_SIZE; j++) {
                cin >> this->s[i][j];
            }
        }
    };

    u_int32_t getC(u_int32_t i) {
        return this->c[i];
    }

    u_int32_t getS(u_int16_t i, u_int32_t j) {
        return this->s[i][j];
    }

private:
    vector<u_int32_t> c;
    vector<vector<u_int32_t>> s;
};

class Schedule {
public:
    Schedule(u_int32_t D) {
        this->schedule = vector<u_int32_t>(D + 1, 0);
    }

    void setTask(u_int32_t day, u_int32_t task) {
        // 1 <= day <= D
        // 1 <= task <= TYPE_SIZE
        this->schedule[day] = task;
    }

    u_int32_t getTask(u_int32_t day) {
        // 1 <= day <= D
        return this->schedule[day];
    }

private: 
    vector<u_int32_t> schedule; // スケジュール
};

vector<int64_t>* calculate_S(SatisfactionCoefficient sts_coefficient, Schedule schedule, u_int32_t D) {
    /*
    D 日までの各日の満足度を返す.
    */
    vector<int64_t> *S = new vector<int64_t>(D + 1);
    (*S)[0] = 0;

    vector<vector<u_int32_t>>  last = vector<vector<u_int32_t>>(D + 1, vector<u_int32_t>(TASK_TYPE_SIZE + 1, 0));
    for (u_int32_t t = 1; t <= TASK_TYPE_SIZE; t++) {
        last[0][t] = 0;
    }

    for (u_int32_t day = 1; day <= D; day++) {
        // last計算
        for (u_int32_t t = 1; t <= TASK_TYPE_SIZE; t++) {
            last[day][t] = last[day - 1][t];
        }
        //  last 上書き
        last[day][schedule.getTask(day)] = day;

        // S 計算
        (*S)[day] = (*S)[day - 1] + sts_coefficient.getS(day, schedule.getTask(day));
        for (u_int32_t t = 1; t <= TASK_TYPE_SIZE; t++) {
            (*S)[day] -= sts_coefficient.getC(t) * (day - last[day][t]);
        }
    }
    
    return S;
}



void Main() {
    // input
    u_int32_t D;
    cin >> D;
    SatisfactionCoefficient sts_coefficient = SatisfactionCoefficient(D);
    Schedule schedule = Schedule(D);

    // translate
    for (u_int32_t day = 1; day <= D; day++) {
        u_int32_t task;
        cin >> task;
        schedule.setTask(day, task);
    }

    // output
    vector<int64_t>* S = calculate_S(sts_coefficient, schedule, D);
    for (u_int32_t day = 1; day <= D; day++) {
        cout << (*S)[day] << endl;
    }
}

int main()
{
    Main();
    return 0;
}


Measured memory_bytes: 3804
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

struct Node{
    int key;
    Node *parent, *left, *right;
};

void print(Node* root, int size, int* in, int* pre);
void binarySearchTreeInsert(Node** rootAddr, int val);
void treeWalk(int** arrAddr, Node* root, int mode);

int main(int argc, char** argv) {
    int len, *in, *pre, nrOfNodes;
    std::string cmd;
    Node* root;

    nrOfNodes = 0;
    root = nullptr;

    scanf("%d", &len);
    for (int i = 0; i < len; i++) {
        std::cin >> cmd;
        if (cmd == "insert") {
            nrOfNodes++;
            int val;
            scanf("%d", &val);
            binarySearchTreeInsert(&root, val);
        } else if (cmd == "print") {
            print(root, nrOfNodes, in, pre);
        }
    }

    return 0;
}

void print(Node* root, int size, int* in, int* pre) {
    int *inPtr, *prePtr;

    in = (int *) calloc(sizeof(int), size + 1);
    inPtr = in;
    pre = (int *) calloc(sizeof(int), size + 1);
    prePtr = pre;

    treeWalk(&inPtr, root, 1);
    treeWalk(&prePtr, root, 0);

    for (int i = 0; i < size; i++) {
        if (i) {
            //printf(" ");
        }
        printf(" %d", *(in + i));
    }
    printf("\n");

    for (int i = 0; i < size; i++) {
        if (i) {
            //printf(" ");
        }
        printf(" %d", *(pre + i));
    }
    printf("\n");

    free(in);
    free(pre);
}

void binarySearchTreeInsert(Node** rootAddr, int val) {
    Node *newNode, *parent;
    
    newNode = (Node *) calloc(sizeof(Node), 1);
    newNode->parent = newNode->left = newNode->right = nullptr;
    newNode->key = val;

    parent = *rootAddr;

    while (true) {
        if (parent != nullptr) {
            if (parent->key > val) {
                if (parent->left != nullptr) {
                    parent = parent->left;
                } else {
                    break;
                }
            } else {
                if (parent->right != nullptr) {
                    parent = parent->right;
                } else {
                    break;
                }
            }
        } else {
            break;
        }
    }

    newNode->parent = parent;
    if (parent != nullptr) {
        if (parent->key > val) {
            parent->left = newNode;
        } else {
            parent->right = newNode;
        }
    } else {
        *rootAddr = newNode;
    }
}

/* mode: 0 - preorder; 1 - inorder; 2 - postorder */
void treeWalk(int** arrAddr, Node* root, int mode) {
    if (root == nullptr) {
        return;
    }

    if (mode == 0) {
        // preorder
        *(*arrAddr)++ = root->key;
    }

    treeWalk(arrAddr, root->left, mode);

    if (mode == 1) {
        // inorder
        *(*arrAddr)++ = root->key;
    }

    treeWalk(arrAddr, root->right, mode);

    if (mode == 2) {
        // postorder
        *(*arrAddr)++ = root->key;
    }
}


Measured memory_bytes: 30484
def main():
    N, K = map(int, [int(x) for x in input().split()])
    S = input()

    ans = ""
    for i, n in enumerate(S):
        if i == K-1:
            n = n.lower()
        ans += n
    print(ans)
    return ans


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main(){
  long long n,money=1000;
  cin >> n;
  int a[n+1];
  rep(i,n){
    cin >> a[i];
  }
  a[n] = 0;
  
  rep(i,n){
    long long count=0,kabu=0;
    while(a[i] < a[i+1]){
      i++;
      count++;
    }
    kabu = money / a[i-count];
    money += (a[i] - a[i-count]) * kabu;
  }
  
  cout << money << endl;
  
  return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);++i)
typedef long long ll;
using namespace std;
 
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int ans;
  
  if(a*a == b*b+c*c) ans = b*c/2;
  else if(b*b == a*a+c*c) ans = a*c/2;
  else ans = a*b/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define M 2001

int main(){
  int n,i,j,min,k,cnt;
  int a[N][N],judge[N],color[N],d[N],p[N];

  scanf("%d",&n);
  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ ){
      scanf("%d",&a[i][j]);
    }
  }

  for( i = 0 ; i < n ; i++ ){
    color[i] = 0;
    p[i] = -1;
    d[i] = M;
  }
  d[0] = 0;

  while(1){
    min = M;

    for( i = 0 ; i < n ; i++ ){
      if( color[i] != 2 && d[i] < min ){
        min = d[i];
        k = i;
      }
    }

    if( min == M )break;

    color[k] = 2;

    for( i = 0 ; i < n ; i++ ){
      if( a[k][i] != -1 && color[i] != 2 && a[k][i] < d[i] ){
        p[i] = k;
        d[i] = a[k][i];
        color[i] = 1;
      }
    }
  }

  for( i = 0 ; i < n ; i++ ){
    if( p[i] != -1 ){
      j = p[i];
      cnt += a[i][j];
    }
  }

  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n,m;
    cin >> n >> m;
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        ans *= (m - i);
        ans %= 1000000007;
    }
    ll p = 1;
    ll q = 0;
    for (int i = 0; i < n; i++) {
        ll pp = p;
        ll qq = q;
        p *= (m - n);
        p %= 1000000007;
        p += qq * (m - n + 1);
        q = (qq+pp) * (n - i - 1);
        p %= 1000000007;
        q %= 1000000007;
    }
    cout << ans*p%1000000007 << endl;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(void){
   int n,i;
   cin>>n;
   int kazu[n];
   for(i=1;i<=n;i++){cin>>kazu[i];}
   for(i=n;i>=1;i--){
       if(i>=2){
           cout<<kazu[i]<<" ";
       }else if(i==1){cout<<kazu[i]<<endl;}
   }
    return 0;
}



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ld double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define mii map<int, int>
#define mp make_pair
#define mod 1000000007
#define pii pair<int, int>
#define vpii vector<pii >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define limit 100005
#define ft first
#define sd second
#define maxval 8.0
#define pi 3.14159265358979323846
int dx[4] = {0, 0, -1, 1};//u d l r
int dy[4] = {1, -1, 0, 0};
/****************************************************************************/

int main()
{
   int n, K;
   cin >> n >> K;
   int a[n+1];
   for(int i = 1; i < n+1; i++)
     cin >> a[i];         
 
   int dp[n+1][K+1] = {};
   for(int j = 0; j < K+1; j++)
      dp[0][j] = 1;
   /*
   dp[0][0] = 1;
   for(int i = 1; i < n+1; i++)
      for(int j = 0; j < K+1; j++)
          for(int k = 0; k < min(a[i], j)+1; k++)
                     dp[i][j] += dp[i-1][j-k];
   */   
   for(int i = 1; i < n+1; i++)
   {
      for(int j = 0; j < K+1; j++)
      {
          int k = j-min(a[i], j);
          dp[i][j] = (dp[i-1][j]+ mod-(k==0?0:dp[i-1][k-1]))%mod;
      }
      for(int j = 1; j < K+1; j++)
         dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
  }

  cout << (dp[n][K]+mod-(K==0?0:dp[n][K-1]))%mod << '\n';

}

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

using namespace std;

const int N = 3e5 + 5, mod = 1e9 + 7;
int dp[N], sum[N];

char s[N];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  scanf("%s", s);
  bool same = 1;
  for (int i = 0; i < m; ++i)
    if (s[i] != s[0])
      same = 0;
  if (same) {
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
      dp[i] = dp[i-1];
      if (i > 1)
        dp[i] = (dp[i] + dp[i-2]) % mod;
    }
    int ans = (dp[n] + dp[n-2]) % mod;
    printf("%d\n", ans);
    return 0;
  }
  int cnt = 0;
  while (s[cnt] == s[0]) ++cnt;
  if ((cnt & 1) == 0)
    ++cnt;
  int cur = 0;
  for (int i = 0; i < m; ++i) {
    if (s[i] != s[0]) {
      if (cur & 1) {
        cnt = min(cnt, cur);
      }
      cur = 0;
    }
    else {
      ++cur;
    }
  }
  dp[0] = 1;
  sum[0] = 1;
  for (int i = 2; i <= n; i += 2) {
    dp[i] = sum[i-2] - (i - (cnt+3) >= 0 ? sum[i - (cnt+3)] : 0);
    dp[i] %= mod;
    if (dp[i] < 0)
      dp[i] += mod;
    sum[i] = (dp[i] + sum[i-2]) % mod;
  }
  int ans = dp[n];
  for (int i = 2; i <= n && i <= cnt+1; i += 2) {
    ans = (ans + 1LL * dp[n-i] * (i-1)) % mod;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll A, B, C;
    cin >> A >> B >> C;
    
    cout << A + B + C - max(A,max(B,C)) << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline

def isPrime(n):
    i = 2
    flag = True
    while i * i <= n:
        if n % i == 0:
            flag = False
            break
        else:
            i += 1
    return flag


x = int(input())

while True:
    if isPrime(x):
        print(x)
        break
    else:
        x += 1




Measured memory_bytes: 62944
h,*s=open(0)
h,w,k,*m=map(int,h.split())
b=512
while b:
 b-=1;r=t=j=-1;d=[0]*h
 while~j+w:
  j+=1;i=c=0
  while h-i:
   d[c]+=s[i][j]>'0';f=t<j
   if d[c]>k:d=[0]*h;r+=1-h*w*~-f;t=j;j-=f;break
   c+=b>>i&1;i+=1
 m+=r-~c,
print(min(m))

Measured memory_bytes: 44380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;


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

    // solution comes here
    ll N, Q;    string S;
    cin >> N >> Q >> S;

    vl SUM(N);
    SUM[0] = 0;
    rep(i, N-1) SUM[i+1] = SUM[i] + ('A'==S[i] and 'C'==S[i+1]);
    
    ll l, r;
    rep(i, Q) {
        cin >> l >> r;
        cout << SUM[--r] - SUM[--l] << nl;
    }
}

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

using ll = long long;
using pii = pair<int, int>;

// 0-indexed
template <typename T>
class fenwick_tree {
public:
    fenwick_tree(int n) : n(n), dat(n, 0) {}

    void add(int i, T value) {
        for(; i<n; i |= i + 1) {
            dat[i] += value;
        }
    }

    T sum(int i) const {
        T res = 0;
        for(; i>=0; i = (i & (i+1)) - 1) {
            res += dat[i];
        }
        return res;
    }
    // [l, r)
    T sum(int l, int r) const {
        return sum(r-1) - sum(l-1);
    }

private:
    const int n;
    std::vector<T> dat;
};


int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<pii>> range(100001);
    for(int i = 0; i < N; ++i) {
        int l, r;
        cin >> l >> r;
        range[r - l].emplace_back(l, r);
    }

    int sum = N;
    fenwick_tree<int> bit(M + 1);
    for(int i = 1; i <= M; ++i) {
        sum -= range[i - 1].size();
        int res = sum;
        for(auto& p : range[i - 1]) {
            bit.add(p.first, 1);
            bit.add(p.second + 1, -1);
        }
        for(int j = i; j <= M; j += i) {
            res += bit.sum(j);
        }
        cout << res << endl;
    }
}



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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            Console.WriteLine((n + 1) / 2);
            //Console.ReadKey();
        }
    }
}


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

using namespace std;

int main(void){
  int A[100002]={0};
  int N = 0;
  int a = 0;
  long sum = 0;
  
  cin >> N;
  
  for(int i=0;i<N;i++){
    cin >> a;
    A[a] ++;
    sum += a;
  }
  
  int Q=0;
  cin >> Q;
  
  for(int i=0;i<Q;i++){
    int B = 0;
    int C = 0;
    cin >> B >> C;
	sum += (C-B)*A[B];
    A[C] += A[B];
    A[B] = 0;
    cout << sum << endl;
  }
  return 0;
}


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


Measured memory_bytes: 22816
#include<bits/stdc++.h>
using namespace std;
int n,q;
vector<int> to[200005];
vector<int> ans;
void solve(int l,int p=-1){
    for(int u:to[l]){
        if(u==p) continue;
        ans.at(u)+=ans.at(l);
        solve(u,l);
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>n>>q;
    int j,k;
    for(int i=0;i<n-1;i++){
        cin>>j>>k;
        to[j-1].push_back(k-1);
        to[k-1].push_back(j-1);
    }
    ans.resize(n);
    for(int i=0;i<q;i++){
        cin>>j>>k;
        ans[j-1]+=k;
    }
    solve(0);
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 26624
using namespace std;
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define INFINITE 1e9 + 5
#define MOD 1000000007
#define MAXN 100001 
#define pll pair<ll,ll>
#define pii pair<int,int>
int dp[MAXN];
int arr[MAXN];
int num,m;
int func(int ind)
{
    if(ind==num)
    {
        return 0;
    }
    if(dp[ind]!=-1)
    {
        return dp[ind];
    }
    int mini=INFINITE;
    for(int i=ind+1;i<=min(num,ind+m);i++)
    {
        mini=min(mini,abs(arr[i]-arr[ind])+func(i));
    }
    return dp[ind]=mini;   
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>num>>m;
    for(int i=1;i<=num;i++)
    {
        cin>>arr[i];
    }   
    cout<<func(1);
}

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

int main()
{
    int a[3];
    scanf("%d%d%d", &a[0], &a[1], &a[2]);
    int ans = 301;
    /*for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            for(int k = 0; k < 3; k++)
            {
                if(i != j && j != k && k != i)
                {
                    ans = std::min(ans, abs(a[i] - a[j]) + std::min( abs(a[j] - a[k]), abs(a[i] - a[k])));
                }
            }
        }
    }*/
    printf("%d", std::max(std::max(a[0], a[1]), a[2]) - std::min(std::min(a[0], a[1]), a[2]));
    return 0;
}


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


int main(){
    int n;
    long long k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    vector<int> narabi;
    vector<int> order(n+1, -1);
    int c = 1;
    int l = 0;
    int v = 1;//vが移動していく
    while(order[v] == -1){//order[v]はa[v-1]での行き先（既に来た場合，何番目に来たかが入っている）
        order[v] = narabi.size();//1,2,3...番目
        narabi.push_back(v);//訪れたところをメモっていく
        v = a[v - 1];
    }
    c = narabi.size() - order[v];
    l = order[v];

    if(k < l) cout << narabi[k] << endl;
    else{
        k -= l;
        k %= c;
        cout << narabi[l + k] << endl;
    }
    return 0;
}

Measured memory_bytes: 5900
n,m = map(int, raw_input().split())
rl = [False for _ in range(n)]
wl = [1 for _ in range(n)]
rl[0] = True
for _ in range(m):
    x,y = map(int, raw_input().split())
    if rl[x-1]:
        rl[y-1] = True
    wl[y-1] += 1
    wl[x-1] -= 1
    if wl[x-1] == 0:
        rl[x-1] = False
print rl.count(True)


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

int main()
{
    int A, B, C, X, cnt = 0;
    cin >> A >> B >> C >> X;

    for (int i = 0; i <= A; i++)
    {
        for (int j = 0; j <= B; j++)
        {
            for (int k = 0; k <= C; k++)
            {
                int XX = X;
                XX -= 500 * i + 100 * j + 50 * k;
                if (XX == 0)
                {
                    cnt++;
                }
            }
        }
    }

    cout << cnt;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
//debug
#define vecprint(v) rep(i,v.size())cout << v[i] << " ";cout << endl;
#define setprint(s) for(auto i=s.begin();i!=s.end();i++)cout << *i << " ";cout << endl;
#define mappairprint(s) for(auto i=s.begin();i!=s.end();i++)cout << i->first << " " << i->second << endl;cout << endl;
//reader
#define r1(a) cin>>(a)
#define r2(a,b) cin>>(a)>>(b)
#define r3(a,b,c) cin>>(a)>>(b)>>(c)
//writer
#define w1(a) cout<<(a)<<" "
#define w2(a,b) cout<<(a)<<" "<<(b)<<" "
#define w3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "
#define wl1(a) cout<<(a)<<endl
#define wl2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wl3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
//variable definition
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
//roop
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define all(c) c.begin(),c.end()
//term
#define elif else if
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
using namespace std;
using ll = long long;
//const
constexpr double PI = 3.141592653589793238462643383279;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};


int main() {
  //input
  int n,k;
  cin >> n >> k;
  
  priority_queue<int> que;
  priority_queue<int, vector<int>, greater<int> > q;
  rep(i,n) {
    int tmp;
    cin >> tmp;
    q.push(tmp);
  }
  
  //process
  int sum = 0;
  int count = 0;
  while (count < k) {
    sum += q.top();
    q.pop();
    count++;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3604
N,M = map(int,input().split())
t = [[0] for _ in range(M+1)]
for _ in range(N):
    a,b = map(int,input().split())
    if a<=M:
        t[a].append(b)
import heapq
A=[-i for i in t[1]]
heapq.heapify(A)
ans = 0
for i in range(1,M+1):
    maxi = heapq.heappop(A)
    ans -= maxi
    if i+1<=M:
        for k in t[i+1]:
            heapq.heappush(A,-k)
print(ans)

Measured memory_bytes: 75680
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn solve(k: i64, s: i64) -> i64 {
    let mut res = 0;
    for i in 0..k+1 {
        for j in 0..k+1 {
            let diff = s - (i + j);
            if diff >= 0 && diff <=k {
                res += 1;
            }
        }
    }
    res
}

#[allow(dead_code)]
fn main() {
    input!{
        k: i64,
        s: i64,
    }
    println!("{}", solve(k, s));
}


Measured memory_bytes: 4352
N,K = map(int, input().split())
H = [int(h) for h in input().split()]

dp = [0]*N

for i in range(1, N):
    j = i-1
    cost = 10**18
    while j >= max(0, i-K):
        cost = min(cost, dp[j]+abs(H[i]-H[j]))
        j -= 1
    dp[i] = cost
    
print(dp[N-1])

Measured memory_bytes: 52448
use std::io::*;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let mut s: Vec<char> = itr.next().unwrap().chars().collect();

    s.reverse();

    let mut goal = false;
    let mut q = std::collections::VecDeque::new();
    let mut ans = Vec::new();
    q.push_back(0);
    while let Some(x) = q.pop_front() {
        goal |= x == n;
        for nx in (1..=m).rev() {
            if x + nx <= n && s[x + nx] == '0' {
                q.push_back(x + nx);
                ans.push(nx);
                break;
            }
        }
    }
    if goal {
        let mut out = Vec::new();
        ans.reverse();
        for e in ans {
            write!(out, "{} ", e).ok();
        }
        out.pop();
        writeln!(out, "").ok();
        stdout().write_all(&out).unwrap();
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 3432
#include<bits/stdc++.h>
using namespace std;
int n,k;
int num[1000];
int main() {
	cin>>n>>k;
	for(int i=1;i<=n;i++) {
		cin>>num[i];
	}
	sort(num+1,num+n+1);
	int ans=0; 
	for(int i=n;i>n-k;i--)
		ans+=num[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, K: int, A: "List[int]"):
    s = sum(A)
    A.sort()
    i = 1
    #print(s)
    #print(A)
    ret = 1
    def is_ok(n):
        downs = []
        for v in A:
            downs.append(v % n)
        downs.sort()
        #print(n, downs)
        cnt = float('inf')
        for i in range(1, N):
            left = 0
            right = 0
            for l in range(i):
                left += downs[l]
            for r in range(i, N):
                right += (n - downs[r])
            tmp = max(left, right)
            cnt = min(cnt, tmp)
            #print(i, left, right, cnt)
        #print(cnt)
        if cnt <= K:
            return True
        return False

    while i * i <= s:
        if s % i == 0:
            if is_ok(s // i):
                ret = max(ret, s // i)
            if is_ok(i):
                ret = max(ret, i)
        i += 1
    print(ret)
    return


def _solve(N: int, K: int, A: "List[int]"):
    s = sum(A)
    A.sort()
    i = 1
    print(s)
    print(A)
    ret = 1
    def is_ok(n):
        cnt = 0
        ls = 0
        us = 0
        bs = 0
        for v in A:
            tmp = v // n
            l = abs(v - n * (tmp))
            u = abs(v - n * (tmp + 1))
            if l < u:
                ls += l
            elif l > u:
                us += u
            else:
                bs += l
        cnt = max(ls, us)
        #cnt = min(ls, us)
        #rest = abs(ls - us)
        #if rest >= bs:
        #    rest -= bs
        #    cnt += bs + rest
        print(n, ls, us, cnt)
        if cnt <= K:
            return True
        return False

    while i * i <= s:
        if s % i == 0:
            if is_ok(s // i):
                ret = max(ret, s // i)
            if is_ok(i):
                ret = max(ret, i)
        i += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3 = -(y2 - y1) + x2;
  int y3 = (x2 - x1) + y2;
  int x4 = (x1 - x2) + x3;
  int y4 = (y1 - y2) + y3;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}

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

int main(void){
  int A,B;
  cin >> A >> B;
  if(A > 12){
    cout << B << endl;
  }else if(A > 5){
     cout << (B/2)<< endl;
  }else{
     cout << "0" << endl;
  }
}

Measured memory_bytes: 888
import sys
L, R = map(int, input().split())

if R-L >= 2018:
    print(0)
    sys.exit()

min_mod = 2019
for i in range(L, R+1):
    for j in range(i+1, R+1):
        mod = (i*j)%2019
        min_mod = mod if min_mod > mod else min_mod
print(min_mod)

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))

typedef long long lint;
typedef pair<int, int> pii;

int H, W;
string pict[55];

bool item[30];
int l[30], t[30], r[30], b[30];
int collision[30];

bool look[30];

bool rec(int i) {
	if (look[i]) return false;
	
	look[i] = true;
	
	int col = collision[i];
	for_(j,0,26) {
		if (col >> j & 1) {
			if (!rec(j)) return false;
		}
	}
	
	look[i] = false;
	
	return true;
}

bool is_safe() {
	minit(collision, 0);
	
	for_(alph,0,26) {
		if (!item[alph]) continue;
		
		char ALPH = 'A' + alph;
		
		for_(y,t[alph],b[alph] + 1) for_(x,l[alph],r[alph] + 1) {
			if (pict[y][x] == '.') return false;
			
			if (pict[y][x] != ALPH) {
				int p = (int)(pict[y][x] - 'A');
				collision[alph] |= 1 << p;
			}
		}
	}
	
	for_(alph,0,26) {
		if (!item[alph]) continue;
		minit(look,0);
		if (!rec(alph)) return false;
	}
	
	return true;
}

void solve() {
	minit(item,0);
	fill(l, l + 30, W);
	fill(t, t + 30, H);
	fill(r, r + 30, 0);
	fill(b, b + 30, 0);
	
	for_(i,0,H) for_(j,0,W) {
		char c = pict[i][j];
		if (c == '.') continue;
		int ci = (int)(c - 'A');
		
		item[ci] = true;
		l[ci] = min(l[ci], j);
		t[ci] = min(t[ci], i);
		r[ci] = max(r[ci], j);
		b[ci] = max(b[ci], i);
	}
	
	if (is_safe()) cout << "SAFE" << endl;
	else cout << "SUSPICIOUS" << endl;
}

int main() {
	int T; cin >> T;
	while (T--) {
		cin >> H >> W;
		for_(i,0,H) cin >> pict[i];
		solve();
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>

using namespace std;

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

    int sum = 0;
    for (int i = 0; i < n; ++i){
        int tmp;
        cin >> tmp;
        if (tmp >= k) ++sum;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
def min(a,b,c):
    if a<b and a<c:
        return a
    elif b<c:
        return b
    else:
        return c


def calc(x):
    try:
        a=x.index("+")
    except:
        a=300
    try:
        b=x.index("-")
    except:
        b=300
    try:
        c=x.index("*")
    except:
        c=300

    ind=min(a,b,c)

    if ind==300:
        return x[0]
    
    if x[ind]=="+":
        x.insert(ind-2,int(x[ind-2])+int(x[ind-1]))
    elif x[ind]=="-":
        x.insert(ind-2,int(x[ind-2])-int(x[ind-1]))
    else:
        x.insert(ind-2,int(x[ind-2])*int(x[ind-1]))
    x.pop(ind-1)
    x.pop(ind-1)
    x.pop(ind-1)
    return calc(x)


operas=input().split(" ")
print (calc(operas))

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

typedef long long ll;
const ll MAXN = 3e6 + 5;
const long long MOD = 1e9 + 9;
const long double eps = 1e-6;

#define mp make_pair
#define pb push_back
#define all(temp) temp.begin(), temp.end()
#define REP(i,n) for(int i = 0; i < n; ++i)


int main()
{

    int n; cin >> n;
    vector<ll> a(n);

    for(int i = 0; i < n; ++i){
        cin >> a[i];
        a[i] -= i;
    }
    if(n == 1){
        cout << "0";
        return 0;
    }

    sort(all(a));
    ll b = a[n / 2];
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        ans += abs(b - a[i]);
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
import sys 
sys.setrecursionlimit(1000000)
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]

used = [0]*n
global ans 
ans = 0
def dfs(u):
  global ans
  used[u] = 1
  if sum(used) == n:
    ans += 1
    return 
  
  for v in graph[u]:
    if used[v] == 0:
      used[v] = 1
      dfs(v)
      used[v] = 0 

  return 

dfs(0)
print(ans)


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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;


int main(){

  int h, w;
  cin >> h >> w;
  vector<ll> cnt(26, 0);

  rep(i, h){
    string s;
    cin >> s;
    rep(j, w) cnt[(int)(s[j] - 'a')]++;
  }

  if(h < w) swap(h, w);

  bool flag;

  /*
  if(h == 1){
    flag = true;
    if(w % 2 == 0) rep(i, 26) if(cnt[i] % 2 != 0) flag = false;
    else{
      bool exist = false;
      rep(i, 26) if(cnt[i] % 2 == 1){
        if(exist) flag = false;
        else exist = true;
      }
    }
  }
  else if(w == 1){
    flag = true;
    if(h % 2 == 0) rep(i, 26) if(cnt[i] % 2 != 0) flag = false;
    else{
      bool exist = false;
      rep(i, 26) if(cnt[i] % 2 == 1){
        if(exist) flag = false;
        else exist = true;
      }
    }
  }
  */
  if(h % 2 == 0 && w % 2 == 0){
    flag = true;
    rep(i, 26) if(cnt[i] % 4 != 0) flag = false;
  }
  else if(h % 2 == 1 && w % 2 == 1){
    flag = true;
    bool exist = false;
    rep(i, 26) if(cnt[i] % 2 == 1){
      if(exist) flag = false;
      else exist = true;
    }
    if(!exist) flag = false;
    int four = 0;
    rep(i, 26) four += (cnt[i] / 4);
    if(four < (h-1) * (w-1) / 4) flag = false;
  }
  else{
    if(h % 2 != 0) swap(h, w);
    flag = true;
    rep(i, 26) if(cnt[i] % 2 == 1) flag = false;
    int four = 0;
    rep(i, 26) four += (cnt[i] / 4);
    if(four < h * (w-1) / 4) flag = false;
  }

  cout << (flag ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int num = 0;
        String q = "CODEFESTIVAL2016";
        String[] qa = q.split("");

        String str = scan.next();
        String[] stra = str.split("");

        for(int i = 0; i<qa.length; i++){
            if(qa[i].equals(stra[i])){

            }else{
                num++;
            }
        }
        System.out.println(num);
    }
}

Measured memory_bytes: 10192
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  int n;
  cin>>n;
  vector<pair<long, long>> vec(n);
  rep(i,n) cin>>vec[i].se >> vec[i].fi;

  sort(all(vec), greater<pair<long,long>>());

  int l=0, r=n+1;
  while(r-l>1){
    auto f = [&](int k){
      if(k==0) return true;
      // fi:b, se:a
      priority_queue<long> pq;
      long acc = 0;
      rep(i,k){
        pq.push(vec[i].se);
        acc += vec[i].se;
      }
      if(acc <= k*vec[k-1].fi) return true;
      repl(i,k,n){
        long mx = pq.top(); pq.pop();
        acc -= mx;
        pq.push(min(mx, vec[i].se));
        acc += min(mx, vec[i].se);

        if(acc <= k*vec[i].fi) return true;
      }
      return false;
    };

    int k = (r+l)/2;
    if(f(k)) l = k;
    else r = k;
  }

  cout << l << endl;

  return 0;
}

Measured memory_bytes: 13780
#include <iterator>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <algorithm>
using namespace std; typedef long long ll; typedef pair<ll,ll> P; const ll INF = 1e15;
int main() {
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k; cin>>k; k--;
  cout<<a[k]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <utility>
#include <set>

using llint = long long int;
using namespace std;

namespace CsF {
#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define nfor(I,J,K) for(int I = 0;I < J;I+=K)

	string ConvertBit(int N, int e) {
		string s = "";
		int r = 0;
		while (N != 0) {
			r = N % e;
			s = to_string(r) + s;
			N -= r;
			N /= e;
		}
		return s;
	}

	int GCD(int a, int b) {
		if (a < b)swap(a, b);
		int r = a % b;
		while (r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}

	int LCM(int a, int b) {
		int n = a * b;
		return (n / GCD(a, b));
	}

	int Count(string s, char c) {
		int cou = 0;
		nfor(i, s.length(), 1) {
			if (s[i] == c)cou++;
		}
		return cou;
	}

	vector<int> SieveOfEratosthenes(int N) {
		vector<bool> memo(N + 1);
		vector<int> ret;
		memo[0] = true;
		memo[1] = true;
		for (int i = 2; i < N; i++) {
			if (memo[i])continue;
			ret.push_back(i);
			for (int b = 2; true; b++) {
				if (i*b <= N) {
					memo[i*b] = true;
				}
				else break;
			}
		}
		return ret;
	}

	vector<int> SpInput(int N) {
		vector<int> ret(N);
		nfor(i, N, 1) { cin >> ret[i]; }
		return ret;
	}
}

using namespace CsF;


int main() {
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	int A[40],B[40],C[40];
	nfor(i, N, 1) { cin >> A[i] >> B[i] >> C[i]; }
	int dp[41][401][401];
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= 400; j++) {
			for (int k = 0; k <= 400; k++) {
				dp[i][j][k] = MAX_INT;
			}
		}
	}
	dp[0][0][0] = 0;
	for (int k = 0; k < N; k++) {
		for (int ai = 0; ai <= 400; ai++) {
			for (int bi = 0; bi <= 400; bi++) {
				if (dp[k][ai][bi] == MAX_INT)continue;
				//加えない時
				dp[k + 1][ai][bi] = min(dp[k + 1][ai][bi], dp[k][ai][bi]);
				//加えるとき
				dp[k + 1][ai + A[k]][bi + B[k]] = min(dp[k + 1][ai + A[k]][bi + B[k]], dp[k][ai][bi] + C[k]);
			}
		}
	}
	int ans = MAX_INT;
	for (int ai = 1; ai <= 400; ai++) {
		for (int bi = 1; bi <= 400; bi++) {
			if (Ma*bi == Mb * ai)ans = min(ans, dp[N][ai][bi]);
		}
	}
	if (ans == MAX_INT)ans = -1;
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 25984
// AOJ 2281
#include <iostream>
#include <string>

using namespace std;

char add(char c, int d)
{
	while (d--){
		if (c == 'z'){
			c = 'a';
			continue;
		}
		c++;
	}
	return c;
}

int main(void)
{
	int n;
	string str;

	while (cin >> n, n){
		cin >> str;
		int data[128][2];
		for (int i = 0; i < n; i++){
			cin >> data[i][0] >> data[i][1];
		}
		for (int i = n - 1; 0 <= i; i--){
			int a = data[i][0] - 1, b = data[i][1] - 1;
			int diff = b - a;
			char c1 = add(str[a], diff), c2 = add(str[b], diff);

			str[a] = c1;
			str[b] = c2;
			swap(str[a], str[b]);
		}
		cout << str << endl;
	}
}

Measured memory_bytes: 1200