akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int cnt=0;

void merge(int A[], int left, int mid, int right){
    int i,j,k;
    int n1=mid-left;
    int n2=right-mid;
    int L[1000000],R[1000000];
    for(i=0;i<n1;i++) L[i]=A[left+i];
    for(i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1]=1000000000;
    R[n2]=1000000000;

    i=0;j=0;
    for(k=left;k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k]=L[i];
            i=i+1;
        }
        else{
            A[k]=R[j];
            j=j+1;
        }
    }

}

void mergesort(int A[], int left, int right){
    if(left+1<right){
        int mid = (left+right)/2;
        mergesort(A, left, mid);
        mergesort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(){
    int n, A[2000000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }

    mergesort(A, 0, n);
    for(int j=0;j<n;j++){
        if(j==n-1) cout<<A[j]<<endl;
        else cout<<A[j]<<" ";
    }

    cout<<cnt<<endl;
    return 0;
}


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

int main(){
  int N,L;
  cin >> N >> L;
  
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin >> S.at(i);
  }
  
  sort(S.begin(),S.end());
  
  for(int i=0;i<N;i++){
    cout << S.at(i) ;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fto(i, s, e) for(int i = (s); i <= (e); ++i)
#define fto1(i, s, e) for(int i = (s); i < (e); ++i)
#define fdto(i, s, e) for(int i = (s); i >= (e); --i)
#define fat(i, a) for(auto i : a)
#define fit(it, var) for(auto it = (var).begin(); it != (var).end(); ++it)
#define frit(it, var) for(auto it = (var).rbegin(); it != (var).rend(); ++it)

#define bc __builtin_popcountll
#define isbit(x, bit) (((x >> bit) & 1) != 0)
#define onbit(x, bit) (x | (1LL << (bit)))
#define offbit(x, bit) (x & ~(1LL << (bit)))
#define y1 ansdj
#define endl '\n'
#define _bug(...) bug(__func__, __LINE__, __VA_ARGS__)

#define ll long long
#define cd complex<double>
#define ii pair<int, int>
#define pl pair<ll, ll>
#define x first
#define y second
#define pb push_back
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()

template<class T, class Cmp = less<T>> using oss = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;

template<class T1, class T2> ostream& operator<<(ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.x << ", " << v.y << ')';
}

template<class T> ostream& operator<<(ostream &os, vector<T> const &v) {
	fto1 (i, 0, sz(v)) { os << v[i]; if (i < sz(v)-1) os << ' '; }
	return os;
}

template<class T> void buga(T const &v, int l, int r) { fto (i, l, r) { cout << v[i] << " \n"[i == r]; } }

template<class T> void bug(T const &v) { cout << v << endl; }
template<class T, class... Args> void bug(T const &v, Args const&... args) { cout << v << ' '; bug(args...); }
 
double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
int const maxn = 1e6+3;

int f[maxn];

int main() {
	#ifdef KITTENS
		freopen("main.inp", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int x; cin >> x;
	fto (i, 0, 5) f[100+i] = 1;

	fto (i, 106, x) {
		fto (j, 100, 105) f[i] = max(f[i], f[i-j]);
	}

	bug(f[x]);

	#ifdef KITTENS
		cerr << 0.001*clock() << endl;
	#endif
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD9, b / 2) % MOD9;
//     else return a * POW(a * a % MOD9, b / 2) % MOD9;
//   }
// }

int main(){
  int N, M;
  cin >> N >> M;
  Graph G(N);
  for(int i=0; i<M; ++i){
    int A, B;
    cin >> A >> B;
    --A; --B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  vector<int> check(N, -1);
  queue<int> Q;
  check[0] = 0;
  Q.push(0);
  while(!Q.empty()){
    int q = Q.front(); Q.pop();
    for(int nq : G[q]){
      if(check[nq] != -1) continue;
      check[nq] = q;
      Q.push(nq);
    }
  }
  cout << "Yes" << endl;
  for(int i=1; i<N; ++i){
    cout << check[i] + 1 << endl;
  }
}


Measured memory_bytes: 10236
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] a = new int[n];
        Arrays.setAll(a, i -> scanner.nextInt() - 1);
        boolean[] visited = new boolean[n];
        int i = 0, j = 0;
        while (true) {
            j++;
            visited[i] = true;
            if (visited[a[i]]) {
                System.out.println(-1);
                return;
            }
            i = a[i];
            if (i == 1) {
                System.out.println(j);
                return;
            }
        }
    }
}

Measured memory_bytes: 62892
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
string s;
cin>>s;
int flag=0;
/*for(int i=0;i<s.size();i++){
	printf("%c ",s[i]);
}*/
int m;
int book=0;
	if(s[0]=='A'){
		if(s[1]<'a'||s[1]>'z')
		flag=1;	
		for(int i=2;i<s.size();i++){
			if(s[i]=='C'){
				m=i;
				book++;
				if(book>1){
					flag=1;
					break;
				}
				for(int j=2;j<m;j++){
					if(s[j]>='A'&&s[j]<='Z'){
						flag=1;
						break;
					}
				}
				for(int j=m+1;j<s.size();j++){
						if(s[j]>='A'&&s[j]<='Z'){
							flag=1;
							break;
					}
				}
				if(flag)
				break;
			}
	}
}
	if(s[0]!='A'){
		flag=1;	
	}
		if(book==0||m==s.size()-1){
			flag=1;
	}
	if(flag==1)
		printf("WA");
	else
		printf("AC");	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
pair<int,int>a[200010],b[200010];
bool cmp1(pair<int,int>x,pair<int,int>y)
{
	return x.first+x.second<y.first+y.second;
}
bool cmp2(pair<int,int>x,pair<int,int>y)
{
	return x.first-x.second<y.first-y.second;
}
signed main()
{
	int n,i,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i].first>>a[i].second;
		b[i]=a[i];
	}
	sort(a+1,a+n+1,cmp1);
	sort(b+1,b+n+1,cmp2);
	ans=max(llabs(a[1].first-a[n].first)+llabs(a[n].second-a[1].second),llabs(b[1].first-b[n].first)+llabs(b[n].second-b[1].second));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9792
nums=gets.strip.split(" ").each do |i|
  i.to_i
end
t_a = nums[1].to_i
t_b = nums[0].to_i
a_a = nums[3].to_i
a_b = nums[2].to_i
s= ''
flag = true
while flag do
  a_b=a_b-t_a
  if a_b<=0
    s = "Yes"
    flag=false
  end
  t_b=t_b-a_a
  if t_b<=0 && flag
    s = "No"
    flag=false
  end
end
puts s


Measured memory_bytes: 14264
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double pi = 3.14159265359;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
string s;

int main()
{
	cin >> s;

	int l = 0;
	int r = s.size() - 1;

	while (s[l] != 'A') l++;
	while (s[r] != 'Z') r--;

	cout << r - l  + 1 << endl;

	return 0;
}


Measured memory_bytes: 640
from collections import defaultdict
N=int(input())
alist=list(map(int,input().split()))

dic_a=defaultdict(int)
for a in alist:
  dic_a[a]+=1
#print(dic_a)

max_answer=0
for v in dic_a:
  answer=0
  if v-1 in dic_a:
    answer+=dic_a[v-1]
  answer+=dic_a[v]
  if v+1 in dic_a:
    answer+=dic_a[v+1]
  max_answer=max(answer,max_answer)
  
print(max_answer)

Measured memory_bytes: 14564
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        int d[]=new int[n+1];
        boolean m[][]=new boolean[n+1][n+1];
        
        for (int i = 1; i <= n; i++) {
			for (int t = i+1; t <= n; t++) {
				m[i][t] = m[t][i] = true;
			}
		}


       int s=n*(n+1)/2;
	   for (int i = 1; i <= n; i++) {
    	   d[i]=s-i;
       }
	   for (int i = 1; i <= n; i++) {
    	   d[i]-=d[n];
    	   if(n%2==0) {
    		   d[i]++;
    	   }
	   }
	   db(d);
	   for (int i = 1; i <= n; i++) {
		   m[i][d[i]]=m[d[i]][i]=false;
	   }
	   int e=0;
       for (int i = 1; i <= n; i++) {
			for (int t = i+1; t <= n; t++) {
				if(m[i][t]) {
					e++;
				}
			}
		}
       out.println(e);
       for (int i = 1; i <= n; i++) {
			for (int t = i+1; t <= n; t++) {
				if(m[i][t]) {
					out.println(i+" "+t);
				}
			}
		}
       


//        out.println();
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

class P implements Comparable<P>{
    int id,T;
    P(int id, int T) {
        this.id=id;
        this.T=T;
    }
    public int compareTo(P p){
        return id-p.id; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long[] nextLongArray(int size) throws IOException{
    	long r[] = new long[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextLong(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
 
int main() {  
  string str;
  cin >> str;
  string s = "s";
  string es = "es";
  int a=str.size();
  if(str[a-1]=='s'){
    cout << str << es << endl;
  }
  else{
    cout << str << s << endl;
  }
}

Measured memory_bytes: 3632
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
      	int N = sc.nextInt();
      	int[] A = new int[N];
        int sum = 0;
      
      	for(int i=0; i<N; i++){
          	A[i] = sc.nextInt();
          	sum += A[i];
        }
      	
      	if((H-sum)<=0){
          	System.out.println("Yes");
        }else{
          	System.out.println("No");
        }
    }
}

Measured memory_bytes: 49724
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;
using ll=long long;

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

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  //n体のモンスター
  //k回までの必殺技
  //hiの体力
  int n,k;
  cin>>n>>k;
  vector<int> h(n);
  rep(i,0,n)cin>>h[i];
  sort(h.begin(),h.end(),greater<int>());
  ll cnt=0;
  rep(i,0,n){
    i<=k-1 ? cnt+=0 : cnt+=h[i];
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
int main(void) {
  int N = 7368800;
  bool p[N];
  int count;
  int m,n;
  int ans;
  
  scanf("%d%d",&m,&n );
  while (m) {
    for (int i = m; i < N; i++) {
      p[i] = true;
    }
    for (int i = m; i < N; i++) {
      if(p[i] == true){
        for (int j = 2 * i; j < N; j += i) {
          p[j] = false;
        }
      }
    }
    count = 0;
    for (int i = m; i < N; i++) {
      if (p[i] == true) {
        count++;
        if (count == n+1) {
          ans = i;
          break;
        }
      }
    }
    printf("%d\n",ans );
    scanf("%d%d",&m,&n );
  }
  return 0;
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, const modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1e9 + 7;
using m64 = modint<MOD>;

int main() {
    string l;
    cin >> l;
    i32 n = l.size();

    vector<vector<m64>> dp(2, vector<m64>(n+1));
    dp[1][0] = 1;
    for (i32 i = 0; i < n; i++) {
        switch (l[i]) {
        case '0':
            dp[1][i+1] += dp[1][i];
            dp[0][i+1] += dp[0][i] * 3;
            break;
        case '1':
            dp[1][i+1] += dp[1][i] * 2;
            dp[0][i+1] += dp[0][i] * 3 + dp[1][i];
            break;
        }
    }
    cout << dp[0][n] + dp[1][n] << endl;
}


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



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

    string N;
    cin>>N;

    int sum=0;
    rep(i,N.size()){
        sum+=N[i]-'0';
        sum%=9;
    }
    if(sum==0)cout<<"Yes"<<endl;
    else cout <<"No" << endl;

    



}


Measured memory_bytes: 3740
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
using namespace std;

#define N 200000
#define EPS 1e-9
#define PI 3.14159265358979323846264338327950

int arr[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, m, w, x;
	cin >> n>> m;
	x = 0;
	for (int i = 0; i < m; ++i) {
		cin >> w;
		x += w;
	}
	if (x > n)
		cout << -1 << '\n';
	else
		cout << n - x << '\n';
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

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

		if (X >= A) {
			System.out.println(10);
		} else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
    public static void main(String[] args) {
        call(new Scanner(System.in).nextInt());
    }
    private static void call(int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= n; i++) {
            if (i % 3 == 0)
                sb.append(' ').append(i);
            else {
                int x = i;
                do {
                    if ( x % 10 == 3) {
                        sb.append(' ').append(i);
                        break;
                    }
                    x /= 10;
                } while (x != 0);
            }
        }
        System.out.println(sb);
    }
}


Measured memory_bytes: 27652
def bisect_left(array, i, left, right):
    n = right - left + 1
    mid = (left+right) // 2
    if n == 1:
        if array[mid] < i:
            return 1
        else:
            return 0
    if i <= array[mid]:
        return bisect_left(array,i,left,mid)
    else:
        return (mid-left+1) + bisect_left(array,i,mid+1,right)

def bisect_right(array, i, left, right):
    n = right - left + 1
    mid = (right+left) // 2
    if n == 1:
        if i < array[mid] :
            return 0
        else:
            return 1
    if array[mid] <= i:
        return  (mid-left+1) + bisect_right(array,i,mid+1,right)
    else:
        return bisect_right(array,i,left,mid)

N = int(input())
L = []
for _ in range(3):
    l = list(map(int,input().split()))
    L.append(sorted(l))
ans = 0
for x in L[1]:
    n = bisect_left(L[0],x,0,N-1)
    m = bisect_right(L[2],x,0,N-1)
    m = N - m
    ans += n*m
print(ans)

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

typedef long long ll;
using namespace std;

int n;
int t[100005];
int a[10005];

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

	cin >> n;

	for (int i = 0;i < n;i++){
		cin >> t[i];
	}

	sort(t,t+n);
	
	int tmp = n;
	for (int i = t[n-1];i > 0;i--){
		if(t[n-1]%i == 0) tmp = i;
		a[i] = tmp;
	}

	int ans = 0;

	for (int i = 0;i < n;i++){
		ans += a[t[i]] - t[i];
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 3584
#include<stdio.h>
 int main(void)
 {
     int K;
     int i,j=0,k=0;

     scanf("%d",&K);

     for(i=1;i<=K;i++){
       if(i*2<=K) j++;
       else break;
     }

     for(i=0;i<=K;i++){
       if(i*2+1<=K) k++;
       else break;
     }

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

     return 0;
 }


Measured memory_bytes: 1700
//皆さん、第9回シンデレラガール総選挙は、トップでオンリーワンを目指す城ヶ崎美嘉に
//そしてボイスアイドルオーディションは、プログラミングが趣味の才女大石泉に、ぜひ投票をお願いします！
//#城ヶ崎美嘉を009のシンデレラに
//#大石泉の必勝プログラム
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int x,y;cin>>x>>y;
	if(x>y) cout<<"safe"<<endl;else cout<<"unsafe"<<endl;
}


Measured memory_bytes: 3632
#include <stdio.h>

int f(int a, int b){
   int x;
    if (a>b) x=a-b;
    else x=b-a;
    return x;
}

int main(void){
    int N, W[105], i, S, s, m;
    scanf("%d", &N);
    S=0; s=0;
    for (i=1; i<=N; i++) {
        scanf("%d", &W[i]);
        S+=W[i];
    }
    m=S;
    for (i=1; i<=N; i++) {
        s+=W[i];
        if (f(S-s, s)<m) m=f(S-s, s);
    }
    printf("%d", m);
    return 0;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
pii a[N];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n + 1, [&](pii aa, pii bb) {
        return aa.first + aa.second < bb.first + bb.second;
    });
    int ans = 0;
    int lst = a[1].first + a[1].second;
    for (int i = 2; i <= n; i++) {
        if (a[i].first - a[i].second >= lst) {
            lst = a[i].first + a[i].second;
        } else ans++;
    }
    cout << n - ans << endl;
    return 0;
}

Measured memory_bytes: 4248
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int NHalf = N/2;
		int a[] = new int [NHalf];
		int b[] = new int [NHalf];

		for(int i = 0; i < NHalf; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(a);
		Arrays.sort(b);

		int cnt = 0;int maxcnt = 0;int maenum = 0;int nibannum = 0;int nibancnt = 0;int maxnum = 0;
		for(int i = 0; i < NHalf; i++) {

			if(i == 0) {
				maenum = a[i];
				continue;
			}


			if(maenum == a[i]) {
			//	前の整数と同じ場合
				cnt ++;

				if(i+1 == NHalf) {
					if(maxcnt <= cnt){
						if(nibancnt <= maxcnt) {
							nibancnt = maxcnt;
							nibannum = maxnum;
						}
						maxcnt = cnt;
						maxnum = a[i];
						cnt = 0;
					}else {
						if(nibancnt <= cnt) {
							nibancnt = cnt;
							nibannum = a[i];
						}
						cnt = 0;
					}
				}
			}else if(maxcnt <= cnt){

				if(nibancnt <= maxcnt) {
					nibancnt = maxcnt;
					nibannum = maxnum;
				}
				maxcnt = cnt;
				maxnum = a[i-1];
				cnt = 0;
			}else {
				if(nibancnt <= cnt) {
					nibancnt = cnt;
					nibannum = a[i-1];
				}
				cnt = 0;
			}
			maenum = a[i];
		}

		int Amaxnum = maxnum;
		int Amaxcnt = maxcnt;
		int Anibannum = nibannum;
		int Anibancnt = nibancnt;

		cnt = 0;maxcnt = 0;maenum = 0;nibannum = 0;nibancnt = 0;maxnum = 0;
		for(int i = 0; i < NHalf; i++) {

			if(i == 0) {
				maenum = b[i];
				continue;
			}

			if(maenum == b[i]) {
			//	前の整数と同じ場合
				cnt ++;

				if(i == (NHalf-1)) {

					if(maxcnt <= cnt){
						if(nibancnt <= maxcnt) {
							nibancnt = maxcnt;
							nibannum = maxnum;
						}
						maxcnt = cnt;
						maxnum = b[i];
						cnt = 0;
					}else {
						if(nibancnt <= cnt) {
							nibancnt = cnt;
							nibannum = b[i];
						}
						cnt = 0;
					}
				}
			}else if(maxcnt <= cnt){

				if(nibancnt <= maxcnt) {
					nibancnt = maxcnt;
					nibannum = maxnum;
				}
				maxcnt = cnt;
				maxnum = b[i-1];
				cnt = 0;
			}else {
				if(nibancnt <= cnt) {
					nibancnt = cnt;
					nibannum = b[i-1];
				}
				cnt = 0;
			}
			maenum = b[i];
		}


		int ans = 0;
		if(N == 2) {
			if(a[0] != b[0]){
				ans = 2;
			}else {
				ans = 1;
			}
		}else if(Amaxnum != maxnum) {
			ans = Amaxcnt + maxcnt + 2;

		}else{

			int x = Amaxcnt + nibancnt;
			int y = Anibancnt + maxcnt;
			if(x >= y) {
				ans = x + 2;
			}else {
				ans = y + 2;
			}

			if(nibannum == 0 && Anibannum == 0 && Amaxnum == maxnum && Amaxcnt == maxcnt) {
				ans --;

			}

		}

		System.out.println((N-ans));
	}

}


Measured memory_bytes: 50836
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    cout << s.find_last_of("Z") - s.find_first_of("A") + 1 << endl;
    return 0;
}

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

typedef long long ll;

#define faster() ios_base::sync_with_stdio(0), cin.tie(0)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7;
const int inf = INT_MAX;
const double eps = 1e-9;

int main()
{
	faster();
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		cout << (s[i] == '1' ? '9' : '1');
	return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = "";
            var array = new String[2];
            while (!string.IsNullOrEmpty(read = Console.ReadLine()))
            {
                array = read.Split();
                if (!(array[0] == "0" && array[1] == "0"))
                {
                    if (int.Parse(array[1]) < int.Parse(array[0]))
                        Console.WriteLine($"{array[1]} {array[0]}");
                    else
                        Console.WriteLine($"{array[0]} {array[1]}");
                }
            }
        }
    }
}



Measured memory_bytes: 13856
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;

typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

typedef vector<P> G;
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}
P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
P reflection(const L &l, const P &p) {
	return p + P(2,0) * (projection(l, p) - p);
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
bool inner(int x,int X,int y,int Y,int a,int b)
{
	return x<=a&&a<=X&&y<=b&&b<=Y;
}

int main()
{
	int n,sx,sy,ex,ey;
	while(scanf("%d",&n),n)
	{
		scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
		L s(P(sx,sy),P(ex,ey));
		vector<L> l(4,L(P(0,0),P(0,0)));
		
		double ans=INF;
		rep(i,n)
		{
			int x,X,y,Y,h; scanf("%d%d%d%d%d",&x,&y,&X,&Y,&h);
			if(inner(x,X,y,Y,sx,sy)||inner(x,X,y,Y,sx,sy))ans=0;
			
			l[0]=L(P(x,y),P(X,y)); l[1]=L(P(x,y),P(x,Y));
			l[2]=L(P(X,y),P(X,Y)); l[3]=L(P(x,Y),P(X,Y));
			rep(j,4)
			{
				double d=distanceSS(s,l[j]);
				double r=(h*h+d*d)/(2*h);
				if(r>=h)ans=min(ans,r);
				else ans=min(ans,d);
			}
		}
		printf("%.7f\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  rep(i, n + 1){
    if(i % 4 == 0 && (n - i) % 7 == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cnt = 0;
  for (int i = 0; i <= 999; i++) {
    string tmp = to_string(i);
    while ((int) tmp.size() < 3) tmp = "0" + tmp;
    int a = -1;
    for (int i = 0; i < N; i++) {
      if (S.at(i) == tmp.at(0)) {
        a = i;
        break;
      }
    }
    if (a == -1) continue;
    int b = -1;
    for (int i = a + 1; i < N; i++) {
      if (S.at(i) == tmp.at(1)) {
        b = i;
        break;
      }
    }
    if (b == -1) continue;
    int c = -1;
    for (int i = b + 1; i < N; i++) {
      if (S.at(i) == tmp.at(2)) {
        c = i;
        break;
      }
    }
    if (c == -1) continue;
    cnt++;
  }
  cout << cnt << "\n";
}

Measured memory_bytes: 384
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//18:08~
int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	int h,i,n,m;cin>>n;
	m=(1<<n);
	multiset<int>a;
	for(i=0;i<m;i++){int x;cin>>x;a.ins(x);}
	vector<int>b;
	b.pub(*prev(a.end()));
	a.erase(*prev(a.end()));
	for(h=0;h<n;h++){
		vector<int>c;c.reserve(1<<h);
		for(auto it:b){
			auto sor=a.lower_bound(it);
			cerr<<it<<endl;
			if(sor==a.begin()){cout<<"No"<<endl;return 0;}
			sor--;
			cerr<<(*sor)<<endl;
			c.pub(*sor);
			a.era(sor);
			
		}
		for(auto it:c){b.pub(it);}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 13684
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 20 20:54:28 2019

@author: sp8783
"""
import copy

n = int(input())
lst = list(map(int,input().split()))

tmp = copy.deepcopy(lst)

f_lst = list(range(n//2))[::-1]

for i in f_lst:
    a = (sum(tmp[i::i+1])-tmp[i]) % 2
    b = tmp[i]
    if a == b:
        tmp[i] = 0
    else:
        tmp[i] = 1
    
print(sum(tmp))
x = [i+1 for i, x in enumerate(tmp) if x == 1]
print(*x)

Measured memory_bytes: 18628
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            :oyhhhhhhyo:    
#define next         .sdNNNmNNNNNNNmds. 
#define y0          -hNNNNy`yNNNNNN`/Nh-
#define y1          mNNNNNd+dNNNNNN+sNNm
#define yn          mNNNNNNNNy--:smNNNms
#define tm          .+oooooosyysooooo+- 
#define read               :yhy/        
#define rank              :mNmo         
#define index              ... 
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int MULT[] = {1, -3, -4, -1, 3, 4};
const int N = 111111;
int dp[N][15];
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    n = sz(s);
    reverse(rng(s));
    dp[0][0] = 1;
    rep(i, 1, n) {
        int mi = (i - 1) % 6;
        rep(pr, 0, 12) {
            if(s[i - 1] == '?') {
                rep(d, 0, 9) {
                    int ne = pr + d * MULT[mi];
                    ne = (ne % 13 + 13) % 13;
                    dp[i][ne] = ((dp[i][ne] + dp[i - 1][pr]) % MOD + MOD) % MOD;
                }
            } else {
                int ne = pr + (int)(s[i - 1] - '0') * MULT[mi];
                ne = (ne % 13 + 13) % 13;
                dp[i][ne] = ((dp[i][ne] + dp[i - 1][pr]) % MOD + MOD) % MOD;
            }
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}


Measured memory_bytes: 12752
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

// a^n mod を計算する
//ただしmとaが互いにその時のみ
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
ll N;
cin >> N;
ll K;
cin >> K;
ll ans=0;
ll MOD=1000000007;
vector<ll> howmany(K+1,0);
for(ll i=K;i>=1;i--){
  ll k=K/i;
  ll sum=modpow(k,N,MOD);
  for(ll j=2;j*i<=K;j++){
    sum-=howmany[i*j];
    sum%=MOD;
  ;}
  howmany[i]=sum;

;}
for(ll i=1;i<=K;i++){
  ans+=howmany[i]*i%MOD;
  ans%=MOD;
;}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int R, C, N;
	R = getint();
	C = getint();
	N = getint();
	vector<pair<int, int>> P1, P2, P3, P4;
	int A[100000] = {};
	rep(i, N) {
		int a, b, c, d;
		a = getint();
		b = getint();
		c = getint();
		d = getint();
		if (a == 0) P1.pb(mp(b, i));
		else if (b == C) P2.pb(mp(a, i));
		else if (a == R) P3.pb(mp(C - b, i));
		else if (b == 0) P4.pb(mp(R - a, i));
		else A[i] = -1;
		if (c == 0) P1.pb(mp(d, i));
		else if (d == C) P2.pb(mp(c, i));
		else if (c == R) P3.pb(mp(C - d, i));
		else if (d == 0) P4.pb(mp(R - c, i));
		else A[i] = -1;
	}
	sort(P1.begin(), P1.end());
	sort(P2.begin(), P2.end());
	sort(P3.begin(), P3.end());
	sort(P4.begin(), P4.end());

	int k = 1;
	int OK = 1;
	for (auto p : P1) {
		if (A[p.second] == 0) {
			A[p.second] = k;
			k++;
		}
		else if (A[p.second] > 0) {
			k--;
			if (A[p.second] != k) OK = 0;
		}
	}
	for (auto p : P2) {
		if (A[p.second] == 0) {
			A[p.second] = k;
			k++;
		}
		else if (A[p.second] > 0) {
			k--;
			if (A[p.second] != k) OK = 0;
		}
	}
	for (auto p : P3) {
		if (A[p.second] == 0) {
			A[p.second] = k;
			k++;
		}
		else if (A[p.second] > 0) {
			k--;
			if (A[p.second] != k) OK = 0;
		}
	}
	for (auto p : P4) {
		if (A[p.second] == 0) {
			A[p.second] = k;
			k++;
		}
		else if (A[p.second] > 0) {
			k--;
			if (A[p.second] != k) OK = 0;
		}
	}

	if (OK) co("YES");
	else co("NO");

	Would you please return 0;
}

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

int check(string &s, int a,vector<int> &mv){
    if(mv[a]!=-1) return mv[a];
    if(s.at(a)=='R'&&s.at(a+1)=='L') return mv[a]=a;
    if(s.at(a)=='L'&&s.at(a-1)=='R') return mv[a]=a;
    if(s.at(a)=='R'&&s.at(a+1)=='R') return mv[a]=check(s,a+2,mv);
    if(s.at(a)=='L'&&s.at(a-1)=='L') return mv[a]=check(s,a-2,mv);
}

int main(){
    string s;
    cin>>s;
    int n=s.size();
    vector<int> ans(n,0);
    vector<int> mv(n,-1);
    for(int i=0;i<n;i++){
        ans[check(s,i,mv)]++;
        
    }
    for(int i=0;i<n;i++){
            cout<<ans[i]<<' ';
        }
    return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<vector<long long int>> vvint;
typedef vector<string> vstr;
typedef long long int llint;

llint gcd(llint x, llint y) {
	while (y != 0) {
		if (x > y) {
			llint r = x % y;
			x = y;
			y = r;
		}
		else {
			llint r = y % x;
			y = r;
		}
	}
	return x;
}

int main(void) {
	int N, ans = 0, cou = 0;
	cin >> N;
	vint p(N);
	for (int i = 0; i < N; i++)cin >> p[i];
	sort(p.begin(), p.end());
	for (int i = 0; i <= N; i++){
		cou = 0;
		for (int j = 0; j < N; j++){
			if (i <= p[j])cou++;
		}
		if (cou >= i)ans = i;
	}
	cout << ans << endl;
}




Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    fast_io

    int n;
    cin>>n;
    int ans=n%10;
    if(ans==3){
        cout<<"bon"<<endl;
    }else if(ans==0 || ans==1 || ans==6 || ans==8) cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <algorithm>

int main () {
  int n;
  int in[102];
  scanf("%d", &n);
  int total = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &in[i]);
    total += in[i];
  }

  if (total % 10 == 0) {
    int min = 999999;
    for (int i = 0; i < n; i++) {
      if (in[i] % 10 != 0) {
        min = std::min(min, in[i]);
      }
    }

    if (min == 999999)
      printf("0\n");
    else
      printf("%d\n", total - min);
  } else
    printf("%d\n", total);

  return 0;
}


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


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

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int a_max = a[max_element(a, a + n) - a];
    if (a_max < k) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    int a_gcd = a[0];
    for (int i = 1; i < n; i++) {
        a_gcd = gcd(a_gcd, a[i]);
    }
    if ((a_max - k ) % a_gcd) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << "POSSIBLE" << endl;
    }
    return 0;
}


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

const long long INF = 1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, q;
    cin >> a >> b >> q;
    vector<long long> s(a+2), t(b+2), x(q);
    for(int i = 1; i <= a; i++){
        cin >> s[i];
    }
    s[0] = -INF; s[a+1] = INF;
    sort(s.begin(), s.end());
    for(int i = 1; i <= b; i++){
        cin >> t[i];
    }
    t[0] = -INF; t[b+1] = INF;
    sort(t.begin(), t.end());
    for(int i = 0; i < q; i++){
        cin >> x[i];
        int idx_s = lower_bound(s.begin(), s.end(), x[i]) - s.begin();
        int idx_t = lower_bound(t.begin(), t.end(), x[i]) - t.begin();
        long long ans = 1e11;
        ans = min(ans, max(s[idx_s], t[idx_t]) - x[i]);
        ans = min(ans, x[i] - min(s[idx_s-1], t[idx_t-1]));
        ans = min(ans, t[idx_t] - s[idx_s-1] + min(t[idx_t]-x[i], x[i]-s[idx_s-1]));
        ans = min(ans, s[idx_s] - t[idx_t-1] + min(s[idx_s]-x[i], x[i]-t[idx_t-1]));
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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

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

  vi a(n);
  rep(i, n) cin >> a[i];

  bool flag = true;
  int n_swap = 0;
  while (flag) {
    flag = false;
    
    for (int i = n - 1; i > 0; i--) {
      if (a[i] < a[i - 1]) {
        swap(a[i], a[i - 1]);
        flag = true;
        n_swap++;
      }
    }
  }

  rep(i, n) {
    cout << a[i];
    if (i != n - 1) cout << " ";
    else cout << endl;
  }

  cout << n_swap << endl;
}



Measured memory_bytes: 3136
N = int(input())

A_i = []
for i in range(N):
    A_i.append(int(input()))

A_i_sord = sorted(A_i)
A_i_max_first = A_i_sord[N - 1]
A_i_max_second = A_i_sord[N - 2]

for i in range(N):
    if A_i_max_first == A_i[i]:
        print(A_i_max_second)
    else:
        print(A_i_max_first)

Measured memory_bytes: 14112
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll N;
ll h[111];

ll check() {
    for(ll i=0; i<N; i++)
        if(h[i]>0) return 1;
    
    return 0;
}

int main(void) {
    cin >> N;
    ll i;
    for(i=0; i<N; i++) cin >> h[i];
    
    ll ans=0;
    ll gro=0;
    while(check()) {
        ll r=1;
        gro= h[0]>0 ? 1 : 0;
        for(i=0; i<N; i++) {
            if(r==1 && h[i]==0) {
                r=0;
            }else if(r==0 && h[i]>0) {
                r=1;
                gro++;
            }
        }
        
        for(i=0; i<N; i++) {
            if(h[i]==0) continue;
            if(h[i]>0) h[i]--;
        }
        
        ans+=gro;
    }
    
    pt(ans);
}






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

if K == 0:
    print(N*N)
    exit()


ans = 0
for b in range(K+1,N+1):
    # N = b * num + rest
    num = N // b 
    rest = N - (b*num)
    # b一周期の中に、余りがK以上になる数字が(b-K)個、残りの中でさらに余りがKを超える物があればそれも加算
    ans += (b - K) * num + max(0, rest-K+1) 


print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<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 REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);
    //SCIN(str);
    //CIN(A);
    //CIN(B);
    //CIN(C);
    int ans = 0;
    for(int a = 1;a <= N;a++){
        int co = 0;
        if(a % 2 == 0)continue;
        for(int b = 1;b <= a;b++){
            if(a % b == 0){
                co++;
            }
        }
        if(co == 8){
            ans++;
        }
    }
    COUT(ans);
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  int ans = 0;
  rep(i, n) {
    cin >> x;
    ans += 2 * min(abs(x), abs(k - x));
  }

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


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

using namespace std;

using i64 = long long int;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(a) a.begin(), a.end()

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    i64 n;
    cin >> n;
    vector<i64> a(n);
    rep(i, n) cin >> a[i];
    vector<i64> used(n, 0), tmp(n , 0);
    i64 ans = 0;
    rep(i, n){
        if(used[i]) continue;
        i64 idx = i;
        i64 flag;
        while(true){
            if(tmp[idx] == 1){
                flag = 0; // 既存のループに当たる場合
                break;
            }else if(tmp[idx] == -1){
                flag = 1; // 新規のループに当たる場合
                break;
            }else{
                tmp[idx] = -1;
                idx = (idx + a[idx]) % n;
            }
        }
        if(flag){
            i64 cnt = 0;
            while(true){
                if(used[idx] == 1) break;
                else{
                    used[idx] = tmp[idx] = 1;
                    idx = (idx + a[idx]) % n;
                    ++cnt;
                }
            }
            ans += cnt;
        }    
        idx = i;
        while(true){
            if(used[idx] == 1) break;
            else{
                used[idx] = tmp[idx] = 1;
                idx = (idx + a[idx]) % n;
            }
        }    
    }
    cout << ans << endl;
}


Measured memory_bytes: 5100