akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int S, n;
	cin >> S >> n;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	int mx = *max_element(a.begin(), a.end());
	if (mx > (S + 1) / 2) {
		cout << (mx - (S + 1) / 2) * 2 - (S % 2 == 0) << endl;
	} else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 3624
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

char s[100005];
ll a[100005];
int main()
{
  ll n, q, x, y;
  scanf("%lld%lld%s", &n, &q, &s[1]);
  for (int i = 1; i <= n; i++)
  {
    a[i] = a[i - 1];
    if (s[i - 1] == 'A' && s[i] == 'C')
    {
      a[i]++;
    }
  }
  for (int i = 0; i < q; i++)
  {
    scanf("%lld%lld", &x, &y);
    printf("%lld\n", a[y] - a[x]);
  }
  return 0;
}

Measured memory_bytes: 1664
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }


#include<iostream>
#include<vector>
#include<functional>

using namespace std;

template <typename T>
struct SegmentTree
{
    using F = function<T(T, T)>;
    int n;
    F f;
    T ti;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f, T ti) : f(f), ti(ti) {}
    void init(int n_)
    {
        n = 1;
        while (n < n_)
            n <<= 1;
        dat.assign(n << 1, ti);
    }

    void build(const vector<T> &v)
    {
        int n_ = v.size();
        init(n_);
        for (int i = 0; i < n_; i++)
            dat[n + i] = v[i];
        for (int i = n - 1; i; i--)
            dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }

    // v[k] = x (0-indexed)
    void set(int k, T x)
    {
        dat[k += n] = x;
        while (k >>= 1)
            dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }

    // get F(v[a], v[a + 1], ... , v[b - 1]) (0-indexed)
    T query(int a, int b)
    {
        T vl = ti, vr = ti;
        for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1)
        {
            if (l & 1)
                vl = f(vl, dat[l++]);
            if (r & 1)
                vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }
};

using namespace std;
const int INF = (1u << 31) - 1;
int gcd(int a, int b) {
    if (a == INF || b == INF) return min(a, b);
    if (a == 0) return b;
    return gcd(b % a, a);
}

int n;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    SegmentTree<int> seg(gcd, INF);
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    seg.build(v);
    int ans = seg.query(0, n);
    REP(i, n) {
        ans = max(ans, gcd(seg.query(0, i), seg.query(i + 1, n)));
        // DDD(i, seg.query(0, i), seg.query(i + 1, n));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	string s;
	cin >> s;
	int sn = s.size();
	sn /= 2;
	while (1)
	{
		bool isans = true;
		sn --;
		for(int i = 0;i<sn;i++)
		{
			if(s[i]!=s[i+sn])isans = false;
		}
		if(isans)
		{
			cout<<sn*2<<endl;
			return 0;
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 256
W, H, N = map(int, input().split())
li = []
for i in range(N):
  li.append(list(map(int, input().split())))

a1, a2, a3, a4 = [], [], [], []

for i in range(N):
  if li[i][2] == 1:
    a1.append(li[i])
  elif li[i][2] == 2:
    a2.append(li[i])
  elif li[i][2] == 3:
    a3.append(li[i])
  elif li[i][2] == 4:
    a4.append(li[i])

a1XMAX, a2Xmin, a3YMAX, a4Ymin = 0, W, 0, H
    
if a1 == []:
  pass
else:
  for i in range(len(a1)):
    a1XMAX = max(a1[i][0], a1XMAX)

if a2 == []:
  pass
else:
  for i in range(len(a2)):
    a2Xmin = min(a2[i][0], a2Xmin)
    
if a3 == []:
  pass
else:
  for i in range(len(a3)):
    a3YMAX = max(a3[i][1], a3YMAX)

if a4 == []:
  pass
else:
  for i in range(len(a4)):
    a4Ymin = min(a4[i][1], a4Ymin)

if a1XMAX >= a2Xmin or a3YMAX >= a4Ymin:
  result = 0
  print(result)
  exit()
else:
  result = (a2Xmin - a1XMAX) * (a4Ymin - a3YMAX)
  print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const int MAXN = 1e5+1;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	vector<int> cnt(MAXN);
	for(int i = 0; i < n; i++){
		cnt[a[i]]++;
	}

	int res = cnt[0]+cnt[1];
	for(int i = 1; i < MAXN; i++){
		int x = cnt[i-1]+cnt[i]+cnt[i+1];
		if(x > res){
			res = x;
		}
	}

	cout << res << endl;

	return 0;
}

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

using namespace std;

int a[30];
char ch;
int main()
{
    while(scanf("%c",&ch)!=EOF){
        if(ch >= 'A' && ch <= 'Z') {ch += 32;}
        if(ch>='a' && ch<='z'){a[ch-'a']++;}
        
    }
    for(char c='a';c<='z';c++){
        printf("%c : %d\n",c,a[c-'a']);
    }
    

    return 0;
}



Measured memory_bytes: 3228
import java.util.*;

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

        char[] S = sc.next().toCharArray();
        int one = 0;
        int zero = 0;
        int answer = 0;

        for (char c : S) {
            if (c == '1') {
                one++;
            } else {
                zero++;
            }
            if (one > 0 && zero > 0) {
                answer += 2;
                one--;
                zero--;
            }
        }

        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 39236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    ll x, y;
    cin >> x >> y;
    if (x % y == 0)
        cout << -1 << endl;
    else
        cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    while (true) {
        ll n = in(), m = in();
        if (n == 0 && m == 0)break;
        ll tsum = 0, hsum = 0;
        vector<ll>t(n), h(m);
        REP(i, n)tsum += t[i] = in();
        REP(i, m)hsum += h[i] = in();
        pair<ll, ll>ans(INFLL, INFLL);
        REP(i, n) {
            REP(j, m) {
                if (tsum - t[i] + h[j] == hsum - h[j] + t[i]) {
                    if (ans.first + ans.second > t[i] + h[j]) {
                        ans = make_pair(t[i], h[j]);
                    }
                }
            }
        }
        if (ans.first == INFLL && ans.second == INFLL) {
            cout << -1 << endl;
        } else {
            cout << ans.first << ' ' << ans.second << endl;
        }
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
int po[111111];
int N,M;
int G[15][15];

int num[1<<15];

int dp[2][1<<15];

int outer[1<<15];

signed main(){
    po[0]=1;
    for(int i=1;i<111111;i++)po[i]=po[i-1]*2%mod;

    cin>>N>>M;
    rep(i,M){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a][b]=G[b][a]=1;
    }

    rep(i,1<<N){
        rep(j,N){
            if(!(i>>j&1))continue;
            for(int k=j+1;k<N;k++){
                if(!(i>>k&1))continue;
                if(G[j][k])num[i]++;
            }
        }
    }

    rep(i,1<<15){
        rep(j,N){
            if(!(i>>j&1))continue;
            rep(k,N){
                if(i>>k&1)continue;
                if(G[j][k])outer[i]|=1<<k;
            }
        }
    }

    rep(s,2){
        rep(i,1<<N){
            if(!(i>>s&1))continue;
            int ei=po[num[i]];
            int sup=i^(1<<s);
            int sub=sup;
            do{
                if(sub!=sup){
                    int tmp=dp[s][sub|(1<<s)];
                    tmp=tmp*po[num[i^sub^(1<<s)]]%mod;
                    ei=(ei-tmp+mod)%mod;
                }
                sub=(sub-1)&sup;
            }while(sub!=sup);
            dp[s][i]=ei;
        }
    }

    int ans=po[M];
    rep(i,1<<N){
        if(!(i&1))continue;
        if(i>>1&1)continue;

        int sup=((1<<N)-1)^i^outer[i];
        if(!(sup>>1&1))continue;
        int sub=sup;

        do{
            if(sub>>1&1){
                int tmp=dp[1][sub];
                tmp=tmp*dp[0][i]%mod;
                tmp=tmp*po[num[((1<<N)-1)^i^sub]]%mod;
                ans=(ans-tmp+mod)%mod;
            }
            sub=(sub-1)&sup;
        }while(sub!=sup);
    }

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


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  while(cin >> N, N){
	vector<PLL> xs(N);
	set<PLL> cnt;
	REP(i,N){
	  cin >> xs[i];
	  cnt.insert(xs[i]);
	}

	LL ans = 0;
	REP(i1,N) REP(i2,N){
	  if(i1 == i2) continue;
	  PLL dp(xs[i2].FF - xs[i1].FF, xs[i2].SS - xs[i1].SS);
	  if((cnt.count(MP(xs[i1].FF - dp.SS, xs[i1].SS + dp.FF)) &&
		  cnt.count(MP(xs[i2].FF - dp.SS, xs[i2].SS + dp.FF))) ||
		 (cnt.count(MP(xs[i1].FF + dp.SS, xs[i1].SS - dp.FF)) &&
		  cnt.count(MP(xs[i2].FF + dp.SS, xs[i2].SS - dp.FF)))
		 ){
		maxi(ans, dp.FF*dp.FF + dp.SS*dp.SS);
	  }
	}
	cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3332
#include<stdio.h>

#define ABS(x) (((x)<0)?(-(x)):(x))
#define MAX(x,y) (((x)>(y))?(x):(y))

int main(void){
  int N,Z,W,an,anm;
  int i,j,k;
  scanf("%d%d%d",&N,&Z,&W);
  if(N!=1){
    for(i=0;i<N-2;i++) scanf("%*d");
    scanf("%d%d",&anm,&an);
  }else{
    scanf("%d",&an);
    anm=W;
  }
  printf("%d\n",MAX(ABS(an-anm),ABS(W-an)));
  return 0;
}
	 


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#define MAX 101
#define INF 2001

int main(){
  int i,j,n,u,v,result=0,mincost,A[MAX][MAX],color[MAX],d[MAX],pi[MAX];

  scanf("%d",&n);
  for(i=1 ; i<=n ; i++){
    for(j=1 ; j<=n ; j++){
      scanf("%d",&A[i][j]);
      if(A[i][j]==-1)A[i][j]=INF;
    }
  }

  for(u=1 ; u<=n ; u++){
    d[u]=INF;
    color[u]=0;
  }
  d[1]=0;

  while(1){
    mincost=INF;
   for(i=1 ; i<=n ; i++){
     if(color[i] != 1 && d[i] < mincost){
       mincost=d[i];    
       u=i;
     }
   }
   
     if(mincost==INF)break;
     color[u] = 1;

     for(v=1 ; v<=n ; v++){
       if(color[v] != 1 && A[u][v] < d[v]){
	 d[v]=A[u][v];
       }
     }
  }
  
  for(i=1 ; i<=n ; i++){
    result += d[i];
  }

  printf("%d\n",result);

  return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++)
        cin >> H[i];
    for (int i = 1; i < N; i++)
    {
        if (H[i - 1] > H[i])
        {
            cout << "No" << endl;
            return 0;
        }
        else
        {
            if (H[i] != H[i - 1])
            {
                H[i] -= 1;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

k = int(input())

ans = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += math.gcd(math.gcd(a,b),c)

print(ans)


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

int main() {
	string s;
	cin >> s;
	string ans;
	ans.push_back(s[0]);
	for (int i = 1;i < s.size();++i) {
		if (i % 2 == 0)ans.push_back(s[i]);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 512
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($N,$M) =  explode(" ",trim(fgets(STDIN)));
//$A = explode(" ",trim(fgets(STDIN)));

$k = 0;
for($i=0;$i<$N;$i++) {
  if (($i%2)==0)
  $k++;
}
printf("%f\n",$k/$N);


Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const ll MOD = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N;
	cin >> N;

	vector<ll> V(N);

	for(auto &a : V) cin >> a;

	vector<ll> S(N);

	S[N-1] = V[N-1];

	for(int i = N - 2; i >= 0; i--) S[i] = (V[i] + S[i+1]) % MOD;

	ll ans = 0;

//	for(int i = 0; i < N; i++) cout << S[i] << " "; cout << endl;

	vector<int> F(N - 1);

	for(int i = 0; i < N - 1; i++) F[i] = (V[i]*S[i+1]) % MOD;

	for(int i = 0; i < N - 1; i++){
		ans = (ans + F[i]) % MOD;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 7136
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;
#define ll long long

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

    int a,b;
    cin>>a>>b;

    int s = a+b;
    int p = a*b;
    int d = a-b;

    cout<<((s>p)?((s>d)?s:d):(p>d)?p:d);

    return 0;
}

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

#print(chr((N%26)+96))
str = []

while N > 0:
    if N%26 == 0 :
        str.append("z")
        N//=26
        N -=1
    else:
        str.append(chr((N%26)+96))
        N //= 26
    # print(N)

#print(str)

for i in reversed(range(len(str))):
    print(str[i],end="")

Measured memory_bytes: 9192
#include <cstdio>
#include <algorithm>

#define MAX 100000
#define SENTINEL 2000000000

struct Card {
	char suit;
	int value;
};

Card L[MAX / 2 + 2], R[MAX / 2 + 2];

int partition(Card *A, int n, int p, int r) {
	Card x = A[r];
	int i = p - 1;
	Card t;
	for (int j = p; j < r; j++) {
		if (A[j].value <= x.value) {
			i++;
			//t = A[i]; A[i] = A[j]; A[j] = t;
			std::swap(A[i], A[j]);
		}
	}
	std::swap(A[i + 1], A[r]);
	//t = A[i+1]; A[i+1] = A[r]; A[r] = t;
	return i + 1;
}

void merge(Card *A, int n, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1].value = R[n2].value = SENTINEL;
	int i = 0;
	int j = 0;
	for (int k = left; k < right; k++) {
		if (L[i].value <= R[j].value) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
		}
	}
	return;
}

void quickSort(Card *A, int n, int p, int r) {
	if (p < r) {
		int q = partition(A, n, p, r);
		quickSort(A, n, p, q - 1);
		quickSort(A, n, q + 1, r);
	}
	return;
}

void mergeSort(Card *A, int n, int left, int right) {
	if (left+1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
	return;
}

int main() {
	int n = 0;
	scanf("%d", &n);
	Card A[MAX], B[MAX];
	char ctmp[10];
	int vtmp=0;
	for (int i = 0; i < n; i++) {
		scanf("%s %d", ctmp, &vtmp);
		A[i].suit = B[i].suit = ctmp[0];
		A[i].value = B[i].value = vtmp;
	}
	mergeSort(A,n,0,n);
	quickSort(B, n, 0, n - 1);
	int stable = 1;
	for (int i = 0; i < n; i++) {
		if (A[i].suit != B[i].suit) {
			stable = 0;
		}
	}
	if (stable) printf("Stable\n");
	else printf("Not stable\n");

	for (int i = 0; i < n; i++) {
		printf("%c %d\n", B[i].suit, B[i].value);
	}
	return 0;
}

Measured memory_bytes: 5092
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.*;

public class Main{
	static boolean temp[]=new boolean[24];
	static int time[]=new int[13];
	static int ans=0;
	public static void main(String[] args) throws IOException {
		StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
		in.nextToken();
		int n=(int)in.nval;
		time[0]=1;
		boolean judge=true;
		for(int i=0;i<n;i++){
			in.nextToken();
			int t=(int)in.nval;
			time[t]++;
			if((t==12||t==0)&&time[t]>1)judge=false;
			else if(time[t]>2)judge=false;
		}
		if(judge){
			Arrays.fill(temp, false);
			temp[0]=true;
			dfs(1);
			out.println(ans);
		}else out.println(0);
		out.flush();
	}
	static void dfs(int now){
		if(now==13){
			int ans1=Integer.MAX_VALUE;
			int pos=0;
			for(int i=1;i<24;i++){
				if(temp[i]){
					ans1=Math.min(ans1, i-pos);
					pos=i;
				}
			}
			ans1=Math.min(ans1, 24-pos);
			ans=Math.max(ans, ans1);
		}else if(time[now]==1){
			temp[now]=true;
			dfs(now+1);
			temp[now]=false;
			temp[24-now]=true;
			dfs(now+1);
			temp[24-now]=false;
		}else if(time[now]==2){
			temp[now]=true;
			temp[24-now]=true;
			dfs(now+1);
		}else dfs(now+1);
	}
}


Measured memory_bytes: 23252
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
int N, M, X[Nmax], Y[Nmax];

int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++){
		cin >> X[i] >> Y[i];
		X[i]--; Y[i]--;
	}

	vector<int> ur(N), uw(N), lr(N), lw(N), t(N);
	ur[0]=lr[0]=t[0]=1;
	for(int i=1; i<N; i++) uw[i]=lw[i]=t[i]=1;

	for(int i=0; i<M; i++){
		t[X[i]]--;
		t[Y[i]]++;
		if(uw[X[i]]==0){
			ur[X[i]]--;
			lr[X[i]]--;
			ur[Y[i]]++;
			lr[Y[i]]++;
		} else if(ur[X[i]]==0){
			uw[X[i]]--;
			lw[X[i]]--;
			uw[Y[i]]++;
			lw[Y[i]]++;
		} else {
			lr[X[i]] = max(0, lr[X[i]]-1);
			lw[X[i]] = max(0, lw[X[i]]-1);
			ur[Y[i]]++;
			uw[Y[i]]++;
		}
		if(t[X[i]]==0){
			lr[X[i]]=ur[X[i]]=lw[X[i]]=uw[X[i]]=0;
		}
	}

	int ans = 0;
	for(int i=0; i<N; i++){
		if(t[i]>0 && ur[i]>0) ans++;
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'


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


const int MOD = 1000000007;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  int a[20], b[20], c[20];
  int sum = 0;

  cin >> n;


  for(int i = 0; i < n; i++) {


     cin >> a[i];
  }

   for(int i = 0; i < n; i++) {


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


     cin >> c[i];
  }



  sum += b[a[0]-1];

  for(int i = 1; i < n; i++) {

     sum += b[a[i]-1];

     if(a[i] == a[i-1] + 1) {

        sum+= c[a[i-1]-1];
     }


  }

  cout << sum << endl;



}



Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

int main(){

	int N,M,P;
	scanf("%d %d %d",&N,&M,&P);

	int tmp;
	bool start_FLG = false;
	priority_queue<int> Q;

	for(int loop = 0; loop < M; loop++){
		scanf("%d",&tmp);

		//??????????§????0?????????
		if(tmp < P){
			tmp = N + (tmp-P);
		}else if(tmp == P){
			start_FLG = true; //?????????????§??????????????§???¨???????????´?????????????????§?????????
			tmp = 0;
		}else{
			tmp -= P;
		}
		Q.push(tmp);
	}

	int index,max_index;
	int* table;

	if(start_FLG == false){
		Q.push(0);
		table = new int[M+1];
		max_index = M+1;
		index = M;
	}else{
		table = new int[M];
		max_index = M;
		index = M-1;
	}

	while(!Q.empty()){
		table[index--] = Q.top();
		Q.pop();
	}

	int minimum = 0;

	minimum = min(table[max_index-1],N-table[1]);

	//1???base?????§???????¨???¨??????N-1???base+1?????§??????????¨???¨???<<????????????????????????????????????!!!>>
	for(int base = 1; base <= max_index-2;base++){
		if(table[base]> N-table[base+1]){
			tmp = 2*(N-table[base+1])+table[base];
		}else{
			tmp = 2*table[base] + (N-table[base+1]);
		}
		minimum = min(minimum,tmp);
	}

	printf("%d\n",minimum*100);

    return 0;
}

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

typedef long long lint;
typedef pair<int, int> pii;

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int n; pii P[MAX];

int solve1(){
	int l = P[1].first, r = P[1].second, s = 0;
	for(int i=1; i<=n; i++){
		l = max(l, P[i].first), r = min(r, P[i].second);
		s = max(s, P[i].second - P[i].first+1);
	}
	return max(r-l+1, 0) + s;
}

int solve2(){
	sort(P+1, P+n+1, [](pii a, pii b){
		return a.second<b.second || (a.second==b.second && a.first>b.first);
	});
	vector<pii> V;
	for(int i=1, l=0; i<=n; i++){
		int x,y; tie(x,y) = P[i];
		if(l<x) V.push_back(P[i]);
		l = max(l, x);
	}

	int m = V.size(), ans = 0;
	for(int i=0; i<m-1; i++){
		int lf = V[0].second - V[i].first+1;
		int ri = V[i+1].second - V[m-1].first+1;
		ans = max(ans, max(0,lf) + max(0,ri));
	}
	return ans;
}

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

	cin>>n;
	for(int i=1; i<=n; i++) cin>>P[i].first>>P[i].second;

	int ans = max(solve1(), solve2());

	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 2168
import sys
def s():
 e=sys.stdin.readline
 n,m=map(int,e().split())
 P=[[]for _ in[0]*n]
 C=[0]*n
 k=0
 for _ in[0]*m:
  s,t=map(int,e().split());P[s]+=[t];P[t]+=[s]
 for i in range(n):
  k+=1
  if C[i]<1:
   s=[i];C[i]=k
   while s:
    u=s.pop()
    for v in P[u]:
     if C[v]<1:C[v]=k;s+=[v]
 for _ in[0]*int(e()):
  a,b=map(int,e().split())
  print(['no','yes'][C[a]==C[b]])
s()


Measured memory_bytes: 24084
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int[][] memo= new int[33][33];
        int[][] mapt = new int[33][33];
        int[][] mapy = new int[33][33];
        int h,w,i,j,nx,ny;
        Queue<Integer> x =new LinkedList<Integer>();
        Queue<Integer> y =new LinkedList<Integer>();
        while(true){
            w = s.nextInt();
            h = s.nextInt();
            if(h+w==0)break;
            for(i=1;i<2*h;i++){
                if(i%2==1)for(j=1;j<w;j++)mapt[i/2+1][j]=1-s.nextInt();
                else for(j=1;j<=w;j++)mapy[i/2][j]=1-s.nextInt();
            }
            x.add(1);
            y.add(1);
            memo[1][1]=1;
            while(x.size()>0&&y.size()>0){
                nx = x.remove();
                ny = y.remove();
                if(mapt[nx][ny-1]==1&&memo[nx][ny-1]==0){
                    x.add(nx);
                    y.add(ny-1);
                    memo[nx][ny-1]=memo[nx][ny]+1;
                }
                if(mapt[nx][ny]==1&&memo[nx][ny+1]==0){
                    x.add(nx);
                    y.add(ny+1);
                    memo[nx][ny+1]=memo[nx][ny]+1;
                }
                if(mapy[nx-1][ny]==1&&memo[nx-1][ny]==0){
                    x.add(nx-1);
                    y.add(ny);
                    memo[nx-1][ny]=memo[nx][ny]+1;
                }
                if(mapy[nx][ny]==1&&memo[nx+1][ny]==0){
                    x.add(nx+1);
                    y.add(ny);
                    memo[nx+1][ny]=memo[nx][ny]+1;
                }
            }
            /*for(i=1;i<=h;i++){
                for(j=1;j<=w;j++){
                    System.out.print(memo[i][j]);
                }
                System.out.println();
            }*/
            System.out.println(memo[h][w]);
            for(i=1;i<2*h;i++){
                if(i%2==1)for(j=1;j<w;j++)mapt[i/2+1][j]=0;
                else for(j=1;j<=w;j++)mapy[i/2][j]=0;
            }
            for(i=0;i<=h;i++)for(j=0;j<=w;j++)memo[i][j]=0;
        }

    }
}


Measured memory_bytes: 70444
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, K;
	int ans = 0;
	int left, right;
	char base;
	string S;

	cin >> N >> K >> S;

	if (N == 1) {
		cout << 0 << endl;
		return 0;
	}

	left = 0;
	right = N - 1;

	rep(i, N - 1) {
		if (S[i] == S[i + 1]) ans++;
	}

	if (S[0] == S[N - 1]) {
		if (S[0] == 'R') base = 'L';
		else base = 'R';
	}
	else {
		base = S[0];

		rep(i, N) {
			if (S[i] == base) left = i;
			else break;
		}
	}

	rep(i, K) {
		for (int j = left + 1; j < N; j++) {
			if (S[j] == base) {
				left = j;
				break;
			}
			else if (j == N - 1) left = N - 1;
		}

		for (int j = right - 1; j >= 0; j--) {
			if (S[j] == base) {
				right = j;
				break;
			}
			else if (j == 0) right = 0;
		}

		if (left <= right) ans += 2;
		else if (S[0] != S[N - 1]) {
			ans++;
			break;
		}
		else break;

		if (base == 'R') base = 'L';
		else base = 'R';
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp> //required
//#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define lb long double
#define pb push_back
#define loop(i,start,n) for(ll i=start;i<n;i++)
#define rloop(i,n,start)for(ll i=n;i>=start;i--)
#define mod 1000000007
#define endl "\n"
#define INF     1e15
#define NEG_INF -1e15
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//using namespace __gnu_pbds;
//template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 


int main(){
	IOS;
	ll n;
	cin >> n;
	ll a[n + 1], b[n + 1];
	loop(i, 1, n + 1)
		cin >> a[i];

	multiset<ll> s, pos;
	loop(i, 1, n + 1){
		cin >> b[i];
		s.insert(b[i]);
	}

	vector<ll> common, ori;
	ll rot = 0;
	map<ll, ll> mp;
	loop(i, 1, n + 1){
		if(s.find(a[i]) != s.end()){
			pos.insert(i);
			s.erase(s.find(a[i]));
			ori.pb(a[i]), common.pb(a[i]);
			mp[a[i]]++;
			rot = max(rot, mp[a[i]]);
		}
	}
	debug(common, rot);
	rotate(common.begin(), common.begin() + rot, common.end());
	debug(common);
	ll cnt = 0, no;
	loop(i, 0, ori.size()){
		if(ori[i] == common[i])
			cnt++, no = ori[i];
		
	}

	set<ll> replace;
	loop(i, 1, n + 1){
		if(pos.find(i) == pos.end()){
			b[i] = *(s.begin());
			s.erase(s.begin());

			if(a[i] != no && b[i] != no)
				replace.insert(i);
		}
		
	}

	debug(cnt);
	if(replace.size() < cnt){
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	loop(i, 0, ori.size()){
		if(ori[i] == common[i]){
			assert(ori[i] == no);
			ll curr =  *(replace.begin());
			replace.erase(replace.begin());
			swap(common[i], b[curr]);
		}

		//assert(ori[i] != common[i]);
	}

	ll curr = 0;
	loop(i, 1, n + 1){
		if(pos.find(i) == pos.end())
			cout << b[i] << " ";
		else
			cout << common[curr++] << " ";
	}
}

Measured memory_bytes: 31268
n=int(input())
s=[]
sum10=0
for i in range(n):
    si=int(input())
    if si%10==0:
        sum10=sum10+si 
    else:
        s.append(si)
s.sort()
ssum=sum(s)
if len(s)==0:
    print(0)
elif ssum%10==0:
    ssum=ssum-s[0]
    print(sum10+ssum)
else:
    print(sum10+ssum)
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}
const int maxn = 1e6 + 7;
void solve() {
	int n;
	cin >> n;
	vi a(n), dp(maxn, 1), mp(maxn, 0);
	rep(i, 0, n) {
		cin >> a[i];
		mp[a[i]]++;
	}
	sort(all(a));
	int ans = 0;
	rep(i, 0, n) {
		if (dp[a[i]]) {
			if (mp[a[i]] > 1)dp[a[i]] = 0;
			for (int j = a[i] * 2; j <= maxn; j += a[i]) {
				dp[j] = 0;
			}
		}
	}
	rep(i, 0, n) {
		if (dp[a[i]])
			ans++;
	}
	cout << ans;
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 11800
#include<stdio.h>


int main(void){

	int n;
	int a[20];
	int b[20];
	int c[20];
	int i;
	int ret;
	int past;


	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	for(i=0;i<n;i++){
		scanf("%d",&b[i]);
	}

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

	ret = b[a[0]-1];
	past = 0;
	for(i=1;i<n;i++){
		ret += b[a[i]-1];
		if(a[i-1] == a[i] -1){
			ret += c[a[i]-2];
		}
	}

	printf("%d\n",ret);

	return 0;
}

Measured memory_bytes: 128
/* Author rumoisen */
/* created 2018/10/20 */

#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <iostream>

using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}

using namespace std;

int main(void)
{
    int n,t[114514],x[114514],y[114514];
    cin>>n;
    for(int i=1;i<=n;i++) cin>>t[i]>>x[i]>>y[i];
    t[0]=x[0]=y[0];
    bool can=true;
    for(int i=0;i<n;i++){
        int dt=t[i+1]-t[i],dist=abs(x[i+1]-x[i]+abs(y[i+1]-y[i]));
        if(dist>dt) can=false;
        if(dist%2!=dt%2) can=false;
    }
    if(can) yes();
    else no();
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin>>n;
    set<string> ss;
    rep(i,n){
        string s;
        cin>>s;
        ss.insert(s);
    }
    cout<<ss.size()<<endl;
    return 0;
}

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

int main() {
	string a,b,c;
		char d,e,f;
		cin >> a >> b >> c;
		d=toupper(a[0]);
		e=toupper(b[0]);
		f=toupper(c[0]);
		cout<<d<<e<<f<<endl;

	return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  cout << string(W+2,'#') << endl;
  for(int i=0;i<H;i++){
    string a;
    cin >> a;
    cout << '#' << a << '#' << endl;
  }
  cout << string(W+2,'#') << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int map[60][60];
int main(void) {
	vector<int> list;
	for (;;) {
		int w, h;
		cin >> w >> h;
		if (!(w&&h))return 0;
		int cnt = 1;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				int buf;
				cin >> buf;
				map[i][j] = (buf?cnt++:0);
			}
		}
		bool update = true;
		for (;update;){
			cnt = 0;
			update = false;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (!map[i][j])continue;
					for (int n = max(0, i - 1); n <= min(h-1, i + 1); n++) {
						for (int m = max(0, j - 1); m <= min(w-1, j + 1); m++) {
							if (!map[n][m])continue;
							if (map[i][j]>map[n][m]) {
								map[i][j] = map[n][m];
								update = true;
							}
						}
					}
				}
			}
		}
		vector<int> num;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				num.push_back(map[i][j]);
			}
		}
		sort(num.begin(), num.end());
		num.erase(unique(num.begin(),num.end()),num.end());
		cout << num.size()-((num[0]==0)?1:0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3120
#!/usr/bin/env python3


LIMIT = 10 ** 18


def prod(xs):
    xs.sort()
    res = 1
    if 0 in xs:
        return 0
    for x in xs:
        res *= x
        if res > LIMIT:
            return None
    return res


def main():
    n = int(input())
    bs = [int(z) for z in input().split()]
    res = prod(bs)
    if res is None:
        print(-1)
    else:
        print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 21652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1000000007;
ll Power(ll a,ll b) {
    if (b==0)return 1;
    ll x = Power(a,b/2);
    x = (x*x)%mod;
    if (b%2)x=(x*a)%mod;
    return x;
}
ll F[1000000];
ll iF[1000000];
ll inv(ll v){ return Power(v, mod-2); }
ll C(ll n, ll k) {
    return (F[n] * ((iF[n - k] * iF[k]) % mod)) % mod;
}
pair<int,int> a[1000000];
ll solve(int n,int k) {
    ll ret=0;
    for (int i=1;i<=n;i++) {
        if (i-1 < k-1)continue;
        ret = (ret + (((C(i -1 ,k-1)*a[i].first)%mod)+mod)%mod)%mod;
    }
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    F[0]=1;
    iF[0]=1;
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++) {
        F[i]=(F[i-1]*i)%mod;
        iF[i]=inv(F[i]);
    }
    for (int i=1;i<=n;i++) {
        cin>>a[i].first;
        a[i].second = i;
    }
    sort(a+1,a+n+1);
    ll x1 = solve(n, k);
    for (int i=1;i<=n;i++)a[i].first=-a[i].first;
    sort(a+1,a+n+1);
    ll x2 = solve(n,k);
    cout<<(x1+x2)%mod<<endl;
}



Measured memory_bytes: 9216
#include <iostream>

using namespace std;

typedef long long int lint;

const int NMAX = 100000 + 5;

int N;
lint A[NMAX];
lint APrim[NMAX];

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

    cin >> N;
    for (int i = 1; i <= N; ++ i)
        cin >> A[i];

    lint S = 0;
    for (int i = 1; i <= N; ++ i)
        S += A[i];

    lint onePass = N * (N + 1LL) / 2;
    if (S % onePass != 0) {
        cout << "NO\n";
        return 0;
    }

    lint passes = S / onePass;
    APrim[0] = A[N];
    for (int i = 1; i <= N; ++ i)
        APrim[i] = A[i];

    lint sumAPrim = 0;
    for (int i = N; i; -- i) {
        APrim[i] -= APrim[i - 1];
        APrim[i] -= passes;
        APrim[i] *= (-1);

        if (APrim[i] < 0 || APrim[i] % N != 0) {
            cout << "NO\n";
            return 0;
        }
        APrim[i] /= N;
        sumAPrim += APrim[i];
    }

    if (sumAPrim != passes)
        cout << "NO\n";
    else
        cout << "YES\n";
    return 0;
}


Measured memory_bytes: 1920
k,u,v=`dd`.scan(/-?\d+/).map &:to_i;x,y,*s=u.abs,v.abs;d=x+y;x,y=y,x if f=x>y;(k+1)*d%2==1&&(p -1;exit);m=(d-1)/k+1;n=d<k ?2:m+(d-m*k)%2;a=d==k ?x :(d-n*k)/2;b=k-a.abs;d%2-d/k==1&&(s=[[0,-k]];a=b=(d-k)/2);n.times{s<<[a,b];t=[x-a,k].min;a+=t;b+=k-t};p s.size;s.each{|a,b|f&&(a,b=b,a);puts [a*(u<=>0.1),b*(v<=>0.1)]*?\s}

Measured memory_bytes: 20868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  if (s < t) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,x,a[100],sum = 0;
	cin >> n >> x;
	for(int i = 0;i < n;i++) cin >> a[i];
	sort(a,a + n);
	for(int i = 0;i < n;i++){
		sum += a[i];
		if(sum > x){
			cout << i << endl;
			return 0;
		}
	}
	if(sum == x) cout << n << endl;
	else cout << n - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);

/// easy access -------------
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
typedef pair<int,int> pi;
typedef tuple<int, int, int> tp;
///-------------------------

int main()
{
    Phuong_; /// <3333
    int k;
    cin >> k;
    vector<bool> f(k,false);
    int m =7;
    if (m%k==0){
        cout << 1;
        return 0;
    }
    int ans =1;
    while (m && !f[m]){
        f[m] = true;
        m=(m*10+7)%k;
        ans++;
    }
    if (f[m]) cout << -1; else
    cout << ans;
    return 0;
}


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

using namespace std;
template<typename T> void in(T &x) { x = 0; bool neg = false; register T c = getchar(); if (c == '-')neg = true, c = getchar(); while ((c < 48) || (c > 57))c = getchar(); for (; c < 48 || c > 57; c = getchar()); for (; c > 47 && c < 58; c = getchar())x = (x << 3) + (x << 1) + (c & 15); if (neg) x *= -1; }
template<typename T> void out(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); }
template<typename T> void outln(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); putchar('\n'); }
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
//#define fastIO 
#define ll long long
#define itr(_c) for(auto i=_c.begin();i!=_c.end();i++)
#define itrr(_c)for(auto i=_c.begin();i!=_c.end();i++)
#define f1(_x)for (int i = 0; i < _x; ++i)
#define fr(_x)for (int i = _x; i >0; i--)
#define f2(_x,_y)for (int i = _x; i < _y; ++i)
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi; typedef vector<string> vs; typedef vector<bool> vb; vector<long long>vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
void fastIO(){ ios_base::sync_with_stdio(false); cin.tie(0); }
int main() {
	fastIO();
	int a, b; cin >> a >> b;
	if (a == 0 && b == 0) { std::cout << 0; return 0; }
	if (a >= 0 && b <= 0 || (b > 0 && a < 0))cout << (abs(abs(a) - abs(b)) + 1);
	else if(b>=a)std::cout << b-a;
	else std::cout << (abs(abs(a) - abs(b)) + 2);
//	std::cout << (a<=0?:);

}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, a: "List[int]"):
    s = 0
    for v in a:
        s = s ^ v
    ret = []
    for v in a:
        ret.append(s ^ v)
    print(*ret, sep=' ')
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 116604
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var r = ReadIntArray();
            if (r[1] -  r[0] == r[2] - r[1])
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13268
#!/usr/bin/env python3

n = int(input())
s = [input() for _ in range(n)]

d = {}
for i in s:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1 
ans = []
m = max(d.values())
for k, v in d.items():
    if v == m:
        ans.append(k)

for s in sorted(ans):
    print(s)


Measured memory_bytes: 35216
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int used[100000], d[100000];
VI e[100000];

int main() {
    int n, m;
    cin >> n >> m;
    while (m--){
        int u, v;
        scanf("%d %d", &u, &v);
        u--;
        v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    ll iso = 0, odd = 0, no_odd = 0;
    REP(i,n){
        if (used[i]) continue;
        if (e[i].size() == 0){
            iso++;
            used[i] = 1;
            continue;
        }
        queue<int> que;
        que.push(i);
        used[i] = 1;
        bool find_odd = false;
        while (!que.empty()){
            int now = que.front();
            que.pop();
            used[now] = 1;
            REP(j,e[now].size()){
                int next = e[now][j];
                if (used[next]){
                    if ((d[now]-d[next]) % 2 == 0) find_odd = 1;
                    continue;
                }
                d[next] = d[now] + 1;
                que.push(next);
            }
        }
        if (find_odd) odd++;
        else no_odd++;
    }
    ll ans = 0;
    REP(i,iso){
        ans += 2*n-1;
        n--;
    }
    ans += (odd + no_odd) * (odd + no_odd) + no_odd * no_odd;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8192