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

int main()
{
    ll n,i;
    cin>>n;
    ll b[n-1];
    for(i=0;i<n-1;i++)
    {
       cin>>b[i];
    }
    ll a[n];
    a[n-1]=b[n-2];
    ll c;
    c=b[n-2];
    for(i=n-2;i>0;i--)
    {
       a[i]=min(b[i],b[i-1]);
       c=c+a[i];

    }
    c=c+b[0];
    cout<<c;
    return 0;
}


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

int n,m,vis[maxn];

ll ans[maxn],a[maxn],k,cnt,q[maxn],pos[maxn];

template <class T>
void read(T &x){
	char s=getchar();int f=0;x=0;
	while(s<'0'||s>'9'){if(s=='-') f=1;s=getchar();}
	while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+s-'0',s=getchar();
	x=f?-x:x;
}

int main(){
	read(n);
	for(int i=1;i<=n;i++){
		read(a[i]);
		pos[i]=1ll*i;
	}
	read(m);read(k);
	for(int i=n;i>=1;i--) a[i]=a[i]-a[i-1];
	for(int i=1,x;i<=m;i++){
		read(x);
		swap(pos[x],pos[x+1]);
	}
	for(int i=1;i<=n;i++){
		ll p=i;cnt=0;
		if(vis[i]) continue;
		q[++cnt]=p;
		vis[p]=1;
		p=pos[p];
		while(p!=i){
			q[++cnt]=p;
			vis[p]=1;
			p=pos[p];
		}
		for(int j=1;j<=cnt;j++) ans[q[j]]=a[q[(j+k-1)%cnt+1]];
	}
	for(int i=1;i<=n;i++){
		ans[i]+=ans[i-1];
		printf("%lld.0\n",ans[i]);
	}
	return 0;
}

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

int gcd(int p,int q){
    if(p%q == 0){
        return q;
    }
        return gcd(q,p%q);
}

int main(){
    int s,w; cin >> s >> w;
    if(w >= s){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
}

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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define x first
#define y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll REM( ll a )
{
	a %= MOD;
	if ( a < 0 ) a += MOD;
	return a;
}

ll ADD( ll a, ll b )
{
	return REM( REM( a ) + REM( b ) );
}

ll SUB( ll a, ll b )
{
	return REM( REM( a ) - REM( b ) );
}

ll MUL( ll a, ll b )
{
	return REM( REM( a ) * REM( b ) );
}

ll POT( ll n, ll k )
{
	if ( k == 0 ) return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 ) return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
   return MUL( a, POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
   if ( x == 1 )
	   return 0;
	for ( ll i = 2;i <= sqrt( x ); i++ )
		if ( x % i == 0 )
		   return 0;
	return 1;
}

const int MAXN = 1e5 + 10;

int n, m;
int task[ MAXN ];
int cor[ MAXN ];

int main()
{
   ios_base::sync_with_stdio( false );
   cin.tie( 0 );
   
   cin >> n >> m;
	FOR( i, 0, m )
	{
		int x;string s;
		cin >> x >> s;
		x--;
		if ( cor[ x ] )
			continue;
		
		if ( s == "WA" )
		{
			task[ x ]++;
		}
		else
		{
			cor[ x ] = 1;
		}
	}

	int ans1 = 0, ans2 = 0;
	FOR( i, 0, n )
	{
		if ( !cor[ i ] )
			continue;
		ans1++;
		ans2 += task[ i ];
	}
	
	cout << ans1 << ' ' << ans2 << "\n";
   return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

//????????£?¨?---------------------------
void print_rect(int x, int y);      //????????¢???????????¢??°
//------------------------------------
int main(void)
{
	int H, W;

	while(1){
		scanf("%d %d", &H, &W);
		
		if(H == 0 && W == 0){
			break;
		}
		if(H >= 3 && W >= 3)
			print_rect(H, W);
		
		else{
			print_rect(H, W);
		}
	}
   return 0;
}

//--------------------------------------------
void print_rect(int x, int y)
{
	for(int i = 0; i < x; i++){
			for(int j = 0; j < y; j++){
				if(i == 0 || j == 0 || i == x - 1 || j == y - 1 ){
					printf("#");
				}
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#define MAX 100

int top=0;
char c_stack[MAX];
int i_stack[MAX];
void push(int);
int pop(void);

int main(){
  int x,a,b,i;
  while(scanf("%s",c_stack)!=EOF){
    if(c_stack[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(c_stack[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(c_stack[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else {
      x=atoi(c_stack); 
      push(x);
    }
  }
  x=0;
  for(i=1;i<=top;i++)
    x=i_stack[i] + x;
  printf("%d\n",x);
  return 0;
}

void push(int x){

 
  top++;
  i_stack[top]=x;

}

int pop(void){

  top--;
  return i_stack[top+1];

}



/*initialize();

    top=0;

    isEmpty();
    return top==0;

    isFull()
      return top >=MAX-1


      push(x)
      if isFull()
		 printf("ERROR OBER FLOW");
    top++;
    S[top] = x

      pop()
      if isEmpty()
		  printf("ERROR UNDER FLOW");


    top--;
    return S[top+1]

  



  return 0;
}
  */



Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
    int n, l, r;
    cin >> n;
    vector<long> v;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        v.emplace_back(tmp);
    }
    sort(v.begin(), v.end());
    l = v[n-1];
    r = v[0];
    double dist = 2e10;
    double judge = l/2.0;
    for(int i = 0; i<n; i++){
        double d = abs((double)v[i] - judge);
        if(dist > d){
            r = v[i];
            dist = d;
        }
    }
    cout << l << " " << r << endl;
    return 0;
}

Measured memory_bytes: 1400
#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;
    if(a <= c && a+b >= c){
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
    
    
    cout << endl;
}


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

int main(){
	int k;
    cin>>k;
  	vector<pair<int, int> > v;
  
  	for(int i=1;i<=9;i++){
      	v.push_back(make_pair(-1, i));
    }
  	int p=0;
  	while(1){
    	int t=v[p].second;
      	if(t==0){
        	v.push_back(make_pair(p, 0));
          	v.push_back(make_pair(p, 1));
        }else if(t==9){
        	v.push_back(make_pair(p, 8));
          	v.push_back(make_pair(p, 9));
        }else{
        	v.push_back(make_pair(p, t-1));
          	v.push_back(make_pair(p, t));
          	v.push_back(make_pair(p, t+1));
        }
      	p++;
      	if(p==k) break;
    }
  	p--;
  
  	long int num=0, ten=1;
  	while(p!=-1){
    	num+=(long int)v[p].second*ten;
      	p=v[p].first;
      	ten*=10;
    }
  
  	cout<<num<<endl;
  
  	return 0;
}

Measured memory_bytes: 7396
#include<stdio.h>
int main(){
int pa,pb,pc,ja,jb,pasta,juice,sum;
scanf("%d\n%d\n%d\n%d\n%d\n",&pa,&pb,&pc,&ja,&jb);
if(pa<=pb && pa<=pc)pasta = pa;
if(pb<=pa && pb<=pc)pasta = pb;
if(pc<=pa && pc<=pb)pasta = pc;
if(ja<=jb)juice = ja;
if(ja>=jb)juice = jb;
sum = (pasta + juice)-50;
printf("%d\n",sum);
return 0;
}

Measured memory_bytes: 596
h, w = map(int, input().split())

def divide(h, w):
    ans = h * w
    for hi in range(1, h):
        #saを決める
        sa = hi * w

        #w分割
        wm = w // 2
        sb = (h - hi) * wm
        sc = (h - hi) * (w - wm)
        ans1 = max(sa, sb, sc) - min(sa, sb, sc)
        #(h-hi)分割
        hm = (h - hi) // 2
        sb = hm * w
        sc = (h - hi - hm) * w
        ans2 = max(sa, sb, sc) - min(sa, sb, sc)

        ans = min(ans, ans1, ans2)
    return ans

print(min(divide(h, w), divide(w, h)))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const double PI=3.14159265358979323846;

ll gcd(ll x,ll y) {
    if(x%y==0) return y;
    else {
        return gcd(y,x%y);
    }
}

vector <pair<ll,ll>> prime_factorize(ll n) {
    vector <pair<ll,ll>> res;
    for(ll i=2;i*i<=n;++i) {
        if(n%i!=0) continue;
        ll num=0;
        while(n%i==0) {
            ++num;
            n/=i;
        }
        res.push_back(make_pair(i,num));
    }
    if(n!=1) res.push_back(make_pair(n,1));
    return res;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll x=gcd(a,b);
    auto pf=prime_factorize(x);
    cout << pf.size()+1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	int n; string s; cin >> n >> s;
	cout << (n%2==0&&s.substr(0, n / 2) == s.substr(n / 2, n / 2) ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        long S = 0;

        for (int i = 0; i < N.length(); i++) {
            S += N.charAt(i) - '0';
        }
        if (Integer.valueOf(N) % S == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}




Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
#define pi 3.14159265358979323846
int main()
{
	double M,H,A,B,th,thh,thm,m,MM,thhh,l;
	cin>>A>>B>>H>>M;
	thh=(H/6+M/360)*pi;
	thm=M*pi/30;
	m=min(thh,thm);
	MM=max(thh,thm);
	thhh=min(MM-m,m+pi*2-MM);
//	dbg((MM/pi));
//	dbg((m/pi));
//	dbg(thhh);//************************
	l=sqrt(A*A+B*B-2*A*B*cos(thhh));
	printf("%.10f",l);
	return 0;
}

Measured memory_bytes: 4160
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  int n; cin >> n;
  int mini = n;
  vector<int> p(n);
  int cnt = 0;
  for(int i = 0; i < n; i++){
    cin >> p[i];
    if(mini >= p[i]){
      cnt++;
      mini = min(mini, p[i]);
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1024
S = list(input())

N = len(S)
S1 = S[:(N-1)//2]
S2 = S[(N+1)//2:]

R = list(reversed(S))
R1 = list(reversed(S1))
R2 = list(reversed(S2))

if S == R and S1 == R1 and S2 == R2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){
  int a,b;
  int sum;
  

  while(cin >> a >> b){
    int digit = 0;
    sum = a + b;
    while(sum > 0){
	digit++;
	sum /= 10;
    }
    cout << digit << endl;
  }
  return 0;
}
//while文の初期化の所で失敗した

Measured memory_bytes: 0
n,k = map(int,input().split())
a = list(map(int,input().split()))
# 小課題１
# cost = 0
# for i in range(1,n):
#    if a[i] < a[i-1] + 1 :
#        cost += a[i-1] + 1 - a[i]
#        a[i] = a[i-1] + 1
# print(cost)

ans = 10**100
for i in range(1,2**n,2):
    if k != sum([ i>>j & 1 for j in range(n)]) :
        continue
    kijun = a[0]
    cost = 0
    for j in range(1,n):
        if ((i>>j) & 1) :
            if a[j] <= kijun :
                cost += (kijun + 1 - a[j])
                kijun = kijun + 1
            else :
                kijun = a[j]
        else :
            kijun = max(kijun,a[j])
    ans = min(ans,cost)
print(ans)


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    int N, i;
    cin >> N >> i;
    cout << N - i + 1 << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


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

int main(){
  int n,k;
  char d;
  cin>>n>>k;
  vector<char> v;
  for(int i=0; i<k; ++i){
    cin>>d;
    v.push_back(d);
  }
  int x;
  while(1){
    x=0;
    string s;
    s=to_string(n);
    for(int i=0; i<k; ++i){
      int y;
      y=0;
      for(int j=0; j<s.size(); ++j){
        if(v[i]==s[j]){
          break;
        } else {
          y++;
        }
      }
      if(y==s.size()){
        x++;
      }
    }
    if(x==k){
      cout<<n<<endl;
      return 0;
    }
    n++;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)
vector<long> A, F;
bool isPossible(long K, long mid){
    long sum_cost = 0;
    long ideal;
    int N = A.size();
    REP(i, 0, N){
        if(A[i] * F[i] > mid){
            ideal = mid / F[i];
            sum_cost += A[i] - ideal;
        }        
    }
    return (sum_cost <= K);
}

long binary_search(long K, long cnt){
    long left = -1; long right = cnt;
    while(right - left > 1){
        long mid = (right + left) /2;
        if(isPossible(K, mid)) right = mid;
        else left = mid;
    }
    return right;
}

int main() {
    long N, K;
    cin>>N>>K;
    long biggest = 1000000000000000000;
    A.resize(N); F.resize(N);
    REP(i, 0, N) cin>> A[i];
    REP(i, 0, N) cin>> F[i];
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());
    long ans = binary_search(K, biggest);
    cout << ans << endl;
}

Measured memory_bytes: 3328
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for CASES in range(int(input())):
'''
inf = 100000000000000000  # 1e17
mod = 998244353

'''
# example input

'''
H, n = map(int, input().split())
bas = 10**4
F = [inf] * (bas*3 + 10)
A = [0] * (bas + 10)
B = [0] * (bas + 10)
for i in range(1, n + 1):
    A[i], B[i] = map(int, input().split())
F[0]=0
for i in range(1, n + 1):
    for j in range(A[i], bas * 3 + 5):
        F[j] = min(F[j], F[j - A[i]] + B[i])
ans = inf
for i in range(H, bas * 3 + 5):
    ans = min(ans, F[i])
print(ans)


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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream &operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e15;
const int modn = 1e9+7;
const int maxn = 2e5+3;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    int n, k;
    cin>>n>>k;
    vi h(n);
    for(int i=0; i<n; i++) {
        cin>>h[i];
    }
    vi dp(n, inf);
    dp[n-1] = 0;
    for(int i=n-2; i>=0; i--) {
        for(int j=i+1; j<=i+k; j++) {
            if(j < n) {
                dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
            }
        }
    }
    cout << dp[0] << "\n";
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll W, H, x, y;
  cin>>W>>H>>x>>y;
  bool can = false;
  if(x*2==W && y*2==H) can = true;
  double ww=W, hh=H;
  if(can) cout<<setprecision(20)<<ww*hh/2<<" "<<1<<endl;
  else cout<<setprecision(20)<<ww*hh/2<<" "<<0<<endl;
}



Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define INF (int)1e9+1
#define INFLL (int)1e18+1
#define sz(bb) (int)bb.size()
#define all(qq) qq.begin(), qq.end() 
#define Max(a, b, c) max(a, max(b, c))
#define Min(a, b, c) min(a, min(b, c))
const double PI=acos(-1);
// #define int unsigned long long int//used when x<=2^64-1 && x>0
#define int long long//used when x<=2^63-1
//bool cmp if returns true it keeps 1st as first else swaps
typedef long long  ll;

const int N=100005;
void solve()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=1;i<n;i++)
        arr[i]+=arr[i-1];
    int dp[n][n];
    for(int len=1;len<=n;len++)
    {
        for(int i=0;i<n;i++)
        {
            int j=i+len-1;
            if(j>=n)
                break;
            int cur=arr[j];
            if(i!=0)
                cur-=arr[i-1];
            if(j==i)
            {
                dp[i][j]=0;
                continue;
            }
            if(j==i+1)
            {
                dp[i][j]=cur;
                continue;
            }
            dp[i][j]=INFLL;
            for(int temp=i;temp<j;temp++)
            {
                dp[i][j]=min(dp[i][j], dp[i][temp]+dp[temp+1][j]+cur);
            }
        }
    }
    cout<<dp[0][n-1]<<"\n";
}
int32_t main()
{
    IOS;
    int t;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4908
flag = True
s = [input() for i in range(2)]
if (len(s[0]) > 10 or len(s[0]) < 1) or (len(s[0]) + 1 != len(s[1])):
    flag = False
else:
    for j in range(len(s[0])):
        if not s[0][j] == s[1][j]:
            flag = False
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cerr << x << " ";} cerr << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cerr << x << " ";}cerr << endl;}
#define printP(p) cerr << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;

int n, k;
bool can[10];

bool ok(int x) {
    while (x > 0) {
        if (!can[x % 10]) return false;
        x /= 10;
    }
    return true;
}

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

    cin >> n >> k;
    rep(i, 10) can[i] = true;
    rep(i, k) {
        int x;
        cin >> x;
        can[x] = false;
    }

    rep2(i, n, 100000) {
        if (ok(i)) {
            cout << i << endl;
            return 0;
        }
    }
}


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

int main() {
  int a, b, c, d;
  cin >>a >>b >>c >>d;
  
  if(a+b > c+d){
    cout << "Left" << endl;
  }
  
  else if(a+b == c+d){
    cout << "Balanced" << endl;
  }
  
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 17
using namespace std;
char str[MAXN];
int main()
{
    scanf("%s",str+1);
    int n=strlen(str+1);
    for(int i=n-1;i>=1;i--)
    {
        if(str[i+1]!='9')
        {
            str[i]--;
            str[i+1]='9';
        }
    }
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        ans+=str[i]-'0';
    }
    printf("%lld",ans);

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  ll n;
  cin >> n;
  string ans = "";

  while(n > 0){
    n--;
    ans = char('a' + n%26) +ans;
    n/=26; 
  }
  cout << ans << endl;
}


Measured memory_bytes: 3604
h,w=map(int,input().split())
n=10
d=[]
for i in range(n):
    d.append(list(map(int,input().split())))
a=[]
for i in range(h):
    a.append(list(map(int,input().split())))

def wf(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d


d=wf(d)
cnt=0
for i in range(h):
    for j in range(w):
        if a[i][j]==-1:continue
        cnt+=d[a[i][j]][1]
print(cnt)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

string s, t, ans = "";
int constexpr maxn = 3002;
int len[maxn][maxn];

void read_input()
{
    cin >> s >> t;
}

int retlen(int i, int j) {
    if(i >= s.size() || j >= t.size()) return 0;
    if(len[i][j] != -1) return len[i][j];

    if(s[i] == t[j]) {
        len[i][j] = 1 + retlen(i + 1, j + 1);
    } else {
        len[i][j] = max(retlen(i + 1, j), retlen(i, j + 1));
    }

    return len[i][j];
}

void go(int i, int j) {
    // i for s
    // j for t
    if(i >= s.size() || j >= t.size()) return;

    if(s[i] == t[j]) {
        ans += s[i];
        go(i + 1, j + 1);
    } else {
        if(retlen(i + 1, j) > retlen(i, j + 1)) go(i + 1, j);
        else go(i, j + 1);
    }
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    read_input();
    for(int i = 0; i < maxn; i++)
        for(int j = 0; j < maxn; j++) len[i][j] = -1;

    go(0, 0);
    cout << ans << endl;

}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    int64_t n;
    cin >> n;

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    constexpr auto M = 1000000007L;
    int64_t ans = 0;
    int64_t s = 0;
    vector<int64_t> nums(60);
    for (auto i : irange(0L, n)) {
        auto aa = a[i];
        auto ss = s;
        for (auto j : irange(0L, 60L)) {
            if ((aa >> j) & 1uL) {
                ss += ((1L << j) % M) * ((i + (M - 2) * nums[j]) % M);
                ss %= M;
            }

            nums[j] += ((aa >> j) & 1uL);
        }

        ans += ss;
        ans %= M;

        s += aa;
        s %= M;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
def func(x,y):
    return min(x,y)

class LazySegmentTree():
    def __init__(self, n):
        self.lv = (n-1).bit_length()
        self.n = 2 ** self.lv
        self.arr = [2**31-1] * (2*self.n-1)
        self.lazy = [None] * (2*self.n-1)

    #伝播区間
    def getidx(self, l, r):
        L = (l + self.n) >> 1
        R = (r + self.n) >> 1
        lc = 0 if l & 1 else (L & -L).bit_length()
        rc = 0 if r & 1 else (R & -R).bit_length()
        for i in range(self.lv):
            if rc <= i:
                yield R
            if L < R and lc <= i:
                yield L
            L >>= 1; R >>=1

    #伝播
    def propagate(self,*ids):
        for i in reversed(ids):
            v = self.lazy[i-1]
            if v is None:
                continue
            self.lazy[2*i-1] = self.arr[2*i-1] = self.lazy[2*i] = self.arr[2*i] = v
            self.lazy[i-1] = None

    #[l, r] をxで更新
    def update(self,l,r,x):
        #[l, r)に変更
        r+=1
        *ids, = self.getidx(l,r)
        self.propagate(*ids)

        L = self.n + l; R = self.n + r
        while L < R:
            if R & 1:
                R -=1
                self.lazy[R-1] = self.arr[R-1] = x
            if L & 1:
                self.lazy[L-1] = self.arr[L-1] = x
                L += 1
            L >>= 1; R >>= 1

        for i in ids:
            self.arr[i-1] = func(self.arr[2*i-1], self.arr[2*i])

    #[l, r]のクエリに答える
    def query(self,l,r):
        #[l, r)に変更
        r+=1
        self.propagate(*self.getidx(l,r))
        L = self.n + l; R = self.n + r

        s = 2**31-1
        while L < R:
            if R & 1:
                R -=1
                s = func(s, self.arr[R-1])
            if L & 1:
                s = func(s, self.arr[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

import sys
input=sys.stdin.readline
n,q=map(int,input().split())
sg=LazySegmentTree(n)
for _ in range(q):
    que=list(map(int,input().split()))
    if que[0]==0:
        y,l,r,x=que
        sg.update(l,r,x)
    else:
        y,l,r=que
        print(sg.query(l,r))



Measured memory_bytes: 12440
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main(){

  int ans = 0;
  int n,q,x,l[100009],r[100009];
  x = 0;
  vector<int> v;
  string s;

  cin >> n >> q >> s;
  for(int i=0;i<q;i++){
    cin >> l[i] >> r[i];
  }

  for(int i=0;i<n-1;i++){
    if(s[i]=='A' && s[i+1]=='C'){
      x++;
    }
    v.push_back(x);
  }
  v.push_back(x);

  int z = 0;
  for(int i=0;i<q;i++){
    if(l[i]-2<0){
      z = 0;
    }
    else{
      z = v[l[i]-2];
    }
    ans = v[r[i]-2] - z;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 2296
#include<iostream>
#include<cstdio>

using namespace std;

int n,a,b,p,x,y,z;

int main(){
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;++i){
		scanf("%d",&p);
		if(p<=a)++x;else if(p>a&&p<=b)++y;else ++z;
	}
	printf("%d",min(x,min(y,z)));
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n, k, cnt = 0;
    cin >> n >> k;
    vector<int> x(n + 1, INF);

    rep(i, 0, n)
    {
        int a;
        cin >> a;
        if (x[a] == INF)
        {
            ++cnt;
            x[a] = 0;
        }
        ++x[a];
    }

    if (cnt <= k)
    {
        cout << 0 << '\n';
        return 0;
    }

    sort(all(x));

    int ans = 0;
    rep(i, 0, cnt - k)
    {
        ans += x[i];
    }

    cout << ans << '\n';
    return 0;
}

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

namespace Union_find {

	class union_find {
		int n;
		std::vector<int> par;
		std::vector<int> rank;
	public:
		union_find(int _n);
		int find(int x);
		void unite(int x, int y);
		bool same(int x, int y) { return find(x) == find(y); }
	};

	union_find::union_find(int _n) :n(_n), par(_n), rank(_n, 1) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
		}
	};

	int union_find::find(int x) {
		if (par[x] == x)
			return x;
		else
			return par[x] = find(par[x]);
	}

	void union_find::unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;

		if (rank[x] < rank[y])
			par[x] = y;
		else
			par[y] = x;

		if (rank[x] == rank[y])
			rank[x]++;

		return;
	}
}

using namespace Union_find;
int main(){
  int n;
  cin>>n;
  vector<int> x(n);
  vector<int> y(n);
  vector<pair<long long int,int>> xx(n);
  vector<pair<long long int,int>> yy(n);
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    xx[i]={x[i],i};
    yy[i]={y[i],i};
  }
  sort(xx.begin(),xx.end());
  sort(yy.begin(),yy.end());
  set<tuple<long long int,int,int>> edge;
  for(int i=0;i<n-1;i++){
    edge.insert(make_tuple(xx[i+1].first-xx[i].first,xx[i].second,xx[i+1].second));
    edge.insert(make_tuple(yy[i+1].first-yy[i].first,yy[i].second,yy[i+1].second));
  }
  union_find u(n);
  
  long long int res=0;
  for(auto it=edge.begin();it!=edge.end();it++){
    auto val=*it;
    long long int cost=get<0>(val);
    int v1=get<1>(val);
    int v2=get<2>(val);
    if(!u.same(v1,v2)){
      res+=cost;
      u.unite(v1,v2);
    }
  }
  cout<<res<<endl;

  return 0;
}


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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    ll ans = 1;
    for (size_t i = 0; i < n; i++)
    {
        ans *= i + 1;
        ans = ans % (1000000000 + 7);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P =pair<ll,ll>;
const ll INF =ll(1e18)+5;

ll N;

bool onBoard(int y,int x){
    if(y>=0&&y<N&&x>=0&&x<N){
        return true;
    }
    return false;
}

int main() {
    cin >> N;
    vector<vector<ll>> num(N);
    vector<vector<bool>> exist(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            int val1 = min(i+1,j+1);
            int val2 = min(N-i,N-j);
            num[i].push_back(min(val1-1,val2-1));
            exist[i].push_back(true);
        }
    }
    int dx[]= {0,1,0,-1};
    int dy[] = {1,0,-1,0};
    ll ans =0;
    for(int q=0;q<N*N;q++){
        int inP;
        cin >> inP;
        --inP;
        int y = inP/N;
        int x = inP%N;
        // cerr <<"P="<<inP<<"y=" <<y <<"x=" <<x <<endl;
       
        ll temp = num[y][x]; 
        // cerr << "temp=" << temp<< endl;;
        ans += temp;
        exist[y][x] = false;
        //更新
        queue<P> pq;
        pq.push(P(y,x));
        while(!pq.empty()){
            P p = pq.front();
            int py =p.first;
            int px = p.second;
            // cerr <<"py="<< py <<"px=" <<px << endl;
            pq.pop();
            
           
            for(int i=0;i<4;i++){
                int ny = py + dy[i];
                int nx = px + dx[i];
                if(!onBoard(ny,nx)){
                    continue;
                }
                ll temp =num[py][px];
                if(exist[py][px]){
                     temp++;
                }
                if(num[ny][nx] > temp){
                    num[ny][nx] = temp;
                    pq.push(P(ny,nx));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5640
N,M,X,Y=(int(i) for i in input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
x.sort()
y.sort()
c=0
for i in range(X+1,Y+1):
    if x[-1] < i and i <= y[0]:
        c=2
if c == 0 :
    print("War")
else:
    print("No War")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,c,k;
cin>>n>>c>>k;
vector<int> v(n);
for(int i=0;i<n;++i)cin>>v[i];
sort(v.begin(),v.end());
int res=0;
for(int i=0;i<n;){
++res;
int j=i;
int r=i;
int t=0;
for(;r<n&&v[r]-v[j]<=k&&t<c;++r,++t);
i=i+t;
}
cout<<res<<endl;
return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int X = scan.nextInt();
    int Y = scan.nextInt();
    int tsuru = 0;
    int kame = 0;
    int leg = 0;
    for (int i = 0;i <= X;i++) {
      tsuru = i;
      kame = X - i;
      leg = tsuru * 2 + kame * 4;
      if (leg == Y) {
        System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");
  }
}


Measured memory_bytes: 35772
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int H, W;
  cin >> H >> W;
  int CX, CY;
  cin >> CX >> CY;
  int DX, DY;
  cin >> DX >> DY;
  vector<vector<char>> M(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> M.at(i).at(j);
    }
  }
  vector<vector<int>> T(H, vector<int>(W, INF));
  T.at(CX - 1).at(CY - 1) = 0;
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> X;
  tuple<int, int, int> DS(0, CX - 1, CY - 1);
  X.push(DS);
  vector<int> SX = {1, -1, 0, 0};
  vector<int> SY = {0, 0, 1, -1};
  vector<int> PX = {2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -2, -2, -2, -2, -2};
  vector<int> PY = {-2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2};
  while (!X.empty()) {
    tuple TX = X.top();
    X.pop();
    if (T.at(get<1>(TX)).at(get<2>(TX)) < get<0>(TX)) {
      continue;
    }
    for (int i = 0; i < 4; i++) {
      if (get<1>(TX) + SX.at(i) >= 0 && get<1>(TX) + SX.at(i) < H &&
          get<2>(TX) + SY.at(i) >= 0 && get<2>(TX) + SY.at(i) < W &&
          M.at(get<1>(TX) + SX.at(i)).at(get<2>(TX) + SY.at(i)) == '.' &&
          T.at(get<1>(TX) + SX.at(i)).at(get<2>(TX) + SY.at(i)) >
          T.at(get<1>(TX)).at(get<2>(TX))) {
        T.at(get<1>(TX) + SX.at(i)).at(get<2>(TX) + SY.at(i)) = 
          T.at(get<1>(TX)).at(get<2>(TX));
        tuple<int, int, int> DT(T.at(get<1>(TX) + SX.at(i)).at(get<2>(TX) + SY.at(i)), get<1>(TX) + SX.at(i), get<2>(TX) + SY.at(i));      
        X.push(DT);
      }
    }
    for (int i = 0; i < 20; i++) {
      if (get<1>(TX) + PX.at(i) >= 0 && get<1>(TX) + PX.at(i) < H &&
          get<2>(TX) + PY.at(i) >= 0 && get<2>(TX) + PY.at(i) < W &&
          M.at(get<1>(TX) + PX.at(i)).at(get<2>(TX) + PY.at(i)) == '.' &&
          T.at(get<1>(TX) + PX.at(i)).at(get<2>(TX) + PY.at(i)) >
          T.at(get<1>(TX)).at(get<2>(TX)) + 1) {
        T.at(get<1>(TX) + PX.at(i)).at(get<2>(TX) + PY.at(i)) = 
          T.at(get<1>(TX)).at(get<2>(TX)) + 1;
        tuple<int, int, int> DT(T.at(get<1>(TX) + PX.at(i)).at(get<2>(TX) + PY.at(i)), get<1>(TX) + PX.at(i), get<2>(TX) + PY.at(i));
        X.push(DT);
      }
    }
  }
  
  if (T.at(DX - 1).at(DY - 1) == INF) {
    cout << -1 << endl;
  }
  else {
    cout << T.at(DX - 1).at(DY - 1) << endl;
  }
}
    

Measured memory_bytes: 8688
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int n, m;

int main() {
    //cout << fixed << setprecision(15);
    int n = readInt(), m = readInt();

    if(n<=5) cout << 0 << endl;
    else if(n <= 12) cout << m/2 << endl;
    else cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

fn main() {
    let n: usize = get();
    let v: Vec<i64> = (0 .. n).map(|_| get()).collect();
    let tot: i64 = v.iter().fold(0, |x,y| x + y);
    let s: i64 = (tot + (n as i64) / 2 * if tot > 0 { 1 } else { -1 }) / (n as i64);
    let mut c: i64 = 0;
    for i in v {
        c += (i - s) * (i - s);
    }
    println!("{}", c);
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
	string S;
	cin >> S;
	rep(i, 3) {
		if(S[i]==S[i+1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}

	cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long long int n;
int main()
{
	long long int ans,temp;
	cin>>n;
	ans=n/11;
	temp=n-11*ans;
	if(temp==0) cout<<2*ans<<endl;
	else if(temp<=6) cout<<2*ans+1<<endl;
	else cout<<2*ans+2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct Tree{

  ll val;
  ll par;
  vector<Tree*> child;

};

int main(void){

  ll n;
  cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);

  vector<ll> is_made(n+1,0);

  map<ll, vector<ll> > next_map;

  rep(i,n-1){
    cin>>a[i];
    cin>>b[i];

    next_map[ a[i] ].pb( b[i] );
    next_map[ b[i] ].pb( a[i] );

  }
  vector<ll> c(n);

  rep(i,n) cin>>c[i];

  sort(all(c),greater<ll>() );
  vector<ll> way(n+1);

  

  //stack<Tree*> sta;
  stack<ll> sta;
  sta.push(1);
  is_made[1]=1;

  ll cnt=0;

  way[1]=c[cnt];
  cnt++;

  while(sta.size()>0){
    auto val=sta.top();
    sta.pop();
    //cout << node->val << endl;
    //cout << next_map[1].size() << endl;
    for(auto x: next_map[ val ]){
      //pripare(x);
      //if(x.first==node->par) continue;
      if(is_made[x]==1) continue;
      else{
        
        is_made[x]=1;
        way[x]=c[cnt];
        cnt++;

        sta.push(x);

      }
    }

  }
  ll ans=0;
  for(ll i=1;i<=n;i++){
    //cout << way[i] << " ";
    if(i!=1) ans+=way[i];
  }
  
  cout << ans << endl;
  for(ll i=1;i<=n;i++){
    cout << way[i] << " ";
  }
  cout << endl;
  

  return 0;

}


Measured memory_bytes: 1920
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> x;
  for(int i=0; i<n; i++){
    int a;
    cin >> a;
    x.push_back(a);
  }
  sort(x.begin(), x.end());
  int min=100000000;
  for(int i=x[0]; i<=x[n-1]; i++){
    int hp=0;
    for(int j=0; j<n; j++){
      hp+=pow(x[j]-i, 2);
    }
    if(min>hp) min=hp;
  }
  cout << min;
  return 0;
}

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

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

int collatz(int n){
	if(n%2==0){return n/2;}
	return 3*n+1;
}

int main(){
	int s; cin >> s;
	vector<bool> a(1000000, false);
	a[s]= true;
	for(int i = 0; i < 1000000; ++i){
		s = collatz(s);
		if(a[s]){
			cout << i+2 << endl;
			return 0;
        }
        else{a[s]= true;}
    }
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long sum=0,m,n,c=0;
	cin >> n >> m;
	vector<int> vec(n);
    for(int i=0;i<n;i++){
    	cin >> vec[i];
        sum+=vec[i];
    }
    for(int i=0;i<n;i++){
    	if((sum+4*m-1)/(4*m) <= vec[i])c++;
    }
    if(c < m)
    	cout<< "No";
    else
		cout << "Yes";
}

Measured memory_bytes: 3636
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n=Integer.parseInt(sc.next());
int k=Integer.parseInt(sc.next());
int ans=1;
for(int i=0;i<n;i++){
ans=Math.min(2*ans,ans+k);
}
System.out.println(ans);
}}

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

int main(){
  int len,a,ans;
  string s;
  while(1){
    cin>>s;
    if(s=="0")break;
    int d[11]={};
    len=s.size();
    ans=a=0;
    for(int i=0;i<len;i++){
      if(s[i]!='0')d[a]++;
      if(i%2)a-=s[i]-'0';
      else a+=s[i]-'0';
      a=(a+11)%11;
      ans+=d[a];
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1316
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

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

ll sum(ll b, ll n)
{
    if (b > n)
        return n;

    return sum(b, n / b) + n % b;
}

int main()
{
    ll n, s, ans;
    cin >> n >> s;

    ans = INF;

    ll sq = sqrt(n);
    if (sq * sq == n)
        sq--;

    if (n == s)
    {
        cout << n + 1 << endl;
        return 0;
    }

    for (ll i = 2; i <= sqrt(n); i++)
    {
        if (sum(i, n) == s)
        {
            ans = min(i, ans);
        }
    }

    for (ll i = 1; i <= sq; i++)
    {
        ll b = (n - s) / i + 1;
        if (b <= 1)
            continue;
        if (sum(b, n) == s)
        {
            ans = min(b, ans);
        }
    }

    if (ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;

    return 0;
}

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

int main(){
	int k,n;
	cin>>n>>k;
	vector<int> a(k);
	for(int i = 0; i < k; i++){
		cin>>a.at(i);
	}
	
	vector<int> diff(k+1);
	//ind diff[k+1];
	for(int i = 1; i<k+1; i++){
		diff[i-1] = a[i] - a[i-1];
	}
	// for(int i = 0; i<k; i++){
	// 	cout<<diff[i]<<endl;
	// }
	//sort(diff.begin(),diff.end());
	//int diff_max=max(diff[0],diff[diff.size()-1]);
	diff[k]=n-a[k-1]+a[0];
	sort(diff.begin(),diff.end());
	int ans = n - max(diff[0],diff[diff.size()-1]);
	int max_diff=max(diff[0],diff[diff.size()-1]);
//	cout<<"max: "<<max_diff<<endl;
	// for(int i = 0; i<k; i++){
	// 	cout<<diff[i]<<endl;
	// }
	cout<<ans<<endl;	
}

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

using namespace std;

using ll = long long;

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

    int a, b;
    cin >> a >> b;
    if (b % a == 0) cout << a + b << endl;
    else cout << b - a << endl;

    return 0;
}


Measured memory_bytes: 256