akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define fi first
#define se second
using namespace std;

const int mn=3007;

int main()
{
	int n,t,a,b,f[mn];
	pair<int,int> p[mn];
	scanf("%d%d",&n,&t);
	FOR(i,1,n) {scanf("%d%d",&a,&b);p[i]=make_pair(a,b);}
	sort(p+1,p+n+1);
	FOR(i,1,n) for(int j=t-1;j>=0;--j) {
		int c=min(j+p[i].fi,t);
		f[c]=max(f[c],f[j]+p[i].se);
	}
	printf("%d",f[t]);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int a,b,c; cin>>a>>b>>c;
    int p=min(a,c);
    int k=p;
    a=a-p;c=c-p;
    if(c<1)cout<<k+b;
    else{
        p=min(b,c); k=k+2*p; b=b-p; c=c-p;
        if(c<1)cout<<k+b;
        else cout<<k+1;
    }
}



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

using namespace std;

const int MAXN = 1e5 + 10;

int memo[MAXN];
int h[MAXN];

int n;

int dp(int pos){
  if(pos >= n) return 1e9 + 9;
  if(pos==(n-1)) return 0;
  if(memo[pos]!=-1) return memo[pos];
  int diff1 = abs(h[pos] - h[pos+1]);
  int diff2 = 0;
  if(pos < (n-2)) diff2 = abs(h[pos] - h[pos+2]);
  return memo[pos] = min(diff1+dp(pos+1),diff2+dp(pos+2));
}

main(){
  cin >> n;
  memset(memo,-1,sizeof(memo));
  for(int i=0;i<n;++i) cin >> h[i];
  cout << dp(0) << endl;
}

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

int n;
int a[4];

double dp[301][301][301];

double dp_count(int a1, int a2, int a3)
{
	if(a1 < 0 || a2 < 0 || a3 < 0)
		return 0;
	
	if(dp[a1][a2][a3] == -1)
	{
		double res = 0;
		
		res = n + a1 * dp_count(a1 - 1, a2, a3) + a2 * dp_count(a1 + 1, a2 - 1, a3) + a3 * dp_count(a1, a2 + 1, a3 - 1);
		
		dp[a1][a2][a3] = res / double(a1 + a2 + a3);
	}
	
	return dp[a1][a2][a3];
}

int main()
{
	for(int i = 0; i <= 300; i++)
	for(int i1 = 0; i1 <= 300; i1++)
	for(int i2 = 0; i2 <= 300; i2++)
	dp[i][i1][i2] = -1;
	dp[0][0][0] = 0;
	
	cin >> n;
	
	for(int i = 1; i <= n; i++)
	{
		int b;
		cin >> b;
		a[b]++;
	}
	
	cout << setprecision(12) << dp_count(a[1], a[2], a[3]);
	
	return 0;
}

Measured memory_bytes: 213376
#include <bits/stdc++.h>
using namespace std;
string s[110];
int a[110];
int num[110];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		num[i]=i;
	for(int i=1;i<=n;i++)
		cin>>s[i]>>a[i];
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
			if(s[i]>s[j] || s[i]==s[j] && a[i]<a[j])
			{
				swap(s[i],s[j]);
				swap(a[i],a[j]);
				swap(num[i],num[j]);
			 } 
	for(int i=1;i<=n;i++)
		printf("%d\n",num[i]);
	return 0;
}

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


int main()     //main method
{
    FIO;




  ll n,x,t;
  cin>>n>>x>>t;
ll a=0;
  while(n>0){
      a++;
      n=n-x;



  }
  cout<<a*t<<"\n";










    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector <int> p(n);
  REP(i, n) {
	cin >> p[i];
  }
  int m   = n + 1;
  int ans = 0;
  REP(i, n) {
	m = min(m, p[i]);
	if (m >= p[i]) {
		ans++;
	  }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int k, a, b; cin >> k >> a >> b;
    for (int i = k; i <= b; i+=k) {
        if (i >= a) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;


    return 0;
}

Measured memory_bytes: 3596
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
n = int(input())
#n, m, k = map(int, sys.stdin.readline().split())
#s = input()
#A = list(map(int, sys.stdin.readline().split()))

a = 1000 - (n % 1000)
if a == 1000:
    a = 0

print(a)










Measured memory_bytes: 9960
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vi  name
//name[i][j]-> vi name[i]
//or-> ||
//map<int,int>mp

//ll n;
//ll ans;
//int ans;
//string s;


signed main(){
	acc_io;
	int H,W;
	string s[100];
	cin>>H>>W;
	rep(i,0,H){
		cin>>s[i];
	}
	int cnt[H][W];
	rep(i,0,W){
		rep(j,0,H){
			if(i+j==0){
				if(s[0][0]=='#')	cnt[0][0]=1;
				else				cnt[0][0]=0;
			}
			else{
				cnt[j][i]=1e9;
				if(i>0){
					if(s[j][i]=='#'&&s[j][i-1]=='.'){
						cnt[j][i]=min(cnt[j][i],cnt[j][i-1]+1);
					}
					else{
						cnt[j][i]=min(cnt[j][i],cnt[j][i-1]);
					}
				}
				if(j>0){
					if(s[j][i]=='#'&&s[j-1][i]=='.'){
						cnt[j][i]=min(cnt[j][i],cnt[j-1][i]+1);
					}
					else{
						cnt[j][i]=min(cnt[j][i],cnt[j-1][i]);
					}
				}
			}
		}
	}
	cout<<cnt[H-1][W-1]<<endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  switch (n%10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
  }
  return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<cstring>
using std::min;
inline void umn(int &a,int b){a=min(a,b);}
using std::max;
inline void umx(int &a,int b){a=max(a,b);}

const int MAXL=5e5+5;

int n;
char s[MAXL];
int main()
{
	int i;
	scanf("%s",s+1);n=strlen(s+1);
	int ans=n;
	for(i=1;i<n;i++) if(s[i]!=s[i+1])
		umn(ans,max(i,n-i));
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
Created on Sun May  3 20:56:39 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

#N = int(input())
N, K = map(int,input().split())

#graph = [[] for _ in range(N+1)]
#for _ in range(N-1):
#    a, b = map(lambda x : int(x)-1, input().split())
#    graph[a].append(b)
#    graph[b].append(a)

su = [False for _ in range(N)]

for _ in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    for a in A:
        su[a-1] = True

ans = 0
for s in su:
    if not s:
        ans += 1
print(ans)


Measured memory_bytes: 9072
#include <stdio.h>

int main(void) {

  int price,quantity;
  int amount=0;
  double sum=0.0;
  int average;
  double i=0.0;

  while(scanf("%d,%d",&price,&quantity)!=EOF) {
    amount+=price*quantity;
    sum=sum+(double)quantity;
    i=i+1.0;
    if(i==3.0) break;
  }
 
  average=(int)((sum/i)+0.5);

  printf("%d\n%d\n",amount,average);

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <bitset>
#include <math.h>
#define INPUT(X) cin >> X
#define OUTPUT(X) cout << X << endl
#define REPEAT(i,n) for(int i=0;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
const ll MOD = 1e9+7;
#define INF 10000000000000


inline ll Upstair(ll n){
	ll rt;
	if(n==1) return 1;
	return n*Upstair(n-1);
}

template<class T>
bool inline ChangeMinimum( T &a, T b )
{
	if( a > b ){
		a = b;
		return true;
	}
	return false;
}

class Tree
{
	public:
//		Tree(int _root);
		int root;
		vector<int> next;
		int value = 0;
};

template<class T>
class Vec3
{
	public:
		T act[3];
};

int main(void) {


	int N;
	INPUT(N);
	vector<Vec3<int>> day(N);
	REPEAT(i,N){
		INPUT(day[i].act[0]);
		INPUT(day[i].act[1]);
		INPUT(day[i].act[2]);
	}
	vector<Vec3<int>> dp(N);

	dp[0].act[0] = day[0].act[0];
	dp[0].act[1] = day[0].act[1];
	dp[0].act[2] = day[0].act[2];

	for(int i=1;i<N;i++){
		dp[i].act[0] = max(dp[i-1].act[1],dp[i-1].act[2]) + day[i].act[0];
		dp[i].act[1] = max(dp[i-1].act[0],dp[i-1].act[2]) + day[i].act[1];
		dp[i].act[2] = max(dp[i-1].act[0],dp[i-1].act[1]) + day[i].act[2];
	}


	int ans = max(dp[N-1].act[0],dp[N-1].act[1]);
	ans = max(ans,dp[N-1].act[2]);

	OUTPUT(ans);
		
}

Measured memory_bytes: 2560
#include <stdio.h>
int main()
{
    int a,b,c,d=0,i;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<=b;i++)
    {
        if(c%i==0)
        d++;

    }
    printf("%d\n",d);
    return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 5;
const int BIG = 2e9;

struct SegmentTree {
    int n;
    vector<int> tree;
    vector<int> lazy;

    SegmentTree() {}
    SegmentTree(int _n) {
        n = _n;
        tree.resize(4 * (n + 2) + 5, BIG);
        lazy.resize(4 * (n + 2) + 5, BIG);
    }

    void propagate(int id, int l, int r) {
        tree[id] = min(tree[id], lazy[id]);

        if(l != r) {
            lazy[id * 2] = min(lazy[id * 2], lazy[id]);
            lazy[id * 2 + 1] = min(lazy[id * 2 + 1], lazy[id]);
        }

        lazy[id] = BIG;
    }

    void update(int id, int l, int r, int L, int R, int val) {
        propagate(id, l, r);

        if(L <= l && r <= R) {
            lazy[id] = min(lazy[id], val);
            propagate(id, l, r);
            return;
        }

        if(r < L || l > R)
            return;

        int mid = (l + r) / 2;
        update(id * 2, l, mid, L, R, val);
        update(id * 2 + 1, mid + 1, r, L, R, val);

        tree[id] = min(tree[id * 2], tree[id * 2 + 1]);
    }

    int getMin(int id, int l, int r, int L, int R) {
        propagate(id, l, r);
        if(L <= l && r <= R)
            return tree[id];

        if(r < L || l > R)
            return BIG;

        int mid = (l + r) / 2;

        return min(getMin(id * 2, l, mid, L, R),
                   getMin(id * 2 + 1, mid + 1, r, L, R));
    }

    void update(int l, int r, int val) {
        update(1, 0, n + 1, l, r, val);
    }

    int getMin(int l, int r) {
        return getMin(1, 0, n + 1, l, r);
    }
};

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

    int n;  cin >> n;
    SegmentTree row(n), col(n);

    for(int i = 1; i <= n - 1; i++) {
        row.update(i, i, n);
        col.update(i, i, n);
    }

    int64_t blackCnt = (int64_t)(n - 2) * (n - 2);

    int q;  cin >> q;

    while(q--) {
        int tp, x;  cin >> tp >> x;
        if(tp == 1) {
            int to = col.getMin(x, x);
            if(2 <= to - 1) {
                blackCnt -= (int64_t)(to - 1 - 2 + 1);
                row.update(1, to - 1, x);
            }
        } else {
            int to = row.getMin(x, x);
            if(2 <= to - 1) {
                blackCnt -= (int64_t)(to - 1 - 2 + 1);
                col.update(1, to - 1, x);
            }
        }
        //cerr << blackCnt << '\n';
    }

    cout << blackCnt << '\n';

    return 0;
}


Measured memory_bytes: 15888
#include <iostream>

using namespace std;

int main(){
	int a, b;	//?????°

	for (a = 1; a <= 9; a++){
		for (b = 1; b <= 9; b++){

			cout << a << "x" << b << "=" << a * b << endl;

		}
	}

	return 0;
}

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

const int sz=1100;
bool mark[sz];

int idx[sz];

int main()
{
    int n,m,p,q,x,y,i,j,k,a,b;

    cin>>n;
    int ara[n+1][n+1];
    for(i=1;i<=n;i++){
        for(j=1;j<n;j++) cin>>ara[i][j];
        idx[i]=1;
    }

    int day=1;
    while(1)
    {
        memset(mark,false,sizeof mark);
        bool bl=false;

        for(i=1;i<=n;i++){
            if(mark[i] || idx[i]>=n) continue;
            p=ara[i][idx[i]];
            if(ara[p][idx[p]]==i && mark[p]==false){
                mark[i]=true, mark[p]=true, bl=true;
                ++idx[i], ++idx[p];
            }
        }

        if(!bl) break;
        ++day;
    }

    bool bl=true;

    for(i=1;i<=n;i++){
        if(idx[i]<n) {
            bl=false;
            break;
        }
    }

    if(!bl) cout<<"-1\n";
    else  cout<<day-1<<'\n';
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int n;
vector<int> a;

bool check(int mid){
    int l1 = 0, r1 = n * 2, l0 = 0, r0 = n * 2;
    if(a[0] >= mid){
        l1 = 1;
    }else{
        l0 = 1;
    }
    if(a[n * 2 - 2] >= mid){
        r1 = n * 2 - 1;
    }else{
        r0 = n * 2 - 1;
    }

    for(int i = n - 1 ; i > 0 ; --i){
        if(a[i] >= mid && a[i - 1] >= mid){
            l1 = i + 1;
            break;
        }else if(a[i] < mid && a[i - 1] < mid){
            l0 = i + 1;
            break;
        }
    }

    for(int i = n - 1 ; i < n * 2 - 2 ; ++i){
        if(a[i] >= mid && a[i + 1] >= mid){
            r1 = i + 1;
            break;
        }else if(a[i] < mid && a[i + 1] < mid){
            r0 = i + 1;
            break;
        }
    }

    return min(abs(n - l1), abs(n - r1)) < min(abs(n - l0), abs(n - r0));
}

int meguru_search(int ok, int ng){
    while(abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

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

    cin >> n;

    a.resize(n * 2 - 1);
    rep(i, n * 2 - 1){
        cin >> a[i];
    }

    int ans = meguru_search(0, n * 2);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class D
{
	public static void Main()
	{
		long mod = 1000000007;
		int N = Int32.Parse(Console.ReadLine());
		string S1 = Console.ReadLine();
		string S2 = Console.ReadLine();
		int prevType = (S1[0] == S2[0]) ? 0 : 1;  // 0:vertical, 1:horizontal
		long ans = (prevType == 0) ? 3 : 6;
		int i = (prevType == 0) ? 1 : 2;
		while(i < N)
		{			
			int type = (S1[i] == S2[i]) ? 0 : 1;
			if(prevType == 0)
			{
				ans = (ans * 2) % mod;
			}
			else if(type == 1)
			{
				ans = (ans * 3) % mod;
			}

			i += (type == 0) ? 1 : 2;
			prevType = type;
		}

		Console.WriteLine(ans);
	}
}





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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, D; cin >> N >> D;
    D = 2*D+1;
    cout << (N+D-1) / D << endl;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const ll MOD=1e9+7;
const int INF = 0x3f3f3f3f;

int main(){
    int n,t;
    cin>>n>>t;
    vector<int>a(t);
    ll sum=0;
    for(int i=0;i<t;i++){
    	cin>>a[i];
    	sum+=a[i];
	}
    if(sum>=n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  	string s;
    int k;
    cin >> k;
	  cin >> s;
  	if(s.length()<=k){
      cout << s << endl;
    }else{
      for(int i = 0; i < k; i++){
        cout << s[i];
      }
      cout << "..." << endl;
    }
}

Measured memory_bytes: 3624
n = int(input())

ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
    s = input()

    if s == 'AC':
        ac += 1
    elif s == 'WA':
        wa += 1
    elif s == 'TLE':
        tle += 1
    elif s == 'RE':
        re += 1

print('AC x ' + str(ac))
print('WA x ' + str(wa))
print('TLE x ' + str(tle))
print('RE x ' + str(re))



Measured memory_bytes: 69980
#include<iostream>
using namespace std;
int main()
{
int sum=0,n,m,digit,x;
cin>>n;
m=n;
while(m>0)
{
	digit=m%10;
	sum=sum*10+digit;
	m=m/10;
}
if(sum==n)
cout<<"Yes";
else
cout<<"No";
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
using namespace std;
 
int main(){
    
    double r, pai;
    
    pai =3.141592653589;
    cin >> r;
    
    cout << fixed << setprecision(6) << r * r * pai << " " << 2 * pai * r << endl; 
    
    return 0;		 
}


Measured memory_bytes: 3224
def gen_d_prim(n):
    D = [0,0] + [-1] * (n-1)
    for i in range(2, n+1):
        if D[i] > 0: continue
        for j in range(i, n+1, i): D[j] = i
    return D

def is_pairwise(A):
    D = gen_d_prim(10**6)
    past = set()
    for a in A:
        now = set()
        while a != 1:
            if not D[a] in now and D[a] in past:
                return False
            now.add(D[a])
            past.add(D[a])
            a //= D[a]
    return True

def gcd_all(A):
    from math import gcd
    g = 0
    for a in A: g = gcd(g, a)
    return g

def solve():
    if is_pairwise(A): return 0
    if gcd_all(A) ==1: return 1
    return 2
    
n = int(input())
A = [*map(int,input().split())]
print(['pairwise','setwise','not'][solve()], 'coprime')

Measured memory_bytes: 126928
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] x = new int[n];
        for(int i = 0; i < n; i++){
            x[i] = Math.abs(scanner.nextInt() - m);
        }
        int cur = x[0];
        for(int i = 1; i < n; i++){
            cur = calcGcd(cur, x[i]);
        }
        System.out.println(cur);
    }
    // 最大公約数を求める。
    static int calcGcd(int m, int n) {
        if (m <= 0 || n <= 0) {
            throw new IllegalArgumentException("Arguments must be 1 and over.");
        }
        if(m < n) {
            int tmp = m;
            m = n;
            n = tmp;
        }
        int remainder = 0;
        while ((remainder = m % n) != 0) {
            m = n;
            n = remainder;
        }
        return n;
    }
}


Measured memory_bytes: 48332
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template

//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int mi=LINF,ma=0;
  for(int i=0;i<N;i++)mi=min(mi,v[i]);
  for(int i=0;i<N;i++)ma=max(ma,v[i]);
  if(ma-mi>1){cout<<"No"<<endl;return 0;}
  if(ma==mi){
    if(ma<=N/2||ma==N-1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }
  int c=0;
  for(int i=0;i<N;i++)c+=ma-v[i];
  if(0<(ma-c)*2&&(ma-c)*2<=N-c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <limits>
#include <type_traits>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;


// Connected component(DFS)
void dfs(int n, int comp[], vector<int> G[]) {
  int i, j, vertex, neighbor, color[100000];
  REP(i, 100000) color[i] = 0;
  stack<int> S;

  for (i = 0; i < n; i++) color[i] = 0;

  for (i = 0; i < n; i++) {
    if (color[i] == 0) {

      S.push(i);
      while (!S.empty()) {
        vertex = S.top();
        S.pop();
        color[vertex] = 1;
        comp[vertex] = i;
        for (j = 0; j < (int) G[vertex].size(); j++) {
          neighbor = G[vertex][j];
          if (color[neighbor] == 0) S.push(neighbor);
        }
      }
    }
  }
}


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N, 1) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
          par[i] = i;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        siz[ry] += siz[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x){
      return siz[root(x)];
    }
};

int main(){
    int N, M, K, x, y;
    cin >> N >> M >> K;

    vector<int> res(N, 0);
    UnionFind friends(N);

    REP(i, M){
      cin >> x >> y;
      x--; y--;
      res[x]--; res[y]--;
      friends.unite(x, y);
    }
    REP(i, N){
      res[i] += friends.size(i)-1;
    }
    REP(i, K){
      cin >> x >> y;
      x--; y--;
      if(friends.same(x, y)){
        res[x]--; res[y]--;
      }
    }

    REP(i, N) cout << res[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 2432
n,x=map(int,input().split())
a=list(map(int,input().split()))
s=[]
for i in range(n):
    s.append(a[i]-x)
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
print(abs(gcd_list(s)))

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

using Graph = vector<vector<int> >;
struct LowLink {
    // main results
    vector<int> aps; // articulation points
    vector<pair<int,int> > brs; // brideges

    // intermediate results
    vector<int> seen, ord, low;
    void dfs_lowlink(const Graph &G, int v, int p = -1) {
        static int time = 0;
        seen[v] = true;
        ord[v] = low[v] = time++;
        int num_of_child = 0;
        bool exist = false; // for articulation point
        for (auto ch : G[v]) {
            if (seen[ch]) {
                if (ch != p) low[v] = min(low[v], ord[ch]); // back edge
                continue;
            }
            dfs_lowlink(G, ch, v);
            low[v] = min(low[v], low[ch]); // forward edge of DFS-tree
            if (ord[v] < low[ch]) brs.emplace_back(v, ch);
            if (ord[v] <= low[ch]) exist = true;
            ++num_of_child;
        }
        if ((p == -1 && num_of_child > 1) || (p != -1 && exist)) aps.emplace_back(v);
    }
    void solve(const Graph &G) {
        int N = (int)G.size();
        seen.assign(N, 0); ord.resize(N); low.resize(N);
        aps.clear(); brs.clear();
        for (int v = 0; v < N; ++v) if (!seen[v]) dfs_lowlink(G, v);
    }
};

void solve(){
    int N, M; cin >> N >> M;
    Graph G(N);
    for(int i = 0; i < M; ++i){
        int s, t; cin >> s >> t; --s; --t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    LowLink ll;
    ll.solve(G);
    cout << ll.brs.size() << '\n';
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt"};
    cout << "------------\n";
    for(auto filename : filenames){
        ifstream in(filename);
        cin.rdbuf(in.rdbuf());
#endif
        solve();

#ifdef MYLOCAL
        cout << "------------\n";
    }
#endif
  return 0;
}



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

int main(void) {
	int n;
	cin >> n;
	cin.ignore();
	string input;
	while(n--) {
		getline(cin, input);
		bool flag = true;

		string str = input;
		for(int a = 1; a <= 26 && flag; a++) {
			for(int b = 1; b <= 26; b++) {
				if(str.find("this") != string::npos || str.find("that") != string::npos) {
					flag = false;
					cout << str << '\n';
					break;
				} else {
					int l = str.size();
					for(int i = 0; i < l; i++) {
						if(input[i] >= 'a' && input[i] <= 'z')
							str[i] = (a * (input[i] - 'a') + b) % 26 + 'a';
					}
				}
			}
		}
	}
}

Measured memory_bytes: 1208
#include<stdio.h>
int main(void)
{
	int b, f, r, v, n, i;
	int room[5][4][11] = { 0 };

	scanf("%d", &n);

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

	}

	for (b = 1; b <= 4; b++)
	{

		for (f = 1; f <= 3; f++)
		{

			for (r = 1; r <= 10; r++)
			{

				printf(" %d", room[b][f][r]);
			}

			printf("\n");



			if ((f == 3) && (b != 4))
			{
				printf("####################\n");
			}

		}
	}


	return 0;

}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int n, m, p, y, tmp;
  cin >> n >> m;
  long long int a[n]={0};
  tuple<long long int, long long int, long long int> tup;
  vector<tuple<long long int, long long int, long long int>> v;
  pair<long long int, long long int> pa;
  vector<pair<long long int, long long int>> ans;
  for(int i=0; i<m; i++){
    cin >> p >> y;
    v.emplace_back(y, p, i);
  }
  sort(v.begin(), v.end());
  for(auto i : v){
    a[get<1>(i)-1]++;
    tmp = get<1>(i)*1000000 + a[get<1>(i)-1];
    ans.push_back(make_pair(get<2>(i), tmp));
  }
  sort(ans.begin(), ans.end());
  for(int i=0; i<m; i++){
    printf("%012lld\n", ans[i].second);
  }
  return 0;
}

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

int main(){
	int N;
	string S;

	cin >> N;
	cin >> S;

	int index = 0;
	int count = 0;

	while(index + 2 < S.size()) {
		if(!memcmp(&S[index], "ABC", sizeof(char) * 3)) {
			count++;
			index += 3;
		} else {
			index++;
		}
	}

	cout << count << endl;
}


Measured memory_bytes: 256
// Problem : D - RGB Triplets
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define m_p make_pair
#define vpii vector<pii>
#define vs vector<string>
//Proof: 
//Complexity:
void print(vi v){
	ll n = v.size();
	for(ll i = 0;i<n;i++){
		cout<<v[i]<<" ";
	}
        cout<<endl;
}
ll power(ll a, ll b){
    ll res = 1;
    while(b!=0){
        if(b&1){
            res *= a; 
        }
        a = (a * a);
        b = (b / 2);
    }
    return res;
}
int main(){
    SPEED;
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll r = 0, g = 0, b = 0;
    for(ll i =0;i<n;i++){
    	if(s[i]=='R')r++;
    	else if(s[i]=='G')g++;
    	else b++;
    }
    ll val = (r * g * b);
    for(ll i = 0;i<n;i++){
    	char c = s[i];
    	ll x = n - i;
    	if(x%2==0)x--;
    	for(ll j = 1;j<=(x/2);j++){
    		char c1 = s[i+j], c2 = s[i + 2*j];
    		// cout<<c<<" "<<c1<<" "<<c2<<endl;
    		if(c!=c1 && c!=c2 && c1!=c2)val--;
    	}
    }
    cout<<val;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  vector<bool> used(26, false);
  int tmp = -1;
  string s0;
  char c1;
  priority_queue<char, vector<char>, greater<char>> pq;
  if (s.size() < 26) {
    for (auto&& w : s) used[w - 'a'] = true;
    for (int i = 0; i < 26; i++)
      if (used[i] == false) {
        char c = 'a' + i;
        cout << s + c << endl, exit(0);
      }
  } else {
    for (int i = 25; i >= 1; i--) {
      if (s[i - 1] > s[i])
        pq.push(s[i]);
      else {
        pq.push(s[i]);
        tmp = i - 1;
        break;
      }
    }
    if (tmp == -1) cout << -1 << endl, exit(0);
    s0 = string(begin(s), begin(s) + tmp);
    while (!pq.empty()) {
      char x = pq.top();
      pq.pop();
      if (x > s[tmp]) {
        c1 = x;
        break;
      }
    }
    cout << s0 + c1 << endl, exit(0);
  }
}


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

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define INF 1e+9;

int main()
{
    int n, k;
    cin >> n >> k;
    int h[n];
    for(int i=0; i<n; i++)
        cin >> h[i];
    if(n <= k+1)
        cout << abs(h[n-1] - h[0]) << "\n";
    else
    {
        long long dp[n];
        for(int i=0; i<=k; i++)
        {
            dp[i] = abs(h[i] - h[0]);
        }
        for(int i=k+1; i<n; i++)
        {
            dp[i] = INF;
            for(int j=i-1; j >= i-k; j--)
                dp[i] = min(dp[i], abs(h[i] - h[j]) + dp[j]);
        }
        cout << dp[n-1] << "\n";
    }
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int cnt;
void insertionSort(int *A,int n,int g){
  for(int i=g;i<n;i++){
    int v=A[i];
    int j=i-g;
    while(j>=0&&A[j]>v){
      A[j+g]=A[j];
      j=j-g;
      cnt++;
    }
    A[j+g]=v;
  }
}
void shellSort(int A[],int n){
  cnt=0;
  int r=1;
  vector<int> G;
  while(r<=n){
    G.push_back(r);
    r=2*r+1;
  }
  int m=G.size();
  reverse(G.begin(),G.end());
  cout<<m<<endl;
  for(int i=0;i<m;i++) cout<<G[i]<<" \n"[i==m-1];
  for(int i=0;i<m;i++) insertionSort(A,n,G[i]);
  cout<<cnt<<endl;
}
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  shellSort(A,n);
  for(int k=0;k<n;k++) cout<<A[k]<<endl;
  return 0;
}


Measured memory_bytes: 6996
#include<stdio.h>
int main()
{
	int S,h,a,m,s;
	scanf("%d", &S);
	h = S/3600;
	a = S % 3600;
	m = a / 60;
	s = a%60;


	
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 2712
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

const UINT mod = 1000000007;

UINT PowMod(UINT x, UINT y)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = PowMod(x, y / 2);
		return tmp * tmp % mod;
	}
	else
	{
		auto tmp = PowMod(x, y / 2);
		return (tmp * tmp % mod) * x % mod;
	}
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

struct uf
{
	vector<INT> p;

	uf(INT n) : p(n)
	{
		for (size_t i = 0; i < n; i++)
		{
			p[i] = i;
		}
	}

	INT rt(INT n)
	{
		return p[n] == n ? n : p[n] = rt(p[n]);
	}

	void un(INT n, INT m)
	{
		p[rt(n)] = p[rt(m)];
	}

	bool eq(INT n, INT m)
	{
		return rt(n) == rt(m);
	}
};

int main()
{
	INT a, b, c;

	cin >> a >> b >> c;

	cout << max(0LL, c - (a - b)) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  mod(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*mod(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return mod(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}



int main()
{
    string s;
    cin>>s;
    ll p=0;int n=s.length();
    for(int i=0;i<n;i++){
            char c=s[i];
        p+=c-48;
    }
    //cout<<p<<endl;
    if(p%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3720
#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 < (n); ++i)

typedef long long LL;
typedef unsigned long UL;

using namespace std;


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

	int n, c, ans = 0;
	cin >> n;

	vector<int> v(n);

	REP(i, n)
	{
		cin >> v[i];
	}
	REP(i, n)
	{
		cin >> c;
		if (v[i] - c > 0)
		{
			ans += (v[i] - c);
		}
	}

	cout << ans << endl;

	return 0;
}


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

void solve(std::string b)
{
    if (b == "A")
        b = "T";
    else if (b == "T")
        b = "A";
    else if (b == "C")
        b = "G";
    else
        b = "C";
    cout << b << endl;
    return;
}

// Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    std::string b;
    std::cin >> b;
    solve(b);
    return 0;
}

Measured memory_bytes: 768
#include<iostream>

int main(){
	int w,h,x,y;
	std::cin >> w >> h>>x>>y;

	std::cout << static_cast<double>(w)*static_cast<double>(h)/2 << " ";
	if(w == 2*x && h == 2*y){
		std::cout << "1";
	}else{
		std::cout << "0";
	}
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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 (b<a) { a=b; return 1; } return 0; }


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

    cout << N*800 - N/15*200 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n;
int main(){
    //vector<ll> v(n);
    ll k;
    int q;
    cin>>n>>k>>q;
    vector<ll> v(n);
    vector<int> a(q);
    for(int i = 0;i < n; i++){
        v[i]=k;
    }
    for(int i = 0;i < q; i++){
        cin>>a[i];
        a[i]--;
    }
    vector<ll> cnt(n);
    for(int i = 0;i < q; i++){
        cnt[a[i]]++;
    }
//    rep(i,n) cout<<cnt[i]<<" ";
//    cout<<endl;
    for(int i = 0;i < n; i++){
        v[i]-=q-cnt[i];
    }
    int sum=0;
    for(int i = 0;i < n; i++){
        if(v[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

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

// ABC128C - Switches
// https://atcoder.jp/contests/abc128/tasks/abc128_c
void ABC128C() {

	int N, M;
	cin >> N >> M;

	vector<int> k(M);
	vector< vector<int>> S(M);

	for (int i = 0; i < M; i++)
	{
		cin >> k[i];
		vector<int> s(k[i]);

		for (int j = 0; j < k[i]; j++)
		{
			cin >> s[j];
		}
		S[i] = s;
	}

	vector<int> p(M);
	for (int i = 0; i < M; i++)
	{
		cin >> p[i];
	}

	int ans = 0;
	for (int bit = 0; bit < (1<<N); bit++)
	{
		//cout << "bit : " << bit << endl;
		bool flag = true;
		for (int j = 0; j < M; j++)
		{
			//cout << "j : " << j << endl;
			int on = 0;
			for (int l = 0; l < S[j].size(); l++)
			{
				int switch_no = S[j][l] - 1; //論理積は2進数で実行するのでスイッチの番号を0番目からカウントするため
				if (bit & (1 << switch_no)) {
					on++;
				}
			}

			if (on % 2 != p[j]) {
				flag = false;
				break;
			}
		}

		if (flag) {
			ans++;
		}
	}

	cout << ans << endl;

}


int main() {
	ABC128C();

	return 0;
}

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

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    num_psgr, bus_cap, max_itvl = read_h()
    arv_tms = sorted(read_v(num_psgr))

    num_bus = 1
    cur_bus_cap = bus_cap - 1
    deadline = arv_tms[0] + max_itvl
    for t in arv_tms[1:]:
        if t <= deadline and cur_bus_cap >= 1:
            cur_bus_cap -= 1
        else:
            num_bus += 1
            cur_bus_cap = bus_cap - 1
            deadline = t + max_itvl

    print(num_bus)


if __name__ == '__main__':
    main()


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll n,k; cin >> n >> k;
  cout << min(n%k,k-n%k) << endl;
  return 0;
}


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

int main(){
  int x, n;
  cin >> x >> n;
  vector<int> p(n);
  for(int i = 0; i<n; i++){
    cin >> p[i];
  }
  
  vector<bool> judge(105, true);
  for(int i = 0; i < n; i++){
    judge[p[i]] = false;
  }
  
  for(int i = 0; i < 100; i++){
    if(judge[x-i]){
      cout << x-i << endl;
      break;
    }
    else if(judge[x+i]){
      cout << x+i << endl;
      break;
    }
  }
}


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

int main() {
    ll N, M; cin >> N >> M;
    ll sum = 0;
    for(int i = 0; i < M; ++i) {
        ll tmp; cin >> tmp; sum += tmp;
    }
    cout << max(N - sum, (ll)-1) << endl;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    string s;cin>>s;
    vector<vector<ll>> dp(n,vector<ll>(n,0));
    ll ans = 0;
    for(ll i=1; i<n; i++){
        ll idx1 = 0, idx2 = i;
        ll same = 0;
        while(idx2<n){
            if(s[idx1]!=s[idx2])same=0;
            else same = min(same+1,i);
            ans = max(ans,same);
            idx1++;idx2++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 195840
// 2017/12/13 Tazoe

#include <iostream>
#include <cstdlib>
using namespace std;

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

		if(n==0)
			break;

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

		int dif = 1000001;		// ???????????????????°????

		for(int i=0; i<n-1; i++){
			for(int j=i+1; j<n; j++){
				int d = abs(a[i]-a[j]);		// ?????????????????¶?????????

				if(d<dif){
					dif = d;
				}
			}
		}

		cout << dif << endl;
	}

	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> a(M,0);
    vector<ll> b(M,0);
    for(ll i=0;i<M;i++){
        cin>>a[i]>>b[i]
    ;}
    ll ans=0;
    for(ll i=0;i<M;i++){
        //1からいけるかどうか
        vector<bool> check(N+1,0);
        check[1]=1;
        for(ll k=0;k<M;k++){
        for(ll j=0;j<M;j++){
            if(j==i)continue;
            if(check[a[j]]==1||check[b[j]]==1){
                check[a[j]]=1;check[b[j]]=1;
            }
        ;}}
        bool notok=0;
        for(ll j=1;j<=N;j++){
            if(!check[j]){notok=1;break;}
        ;}
        if(notok){ans++;}
    ;}
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int n;
cin>>n;
long long int a[n];
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
long long int maxi=0;
long long int sum=0;
for(int i=0;i<n;i++)
{
	maxi=max(a[i],maxi);
	
	sum = sum + (maxi-a[i]);
}	
	cout<<sum;
	

}

 
 

 


Measured memory_bytes: 5180
#include<stdio.h>
#include<string.h>
int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}
int main(){
  char s[200010];
  char t[200010];
  int snum[30]={};
  int tnum[30]={};
  int slen,tlen;
  int i,j;
  scanf("%s%s",s,t);
  slen=strlen(s);
  tlen=strlen(t);
  for(i=0;i<slen;i++){
    snum[s[i]-'a']++;
  }
  for(i=0;i<tlen;i++){
    tnum[t[i]-'a']++;
  }
  qsort(snum,26,sizeof(int),desc);
  qsort(tnum,26,sizeof(int),desc);
  for(i=0;i<27;i++){
    if(snum[i]!=tnum[i]){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
using namespace std;
const double EPS=1e-10;
double wx[100],wy[100],r[100],tx,ty,sx,sy;
int n,m;
main()
{
	while(cin>>n,n)
	{
		for(int i=0;i<n;i++)cin>>wx[i]>>wy[i]>>r[i];
		cin>>m;
		for(;m--;)
		{
			cin>>tx>>ty>>sx>>sy;
			bool ok=false;
			for(int i=0;i<n;i++)
			{
				if(hypot(wx[i]-sx,wy[i]-sy)<r[i]+EPS&&
					hypot(wx[i]-tx,wy[i]-ty)<r[i]+EPS)continue;
				double t=((wx[i]-sx)*(tx-sx)+(wy[i]-sy)*(ty-sy))/((tx-sx)*(tx-sx)+(ty-sy)*(ty-sy));
				if(t<0)t=0;
				if(t>1)t=1;
				double x=sx+t*(tx-sx),y=sy+t*(ty-sy);
				double dis=hypot(wx[i]-x,wy[i]-y);
				if(dis<r[i]+EPS)
				{
					ok=true;
					break;
				}
			}
			cout<<(ok?"Safe":"Danger")<<endl;
		}
	}
}



Measured memory_bytes: 3240
S=input()
ym=False
my=False
if 1<=int(S[0:2])<=12:
    my=True
if 1<=int(S[2:4])<=12:
    ym=True
if my and ym:
    print('AMBIGUOUS')
elif my:
    print('MMYY')
elif ym:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)

signed main(){
    int n;
    cin >> n;
    vector<int>a(1<<n);
    rep(i,(1<<n)){
        cin >> a[i];
    }
    int s = 0;
    bool ng = 0;
    rep(i,(1<<n)){
        bool flag = 0;
        rep(j,n){
            if((i>>j)&1){
                if(a[i]==0&&a[(i^(1<<j))]==1){
                    ng = 1;
                }
                if(a[(i^(1<<j))]==1){
                    flag = 1;
                }
            }
        }
        if(!flag){
            if(a[i]==1){
                s++;
            }
        }
    }
    if(ng){
        cout << -1 << endl;
    }else{
        cout << s << endl;
    }
    return 0;
}


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

using namespace std;

int main() {
	long long h, aux = 0, total = 0;
	cin >> h;
	
	while (h > 0) {
		h /= 2;
		total += (long long)pow(2, aux);
		aux++;
	}
	
	cout << total;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <set>

// Attributes
int v, e;
std::vector<std::multiset<int>> edges;

// Simplifying
void simplify(int index){
	if(edges[index].size() == 2){
		int next1 = *(edges[index].begin()), next2 = *(edges[index].rbegin());
		if(next1 == next2) return;
		edges[next1].erase(edges[next1].find(index));
		edges[next2].erase(edges[next2].find(index));
		edges[next1].insert(next2);
		edges[next2].insert(next1);
		edges[index].clear();
		simplify(next1);
		simplify(next2);
	}
}

int main(void){
	
	scanf("%d %d", &v, &e);
	edges = std::vector<std::multiset<int>>(v+1);
	for(int i=0; i<e; i++){
		int v1, v2; scanf("%d %d", &v1, &v2);
		edges[v1].insert(v2);
		edges[v2].insert(v1);
	}
	
	// Simplify
	for(int i=1; i<=v; i++) simplify(i);
	
	// Odd vertex -> NO
	int vexist = 0, v2 = 0, v4 = 0, v6plus = 0;
	for(int i=1; i<=v; i++){
		if(edges[i].size() % 2 != 0){
			printf("No");
			return 0;
		}
		else if(edges[i].size() == 2) v2++;
		else if(edges[i].size() == 4) v4++;
		else if(edges[i].size() >= 6) v6plus++;
		
		if(edges[i].size() > 0) vexist++;
	}
	
	/*for(int i=1; i<=v; i++){
		printf("Vertex #%d: ", i);
		for(auto next: edges[i]) printf("%d, ", next);
		printf("\n");
	} printf("v6+: %d, v4: %d, v2: %d, total %d\n", v6plus, v4, v2, vexist);*/
	
	bool status = false;
	if(v6plus > 0) status = true;
	else if(v4 >= 2 && vexist > 2) status = true;
	printf(status ? "Yes":"No");
	return 0;
}

Measured memory_bytes: 17280
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



template <class T>
map<T, int> prime_factors(T n)
{
	map<T, int> res;
	for (T i = 2; i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			int c = 0;
			for ( ; n % i == 0; n /= i)
				++c;
			res[i] = c;
		}
	}
	if (n > 1)
		res[n] = 1;
	return res;
}
vector<int> fact_num, take;
ll dfs(int depth)
{
	if (depth == take.size())
	{
		ll res = 1;
		for (int i = 0; i < take.size(); ++i)
			if (take[i] == fact_num[i])
				res *= fact_num[i] + 1;
		return res;
	}
	else
	{
		ll res = 0;
		for (int i = 0; i <= fact_num[depth]; ++i)
		{
			take[depth] = i;
			res += dfs(depth + 1);
		}
		return res;
	}
}
int main()
{
	ll L;
	while (scanf("%lld", &L), L)
	{
		map<ll, int> f = prime_factors(L);
		fact_num = vector<int>();
		foreach (it, f)
			fact_num.push_back(it->second);
		take.resize(fact_num.size());

		printf("%lld\n", (dfs(0) + 1) / 2);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll l, r, modl[2020];
string str;

int main(){
	cin >> l >> r;
	memset(modl, 0, sizeof(modl));
	if(r-l < 2*2019){
		for(ll i = l; i <= r; i++){
			modl[i%2019]++;
		}
		
		ll ans = 2019;
		for(ll i = 0; i < 2019; i++){
			for(ll j = 0; j < 2019; j++){
				if((i != j && modl[i] > 0 && modl[j] > 0) || (i == j && modl[i] >= 2)){
					ans = min((i*j)%2019, ans);
				}
			}
		}
		cout << ans << endl;
	}
	else{cout << 0 << endl;}
	return 0;
}

Measured memory_bytes: 256