akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long long ull;
const ull M=998244353;
const ull N=1000000007; 
const ull X=99431;
const ull Y=99487;
ull R;
ull L;
const int W=800;
 
 
ull ModPow(ull x, ull n, ull mod) {
        ull ret = 1;
        for (; n > 0; n /= 2, x = (x * x) % mod)
            if ((n & 1) == 1) ret = (ret * x) % mod;
        return ret;
    }
 
ull has=0,vec=1;
ull has2=0,vec2=1;
 
int n;
string s;
unordered_map<ull,int> B[550];
long long ans;
inline void calc(char c, ull &u,ull &p,ull &v,ull &q){
	if(c=='+'){u+=p;v+=q;}
	else if(c=='-'){u+=M-p;v+=N-q;}
	else if(c=='>'){p=(p*X)%M;q=(q*Y)%N;}
	else {p=(p*R)%M;q=(q*L)%N;}
	if(u>=M)u-=M;
	if(v>=N)v-=N;
}
int main(){
	R=ModPow(X,M-2,M);
	L=ModPow(Y,N-2,N);
	cin>>n>>s;
    //n=250000;
    //s=string(n,'+');
	for(int i=0;i<n;i++)calc(s[i],has,vec,has2,vec2);
	for(int i=0;i<n;i++){
		if(i%W==0)continue;
		ull h=0,x=1,hh=0,y=1;
		for(int j=i;j<n;j++){
			if(j%W==0)break;
			calc(s[j],h,x,hh,y);
			if(h==has&&hh==has2)ans++;
		}
		ull nh = (has+M-h)%M;
		nh = nh * ModPow(x,M-2,M)%M;
		ull nh2 = (has2+N-hh)%N;
		nh2 = nh2 * ModPow(y,N-2,N)%N;
		B[i/W+1][nh*N+nh2]++;
	}
	for(int i=0;i<n;i+=W){
		ull h=0,x=1,hh=0,y=1;
		for(int j=i;j<n;j++){
			calc(s[j],h,x,hh,y);
			if(h==has&&hh==has2)ans++;
			auto it = B[i/W].find(h*N+hh);
			if(it!=B[i/W].end())ans+=it->second;
		}
	}
	
	cout<<ans;
 
 
}

Measured memory_bytes: 10372
#include<stdio.h>
#include<string.h>
int vis[100005];
int n,m;
int mod=1e9+7;
int check()
{
    int i=0,j;
    for(j=1;j<=n;++j)
    {
            if(vis[j]==-1)
            {
                vis[j]=0;
            }
            else
            {
                vis[j]=(j>=2?vis[j-2]:0)%mod+vis[j-1]%mod;
            }
    }
    return vis[j-1]%=mod;
}
int main()
{
    int flag=0;
    memset(vis,0,sizeof(vis));
    scanf("%d %d",&n,&m);
    vis[0]=1;
    for(int i=1;i<=m;i++)
    {
        int x;
        scanf("%d",&x);
        vis[x]=-1;
        if(vis[x-1]==-1)
        {
            flag=1;
        }
    }
    if(flag==1)
    {
        printf("0\n");
    }
    else
    {
        printf("%d",check());
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define N 300 + 5
#define Mod 1000000007
#define rep(i, l, r) for(int i = l; i <= r; ++i)
int n, m, l, r, x, ans, cnt[N], a[N][N], num[N][N], dp[N][N][N];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int check(int x, int y, int pos){
    int ans = 0;
    if(x >= pos) ans++;
    if(y >= pos) ans++;
    return ans;
}
int Inc(int a, int b){ return (a += b) >= Mod ? a - Mod : a;}
int main(){
    n = read(), m = read();
    rep(i, 1, m){
        l = read(), r = read(), x = read(), cnt[r]++;
        a[r][cnt[r]] = l, num[r][cnt[r]] = x;
    }
    dp[1][0][0] = 1;
    rep(i, 1, cnt[1]) if(num[1][i] > 1){ puts("0"); return 0;}
    rep(i, 1, n - 1){
        rep(j, 0, i - 1) rep(k, 0, i - 1) if(k != j || (j == 0 && k == 0)){
            dp[i + 1][j][k] = Inc(dp[i + 1][j][k], dp[i][j][k]);
            dp[i + 1][i][k] = Inc(dp[i + 1][i][k], dp[i][j][k]);
            dp[i + 1][j][i] = Inc(dp[i + 1][j][i], dp[i][j][k]);
            rep(p, 1, cnt[i + 1]){
                if(num[i + 1][p] == 1){
                    if(check(j, k, a[i + 1][p]) != 0) dp[i + 1][j][k] = 0;
                    if(check(i, k, a[i + 1][p]) != 0) dp[i + 1][i][k] = 0;
                    if(check(j, i, a[i + 1][p]) != 0) dp[i + 1][j][i] = 0;
                }
                if(num[i + 1][p] == 2){
                    if(check(j, k, a[i + 1][p]) != 1) dp[i + 1][j][k] = 0;
                    if(check(i, k, a[i + 1][p]) != 1) dp[i + 1][i][k] = 0;
                    if(check(j, i, a[i + 1][p]) != 1) dp[i + 1][j][i] = 0;
                }
                if(num[i + 1][p] == 3){
                    if(check(j, k, a[i + 1][p]) != 2) dp[i + 1][j][k] = 0;
                    if(check(i, k, a[i + 1][p]) != 2) dp[i + 1][i][k] = 0;
                    if(check(j, i, a[i + 1][p]) != 2) dp[i + 1][j][i] = 0;
                }
            }
        }
    }
    rep(i, 0, n) rep(j, 0, n) ans = Inc(ans, dp[n][i][j]);
    printf("%d", 1ll * ans * 3 % Mod);
    return 0;
}

Measured memory_bytes: 109568
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const int MAX_N = 100000;

ll a[MAX_N + 1];
ll patterns[MAX_N + 1];


void init(ll patterns[], ll N){
    patterns[0] = 1;
    patterns[1] = 1;

    
    For(i, 2, N + 1){
        patterns[i] = (patterns[i - 1] + patterns[i - 2]) % mod;
    }
}

int main(void){
    ll N, M;
    cin >> N >> M;

    ll answer = 1;

    init(patterns, N);

    rep(i, M){
        cin >> a[i];
    }

    if(M == 0){
        answer = (answer * patterns[N]) % mod;
    }else{
        answer = (answer * patterns[a[0] - 1]) % mod;
        answer = (answer * patterns[N - (a[M - 1] + 1)]) % mod;
    }
        

    rep(i, M - 1){
        ll idx;

        idx = (a[i + 1] - 1) - (a[i] + 1);
        
        if (idx < 0){
            answer = 0;
            break;
        }

        answer = (answer * patterns[idx]) % mod;
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s; cin>>s;
    map<int, int> mp;
    mp[s]++;
    int cnt = 1;
    while(1){
        cnt++;
        s = (s%2==0) ? (s/2) : 3*s+1;
        if(mp[s]>0) break;
        mp[s]++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

ll editDistance(const string x,const string y){
    ll n=x.size(),m=y.size();
    ll dp[n+2][m+2];
    rep(i,n+2)rep(j,m+2) dp[i][j]=LLINF;
    rep(i,n+1) dp[i][0]=i;
    rep(i,m+1) dp[0][i]=i;
    rep2(i,1,n+1)rep2(j,1,m+1){
        dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
        dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
        dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(x[i-1]!=y[j-1]));
    }
    return dp[n][m];
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s,t;
    cin>>s>>t;
    cout<<editDistance(s,t)<<endl;
    return 0;
}


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

using namespace std;


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

    vector<long long> L = {2, 1};
    L.reserve(N);
    for (int i = 2; i <= N; i++) {
        long long sum = 0;
        for (auto l_ptr = L.end() - 2; l_ptr < L.end(); l_ptr++) {
            sum += *l_ptr;
        }
        L.push_back(sum);
    }

    cout << L.back() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

int N,sum=0,max=0;
scanf("%d",&N);
int A1[N];
int A2[N];

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

sum = A1[0];

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

max = sum;
for (int i = 0; i < N-1; i++)
{
  sum = sum+A1[i+1]-A2[i];
  if (max < sum){ max = sum;}
}

printf("%d",max);

return 0;

}

Measured memory_bytes: 1700
n = int(input())
l = list(map(int,input().split()))

num = max(l)+1
rcd = [0 for _ in range(num)]

for x in l:
    for y in range(x, num, x):
            rcd[y] += 1

ans = 0
for k in l:
    if rcd[k] == 1:
        ans += 1

print(ans)


Measured memory_bytes: 32064
#include <iostream>
using namespace std;
int main(void){
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<=n;i++){
     for(int j=0;j<=m;j++){
         if(i*(m-j)+j*(n-i)==k){
             
          cout<<"Yes"<<endl;
          return 0;
         }
         
     }   
     
     
        
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
double W,H,x,y;
int main(){
  cin>>W>>H>>x>>y;
  double res=(H*W)/2;
  int h=H,w=W,X=x,Y=y;
  int f;
  if(h%2==0&&h/2==Y&&w%2==0&&w/2==X) f=1;
  else f=0;
  printf("%.9f\t%d\n",res,f);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>



void change(char *str){
  int len=strlen(str);
  int i;
  for(i=0;i<len;i++){
    if('a'<=str[i]&&str[i]<='z'){
      str[i]-=32;
    }
  }
}

int main(){
  char t[10000];
  char key[10000];
  char eofstr[]={"END_OF_TEXT"};
  int ans=0;

  scanf("%s",key);
  change(key);

  while(1){
    scanf("%s",t);
    if(strcmp(t,eofstr)==0){
      break;
    }
    change(t);
    if(strcmp(t,key)==0){
      ans++;
    }
  }

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



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  int k;
  cin>>n>>k;
  int d = n%k;
  int e = abs(d-k);
  if(d<e) cout<<d<<"\n";
  else cout<<e<<"\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a,b,c,d,n,ans=0; cin>>a>>b>>c>>d>>n;
  if(c*2<=d){
    if(b*2<=c){
      if(a*2<=b){
        ans+=n*4*a;
      }else{
        ans+=n*2*b;
      }
    }else{
      if(a*4<=c){
        ans+=n*4*a;
      }else{
        ans+=c*n;
      }
    }
  }else{
    if(b*4<=d){
      if(a*2<=b){
        ans+=n*4*a;
      }else{
        ans+=n*2*b;
      }
    }else{
      if(a*8<=d){
        ans+=a*4*n;
      }else{
        ans+=(n/2)*d;
        if(b*2<=c){
          if(a*2<=b){
            ans+=(n%2)*4*a;
          }else{
            ans+=(n%2)*2*b;
          }
        }else{
          if(a*4<=c){
            ans+=(n%2)*4*a;
          }else{
            ans+=c*(n%2);
          }
        }
      }
    }
  }
  cout<<ans<<endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
const int MAX_N=200005;
#define int LL
int n;
int A[MAX_N];
int rec[32];
int res[MAX_N];
signed main()
{
//	fill(rec,rec+32,1);
	cin>>n;
	For(i,1,n)cin>>A[i];
	int ans=0;
	For(i,1,n)
	{
		rep(j,0,30)
		{
			if(A[i]&(1<<j))
			{
				res[i]=max(res[i],rec[j]);
				rec[j]=i;
			}
		}
		res[i]=max(res[i],res[i-1]);
		ans+=i-res[i];
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3328
#include<stdio.h>
#include<stdlib.h>
int asc1(const void* a, const void* b)
{
	if (*(int*)a > * (int*)b)return -1;
	if (*(int*)a < *(int*)b)return 1;
	return 0;
}
int en[50004], ec[50004], on[50004], oc[50004];
int asce(const void* a, const void* b)
{
	if (ec[*(int*)a] > ec[*(int*)b])return -1;
	if (ec[*(int*)a] < ec[*(int*)b])return 1;
	return 0;
}
int asco(const void* a, const void* b)
{
	if (oc[*(int*)a] > oc[*(int*)b])return -1;
	if (oc[*(int*)a] < oc[*(int*)b])return 1;
	return 0;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int v[100005];
	for (i = 0; i < n; i++)
		scanf("%d", &v[i]);
	int e[50004], o[50004];
	for (i = 0; i < n; i++)
	{
		if (i % 2 == 0)
			e[i / 2] = v[i];
		else
			o[i / 2] = v[i];
	}
	qsort(e, n / 2, sizeof(int), asc1);
	qsort(o, n / 2, sizeof(int), asc1);
	for (i = 0; i < 50004; i++)
		ec[i] = oc[i] = 0;
	en[0] = e[0];
	ec[0] = 1;
	int k = 1;
	for (i = 1; i < n / 2; i++)
	{
		if (e[i] == en[k - 1])
			ec[k - 1]++;
		else
		{
			en[k] = e[i];
			ec[k] = 1;
			k++;
		}
	}
	on[0] = o[0];
	oc[0] = 1;
	k = 1;
	for (i = 1; i < n / 2; i++)
	{
		if (o[i] == on[k - 1])
			oc[k - 1]++;
		else
		{
			on[k] = o[i];
			oc[k] = 1;
			k++;
		}
	}
	int os[50004], es[50004];
	for (i = 0; i < n / 2; i++)
		os[i] = es[i] = i;
	qsort(es, n / 2, sizeof(int), asce);
	qsort(os, n / 2, sizeof(int), asco);
	if (en[es[0]] != on[os[0]])
		printf("%d\n", n - ec[es[0]] - oc[os[0]]);
	else if (ec[es[1]] > oc[os[1]])
		printf("%d\n", n - oc[os[0]] - ec[es[1]]);
	else
		printf("%d\n", n - ec[es[0]] - oc[os[1]]);
	return 0;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  A--;
  ll cntA = A / C + A / D - A / (C / __gcd(C, D) * D);
  ll cntB = B / C + B / D - B / (C / __gcd(C, D) * D);
  cout << (B - A) - (cntB - cntA) << endl; 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int A[3];
  rep(i,3) cin >> A[i];
  sort(A,A+3);
  if (A[0]==A[1] && A[1]!=A[2]) cout << "Yes" << endl;
  else if (A[0]!=A[1] && A[1]==A[2]) cout << "Yes" << endl;
  else cout << "No" << endl;




  // cout << fixed << setprecision(6);
  return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
int n, a[200005], x, d[1000010], sol;
 
int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a, a+n);
    for(int i=0;i<n;i++){
        x=a[i];
        if(d[x]!=0){
            d[x]++;
            continue;
        }
        for(int j=x;j<=a[n-1];j+=x){
            d[j]++;
        }
    }
    for(int i=0;i<n;i++){
        if(d[a[i]]==1){
            //cout<<a[i]<<" ";
            sol++;
        }
    }
    cout<<sol;
    return 0;
}

Measured memory_bytes: 8136
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int one = a+b, two = b+c, three = a+c;
    int mini = min(one, two);
    cout << min(mini, three);
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main (){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans = 0;
    char res = S[0];
    rep(i, N-1){
      if (S[i+1] == res){
          continue;
      }  else {
          ans++;
          res = S[i+1];
      }
    }

    ans++;
    cout << ans << endl;

}

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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define FI ios::sync_with_stdio(false); cin.tie(0);

#define LL long long

const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
const int MX = 3e5 + 5;

int h,w,m;
vector<int> columnPts[MX];

int rowSum[MX];
int colSum[MX];

int main() {
	memset(rowSum, 0, sizeof(rowSum));
	memset(colSum, 0, sizeof(colSum));

	cin >> h >> w >> m;
	int x,y;
	for(int i=0;i<m;i++) {
		cin >> x >> y;

		rowSum[x]++;
		colSum[y]++;

		columnPts[y].push_back(x);
	}

	set<pair<int, int>, greater<pair<int,int> > > intersect, not_intersect;
	set<pair<int, int>, greater<pair<int,int> > >::iterator it;

	for(int r=1;r<=h;r++) {
		pair<int,int> pt;
		pt.first = rowSum[r];
		pt.second = r;
		
		not_intersect.insert(pt);
	}

	int ans = 0;
	for(int c=1; c<=w; c++) {
		for(int i=0;i<columnPts[c].size();i++) {
			int r = columnPts[c][i];

			pair<int,int> pt;
			pt.first = rowSum[r];
			pt.second = r;

			not_intersect.erase(pt);
			intersect.insert(pt);
		}

		//from intersecting
		if(!intersect.empty()) {
			pair<int,int> maxRpt = *(intersect.begin());
			int ret = colSum[c] + maxRpt.first - 1;
			ans = max(ans, ret);
		}
		//from non intersecting
		if(!not_intersect.empty()) {
			pair<int,int> maxRpt = *(not_intersect.begin());
			int ret = colSum[c] + maxRpt.first;
			ans = max(ans, ret);
		}

		for(it = intersect.begin(); it != intersect.end(); it++) {
			pair<int,int> pt = *it;
			not_intersect.insert(pt);
		}
		intersect.clear();
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 41824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int inf = 1e9;
vi w, p;
int N;
int knapsack(const vi& w, const vi& p, int B) {
  ll maxP = accumulate(ALL(p), 0);

  vvi dp(maxP + 1, vi(SZ(w), inf));
  fill(ALL(dp[0]), 0);
  dp[p[0]][0] = w[0];

  FOR(t, 1, maxP + 1) {
    FOR(i, 1, SZ(w)) {
      dp[t][i] = dp[t][i - 1];
      if(t - p[i] >= 0)
        ckmin(dp[t][i], dp[t - p[i]][i - 1] + w[i]);
    }
  }

  int res = 0;
  F0R(i, maxP + 1)
    if(dp[i][SZ(w) - 1] <= B)
      ckmax(res, i);
  return res;
}

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

  int B;
  cin >> N >> B;

  vi w(N), p(N);
  F0R(i, N)
    cin >> w[i] >> p[i];

  cout << knapsack(w, p, B) << endl;
}


Measured memory_bytes: 46068
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        x: [i32; n],
    }
    let mut min = 2147483647;
    let mut sum = 0;
    for i in 1..100 {
        sum = 0;
        for j in 0..n {
         sum = sum + (x[j] - i).pow(2);   
        }
        if sum < min {
            min = sum;
        }
    }
    println!("{}", min);

}



Measured memory_bytes: 4352
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[][] = new int[N][26];
        List<Character> ans = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            String s = sc.next();
            for (int j = 0; j < s.length(); j++) {
                a[i][s.charAt(j) - 'a']++;
            }
        }

        for (int i = 0; i < 26; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 0; j < N; j++) {
                min = Math.min(min, a[j][i]);
            }
            for (int j = 0; j < min; j++) {
                ans.add((char)(i + 'a'));
            }
        }
        Collections.sort(ans);
        for (char c : ans) {
            System.out.print(c);
        }
        System.out.println();
    }
}




Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int w[305];
bool d[305][305];
int dp[305];
int main(void){
    while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<300;i++)for(int j=0;j<300;j++)d[i][j]=false;
    for(int i=0;i<=300;i++)dp[i]=0;
    for(int i=0;i<n;i++)cin>>w[i];
    for(int i=0;i<n-1;i++){
        if(abs(w[i]-w[i+1])<=1)d[i][i+1]=true;
    }
    for(int i=3;i<n;i++){
        for(int j=0;j+i<n;j++){
            int l=j,r=j+i;
            if(d[l+1][r-1]&&abs(w[l]-w[r])<=1)d[l][r]=true;
            for(int k=l+1;k+1<r;k++){
                if(d[l][k]&&d[k+1][r])d[l][r]=true;
            }
        }
    }
    for(int i=0;i<n;i++){
        dp[i+1]=max(dp[i+1],dp[i]);
        for(int j=i+1;j<n;j++)if(d[i][j])dp[j+1]=max(dp[j+1],dp[i]+j-i+1);
    }
    cout<<dp[n]<<endl;
    }
}



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

using namespace std ;

int n ;
int a [12345] ;

int main ( )  {
	cin >> n ;
	for ( int i = 1 ; i <= n ; ++ i )  cin >> a [i] ;
	int ans = pow ( 3, n ), sum = 1 ;
	for ( int i = 1 ; i <= n ; ++ i )  sum <<= ( ( a [i] & 1 ) == 0 ) ;
	return printf ( "%d\n", ans - sum ), 0 ;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1)*18;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int i,j,k,n;cin>>k>>n;
	//半分からア
	if(k==1){
		for(i=0;i<(n+1)/2;i++){cout<<"1 ";}cout<<endl;RE;
	}
	if(k%2==0){
		cout<<k/2<<" ";
		for(i=1;i<n;i++){cout<<k<<" ";}cout<<endl;RE;
	}
	vector<int>ans(n,(k+1)/2);
	int zro=n;
	for(i=0;i<n/2;i++){
		for(j=n-1;j>=0;j--){
			if(ans[j]==0){continue;}
			ans[j]--;break;
		}
		if(ans[j]>0){for(j++;j<n;j++){ans[j]=k;}}
	}
	for(auto it:ans){if(it>0){cout<<it<<" ";}}cout<<endl;RE;
}


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

using namespace std;
using ll = long long;

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0);
  string s;
  cin >> s;
  ll n = (ll) s.size();
  ll cur_A = 0;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (s[i] == 'A') {
      cur_A++;
    } else if (s.substr (i, 2) == "BC") {
      ans += cur_A;
      i++;
    } else {
      cur_A = 0;
    }
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 720
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

double bmi(double h, double w)
{
	return w / (h * h);
}

int main()
{
    for(int n; cin >> n && n;)
	{
		int index = 0;
		double fit = 0;
		
		rep(i, n)
		{
			int in;
			double h, w;
			cin >> in >> h >> w;
			
			double p = abs(22.0 - bmi(h / 100.0, w));
			if(!i || p < fit)
			{
				index = in;
				fit = p;
			}
			else if(p == fit && in < index)
			{
				index = in;
			}
		}
		
		cout << index << endl;
	}
}

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

#define INF 0x3f3f3f3f
#define int long long
#define pii pair<int, int>

const int N = 3005;

double dp[N][N];
double p[N];
double solve(int x, int k) {        // x coins with k heads
    if(!x and !k)
        return 1.00;
    if(x < 1 or k < 0)
        return 0.0;
    if(dp[x][k] != -1.0f)
        return dp[x][k];
    dp[x][k] = 0.0;
    dp[x][k] += ((1.0-p[x])*solve(x-1, k));     // using tails
    dp[x][k] += (p[x]*solve(x-1, k-1));         // using heads
    return dp[x][k];
}

int32_t main() {
    int i, j, n;
    double ans;
    scanf("%lld", &n);
    for(i = 1 ; i <= n ; i++) {
        scanf("%lf", &p[i]);
    }
    for(i = 0 ; i <= n ; i++)
        for(j = 0 ; j <= n ; j++)
            dp[i][j] = -1.0f;
    ans = 0.0;
    for(i = (n+1)/2 ; i <= n ; i++)
        ans += solve(n, i);
    printf("%.10lf", ans);
    return 0;
}


Measured memory_bytes: 70912
import sys
from collections import defaultdict
N = int(sys.stdin.readline())
cnt = defaultdict(int)
for i in range(1, N+1):
  str_i = str(i)
  cnt[(str_i[0], str_i[-1])] += 1
 
ans = 0
for d1 in range(1, 10):
  for d2 in range(1, 10):
    d1, d2 = str(d1), str(d2)
    ans += cnt[(d1, d2)] * cnt[(d2, d1)]
print(ans)

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if (s.size() == 3) {
    swap(s[0], s[2]);
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int dp[1<<15];

int main() {
  int N,M,W;
  cin >> N >> M >> W;
  vector<pii> v;
  int ma = 0;
  
  REP(i, N) {
    int k;
    cin >> k;
    REP(j, k) {
      int a;
      cin >> a;
      if (i) {
        v.push_back(pii(i, a));
        ma = max(ma, i);
      }
    }
  }
  int n = v.size();
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  REP(i, 1<<n) dp[i] = INF;
  dp[0] = 0;
  REP(S, 1<<n) {
    vector<int> tmp;
    REP(i, n) if (S>>i&1) tmp.push_back(i);
    int num = tmp.size();
    REP(tT, 1<<num) {
      int T = 0;
      REP(j, num) if (tT>>j&1) T |= 1<<tmp[j];
      int weight = 0;
      REP(j, n) {
        if (T>>j&1) weight += v[j].second;
      }
      if (weight <= W) {
        dp[S] = min(dp[S], dp[S^T]+1);
      }
    }
  }
  int now = 0;
  int ans = 0;
  for (int i=N-1; i>=1; --i) {
    REP(j,n) if (v[j].first == i) now |= 1<<j;
    ans += dp[now]*2;
  }
  M--;
  ans -= ma;
  ans += abs(M-ma);
  cout << ans << endl;
}

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

int main() {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int ans=0;
  for(int i=0; i<=a; i++){
  	for(int j=0; j<=b; j++){
      for(int k=0; k<=c; k++){
      	if(500*i+100*j+50*k == x) ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split(' ');
		int a = int.Parse(str[0]);
		int b = int.Parse(str[1]);
		int d = a/b;
		int r = a%b;
		double f = 1.0*a/b;
		Console.WriteLine(d + " " + r + " " + f.ToString("F8"));
	}
}


Measured memory_bytes: 9152
import java.util.Scanner;

public class Main {

	  static String a[];
	    static String b[];
	    
	    static void BubbleSort(String a[],int n){
	        for(int i=0;i<n;i++){
	            for(int j=n-1;j>i;j--){
	                if(a[j].charAt(1)-'0'<a[j-1].charAt(1)-'0'){
	                    String temp = a[j];
	                    a[j] = a[j-1];
	                    a[j-1] = temp;
	                }
	            }
	        }
	    }
	    
	    static boolean flag = true;
	    
	    static void SelectionSort(String b[],int n){
	        for(int i=0;i<n;i++){
	            int min = i;
	            for(int j=i;j<n;j++){
	                if(b[j].charAt(1)-'0'<b[min].charAt(1)-'0'){
	                    min = j;
	                }
	            }
	            if(i != min){
	                String temp = b[i];
	                b[i] = b[min];
	                b[min] = temp;
	            }
	        }
	    }
	    
	    public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int n = sc.nextInt();
	         a = new String[n];
	         b = new String[n];
	        for(int i=0;i<n;i++){
	            a[i] = sc.next();
	            b[i] = a[i];
	        }
	        
	        BubbleSort(a,n);
	    
	        System.out.print(a[0]);
	        for(int i=1;i<n;i++){
	            System.out.printf(" %s",a[i]);
	        }
	        System.out.println();
	        System.out.println("Stable");
	        
	        SelectionSort(b,n);
	        
	        System.out.print(b[0]);
	        for(int i=1;i<n;i++){
	            System.out.printf(" %s",b[i]);
	        }
	        
	        for(int i=0;i<n;i++) {
	        	if(! a[i].equals(b[i])) {
	        		flag = false;
	        	}
	        }
	        
	        System.out.println();
	        if(flag){
	             System.out.println("Stable");
	        }else{
	            System.out.println("Not stable");
	        }
	    }	  

	}





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

#define for0(i, n) for (long long  i = 0; i < n; i++) 
#define for1(i, n) for (long long  i = 1; i <= n; i++) 
#define forc(i, l, r) for (long long  i = l; i <= r; ++i) 
#define forr0(i, n) for (long long  i = n - 1; i >= 0; i--) 
#define forr1(i, n) for (long long  i = n; i >= 1; i--) 

#define pb push_back
#define fi first
#define se second

#define all(x) (x).begin(), (x).end() 
#define rall(x) (x).rbegin, (x).rend() 

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef long long int lli;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

const ll N = 1e5 + 105;
const ll mod = 1e9 + 7;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    ll i,j,k,n;
    cin>>n>>k;
    vector<ll> a(N);
    vector<ll> dp(N,INT_MAX);
    for0(i,n) cin>>a[i];
    for0(i,N) dp[i]=1e15;
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<=i+k;j++)
        {
            dp[j]=min(dp[j],dp[i]+(ll)abs(a[j]-a[i]));
        }
    }
    // for0(i,n) cout<<dp[i]<<" ";
    cout<<dp[n-1]<<endl;
    
    return 0;
}



Measured memory_bytes: 4788
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCm(ll n, ll m){
    if(m == 0 || m == n){
        return 1;
    } else if(m == 1){
        return n;
    }
    return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------


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

    cout << min({a + b, a + c, b + c}) << endl;
}

Measured memory_bytes: 256
D,G = map(int,input().split())
PC = [list(map(int,input().split())) for i in range(D)]

def up_f(i,score):
	if i == D+1:
		return 10**9
	n = min(score//(i*100),PC[i-1][0])
	s = n*100*i
	s += PC[i-1][1] if n == PC[i-1][0] else 0
	if s < score:
		n += up_f(i+1,score-s)
	return min(n,up_f(i+1,score))

def down_f(i,score):
	if i == 0:
		return 10**9
	n = min(score//(i*100),PC[i-1][0])
	s = n*100*i
	s += PC[i-1][1] if n == PC[i-1][0] else 0
	if s < score:
		n += down_f(i-1,score-s)
	return min(n,down_f(i-1,score))

print(min(up_f(1,G),down_f(D,G)))

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

ll inf=9223372036854775806,ans=0;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll i,t1=0,t2,a[100000],n,m,dif=inf;
	cin>>n;
	for (i=0;i<n;i++){
		cin>>a[i];
		if (a[i]>t1){
			t1=a[i];
			m=i;
		}
	}
	for (i=0;i<n;i++){
		if (i!=m){
			ll p=abs(2*a[i]-t1);
			if (p<dif){
				dif=p;
				t2=a[i];
			}
		}
	}
	cout<<t1<<" "<<t2;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];

    lint res = 0;
    lint mx = a[0];

    for (int i = 1; i < n; i++) {
        if (a[i] < mx) {
            res += mx - a[i];
        }
        mx = max(mx, a[i]);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4836
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int a[100010];
vector<int> vt;
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int q;
		scanf("%d", &q);
		vt.push_back(q);
		a[q]++;
	}
	sort(vt.begin(), vt.end());
	vt.erase(unique(vt.begin(), vt.end()), vt.end());
	if (vt.size() == 1) {
		if (vt[0] == n - 1||n/2>=vt[0])puts("Yes");
		else puts("No");
		return 0;
	}
	int t = vt.size();
	if (vt[t - 1] - vt[0] > 1) {
		puts("No");
		return 0;
	}
	if (a[vt[0]] + 1 <= vt[1] && vt[1] <= a[vt[0]] + a[vt[1]] / 2)
		puts("Yes");
	else
		puts("No");
}

Measured memory_bytes: 1148
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
  int i, N, min, max;
  int *a, *b;

  scanf("%d", &N);
  a = (int*)malloc(sizeof(int) * N);
  b = (int*)malloc(sizeof(int) * N);

  scanf("%d %d", &a[0], &b[0]);
  max = a[0];
  min = b[0];

  for (i = 1; i < N; i++) {
    scanf("%d %d", &a[i], &b[i]);
    if (a[i] > max) max = a[i];
    if (b[i] < min) min = b[i];
  }

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

Measured memory_bytes: 896
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    r, D, x = i2nn()
    for _ in range(10):
        x = (r * x) - D
        print(x)

main()


Measured memory_bytes: 38384
# D 終了後再チャレンジ
# -*- coding: utf-8 -*-
import heapq

N, M = map(int, input().split())
A_list = list(map(int, input().split()))
A_list = [-a for a in A_list]
heapq.heapify(A_list)

for i in range(M):
    max_price = heapq.heappop(A_list) * (-1)
    heapq.heappush(A_list, max_price // 2 * (-1))
    
ans = sum(A_list) * (-1)
print(ans)

Measured memory_bytes: 14184
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const long long MAXN=200005,INF=2000000005,MOD=1e9+7;
long long n,X,Y;
long long a[MAXN],w[MAXN],c[MAXN],d[MAXN];
long long jc[MAXN],Inv[MAXN];
long long ksm(long long x,long long y)
{
	long long k=1;
	while(y)
	{
		if(y&1)
			k=(k*x)%MOD;
		x=(x*x)%MOD;
		y>>=1;
	}
	return k;
}
void Init()
{
	jc[0]=1;
	for(long long i=1;i<MAXN;i++)
		jc[i]=(jc[i-1]*i)%MOD;
	Inv[MAXN-1]=ksm(jc[MAXN-1],MOD-2);
	for(long long i=MAXN-2;i>=0;i--)
		Inv[i]=(Inv[i+1]*(i+1))%MOD;
}
int main()
{
	//freopen("colorball.in","r",stdin);
	//freopen("colorball.out","w",stdout);
	Init();
	scanf("%lld %lld %lld",&n,&X,&Y);
	for(long long i=0;i<=n;i++)
		c[i]=INF;
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a[i],&w[i]);
		c[a[i]]=min(c[a[i]],w[i]);
	}
	long long MI=c[1]<c[2]?1:2,MC=c[1]<c[2]?2:1;
	for(long long i=3;i<=n;i++)
	{
		if(c[i]<c[MI])
		{
			MC=MI;
			MI=i;
		}
		else if(c[i]<c[MC])
			MC=i;
	}
	for(long long i=1;i<=n;i++)
		if(w[i]+c[a[i]]<=X)
			w[i]=c[a[i]];
	long long o=0;
	for(long long i=1;i<=n;i++)
		if((w[i]+c[MI]<=Y&&MI!=a[i])||(w[i]+c[MC]<=Y&&MC!=a[i]))
		{
			o++;
			d[a[i]]++;
		}
	long long ans=jc[o];
	for(long long i=1;i<=n;i++)
	{
		if(d[i])
			ans=(ans*Inv[d[i]])%MOD;
	}
	printf("%lld\n",ans);
	fclose(stdin);
	fclose(stdout);
}

Measured memory_bytes: 9600
# -*- coding: utf-8 -*-
import itertools

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

Nlst = []
Nlst_gu = []
# for i in range(1,N+1):
#     Nlst.append(i)

if K % 2 == 0:
    for i in range(1,N+1):
        if i % K == 0:
            Nlst.append(i)
        elif i % (K/2) == 0:
            Nlst_gu.append(i)
else:
    for i in range(1,N+1):
        if i % K == 0:
            Nlst.append(i)
#
# print(Nlst)
# print(Nlst_gu)

ans = len(Nlst)
ans_gu = len(Nlst_gu)

print(ans * ans * ans + ans_gu * ans_gu * ans_gu)

#
# tmplst = []
# for i in itertools.product(Nlst, repeat=3):
#     tmplst.append(i)
#
# ans = 0
#
# for (a,b,c) in tmplst:
#     if (a+b) % K == 0 and (b+c) % K == 0 and (c+a) % K == 0:
#         ans += 1
#
#
# print(ans)


Measured memory_bytes: 11064
#include <bits/stdc++.h>
#define i64 long long
using namespace std;
int main() {
	int N,x,y;
	cin>>N;
  	if(N<4) {
    	printf("No\n"); return 0;
    }
	if(N%4==0 or N%7==0){
		printf("Yes\n"); return 0;
	} 
	//if 4x+7y == N => 7y = (N-4x) , so N-4x is divisible by 7
	int lim = N>>2;  //N/4
	bool found = false;
	for(int x=0;x<=lim and !found; x++){
		int y = (N-4*x)/7;
		if(y<0) continue;
		if(4*x + 7*y == N) found = true;
	}
	printf("%s\n", found ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

struct Point { double x, y; };

void koch(int n, Point a, Point b) {
  if ( n == 0 ) return;

  Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n - 1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n - 1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n - 1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n - 1, t, b);
}

int main() {
  Point a, b;
  int n;

  scanf("%d", &n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}


Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
string n;
cin>>n;
 if(n.at(0)==n.at(1) && n.at(1)==n.at(2) || n.at(1)==n.at(2) && n.at(2)==n.at(3)){
 cout<<"Yes"<<endl;
 }
else{
	cout<<"No"<<endl;
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


int main(){
    string s; cin >> s;
    int n = s.size();
    int ans = N;
    int i = 0;
    while(s.size() > 0){
        i += 2;
        s.erase(n - i, 2);
        if(s.empty())break;
        string t, u;
        t = s.substr(0, (n - i) / 2);
        u = s.substr((n - i) / 2, (n - i) / 2);
        //cout << t << " " << u << endl;
        if(t == u){
            ans = n - i;
            break;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int tmp1;
    int tmp2;
    int radiant = 0;
    double x = 0;
    double y = 0;

    while(scanf("%d,%d", &tmp1, &tmp2), (tmp1 != 0 || tmp2 != 0)){
        x += tmp1 * sin(radiant * M_PI / 180.0);
        y += tmp1 * cos(radiant * M_PI / 180.0);
        radiant += tmp2;
    }
    cout << (int)x << endl;
    cout << (int)y << endl;
    return 0;
}

Measured memory_bytes: 0
/*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 998244353
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 3005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
const ll infinity = 9e18;


#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int



bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }

ll n, s;
ll a[MAXN], v[MAXN][MAXN];

ll dp(ll idx,ll s)
{
    if(s == 0) return power(2,n-idx+1,mod);
    if(s < 0) return 0;
    if(idx > n) return 0;
    ll &ans = v[idx][s];
    if(ans != -1) return ans;
    return ans = (2*dp(idx+1,s)+dp(idx+1,s-a[idx]))%mod;
}

int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    cin>>n>>s;
    memset(v,-1,sizeof(v));
    forn(i,1,n+1)
    {
        cin>>a[i];
    }
    cout<<(dp(1,s)%mod);
    return 0;
}   





Measured memory_bytes: 74412