akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
    double r, a, c;
    std::cin >> r;

    a = M_PI * std::pow(r, 2.0);
    c = 2.0 * M_PI * r;

    std::cout << std::fixed << std::setprecision(6) << a << " " << c << std::endl;

    return 0;
}



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

int ans=0;

int main(void)
{
    //input
    string str;
    cin >> str;
    
    //calculate
    for(int i=0; i<str.size(); i++){
        int j=0;
        int sum=0;
        while(str[i+j] == 'A' || str[i+j] == 'C' || str[i+j] == 'T' || str[i+j] == 'G'){
            sum++;
            j++;
        }
        ans=max(ans,sum);
    }
        
    cout << ans << endl;
    return 0;    
}

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

int main(){
  int N;
  cin >> N;
  vector<int> L(2 * N);
  for(int i = 0; i < 2 * N; i++) cin >> L[i];
  sort(L.begin(), L.end());
  int result = 0;
  for(int i = 0; i < N; i++) result += L[2 * i];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import re

Input = input()

pat = r'[0-9]+'

num_list = re.findall(pat, Input)

#print("HP =",num_list[0])
#print("ATK =",num_list[1])

HP = int(num_list[0])
ATK = int(num_list[1])

cou = HP//ATK

if HP % ATK:
    cou += 1

print(cou)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vs = vector<string>;
using pint = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    int x = n % (2*d+1);
    int ans = 0;
    if(x == 0) {
        ans = n / (2*d+1);
    } else {
        ans = n / (2*d+1) + 1;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define SANKOU(n, a, b) cout << ((n) ? (#a) : (#b)) << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>

int N;
V v;

void solve()
{
    int n = N;
    int a = 0;
    for (int i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            if (N / i - 1 <= i) {
                break;
            }
            a += N / i - 1;
        }
    }
    cout << a << endl;
}

signed main()
{
    cin >> N;
    solve();
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0;
setter = -100;
for i in a:
    ans+=b[i-1]
    if(setter+1 == i):
        ans+= c[setter-1]
    setter = i
print(ans)

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

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

int main() {
	int n; cin >> n;
  	vector<pair<double, double> > v(n);
  	for (int i = 0; i < n; i++) {
    	cin >> v[i].first >> v[i].second;
    }
	double avg = 0;
  	sort(v.begin(), v.end());
  	do {
    	for (int i = 1; i < n; i++) {
        	avg += dist(v[i - 1], v[i]);
        }
    }
  	while (next_permutation(v.begin(), v.end()));
    double fact = n;
    while (--n) fact *= n;
    cout << setprecision(12) << avg / fact << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); //cinの高速化
  
  string S;
  IN(S);
  
  int cnt=0;
  int j;
  for(int i=1; i<S.length(); ++i){
    if(S.length()==1) goto fin;
    if((S[i]=='1' && S[i-1] =='0') || (S[i]=='0' && S[i-1] =='1')){
      S.erase(i-1,2);
      cnt += 2;
      if(S.length() >0) i=i-2;
      else goto fin;
      
    }
  }
  fin:
  OUT(cnt);
  return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
//#define int ll

const int N = 1e5 + 10;
int p[N], sz[N];

int find(int v) {
  return p[v] == v ? v : p[v] = find(p[v]);
}

vector<int> g[N], hg[N];

void merge(int a, int b) {
  a = find(a), b = find(b);
  assert(a != b);
  if (sz[a] < sz[b]) {
    swap(a, b);
  }
  sz[a] += sz[b];
  p[b] = a;
}

bool used[N];
char c[N];

void dfs(int v, int cl) {
  c[v] = (cl == 0 ? 'B' : 'W');
  used[v] = true;
  for (auto u : hg[v]) {
    if (!used[u]) {
      dfs(u, cl ^ 1);
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  map<int, vector<int>> have;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    have[a[i]].pb(i);  
  }
  vector<pair<int, int>> edges;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
    edges.pb({u, v});
  }
  map<pair<int, int>, int> ans;
  for (auto it : have) {
    //cout << it.F << '\n';
    vector<int> V = it.S;
    for (auto v : V) {
      p[v] = v;
      //cout << "C " << v << '\n';
      sz[v] = 1;
    }
    for (auto v : V) {
      for (auto u : g[v]) {
        if (a[u] <= a[v] && find(v) != find(u)) {
          //cout << u << ' ' << v << '\n';
          ans[{u, v}] = ans[{v, u}] = it.F;
          hg[u].pb(v);
          hg[v].pb(u);
          merge(u, v);
        }
      }
    }
    for (int v : V) {
      if (sz[find(v)] == 1) {
        cout << -1 << '\n';
        exit(0);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      dfs(i, 0);
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << c[i];
  }
  cout << '\n';
  for (auto it : edges) {
    if (ans.count(it)) {
      cout << ans[it] << '\n';
    }
    else {
      cout << 1000000000 << '\n';
    }
  }
} 

Measured memory_bytes: 42048
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
using namespace std;

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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	ul a, b, c, d;cin >>a>>b>>c>>d;
	ul p = (ul)((b)/c) - (ul)((a-1)/c);
	ul q = (ul)((b)/d) - (ul)((a-1)/d);


	//cerr << t/d << endl;
	ul r = (ul)((b)/(c*d/gcd(c,d))) - (ul)((a-1)/(c*d/gcd(c,d)));
	cout << b-a+1-(p + q - r) << endl;
	return 0;
}


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

using namespace std;

typedef long long lint;

const int maxn = 1e5+5, inf = 0x3f3f3f3f;

int n, i, j;
lint k, x;
int one[100], zero[100];

lint ans;
lint v[maxn];
int main()
{
    //freopen("f.in", "r", stdin);
    //freopen("f.out", "w", stdout);

    scanf("%d%lld", &n, &k);

    for(i = 1; i <= n; i ++) {
        scanf("%lld", &x); v[i] = x;
        for(j = 0; j <= 40; j ++) {
            if((x & (1LL << j)) != 0) {
                one[j] ++;
            } else {
                zero[j] ++;
            }
        }
    }

    lint x = 0;
    for(i = 40; i >= 0; i --) {
        lint u = 1LL << i;
        if(x + u <= k && zero[i] > one[i]) {
            x += u;
        }
    }

    for(i = 1; i <= n; i ++) {
        ans += (x ^ v[i]);
    }
    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string s;
    cin >> s;
    cout << s[0] << s.length()-2 << s[s.length()-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;

int n;
const int nx = 1e5+5;
int ac[nx][3];
int dp[3][nx];

int go(int a, int i){
	if(i == n) return 0;
	if(dp[a][i] != -1) return dp[a][i];
	int& ans = dp[a][i];
	
	if(a==0){
		ans=max(ans, go(1, i+1)+ac[i][0]);
		ans=max(ans, go(2, i+1)+ac[i][0]);
	}
	if(a==1){
		ans=max(ans, go(0, i+1)+ac[i][1]);
		ans=max(ans, go(2, i+1)+ac[i][1]);
	}
	if(a==2){
		ans=max(ans, go(0, i+1)+ac[i][2]);
		ans=max(ans, go(1, i+1)+ac[i][2]);
	}
	
	return ans;
}

int main(){
	cin>>n;
	for(int i=0; i<n; i++) cin>>ac[i][0]>>ac[i][1]>>ac[i][2];
	memset(dp, -1, sizeof dp);
	cout<<max(go(0,0),max(go(1,0),go(2,0)))<<"\n";
	return 0;
}


Measured memory_bytes: 7296
def main():
    N, A, B = map(int, input().split())

    if not (((N - 1) // A + 1) <= B <= (N - A) + 1):
        print(-1)
        return

    if B == 1:
        print(*range(1, N + 1))
        return

    q, r = divmod(N - A, B - 1)

    ctr = [A]
    ctr += [q] * (B - 1 - r)
    ctr += [q + 1] * r

    ans = []
    ma = N
    for x in ctr:
        ans += list(range(ma - x + 1, ma + 1))
        ma -= x
    print(*ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 22988
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in insert
#define mp make_pair
#define F first
#define pb push_back
#define pf push_front
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll exp(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x); x=(x*x); y/=2; } return res;}
set<ll> s;

int main(){
    ll n,m; cin>>n>>m;
    ll a[n];
    ll sum=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    ll c=0;
    ll x=sum/(4*m);
    if(sum%4*m!=0){
        x+=1;
    }
    for(ll i=0;i<n;i++){
        if(a[i]>=x)
            c++;
    }
    if(c>=m)
        cout<<"Yes";
    else cout<<"No";
  //  cout<<c;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main(void)
{
	LL H, W, h, w;
	cin >> H >> W >> h >> w;
	LL nH = H / h;
	LL nW = W / w;
	if (!nH)nH = 1;
	if (!nW)nW = 1;
	/*
	LL val = H * W - nH * nW * (h * w + 1);
	if (val <= 0)
	{
		cout << "No\n"; return 0;
	}
	cout << "Yes\n";
	*/
	vector<vector<int>>dis(H, vector<int>(W));
	LL tot = 0;
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			if (i % h == h - 1 && j % w == w - 1)
			{
				dis[i][j] = -1000000000;
			}
			else if (i % h == 0 && j % w == 0)
			{
				dis[i][j] = 1000000000 - 1;
			}
			tot += dis[i][j];
		}
	}
	if (tot <= 0)
	{
		cout << "No\n"; return 0;
	}
	cout << "Yes\n";
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			cout << dis[i][j] << " \n"[j == W - 1];
		}
	}
	return 0;
}


Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
vector<string> bit;


void subBin(string str, int n)
{
    if (n == 0){
        bit.push_back(str);
    }
    if (n > 0) {
        subBin(str + "0", n - 1);
        subBin(str + "1", n - 1);
    }
}

string toBin(int n){
    if(n == 1)return "1";
    else if(n == 0)return "0";

    return toBin(n/2)  + to_string(n%2);
}
int main(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    bool ans = (w/2 ==x&& h/2 == y);

    printf("%lf", w*h/2.0);
    cout << " " << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s, a="", b="", c, d, f;
	cin >> s;
	int len = s.length();
	for(int i=0;i<((len-1)/2);i++) a+=s[i];
	for(int i=(((len+3)/2)-1);i<len;i++) b+=s[i];
	c = a;
	d = b;
	f = s;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	reverse(s.begin(), s.end());
	if(f==s && c==a && d==b) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
x,k,d=map(int,input().split())
x=abs(x)
if x>k*d:
    print(x-k*d)
elif x%d==0:
    t=x//d
    print(d if (k-t)%2 else 0)
else:
    t=x//d
    m=x%d
    print(abs(m-d) if (k-t)%2 else m)

Measured memory_bytes: 61704
#include<stdio.h>
void calcu(int x,int y){
  int n;
    n = x%y;
    while(n!=0){
      x=y;
      y=n;
      n=x%y;
    }
    printf("%d\n",y);
}
  
int main(){
  int n,m,x,y;
  scanf("%d%d",&n,&m);
  if(n>=m){
    x=n;
    y=m;
  }
  else{
    x=m;
    y=n;
  }
  calcu(x,y);
  return 0;
}
  
    



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

int main(){
  int n,num;

  while(cin >> n){
    num = 0;
    while(n--){
      num++;
      if(num == 40)num = 1;
    }
    cout << "3C";
    if(num < 10)cout << 0;
    cout << num << endl;
  }
}

Measured memory_bytes: 0
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
//        DecimalFormat df = new DecimalFormat("0.00000000");

        final int N = Integer.parseInt(sc.next());
        int[] ar = new int[N];
        for (int i = 1; i < N; i++) {
            int index = Integer.parseInt(sc.next());
            ar[index - 1]++;
        }
        for (int i = 0; i < N; i++) {
            out.println(ar[i]);
        }
        
        out.flush();
    }
}

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

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

    int ans = 0;
    for (int i = A; i <= B; i++)
    {
        string s = to_string(i);
        string rev = to_string(i);
        reverse(rev.begin(), rev.end());
        if (s == rev)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, s, mx, c[150], d[150];
string a;
int main() {
	int i, j;
	cin>>n>>a;
	for(i=0; i<n; i++) d[a[i]]++;
	for(i=0; i<n; i++) {
		c[a[i]]++;
		d[a[i]]--;
		for(j='a', s=0; j<='z'; j++) if(c[j] && d[j]) s++;
		mx = max(mx, s);
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256
#C
from collections import Counter
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = a.copy()
b.sort()
b.reverse()
fi = b[0]
se = b[1]
for i in a:
    if i == fi:
        print(se)
    else:
        print(fi)

Measured memory_bytes: 14480
n,y=map(int,input().split())
an=-1,-1,-1
for m in range(n+1):
    for g in range(n+1):
        s=n-m-g
        if m+g >n:
            break
        if m+g+s == n and 10000*m+5000*g+1000*s ==y:
            print(m,g,s)
            exit(0)

print(*an)


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**7)
def main():
    N, M = map(int, input().split())
    l = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        l[a-1].append(b-1)
    c = [0] * N
    loop = []
    def cyclic(n):
        if c[n] == 2:
            return False
        if c[n] == 1:
            loop.append(n)
            return True
        c[n] = 1
        for i in l[n]:
            if cyclic(i):
                loop.append(n)
                return True
        c[n] = 2
        return False
    for i in range(N):
        if cyclic(i):
            break
    if len(loop) == 0:
        print(-1)
        return
    print(0)
    return
main()


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

int main(){
  int n,m=0;
  cin >> n;
  vector<int64_t>a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i)<0)m++;  
    a.at(i)=abs(a.at(i));
  }
  int64_t ans=0;
  for(int i=0;i<n;i++) ans+=a.at(i);
  if(m%2==1){
    int64_t s=1000000000;
    for(int i=0;i<n;i++)s=min(s,a.at(i));
    ans-=s*2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3968
def main():
    MOD = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split(' ')))
    # 対称性から、左半分（中央含む）の各場所でのアサイン候補人数だけ考える。
    # 中央では1人、その他では2人（左右それぞれにアサイン）であればOK。
    # アサイン可能なのであれば答えは 2 ** (N // 2) 通り。
    count = [0 for _ in range(N // 2 + 1)]
    for a in A:
        if (N - 1 - a) % 2 > 0:
            print(0)
            return
        left = (N - 1 - a) // 2  # right = (N - 1 + a) // 2
        count[left] += 1
    for i in range(len(count)):
        c = count[i]

        if i == N // 2:
            if N % 2 > 0 and c != 1:
                print(0)
                return
        else:
            if c != 2:
                print(0)
                return
    # caclulate answer
    ans = 1
    for _ in range(N // 2):
        ans *= 2
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14008
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;

	int total = 0;

	int max_en = 0;
	for (int i = 0; i < N; i++) {
		int cur;
		cin >> cur;
		total += cur;
		if (cur > max_en) {
			max_en = cur;
		} 
	}
	cout << total - max_en /2  << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = scanner.nextInt();
        }
        for(int j = 0; j < n; j++){
            q[j] = scanner.nextInt();
        }
        int[] C = new int[n];
        for(int i = 0; i < n; i++){
            C[i] = i+1;
        }
        int a = -1;
        int b = -1;
        int count = 1;
        do{
            boolean aflag = true;
            boolean bflag = true;
            if(a == -1){
                for(int i = 0; i < n; i++){
                    if(C[i] != p[i]){aflag = false;break;}
                }
                if(aflag){a=count;}
            }
            if(b == -1){
                for(int i = 0; i < n; i++){
                    if(C[i] != q[i]){bflag = false;break;}
                }
                if(bflag){b=count;}
            }
            if(a != -1 && b != -1){break;}
            count++;
        }while(nextPermutation(C));
        System.out.println(Math.abs(a-b));
    }

    //【参考URL】
    // http://d.hatena.ne.jp/tomerun/20081203/1228321480
    public static boolean nextPermutation(int[] a) {
    for (int i = a.length - 1; 0 < i; i--) {
      if (a[i - 1] < a[i]) {
        int index = find(a[i - 1], a, i, a.length - 1);
        int temp = a[index];
        a[index] = a[i - 1];
        a[i - 1] = temp;
        Arrays.sort(a, i, a.length);
        return true;
      }
    }
    return false;
  }

    // destより大きい要素の中で最小のもののインデックスを二分探索で探す
    private static int find(int dest, int[] a, int s, int e) {
        if (s == e) {
        return s;
        }
        int m = (s + e + 1) / 2;
        return a[m] <= dest ? find(dest, a, s, m - 1) : find(dest, a, m, e);
    }
}



Measured memory_bytes: 24660
#include "bits/stdc++.h"
using namespace std;
 
int main(void) {
	int n;
	cin >> n;
	vector<int> d(n);

	for(int i=0;i<n;i++) cin >> d[i];

	sort(d.begin(), d.end());

	int count = 0;

	for(int i=0;i<n-1;i++) {
		if(d[i] == d[i+1]) count++;
	}

	cout << n - count << endl;
}


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

void solve(int a[])
{
	if(a[1]==a[0] && a[1]!=a[2]) 
	{
		cout<<"Yes"; return ;
	}
	if(a[1]==a[2] && a[1]!=a[0]) 
	{
		cout<<"Yes"; return;
	}
	cout<<"No";
}
int main()
{
	int a[3];
	for(int i=0;i<3;i++) cin>>a[i];
	sort(a,a+3);

	solve(a);
	cout<<"\n";
}

Measured memory_bytes: 256
from itertools import product


def main():
    c500 = int(input())
    c100 = int(input())
    c50 = int(input())
    target = int(input())

    count = 0
    for n_c500, n_c100, n_c50 in product(range(c500+1), range(c100+1),  range(c50+1)):
        if (n_c500*500+n_c100*100+n_c50*50 == target): count += 1
    print(count)

if __name__ == '__main__':
    main()


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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  int arr[n];
  for(int a=0;a<n;a++)
    cin>>arr[a];
  int memo[n];
  memset(memo,0,sizeof(memo));
  memo[1]=abs(arr[1]-arr[0]);
  for(int a=2;a<n;a++)
    memo[a]=min(memo[a-2]+abs(arr[a-2]-arr[a]),memo[a-1]+abs(arr[a-1]-arr[a]));
  cout<<memo[n-1];
}

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

int main() {
	vector<int> dt;
	int n;
	while (cin >> n, n) {
		int tmp;
		dt.clear();
		for (int i=0; i<n; i++) {
			cin >> tmp;
			dt.push_back(tmp);
		}

		int cnt = 0;
		while (1) {
			vector<int> t = dt;
			for (int i=0; i<n; i++)
				dt[i] = count(t.begin(), t.end(), t[i]);

			if (t == dt) {
				cout << cnt << endl;
				for (int i=0; i<n-1; i++)
					cout << t[i] << ' ';

				cout << t[n-1] << endl;
				break;
			}
			cnt++;
		}
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
Dishes = [int(i) for i in input().split()]
Sat = [int(i) for i in input().split()]
AddSat = [int(i) for i in input().split()]
FinishSat = 0
for i in range(n):
    FinishSat += Sat[i]
    if i > 0:
        if Dishes[i - 1] + 1 == Dishes[i]:
            FinishSat += AddSat[Dishes[i - 1] - 1]
print(FinishSat)


Measured memory_bytes: 3060
def yaku(n):
    x=[]
    for i in range(1,n+1):
        if n%i==0:
            x.append(i)
    return len(x)

n=int(input())
x=0
for i in range(n+1):
    if i%2==0:
        continue
    else:
        if yaku(i)==8:
            x+=1
print(x)

Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    string S, T; cin>>S>>T;
    int n=S.size(), m=T.size();
    vector<string> s(n), t(m);
    for(int i=0; i<n; i++){
        s[i]=S[i];
    }
    for(int i=0; i<m; i++){
        t[i]=T[i];
    }

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<string>());

    for(int i=0; i<min(n, m); i++){
        if(s[i]<t[i]){
            cout << "Yes" << endl;
            return 0;
        }
        
        if(s[i]>t[i]){
            cout << "No" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=(a);i<(b);i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}

int log(int x) {
    int i;
    for(i=0;(1<<i)<=x;i++);
    return i;
}

vector<int> osci(vector<int> v) {
	vector<int> v1;
	int n=v.size();
	int i=0,j=n-1;
	for(int k=0;k<n;k++) {
		if(k%2==0)
			v1.pb(v[i++]);
		else
			v1.pb(v[j--]);
	}
	reverse(all(v1));
	return v1;
} 
 
int32_t main() {
    fio
	cout << fixed << setprecision(15);
    
    string s;
    cin >> s;
    sort(all(s));
    char ch='a';
    int f=0;
    for(auto i:s) {
        if(i==ch) {
            if(ch=='z') {
                f=1;
                break;
            }
            ch=(char)(ch+1);
        }
    }
    
    if(f==1) {
        cout << "None";
        return 0;
    }
    cout << ch;


	return 0;
    
}

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,l,t;
    cin >> n >> l >> t;
    int arr[n],w[n];
    for (int i = 0; i < n; i++) cin >> arr[i] >> w[i];
    int finpos[n];
    for (int i = 0; i < n; i++){
        if (w[i] == 1) finpos[i] = (arr[i]+t)%l;
        else finpos[i] = (arr[i]+l-t%l)%l;
    }
    int start = 0;
    for (int i = 1; i < n; i++){
        if (w[i] != w[0]){
            int loop = t/l;
            int change = 2*loop;
            int timeleft = t-loop*l;
            if (w[0] == 1){
                int rem = arr[i]-arr[0];
                if (rem/2 < timeleft) change++;
                if ((rem+l)/2 < timeleft) change++;
                start = (start+change%n)%n;
            }
            else{
                int rem = l-arr[i]+arr[0];
                if (rem/2 < timeleft) change++;
                if ((rem+l)/2 < timeleft) change++;
                start = (start+n-change%n)%n;
            }

        }
    }
    int actpos[n];
    actpos[start] = finpos[0];
    sort(finpos,finpos+n);
    int newpos = 0;
    for (int i = 0; i < n; i++){
        if (finpos[i] == actpos[start]) {
            newpos = i;
            break;
        }
    }
    if (newpos != n-1 && finpos[newpos] == finpos[newpos+1] && w[0]== 2)newpos++;
    for (int i = 1; i < n; i++) actpos[(start+i)%n] = finpos[(newpos+i)%n];
    for (int i = 0; i < n; i++) cout << actpos[i] << "\n";
}


Measured memory_bytes: 5132
<?php

while (($line = trim(fgets(STDIN))) !== '0') {
    $n = (int)$line;
    $arr = array_fill(0, $n + 1, array_fill(0, $n + 1, 0));
    for ($i = 0; $i < $n; $i++) {
        $line = trim(fgets(STDIN));
        foreach (explode(' ', $line) as $j => $m) {
            $m = (int)$m;
            $arr[$i][$j] = $m;
            $arr[$i][$n] += $m;
            $arr[$n][$j] += $m;
        }
    }
    $arr[$n][$n] = array_sum($arr[$n]);

    for ($i = 0; $i <= $n; $i++) {
        for ($j = 0; $j <= $n; $j++) {
            printf('%5d', $arr[$i][$j]);
        }
        echo PHP_EOL;
    }
}



Measured memory_bytes: 9336
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;


using namespace std;

struct Team{
  int t_num;
  int t_correct;
  int t_time;
  int t_wrong[11];
  Team(int n,int p){
    t_num=n;
    t_correct=0;
    t_time=0;
    rep(i,p) t_wrong[i]=0;
  }
};

//構造体ソート
class sort_type1{
  public:
    bool operator()(const Team& a,const Team& b){
      
      if(a.t_correct!=b.t_correct) return a.t_correct > b.t_correct;
      
      if(a.t_time != b.t_time) return a.t_time < b.t_time;

      return a.t_num < b.t_num;
    }
};

int main(){
  
  while(1){
    int T,P,R;
    cin >> T >> P >> R;
    
    if(T==0&&P==0&&R==0) break;
    
    vector<Team> list;
    rep(i,T){
      Team tmp(i,P);
      list.push_back(tmp);
    }
    
    rep(i,R){
      int t,p,time;
      string str;
      cin >> t >> p >> time >> str;
      t--;p--;
      if(str=="WRONG"){
        list[t].t_wrong[p]++;
       // cout << "WRONG" << endl;
      }else if(str=="CORRECT"){
        
        list[t].t_time+=(1200*list[t].t_wrong[p]);
        list[t].t_time+=time;
        list[t].t_correct++;
      }
   }

    sort(list.begin(),list.end(),sort_type1());
    rep(i,list.size()){
      cout << list[i].t_num + 1 << " " << list[i].t_correct << " " <<list[i].t_time << endl;
    }
  }


}

Measured memory_bytes: 1228
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>
#include <cfloat>
#include <array>


constexpr long long int MOD = 1000000007;
long long int power(long long int base, int exp) {
	switch (exp) {
	case 0: return 1L;
	case 1: return base % MOD;
	default: return power(base * base % MOD, exp >> 1) * power(base, exp & 1) % MOD;
	}
}
long long int solve(int position, int diff, bool is_use, const std::vector<long long int>& values, std::vector<std::vector<std::vector<long long int>>>& memo) {
	if (position >= values.size()) return (diff == 0) ? 0 : LONG_MIN / 2;
	if (diff < -1 || 1 < diff) return LLONG_MIN / 2;
	if (memo[position][diff + 1][is_use] != LLONG_MIN) return memo[position][diff + 1][is_use];
	long long int result{ LLONG_MIN };
	if (!is_use) {
		if (position % 2 == 1) {
			result = std::max(result, solve(position + 1, diff, true, values, memo) + values[position]);
		}
		else {
			result = std::max(result, solve(position + 1, diff - 1, true, values, memo) + values[position]);
		}
	}
	if (position % 2 == 1) {
		result = std::max(result, solve(position + 1, diff + 1, false, values, memo));
	}
	else {
		result = std::max(result, solve(position + 1, diff, false, values, memo));
	}
	return memo[position][diff + 1][is_use] = result;
}
int main() {
	int n; std::cin >> n;
	std::vector<long long int> values(n); for (auto& v : values) std::cin >> v;
	std::vector<std::vector<std::vector<long long int>>> memo(n, std::vector<std::vector<long long int>>(3, std::vector<long long int>(2, LLONG_MIN)));
	for (auto i = 1; i < n; i += 1000) {
		solve(n - i, 0, false, values, memo);
	}
	std::cout << solve(0, 0, false, values, memo) << std::endl;
}

Measured memory_bytes: 62284
fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();

    let mut mi = v[0];
    let mut cnt = 0;
    for i in 0..n {
        if v[i] <= mi {
            cnt += 1;
            mi = v[i];
        }
    }

    println!("{}", cnt);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 10492
/*
  Author - KISHAN TIWARI
  Dream bigger. Do bigger.
  Wake up with determination. Go to bed with satisfaction.
*/
//Sometimes later becomes never. Do it now.
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define f(i,a,b)     for(ll i=a;i<b;i++)
#define mod          1000000007
#define fi           first
#define se           second
#define pa           pair <ll,ll>
#define mp           make_pair
#define pb           push_back
#define ve           vector<ll>
#define vep          vector< pa >
#define all(a)       a.begin(), a.end()
#define sz(x)        (ll)x.size()
#define c(t)         cout<<t<<"\n"
using namespace std;
void solve()
{  ll k,x;
cin>>k>>x;
ll l=x-k+1,r=x+k-1;
if(l<-1000000)
   l=-1000000;
if(r>1000000)
    r=1000000;
f(i,l,r+1)
cout<<i<<" ";
cout<<"\n";



}
int main()
{
    ios::sync_with_stdio(true);
   //freopen ("input.txt","r",stdin);
   //freopen ("output.txt","w",stdout);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }
return 0;
}


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

int main() {
    long k, n; cin >> k >> n;
    vector<long> a(n);
    long maxa = 0;
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
        if (i != 0) {
            maxa = max(maxa, a.at(i) - a.at(i - 1));
        }
        if (i == n - 1) {
            maxa = max(maxa, k - (a.at(n - 1) - a.at(0)));
        }
    
    }
    cout << k - maxa << endl;
}





Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(3 * N);
    for (auto& a : A) {
        cin >> a;
    }
    sort(all(A));
    reverse(all(A));
    ll ans = 0;
    for (int i = 1; i < 2 * N; i += 2) {
        ans += A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
n = int(input())
h = list(map(int, input().split()))

counter, ans = 0, 0
for i in range(len(h)-1):
    if h[i] >= h[i+1]:
        counter += 1
    else:
        if ans <= counter:
            ans = counter
        counter = 0
ans = max(ans, counter)


print(ans)


Measured memory_bytes: 14252
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const int N = 1000010,p = 100001,MOD = 1e9+7;
vector<ll> G[N];
ll Hash[N];
map<ll,ll> m;
map<ll,ll>::iterator it;
void dfs(ll u)
{
    Hash[u] = 1;
    for(int i = 0;i < G[u].size();i++)
    {
        ll v = G[u][i];
        dfs(v);
        Hash[u] = (Hash[u]+Hash[v]*p)%MOD;//哈希方程，p取一个6到8位的素数，mod一般取1e9+7 
    }
    m[Hash[u]]++;
}
int main()
{/*
int size = 256 << 20; // 256MB
char *p = (char*)malloc(size) + size;
__asm__("movl %0, %%esp\n" :: "r"(p));*/

    int n,u,v;
    cin >> n;
    for(int i = 1;i <= n-1;i++)
    {
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
    }
    dfs(1);
    ll ans = 0; 
    for(it = m.begin();it != m.end();it++)
        ans += it->second*(it->second-1)/2;
    printf("%lld\n",ans);
    return 0;
}
/*
https://blog.csdn.net/huatian5/article/details/70305845
*/ 


Measured memory_bytes: 44640
from collections import deque

K = int(input())
Q = deque([i for i in range(1, min(9, K) + 1)])
ctr = 0

while Q:
    cur = Q.popleft()
    simo = cur % 10
    ctr += 1
    if ctr == K:
        print(cur)
        break
    for dx in [-1, 0, 1]:
        if 0 <= simo + dx <= 9:
            Q.extend([10 * cur + simo + dx])

Measured memory_bytes: 46460
#include<bits/stdc++.h>
int MOD = 1000000007;
using namespace std;
//g++ -std=c++14
//setprecision(10)
int main(){
	string s;
	cin >> s;
	int ans = -1;
	int va;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'A' && ans == -1) 
			ans = i;
		if(s[i] == 'Z' && ans != -1)
			va = i;
	}
	cout << va - ans + 1 << endl;
}

Measured memory_bytes: 640
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 998244353


def solve():
    n = I()
    x = LI()
    ans = 0
    for i in range(n):
        xi = x[i]
        ans += pow(2,n-i-1,mod)*xi*pow(xi+1,i,mod)
        if ans >= mod:
            ans %= mod
    print(ans)
    return


if __name__ == "__main__":
    solve()



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

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

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

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

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

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

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

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

fn main() {
    input!(n: usize, k: usize, h: [i64; n]);

    let mut costs = vec![-1; n];
    let mut index = 0;

    loop {
        let mut i = 1;
        loop {
            if i == k + 1 {
                break;
            }
            if index + i == n {
                break;
            }

            if index == n {
                println!("{:?}",costs[index - 1]);
                return 
            }

            let current_h = h[index];
            let current_cost = if costs[index] == -1 { 0 } else { costs[index] };

            let hop = h[index + i];
            let hop_cost = (current_h - hop).abs() + current_cost;
            if costs[index + i] == -1 || costs[index + i] > hop_cost {
                costs[index + i] = hop_cost;
            }

            i = i + 1
        }

        index = index + 1;
    }
}


Measured memory_bytes: 6524
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int N;
int A[220000];

int main(void){

    cin >> N;

    for (int i = 0;i < N;i++) {
        cin >> A[i];
    }
    sort (A, A+N, greater<int>());
//    for (int i = 0;i < N;i++) cout << A[i];
 
    long long ans = 0;

    for (int i = 0;i < N - 1;i++) {
        ans += A[(i + 1)/2];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4380
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <climits>
#include <random>

#define ll long long

using namespace std;

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int n;
    scanf("%d", &n);
    vector<ll> a(n + 1);
    vector<ll> sum(n + 1, 0);
    vector<vector<ll>> d(1 + n + 1, vector<ll>(1 + n + 1, 0));
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        sum[i] = sum[i - 1] + a[i];
    }
    for (int len = 1; len <= n; len++) {
        for (int i = 1; i + len - 1 <= n; i++) {
            int j = i + len - 1;
            d[i][j] = max(sum[j] + a[i] - sum[i] - d[i + 1][j], sum[j - 1] + a[j] - sum[i - 1] - d[i][j - 1]);
        }
    }
    ll val_1 = d[1][n];
    ll val_2 = (sum[n] - d[1][n]);
    printf("%lld\n", val_1 - val_2);
    return 0;
}

Measured memory_bytes: 70784
#include<iostream>

using namespace std;

const int MAX_R = 11;
const int MAX_C = 10001;


bool in[MAX_R][MAX_C];
int R,C,LIM;

void input(){
  for(int i = 0; i < R; i++)
    for(int j = 0; j < C; j++)
      cin >> in[i][j];
}

void print(){
  for(int i = 0; i < R; i++){
    for(int j = 0; j < C; j++)
      cout << in[i][j] << " ";
    cout << endl;
  }
}

int make(){

  //print();
  int out = 0;
  
  for(int j = 0; j < C; j++){
    int sum = 0;
    for(int i = 0; i < R; i++)
      if(in[i][j]) sum++;
    // cout << " " << max(sum,R-sum);
    out += max(sum,R-sum);
  }
  //  cout << endl;
  return out;
}

int rev(int n){

  for(int i = 0; i < 10; i++)
    if( (n&(1<<i)))
      for(int j = 0; j < C; j++)
	in[i][j] = !in[i][j];

  int max_O = make();


  for(int i = 0; i < 10; i++)
    if( (n&(1<<i)) == 1 )
      for(int j = 0; j < C; j++)
	in[i][j] = !in[i][j];
 
  return max_O;
}

void solve(){
  
  LIM = (1<<R);
  int ans = 0;
  for(int i = 0; i < LIM; i++)
    ans = max(ans,rev(i));

  cout << ans << endl;
}

int main(){
  while(cin >> R >> C && R+C){
    input();
    solve();
  }
  return 0;
}

Measured memory_bytes: 1256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int t[30] = {};
	int N, ans = 0;
	string S;
	
	cin>>N;
	
	cin>>S;
	
	for(int i = 0; i < S.size(); i++){
		t[S[i]-'a']++;
	}
	for(int i = 0; i < 26; i++){
		// cout<<t[i]<<endl;
		if(t[i]){
			ans *= t[i]+1;
			ans += t[i];
			ans %= MOD;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,m;
  cin >> n >> m;
  ll a[n];
  for(ll i=0;i<n;i++)cin >> a[i];

  ll s[n+1]={};
  for(ll i=0;i<n;i++)s[i+1]=s[i]+a[i];

  vec v;
  for(ll i=0;i<n+1;i++)v.push_back(s[i]%m);

  sort(v.begin(),v.end());
  vec u=v;
  u.erase(unique(u.begin(),u.end()),u.end());

  ll ans=0;
  for(ll i=0;i<u.size();i++){
    ll p=distance(lower_bound(v.begin(),v.end(),u[i]),upper_bound(v.begin(),v.end(),u[i]));
    ans+=p*(p-1)/2;
    //cout << p << endl;
  }
  cout << ans << endl;

}

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

int N;

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

int main(){
  
  cin >> N;
  vector<int> city(N+1);
  vector<int> dist(N);

  for(int i = 0; i <= N; i++){
    cin >> city[i];
  }
  
  sort(city.begin(), city.end());
  
  for(int i = 0; i < N; i++){
    dist[i] = city[i+1] - city[i];
  }
  
  int ans = dist[0];
  for(int i = 1; i < N; i++){
    ans = gcd(dist[i], ans);
  }
  
  cout << ans << endl;
}

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

#define INF ((1<<31)-1)  //int32_t
#define MOD 1000000007
#define MOD2  

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){
    bool flag=true;
    ll ans=0,sum=0;
    int n;
    string s;
    cin >>n>>s;
    //vector<vector<int>> diff(n);

    int dp[n][n];

    for (int i = n-1; i >= 0; --i){
        for (int j = n-1; j >= 0; --j){
            if(s[i]==s[j]){
                if(i+1 <= n-1  && j+1 <= n-1){
                    dp[i][j] = dp[i+1][j+1] + 1;
                }else{
                    dp[i][j]=1;
                }
            }else{
                dp[i][j]=0;
            }

            ans = max((ll)min(dp[i][j],abs(i-j)),ans);
        }
        
    }
    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 97920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void) {
	string s; cin >> s;
	int size = s.size() - 2;
	string t = s.front() + to_string(size) + s.back();
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
import math

def main():
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())

    capa = [A, B, C, D, E]
    time = math.ceil(N / min(capa)) + len(capa) - 1
    print(time)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int x,a,b;
int main()
{
    scanf("%d%d%d",&x,&a,&b);
    printf("%d",(x-a)%b);
    return 0;
}

Measured memory_bytes: 256