akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b) {
  if(a < b)
    gcd(b, a);
  int r;
  while((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int n, m = 0;
  cin >> n;
  vector<int> a(n), g(n), gr(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
    if(i)
      g.at(i) = gcd(g.at(i - 1), a.at(i));
    else
      g.at(i) = a.at(i);
  }
  for(int i = n - 1; i >= 0; i--) {
    if(i == n - 1) {
      gr.at(i) = a.at(i);
      m = g.at(i - 1);
    } else {
      gr.at(i) = gcd(gr.at(i + 1), a.at(i));
      if(i)
        m = max(m, gcd(g.at(i - 1), gr.at(i + 1)));
      else
        m = max(m, gr.at(i + 1));
    }
  }
  cout << m << endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r) - sum(l-1);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,q; cin>>n>>q;
  BIT<ll> bit(n);
  
  rep(_,q){
    ll c,x,y; cin>>c>>x>>y;
    if(c==0){
      bit.add(x,y);
    }else{
      cout<<bit.sum(x,y)<<endl;
    }
  }
  
}


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

int main(){
    int N;
    cin >> N;
    int a;
    vector<int> A = vector<int>();
    for (int i = 0; i < N; i++){
        cin >> a;
        A.emplace_back(a);
    }
    sort(A.begin(), A.end());
    int k = A[N-1];
    A.pop_back();
    int m = A[0];
    int hk = int(k / 2);
    for (int i = 1; i < A.size(); i++){
        int l = A[i];
        if (l > hk){
            l = k - A[i];
        }
        if (abs(hk - m) > abs(hk - l)){
            m = A[i];
        };
    }
    cout << k << " " << m;
    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

signed main(){
	int n, a, b, c, d, ans = 0;
	scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
	rep(i,n-1){
		if(i*c-(n-1-i)*d <= b-a and b-a <= i*d-(n-1-i)*c)ans = 1;
	}
	printf("%s\n", ans ? "YES" : "NO");
	return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  string s;
  cin >> s;

  string k = "keyence";
  ll rec = 0, knum = 0, sl = s.size();

  REP(i, sl){
    if(s[i] == k[knum]) knum++;
    else{
      REP(j, 7 - knum){
        if(s[sl - 1 - j] != k[6 - j]){
          cout << "NO" << endl;
          return 0;
        }
      }
      cout << "YES" << endl;
      return 0;
    }
    if(knum == 7){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,k=map(int, input().split())
if n%2==1:
    if (n//2 + 1) >= k:
        print("YES")
    else:
        print("NO")
else:
    if (n//2) >= k:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 3060
n, m = map(int, input().split())
num = [1] * n
red = [False] * n
red[0] = True
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if red[x]:
        red[y] = True
    num[x] -= 1
    num[y] += 1
    if num[x] == 0:
        red[x] = False
ans = 0
for r in red:
    ans += r
print(ans)

Measured memory_bytes: 10284
#include <iostream>
#include <string>
using namespace std;
int main(){
	string str;
	int count=0;
	while(cin>>str){
		if(str.length()==1){
			count++;
		}else if(str.length()%2==0){
			for(int i=0;i<str.length()/2;i++){
				if(str[i]==str[str.length()-1-i]){
					if(i==str.length()/2-1) count++;
					continue;
				}else break;
			}
		}else if(str.length()%2==1){
			for(int i=0;i<(str.length()-1)/2;i++){
				if(str[i]==str[str.length()-1-i]){
					if(i==(str.length()-1)/2-1) count++;
					continue;
				}else break;
			}
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1184
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main ()
{
  float* resis;
  int N;
  float sum=0;
  resis=malloc(N*sizeof(float));
  scanf("%d",&N);
  printf("\n");
  for(int i=0;i<N;i++)
  {
    scanf("%f",&resis[i]);
    sum+=1/resis[i];
  }
  printf("%f",1/sum);
  return 0;

}


Measured memory_bytes: 128
def insertionSort(A, n, g):
    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            global cnt
            cnt += 1
        A[j+g] = v

def shellSort(A, n):
    global cnt
    cnt = 0
    G =[]
    g = 0
    for h in range(100):
        g = 3*g + 1
        if g <= n:
            G.insert(0,g)
        m = len(G)

    for  i in range(m):
        insertionSort(A, n, G[i])
    print(m)
    print(*G)
    print(cnt)
    print(*A,sep="\n")

n = int(input())
A = [int(input()) for i in range(n)]

shellSort(A, n)


Measured memory_bytes: 53280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#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(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

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

Measured memory_bytes: 1024
#include <stdio.h>

#define MIN 0
#define MAX 10000

int main(void){
	int high[10];
	int result[10];
	int i = 0;
	int j = 0;
	int tmp;
	int top;

	for(i = 0; i < 10; i++){
		scanf("%d", &high[i]);
		if(!((MIN <= high[i]) && (high[i] <= MAX))){
			return 0;
		}
	}

	for(i = 0; i < 10 - 1; i++){
		for(j = 10 - 1; j > i; j--){
			if(high[j - 1] < high[j]){
				tmp = high[j - 1];
				high[j - 1] = high[j];
				high[j] = tmp;
			}
		}
	}
	
	
	for(i = 1; i <= 3; i++){
		printf("%d\n", high[i - 1]);
	}
	return 0;
}

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

int Sum(int i){
	int s = 0;
	while(i > 0){
		s += i%10;
		i/=10;
	}
	return s;
}


int main() {
	int n, a ,b;
	scanf("%d %d %d", &n, &a, &b);
	int s = 0;
	for(int i = 1; i <= n; i++){
		if(Sum(i) >= a&&Sum(i) <= b){
			s+=i;
		}
	}
	printf("%d", s);
	
	return 0;
}

Measured memory_bytes: 1704
import collections
s=input()
l=[]
dist=[]
ma=0
cnt=0
s2=""
s3=""
l=list(set(s))
#print(l)
for i in range(len(l)):
    ma=0
    cnt=0
    for j in range(len(s)):
        #print(l[i],s[j],cnt)
        if s[j]!=l[i]:
            cnt=cnt+1
        else:
            if (ma<=cnt):
                ma=cnt
            cnt=0
    if ma <= cnt:
        ma = cnt
    #print(cnt)
    dist.append(ma)
dist.sort()
print(dist[0])

"""

l2=[]
#print(l)
for i in range(len(l)):
    c=l[i]
    k=0
    s2=s
    s3=""
    #print(len(set(s2)))
    while True:
        if len(set(s2))==1:
            break
        else:
            for j in range(len(s2)-1):
                if (s2[j]==c)or(s2[j+1]==c):
                    s3="".join((s3,c))
                else:
                    s3 = "".join((s3, s2[j]))
            print(s3)
            s2=s3
            s3=""
            k=k+1
    l2.append(k)
l2.sort()

print(l2[0])
"""


Measured memory_bytes: 38512
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[100005];
int b[100005];
int n;
main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    int sum=0;
    for(int i=1;i<=n+1;++i){cin>>a[i];sum+=a[i];}
    for(int i=1;i<=n;++i)cin>>b[i];
    for(int i=1;i<=n;++i){
        int l=max(0ll,b[i]-a[i]);
        a[i]=max(0ll,a[i]-b[i]);
        a[i+1]=max(0ll,a[i+1]-l);
    }
    for(int i=1;i<=n+1;++i){
        sum-=a[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
int n,r;
cin>>n>>r;
ol(r+100*max(0,10-n));
return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=500010;
struct poi{int too,pre;}e[maxn];
int n,m,x,y,ans,tot,t,one,two; 
int last[maxn],v[maxn];
void read(int &k)
{
	int f=1;k=0;char c=getchar();
	while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
	k*=f;
}
void add(int x,int y){e[++tot].too=y;e[tot].pre=last[x];last[x]=tot;}
void dfs(int x,int col)
{
	v[x]=col;
	for(int i=last[x];i;i=e[i].pre)
	{
		if(v[e[i].too]==-1)dfs(e[i].too,col^1);
		else if(v[e[i].too]==col){printf("%lld\n",(1ll*n*(n-1)>>1)-m);exit(0);}
	}
}
int main()
{
	read(n);read(m);memset(v,-1,(n+1)<<2);
	for(int i=1;i<=m;i++)read(x),read(y),add(x,y),add(y,x);
	dfs(1,1);
	for(int i=1;i<=n;i++)if(v[i]==1)one++;else two++;
	printf("%lld\n",1ll*one*two-m);
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int

using namespace std;

void solve()
{
	string a,b;
	cin>>a>>b;
	int n = a.size();
	int t = b.size();
	int ans=INT_MAX;
	for(int i=0;i+t-1<n;i++)
	{
		int count=0;
		string temp = a.substr(i,t);

		for(int j=0;j<t;j++)
		{
			count+=(b[j]!=temp[j]);
		}
		ans=min(ans,count);
	}

	cout<<ans;



}
signed main()

{
	FAST_IO;
	int t = 1;

	// cin>>t;

	while(t--)
	{
		solve();
	}
	
	return 0;
}

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

long long n, a, b;

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> a >> b;
    if (a + b == 0)
    {
        cout << 0;
        return 0;
    }
    cout << n / (a + b) * a + min(n % (a + b), a);
    cin >> n;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int m,d,d1,d10,k=0,count=0;
  scanf("%d %d",&m,&d);
  int a[2][9900];
 /* d10 = d/10;
    d1 = d%10; */
  for(int i=1;i<=m;i++){//month
    for(int c=1;c<=d;c++){ //day
        d10 = c/10;
	d1 = c%10;
	if((d10<2 || d1<2)){
	}
	else if( i==d10*d1){
	a[0][k] = d10;
	a[1][k] = d1;
	k++;
	count++;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
import heapq


def resolve():
    n, m = map(int, input().split())
    a = list(map(lambda x: -int(x), input().split()))
    heapq.heapify(a)
    for _ in range(m):
        nexta = -1 * heapq.heappop(a) // 2
        heapq.heappush(a, -nexta)
    print(-sum(a))


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 72088
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,a[MAXN];
int tot;
void Solve() {
    read(N);
    int maxx = 0,minn = N;
    for(int i = 1 ; i <= N ; ++i) {
	read(a[i]);maxx = max(a[i],maxx);minn = min(a[i],minn);
    }
    if(maxx - minn > 1) {puts("No");return;}
    if(maxx == minn) {
	if(maxx == N - 1) puts("Yes");
	else if(maxx * 2 <= N)  puts("Yes");
	else puts("No");
	return;
    }
    
    for(int i = 1 ; i <= N ; ++i) {
	if(a[i] == minn) ++tot;
    }
    if(maxx <= tot) {puts("No");return;}
    if(N - tot >= 2 * (maxx - tot)) {
	puts("Yes");return;
    }
    puts("No");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

struct SegmentTreeForLCA{
    int sz;
    // {深さ,id}
    vector<pair<int,int>> seg;
    // 初期化
    void resize(int n){
        sz=1;
        while(sz<n) sz<<=1;
        seg.resize(sz<<1,{1<<30,-1});
    }
    // 代入
    void set(int id,int depth){
        seg[id+sz]={depth,id};
    }
    // 構築
    void build(){
        for(int k=sz-1;k>0;k--){
            seg[k]=min(seg[2*k],seg[2*k+1]);
        }
    }
    // [l,r]の結果を取得
    int get(int l,int r){
        pair<int,int> L={1<<30,-1},R={1<<30,-1};
        l+=sz,r+=sz+1;
        for(;l<r;l>>=1,r>>=1){
            if(l&1) L=min(L,seg[l++]);
            if(r&1) R=min(seg[--r],R);
        }
        return min(L,R).second;
    }
};
struct LCA{
    const int V;
    const int root;
    const vector<vector<int>> &edge;
    vector<int> nodeOrder;
    vector<int> depthOrder;
    vector<int> nodeFirstID;
    SegmentTreeForLCA seg;
    LCA(int V,int root,vector<vector<int>> edge):
        V(V),
        root(root),
        edge(edge)
        {
            const int MAX=2*V-1;
            nodeOrder.resize(MAX);
            depthOrder.resize(MAX);
            nodeFirstID.resize(V+1);
            dfs(root,-1,0);
            seg.resize(MAX);
            for(int id=0;id<MAX;id++){
                seg.set(id,depthOrder[id]);
            }
            seg.build();
        }
    int id=0;
    void dfs(int from,int par,int depth){
        nodeOrder[id]=from;
        depthOrder[id]=depth;
        nodeFirstID[from]=id;
        id++;
        for(int to:edge[from]){
            if(to==par) continue;
            dfs(to,from,depth+1);
            nodeOrder[id]=from;
            depthOrder[id]=depth;
            id++;
        }
    }
    int get(int u,int v){
        return nodeOrder[seg.get(min(nodeFirstID[u],nodeFirstID[v]),max(nodeFirstID[u],nodeFirstID[v]))];
    }
};

int main(){
    int n; cin>>n;
    vector<vector<int>> g(n+1);
    for(int i=0;i<n;i++){
        int k; cin>>k;
        while(k--){
            int c; cin>>c;
            g[i].push_back(c);
            g[c].push_back(i);
        }
    }
    LCA lca(n,0,g);
    int q; cin>>q;
    while(q--){
        int u,v; cin>>u>>v;
        cout<<lca.get(u,v)<<endl;
    }
    return 0;
}



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 5e3 + 11;

int n;
string s;

int dp[maxn][maxn];

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

  cin>>n>>s;
  int ans = 0;

  for (int i=0; i<n; i++) {
    for (int j=i+1; j<n; j++) {
      if (s[i]==s[j]) {
	dp[i+1][j+1] = min(1+dp[i][j], j-i);
	ans = max(ans, dp[i+1][j+1]);
      }
    }
  }

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


Measured memory_bytes: 96896
import java.io.*;

class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try{
            String line = reader.readLine();
            char tmp = line.charAt(0);
            int sum=0,i;

            while(true){
                int x = tmp - '0';
                sum += x;
                if(sum==0) break;
                else{
                    for(i=1;i<line.length();i++){
                        sum += line.charAt(i) - '0';
                    }
                    System.out.println(sum);
                }
                sum = 0;
                line = reader.readLine();
                tmp = line.charAt(0);
            }

        }catch(IOException e){
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 24264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n; cin >> n;
    for(int i = 64; ; i/=2){
        if(i <= n){
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
total = sum(A)

def checkPopular():
    count = 0
    for i in range(N):
        if (A[i] / total)  >= (1 / (4*M)):
            count += 1
    return count

if checkPopular() < M:
    print('No')
else:
    print('Yes')

    


Measured memory_bytes: 2940
n = int(input())
c = [int(i) for i in input().split()]
c.sort(reverse=True)
ans = 0
mod = 10 ** 9 + 7
no = n
for i, j in enumerate(c):
    if i == 0:
        ans += j * pow(2, no, mod)
    else:
        ans += j*(pow(2, i, mod)+pow(2, i-1, mod)*i) * \
            pow(2, no, mod)
    no -= 1
    ans %= mod
print(ans*pow(2,i,mod) % mod)


Measured memory_bytes: 26172
#include <stdio.h>
int judge(int x[],int y[],int p[]){
  int a,b,c;
  a=((p[0]-x[0])*(p[1]-y[1])-(p[1]-y[0])*(p[0]-x[1])>0)?1:-1;
  b=((p[0]-x[1])*(p[1]-y[2])-(p[1]-y[1])*(p[0]-x[2])>0)?1:-1;
  c=((p[0]-x[2])*(p[1]-y[0])-(p[1]-y[2])*(p[0]-x[0])>0)?1:-1;
  if(a==b&&b==c)
    return 1;
  else
    return 0;
}
int main(void){
  int x[3],y[3],p[2][2],i,j,fk,fs,n;
  scanf("%d",&n);
  while(n--){
    for(i=0;i<3;i++)
      scanf("%d %d",&x[i],&y[i]);
    for(i=0;i<2;i++)
      for(j=0;j<2;j++)
	scanf("%d",&p[i][j]);
    fk=judge(x,y,p[0]);
    fs=judge(x,y,p[1]);
    if(fk==fs)
      puts("NG");
    else
      puts("OK");
  }
  return 0;
}

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

using namespace std;

long long int nCr(int n, int r) {
    long long int  ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans * i;
    }
    for (int i = 1; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

int main() {
    long long int n, k;
    cin >> n >> k;

    long long int ans = 0;
    long long int temp;
    
    for (int i = k; i < n + 2; i++) {
        
        temp = (n + 1 - i) * i + 1;
        while (true)
        {
            if (temp< 0) {
                temp += (1000000000 + 7);
            } else {
                break;
            }
        }
        if (temp >= (1000000000 + 7)) {
            temp %= (1000000000 + 7);
        }
        ans += temp;

        //ans += nCr(n + 1, i);
        if (ans >= (1000000000 + 7)) {
            ans %= (1000000000 + 7);
        }
        while (true)
        {
            if (ans < 0) {
                ans += (1000000000 + 7);
            } else {
                break;
            }
        }
        
    }

    cout << ans;


    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

class Main {

    public static void main(String[] args){
	Scanner stdin = new Scanner(System.in);
	int money = 100000;
	int n = stdin.nextInt();
	for(int i = 0; i < n; i++){
	    money = (int)(money * 1.05);
	    if(money % 1000 > 0){
		money /= 1000;
		money++;
		money *= 1000;
	    }
	}
	System.out.println(money);
    }
}

Measured memory_bytes: 12000
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 5e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
	string s;
	cin >> s;
	if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
		cout << 3 << '\n';
	else if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R'))
		cout << 2 <<"\n";
	else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
		cout << 1 << '\n';
	else 
		cout << 0 << "\n";
}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>

using namespace std;

using u64 = uint64_t;

int main()
{
    u64 N,A,B;
    cin >> N >> A >> B;

    u64 ans = 0;

    u64 tmp = N / (A + B);
        if (N % (A + B) < A) {
            ans = tmp * A + N % (A + B);
        } else {
            ans = (tmp + 1) * A;
        }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1e9 + 7;

int dif(int type, int x) {
  if (type == 0 || type == 4) return x;
  if (type == 1 || type == 3) return x == 0 ? 2 : x % 2;
  return (x + 1) % 2;
}
signed main() {
  int n; cin >> n;
  VI a(n); REP (i, n) cin >> a[i];
  VI dp(5);
  REP (i, n) {
    for (int j = 4; j >= 0; j--) {
      dp[j] = dp[j] + dif(j, a[i]);
    }
    REP (j, 4) {
      dp[j + 1] = min(dp[j + 1], dp[j]);
    }
  }
  cout << dp[4] << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    string s, t;
    cin >> s >> t;
    vector<vector<lint>> dp(s.size()+1, vector<lint>(26, 0));
    REP(i, s.size()) {
        dp[i][s[i] - 'a'] = i+1;
    }
    IREP(i, s.size()) {
        REP(j, 26) {
            if(dp[i][j] == 0) {
                dp[i][j] = dp[i+1][j];
            }

        }
    }
    lint tidx = 0;
    lint sloop = 0;
    lint sidx = 0;
    bool flg = false;
    while(tidx < t.size()) {
        //cout << sidx << " " << tidx << endl;
        if(dp[sidx][t[tidx] - 'a'] != 0) {
            sidx = dp[sidx][t[tidx] - 'a'];
            tidx++;
            flg = true;
        } else {
            if(!flg) {
                cout << -1 << endl;
                return 0;
            } else {
                sloop++;
                sidx = 0;
                flg = false;
            }
        }
    }
    lint ans = sloop * s.size() + sidx;
    cout << ans << endl;
}

Measured memory_bytes: 24704
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val k = sc.nextLong()
    val n = sc.nextLong()
    val a = (0 until n).map { sc.next().toLong() }
    println(problem160c(k, n, a))
}

fun problem160c(k: Long, n: Long, a: List<Long>): Long {
    var maxDiff = a[0]
    var maxI = -1
    for (i in 1 until a.size) {
        val diff = a[i] - a[i - 1]
        if (maxDiff < diff) maxI = i
        maxDiff = Math.max(maxDiff, diff)
    }
    if (maxDiff <= k - a.last() + a[0]) maxI = -1

    if (maxI == -1) {
        return a.last() - a[0]
    }
    return a[maxI - 1] + k - a[maxI]
}


Measured memory_bytes: 55916
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 998244353;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------

void work(){
    LL N;
    scanf("%lld",&N);
//    printf("N = %lld\n",N);
    LL ans=N-1;
    for(LL i=1;i*i<=N;i++){
        if(N%i==0){
            ans=min(ans,i+N/i-2);
        }
    }
    printf("%lld\n",ans);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}






Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;
const ll MOD=1000000007LL;
int main(){
  int n;
  cin>>n;
  int k=-1;
  for(int i=2;i*(i-1)/2<=100000;i++){
    if(i*(i-1)/2==n)k=i;
  }
  if(k==-1){
    cout<<"No"<<endl;
    return 0;
  }
  vvi ans(k);
  int count=1;
  for(int i=0;i<k;i++){
    for(int j=i+1;j<k;j++){
      ans[i].push_back(count);
      ans[j].push_back(count);
      count++;
    }
  }
  cout<<"Yes"<<endl;
  cout<<k<<endl;
  for(int i=0;i<k;i++){
    cout<<k-1<<" ";
    for(int j=0;j<k-1;j++){
      if(j==k-2){
        cout<<ans[i][j]<<endl;
      }
      else cout<<ans[i][j]<<" ";
    }
  }
}
      
  

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

int main()
{
    string s,t;
    cin >> s >> t;
    int cnt=0;
    for(int i=0;i<3;++i){
        if(s[i]==t[i]) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long n = scan.nextLong();
        long m = scan.nextLong();
        long d = scan.nextLong();
        double ans = 0;
        if (d == 0) {
            for (int i = 0; i < m - 1; i++) {
                ans += ((double) 1) / ((double) n);
            }
        } else {
            for (int i = 0; i < m - 1; i++) {
                ans += ((double) 2 * (n - d)) / ((double) n * n);
            }
        }
        System.out.printf("%.9f\n", ans);
    }
}


Measured memory_bytes: 21844
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    l = [[-1]*n for _ in range(n)]
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x,y = map(int, input().split())
            l[i][x-1] = y
    
    res = 0
    for s in range(1<<n):
        flag = 1
        check = [-1]*n
        #i人目
        for i in range(n):
            #i人目が正直者
            if (s>>i) & 1:
                #j人目についての証言
                for j in range(n):
                    if i==j:
                        continue
                    if l[i][j] == -1:
                        continue
                    if check[j] == -1:
                        check[j] = l[i][j]
                    else:
                        if check[j] != l[i][j]:
                            flag = 0
            # #i人目が真偽不明
            # else:
            #     #j番目の証言
            #     for j in range(n):
            #         if i==j:
            #             continue
            #         if l[i][j] == -1:
            #             continue
            #         if check[j] == -1:
            #             check[j] = l[i][j]^1
            #         else:
            #             if check[j] == l[i][j]:
            #                 flag = 0
            if flag==0:
                break
        else:
            for i in range(n):
                if check[i] == -1:
                    continue
                if ((s>>i)&1) != check[i]:
                    break
            else:
                res = max(res, bin(s).count('1'))
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
S = input()

cnt = 0
maxcnt = 0
for i in range(len(S)):
    if S[i]=="A" or S[i]=="T" or S[i]=="G" or S[i]=="C":
        cnt += 1
    else:
        if cnt>maxcnt:
            maxcnt = cnt
            cnt = 0
        else:
            cnt = 0
print(max(cnt, maxcnt))

Measured memory_bytes: 3060
#if 0
????????£?????????????´?2??????
?????????????±?????????£????????´??¨?????´????????????????????¨????±?????????????
??????????????£??¨???????????????????????????
???????????????????????¨?????????????????????cross_product????????¨??????????????????????????????????????????dot_product????????¨???????????????
??????????????????????????¨??????????°???????????????????
?????´??¨?????´?????????????????¨????±?????????¨????????????????????¨?????????????????¢??°?????????????????????????????§????????????loop????????¨???????????????
?????´???loop??§????????´???loop??????????????????i--???i++??????????????????????????????????????????????????????
???????????????????????§???????????????????????????????????????
#endif
#include <iostream>
#include <complex>
#include <algorithm>
#include <cmath>
using namespace std;
typedef complex<int> xy_t;
int n=0;
xy_t point[100001];
xy_t ans[100001];


bool cmp(xy_t a,xy_t b)
{
  if(a.imag()<b.imag())
    return true;
  else if (a.imag()>b.imag())
    return false;
  else
    if(a.real()<b.real())
      return true;
    else
      return false;
}
bool cmp2(xy_t a,xy_t b)
{
  return !cmp(a,b);
}
int cross_product(xy_t a,xy_t b)
{
  return (conj(a)*b).imag();
}
bool legal(xy_t a, xy_t b, xy_t c)
{
  xy_t a1=b-a;
  xy_t a2=c-b;
  if(cross_product(a1,a2)>=0)
    return true;
  else
    return false;
}

int side()
{
  int cn=2;
  ans[0]=point[0];
  ans[1]=point[1];
  for(int i=2;i<n;i++)
  {
    if(legal(ans[cn-2],ans[cn-1],point[i]))
    {
      ans[cn++]=point[i];
    }
    else
    {
      if(cn>2)
      {
        cn--;
        i--;
      }
      else
      {
        ans[1]=point[i];
      }
    }
  }
  return cn;
}

int side2(int c)
{
  int cn=1+c;
  ans[c]=point[n-2];
  for(int i=n-3;i>=0;i--)
  {
    if(legal(ans[cn-2],ans[cn-1],point[i]))
    {
      ans[cn++]=point[i];
    }
    else
    {
      if(cn-c>1)
      {
        cn--;
        i++;
      }
      else
      {
        ans[c]=point[i];
      }
    }
  }
  return cn;
}
void printans(int countn)
{
  for(int i=0;i<countn;i++)
  {
    int x=ans[i].real();
    int y=ans[i].imag();
    cout << x << ' '<<y<<endl;
  }
}

int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
  {
    int x,y;
    cin>>x>>y;
    point[i]=xy_t(x,y);
  }
  sort(point,point+n,cmp);
  int countn=side2(side())-1;
  cout<<countn<<endl;
  printans(countn);

/*  for(int i=0;i<n;i++)
  {
    int x=point[i].real();
    int y=point[i].imag();
    cout << x << ' '<<y<<endl;
  }*/

  return 0;
}

Measured memory_bytes: 4648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define vpli vector<pair<long long,int>>
#define deb(x) cout<<x<<endl;
#define all(x) x.begin(),x.end()
ll MOD = 1e9+7;


void solve()
{
    int x;
    for(int i=1;i<=5;i++)
    {
        cin>>x;
        if(x == 0)
        {
            cout<<i;
            break;
        }
    }
}

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

Measured memory_bytes: 3564
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(20);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define double long double
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI=3.141592653589793;
const int L=1e18;


void solve()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i] ;
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(a[i]==a[j]) continue;
			int csum= a[i]+a[j];
			for(int k=j+1;k<n;k++)
			{
				if(a[j]==a[k]) continue;
				if(a[k]<csum) ans++;
			}
		}
	}
	cout << ans;
}

int32_t main()
{
	FastIO;
	Fast_D;
	solve();
	return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			String str = scanner.nextLine();
			if (str.equals("0"))
				break;
			StringTokenizer tokenizer = new StringTokenizer(str);
			int i = tokenizer.countTokens();
			int sum = 0;
			boolean a = false;
			while (i-- > 0) {
				int num = Integer.parseInt(tokenizer.nextToken());
				if (num > 10) {
					num = 10;
				} else if (num == 1) {
					a = true;
				}
				sum += num;
			}
			if (sum > 21) {
				System.out.println(0);
			} else {
				if (a && sum < 12) {
					sum += 10;
				}
				System.out.println(sum);
			}
		}
	}
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;




int main(){
  int N;
  cin >> N;
  vector<int> A(N), cnt(N, 0);
  REP(i, N){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  REP(i, N-1){
    if(i % 2){
      cnt[i]++;
      cnt[i+1]--;
    }
    else{
      cnt[i]--;
      cnt[i+1]++;
    }
  }
  ll ans = 0, sum = 0;
  sort(cnt.begin(), cnt.end());
  REP(i, N){
    sum += cnt[i] * A[i];
  }
  ans = sum;
  sum = 0;
  REP(i, N){
    cnt[i] = 0;
  }
  REP(i, N-1){
    if(i % 2){
      cnt[i]--;
      cnt[i+1]++;
    }
    else{
      cnt[i]++;
      cnt[i+1]--;
    }
  }
  sort(cnt.begin(), cnt.end());
  sum = 0;
  REP(i, N){
    sum += cnt[i] * A[i];
  }
  ans = max(ans, sum);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4028
x, n = map(int, input().split())
p = list(map(int, input().split()))
cnt = 0
while True:
    tmp = []
    if x+cnt not in p:
        tmp.append(x+cnt)
    
    if x-cnt not in p:
        tmp.append(x-cnt)
    


    if len(tmp) != 0:
        print(min(tmp))
        break

    cnt += 1


Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	string s; cin >> s;
	if(sz(s)%2 != 0)
	{
		cout << "No" << endl;
		return;
	}
	rep(i, sz(s))
	{
		if((i%2==0 && s[i]!='h')||(i%2==1 && s[i]!='i'))
		{
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
	return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/agc034_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  A--;
  B--;
  C--;
  D--;

  string S;
  cin >> S;

  repi(i, A, D - 1) {
    if (S[i] == '#' && S[i + 1] == '#') {
      cout << "No";
      return 0;
    }
  }

  if (C > D) {
    repi(i, B - 1, D) {
      if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') {
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3752
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = int.Parse(Console.ReadLine());
            Console.WriteLine(N % 500 <= A ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11092
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt();
			int c = scanner.nextInt(), d = scanner.nextInt();
			int e = scanner.nextInt(), f = scanner.nextInt();
			// 水の組合せ
			Set<Integer> waters = new HashSet<>();
			IntStream.range(0, f / a / 100 + 1)
					.forEach(i -> IntStream.range(0, (f - 100 * a * i) / b / 100 + 1).forEach(j -> {
						int water = 100 * a * i + 100 * b * j;
						if ((water <= f) && (water > 0)) {
							waters.add(water);
						}
					}));
			// 砂糖の組合せ
			Set<Integer> sugars = new HashSet<>();
			IntStream.range(0, (f - a) / c).forEach(i -> IntStream.range(0, (f - a - i) / d).forEach(j -> {
				int sugar = c * i + d * j;
				if ((sugar <= (f - a))) {
					sugars.add(sugar);
				}
			}));
			double maxRatio = -0.1d;
			int maxWater = 0, maxSugar = 0;
			for (int water : waters) {
				for (int sugar : sugars) {
					if ((water + sugar) <= f) {
						double radio = calcRadio(water, sugar, e);
						if (radio > maxRatio) {
							maxRatio = radio;
							maxWater = water;
							maxSugar = sugar;
						}
					}
				}
			}
			System.out.println((maxWater + maxSugar) + " " + maxSugar);
		}
	}

	/**
	 * @param water    水の量
	 * @param sugar    砂糖の量
	 * @param maxRadio 最大濃度
	 * @return 現在の濃度（最大濃度を超えた場合は0）
	 */
	private static double calcRadio(int water, int sugar, int maxRadio) {
		int maxSugar = water / 100 * maxRadio;
		if (sugar > maxSugar) {
			return 0.0d;
		} else {
			return 100.0 * sugar / (water + sugar);
		}
	}
}


Measured memory_bytes: 32964
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	int N;
	long long A, B;
	cin >> N >> A >> B;
	vector<long long> X(N);
	for (auto &X_i : X) {
		cin >> X_i;
	}
	long long ans = 0;
	for (int i = 0; i + 1 < N; ++i) {
		long long d = min(A * (X[i + 1] - X[i]), B);
		ans += d;
	}
	cout << ans << endl;
}



Measured memory_bytes: 1024
def main():
    N = int(input())
    s = input()
    c = ["SW", "WS", "SS", "WW"]
    o_ = {"SS": "S", "WS": "W", "SW": "W", "WW": "S"}
    x_ = {"SS": "W", "WS": "S", "SW": "S", "WW": "W"}
    _o_ = ["SSS", "WSW", "SWW", "WWS"]
    _x_ = ["WSS", "SSW", "SWS", "WWW"]
    ok = False
    for tmp in c:
        ans = tmp
        for i in range(1, N):
            if s[i] == "o": # oの時
                ans += o_[ans[-2:]]
            else:           # xの時
                ans += x_[ans[-2:]]
    
        if ans[0] == ans[-1]:
            jud = ans[-2:] + ans[1]
            if s[0] == "o":
                if jud in _o_:
                    ok = True
            else:
                if jud in _x_:
                    ok = True
        if ok:
            print(ans[:-1])
            break
    if not ok:
        print(-1)

if __name__ == "__main__":
    main()

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

int main(){
int n;
int A[10001] = {};
int *a, *b;

cin >> n;

  a = (int *)malloc(sizeof(int) * n+1);
  b = (int *)malloc(sizeof(int) * n+1);
  
for(int i = 0 ; i < n ; i++){
	cin >> a[i + 1];
	A[a[i + 1]]++;
}

for(int i = 1 ; i <= 10000 ; i++){
	A[i] += A[i - 1];
}

for(int i = 1 ; i <= n ; i++){
	b[A[a[i]]] = a[i];
	A[a[i]]--;
}

for(int i = 1 ; i <= n ; i++){
	if(i != n){
		cout << b[i] << " ";
	}else{
		cout << b[i] << endl;
	}
}

return 0;

}

Measured memory_bytes: 16856