akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
#define mx 100001
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define d double
void solve(){
	ll n;
	cin>>n;
	vl a(n);
	cin>>a;
	vl pre(n);
	pre[0]=a[0];
	rep(i,1,n) pre[i]=pre[i-1]+a[i];
	vvl dp(n,vl(n));
	for(int i=0;i<n;i++) dp[i][i]=a[i];
	for(int i=0;i<n-1;i++) dp[i][i+1]=max(a[i],a[i+1]);
	for(ll l=3;l<=n;l++){
		for(int i=0;i<=n-l;i++){
			ll left=pre[i+l-1]-pre[i];
			ll right;
			if(i==0) right=pre[i+l-2];
			else right=pre[i+l-2]-pre[i-1];
			dp[i][i+l-1]=max(a[i]+(left-dp[i+1][i+l-1]),a[i+l-1]+(right-dp[i][i+l-2]));
		}
	}
	ll t=0;
	rep(i,0,n) t+=a[i];
	cout<<2*dp[0][n-1]-t;
	
}
int32_t main(){
int t=1;
//cin>>t;
while(t--){
	solve();
}
 
}

Measured memory_bytes: 70784
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

    ll ans = 0;
    for(ll i=1; i<n; ++i){
        if(s[i]==s[i-1])ans++;
    }
    ll add = 2*k;
    // if(s.back()!=s.front())add--;
    ans = min(n-1, ans+add);
    cout << ans << endl;
}

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

int main() {
  int n, m; cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i,m) cin >> s[i] >> c[i], --s[i];
  string ans = "-1";
  rep(i,1000) {
    string si =  to_string(i);
    if ((int)si.size() != n) continue;
    bool flag = true;
    rep(j,m) {
      if (si[s[j]] != (char)(c[j] + '0')) flag = false;
    }
    if (flag) { ans = si; break; }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
void explore(vector<int>adj[],int visit[],int pos,int j)
{
    if(visit[pos]!=0&&visit[pos]!=j)
        return;
    visit[pos]=j;
    for(int i=0;i<(int)adj[pos].size();i++)
    {
        if(visit[adj[pos][i]]==0)
        {
            //cout<<adj[pos][i]<<" ";
            visit[adj[pos][i]]=j;
            explore(adj,visit,adj[pos][i],j);
        }
    }
}
int main()
{
    int n;
    cin>>n;
    vector<int>a[n+1];
    for(int i=1;i<=n;i++)
    {
        //a[i].push_back(i);
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    int *visit=new int[n+1];
    visit[0]=1;
    for(int i=1;i<=n;i++)
        visit[i]=0;
    for(int j=1;j<=n;j++)
    {
        explore(a,visit,j,j);
    }
    sort(visit,visit+n+1);
    int max=1;
    int c=1;
    for(int i=2;i<=n;i++)
    {

        if(visit[i]==visit[i-1])
            c++;
        else
        {
            if(max<c)
                max=c;
            c=1;
        }
    }
    if(max<c)
        max=c;
    cout<<max<<"\n";
}


Measured memory_bytes: 24668
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<vector<int> > > n(h+1, vector<vector<int> >(w+1, vector<int>(3, 0)));
    for(int y=1; y<=h; ++y){
        vector<int> row(3, 0);
        for(int x=1; x<=w; ++x){
            char c;
            cin >> c;

            if(c == 'J')
                ++ row[0];
            else if(c == 'O')
                ++ row[1];
            else
                ++ row[2];

            for(int i=0; i<3; ++i)
                n[y][x][i] = n[y-1][x][i] + row[i];
        }
    }

    while(--k >= 0){
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;

        for(int i=0; i<3; ++i){
            int ret = n[y2][x2][i] - n[y2][x1-1][i] - n[y1-1][x2][i] + n[y1-1][x1-1][i];
            cout << ret;
            if(i < 2)
                cout << ' ';
            else
                cout << endl;
        }
    }

    return 0;
}

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

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll X;
    cin >> X;
    ll m{0};
    for (auto &&i: irange(0LL, numeric_limits<ll>::max())){
        m = m + i;
        if (m >= X){
            cout << i << endl;
            return 0;
        }
    }


//    set<ll> s{0};
//    for (auto &&i: irange(0LL, 10LL)) {
//        cout << "i: " << i << endl;
//        set<ll> s_new = s;
//        for (auto &&j: s) {
//            s_new.insert(j - i);
//            s_new.insert(j + i);
//        }
//        for (auto &&j  : s_new) {
//            cout << j << " ";
//        }
//        cout << endl;
//        s = s_new;
//    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	ll a,b,n;
	cin>>a>>b>>n;
	ll x;
	if(n < b)
	{
		x = n;
	}
	else
	{
		x = b-1;
	}
	
	cout<<((a*x)/b - a*(x/b))<<endl;
	return 0;
}

Measured memory_bytes: 3604
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 101000
using namespace std;
inline void read(int &x)
{
	x=0;
	int p=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
int ans;
int n;
int a[N];
int main()
{
//	freopen("a.out","w",stdout);
	read(n);
	for(int i=1;i<=n;i++)
	{
		int x;
		read(x);
		a[x]++;a[x-1]++;a[x+1]++;
		ans=max(ans,a[x]);
		ans=max(ans,a[x+1]);
		ans=max(ans,a[x-1]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
from collections import deque
 
 
walk = [(1, 0), (-1, 0), (0, 1), (0, -1)]
warp = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),
        (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
        (0, -2), (0, -1), (0, 1), (0, 2),
        (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
        (2, -2), (2, -1), (2, 0), (2, 1), (2, 2),]
 
 
def get_warped(walked, map_):
    warped = deque()
    while walked:
        h, w = walked.popleft()
        for i, j in warp:
            h2 = h + i
            w2 = w + j
            if -1 < h2 < H and -1 < w2 < W and map_[h2][w2] == '.':
                warped.append((h2, w2))
                map_[h2][w2] = map_[h][w] + 1
    return warped, map_
 
 
def get_walked(candidate, map_):
    walked = deque()
    while candidate:
        h, w = candidate.popleft()
        walked.append((h, w))
        for i, j in walk:
            h2 = h + i
            w2 = w + j
            if -1 < h2 < H and -1 < w2 < W and map_[h2][w2] == '.':
                candidate.append((h2, w2))
                map_[h2][w2] = map_[h][w]
    return walked, map_
 
H, W = map(int, input().split())
s_h, s_w = [i-1 for i in map(int, input().split())]
d_h, d_w = [i-1 for i in map(int, input().split())]
map_ = [list(input()) for i in range(H)]
 
candidate = deque([(s_h, s_w)])
map_[s_h][s_w] = 0
 
while candidate:
    walked, map_ = get_walked(candidate, map_)
    candidate, map_ = get_warped(walked, map_)
 
for h in range(H):
    for w in range(W):
        if map_[h][w] == '.':
            map_[h][w] = -1
 
print(map_[d_h][d_w])

Measured memory_bytes: 155836
#include<bits/stdc++.h>
#define rep(i,n) for(i=1;i<=n;i++)
using namespace std;
double dis[30][30];
struct zz{double x1,x2,x3;}co[30];
int n,m;
double ans;
int bitcount(int n) 
{ 
    n = (n &0x55555555) + ((n >>1) &0x55555555) ; 
    n = (n &0x33333333) + ((n >>2) &0x33333333) ; 
    n = (n &0x0f0f0f0f) + ((n >>4) &0x0f0f0f0f) ; 
    n = (n &0x00ff00ff) + ((n >>8) &0x00ff00ff) ; 
    n = (n &0x0000ffff) + ((n >>16) &0x0000ffff) ; 

    return n ; 
}
void dfs(int pre,int comb)
{

	int sum=bitcount(comb);
//	printf("pre=%d comb=%d sum=%d\n",pre,comb,sum); 
	int i,j;
	double tot=0;
	if(sum == m)
	{
		rep(i,n)
			for(j=i+1;j<=n;j++)
				if((comb&(1<<(i-1))) &&(comb&(1<<(j-1))))
					tot+=dis[i][j];
		ans=max(ans,tot);
		return ;
	}
	for(i=pre+1;i<=n;i++)
		dfs(i,comb+(1<<(i-1)));
}
int main()
{
	scanf("%d%d",&n,&m);
	int i,j;
	rep(i,n)
	{
		double x1,x2,x3;
		cin>>x1>>x2>>x3;
		co[i].x1=x1;	co[i].x2=x2;	co[i].x3=x3;
	}
	rep(i,n)
		for(j=i+1;j<=n;j++)
			dis[i][j]=(co[i].x1-co[j].x1)*(co[i].x1-co[j].x1)+(co[i].x2-co[j].x2)*(co[i].x2-co[j].x2)+(co[i].x3-co[j].x3)*(co[i].x3-co[j].x3);
	dfs(0,0);
	printf("%.12f",ans);
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define long long long
using namespace std;
int vis[1000];
string s;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin>>s;
  for(auto x:s)vis[x-'a']=1;

  if(s.size()<=25)
  {
    cout<<s;
    for(int i=0;i<=25;i++)
    {
      if(vis[i]==0)
      {
        cout<<(char)(i+'a')<<endl;
        return 0;
      }
    }
  }
  for(int i=s.size()-1;i>=0;i--)
  {
    for(int j=s[i]-'a'+1;j<=25;j++)
    {
      if(vis[j]==0)
      {
        s[i]=j+'a';
        cout<<s<<endl;
        return 0;
      }
    }
    vis[s[i]-'a']=0;
    s.pop_back();
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

mt19937 rng(10);

#define int long long

#ifdef LOCAL
int n;
#endif

int query(int N) {
	#ifdef LOCAL
	assert(N <= 1e18);
	if (n <= N && to_string(n) <= to_string(N)) return 1;
	if (n > N && to_string(n) > to_string(N)) return 1;
	return 0;
	#else 
	cout << "? " << N << endl;
	char c;
	cin >> c;
	return c == 'Y';
	#endif	
}

int chpref(int N) {
	while (N <= 1e17) {
		N = 10 * N + 9;
	}
	return query(N);
}

void run() {
	int pr = 0;
	for (int j = 0; j < 20; j++) {
		if (j > 0 && chpref(10 * pr + 0)) {
			if (query(pr + 1) == chpref(pr + 1)) break;
		}
		int l = 0;
		if (j > 0) l = -1;
		int r = 9;
		while (r - l > 1) {
			int m = (r + l) / 2;
			if (!chpref(10 * pr + m)) l = m;
			else r = m;
		}
		pr = 10 * pr + r;
	}
	#ifdef LOCAL
	if (n != pr) {
		cerr << "WA: " << n << endl;
		cerr << pr << endl;
		exit(0);
	} else {
		cerr << "AC" << endl;
	}
	#else 
	cout << "! " << pr << endl;
	#endif
}

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

	#ifdef LOCAL
	while (true) {
		n = rng() % (int)(1e9) + 1;
		run();		
	}
	#else 
	run();
	#endif
}


Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

char board[12][6];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print() {
  int i,j;
  rep(i,12) {
    rep(j,6)
      cout<<board[i][j];
    cout<<endl;
  }
}

bool isok(int x,int y) {
  return (x >= 0 && x < 6 && y >= 0 && y < 12);
}

bool erase() {
  bool isb[12][6];
  int i,j,k,l;
  bool update = false;
  memset(isb, false, sizeof(isb));
  rep(i,12) {
    rep(j,6) {
      if(isb[i][j]) continue;
      isb[i][j] = true;
      if(board[i][j] == '.' || board[i][j] == 'O') continue;

      queue<pair<int,int> > Q;
      vector<pair<int,int> > vv;
      Q.push(make_pair(i,j)); vv.push_back(make_pair(i,j));
      while(!Q.empty()) {
	pair<int,int> p = Q.front(); Q.pop();
	int x = p.second,y = p.first;
	rep(k,4) {
	  if(isok(x+dx[k],y+dy[k]))
	    if(board[y+dy[k]][x+dx[k]] == board[y][x] && !isb[y+dy[k]][x+dx[k]]) {
	      Q.push(make_pair(y+dy[k],x+dx[k]));
	      isb[y+dy[k]][x+dx[k]] = true;
	      vv.push_back(make_pair(y+dy[k],x+dx[k]));
	    }
	}
      }

      if(vv.size() >= 4) {
	update = true;
	rep(k,vv.size()) {
	  int x = vv[k].second,y = vv[k].first;
	  rep(l,4) {
	    if(isok(x+dx[l],y+dy[l]))
	      if(board[y+dy[l]][x+dx[l]] == 'O')
		board[y+dy[l]][x+dx[l]] = '.';
	  }
	  board[vv[k].first][vv[k].second] = '.';
	}
      }
    }
  }

  return update;
}

void drop() {
  int i,j,k;
  for(i=11; i>=0; --i) {
    rep(j,6) {
      if(board[i][j] == '.') {
	k = i;
	while(k >= 0) {
	  if(!(board[k][j] == '.')) {
	    board[i][j] = board[k][j];
	    board[k][j] = '.';
	    break;
	  }
	  k--;
	}
      }
    }
  }
}

int solve() {
  bool update = false;
  int t = 0;
  while(true) {
    update = erase();
    if(!update) return t;
    t++;
    drop();
  }
}

void input() {
  int i,j;
  string s;
  rep(i,12) {
    cin>>s;
    rep(j,6)
      board[i][j] = s.at(j);
  }
  return;
}

int main() {
  int t;
  cin>>t;
  while(t--) {
    memset(board,0,sizeof(board));
    input();
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 0
N, = map(int, input().split())
X = list(map(int, input().split()))
r = 0
for d in range(1, N):
    s = 0
    vs = set([0, N-1])
    for ld in range(d, N-d, d):
        bld = N-ld-1
        vs.add(bld)
        if ld in vs:
            break
        vs.add(ld)
        s += X[ld] + X[bld]
        r = max(s, r)
print(r)


Measured memory_bytes: 87892
#include<stdio.h>
 
#define ll long long
 
int main()
{
  	unsigned ll n;
  	unsigned ll answer;
  
  	scanf("%llu",&n);
  	if(n==1)
      	answer=1;
  	else
      	answer=n*n*n;
  	printf("%llu",answer);
  return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

const int mod = 1000000007;

int main() {
    string N;
    cin >> N;
    int num = 0;
    for (auto n: N) num += n - '0';

    if (num % 9) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 3692
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    X=list(zip(A,B))
    X.sort(lambda x:x[1])

    C=[(x[0],i) for i,x in enumerate(X)]
    C.sort()
    perm=[C[i][1] for i in range(n)]

    A.sort()
    B.sort()

    # A <= B を満たしていなければ不可能
    if(any(A[i]>B[i] for i in range(n))):
        print("No")
        return

    # 自由度が1つあれば可能
    if(any(A[i+1]<=B[i] for i in range(n-1))):
        print("Yes")
        return

    # permのYoung図が[n]かどうかで判断
    p=0
    cnt=0
    while(True):
        cnt+=1
        p=perm[p]
        if(p==0): break
    print("Yes" if(cnt<n) else "No")
resolve()

Measured memory_bytes: 83616
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int N;cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  reverse(ALL(vec));
  int ANS = 0;
  for (int i = 0; i < N-1; i++)
  {
    if(vec[i+1] - vec[i] == -1)
    {
      ANS++;
    }
    else if(vec[i+1] == vec[i])
    {
      ANS += vec[i];
    }
    else
    {
      if(vec[i+1] > vec[i])
      {
        ANS += vec[i];
      } 
      else
      {
        cout<<-1<<endl;
        return;
      }
      
    }
    // DEBUG(ANS);
    
  }
  if(vec[N-1] != 0)
  {
    cout<<-1<<endl;
    return;
  }
  cout<<ANS<<endl;
  return;
  
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}


Measured memory_bytes: 1792
#ifdef __APPLE__
    # include <iostream>
    # include <cmath>
    # include <algorithm>
    # include <stdio.h>
    # include <cstdint>
    # include <cstring>
    # include <string>
    # include <cstdlib>
    # include <vector>
    # include <bitset>
    # include <map>
    # include <queue>
    # include <ctime>
    # include <stack>
    # include <set>
    # include <list>
    # include <random>
    # include <deque>
    # include <functional>
    # include <iomanip>
    # include <sstream>
    # include <fstream>
    # include <complex>
    # include <numeric>
    # include <immintrin.h>
    # include <cassert>
    # include <array>
    # include <tuple>
    # include <unordered_map>
    # include <unordered_set>
    # include <thread>
#else
    # include <bits/stdc++.h>
#endif

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const int max_n = -1, inf = 1000111222;

ll pref_sum(int a)
{
    return 1ll*a*1ll*(a+1)/2;
}

int main() {
//    freopen("barik.in", "r", stdin);
//    freopen("barik.out", "w", stdout);

    int n;
    cin>>n;
    ll ans=0;
    for (int i=1;i<=n;i++){
        ans+=pref_sum(n-i+1);
    }
    for (int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        if (u>v){
            swap(u,v);
        }
        ans-=1ll*u*1ll*(n-v+1);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3624
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] * (N + 1)
    for i in range(N):
        B[A[i]] = i

    uni = UnionFind(N)
    ans = 0
    for i in range(N, 0, -1):
        k = B[i]
        left = 0
        right = 0
        if k - 1 >= 0 and A[k-1] > A[k]:
            left = uni.size(uni.find(k-1))
            uni.union(k-1,k)
        if k + 1 <= N - 1 and A[k+1] > A[k]:
            right = uni.size(uni.find(k+1))
            uni.union(k+1,k)

        ans += (left+1) * (right+1) * A[k]

    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 141264
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#define ll long long
#define MAXN 100000
using namespace std;



int main() {
    int N;
    cin>>N;
    map<int,int> counts;
    for(int i=0;i<N;i++) {
        int x;
        cin>>x;
        counts[x]++;
    }
    
    
    int M;
    cin>>M;
    
    bool ok=true;
    for(int i=0;i<M;i++) {
        int x;
        cin>>x;
        if (counts[x] == 0) {
            ok=false;
            break;
        }
        counts[x]--;
    }
    
    if (ok)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    
}

Measured memory_bytes: 9600
def gcd(x, y):
    a = max([x, y])
    b = min([x, y])
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)


def lcm(x, y):
    return (x * y) // gcd(x, y)


N = int(input())
S = 1
for i in range(N):
    S = lcm(S, int(input()))

print(S)


Measured memory_bytes: 3060
N = int(input())

A = list(map(int,input().split()))


b = sorted(list(A))
dp = [0]*(max(A)+1)

m_a = max(A)+1
for i in b:
    dp[i] += 1
    if dp[i]==1 :
        for j in range(i*2, m_a,i):
            dp[j] +=100

print(dp.count(1))

Measured memory_bytes: 41196
#include<stdio.h>
int min(int a,int b){
  if(a<=b){
    return a;
  }
  else {
    return b;
  }
}


int main(){
  int N;
  scanf("%d",&N);
  int b[N-1];
  int a[N];
  
  for (int i=0;i<=N-1;i++){
    scanf("%d",&b[i]);
  }
  
  a[0]=b[0];
  
  for (int i=1;i<=N-2;i++){
    a[i]=min(b[i],b[i-1]);
  }
  
  a[N-1]=b[N-2];
  
  int ans=0;
  for (int i=0;i<N;i++){
    ans+=a[i];
  }
  
  printf("%d",ans);
  
  return 0;
}


Measured memory_bytes: 1732
from math import ceil
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ca = 0
cb = 0
for i, j in zip(a, b):
    if i < j:
        ca += ceil((j-i)/2)
    else:
        cb += i-j
n = sum(b)-sum(a)
print("Yes" if n >= cb and n >= ca else "No")


Measured memory_bytes: 41584
#include <iostream>
#include <cstdlib>
using namespace std;
int sx, sy, tx, ty;

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

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

    cin >> sx >> sy >> tx >> ty;
    int difx, dify;
    difx = abs(sx - tx);
    dify = abs(sy - ty);

    rep(i,difx) cout << "R";
    rep(i,dify) cout << "U";
    rep(i,difx) cout << "L";
    rep(i,dify) cout << "D";

    cout << "D";
    rep(i,difx+1) cout << "R";
    rep(i,dify+1) cout << "U";
    cout << "LU";
    rep(i,difx+1) cout << "L";
    rep(i,dify+1) cout << "D";
    cout << "R" << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
	if (n==0) return 1;
	long long res = mod_pow(x * x % MOD, n/2);
	if (n&1) res = res * x % MOD;
	return res;
}

ll calc(ll n, ll r) {
    long long X = 1, Y = 1;
    for (ll i=n; i>=n-r+1; i--) {
        X *= i;
        X %= MOD;
    }
    for (int i=1; i<=r; i++) {
        Y *= i;
        Y %= MOD;
    }
    Y = mod_pow(Y, MOD-2);
    return (X * Y) % MOD;
}

int main(void) {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = mod_pow(2, n) - 1;
    ans -= calc(n, a) + calc(n, b);

    ans %= MOD;
    if (ans<0) ans += MOD; 

    printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]a = new int[N*2];
   
    int ans = 0;
    for(int i=0; i<N*2; i++){
    a[i] = sc.nextInt();
    if(i%2!=0){
        ans += a[i]-a[i-1]+1;
    }
}
    	System.out.println(ans);
    }
}

Measured memory_bytes: 39468
import java.util.*;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long n = scan.nextInt();
        long k = scan.nextInt();
        long sum = 0;
        if(k == 0) {
            System.out.println(n*n);
            return;
        }
        for (int i = 1; i <= n; i++) {
            if (i <= k) {
                continue;
            }
            sum += (i - (k % i)) * (n / i);
            sum += Math.max(0, n % i - k + 1);
        }
        System.out.println(sum);
    }

}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li n;
li a[55];

int main() {
    cin >> n;
    rin{
        cin >> a[i];
    }
    li res = 0;
    sort(a, a + n);
    li cnt = 0;
    while (a[n - 1] >= n) {
        cnt++;
        li num = a[n - 1] / n;
        a[n - 1] -= n * num;
        res += num;
        rep(i, n - 1) {
            a[i] += num;
        }
        sort(a, a + n);
    }
    cout << res << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    cout << 2*n*3.141592 << endl;
    return 0;
}


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

taro = 0
hanako = 0
for _ in range(n):
	line = input().rstrip().split()

	if line[0] > line[1]: taro += 3
	elif line[0] < line[1]: hanako += 3
	else:
		taro += 1
		hanako += 1
print(taro, hanako)


Measured memory_bytes: 5596
n = int(input())
a = list(map(int,input().split()))

cnt = [0]*200010

b = []

for i in reversed(range(n)):

	num = i + 1
	if cnt[num]%2 != a[num-1]:
		b.append(num)
		j = 1
		while j*j <= (num):
			if num%j==0 :
				cnt[j] += 1
				if num//j != j:
					cnt[num//j]+=1
			j = j +1


print(len(b))
b.sort()

for i in b:
	print(str(i)+' ',end='')

print()

Measured memory_bytes: 96804
#include <iostream>

int main()
{
    std::string str;
    std::cin >> str;
    if ((str[0] == str[1]) && (str[1] == str[2])) std::cout << "Yes" << std::endl;
    else if ((str[1] == str[2]) && (str[2] == str[3])) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    return 0;
}


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

int main()
{
    ll X;
    cin >> X;

    for (ll i = 0; i < X; ++i)
    {
        if (100 * i <= X && X <= 105 * i)
        {
            cout << 1 << endl;
            return 0;
        }
    }

    cout << 0 << endl;
}


Measured memory_bytes: 3576
import java.util.*;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String str1 = sc.next();
    	String str2 = sc.next();
    	String str3 = sc.next();

    	System.out.println(str1.substring(0,1) + str2.substring(0,1) + str3.substring(0,1));
    }
}

Measured memory_bytes: 21844
#include        <map>
#include      <cmath>
#include      <queue>
#include     <string>
#include     <cstdio>
#include     <vector>
#include    <cstring>
#include   <iostream>
#include  <algorithm>
using namespace std;
#define ll long long
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 100000+5;
const ll mod = 1e9+7;

int head[maxn], to[maxn*2], nx[maxn*2], val[maxn*2], tot = 0;
int tmp[maxn], ans=0;
inline void add(int u,int v,int c){
    to[tot] = v;
    nx[tot] = head[u];
    val[tot] = c;
    head[u] = tot++;
}
void dfs(int u, int fa,int fa_c){
    int s = 1, cnt=0;
    for(int i=head[u];i!=-1;i=nx[i]){
        int v = to[i];
        if(v == fa)continue;
        if(fa_c==s)s++;
        tmp[val[i]] = s;
        dfs(v,u,s);

        cnt ++;
        s++;
    }
    ans = max(ans,cnt+(fa!=-1));
}
int main(){
    int n;
    int u , v;
    memset(head,-1,sizeof(head));
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        scanf("%d%d",&u,&v);
        add(u,v,i);add(v,u,i);
    }
    dfs(1,-1,0);
    printf("%d\n",ans);
    for(int i=1;i<n;i++)
        printf("%d\n",tmp[i]);
    return 0;
}


Measured memory_bytes: 6912
// N <= 10^5 なのに再帰DFSで通る理由
// https://twitter.com/maspy_stars/status/1256955111273717760
// https://twitter.com/_phocom/status/1257107130286370816
// 「それぞれの状況に対して、二手先まで読めば最適な解が得られ、各操作で二回の選択肢しかないので、
// DFSで巻き戻ることがあっても一回しか巻き戻らず、また巻き戻った先の別の選択肢を選べばさらに深く探索していける」
// maspyさん、https://twitter.com/maspy_stars/ phocomさん https://twitter.com/_phocom 有難うございます。
// けんしんさんのツイート参考https://twitter.com/knshnb/status/1256952059061927936?s=20
#include <bits/stdc++.h>

int main() {
    long long N, A, B, C;
    std::cin >> N >> A >> B >> C;
    std::vector<std::string> s(N);
    for(int i = 0; i < N; ++i) {
        std::cin >> s[i];
    }
    std::vector<char> ans;
    std::vector<long long> rem = {A, B, C};
    auto dfs = [&](auto f, long long idx) -> void {
        if(idx == N) {
            std::cout << "Yes" << std::endl;
            for(char c : ans) std::cout << c << "\n";
            exit(0);
        }
        long long x = s[idx][0] - 'A', y = s[idx][1] - 'A';
        for(int _ = 0; _ < 2; ++_) {
            if(rem[x] > 0) {
                ans.push_back('A' + y);
                rem[x]--, rem[y]++;
                f(f, idx + 1);
                rem[x]++, rem[y]--;
                ans.pop_back();
            }
            std::swap(x, y);
        }
    };
    dfs(dfs, 0);
    std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 19488
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		long count = 0;
		for (int b = K + 1; b <= N; b++) {
			
			if (N%b == 0) {
				count += (N/b) * (b - K);
			} else {
				int step = (N-1)/b;
				count += step * (b - K);
				int lim = N - step * b;
				if (K == 0) {
					count += lim;
				} else {
					count += Math.max(0, lim - K + 1);
				}
			}
			// System.out.println("b = " + b + ", count = " + count);
		}
		System.out.println(count);
	}
}


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

void solve(long long N, vector<long long> L){
	long long sum = 0, maxl= 0;
	for (int i = 0; i < N; i++) {
		sum += L[i];
		maxl = max(maxl,L[i]);
	}
	if (maxl < sum - maxl) printf("Yes\n"); else printf("No\n");

}

int main(){
	long long N;
	scanf("%lld",&N);
	vector<long long> L(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&L[i]);
	}
	solve(N, L);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(isHarshad(n) ? "Yes" : "No");
    }

    private static boolean isHarshad(int n) {
        char[] c = String.valueOf(n).toCharArray();
        int sum = 0;
        for (int i = 0; i < c.length; i++) {
            sum += Integer.valueOf(String.valueOf(c[i]));
        }
        return n % sum == 0;
    }
}


Measured memory_bytes: 24276
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

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

	int ans = min(b, d) - max(a, c);
	if (ans < 0)cout << 0 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N,Q=map(int,input().split())
alist=list(map(int,input().split()))

#A1～Aiまでの和 O(logN)
def BIT_query(idx):
  res_sum = 0
  while idx > 0:
    res_sum += BIT[idx]
    idx -= idx&(-idx)
  return res_sum
#Ai += x O(logN)
def BIT_update(idx,x):
  while idx <= N:
    BIT[idx] += x
    idx += idx&(-idx)
  return

BIT=[0]*(N+1)
for i in range(N):
  BIT_update(i+1,alist[i])

for _ in range(Q):
  q1,q2,q3=map(int,input().split())
  if q1==0:
    BIT_update(q2+1,q3)
  else:
    print(BIT_query(q3)-BIT_query(q2))

Measured memory_bytes: 132528
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
set <int> st;
int N,ans=0;
vi L(205);

int main(int argc,char const* argv[])
{
  cin >> N;
  for(int i=0;i<2*N;i++)
    {
      cin >> L[i];
    }
  sort(L.begin(),L.end(),greater<int>());
  for(int i=0;i<2*N-1;i+=2)
    {
      if(L[i]>L[i+1]) ans+=L[i+1];
      else ans+=L[i];
    }
  cout << ans << endl;
  return 0;
}


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

int main() {
    char c;
    cin >> c;
    if((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u')){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <set>

using namespace std;

//bool passed[1<<25];
set<int> passed;

int field[10][10];

int main(){
	int n;
	while(cin>>n&&n){
		int ss=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>field[i][j];
				if(field[i][j])ss|=(1<<(i*n+j));
			}
		}
		passed.clear();
		//memset(passed,0,sizeof(passed));
		queue<int> q[2];
		int cur=0;
		int nxt=1;
		q[cur].push(ss);
		int cnt=0;
		//passed[ss]=true;
		passed.insert(ss);
		bool fin=false;
		while(q[cur].size()){
			while(q[cur].size()){
				int cs=q[cur].front();
				if(cs==0){
					fin=true;
					break;
				}
				q[cur].pop();
				// csÌóÔ©çÚ®Å«éóÔðñ
				int minx,miny;
				minx=miny=-1;
				for(int i=0;i<n;i++){
					for(int j=0;j<n;j++){
						if((cs>>(i*n+j))&1){
							minx=j;
							miny=i;
							break;
						}
					}
					if(minx!=-1)break;
				}
				// EºÌÀWðè
				for(int i=miny;i<n;i++){
					for(int j=minx;j<n;j++){
						// ½]
						int ns=cs;
						for(int k=miny;k<=i;k++){
							for(int l=minx;l<=j;l++){
								if((ns>>(k*n+l))&1)ns&=~(1<<(k*n+l));
								else ns|=(1<<(k*n+l));
							}
						}
						if(passed.find(ns)==passed.end()){
							q[nxt].push(ns);
							//passed[ns]=true;
							passed.insert(ns);
						}
					}
				}
			}
			if(fin)break;
			cnt++;
			swap(cur,nxt);
		}
		for(int i=0;i<cnt;i++)cout<<"myon";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 6872
def OuterProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.imag

def Area(dots):
	res = 0
	for i in range(len(dots)-1):
		res += OuterProduct(dots[i], dots[i+1])
	res += OuterProduct(dots[-1], dots[0])
	return res/2

d = [list(map(int, input().split())) for _ in range(3)]
x = complex(d[0][0], d[0][1])
y = complex(d[1][0], d[1][1])
z = complex(d[2][0], d[2][1])
s = abs(Area([x, y, z]))
a, b, c = abs(x-y), abs(y-z), abs(z-x)
print(2*s/(a+b+c+(4*s/max(a, b, c))))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define pb push_back
using namespace std;

void solve(int test){
	int n,x,t;
	cin>>n>>x>>t;
	cout<<t * ((n + (x - 1))/ x);
}
  
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1,k;
	//cin>>t;
	k = t;
	while(t--){
		solve(k - t);
	}
	cerr<<"Timpe elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " mps\n" ;
	return 0;
}

Measured memory_bytes: 3800
#include<iostream>
#include<iomanip>
using namespace std;

int main(){
  int n;
  double sum=0.0,A;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>A;
    sum+=1.0/A;
  }
  sum=1.0/sum;
  cout<<setprecision(16)<<sum<<endl;
  return 0;
}

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

int main(){
    string S; cin >> S;
    int Q; cin >> Q;
    bool flag=false;
    string C, D;
    for(int i=0; i<Q; i++){
        int T; cin >> T;
        if(T == 1){
            flag=!flag;
        }
        else{
            int F; cin >> F;
            string ch; cin >> ch;
            if((F==1 && !flag) || (F==2 && flag)) C+=ch;
            else D+=ch;
        }
    }
    reverse(C.begin(), C.end());
    S=C+S+D;
    if(flag) reverse(S.begin(), S.end());
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 1348
$sandpool = []
$check_points = []
$wave_count = 0
$break_points = []

def breakable?(castle)
    1 <= castle && castle < 9
end

def search_around(px, py)
    ((px - 1)..(px + 1)).each do |x|
        ((py - 1)..(py + 1)).each do |y|
            next if x == px && y == py
            yield(x, y)
        end
    end
end

def check_break_points
    $check_points.each do |i, j|
        castle = $sandpool[i][j]
        search_around(i, j) do |pi, pj|
            break if castle == 0
            castle -= 1 if $sandpool[pi][pj] == 0
        end
        $break_points << [i, j] if castle == 0
    end
end

def break_castles
    $break_points.each do |i, j|
        $sandpool[i][j] = 0
    end
end

def setup_next_check_points
    $check_points = []
    $break_points.each do |i, j|
        search_around(i, j) do |pi, pj|
            castle = $sandpool[pi][pj]
            $check_points << [pi, pj] if breakable?(castle)
        end
    end
    $check_points.uniq!
end

def broken?
    bool = $break_points.length > 0
    $break_points = []
    $wave_count += 1 if bool
    bool
end

def wave
    check_break_points
    break_castles
    setup_next_check_points
    broken?
end

#initialize
row, column = gets.split(" ").map(&:to_i)
row.times do
    ar = []
    gets.chomp.each_char do |char|
        ar << (char == "." ? 0 : char.to_i)
    end
    $sandpool << ar
end
(1..(row - 2)).each do |i|
    (1..(column - 2)).each do |j|
        castle = $sandpool[i][j]
        $check_points << [i, j] if breakable?(castle)
    end
end
#count
is_broken = true
while is_broken
    
    is_broken = wave
end
#output
puts $wave_count



Measured memory_bytes: 104864
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed parsing")
}

fn main() {

    #[allow(non_snake_case)]
    let N: u32 = read();
    let mut x: i32 = read();
    let mut result: u8 = 0;

    let mut vec = Vec::new();

    for i in 0..N {
        let a: i32 = read();
        vec.push(a);
    }
    vec.sort();
    vec.reverse();

    for i in 0..N {

        let a = vec.pop().expect("error");

        if x < a {

            continue;
        }
        if i == N - 1 && x > a {

            break;
        }
        if x - a >= 0 {

            x -= a;
            result += 1;
            if x == 0 {

                break;
            }
        }
    }

    println!("{}", result);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    ll a,b,k;
    cin >> a >> b >> k;
    if(a >= k) {cout << a - k <<' ' << b; return 0;}
    k -=a;
    cout << 0 << ' ' <<(b - k < 0? 0 : b - k);
    return 0;
    }



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

ll bai(ll A,ll B,ll w) {
  return 1+(B/w)-((A+w-1)/w);
}

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

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

using namespace std;
typedef long long ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }


const int q = 1e9+9;



int main()
{
    int n,ans=0;
    cin>>n;
    for(int i=105;i<=n;i+=2){
        int co=0;
        for(int j=1;j<=i;j++){
            if(i%j==0) co++;
        }
        if(co==8) ans++;
    }

    cout<<ans<<endl;

    return 0;
}
// gotcha;


Measured memory_bytes: 256