akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

#define kais 4
using namespace std;


typedef struct{
  int f,b,t,u,r,l;
}_sai;

_sai s;
_sai s2;

bool tate=false,yoko=false,front=false,top=false,right=false,left=false,under=false,back=false,final=false;

void dice(_sai* tmp,char muki){
  int b1=(*tmp).f,b2=(*tmp).b,b3=(*tmp).t,b4=(*tmp).u,b5=(*tmp).r,b6=(*tmp).l;
  if(muki=='S'){
    (*tmp).u=b1;
    (*tmp).f=b3;
    (*tmp).t=b2;
    (*tmp).b=b4;
  }
  else if(muki=='N'){
    (*tmp).t=b1;
    (*tmp).b=b3;
    (*tmp).u=b2;
    (*tmp).f=b4;
  }
  else if(muki=='E'){
    (*tmp).r=b3;
    (*tmp).u=b5;
    (*tmp).l=b4;
    (*tmp).t=b6;
  }
  else if(muki=='W'){
    (*tmp).l=b3;
    (*tmp).u=b6;
    (*tmp).r=b4;
    (*tmp).t=b5;
  }
}

void judge(){

  if(s.r==s2.r){
     if(s.l==s2.l){
       if(s.u==s2.u){
	 if(s.b==s2.b){
	   final=true;
	 }	 
       }
     }
  }
  if(final){
    if(!tate){
      final=false;
    }
    if(!yoko){
      final=false;
    }
  } 
}

void roll(){

  for(int i=0; i<kais; i++){
    if(s.f==s2.f){
      tate=true;
      break;
    }
    dice(&s,'S');
  }
  
  if(!tate){
    dice(&s,'E');
    for(int i=0; i<kais; i++){
      if(s.f==s2.f){
	tate=true;
	break;
      }
      dice(&s,'S');
    }
  }
  
  for(int i=0; i<kais; i++){
    if(s.t==s2.t){
      yoko=true;
      break;
    }
    dice(&s,'W');
  }

  judge();
}

int main(){

  
  cin>> s.t>> s.f>> s.r>> s.l>> s.b>> s.u;
  cin>> s2.t>> s2.f>> s2.r>> s2.l>> s2.b>> s2.u;

  roll();

  if(final){
    cout <<"Yes"<<endl;
  }
  else {
    cout <<"No"<<endl;
  }
  


  return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define ll long long
#define MAX 5000005
using namespace std;


int n, cnt[MAX][5];
char s[MAX];

int main()
{
    cin >> n;
    scanf("%s", s+1);
    for(int i = 1; i <= n; i++){
        cnt[i][1] = cnt[i-1][1];
        cnt[i][2] = cnt[i-1][2];
        cnt[i][3] = cnt[i-1][3];
        if(s[i] == 'R') s[i] = 1, cnt[i][1]++;
        else if(s[i] == 'G') s[i] = 2, cnt[i][2]++;
        else s[i] = 3, cnt[i][3]++;
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = i+2; j <= n; j++){
            if(s[i] == s[j]) continue;
            char c = 6-s[i]-s[j];
            ans += cnt[j-1][c]-cnt[i][c];
            if(((i+j)%2==0) && s[(i+j)/2] == c) ans--;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if(k<=x/d) cout<<x-k*d<<endl;
    else{
        if((k-x/d)%2) cout<<d-x%d<<endl;
        else cout<<x%d<<endl;
    }
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b)
		cout << c << endl;
	else if(a == c)
		cout << b << endl;
	else
		cout << a << endl; 
	return 0;
}


Measured memory_bytes: 256
# ABC090 D - Remainder Reminder
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,k=nm()
ans=0

if k==0:
    print(n**2)
    exit()

for i in range(k+1,n+1):
    ans+=(n//i)*(i-k)
    if n%i>=k:
        ans+=n%i-k+1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//
//-------------------関数----------------------//

int main() {
  ll n;
  cin >> n;
  ll a[114514];
  ll cnt = 0;
  REP(i, n) {
    ll b;
    cin >> b;
    if (b > 100000) {
      cnt++;
    } else {
      a[b]++;
    }
  }
  REP(i, 100000) {
    if (a[i] >= i) {
      cnt += a[i] - i;
    } else {
      cnt += a[i];
    }
  }
  cout << cnt << endl;
}


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

int main() {
	string S, T;
	cin >> S >> T;
	int result = 1000000;
	rep(i, S.size()-T.size()+1) {
		int sum = T.size();
		string substr=S.substr(i, T.size());
		rep(j, T.size()) {
			if (substr.at(j) == T.at(j)) {
				sum -= 1;
			}
		}

		result=min(sum, result);
	}
	cout << result << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007

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

    // input
    int N, M;
    cin >> N >> M;
    vector<string> vec_A(N), vec_B(M);
    REP(i, N) cin >> vec_A.at(i);
    REP(i, M) cin >> vec_B.at(i);
    
    // calculation
    if (N == M) {
        REP(i, N) {
            if (vec_A[i] != vec_B[i]) {
                cout << "No" << "\n";
                return 0;
            }
        }
        cout << "Yes" << "\n";
        return 0;
        
    } else {
        string tmp;
        int sum;
        REP(i, N-M+1) {
            REP(j, N-M+1) {
                sum = 0;
                REP(k, M) {
                    tmp = vec_A[i+k].substr(j, M);
                    if (tmp == vec_B[k]) {
                        sum++;
                    } else {
                        break;
                    }
                }
                
                if (sum == M) {
                    cout << "Yes" << "\n";
                    return 0;
                }
            }
        }
        cout << "No" << "\n";
        
        return 0;
    }
}


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

typedef long long int ll;

ll findDivisors(ll n)
{
    //vector<int> v;
    // Array to store the count
    // of divisors
    ll div[n + 1];
    memset(div, 0, sizeof div);

    ll ans = 0;

    // For every number from 1 to n
    for (ll i = 1; i <= n; i++) {

        // Increase divisors count for
        // every number divisible by i
        for (ll j = 1; j * i <= n; j++){
            div[i * j]++;
            //ans += i * div[i * j - 1];
        }
    }

        for(ll i = 1; i <= n; i++){
            ans += i * div[i];
        }

    return ans;
}

int main() {

    //freopen ("in.txt","r",stdin);
    //freopen ("out.txt","w",stdout);

	ll n;
	cin >> n;

	cout << findDivisors(n) << "\n";
	return 0;
}


Measured memory_bytes: 81668
def cut_kouho(s, char):
    ret = []
    for i in range(s.count(char)):
        ind = s.find(char)
        ret.append(s[ind:])
        if ind == len(s) -1 :
            break
        s = s[ind+1:]
    #print(ret)
    return ret

s = input()
k = int(input())

if len(s) < 51 and False:
    tmp = []
    for i in range(len(s)):
        for j in range(i,len(s)):
            tmp.append(s[i:j+1])
    a = list(set(tmp))
    a.sort()
    print(a[k-1])
else:
    char = list(set(list(s)))
    char.sort()
    #print(char)
    nokori = k
    for c in char:
        kouho = cut_kouho(s, c)
        # k文字まで減らしていい
        kouho = [i[:min(nokori, len(i))] for i in kouho]
        # 全探索
        #print(kouho)
        tmp = []
        for string in kouho:
            for i in range(len(string)):
                tmp.append(string[:i+1])
        a = list(set(tmp))
        a.sort()
        #print(a)
        if len(a) >= nokori:
            print(a[nokori-1])
            exit()
        else:
            nokori -= len(a)

Measured memory_bytes: 16624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    long long Q,H,S,D,N;
    cin >> Q >> H >> S >> D >> N;
    H=min(H,2*Q);
    S=min(S,2*H);
    D=min(D,S*2);

    cout << D*(N/2)+(N%2)*S << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <limits>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repd(i,a) for(ll i=(a);i>=0;--i)
#define all(a) (a).begin(), (a).end()

using ll = long long;

const ll MAX_K = 100000, INF = 1e18;

ll K;
ll A[MAX_K];

ll C( ll mid )
{
  rep( i, K )
    mid = (mid / A[i]) * A[i];

  return mid;
}

int main()
{
  scanf( "%lld", &K );
  rep( i, K )
    scanf( "%lld", A+i );

  ll ma = -1, mi = -1;
  ll lb = 2, ub = INF;
  while( lb < ub )
  {
    ll mid = lb+ub>>1;

    if( C(mid) >= 2 )
      ub = mid;
    else
      lb = mid+1;
  }

  if( C(lb) == 2 )
    mi = lb;

  lb = 2, ub = INF;
  while( lb < ub )
  {
    ll mid = (lb+ub+1)>>1;

    if( C(mid) > 2 )
      ub = mid-1;
    else
      lb = mid;
  }

  if( C(lb) == 2 )
    ma = lb;

  if( mi == -1 )
    puts( "-1" );
  else
    printf( "%lld %lld\n", mi, ma );

  return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
    long long n,a[100][2],i,j,k,ans;
    cin>>n;
    for (i = 0; i < 100; i++) for (j = 0; j < 2; j++) a[i][j]=0;
    j=0;
    ans=0;
    while (n>1)
    {
        for (i = 2; i < n; i++)
        {
            if (pow(i,2)>n)
            {
                a[j][0]=i;
                j++;
                a[j-1][1]++;
                n=1;
            }
            else if (n%i==0)
            {
                a[j][0]=i;
                j++;
                while (n%i==0)
                {
                    n/=i;
                    a[j-1][1]++;
                }
            }
        }
    }
    for (i = 0; i < j; i++)
    {
        k=1;
        while (a[i][1]>0)
        {
            a[i][1]-=k;
            if (a[i][1]>=0) k++;
        }
        ans=ans+k-1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  string a;
  cin>>A>>B>>C>>D;
  if(A+B>C+D) a="Left";
  else if(A+B<C+D) a="Right";
  else a="Balanced";
  cout<<a<<endl;
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
#include "tuple"

#define rep(n) for (int i = 0; i < n; ++i)
#define REP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define intinf 1000000000
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define P pair<ll, ll>
typedef long long ll;
using namespace std;

string n;

int main() {
	cin >> n;
	rep(3) {
		if (n[i] == '9')n[i] = '1';
		else if (n[i] == '1')n[i] = '9';
	}
	cout << n << endl;
}

Measured memory_bytes: 256
//I solved it before. If I had enough time I wouldn't have submitted old codes.
//If you forbid I won't do this in the upcoming contests
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
#include <limits.h>
#include <bits/stdc++.h>
#define fw(x) freopen("x.txt","w",stdout)
#define For(i,a,b,c) for(int i = a;i < b;i+=c)
#define REP(i,n) for(int i = 0;i < n;++i)
#define REP1(i,n) for(int i = 1; i<=n;i++)
#define mem(a,s) memset(a,s,sizeof a)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x)  cout<<#x"="<<(x)<<endl
#define pb push_back


using namespace std;


// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/


//big_mod

//ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}

const int mod = 1000000007;
ll qpow(ll n,ll k)
{
    ll ans=1;
    assert(k>=0);
    n%=mod;
    while(k>0)
    {
        if(k&1)
            ans=(ans*n)%mod;
        n=(n*n)%mod;
        k>>=1;
    }
    return ans%mod;
}
int ar[100009];
int cost[100009];
void run(int i, int n, int k){
    if(i>=n) return;
    if(cost[i]== -1 ){
        REP1(j, k){
            if(i+j < n ){
                if(cost[i+j] == -1 ) run(i+j, n, k);
            }
            else break;
        }
    }
    int mn = INT_MAX;
    REP1(j, k){
        if(i+j <= n){
            int c1 = cost[i+j] + abs(ar[i]-ar[i+j]);
            if(mn>c1) mn=c1;
        }
        else break;
    }
    cost[i] = mn;
}
int main()
{
    fast;
    int n, k, v;
    cin>>n>>k;
    REP1(i, n){
        cin>>v;
        cost[i]= -1;
        ar[i] = v;
    }
    cost[n]=0;
    run(1, n, k);
    cout<<cost[1]<<'\n';
    return 0;
}

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

map<int, int> factorization(int x){
    map<int, int> pn;
    for (int i=2; i*i<=x; i++)
    {
        while (x % i == 0) { x/=i; pn[i]++; }
    }
    if (x != 1) pn[x]++;
    return pn;
}

void Main()
{
    int n;
    cin >> n;
    int M = 1000000;
    vector<int> sum(M+1);
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        for (auto j: factorization(a)) {
            sum[j.first]++;
        }
    }
    
    int maxsum = 0;
    for (int i = 0; i < sum.size(); i++)
    {
        maxsum = max(maxsum, sum[i]);
    }
    
    if (maxsum <= 1)
        cout << "pairwise coprime" << endl;
    else if (maxsum <= n-1)
        cout << "setwise coprime" << endl;
    else
        cout << "not coprime" << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 7152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl t(n), l(n + 2), r(n + 2), v(n + 2);
  ll now = 0;
  rep(i, n) {
    cin >> t[i];
    l[i] = now;
    now += t[i];
    r[i] = now;
  }
  l[n] = now;
  r[n] = now;
  v[n] = l[n + 1] = r[n + 1] = v[n + 1] = 0;
  rep(i, n) cin >> v[i];
  ll m = now * 2 + 1;
  vd s(m, 1e18);
  rep(i, m) rep(j, n + 2) {
    double now;
    if(i < 2 * l[j])
      now = -double(i) / 2.0 + double(l[j]) + double(v[j]);
    else if(i > 2 * r[j])
      now = double(i) / 2.0 - double(r[j]) + double(v[j]);
    else
      now = double(v[j]);
    s[i] = min(s[i], now);
  }
  double ans = 0;
  rep(i, m - 1) ans += (s[i] + s[i + 1]) / 4.0;
  printf("%.15f\n", ans);
}

Measured memory_bytes: 3792
directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
 
 
def main():
    H, W = map(int, input().split())
    s = [input() for _ in range(H)]
    path = [[float("inf")] * W for _ in range(H)]
    white = sum([len(row.replace("#", "")) for row in s])
    scan = [(0, 0, 1)]  # i, j, cost
    while len(scan):
        i, j, cost = scan.pop(0)
        if cost >= path[i][j]:
            continue
        path[i][j] = cost
        for d in directions:
            nexti = i + d[0]
            nextj = j + d[1]
            if 0 <= nexti and nexti < H and \
               0 <= nextj and nextj < W and \
               s[nexti][nextj] == ".":
                scan.append((nexti, nextj, cost + 1))
    if path[H-1][W-1] == float("inf"):
        print(-1)
    else:
        print(white - path[H-1][W-1])
 
 
if __name__ == "__main__":
    main()


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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,m,q;
  cin>>n>>m>>q;
  vector<Int> a(q);
  for(Int i=0;i<q;i++) cin>>a[i];
  vector<Int> d(m,0);
  for(Int i=0;i<q;i++) d[a[i]]=1;

  Int w=7,h=(m%7?m:m/7);
  Int dy[]={0,0,1,-1};
  Int dx[]={1,-1,0,0};
  auto in=[&](Int y,Int x){return 0<=y&&y<h&&0<=x&&x<w;};

  auto dp=make_v<Int>(h,w);
  fill_v(dp,-1);

  auto idx=[&](Int y,Int x){return (y*w+x)%m;};
  
  auto bfs=
    [&](Int y,Int x,Int p){
      using P = pair<Int, Int>;
      queue<P> q;
      dp[y][x]=p;
      q.emplace(y,x);
      while(!q.empty()){
	tie(y,x)=q.front();q.pop();
	for(Int k=0;k<4;k++){
	  Int ny=y+dy[k],nx=x+dx[k];
	  if(!in(ny,nx)||d[idx(ny,nx)]||~dp[ny][nx]) continue;
	  dp[ny][nx]=p;
	  q.emplace(ny,nx);
	}
      }
    };

  Int cnt=0;
  for(Int i=0;i<h;i++)
    for(Int j=0;j<w;j++)
      if(!d[idx(i,j)]&&!~dp[i][j])
	bfs(i,j,cnt++);
  
  Int ans=cnt;
  Int num=n/h-1;
  UnionFind uf(cnt*2);
  for(Int j=0;j<w;j++)
    if(~dp[0][j]&&~dp[h-1][j])
      uf.unite(dp[0][j],cnt+dp[h-1][j]);
  
  Int dif=-cnt;
  for(Int i=0;i<cnt*2;i++)
    if(uf.find(i)==i) dif++;
  
  ans+=dif*num;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  string S;
  cin>>N>>S;
  
  
  for(int i=0;i<S.size();i++){
    S[i]=(S[i]-'A'+N)%26+'A';
  }
  
  
  cout<<S<<endl;
}
    

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

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
bool hikaku(vector<int> const& a,vector<int> const& b,int n){
  int ans=0;
  rep(i,n){
    if(a[i]!=b[i])ans++;
  }
  return ans==0;
}

signed main(){
  int n;cin>>n;
  vector<int> p(n);
  vector<int> q(n);
  vector<int> array;
  rep(i,n)array.push_back(i+1);
  rep(i,n)cin>>p[i];
  rep(i,n)cin>>q[i];
  int count=0;
  int qn,pn;
  do{
    count++;
    if(hikaku(p,array,n)){
      pn=count;
    }
    if(hikaku(q,array,n)){
      qn=count;
    }
  }while(next_permutation(array.begin(),array.end()));
  int ans=max(pn-qn,qn-pn);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

const int L =   1'000;
const int K = 500'000 / L;
int A1[L], B1[L], am, bm, ac, bc, mi, sum;
pair<int, int> A2[K], B2[K];
int main() {
	until(getchar_unlocked() == '\n') { }
	while(true) {
		char c = getchar_unlocked();
		if(c == '(' || c == ')') {
			sum += (c == '(' ? +1 : -1);
			setmin(mi, sum);
		} else {
			int a = -mi, b = sum - mi;
			if(a <= b) { if(a < L) { A1[a] += sum; setmax(am, a + 1); } else { A2[ac++] = { a, sum }; } }
			else       { if(b < L) { B1[b] += sum; setmax(bm, b + 1); } else { B2[bc++] = { b, sum }; } }
			mi = 0, sum = 0;
			if(c == EOF) { break; }
		}
	}
	sort(A2, A2 + ac);
	sort(B2, B2 + bc);
	inc(i, am) {
		setmin(mi, sum - i);
		sum += A1[i];
	}
	inc(z, ac) { auto [i, Ai] = A2[z];
		setmin(mi, sum - i);
		sum += Ai;
	}
	dec(z, bc) { auto [i, Bi] = B2[z];
		sum += Bi;
		setmin(mi, sum - i);
	}
	dec(i, bm) {
		sum += B1[i];
		setmin(mi, sum - i);
	}
	puts(mi >= 0 && sum == 0 ? "Yes" : "No");
}


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

int main(void) {
  int n;
  stack<int> s;
  
  cin >> n;
  s.push(n);
  
  while(cin >> n) {
    if(n == 0) { n = s.top(); s.pop(); cout << n << endl; }
    else s.push(n);
  }
  
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1)
#define io  ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;
int main(){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        if(c%b!=0)
                c=c/b +1;
        else c=c/b;
        if(a%d!=0)
            a=a/d+1;
        else a=a/d;
        if(a<c)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;



return 0;
}


Measured memory_bytes: 3592
N = map(int, list(raw_input()))

if N[0] > N[1]:
    l = [N[0]] * 3
    print(''.join([str(i) for i in l]))
elif N[0] == N[1] >= N[2]:
    l = [N[0]] * 3
    print(''.join([str(i) for i in l]))
elif N[0] == N[1] < N[2]:
    l = [N[0]+1] * 3
    print(''.join([str(i) for i in l]))
elif N[0] < N[1]:
    l = [N[0]+1] * 3
    print(''.join([str(i) for i in l]))




Measured memory_bytes: 2692
# -*- coding: utf-8 -*-
N=int(input())
A=list(map(int,input().split()))
Alist=[]
for i in range(N):
    Alist.append((i+1,A[i]))
Alist.sort(key=lambda x:x[1])
ans=[str(i[0]) for i in Alist]
ans=" ".join(ans)
print(ans)

Measured memory_bytes: 24932
#include<stdio.h>
int main (void){
int r,g,b,a;
scanf("%d",&r);
scanf("%d",&g);
scanf("%d",&b);
a=r*100+g*10+b;
if(a%4==0){
printf("YES\n");}
else{printf("NO\n");
}
return 0;
}


Measured memory_bytes: 128
s = list(input())

for i in range(1<<3):
    form = ""
    for j in range(3):
        form += s[j]
        if i & 1<<j:
            form += "+"
        else:
            form += "-"
    form += s[-1]
    if eval(form) == 7:
        print(form + "=7")
        exit()


Measured memory_bytes: 9108
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int A = sc.nextInt();
    int B = sc.nextInt();

    sc.close();

    int count = 0;

    for (int i = A; i <=B; i++){
      String s = String.valueOf(i);
      String[] arr = s.split("");
      if (arr[0].equals(arr[4]) && arr[1].equals(arr[3])){
        count++;
      }
    }

    System.out.println(count);
 
  }

}

Measured memory_bytes: 61908
#include <stdio.h>

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

    int i = 0;
    double height = 0.0000;
    double small = 0.0000, big = 0.0000;
    
    while (scanf("%lf",&height) != EOF) {
        if (i == 0) small = height;
        if (small > height) small = height;
        //printf("%f\n",small);
        if (big < height) big = height;
        //printf("%f\n",big);
        i++;
    }
       printf("%f\n",(big - small));
    return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <set>
using namespace std;
int main()
{
  int a,b,c;
  set<int> s;
  cin >> a >> b >> c;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  if (s.size()==2){
  	cout << "Yes";
  }
  else cout << "No";
}

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

int H, W;
string s[110];
int cnt[26];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> s[i];
    for (int j = 0; j < W; j++) {
      cnt[s[i][j] - 'a']++;
    }
  }
  int a = 0, b = 0, c = 0;
  for (int i = 0; i < 26; i++) {
    a += cnt[i]/4;
    b += cnt[i]%4/2;
    c += cnt[i]%2;
  }
  int four = (H/2) * (W/2);
  int one = (H%2) * (W%2);
  int two = (H*W - four*4 - one)/2;
  if (a < four) {
    cout << "No" << endl;
    return 0;
  }
  a -= four;
  b += a*2;
  if (b < two) {
    cout << "No" << endl;
    return 0;
  }
  if (c < one) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
#define pi 3.1415926535897
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int a,b,c;
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	in(a);in(b);in(c);
	printf("%d %d %d\n",c,a,b);
	return 0;
}

Measured memory_bytes: 3676
N,K=map(x->parse(Int,x),split(readline()))
A=map(x->parse(Int,x),split(readline()))
now=0
for a=A
	now+=a$K
end
ans=now
i=0
while K>0
	c=0
	for a=A
		c+=(a>>i)%2
    end
	if K%2==1
		ans=max(ans,now+(1<<i)*(2c-N))
		now+=(1<<i)*max(0,2c-N)
	else
		now+=(1<<i)*max(0,N-2c)
	end
	i+=1
	K>>=1
end
println(ans)


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

using namespace std;

int main() {
    long long x = 0;
    cin >> x;

    for(long long i = -120 ; i <= 120 ; i++){
        for(long long j = -120;j <= 120 ; j++){
            long long I = i * i * i * i * i;
            long long J = j * j * j * j * j;
            if(I - J == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3596
#include<cstdio>
const int MaxN=200010;
int N,p[MaxN],deg[MaxN],stk[MaxN];
struct edge{int to;edge*next;}E[MaxN],*fir[MaxN];
bool vis[MaxN];
int f[MaxN][2],cir[MaxN],len,nxt[MaxN*2];
int dfn[MaxN*2],now=1;
void work(){
	
	for(int i=1;i<=N;i++){
		scanf("%d",p+i);
		deg[p[i]]++;
		E[i]=(edge){i,fir[p[i]]};
		fir[p[i]]=E+i;
	}
	int*tp=stk;
	for(int i=1;i<=N;i++)if(!deg[i])*tp++=i;
	while(tp>stk){
		int x=*--tp;
		for(edge*e=fir[x];e;e=e->next)vis[*f[e->to]]=1;
		while(vis[*f[x]])++*f[x];
		for(edge*e=fir[x];e;e=e->next)vis[*f[e->to]]=0;
		if(!--deg[p[x]])*tp++=p[x];
	}
	int o=0;
	for(int i=1;!o;i++)if(deg[i])o=i;
	for(int i=o;;){
		cir[len++]=i;
		for(edge*e=fir[i];e;e=e->next)if(!deg[e->to])vis[*f[e->to]]=1;
		while(vis[*f[i]])++*f[i];
		for(f[i][1]=*f[i]+1;vis[f[i][1]];++f[i][1]);
		for(edge*e=fir[i];e;e=e->next)if(!deg[e->to])vis[*f[e->to]]=0;
		if((i=p[i])==o)break;
	}
	for(int i=0;i<len;i++){
		nxt[i]=(i+1)%len+(f[cir[i]][0]==f[cir[(i+1)%len]][0])*len;
		nxt[i+len]=(i+1)%len+(f[cir[i]][1]==f[cir[(i+1)%len]][0])*len;
	}
	for(int i=0;i<len;i++){
		int la=now,x=i,mv=now;
		while(!dfn[x]){
			dfn[x]=now++;
			if(x<len)mv=dfn[x];
			x=nxt[x];
		}
		if(dfn[x]>=la&&now-dfn[x]==len&&mv>=dfn[x]){
			puts("POSSIBLE");
			return;
		}
	}
	puts("IMPOSSIBLE");
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while(scanf("%d",&N)==1){
		for(int i=1;i<=N;i++)fir[i]=0,deg[i]=*f[i]=dfn[i-1]=dfn[i+N-1]=0;
		now=1;len=0;
		work();
	}
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,ans=0;
  cin>>a>>b>>c>>d;
  if(a==b){
    if(c==d) ans=1;
  }
  else if(b==c){
    if(a==d) ans=1;
  }
  if(ans==1) cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  return 0;
}



Measured memory_bytes: 3096
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

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

#define f first
#define s second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int md = 1e9+7;
const ll inf = 1e18;
const int maxn = 2e5+5;

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

int vis[maxn];
vi adj[maxn];

int dfs(int u)
{
	vis[u] = 1;
	int res = 1;
	for(int v : adj[u])
	{
		if(vis[v]) continue;
		res += dfs(v);
	}
	return res;
}


int main()
{
	int n, m; scanf("%d %d", &n, &m);
	for(int i = 0; i< m; i++)
	{
		int u, v; scanf("%d %d", &u, &v);
		adj[u].pb(v);
		adj[v].pb(u);
	}

	int most = 0;
	for(int i = 1; i<= n; i++)
	{
		if(vis[i]) continue;
		most = max(most, dfs(i));
	}
	printf("%d\n", most);
}

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

#define FOR(i, n) for(int i=0;i<n;i++)
#define FORM(i, n) for(int i=1;i<=n;i++)
#define ll long long
using namespace std;

double sq(double a){
    return a*a;
}

double dist(pair<double, double> a, pair<double, double> b){
    return sqrt(sq(a.first-b.first)+sq(a.second-b.second));
}

int n;
vector<pair<double, double>> v;
bool visited[8];
double ans = 0;
vector<int> vis;

void dfs(int cnt){
    if(cnt==n){
        FOR(i, n-1){
            ans += dist(v[vis[i]], v[vis[i+1]]);
        }
    }
    FOR(i, n){
        if(visited[i]) continue;
        vis.push_back(i);
        visited[i] = true;
        dfs(cnt+1);
        vis.pop_back();
        visited[i] = false;
    }
}

double factorial(double x){
    if(x==1) return 1;
    return x*factorial(x-1);
}

int main(void){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    cin>>n;
    FOR(i, n){
        double a, b;
        cin>>a>>b;
        v.push_back(make_pair(a, b));
    }
    dfs(0);
    ans = ans/(1.0*factorial(n));
    printf("%.8lf", ans);
}

Measured memory_bytes: 256
# include <iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    int x;
    cin>>x;
    if(x>=400&&x<=599)
        cout<<8<<endl;
     else if(x>=600&&x<=799)
        cout<<7<<endl;
    else if(x>=800&&x<=999)
        cout<<6<<endl;
     else if(x>=1000&&x<=1199)
        cout<<5<<endl;
     else if(x>=1200&&x<=1399)
        cout<<4<<endl;
     else if(x>=1400&&x<=1599)
        cout<<3<<endl;
     else if(x>=1600&&x<=1799)
        cout<<2<<endl;
      else if(x>=1800&&x<=1999)
        cout<<1<<endl;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
long long GCD(long long a, long long b){
    return (b ? GCD(b, a%b) : a);
}
long long LCM(long long a, long long b) {
    return a*b/GCD(a,b);
}

/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    ll n; cin >> n;
    vll a(5); rep(i,5) cin >> a[i];

    ll p = infll, Time = 0;
    rep(i,5) {
        chmin(p,a[i]);
    }
    Time = (n+p-1)/p + 4;
    cout << Time << '\n';

    // printf("ExcutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし


N,K = MI()
S = LI2()

A = []
a = 1
for i in range(1,N):
    if S[i-1] == S[i]:
        a += 1
    else:
        A.append(a)
        a = 1
A.append(a)

l = len(A)
if l <= 2*K-1:
    print(N)
    exit()

if S[0] == 1:
    A = [1]+A
if S[-1] == 1:
    A = A+[1]

A = [0]+A
l = len(A)

from itertools import accumulate

A = list(accumulate(A))
ans = 0
for i in range(l//2-K+1):
    if i == 0:
        ans = max(ans,A[2*(K+i)]-A[2*i])
    elif i == l//2-K:
        ans = max(ans,A[2*(K+i)-1]-A[2*i-1])
    else:
        ans = max(ans,A[2*(K+i)]-A[2*i-1])

print(ans)


Measured memory_bytes: 92304
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  vector<int> A(N+1);
  vector<int> B(N);
  for(int i=0;i<N+1;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  int64_t ans=0;
  for(int i=0;i<N;i++){
    if(A.at(i)>B.at(i)){
      ans+=B.at(i);
    }
    if(A.at(i)<=B.at(i) && B.at(i)-A.at(i)>A.at(i+1)){
      ans+=A.at(i)+A.at(i+1);
      A.at(i+1)=0;
    }
    else if(A.at(i)<=B.at(i) && B.at(i)-A.at(i)<=A.at(i+1)){
      ans+=B.at(i);
      A.at(i+1)-=B.at(i)-A.at(i);
    }
  }
  cout << ans << endl;
}
      

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    private static Scanner scan;

    public static void main(String[] args) {
        scan = new Scanner(System.in);
        int n = scan.nextInt();
        ArrayList<Long> list = new ArrayList<Long>();
        long input = 0;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            input = scan.nextLong();
            sum += input;
            list.add(input);
        }
        Collections.sort(list);
        System.out.println(list.get(0) + " " + list.get(n-1) + " " + sum);
    }
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		vector<int> a(n-1, 0);
		for(int i=0; i<n-1; i++)cin >> a[i];		
		int ret = a[0] + a[n-2];
		for(int i=0; i < n-2; i++){
			ret += min(a[i], a[i+1]);
		}
		cout << ret << "\n";
		
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000009;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int p[11];
int main(){
	int n; cin >> n;
	rep(i, n) {
		cin >> p[i];
	}
	sort(p, p + n);
	int out = 0;
	rep(i, n-1) {
		out += p[i];
	}
	out += p[n - 1] / 2;
	cout << out << endl;
	return 0;
}

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

namespace CSharpSample01
{



    class Program
    {

        const long INF = 999999999999;

        static void WarshallFloyd(int V, long[,] d)
        {

            for (int k = 0; k < V; k++)
            {
                for (int i = 0; i < V; i++)
                {
                    for (int j = 0; j < V; j++)
                    {
                        if (d[i, k] != INF && d[k, j] != INF)
                            d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
                    }
                }
            }
            
        }

        static void Show(int V, long[,] d)
        {

            //負の閉路の確認
            for (int i = 0; i < V; i++)
            {
                if (d[i, i] < 0)
                {
                    Console.WriteLine("NEGATIVE CYCLE");
                    return;
                }
            }

            //表示
            for (int i = 0; i < V; i++)
            {
                for (int j = 0; j < V; j++)
                {
                    if (d[i, j] >= INF) Console.Write("INF");
                    else Console.Write($"{d[i, j]}");
                    if (j != V - 1) Console.Write(" ");
                }
                Console.WriteLine();
            }

        }

        //重み付き有効グラフ
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int V = int.Parse(input[0]);
            int E = int.Parse(input[1]);

            //g[i, j] := i -> jへの重み
            long[,] g = new long[V, V];

            for (int i = 0; i < V; i++)
            {
                for (int j = 0; j < V; j++)
                {
                    if (i == j) g[i, j] = 0;
                    else g[i, j] = INF;
                }
            }

            for (int i = 0; i < E; i++)
            {
                input = Console.ReadLine().Split(' ');
                int from = int.Parse(input[0]);
                int to = int.Parse(input[1]);
                int w = int.Parse(input[2]);
                g[from, to] = w;
            }

            WarshallFloyd(V, g);
            Show(V, g);

        }
    }
}


Measured memory_bytes: 18040
#include "bits/stdc++.h"
using namespace std;
    int main(){
        int n, k;
        cin >> n >> k;
        vector<int>vec(n);
        for (int i = 0; i < n; i++){
            cin >> vec.at(i);
        }
        priority_queue<int> pq;
        for(int i = 0; i < n; i++){
            pq.push(vec.at(i));
        }
        int ans = 0;
        for(int i = 0; i < k; i++){
            ans += pq.top();
            pq.pop();
        }
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		while (true) {
			int w = 1;
			int h = 1;
			int moveCan = 0;

			w = scan.nextInt();
			h = scan.nextInt();

			if (w == 0 && h == 0)
				break;

			char[][] table = new char[h][w];
			// int[][] num = new int[h][w];

			for (int i = 0; i < h; i++) {
				// for (int j = 0; j < w; j++) {
				table[i]/* [j] */= scan.next().toCharArray();
				// }
			}

			moveCan = AtCheck(table, w, h);
			System.out.println(moveCan);
		}

		scan.close();
	}

	public static int AtCheck(char table[][], int w, int h) {
		int befAtNum = 0;
		int aftAtNum = 0;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (table[i][j] == '@')
					befAtNum++;
			}
		}

		int[][] atPlace = new int[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (table[i][j] == '@') {
					atPlace[i][j] = 1;
					// if (i != (h - 1) && j != (w - 1) && i != 0 && j != 0
					// && table[i - 1][j - 1]=='.')
					// atPlace[i - 1][j - 1] = 1;
					if (j != 0 && table[i][j - 1] == '.')
						atPlace[i][j - 1] = 1;
					// if (i != (h - 1) && j != (w - 1) && i != 0 && j != 0
					// && table[i + 1][j - 1]=='.')
					// atPlace[i + 1][j - 1] = 1;
					if (i != 0 && table[i - 1][j] == '.')
						atPlace[i - 1][j] = 1;
					if (i != (h - 1) && table[i + 1][j] == '.')
						atPlace[i + 1][j] = 1;
					// if (i != (h - 1) && j != (w - 1) && i != 0 && j != 0
					// && table[i - 1][j + 1]=='.')
					// atPlace[i - 1][j + 1] = 1;
					if (j != (w - 1) && table[i][j + 1] == '.')
						atPlace[i][j + 1] = 1;
					// if (i != (h - 1) && j != (w - 1) && i != 0 && j != 0
					// && table[i + 1][j + 1]=='.')
					// atPlace[i + 1][j + 1] = 1;
				}
			}
		}

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (atPlace[i][j] == 1)
					table[i][j] = '@';
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (table[i][j] == '@')
					aftAtNum++;
			}
		}
		if (befAtNum != aftAtNum) {
			return AtCheck(table, w, h);
		} else {
			return aftAtNum;
		}
	}

}

Measured memory_bytes: 33572
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n = int(input().strip())
    print(2*n*math.pi)


if __name__ == '__main__':
    main()

Measured memory_bytes: 83424
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

const int MAX = 1000001;

int prime[MAX];

void make(){
  fill(prime,prime+MAX,1);
  prime[0] = 0;
  prime[1] = 0;
  for(int i = 2; i < sqrt(MAX); i++){
    if(prime[i]){
      for(int j = 2*i; j < MAX; j+=i) prime[j] = 0;
    }
  }
}
int main(){
  make();
  int a,d,n;
  while(cin >> a >> d >> n && a+d+n){
    int rev = 0;
    while(1){
      if(prime[a]) rev++;
      if(n == rev) break;
      a+=d;
    }
    cout << a << endl;
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        while (true) {
            if (IsPrimeNumber(n)) return n;
            n++;
        }
    }

    static bool IsPrimeNumber(long n) {
        if (n > 2 && n % 2 == 0) return false;

        var r = (long)Math.Sqrt((double)n);
        
        for(int i=3; i<=r; i+=2) {
            if (n % i == 0) return false;
        }
        return true;
    }
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
int n, A[MAXN], co, pos;
ll ans;
int main(){
	FAST
	cin>>n;
	FOR(i,0,n-1)cin>>A[i];
	sort(A,A+n,greater<>());
	co = 1, pos = 1, ans = A[0];
	while(co < n-1){
		if(co == n-2){
			ans += A[pos];
			break;
		}
		ans += A[pos] * 2;
		co += 2;
		++ pos;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 4432