akhauriyash/Code-Regression huggingface dataset:
n = int(input())
h = list(map(int, input().split()))
h = [-1] + h

for i in range(1, n + 1):
    if h[i - 1] < h[i]:
        h[i] -= 1
    if h[i-1] > h[i]:
        print("No")
        exit()
print("Yes")

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

using namespace std;

const int N = 555;

int n, m, d;

char ans[N][N];
char names[4] = {'B', 'R', 'Y', 'G'};

int main() {
	cin >> n >> m >> d;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int x = i + j, y = i - j + 10000;
			int mask = (x / d) % 2;
			mask |= ((y / d) % 2) << 1;
			ans[i][j] = names[mask];
		}
	}
	for (int i = 0; i < n; i++) {
		ans[i][m] = 0;
		printf("%s\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    int n, k, q; cin >> n >> k >> q;
    k -= q;

    int a[q];
    REP(0, i, q) {
        cin >> a[i];
        a[i]--;
    }

    int v[n];
    REP(0, i, n) v[i] = k;

    REP(0, i, q) {
        v[a[i]]++;
    }

    REP(0, i, n) {
        cout << (v[i] > 0 ? "Yes" : "No") << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;
#define MAXN 100005
#define NIL -1

struct Node{
	int p, l, r;
};

Node T[MAXN];
int n, D[MAXN];

void print(int u){
	int i, c;
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";
	
	if (T[u].p == NIL) {
		cout << "root, ";
	}else if (T[u].l == NIL) {
		cout << "leaf, ";
	}else {
		cout << "internal node, ";
	}
	
	cout << "[";
	
	for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
		if (i) {
			cout << ", ";
		}
		cout << c;
	}
	cout << "]" << endl;
}

void setDepth(int u, int p){
	D[u] = p;
	if (T[u].r != NIL) {
		setDepth(T[u].r, p);
	}
	if (T[u].l != NIL) {
		setDepth(T[u].l, p+1);
	}
}

int main(int argc, char *argv[]) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		T[i].p = T[i].l = T[i].r = NIL;
	}

	for (int i = 0; i < n; i++) {
		int v, m, l;
		cin >> v >> m;
		for (int j = 0; j < m; j++) {
			int child;
			cin >> child;
			if (j == 0) {
				T[v].l = child;
			}else {
				T[l].r = child;
			}
			l = child;
			T[child].p = v;
		}
	}
	int root;
	for (int i = 0; i < n; i++) {
		if (T[i].p == NIL) {
			root = i;
		}
	}
	setDepth(root, 0);
	for (int i = 0; i < n; i++) {
		print(i);
	}
	return 0;
}


Measured memory_bytes: 7772
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] Pz = new int[N];
        for (int i = 0; i < N; i++) {
            Pz[i] = sc.nextInt();
        }
        int minVal = 1000000000;
        int cnt = 0;
        for (int i = 0; i < N; i++){
            if (Pz[i] < minVal){
                minVal = Pz[i];
                cnt++;
            }

        }
        System.out.println(cnt);

    }
}

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

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

using namespace std;

int main() {
  int n, d, x;
  std::cin >> n >> d >> x;
  std::vector<int> a(n);
  rep(i, n) std::cin >> a[i];

  rep(j, n) {
    int i = 0;
    while(d >= i * a[j] + 1) {
      i++;
      x++;
    }
  }

  std::cout << x << std::endl;
  return 0;
}


Measured memory_bytes: 3572
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve() {
	int k, r, l;
	cin >> k >> r >> l;
	long double p, e, t;
	cin >> p >> e >> t;
	queue<tuple<int, long double, long double, long double>> nextgo;
	nextgo.push(make_tuple(k, (long double)1.0L, (long double)r, (long double)l));
	long double ans = 0;
	while (nextgo.empty() == false) {
		tuple<int, long double, long double, long double> now = nextgo.front();
		nextgo.pop();
		if (t - e <= get<2>(now) && get<3>(now) <= t + e) {
			ans += get<1>(now);
			continue;
		}
		if (get<2>(now) > t + e || get<3>(now) < t - e) continue;
		get<0>(now)--;
		long double next = (get<2>(now) + get<3>(now)) / 2.0L;
		if (get<0>(now) < 0) {
			if (t - e <= next && next <= t + e) {
				ans += get<1>(now);
			}
			continue;
		}
		if (next < t) {
			//l should be bringed
			nextgo.push(make_tuple(get<0>(now), get<1>(now) * p, get<2>(now), next));

			nextgo.push(make_tuple(get<0>(now), get<1>(now) * (1.0L - p), next ,get<3>(now)));
		}
		else {
			nextgo.push(make_tuple(get<0>(now), get<1>(now) * (1.0L - p), get<2>(now), next));

			nextgo.push(make_tuple(get<0>(now), get<1>(now) * p, next, get<3>(now)));
		}
	}
	cout << ans << endl;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3324
#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);

ll DP[200005][2];

int main() {
  int N;
  cin>>N;
  ll A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  if(N==2) {
    cout<<max(A[0], A[1])<<endl;
    return 0;
  }
  if(N==3) {
    cout<<max(A[0], max(A[1], A[2]))<<endl;
    return 0;
  }
  DP[0][1] = A[0];
  DP[1][1] = A[1];
  DP[2][0] = A[2];
  DP[2][1] = A[0]+A[2];
  for(int i=3;i<N;++i) {
    if(i%2==0) {
      DP[i][1] = DP[i-2][1]+A[i];
      DP[i][0] = max(DP[i-4][1], max(DP[i-3][1], DP[i-2][0])) + A[i];
    }
    else {
      DP[i][1] = max(DP[i-2][1], DP[i-3][1]) + A[i];
    }
  }
  if((N-1)%2==0) cout<<DP[N-1][0]<<endl;
  else cout<<DP[N-1][1]<<endl;
}



Measured memory_bytes: 8268
import sys
input = sys.stdin.readline

def main():
    while True:
        n, w, d = map(int, input().split())
        if w == 0:
            break
        cuts = [list(map(int, input().split())) for i in range(n)]
        cakes = [(w,d,w*d)]
        for cut in cuts:
            p, s = cut
            w, d, wd = cakes.pop(p-1)
            s = s % (w*2+d*2)
            if s > w+d:
                s -= w+d
            if 0 < s and s < w:
                w1 = min(s, w-s)
                w2 = w - w1
                cakes.append((w1, d, w1*d))
                cakes.append((w2, d, w2*d))
            else:
                d1 = min(w+d-s, s-w)
                d2 = d - d1
                cakes.append((w, d1, w*d1))
                cakes.append((w, d2, w*d2))
        cakes = sorted(cakes, key=lambda x:x[2])
        len_ = len(cakes)
        for i in range(len_):
            _,__,area = cakes[i]
            print(area, end="")
            if i != len_ - 1:
                print(" ",end="")
            else:
                print()

if __name__ == "__main__":
    main()



Measured memory_bytes: 6668
import java.util.*;
import java.io.PrintWriter;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong()-1;
		ArrayList<Character> list=new ArrayList<>();
		while(n>=0){
			list.add((char)('a'+n%26));
			n/=26;
			n--;
		}
		for(int i=list.size()-1; i>=0; i--){
			System.out.print(list.get(i));
		}
	}
}


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

int main(){
	int N,K;
	int R,S,P;
	string T;
	cin >> N >> K;
	cin >> R >> S >> P;
	cin >> T;

	string str;
	ll ans = 0;
	for(int i=0; i<N; i++){
		char c; int score=0;
		switch(T.at(i)){
			case 'r': c='p'; score=P; break;
			case 's': c='r'; score=R; break;
			case 'p': c='s'; score=S; break;
			default : break;
		}
		if(i-K>=0 && str.at(i-K)==c){ c = 'n'; score=0; }
		ans += score;
		str.push_back(c);
	}

	cout << ans << endl;

}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1)*a%MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1)*a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b,a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size()>n) return kaijo_memo[n];
  if(kaijo_memo.size()==0) kaijo_memo.push_back(1);
  while(kaijo_memo.size()<=n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1]*kaijo_memo.size()%MOD);
  return kaijo_memo[n];
}

signed main(){
	int n; cin>>n;
	VI a(n); rep(i,n) cin>>a[i]; sort(ALL(a));
	cout<<a[n-1]-a[0]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,n,f=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        f=f+a[i];
    }
    f=f-n;
    printf("%d\n",f);
    return 0;
}


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

int main(void){
	string s, t;
	cin >> s;
	cin >> t;
	if(s.substr(0, s.size()) == t.substr(0, s.size())){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

int main() {
  int Q;
  cin>>Q;
  vector<int> p={};
  for(int i=3;i<100000;i+=2){
    int a=2,x=0;
    while(a<=sqrt(i)){
      if(i%a==0){
        x++;
        break;
      }
      a++;
    }
    if(x==1){
      continue;
    }
    int Z=(i+1)/2;
    a=2;
    while(a<=sqrt(Z)){
      if(Z%a==0){
        x++;
        break;
      }
      a++;
    }
    if(x==0){
      p.push_back(i);
    }
  }
  for(int i=0;i<Q;i++){
    int l,r;
    cin>>l>>r;
    int A=lower_bound(p.begin(),p.end(),r+1)-p.begin();
    int B=lower_bound(p.begin(),p.end(),l)-p.begin();
    cout<<A-B<<endl;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define MD 1000000007
typedef long long int ll;
 
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a*b>=c*d){
        cout<<a*b<<endl;
    }else{
        cout<<c*d<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#n=int(input())
a,b,c,k=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

if k<=a+b:
    ans=min(a,k)
else:
    ans=a-(k-(a+b))

print(ans)




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

int main(){
    int A, B;

    cin >> A >> B;

    cout << max({A+B, A*B, A-B}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    LL n, k; cin >> n >> k;
    
    LL ans = (n-2) / (k-1) + 1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<queue>
#define sqr(x)(x)*(x)
#define fz1(i,n) for (i=1;i<=n;i++)
#define fd1(i,n) for (i=n;i>=1;i--)
#define fz0g(i,n) for (i=0;i<=n;i++)
#define fd0g(i,n) for (i=n;i>=0;i--)
#define fz0k(i,n) for (i=0;i<n;i++)
#define fd0k(i,n) for (i=(long long)(n-1);i>=0;i--)
#define fz(i,x,y) for (i=x;i<=y;i++)
#define fd(i,y,x) for (i=y;i>=x;i--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
int n,m,i,j,cnt,sz[100005];
char ss[100005];
priority_queue<pair<int,int> > pq;
vector<int> s1,s2;
string st;
void no()
{
	puts("-1");
	exit(0);
}
int main()
{
	scanf(" %s",ss);st=ss;
	n=st.length();st=" "+st; 
	cnt=1;pq.push(make_pair(n,1));sz[1]=n;
	if (st[1]=='0'||st[n]=='1') no();
	for (i=1;i<=n-i;i++) if (st[i]!=st[n-i]) no();
	for (i=n-1;i>=n-i;i--) if (st[i]=='1')
	{
		int x=pq.top().second;pq.pop();
		if (sz[x]<i)
		{
			no();
		}
		if (sz[x]>i)
		{
			cnt++;
			s1.push_back(x);
			s2.push_back(cnt);
			sz[x]-=i;
			sz[cnt]=i;
			pq.push(make_pair(sz[cnt],cnt));
		}
		pq.push(make_pair(sz[x],x));
	}
	while (!pq.empty())
	{
		int x=pq.top().second;pq.pop();
		while (sz[x]>1)
		{
			sz[x]--;
			s1.push_back(x);
			s2.push_back(++cnt);
		}
	}
	for (i=0;i<n-1;i++) printf("%d %d\n",s1[i],s2[i]);
	return 0;
}

Measured memory_bytes: 3448
#include <iostream>
#include <stdint.h>
#include <vector>

using namespace std;

struct Answer {
  short h0;
  short w0;
  short h1;
  short w1;
};

vector<struct Answer> answers;

int main()
{
  short H, W;
  cin >> H >> W;

  short A[500][500];
  
  for (short h=0; h<H; ++h)
    for (short w=0; w<W; ++w)
      cin >> A[h][w];

  int count=0;

  for (short h=0; h<H; ++h) {
    if (h%2==0) {
      short w=0;
      for (; w<W-1; ++w) {
	if (A[h][w]%2==1) {
	  --A[h][w];
	  ++A[h][w+1];
	  answers.push_back({h,w,h,(short)(w+1)});
	}
      }
      // w == W-1
      if (A[h][w]%2==1 && h<H-1) {
	--A[h][w];
	++A[h+1][w];
	answers.push_back({h,w,(short)(h+1),w});
      }
    } else {
      short w=W-1;
      for (; w>0; --w) {
	if (A[h][w]%2==1) {
	  --A[h][w];
	  ++A[h][w-1];
	  answers.push_back({h,w,h,(short)(w-1)});
	} 
      }
      // w == 0
      if (A[h][w]%2==1 && h<H-1) {
	--A[h][w];
	++A[h+1][w];
	answers.push_back({h,w,(short)(h+1),w});
      }
    }	     
  }

  cout << answers.size() << endl;
  for (auto& ans : answers)
    cout << ans.h0+1 << ' ' << ans.w0+1 << ' ' << ans.h1+1 << ' ' << ans.w1+1 << endl;
  
  return 0;
}

Measured memory_bytes: 3700
import java.util.*;

import static java.lang.System.*;

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

        long onePrice = Math.min(Math.min(Q * 4, H * 2), S);

        if ((double) onePrice <= (double) D / 2) {
            out.println(N * onePrice);
        } else {
            out.println((N / 2) * D + (N % 2) * onePrice);
        }
    }
}

Measured memory_bytes: 23764
#include<stdio.h>
int Y[]={1,0,-1,0};
int X[]={0,1,0,-1};
int main(){
  int h,w,ans=0,max,i,j,k,l,ny,nx,y[510],x[510],c[30][30],t,r;
  char m[30][30]={};
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++)scanf("%s",m[i+1]+1);
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      if(m[i][j]=='#')continue;
      for(k=0;k<h;k++){
	for(l=0;l<w;l++)c[k+1][l+1]=-1;
      }
      c[y[0]=i][x[0]=j]=t=max=0;
      for(r=1;r-t;t++){
	for(k=0;k<4;k++){
	  ny=y[t]+Y[k];
	  nx=x[t]+X[k];
	  if(m[ny][nx]!='.')continue;
	  if(c[ny][nx]>-1)continue;
	  c[y[r]=ny][x[r]=nx]=c[y[t]][x[t]]+1;
	  if(max<c[ny][nx])max=c[ny][nx];
	  r++;
	}
      }//printf("max%d\n",max);
      if(ans<max)ans=max;
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

using namespace std;

int main(){
   int X,Y;
   cin >> X >> Y;
   if(X*2 > Y) cout << "No" << endl;
   else if(X*4 < Y) cout << "No" << endl;
   else if((Y-(X*2))%2==1) cout << "No" << endl;
   else cout << "Yes" << endl;
   return 0;
}


Measured memory_bytes: 3644
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())
inline void Fail(){
	printf("IMPOSSIBLE");
	exit(0);
}

const int maxn=1005;
const int maxm=5005;
int n;
vector<int>edge[maxn];
int dp[2][maxn],w[maxn],tmp[2][maxn][maxm];

void dfs(int x,int p){
	vector<int>son;
	rep(i,edge[x].size()){
		int y=edge[x][i];
		if(y==p)continue;
		dfs(y,x);
		son.push_back(y);
	}
	if(son.empty()){
		dp[0][x]=dp[1][x]=0;
		return;
	}
	rep(i,son.size())rep(j,w[x]+1)rep(k,2)tmp[k][i][j]=INF;
	int mn[2]={1000000000,1000000000};
	rep(k,2)rep(i,son.size())rep(j,w[x]+1){
		if(j>=w[son[i]])tmp[k][i][j]=min(tmp[k][i][j],(!i?0:tmp[k][i-1][j-w[son[i]]])+dp[k^1][son[i]]);
		if(j>=dp[k][son[i]])tmp[k][i][j]=min(tmp[k][i][j],(!i?0:tmp[k][i-1][j-dp[k][son[i]]])+w[son[i]]);
		if(i==son.size()-1)mn[k]=min(mn[k],tmp[k][i][j]);
	}
	if(mn[0]==1000000000&&mn[1]==1000000000)Fail();
	dp[1][x]=mn[0];
	dp[0][x]=mn[1];
//	printf("%d %d %d\n",x,dp[0][x],dp[1][x]);
}

int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		int p;
		scanf("%d",&p);
		edge[p].push_back(i);
		edge[i].push_back(p);
	}
	REP(i,n)scanf("%d",&w[i]);
	dfs(1,-1);
	printf("POSSIBLE");
	return 0;
}

Measured memory_bytes: 37632
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
const double eps=1e-9;
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
int N;
int main(){
    read(N);
    for (int h=1;h<=3500;h++){
        for (int n=1;n<=3500;n++){
            ll x=1LL*N*h*n,y=4LL*h*n-N*n-N*h;
            if (y>0 && x%y==0){
                ll w=x/y;
                return printf("%d %d %lld\n",h,n,w)*0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
     public static void main(String[] args) {
          Scanner scanner = new Scanner(System.in);
          int n = scanner.nextInt();
          if( n == 1 ) {
               System.out.println("Hello World");
               return;
          }
          if( n != 2 ) return;
          int a = scanner.nextInt();
          int b = scanner.nextInt();
          System.out.println( a + b );
     }
}


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

int main(){
  int k; cin >>k;
  string s="";
  rep(i,k) s+="ACL";
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    int ab=0;
    int lb=0;
    int ra=0;
    int inab=0;
    rep(i,n){
        string s;
        cin>>s;
        if(s[0]=='B'&&s[s.size()-1]=='A'){
            ab++;
        }else if(s[0]=='B'){
            lb++;
        }else if(s[s.size()-1]=='A'){
            ra++;
        }

        for(int j=0;j<s.size()-1;j++){
            if(s[j]=='A'&&s[j+1]=='B')inab++;
        }
    }
    //cout<<ab<<lb<<ra<<inab<<endl;
    int ans=0;
    ans+=inab;



    if(ab==0){
        ans+=min(lb,ra);

    }else {

       ans+=(ab-1);
       //cout<<ans<<endl;
       if(lb>=1){ans++;lb--;}
       if(ra>=1){ans++;ra--;}
       ans+=min(lb,ra);

    }

    cout<<ans<<endl;


    return 0;
}


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

int main() {
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  vector<int> y(M);

  int i=0;
  for(;i<N;i++){
    cin >> x.at(i);
  }
  for(i=0;i<M;i++){
    cin >> y.at(i);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  int Z,j=0;
  for(Z=X+1; Z<=Y; Z++){
    if( (x.at(N-1)<Z) && (Z<=y.at(0)) ){
      j++; break;
    }
  }
  if(j!=0){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int a, b;
	bool is_first = true;
	double area_t = 0;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> a >> b;
#else
	std::cin >> a >> b;
#endif

	area_t = a * b / 3.305785;

	printf("%.6lf\n", area_t);
 
#if INPUT_FROM_FILE
	//fclose(fp);
#endif
    return 0;
}


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

char s[25][25];
int v[25][25];
int h, w;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

void dfs(int y, int x, int k) {
    if (y < 0 || y >= h || x < 0 || x >= w) return;
    if (s[y][x] == '#') return;
    if (v[y][x] <= k) return;
    v[y][x] = k;
    rep(i, 4) dfs(y + dy[i], x + dx[i], k + 1);
}

int main() {
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> s[i][j];

    int ans = 0;
    rep(i, h) rep(j, w) {
        if (s[i][j] == '.') {
            memset(v, 0x40, sizeof(v));
            dfs(i, j, 0);
            rep(y, h) rep(x, w) {
                if (v[y][x] != v[24][24]) ans = max(ans, v[y][x]);
            }
        }
    }

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


Measured memory_bytes: 3644
# WA

N = int(input())
A = [int(_) for _ in input().split()]

dp = [1000]
K = [0]
C = [0]

for i in range(N):
    k, c = divmod(dp[-1], A[i])
    v = dp[-1]
    for j in range(i+1):
        u = K[j] * A[i] + C[j]
        v = max(u, v)
    K.append(k)
    C.append(c)
    dp.append(v)
print(dp[-1])


Measured memory_bytes: 9196
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

ll L;

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

void func(){

	if(L == 1){
		printf("1\n");
		return;
	}

	vector<ll> DIVISOR;

	for(ll i = 1; i <= sqrt(L); i++){
		if(L%i == 0){
			DIVISOR.push_back(i);
			if(i*i != L)DIVISOR.push_back(L/i);
		}
	}

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

	ll small,big,common;

	int ans = 0;

	for(int i = 0; i < DIVISOR.size(); i++){
		for(int k = i; k < DIVISOR.size(); k++){
			small = DIVISOR[i];
			big = DIVISOR[k];

			common = calc(big,small);

			small /= common;
			big /= common;

			if(small*big*common == L)ans++;
		}
	}

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

int main(){

	while(true){
		scanf("%lld",&L);
		if(L == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,x,y;
lol i[200001];
lol u[200001];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    lol c,d=0,e=0,f=0,g=1,h=0;
    cin >>a;
    for(int n=0;n<a;n++){
	cin >>i[n];
	u[n]=i[n];
	if(d<i[n]) e=1,d=i[n];
	else if(d==i[n]) e++;
    }
    sort(u,u+a,greater<lol>());
    if(e>=2) for(int n=0;n<a;n++) cout <<d<<'\n';
    else{
	for(int n=0;n<a;n++){
	    if(d==i[n]) cout <<u[1]<<'\n';
	    else cout <<d<<'\n';
	}
    }
    return (0);
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double h = x/(a*a);
  double pi = acos(-1);
  if(2*h-b>=0) {
    double p, q, r;
    p = a;
    q = 2*(b-h);
    r = sqrt(p*p+q*q);
    double ans = acos(p/r)/pi*(double)180;
    cout << fixed << setprecision(10) << ans << endl;
  }
  else {
    double p, q, r;
    p = 2*h*a/b;
    q = b;
    r = sqrt(p*p+q*q);
    double ans = acos(p/r)/pi*(double)180;
    cout << fixed << setprecision(10) << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello{
    public static int n;
    public static int m;
    public static int x;
    public static List<List<long>> a;
    public static List<long> c;
    public static void Main(){
        var input = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToList();
        n = input[0];
        m = input[1];
        x = input[2];

        c = new List<long>(n);
        a = new List<List<long>>(n);
        
        for(var i = 0; i < n; ++i){
            var row = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToList();
            c.Add(row[0]);
            var current = new List<long>(m);
            a.Add(current);
            for(var j = 0; j < m; ++j){
                current.Add(row[j + 1]);
            }
        }
        
        var skills = new List<long>(m);
        
        for(var i = 0; i < m; ++i){
            skills.Add(0);
        }
        
        var ret = loop(0, skills);
        
        System.Console.WriteLine(ret);
    }
    
    public static List<long> Lean(List<long> skills, List<long> book){
        var ret = new List<long>(m);
        for(var i = 0; i < m; ++i){
            ret.Add(skills[i] + book[i]);
        }
        return ret;
    }
    
    public static long loop(int current, List<long> skills){
        if(skills.All(y => x <= y)) return 0;
        if(n <= current) return -1;
        
        var ret1 = loop(current + 1, Lean(skills, a[current]));
        if(ret1 != -1) ret1 += c[current];
        var ret2 = loop(current + 1, skills);
        
        if(ret1 == -1){
            return ret2;
        } else if(ret2 == -1){
            return ret1;
        } else if(ret1 <= ret2){
            return ret1;
        } else {
            return ret2;
        }
    }
}


Measured memory_bytes: 29280
#include <stdio.h>

int main (void){

int a=0;
int b=0;

scanf("%d %d",&a,&b);

if(a < b){
printf("a < b\n");
}
else if(a > b){
printf("a > b\n");
}
else if(a = b){
printf("a == b\n");
}   
 return 0 ;
}

Measured memory_bytes: 2688
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

input=sys.stdin.readline
x=[int(input()) for _ in range(5)]
k=int(input())

if x[-1]-x[0]<=k:
  print("Yay!")
else:
  print(":(")

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

using namespace std;
#define intMax 2147483647
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repp(i, a, b) for (int i = a; i >= b; i--)
#define be(a) (a.begin(), a.end())
#define rbe(p) (p.rbegin(), p.rend())
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    long long ans = 0;
    rep(i,1,n){
        ans += i;
    }
    cout << ans;
}

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

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

// int A, B, F, H, I, J, K, L, M, N, S, T, U;
// long long int A, B, F, H, I, J, K, L, M, N, S, T, U;
string S, T, U;
int A, B;
int ans;

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

	cin >> S >> T >> A >> B >> U;

	if (S == U)
		A--;
	else if (T == U)
		B--;

	cout << A << " " << B << endl;
	return 0;
}

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

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

Measured memory_bytes: 256
/**akshaykumar99**/
 
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define pu push_back           
#define pp pop_back
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int MOD=1e9+7 ;
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+1;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> ivc;
typedef pair<ll,ll> ipr;

int longestRepeatedSubstring(string str) 
{ 
  int n = str.length(); 
  int LCSRe[n+1][n+1]; 
  memset(LCSRe, 0, sizeof(LCSRe)); 

  string res;
  int res_length = 0;
  int i, index = 0; 
  for (i=1; i<=n; i++) 
  { 
    for (int j=i+1; j<=n; j++) 
    { 

      if (str[i-1] == str[j-1] && 
        LCSRe[i-1][j-1] < (j - i)) 
      { 
        LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 
        if (LCSRe[i][j] > res_length) 
        { 
          res_length = LCSRe[i][j]; 
          index = max(i, index); 
        } 
      } 
      else
        LCSRe[i][j] = 0; 
    } 
  }
  if (res_length > 0) 
    for (i = index - res_length + 1; i <= index; i++) 
      res.push_back(str[i-1]); 

  return res.size(); 
} 
int32_t main() 
{ 

  long n;
  cin >> n;
  string str;
  cin >> str; 
  cout << longestRepeatedSubstring(str); 
  return 0; 
}

Measured memory_bytes: 97920
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;
  ll ans = 1;
  for (ll i = 1; i * i <= N; i++) {
    ans = i * i;
  }

  print(ans);

  return 0;
}


Measured memory_bytes: 256
H, W, k = map(int, input().split())
field = []
for i in range(H):
    s = list(input())
    field.append(s)
ans = 0

# bit全探索
for maskR in range((1 << H)):
    for maskC in range((1 << W)):
        # print(maskR,maskC)
        black = 0
        for i in range(H):
            for j in range(W):
                if ((maskR >> i) & 1 == 0) and (
                    (maskC >> j) & 1 == 0) and field[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1

print(ans)


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

using namespace std;
typedef long long ll;

int n;
int t[100005],a[100005],c[100005],d[100005],h[100005],H[100005];
ll e[100005];
const ll mod=1e9+7;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>n;

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

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

if(t[n-1]!=a[0]){
  cout<<0<<endl;
  return 0;
}

int m=t[0]; 
c[0]=1; h[0]=t[0];
for(int i=1; i<n; i++){
  if(t[i]>m){
    m=t[i];
    c[i]=1;
    h[i]=t[i];
  }
  else{
    c[i]=t[i];
    h[i]=-1;
  }
}

for(int i=0; i<n; i++){
  if(h[i]!=-1){
    if(h[i]>a[i]){
      cout<<0<<endl; return 0;
    }
  }
}

m=a[n-1];
d[n-1]=1; H[n-1]=t[n-1];
for(int i=n-2; i>=0; i--){
  if(a[i]>m){
    m=a[i];
    d[i]=1;
    H[i]=a[i];
  }
  else{
    d[i]=a[i];
    H[i]=-1;
  }
}

for(int i=0; i<n; i++){
  if(H[i]!=-1){
    if(H[i]>t[i]){
      cout<<0<<endl; return 0;
    }
  }
}

ll ans=1L;
for(int i=0; i<n; i++){
  e[i]=min(c[i],d[i]);
  ans=(ans*e[i])%mod;
}

cout<<ans<<endl;

}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++)
    cin >> d[i];
  int ans = 0;
  for (int i = 0; i < N - 1; i++)
  {
    for (int j = i + 1; j < N; j++)
    {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
}


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

using namespace std;

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

    int sum = (a+9)/10*10+(b+9)/10*10+(c+9)/10*10+(d+9)/10*10+(e+9)/10*10;

    int res = min({sum-((a+9)/10*10)+a,sum-((b+9)/10*10)+b,sum-((c+9)/10*10)+c,sum-((d+9)/10*10)+d,sum-((e+9)/10*10)+e});

    cout<<res;
}


Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
import itertools
import copy

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
s = [readInt() for i in range(n)]
s.sort()
ans = sum(s)
boo = 0
if ans%10==0:
	for i in s:
		if i%10!=0:
			ans-=i
			boo = 1
			break
	if boo==0:
		ans = 0

print(ans)

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

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vector<int>> A(N, vector<int>(N));
  rep(i, N) {
    rep(j, N) { cin >> A[i][j]; }
  }

  int64_t answer = 0;
  for (int i = 0; i < N - 1; ++i) {
    for (int j = i + 1; j < N; ++j) {
      bool flag = true;
      for (int k = 0; k < N; ++k) {
        if (k == i || k == j) continue;
        if (A[i][k] + A[k][j] == A[i][j])
          flag = false;
        else if (A[i][k] + A[k][j] < A[i][j]) {
          cout << "-1" << endl;
          return 0;
        }
      }
      if (flag) answer += A[i][j];
    }
  }
  cout << answer << endl;
  return 0;
}


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

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> D(n + 1);
    D[0] = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        D[i + 1] = D[i] + x;
    }
    int ans = 0;
    for(int i = 0; i <= n; i++){
        if(D[i] <= x){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; ++i) {
        string s;
        cin >> s;
        cout << s << endl
             << s << endl;
    }

    return 0;
}

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

int main(int argc, const char * argv[]) {
    int n=0;
    int s[1000];
    int sum;  //平均算出用
    double sn;   //平均
    double aa_sum;   //分散計算用
    double aa;   //分散
    double a;    //標準偏差
    
    while (1) {
        sum=0;
        aa=0;
        a=0;
        scanf("%d", &n);
        if (n==0) {
            break;
        }
        //得点入力
        for (int i=0; i<n; i++) {
            scanf("%d", &s[i]);
        }
        
        //平均を計算
        sn=0;        aa_sum=0;

        for (int i=0; i<n; i++) {
            sum+=s[i];
        }
        sn = sum / (n*1.0);
        
        //printf("平均は，%lf\n", sn);
        //分散を計算
        aa_sum=0;
        for (int i=0; i<n; i++) {
            aa_sum += ((s[i]*1.0)-sn)*((s[i]*1.0)-sn);
        }
        aa = aa_sum / (n*1.0);

        //printf("分散は，%lf / %d = %.8lf\n", aa_sum, n, aa);

        a = sqrt(aa);
        
        //printf("標準偏差は，%.8lf\n", a);
        printf("%.8lf\n", a);
        
    }
    
    return 0;
}


Measured memory_bytes: 2044
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String args[]) throws Exception{
    	BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    	int N= Integer.parseInt( br.readLine() );
    	ArrayList<Integer>  min= new ArrayList<Integer>();
    	//min.get(i): minimum amount that needs for i measurements
    	min.add(0);
    	min.add(2);
    	
    	int tmp_min= 2;
    	int size_worse;
    	for(int i=3;i<=N;i++){
    		if( i%3==0 ){
    			size_worse= i/3;
    		} else {
    			size_worse= i/3+1;
    		}		
    		if( size_worse >= tmp_min ){
    			min.add(i);
    			tmp_min= i;
    			i= 3*(i-1);
    		}
    	}
    	
		System.out.println( min.size()-1 );
    }
}

Measured memory_bytes: 18592
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  cin.ignore();
  while(n--) {
    string line;
    getline(cin,line);
    REP(i,line.length()-6) {
      if (line.substr(i,7) == "Hoshino")
        line.replace(i,7,"Hoshina");
    }
    cout << line << endl;
  }
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();

        int count = 0;
        for (int i = 0; i < str.length() / 2; i++) {
            if (str.charAt(i) != str.charAt(str.length() - i - 1)) count++;
        }

        System.out.println(count);
    }
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n), sum(n+1, 0);
	rep(i,n) cin >> a[i];
	sort(a.begin(), a.end());
	rep(i,n) sum[i+1] = sum[i] + a[i];
	ll ok = 0, ng = 1e6, cnt;
	while(ng - ok > 1){
		ll mid = (ok + ng) / 2;
		cnt = 0;
		rep(i,n){
			cnt += n - (lower_bound(a.begin(), a.end(), mid - a[i]) - a.begin()); 
		}
		if(cnt >= m) ok = mid;
		else ng = mid;
	}
	ll ans = 0;
	cnt = 0;
	rep(i,n){
		int it = lower_bound(a.begin(), a.end(), ok - a[i]) - a.begin();
		cnt += n - it;
		ans += (n - it) * a[i] + sum[n] - sum[it];
	}
	ans -= (cnt - m) * ok;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int n;
int c[55];
long long dp[55][55][2505];
int md;

long long solve(int pos, int k, int v) {
	if (pos == n) {
		if (v == 0 && k == 0) return 1ll;
		return 0ll;
	}
	if (k < 0 || v < 0) return 0;
	if (dp[pos][k][v] != -1) return dp[pos][k][v];                                 
	long long ans = solve(pos + 1, k - 1, v - c[pos]) + solve(pos + 1, k, v);
	return dp[pos][k][v] = ans;
}

int main() {
	int a;
	scanf("%d %d", &n, &a);
	for (int i = 0; i < n; i++) {
		scanf("%d", c + i);
	}
	long long ans = 0;
	memset(dp, -1, sizeof dp);
	for (int k = 1; k <= n; k++) {
		ans += solve(0, k, a * k);
	}
	printf("%lld\n", ans);  
	return 0;
}      

Measured memory_bytes: 59392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1);
    for (ll i = 1; i <= N; i++) {
        cin >> A[i];
    }
    vector<ll> S(N+1);
    S[0] = 0;
    for (ll i = 1; i <= N; i++) {
        S[i] = S[i-1] + A[i];
    }

    ll ans = INF;
    ll b1,b2,c1,c2,d1,d2,e1,e2;
    ll tmp, ind;
    for (ll k = 2; k < N-1; k++) {
        tmp = S[k] / 2 + 1;
        ind = lower_bound(S.begin() + 1, S.begin() + k, tmp) - S.begin();
        b1 = S[ind]; c1 = S[k] - S[ind];
        b2 = S[ind - 1]; c2 = S[k] - S[ind - 1];

        tmp = (S[N] - S[k]) / 2 + S[k] + 1;
        ind = lower_bound(S.begin() + k, S.end(), tmp) - S.begin();
        d1 = S[ind] - S[k]; e1 = S[N] - S[ind];
        d2 = S[ind - 1] - S[k]; e2 = S[N] - S[ind - 1];        

        tmp = max({b1,c1,d1,e1}) - min({b1,c1,d1,e1});
        ans = min(ans, tmp);
        tmp = max({b1,c1,d2,e2}) - min({b1,c1,d2,e2});
        ans = min(ans, tmp);
        tmp = max({b2,c2,d1,e1}) - min({b2,c2,d1,e1});
        ans = min(ans, tmp);
        tmp = max({b2,c2,d2,e2}) - min({b2,c2,d2,e2});
        ans = min(ans, tmp);    
    }
    printf("%lld\n", ans);


}


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

long long COM(long long n, long long k){
    return n*(n-1)/2;
}

int main(){
    long long n;
    cin >> n;
    vi a(n, 0);
    map<long long, long long> d;
    rep(i, n){
        cin >> a.at(i);
        d[a.at(i)]++;
    }
    long long sum = 0;
    for (auto p : d) {
      //auto k = p.first;
      auto v = p.second;
      if(v>=2)
      sum += COM(v, 2);
    }
    rep(i, n){
        long long ans = sum;
        if(d[a.at(i)]>2){
            long long tmp = COM(d[a.at(i)], 2);
            ans = ans - tmp + COM(d[a.at(i)]-1, 2);
        }
        if(d[a.at(i)] == 2){
            ans--;
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
  long long N;
  cin >> N;
  long long A[N];
  rep(i, N)
    cin >> A[i];
  //

  long long ans = 0;
  rep(i, N-1){
    if(A[i]>A[i+1]){
      long long step = A[i]-A[i+1];
      A[i+1] += step;
      ans += step;
    }
  }

  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 5092