akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  os << "{";
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? "," : "") << a[i];
  return os << "}";
}

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

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

  vector<vector<int>> g(h + w + 1);
  // 左y, →x
  rep(i, 0, m) {
    int y, x;
    cin >> y >> x;
    --y, --x;
    g[y].push_back(x + h);
    g[x + h].push_back(y);
  }

  ll ans = 0;
  ll max_y = 0;
  ll max_yi = 0;
  ll min_child = INFL;
  // hからつながってる数が同じなら、そのつながってるwからのびるhへの辺が少ないほうが、あとでwを選んだ時にさいだいかしやすいよね
  // idxほしい、辺の数降順、相手の数昇順にしたいから、たぷる
  vector<tuple<ll, ll, ll>> unko;
  rep(i, 0, h) {
    ll sz = g[i].size();
    ll ch = 0;
    for (int v : g[i]) ch += (ll)g[v].size();
    unko.emplace_back(sz, -ch, i);
  }
  sort(unko.rbegin(), unko.rend());
  max_y = get<0>(unko[0]);
  max_yi = get<2>(unko[0]);

  ans += max_y;
  for (int v : g[max_yi]) {
    g[v].erase(remove(g[v].begin(), g[v].end(), max_yi), g[v].end());
  }

  ll max_x = 0;
  rep(i, h, h + w) {
    ll sz = g[i].size();
    max_x = max(max_x, sz);
  }
  ans += max_x;
  // 二部グラフを考える。
  // hの座標が同じもの、wの座標が同じものを
  // y, xを選んだ時に消えるものの組み合わせは
  //
  // 二部グラフ作る、hで最大なのを選ぶ、そのhにつながってるのをひく、wで最大なのをえらぶ。
  cout << ans << endl;
  return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

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

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

class UnionFind{
private:
  vector<int> par, rank;
public:
  UnionFind(int n){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i)
	  par[i] = i;
  }

  //find root of x
  int find(int x){
	if(par[x] == x)
	  return x;
	return (par[x] = find(par[x]));
  }

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

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

  bool same(int x, int y){
	return find(x) == find(y);
  }
};

struct Edge{
  int to, cost;

  Edge(int t, int c): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }
};
typedef vector< vector<Edge> > Graph;

void add_edge(Graph& graph, int u, int v, int cost){
  graph[u].push_back(Edge(v,cost));
  graph[v].push_back(Edge(u,cost));
}

int kruskal(const Graph& G){
  int N = SZ(G);
  UnionFind uf(N);
  vector<pair<Edge,int>> edges;
  REP(i,N) for(auto& e:G[i]){
	edges.push_back(MP(e, i));
  }
  sort(ALL(edges));

  int res = 0;
  for(int i=0,n=1;n<N;++i){
	auto& e = edges[i].first;
	int v = edges[i].second;
	if(!uf.same(e.to,v)){
	  uf.unite(e.to, v);
	  res += e.cost;
	  ++n;
	}
  }
  return res;
}

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

  int V, E; cin >> V >> E;
  Graph G(V);
  REP(i,E){
	int a, b, c; cin >> a >> b >> c;
	add_edge(G, a, b, c);
  }

  cout << kruskal(G) << endl;

  return 0;
}

Measured memory_bytes: 8956
#include <bits/stdc++.h>
using namespace std;
static const long long MOD=1000000007;

int main(){
  long long N,A,B,C;
  cin>>N>>A>>B;
  long long P[N];
  for(int i=0;i<N;i++){
    cin>>P[i];
  }
  C=0;
  for(int i=0;i<N-1;i++){
    if((P[i+1]-P[i])*A<=B){
      C+=(P[i+1]-P[i])*A;
    }
    else{
      C+=B;
    }
  }
  cout<<C<<endl;
  
  return 0;
}


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

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

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   int x[n] , l[n];
   vector <pii> v;
   for(int i = 0 ; i < n ; i++){
      cin >> x[i] >> l[i];
      v.push_back({x[i] - l[i] , i});
   }
   sort(v.begin() , v.end());
   int mx = -mod;
   int ans = 0;
   for(pii xx : v){
      if(mx > xx.first){
         ans++;
         mx = min(mx , x[xx.second] + l[xx.second]);
      }
      else{
         mx = x[xx.second] + l[xx.second];
      }
   }
   cout << n - ans;
   return 0;
}


Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MAX=101000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        //???
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(){
    COMinit();
    int n;
    cin>>n;
    int a[n+1];
    vector<vector<int>> v(n);
    vector<bool> app(n,false);
    int dab;
    rep(i,n+1){
        cin>>a[i];a[i]--;
        if(app[a[i]]) dab=a[i];
        app[a[i]]=true;
    }
    int f,m,b,idx1=-1,idx2;
    rep(i,n+1){
        if(a[i]==dab&&idx1<0) idx1=i;
        else if(a[i]==dab&&idx1>=0) idx2=i;
    }
    f=idx1;b=n-idx2;m=idx2-idx1-1;
    
    /*f:1個目ダブリの前の個数,m:ダブリ間個数,b:2個目ダブリ後個数
    f f...f daburi m m .... m m daburi b b ...b b
    長さxの部分列
    ダブリをとらない->f+m+bCx
    ダブリを1個とる->2*(f+m+b)C(x-1)-(f+b)C(x-1)
       f,m,bからx-1個とるけど、f,f..ﾀﾞﾌﾞ..b,bってやつを
       ダブってとってるので引きます
    ダブリを2個とる->(f+m+b)C(x-2)
    全部足して終わり
     */

    for(int x=1;x<=n+1;x++){
        ll ans=0;
        ans=(ans+COM(f+m+b,x))%mod;
        ll tmp=2*COM(f+m+b,x-1)-COM(f+b,x-1);
        if(tmp<0) tmp+=mod;
        ans=(ans+tmp)%mod;
        ans=(ans+COM(f+m+b,x-2))%mod;
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, K;
  cin >> N >> K;
  vector<ll> v;
  rep(i,N){
    ll h;
    cin >> h;
    v.push_back(h);
  }
  sort(ALLOF(v));

  ll mn = v[K-1] - v[0];
  rep(i,N){
    if(K-1+i<N){
      mn = min(mn, v[K-1+i] - v[i]);
    }
  }

  cout << mn << endl;
  
  return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define maxN 3000

int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);

}

bool comp(int a, int b) {
	return abs(a) > abs(b);
}



int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
	int x;
	cin >> x;
	if (x) {
		cout << 0 << endl;
	} else {
		cout << 1 << endl;
	}
	return 0;
}

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

using namespace std;

int n;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    int k = (n + 999) / 1000;
    cout << 1000 * k - n << endl;
    return 0;
}


Measured memory_bytes: 3636
/**
**	author : Raghav
**	codechef:raghav_456
**	codeforces:raghavramola7
**/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define endl 			"\n"
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void Raghav()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(100);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int digit_sum(int a)
{
	int m, sum = 0;
	while (a)
	{
		m = a % 10;
		sum = sum + m;
		a = a / 10;
	}
	return sum;
}
int32_t main()
{
	Raghav();
	int n, k;
	cin >> n >> k;
	int a = 1;
	while (n--)
	{
		if (a * 2 <= a + k)
		{
			a = a * 2;
		}
		else
			a += k;
	}
	cout << a;
	return 0;

}

Measured memory_bytes: 3576
menu = [int(input()) for i in range(5)]
adjust = []
total = 0

for i in menu:
    if i%10 == 0:
        total += i
    else:
        adjust.append(i%10)
        total += (i + 10-(i%10))

adjust.sort()
if len(adjust) > 0:
    total -= 10-adjust[0]

print(total)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],arr1[1000000],arr2[1000000],arr3[1000000],arr4[1000000];
int main()
{
	long long t,i,j,x,y,a,b,c,ans,p,q,r,rr,gg,z;
	ans=0;
	cin>>x>>y>>a>>b>>c;
	for (i=0;i<a;i++)
	{
		cin>>arr[i];
	}
	for (i=0;i<b;i++)
	{
		cin>>arr1[i];
	}
	for (i=0;i<c;i++)
	{
		cin>>arr2[i];
	}
	sort(arr,arr+a);
	sort(arr1,arr1+b);
	sort(arr2,arr2+c);
	rr=0;
	for (i=a-1;i>a-1-x;i--)
	{
		ans+=arr[i];
		arr3[rr]=arr[i];
		rr++;
	}
	//cout<<ans<<endl;
	for (j=b-1;j>b-1-y;j--)
	{
		ans+=arr1[j];
		arr3[rr]=arr1[j];
		rr++;
	}	
	//cout<<ans<<endl;
	sort (arr3,arr3+rr);
	gg=0;
	z=c-x-y;
	z=fmax(z,0);
	for (i=c-1;i>=z;i--)
	{
		arr4[gg]=arr2[i];
		gg++;
	}
	gg=0;
	for (i=0;i<rr;i++)
	{
		if (arr4[gg]>arr3[i])
		{
			ans=ans-arr3[i]+arr4[gg];
			gg++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 13312
arr = gets.split(" ")
n = arr[0].to_i
a = arr[1].to_i
b = arr[2].to_i
r = [] << 0
(n+1).times do |i|
  s = i.to_s.chars.map(&:to_i)
  t = s.reduce(&:+)
  if( t >= a && t <= b) 
    r << i
  end
end
puts r.reduce(&:+)

Measured memory_bytes: 1916
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    s = 0
    P = int(1e9)+7
    for k in range(60):
        cnt = 0    
        for e in a:
            if (e>>k) & 1:
                cnt += 1
        s += cnt*(n-cnt)*pow(2, k, P)
        s %= P
    print(s)
if __name__ == '__main__':
    main()


Measured memory_bytes: 89712
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007
#define BOX 200000

typedef long long ll;

#define rep(i, s, e) for(unsigned int i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)
#define so(a) sort(begin(a), end(a))
#define soR(a) sort(begin(a), end(a), greater<ll>())
#define sum(a) accumulate(begin(a), end(a), 0)


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



int main() {
    string s;
    cin >> s;
    string start{ s[0] };
    string end{ s[s.size() - 1] };
    string len = to_string(s.size() - 2);

    cout << start + len + end << endl;

    return 0;

}

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

int	main()
{
	int N;
	cin >> N;
	vector<int> cnt_vec(N, 0);
	int A;
	for (int i = 1; i < N; ++i) {
		cin >> A;
		--A;
		++cnt_vec.at(A);
	}
	for (int i = 0; i < N; ++i) 
		cout << cnt_vec.at(i) << endl;
}


Measured memory_bytes: 4000
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
#define int long long
#define debug(x) cerr << #x << " = " << x << endl
#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 > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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


  ll n,m;
  cin>>n>>m;
  UnionFind tree(n+1);
  ll a[m],b[m];
  rep(i,m) {
    cin>>a[i]>>b[i];
  }
  ll ans[m+1];
  ans[m] = n * (n-1) / 2;
  ll cnt[n+1];
  rep(i,n+1) cnt[i] = 1;
  repr(i,m-1) {
    if(!tree.same(a[i],b[i])) {
      ans[i] = max(0LL, ans[i+1] - cnt[tree.root(a[i])] * cnt[tree.root(b[i])]);
      cnt[tree.root(a[i])] += cnt[tree.root(b[i])];
      cnt[tree.root(b[i])] = cnt[tree.root(a[i])];
    } else {
      ans[i] = ans[i+1];
    }
    tree.unite(a[i], b[i]);
  }
  FOR(i,1,m+1) {
    cout << ans[i] << endl;
  }


  return 0;
}


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

int main(){
  int N,x; cin >> N >> x;
  vector<int>V(N);
  for(auto&&e:V)cin >> e;
  sort(V.begin(), V.end());
  int cnt = 0;
  for(int i = 0; i < N; ++i){
    if(i == N - 1){
      if(x == V[i])cnt++;
    }
    else{
      if(x < V[i])break;
      cnt++;
      x-=V[i];
    }	
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

X = []
for _ in range(M):
    t = list(map(int, input().split()))
    X.append(t[1:])

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

r = 0
for i in range(2**N):
    j = i
    c = 1
    cs = set()
    while j:
        if j % 2:
            cs.add(c)
        j //= 2
        c += 1

    for i in range(M):
        t = 0
        for x in X[i]:
            if x in cs:
                t += 1
        if t%2 != P[i]:
            break
    else:
        r += 1

print(r)


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

int main(void){
    int n,S=0;
    cin>>n;
    int N=n;
    do{
        S+=N%10;
        N/=10;
    }while(N!=0);

    if(n%S==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// べき乗
ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  string S;
  cin >> S;
  cout << S.substr(0,3) << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h;
    while (cin>>h) {
        if (h==0) {
            break;
        }
        std::vector<vector<int>> vec(h,vector<int>(5));
        int a;
        for (int i=0;i<h;i++) {
            for (int j=0;j<5;j++) {
                cin>>a;
                vec[i][j]=a;
            }
        }
        int flag=0,score=0;
        while (1) {
            flag=0;
            for (int i=0;i<h;i++) {
                if (vec[i][0]!=0&&vec[i][0]==vec[i][1]&&vec[i][0]==vec[i][2]&&vec[i][0]==vec[i][3]&&vec[i][0]==vec[i][4]) {
                    score+=vec[i][0]*5;
                    flag=1;
                    for (int j=0;j<5;j++) {
                        vec[i][j]=0;
                    }
                } else if (vec[i][0]!=0&&vec[i][0]==vec[i][1]&&vec[i][0]==vec[i][2]&&vec[i][0]==vec[i][3]) {
                    score+=vec[i][0]*4;
                    flag=1;
                    for (int j=0;j<4;j++) {
                        vec[i][j]=0;
                    }
                } else if (vec[i][1]!=0&&vec[i][1]==vec[i][2]&&vec[i][1]==vec[i][3]&&vec[i][1]==vec[i][4]) {
                    score+=vec[i][1]*4;
                    flag=1;
                    for (int j=1;j<5;j++) {
                        vec[i][j]=0;
                    }
                } else if (vec[i][0]!=0&&vec[i][0]==vec[i][1]&&vec[i][0]==vec[i][2]) {
                    score+=vec[i][0]*3;
                    flag=1;
                    for (int j=0;j<3;j++) {
                        vec[i][j]=0;
                    }
                } else if (vec[i][1]!=0&&vec[i][1]==vec[i][2]&&vec[i][1]==vec[i][3]) {
                    score+=vec[i][1]*3;
                    flag=1;
                    for (int j=1;j<4;j++) {
                        vec[i][j]=0;
                    }
                } else if (vec[i][2]!=0&&vec[i][2]==vec[i][3]&&vec[i][2]==vec[i][4]) {
                    score+=vec[i][2]*3;
                    flag=1;
                    for (int j=2;j<5;j++) {
                        vec[i][j]=0;
                    }
                }
            }
            if (flag==0) {
                cout<<score<<endl;
                break;
            } else {
                for (int i=h-1;i>=0;i--) {
                    for (int j=0;j<5;j++) {
                        if (vec[i][j]!=0) {
                            int tmp=i;
                            while (tmp+1<h&&vec[tmp+1][j]==0) {
                                swap(vec[tmp][j],vec[tmp+1][j]);
                                tmp++;
                            }
                        }
                    }
                }
                /*
                for (int i=0;i<h;i++) {
                    for (int j=0;j<5;j++) {
                        cout<<vec[i][j]<<" ";
                    }
                    cout<<endl;
                }
                cout<<endl;
                */
            }
        }
    }
}


Measured memory_bytes: 3168
h = Hash.new(0)

n = gets.to_i
ss = []
n.times do
  s = gets.chomp
  h[s] += 1
end

m = gets.to_i
ts = []
m.times do
  t = gets.chomp
  h[t] -= 1
end

max = h.values.max
puts [max, 0].max

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

lint f( lint n ) {
    lint ans = 0;
    for( lint i=n/4*4; i<=n; i++ ) {
        ans ^= i;
    }
    return ans;
}

int main() { cin.tie(0); ios::sync_with_stdio(false);
    lint A = in-1, B = in;
    cout << (f(A) ^ f(B)) << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s;
int n;
int main(){
  cin >> n >> s;
  int ret = 0;
  for(int i=1; i<n-1; i++){
    string a, b;
    bool used[26];
    for(int i=0; i<26; i++) used[i] = false;
    int tmp = 0;
    a = s.substr(0, i);
    b = s.substr(i);
    for(char ca : a){
      for(char cb : b){
        if(ca == cb){
          if(used[int(ca-'a')]) continue;
          tmp ++;
          used[int(ca-'a')] = true;
          break;
          }
        }
      }
      ret = max(ret, tmp);
      }
    cout << ret << endl;
    return 0;
    }

Measured memory_bytes: 256
// Aizu 1160: How Many Islands?
// 2017.9.13 bal4u@uu

#include <stdio.h>

#define MAX 3000  // > N*N
#define N 50

// UNION-FIND library
int p[MAX], rank[MAX];
void make_set(int x) { p[x] = x, rank[x] = 0; }
void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }
// UNION-FIND library above

char map[N+3][N+3];
int  id[N+3][N+3];
int m[8][2] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};

int main()
{
	int w, h, i, r, c, r2, c2, a, n;

	while (scanf("%d%d", &w, &h) && w) {
		for (n = 0, r = 0; r < h; r++) for (c = 0; c < w; c++) {
			scanf("%d", &a), map[r][c] = a;
			if (a) make_set(n), id[r][c] = n++;
		}
		for (r = 0; r < h; r++) for (c = 0; c < w; c++) {
			if (!map[r][c]) continue;
			for (i = 0; i < 8; i++) {
				r2 = r + m[i][0], c2 = c + m[i][1];
				if (r2 < 0 || r2 >= h || c2 < 0 || c2 >= w || !map[r2][c2]) continue;
				union_set(id[r][c], id[r2][c2]);
			}
		}
		for (n = 0, r = 0; r < h; r++) for (c = 0; c < w; c++) if (map[r][c]) {
			if (id[r][c] == p[id[r][c]]) n++;
		}
		printf("%d\n", n);
	}
	return 0;
}

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

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

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val)
{
    std::fill((T*)array, (T*)(array + N), val);
}
int dp[(1 << 12) + 1][1010];
// vector<vector<int>> dp(1 << 12 + 1, vector<int>(1010, INF_32));
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    vector<int> c(M, 0);
    for (int i = 0; i < M; i++) {
        int b;
        cin >> a[i] >> b;
        for (int j = 0; j < b; j++) {
            int inp;
            cin >> inp;
            inp--;
            c[i] |= (1 << inp);
        }
    }

    Fill(dp, INF_32);
    dp[0][0] = 0;
    for (int i = 0; i < M; i++) {
        for (int bit = 0; bit <= (1 << N) - 1; bit++) {
            dp[bit | c[i]][i + 1] = min(dp[bit | c[i]][i + 1], dp[bit][i] + a[i]);
            dp[bit][i + 1] = min(dp[bit][i + 1], dp[bit][i]);
        }
    }

    cout << ((dp[(1 << N) - 1][M] == INF_32) ? -1 : dp[(1 << N) - 1][M]) << endl;
    return 0;
}

Measured memory_bytes: 19808
#include <cstdio>

char s[101];
bool f, g;

int main(){
	scanf("%s", s);
	for(int i=0; s[i]!='\0'; ++i){
		if(s[i] == 'C')
			f = true;
		if(f && s[i] == 'F')
			g = true;
	}
	if(g) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
/*                                  /   \                                                                   (Hello)//JSM//*/      
/*                                 /*****\                                                                              */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K                                                            */
#include<vector>
#include<iostream>
#include<algorithm>                
#include<string.h>                 
#include<bits/stdc++.h>            
#include<cstring>                  
#include<map>                     
#include<cmath>                  
#include<set>
using namespace std;            
#define ll long long int        
#define ld long double
#define MOD 1000000007 
#define PI 3.1415926535897932384626433832795                                               
#define YY cout<<"YES"
#define NN cout<<"NO"
#define EE cout<<"\n"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back 
#define ff first
#define ss second
#define mkp make_pair    
#define mkt make_tuple
#define all(v ) sort(v.begin(), v.end())      
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vc vector<char> 
#define vll vector< pair<ll,ll> > 
#define pr pair<ll,ll>
#define mps map<string ,ll>
#define mpc map<char ,char>
#define mpl map<ll,ll>
#define tpl tuple<ll,ll,ll>
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);	
	  ll t=1;
//	   cin>>t;
	      while(t--)
{

/*
1000 8
1 3 4 5 6 7 8 9*/
ll n,m,i,j,k;
cin>>n>>m;
ll a[m];
mpl M;
fo(i,m)
{
	cin>>a[i];
    M[a[i]]++;
}
for(i=1;i<=1000000;i++)
{ll g=-1;
	if(i>=n)
	{g=1;
		ll N=i;
		while(N!=0)
		{
			if(M[N%10]!=0)
			{
				g=-1;
			break;
			}
			N/=10;
		}
	}
	if(g==1)
	{
		cout<<i;
		return 0;
	}
}
}
return 0;
}



Measured memory_bytes: 3656
def main():
    N = list(map(int, input().split()))
    if 1 in N:
        del N[N.index(1)]
    if 9 in N:
        del N[N.index(9)]
    if 7 in N:
        del N[N.index(7)]
    if 4 in N:
        del N[N.index(4)]
    if N == []:
        return "YES"
    else:
        return "NO"

if __name__ == "__main__":
    print(main())


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

const int MAX=510000;
const int MOD=998244353;
long long fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

long long COM(int n,int k){
  if(n<k) return 0;
  if(n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  COMinit();
  ll mod=998244353;
  ll n,a,b,k;
  ll ans=0;
  cin>>n>>a>>b>>k;
  for(ll i=0;i<=n;i++){
    ll x=k-a*i;
    if(x%b==0&&x/b>=0&&x/b<=n){
      ll j=x/b;
      ans+=(COM(n,i)*COM(n,j))%mod;
      ans%=mod;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 15584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int a,b,k;cin>>a>>b>>k;
    int count=0;
    for(int i=a;;i--){
        if(a%i==0&&b%i==0){
            count++;
        }
        if(count==k){
            cout<<i<<endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main() {
    int n, e, p, q;
    vector< pair<int, unsigned long long> > data;
    vector< pair<int, unsigned long long> >::iterator it;

    while (cin >> n) {
        if(n == 0) break;

        data.clear();
        for (int i=0; i<n; i++) {
            cin >> e >> p >> q;

            it = data.begin();
            while (it != data.end()) {
                if(e == it->first) {
                    it->second += (unsigned long long)(p * q);
                    break;
                }
                it++;
            }
            
            if(it == data.end()) data.push_back(make_pair(e, (unsigned long long)(p * q)));
        }

        it = data.begin();
        bool isoutput = false;
        while (it != data.end()) {
            if(it->second >= 1000000) {
                cout << it->first << endl;
                isoutput = true;
            }
            it++;
        }
        if(!isoutput) cout << "NA" << endl;
    }
}

Measured memory_bytes: 3008
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N, K;
    cin >> N >> K;
    ll sum = 0;
    rep(i, N) {
        ll x;
        cin >> x;
        if (x > abs(K-x)) {
            sum += abs(K-x) * 2;
        } else {
            sum += x * 2;
        }
    }
    print(sum);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define w(x) scanf("%d",&x);while(x--)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 2*acos(0.0)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

long long int mod=1e9+9;
const int N=100000;
int t,i,j,cs=0,n,a,b;
string s;

int main()
{
    long long n;
    cin>>n;
    long long ans=n*(n+1)/2 ;
     long long a=n;
     n/=3;
     ans-=3*n*(n+1)/2;
     n=a/5;
     ans-=5*n*(n+1)/2;
     n=a/15;
     ans+=15*n*(n+1)/2;
    cout<<ans<<endl;
}




Measured memory_bytes: 3632
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

const int N_MAX = 3005;

int N;
vector<int> A;
long long dp[N_MAX][N_MAX];

int main() {
    scanf("%d", &N);
    A.resize(N);

    for (int &a : A)
        scanf("%d", &a);

    for (int i = 0; i <= N; i++)
        dp[i][i] = 0;

    for (int i = N - 1; i >= 0; i--)
        for (int j = i + 1; j <= N; j++)
            dp[i][j] = max(A[i] - dp[i + 1][j], A[j - 1] - dp[i][j - 1]);

    printf("%lld\n", dp[0][N]);
}


Measured memory_bytes: 70016
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    a = LIR(n)
    if n == 1:
        print(*a[0])
        quit()
    for cy in range(101):
        for cx in range(101):
            for i in range(n):
                x,y,h = a[i]
                if h > 0:
                    H = abs(x-cx)+abs(y-cy)+h
                    break
            f = True
            for i in range(n):
                x,y,h = a[i]
                if max(H-abs(x-cx)-abs(y-cy),0) != h:
                    f = False
                    break
            if f:
                print(cx,cy,H)
                quit()
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 43504
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

#define YES "POSSIBLE"
#define NO "IMPOSSIBLE"

int n;
vector<int> p;
vector<int> x;

vector<vector<int>> g;
vector<int> sum;

vector<int> dp;
int sdp[5100];

string ans;

void dfs(int v, int p) {
    for(int nv: g[v]) {
        if(nv == p) continue;
        dfs(nv, v);
    }
    rep(i, 5100) sdp[i] = INF;
    sdp[0] = 0;
    for(int nv: g[v]) {
        if(nv == p) continue;
        for(int i = 5000; i >= 0; -- i) {
            int tmp = sdp[i];
            sdp[i] = INF;
            if(tmp == INF) continue;
            if(i + x[nv] <= 5000) {
                chmin(sdp[i + x[nv]], tmp + dp[nv]);
                //cerr << i + x[nv] << " " << sdp[i + x[nv]] << endl;
            }
            if(i + dp[nv] <= 5000) {
                chmin(sdp[i + dp[nv]], tmp + x[nv]);
                //cerr << i + dp[nv] << " " << sdp[i + dp[nv]] << endl;
            }
        }
    }
    for(int i = 0; i <= x[v]; ++ i) {
        chmin(dp[v], sdp[i]);
    }
    if(dp[v] == INF) ans = NO;
}

void solve() {
	cin >> n;
    p.resize(n, -1);
    x.resize(n);
    g.assign(n, vector<int>());
    rep(i, n - 1) {
        cin >> p[i + 1];
        -- p[i + 1];
        g[i + 1].pb(p[i + 1]);
        g[p[i + 1]].pb(i + 1);
    }
    rep(i, n) {
        cin >> x[i];
    }
    dp.assign(n, INF);
    ans = YES;
    dfs(0, -1);
    // rep(i, n) cerr << dp[i] << endl;
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, Ma, Mb;

int main() {
    cin >> N >> Ma >> Mb;
    map<Pii, int> dp, tmp;
    dp[make_pair(0,0)] = 0;
    Pii key;
    int a, b, c, ma, mb, value;
    REP(i, N) {
        cin >> a >> b >> c;
        for(auto v : dp) {
            ma = a + v.first.first;
            mb = b + v.first.second;
            key = make_pair(ma, mb);
            value = v.second + c;
            tmp[key] = value;
        }
        for(auto v : tmp) {
            if(dp.find(v.first) != dp.end())
                dp[v.first] = min(dp[v.first], v.second);
            else
                dp[v.first] = v.second;
        }
        tmp.clear();
    }
    int ans = INF;
    FOR(i, 1, 40) {
        key = make_pair(i*Ma, i*Mb);
        if(dp.find(key) != dp.end())
            ans = min(ans, dp[key]);
    }
    if(ans==INF) ans = -1;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main()
{
  char c11,c12,c13,c21,c22,c23,c31,c32,c33;
  cin>>c11>>c12>>c13>>c21>>c22>>c23>>c31>>c32>>c33;
  cout<<c11<<c22<<c33<<endl;
  return 0;
}


Measured memory_bytes: 256
N=input()
b=len(N)
c=N.count("h")
d=N.count("i")
e="hi"
f="hihi"
g="hihihi"
h="hihihihi"
i="hihihihihi"
if N==e or N==f or N==g or N==h or N==i:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 2940
// C - Average Length
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define eb emplace_back
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
using vp = vector<P>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int origin(lli z)
{
  lli xx = 1;
  repe(i, 1, z)
  {
    xx = xx * i;
  }
  return xx;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  long double res = 0;
  string s, t;
  cin >> n;
  vlli x(n), y(n), z;
  pair<lli, lli> d[8];
  rep(i, 0, n)
  {
    cin >> x[i] >> y[i];
    d[i].first = x[i];
    d[i].second = y[i];
  }
  long double par = origin(n);

  rep(i, 0, n)
  {
    z.pb(i);
  }
  do
  {
    rep(i, 0, n - 1)
    {
      res += hypot(d[z[i + 1]].second - d[z[i]].second, d[z[i + 1]].first - d[z[i]].first);
    }
  } while (next_permutation(ALL(z)));
  cout << fixed << setprecision(12) << res / par << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define EPS                 0.00000001
#define LL_MAX              1e18
#define LL_MIN              -1e18
#define MAX                 0x3f3f3f3f
#define MIN                 -0x3f3f3f3f
#define MOD                 1000000007
#define DEBUG(x)            cout << '>' << #x << ':' << x << endl;
#define REP(i,n)            for(int i=0;i<(n);i++)
#define FOR(i,a,b)          for(int i=(a);i<=(b);i++)
#define FORD(i,a,b)         for(int i=(a);i>=(b);i--)
#define n1                  '\n'

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> pt;
typedef vector<pt> pol;

ll power(ll b, int e) {
    ll res = 1;
    for ( ; e>0; e/=2) {
        if (e&1) res = res*b % MOD;
        b = b*b % MOD;
    }
    return res;
}

inline void IOS() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main()
{
    IOS();
    int n;
    cin >> n;
    vector<int> arr(n);
    REP(i, n) {
        cin >> arr[i];
    }
    vector<int> dp(n);
    dp[1] = abs(arr[1] - arr[0]);
    FOR(i, 2, n-1) {
        dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
// start fold
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cstring>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
using namespace std;
#define ri register int
#define il inline
#define LL long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pairint pair<int,int>
#define fi first
#define se second
#define iv il void
#define enter putchar('\n')
#define size(x) ((int)x.size())
#define mem0(x) memset(x,0,sizeof(x))
template<class T>il void in(T &x)
{
    x=0; short f=1; char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9') x=x*10+(c^'0'),c=getchar();
    x*=f;
}
template<class T>il void out(T x,const char c='\n')
{
    static short st[30];
    short m=0;
    if(x<0) putchar('-'),x=-x;
    do st[++m]=x%10,x/=10; while(x);
    while(m) putchar(st[m--]|'0');
    putchar(c);
}
namespace i207M
{
// end fold
#define N 2000005
const int md=1e9+7;
int fac[N],ifac[N];
il int qpow(int a,int b)
{
    int res=1;
    for(; b; b>>=1,a=(LL)a*a%md) if(b&1) res=(LL)res*a%md;
    return res;
}
void prework()
{
    fac[0]=1;
    for(ri i=1; i<N; ++i) fac[i]=(LL)fac[i-1]*i%md;
    ifac[N-1]=qpow(fac[N-1],md-2);
    for(ri i=N-1; i>=1; --i) ifac[i-1]=(LL)ifac[i]*i%md;
}
int c(int n,int m)
{
    if(n<m) return 0;
    return (LL)fac[n]*ifac[m]%md*ifac[n-m]%md;
}
struct Node
{
    int x,y,k;
    Node() {}
    Node(const int xx,const int yy,const int kk=0)
    {
        x=xx,y=yy,k=kk;
    }
} p[10];
int f(const Node &u,const Node &v)
{
    int a=abs(u.x-v.x),b=abs(u.y-v.y);
    return c(a+b,a);
}
int xx[10],yy[10];
int x3,x4,y3,y4;
int solve(const Node &u,const Node &v)
{
    int ans=0;
    for(ri i=x3; i<=x4; ++i)
    {
        ans=(ans-(LL)f(u,Node(i,y3-1))*(i+y3-1)%md*f(Node(i,y3),v)%md)%md;
        ans=(ans+(LL)f(u,Node(i,y4))*(i+y4)%md*f(Node(i,y4+1),v)%md)%md;
    }
    for(ri i=y3; i<=y4; ++i)
    {
        ans=(ans-(LL)f(u,Node(x3-1,i))*(x3-1+i)%md*f(Node(x3,i),v)%md)%md;
        ans=(ans+(LL)f(u,Node(x4,i))*(x4+i)%md*f(Node(x4+1,i),v)%md)%md;
    }
    ans=ans*u.k*v.k;
    return ans;
}
signed main()
{
#ifdef M207
    freopen("in.in","r",stdin);
//  freopen("out.out","w",stdout);
#endif
    prework();
    for(ri i=1; i<=6; ++i) in(xx[i]); x3=xx[3],x4=xx[4];
    for(ri i=1; i<=6; ++i) in(yy[i]); y3=yy[3],y4=yy[4];
    p[1]=Node(xx[1]-1,yy[1]-1,1);
    p[2]=Node(xx[2],yy[1]-1,-1);
    p[3]=Node(xx[1]-1,yy[2],-1);
    p[4]=Node(xx[2],yy[2],1);
    p[5]=Node(xx[5],yy[5],1);
    p[6]=Node(xx[6]+1,yy[5],-1);
    p[7]=Node(xx[5],yy[6]+1,-1);
    p[8]=Node(xx[6]+1,yy[6]+1,1);
    int ans=0;
    for(ri i=1; i<=4; ++i)
        for(ri j=5; j<=8; ++j)
            ans=(ans+solve(p[i],p[j]))%md;
    ans=(ans+md)%md;
    out(ans);
    return 0;
}
// start fold
}
signed main()
{
    i207M::main();
    return 0;
}
// end fold

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> K;
    vector<ll> p(N);
    REP(i, N) {
        cin >> p[i];
        //p[i] = (p[i] + 1.0) / 2.0;
    }
    ll sum = 0;
    REP(i, K) {
        sum += p[i];
    }
    ll ans = sum;
    FOR(i, K, N) {
        sum += p[i] - p[i - K];
        ans = max(sum, ans);
    }
    ans += K;
    cout << setprecision(10) << double(ans) / 2.0 << endl;
}

Measured memory_bytes: 4820
#include<stdio.h>

int main()
{
 long long int A;
 long long int B;
 long long int C;
 long long int out;

 scanf("%lld %lld %lld",&A,&B,&C);
 if(C<=B-1) out = B+C;
 if((C>B-1)&&(C-B-1<=A)) out = B + C; 
 if((C>B-1)&&(C-B-1>A)) out = 2*B + 1+ A;

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

 return 0;
}


Measured memory_bytes: 128
#coding:utf-8
N = int(input())
ls_a  = list(map(int,input().split()))
avg = sum(ls_a)/N
min_l = 1e+6
for i,a in enumerate(ls_a):
    if abs(a-avg)<min_l:
        min_l = abs(a-avg)
        min_idx = i
print (min_idx)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>

#define ll long long
using namespace std;

ll mod = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<ll> sum(200010);
    int back = -1;
    vector<ll> ret(n + 1);
    ret[0] = 1;
    for (int i = 1; i <= n; i++) {
        ret[i] = ret[i - 1];
        int x;
        cin >> x;
        if (x == back)continue;
        ret[i] += sum[x];
        ret[i] %= mod;
        sum[x] += ret[i - 1];
        back = x;
    }

    cout << ret[n] << endl;
    return 0;
}

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

int main() {
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;  // 初期状態
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];  // 1-index にしておく

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;  // dist と dt の偶奇は一致する必要あり！
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408