akhauriyash/Code-Regression huggingface dataset:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,A,B = MI()
    print(min(B,N*A))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;
int cnt[100010];
int main() {
  int N; cin >> N;
  if ( N == 1 ) {
    int a; cin >> a;
    cout << 1 << endl;
    return 0;
  } else if ( N == 2 ) {
    int a,b; cin >> a >> b;
    if ( a == b ) cout << 2 << endl;
    else if ( abs(a-b) == 1 ) cout << 2 << endl;
    else cout << 1 << endl;
    return 0;
  }
  for ( int i = 0; i < N; i++ ) {
    int a; cin >> a;
    cnt[a]++;
  }

  int ans = -1;
  for ( int i = 1; i <=99999; i++ ) {
    int tmp = cnt[i-1]+cnt[i]+cnt[i+1];
    ans = max(tmp,ans);
  }

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


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

    vector<pair<pair<int, int>, bool>> r(n);
    vector<pair<int, int>> b(n);

    for (int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        r[i] = make_pair(make_pair(x, y), false);
    }

    for (int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        b[i] = make_pair(x, y);
    }

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

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        //bを一つずつ見ていく
        //rは全て確認
        int mx_y = -1;
        int idx = -1;
        for (int j = 0; j < n; ++j) {
            if (r[j].second) continue;

            if (r[j].first.first < b[i].first && r[j].first.second < b[i].second) {
                if (r[j].first.second > mx_y) {
                    idx = j;
                    mx_y = r[j].first.second;
                }
            }
        }

        if (idx != -1) {
            r[idx].second = true;
            ++ans;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

N = int(input())
L_int_list = list(map(int, input().split()))
L_int_set = set(L_int_list)

ans = 0

if len(L_int_set) < 3:
    print(ans)
    exit()

for i in itertools.combinations(L_int_list, 3):
    if len(set(i)) == 3:
        if max(i) < sum(i) - max(i):
            ans += 1

print(ans)



Measured memory_bytes: 9192
import math
import collections
def prime_factor_table(n):
    table = [0] * (n + 1)

    for i in range(2, n + 1):
        if table[i] == 0:
            for j in range(i + i, n + 1, i):
                table[j] = i

    return table

def prime_factor(n, prime_factor_table):
    prime_count = collections.Counter()

    while prime_factor_table[n] != 0:
        prime_count[prime_factor_table[n]] += 1
        n //= prime_factor_table[n]
    prime_count[n] += 1
    keys, values = zip(*prime_count.most_common())

    return values

N = int(input())
table = prime_factor_table(N)
ans = 0
for i in range(1,N+1,2):
    if prime_factor(i,table) == (1,1,1) or prime_factor(i,table) == (3,1) or prime_factor(i,table) == (1,3):
        ans += 1

print(ans)


Measured memory_bytes: 67240
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back


int main() {
	string s; cin >> s;
	ll n = (ll)s.size();
	if(s[0] == 'A' && islower(s[1]) && islower(s[n-1])) {
		ll cnt = 0; char c = ' ';
		FOR(i,2,n-1) if(s[i] < 'a') {
				cnt++;
				c = s[i];
		}
		if(cnt == 1 && c == 'C') cout << "AC" << endl;
		else cout << "WA" << endl;
	} else cout << "WA" << endl;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long X, long long Y){
    bool check = false;
    for(ll i = 0; i <= 100; ++i){
        for(ll j = 0; j <= 100; ++j){
            if(2*i + 4*j == Y && i + j == X) check = true;
        }
    }
    if(check){
        cout << YES << endl;
        return;
    }
    cout << NO << endl;
    return;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 3724
// AGC_01		A


#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

int main()
{
	int N;
	int N2;
	cin >> N;
	N2 = 2 * N;

	vector<int> list;
	list.resize(N2);

	int in;
	for (size_t i = 0; i < N2; i++)
	{
		cin >> in;
		list[i] = in;

	}
	sort(list.begin(), list.end());

	int sum = 0;

	for (size_t i =	0; i < N; i++)
	{
		sum += list[i * 2];
	}

	cout << sum << endl;



}

Measured memory_bytes: 256
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))

d1 = 0
for i in range(n):
    d1 += abs(x[i] - y[i])
print('{:.8f}'.format(d1))

d2 = 0
for i in range(n):
    d2 += abs(x[i] - y[i])**2
print('{:.8f}'.format(d2**(1/2)))

d3 = 0
for i in range(n):
    d3 += abs(x[i] - y[i])**3
print('{:.8f}'.format(d3**(1/3)))

d = []
p = float('inf')
for i in range(n):
    d.append(abs(x[i] - y[i]))
print('{:.8f}'.format(max(d)))


Measured memory_bytes: 5668
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<utility>
#include<bitset>
#include<complex>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=a; i<=b; ++i)
#define FOR(i,a,b) for(int i=a; i<b; ++i)
#define MP make_pair
typedef long long LL;
typedef pair<int,int> pii;

const int maxn = 300;
const int md = 1e9 + 7;

int n, m;
LL f[maxn+2][maxn+2][maxn+2];

inline void Update(int i, int k, int j, int nx) {
	if(f[i][k][j] == -1) return;
	if(f[nx][k][j] != -1)
		f[nx][k][j] = (f[nx][k][j] + f[i][k][j]) % md;
	if(f[i][nx][j] != -1)
		f[i][nx][j] = (f[i][nx][j] + f[i][k][j]) % md;
	if(f[i][k][nx] != -1)
		f[i][k][nx] = (f[i][k][nx] + f[i][k][j]) % md;
}

int main() {
	scanf("%d%d", &n, &m);
	int li, ri, xi;
	f[1][0][0] = f[0][1][0] = f[0][0][1] = 1;
	for(int i = 1; i <= m; ++i) {
		scanf("%d%d%d", &li, &ri, &xi);
		for(int k = 0; k < ri; ++k)
			for(int j = 0; j < ri; ++j) {
				if(k != 0 && k == j) continue;
				int tmp = 1;
				if(k >= li) ++tmp;
				if(j >= li) ++tmp;
				if(tmp != xi)
					f[ri][k][j] = f[k][ri][j] = f[k][j][ri] = -1;
			}
	}
	for(int i = 1; i < n; ++i) {
		for(int k = 0; k < i; ++k)
			for(int j = 0; j < i; ++j) {
				if(k != 0 && k == j) continue;
				Update(i, k, j, i+1);
				Update(k, i, j, i+1);
				Update(k, j, i, i+1);
			}
	}
	LL ans = 0;
	for(int i = 0; i < n; ++i)
		for(int k = 0; k < n; ++k) {
			if(f[n][i][k] > 0)
				ans = (ans + f[n][i][k]) % md;
			if(f[i][n][k] > 0)
				ans = (ans + f[i][n][k]) % md;
			if(f[i][k][n] > 0)
				ans = (ans + f[i][k][n]) % md;
		}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 215424
#include<stdio.h>
int main(){
  int n,a[110],b[110],i;
  char s[110],c;
  while(scanf("%d",&n),n){
    scanf("%s",s);
    for(i=0;i<n;i++)scanf("%d %d",&a[i],&b[i]);
    while(n--){
      a[n]--;
      b[n]--;
      c=(s[a[n]]+b[n]-a[n]-'a')%26+'a';
      s[a[n]]=(s[b[n]]+b[n]-a[n]-'a')%26+'a';
      s[b[n]]=c;
    }
    printf("%s\n",s);
  }
  return 0;
}

Measured memory_bytes: 588
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　   ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

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

    string s;
    cin >> s;
    Yes(s[2] == s[3] && s[4] == s[5]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
//const ll big=998244353;
const ll big=1000000007;
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll in(ll x){
    return exp(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    string s;cin >> s;
    string ans="";
    rep(i,s.size()){
        if(s[i]=='0'||s[i]=='1')ans.push_back(s[i]);
        else {
            if((int)ans.size()!=0)ans.pop_back();
            else continue;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define SZ(x) ((int)(x).size())
#define MEM(x,a) memset(x,a,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
const ll mod=1000000007,N=1e5+5,M=1e5+5,INF=0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head

int main(void){
    int x,ans=0;
    cin>>x;
    ans+=x/500*500*2;
    x%=500;
    ans+=x/5*5;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N, K; cin >> N >> K;
    cout << (N - K + 1) << endl;
}


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

int main(){
	int n;
	cin>>n;
	int *A=new int[n];
	for(int i=0;i<n;++i)cin>>A[i];
	int q,k,sum=0;
    cin>>q;
    for(int i=0;i<q;++i){
    	cin>>k;
    	if(*(lower_bound(A,A+n,k))==k)sum++;
    }
    cout<<sum<<endl;
	return 0;
}


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

typedef vector<vector<pair<vector<int>, long long int>>>type;

int V, E, K;
 type time(const type&lts, const type&rts, const bool flag) {
	type squs(V,vector<pair<vector<int>,long long int>>(V));
	for (int i = 0; i < V; ++i) {
		for (int j = 0; j < V; ++j) {
			if (i == j)squs[i][j] = make_pair(vector<int>(), 0ll);
			else squs[i][j] = make_pair(vector<int>(), static_cast<long long>(-1e17));
		}
	}
	vector<vector<int>>ps(V, vector <int>(V));
	for (int k = 0; k < V; ++k) {
		for (int i = 0; i < V; ++i) {
			for (int j = 0; j < V; ++j) {
				if (squs[i][j].second <lts[i][k].second + rts[k][j].second) {
					squs[i][j].second = lts[i][k].second + rts[k][j].second;
					if (flag) {
						ps[i][j] = k;
					}
				}
			}
		}
	}
	
	if (flag) {
		for (int i = 0; i < V; ++i) {
			for (int j = 0; j < V; ++j) {
				const int k = ps[i][j];
				squs[i][j].first.clear();
				squs[i][j].first.insert(squs[i][j].first.end(), lts[i][k].first.begin(), lts[i][k].first.end());
				squs[i][j].first.insert(squs[i][j].first.end(), rts[k][j].first.begin(), rts[k][j].first.end());
			}
		}
	}
	return squs;
}
type square(const type&ts,bool flag) {
	return time(ts, ts, flag);
}

type power(const type&ts,const long long  int num,const bool flag) {
	assert(num);
	if (num == 1)return ts;
	else {
		type pot(square(power(ts,num/2,flag),flag));
		if (num % 2) {
			pot = time(pot, ts, flag);
		}
		return pot;
	}
}
vector<int>ans;
bool check(const type &ts,const long long int run,const int point,const bool flag) {
	
	type t(power(ts, run, flag&&run <= 100));
	long long int amax = 0;
	int ai = -1;
	int aj = -1;
	for (int i = 0; i < V; ++i) {
		for (int j = 0; j < V; ++j) {
			if (amax < t[i][j].second) {
				amax = t[i][j].second;
				ai = i;
				aj = j;
				
			}
		}
	}if (run <= 100 && flag) {
		ans.clear();
		ans.push_back(ai);
		ans.insert(ans.end(), t[ai][aj].first.begin(), t[ai][aj].first.end());
	}
	if (amax >= point)return true;
	else return false;
}

int main() { cin >> V >> E >> K;
	type times(V, vector<pair<vector<int>,long long int>>(V, make_pair(vector<int>(),static_cast<long long int>(-1e18))));
	for (int i = 0; i < E; ++i) {
		long long int a, b, c; cin >> a >> b >> c;

		times[a][b].second = max(times[a][b].second, c);
		times[a][b].first = vector<int>(1,b);
	}
	for (int i = 0; i < V; ++i) {
		times[i][i] = make_pair(vector<int>(1,i),0);
		
	}
	long long int amin = 0;
	long long int amax = 1e6+10;
	while (amin + 1 != amax) {
		long long int amid((amin + amax) / 2);
		if (check(times,amid, K,false)) {
			amax = amid;
		}
		else {
			amin = amid;
		}
	}
	if (amax >1e6+5) {
		cout << -1 << endl;
	}
	else {
		check(times, amax, K,true);
		cout << amax << endl;
		if (amax <= 100) {
			for (int i = 0; i < ans.size(); ++i) {
				cout << ans[i];
				if (i != ans.size() - 1)cout << " ";
				else cout << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 13992
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint l, r; cin >> l >> r;
  r = min(r, l + 2019);
  lint res = 1e9;
  for (lint j = l; j <= r; ++j) for (lint i = l; i < j; ++i) {
    res = min(res, i * j % 2019);
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int n,t,a;
ll ans[mx];
vector<int> v[mx];
vector<int> d(mx,0);
vector<int> e(mx,0);
vector<int> ne(mx,0);
int me=0;

void dfs(int x,int p){
  for(auto to : v[x]){
    if(to == p){  continue; }
    d[to] = d[x]+1;
    ne[to]=x;
    dfs(to,x);
  }
}

void ndfs(int x,int p){
  for(auto to : v[x]){
    if(to == p){ continue;}
    e[to] = e[x]+1;
    me = max(me,e[to]);
    ndfs(to,x);
  }
}


int main() {
  cin >> n >> t >> a;
  for(int i=1,a,b; i<n; i++){ 
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  d[a]=0;
  dfs(a,-1);
  int md = 1+(d[t]/2);//max noboreru
  int k=d[t];
  int nxtt = t;
  while(k>md){
    nxtt = ne[nxtt];//oya?
    k = d[nxtt];
  }
  //nxtt new ne//k origin fukasa
  e[nxtt]=0;
  ndfs(nxtt,ne[nxtt]);
  cout << d[nxtt]+me-1 <<endl; 
  return 0;
}  


Measured memory_bytes: 15744
n, qtime = map(int, input().split(" "))
Name, Time,  = [], []
for i in range(n):
    name, time = map(str, input().split(" "))
    time = int(time)
    Name.append(name)
    Time.append(time)

cu_time = 0
while len(Time) > 0:
    #print(Name, Time)
    name, time = Name.pop(0), Time.pop(0)
    if time <= qtime:
        cu_time += time
        print(name, cu_time)
    else:
        time -= qtime
        cu_time += qtime
        Name.append(name)
        Time.append(time)

    


Measured memory_bytes: 9528
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
ll work(int x){
	return (ll)x*x*x;
}
int main(){
	int n=read(),k=read();
	ll ans=work((n/k));
	if(k%2==0){
		int u=k/2;
		ans+=work((n/u+1)/2);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
string s;
int a,b,c,i;
vector<int>v;
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='a')a++;
		else if(s[i]=='b')b++;
		else c++;
	}
	v.pb(a),v.pb(b),v.pb(c);
	sort(v.begin(),v.end());
	if(v[2]-v[0]<=1)rc("YES");
	rc("NO");
}

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

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

void solve(){
    int x, n; cin >> x >> n;
    vector<int> p(n);

    int idx = 0;
    for(int i = 0; i < n; i++) {
        cin >> p[i];
        if(p[i] == x){
            idx = i;
        }
    }



    unordered_set<int> elem(p.begin(), p.end());
    if(elem.find(x) == elem.end()){
        cout << x << endl;
        return;
    }
    int before = x - 1;
    int after = x + 1;
    while(true){
        if(elem.find(before) == elem.end()){
            cout << before << endl;
            return;
        }
        if(elem.find(after) == elem.end()){
            cout << after << endl;
            return;
        }
        before--;
        after++;
    }

}

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

    solve();
    
    return 0;
}



Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);

    vector<int> a(n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);

    sort(a.begin(), a.end());
    int max = a[n - 1], center = a[0];
    int max_2 = (max + 1) / 2;

    for(int i = 1; i < n - 1; i++){
        if(abs(max_2 - a[i]) < abs(max_2 - center)) center = a[i];
    }

    printf("%d %d\n", max, center);

    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    if (n % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < n/2; ++i) {
        if (s[i] != s[i + n/2]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[11], t[11];
    int i, len1, len2;

    gets(s);
    gets(t);

    len1=strlen(s);
    len2=strlen(t);

    for(i=0; i<len1; i++){
        if(s[i]!=t[i]){
            printf("No\n");
            return 0;
        }
    }
    if(t[len2-1]>=97 && t[len2-1]<=122 && len2==(len1+1)) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 1512
#include <stdio.h>
#include <cmath>
#include <algorithm>

int main(){
	int n,tmp,count = 0,limit;
	scanf("%d",&n);

	for(int i = 0; i < n; i++)
	{
		scanf("%d",&tmp);
		limit = sqrt(tmp);
		for(int j = 2; j <= limit; j++){
			if(tmp%j==0){
				count++;
				break;
			}
		}
	}
	printf("%d\n",n-count);
}



Measured memory_bytes: 2716
function Main (S) {
  S = S.split("\n")[0].split("");
  var oche = [];
  var ans = "yes";
  for (var i of S) {
    if (oche.some(inp => inp == i)) ans = "no";
    oche.push(i);
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll m, d;
    cin >> m >> d;
    ll ans = 0;
    repd(i, 1, m + 1) {
        repd(j, 1, d + 1) {
            int d1 = j % 10, d10 = j / 10;
            if (d1 >= 2 && d10 >= 2 && d1 * d10 == i)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
  
  int d; cin>>d;
  vector<int> c(26), t(d), l(26,-1);
  vector s(d,vector(26,0));
  for(auto &i:c) cin>>i;
  for(auto &i:s){
    for(auto &j:i) cin>>j;
  }
  for(auto &i:t) {
    cin>>i; --i;
  }
  ll score{};
  for(int day=0; day<d; day++){
    score += s.at(day).at(t.at(day));
    l.at(t.at(day)) = day;
    for(int i=0; i<26; i++){
      score -= c.at(i)*(day-l.at(i));
    }
    cout << score << endl;
  }
  
}


Measured memory_bytes: 3648
#include<iostream>

using namespace std;

int main() {

   int n, m;
   cin >> n >> m;
   int mtrxA[n][m], mtrxB[m];
   for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
         int v;
         cin >> v;
         mtrxA[i][j] = v;
      }
   }

   for (int i = 0; i < m; i++) {
      int v;
      cin >> v;
      mtrxB[i] = v;
   }

   for (int i = 0; i < n; i++) {
      long sum = 0;
      for (int j = 0; j < m; j++) {
         sum += mtrxA[i][j] * mtrxB[j];
      }
      cout << sum << endl;
   }

   return 0;

}

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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<ll int,ll int>
#define pb push_back
#define ppb pop_back
#define vi vector<ll int>


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		ll n,a,b;
		cin >> n >> a >> b;
		ll ans = n / (a+b);
		ans = ans * a;
		ll r = n % (a+b);
		if(r > a) ans += a;
		else ans += r;
		cout << ans;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>

int main(){
    boost::multiprecision::cpp_int A,B;
    std::cin>>A>>B;
    if(A>B)std::cout<<"GREATER";
    else if(A<B)std::cout<<"LESS";
    else std::cout<<"EQUAL";
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int n,m;
bool vis[100005];
vector<int> road1,road2,g[100005];
void dfs(int x)
{
	vis[x]=1;
	road1.push_back(x);
	for(int i=0;i<g[x].size();i++)
		if(!vis[g[x][i]])
		{
			dfs(g[x][i]);
			break;
		}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1);
	swap(road1,road2);
	dfs(1);
	cout<<road1.size()+road2.size()-1<<endl;
	for(int i=road1.size()-1;i>=0;i--)
		cout<<road1[i]<<' ';
	for(int i=1;i<road2.size();i++)
		cout<<road2[i]<<' ';
	cout<<endl;
	return 0;
}


Measured memory_bytes: 9720
import java.util.Scanner;
import java.util.function.LongSupplier;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static final long[] fal_rnd(long[] ar,LongSupplier sp){
		int l=-1,r=ar.length;
		while(l+1!=r)
			ar[Math.random()<0.5?++l:--r]=sp.getAsLong();
		return ar;
	}
	static final IntStream REPS(int v){
		return IntStream.range(0,v);
	};
	public static void main(String[] __){
		int j;
		while((j=s.nextInt())!=0){
			System.out.println(
					(int)
					REPS(j).map(i->s.nextInt()).sorted().skip(1).limit(j-2).average().getAsDouble()
					);
		}
	}
}

Measured memory_bytes: 33596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define INF (int)1e9
#define EPS 1e-6
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long int lli;
typedef pair<lli, lli> pll;
typedef pair<int, int> pii;
typedef unordered_map<char, lli> mcl;
typedef unordered_map<lli, lli> mll;
typedef unordered_set<lli> usl;
typedef unordered_set<char> usc;
typedef unordered_set<pll> uspll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef map<int,int> mpii;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<double, double> pdd;
const double pi = 3.14159265358979323;

vector<lli> a_vec;
vector<lli> b_vec;
vector<lli> c_vec;
lli a, b, c;
lli dp[200][200][200];
		
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tc, n;
	string s;
	int ans = 0;
	cin >> n;
	vector<int> vec;
	REP(i, n){
		int val;
		cin >> val;
		vec.PB(val);
	}
	sort(all(vec));
	REP(i, n){
		FOR(j, i + 1, n, 1){
			FOR(k, j + 1, n, 1){
				if((vec[i] + vec[j] > vec[k]) && (vec[i] != vec[j]) && (vec[j] != vec[k])){
					ans++;
				}
			}
		}
	}
	cout << ans;
		
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

signed main() {

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

  int t;

  // cin >> t;
  t = 1;

  while (t--) {
    string s, t;
    cin >> s >> t;

    t.pop_back();

    cout << (s == t ? "Yes" : "No") << endl;
  }
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int n[] = new int[5];
		int count = 0;
		int temp = 0;

		for(int i = A; i <= B; i++) {
			temp = i;
			for(int j = 0; j < 5; j++) {
				n[j] = temp % 10;
				temp = temp / 10;
			}

			if(n[0]==n[4] && n[1]==n[3]) {
				count++;
			}
		}

		System.out.println(count);
	}

}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
#define CAP_MIN 1000000000000001

int main(void) {
	long long n, capacity[5];
//	long long cap_min = long long(pow(10, 15))+1;
	long long cap_min = CAP_MIN;
	cin >> n;
	for (int i = 0; i < 5; i++) {
		cin >> capacity[i];
		if (cap_min > capacity[i]) {
			cap_min = capacity[i];
		}
	}
	long long ret = (n - 1) / cap_min;
	ret += 5;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100

typedef unsigned char	U08;

static U08 Serection_Sort_U08( U08 *u08a_A, U08 u08_N );

int main()
{
	U08 u08_length;
	U08 u08a_sequence[MAX];
	U08 u08_idx;
	U08 u08_cnt;
	
	scanf("%d",&u08_length);
	
	for( u08_idx = 0; u08_idx < u08_length; u08_idx++ )
	{
		scanf("%d",&u08a_sequence[u08_idx]);
	}
	
	u08_cnt = Serection_Sort_U08( u08a_sequence, u08_length );
	
	for( u08_idx = 0; u08_idx < u08_length; u08_idx++ )
	{
		if( u08_idx == ( u08_length - 1 ) )
		{
			printf("%d\n",u08a_sequence[u08_idx]);
		}
		else
		{
			printf("%d ",u08a_sequence[u08_idx]);
		}
	}
	printf("%d\n",u08_cnt);
	
	return 0;
}

U08 Serection_Sort_U08( U08 *u08a_A, U08 u08_N )
{
	U08 u08_i;
	U08 u08_j;
	U08 u08_minj;
	U08 u08_buffer;
	U08 u08_flg = 0;
	U08 u08_swap = 0;
	
	for( u08_i = 0; u08_i < ( u08_N - 1 ); u08_i++ )
	{
		u08_minj = u08_i;
		
		for( u08_j = ( u08_i + 1 ); u08_j <= ( u08_N - 1 ); u08_j++ )
		{
			if( u08a_A[u08_j] < u08a_A[u08_minj] )
			{
				u08_minj = u08_j;
				u08_flg = 1;
			}
			else
			{
				//Do Nothing
			}
		}
		
		if( 0 != u08_flg )
		{
			u08_buffer = u08a_A[u08_minj];
			u08a_A[u08_minj] = u08a_A[u08_i];
			u08a_A[u08_i] = u08_buffer;
			u08_swap++;
			u08_flg = 0;
		}
	}
	return u08_swap;
}


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  if(N%2==1){
    cout << "No" << endl;
    return 0;
  }
  string T(N/2,'a');
  for(int i=0; i<N/2; i++){
    T.at(i) = S.at(i);
  }
  if(S==T+T){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi

a=1
a1 = []
10.times do |i|
  a*=6
  if a<=n
    a1<<a
  else
    break
  end
end

a=1
a2 = []
10.times do |i|
  a*=9
  if a<=n
    a2<<a
  else
    break
  end
end

a1.reverse!
a2.reverse!
#puts a1.to_s
#puts a2.to_s

# dp[金額]=回数
dp = h
dp[0]=0
a1.each do |i|
  d=n/i
  
  cur=Marshal.load(Marshal.dump dp)
  cur.each do |k,v|
    min = min d,5
    1.upto(min) do |j|
      dp[k+i*j] = dp[k] + j if k+i*j<=n
    end
  end
end

#puts dp.to_s

a2.each do |i|
  d=n/i
  
  cur=Marshal.load(Marshal.dump dp)
  cur.each do |k,v|
    min = min d,8
    1.upto(min) do |j|
      next if k+i*j>n

      c = dp[k] + j 
      if dp[k+i*j]>c || dp[k+i*j]==0
        dp[k+i*j] = c 
      end
    end
  end
end

#puts dp.to_s


ar = dp.to_a.sort
#puts ar.to_s
cnt = ar[-1][1] + n-ar[-1][0] 
puts cnt

Measured memory_bytes: 14076
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main()
{
  IOS;
  int n;
  cin>>n;
  int count = 0;
  int k = n%1000;
  if(k!=0)
  {
    int ans = 1000-k;
    cout<<ans;
  }
  else
  {
    cout<<"0";
  }
  

  return 0;
}



Measured memory_bytes: 3608
/*input
1000000000
*/

#include <bits/stdc++.h>

using namespace std;

int main() {
  int a;
  scanf("%d", &a);
  int b = a / 500 * 1000;
  int c = (a % 500) / 5 * 5;
  printf("%d\n", b + c);
  return 0;
}

Measured memory_bytes: 256
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, ll M) {
  ll result = 0;

  if (M - 2 * N >= 0) {
    result += N;
    M -= N * 2;
  } else {
    result += M / 2;
    M = 0;
  }
  result += M / 4;

  cout << result << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  solve(N, M);
  return 0;
}


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B){
    cout << C << endl;
  }else if(A==C){
    cout << B << endl;
  }else{
    cout << A << endl;
  }
  return 0;
}


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

int main() {
  int H, W;
  string S;

  cin >> H >> W;
  for (int i=0; i < W+2; i++)
    cout << '#';
  cout << endl;
  for (int i=0; i < H; i++) {
    cin >> S;
    cout << '#' << S << '#' << endl;
  }
  for (int i=0; i < W+2; i++)
    cout << '#';
  cout << endl;
}

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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

int N, K, A[(int)1e5];

inline void Main() {
  // code
  int n, a[(int)1e5];
  long long x[(int)1e5];
  long long s = 0, t = 0;
  cin>>n;
  rep(i,n) {
    cin>>a[i];
    s += a[i];
    if(i % 2 == 1) t += a[i];
  }

  x[0] = s - 2*t;
  repi(i, 1, n) {
    x[i] = 2*a[i-1] -x[i-1];
  }
  rep(i, n) {
    if(i!=0) cout << ' ';
    cout << x[i];
  }
  cout << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
  string s;
  cin >> s;

  //入力が1種類の場合
  bool allFlag = true;
  rep(i,s.size()-1){
    if(s[i] != s[i+1]) allFlag = false;
  }

  if(allFlag){
    cout << s.size() << endl;
    return 0;
  }
  //その他の処理
  int ans = 10000000;
  rep(i,s.size()-1){
    if(s[i+1] != s[i]) ans = min(ans,max(i+1,(int)s.size()-i-1));
  }
  cout << ans << endl;
  return 0;
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define mod 1000000007

int main()
{

    ll n, m;
    cin >> n >> m;
    vector<string> v;
    for(ll i = 0; i < n; i++)
    {

        string ss;
        cin >> ss;
        v.pb(ss);
    }
    n+=2;
    m+=2;
    ll id=0;
    for(ll i = 1; i <= n; i++)
    {

        if(i==1||i==n)
        {

            for(ll j =0; j < m; j++) cout << "#";
        }
        else
            cout << "#" << v[id++] << "#";
        cout << endl;
    }
}


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

int main(){
	int n;
	cin >> n;
	vector<int> l(n);
	rep(i,n) cin >> l[i];
	sort(l.begin(), l.end());
	
	int res = 0;
	rep(a,n){
		int c = a+2;
		for(int b = a+1; b < n; b++){
			while(c < n && (l[c] < l[a] + l[b]) ){
				c++;
			}
			res += (c-1) - b;
		}
	}
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	if (n % min(min(min(min(a, b), c), d), e) == 0) {
		cout << n / min(min(min(min(a, b), c), d), e) + 4 << endl;
	}
	else {
		cout << n / min(min(min(min(a, b), c), d), e) + 5 << endl;
	}
	cin >> n;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#define N 1000

using namespace std;

int main(void){
  int c0[N+1]={0}, c1[N+1]={0};
  int c,d;
  char buf[16];
  
  while (fgets(buf, 16, stdin), strlen(buf)>2){
    sscanf(buf, "%d,%d", &c,&d);
    c0[c]++;
  }
  while (fgets(buf, 16, stdin)){
    sscanf(buf, "%d,%d", &c,&d);
    c1[c]++;
  }
  for (int i=1; i<=N; i++){
    if (c0[i]>0 && c1[i]>0){
      printf("%d %d\n",i, c0[i]+c1[i]);
    }
  }
  
  return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define inf 2e9
#define f first
#define s second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

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

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

ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}


int main (){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min({a+b,b+c,c+a}) << "\n";
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A1 = list(map(int,input().split()))
    A2 = list(map(int,input().split()))

    max = 0
    candy = 0
    for i in range(N):
        candy = sum(A1[:i])+sum(A2[i-1:])
        if candy > max:
            max = candy
    if(N == 1):
        max = A1[0]+A2[0]
    print(max)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include <numeric>
#include<vector>

#define LL long long
#define MOD 1000000007

using namespace std;


/*
LL GCD(LL a, LL b) {
	if (a < b) GCD(b, a);
	LL r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
*/

int main() {

	LL N, M;

	cin >> N >> M;

	LL A[31][31];
	LL ANS[31][31] = {};

	for (int i = 0; i < N; i++) {
		cin >> A[i][0];
		for (int j = 1; j <= A[i][0]; j++) {
			cin >> A[i][j];
			ANS[i][A[i][j]-1] = 1;
		}
	}
	int ans = 0;
	for (int i = 0; i < M; i++) {
		bool flag = true;
		for (int k = 0; k < N; k++) {
			if (ANS[k][i] == 0) {
				flag = false;
			}
		}
		if(flag)
			ans++;
	}

	cout << ans << endl;
	cin >> ans;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int a[3][3];
    for(int i=0; i<3; i++) for(int j=0; j<3; j++) cin >>a[i][j];

    int x[3], y[3];
    x[0] = 0;

    for(int i=0; i<3; i++) y[i] = a[0][i] - x[0];
    for(int i=0; i<3; i++) x[i] = a[i][0] - y[0];

    bool flg = true;

    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            if(x[i]+y[j] != a[i][j]) {
                flg = false;
            }
        }
    }
    if(flg) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

template <typename T> T gcd(T a, T b) {
	if (b == 0) return abs(a);
	T r; while ((r = a % b) != 0) a = b, b = r;
	return abs(b);
}

signed main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >>N;
    vector<int> x(N+1); cin >> x;

    sort(all(x));

    int g = x[1] - x[0];
    rep1(i, N) {
        g = gcd(g, x[i+1] - x[i]);
    }
    
    cout << g << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
typedef long long ld;


int main() {
	// violinista forever xd
	ios::sync_with_stdio(0),cin.tie(0);
	string num;
	cin>>num;
	ll n=0;
	for(int i=0;i<num.size();i++) n+=num[i]-48;
	if(n%9) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	
	return 0;
}

Measured memory_bytes: 3720
from collections import Counter

N = int(input().strip())
Vs = list(map(int,input().strip().split()))


def get_word_num(Ss):
    hists = {}
    for v in Ss:
        if v in hists.keys():
            hists[v] += 1
        else:
            hists[v] = 1

    return sorted(hists.items(),reverse = True,key = lambda h: h[1])


even_ar = Vs[0::2]
odd_ar = Vs[1::2]

#even_hist = Counter(even_ar).most_common(2)
even_hist = get_word_num(even_ar)
#odd_hist = Counter(odd_ar).most_common(2)
odd_hist = get_word_num(odd_ar)

if even_hist[0][0] != odd_hist[0][0]:
    print(N - even_hist[0][1] - odd_hist[0][1])
else:
    if len(even_hist) == 1 and len(odd_hist) == 1:
        print(len(even_ar))
    else:
        print(N - max(even_hist[0][1] + odd_hist[1][1], even_hist[1][1] + odd_hist[0][1]))


Measured memory_bytes: 21084
/*"You can do anything you set your mind to,man" - Eminem*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define llpow(a,b) (ll)(pow(a,b)+0.5)
#define l_b(a,val) min((int)a.size()-1, (int)(lower_bound(a.begin(),a.end(),val)-a.begin()))
#define f first
#define up(a,b) max(a,b)
#define s second
#define INF 9223372036854775807
const  int mod = 1000000007;
void add(ll& a, ll b){a+=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
void mul(ll& a, ll b){a*=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
void up_self(ll& a, ll b){a = up(a,b);}
void min_self(ll& a, ll b){a = min(a,b);}
ll binexpomodulo(ll x, ll y){ll res =1;x%=mod;if(!x)return 0;while(y){if(y&1){mul(res, x);}mul(x,x);y>>=1;}return res;}
ll nCrInOr(ll n, ll r){ll res = 1;if(r>n-r)r = n-r;ll rin = 1;for(ll i = 1; i <=r ; i++)rin = (rin*i)%mod;rin = binexpomodulo(rin,mod-2);for(ll i = 1; i <= r; i++)res = (res*(n-i+1))%mod;res = (res*rin)%mod;return res;}
int msb(ll n){int ans;for(int i = 0 ; i < 64;  i++)if(n&(1LL<<i))ans = i+1;return ans;}
void strrev(string& s){int n = (s.size());for(int i = 0 ; i < n/2; i++)swap(s[i],s[n-1-i]);}
int main()
{
	int n, k; cin>>n>>k;
	for(int i = 0 ; i < k ;i++){
		int z; cin>>z;
		n-=z;
	}
	if(n<0)
		cout<<-1<<endl;
	else
		cout<<n<<endl;
	
  	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(void){
  int n,i;
  int x = 0;
  int max = 0;
  scanf("%d",&n);
  char s[n];
  scanf("%s",&s);

  for(i = 0 ;i < n;i++){
    if(s[i] == 'I'){
      x++;
      if(x > max){
        max = x;
      }
    }else if(s[i] == 'D'){
      x--;
    }else{
      printf("error!");
    }
  }
    printf("%d",max);
    return 0;

}


Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int N, A;
  scanf("%d",&N);
  scanf("%d",&A);
  if(N < 500){
    if(N <= A) puts("Yes");
    else puts("No");
  }
  else if(N % 500 != 0){
    if(N % 500 <= A) puts("Yes");
    else puts("No");
  }
  else puts("Yes");

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int H, W;
  cin >> H >> W;

  vector<string> S(H + 1);
  vector<vector<int>> ans(H + 1, vector<int>(W + 1, 0));

  for (int i = 1; i < H + 1; i++) {
    cin >> S[i];
  }

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

  for (int i = 1; i < H + 1; i++) {
    for (int j = 0; j < W; j++) {
      int count = 0;
      if (S[i][j] == '.') {
        for (int k = 0; k < 8; k++) {
          if (1 <= i + dy[k] && i + dy[k] <= H && 0 <= j + dx[k] &&
              j + dx[k] < W) {
            count += S[i + dy[k]][j + dx[k]] == '#' ? 1 : 0;
          }
        }
      }
      ans[i][j] = count;
    }
  }

  for (int i = 1; i < H + 1; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        cout << ans[i][j];
      } else {
        cout << "#";
      }
    }
    cout << "\n";
  }

  return 0;
}


Measured memory_bytes: 256
function Main(input) {
	input = input.split("\n");
    var N = input[0];
	var A = input[1].split(" ").map(Number); //monster
	var B = input[2].split(" ").map(Number); //hero
  
  	var count = 0;
    
  	if(A[0] >= B[0]){
      count += B[0];
      B[0] = 0;
    }
  	else{
      count += A[0];
      B[0] -= A[0];
  	}
  
  	for(var i=1; i<N; i++){
      if(B[i-1] > 0){
        if(A[i] >= B[i-1]){
        	A[i] -= B[i-1];
          	count += B[i-1];
        }
        else{
          	count += A[i];
          	A[i] = 0;
        }
      }
      
      if(A[i] >= B[i]){
      	count += B[i];
      	B[i] = 0;
      }
  	  else{
      	count += A[i];
      	B[i] -= A[i];
  	  }
    }
  
    if(A[N] >= B[N-1]){
        count += B[N-1];
        B[N-1] = 0;
      }
    else{
        count += A[N];
    }

  	//出力
	console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 31764