akhauriyash/Code-Regression huggingface dataset:
//-----Rashish-----//
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define endl '\n'
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hcf(ll n1, ll n2) {if (n2 != 0)return hcf(n2, n1 % n2); else return n1;}
ll fact(ll n) { ll i = 1, co = 1; for (i = 1; i <= n; i++)co *= i; return co;}
ll isprime(ll n) {
  if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
  for (ll i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1;
}
ll sod(ll n) {ll sum = 0; while (n) {sum += n % 10; n /= 10;} return sum;}




int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int t;
  t = 1;
  //cin>>t;
  while (t--) {
    ll n, s = 0;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; ++i)
    {
      cin >> a[i];

    }
    for (int i = 1; i < n; ++i)
    {
      // cin >> a[i];
      if (a[i] < a[i - 1]) {
        s += (a[i - 1] - a[i]);
        a[i] += ((a[i - 1] - a[i]));
        /* code */
      }
    }
    cout << s << endl;



  }

  return 0;
}


Measured memory_bytes: 5264
#include<stdio.h>
int a[100003];
int main()
{
	long long b,c,d;
	scanf("%lld",&b);
	for(int i=1;i<=b;i++)
	{
	scanf("%lld",&a[i]);
	} 
	c=a[1];
	if(c==2) printf("1");
	else {
	for(int i=1;;i++)
	{
	d=a[c];
	if(d==2) 
	{
	printf("%d",i+1);
	break;
   }
	c=d;
	if(i==b-1){
     
	printf("-1");
	break;
	}       
}
}
	return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m, x;
  cin >> n >> m >> x;

  set<int> va;
  for (int i = 0; i < m; ++i) {
    int a;
    cin >> a;
    va.insert(a);
  }

  int ans = 0;
  for (int i = x + 1; i <= n; ++i) {
    if (va.count(i)) {
      ans++;
    }
  }

  int ans2 = 0;
  for (int i = x - 1; i >= 0; --i) {
    if (va.count(i)) {
      ans2++;
    }
  }

  cout << min(ans, ans2) << '\n';
  return 0;
}

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

int main() {
  int N;
  int A;
  double S=0.000000000;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A;
    S=S+1.000000000/A;
    
  }
 cout<<1.000000000/S<<endl;
}

Measured memory_bytes: 256
import java.io.*;
  
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s;
        while(null != (s = in.readLine())){
            String[] arr = s.split(" ",0);
            double[] iarr = toDoubleArray(arr);
            calc(iarr);
        }
    }
    private static double[] toDoubleArray(String[] arr){
        double[] result = new double[arr.length];
        for(int i=0;i<arr.length;i++)
            result[i] = Integer.parseInt(arr[i]);
        return result;
    }
    private static void calc(double[] arr){
        double det = arr[0]*arr[4]-arr[1]*arr[3];
        double x = (arr[2]*arr[4]-arr[1]*arr[5])/det+0.0;
        double y = (-arr[2]*arr[3]+arr[0]*arr[5])/det+0.0;
        System.out.printf("%.3f %.3f\n",x,y);
    }
}

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

int main(){
    int n,k;
    cin>>n>>k;
    long long int h[n],i,j;
    for(i=0;i<n;i++)cin>>h[i];
    long long int s=0;
    sort(h,h+n);
    for(i=0;i<n-k;i++){
    	s+=h[i];
	}
    cout<<s;
	return 0;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

ll powll(ll in, ll count) {
	ll reg = 1;
	for (ll i = 0; i < count; ++i)
		reg *= in;
	return reg;
}

signed main()
{
	fastio();
	ll a, max;
	cin >> a ;
	max = 1;

	for (int i = 2; i < a; i++) {
		for (int j = 2; powll(i, j) <= a; j++) {
			if (max < powll(i, j))
				max = powll(i, j);
		}
	}

	cout << max <<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var X, N int
	fmt.Scan(&X, &N)
	if N == 0 {
		fmt.Println(X)
		return
	}
	p_lis := make([]int, N)
	for i := 0; i < N; i++ {
		var p int
		fmt.Scan(&p)
		p_lis[i] = p
	}
	diff := 0
	for {
		if !contains(p_lis, X-diff) {
			fmt.Println(X - diff)
			return
		}
		if !contains(p_lis, X+diff) {
			fmt.Println(X + diff)
			return
		}
		diff++
	}
}
func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}


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

using namespace std;

long long n, k;
long long f[100010];
const long long mod = 1e9 + 7;
long long power(long long a, long long b)
{
	return b? power(a*a%mod, b/2)*(b%2?a:1)%mod:1;
} 
int main()
{
	cin >> n >> k;
	long long ans = 0;
	for(int i = k; i >= 1; i--)
	{
		f[i] = power(k/i, n);
		for(int j = 2 * i; j <= k; j += i)
		{
			f[i] -= f[j];
		}
		ans = (ans + i * f[i] %mod)%mod;
	}
	cout << (ans+mod) % mod <<endl;
	return 0;
}


Measured memory_bytes: 4372
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

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

  string s; cin >> s;
  int a = 0, b = 0, c = 0;
  for (int i = 0; i < (int) s.size(); ++i) {
    a += s[i] == 'a';
    b += s[i] == 'b';
    c += s[i] == 'c';
  }

  if (max({a, b, c}) - min({a, b, c}) < 2) {
    print("YES");
  } else {
    print("NO");
  }

  return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
namespace io
{
	const int N=1<<20;
	char buf[N],*t1=buf,*t2=buf;
	#ifdef cjy 
	#define getc() getchar()
	#else
	#define getc() t1==t2&&(t2=(t1=buf)+fread(buf,1,N,stdin),t1==t2)?EOF:*t1++
	#endif
	inline int read()
	{
		static int an,f;an=0,f=1;
		static char ch;ch=getc();
		while(ch<48||ch>57)ch=='-'?f=-1:0,ch=getc();
		while(ch>=48&&ch<=57)an=(an<<3)+(an<<1)+(ch^48),ch=getc();
		return an*f;
	}
	char buff[N],*T=buff;
	inline void flush(){fwrite(buff,1,T-buff,stdout);}
	inline void putc(char ch){T==buff+N?flush(),T=buff:0;*T++=ch;}
	inline void print(int x)
	{
		if(!x){putc('0');return;}
		static int st[20],tp;
		while(x)st[++tp]=x%10,x/=10;
		while(tp)putc(st[tp--]^48);
	}
}
using io::read;
using io::putc;
using io::flush;
using io::print;
char s[200020];
int n,dp[200020][2],from[200020][2];
void getans(int p,int w)
{
	if(!p)return;
	getans(p-1,from[p][w]);
	if(w==0)putchar('D');
	else putchar('P');
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;++i)if(s[i]=='?')s[i]='D';
	printf("%s",s+1);
	return 0;
	dp[0][1]=-0x3f3f3f3f;
	for(int i=1;i<=n;++i)
	{
		dp[i][0]=dp[i][1]=0xc0c0c0c0;
		if(s[i]!='P')
		{
			if(dp[i-1][0]+1>dp[i][0])dp[i][0]=dp[i-1][0]+1,from[i][0]=0;
			if(dp[i-1][1]+2>dp[i][0])dp[i][0]=dp[i-1][1]+2,from[i][0]=1;
		}
		if(s[i]!='D')
		{
			if(dp[i-1][0]>dp[i][1])dp[i][1]=dp[i-1][0],from[i][1]=0;
			if(dp[i-1][1]>dp[i][1])dp[i][1]=dp[i-1][1],from[i][1]=1;
		}
	}
	getans(n,dp[n][0]<dp[n][1]);
	flush();
	return 0;
}

Measured memory_bytes: 1828
#include<bits/stdc++.h>
    #include <ext/pb_ds/tree_policy.hpp> 
    #include <functional> // for less 
    using namespace __gnu_pbds; 
    using namespace std;
    //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;    
    #define ll            long long
    #define pb            push_back
    #define ppb           pop_back
    #define si            set <ll>
    #define endl          '\n'
    #define fr            first
    #define sc            second
    #define mii           map<ll,ll>
    #define msi           map<string,ll>
    #define mis           map<ll,string>
    #define rep(i,a,b)    for(ll  i=a;i<b;i++)
    #define all(v)        v.begin(),v.end()
    #define sort(v)       sort(all(v))
    #define pii           pair<ll ,ll >
    #define vi            vector<ll >
    #define vii           vector<pair<ll,ll>>
    #define vs            vector<string>
    #define sz(x)         (ll)x.size()
    #define M             1000000007
    #define bs            binary_search
    #define rev(a)        reverse(all(a));
    #define sp(n)         setprecision(n)
    #define spl           " "
    #define arr(a,n)      rep(i,0,n) cin>>a[i]
    #define mod           998244353
    #define print_vector(a)  for(auto t:a) cout<<t<<" ";cout<<endl;
    #define print_arr(a,n)   rep(i,0,n) cout<<a[i]<<" "; cout<<endl;        
    #define show(a,n)     for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
    #define debug(x)      cout << #x << " is " << x << endl;
    #define time          cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    #define INF           1ll<<31
    #define hi            cout<<"hi"<<endl;
    const ll maxn=int(3e5)+500;
    const ll maxa=(1<<20)+3;
    ll bpow(ll a, ll b, ll mm = M)
    {
        ll res = 1;
     
        while(b)
        {
            if(b & 1)
                res = (res * a) % mm;
            a = (a * a) % mm;
     
            b >>= 1;
        }
     
        return res;
    }
    
    void solve()
    {
     ll s,w;
     cin>>s>>w;
     if(w>=s) {cout<<"unsafe";}
     else cout<<"safe"<<endl;

    } 
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t=1;
        //cin>>t;
        while(t--) solve();
    }

  

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
// clang-format off

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on

void solve(long long N, std::vector<long long> X) {
  // solver code

  LL sum = 0;

  for (auto e : X) {
    sum += e;
  }

  // COUT((double)sum / N);

  double mid = (double)sum / N;
  LL pt = (LL)(mid + 0.5);
  // COUT(pt);

  LL res = 0;

  for (auto e : X) {
    res += pow(e - pt, 2);
  }
  cout << res << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> X(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &X[i]);
  }
  solve(N, std::move(X));
  return 0;
}


Measured memory_bytes: 256
n = int(input())
xxx = []
yyy = []
for _ in range(n):
    cx, cy = map(int, input().split())
    xxx.append(cx + cy)
    yyy.append(cx - cy)

max_x = max(xxx)
min_x = min(xxx)
max_y = max(yyy)
min_y = min(yyy)

print(max(max_x - min_x, max_y - min_y))


Measured memory_bytes: 24744
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cctype>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <deque>
#include <map>
#include <bitset>
#include <functional>
#include <cmath>

#define INF 1000000000
using namespace std;

int main() {
    long long n;
    cin >> n;
    map<long long, long long> m;

    long long i;
    long long ans = 0;
    for(i = 0; i < n; i++){
        long long a;
        cin >> a;
        m[a]++;
        ans += a;
    }

    long long q;
    cin >> q;
    for(i = 0; i < q; i++){
        long long b, c;
        cin >> b >> c;

        ans += (c - b) * m[b];

        m[c] += m[b];
        m[b] = 0;


        cout << ans << endl;
    }
}


Measured memory_bytes: 9544
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();

    let mut it = buf.split_whitespace().map(|n| i64::from_str(n).unwrap());
    let (a, b) = (it.next().unwrap(), it.next().unwrap());

    if a % 3 == 0 {
        println!("Possible");
        return;
    }
    if b % 3 == 0 {
        println!("Possible");
        return;
    }
    if (a + b) % 3 == 0 {
        println!("Possible");
        return;
    }
    println!("Impossible");

}


Measured memory_bytes: 4352
while True:
    # データを受け取る
    n, x = map(int, input().split())
    if n==x==0:
        break

    num = 0

    for i in range(1, n + 1):
        for j in range(1, n + 1):
            for k in range(1, n + 1):
                result = i + j + k
                if i >= j or i >= k or j >= k:
                    pass
                elif result == x:
                    num += 1
                else:
                    pass
    print(num)



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

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, const T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, const T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

void calc() {
	int n; cin >> n;
	V v(3 * n); input(v);
	sort(all(v));
	int ans = 0;
	int idx = 3 * n - 2;
	rep(i, n) {
		ans += v[idx];
		idx -= 2;
	}
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	calc();
#ifdef _MSC_VER
	system("pause");
#endif
}

Measured memory_bytes: 2560
N, K = map( int, input().split())
A = list( map( int, input().split()))
RA = sorted(A)
RA = RA[::-1]
s = 0
ans = 0
for i in range(N):
    a = RA[i]
    if s+a < K:
        s += a
        ans += 1
    else:
        ans = 0
print(ans)
#反例
#5 12
#6 4 3 2 1

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

int main(){
	int n; cin>>n;
	int maxx = -1, minn = 1002;
	while(n--){
		int x; cin>>x;
		maxx = max(maxx, x);
		minn = min(minn, x);
	}	
	cout<<maxx - minn<<endl;
}


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

int main() {
  uint64_t n;
  std::cin >> n;
  std::vector<uint64_t> odd(100000, 0);
  std::vector<uint64_t> even(100000, 0);

  for (uint64_t i = 0; i < n; i++) {
    uint64_t tmp;
    std::cin >> tmp;
    if (i % 2 == 0) {
      even[tmp]++;
    } else {
      odd[tmp]++;
    }
  }

  const auto e_top = std::distance(even.cbegin(),
    std::max_element(even.cbegin(), even.cend()));
  const auto e_top_count = even[e_top];

  const auto o_top = std::distance(odd.cbegin(),
    std::max_element(odd.cbegin(), odd.cend()));
  const auto o_top_count = odd[o_top];

  if (e_top != o_top) {
    std::cout << n - e_top_count - o_top_count << std::endl;
    return 0;
  } else {
    if (e_top_count == n / 2 && o_top_count == n / 2) {
      std::cout << n / 2 << std::endl;
      return 0;
    } else if (e_top_count == n / 2) {
      odd[o_top] = 0;
      const auto o_top = std::distance(odd.cbegin(),
        std::max_element(odd.cbegin(), odd.cend()));
      const auto o_top_count = odd[o_top];
      std::cout << n / 2 - o_top_count << std::endl;
      return 0;
    } else if (o_top_count == n / 2) {
      even[e_top] = 0;
      const auto e_top = std::distance(even.cbegin(),
        std::max_element(even.cbegin(), even.cend()));
      const auto e_top_count = even[e_top];
      std::cout << n / 2 - e_top_count << std::endl;
      return 0;
    } else {
      odd[o_top] = 0;
      even[e_top] = 0;
      const auto e_2top = std::distance(even.cbegin(),
        std::max_element(even.cbegin(), even.cend()));
      const auto e_2top_count = even[e_2top];

      const auto o_2top = std::distance(odd.cbegin(),
        std::max_element(odd.cbegin(), odd.cend()));
      const auto o_2top_count = odd[o_2top];
      std::cout << std::min(n - e_top_count - o_2top_count,
        n - o_top_count - e_2top_count) << std::endl;
      return 0;
    }
  }

  return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--, b--, c--, d--;
    string s; cin >> s;

    bool ok = true;
    for(int i = a; i <= c; i++){
        if(s[i] == '#' && s[i + 1] == '#'){
            ok = false;
            break;
        }
    }
    for(int i = b; i <= d; i++){
        if(s[i] == '#' && s[i + 1] == '#'){
            ok = false;
            break;
        }
    }
    if(!ok) {
        cout << "No" << endl;
        return 0;
    }

    if(d < c){
        bool flag = false;
        for(int i = b; i <= d; i++){
            if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
                flag = true;
                break;
            }
        }
        if(!flag){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3696
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> len(n);
		REP(i, n) {
			string s;
			cin >> s;
			len[i] = s.length();
		}
		int ans = 1;
		int idx = 0;
		int cnt=0;
		int no;
		while (1) {
			if (idx == 5)
				break;
			if (idx == 0 && cnt == 0)
				no = ans;
			cnt += len[no - 1];
			no++;
			if (idx == 0 || idx == 2) {
				if (cnt == 5) {
					idx++;
					cnt = 0;
					continue;
				}
				if (cnt > 5) {
					ans++;
					idx = 0;
					cnt = 0;
				}
			}
			else {
				if (cnt == 7) {
					idx++;
					cnt = 0;
					continue;
				}
				if (cnt > 7) {
					ans++;
					idx = 0;
					cnt = 0;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3148
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

ll expo(ll a, ll b){
    ll ex = 1;
    rep(i, b){
        ex *= a;
    }
    return ex;
}

ll fact(ll a){
    ll fc = 1;
    REP(i, 1, a+1){
        fc *= i;
    }
    return fc;
}

int main() {
    ll n;
    cin >> n;
    ll cnt = 0;
    REP(a, 1, n) {
        cnt += (n-1)/a;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main()
{
  char s[4];
  scanf("%s",&s);
  if(strcmp(s,"MON")==0)
       printf("6");
  
  else if(strcmp(s,"TUE")==0)
       printf("5");
  
   else if(strcmp(s,"WED")==0)
       printf("4");
  
   else if(strcmp(s,"THU")==0)
       printf("3");
  
    else if(strcmp(s,"FRI")==0)
       printf("2");
  
    else if(strcmp(s,"SAT")==0)
       printf("1");
  
    else 
       printf("7");
}


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

using namespace std;

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  string s; cin >> s;
  string t; cin >> t;
  int n = (int)s.size();
  int m = (int)t.size();
  set<string> res;
  REP(i,n) {
    if (i+m > n) break;
    string u = s.substr(i,m);
    REP(j,m) if (u[j] == '?') u[j] = t[j];
    if (u.compare(t) == 0) {
      string v;
      REP(j,i) v += s[j] == '?' ? 'a' : s[j];
      v += u;
      FOR(j,i+m,n) v += s[j] == '?' ? 'a' : s[j];
      res.insert(v);
    }
  }
  if (res.size()) {
    cout << *res.begin() << endl;
  } else
    puts("UNRESTORABLE");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;
    
#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;
    
int n;
multiset<int> a;
int ans[100000][2];
int result;
int in;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    rep(i,n){
        cin >> in;
        a.insert(in);
    }
    
    for(int i=0; i<n-2; i++){
        /*
        cout << "\t";
        for(int j=0; j<a.size(); j++){
            cout << a[j] << " ";
        }
        cout << endl;
        */
       auto target = a.begin();
       target ++; 
       auto bottom = a.end();
       bottom --;

        if(*target <= 0){
            ans[i][0] = *bottom;
            ans[i][1] = *target;
            a.erase(target);
            a.erase(bottom);
            a.insert(ans[i][0] - ans[i][1]);
        }else{
            ans[i][0] = *a.begin();
            ans[i][1] = *target;
            a.erase(target);
            a.erase(a.begin());
            a.insert(ans[i][0] - ans[i][1]);
        }
    }
    
        // cout << "\t";
        // for(int j=0; j<a.size(); j++){
        //     cout << a[j] << " ";
        // }
        // cout << endl;
    auto itr = a.begin();
    ans[n-2][1] = *itr;
    itr ++;
    ans[n-2][0] = *itr;
    //cout << "a:" << ans[n-2][0] << "\tb:" << ans[n
    result = ans[n-2][0] - ans[n-2][1];
    
    cout << result << endl;
    for(int i=0; i<n-1; i++){
        cout << ans[i][0] << " " << ans[i][1] << endl;
    }
    
    return 0;
}

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

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

    switch(a+b)
    {
    case 3: 
    cout << 3;
    break;
    case 4: 
    cout << 2;
    break;
    case 5:
    cout << 1;
    break;
    }
    cout << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int A, B, C, X;
  std::cin >> A;
  std::cin >> B;
  std::cin >> C;
  std::cin >> X;

  int count = 0;

  if (X%50!=0) {
    cout << 0 << endl;
    return 0;
  }
  
  for (int a = 0; a <= X/500 && a <= A; ++a) {
    int xa = X - 500*a;
    for (int b = 0; b <= xa/100 && b <= B; ++b) {
      int xb = xa - 100*b;
      if (xb%50==0 && xb/50 <= C ) {
	++count;
      }
    }
  }
  
  std::cout << count << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<vector>
using namespace std;
int N, Q;
int l, r;
int main(){
  string S;
  cin >> N >> Q;
  cin >> S;
  map<int, int> f;
  vector<int> sum(N, 0);
  for(int i=0; i<N; i++){
    if (S[i] == 'A' && S[i+1] == 'C') f[i] =1;
    else f[i] =0;
    if (i==0) sum[i] =f[i];
    else sum[i] =sum[i-1] +f[i];
  }
  for(int i=0; i<Q; i++){
    cin >> l >> r ;
    if(l>1){
      cout << sum[r-2] -sum[l-2] << endl;
    }
    else cout << sum[r-2] << endl;
  }
  return 0;
}

Measured memory_bytes: 6016
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v1;
    int tmp=6;
    v1.push_back(1);
    while(tmp<=100000){
        v1.push_back(tmp);
        tmp*=6;
    }
    tmp=9;
    while(tmp<=100000){
        v1.push_back(tmp);
        tmp*=9;
    }
    
    int ans=0;
    int dp[n+1];
    int inf=1000000;
    for(int i=0; i<=n; i++){
        dp[i]=inf;
    }
    dp[0]=0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<v1.size(); j++){
            if(i>=v1[j]){
                dp[i]=min(dp[i], dp[i-v1[j]]+1);
            }
        }
    }
    cout << dp[n] << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define arena ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main()
{
    arena
    ll x;
    cin>>x;
    for(ll i=0;i<=3900;i++)
    {
        for(ll j=0;j<=3900;j++)
        {
            ll a=i*i*i*i*i;
            ll b=j*j*j*j*j;
            if(a-b==x)
         {   cout<<i<<" "<<j;
            return 0;
        }
            if(a+b==x)
          {  cout<<i<<" "<<-j;
          return 0;}
        }
    }
}

Measured memory_bytes: 3628
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


h = fetch_int_input()[0]

count = 0
def attack(tmp_h):
    global count
    if tmp_h > 1:
        attack(tmp_h / 2)
        attack(tmp_h / 2)
        count += 1
    else:
        count += 1
        return
import math
while h >= 1:
    h = math.floor(h / 2)
    count += 1

answer = 0
for i in range(count):
    answer += pow(2, i)
print(answer)



Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int n;
ll m;
vector<int> a;

// k以上のものがいくつか
ll f(ll k) {
    ll p = 0;
    for (int i = 0; i < n; i++) {
        p += a.end() - lower_bound(a.begin(), a.end(), k - a[i]);
    }
    return p;
}

int main() {
    cin >> n >> m;
    a.resize(n);
    vector<ll> b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        b[i] = a[i];
        if (i > 0) b[i] += b[i - 1];
    }
    constexpr int INF = 1e9 + 6;
    ll l = 0, r = INF;
    while (r - l > 1) {
        ll mid = l + (r - l) / 2;
        if (f(mid) <= m) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll s = lower_bound(a.begin(), a.end(), r - a[i]) -a.begin() - 1;
        if (s >= 0) {
            ans += b[n - 1] - b[s];
            ans += ll(n - 1 - s) * a[i];
        }
        else {
            ans += b[n - 1];
            ans += ll(n) * a[i];
        }
    }
    cout << ans + (m - f(r)) * l << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
    double n, m, d;
    cin >> n >> m >> d;
    if (d < 1e-9)
        cout << setprecision(9) << (n - d) * (m - 1) / (n * n) << "\n";
    else
        cout << setprecision(9) << (n - d) * 2 * (m - 1) / (n * n) << "\n";
    return 0;
}


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

typedef struct Amd {
	int h, p, q;
	bool operator<(const Amd &a) {
		return h < a.h;
	}
}Amd;

int n, m, a;
int t[101];
Amd amd[1000];

int main(){
	while (cin >> n >> m >> a && n != 0) {
		for (int i = 1; i <= n; i++) {
			t[i] = i;
		}
		for (int i = 0; i < m; i++) {
			cin >> amd[i].h >> amd[i].p >> amd[i].q;
		}
		sort(amd, amd + m);
		for (int i = 0; i < m; i++) {
			int r = t[amd[i].p];
			t[amd[i].p] = t[amd[i].q];
			t[amd[i].q] = r;
		}
		cout << t[a] << endl;
	}

	return 0;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
int Next[N*2],Head[N],To[N*2],Val[N*2],cnt;
int tag[N],x[N],y[N],z[N];
int n,m;
bool vis[N];
void add(int u, int v, int w){
    ++cnt; Next[cnt] = Head[u]; 
    Head[u] = cnt; To[cnt] = v; Val[cnt] = w;
}
void dfs(int u,int fa, int now){
    vis[u] = 1;
    for (int i = Head[u]; i; i = Next[i]){
        int v = To[i];
        if (vis[To[i]]) continue;
        dfs(v,u,Val[i]);
    }
    if (tag[u]){
        tag[u] ^= 1; tag[fa]^=1;
        z[now] = -z[now];
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for (int i = 0; i < m; ++i){
        scanf("%d%d",&x[i],&y[i]); z[i] = 1;
        add(x[i],y[i],i); add(y[i],x[i],i);
        tag[x[i]]^=1;
    }
    if (m & 1){
        puts("-1"); return 0;
    }
    dfs(1,0,0);
    for (int i = 0; i < m; ++i){
        if (z[i] > 0) printf("%d %d\n",x[i],y[i]); else printf("%d %d\n",y[i],x[i]);
    }
    return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct mint{
	ll x;
	mint(ll x=0):x((x%mod+mod)%mod){}
	friend ostream &operator<<(ostream& os,const mint& a){
		return os<<a.x;
	}
	friend istream &operator>>(istream& is,mint& a){
		ll t;
		is>>t;
		a=mint(t);
		return (is);
	}
	mint& operator+=(const mint a){
		if((x+=a.x)>=mod) x-=mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x+=mod-a.x)>=mod)x-=mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x*=a.x)%=mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if (!t) return 1;
		mint a=pow(t>>1);
		a*=a;
		if(t&1) a*=*this;
		return a;
	}
	// for prime mod
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this)*=a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
};

struct combination{
  vector<mint> fact,ifact;
  combination(int n):fact(n+1),ifact(n+1){
	assert(n<mod);
	fact[0]=1;
	for(int i=1;i<=n;i++) fact[i]=fact[i-1]*i;
	ifact[n]=fact[n].inv();
	for(int i=n;i>=1;i--) ifact[i-1]=ifact[i]*i;
  }
  mint operator()(int n,int k){
	if (k<0 || k>n) return 0;
	return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,m,k;
	cin>>n>>m>>k;
	mint ans=0;
	combination comb(n*m+100);
	rep(d,n){
		ans+=comb(n*m-2,k-2)*m*m*(n-d)*d;
	}
	rep(d,m){
		ans+=comb(n*m-2,k-2)*n*n*(m-d)*d;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int K, A, B;

int main() {

	cin >> K >> A >> B;

	for (int i = A; i <= B; ++i) {
		if (i % K == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}


	cout << "NG" << endl;

	return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int H, W, N; cin >> H >> W >> N;
  if (H < W) swap(H, W);
  int ans = N / H;
  if (N % H != 0) ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;

int main(){
  int H,n;
  cin>>H>>n;
  vector<int>dp(H+1,INF);
  dp[0] = 0;
  while(n--){
  	int value,cost;
    cin>>value>>cost;
    for(int i = 0;i<=H;i++){
      int j = min(H,i+value);
      dp[j]=min(dp[j], dp[i]+cost);
    }
  }
      cout<<dp[H];
}

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

int main() {
  string ans = "Three";
  int N;
  cin >> N;
  for (int i = 0; i < N; i++){
    char s;
    cin >> s;
    if (s == 'Y'){
    ans = "Four";
    break;
    }
  }
   cout << ans << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, s, sum = 0, ch = INF;
  cin >> n;
  rep(i, n) {
    cin >> s;
    sum += s;
    if(s % 10) ch = min(ch, s);
  }
  if(sum % 10) cout << sum << endl;
  else if(ch == INF) cout << 0 << endl;
  else cout << sum - ch << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
    int n;
    cin >> n;
    map<string,int> mp;
    rep(i,n){
        string a;
        cin >> a;
        mp[a]++;
    }
    cout << mp.size() << endl;
}

Measured memory_bytes: 19256
import sys


def binsearch(x, s):
    l = 0
    r = len(s)
    while (l < r):
        m = int((l + r) / 2)
        if s[m] == x:
            return True
        else:
            if s[m] < x:
                l = m + 1
            else:
                r = m
    return False


ns = sys.stdin.readline()
s = [int(i) for i in sys.stdin.readline().split()]
nt = sys.stdin.readline()
t = [int(i) for i in sys.stdin.readline().split()]

cnt = 0
for x in t:
    if binsearch(x, s):
        cnt += 1
print(cnt)

Measured memory_bytes: 16360
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;


int main()
{
	
	string s,t;
	cin >> s >> t;
	
	cout << t+s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    double r;
    scanf("%lf", &r);
    const double PI=3.141592653589643;
    printf("%.10lf %.10lf\n",PI*r*r, 2*PI*r );
    return 0;
}



Measured memory_bytes: 2708
#D問題
N = int(input())

flag = 0
for i in range(2*N):
    I = i+1
    if I*(I+1) == 2*N:
        k = I+1
        flag = 1
        break
        
if flag == 0:
    print("No")
else:
    print("Yes")
    print(k)
    ans = [[] for i in range(k)]
    now = 0
    for i in range(k-1):
        loop = 1+i
        for j in range(loop):
            now+=1
            if j == 0:
                ans[0].append(now)
            if j == loop-1:
                ans[-1].append(now)
            if j > 0 and j < loop-1:
                ans[j].append(now)
            if i != 0:
                ans[i].append(now)
            
    for a in ans:
        print(len(a),end=" ")
        print(*a)

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            if(i * 4 + j * 7 == n)
                return cout << "Yes\n", 0;
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
def get_path(current, goal, edges, path)
  next_edges = edges.select{ |e| e[0,2].include?(current) }
  next_nodes = next_edges.map{ |e| e[0,2].select{|x| x!=current}.first }

  next_nodes.map do |n|
    if n == goal
      path + [n]
    elsif path.include?(n)
      nil
    else
      get_path(n, goal, edges, path + [n])
    end
  end
end

def construct_paths(start, goal, edges, edges_cost)
  paths = []
  i = 0

  get_path(start, goal, edges, [start]).flatten.each do |x|
    if x.nil?
      i += 1
      next
    elsif x == goal
      paths[i] << x
      i += 1
    elsif paths[i].nil?
      paths[i] = [x]
    else
      paths[i] << x
    end
  end
  paths.compact
end

def cost_of_paths(start, goal, edges, edges_cost)
  costs = construct_paths(start, goal, edges, edges_cost).map do |path|
    cost = 0
    path.each.with_index { |x,i|cost += edges_cost[[path[i], path[i+1]]] unless i == path.size-1 }
    cost
  end
  costs.min
end

if __FILE__ == $0
  n = gets.to_i
  m = gets.to_i

  edges = []
  edges_cost = {}

  m.times do
    a, b, c, d = gets.chomp.split(',').map(&:to_i)
    edges << [a, b, c, d]
    edges_cost[[a,b]] = c
    edges_cost[[b,a]] = d
  end

  start, goal, money, tree_cost = gets.chomp.split(',').map(&:to_i)

  total_cost = tree_cost + cost_of_paths(start, goal, edges, edges_cost) + cost_of_paths(goal, start, edges, edges_cost)

  p money - total_cost
end

Measured memory_bytes: 6144
from collections import Counter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
n = int(input())
edges = [[] for _ in range(n * 1001)]
memo = []
start = set()
for i in range(n):
    A = list(map(int, input().split()))
    for j in range(n-1):
        if i < A[j] - 1:
            A[j] = i * 1000 + A[j] - 1
        else:
            A[j] = (A[j] - 1) * 1000 + i

    for j in range(n-2):
        edges[A[j]].append(A[j+1])
    memo.append(A[0])

memo = Counter(memo).most_common()
for x, t in memo:
    if t > 1:
        start.add(x)

#閉路検出/最長のパス
d = [-1 for _ in range(1001 * n)]
def dfs(v):
    d[v] = -2
    l = 0
    for to in edges[v]:
        if d[to] == -2:
            print(-1)
            exit()
        if d[to] == -1:
            dfs(to)
        l = max(l, d[to] + 1)
    d[v] = l

if len(start) == 0:
    print(-1)
    exit()
for i in start:
    dfs(i)
print(max(d) + 1)

Measured memory_bytes: 174820
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	h := scanInt()
	n := scanInt()

	as := make([]int, n)
	bs := make([]int, n)

	for i := 0; i < n; i++ {
		as[i] = scanInt()
		bs[i] = scanInt()
	}

	dp := make([]int, h+1)
	for i := 0; i < h+1; i++ {
		dp[i] = (1 << 31)-1
	}

	dp[0] = 0

	for i := 0; i < n; i++ {
		for j := 0; j < h+1; j++ {
			if j+as[i] < h {
				dp[as[i]+j] = min(dp[as[i]+j], dp[j]+bs[i])
			} else {
				dp[h] = min(dp[h], dp[j]+bs[i])
			}
		}
		// fmt.Println(dp)
	}

	fmt.Println(dp[h])
}

func min(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] { res = a[i] }
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] { res = a[i] }
	}
	return res
}


Measured memory_bytes: 768