akhauriyash/Code-Regression huggingface dataset:
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x); x=((x)*(x));n=n/2;}return result;}



int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ld a[n];
	rep(i,0,n) cin >> a[i];
	sort(a,a+n);
	for(ll i=0; i<n-1; i++){
		a[i+1]=(ld)(1.0*(a[i]+a[i+1])/2);
	}
	//trace1(ans);
	cout << fixed << setprecision(20) << a[n-1];
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    string s; cin >> s;
    int num = s.size()-2;
    cout << s[0] << num << s[s.size()-1] << endl;

    return 0;
}

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

result = [-1] * (N + 1)
edge_from = [[] for _ in range(N + 1)]
edge_to = [[] for _ in range(N + 1)]

for _ in range(N - 1 + M):
    A, B = map(int, input().split())
    edge_from[B].append(A)
    edge_to[A].append(B)

parent = []
for i in range(1, N + 1):
    if any(edge_to[i]) and not any(edge_from[i]):
        parent.append(i)
        result[i] = 0
        break

while True:
    next_ = []
    for p in parent:
        for child in edge_to[p]:
            edge_from[child].remove(p)
            if not any(edge_from[child]):
                result[child] = p
                next_.append(child)
    if not any(next_):
        break
    parent = next_

for x in result[1:]:
    print(x)


Measured memory_bytes: 35344
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
int n,ls[30],mx1,mx2,x,c[30];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=26;i++)scanf("%d",&c[i]);
    for(int i=1;i<=n;i++)
    {
        mx1=0,mx2=1;
        for(int j=1;j<=26;j++)
        {
            scanf("%d",&x);
            if(mx1<(i-ls[j])*c[i])mx1=(i-ls[j])*c[i],mx2=j;
            else if(mx1==(i-ls[j])*c[i])if(ls[j]<ls[mx2])mx2=j;
        }
        //printf("[%d]",mx1);
        ls[mx2]=i;
        printf("%d\n",mx2);
    }
}


Measured memory_bytes: 3736
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

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

	int n,m;
	cin>>m>>n;
	cmin(m,n);
	vi in(n);
	rep(i,n)cin>>in[i];
	sort(all(in));
	vi t;
	rep(i,n-1)t.pb(in[i+1]-in[i]);
	sort(all(t));
	int out=0;
	rep(i,n-m)out+=t[i];
	cout<<out<<endl;
}





Measured memory_bytes: 2168
#include<stdio.h>                                       
                                                        
signed main()                                           
{                                                       
  char s[1024];                                         
                                                        
  scanf("%s",s);                                        
                                                        
  if( s[0] == s[1] && s[1] == s[2] ) puts("Yes");       
  else if( s[1] == s[2] && s[2] == s[3] ) puts("Yes");  
  else puts("No");                                      
                                                        
  return 0;                                             
}                                                       

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

int gcd(int a, int b){
    if(a < b){
        return gcd(b,a);
        // swap(a,b);
    }
    if(b == 0){
        return a;
    } else {
        return gcd(b,a%b);
    }
}

int main(){
    int a,b;
    while(cin >> a >> b){
        int g =gcd(a,b);
        cout << g << " " << (a / g) * b << endl;
    }
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
int f(int x) {
    int ans = 0;
    while(x%2==0) {
        x /= 2;
      	ans++;
    }
    return ans;
}
int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        ans += f(a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A , B;
  cin >> A >> B;
  if((A == 1 && B == 2)||(A == 2 && B == 1)){
    cout << 3 << endl;
    }
  if((A == 1 && B == 3)||(A == 3 && B == 1)){
    cout << 2 << endl;
    }
  if((A == 3 && B == 2)||(A == 2 && B == 3)){
    cout << 1 << endl;
    }
}

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

int main(){
	int i,n,j;
	cin>>n;
	vector<double> p(n+1);
	for(i=1; i<=n; ++i)
		cin>>p[i];
	vector<double> dp(n+1,0);
	dp[0]=1;
	for(i=1; i<=n; ++i){
		for(j=i; j>=0; --j){
			dp[j]=dp[j]*(1-p[i]);
			if(j>0)
				dp[j]+=dp[j-1]*p[i];
		}
		//for(int k=0; k<=n; k++)
			//cerr<<dp[k]<<" ";
		//cerr<<"\n";
	}
	double ans=0;
	for(i=n/2+1; i<=n; ++i)
		ans+=dp[i];
	cout << setprecision(10) << ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
const int N = 400005;

inline int input() {
	int x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

inline void chkmin(int &x, int y) { x = x < y ? x : y; }

int n, m;
int a[N], b[N], du[N];
int head[N], ne[N], to[N], cnte = 1;
int ans[N], tot, stk[N], top;
bool vis[N], ins[N];

inline void AddEdge(int x, int y) {
	ne[++cnte] = head[x], head[x] = cnte, to[cnte] = y;
	ne[++cnte] = head[y], head[y] = cnte, to[cnte] = x;
}

void dfs(int u) {
	for (int i = head[u]; i; i = ne[i]) {
		if (vis[i]) continue;
		vis[i] = vis[i ^ 1] = true;
		dfs(to[i]);
	}
	ans[++tot] = u;
}

bool check() {
	int cnt = 0;
	dfs(1), reverse(ans + 1, ans + tot + 1);
//	for (int i = 1; i <= tot; ++i)
//		debug("%d\n", ans[i]);
	for (int i = 1; i <= tot; ++i) {
		if (ins[ans[i]]) {
			while (stk[top] != ans[i])
				ins[stk[top--]] = false;
			++cnt;
		} else {
			stk[++top] = ans[i];
			ins[ans[i]] = true;
		}
	}
	return cnt >= 3;
}

int main() {
#ifdef local
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
//	freopen("log", "w", stderr);
#endif
	ios::sync_with_stdio(false);

	cin >> n >> m;

	for (int i = 1; i <= m; ++i) {
		cin >> a[i] >> b[i];
		++du[a[i]], ++du[b[i]];
		AddEdge(a[i], b[i]);
	}

	for (int i = 1; i <= n; ++i)
		if (du[i] & 1) return puts("No"), 0;
	if (m - n >= 3) puts("Yes");
	else if (m - n == 2) puts(check() ? "Yes" : "No");
	else puts("No");
	return 0;
}

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

constexpr int MAX_N=100,MAX_W=10000;

int n,W;
int v[MAX_N],w[MAX_N];
int dp[MAX_W];

int main(){
    std::cin>>n>>W;

    for(int i=0;i<n;++i){
        std::cin>>v[i]>>w[i];
    }

    for(int i=w[0];i<=W;++i){
        dp[i]=dp[i-w[0]]+v[0];
    }

    for(int i=1;i<n;++i){
        for(int j=1;j<=W;++j){
            if(w[i]<=j){
                dp[j]=std::max(dp[j],dp[j-w[i]]+v[i]);
            }
        }
    }
    std::cout<<dp[W]<<std::endl;
    return 0;
}

Measured memory_bytes: 3156
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

signed main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll c=a+b;
    ll ans=0;
    ll m=n/c;
    ans+=m*a;
    ans+=min(n-m*c,a);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define mod 1000000007
#define ll long long

int r1,c1,r2,c2;
int st,la;
ll ans=0;

ll pow2(ll a,ll n){
  /*
  if(n==1) return a;
  if(n%2==0){
    return pow2(a*a%mod,n/2)%mod;}
  else{
    return a*pow2(a-1,n)%mod;}
  */
  ll x=1;
  for(a%=mod;n;n/=2) n&1 ? x=x*a%mod:0,a=a*a%mod;
  return x;
}

ll com(int n,int k){
  ll ans=1;
  for(int i=0;i<k;i++){
    ans = ans*(n-i)%mod*pow2(k-i,mod-2)%mod;}
  return ans;}

ll g(int r,int c){
  return com(r+1+c+1,r+1);
}

int main(){
  scanf("%d %d %d %d",&r1,&c1,&r2,&c2);

  ll ans = g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1);
  ans = (ans+mod)%mod;
  printf("%lld\n",ans);
}


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

int func (int n, int a) {

    int res = 0;
    while (n > 0) {
        res += n % a;
        n /= a;
    }

    return res;
}

int main () {

    int N;
    cin >> N;

    int res = N;
    for (int i = 0; i <= N; i++) {
        int tmp = func(i, 6) + func(N - i, 9);
        res = min(res, tmp);
    }

    cout << res << endl;

    return 0;
}

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

ll multi_p(ll a, ll n, ll p) {
  if (n == 1) return a;
  if (n % 2) return (a * multi_p(a, n-1, p)) % p;
   
  ll t = multi_p(a, n/2, p);
  
  return (t * t) % p;
}

const ll MOD = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  ll sum = 0;
  
  for (int i = 0; i < N; i++) {
    sum += A[i];
    sum %= MOD;
  }
  
  ll sum1 = (sum * sum) % MOD; 
  
  ll sum2 = 0;
  for (int i = 0; i < N; i++) {
    sum2 += A[i] * A[i];
    sum2 %= MOD;
  }
  
  ll ans = (sum1 - sum2 + MOD) * multi_p(2, MOD-2, MOD);
  ans %= MOD;
  cout << ans << endl;
  
  
}

Measured memory_bytes: 4768
program aaa
implicit none

integer :: h, w, x, y, i, res
integer,allocatable,dimension(:,:) :: a

read*, h, w
allocate(a(h,w))
read*, x, y

a=0
res=0

do i=1,x
a(i,:)=1
end do
do i=1,y
a(:,i)=1
end do

write(*,'(i0)') h*w-sum(a)

end program

Measured memory_bytes: 384
import sys

# after これ通る？コピペs


def solve(n, k, aaa):
    MOD = 10 ** 9 + 7

    if n == k:
        ans = 1
        for a in aaa:
            ans = ans * a % MOD
        return ans

    pos = []  # Strictly, Non-neg
    neg = []
    for a in aaa:
        if a >= 0:
            pos.append(a)
        elif a < 0:
            neg.append(a)

    if len(pos) == 0:
        if k % 2 == 1:
            neg.sort(reverse=True)
        else:
            neg.sort()
        ans = 1
        for a in neg[:k]:
            ans = ans * a % MOD
        return ans

    pos.sort()
    neg.sort(reverse=True)
    ans = 1
    r = k

    if r % 2 == 1:
        ans = ans * pos.pop() % MOD
        r -= 1

    while r > 0:
        if len(pos) <= 1:
            ans = ans * neg.pop() * neg.pop() % MOD
        elif len(neg) <= 1:
            ans = ans * pos.pop() * pos.pop() % MOD
        else:
            pm = pos[-1] * pos[-2]
            nm = neg[-1] * neg[-2]
            if pm > nm:
                ans = ans * pos.pop() * pos.pop() % MOD
            else:
                ans = ans * neg.pop() * neg.pop() % MOD
        r -= 2

    return ans


n, k, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, k, aaa))


Measured memory_bytes: 111212
n=int(input())
F=[int(input().replace(' ',''),2) for i in range(n)]
P=[list(map(int,input().split())) for i in range(n)]
ans=-10**9
for i in range(1,1<<10):
    r=0
    for j in range(n):
        r+=P[j][str(bin(i&F[j])).count('1')]
    ans=max(ans,r)
print(ans)

Measured memory_bytes: 3064
import sys
from collections import deque
import copy
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

h, w = na()
g = [[1]*(w+2)]
for _ in range(h):
    g += [[1] + [1 if s=="#" else 0 for s in ns()] +[1]]
g += [[1]*(w+2)]
inf = 10**9
def bfs(sx, sy):
    dist = [[inf]*(w+2) for _ in range(h+2)] 
    dist[sx][sy] = 0
    que = deque([[sx, sy]])
    used = set([(sx, sy)])
    while que:
        x, y = que.popleft()
        for i, j in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            nx, ny = x+i, y+j
            if (nx, ny) in used:
                continue
            used.add((nx, ny))
            if g[nx][ny]==0:
                dist[nx][ny] = dist[x][y] + 1
                que.append([nx, ny])
    res = 0
    for i in range(h+2):
        for j in range(w+2):
            if g[i][j] == 0:
                res = max(res, dist[i][j])

    return res


ans = 0
for sx in range(1,h+1):
    for sy in range(1, w+1):
        if g[sx][sy]==0:  
            ans = max(ans, bfs(sx, sy))
print(ans)


Measured memory_bytes: 3568
import Data.List

main = do
  getLine
  getLine
  s <- getLine
  print $ solve4 s
 
solve4 xs = case group xs of
  ((_ : []) : ys) -> solve4' 'v' 3 ys
  ((_ : _ : []) : ys) -> solve4' 'h' 6 ys
  where
    solve4' d p = snd . foldl (\a b -> let t = solve4'' a b in (fst t, (`mod` 1000000007) $ snd t)) (d, p)
    solve4'' acc x = case acc of
        ('v', z)
          | length x == 1 -> ('v', 2 * z)
          | length x == 2 -> ('h', 2 * z)
        ('h', z)
          | length x == 1 -> ('v', z)
          | length x == 2 -> ('h', 3 * z)


Measured memory_bytes: 508
#include <iostream>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

void printVec(vector<string> &vec){
    for (auto it = vec.begin(); it != vec.end(); ++it){
        cout << *it << endl;
    }
}

int main(){
    int N;
    cin >> N;
    string S;
    vector<string> SV;

    for (int i = 1; i < N + 1; i++){
        cin >> S;
        SV.push_back(S);
    }   

    sort(SV.begin(), SV.end());
    SV.erase(unique(SV.begin(), SV.end()), SV.end());
    // printVec(SV);
    size_t size = SV.size();
    cout << size << endl;
    
    return 0;
}

Measured memory_bytes: 11664
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int a,b,c;
	cin>>a>>b>>c;
	
	if(a+b==c||b+c==a||c+a==b){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    int count = 0, ans = 0;
    
    std::cin >> n;
    
    for(int i = 1; i <= n; i += 2){
        count = 0;
        for(int j = 1; j <= i; j++){
            if(i % j == 0) count++;
            //std::cout << i << ' ' << j << ' ' << i % j << endl;
        }
        //std::cout << ':' << count << std::endl;
        if(count == 8) ans++;
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int d, n;
  cin >> d >> n;
  int mul = 1;
  if (d == 1)
    mul = 100;
  else if (d == 2)
    mul = 10000;

  if (n == 100)
    cout << mul * n + mul << endl;
  else
    cout << mul * n << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;

int main()
{
    int h,w; cin >> h >> w;
    int n; cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    int tmp = 1;
    int ans[h][w];
    rep(i,h) rep(j,w){
        if(a[tmp-1] == 0) tmp++;
        if(i%2 == 0) ans[i][j] = tmp;
        else ans[i][w-j-1] = tmp;
        a[tmp-1]--;
    }
    rep(i,h){
        rep(j,w) cout << ans[i][j] << ' ';
        cout << endl;
    }
}


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

inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}

using namespace std;

const int maxn = 1e5 + 50;

int n , sz[maxn] , Find , Root , Mi = 1e9 + 7;
long long ans = 0;
vector < pair < int , int > > Edge[maxn];

void Dfs( int u , int fa = 0 ){
	sz[u] = 1;
	for(auto it : Edge[u]){
		int v = it.first , c = it.second;
		if( v == fa )
			continue;
		Dfs( v , u );
		ans += 1LL * 2 * min( sz[v] , n - sz[v] ) * c;
		sz[u] += sz[v];
	}
}

void Dfs2( int u , int fa = 0 ){
	for(auto it : Edge[u]){
		int v = it.first;
		if( v == fa )
			continue;
		if( sz[v] == n - sz[v] ){
			Find = 1;
			ans -= it.second;
		}
		Dfs2( v , u );
	}
}

void Find_Root( int u , int fa = 0 ){
	int mx = n - sz[u];
	for(auto it : Edge[u]){
		int v = it.first;
		if( v == fa )
			continue;
		Find_Root( v , u );
		mx = max( mx , sz[v] );
	}
	if( mx < Mi )
		Mi = mx , Root = u;
}

int main( int argc , char * argv[] ){
	n = read();
	int Mi = 1e9 + 7;
	for(int i = 2 ; i <= n ; ++ i){
		int u = read() , v = read() , c = read();
		Edge[u].emplace_back( make_pair( v , c ) );
		Edge[v].emplace_back( make_pair( u , c ) );
		Mi = min( Mi , c );
	}
	Dfs( 1 , 0 );
	Dfs2( 1 , 0 );
	if( !Find ){
		Find_Root( 1 , 0 );
		int FF = 1 << 30;
		for(auto it : Edge[Root])
			FF = min( FF , it.second );
		ans -= FF;
	}
	printf( "%lld\n" , ans );
	return 0;
}

Measured memory_bytes: 12800
//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>


using namespace std;

void solve()
  {
	int n;
	cin>>n;
	string s;
	cin>>s;
	int w=0,cntw=0;
	repD(i,n-1,0)
	{
		if(s[i]=='W')w++;
	}
	repA(i,n-w,n-1)
	{
		if(s[i]=='W')cntw++;
	}
	cout<<w-cntw;

  }



signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	string s;
	cin>>s;
	ll k=0;
	FOR(i,0,ll(s.size()))
	{
		k+=ll(s[i]-'0');
	}
	cout<<(k%9 == 0?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 3732
def main():

    n, m = map(int, input().split())
    tree = [[]*n for i in range(n)]
    l = [list(map(int, input().split())) for _ in range(m)]
    
    for i in l:
        tree[i[0]-1].append(i[1]-1)
        tree[i[1]-1].append(i[0]-1)

    ver = [i for i in range(n)]

    cnt = 0

    def dfc(now, moved):
        
        nonlocal cnt
     
        moved.sort()
        if moved == ver:
            cnt += 1

        for i in tree[now]:
            if i in moved:
                continue
            dfc(i, moved + [i])

    dfc(0, [0])
    print(cnt)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin(),(c).end())
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { SORT(a); a.erase(unique(ALL(a)),a.end()); }
template <class S, class T> ostream& operator<<(ostream& os, const pair<S,T> a) {
  return os << a.first << ' ' << a.second;
}
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

string S;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> S;
  int n = S.size();
  int a = 0, b = 0;
  REP(i,n) {
    if (i % 2 == 0) {
      if (S[i] == '0') a++;
      else b++;
    } else {
      if (S[i] == '1') a++;
      else b++;
    }
  }
  cout << min(a,b) << endl;

  return 0;
}

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

int main() {
  int x;cin>>x;
  int ans=1;
  for(int i=2;i<=sqrt(x);i++){
    int a=i*i;
    while(a<=x){
      ans=max(ans,a);
      a*=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3548
#include<stdio.h>
#include<string.h>

int main(void)
{
    int i, j;
    int lenstr;
    char str[100];

    while (fgets(str, 100, stdin) != NULL) {
        j = 0;
        while (j++ < 26) {
            for (i = 0; i < strlen(str); i++) {
                if (str[i] >= 'a' && str[i] <= 'z') str[i] += 1;
                str[i] = str[i] > 'z' ? 'a' : str[i];
            }
            if (strstr(str, "the") != NULL || strstr(str, "this") != NULL || strstr(str, "that") != NULL) {
                printf("%s", str);
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;

public class Main{
    public static void main(String args[]){

    Scanner scan = new Scanner(System.in);

    
    //String n2 = scan.next();
    //String s = scan.next();

    int a = scan.nextInt();
    int b = scan.nextInt();

    int h = scan.nextInt();
    int m = scan.nextInt();

    double e1 = (h * 60 + m) * 0.5;
    double e2 = m * 360 / 60;

    double e = Math.abs(e1-e2);

    if (e>180){
        e = 360 - e;
    }

    //System.out.println(e);


    double r=Math.sqrt(Math.pow(a,2)+Math.pow(b,2)-2*b*a*Math.cos(Math.toRadians(e)));

    System.out.println(r);


      scan.close();
    }
  }

Measured memory_bytes: 35816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

void Main();

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
	return 0;
}

vector<int> counter(200000, 0);
vector<vector<int>> tree(200000, vector<int>());

void dfs(int node, int par){
	for(int child: tree[node]){
		if(child != par){
			counter[child] += counter[node];
			dfs(child, node);
		}
	}
}

void Main(){
	int n, q; cin >> n >> q;
	
	Rep(n-1){
		int a,b; cin >> a >> b;
		a--; b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	Rep(q){
		int p,x; cin >> p >> x;
		p--;
		counter[p] += x;
	}
	dfs(0,-1);
	rep(i,n){
		cout << counter[i] << ' ';
	}
}

Measured memory_bytes: 24236
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string S;

int main(void) {

	cin >> S;

	int N = S.size();

	int ans = 9999;

	for (int i = 0; i <= N - 1 - 2; i++) {
		int tmp = (S[i] - '0') * 100 + (S[i+1] - '0') * 10 + (S[i+2] - '0');
		ans = min(ans, abs(tmp - 753));
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int d[10]={0};

int han(int k){
	while(k>0){
		if(d[k%10]==1)return 1;
		k=(k-k%10)/10;
	}
	return 0;
}

int main(){
	int n,k,i,a;
	scanf("%d%d",&n,&k);
	for(i=0;i<k;i++){
		scanf("%d",&a);
		d[a]=1;
	}
	for(i=n;;i++){
		if(han(i)==0){
			printf("%d\n",i);
			return 0;
		}
	}
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().ToCharArray().Select(c => int.Parse(c.ToString())).ToArray();

            var array1 = new int[S.Length];
            var array2 = new int[S.Length];
            Set(array1, array2);

            Console.WriteLine(Math.Min(Count(S, array1), Count(S, array2)));
        }

        static void Set(int[] array1, int[] array2)
        {
            for (int i = 0; i < array1.Length; i++)
            {
                array1[i] = i % 2;
                array2[i] = (i + 1) % 2;
            }
        }

        static int Count(int[] S, int[] array)
        {
            return S.Zip(array, (s, t) => s != t).Count(b => b);
        }
    }
}


Measured memory_bytes: 15968
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

void solve() {
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m);
    for(int i = 0;i < m;i++){
       cin >> a[i];
    }
    sort(a.begin(),a.end());
    vector<ll> b(m-1);
    for(int i = 0;i< m-1;i++){
        b[i] = a[i+1]-a[i];
    }
    sort(b.begin(),b.end());
    ll ans = 0;
    for(int i = 0;i < m-n;i++){
        ans+=b[i];
    }
    
    cout << ans << endl;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;


int main()
{
	string s, t;
	string::iterator sit, tit;
	bool ans = false;

	cin >> s >> t;

	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());

	sit = s.begin();
	tit = t.begin();

	while (sit != s.end() && tit != t.end()) {
		if (*sit > * tit) {
			ans = false;
			break;
		}
		else if (*sit < *tit) {
			ans = true;
			break;
		}

		sit++;
		tit++;
	}
	if (sit == s.end() && tit != t.end()) ans = true;

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

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
	char S[101];
	long long K;
	int dummy;
	dummy = scanf("%s %lld", S, &K);
	
	int i;
	for (i = 0; S[i] != 0; i++) {
		if (S[i] != '1') break;
	}

	if (i < K) printf("%c\n", S[i]);
	else printf("%c\n", '1');

	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    ll a;
    string b;
    cin >> a >> b;
    int r = (b[2] - '0') * 10 + (b[3] - '0');
    ll ans = a * (b[0] - '0') + a * r / 100;
    cout << ans << "\n";
}


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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

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

const int N = (int)1e5 + 123, mod = (int)1e9 + 7, inf = (int)1e9;

ll n, x, ans = 1e18, a[N], b[N];
int main(){    
	cin >> n >> x;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		b[i] = a[i];
	}

	for(int i = 0; i <= n; i++){
		ll cur = 0;
		for(int j = 0; j < n; j++){
			b[j] = min(b[j], a[(j - i + n) % n]);
			cur += b[j];
		}
		ans = min(ans, cur + i * x);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
ans = [0 for i in range(n)]
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            a = x**2 + y**2 + z**2 + x*y + y*z + x*z
            if a <= n:
                ans[a-1] += 1
            else:
                break
for i in range(len(ans)):
    print(ans[i])


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int r=0;
 for(int i=0;i<n;i++){
     if(s.at(i)== 'R') r++;
     else r--;
 }  
 if(r>0) cout << "Yes" << endl;
 else cout << "No" << endl;
}


Measured memory_bytes: 256
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])
H = list(map(int, inputs[1].split()))

maximum = 0
count = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        count += 1
    else:
        if maximum < count:
            maximum = count
        count = 0
if maximum < count:
    maximum = count
    
print(maximum)

Measured memory_bytes: 15284
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include<cstdio>
#include <vector>
#include<queue>
#include<limits.h>
#include<string.h>
#include<functional>
#include<map>
#include<set>
#include<list>
#include<unordered_map>
using namespace std;

signed main(){
	unordered_map<int, bool>U;
	int a; cin >> a;
	while (a--) {
		int b; cin >> b;
		U[b] = true;
	}
	int ans = 0;
	cin >> a;
	while (a--) {
		int b; cin >> b;
		ans += U[b];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3116
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll ans=0;
	for(ll i=1; i<=n; i++){
		string s=to_string(i);
		if(s.size()%2==1) ans++;
	}
	cout << ans;
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))

int main() {

    int N;
    cin >> N;

    vector<long long> x(N), y(N), h(N);
    for (int i = 0; i < N; i++)cin >> x[i] >> y[i] >> h[i];

    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            int cx = i;
            int cy = j;
            int prex, prey, ch;
            for (int k = 0; k < N; k++) if (h[k] != 0) prex = x[k], prey = y[k], ch = h[k];
            int H = ch + abs(cx - prex) + abs(cy - prey);
            bool good = true;
            for (int k = 0; k < N; k++) if (C_MAX(H - abs(x[k] - cx) - abs(y[k] - cy), 0) != h[k]) good = false;
            if (good) {
                cout << cx << " " << cy << " " << H << endl;
                return 0;
            }
        }
    }

    return 0;
}




























Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while(true){
      int h = sc.nextInt();
      int w = sc.nextInt();
      if(h == 0 && w == 0) return;
      for(int i = 0; i<h; i++) {
        for(int j = 0; j<w; j++) {
          if(i%2 == 0){
            System.out.print(j%2 == 0 ? "#" : ".");
          }else{
            System.out.print(j%2 == 0 ? "." : "#");
          }
        }
        System.out.println();
      }
      System.out.println();
    }
  }
}

Measured memory_bytes: 35116
import numpy as np
from functools import reduce
from operator import add,sub,mul,truediv
from fractions import gcd
import itertools

n = int(input())


m = 0
a = 0
r = 0
c = 0
h = 0

x = ['m','a','r','c','h']

cnt = [0,0,0,0,0]
for i in range(n):
    s = str(input())
    if s[0] == 'M':cnt[0]+=1
    elif s[0] == 'A':cnt[1]+=1
    elif s[0] == 'R':cnt[2]+=1
    elif s[0] == 'C':cnt[3]+=1
    elif s[0] == 'H':cnt[4]+=1


ans = 0
for v in itertools.combinations(cnt,3):
    t = v[0] 
    for i in range(1,3):
        t*=v[i]

    ans+=t

print(ans)

Measured memory_bytes: 13540
import sys
def IL(): return map(int,sys.stdin.readline().rstrip().split())

if __name__=='__main__':
    n,k = IL()
    a = list(IL())
    l = n-k
    pre = b = 0
    for i in range(l):
        if a[i]<a[i+k]:
            print('Yes')
        else:
            print('No')
    exit()

Measured memory_bytes: 94260
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>
int max(int a, int b){return a>b?a:b;}
int min(int a, int b){return a<b?a:b;}
int gcd(int a, int b){return min(a,b)==0 ?max(a,b):gcd(min(a,b),max(a,b)%min(a,b));}
long long llmax(long long a, long long b){return a>b?a:b;}
long long llmin(long long a, long long b){return a<b?a:b;}
long long llgcd(long long a, long long b){return min(a,b)==0 ?max(a,b):gcd(min(a,b),max(a,b)%min(a,b));}
int assort(const void *a, const void *b){return *(int*)a-*(int*)b;}
int dessort(const void *a, const void *b){return *(int*)b-*(int*)a;}
int llassort(const void *a, const void *b){return *(long long*)a-*(long long*)b;}
int lldessort(const void *a, const void *b){return *(long long*)b-*(long long*)a;}
int charassort(const void *a, const void *b){return strcmp((char*)a ,(char*)b);}
int chardessort(const void *a, const void *b){return strcmp((char*)b ,(char*)a);}
char lowcmp[26]="abcdefghijklmnopqrstuvwxyz";
char upcmp[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int ntoi(char c){return c-'0';}
int ltoi(char c){return c-'a';}
int utoi(char c){return c-'A';}
long long mod=1000000007;

int main(void){
    int N,M,X,Y;
    scanf("%d%d%d%d",&N,&M,&X,&Y);
    int x,y,a=-120,b=120;
    for (int i=0; i<N; i++){
        scanf("%d",&x);
        a=max(x,a);
    }
    for (int i=0; i<M; i++){
        scanf("%d",&y);
        b=min(y,b);
    }
    if (max(a,X)<min(b,Y)){
        printf("No War\n");
    } else {
        printf("War\n");
    }
    return 0 ;
}

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

using namespace std;

int main(){
    string s , res = "CODEFESTIVAL2016";
    cin>>s;
    int c = 0 ;
    for(int i = 0 ; i < s.size() ; ++i){
        if(s[i] != res[i])c++;
    }
    cout<<c<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

void display(vector<int> &v){
  cout <<v[0];
  FOR(i, 1, v.size()) cout <<" " <<v[i];
  cout <<endl;
}

int selectionSort(vector<int> &v){
  int cnt = 0;
  REP(i, v.size()){
    int idx = i;
    FOR(j, i, v.size()) if(v[j] < v[idx]) idx = j;
    swap(v[i], v[idx]);
    if(i != idx) ++cnt;
  }
  display(v);
  return cnt;
}
 
int main() {
  int N; cin >>N;
  vector<int> v(N);
  REP(i, N) cin >>v[i];
  cout <<selectionSort(v) <<endl;
  return 0;
}

Measured memory_bytes: 1196
n = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0

# それぞれの頭文字から名前が始まる人をカウント
for i in range(n):
    s = input()
    if s[0] == "M":
        m += 1
    if s[0] == "A":
        a += 1
    if s[0] == "R":
        r += 1
    if s[0] == "C":
        c += 1
    if s[0] == "H":
        h += 1

D = []
D.append(m)
D.append(a)
D.append(r)
D.append(c)
D.append(h)
# 3人の名前の頭文字を選ぶ組み合わせ
P = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
Q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
R = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

ans = 0
for i in range(10):
    ans += D[P[i]] * D[Q[i]] * D[R[i]]
print(ans)


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

int main() {
	int A, B, K;
    cin >> A >> B >> K;
    int Kth = 1;
    int waru = min(A, B);
    int count = 0;
    while(true){

    		if((A % waru == 0) && (B % waru == 0)){
    			count++;
    			if(count == K) break;
    			waru--;
    		}else{
    			waru--;
    		}
    	
    }

	cout << waru << endl;

}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut xv = vec![0i32; n];
    for i in 0..n - 1 {
        xv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    xv[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let mut yv = xv.clone();
    yv.sort();
    let m1 = yv[n / 2 - 1];
    let m2 = yv[n / 2];
    for i in 0..n {
        println!("{}", if xv[i] <= m1 { m2 } else { m1 });
    }
}


Measured memory_bytes: 8316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  bool k=0;
  cin>>n;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    if(a==b)
      ans++;
    else
      ans=0;
    if(ans>=3)
      k=1;
  }
  if(k==1)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
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 COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


using Graph = vector<vector<int>>;
int N, Q;
Graph G;

void dfs(int v, int p, vector<long long> &res) {
  if (p != -1) res[v] += res[p];
  for (auto e : G[v]) {
    if (e == p) continue;
    dfs(e, v, res);
  }
}

int main() {
  cin >> N >> Q;
  G.assign(N, vector<int>());
  for (int i = 0; i < N-1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<long long> val(N, 0);
  for (int i = 0; i < Q; ++i) {
    int p, x;
    cin >> p >> x;
    --p;
    val[p] += x;
  }
  dfs(0, -1, val);
  for (auto v : val) cout << v << " ";
  cout << endl;
}

Measured memory_bytes: 24320