akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P2;
int next_animal(int a,int b,int c){
  //a:左の動物、b:真ん中の動物、c:oか×か
  //ひつじ:0 おおかみ:1
  if(b==1) c=(c+1)%2;
  if(c==0) return a;
  else return (a+1)%2;
}
int main(){
  int n;
  cin>>n;
  vector<int> vec;
  for(int i=0;i<n;i++){
    char a;
    cin>>a;
    if(a=='o') vec.push_back(0);
    else vec.push_back(1);
  }
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      vector<int> ans;
      ans.push_back(i);
      ans.push_back(j);
      for(int k=1;k<n-1;k++){
        int ps=ans.size()-1;
        ans.push_back(next_animal(ans[ps-1],ans[ps],vec[ps]));
      }
      if(next_animal(ans[n-2],ans[n-1],vec[n-1])==i&&next_animal(j,i,vec[0])==ans[n-1]){
        for(int k=0;k<n;k++) cout<<(ans[k]==0?'S':'W');
        cout<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 1636
//2018.09.21

#include <iostream>
using namespace std;


int main() {

    int d,n;
    cin >> d >> n;

    if(n == 100){
        if(d==0)cout << n+1 << endl;
        else if(d==1)cout << (n+1)*100 << endl;
        else cout << (n+1)*10000 << endl;

    }
    else{
        if(d==0)cout << n << endl;
        else if(d==1)cout << n*100 << endl;
        else cout << n*10000 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def resolve():
  d, n = map(int, input().split())
  if d == 0:
    if n == 100:
      print(101)
    else:
      print(n)
    return
  
  if d == 1:
    if n == 100:
      print(10100)
    else:
      print(100 * n)
    return

  if d == 2:
    if n == 100:
      print(1010000)
    else:
      print(10000 * n)
    return

  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
using ll = long long;

int main(){
  int n;
  cin >> n;
  vector<int> col(n);
  vector<vector<int>> v(200000);
  for(int i=0; i<n; ++i){
    cin >> col[i];
    --col[i];
    v[col[i]].push_back(i);
  }
  ll dp[n];
  dp[0] = 1;
  for(int i=1; i<n; ++i){
    dp[i] = dp[i-1];
    auto it = lower_bound(v[col[i]].begin(),v[col[i]].end(),i);
    if(it != v[col[i]].begin()){
      --it;
      if(*it +1 != i){
        dp[i] += dp[*it];
        dp[i] %= MOD;
      }
    }
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 16368
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
	int x;
	cin >> x;
	switch(x/200){
		case 2: printf("8\n");break;
		case 3: printf("7\n");break;
		case 4: printf("6\n");break;
		case 5: printf("5\n");break;
		case 6: printf("4\n");break;
		case 7: printf("3\n");break;
		case 8: printf("2\n");break;
		case 9: printf("1\n");break;
	}
	return 0;
} 

Measured memory_bytes: 3632
using System;

namespace ITP1_9_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int pointT = 0;
            int pointH = 0;
            for(int i = 0; i < n; i++)
            {
                string[] cards = Console.ReadLine().Split(' ');
                int point = cards[0].CompareTo(cards[1]);
                if (point > 0)
                    pointT += 3;
                else if (point < 0)
                    pointH += 3;
                else
                {
                    pointT += 1;
                    pointH += 1;
                }
            }
            Console.WriteLine("{0} {1}", pointT, pointH);
        }
    }
}

Measured memory_bytes: 9896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(){
  string s;
  cin >> s;
  vector<int> len(s.size());
  int cnt = 0;
  rep(i,s.size()) {
    if (s[i] == 'A' || s[i] == 'G' || s[i] == 'T' || s[i] == 'C') {
      cnt++;
      len[i] = cnt;
    }
    else {
      cnt = 0;
      len[i] = 0;
    } 
  }
  int ans = 0;
  rep(i,s.size()) ans = max(ans, len[i]);
  cout << ans << endl;
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

ll op(ll a, ll b) { return max(a, b); }

ll e() { return (ll)-1; }

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> vec(n);
    vector<pair<ll,ll>> arr;
    vector<ll> a(300001,0);
    ll len = 0;
    rep(i,n){
        cin >> vec[i];
    }
    segtree<ll, op, e> seg(a);
    ll score;
    rep(i,n){
        t1 = vec[i];
        score = seg.prod(max((ll)0,vec[i]-k),min(vec[i]+k+1,300001ll)) + 1;
        //cout << score << endl;
        if(seg.get(t1) < score){
            seg.set(t1,score);
        }
        //cout << score << endl;
    }
    ll ans = seg.prod(0,300001);
    cout << ans << endl;
}

Measured memory_bytes: 16228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define dump(x)  cerr << #x << " = " << (x) << endl;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL; 

 

//ここから書き始める
int main(int argc, char const *argv[])
{
	int N, K;
	cin >> N >> K;
	LL ans;

	if(K%2 == 1)
	{
		cout << LL(pow(N / K, 3)) << endl;
	}
	else
	{
		cout << LL(pow(N / K, 3) + pow((N % K < K / 2 ? N / K : N / K + 1), 3)) << endl;
	}


}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	int x,a,b;
	cin>>x>>a>>b;
	if(b<=a)cout<<"delicious"<<endl;
	else if(a+x<b)cout<<"dangerous"<<endl;
	else cout<<"safe"<<endl;
	return 0;
}

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

int main(){
    bool ans = 0;
    int n;
    cin >> n;
    if(n > 81){
        ans = 0;
    }
    else{
        for(int i = 1;i <= 9;i++){
            if((n%i == 0)&&(n/i < 10)){
                ans = 1;
                break;
            }
        }
    }

    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,sa[7];
	for(int i=0;i<7;i++){
		scanf("%d %d",&a,&b);
		sa[i] = a - b;
	}
	for(int i=0;i<7;i++)
		printf("%d\n",sa[i]);
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main(){
    int n;
    string s,t;
    cin>>n>>s>>t;
    int j=0;
    rep(i,2*n){
        if(i%2==0)
            cout<<s[j];
        if(i%2==1)
            cout<<t[j++];
    }
}

Measured memory_bytes: 3632
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main()
{
	int K, X;
	cin >> K >> X;

	for (int i = X - (K - 1); i <= X + (K - 1); ++i)
		cout << i << " ";
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int sort(int *, int *);
int main(void){
  int n;
  scanf("%d",&n);
  int l[n+1];
  for(int i=0;i<n;i++){
    scanf("%d",&l[i]);
  }
  qsort(l,n,sizeof(int),sort);
  int count=0;
  for(int i=0;i<n-2;i++){
	for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(l[i]-l[j]<l[k])count++;
      }
    }
  
}
  printf("%d",count);
  return 0;
}
int sort(int *a, int *b){
  return *b-*a;
}

Measured memory_bytes: 252
n, k = map(int, input().split())
aList = list(map(int, input().split()))
bits0 = [0] * 42
bits1 = [0] * 42
def getBit(a):
    mask = 1
    for i in range(42):
        if mask > a and mask > k:
            break
        if a & mask:
            bits1[i] += 1
        else:
            bits0[i] += 1
        mask <<= 1

for a in aList:
    getBit(a)


"""
私は嘘解法でACしました
hack_case
5 2
0 0 0 2 2
-> 6

ans = 0
for i in range(41, -1, -1):
    cnt1 = bits1[i]
    cnt0 = bits0[i]
    if k < 2 ** i:
        ans += 2 ** i * cnt1
        continue
    if cnt0 <= cnt1:
        ans += 2 ** i * cnt1
    else:
        ans += 2 ** i * cnt0
        k -= 2 ** i
print(ans)
"""

INF = 10 ** 20
dp = [[0, -INF] for _ in range(43)]
for i in range(41, -1, -1):
    cnt0 = bits0[i]
    cnt1 = bits1[i]
    if k & (1 << i):
        dp[i][0] = dp[i + 1][0] + 2 ** i * cnt0
        dp[i][1] = max(dp[i + 1][0] + 2 ** i * cnt1, dp[i + 1][1] + 2 ** i * max(cnt0, cnt1))
    else:
        dp[i][0] = dp[i + 1][0] + 2 ** i * cnt1
        dp[i][1] = max(dp[i + 1][1] + 2 ** i * cnt1, dp[i + 1][1] + 2 ** i * cnt0)
print(max(dp[0]))



Measured memory_bytes: 14620
from math import sqrt

N=int(input())
XY=[]
for i in range(N):
    x,y=map(int,input().split())
    XY.append([x,y])

distance=0
for i in range(N):
    for j in range(i+1,N):
        distance+=sqrt( pow( (XY[i][0])-(XY[j][0]) ,2 ) + pow(XY[i][1] - XY[j][1],2) )

tmp=0        
for i in range(1,N):
    tmp+=i
    

print(distance*(N-1)/tmp)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 333337;
const int MOD = 1000000007;

long long degree(long long a, long long k, long long p) {
    long long res = 1;
    long long cur = a;

    while (k) {
        if (k % 2) {
            res = (res * cur) % p;
        }
        k /= 2;
        cur = (cur * cur) % p;
    }
    return res;
}
int get_degree(long long n, long long p) { // returns the degree with which p is in n!
    int degree_num = 0;
    long long u = p;
    long long temp = n;

    while (u <= temp) {
        degree_num += temp / u;
        u *= p;
    }
    return degree_num;
}

long long C(int n, int k, long long p) {
    int num_degree = get_degree(n, p) - get_degree(n - k, p);
    int den_degree = get_degree(k, p);

    if (num_degree > den_degree) {
        return 0;
    }
    long long res = 1;
    for (long long i = n; i > n - k; --i) {
        long long ti = i;
        while(ti % p == 0) {
            ti /= p;
        }
        res = (res * ti) % p;
    }
    long long denom = 1;
    for (long long i = 1; i <= k; ++i) {
        long long ti = i;
        while(ti % p == 0) {
            ti /= p;
        }
        denom = (denom * ti) % p;
    }
    res = (res * degree(denom, p-2, p)) % p;
    return res;
}

void solve() {
    long long x, y;
    cin >> x >> y;
    if ((x + y) % 3 || max(x, y) > 2 * min(x, y)) {cout << 0; return;}
    cout << C(((x + y) / 3), (x - ((x + y) / 3)), MOD);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("in.in", "r", stdin); freopen("out.out", "w", stdout);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {cout << "Case #" << i << ": "; solve();}
    solve();
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, A;
    cin >> N >> A;
    vector<ll> x(N);
    Rep (i, N) {
        cin >> x[i];
    }

    vector<vector<vector<ll>>> dp(51, vector<vector<ll>>(51, vector<ll>(2501, 0)));
    dp[0][0][0] = 1;
    Rep (i, 51) Rep (j, 51) Rep (k, 2501){
        // choose x[i]
        if (i+1 < 51 && j+1 < 51 && k+x[i] < 2501) dp[i+1][j+1][k+x[i]] += dp[i][j][k];
        // don't choose x[i]
        if (i+1 < 51) dp[i+1][j][k] += dp[i][j][k];
    }

    // Rep (i, 5) Rep (j, 5) Rep (k, 20) {
    //     cout << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
    // }

    ll ans = 0;
    for (ll j = 1; j <= N; j++) {
        ans += dp[N][j][j*A];
    }

    cout << ans << endl;
}

Measured memory_bytes: 52224
// const input = require('fs').readFileSync('/dev/stdin', 'utf8');
// const inputList = input.split('/'); // 空白文字に注意
// const inputNumberList = inputList.map(Number);

const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const inputList = input.split('\n');
// const inputNumberList = inputList.map(Number);

const firstInputList = inputList[0].split(' ').map(Number);

const N = firstInputList[0];
const A = firstInputList[1];
const B = firstInputList[2];
const C = firstInputList[3];

const lList = inputList.slice(1, -1).map(Number);

const func = (list, a, b, c) => {
  const mpList = [];

  for (let i = 0; i < 4 ** list.length; i++) {
    let notation4 = i.toString(4);
    if (notation4.length < list.length) {
      notation4 = '0'.repeat(list.length - notation4.length) + notation4;
    }
    let mp = 0;
    let aLength = 0;
    let bLength = 0;
    let cLength = 0;

    for (let j = 0; j < notation4.length; j++) {
      const bunbooNumber = notation4[j];
      const bunbooLength = list[j];

      if (bunbooNumber === '1') {
        aLength += bunbooLength;
        mp += 10;
      }
      if (bunbooNumber === '2') {
        bLength += bunbooLength;
        mp += 10;
      }
      if (bunbooNumber === '3') {
        cLength += bunbooLength;
        mp += 10;
      }
    }

    if ((aLength !== 0) && (bLength !== 0) && (cLength !== 0)) {
      mp = mp + Math.abs(a - aLength) + Math.abs(b - bLength) + Math.abs(c - cLength) - 30;
      mpList.push(mp);
    }
  }

  mpList.sort((i, j) => {
    return i - j;
  });

  return mpList[0];
};

console.log(func(lList, A, B, C));


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

using namespace std;

int main() {
    stack<int> st;
    string s;
    int a, b;

    while (cin >> s) {
        switch (s[0]) {
            case '+':
                a = st.top();
                st.pop();
                b = st.top();
                st.pop();
                st.push(a + b);
                break;
            case '-':
                a = st.top();
                st.pop();
                b = st.top();
                st.pop();
                st.push(b - a);
                break;
            case '*':
                a = st.top();
                st.pop();
                b = st.top();
                st.pop();
                st.push(a * b);
                break;
            default:
                st.push(stoi(s));
                break;
        }
    }

    cout << st.top() << endl;
}

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

const int maxn=2e5+10;
const int mod=998244353;
char c[maxn];
ll a[maxn],sum[maxn],tot,f[maxn],b[maxn];
int n;
ll poww(ll x,ll k) {
    ll ans=1;
    while(k) {
        if(k&1) ans=ans*x%mod;x=x*x%mod;k>>=1; 
    }return ans;
}
bool check(int x) {
    int now=1,f=0;
    for(int i=1;i<=n;++i) {
        if(((c[now]-'0')^f)>(c[i]-'0')) return 0;
        else if(((c[now]-'0')^f)<(c[i]-'0')) return 1;
        else {
            now++;
            if(now>x) now=1,f^=1;
        }
    }
    return 1;
}
int get(int x) { 
    if((n/x)%2) {
        if(check(x))
        return sum[x]+1;
        else return sum[x];
    }
    return 0;
} 
ll ans;
int main()
{
    scanf("%d",&n);
    scanf("%s",c+1);
    for(int i=1;i<=n;++i) {
        tot=tot*2%mod;
        if(c[i]=='1') tot=tot+1;
        sum[i]=tot; 
    //  cout<<sum[i]<<"*\n";
    }
    tot=tot%mod;
    for(int i=1;i<=sqrt(n);++i) {
        if(n%i==0) f[i]=get(i);
        if(i*i!=n&&(n%(n/i)==0)) f[n/i]=get(n/i);
    }
    //cout<<get(n/2)<<"\n";
    //for(int i=1;i<=n;++i) cout<<f[i]<<"*\n";
    for(int i=1;i<=n;++i) {
        for(int j=i+i;j<=n;j+=i) f[j]=(f[j]-f[i]+mod)%mod;
    }
    for(int i=1;i<=n;++i) {
        if(n%i==0) {
            ans=(ans+f[i]*2*i%mod)%mod;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4992
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
    int x,y,z;
  cin>>x>>y>>z;
  cout<<z<<" "<<x<<" "<<y<<endl;
    
    
}

Measured memory_bytes: 256
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let cols = lines.shift().split(/\s/).map((v) => v - 0);
    let H = cols[0], W = cols[1];
    let A = [];
    for (let n = 0; n < H; n++) {
        let cols = lines.shift().split(/\s/).map((v) => v - 0);
        cols.forEach((v) => A.push(v));
    }
    const yx = (v) => `${Math.floor(v / W) + 1} ${(v % W) + 1}`;
    const wh = W * H;
    const wh0 = W * (H - 1);
    let N = 0;
    let op = "";
    for (let n = 0; n < wh; n++) {
        if (A[n] % 2) {
            if (n < wh0 - 0) {
                A[n] -= 1;
                A[n + W] += 1;
                op += `\n${yx(n)} ${yx(n + W)}`;
                N += 1;
            } else if (n < wh - 1) {
                A[n] -= 1;
                A[n + 1] += 1;
                op += `\n${yx(n)} ${yx(n + 1)}`;
                N += 1;
            }
        };
    }
    console.log(N + op);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int a[6] = {500, 5, 100, 50, 10, 1};

int main(){
    int x;
    cin >> x;
    int d = 0, b = 0, c = 0;
    for(int i = 0; i < 6; i++){
        b = x / a[i];
        if(b != 0){
            x = x - b*a[i];
           // cout << x << ' ' <<  b << ' ' << a[i] << endl;
            if(a[i] == 500)
                c = c + b*1000;
            if(a[i] == 5){
                c = c + b*5;
            }
        }
        if( x == 0){
            break;
        }        
    }
    cout << c << '\n';
}

Measured memory_bytes: 256
i=input;k = int(i());x, y = map(int, i().split());x,y=x-y,x+y
def cc(x, xs):
    if abs(x-xs)<=2*k and abs(x-xs)%2==0:
        return 1,x+(k if abs(x+k-xs) <= abs(x-k-xs) else -k)
    return 0,xs+(k if x-xs>0 else -k)
if (k%2,x%2)==(0,1):
    print(-1)
else:
    rs = []
    xs, ys = 0, 0
    while True:
        if abs(x-xs) == k or abs(y-ys) == k:
            if abs(x-xs) <= k and abs(y-ys) <= k:
                rs+=["{} {}".format((x+y)//2,(y-x)//2)]
                break
        mm,ys=cc(y,ys)
        if mm:
            xs = xs+(k if x > xs else -k)
        else:
            mm, xs = cc(x, xs)
        rs+=["{} {}".format((xs+ys)//2,(ys-xs)//2)]
    print(len(rs))
    print("\n".join(rs))


Measured memory_bytes: 24216
#074_D
from copy import deepcopy
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]

def warshall_floyd(d, v):
    for k in range(v):
        for i in range(v):
            for j in range(v):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

b = deepcopy(a)
warshall_floyd(b, n)

flg = True
ans = 0
for i in range(n):
    for j in range(n):
        if b[i][j] < a[i][j]:
            flg = False
            break
        else:
            flg2 = True
            for k in range(n):
                if i == k or j == k:
                    continue
                elif b[i][j] == b[i][k] + b[k][j]:
                    flg2 = False
            ans += b[i][j] if flg2 else 0
                    
print(ans//2 if flg else -1)

Measured memory_bytes: 57564
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,a[200000];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    map<int,bool>exi,exi2;
    bool isp[1000001];
    for(int i=0;i<n;i++){
        if(exi[a[i]])
            exi2[a[i]]=0;
        else
            exi2[a[i]]=1;
        exi[a[i]]=isp[a[i]]=1;
    }
    for(int i=1;i<=1000000;i++){
        if(exi[i]&&isp[i])
            for(int j=i*2;j<=1000000;j+=i)
                if(exi[j])
                    isp[j]=0;
    }
    int ans=0;
    for(int i=0;i<=1000000;i++)
        if(isp[i]&&exi2[i])
            ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 80360
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  int a;
  int ans = 0;
  for(int i=0; i<n; i++){
    cin >> a;
    if(a>=k){
      ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

int main(void){
    int N, M;
    cin >> N >> M;
    vector<int>a(N);
    vector<int>b(N);
    rep(i,N) cin >> a[i] >> b[i];
    vector<int>c(M);
    vector<int>d(M);
    rep(i, M) cin >> c[i] >> d[i];
    vector<int>A(M);
    rep(j, N) {
        int MIN = 10000000000;
        int B = 1;
        rep(i, M) {
            A[i] = abs(a[j] - c[i]) + abs(b[j] - d[i]);
            if (A[i] < MIN) {
                MIN = A[i];
                B = i + 1;
            }
        }
        cout << B << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define endl "\n"

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

signed main() {
	crap;

	int x;
	cin >> x;

	int a; cin >> a; char c; cin >> c; int b; cin >> b;

	a = a * 100 + b;

	int y = a * x;
	cout << y / 100 << endl;



	return 0;
}

Measured memory_bytes: 3656
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    int t=1;;
    //cin>>t;
    while(t--)
    {
        ll ans=0;
    ll n, k, d;
    cin>>n>>k>>d; 
    if (n < 0) n = -n;
	
	if (n / d < k) {
		ll rest = k - n / d;
		if (rest % 2 == 0) ans = n % d;
		else ans = d - n % d;
	} else {
		ans = n - d * k;
	}
	cout << ans << '\n';
    }
}

Measured memory_bytes: 3648
from collections import deque
n=int(input())
que=deque()

for i in range(n):
    command=input()
    if command=="deleteFirst":que.popleft()
    elif command=="deleteLast":que.pop()
    else:
        x,y=command.split()
        if x=="insert":que.appendleft(y)
        else:
            if y in que:que.remove(y)

print(*que)


Measured memory_bytes: 69732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>

int main() {
    ll K,S;
    cin >> K >> S;

    ll count = 0;
    rep(i,K+1){
        rep(j,K+1){
            ll z = S - i - j;
            if(0 <= z && z <= K) count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
using namespace std;
 
struct P{
    int a,b;
    string c;
   
    P(int a,int b,string c) : a(a),b(b),c(c) {}
    bool operator < (const P &p)const{
	if(a != p.a){
	    return a > p.a;
	}else{
	    return b < p.b;
	}
    }
};
 
int main(){
    string str,s;
    map<string,string> mp;
    mp["e"] = "egg";
    mp["c"] = "chicken";
    cin >> str;
    for(int i = 0 ; i < (int)str.size() ; i++){
	if(str[i] == 'e'){
	    i += 2;
	    s += 'e';
	}else{
	    i += 6;
	    s += 'c';
	}
    }
    int size = s.size();
    if(size == 1){
	cout << mp[s] << endl;
    }else{
	vector<P> vec;
	string tmp; tmp += s[0];
	for(int i = 1 ; i < size ; i++){
	    if(s[i-1] == s[i]){
		vec.push_back(P(tmp.size(),i,tmp));
		tmp = "";
	    }
	    tmp += s[i];
	}
	if(!tmp.empty()){
	    vec.push_back(P(tmp.size(),size,tmp));
	    tmp = "";
	}
	sort(vec.begin(),vec.end());
	tmp += vec[0].c[vec[0].c.size()-1];
	cout << mp[tmp] << endl;
    }
    return 0;
}

Measured memory_bytes: 3208
/*SorooshH*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> tpi;
typedef pair<pii,pii> qpi;
const int MAX = 1e6;
const int MV = 1e5;
const int INF = 2e9;
const int MOD = 1e9 + 7;
int MA = -INF , MI = INF , ANS;

int n;

int32_t main()
{
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n;
    cout << n/3 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int n;
    cin >> n;
    int t = 0;
    int x = 0;
    int y = 0;
    while (n--)
    {
        int nt;
        int nx;
        int ny;
        cin >> nt >> nx >> ny;
        int dt=(nt-t)-abs(nx-x)-abs(ny-y);
        if(dt>=0 && dt%2==0){
            t=nt;
            x=nx;
            y=ny;
        }else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int N;
    int A[100000];
    int min;
    int max;

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

    max = min = A[0];
    for (int i=0; i<N; i++)
    {
        if (max<A[i])
        {
            max=A[i];
        }
        else if (min>A[i])
        {
            min = A[i];
        }
    }
    printf("%d\n", max-min);
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  int x=a[n-1];
  int y=0;
  int id=0;
  for(int i=0;i<n;i++){
    int tmp=min(abs(0-a[i]),abs(a[n-1]-a[i]));
    if(tmp>y){
      y=tmp;
      id=i;
    }
  }
  cout<<a[n-1]<<" "<<a[id]<<endl;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int H = in.nextInt();
            int W = in.nextInt();
            char[][] matrix = new char[H][W];
            for (int i = 0; i < H; i++)
            {
                matrix[i] = in.next().toCharArray();
            }
            int x = H - 1;
            int y = W - 1;
            int[][] memo = new int[H][W];
            for (int i = 0; i < H; i++)
            {
                Arrays.fill(memo[i], -1);
            }
            out.println(getNWays(x, y, matrix, memo) % 1000000007);
        }

        int getNWays(int row, int column, char[][] matrix, int[][] memo)
        {
            if (row == 0 && column == 0) return 1;
            if (memo[row][column] != -1)
            {
                return memo[row][column];
            }
            int ways = 0;
            int x[] = {-1, 0};
            int y[] = {0, -1};

            if (isValid(row + x[0], column + y[0], matrix))
            {
                ways += getNWays(row + x[0], column + y[0], matrix, memo) % 1000000007;
            }

            if (isValid(row + x[1], column + y[1], matrix))
            {
                ways += getNWays(row + x[1], column + y[1], matrix, memo) % 1000000007;
            }
            memo[row][column] = ways;
            return ways;
        }

        boolean isValid(int row, int column, char[][] matrix)
        {
            return row >= 0 && row < matrix.length && column >= 0 && column < matrix[0].length && matrix[row][column] != '#';
        }

    }
}



Measured memory_bytes: 49876
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>

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

using namespace std;
unsigned long long int newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main()
{
	int N,M;
	vector<int> A;
	// 値　個数
	priority_queue<pair<int, int> > q;
	cin >> N >> M;
	int i,j,k;
	for(i=0; i<N; ++i)
	{
		cin >> j;
		A.push_back(j);
	}
	for(i=0; i<M; ++i)
	{
		cin >> j >> k;
		q.push(make_pair(k,j));
	}
	sort(A.begin(), A.end());
	int cur = 0;
	int end = 0;
	while(!q.empty())
	{
		j = q.top().first;
		k = q.top().second;
		q.pop();
		for(i=0; i < k; ++i)
		{
			if(A[cur] < j)
			{
				A[cur] = j;
				++cur;
			}
			else
			{
				end = 1;
				break;
			}
			if(cur==N)
			{
				end=1;
				break;
			}
		}
		if(end)
			break;
	}
	unsigned long long int ans = 0;
	for(i=0; i<N; ++i)
	{
		ans += A[i];
	}
	cout << ans << endl;
	return 0;
}




































Measured memory_bytes: 1784
#include <iostream>

#define N 110
#define H 1010

using namespace std;

int main(void)
{

	int n,m,a;
	int h,p,q;

	int f[H][N];

	int k;


	int i1,i2;

	while(1){
		cin >> n;
		cin >> m;
		cin >> a;

		if (n == 0 && m == 0 && a == 0) break;


		for(i1=0;i1<H;i1++){
			for(i2=0;i2<N;i2++){
				f[i1][i2] = 0;
			}
		}

		for (i1=0;i1<m;i1++){
			cin >> h;
			cin >> p;
			cin >> q;

			if(p<q) {
				f[1000-h][p] = 1;
			}
			else {
				f[1000-h][q] = 1;
			}
		}


		k=a;
		for(i1=0;i1<H;i1++){

			if (f[i1][k-1] == 1){
				k--;
			}
			else if (f[i1][k] == 1){
				k++;
			}

		}

		cout << k << endl;
	}


	return 0;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 n,m;
    cin >> n >> m;
    vector<vector<pair<i64,i64>>> graph(n);
    rep(i,0,m){
        i64 u,v,s;
        cin >> u >> v >> s;
        --u;
        --v;
        graph[u].push_back(make_pair(v,s));
        graph[v].push_back(make_pair(u,s));
    }

    vector<i64> a(n),b(n),x(n,-1);
    vector<bool> visited(n);
    function<bool(i64)> rec=[&](i64 u){
        for(auto& e:graph[u]){
            i64 v=e.first,s=e.second;
            i64 av=-a[u],bv=s-b[u];
            if(!visited[v]){
                a[v]=av;
                b[v]=bv;
                visited[v]=true;
                if(!rec(v)) return false;
            }else{
                if(a[v]!=av or b[v]!=bv){
                    if(a[v]==av or (bv-b[v])%(av-a[v])!=0) return false;
                    x[0]=-(bv-b[v])/(av-a[v]);
                }
            }
        }
        return true;
    };

    a[0]=1;
    b[0]=0;
    visited[0]=true;
    if(!rec(0)){
        cout << 0 << endl;
        return;
    }

    if(x[0]!=-1){
        rep(i,0,n){
            x[i]=a[i]*x[0]+b[i];
            if(x[i]<=0){
                cout << 0 << endl;
                return;
            }
        }
        rep(i,0,n) for(auto& e:graph[i]){
            if(x[i]+x[e.first]!=e.second){
                cout << 0 << endl;
                return;
            }
        }
        cout << 1 << endl;
        return;
    }

    i64 l=0,r=inf;
    rep(i,0,n){
        if(a[i]>0) l=max(l,1-b[i]);
        else r=min(r,-1+b[i]);
        for(auto& e:graph[i]){
            i64 s=e.second;
            if(a[i]>0) r=min(r,s-b[i]);
            else l=max(l,-s+b[i]);
        }
    }

    cout << max((i64)0,r-l+1) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

using namespace std;

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

typedef long long LL;
typedef pair<int, int> Pii;

const int inf = 0x3f3f3f3f;
const LL infLL = 0x3f3f3f3f3f3f3f3fLL;

const int maxn = 200000 + 5;

int psz;
struct Node {
  int key, siz;
  LL sum;
  Node *ch[2];
  void update() {
    siz = ch[0]->siz + ch[1]->siz + 1;
    sum = ch[0]->sum + ch[1]->sum + key;
  }
} pool[maxn], *null = new Node();

Node *new_node(int k) {
  Node *i = pool + psz++;
  i->key = i->sum = k, i->siz = 1, i->ch[0] = i->ch[1] = null;
  return i;
}

class SBT {
  Node *root;

  void rotate(Node *&u, int d) {
    Node *v = u->ch[d ^ 1];
    u->ch[d ^ 1] = v->ch[d];
    v->ch[d] = u;
    v->siz = u->siz;
    u->update();
    u = v;
    u->update();
  }

  void maintain(Node *&u, int d) {
    if (u == null) return;
    if (u->ch[d]->ch[d]->siz > u->ch[d ^ 1]->siz)
      rotate(u, d ^ 1);
    else if (u->ch[d]->ch[d ^ 1]->siz <= u->ch[d ^ 1]->siz)
      return;
    else
      rotate(u->ch[d], d), rotate(u, d ^ 1);
    maintain(u->ch[0], 0);
    maintain(u->ch[1], 1);
    maintain(u, 0);
    maintain(u, 1);
  }

  void insert(Node *&u, int k) {
    if (u == null) {
      u = new_node(k);
      return;
    }
    int d = (k > u->key);
    insert(u->ch[d], k);
    maintain(u, d), u->update();
  }

 public:
  SBT() : root(null) { null->sum = 0, null->ch[0] = null->ch[1] = null; }
  int size() { return root->siz; }
  void insert(int k) { insert(root, k); }
  int select(int k, LL &s) {
    for (Node *u = root; u != null;) {
      int t = u->ch[0]->siz;
      if (k == t) {
        s += u->ch[0]->sum;
        return u->key;
      }
      if (k > t) s += u->ch[0]->sum + u->key;
      u = u->ch[k > t], k -= (k > t ? t + 1 : 0);
    }
    return inf;
  }
};

int main() {
  int n;
  scanf("%d", &n);
  SBT bst;
  LL sum = 0;
  while (n--) {
    int op, a, b;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d", &a, &b);
      bst.insert(a);
      sum += a + b;
    } else {
      int i = (bst.size() - 1) / 2;
      LL s = 0;
      int x = bst.select(i, s);
      printf("%d %lld\n", x, sum - 2 * s - (LL)x * (bst.size() - 2 * i));
    }
  }

  return 0;
}

Measured memory_bytes: 6912
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,a[1000010],s;
int main(){
	scanf("%d",&n);
	FOR(i,1,n) getint(a[i]);
	sort(a+1,a+n+1);
	if (a[n]-a[1]>1) return puts("No"),0;
	if (a[1]==a[n]){
		if (a[1]+1==n || n/2>=a[1]) return puts("Yes"),0;
		else return puts("No"),0;
	}
	FOR(i,1,n)
		if (a[i]==a[1]) ++s;
	if (n-s>1){
		if (s+(n-s)/2>=a[n] && s<a[n]) return puts("Yes"),0;
		else return puts("No"),0;
	}
	else{
		return puts("No"),0;
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using std::cin;
using std::vector;

int main()
{
    int from_num;
    cin >> from_num;
    vector<int> from(from_num);
    for (auto i = 0; i < from_num; i++) {
        cin >> from.at(i);
    }

    int target_num;
    cin >> target_num;
    vector<int> target(target_num);
    for (auto i = 0; i < target_num; i++) {
        cin >> target.at(i);
    }

    int cnt = 0;
    for (auto i = 0; i < target_num; i++) {
        int first = 0, last = from_num;
        while (first <= last) {
            int mid = (last + first) / 2;
            if (from[mid] < target[i]) {
                first = mid + 1;
            } else if (target[i] < from[mid]) {
                last = mid - 1;
            } else {
                cnt++;
                break;
            }
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}

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


#define mod 1000000007
int dp[1010][1010];



int main()
{

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

    int h,w;
    cin>>h>>w;

    string s[h+10];

    for(int i=0;i<h;i++)
        cin>>s[i];

dp[0][1]=1;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(s[i][j]=='.')
            {
                dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j])%mod;
            }
        }
    }

    cout<<dp[h][w]<<'\n';

    return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2E5+7;
const ll INF=1E18+7;
ll arr[N];
ll brr[N];
ll n,m;
bool check(ll mid,ll m1){
	for(ll i=1;i<=n;i++){
		if(arr[i]*brr[n-i+1]<=mid) continue ;
		else {
			ll x=mid/brr[n-i+1];
			ll y=arr[i]-x;
			m1-=y;
			if(m1<0) return 0;
		}
	}
	return 1;
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)	cin>>arr[i];
	for(int j=1;j<=n;j++)	cin>>brr[j];
	sort(arr+1,arr+1+n);
	sort(brr+1,brr+1+n);
	ll l=0,r=brr[n]*arr[n];
	ll ans=INF;
	while(l<=r){
		ll mid=(l+r)>>1;
		if(check(mid,m)){
			r=mid-1;
			ans=min(ans,mid);
		}
		else {
			l=mid+1;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
def main():
    N = int(input())
    ans = set()

    def trial_division(n):
        divs = set()
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                if i != 1:
                    divs.add(i)
                if i != n//i:
                    divs.add(n//i)
        return divs

    ans |= (trial_division(N))
    ans |= (trial_division(N-1))
    answer = 0
    for k in ans:
        cur = N
        while cur % k == 0 and cur != 1:
            cur //= k
        if cur == 1 or cur % k == 1:
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()


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

int main()
{
    char c,d;
    int a,b;
    cin >> c;
    a = c - '0';
    while (cin >> d)
    {
        b = d - '0';
        a = (a+b)%9;
    }
    if (a%9==0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>

#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
#define mod 1000000007
#define MAXN 200001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


void solve()
{
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl;
}

int main()
{
    int t;
    // cin>>t;
    t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<cstring>
#include<math.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
int l1,l2,l,n;
int head[N];
int vis[N];
int main()
{
     int i,j,k,n,m,x,y;
     memset(head,0,sizeof(head));
     memset(vis,0,sizeof(vis));
     scanf("%d%d",&n,&m);
     for(i=0;i<m;i++)
     {
          scanf("%d%d",&x,&y);
          if(x==1)
               head[y]=1;
          if(y==1)
               head[x]=1;
          if(x==n)
               vis[y]=1;
          if(y==n)
               vis[x]=1;
     }
     k=0;
     for(i=2;i<n;i++)
     {
          if(vis[i]==1&&head[i]==1)
          {
               k=1;
               break;
          }
     }
     if(k==1)
          printf("POSSIBLE\n");
     else
          printf("IMPOSSIBLE\n");
     return 0;
}


Measured memory_bytes: 1920
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;



signed main(){
	string s;
	cin >> s;
	int cnt = 0;
	REP(i, s.size()) {
		cnt += s[i] - '0';
		cnt %= 9;
	}
	if(cnt == 0) out("Yes");
	else out("No");
}

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

int main() {


    int l;
    cin >> l;

    ld d = ((ld)l) / 3;
    std::cout << std::fixed;
    std::cout << std::setprecision(10) << std::pow(d, (ld)3);
    std::cout << endl;

    return 0;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
 

int main() {
    int man,gosen,sen,n,s;
    
    man=-1;
    gosen=-1;
    sen=-1;
    
   
    
   
       cin>>n>>s;
       

    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            
                if(i*10000+j*5000+(n-i-j)*1000==s) {
                    man=i;
                    gosen=j;
                    sen=(n-i-j);
                }
            
             
       
         }
   }
   
   

    cout<<man<<" "<<gosen<<" "<<sen<<endl;

}

Measured memory_bytes: 256