akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<ll> v(n+2);
	rep(i,0,n)cin >> v[i];
	const ll inf = 1e17;
	vector<vector<ll>> dp(n+3, vector<ll>(3,-inf));
	dp[0][0] = v[0];
	dp[1][1] = v[1];
	dp[2][2] = v[2];
	rep(i,0,n){
		rep(j,0,3){
			gmax(dp[i+2][j], dp[i][j] + v[i+2]);
			if(j < 2 && i+3 < n){
				gmax(dp[i+3][j+1], dp[i][j] + v[i+3]);
			}
			if(j == 0 && i + 4 < n){
				gmax(dp[i+4][j+2], dp[i][j] + v[i+4]);
			}
		}
	}
	ll ans = -inf;
	if(n&1)gmax(ans, max(dp[n-1][2],max(dp[n-2][1], dp[n-3][0])));
	else gmax(ans, max(dp[n-1][1], dp[n-2][0]));
	cout << ans << '\n';
}


Measured memory_bytes: 15876
<?php

fscanf(STDIN, "%d", $n);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));

$m = [];
$m[] = abs($A[0] - 0);
for ($i = 1; $i < $n; ++$i) {
    $m[] = abs($A[$i] - $A[$i - 1]);
}
$m[] = abs($A[$n - 1] - 0);

$sum = array_sum($m);

for ($i = 0; $i < $n; ++$i) {
    $tmpsum = $sum;
    $tmpsum -= ($m[$i] + $m[$i + 1]);

    // A[i]を除外する
    // newA[i+1]分を追加する

    if ($i == 0) {
        $tmpsum += abs($A[$i + 1]);
    } else if ($i == $n - 1) {
        $tmpsum += abs($A[$i - 1]);
    } else {
        $tmpsum += abs($A[$i + 1] - $A[$i - 1]);
    }

    echo $tmpsum, PHP_EOL;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

ll INF = (1ll << 32);
double EPS = 1e-4;

int main() {
  ll N;
  cin >> N;
  vi t(N), v(N);
  for (ll i = 0; i < N; i++) {
    cin >> t[i];
  }
  for (ll i = 0; i < N; i++) {
    cin >> v[i];
  }

  vector<vector<double>> dp(N, vector<double>(101, -(double)INF));
  for (ll j = 0; j <= v[0]; j++) {
    if (N >= 2 && j > v[1]) {
      continue;
    }
    double x = (double)(j + t[0]) / 2;
    if (x < -EPS || x - EPS > t[0]) {
      continue;
    }
    if (x > v[0]) {
      dp[0][j] = max(dp[0][j], (double)t[0] * v[0] - (double)v[0] * v[0] / 2 - (double)(v[0] - j) * (v[0] - j) / 2);
    } else {
      dp[0][j] = max(dp[0][j], (double)x * x / 2 + (double)(t[0] - x) * (x + j) / 2);
    }
  }

  for (ll i = 1; i < N; i++) {
    for (ll k = 0; k <= min(v[i - 1], v[i]); k++) {
      for (ll j = 0; j <= v[i]; j++) {
        if (i < N - 1 && j > v[i + 1]) {
          continue;
        }
        double x = (double)(j - k + t[i]) / 2;
        if (x < -EPS || x - EPS > t[i]) {
          continue;
        }
        if ((double)k + x > v[i]) {
          dp[i][j] = max(dp[i][j], dp[i - 1][k] + t[i] * v[i] - (double)(v[i] - k) * (v[i] - k) / 2 - (double)(v[i] - j) * (v[i] - j) / 2);
        } else {
          dp[i][j] = max(dp[i][j], dp[i - 1][k] + (double)(x + k + k) * x / 2 + (double)(x + j + k) * ((double)t[i] - x) / 2);
        }
      }
    }
  }

  cout << fixed;
  cout << dp[N - 1][0] << endl;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int h, w, v;
	int n, i, r, c;
	
	while (1){
		scanf("%d %d %d", &h, &w, &v);
		
		if (w == 0 && h == 0 && v == 0){
			break;
		}
		
		scanf("%d", &n);
		c = 0;
		
		c = h * h + w * w;
		
		if (c > h * h + v * v){
			c = h * h + v * v;
		}
		if (c > v * v + w * w){
			c = v * v + w * w;
		}
		
		
		for (i = 0; i < n; i++){
			scanf("%d", &r);
			r = r * 2 * r * 2;
			
			if (c < r){
				puts("OK");
			}
			else{
				puts("NA");
			}
		}
	}
	
	return (0);
}
		
		
			

Measured memory_bytes: 584
s = input()
li = [i for i in s]
global ans
def cal(left, count, remaining):
    global ans
    if len(remaining) > 0:
        cal(left + "+" + remaining[0], count + int(remaining[0]), remaining[1:])
        cal(left + "-" + remaining[0], count - int(remaining[0]), remaining[1:])
    elif count == 7:
        ans = left

cal(li[0], int(li[0]), li[1:])
print(ans+"=7")

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define mod 1000000007
#define INF 100000000
#define fk first
#define sv second

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, a, b;
  cin >> x >> a >> b;

  int c = b - a;
  if (b <= a) {
    cout << "delicious";
  } else if (x < c) {
    cout << "dangerous";
  } else {
    cout << "safe";
  }
  cout << endl;
  return (0);
}

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

int main(){
  int x;
  cin >> x;
  int a[100001];
  for ( int i = 0; i <= 99; i++ ) a[i] = 0;
  for ( int i = 100; i <= 105; i++)a[i] = 1;
  for ( int i = 106; i <= x; i++){
    if ( a[i-100] + a[i-101] + a[i-102] + a[i-103] + a[i-104] + a[i-105] >= 1){
      a[i] = 1;
    } else {
      a[i] = 0;
    }
  }

  cout << a[x] << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i%2==0) {
			if(s[i]!='R'&&s[i]!='U'&&s[i]!='D') {
				cout<<"No"<<endl;
				return 0;
			}
		}
		else {
			if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
n = int(input())
a  = list(map(int, input().split()))
ans = True
for i in a:
    if i % 2 == 0 and i % 3 != 0 and i % 5 != 0:
        ans = False
        break

if ans:
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 2940
a=int(input())#500
b=int(input())#100
c=int(input())#50
n=int(input())
co=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      go=500*i+100*j+50*k
      if go==n:
        co+=1
print(co)

Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
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 ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,a,b;cin >> k >> a >> b;
    if((a+k-1)/k*k<=b){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}

vector<ll> get_path(const vl &prev, ll t) {
    vector<ll> path;
    for (ll cur = t; cur != -1LL; cur = prev[cur]) {
        path.push_back(cur);
    }
    reverse(path.begin(), path.end()); // 逆順なのでひっくり返す
    return path;
}

int main(){
    ll n,m;cin >> n >>m;
    vvpl g(n);rep(i,m){
        ll a,b;cin >> a >> b;a--;b--;
        g[a].pb({b,1});
    }
    vl ans;ll len=inf;
    rep(i,n){
        vl prev(n,-1);
        vl d(n,inf);pqueue(pl) que;
        que.push({0,i});d[i]=0;
        while(!que.empty()){
            pl p=que.top();
            que.pop();
            ll v=p.se;
            if(d[v]<p.fi)continue;
            rep(i,g[v].size()){
                pl ed=g[v][i];
                if(d[ed.fi]>d[v]+ed.se){
                    prev[ed.fi]=v;
                    d[ed.fi]=d[v]+ed.se;
                    que.push({d[ed.fi],ed.fi});
                }
            }
        }
        rep(j,n){
            for(auto nv:g[j])if(nv.fi==i)if(chmin(len,d[j]+1))ans=get_path(prev,j);
        }
    }
    if(ans.empty())cout << -1 <<endl;
    else {
        cout << ans.size() <<endl;
        for(auto p:ans)cout << p+1 <<endl;
    }
}


Measured memory_bytes: 3688
#include <iostream>
#include <string>
#include <set>

using namespace std;

set<string> data;
int n, m;

main(){
  cin >> n;
  for(int i=0;i<n;i++){
    string in;
    cin >> in;
    data.insert(in);
  }
  cin >> m;
  int open = 0;
  for(int i=0;i<m;i++){
    string in;
    cin >> in;
    if(data.find(in) != data.end()){
      cout << (open ? "Closed by" : "Opened by") << ' ' << in << endl;
      open = 1 - open;
    }else cout << "Unknown" << ' ' << in << endl;
  }
}

Measured memory_bytes: 1232
//---------------prashant Sharma------------

#include<bits/stdc++.h>

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cerr << #x << " is " << x << endl;
#define endl                           '\n'

using namespace std;

int main()
{

  string s;
  cin>>s;
  ll i,j;
  ll n;
  n=s.size();
  ll a[n];
  rep(i,0,n)
  {
      a[i]=0;
  }
  ll c=0;
  if(s[i]=='B')
  c=1;
  a[0]=0;
  rep(i,0,n)
  {
     a[i]=c;
     if(s[i]=='B')
     c++;
  }
  ll ans=0LL;
  rep(i,0,n)
  {
      if(s[i]=='W')
      {
          ans+=a[i];
      }
  }
  cout<<ans;
   return 0;
}

Measured memory_bytes: 2180
#include <iostream>
using namespace std;
int main()
{
    int i, a;
    cin >> i;
    a = 0;
    for(int n=1; n<=i; n++)
    {
        if(n<10 || (n>=1e2&&n<1e3) || (n>=1e4&&n<1e5))
            a++;
        else if((n>=10&&n<100) || (n>=1e3&&n<1e4) || n==1e5)
            continue;
    }
    cout << a <<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INT long long
using namespace std;
INT a, b, t[110][110];
int main(){
    ios::sync_with_stdio(false);
    cin>>a>>b;
    for(int i = 0 ; i < 50 ; i++ ) for(int j = 0 ; j < 100 ; j++ ) t[i][j] = 1;
    a--, b--;
    while( b ){
        for(int i = 2 ; b and i < 49 ; i+=2 ) for(int j = 2 ; b and j < 98 ; j+=2 )
            t[i][j] = 0, b--;
    }
    while( a ){
        for(int i = 51 ; a and i < 98 ; i+=2 ) for(int j = 2 ; a and j < 98 ; j+=2 )
            t[i][j] = 1, a--;
    }
    cout<<100<<" "<<100<<endl;
    for(int i = 0 ; i < 100 ; i++ ){
        for(int j = 0 ; j < 100 ; j++ )
            if( t[i][j] ) cout<<".";
            else cout<<"#";
        cout<<endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
const long long int MOD = 1e9 + 7;
int cnt[1001];
bool isprime[1001];
vector <int> prime;
 
void eratos()
{
	memset(isprime,true,sizeof(isprime));
 
	for(int i=2;i<=1000;i++)
	{
		if(isprime[i])
		{
			for(int j=2*i;j<=1000;j+=i)
			{
				isprime[j] = false;
			}
			prime.push_back(i);
		}
	}
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	int n;
 
	cin >> n;
 
	eratos();
 
	memset(cnt,0,sizeof(cnt));
 
	for(int i=1;i<=n;i++)
	{
		int x = i;
		for(int j=0;j<prime.size();j++)
		{
          	if(x==1)
            {
              break;
            }
			while(1)
			{
				if(x%prime[j]!=0)
				{
					break;
				}
				x/=prime[j];
				cnt[prime[j]]++;
			}
		}
	}
 
	long long int res = 1;
	for(int j=0;j<prime.size();j++)
	{
		res = (res)*(cnt[prime[j]]+1);
		res%=MOD;
	}
 
	cout << res << '\n';
 
	return 0;
}

Measured memory_bytes: 256
n,m,k=map(int, input().split( ))
F = [tuple(map(int, input().split( ))) for _ in range(m)]
B = [tuple(map(int, input().split( ))) for _ in range(k)]
Fx = [[] for i in range(n+1)]
Bx = [[] for i in range(n+1)]
for a,b in F:
    Fx[a].append(b)
    Fx[b].append(a)
for a,b in B:
    Bx[a].append(b)
    Bx[b].append(a)
#友達関係での連結成分で分解
#連結成分中から2つ選ぶ場合の数から友達関係とブロック関係を引く
#各人ごと
#https://tjkendev.github.io/procon-library/python/union_find/union_find.html
*p, = range(n+1)
rank = [1]*(n+1)
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    rx = rank[px]; ry = rank[py]
    if ry < rx:
        p[py] = px
    elif rx < ry:
        p[px] = py
    else:
        p[py] = px
        rank[px] += 1
    return 1
for a,b in F:
    unite(a,b)
dic = {}
for i in range(1,n+1):
    if root(i) in dic:
        dic[root(i)] +=1
    else:
        dic[root(i)] = 1
for i in range(1,n+1):
    ans = dic[root(i)]-1
    for b in Fx[i]:
        if root(b)==root(i):
            ans-=1
    for b in Bx[i]:
        if root(b)==root(i):
            ans-=1
    print(ans,end=" ")


Measured memory_bytes: 127832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Circle
{
    class Program
    {
        static void Main(string[] args)
        {
            double r = double.Parse(Console.ReadLine());
            Console.WriteLine("{0:f10} {1:f10}", r * r * Math.PI, 2 * r * Math.PI);
        }
    }
}


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

int main(){
    char s[20], t[20];
    scanf("%s%s", s, t);
    if(strlen(s)+1 != strlen(t)){
        printf("No\n");
        return 0;
    }
    for(int i = 0; i < strlen(s); i++){
        if(s[i]!=t[i]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 1616
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)

int main() 
{		
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	long long int a,b;
	cin>>a>>b;
	cout<<((a*(a-1))/2)+((b*(b-1))/2);
	
	return 0;	
}

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

const size_t MAX_N = 5005, MAX_K = 5005;

bool dp[2][MAX_N][MAX_K], nece[MAX_N];
int a[MAX_N];
vector<int> vc[MAX_N];

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    sort(a + 1, a + n + 1);
    for (; a[n] >= k; n--) { }

    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < k; j++) dp[0][i][j] = dp[0][i - 1][j];
        for (int j = a[i]; j < k; j++) dp[0][i][j] |= dp[0][i - 1][j - a[i]];
    }
    dp[1][n + 1][0] = 1;
    for (int i = n; i >= 1; i--) {
        for (int j = 0; j < k; j++) dp[1][i][j] = dp[1][i + 1][j];
        for (int j = a[i]; j < k; j++) dp[1][i][j] |= dp[1][i + 1][j - a[i]];
    }

    for (int i = 0; i <= n; i++)
        for (int j = 0; j < k; j++)
            if (dp[0][i][j]) vc[i].emplace_back(j);

    for (int i = 1; i <= n; i++)
        for (int j = 0; j < k; j++)
            if (dp[1][i + 1][j]) {
                int en = upper_bound(vc[i - 1].begin(), vc[i - 1].end(),
                                     k - j) - 1 - vc[i].begin();
                int st = lower_bound(vc[i - 1].begin(), vc[i - 1].end(),
                                     k - a[i] - j) - vc[i].begin();
                if (en >= st) {
                    nece[i] = true;
                    break;
                }
            }

    int res = 0;
    for (int i = 1; i <= n; i++) res += !nece[i];
    cout << res;
}

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

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
#define x first
#define y second
#define mp make_pair

const int MAXN = (int)1e5;
int n, sol[MAXN + 5], maxi = 0;
vector <pii> ms[MAXN + 5];

void dfs(int x, int p){
	int taj = 0;
	for(vector <pii>::iterator i = ms[x].begin() ; i != ms[x].end() ; ++i){
		pii o = *i;
		if(o.x == p){
			taj = sol[o.y];
			break;
		}
	}
	int sad = 1;
	for(vector <pii>::iterator i = ms[x].begin() ; i != ms[x].end() ; ++i){
		pii o = *i;
		if(o.x == p)
			continue;
		if(sad == taj)
			sad++;
		sol[o.y] = sad;
		maxi = max(maxi, sad);
		sad++;
	}
	for(vector <pii>::iterator i = ms[x].begin() ; i != ms[x].end() ; ++i){
		pii o = *i;
		if(o.x == p)
			continue;
		dfs(o.x, x);
	}
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0 ; i < n - 1 ; ++i){
	int x, y;
	cin >> x >> y;
	ms[x].push_back(mp(y, i));
	ms[y].push_back(mp(x, i));
}
dfs(1, -1);
cout << maxi << endl;
for(int i = 0 ; i < n - 1 ; ++i){
	cout << sol[i] << endl;
}

return 0;
}



Measured memory_bytes: 7552
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,sum=0;
  cin>>N;
  vector<int> A(N);
  for(int &i:A){
    cin>>i;
    sum+=i;
  }
  cin>>M;
  while(M--){
    int P,X;
    cin>>P>>X;
    cout<<sum-A[P-1]+X<<endl;
  }
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#define INF 1e+9;
using namespace std;

int main() {
	int n,ma;
	int x[3000],y[3000];
	vector<int> pos;
	while(cin >> n,n){
		pos.clear();
		ma = 0;
		for(int i = 0;i < n;i++){
			cin >> x[i] >> y[i];
			pos.push_back(x[i] * 10000 + y[i]);
		}
		sort(pos.begin(),pos.end());
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(i == j) continue;
				int dx = x[j] - x[i],dy = y[j] - y[i];
				int kx = x[j] - dy,ky = y[j] + dx;
				int lx = kx - dx,ly = ky - dy;
				if(kx >= 0 && ky >= 0 && lx >= 0 && ly >= 0){
					if(upper_bound(pos.begin(),pos.end(),kx * 10000 + ky) - lower_bound(pos.begin(),pos.end(),kx * 10000 + ky) == 1 && upper_bound(pos.begin(),pos.end(),lx * 10000 + ly) - lower_bound(pos.begin(),pos.end(),lx * 10000 + ly) == 1){
						ma = max(ma,dx * dx + dy * dy);
					}
				}
			}
		}
		cout << ma << endl;
	}
	return 0;
}

Measured memory_bytes: 3152
// 2014/01/30 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int M, N;
	cin >> M >> N;

	int K;
	cin >> K;

	int J[1001][1001];
	int O[1001][1001];
	for(int y=0; y<=M; y++){
		J[y][0] = O[y][0] = 0;
	}
	for(int x=0; x<=N; x++){
		J[0][x] = O[0][x] = 0;
	}

	for(int y=1; y<=M; y++){
		for(int x=1; x<=N; x++){
			char c;
			cin >> c;

			J[y][x] = J[y-1][x]+J[y][x-1]-J[y-1][x-1];
			O[y][x] = O[y-1][x]+O[y][x-1]-O[y-1][x-1];

			if(c=='J'){
				J[y][x]++;
			}
			else if(c=='O'){
				O[y][x]++;
			}
		}
	}

	for(int i=0; i<K; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		int cnt_J = J[c][d]-J[a-1][d]-J[c][b-1]+J[a-1][b-1];
		int cnt_O = O[c][d]-O[a-1][d]-O[c][b-1]+O[a-1][b-1];
		int cnt_I = (c-a+1)*(d-b+1)-cnt_J-cnt_O;

		cout << cnt_J << ' ' << cnt_O << ' ' << cnt_I << endl;
	}

	return 0;
}

Measured memory_bytes: 8976
n = gets.chomp.split("").map(&:to_i)

if n.size == 1
    puts n[0]
    exit
end

if n[0] == 9 
    if n.count(9) != n.size
        n[0] = 8
        1.upto(n.size-1) {|i| n[i] = 9}
    end
else
    if n[1] != 9
        n[0] -= 1
        1.upto(n.size-1) {|i| n[i] = 9}
    elsif n.size > 2 && n.count(9) != n.size - 1
        n[1] -= 1
        2.upto(n.size-1) {|i| n[i] = 9}
    end
end

puts n.inject(:+)

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n,m,s,t;
graph a;
graph b;
set<lli> used;
priority_queue<vll,vector<vll>,greater<vll>> q;
vll sdist,tdist;
mat dist;

int main(){
  cin >> n >> m >> s >> t;
  for(lli i = 0;i < m;i++){
    lli _u,_v,_a,_b;
    cin >> _u >> _v >> _a >> _b;
    a[_u][_v] = a[_v][_u] = _a;
    b[_u][_v] = b[_v][_u] = _b;
  }
  sdist = vll(n+1);
  tdist = vll(n+1);
  q.push(vll({0,s}));
  while(!q.empty()){
    lli c = q.top()[0];
    lli p = q.top()[1];
    q.pop();
    if(used.count(p)) continue;
    used.insert(p);
    sdist[p] = c;
    for(auto y : a[p]){
      if(used.count(y.first) == 0) q.push(vll({c+y.second,y.first}));
    }
  }
  q.push(vll({0,t}));
  used = set<lli>();
  while(!q.empty()){
    lli c = q.top()[0];
    lli p = q.top()[1];
    q.pop();
    if(used.count(p)) continue;
    used.insert(p);
    tdist[p] = c;
    for(auto y : b[p]){
      if(used.count(y.first) == 0) q.push(vll({c+y.second,y.first}));
    }
  }
  for(lli i = 1;i <= n;i++){
    dist.push_back(vll({sdist[i]+tdist[i],i}));
  }
  sort(dist.begin(),dist.end());
  // for(lli i = 0;i < n;i++){
  //   cout << dist[i][0] << " " << dist[i][1] << endl;
  // }
  lli p = 0;
  for(lli i = 0;i < n;i++){
    while(dist[p][1] <= i) p++;
    cout << 1000000000000000ll-dist[p][0] << endl;
  }


}


Measured memory_bytes: 53056
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

inline void setin(string s) {
	freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
	freopen(s.c_str(), "w", stdout);
}

template <typename T> inline T range(T l, T r) {
	return uniform_int_distribution <T>(l, r)(rng);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 5e3 + 15;
int n, a[N];
vector <int> g[N];

int dp[N][2]; // dp[v][its_color] = min_sum_of_the_other_color

int temp[2][2][N]; // temp[i][color][val_of_the_color] = min_val

void dfs(int v) {
	for(int i = 0; i < g[v].size(); ++i)
		dfs(g[v][i]);
	int bit = 0;
	memset(temp, 0x3f, sizeof(temp));
	temp[1][0][0] = temp[1][1][0] = 0;
	for(int i = 0; i < g[v].size(); ++i) {
		int to = g[v][i];
		bit = i & 1;
		memset(temp[bit], 0x3f, sizeof(temp[bit]));
		for(int j = 0; j < 2; ++j) {
			if(dp[to][j] != inf) {
				int k = dp[to][j];
				for(int t = 0; t < N; ++t) {
					if(t + a[to] < N) {
						Min(temp[bit][j][t + a[to]], temp[bit ^ 1][j][t] + k);
					}
					if(t + k < N) {
						Min(temp[bit][j ^ 1][t + k], temp[bit ^ 1][j ^ 1][t] + a[to]);
					}
				}
			}
		}
	}
	if(g[v].empty())
		dp[v][0] = dp[v][1] = 0;
	else {
		for(int i = 0; i < 2; ++i)
			for(int j = 0; j < N; ++j) {
				if(j <= a[v])
					Min(dp[v][i], temp[bit][i ^ 1][j]);
				if(temp[bit][i][j] <= a[v])
					Min(dp[v][i], j);
			}
	}
}

main() {
	memset(dp, 0x3f, sizeof(dp));
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	// setin("input.txt");
	cin >> n;
	for(int i = 2; i <= n; ++i) {
		int p;
		cin >> p;
		g[p].pb(i);
	}
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	dfs(1);
	// cout << endl;
	// for(int i = 1; i <= n; ++i)
	// 	cout << a[i] << ' ' << dp[i][0] << ' ' << dp[i][1] << endl;
	if(dp[1][0] != inf || dp[1][1] != inf)
		cout << "POSSIBLE" << endl;
	else
		cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 1152
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007
 //----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int n,l;
	cin>>n>>l;
	int sum=0;
    int minn=INF;
	bool is_negative=false;
	for(int i=1;i<=n;i++)
	{
		int flavour=l+i-1;
		sum+=flavour;
		if(abs(flavour)<minn)
		{
			minn=abs(flavour);
			if(flavour<0)
				is_negative=true;
			else
				is_negative=false;
		}
	}
	sum=is_negative?sum+minn:sum-minn;
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class J { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	private long N;
	private long[] a;
	private bool[,,] flag;
	private double[,,] memo;

	public void Solve()
	{
		N = GetLong();
		a = GetLongs(N);
		flag = new bool[N + 1, N + 1, N + 1];
		memo = new double[N + 1, N + 1, N + 1];
		var cnt = Range(1, 3).Select(x => a.Count(y => y == x)).ToArray();
		WriteLine($"{rec(cnt[0], cnt[1], cnt[2]):F12}");
	}

	private double rec(long i, long j, long k)
	{
		if(flag[i, j, k])
			return memo[i, j, k];

		flag[i, j, k] = true;
		long s = i + j + k;
		if(s == 0)
			return (memo[i, j, k] = 0);

		double sum = (double)N;
		if(i > 0) sum += (double)i * rec(i - 1, j, k);
		if(j > 0) sum += (double)j * rec(i + 1, j - 1, k);
		if(k > 0) sum += (double)k * rec(i, j + 1, k - 1);
		return (memo[i, j, k] = sum / (double)s);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 151156
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define mod 1000000007
#define inf 9999999999999999ll
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    string s;
    cin>>n>>s;
    n%=26;
    vi a(s.size());
    for(ll i=0;i<s.size();i++)
    {
        a[i]=s[i]-'A';
    }
    for(ll i=0;i<s.size();i++)
    {
        a[i]+=n;
        a[i]%=26;
        s[i]=a[i]+'A';
    }
    cout<<s<<endl;
}


Measured memory_bytes: 384
n = int(input().strip())
s = input().strip()
ans = 0

for i in range(1, n, 1):
    a = s[:i]
    b = s[i:]
    rep = 0
    for word in "abcdefghijklmnopqrstuvwxyz":
        if word in a and word in b:
            rep += 1
    ans = max(ans, rep)
print(ans)


Measured memory_bytes: 39152
#include <stdio.h>

int main(void) {
    int n, a, b, res=0;
    scanf("%d %d %d", &n, &a, &b);

    for (int i = 0; i <= n; i++) {
        int t = 0;
        int j = i;
        while (j > 0) {
            t += j % 10;
            j = j / 10;
        }
        if ((t >= a) && (t <= b)) {
            res += i;
        }
    }

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

Measured memory_bytes: 128
def main():
    import math
    A, B, H, M = map(int, input().split())

    Sh = 360.0 * (H + M / 60.0) / 12.0
    Sm = 360.0 * M / 60.0
    S = 0.0
    #print (math.cos(90))
    #print (math.cos(0))
    #print (math.cos(math.pi / 2.0))
    if Sh == Sm :
        print(abs(A-B))
    elif Sh > Sm :
        S = Sh - Sm
        S = S * math.pi / 180.0
        c = (A * A + B * B - 2.0 * A * B * math.cos(S)) ** 0.5
        print(c)
    else :
        S = Sm - Sh
        S = S * math.pi / 180.0
        c = (A * A + B * B - 2.0 * A * B * math.cos(S)) ** 0.5
        print(c)

if __name__ == '__main__':
    main()


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int r; cin >> r;

    cout << r * r << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	int N; cin >> N;
	string s, t; cin >> s >> t;
	int overlap = N;
	while (overlap > 0) {
		if (s.substr(N - overlap, overlap) == t.substr(0, overlap))break;
		else overlap--;
	}
	cout << (2 * N - overlap) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;

typedef struct{
	long long a;
	long long b;
}Store;

int main() {

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

	long long n, m;
	cin >> n >> m;
	vector<Store> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i].a >> s[i].b;
	}

	sort(s.begin(), s.end(), [](Store& a, Store& b) {return a.a < b.a;});

	long long ans = 0;

	for (int i = 0; i < n; i++) {
		if (m > s[i].b) {
			m -= s[i].b;
			ans += s[i].b * s[i].a;
		}
		else {
			ans += s[i].a * m;
			m = 0;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define int long long

int n;
int a[1010];
int b[1010];

int memo[1010][10010];

int dp(int i, int h){
    if(h == 0) return 0;
    if(i == n) return INT_MAX;

    if(memo[i][h] != -1) return memo[i][h];

    return memo[i][h] = min(dp(i+1, h), dp(i, max(h-a[i], 0ll))+b[i]);
}

signed main(){
    int h;
    cin >> h >> n;

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

    memset(memo, -1, sizeof(memo));

    cout << dp(0, h) << endl;

    return 0;
}



Measured memory_bytes: 79744
#include <iostream>
#include <cmath>

using namespace std;

int n, k;

int check(int x, int cnt) {

    if (cnt >= n) {
        return x;
    } else {
        cnt++;
        return min(check(x + k, cnt), check(x * 2, cnt));
    }
    return x;
}

int main()
{
    cin >> n >> k;
    cout << check(1, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
//use proconio::marker::Usize1;
use proconio::marker::Chars;
//use std::collections::HashSet;
//use std::cmp::*;
fn main() {
    input! {
        n: usize,
        s: String
    }
    if n % 2 != 0 {
        println!("No");
        return;
    }
    if &s[..(n / 2)] == &s[(n / 2)..] {
        println!("Yes");
        return;
    }
    println!("No");
}


Measured memory_bytes: 2140
/*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    ll k, ans = 0; cin >> k;
    vector<ll> w(n);
    vector<ll> v(n);
    vector<vector<ll>> dp(n, vector<ll> (k + 1));
    for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
   	for(int i = w[0]; i < k + 1; i++) dp[0][i] = v[0];
   	for(int i = 1; i < n; i++) for(int j = 0; j < k + 1; j++)
   	{
   		dp[i][j] = dp[i - 1][j];
   		if(j - w[i] >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
   	}
   	for(int i = 0; i < k + 1; i++) ans = max(ans, dp[n - 1][i]);
   	cout << ans;

    return 0;
}


Measured memory_bytes: 79488
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
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;

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    REP(i, n) cin >> l[i];
    sort(ALL(l));
    int wa = 0;
    REP(i, n - 1) wa += l[i];
    if (wa > l[n - 1]) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    string num(n, 'x');
    for (int i = 0; i < m; i++)
    {
        int s, c;
        cin >> s >> c;
        s = n - s;
        char ch = '0' + c;
        if (num[s] != 'x' && num[s] != ch)
        {
            cout << -1 << endl;
            return 0;
        }
        else
        {
            num[s] = ch;
        }
    }
    if(num[n-1]=='x') num[n-1] = n == 1?'0':'1';
    for (int i = 0; i < n-1; i++)
    {
        if (num[i] == 'x')
        {
            num[i] = '0';
        }
    }
    reverse(num.begin(), num.end());
    string res = "";
    for (int i = 0; i < n; i++)
    {
        if (num[i] != '0')
        {
            while (i < n)
            {
                res.push_back(num[i]);
                i++;
            }
            break;
        }
    }
    if (res.length() == 0)
        res = "0";
    if (res.length() != n)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int x, cnt, ans;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for (int i = 0; i < 2; i++) {
        cin >> x;
        if (x == 1) {
            cnt++;
            ans += 300000;
        }
        if (x == 2) ans += 200000;
        if (x == 3) ans += 100000;
    }
    if (cnt == 2) ans += 400000;
    cout << ans << E;
    //system("pause");
    return 0;
}

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

class DSU {

      public :
      vector<int> par ;  
      vector<int> r ; 
      int ans = 0 ; 
      DSU(int n) {
            par.assign(n+1,0) ; 
            r.assign(n+1,0) ; 
            for(int i = 0 ; i <= n ; ++i) {
                  par[i] = i ; 
                  r[i] = 1  ; 
            }
      }
      
      int get(int n) {
            return par[n] = (par[n] ==n ? n : get(par[n])) ; 
      }

      void set_union(int a, int b) {
            a = get(a) ; 
            b = get(b) ; 
            if(a == b) 
            	return ; 
            if(r[a] > r[b]) {
                  swap(a,b) ;  
            }
            par[b] = a ; 
            r[a] += r[b] ; 
            ans = max(ans , r[a]) ; 
            ans = max(ans , r[b]) ;  
      }
      
}; 


int main() {
	
	#ifndef ONLINE_JUDGE
  		freopen("input.txt","r",stdin);
  		freopen("output.txt","w",stdout);
  	#endif 
  	
  	int n , m ; 
  	cin >> n >> m ; 
  	DSU fr(n) ; 
  	int a, b ; 
  	while(m--) {
  		cin >> a >> b  ; 
  		fr.set_union(a,b) ; 
  	}
  	int ans = 0 ; 
  	for(int i = 1 ; i <= n ; ++i) 
  		ans = max(ans, fr.r[i]) ; 
  	cout << ans  << "\n" ; 

  	return 0 ; 
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

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 ll INF=(ll)1e19;
//const int INF=(1<<30);

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

  ll n = 100;
  int cnt = 0;
  while(n < x){
    n = (ll)n * 1.01;
    cnt++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3632
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>

using namespace std;

int main(void)
{
	int a, b;
	string s;

	cin >> s;

	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'A')
		{
			a = i;
			break;
		}
	}

	for (int i = s.length() - 1; i > a; i--)
	{
		if (s[i] == 'Z')
		{
			b = i;
			break;
		}
	}

	cout << b - a + 1 << endl;

	return 0;
}

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

using namespace std;

#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define int long long
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define MOD 1000000007

const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};

int n, m, i;

signed main()
{
    fast_IO;
    int test = 1;
    // cin >> test;
    while(test--)
    {
        string s;
        cin >> n;
        cin >> s;
        int red = 0, white = 0;
        for(auto x: s)
        {
            if(x == 'R')
                red++;
            else
                white++;
        }
        int cnt = 0;
        for(i = 0; i < red; i++)
            if(s[i] == 'W')
                cnt++;
        cout << min({red, white, cnt});
        
    }
    return 0;
} 

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

int main(){
    int N, M;
    cin>>N>>M;
    int c[M][2];
    rep(i, M){
        cin>>c[i][0]>>c[i][1];
    }
    int count;
    rep(i, N){
        count=0;
        rep(j, M){
            if(c[j][0]==i+1||c[j][1]==i+1){
                count++;
            }         
        }
        cout<<count<<endl;
    }
}

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

int lis(vector<int> a){
    int n = a.size();
	int dp[n];
	fill(dp, dp + n, INT_MAX);
	rep(i,n) *lower_bound(dp, dp+n, a[i]) = a[i];
	return lower_bound(dp, dp+n, INT_MAX) - dp;
}
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    cout << lis(a) << endl;
}


Measured memory_bytes: 3952
N=int(input())
flag='Yes'
p,q,r=0,0,0
for _ in range(N):
  t,x,y=map(int,input().split())
  a=abs(x-p)+abs(y-q)
  e=t-r
  if a<=e:
    if (e-a)%2!=0:
      flag='No'
      break
  else:
    flag='No'
    break
  p,q,r=x,y,t
print(flag)

Measured memory_bytes: 9220
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

template <typename T, typename E> class SegmentTree {
  private:
    using F = function<T(T, T)>;
    using G = function<T(T, E)>;
    int sz;
    const T id;
    const F f;
    const G g;
    vector<T> dat;

  public:
    SegmentTree(F f, G g, T id) : f(f), g(g), id(id) {}
    void init(int n) {
        for(sz = 1; sz < n;)
            sz <<= 1;
        dat.assign(sz << 1, id);
    }
    void build(const vector<T> &v) {
        int n = v.size();
        init(n);
        for(int i = 0; i < n; i++)
            dat[sz + i] = v[i];
        for(int i = sz; --i;)
            dat[i] = f(dat[i << 1], dat[i << 1 | 1]);
    }
    void update(int k, E x) {
        k += sz;
        dat[k] = g(dat[k], x);
        while(k >>= 1)
            dat[k] = f(dat[k << 1], dat[k << 1 | 1]);
    }
    T query(int l, int r) const {
        T vl = id, vr = id;
        for(l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
            if(l & 1) vl = f(vl, dat[l++]);
            if(r & 1) vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }
};

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

    int N, Q;
    cin >> N >> Q;

    auto f = [](int a, int b) { return min(a, b); };
    auto g = [](int a, int b) { return b; };
    SegmentTree<int, int> seg(f, g, INT32_MAX);
    seg.init(N);

    int c, x, y;
    while(Q--) {
        cin >> c >> x >> y;
        if(c)
            cout << seg.query(x, y + 1) << "\n";
        else
            seg.update(x, y);
    }
}


Measured memory_bytes: 3804
import math

INF = float("inf")

# Check

def good(N, A):
    even = 0
    zero = 0
    c = 0

    ans = 0
    for i in A:
        if i < 0:
            c += 1
        elif i == 0:
            even = 0
            c = 0
        else:
            if c % 2 != 0:
                even += 1
            c = 0
        ans += abs(i)

    if c != 0 and c % 2 != 0:
        even += 1

    if even % 2 == 0:
        print(ans)
    else:
        print(ans - min([abs(i) for i in A if abs(i) > 0]) * 2)


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

    dp[0][0] = 0
    dp[0][1] = -INF

    for i in range(N):
        dp[i+1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
        dp[i+1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])

    print(dp[N][0])
    # good(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 72736
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

void print_vec(vector<int> A, int n) {
	Rep(i, n) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

int main() {
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 1; i <= n; i++) {
		A[i - 1] = i;
	}
	do {
		print_vec(A, n);
	} while (Next_permutation(A));
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,k,sum=0;
    cin >> n >> k;
    int p[n];
    for (int i=0;i<n;i++)
    {
        cin >> p[i];
    }
    sort(p,p+n);
    for(int i=0;i<k;i++)
    {
        sum+=p[i];
    }
cout << sum;
return 0;
}



Measured memory_bytes: 3168
from collections import defaultdict

n = int(input())
box = list(map(int, input().split()))
c = defaultdict(int)
for b in box:
    c[b] += 1
    
anss = sum([int(1/2 * c[k] * (c[k] - 1)) for k in c.keys()])
for b in box:
    fi = anss - int(1/2 * c[b] * (c[b] - 1)) + int(1/2 * (c[b]-1) * (c[b] - 2)) 
    print(fi)


Measured memory_bytes: 26772
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();
		int H[]= new int[N];
		double Max = Integer.MAX_VALUE;
		int answer = 0;
		for(int i=0; i<N; i++) {
			H[i] = sc.nextInt(); //N個の標高の入力
			double ave = T - H[i] * 0.006; //平均気温
			if(Max>Math.abs(A-ave)) {
				Max = Math.abs(A-ave);
				answer = i+1;
			}
		}
		System.out.println(answer);
		
	}
}

Measured memory_bytes: 24404