akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define N 22

double num[N][3];
int choose[N];
double ans;
int n, m;

double sqr(double n) {
	return n * n;
}

double max(double a, double b) {
	return a > b ? a : b;
}

void update() {
	double tmp = 0.0;
	for (int i = 0; i < m; i++) {
		for (int j = i + 1; j < m; j++) {
			for (int k = 0; k < 3; k++) {
				tmp += sqr( num[choose[i]][k] - num[choose[j]][k] );
			}
		}
	}
	ans = max(ans, tmp);
}

void DFS(int d, int s) {
	if (m - d > n - s) {
		return;
	} else if (d == m) {
		update();
	} else {
		for (int i = s; i < n; i++) {
			choose[d] = i;
			DFS(d + 1, i + 1);
		}
	}
}

int main () {
	while (scanf ("%d %d", &n, &m) != EOF) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				scanf ("%lf", &num[i][j]);
			}
		}
		ans = 0.0;
		DFS(0, 0);
		printf ("%.5f\n", ans);
	}
	return 0;
}

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

int main(){

 int x, y, z, t;

 cin >> x >> y >> z;

 if (x > y) {
  t = x;
  x = y;
  y = t;
 }

 if (y > z) {
  t = y;
  y = z;
  z = t;
 }

 if (x > y) {
  t = x;
  x = y;
  y = t;
 }

 cout << x << " " << y << " " << z << "\n";

 return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			switch (op) {
			case "+":
				System.out.println(a + b);
				break;
			case "-":
				System.out.println(a - b);
				break;
			case "*":
				System.out.println(a * b);
				break;
			case "/":
				System.out.println(a / b);
				break;
			default:
				break;
			}
			if (op.equals("?"))break;
		}
	}
}


Measured memory_bytes: 26416
require 'matrix'

def len3d(x, y)
  l2=0.0
  0.upto(3-1){|i|
    l2 += (x[i] - y[i])**2
  }
  return Math.sqrt(l2)
end

def heron(a,b,c)
  s = (a + b + c) / 2.0
  return  Math.sqrt(s*(s-a).abs*(s-b).abs*(s-c).abs)
end

Eps=1e-9
def insideTriangle(p,a,b,c)
# If the sum of the area of triangle PAC, PAB, PBC equals the are of the triangle ABC, the point P is inside triangle ABC.

  pa = len3d(a, p)
  pb = len3d(b, p)
  pc = len3d(c, p)
  ab = len3d(b, a)
  ac = len3d(c, a)
  bc = len3d(c, b)

  s0=heron(ab,ac,bc)
  s1=heron(pa,pc,ac)
  s2=heron(pa,pb,ab)
  s3=heron(pb,pc,bc)

  return  (s1+s2+s3-s0).abs <Eps
end

def solve(a,b,c,d,e)   # returns true if beam hits barrier.
  # a, b, c: Position vector of the barrier's apex triangle
  # d:Position vector of UAZ
  # e:Position vector of the enemy
  # Solve a + s*u + t*v = d + x*w. (0<x<1) if point P(d+xw)is in triangle ABC, the barrier repels the beam
  # returns true if repelled, else false
  u = c - a
  v = b - a
  w = e - d
  m = Matrix.columns([u, v, -w])

# As triangle ABC should not be seen as a line from d, then  if m does not have a  solution line de is parallell to ABC and not within the plane of ABC. That means beam will not be barriered.
  return false if m.determinant.abs <Eps

  parms = m.lup.solve(d - a)
  s = parms[0]
  t = parms[1]
  x = parms[2]
  # point P is the intersect of a plane which includes triangle ABC and a line betweenn D and E.
  return false if x < 0 or x > 1.0
  p = d + x*w
  return insideTriangle(p,a,b,c)

end

def main
  if true then
#  if false then
    fh=STDIN
  else
    #fh=open("in1_0115a.txt")
    #fh=open("in1_0115b.txt")
    #fh=open("in1_0115c.txt")
    fh=open("in1_0115d.txt")
  end
  d1,d2,d3=fh.gets.chomp.split.map{|x| x.to_i}
  e1,e2,e3=fh.gets.chomp.split.map{|x| x.to_i}
  a1,a2,a3=fh.gets.chomp.split.map{|x| x.to_i}
  b1,b2,b3=fh.gets.chomp.split.map{|x| x.to_i}
  c1,c2,c3=fh.gets.chomp.split.map{|x| x.to_i}

  d=Vector[d1,d2,d3]
  e=Vector[e1,e2,e3]
  a=Vector[a1,a2,a3]
  b=Vector[b1,b2,b3]
  c=Vector[c1,c2,c3]

  if solve(a,b,c,d,e) then
    puts "MISS"
  else
    puts "HIT"
  end

end

if $0 == __FILE__ then
  main
end

Measured memory_bytes: 9340
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdlib>

using namespace std;

int A[305][305];
int magic[90005];

map<int,pair<int,int> >mp;

int main() {

	int H,W,D;

	scanf("%d %d %d",&H,&W,&D);

	int i,j;

	for(i=1;i<=H;i++){
		for(j=1;j<=W;j++){
			scanf(" %d",&A[i][j]);
			mp[A[i][j]]=make_pair(i,j);
		}
	}

	for(i=1;i<=D;i++){
		for(j=i;j<=H*W;j+=D){
			if(j!=i){
				magic[j]=magic[j-D]+abs(mp[j].first-mp[j-D].first)+abs(mp[j].second-mp[j-D].second);
			}
		}
	}

	int Q;

	scanf("%d",&Q);

	for(i=0;i<Q;i++){
		int Li,Ri;
		scanf("%d %d",&Li,&Ri);
		printf("%d\n",magic[Ri]-magic[Li]);

	}

	return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
bool kaibun(int a, int b, string s) {
  string S = s.substr(a, b-a);
  string R = s.substr(a, b-a);
  reverse(R.begin(), R.end());
  if (S == R) {
    return true;
  }else{
    return false;
  }
}

int main() {
  string s;
  cin >> s;
  int N = s.size();
  if (kaibun(0, N, s) && kaibun(0, (N-1)/2, s) && kaibun((N+3)/2-1, N, s)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long freq[100005], n, q, b, c, t, sum;
int main() {
    cin >> n;
    while (n--) {
        cin >> t;
        freq[t]++;
        sum+=t;
    }
    
    cin >> q;
    while (q--) {
        cin >> b >> c;
        sum+=(c-b)*freq[b];
        freq[c]+=freq[b];
        freq[b]=0;
        cout << sum << "\n";
    }
}


Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
bool check(int x)
{
	int keta = 0;
	while (x) {
		keta++;
		x /= 10;
	}
	return keta % 2 == 1; //桁数が奇数ならtrueを返す
}
int main()
{
	int n;
	scanf("%d", &n);
	int ans = 0;
for(int i = 1; i <= n; i++) { //全探索
		if(check(i)) ans++; //桁数が奇数ならans++
	}
	printf("%d\n", ans);
	return 0;
}


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

typedef unsigned uint;
typedef long long INT;
typedef unsigned long long UINT;
const int INF = 1001001001;
const INT INFLL = 1001001001001001001LL;

 int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
INT lin() { INT x; scanf("%lld", &x); return x; }
UINT luin() { UINT x; scanf("%llu", &x); return x;}


int main(){
    int a, b, c;
    double fa, fb, fc;
    char S[128], sa[128], sb[128], sc[128];
    // int N = in();
    // int K = in();
    // scanf("%s", S);

    int A = in();
    int B = in();
    int H = in();
    int M = in();

    // std::vector<INT> vecA;
    // for (INT i = 0; i < N; ++i) {
    //     vecA.push_back(lin());
    // }

    double x = 30 * (H + M / 60.0);
    double y = 6 * M;

    double rad = abs(2 * acos(-1) * abs(x - y) / 360);

    double ans = sqrt(A * A + B * B - 2 * A * B * cos(rad));

    printf("%.16lf", ans);

    return 0;
}







Measured memory_bytes: 4256
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define MOD 1000000007LL
//#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[&](auto f,auto... args){return f(f,args...);};

int main(){
    lint n,h,w;
    cin>>n>>h>>w;
    lint ans=0;
    rep(i,n){
        lint s,t;
        cin>>s>>t;
        if(h<=s&&w<=t)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*


                 """Bismillahir Rahmanur Rahim"""

*/
#include<bits/stdc++.h>
using namespace std;
#define pi 2*acos(0.0)
#define ll long long int
#define inf 9223372034700
#define pb push_back
#define pf push_front
const ll sz = 1000001;
#define ek(x) __builtin_popcount(x)
#define ses '\n'
#define in(x) scanf("%lld",&x);
#define out(x) printf("%lld\n",x);
#define stm istringstream
#define all(x) x.begin(),x.end()
#define ghora ios_base::sync_with_stdio(0);cin.tie(0);
#define gcd __gcd
ll lcm(ll x,ll y)
{
    return (x*y)/gcd(x,y);
}
#define tin ll T;cin>>T; for(ll o=1;o<=T;o++)
#define tout cout<<"Case "<<o<<": ";
#define spc printf(" ");
ll n,m;
ll mod=1000000007;
char a[1002][1002];
ll dp[1002][1002];
bool valid(ll x,ll y)
{
    if(x>=0&&y>=0&&x<n&&y<m&&a[x][y]=='.')
        return true;
    else return false;
}
ll f(ll x,ll y)
{
   // cout<<x<<y<<ses;
    if(!valid(x,y))
        return 0;
    if(x==n-1&&y==m-1)
        return 1;
    if(dp[x][y]!=-1)
        return dp[x][y];
    ll yo=f(x,y+1);
    ll yo1=f(x+1,y);
    return dp[x][y]=((yo%mod)+(yo1%mod))%mod;
}
int main()
{
    //freopen ("input.txt","r",stdin);
    //freopen ("output.txt","w",stdout);
   cin>>n>>m;
   memset(dp,-1,sizeof(dp));
   for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++)
        cin>>a[i][j];
    cout<<f(0,0)<<ses;
    return 0;
}
/*   --------------------
    |      ~SOHAN~       |
    |   ~Chandler68~     |
     --------------------
    || VALAR MORGULIS||==|| ALL MEN MUST DIE ||
    \\ Power Is Power//
    || I Can Do This All day ||
    // We are on a Break \\ // How you doin'? \\
    || Say My Name || ~~ || I Am The Who Knocks ||
    // I Am Ted Mosby Architect \\
    || It Is Legen --wait for it -- dary ,Legendary ||
    \\ Penny - Penny - Penny // -- Bazinga

*/


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  for (int i = 0; i < 5; i++) {
    cout << a[i];
    if (i == 4) {
      cout << " ";
    }
  }
  for (int i = 6; i < 13; i++) {
    cout << a[i];
    if (i == 12) {
      cout << " ";
    }
  }
  for (int i = 14; i < 19; i++) {
    cout << a[i];
  }
       }

Measured memory_bytes: 3532
module Main (main) where

import qualified Data.ByteString.Char8     as C8
import           Data.Maybe

main :: IO ()
main = do
  [x,t] <- readInts
  putStrLn $ pretty $ solve (x,t)

type Input  = (Int, Int)
type Output = Int

solve :: Input -> Output
solve (x,t) = if y < 0 then 0 else y
  where
    y = x-t

pretty :: Output -> String
pretty = show

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

Measured memory_bytes: 380
$c=<>=~$";($\+=($_[$_-1]-$_[-$_])*$c)%=$%=1e9+7,$c=$c*$_%$%*($i[$j]=$j++?($%/$j|0)*-$i[$%%$j]%$%:1)%$%for$'..(@_=sort{$a-$b}glob<>);print

Measured memory_bytes: 31728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int a;
  a = 0;
  int b;
  b = N;
  int c = 0;
  for (int i=0; i < 9; i++){
    c = b;
    for (int j=0; j < 8-i; j++){
  c = c / 10;
    }
  a += c;
    for ( int k=0; k < 8-i; k++){
    c = 10 * c;
  }
    b = b - c;
  }
  while (N > 0){
    N = N - a;
  }
  if (N == 0){
  cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<ll> v;
ll n,a,b;

bool enough(ll t){
    ll count=0;
    for(ll i=0;i<n;i++){
        ll k=(v[i]-b*t);
        if(k<0){
            continue;
        }
        if(k%(a-b)==0){
            k/=(a-b);
        }
        else{
            k/=(a-b);
            k+=1;
        }
        count+=k;
    }
    return (count<=t);
}

int binarysearch(ll x,ll y){
    ll lo=x;
    ll hi=y;
    ll me=(lo+hi)/2;
    if(hi>lo+1){
        if(enough(me)==0){
            return binarysearch(me+1,hi);
        }
        else{
            return binarysearch(lo,me);
        }
    }
    else{
        if(enough(lo)==1)
            return lo;
        else
            return hi;
    }
}


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>a>>b;
    ll hmax=0;
    for(ll i=0;i<n;i++){
        ll h;
        cin>>h;
        v.pb(h);
        if(h>hmax)
            hmax=h;
    }
    hmax/=b;
    hmax+=1;
    ll ans=binarysearch(1,hmax);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1400
n = int(input())
#x, y = map(int,input().split())
#li = list(map(int, input().split()))

if n == 1:
    print(1)
if n >=2:
    if n%2 == 0:
        print(1/2)
    elif n%2 ==1:
        print((n+1)/(2*n))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int D;
vector<int> c(26); 
vector<vector<int>> s(365, vector<int>(26));

int cal_score(vector<int> t){
    int satis = 0;
    vector<int> last(26, 0);
    rep(d, D){
        satis += s[d][t[d] - 1];
        last[t[d] - 1] = d + 1;
        rep(i, 26){
            satis -= c[i] * (d - last[i] + 1);
        }
    }
    return satis;
}

int ch_sch(vector<int> t, int d, int q, int score){
    // change t[d - 1] -> q
    // calculate the score
    int old = t[d - 1];
    score -= s[d - 1][old - 1];
    score += s[d - 1][q - 1];

    int last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old ) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score += c[old - 1] * (i - last_old + 1);
        score += c[q - 1] * (i - last_new + 1);
    }

    t[d - 1] = q;

    last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score -= c[old - 1] * (i - last_old + 1);
        score -= c[q - 1] * (i - last_new + 1);
    }
    return score;
}

int main(){
    srand((unsigned)time(NULL));

    // input 
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }

    // greedy
    vector<int> last(26, 0);
    vector<int> res(D);

    rep(d, D){
        int max_plus = -10000;
        int use = -1;
        rep(i, 26){
            int tmp = s[d][i] + c[i] * (d - last[i] + 1);
            if(max_plus < tmp){
                max_plus = tmp;
                use = i;
            }
        }
        last[use] = d + 1;
        res[d] = use + 1;
    }

    int cur_score = cal_score(res);
    //int ch_d = 1;
    //int cnt = 0;

    while((clock() / (double)CLOCKS_PER_SEC) <= 1.98){
        // cnt++;
        int ch_d = rand() % D + 1;
        int ch_c = rand() % 26 + 1;
        // int ifch = rand() % 100;
        int new_score = ch_sch(res, ch_d, ch_c, cur_score);
        if(cur_score < new_score){
            cur_score = new_score;
            res[ch_d - 1] = ch_c;
            // ch_d--;
            // if(ch_d == 0) ch_d = D;
        }
    }

    rep(i, D){
        cout << res[i] << endl;
    }
    return 0;
}


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


using namespace std;

int gcd(int, int);

int main() {

    int a, b, x, y;
    cin >> a >> b;
    x = max(a, b);
    y = min(a, b);

    cout << gcd(a, b) << endl;


    return 0;
}

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


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

int main(){
  long long n,a[100010]={},b[100010]={},c[100010]={},d[100010]={};
  cin>>n;
  for(int i=1;i<=n;++i)cin>>a[i];
  for(int i=1;i<=n;++i)cin>>b[i];
  for(int i=1;i<=n;++i)cin>>c[i];
  sort(a,a+n+1);
  sort(b,b+n+1);
  sort(c,c+n+1);

  int p=1,q=1;
  while(q<=n){
    if(p>n){
        d[q]=0;
        q++;
    }
    else if(c[p]<=b[q]){
        p++;
    }
    else{
       d[q]=n-p+1;
       q++;
    }
  }

  for(int i=2;i<=n;++i){
    d[i]+=d[i-1];
  }

  p=1;q=1;
  while(q<=n){
    if(p>n){
        a[q]=0;
        q++;
    }
    else if(b[p]<=a[q]){
        p++;
    }
    else{
        a[q]=d[n]-d[p-1];
        q++;
    }
  }

  for(int i=2;i<=n;++i){
    a[i]+=a[i-1];
  }

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


Measured memory_bytes: 3328
from collections import Counter

cnt = Counter()
n = int(input())
for _ in range(n):
  h = float(input())
  if h < 165:
    cnt[1] += 1
  elif h < 170:
    cnt[2] += 1
  elif h < 175:
    cnt[3] += 1
  elif h < 180:
    cnt[4] += 1
  elif h < 185:
    cnt[5] += 1
  else:
    cnt[6] += 1

for k in (1, 2, 3, 4, 5, 6):
  print(k, "*" * cnt[k], sep=":")



Measured memory_bytes: 6004
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long 
#define pb push_back
#define fo(i,N) for(int i = 0 ; i < N ; i++)
#define foo(i,x,N) for (int i = x; i < N ; i++)
#define fill(a,val) memset(a,val,sizeof(a))
#define fastio()  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define MAX 1234567
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define inf 1e14+1
#define all(a) a.begin(),a.end()
int n;
vector <int> adj[100001];
int dp[100001][2];


ll solve(int cur,int par,int col)
{
 
  if ( dp[cur][col] != -1)
    return dp[cur][col];


  ll ans = 0;
  ll w1 = 1;
  
  for(int nxt : adj[cur])
  {
     if ( nxt != par)
      w1 = (w1*solve(nxt,cur,1))%M;
  }
  
  ans = w1;

  if (col)
  { 
    ll w2 = 1;
    for(int nxt : adj[cur])
    {
      if ( nxt != par)
      w2 = (w2*solve(nxt,cur,0))%M;
    }
    ans = (ans+w2)%M;
  }

   return dp[cur][col] = ans;

}

int main()
{ 
  cin >> n;
  
  int x,y;

  fo(i,n-1)
  {
    cin >> x >> y;
    adj[x].pb(y);
    adj[y].pb(x);
  }
  fill(dp,-1);

  cout << solve(1,-1,1) << endl;

  
}

Measured memory_bytes: 14848
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;

int n,x[110];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>x[i];
	int minv=INF;
	for(int i=1;i<=100;i++){
		int num=0;
		for(int j=1;j<=n;j++) num+=(x[j]-i)*(x[j]-i);
		minv=min(minv,num);
	}
	cout<<minv<<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N, M = map(int, input().split(' '))
switches = []
for _ in range(M):
    S = list(map(int, input().split(' ')))
    switches.append(S[1:])

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

ans = 0
def solve(buf):
    global ans

    if len(buf) == N:
        is_solve = True
        for i in range(M):
            n = sum([buf[j-1] for j in switches[i]])
            if (n%2) != P[i]:
                is_solve = False
                break

        if is_solve:
            ans += 1


    else:
        solve(buf + [0])
        solve(buf + [1])

solve([])
print(ans)

Measured memory_bytes: 43624
import sys

def solve():
    a = int(input())
    b = int(input())

    if a == b:
        print(1)
        return

    t = a ^ b
    N = bitlen(t)

    a = a & (2**N - 1)
    b = b & (2**N - 1)

    blen = bitlen(b)

    sb = b & (2**(blen - 1) - 1)

    sblen = bitlen(sb)

    s = 2**sblen - 1

    ymax = b | s

    T = 2**(N - 1)

    ans = T - a

    if ymax < T + a:
        ans += ymax + 1 - a
    else:
        ans += T

    print(ans)

def bitlen(x):
    return 1 + bitlen(x >> 1) if x else 0

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mxn 200005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
typedef long long int ll;
int bit[130][8];
using  namespace std;
int main(void){
	#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	fast;
	int n;
	cin>>n;
	if(n>=30)
	cout<<"Yes";
	else
	cout<<"No";
}


Measured memory_bytes: 3660
#include <iostream>
#include<string>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;


int main() {
	int A, B, C,tmp,output;
	cin >> A >> B >> C;
	tmp = A - B;
	output = C - tmp;

	if (output > 0) {
		cout << output;
	}
	else if (output <= 0) {
		cout << 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define all(obj) obj.begin(), obj.end()
#define debug(x) cerr << #x << ":" << x << "\n"
#define vdebug(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	string s, t; cin >> s >> t;
	ll l = s.size();	
	s += s; // 2倍にする
	vvi m(26); // i番目のアルファベットがsの何文字目に現れるか
	rep(i, 2 * l) m[s[i] - 'a'].push_back(i);
	int x = -1, y; // sの中での現在の位置，新しい位置
	bool f = true; // tを作れるか
	ll loop = 0; // sを初めから走査する回数
	
	for (char c : t) {
		auto itr = lower_bound(all(m[c - 'a']), x + 1); // sの中での新しい位置のイテレータ
		if (itr == m[c - 'a'].end()) {
			f = false;
			break;
		} else {
			y = *itr;	// これでよかった!		
			if (y < l) {
				x = y;
			} else if (y >= l) {
				x = y - l;
				loop++;
			}
		}		
	}
	if (f) cout << l * loop + x + 1 << endl;
	else cout << -1 << endl;
}

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

using namespace std;

int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();

    // 桁, 0以外の個数, キツイか
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(k + 1, vector<int>(2)));
    dp[0][0][true] = 1;
    for (int index = 0; index < n; index++) {
        for (int count = 0; count <= k; count++) {
            for (int num = 0; num <= 9; num++) {
                if (num == 0) {
                    dp[index + 1][count][s[index] == '0'] += dp[index][count][true];
                    dp[index + 1][count][false] += dp[index][count][false];
                } else if (count + 1 <= k) {
                    if (s[index] - '0' > num) dp[index + 1][count + 1][false] += dp[index][count][true];
                    else if (s[index] - '0' == num) dp[index + 1][count + 1][true] += dp[index][count][true];
                    dp[index + 1][count + 1][false] += dp[index][count][false];
                }
            }
        }
    }

    cout << dp[n][k][true] + dp[n][k][false] << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
XYs = [list(map(int, input().split())) for _ in range(N)]
XYs.sort()

prevX = None
minY = maxY = XYs[0][1]
ans = 0
for x, y in XYs:
    if prevX != x and prevX is not None:
        minY -= x - prevX
        maxY += x - prevX
    ans = max(ans, abs(minY-y), abs(maxY-y))
    minY = minY if minY < y else y
    maxY = maxY if maxY > y else y
    prevX = x
print(ans)


Measured memory_bytes: 46168
N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(N):
    B.append(A[i]-i-1)
B.sort()
med = N // 2
grief = 0
for i in range(N):
    grief += abs(B[i]-B[med])
print(str(grief))

Measured memory_bytes: 99796
#include <stdio.h>

int main(void){
  unsigned long a,b,d,r;
  double f;

  scanf("%lu%lu",&a,&b);
  d=a/b;  r=a%b;
  f=(double)a/b;
  printf("%lu %lu %f\n",d,r,f);

  return 0;
}

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

int main() {
  int n,k;
  string str;
  str="No";
  vector<int> vec(9);
  vector<int> bingo(9);
  for(int i=0; i<9; i++){
    cin>>vec.at(i);
    bingo.at(i)=0;
  }
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>k;
    for(int j=0; j<9; j++){
      if(vec.at(j)==k){
        bingo.at(j)=1;
      }
    }
  }
  if(bingo.at(0)==1){
    if(bingo.at(1)==1){
      if(bingo.at(2)==1){
        str="Yes";
      }
    }
    if(bingo.at(3)==1){
      if(bingo.at(6)==1){
        str="Yes";
      }
    }
    if(bingo.at(4)==1){
      if(bingo.at(8)==1){
        str="Yes";
      }
    }
  }
  if(bingo.at(1)==1){
    if(bingo.at(4)==1){
      if(bingo.at(7)==1){
        str="Yes";
      }
    }
  }
  if(bingo.at(2)==1){
    if(bingo.at(5)==1){
      if(bingo.at(8)==1){
        str="Yes";
      }
    }
    if(bingo.at(4)==1){
      if(bingo.at(6)==1){
        str="Yes";
      }
    }
  }
  if(bingo.at(3)==1){
    if(bingo.at(4)==1){
      if(bingo.at(5)==1){
        str="Yes";
      }
    }
  }
  if(bingo.at(6)==1){
    if(bingo.at(7)==1){
      if(bingo.at(8)==1){
        str="Yes";
      }
    }
  }
  cout<<str;
}

Measured memory_bytes: 256
def resolve():
    N, K = list(map(int, input().split(" ")))
    A = list(map(int, input().split(" ")))
    d = {}
    for a in A:
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    d = sorted(list(d.items()), key=lambda x: x[1], reverse=True)
    res = 0
    while len(d) > K:
        num, cnt = d.pop()
        res += cnt
    print(res)


if '__main__' == __name__:
    resolve()

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = Console.ReadLine().Split(' ');
            int a = Convert.ToInt32(nums[0]), b = Convert.ToInt32(nums[1]);
            int[] numArray = { a + b, a - b, a * b };
            Console.WriteLine(numArray.Max());
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ans += d.at(i) * d.at(j);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int dp0[120][120] = {0},dp1[120][120] = {0};
    int tate,yoko;
    while(scanf("%d%d",&yoko,&tate),yoko + tate)
    {

        for(int i = 0; i < tate; i++)
        {
            for(int j = 0; j < yoko; j++)
            {
                if(i == 0)dp0[j][i] = 1;
                else if(j == 0)dp0[j][i] = 0;
                else dp0[j][i] = (dp0[j - 1][i] + dp1[j - 1][i - 1]) % 100000;
                if(j == 0)dp1[j][i] = 1;
                else if(i == 0)dp1[j][i] = 0;
                else dp1[j][i] = (dp1[j][i - 1] + dp0[j - 1][i - 1]) % 100000;
            }
        }
        if(tate == 1 && yoko == 1)printf("1\n");
        else printf("%d\n",(dp0[yoko - 1][tate - 1] + dp1[yoko - 1][tate - 1]) % 100000);
    }
    return 0;
}

Measured memory_bytes: 2748
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n1,n2,n3,s;
    scanf("%d%d%d",&n1,&n2,&n3);
    s=n1+n2+n3;
    if(s>=22){
        printf("bust");
    }
    else{
        printf("win");
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main() {

	int N,i,tmp=0;
	char S[1000];

	scanf("%d", &N);
	scanf("%s", S);

	if ((N % 2) != 1) {	//奇数でないなら↓へ
		for (i = 0; N / 2 > i; i++) {

//			printf("%c %c \t", S[i], S[i + N / 2]);

			if (S[i] == S[i + N / 2]) {	//i文字目とi文字目+N/2番目比較
								//合っていれば
				tmp = 1;
//				printf("%d \t", tmp);
			}
			else {
				tmp = 0;
				break;	//不一致になったらループ抜ける
			}
			
			
		}
	}

	if (tmp == 1) {
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}

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

int main()
{
    int n[5];
    cin >> n[0];
    
    int min;
    int amari(int n);
    min = amari(n[0]);
    
    for (int i = 1; i<5; i++){
        cin >> n[i];
        if (min > amari(n[i])){min = amari(n[i]);}
    }
    
    
    //cout << "min = " << min << "\n";
    int kotae = min - 10;
    for (int i = 0;i<5;i++){
        kotae =  kotae + n[i] + 10 - amari(n[i]);
        //cout << "Now kotae=" << kotae << "\n";
    }
    cout << kotae;

}

int amari(int n){
    int kotae;
    kotae = n%10;
    if (kotae == 0){kotae = 10;}
    return kotae;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        int ans = 0;
        ans += (n / 500) * 1000;
        n %= 500;
        ans += (n / 5) * 5;
        cout << ans << '\n';
    }
}

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

#define EPS (1e-7)
#define INF (1LL << 32)
#define PI (acos(-1))
#define MAXN 1010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

ll d[MAXN][MAXN];
int n, u, v, c, e;

void warshall_floyd() {
    for(int k=0; k<n; ++k) {
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                if (d[i][k] != INF && d[k][j] != INF)  d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}
           
int main() {
    cin >> n >> e;

    rep(i, n) {
        rep(j, n) {
            d[i][j] = ( (i==j) ? 0: INF );
        }
    }

    rep(i, e) {
        cin >> u >> v >> c;
        d[u][v] = c;
    }


    warshall_floyd();

    bool negative = false;

    rep(i, n) if (d[i][i] < 0) negative = true;

    if (negative) {
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        rep(i, n) {
            rep(j, n) {
                if (j) cout << " ";
                if (d[i][j] == INF) cout << "INF";
                else cout << d[i][j];
            }
            cout << endl;
        }
    }
}




Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,m,k;
    cin >> n >> m >> k;
    rep(i, n + 1){
        rep(j, m + 1){
            if ((n - i) * j + (m - j) * i == k) {
                Yes;
                return 0;
            }
        }
    }
    No;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

#define INF 100000

int main()
{
    string s,t;
    cin >> s;
    cin >> t;
    
    int ans = 1;
    for (int i = 0;i < s.size();i++){
        if (s[i] != t[i]){
            ans = 0;
            break;
        }
    }
    if (ans == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
N, A = map(int,input().split())
X = list(map(int,input().split()))
dp = [[[0 for _ in range(50*50 + 1)] for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1
for i in range(1, N+1):
    for j in range(i+1):
        for k in range(50*j+1):
            dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i-1]]

ans = 0
for i in range(1, N+1):
    ans += dp[N][i][A * i]
print(ans)

Measured memory_bytes: 65396
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0)
                break;
            if (n == 1){
                System.out.println(sc.next());
                continue;
            }
            Map<String, Integer> hash = new HashMap<String, Integer>();
            String ans = "NO COLOR";
            for (int i = 0; i < n; i++) {
                String k = sc.next();
                if (hash.containsKey(k)) {
                    hash.put(k, hash.get(k) + 1);
                    if (hash.get(k) > n / 2) {
                        ans = k;
                        for (int j = i + 1; j < n; j++) {
                            sc.next();
                        }
                        break;
                    }
                } else
                    hash.put(k, 1);
            }
            System.out.println(ans);
        }
    }
}

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

const int N = 200005;

int s, w;

int solve() {
  scanf("%d %d", &s, &w);
  if (w >= s) printf("unsafe\n");
  else printf("safe\n");

  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    // printf("Case #%d: ", tc+1);
    solve();
  }
  return 0;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main(void) {
	int N;
	scanf("%d", &N);
	if (N < 10) {
		printf("%d\n", N);
	} else if (10 <= N && N < 100) {
		printf("%d\n", 9);
	} else if (100 <= N && N < 1000) {
		printf("%d\n", 9 + N - 99);
	} else if (1000 <= N && N < 10000) {
		printf("%d\n", 9 + 999 - 99);
	} else if (10000 <= N && N < 100000) {
		printf("%d\n", 9 + 999 - 99 + N - 9999);
	} else {
		printf("%d\n", 9 + 999 - 99 + 99999 - 9999);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];
	}
	ll res = 0;
	int m = 0;
	REP(i, n) {
		if (m == 0) {
			res += (a[i] - 1) / (m + 1);
			m = 1;
		}else if (a[i] == m + 1) {
			m = a[i];
		} else if (a[i] > m + 1) {
			res += (a[i] - 1) / (m + 1);
		}
	}
	put(res);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <set>
#include <algorithm>

using namespace std;



int main() {
	int m; cin >> m;
	
	for (int rep = 0; rep < m; rep++) {
		string train; cin >> train;
		
		set<string> make;
		int n = (int)train.size();
		for (int i=1; i<n; i++) {
			string s1 = train.substr(0, i), s2 = train.substr(i);
			
			make.insert(s1 + s2);
			make.insert(s2 + s1);
			
			string _s1 = s1;
			reverse(_s1.begin(), _s1.end());
			make.insert(_s1 + s2);
			make.insert(s2 + _s1);
			
			string _s2 = s2;
			reverse(_s2.begin(), _s2.end());
			make.insert(s1 + _s2);
			make.insert(_s2 + s1);
			
			make.insert(_s1 + _s2);
			make.insert(_s2 + _s1);
		}
		cout << (int)make.size() << endl;
	}
	
	return 0;
}

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

const int INF = 1e+9;

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> book(n, vector<int>(m+1));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m+1; j++){
            cin >> book[i][j];
        }
    }
    int ans = INF;
    for(int i = 0; i < (1 << n); i++){
        int cost = 0;
        vector<int> a(m);
        for(int j = 0; j < n; j++){
            if(i >> j & 1){
                cost += book[j][0];
                for(int k = 1; k <= m; k++){
                    a[k-1] += book[j][k];
                }
            }
        }
        bool flag = true;
        for(int j = 0; j < m; j++){
            if(x > a[j]){
                flag = false;
            }
        }
        if(flag)
            ans = min(ans, cost);
    }
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 3624
import heapq
from collections import deque
from functools import lru_cache

N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = 0

for l in range(0,K + 1):
  for r in range(0,K - l + 1):
    d = K - r - l
    tmp = 0
    have = []
    if l + r > N:
      continue
    for i in range(0,l):
      tmp += V[i]
      have.append(V[i])
    for j in range(N - r,N):
      tmp += V[j]
      have.append(V[j])
    h = len(have)
    #print(have)
    have = sorted(have)
    for k in range(0,d):
      #print(have,sum(have))
      if k >= h:
        break
      if have[k] > 0:
        break
      tmp -= have[k]
    ans = max(tmp,ans)
    
print(ans)


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

using namespace std;

int main(){
    int h; cin >> h;
    int h_lst[h+1];
    for(int i=1;i<h+1;i++) cin >> h_lst[i];


    for(int i=1;i<h+1;i++){
        cout << "node " << i << ": key = " << h_lst[i] << ", ";
        if(i>1)
            cout << "parent key = " << h_lst[i/2] << ", ";
        if((2*i) <= h){
            cout << "left key = " << h_lst[2*i] << ", ";
            if((2*i+1) <= h)
                cout << "right key = " << h_lst[2*i+1] << ", ";
        }
        cout << endl;

    }

}


Measured memory_bytes: 3100
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int H;
		int u=0;
		int[]x = new int [n];
		int[]y = new int [n];
		int[]h = new int [n];
		for(int i=0;i<n;i++) {
			x[i]=sc.nextInt();
			y[i]=sc.nextInt();
			h[i]=sc.nextInt();
			if(h[i]>0)u=i;
			
		}
		int t;
		for(int i=0;i<=100;i++) {
			for(int j=0;j<=100;j++) {
				H=h[u]+Math.abs(i-x[u])+Math.abs(j-y[u]);
				t=0;
				for(int k=0;k<n;k++) {
					int Hh=Math.max(H-Math.abs(i-x[k])-Math.abs(j-y[k]),0);
					if(Hh!=h[k]) {
						t=1;
						break;
					}
				}
				if(t==0)
					System.out.println(i+" "+j+" "+H);
			}
		}
	}

}


Measured memory_bytes: 23636
from collections import deque


def main():
    S = deque(list(map(str, input())))
    T = input()

    for _ in range(len(S)):
        if "".join(S) == T:
            print("Yes")
            return
        else:
            s = S.pop()
            S.appendleft(s)

    print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	P[] ps;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if( n == 0 ) break;
			ps = new P[n];
			for(int i=0;i<n;i++) {
				ps[i] = new P(sc.nextDouble(), sc.nextDouble());
			}
			int cnt_max = 1;
			int cnt = 0;
			for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) {
				
				if( sqrt(dis( ps[i], ps[j] )) < 2.0 ) {
					P m = new P( (ps[i].x+ps[j].x)/2, (ps[i].y+ps[j].y)/2);
					double d = sqrt(1-dis(ps[i], m ));
					P dp = new P((ps[i].y-ps[j].y), -(ps[i].x-ps[j].x));
					dp.nom();
					dp.mult(d);
					P c[] = new P[2];
					c[0] = m.add(dp);
					dp.mult(-1.0);
					c[1] = m.add(dp);
					for(int l=0;l<2;l++) {
						cnt = 0;
//						LinkedList<Double> dist = new LinkedList<Double>();
//						LinkedList<Integer> ind = new LinkedList<Integer>();
						for(int k=0;k<n;k++) {
//							debug(dis(c[l], ps[k]));
							if(sqrt(dis(c[l], ps[k])) < 1.0 || k==i||k==j) {
//								dist.add(dis(c[l], ps[k]));
//								ind.add(k);
								cnt++;
							}
						}
//						debug(dis( ps[i], ps[j] ), cnt_max, cnt);
						cnt_max = max(cnt_max, cnt);
					}
				}
			}
			System.out.println(cnt_max);
		}
	}
	
	double dis( P p1, P p2 ) {
		return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
	
	class P {
		double x, y;
		P (double x, double y) {
			this.x = x;
			this.y = y;
		}
		void nom() {
			double nom = sqrt(x*x + y*y);
			x /= nom;
			y /= nom;
		}
		P add(P p) {
			x += p.x;
			y += p.y;
			return new P(x, y);
		}
		P mult(double d) {
			x *= d;
			y *= d;
			return new P(x, y);
		}
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#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;}}

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

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


int main(){
	int n; cin >> n;
	string s1,s2; cin >> s1 >> s2;
	int i = 0;
	bool isrow;
	mint ans(1);
	if(s1[0] == s2[0]){
		ans *= 3;
		i = 1;
		isrow = false;
	}else{
		ans *= 6;
		i = 2;
		isrow = true;
	}

	while(i < n){
		if(s1[i] == s2[i]){
			if(isrow){
				
			}else{
				ans *= 2;
			}
			isrow = false;
			i++;
		}else{
			if(isrow){
				ans *= 3;
			}else{
				ans *= 2;
			}
			isrow = true;
			i += 2;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3640
//abc066_a.cpp
//Sun Sep 30 16:01:03 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	sort(a,a+3);

	cout << a[0]+a[1]<< endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int       long long
#define w(x)      int x;cin >> x;while (x--)
#define rep(d,a,n)  for(int d=a;d<=n;d++)
#define rep_(d,a,n)  for(int d=a;d>=n;d--)
#define nl        "\n" 
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define oj  freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
const int inf=1e18;
int gcd(int a,int b,int temp){
    if(temp==1){
        return 1;
    }else if(a%temp==0 && b%temp==0){
        return temp;
    }
    temp-=max(a%temp,b%temp);
    return gcd(a,b,temp);
}

void fun(){
    int n;cin>>n;
    int sum=0;
    vector<int>val(100000);
    rep(i,0,n-1){
        int tem;cin>>tem;
        sum+=tem;
        val[tem]++;
    }
    int q;cin>>q;
    while(q--){
        int b,c;cin>>b>>c;
        sum+=(c)*val[b];
        sum-=b*val[b];
        val[c]+=val[b];
        val[b]=0;
        cout<<sum<<nl;
    }
}
int32_t main()
{
   
    fast_io;
    fun();
    return 0;
}

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


int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int left = 0, right = w, top = h, bottom = 0;
    for (int i = 0; i < n; i++) {
        int x, y, a;
        cin >> x >> y >> a;

        switch (a) {
            case 1:
                if (left < x) left = x;
                break;
            case 2:
                if (x < right) right = x;
                break;
            case 3:
                if (bottom < y) bottom = y;
                break;
            case 4:
                if (y < top) top = y;
                break;
        }

    }
    if (top >= bottom && right >= left) {
        cout << (top - bottom) * (right - left) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256