akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <functional>
#include <algorithm>
#include <cmath>
#include <stdlib.h>
using namespace std;
int n,num1[8],m,M;

int henkan()
{
  int num = 0;
  for(int i = 0;i < 8 ;i++){
    num+=num1[i]*pow(10,7-i);
  }
  return num;
}


int main(){

  char num;
  cin >> n;
  for(int i = 0; i < n ; i++ ){
    m = M = 0;
    for(int j = 0;j < 8 ;j++ )
      {
	cin >> num;
	num1[j] =  num-'0';
      }
    sort(num1,num1+8);
    m =  henkan();

    sort(num1,num1+8,greater<int>());
    M = henkan();

    cout << M - m << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
	ll n,m;
cin>>n>>m;
if(m&1)
{
	if(m!=1){
	ll row=(m+1)/2;
	ll ans=row*((n+1)/2)+(row-1)*(n/2);
	cout<<ans;
}
else
cout<<1;
}
else
{
	if(n!=1){
	ll row=(m+1)/2;
	ll ans=row*n;
	cout<<ans;
}
else
cout<<1;
}
}
int main()
{
//code

fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := scanner.Text()
	n := len(s)

	var count int
	for i := 0; i < n/2; i++ {
		if s[i] != s[n-i-1] {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
n, m = list(map(int, input().split()))

import numpy as np
dists = np.ones((n + 1, n + 1)) * (10 ** 6)
edges = []
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    dists[a, b] = dists[b, a] = c
    edges.append((a, b, c))
for i in range(1, n + 1):
    dists[i, i] = 0
for i in range(1, 1 + n):
    dists = np.minimum(dists, dists[i: i + 1] + dists[:, i: i + 1])
cnt = 0
for a, b, c in edges:
    if dists[a, b] < c:
        cnt += 1

print(cnt)


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

#define deb(x) cout << #x << "=" << x << endl
#define ll long long

const int mod = 1000000007;
const int N = 3e5, M = N;

void solve() {
	ll a, b, n, W;
	ll input;
	cin >> n >> W;
	vector<ll> wt(n);
	vector<ll> val(n);
	for (int i = 0; i < n; i++)
	{
		cin >> wt[i] >> val[i];
	}
	// cout << endl;
	ll dp[n + 1][W + 1];
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= W; j++)
		{
			if (i == 0 || j == 0)
				dp[i][j] = 0;
			else if (wt[i - 1] > j)
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
		}
	}

	cout << dp[n][W] << endl;














}



int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}



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

using namespace std;
long long dp[305][305][305],l,r,x,n,m,mod;
vector<pair<int,int> > a[305];
long long dq(int i,int v1,int v2,int v3)
{
    bool kt=true;
    int l,mau;
    for (int j=0;j<a[i-1].size();++j)
    {
        l=a[i-1][j].first;
        mau=a[i-1][j].second;
        if (v1>=l) mau--;
        if (v2>=l) mau--;
        if (v3>=l) mau--;
        if (mau!=0) {kt=false;break;}
    }
    if (!kt) return 0;
    if (i>n) return 1;
    if (dp[v1][v2][v3]!=-1) return dp[v1][v2][v3];
    long long k=(dq(i+1,i,v2,v3)+dq(i+1,v1,i,v3)+dq(i+1,v1,v2,i))%mod;
    return dp[v1][v2][v3]=k;

}
int main()
{

  
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;mod=1000000007;
    for (int i=1;i<=m;++i)
    {
        cin>>l>>r>>x;
        a[r].push_back({l,x});
    }
    memset(dp,-1,sizeof(dp));
    cout<<dq(1,0,0,0);

    return 0;
}


Measured memory_bytes: 221952
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
    string S;
    cin>>S;
    S[5]=' ';
    S[13]=' ';

    cout<<S<<endl;

    return 0;
}


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

int main(){
	string s;
	cin >> s;
	int len = s.size();
	if(s[0] != 'A'){
		cout << "WA" << endl;
		return 0;
	}
	int ccnt = 0;
	int cind;
	for(int i = 2;i <= len-2;i++){
		if(s[i] == 'C'){
			ccnt++;
			cind = i;
		}
	}
	if(ccnt != 1){
		cout << "WA" << endl;
		return 0;
	}
	for(int i = 1;i < len;i++){
		if(i == cind) continue;
		if(isupper(s[i])){
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << "AC" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define all(t) (t).begin(),(t).end()
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int dist[11][11];

void warshall_floyed(){
	
	for (int i = 0; i <= 9; i++)
    	for (int j = 0; j <= 9; j++)
      		for (int k = 0; k <= 9; k++)
        		dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}

int main(){
	int h,w;
	cin >> h >> w;
	FOR(i,10){
		FOR(j,10){
			cin >> dist[i][j];
		}
	}
	warshall_floyed();
	int a,ans=0;
	FOR(i,h){
		FOR(j,w){
			cin >> a;
			if(a==-1)continue;
			ans+=dist[a][1];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace B
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var an = Console.ReadLine().Split().Select(int.Parse).ToList();
			an.Sort();
			an.Reverse();
			var alice = 0;
			var bob = 0;
			for (var i = 0; i < n; i++)
			{
				if (i % 2 == 0) { alice += an[i]; }
				else { bob += an[i]; }
			}

			Console.WriteLine(alice - bob);
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll r = n / i;
    ans += (r * (r + 1) / 2) * i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
n = int(input())
vals = list(map(int, input().split()))
d= {}
a = [0, 0]

for i in range(n):
    if(vals[i] in d.keys()):
        d[vals[i]] += 1
    else:
        d[vals[i]] = 1


for i in d.keys():
    if(d[i] >= 4):
        a.append(i)
        a.append(i)
    elif(d[i] >= 2):
        a.append(i)
a.sort()

print(a[-1]*a[-2])

Measured memory_bytes: 18316
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii> 
using vec = vector<T>;

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

const int MAX = 1e6;

vec<> adj;
priority_queue<int> q;
vii res;
void dfs(int curr = 0, int prev = -1) {
    res[curr] = q.top();
    q.pop();
    for (int node : adj[curr]) {
        if (node == prev) {
            continue;
        }
        dfs(node, curr);
    }
}

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);
    
    int n;
    cin >> n;
    adj.resize(n);
    res.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        q.push(x);
        ans += x;
    }
    ans -= q.top();
    dfs();
    cout << ans << '\n';
    for (int e : res) {
        cout << e << ' ';
    }
    cout << '\n';
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

ll gcd(ll x, ll y) {
    if(x < y) swap(x, y);

    while(y > 0) {
        ll temp = x % y;
        x = y;
        y = temp;
        if(x < y) swap(x, y);
    }
    return x;
}

ll n, d, x;

int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>x;
        d = gcd(d, x);
    }
    cout<<d<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int a[26];

int main(){
    
    // 1. 入力情報.
    char c[1010];
    scanf("%s", c);
    int l = strlen(c);
    
    // 2. 出現回数をカウント.
    rep(i, l) a[c[i] - 'a']++;
    
    // 3. 判定.
    bool ans = true;
    rep(i, 26) if(a[i] & 1) ans = false;
    
    // 4. 出力.
    printf("%s\n", ans ? "Yes" : "No");
    return 0;
    
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    int x = 1;
    for(int i = m;i > 0;i--)
    {
        x *= 2;
    }
    cout << (1900 * m + 100 * (n - m)) * x;
    return 0;
}

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

#define sqr(x) ((x) * (x))

struct edge { int u, v; double cost; };
const int MAXN = 10000 + 16;
const int MAXM = MAXN << 3;

int N, M, x[MAXN], y[MAXN];
edge es[MAXM];

int p[MAXN];
void init_union_find(int N) {
    for (int i = 0; i <= N; i++) {
        p[i] = i;
    }
}
int find(int i) {
    if (p[i] != i) p[i] = find(p[i]);
    return p[i];
}
int unite(int i, int j) {
    p[find(i)] = p[find(j)];
}

bool cmp(const edge & e1, const edge & e2) {
    return e1.cost < e2.cost;
}

int main() {
    //freopen("2224-in29.txt", "r", stdin);
    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        cin >> x[i] >> y[i];
    }
    edge e;
    for (int i = 0; i < M; i++) {
        cin >> e.u >> e.v;
        e.cost = sqrt(sqr(x[e.u]-x[e.v]) + sqr(y[e.u]-y[e.v]));
        es[i] = e;
    }
    init_union_find(N);
    sort(es, es + M, cmp);
    double result = 0;
    for (int i = M - 1; i >= 0; i--) { // descending
        int u = es[i].u, v = es[i].v;
        if (find(u) != find(v)) {
            unite(u, v);
        } else {
            result += es[i].cost;
        }
    }
    cout << fixed << setprecision(4) << result << "\n";
}

Measured memory_bytes: 3800
#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 dp[5005][5005];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s;
	cin >> n >> s;
	for(int i = n-1; i >= 0; --i){
		for(int j = n-1; j >= 0; --j){
			if(s[i] == s[j]) dp[i][j] = dp[i+1][j+1] + 1;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; ++i){
		for(int j = i+1; j < n; ++j){
			int cmp = min(dp[i][j], j - i);
			chmax(ans, cmp);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 98048
n=int(input())
ppl=(input().split())
answer=0
if n==1:
    print(0)
for x in range(0,n-1):
    ppl[x]=int(ppl[x])
    ppl[x+1]=int(ppl[x+1])
    if ppl[x]>ppl[x+1]:
        answer+=ppl[x]-ppl[x+1]
        ppl[x+1]=ppl[x]
if(n!=1):
    print(answer)

Measured memory_bytes: 25220
s=input()
rev = s[::-1]
n = len(s)
s1 = s[:int((n-1)/2)]
rev1 = s1[::-1]
s2 = s[int(((n+3)/2)-1):]
rev2 = s2[::-1]
if s == rev and s1 == rev1 and s2 == rev2:
	print("Yes")
else:
    print("No")
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  int a[n+1];
  rep(i,0,n) cin>>a[i+1];
  int m=0;
  int b[n+1];
  rep(i,0,n+1) b[i]=0;
  bool ok=true;
  for(int i=n;i>=1;i--){
                int cnt=0;//iの倍数のはこに何個入っているか mod2
                int s=i;
                
    
                while(s+i<=n){
                          s+=(i);
                          if(b[s]==1){
                            cnt+=1;
                            cnt%=2;
                           // cout<<s<<a[i]<<cnt<<endl;
                          }
                }   
               if(a[i]!=cnt){
                           m++;
                           b[i]=1;
               }
  }
  if(ok){
  cout<<m<<endl;
  rep(i,1,n+1){
    if(b[i]==1)
   cout<<i<<" "; 
  }
    cout<<endl;
  }
  else cout<<-1<<endl;
}



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

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    double n;
    int ans;
    double num;
    cin >> n;

    num = n / 1.08;
    ans = num;

    int flag = 1;
    if (ans * 1.08 != n) {
        for (int i = ans + 1; i < ans + 10; i++) {
            int money = i * 1.08;
            if (money == n) {
                ans = i;
                flag = 0;
                break;
            }
        }
        if (flag == 1) {
            cout << ":(" << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int n;cin >>n;
    Vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    V cnt(1001001,0);
    for (int i = 0; i < n; ++i) {
        ll c=a[i];
        for (ll j =2; j*j<=c; ++j) {
            if(c%j==0) {
                cnt[j]++;
                while (c% j == 0) {
                    c/=j;
                }
            }
        }
        if(c!=1)cnt[c]++;
    }
    bool flg=true;
    for (int i = 0; i <=1000000; ++i) {
        if(cnt[i]>=2){
            flg=false;
        }
    }
    if(flg)puts("pairwise coprime");
    else {
        ll g=0;
        for (int i = 0; i < n; ++i) {
            g=__gcd(g,a[i]);
        }
        if(g==1){
            puts("setwise coprime");
        }
        else {
            puts("not coprime");
        }
    }
}


Measured memory_bytes: 14808
#include <stdio.h>
 
int main(){
    int h, w, i, j;
    while (1){
        scanf("%d %d", &h, &w);
        if (h == 0 && w == 0){
            return 0;
        }
        for (i = 0; i < h; i++){
            for (j = 0; j < w; j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//ceil(a/(double)b)=(a+b-1)/b
//printf("myco\n");//for debug
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    V p(n);
    rep(i,n)cin>>p[i];
    bool ok=false;
    bool okk=true;
    rep(k,n-1){
        if(p[k]>p[k+1])okk=false;
    }
    if(okk)ok=true;
    else{
    rep(i,n-1){
        bool good=false;
        for(int j=i+1;j<n;j++){
            bool flag=true;
            int tmp=p[i];
            p[i]=p[j];
            p[j]=tmp;
            //printf("%d %d//",p[i],p[j]);
            //判定
            rep(k,n-1){
                //printf("%d ",p[k]);
                if(p[k]>p[k+1])flag=false;
            }
            //printf("f=%d\n",flag);
            //復元
            p[j]=p[i];
            p[i]=tmp;
            if(flag)good=true;
        }
        if(good){
            ok=true;
            break;
        }
    }
    }
    cout<<(ok?"YES":"NO")<<endl;
}


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

int main() {
	int n; scanf("%d",&n);
	vector<int> v(n);
	for(int i = 0 ; i < n; i++) scanf("%d",&v[i]);
	
	const int nax = 1e9 + 90;
	vector<int> dp(n,nax);
	dp[0] = 0;
	
	for(int i = 0 ; i < n; i++){
		for(int x : {i+1,i+2} ){
			if(x < n )
			dp[x] = min( abs(v[i]-v[x]) + dp[i] , dp[x] );
		}
	}
	printf("%d\n",dp[n-1]);
	return 0;
}


Measured memory_bytes: 1024
/*
 * template.cpp
 *
 *  Created on: 2016/10/30
 *      Author: jin
 */
#define MYDEBUG
#include <iostream>
#include <vector>
#include <cstring>

#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif
#define LL long long
#define ULL unsigned long long
#define eps 1e-14
using std::max;
using std::min;
using std::swap;
using std::cout;
using std::cin;
using std::ostream;
using std::vector;
using std::endl;
using std::string;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}

class Main {
public:
  void sample() {
    cout << "-------------this is sample program.----------------" << endl;
  }
  void ABC047_A(){
	  int a,b,c;
	  cin >> a >> b >> c;
	  if(a==(b+c)) printf("Yes");
	  else if(b==(c+a)) printf("Yes");
	  else if(c==(a+b)) printf("Yes");
	  else printf("No");
  }
  
  void ABC047_B(){
	  int W,H,N;
	  cin >> W >> H >> N;
	  vector<vector<int> > rect();
	  
	  for(int i=0; i<N; ++i){
		  
	  }
  }
  
  void ABC044_A(){
	  int n,k,x,y;
	  cin >> n >> k >> x >> y;
	  int ans;
	  if(n<=k){
		ans = n*x;
	  }else{
		ans = k*x + (n-k)*y;
	  }
	  cout << ans << endl;
  }
  
  void ABC044_B(){
	  string str;
	  cin >> str;
	  vector<int> v(26);
	  std::fill(v.begin(),v.end(),0);
	  for(int i=0; i<str.length(); ++i){
		  v[str[i]-97]++;
	  }
	  for(int i=0; i<v.size(); ++i){
		  if(v[i]%2!=0){
			  cout << "No" << endl;
			  return;
		  }
	  }
	  cout << "Yes" << endl;
  }
  
};

int main() {
	Main m;
	m.ABC044_B();
}


Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

N,W = MI()
WV = LI(N)

ls_w = mycol(WV,0)
ls_w = list(set(ls_w))
ls_w.sort()
if len(ls_w)==3:
    ls_w = [0] + ls_w
elif len(ls_w)==2:
    ls_w = [0,0] + ls_w
elif len(ls_w)==1:
    ls_w = [0,0,0] + ls_w
else:
    pass
# print(ls_w)

a = []
b = []
c = []
d = []
for i in range(N):
    w = WV[i][0]
    v = WV[i][1]
    ind = ls_w.index(w)
    if ind==0:
        a.append(v)
    elif ind==1:
        b.append(v)
    elif ind==2:
        c.append(v)
    elif ind==3:
        d.append(v)
    else:
        print("E")
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d.sort(reverse=True)
# print("---")
# print(a)
# print(b)
# print(c)
# print(d)
# print("---")

M = -1*INF

for i in range(len(a)+1):
    for j in range(len(b)+1):
        for k in range(len(c)+1):
            for l in range(len(d)+1):
                w = i*ls_w[0] + j*ls_w[1] + k*ls_w[2] + l*ls_w[3]
                if w>W:
                    pass
                else:
                    v = sum(a[:i]) + sum(b[:j]) + sum(c[:k]) + sum(d[:l])
                    M = max(M,v)
print(M)

Measured memory_bytes: 58200
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int>q(n+1,0);
    int ans = 0;
    f(i,1,n+1){
    	cin >> q[i];
    	if(i&1){
    		ans += (q[i]%2);
    	}
    }
    cout << ans;
    return 0;
}
 

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int N,K;

int main() {
  cin>>N>>K;
  vector<int> Hs(N);
  for(int i=0;i<N;i++){cin>>Hs.at(i);}
  sort(Hs.begin(),Hs.end());
  int min_d=Hs.at(N-1)-Hs.at(0);
  for(int i=0;i<N-(K-1);i++){
    int d=abs(Hs.at(i)-Hs.at(i+(K-1)));
    min_d=min(d,min_d);
  }
  cout<<min_d<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int x[100],y[110];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)   cin>>x[i]>>y[i];
    double ans=0;
    for(int i=1;i<=n-1;i++){
        for(int j=i+1;j<=n;j++){
            ans+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
        }
    }
    printf("%.10lf\n",2*ans/n);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]

No1 = 0
No2 = 0
for i in range(N):
    if A[i] > No1:
        No2 = No1
        No1 = A[i]
    elif A[i] > No2:
        No2 = A[i]

for i in range(N):
    if A[i] == No1:
        print(No2)
    else:
        print(No1)


Measured memory_bytes: 12532
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

A,B,C = I()
K = i()
num = 0
for i in range(100):
    if B > A:
        break
    B *= 2
    num += 1
for i in range(100):
    if C > B:
        break
    C *= 2
    num += 1
if num <= K:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 10088
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[27]={0};
	string s;
	cin>>s;
	for(int i=0;i<4;i++)
	a[s[i]-'A']++;
	for(int i=1;i<=26;i++)
	if(!(a[i]==0||a[i]==2)) 
	{
	cout<<"No";
	return 0;
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 256
//
// Created by Abhishek Bansal on 9/01/2020.
//
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1000000;
int gcd (int a, int b) {
    return b ? gcd (b, a % b) : a;
}
int lp[N+1];
vector<int> pr;
void computePrimes() {
    for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

    int n; cin >> n;int a[n];for(int i=0;i<n;i++) cin >> a[i];
    computePrimes();
    bool poss = true;
    vector<bool> p(1000000);
    for(int i=0;i<n;i++) {
        int x = a[i];
        while (x != 1) {
            if (p[lp[x]]) {poss = false;break;} else p[lp[x]] = true;
            int tp = lp[x];
            while (x%tp==0) {x/=tp;}
        }
        if (!poss) break;
    }
    if (poss) cout << "pairwise coprime";
    else {
        int gc = a[0];for(int i=1;i<n;i++) gc = gcd(gc, a[i]);
        if(gc == 1) cout << "setwise coprime";
        else cout << "not coprime";
    }
    return 0;
}

Measured memory_bytes: 11692
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  int h[100000];
  int answer=0;
  for(int i=0;i<N;i++){
    cin>>h[i];
    if(h[i]>=K){
      answer+=1;
    }
  }
  cout<<answer<<endl;
  
  return 0;
}

Measured memory_bytes: 768
use strict;
use warnings;

my $s = <>;
chomp $s;
my @str = split //, $s;
my ($a, $z) = (0, 0);

for(my $i = 0; $i < $#str; $i++) {
	if($str[$i] eq 'A') {
		$a = $i;
		last;
	}
}
for(my $i = $#str; $i > 0; $i--) {
	if($str[$i] eq 'Z') {
		$z = $i;
		last;
	}
}
$z++;
print $z - $a . "\n";
exit;

Measured memory_bytes: 27520
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int n,k,i,j,T;
	int c[2001],g[2001],sum;
	int jan[11][2001],cnt[11],x,kk,temp;
	int janaf[11][2001],dp[11][2001];
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++) scanf("%d %d",&c[i],&g[i]);
	for(i=1;i<=10;i++) cnt[i]=0;
	for(i=0;i<=10;i++) {
		for(j=0;j<2000;j++) {
			jan[i][j]=0;
			janaf[i][j]=0;
		}
	}
	for(i=0;i<n;i++) {
		x=g[i];
		jan[x][cnt[x]]=c[i];
		cnt[x]++;
	}
	for(i=1;i<=10;i++) sort(jan[i],jan[i]+cnt[i],greater<int>());
	sum=0;
	for(i=1;i<=10;i++) {
		for(j=0;j<cnt[i];j++) {
			sum+=jan[i][j];
			janaf[i][j]=sum;
		}
		sum=0;
	}
	for(i=1;i<=10;i++) {
		for(j=0;j<cnt[i];j++) janaf[i][j]+=(j+1)*j;
		
	}
	for(i=0;i<=10;i++) {
		for(j=0;j<=k;j++) dp[i][j]=-1;
	}
	dp[0][0]=0;
	for(i=1;i<=10;i++) {
		for(j=0;j<=k;j++) {
			for(kk=0;kk<=cnt[i];kk++) {
				if(dp[i-1][j]>dp[i][j]) dp[i][j]=dp[i-1][j];
				if(k>=j+(kk+1)){
					if(dp[i][j+(kk+1)]<dp[i-1][j]+janaf[i][kk]) {
						dp[i][j+(kk+1)]=dp[i-1][j]+janaf[i][kk];
					}
				}
			}
		}
	}
	printf("%d\n",dp[10][k]);
	return 0;
}

Measured memory_bytes: 1312
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    bool operator<(const P &p) const {
        return b < p.b;
    }
    int a, b;
};

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

    int n;
    cin >> n;

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i].a >> p[i].b;
    }
    sort(p.begin(), p.end());

    int r = 1;
    ll s = 0;
    for (int i = 0; i < n; i++) {
        s += p[i].a;
        if (s > p[i].b) r = 0;
    }

    cout << (r ? "Yes" : "No") << endl;

    //各時刻について締め切りがそれ以下の和が時刻0からの経過時間以下ならよい

    return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

n = int(input())
p_list = list(map(int, input().split()))

ans = 0
temp_min = MOD
for i in p_list:
    if i <= temp_min:
        temp_min = i
        ans += 1

print(ans)

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


int main()
{
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i,n)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    string a[4] = {"AC", "WA", "TLE", "RE"};
    rep(i,4) cout << a[i] << " x " << mp[a[i]] << endl;

    return 0;
}

Measured memory_bytes: 3632
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

////////////////////////////////////////////////////////////////////////

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val H = IntArray(N) { sc.next().toInt() }
        val d = IntArray(N)
        d[0] = 0
        d[1] = Math.abs(H[0] - H[1])
        for (i in 2 until N) {
            d[i] = arrayOf(
                d[i - 1] + Math.abs(H[i] - H[i - 1]),
                d[i - 2] + Math.abs(H[i] - H[i - 2])
            ).min()!!
        }
        pw.println(d[N - 1])
    }
}


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

int H;
int N;
vector<vector<int>> v;
int ansx, ansy, ansh;

int main() {
	cin >> N;
	rep(i, N) {
		int x, y, h;
      	cin >>x >>y >>h;
		v.push_back({h,x,y});
	}

	sort(v.rbegin(), v.rend());
	/*/
  	rep(i,N){
    cout <<v[i][0] <<" "<<v[i][1] <<" " <<v[i][2] <<endl;
    }
    //*/
      
	bool flag = 1;
	rep(i, 101) {
		rep(j, 101) {
			ansh = v[0][0] + abs(i - v[0][1]) + abs(j - v[0][2]);
			rep(k, N) {
				if (v[k][0] != max(ansh- abs(i - v[k][1]) - abs(j - v[k][2]),0)){
                  	flag = 0;
					break;
                }
			}
			
			if (flag) { 
				ansx = i; ansy = j; 
				cout << ansx << " " << ansy << " " << ansh << endl;
				return 0;
			}
          
          	flag=1;
		}
	}


	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in); // ??\???????????????
		StringBuilder out = new StringBuilder(); // ??¨?????¨??¢??°
		StringBuilder output = new StringBuilder(); // #,\n???????´?????????¢??°

		while (true) { // ???????????????
			int H = sc.nextInt(); // ????????\??????
			int W = sc.nextInt(); // ?¨??????\??????

			if (H + W == 0) // ?????¨?¨????0 0????????????
				break;

			for (int i = 0; i < H; i++) {// ????????°???????????????
				for (int j = 0; j < W; j++) {// ?¨??????°???????????????
					if((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)){
						out = out.append("#");
					}else{
						out = out.append(".");
					}
				}
				out = out.append("\n");
			}
			output = output.append(out + "\n"); // ????´???????#,\n???????´?
			out.delete(0, out.length()); // ??¨?????¨out????????????
		}
		System.out.print(output); // ??????
		sc.close();
	}

}

Measured memory_bytes: 28192
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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


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

    int N;
    cin >> N;
    vector<string> W(N);

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

    bool ban = false;

    for(int i = 0; i < N-1; i++){
        
        if(W[i].substr(W[i].length()-1, 1) != W[i+1].substr(0, 1)){
            cout << "No" << endl;
            ban = true;
            break;
        }

        if(find(W.begin()+i+1, W.end(), W[i]) != W.end()){
            cout << "No" << endl;
            ban = true;
            break;
        }

    }

    if(!ban){
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int v[]= {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int x,y;
  cin>>x>>y;
  if(v[x]==v[y])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n = inp[0]
tab = na2(n+1,0)
lis = na(n+1,0)
(n-1).times do
  dat = inp
  tab[dat[0]].push(dat[1])
  tab[dat[1]].push(dat[0])
end
fn = 1
ff = 1
lis[1] = 1
lis[n] = 1
que1 = []
que2 = []
tab[1].each do |d|
  que1.push(d) 
end
tab[n].each do |d|
  que2.push(d)
end

while (que1.size > 0 or que2.size > 0)
  if(que1.size > 0)
    que1.size.times do
      now = que1.shift
      if(lis[now] != 1)
        fn += 1
        lis[now] = 1
        tab[now].each do |d|
          que1.push(d) 
        end
      end
    end
  else
  end
  if(que2.size > 0)
    que2.size.times do
      now = que2.shift
      if(lis[now] != 1)
        lis[now] = 1
        ff += 1
        tab[now].each do |d|
          que2.push(d)
        end
      end
    end
  end
end

puts (fn > ff)? "Fennec" : "Snuke"


Measured memory_bytes: 12924
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

    ll i,j,k,m,n;
    ll cnt=1;
    ll x,y;
    cin>>x>>y;
    if(y==0)
    {
        if(x>0)
            cout<<x+1<<endl;
        else
            cout<<abs(x)<<endl;
    }
    else
    {
        if(x>=0&&y>0)
        {
            if(x>y)
                cout<<x-y+2<<endl;
            else
                cout<<y-x<<endl;
        }
        else if(x<0&&y<0)
        {
            if(x>y)
                cout<<x-y+2<<endl;
            else
                cout<<y-x<<endl;
        }
        else
        {
            x=abs(x);
            y=abs(y);
            if(x>y)
            {
                cout<<x-y+1<<endl;
            }
            else
                cout<<y-x+1<<endl;
        }

    }
    return 0;
}


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

int a[100005],b[100005],n,x;

int q[200005],bkt[200005],c;

int f[100005];
int anc(int x){return f[x]?f[x]=anc(f[x]):x;}
void uni(int x,int y){if((x=anc(x))!=(y=anc(y)))f[x]=y,--c;}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
	scanf("%d",&a[i]),x^=a[i],q[++c]=a[i];
    for(int i=1;i<=n;++i)
	scanf("%d",&b[i]),q[++c]=b[i];

    q[++c]=x;
    std::sort(q+1,q+c+1);
    c=std::unique(q+1,q+c+1)-q-1;

    ++bkt[x=std::lower_bound(q+1,q+c+1,x)-q];
    for(int i=1;i<=n;++i)
    {
	a[i]=std::lower_bound(q+1,q+c+1,a[i])-q;
	b[i]=std::lower_bound(q+1,q+c+1,b[i])-q;

	++bkt[a[i]],--bkt[b[i]];
    }

    for(int i=1;i<=c;++i)
	if(bkt[i]<0)return puts("-1"),0;

    c=0,bkt[x]=978978;
    for(int i=1;i<=n;++i)
	if(a[i]!=b[i])
	{
	    if(bkt[a[i]]!=978978)++c,bkt[a[i]]=978978;
	    if(bkt[b[i]]!=978978)++c,bkt[b[i]]=978978;
	    uni(b[i],a[i]),++c;
	}
    
    printf("%d\n",c);
    
    return 0;
}

Measured memory_bytes: 2560
from sys import stdin

def Check(P):
    j = 0
    for _ in range(k):
        s = 0
        while s + W[j] <= P:
            s += W[j]
            j += 1
            if j == n:
                return j
    return j

def Solve():
    l = 0
    r = 100000 * 100000
    while r - l > 1:
        m = (l + r) // 2
        v = Check(m)
        if v == n:
            r = m
        else:
            l = m
    return r

n, k = map(int, stdin.readline().split())
W = [int(x) for x in stdin.readlines()]

print(Solve())


Measured memory_bytes: 15896
#include<iostream>

using namespace std;

int H,t[50][6];

int main(){
    while(1){
        cin>>H;
        if(H==0)break;

        for(int i=H-1;i>=0;i--){
            for(int j=0;j<5;j++){
                cin>>t[i][j];
            }
        }

        int ans=0;

        while(1){
            int tmp=ans;

            for(int i=0;i<H;i++){
	            int key=t[i][0],cnt=1;
	            t[i][5]=-1;

	            for(int j=1;j<6;j++){
	                if(key==t[i][j])cnt++;
	                else{
	                    if(cnt>=3&&key!=0)

	                    for(int k=0;k<cnt;k++){
		                ans+=key;
		                t[i][j-k-1]=0;
	                    }

	                    cnt=1;
	                    key=t[i][j];
	                }
	            }
            }

            if(tmp==ans)break;

            for(int j=0;j<5;j++){
	            int I=0;

	            for(int i=0;i<H;i++){
	                if(t[i][j]==0)continue;
	                t[I][j]=t[i][j];
	                I++;
	            }

	            while(I<H)t[I++][j]=0;
            }
        }
    
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 2996
x = [int(input()) for i in range(4)]
cnt = 0
for i in range(x[0] + 1):
    for j in range(x[1] + 1):
        for k in range(x[2] + 1):
            if i*500+j*100+k*50 == x[3]:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
string s,s1;
vector<char> v;
int main()
{
    cin>>s;
    for(int i=0;i<s.size();++i)
    {

        if(s[i] =='B'&&s1.size()!=0)
            s1.pop_back();
            else if(s[i]!='B')
            s1.push_back(s[i]);
    }

        cout<<s1;
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

void TopoSort(const vector<list<int>> & d, vector<int> & in, queue<int> & ans) {
	int i, a;
	queue<int> que;
	rep(i, in.size()) {
		if (!in[i])
			que.push(i);
	}
	while (!que.empty()) {
		a = que.front();
		que.pop();
		ans.push(a);
		for (auto it = d[a].begin(); it != d[a].end(); it++) {
			in[*it]--;
			if (!in[*it])
				que.push(*it);
		}
	}
	return;
}

int main(void) {
	int num, m, i, a, b, ma = 0;
	cin >> num >> m;
	queue<int> topo;
	vector<int> in(num + 1, 0), ans(num + 1, 0);
	vector<list<int>> d(num + 1);
	rep(i, m) {
		cin >> a >> b;
		d[a].push_back(b);
		in[b]++;
	}
	TopoSort(d, in, topo);
	while (!topo.empty()) {
		a = topo.front();
		topo.pop();
		for (auto it = d[a].begin(); it != d[a].end(); it++)
			chmax(ans[*it], ans[a] + 1);
		chmax(ma, ans[a]);
	}
	cout << ma << "\n";
	return 0;
}

Measured memory_bytes: 9740
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn f(u: usize, p: usize, c: u64, edges: &Vec<Vec<(usize, u64)>>, depth: &mut Vec<u64>) {
    depth[u as usize] = c;
    for v in &edges[u] {
        if v.0 == p {
            continue;
        }
        f(v.0, u, c + v.1, edges, depth);
    }
}

fn dist(a: u32, b: u32) -> u32 {
    if a > b {
        a - b
    } else {
        b - a
    }
}

fn atou(a: char) -> usize {
    (a as usize) - 97
}

fn main() {
    let s: String = read();
    let t: String = read();

    let svec: Vec<char> = s.chars().collect();
    let tvec: Vec<char> = t.chars().collect();

    let mut next: Vec<Vec<usize>> = vec![vec![1000000; 26]; s.len()];
    let mut tmp: Vec<usize> = vec![1000000; 26];
    for i in (0..s.len()).rev() {
        next[i] = tmp.clone();
        tmp[atou(svec[i])] = i;
    }
    for i in (0..s.len()).rev() {
        next[i] = tmp.clone();
        tmp[atou(svec[i])] = i;
    }

    let mut id: usize = 1000000;
    for i in 0..s.len() {
        if svec[i] == tvec[0] {
            id = i;
            break;
        }
    }
    if id > 100000 {
        println!("-1");
        return;
    }
    let mut dis = id + 1;
    let mut ans: u64 = dis as u64;
    for i in 1..t.len() {
        let nextid = next[id][atou(tvec[i])];
        if nextid > 100000 {
            println!("-1");
            return;
        }
        dis = (nextid + s.len() - id) % s.len();
        if dis == 0 {
            dis = s.len();
        }
        id = nextid;
        ans += dis as u64;
    }

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


Measured memory_bytes: 30972
#include <algorithm>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

int main() {
  std::string s, t;
  std::cin >> s >> t;

  int N = s.length();
  int M = t.length();
  int inf = 1 << 30;
  std::vector<std::vector<int>> dp(N + 7, std::vector<int>(M + 7, -inf));
  std::vector<std::vector<std::pair<int, int>>> prev(
      N + 7, std::vector<std::pair<int, int>>(M + 7, std::make_pair(-1, -1)));

  dp[0][0] = 0;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= M; ++j) {
      if (chmax(dp[i + 1][j], dp[i][j]))
        prev[i + 1][j] = std::make_pair(i, j);
      if (chmax(dp[i][j + 1], dp[i][j]))
        prev[i][j + 1] = std::make_pair(i, j);
      if (s[i] == t[j])
        if (chmax(dp[i + 1][j + 1], dp[i][j] + 1))
          prev[i + 1][j + 1] = std::make_pair(i, j);
    }
  }

  std::string res;
  int i = N;
  int j = M;
  while (prev[i][j] != std::make_pair(-1, -1)) {
    if (prev[i][j] == std::make_pair(i - 1, j - 1))
      res += s[i - 1];
    std::tie(i, j) = std::make_pair(prev[i][j].first, prev[i][j].second);
  }
  std::reverse(res.begin(), res.end());
  std::cout << res << std::endl;
}


Measured memory_bytes: 106496
// https://atcoder.jp/contests/abc128/tasks/abc128_a

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, p;
    cin >> a >> p;
    cout << (p + a * 3) / 2 << endl;

    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n;
  string s;
  cin>>n>>s;

  ll x=0,y=0;
  rep(i,n){
    if( 'A'<=s[i] && s[i]<='M' )y++;
    else if( 'N'<=s[i] && s[i]<='Z' )y--;
    else  if( 'a'<=s[i] && s[i]<='m' )x++;
    else x--;
  }

  string ans="";
  if(y>0)rep(i,y)ans+='A';
  else if(y<0)rep(i,abs(y))ans+='N';
  if(x>0)rep(i,x)ans+='a';
  else if(x<0)rep(i,abs(x))ans+='n';
  cout<<ans.size()<<endl;
  cout<<(ans)<<endl;


}



Measured memory_bytes: 3352