akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	long int x,i,j,k;
	cin>>x;
	string  s;
	long long int a[5];
	for(i=0;i<5;i++)
	  a[i]=0;
	for(i=0;i<x;i++)
	  {   cin>>s;
	     if(s[0]=='M')
	       {
	       	a[0]++;
	       }
	     if(s[0]=='A')
	       {
	       	a[1]++;
	       	//cout<<"Four";
	       	//return 0;
	       }
	     if(s[0]=='R')
	       {
	       	a[2]++;
	       	//cout<<"Four";
	       	//return 0;
	       }
	      if(s[0]=='C')
	       {   a[3]++;
	       	//cout<<"Four";
	       	//return 0;
	       } 
	      if(s[0]=='H')
	       {	a[4]++;
	       	//cout<<"Four";
	       	//return 0;
	       } 
	  }
	long long int ans=0;  
	for(i=0;i<5;i++)
	  {
	     for(j=i+1;j<5;j++)
	       {
	       	for(k=j+1;k<5;k++)
	       	  ans=ans+((a[i]*1ll*a[j])*1ll*a[k]);
	       }
	  }
	cout<<ans<<" ";  
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
X = [int(x) for x in input().split()]
ans = 10 ** 9
if K == 1:
  ans = min([abs(x) for x in X])
elif K == N:
  ans = X[N - 1] - X[0] + min(abs(X[0]), abs(X[N - 1]))
for i in range(N - K + 1):
  ans = min(X[i + K - 1] - X[i] + min(abs(X[i]), abs(X[i + K - 1])), ans)
print(ans)

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;

    int l = 0;
    int r = s.size() - 1;
    int ans = 0;
    while (l < r) {
        if (s[l] == s[r]) {
            l++;
            r--;
        } else if (s[l] == 'x' && s[r] != 'x') {
            l++;
            ans++;
        } else if (s[l] != 'x' && s[r] == 'x') {
            r--;
            ans++;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll modex(ll x,ll n,ll m)
{
	ll res=1;
	while(n>0)
	{
		if(n&1)
			res=(res*x)%m;
		x=(x*x)%m;
		n=n/2;
	}
	return res;
}
int main()
{

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt" , "r" , stdin);
	// freopen("output.txt" , "w" , stdout);
	// #endif

	ll n,a,b,ans,m=1e9+7;
	cin>>n>>a>>b;
	ans=modex(2,n,m);
	ll ip[200005];
	ip[1]=1;
	for(ll i=2;i<=200000;i++)
	{
		ip[i]=(ip[i-1]*modex(i,m-2,m))%m;
	}
	ll ans1=1,ans2=1,j=n;
	for(ll i=1;i<=a;i++)
	{
		ans1=(ans1*j)%m;
		j--;
	}
	ans1=(ans1*ip[a])%m;
	j=n;
	for(ll i=1;i<=b;i++)
	{
		ans2=(ans2*j)%m;
		j--;
	}
	ans2=(ans2*ip[b])%m;
	ans=(ans-ans1-ans2-1+2*m)%m;
	cout<<ans<<endl;


	
	
}


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

char ans[105][105];

int main() {
  int a,b;
  scanf("%d%d",&a,&b);
  puts("100 100");
  for(int i=0;i<100;i++) {
    for(int j=0;j<50;j++) ans[i][j] = '.';
    for(int j=50;j<100;j++) ans[i][j] = '#';
  }
  a--,b--;
  for(int i=0;i<100 && b;i+=2)
    for(int j=0;j<49 && b;j+=2) {
      ans[i][j] = '#';
      b--;
    }
  for(int i=0;i<100 && a;i+=2)
    for(int j=51;j<100 && a;j+=2) {
      ans[i][j] = '.';
      a--;
    }

  for(int i=0;i<100;i++) puts(ans[i]);
}


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

using namespace std;

struct RollingHash {
    using I = long long;
    static constexpr size_t L = 2;
    static constexpr I bs[L] = {1007, 2009};
    static constexpr I ms[L] = {1000000007, 1000000009};

    using T = pair<I, I>;

    vector<I> hs[L], pws[L];

    RollingHash(const string &s) {
        size_t n = s.size();
        for(size_t i=0; i<L; i++) {
            hs[i].assign(n+1, 0);
            pws[i].assign(n+1, 0);
            pws[i][0] = 1;
            for(size_t j=0; j<n; j++) {
                pws[i][j+1] = (pws[i][j]*bs[i]) % ms[i];
                hs[i][j+1] = (hs[i][j]*bs[i] + s[j]) % ms[i];
            }
        }
    }

    // [l, r)
    inline T hash(size_t l, size_t r) const {
        return {
            (((hs[0][r] - hs[0][l] * pws[0][r-l]) % ms[0]) + ms[0]) % ms[0],
            (((hs[1][r] - hs[1][l] * pws[1][r-l]) % ms[1]) + ms[1]) % ms[1],
        };
    }
};
constexpr RollingHash::I RollingHash::bs[];
constexpr RollingHash::I RollingHash::ms[];

int main(void) {
    long n;
    cin >> n;
    string s;
    cin >> s;

    RollingHash rh(s);

    long ok = 0, ng = n;
    while(ng - ok > 1) {
        long m = (ok+ng)/2;

        set<RollingHash::T> ss;
        queue<RollingHash::T> q;
        for(int i=0; i<m; i++)
            q.push(rh.hash(i, i+m));
        for(int i=m; i+m<=n; i++) {
            ss.insert(q.front()); q.pop();
            auto h = rh.hash(i, i+m);
            if(ss.count(h))
                goto ok;
            q.push(h);
        }
        ng = m;
        continue;
ok:
        ok = m;
    }

    cout << ok << endl;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  string S;
  cin >> S;
  int count = 0, intercount = 0;
  rep(i, N) {
    if (S.at(i) == 'a') {
      if (count < A + B) {
        cout << "Yes" << endl;
        count++;
      }
      else cout << "No" << endl;
    }
    else if (S.at(i) == 'b') {
      if (count < A + B && intercount < B) {
        cout << "Yes" << endl;
        count++;
        intercount++;
      }
      else cout << "No" << endl;
    }
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t="CODEFESTIVAL2016";
int ans =0;
cin >> s;
for(int i=0;i<16;i++){
if(s.at(i) != t.at(i)){
ans++;
}
}
cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    static int n,k;
    static String line;
    public static void main(String args[]){

        Scanner s=new Scanner(System.in);
        Integer a= s.nextInt();
        Integer b=s.nextInt();

        if(a.equals(b)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }



    }
}

Measured memory_bytes: 21844
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    int X = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();

    System.out.println((X - A) % B);

  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) {
      return buffer[ptr++];
    } else {
      return -1;
    }
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
}

Measured memory_bytes: 23252
/*
   Created by Rahul Goel.
*/

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;

#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c) (c).begin(), (c).end()
#define pii pair < ll, ll >
#define vi vector < ll >
#define vb vector < bool >
#define vvi vector < vector < ll > >
#define vvb vector < vector < bool > >
#define vpii vector < pair < ll, ll > >
#define vvpii vector < vector < pair < ll, ll > > >
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define min_pq(t) priority_queue < t, vector < t >, greater < t > >
#define max_pq(t) priority_queue < t >
#define pb push_back
#define ff first
#define ss second

ll mod_sum() { return 0ll; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_prod() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }

// --------------------------------------------------------------

vvi adj;
vi vec;

bool compare(int a, int b){
    return vec[a] > vec[b]; 
}

void add_edge(int u, int v){
    adj[u].pb(v);
    adj[v].pb(u);
}

ll solve(){
    int n, m;
    cin >> n >> m;
    vec.resize(n+1);
    adj.resize(n+1);
    for(int i=1; i<=n; i++)
        cin >> vec[i];
    for(int i=0; i<m; i++){
        int u, v;
        cin >> u >> v;
        add_edge(u, v);
    }
    int count = 0;
    for(int i=1; i<=n; i++){
        sort(all(adj[i]), compare);
        if(adj[i].size() == 0)
            count++;
        else if(vec[i] > vec[adj[i][0]])
            count++;
    }
    cout << count << endl;
    return 0;
}

int main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}



Measured memory_bytes: 9796
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

char S[403][403];
P dfs(int x, int y,char c){
	int dx=1,dy=0;
	S[x][y]=0;
	P ret=P(1,0);
	for(int k=0;k<4;swap(dx,dy),k++,dx=-dx){
		int i=dx+x;
		int j=dy+y;
		if(S[i][j]!=0&&S[i][j]!=c){
			P r=dfs(i,j,S[i][j]);
			ret.first+=r.second;
			ret.second+=r.first;
		}
	}
	return ret;
}
int main() {
	int H,W;
	cin >> H >> W;
	for(int i=1;i<=H;i++){
		cin >> (S[i]+1);
	}
	LL ret=0;
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			if(S[i][j]){
				P r=dfs(i,j,S[i][j]);
				ret+=r.first*r.second;
			}
		}
	}
	cout << ret << endl;


	return 0;
}



Measured memory_bytes: 12928
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n=int(input())
    a = set(map(int, input().split()))
    print('YES' if n == len(a) else 'NO')

main()


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

#define N 200000000
#define INF 2000000001

int size;
int h[N];

void swap(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void maxHeapify(i){

  int l = 2*i;
  int r = 2*i+1;
  int valM;

  if(l <= size && h[l] > h[i]) valM = l;
  else valM = i;
  if(r <= size && h[r] > h[valM]) valM = r;
  if(valM != i){
    swap(&h[i], &h[valM]);
    maxHeapify(valM);
  }
}

void hIncreaseKey(int i, int key){
  if(key < h[i]) return;
  h[i] = key;
  while(i>1 && h[i/2]<h[i]){
    swap(&h[i], &h[i/2]);
    i = i/2;
  }
}

void maxHeapInsert(int key){
  size++;
  h[size] = -INF;
  hIncreaseKey(size, key);
}

int heapExtractMax(){
  int valM;
  if(size < 1) return 0;
  valM = h[1];
  h[1] = h[size--];
  maxHeapify(1);
  return valM;
}

int main(){
  char input[20];
  size = 0;
  while(scanf("%s", input)){
    if(!strcmp(input, "end")) break;
    if(!strcmp(input, "extract")) printf("%d\n", heapExtractMax());
    else{
      char val[20];
      scanf("%s", val);
      maxHeapInsert(atoi(val));
    }
  }
  return 0;
}

Measured memory_bytes: 4636
import sys

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


def divisors(n):
    lower = []
    upper = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)

    lower.extend(reversed(upper))
    return lower


def main():
    N = int(readline())

    D = divisors(N)
    D1 = divisors(N - 1)
    ans = len(D1) - 1

    for d in D[1:]:
        n = N
        while n % d == 0:
            n //= d
        if n % d == 1:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 65760
#include<iostream>

using namespace std;


long long pow(long long a,long long b)
{
  long long ans=1;
  for(int i=1;i<=b;i++)
    ans*=a;
  return ans;
}

long long re(long long n,long long x)
{
  if(n==0)
    return 1;
  if(x==1)
    return 0;
  long long half=pow(2,n+1)-1;
  long long all=pow(2,n+2)-3;
  if(x==half)//half
    return pow(2,n);
  else if(x==all)//all
    return pow(2,n+1)-1;
  else if(x<half)
    return re(n-1,x-1);
  else
    return re(n-1,x-half)+pow(2,n);
}

int main(void)
{
  long long n,x;
  cin >> n >> x;

  cout << re(n,x) << endl;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  auto myexec = [&](const auto& vec) -> ll {
    ll ret = 0;
    ll acc = 0;
    for (ll i = 0; i < (ll)vec.size(); i++) {
      if (vec[i] == 0) acc++;
      else ret += acc;
    }
    return ret;
  };

  string s; cin >> s;
  ll n = s.size();
  ll i = 0;
  vector<ll> vec;
  ll ans = 0;
  while (i < n) {
    if (s[i] == 'A') {
      vec.push_back(0);
      i++;
    } else if (s[i] == 'B') {
      if (i+1 < n && s[i+1] == 'C') {
	vec.push_back(1);
	i += 2;
      }else {
	ans += myexec(vec);
	vec.resize(0);
	i++;
      }
    }else if (s[i] == 'C') {
      ans += myexec(vec);
      vec.resize(0);
      i++;
    }else assert(0);
  }
  ans += myexec(vec);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 5532
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

string S;
int K;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> S >> K;
  vector<string> vs;

  rep(i, S.length()) {
    string s = "";
    rep(j, 5) {
      if (i+j >= S.length()) break;
      s += S[i+j];
      vs.pb(s);
    }
  }
  sort(all(vs)); uniq(vs);
  cout << vs[K-1] << "\n";
  return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll a, b, c;
int main() {
	cin >> a >> b >> c;
	REP(k, 1000) {
		ll s[3][3];
		s[0][0] = a;
		s[0][1] = b;
		s[1][1] = c;
		bool ok = true;
		s[0][2] = k;
		ll sum = s[0][0] + s[0][1] + s[0][2];
		s[2][0] = sum - s[1][1] - s[0][2];
		s[2][2] = sum - s[1][1] - s[0][0];
		s[1][0] = sum - s[0][0] - s[2][0];
		if (s[0][1] + s[1][1] == s[2][0] + s[2][2]) s[2][1] = sum - s[0][1] - s[1][1];
		else ok = false;
		if (s[1][1] + s[1][0] == s[0][2] + s[2][2]) s[1][2] = sum - s[0][2] - s[2][2];
		else ok = false;
		if (ok) {
			REP(i, 3) {
				REP(j, 3) {
					if (j != 0)cout << " ";
					cout << s[i][j];
				}
				cout << endl;
			}
		}
	}
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    D = int(input())
    c = [0] + list(map(int, input().split()))
    s = [[0]*27]
    for _ in range(D):
        s.append([0] + list(map(int, input().split())))
    for i in range(1, 366):
        print(s[i].index(max(s[i])))

if __name__ == '__main__':
    main()

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct edge{
    int from, to;
    lint cost;
};

vector<edge> edges;

bool find_negative_loop(int V){
    int E = edges.size();
    vector<lint> dis(V, LLINF);
    dis[0] = 0;
    rep(i, V){
        rep(j, E){
            edge e = edges[j];
            if(dis[e.to] > dis[e.from] + e.cost){
                dis[e.to] = dis[e.from] + e.cost;
                if(i == V - 1){
                    return true;
                }
            }
        }
    }
    return false;
}

int main(){
    int V, E;
    cin >> V >> E;
    rep(i, E){
        edge e;
        cin >> e.from >> e.to;
        e.cost = -1;
        edges.push_back(e);
    }
    if(find_negative_loop(V)){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3172
N,K = list(map(int, input().split()))

#print (N,K)

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

#print (a)

#入力の取得成功

a.sort()

#print (a)

#安い順に並び替え成功

result = 0

for i in range (K):
 result += a[i]

print (result)
 

Measured memory_bytes: 9152
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int n;
	cin >> n;
	ll a[n];
	rep (i, n) cin >> a[i];

	ll ans = 1001001001001001;
	for (int i = -100; i <= 100; i++) {
		ll sum = 0;
		rep (j, n) sum += (a[j] - i) * (a[j] - i);
		chmin(ans, sum);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import bisect as bs

n = int(input())

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
c_l = list(map(int, input().split()))

a_l.sort()
b_l.sort()
c_l.sort()

ans = 0
for b in b_l:
    ans += bs.bisect_left(a_l,b) * (n-bs.bisect_right(c_l,b))
print(ans)


'''
以下の方法だと、N*logN*logN
for i in range(n):
    index_1 = bs.bisect_right(b_l,a_l[i])
    for j in range(index_1,n):
        index_2 = bs.bisect_right(c_l,b_l[j])
        ans += (n-index_2)
print(ans)
'''


Measured memory_bytes: 105568
#include <iostream>
#include <string>

using namespace std;

int main(){
  int a, b;

  cin >> a >> b;

 if (a * b >= a + b && a * b >= a - b){
     cout << a * b << endl;
   } else if (a + b >= a * b && a + b >= a - b) {
     cout << a + b << endl;
   } else {
     cout << a - b << endl;
   }
 
 return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;

vector<int> person[ARRAY_MAX];//人の隣接リスト
vector<int> lang[ARRAY_MAX];//言語の隣接リスト
bool person_used[ARRAY_MAX];//人を使ったかどうか
bool lang_used[ARRAY_MAX];//言語を使ったかどうか

void lang_dfs(int lang_now);
void person_dfs(int person_now);


void person_dfs(int person_now){
    //現在見ている言語を話せる人
    //cout << "person = " << person_now << endl;
    person_used[person_now] = true;

    for(int i = 0;i < person[person_now].size();i++){
        //cout << "i = " << i << endl;
        if(lang_used[person[person_now][i]] == true){
            //既にこの言語は調べられている
            continue;
        }
        lang_dfs(person[person_now][i]);
    }
}

void lang_dfs(int lang_now){
    //現在見ている人が話せる言語
    //cout << "lang = " << lang_now << endl;
    lang_used[lang_now] = true;

    for(int i = 0;i < lang[lang_now].size();i++){
        //cout << "j = " << i << endl;
        if(person_used[lang[lang_now][i]] == true){
            continue;
        }
        person_dfs(lang[lang_now][i]);
    }
}




int main(){

    int n,m;
    cin >> n >> m;

    for(int i = 0;i < n;i++){
        int k;
        cin >> k;
        for(int j = 0;j < k;j++){
            int a;
            cin >> a;
            person[i].push_back(a-1);//人iが話せる言語
            lang[a-1].push_back(i);//言語a-1を話せる人の番号
        }
    }

    person_dfs(0);
    /*for(int i = 0;i < m;i++){//言語で潜る
        if(lang_used[i] == true){
            //既にその言語が調べられているときは調べない
            continue;
        }
        cout << i << endl;
        lang_used[i] = true;
        for(int j = 0;j < lang[i].size();j++){//言語を話せる人
            if(person_used[lang[i][j]] == false){
                //まだこの人を調べていない
                person_dfs(lang[i][j]);
            }
        }
    }*/

    for(int i = 0;i < n;i++){
        if(person_used[i] == false){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 8704
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

int main() {
  unsigned long long n = 0;
  std::cin >> n;
  std::unordered_map<std::string, unsigned long long> map;
  for (unsigned long long i = 0; i < n; ++i) {
    std::string str;
    std::cin >> str;
    std::sort(str.begin(), str.end());
    if (map.find(str) != map.end()) map[str] += 1;
    else map[str] = 1;

  }
  unsigned long long ans = 0;
  std::for_each(map.begin(), map.end(), [&](auto& pair) {
    ans += pair.second * (pair.second - 1) / 2;
  });
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 10660
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

const long mod = 1_000_000_007;

void main(){
	int n = read.to!int;
	int m = read.to!int;
	
	int[] as;
	foreach(i; 0 .. n) as ~= read.to!int;
	
	int[] bs;
	foreach(j; 0 .. m) bs ~= read.to!int;
		
	int[int] aPos, bPos;
	foreach(i; 0 .. n) aPos[as[i]] = i;
	foreach(j; 0 .. m) bPos[bs[j]] = j;
	
	// xを減らしていくとき、その行・列・全体で入れるマスはいくつあるか
	int[] aCounts; // その行にすでに入っている個数
	int[] bCounts; // その列にすでに入っている個数
	int aCount; // 解禁されている行数
	int bCount; // 解禁されている列数
	foreach(i; 0 .. n) aCounts ~= 0;
	foreach(j; 0 .. m) bCounts ~= 0;
	aCount = 0;
	bCount = 0;
	
	long ans = 1;
	foreach_reverse(x; 1 .. n * m + 1){
		if(x in aPos && x in bPos){
			// そこの場所できまり
			ans *= 1;
			// その行および列は新たに解禁された
			aCount += 1;
			bCount += 1;
			// その行および列はあきが減る
			aCounts[aPos[x]] += 1;
			bCounts[bPos[x]] += 1;
		}
		else if(x in aPos && x !in bPos){
			// その行で、解禁済みの列のうち、あきをさがす
			ans *= bCount - aCounts[aPos[x]];
			ans %= mod;
			// その行は新たに解禁された
			aCount += 1;
			// その行はあきが減る
			aCounts[aPos[x]] += 1;
		}
		else if(x !in aPos && x in bPos){
			// その列で、解禁済みの行のうち、あきをさがす
			ans *= aCount - bCounts[bPos[x]];
			ans %= mod;
			// その列は新たに解禁された
			bCount += 1;
			// その列はあきが減る
			bCounts[bPos[x]] += 1;
		}
		else{
			// 全体で、解禁済みの行かつ解禁済みの列のうち、あきをさがす
			ans *= aCount * bCount - (n * m - x);
			ans %= mod;
		}
	}
	
	ans.writeln;
}


Measured memory_bytes: 2556
#include <stdio.h>

int a, b;
int n;

int map[32][32];

int dfs(int y, int x)
{
	int response;

	if (b < y || a < x) {
		response = 0;
	}
	else if (map[y][x] == -1) {
		response = 0;
	}
	else if (y == b && x == a) {
	 response =	1;
	}
	else {
		response = 0;
		
		response += dfs(y + 1, x);
		response += dfs(y, x + 1);
	}

	return (response);
}

int main(void)
{
	int x, y;
	int i, j;
	int ans;

	while (1){
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0) {
			break;
		}

		for (i = 0; i < 32; i++){
			for (j = 0; j < 32; j++){
				map[i][j] = 0;
			}
		}

		scanf("%d", &n);
		for (i = 0; i < n; i++){
			scanf("%d %d", &x, &y);
			map[y][x] = -1;
		}

		ans = dfs(1, 1);

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

	return (0);
}

Measured memory_bytes: 2704
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)

const int kMaxN = 200000;

int n, k, ans = 0;
int c[kMaxN+1] = {};

int main() {
  cin >> n >> k;
  REP(i, n) {
    int tmp;
    cin >> tmp;
    ++c[tmp];
  }

  sort(c, c+n+1);
  REP(i, n+1-k) { ans += c[i]; }

  cout << ans << endl;
  return 0;
}


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

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

vector<pair<i64, int>> factorize(i64 x)
{
    vector<pair<i64, int>> res;
    for (i64 f = 2; f * f <= x; f++)
    {
        if (x % f)
        {
            continue;
        }
        int cnt = 0;
        while (x % f == 0)
        {
            cnt++;
            x /= f;
        }
        res.push_back(make_pair(f, cnt));
    }
    if (x > 1)
    {
        res.push_back(make_pair(x, 1));
    }
    return res;
}

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    i64 n;
    cin >> n;
    auto fs = factorize(n);
    int ans = 0;
    for (auto p : fs)
    {
        int res = p.second;
        for (int i = 1; i <= res; i++)
        {
            res -= i;
            ans++;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
  int a,b,i,ans;cin >> a >> b;ans = 0;
  for(i=0;i<2;i++){
    if(a>b){
      ans += a;
      a -= 1;
    } else {
      ans += b;
      b -= 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import static java.lang.System.*;
import java.util.*;

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

        String s = sc.next();
		
		int max = 0;
		int count = 0;
		for(char c: s.toCharArray()){
			if(c=='A' || c=='C' || c=='G' || c=='T') {
				count++;
				max = Math.max(max, count);
			}
			else count = 0;
		}
		
        out.println(max);
    }
}


Measured memory_bytes: 22484
#include <iostream>

using namespace std;

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

    int min = a[0];
    int in = 0;
    for (int i = 1; i < n; i++)
        if (a[i] < min)
            min = a[i], in = i;

    int ans = 0;
    int i = n;
    while (i > 0)
    {
        i -= k;
        if (i > 0)
            i++;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <iostream>

int main()
{
  int N, K;
  std::cin >> N >> K;

  int ans = 1;
  for (int i = 0; i < N; i++) {
    ans = std::min(ans + K, ans * 2);
  }

  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1000000007;

int coudp[100001];

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A * N, B) << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
constexpr ll mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int n;cin>>n;
    ll a[n];
    rep(i,n) cin>>a[i];
    ll sum = 0;
    for(int i = 0; i < n; ++i) sum += a[i];
    // cout<<sum<<endl;

    ll res = 0;
    rep(i,n) {
        sum -= a[i];
        res += (sum%mod) * a[i];
        res %= mod;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 5156
#include<iostream>
#include<string>
#include<vector>
#include<algorithm> // sort

using namespace std;

void Main()
{
    int N;
    string S;
    cin >> N >> S;

    for (int i = 0; i < S.size(); i++) {
        S[i] += (N % 26);
        if (S[i] > 'Z') S[i] -= 26;
    }
    cout << S << endl;
}

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


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, m, k; cin >> n >> m >> k;
  vll a(n), b(m);
  REP(i, n) {
    cin >> a[i];
  }
  REP(i, m) {
    cin >> b[i];
  }

  vll sua(n+1), sub(m+1);
  REP(i, n) {
    sua[i+1] = sua[i] + a[i];
  }
  REP(i, m) {
    sub[i+1] = sub[i] + b[i];
  }

  int pos = m;
  int ma = 0;
  REP(i, n+1) {
    int now = k - sua[i];
    while(pos >= 0 && now < sub[pos]) {
      pos--;
    }
    if(pos < 0) break;
    chmax(ma, i + pos);
  }
  cout << ma << endl;


}








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

int main()
{
    long long int a,b,sum;
    sum = 0;
    scanf("%lld %lld",&a,&b);
    if(2*a<=b)
    {
        sum += a;
        b = b - a*2;
        sum += b/4;
    }
    else
    {
        sum += b/2;
    }
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
void ABC120(void);
void ABC121(void);
void ABC122(void);
void ABC123(void);
void ABC124(void);
void ABC125(void);
void ABC126(void);
void ABC127(void);
void ABC128(void);
void ABC129(void);

int main(void){
    ABC126();
}

void ABC126(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    s[k-1]=s[k-1]-('A'-'a');
    cout<<s<<endl;
}

Measured memory_bytes: 256
N = int(input())
P = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    P[a].append(b)
    P[b].append(a)

Qb, Qw = [0], [N-1]
dB, dW = [-1 for i in range(N)], [-1 for i in range(N)]
dB[0], dW[N-1] = 0, 0
while Qb:
    temp = Qb.pop(0)
    for n in P[temp]:
        if dB[n] == -1:
            dB[n] = dB[temp] + 1
            Qb.append(n)
while Qw:
    temp = Qw.pop(0)
    for n in P[temp]:
        if dW[n] == -1:
            dW[n] = dW[temp] + 1
            Qw.append(n)

B, W = 0, 0
for i in range(N):
    if dB[i] <= dW[i]:
        B += 1
    else:
        W += 1
print("Fennec" if B > W else "Snuke")

Measured memory_bytes: 29140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<int, int> mp;
  rep(i, 3) {
    int a;
    cin >> a;
    mp[a]++;
  }
  if (mp.size() == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<int, int> P;

vector<int> E[200];

P far_v(int pre, int cur){
	P p;
	p.first = -1;
	p.second = cur;
	for(int i = 0; i < E[cur].size(); i++){
		if(E[cur][i] != pre){
			P p1 = far_v(cur, E[cur][i]);
			if(p1.first > p.first){
				p.first = p1.first;
				p.second = p1.second;
			}
		}
	}
	p.first++;
	return p;
}

void dist_v(int dist, int pre, int cur, int d[]){
	d[cur] = dist;
	for(int i = 0; i < E[cur].size(); i++){
		if(E[cur][i] != pre){
			dist_v(dist + 1, cur, E[cur][i], d);
		}
	}
}

int main(){
	
	int N;
	cin >> N;
	
	for(int i = 0; i < N - 1; i++){
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	
	P p = far_v(-1, 0);
	int Ru1 = p.second;
	p = far_v(-1, Ru1);
	int D = p.first;
	int Ru2 = p.second;
	
	int d1[200] = {};
	int d2[200] = {};
	
	dist_v(0, -1, Ru1, d1);
	dist_v(0, -1, Ru2, d2);
	
	int cent;
	vector<int> u_can;
	if(D % 2 == 0){
		for(int i = 0; i < N; i++){
			if(d1[i] + d2[i] == D && d1[i] == d2[i]){
				cent = i;
			}
		}
		u_can.push_back(cent);
		for(int i = 0; i < E[cent].size(); i++){
			u_can.push_back(E[cent][i]);
		}
	}else{
		for(int i = 0; i < N; i++){
			if(d1[i] + d2[i] == D && (d1[i] - d2[i]) * (d1[i] - d2[i]) == 1){
				u_can.push_back(i);
			}
		}
		
		cent = u_can[1];
		u_can.pop_back();
	}
	
	long long int ans = 1000000000000000000LL;
	for(int loop = 0; loop < u_can.size(); loop++){
		int v2 = u_can[loop];
		
		int du[200] = {};
		int dv[200] = {};
		
		dist_v(0, -1, cent, du);
		dist_v(0, -1, v2, dv);
		
		vector<int> v_dist[200];
		for(int i = 0; i < N; i++){
			int ret = min(du[i], dv[i]);
			v_dist[ret].push_back(i);
		}
		
		long long int cnt = 1;
		for(int i = 0; i < N; i++){
			long long int maxi = 2;
			//cout << i << " ";
			for(int j = 0; j < v_dist[i].size(); j++){
				//cout << v_dist[i][j] << " ";
				maxi = max(maxi, (long long int)E[v_dist[i][j]].size());
			}
			//cout << endl;
			if(cent != v2 || i != 0){
				maxi--;
			}
			cnt *= maxi;
		}
		if(cent != v2){
			cnt *= 2;
		}
		ans = min(ans, cnt);
	}
	cout << D / 2 + 1 << " " << ans << endl;
	
	return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807


int h,w,c[10][10],a,ans;

signed main() {
    cin >> h >> w;
    rep(i,10) rep(j,10) cin >> c[i][j];
    rep(k,10) rep(i,10) rep(j,10) c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
    rep(i,h) rep(j,w) {
        cin >> a;
        if (a>=0) ans += c[a][1];
    }
    cout << ans << endl;
}


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

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

    int maxlength = 0;
    int length = 0;
    rep(i,n) {
        int dist;
        if(i!=n-1)
            dist = a[i+1] - a[i];
        else
            dist = a[0] - a[i] + k;
        maxlength = max(maxlength,dist);
        length += dist;
    }

    cout << length - maxlength << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
typedef long long int ll;
int main()
{
 ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll k;
  cin>>k;
  string a;
  for(ll i=0;i<k;i++)
    a+="ACL";
  cout<<a<<"\n";
  return 0;
}  

Measured memory_bytes: 3008
#include <cstdio>

int main(int argc, const char * argv[]) {
    
    int a,b,c,d;
    
    scanf("%d %d %d %d",&a,&b,&c,&d);
    
    if(a>b) a=b;
    if(c>d) c=d;
    
    printf("%d\n",a+c);
    
    return 0;
}


Measured memory_bytes: 128
#include<string.h>
#include<stdio.h>
int main(){
        int n,m,x,y,pos[22][22];
        int i,j,a,b,c,cnt;
        int l;
        char d[2];
        while(1){
                scanf("%d",&n);
                if(n==0)break;
                memset(pos,0,sizeof(pos));
                cnt=0;
                for(i=0;i<n;i++){
                        scanf("%d %d",&a,&b);
                        pos[a][b]=1;
                }
                x=10;
                y=10;
                scanf("%d",&m);
                for(i=0;i<m;i++){
                        scanf("%s%d",d,&l);
                        for(j=0;j<l;j++){
                                if(d[0]=='N'){
                                        y++;
                                }else if(d[0]=='E'){
                                        x++;
                                }else if(d[0]=='S'){
                                        y--;
                                }else if(d[0]=='W'){
                                        x--;
                                }
                                if(pos[x][y]==1){
                                        cnt++;
                                        pos[x][y]=0;
                                }
                        }
                }
                if(cnt==n){
                        printf("Yes\n");
                }else{
                        printf("No\n");
                }
        }
        return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
  int N;
  cin >> N;
  vector<int> B(N - 1);
  for (int i = 0; i < N - 1; i++)
  {
    cin >> B[i];
  }
  int ans = B[0];
  for (int i = 1; i < N - 1; i++)
  {
    ans += min(B[i], B[i - 1]);
  }
  ans += B[N - 2];
  cout << ans << endl;
  return 0;
}

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

ll a[200000];

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i=0; i<n; ++i)cin >> a[i];
    ll l=1, r=1e9;
    while(l+1<r){
        ll m = (l+r)/2;
        ll logs_cnt = 0;
        for(int i=0; i<n; ++i) logs_cnt += (a[i] + m - 1) / m;
        if (logs_cnt <= n+k){
            r=m;
        }else{
            l=m;
        }
    }
    ll logs_cnt = 0;
    for(int i=0; i<n; ++i) logs_cnt += (a[i] + l - 1) / l;
    if(logs_cnt <= n+k){
        cout << l << endl;
    }else{
        cout << r << endl;
    }
    return 0;
}


Measured memory_bytes: 5184
N = int(input())
A = [int(s) for s in input().split(' ')]
B = [int(s) for s in input().split(' ')]
C = [int(s) for s in input().split(' ')]
ret = 0
prev = -1
for i in range(N):
    ii = A[i] - 1
    ret += B[ii]
    if prev > -1:
        if prev + 1 == ii:
            ret += C[prev]
    prev = ii
print(ret)


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

//int tri[5010][5010];
vector<int> tri[5010];
int main()
{
	for (int i = 0; i < 5010; i++){
		tri[i].reserve(i + 1);
		for (int j = 0; j <= i; j++){
			tri[i][j] = 0;
		}
	}
	
	int n, m;
	scanf("%d %d", &n, &m);
	
	for (int i = 0; i < m; i++){
		int a, b, x;
		scanf("%d %d %d", &a, &b, &x);
		a++;
		
		tri[a][b]++;
		tri[a][b + 1]--;
		tri[a + x + 1][b]--;
		tri[a + x + 2][b + 1]++;
		tri[a + x + 1][b + x + 2]++;
		tri[a + x + 2][b + x + 2]--;
	}
	
	for (int i = 0; i <= n + 3; i++){
		for (int j = 0; j <= i; j++){
			//printf("%d ", tri[i][j]);
		}
		//puts("");
	}
	
	for (int i = 0; i <= n + 3; i++){
		for (int j = 1; j <= i; j++){
			tri[i][j] += tri[i][j - 1];
		}
	}
	for (int i = 1; i <= n + 3; i++){
		for (int j = 1; j <= i - 1; j++){
			tri[i][j] += tri[i - 1][j];
		}
	}
	for (int i = 1; i <= n + 3; i++){
		for (int j = 1; j <= i; j++){
			tri[i][j] += tri[i - 1][j - 1];
		}
	}
	
	int cnt = 0;
	for (int i = 2; i <= n + 1; i++){
		for (int j = 1; j <= i - 1; j++){
			cnt += !!tri[i][j];
			//printf("%d ", tri[i][j]);
		}
		//puts("");
	}
	printf("%d\n", cnt);
	
	return 0;
}

Measured memory_bytes: 50372
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<bits/stdc++.h>
#define N 1000000007
#include<iostream>
#include<algorithm>
#define IO ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static int min=100000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] p=new int[5];
		p[0]=sc.nextInt();
		p[1]=sc.nextInt();
		p[2]=sc.nextInt();
		p[3]=sc.nextInt();
		p[4]=sc.nextInt();
		sc.close();
		String key="01234";
		permutation(key,"",p);
		System.out.println(min);
	}

	public static void permutation(String q, String ans,int[] p){
		if(q.length() <= 1) {
			char[] ch=(ans+q).toCharArray();
			int val=0;
			for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			}
			min=Math.min(min, val);
		} else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			}
		}
	}
}

Measured memory_bytes: 23380
#include <iostream>
using namespace std;
typedef unsigned long ulong;

ulong factorial(int n){
	ulong s = 1;
	while (n){
		s *= n--;
	}
	return s;
}

int main(void){
	int n;
	cin>>n;
	cout<<factorial(n)<<endl;
	return 0;
}

Measured memory_bytes: 1156
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int total = a + b + c;

    int maxNum = a;
    maxNum = max(maxNum, b);
    maxNum = max(maxNum, c);

    cout << total - maxNum << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;

priority_queue<ll> q;
int a[1234567];
int main() {
	int n,x = 1000000000,y;
	cin >> n;
	for (int i = 0; i < n; i++) scanf("%d",&a[i]);
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
			y = __gcd(a[i], a[0]);
			x = min(x, y);
			if (x == 1) {
				puts("1");
				return 0;
		}
	}
	
	printf("%d\n", x);
	return 0;
}



Measured memory_bytes: 640