akhauriyash/Code-Regression huggingface dataset:
program green_bin
    implicit none
    integer(4):: n,i,j,k
    integer(4),allocatable:: a(:)
    integer(8) :: count=0
    character(10):: c
    character(10),allocatable:: ca(:)
    character(26),parameter:: alpha='abcdefghijklmnopqrstuvwxyz'
    
    read*, n
    allocate(a(10), ca(n))

    do i=1,n
        read*,c(:)
        do j=1,10
            a(j) = ichar(c(j:j))
        end do
        call merge_sort(a(:),1,10)
        do j=1,10
            ca(i)(j:j) = char(a(j))
        end do
        
    end do

    call smerge_sort(ca(:), 1, n)

    block; integer(4):: fst, scd
        fst=1; scd=2
        do while (scd <= n)
            if (ca(fst)==ca(scd)) then
                count = count + scd-fst
                scd=scd+1
            else
                fst=scd
                scd=scd+1
            end if
        end do
    end block

    print*, count



contains
recursive subroutine merge_sort(ar,fst,lst)
    integer(4):: ar(:), fst, lst, mid, tmp

    if (lst-fst < 2)then
        if (ar(lst) < ar(fst)) then
            tmp = ar(fst)
            ar(fst) = ar(lst)
            ar(lst) = tmp
        end if
        return
    end if

    mid = (fst+lst)/2
    call merge_sort(ar,fst,mid)
    call merge_sort(ar,mid+1,lst)
    call merge(ar,fst,mid,lst)
end subroutine

subroutine merge(ar, fst, mid, lst)
    integer(4):: ar(:), fst, mid, lst
    integer(4),pointer:: tmp(:)
    integer(4):: it, il, ir
    
    allocate(tmp(lst-fst+1))
    it=1
    il=fst
    ir=mid+1

    do while(il <= mid .and. ir <= lst)
        if (ar(il) <= ar(ir)) then
            tmp(it)=ar(il)
            il=il+1
        else
            tmp(it)=ar(ir)        
            ir=ir+1
        end if
        it=it+1
    end do

    if(ir > lst) then
        tmp(it:) = ar(il:mid)
    else
        tmp(it:) = ar(ir:lst)
    end if

    ar(fst:lst) = tmp(:)
    deallocate(tmp)
    
end subroutine

recursive subroutine smerge_sort(ar, fst, lst)
    character(10):: ar(:), tmp
    integer(4):: fst, lst, mid

    if (lst-fst < 2) then
        if (ar(lst) < ar(fst)) then
            tmp = ar(fst)
            ar(fst) = ar(lst)
            ar(lst) = tmp
        end if
        return
    end if

    mid = (fst+lst)/2
    call smerge_sort(ar, fst, mid)
    call smerge_sort(ar, mid+1, lst)
    call smerge(ar, fst, mid, lst)
end subroutine

subroutine smerge(ar, fst, mid, lst)
    character(10):: ar(:)
    character(10),pointer:: tmp(:)
    integer(4):: fst, mid, lst
    integer(4):: it, il, ir

    allocate(tmp(lst-fst+1))
    it=1
    il=fst
    ir=mid+1

    do while(il <= mid .and. ir<=lst)
        if (ar(il) <= ar(ir)) then
            tmp(it) = ar(il)
            il=il+1        
        else
            tmp(it) = ar(ir)
            ir=ir+1
        end if
        it=it+1
    end do

    if (ir > lst) then
        tmp(it:) = ar(il:mid)
    else
        tmp(it:) = ar(ir:lst)
    end if
    ar(fst:lst) = tmp(:)
end subroutine


    
end program green_bin

Measured memory_bytes: 17920
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<queue>
#include<iostream>
#define REP(i, n) for(int i = 0, ed_##i = n; i < ed_##i; i++)
#define FOR(i, n) for(int i = 1, ed_##i = n; i <= ed_##i; i++)
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))  // Leading zeros
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#ifdef QWERTIER
#define err(x) cerr << #x << " : " << x << endl
#else
#define err(x)
#endif

typedef long long LL;
using namespace std;

typedef pair<int,int> pii;
#define MP make_pair

char s[200010];
int main(){
#ifdef QWERTIER
  freopen("in.txt","r",stdin);
#endif
  scanf("%s", s);
  int sum = 0, ans = 0;
  REP (i, strlen(s)) {
    if (s[i] == 'S') {
      sum++;
    } else {
      if (sum <= 0) {
        ans++;
      } else {
        sum--;
      }
    }
  }
  printf("%d", ans+sum);
  return 0;
}


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

int main(){
  int a,i,j,array[100],b=0,c=0;
  cin>>a;
  for(i=0;i<a;i++){
    cin>>array[i];
  }
  sort(array,array+a);
  for(i=0;i<a;i++){
    if(i%2){
      c+=array[a-1-i];
    }else{
      b+=array[a-1-i];
    }
  }
  cout<<b-c<<endl;
}

Measured memory_bytes: 256
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

const ll MAX = 1e9+5;


int main()
{
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    int n, k;
    cin>>n>>k;

    int arr[k+1];
    for(int i=1; i<=n; i++){
        cin>>arr[i];
    }

    int dp[k+1];
    for(int i=0; i<=k; i++){
        dp[i] = 2;
    }

    for(int j=1; j<=k; j++){
        for(int i=1; i<=n; i++){
            if(arr[i] <= j){
                if(dp[j - arr[i]] == 2){
                    dp[j] = 1;
                }
            }
        }
    }

    if(dp[k] == 1){
        cout<<"First"<<endl;
    }
    else{
        cout<<"Second"<<endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,a[100005];
ll ans;
ll k=1000000000000000000;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    if(a[0]==0){
        cout<<0<<endl;
        return 0;
    }
    ans=1;
    for(int i=0;i<n;i++){
        if(a[i]>k/ans){
            cout<<-1<<endl;
            return 0;
        }else{
            ans=ans*a[i];
        }
    }
    cout<<ans<<endl;

}



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

s=list([0])
for i in range(N-1):
  if A[i]>A[i+1]:
    s.append(A[i]-A[i+1])
    A[i+1] = A[i]
  else:
    s.append(0)
print(sum(s))

Measured memory_bytes: 32192
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {

  i64 N;
  cin >> N;
  i64 o = (N + 1) / 2;
  cout << double(o) / double(N) << std::endl;
  return 0;
}


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

int main() {
  int n, s;
  int a[9], b;
  long long int dp[9][1001];
  memset(dp, 0, sizeof(long long int)*9*1001);
  for (int i=0; i<9; i++) a[i]=i*(i+1)>>1;
  for (int i=0; i<=100; i++) {
    for (int j=8; j; j--) {
      if (i<j) continue;
      b = j*(2*i-j-1)>>1;
      for (int k=a[j-1]; k<=b; k++) {
        dp[j][k+i] += dp[j-1][k];
      }
    }
    dp[0][i] = 1;
  }
  while (1) {
    cin >> n >> s;
    if (!n && !s) break;
    cout << dp[n-1][s] << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
N = int(input())
ans = 0

if(N < 105):
  print(0)
else: 
  for i in range(105,N+1):
   count = 0
   if(i%2 == 1):
    for j in range(1,N+1):
     if(i%j == 0):
      count += 1
   if(count == 8):
     ans += 1
  print(ans)
    

Measured memory_bytes: 3060
N = input()
p=list(map(int, input().strip().split()))

N=int(N)

k=0

for i in (range(N)):
    for j in (range(N)):
        p[i],p[j]=p[j],p[i]
        if p == sorted(p):
            k=1
            break
        p[i],p[j]=p[j],p[i]
    if k==1:
        break

if k==1:
    print("YES")
else:
    print("NO")
    


Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	int N, count = 0, an = 0;
	long long a[10000];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
	}
	while (true){
		count = 0;
		for (int i = 0; i < N; i++) {
			if (a[i] % 2 == 0) {
				a[i] /= 2;
				break;
			}
			count++;
		}
		if (count == N) {
			printf("%d", an);
			return 0;
		}
		an++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<pii> a(m);
	rep(i,m) cin >> a.at(i).first >> a.at(i).second;
	sort(a.begin(),a.end());
	int ans = 0,k = 0;
	rep(i,m){
		if(a.at(i).first >= k){
			ans++;
			k = a.at(i).second;
		}
		k = min(k, a.at(i).second);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace c {
    class Program {
        static void Main (string[] args) {
            int N = int.Parse (Console.ReadLine ());
            int[] d = Console.ReadLine ().Split ().Select (t => int.Parse (t)).ToArray ();
            Array.Sort (d);
            int result = 0;
            if (N % 2 == 0) {
                result = d[N / 2] - d[N / 2 - 1];
            }

            Console.WriteLine (result);
        }
    }
}

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

int main()
{
 long long int n;
 cin>>n;
 long long int sum=0;
 for(int i=1;i<=n;i++)
 {
  if(((i%3)!=0) && ((i%5)!=0))
  {
    sum = sum +i;

  }
 }
 cout<<sum<<endl;






}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//最大公約数をユークリッドの互除法を使って求める
 
int gcd(int a, int b) {
    if(a % b == 0)
    return b;
    return gcd(b, a % b);
}


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

    int ans=a[0];
    for(int i=1;i<n;i++) {
        ans=gcd(ans,a[i]);
    }
    
    cout<<ans<<endl;


 return 0;
}


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

using pii = pair<int, int>;

constexpr int INF = 1e9;

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

int main() {
    int W, H;
    while(cin >> W >> H, W) {
        vector<vector<int>> wall(2*H-1);
        for(int i=0; i<2*H-1; ++i) {
            int lim = i%2 == 0 ? W-1 : W;
            for(int j=0; j<lim; ++j) {
                int t; cin >> t;
                wall[i].push_back(t);
            }
        }
        vector<vector<int>> d(H, vector<int>(W, INF));
        d[0][0] = 1;
        queue<pii> que;
        que.push(make_pair(0, 0));
        while(!que.empty()) {
            pii p = que.front();
            int y = p.first, x = p.second;
            que.pop();
            int wy[4] = {y*2+1, y*2, y*2-1, y*2};
            int wx[4] = {x, x, x, x-1};
            for(int i=0; i<4; ++i) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if(ny < 0 || H <= ny || nx < 0 || W <= nx || d[ny][nx] != INF) {
                    continue;
                }
                if(!wall[wy[i]][wx[i]]) {
                    que.push(make_pair(ny, nx));
                    d[ny][nx] = d[y][x] + 1;
                }
            }
        }
        int res = d[H-1][W-1];
        cout << (res == INF ? 0 : res) << endl;
    }
}


Measured memory_bytes: 3148
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    string S; cin >> S;
    for (int i = 0; i < 7; i++) {
        string a = S.substr(0, i), b = S.substr(S.length() - (7 - i), 7 - i);
        if (a + b == "keyence") {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3572
n = int(input())
path = [[] for i in range(n)]

for i in range(n-1):
    a, b, c = map(int, input().split())
    path[a-1].append((b-1, c))
    path[b-1].append((a-1, c))


q, k = map(int, input().split())
distance = [None] * n
distance[k-1] = 0
queue = [k-1]
while(len(queue)):
    p = queue.pop()
    for i,c in path[p]:
        if(distance[i] == None):
            distance[i] = distance[p] + c
            queue.append(i)

for i in range(q):
    x, y = map(int, input().split())
    print(distance[x-1]+distance[y-1])


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

//计算n的阶乘 
long long int jc(long long int n){
    long long int i,res=1;
    for(i=1;i<=n;i++){
        res=res*i;
    } 
    return res;
}

//计算组合数
long long int C(long long int m,long long int n){
    return (jc(n))/(jc(m)*jc(n-m));
} 

int main(void)
{

    long long int n,a,b;
    cin>>n>>a>>b;
    if(n==1)
    {
        if(a==b) cout<<1<<endl;
        else cout<<0<<endl;
    }
    else if(n > 1)
    {
        if(a > b) cout<<0<<endl;
        else    cout<<(a+(n-1)*b)-((n-1)*a+b)+1<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
l = a[0]
r = a[-1]
ans = 10**10
for i in range(l,r+1):
    cand = 0
    for j in range(n):
        cand += (i - a[j])**2
    ans = min(ans, cand)
print(ans)

Measured memory_bytes: 38512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int N;

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

    cin >> N;
    vector<int> d(N);
    rep(i,N) cin >> d[i];
    sort(d.begin(), d.end());
    cout << d[N/2] - d[N/2-1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(void){
  
  int xx;
  int yy;
  int tur = 0;
  int clane = 0;
  cin >> xx >> yy;
  
  if((yy % 2) != 0){
  	cout << "No" << endl;
	return 0;
  }
  
  tur = xx;
  
  for(int i = 0; i <= xx; i++){
  	if((tur * 4 + clane * 2) == yy){
    	cout << "Yes" << endl;
      	return 0;
    }
    tur--;
    clane++;
  }
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
import math
N=int(input())
from sys import stdin
num_list=[3,5,7]

count=0
for i in range(N):
    flag=1
    cmd = int(stdin.readline().strip())

    if cmd==2 or cmd==3 or cmd==5 or cmd==7:
        count+=1
        continue
    if (cmd) % 2 == 0:
        continue
    else:
        for i in range(3,int(math.sqrt(cmd)+1),2):
            if cmd % i == 0:flag=0
        if flag==1:
            count+=1

print(count)


Measured memory_bytes: 5676
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int a,b,c,d;
	cin >> a >> b >>c >> d;
	if (a != c){
		cout << 1 << endl;
	}
	else{
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

int main(){
	ll N;
	cin >> N;
	ll ans = 0;
	ll k;
	for (k = 1; true; k++){
		if (k*(k + 1) >= N){
			break;
		}
		if (N%k == 0){
			ans += (N / k) - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

  scanf("%d", &n);

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

  /* your code */
  for(i = 0;i <= VMAX;i++)
    C[i] = 0;

  for(j = 1;j <= n;j++)
    {
      scanf("%d",&A[j]);
      C[A[j]]++;
    }

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

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

  for(i = 1;i < n;i++)
    printf("%d ",B[i]);
  printf("%d\n",B[n]);



  return 0;
}



Measured memory_bytes: 9596
#include <stdio.h>

int main(void) {
  int i, n, j;
  scanf("%d", &n);
  char a[4][14];
  for(i = 0; i < 4; ++i) for(j = 0; j < 14; ++j) a[i][j] = 0;
  for(i = 0; i < n; ++i) {
    char c;
    int d;
    scanf("%c", &c);
    scanf("%c %d", &c, &d);
    if(c == 'S') a[0][d] = 1;
    else if(c == 'H') a[1][d] = 1;
    else if(c == 'C') a[2][d] = 1;
    else if(c == 'D') a[3][d] = 1;
  }
  for(i = 0; i < 4; ++i) for(j = 1; j < 14; ++j) {
    if(!a[i][j]) {
      if(i == 0) printf("S %d\n", j);
      else if(i == 1) printf("H %d\n", j);
      else if(i == 2) printf("C %d\n", j);
      else if(i == 3) printf("D %d\n", j);
    }
  }
  return 0;
}


Measured memory_bytes: 2724
nk = list(map(int, input().split()))
N = nk[0]
K = nk[1]

d = input().split()
a = True
for i in range(N, 90001):
  a = True
  for j in d:
    if str(i).count(j) > 0:
      a = False
      break
  if a:
    print(i)
    break

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

const int MOD = 1000000007;

int fac[2010];
int inv[2010];

int modpow(int b, int e)
{
    int a = 1;
    
    while (e)
    {
        if (e & 1)
            a = (1LL * a * b) % MOD;
        b = (1LL * b * b) % MOD;
        e >>= 1;
    }
    
    return a;
}

void init()
{
    fac[0] = 1;
    inv[0] = 1;
    
    for (int i = 1; i != 2010; ++i)
    {
        fac[i] = (1LL * fac[i - 1] * i) % MOD;
        inv[i] = modpow(fac[i], MOD - 2);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    init();
    
    int n, k;
    cin >> n >> k;
    
    for (int i = 1; i <= k; ++i)
    {
        if (n + 1 < k + i)
            cout << 0 << '\n';
        else
        {
            int ans = (1LL * fac[k - 1] * fac[n - k + 1]) % MOD;
            ans = (1LL * ans * inv[i - 1]) % MOD;
            ans = (1LL * ans * inv[k - i]) % MOD;
            ans = (1LL * ans * inv[i]) % MOD;
            ans = (1LL * ans * inv[n - i - k + 1]) % MOD;
            
            cout << ans << '\n';
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
while True:
    w,h = map(int,input().split())
    if w==0: break
    mapp = [[[0]*2 for _ in range(w+2)] for _ in range(h+2)]
    mapp[0][0][0] = mapp[0][0][1] = 1
    mapp[0][2][0] = mapp[2][0][1] = -1
    for i in range(0,h):
        for j in range(0,w):
            if i==h-1 and j==w-1 : break
            mapp[i][j+1][0] += mapp[i][j][0]
            if mapp[i][j+1][0] >= 100000: mapp[i][j+1][0] -= 100000
            mapp[i][j+2][0] += mapp[i][j][1]
            if mapp[i][j+2][0] >= 100000: mapp[i][j+2][0] -= 100000
            mapp[i+1][j][1] += mapp[i][j][1]
            if mapp[i+1][j][1] >= 100000: mapp[i+1][j][0] -= 100000
            mapp[i+2][j][1] += mapp[i][j][0]
            if mapp[i+2][j][1] >= 100000: mapp[i+2][j][0] -= 100000

    print(sum(mapp[h-1][w-1]+mapp[h][w-1]+mapp[h-1][w])%100000)

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

struct Edge {
	ll to, rev;
    long double cap;
	Edge(ll _to, long double _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

//最大公約数
ll gcd(ll m, ll n) {
 if (n == 0)return m;
 return gcd(n, m % n);
}//gcd

template<typename T, typename F>
class SegmentTree {
private:
	T e;
	F op;
	ll n;
	vector<T> dat;
public:
	SegmentTree(F f, T _e, vector<T> v) :op(f), e(_e) {
		int _n = v.size();
		n = 1;
		while (n < _n)n *= 2;
		dat.resize(2 * n - 1, e);
		REP(i, _n)dat[n + i - 1] = v[i];
		for (int i = n - 2; i >= 0; i--)dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
	}
	SegmentTree(F f, T _e, int _n) :op(f), e(_e) {
		n = 1;
		while (n < _n)n *= 2;
		dat.resize(2 * n - 1, e);
		for (int i = n - 2; i >= 0; i--)dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
	}
	void update(int i, T x) {
		i += n - 1;
		dat[i] = x;
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}
	T query(int l, int r) {
		//[l,r)でのクエリ処理
		T left = e, right = e;
		l += n - 1; r += n - 1;
		while (l < r) {
			if ((l & 1) == 0)left = op(left, dat[l]);
			if ((r & 1) == 0)right = op(dat[r - 1], right);
			l = l / 2;
			r = (r - 1) / 2;
		}
		return op(left, right);
	}
};

void solve(){
    ll n;
    cin>>n;

    Array a(n);
    REP(i,n) cin>>a[i];

    auto op = [](ll a, ll b) {return gcd(a,b); };
    SegmentTree<ll, decltype(op)> seg(op,0,a);

    ll ans=0;
    REP(i,n) chmax(ans,gcd(seg.query(0,i), seg.query(i+1,n)));
    cout<<ans<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


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

int main(){
    long trans[6];
    for(int i = 0; i < 6; i++){
        cin >> trans[i];
    }
    long temp = 1e+16;
    int num = 0;
    for(int i = 1; i < 6; i++){
        if(trans[i] < temp){
            temp = trans[i];
            num = i;
        }
    }
    long total = 0;
    for(int i = 1; i < 6; i++){
        if(i != num){
            total++;
            //cout << i << ':' << total << endl;
        }else{
            total += (long)(trans[0] / trans[num]);
            if(trans[0] % trans[num] != 0){
                total++;
            }    
            //cout << "rest:" << trans[0] % trans[num] <<endl;
            //cout << i << ':' << total << endl;
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)

int main(void) {
	int a; cin >> a;
	cout << (a < 1200 ? "ABC" : "ARC") << endl;
	return 0;
}

Measured memory_bytes: 256
#1:50

import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
#print(P, Q)

ln = list()
for i in range(1, N+1):
    ln.append(i)

all = list(itertools.permutations(ln))

print(abs(all.index(P) - all.index(Q)))

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

UL N, Q;
UL P[100000][18];
UL D[100000];
UL C[100000];
vector<pair<UL, UL>> E[100000];

UL LCA(UL a, UL b) {
	if (C[a] < C[b]) swap(a, b);
	UL d = C[a] - C[b];
	for (UL i = 17; i != ~0u; i--) {
		if ((1u << i) & d) a = P[a][i];
	}
	if (a == b) return a;
	for (UL i = 17; i != ~0u; i--) {
		if (P[a][i] == P[b][i]) continue;
		a = P[a][i]; b = P[b][i];
	}
	return P[a][0];
}

pair<UL, UL> MP(UL a, UL b) {
	UL X = D[LCA(a, b)];
	if (D[a] < D[b]) swap(a, b);
	UL Y = D[a] - D[b] + X + X;
	for (UL i = 17; i != ~0u; i--) {
		if (D[P[a][i]] * 2 <= Y) continue;
		a = P[a][i];
	}
	if (X == D[a]) return{ a,a };
	else return { a, P[a][0] };
}

UL Dist(UL a, UL b) {
	UL X = D[LCA(a, b)];
	return D[a] + D[b] - X - X;
}

int main() {
	scanf("%u%u", &N, &Q);
	rep(i, N - 1) {
		UL u, v, w; scanf("%u%u%u", &u, &v, &w); u--; v--;
		E[u].push_back({ v, w });
		E[v].push_back({ u, w });
	}
	{
		P[0][0] = 0; D[0] = 0; C[0] = 0;
		queue<UL> G; G.push(0);
		while (G.size()) {
			UL p = G.front(); G.pop();
			for (auto& e : E[p]) {
				if (P[p][0] == e.first) continue;
				P[e.first][0] = p;
				D[e.first] = D[p] + e.second;
				C[e.first] = C[p] + 1;
				G.push(e.first);
			}
		}
	}
	rep(i, 17) rep(j, N) P[j][i + 1] = P[P[j][i]][i];

	rep(q, Q) {
		UL a, b, c; scanf("%u%u%u", &a, &b, &c); a--; b--; c--;
		UL ans = ~0u;
		rep(t, 3) {
			auto mp = MP(a, b);
			UL q1 = max(max(Dist(mp.first, a), Dist(mp.first, b)), Dist(mp.first, c));
			UL q2 = max(max(Dist(mp.second, a), Dist(mp.second, b)), Dist(mp.second, c));
			ans = min(ans, min(q1, q2));
			swap(a, b); swap(b, c);
		}
		printf("%u\n", ans);
	}
	return 0;
}



Measured memory_bytes: 17116
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

void solve(int R) {
  if (R < 1200) {
    printf("ABC\n");
  } else if (R < 2800) {
    printf("ARC\n");
  } else {
    printf("AGC\n");
  }
}

int main() {
  int R;
  cin >> R;
  solve(R);
  return 0;
}


Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main() {
	int N, a, b;
	vector<int> v[100000];
	cin >> N;
	REP(i, N) {
		cin >> a >> b;
		v[a - 1].push_back(b - 1);
		v[b - 1].push_back(a - 1);
	}

	int parent[100000];
	REP(i, N) {
		parent[i] = -1;
	}
	stack<int> s;
	s.push(0);
	parent[0] = -2;
	while (s.size() != 0) {
		int k = s.top();
		s.pop();
		REP(i, v[k].size()) {
			if (parent[v[k][i]] == -1) {
				parent[v[k][i]] = k;
				s.push(v[k][i]);
			}
		}
	}

	int key = N - 1;
	vector<int> path;
	while (key != -2) {
		path.push_back(key);
		key = parent[key];
	}
	//cout << parent[3] << endl;
	int left = path[path.size() / 2 - 1];
	int right = path[path.size() / 2];
	int size = v[left].size();
	REP(i, size) {
		int k = v[left][0];
		v[left].erase(v[left].begin());
		if (k != right) {
			v[left].push_back(k);
		}
	}
	size = v[right].size();
	REP(i, size) {
		int k = v[right][0];
		v[right].erase(v[right].begin());
		if (k != left) {
			v[right].push_back(k);
		}
	}

	REP(i, N) {
		parent[i] = -1;
	}
	stack<int>t;
	t.push(0);
	parent[0] = -2;
	while (t.size() != 0) {
		int k = t.top();
		t.pop();
		REP(i, v[k].size()) {
			if (parent[v[k][i]] == -1) {
				parent[v[k][i]] = k;
				t.push(v[k][i]);
			}
		}
	}
	int cnt = 0;
	REP(i, N) {
		if (parent[i] != -1) {
			cnt++;
		}
	}

	//cout << right << " " << left << endl;
	int fe = cnt;
	if (2 * fe > N) {
		cout << "Fennec" << endl;
	}
	else {
		cout << "Snuke" << endl;
	}


	return 0;
}

Measured memory_bytes: 6780
using System;

namespace AtCoder
{
    class Curtain
    {
        static void Main(string[] args)
        {
            string line = System.Console.ReadLine();
            string[] stArrayData = line.Split(' ');
            int A = int.Parse(stArrayData[0]);
            int B = int.Parse(stArrayData[1]);

            int C = A - B * 2;
            
            Console.WriteLine(Math.Max(0, C));
        }
    }
}


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

string judge(double a, double b) {
    if (a < 35.50 && b < 71.00) {
        return "AAA";
    } if (a < 37.50 && b < 77.00) {
        return "AA";
    } if (a < 40.00 && b < 83.00) {
        return "A";
    } if (a < 43.00 && b < 89.00) {
        return "B";
    } if (a < 50.00 && b < 105.00) {
        return "C";
    } if (a < 55.00 && b < 116.00) {
        return "D";
    } if (a < 70.00 && b < 148.00) {
        return "E";
    }
    return "NA";
}

int main() {
    double a, b;
    while (cin >> a >> b) {
        cout << judge(a, b) << endl;
    }
    return 0;
}

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

#define 	ll 						long long int
#define 	pb 						push_back
#define 	mp 						make_pair
#define 	fast 					ios_base::sync_with_stdio(false);cin.tie(NULL);
#define 	ff 						first
#define 	ss 						second
#define 	nil 					-10e+9
#define 	initial 				0
#define 	waiting 				1
#define 	visit 					2
#define 	inf  					10e+9
#define 	mx   					200005
#define 	mxx  					1000005
#define 	mod  					1000000007
#define 	pr   					pair<ll,ll>
#define 	pp_queue 			priority_queue<pr,vector<pr>, greater<pr> >
#define 	dp_queue 			priority_queue<int,vector<int>, greater<int> >
#define 	sp_queue 			priority_queue<int>
#define 	fr(i,p,q)			for(int i=p;i<q;++i)
#define 	frr(i,p,q) 		for(int i=p;i<=q;++i)
#define 	mem(a,b) 			memset(a,b,sizeof(a))
#define 	len(a)   			(int)a.size()
#define 	input  				freopen("input.txt", "r", stdin);
#define 	output 				freopen("output.txt", "w", stdout);
#define 	debug(arr,j,n) fr(i,j,n) cout<<arr[i]<<" ";

ll power(ll a,ll b){ll aa=1;while(b){if(b&1){aa=aa*a;aa%=mod;}a=a*a;a%=mod;b/=2;}return aa;}

using namespace std;

int main()
{
  int n;
	cin>>n;
	if(n==1) cout<<"1\n";
	else 
	 cout<<n*n*n<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

bool is_prime[1000010];
int dp[100010];
int ana[100010];
int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; ++i){
        cin >> a[i];
        ana[a[i]] = 1;
    }
    dp[0] = 1;
    if(ana[1] != 1)dp[1] = 1;
    else dp[1] = 0;
    for (int i = 2; i <= n; ++i) {
        if(!ana[i-2]){
            dp[i] += dp[i-2];
            dp[i] %= mod;
        }
        if(!ana[i-1]){
            dp[i] += dp[i-1];
            dp[i] %= mod;
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;

ll cnt(ll p){
  ll ret = 0;
  while(p){
    ret += (p /= 5);
  }
  return ret;
}

int main()
{
  cin >> n;
  if(n%2){
    cout << 0 << endl;
    return 0;
  }
  cout << cnt(n / 2) << endl;
  return 0;
}


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

using namespace std;
int N;
int gcd(int a,int b,int c){
  int ans,work;
  if(a>b){
    work=a; 
  }else{
    work=b; 
  }
  if(work>c){
  }else{
    work=c;
  }

  for(int i=work;i>0;i--){
    if(a%i+b%i+c%i==0){
      return i;
    }
  }
  
  //12345678910
  //20191817161514131211
  return 1;
}
int main()
{
  cin>>N;
  int count=0;
  for(int i=1;i<N+1;i++){
    for(int j=i;j<N+1;j++){
      for(int l=j;l<N+1;l++){
        if(i==j&&i==l){
          count+=i;
        }else{
          if(i==j||j==l||l==i){
            count+=gcd(i,j,l)*3;
          }else{
            count+=gcd(i,j,l)*6;
          }

        }
        //cout<<i<<""<<j<<""<<l<<" "<<count<<""<<"\n";
      }
    }
  }
    cout<<count;

  return 0;
}





Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
#define mst(a) memset(a,0,sizeof a)
vector<int>e[N];
int n,m,ans[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++){
		scanf("%d%d",&u,&v);
		e[u].push_back(v),e[v].push_back(u);
	}
	ans[1]=1;
	queue<int>q;
	q.push(1);
	while(q.size()){
		int u=q.front();q.pop();
		for(auto v:e[u])
			if(!ans[v]) ans[v]=u,q.push(v); 
	}
	puts("Yes");
	for(int i=2;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
} 


Measured memory_bytes: 10712
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	int n;
	llint mn = 1000000, mx = -1000000, sum = 0;
	cin >> n;
	rep(i, n) {
		llint x;
		cin >> x;
		mn = min(mn, x);
		mx = max(mx, x);
		sum += x;
	}
	cout << mn << " " << mx << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3116
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.array;

void main() {
    auto l = readln.chomp.split.map!(to!int).array;
    l.sort!("a < b");

    int a = l[0], b = l[1], c = l[2];

    int ans = (c - a) / 2 + (c - b) / 2;

    if ((c - a) % 2 == 0) {
        if ((c - b) % 2 == 1) {
            ans += 2;
        }
    }
    else {
        if ((c - b) % 2 == 0) {
            ans += 2;
        }
        else {
            ans += 1;
        }
    }

    writeln(ans);

    return;
}

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

const int maxn = 1e5 + 15;

int n;
int cnt[maxn];

bool is[maxn];

set<int> st[maxn];
vector<int> g[maxn];

int main() {
	cin >> n;
	for(int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		cnt[u]++;
		cnt[v]++;
		st[u].insert(v);
		st[v].insert(u);		
		g[u].push_back(v);
		g[v].push_back(u);
	}
	queue<int> q;
	for(int i = 0; i < n; i++) {
		if(cnt[i] == 1) {
			q.push(i);
		}
	}
	while(q.size()) {
		int u = q.front();
		if(!cnt[u]) {
			return cout << "First", 0;
		}
		int v = *st[u].begin();
		is[u] = true;
		is[v] = true;
		for(auto it = st[v].begin(); it != st[v].end(); it++) {
			cnt[*it]--;
			st[*it].erase(v);
			if(cnt[*it] == 1 && !is[*it])
				q.push(*it);
		}
		q.pop();
	}
	string a = "Second";
	for(int i = 0; i < n; i++) {
		if(!is[i])
			a = "First";
	}
	cout << a;
	
	return 0;
}


Measured memory_bytes: 20608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	loop(i,1,n+1)if(n%i==0){
		bool h=true;
		rep(j,n-i)if(in[j]!=in[j+i])h=false;
		if(h){
			cout<<n/i<<endl;
			break;
		}
	}
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=2e5+10;
int n;
int main() {
  //  freopen("test.txt","r",stdin);
    int n,k;
    int a[maxn];
    cin>>n>>k;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    ll ans=0;
    for(int i=1;i<=n-k;i++) {
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
open Str

let read_list f =
  split (regexp " +") (read_line ()) |> List.map f

let rec derangement ct ix = function
    [] -> ct
  | [h] when h = ix -> ct + 1
  | h :: _ :: t when h = ix -> derangement (ct + 1) (ix + 2) t
  | h :: t -> derangement ct (ix+1) t

let () =
  let _ = read_line () in
  let lst = read_list int_of_string in
  derangement 0 1 lst |> string_of_int |> print_endline


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
int dfs(int i, vector<vector<int>>&adj, vector<int>&dp){
  if(dp[i]!=-1)
    return dp[i];
  dp[i]=0;
  for(auto j : adj[i])
    dp[i]=max(dp[i], 1+dfs(j, adj, dp));
  
  return dp[i];
}

int main(){
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  int nodes, edges;
  cin>>nodes>>edges;
  vector<vector<int>>adj(nodes+1);
  vector<int>dp(nodes+1, -1);
  
  for(int i=0;i<edges;i++){
    int u,v;
    cin>>u>>v;
    adj[u].push_back(v);
  }
  int ans=INT_MIN;
  for(int i=1;i<=nodes;i++){
    if(dp[i]==-1){
      dfs(i, adj,dp);
    }
    ans=max(ans, dp[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 8832
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  if(n<r)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll i,j,N,K,ans;
  cin>>K>>N;
  vec v(N);
  rep(i,N)cin>>v[i];
  ans=v[0]+K-v[N-1];
  rep1(i,N){
    chmax(ans,v[i]-v[i-1]);
  }
  print(K-ans);
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
 
    string s;
    cin>>s;

    if(s=="Sunny")
        cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")
        cout<<"Rainy"<<endl;
    else//rainy
        cout<<"Sunny"<<endl;

    return 0;
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=200005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N, K, C, L[MAXN], R[MAXN];
char A[MAXN];
main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> K >> C;
	FOR(i,1,N) cin >> A[i];
	FOR(i,1,N){
		L[i] = L[i-1];
		if (A[i]=='x') continue;
		L[i] = max(L[i], L[i-C-1]+1);
	}
	DEC(i,N,1){
		R[i] = R[i+1];
		if (A[i]=='x') continue;
		R[i] = max(R[i], R[i+C+1]+1);
	}
	FOR(i,1,N){
		//cout << L[i-1] << " " << R[i+1] << "\n";
		if (L[i-1]+R[i+1]<K) cout << i << "\n";
	}
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <math.h>

#define N 101

int main()
{
  int i, j, l, k, q;
  int n, P[N], M[N][N];

  scanf("%d", &n);
  
  for( i = 0 ; i < n ; i++ ) scanf("%d%d", &P[i], &P[i+1]);
  
  for( i = 1 ; i <= n ; i++ ) M[i][i] = 0;
  
  for( l = 2 ; l <= n ; l++ ){
    for( i = 1 ; i <= n-l+1 ; i++ ){
      j = i+l-1;
      M[i][j] = 100000000;
      for( k = i ; k <= j-1 ; k++ ){
	q = M[i][k] + M[k+1][j] + P[i-1] * P[k] * P[j];
	M[i][j] = fmin(M[i][j], q);
      }
    }
  }
  
  printf("%d\n", M[1][n]);

  return 0;
}

Measured memory_bytes: 640
import sys
from operator import mul
 
N,M,C = sys.stdin.readline().strip().split()
N = int(N)
M = int(M)
C = int(C)
 
B_list = sys.stdin.readline().strip().split()


for i in range(len(B_list)):
    B_list[i] = int(B_list[i])

#print(B_list)

A_list = []
for i in range(N):
    tmp = sys.stdin.readline().strip().split()
    A_list.append(tmp)

for i in range(len(A_list)):
    for j in range(len(A_list[i])):
        A_list[i][j] = int(A_list[i][j])

#print(A_list)

cnt = 0
for k in range(N):
    combined = [A * B for (A, B) in zip(A_list[k], B_list)]
    calc = sum(combined) + C
    if(calc>0):
        cnt += 1

print(cnt)
#combined = map(mul, A_list, B_list)
#print(combined)

Measured memory_bytes: 3064