akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll X[20], Y[20], P[20];
ll ans[20];
ll three[16];
ll xdist[16][(1<<15)+10], ydist[16][(1<<15)+10];

ll on( ll x, ll idx ) {
  rep( i, idx )
    x /= 3;

  return x%3;
}

int main()
{
  std::cin >> N;

  rep( i, N )
    std::cin >> X[i] >> Y[i] >> P[i];

  three[0] = 1;

  rep( i, N )
    three[i+1] = three[i]*3;  

  rep( bit, 1<<N ) {
    std::vector<ll> xs = { 0 }, ys = { 0 };

    rep( j, N ) if( bit>>j&1 ) {
      xs.emplace_back( X[j] );
      ys.emplace_back( Y[j] );
    }

    rep( i, N ) {
      ll mi = INF;

      for( auto x : xs )
        chmin( mi, llabs(x-X[i]) );

      xdist[i][bit] = mi*P[i];
    }

    rep( i, N ) {
      ll mi = INF;

      for( auto y : ys )
        chmin( mi, llabs(y-Y[i]) );

      ydist[i][bit] = mi*P[i];
    }
  }

  rep( i, N+1 )
    ans[i] = INF;

  rep( tit, three[N] ) {
    ll xbit = 0, ybit = 0;
    ll cnt = 0;

    rep( j, N ) {
      ll t = on(tit, j);

      if( t == 1 )
        xbit |= 1ll<<j, ++cnt;
      else if( t == 2 )
        ybit |= 1ll<<j, ++cnt;
    }

    ll sum = 0;

    rep( i, N )
      sum += std::min( xdist[i][xbit], ydist[i][ybit] );

    chmin( ans[cnt], sum );
  }

  rep( K, N+1 )
    std::cout << ans[K] << std::endl;

  return 0;
}

Measured memory_bytes: 11324
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=305;
int n,k,a[N];
ll dp[N][N];
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    memset(dp,inf,sizeof(dp));
    dp[0][0]=0;
    ll ans=1e15;
    for(int i=1;i<=n;i++)
        for(int j=0;j<i;j++)
        for(int k=i-1;k>=0;k--)
            dp[i][k+1]=min(dp[i][k+1],dp[j][k]+max(0,a[i]-a[j]));
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
        if(j>=n-k) ans=min(ans,dp[i][j]);
    printf("%lld\n",ans);
}


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;

map<int, string> t;

enum NodeType{ROOT = 0,INTERNALNODE = 1,LEAF = 2};

struct type_name{
 map<int, string> type_map;
 type_name(){
  type_map[ROOT] = "root";
  type_map[INTERNALNODE] = "internal node";
  type_map[LEAF] = "leaf";
 }
};

struct Tree{
 int n;
 int root;
 struct type_name t;
 vector<int> parent;
 vector<int> depth;
 vector<int> type;
 vector< vector<int> > child;

 Tree(int n) : n(n){
  parent.reserve(n); parent.assign(n,-1);
  depth.reserve(n); depth.assign(n,0);
  type.reserve(n); type.assign(n,INTERNALNODE);
  child.reserve(n);
 }

 void SearchRoot(){
  for(int i = 0; i < parent.size(); i++){
   if(parent[i] == -1){
    root = i;
    type[i] = ROOT;
   }
  }  
 }

 void ComputeDepth(){
   queue<int> queue;

   queue.push(root);
   while( !queue.empty()){
    int key = queue.front();queue.pop();
    for(int i = 0; i < child[key].size(); i++){
     int buf = child[key][i];
     queue.push(buf);
     depth[buf] = depth[key] + 1;
    }
   }
 }

 void output(){
  for(int i = 0; i < n; i++){
   cout << "node " << i << ": parent = " << parent[i] << ", depth = " << depth[i] << ", " << t.type_map[type[i]] << ", [";
   for(int j = 0; j < child[i].size(); j++){
    cout << child[i][j] << (j+1 < child[i].size() ? ", " : "");
   }
   cout << "]" << '\n';
  }
 }
};

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

 int n = 0;
 cin >> n;
 
 Tree tree(n);
 
 for(int i = 0; i < n; i++){
   int node_num, child_num;
   cin >> node_num >> child_num;

   if(child_num == 0)
    tree.type[node_num] = LEAF;

   for( int j = 0; j < child_num; j++){
    int buf;
    cin >> buf;
    tree.child[node_num].push_back(buf);
    tree.parent[buf] = node_num;
   }
 }
 
 tree.SearchRoot();
 tree.ComputeDepth();
 tree.output();
 
 return 0;
}

Measured memory_bytes: 5236
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.function.IntToDoubleFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
/**
 * @author yoshizaki
 *
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int num = scanner.nextInt();
        scanner.nextLine();
        List<Double> values = new ArrayList<Double>();
        String[] valueString = scanner.nextLine().split(" ");
        Stream<String> stream = Arrays.stream(valueString);
        values = stream.map(v -> Double.parseDouble(v)).collect(Collectors.toList());
 //        for (int i = 0 ; i < num ; i++) {
//            values.add(scanner.nextDouble());
//        }
        Collections.sort(values);
        Double ans = values.stream().reduce(values.get(0), (val, elm) -> (val + elm)/2);
        System.out.println(ans);
//        for(int i = 0; i < num-1 ; i++) {
//            Double v = (values.get(i) + values.get(i+1))/2;
//            values.set(i+1, v);
//        }
//        System.out.println( values.get(num-1));
    
    
        
    }
}

Measured memory_bytes: 26964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qpow(ll a,ll b)
{
  ll sum=1;
  for(int i=0;i<b;i++)
  sum*=a;
  return sum;
}
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll a,b;
  cin>>a>>b;
  cout<<b*qpow(b-1,a-1);
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))
    r, d, count = 0, 0, 0
    for l in range(n):
        while True:
            if r == n or d & a[r] > 0:
                break
            d += a[r]
            r += 1
        d -= a[l]
        count += r - l

    print(count)


main()


Measured memory_bytes: 24840
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	string s,tmp="CODEFESTIVAL2016";
	int ans=0;
	cin >> s;
	rep(i,s.size()){
		if(s[i]!=tmp[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int h,n;
ll dp[30001];
bool f[1001];
pair<int,ll> p[1001]; 
int main(){
	cin>>h>>n;
	rep(i,n){
		int a;
		ll b;
		cin>>a>>b;
		p[i]=m_p(a,b);
	}
	sort(p,p+n);
	rep(i,n-1){
		if(p[i].fr==p[i+1].fr)
		f[i+1]=true;
	}
	ll mn=100000000ll;
	for(int i=n-1;i>=0;i--){
		if(p[i].se>mn)
		f[i]=true;
		else mn=p[i].se;
	}
	rep(i,2*h+1)
	dp[i]=10000000000ll;
	dp[0]=0ll;
	ll ans=10000000000ll,mi;
	rep(i,n){
		if(f[i])
		continue;
		int a=p[i].fr;
		ll b=p[i].se;
		if(a>h)
		ans=min(ans,b);
		int na=a;
		ll nb=b;
		while(na<=2*h){
			dp[na]=min(dp[na],nb);
			if(dp[na]==nb&&h>na)
			for(int j=1;j<=2*h-na;j++){
				dp[j+na]=min(dp[j+na],dp[j]+dp[na]);
			}
			nb+=b;
			na+=a;
			
		}
	}
	for(int i=h;i<=2*h;i++){
		if(ans>dp[i])mi=i;
		ans=min(ans,dp[i]);
	}
	cout<<ans;
	re 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

const int MAX_ROW = 625; // to be set appropriately
const int MAX_COL = 625; // to be set appropriately
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) { }
    bitset<MAX_COL>& operator[] (int i) { return val[i]; }
};
int GaussJordan(BitMatrix &A, bool is_extended = false) {
    int rank = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rank; row < A.H; ++row) {
            if (A[row][col]) { pivot = row; break; }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}
int linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {
    int m = A.H, n = A.W;
    BitMatrix M(m, n + 1);          // augmented matrix (A|B)
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
        M[i][n] = b[i];
    }
    int rank = GaussJordan(M, true);
    // check if it has no solution
    for (int row = rank; row < m; ++row) if (M[row][n]) return -1;
    // answer
    res.assign(n, 0);
    for (int i = 0; i < rank; ++i) res[i] = M[i][n];
    return rank;
};

int main() {
    int m, n, d;
    while (cin >> m >> n >> d, m) {
        vector<vector<int>> a(n, vector<int>(m));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) cin >> a[i][j];
        }
        BitMatrix A(m * n, m * n);
        vector<int> b(m * n, 0), res;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                A[i * m + j][i * m + j] = 1;
                for (int k = 0; k < n; k++) {
                    for (int l = 0; l < m; l++) {
                        if (abs(i - k) + abs(j - l) != d) continue;
                        A[k * m + l][i * m + j] = 1;
                    }
                }
                b[i * m + j] = a[i][j];
            }
        }
        int rank = linear_equation(A, b, res);
        cout << (rank != -1) << endl;
    }
    return 0;
}


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

int main() {
int n,k,a;
cin>>n;
int counter=0;
for(int i=0;i<n;i++){
cin>>a;
if(a%2==1||a%3==0||a%5==0){
counter++;}}
if(counter==n){
cout<<"APPROVED"<<endl;}
else{
cout<<"DENIED"<<endl;}}

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

int main()
{
  int n, m;
  cin >> n >> m;
  
  vector<int> ac(n, 0);
  vector<int> wa(n, 0);
  
  int num;
  string out;
  
  for(int i = 0; i < m; i++){
    cin >> num >> out;
    if(out == "WA" && ac.at(num - 1) == 0){
      wa.at(num - 1)++;
    }
    else if(out == "AC" && ac.at(num - 1) == 0){
      ac.at(num - 1) = 1;
    }
  }
  
  int answ = 0, ansa = 0;
  for(int i = 0; i < n; i++){
    if(ac.at(i) == 1){
      ansa++;
      answ += wa.at(i);
    }
  }
  
  cout << ansa << " " << answ << endl;

  return 0;
}

Measured memory_bytes: 1024
def isAvailableAreas(area):
	ymax = int(area**0.5)
	for i in range(1, ymax+1):
		if (area-i)%(2*i+1)==0:
			return True
	return False


n = int(input())
A = []
for i in range(n):
	A.append(int(input()))

suma = 0
for i in A:
	if not isAvailableAreas(i):
		suma = suma+1

print(suma)



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

int Q,l,r;
int table[1000000] ={0};
bool p[1000000] = {false}; // false = prime number

int main(){
	p[0] = p[1] = true;
	for(int i = 2; i < 1000000; i++){
		if(p[i] == false){
			for(int j = i*2; j < 1000000; j+=i){
				p[j] = true;
			}
		}
	}
	for(int i = 3; i < 1000000; i++){
		table[i] = table[i-1];
		if(p[i] == false && p[(i+1)/2] == false){
			table[i]++;
		}
	}
	scanf("%d",&Q);
	for(int i = 0; i < Q; i++){
		scanf("%d%d",&l,&r);
		printf("%d\n",table[r] - table[l-1]);
	}

	return 0;
}


Measured memory_bytes: 5504
import Control.Applicative
import Data.Char

main = do s <- map toLower . filter isAlpha <$> getContents
          putStr . unlines . map toOut $ [(c,n)|c<-['a'..'z'],let n=length $ filter (==c) s]

toOut :: (Char,Int) -> String
toOut (c,n) = c : " : " ++ (show n)

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

int n;
int p[15];

int main(){
    int pmax = 0;
    scanf("%d", &n);
    for(int i=0; i< n; i++){
        scanf("%d", &p[i]);
        if(p[i] > p[pmax]){
            pmax = i;
        }
    }
    int sum = 0;
    for(int i=0; i<n; i++){
        if(i != pmax){
            sum += p[i];
        }else{
            sum += p[i] / 2;
        }
    }
    printf("%d\n", sum);
    return 0;

}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		System.out.println(Math.max(Math.max(a + b, a - b), a * b));
	}
}

Measured memory_bytes: 23124
use proconio::input;

fn main() {
    input! {
        n: i64,
        k: i64,
    }

    let mut result = n;

    let t = if n > k || n == 0 { n / k } else { k / n };

    if (n - (t - 1) * k).abs() < result {
        result = (n - (t - 1) * k).abs();
    }
    if (n - t * k).abs() < result {
        result = (n - t * k).abs();
    }
    if (n - (t + 1) * k).abs() < result {
        result = (n - (t + 1) * k).abs();
    }

    println!("{}", result);


}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int LIMIT = 1e9 + 7;
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
	int N;cin>>N;
  int mae = 0;
  ll ans = 0;
  rep(i,N){
    int A;cin>>A;
    if(A>=mae){
      mae = A;
    }else{
      ans += mae - A;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3580
unittest
{
	assert( [ "11" ].parse.expand.solve == "Yes" );
	assert( [ "40" ].parse.expand.solve == "Yes" );
	assert( [ "3" ].parse.expand.solve == "No" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( int );
	
	return tuple( n );
}

auto solve( in long n )
{
	foreach( d4; 0 .. ( 1 + n / 4 ) )
	{
		foreach( d7; 0 .. ( 1 + n / 7 ) )
		{
			if( d4 * 4 + d7 * 7 == n ) return "Yes";
		}
	}
	
	return "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair <int, int> PII;
typedef pair <int, PII> PIP;

const int size = 101;
int P[size];
bool used[size];
int cnt[size];
int n, m;
vector <PIP> E;

void init( int n ) {
  for ( int i = 0; i < n; i++ ) {
    P[i] = -1;
  }
}

int find( int a ) {
  if ( P[a] == -1 ) return a;
  return P[a] = find( P[a] );
}

void unite( int a, int b ) {
  int fa = find( a ), fb = find( b );
  if ( fa != fb ) {
    P[fa] = fb;
  }
}

bool same_set( int a, int b ) {
  return find( a ) == find( b );
}

int main() {
  string line;

  while ( getline( cin, line ) ) {
    if ( line == "0" ) break;

    {
      // n
      istringstream is( line );
      is >> n;
    }
    {
      // m
      getline( cin, line );
      istringstream is( line );
      is >> m;
    }

    E.clear();
    for ( int i = 0; i < m; i++ ) {
      // a, b, c
      getline( cin, line );
      replace( line.begin(), line.end(), ',', ' ' );
      istringstream is( line );
      int a, b, c;
      is >> a >> b >> c;

      // add edge
      PIP edge( c, PII( a, b ) );
      E.push_back( edge );
    }

    sort( E.begin(), E.end() );

    init(n);
    for ( int i = 0; i < n; i++ ) {
      used[i] = false;
      cnt[i] = 0;
    }

    int answer = 0;
    for ( int i = 0; i < m; i++ ) {
      int a = E[i].first;
      int b = E[i].second.first;
      int c = E[i].second.second;

      if ( find( b ) != find( c ) ) {
	unite( b, c );
	answer += ( a / 100 ) - 1;
      }
    }

    cout << answer << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}



int main() {
  int R=input();
  if(R<1200){
    cout<<"ABC"<<endl;
  }else if(R<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }

  


  



  
  
  

  


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int p[100010];
int root(int x){
	if(x == p[x]) return x;
	return p[x] = root(p[x]);
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi x(n), y(n);
	vector<pi> tate, yoko;
	rep(i, n){
		cin >> x[i] >> y[i];
		yoko.emplace_back(x[i], i);
		tate.emplace_back(y[i], i);
	}
	sort(all(yoko));
	sort(all(tate));
	
	vector<pair<int, pi>> e;
	rep(i, n - 1){
		e.emplace_back(abs(yoko[i].first - yoko[i + 1].first), pi(yoko[i].second, yoko[i + 1].second));
		e.emplace_back(abs(tate[i].first - tate[i + 1].first), pi(tate[i].second, tate[i + 1].second));
	}
	sort(all(e));
	rep(i, n) p[i] = i;
	ll ans = 0;
	for(auto i : e){
		int a = i.second.first, b = i.second.second;
		a = root(a); b = root(b);
		if(a == b) continue;
		p[b] = a;
		ans += i.first;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 7656
import math

a,b,h,m = map(int,input().split())
ang_a = h/12 + m/60/12
ang_b = m/60
ang = min(math.fabs(ang_a-ang_b),1-math.fabs(ang_a-ang_b))
ans_s = a**2+b**2-2*a*b*math.cos(2*ang*math.pi)
ans = math.sqrt(ans_s)
print(ans)

Measured memory_bytes: 9512
import sys
iN = int(input())
aS = [int(_) for _ in sys.stdin.readlines()]


iSum = sum(aS)
if iSum % 10 :
    print(iSum)
    exit()
aNot10 = [ _ for _ in  aS if _ % 10 != 0]
if aNot10 != [] :
    iMin = min(aNot10)
    print(iSum-iMin)
else:
    print(0)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    rep(i,0,n) cin >> a[i];
    rep(i,0,n) cin >> b[i];
    rep(i,0,n) cin >> c[i];

    sort(a.begin(), a.end()); 
    sort(b.begin(), b.end()); 
    sort(c.begin(), c.end()); 

    ll ans(0);
    rep(i,0,n)
    {
        ll na = a.begin() - lower_bound(a.begin(), a.end(), b[i]); 
        ll nb = upper_bound(c.begin(), c.end(), b[i]) - c.end(); 
        ans += nb * na;
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

ll gcd(ll a, ll b) {
  return (!a || !b) ? 0 : ((a % b == 0) ? b : gcd(b, a % b));
}

// 結果を入れたmapを返します
map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i <= sqrt(n); i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  // 2以上で割り切れなかったら
  if (n != 1) ret[n] = 1;
  return ret;
}

// ====================================================================

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a, b);

  map<ll, int> prime = prime_factor(g);
  cout << prime.size() + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int m, f, r;
    while (cin >> m >> f >> r) {
        if (m == -1 && f == -1 && r == -1)
            break;

        if (m == -1 || f == -1)
            cout << "F\n";
        else if (m + f >= 80)
            cout << "A\n";
        else if (m + f >= 65)
            cout << "B\n";
        else if (m + f >= 50)
            cout << "C\n";
        else if (m + f >= 30)
            if (r >= 50)
                cout << "C\n";
            else
                cout << "D\n";
        else
            cout << "F\n";
    }
}



Measured memory_bytes: 3168
n, a, b = map(int, input().split())
s = str(input())
domestic = 0
abroad = 0

for i in s:
    if i == 'a':
        if domestic + abroad <= a + b - 1:
            print('Yes')
            domestic += 1
        else:
            print('No')
    elif i == 'b':
        if domestic + abroad <= a + b - 1 and abroad <= b - 1:
            print('Yes')
            abroad += 1
        else:
            print('No')
    else:
        print('No')


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

typedef long long LL;
typedef pair<int, int> II;

const int N = 300 + 10;
const int P = (int) 1e9 + 7;
int n, m;
int l[N], r[N], x[N];
int dp[N][N][N];
vector<int> Z[N];

bool Check(int pos, int r, int g, int b) {
    for (int i = 0; i < (int) Z[pos].size(); ++i) {
        int t = Z[pos][i];
        int c = 0;
        if (l[t] <= r) c++;
        if (l[t] <= g) c++;
        if (l[t] <= b) c++;
        if (c != x[t]) return false;
    }
    return true;
}

void Update(int &a, int v) {
    a += v;
    if (a >= P) a -= P;
}

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; ++i) {
        scanf("%d%d%d", &l[i], &r[i], &x[i]);
        Z[r[i]].push_back(i);
    }

    dp[0][0][0] = 1;
    for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j)
    for (int k = 0; k <= n; ++k) {
        int pos = max(max(i, j), k);
        if (Check(pos, i, j, k) == false) {
            dp[i][j][k] = 0;
            continue;
        }
        Update(dp[pos + 1][j][k], dp[i][j][k]);
        Update(dp[i][pos + 1][k], dp[i][j][k]);
        Update(dp[i][j][pos + 1], dp[i][j][k]);
    }

    int ans = 0;
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= n; ++j)
            for (int k = 0; k <= n; ++k)
                if (max(max(i, j), k) == n) Update(ans, dp[i][j][k]);
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 114944
#include<stdio.h>
int main()
{
   int a,b,c,x;

    scanf("%d",&a);

    x=a%10;
    a=a/10;
    b=a%10;
    c=a/10;

    if (x==c)
       printf("Yes");
    else
       printf("No");

    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

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

    vector<vector<int>> a(N);
    vector<vector<int>> cost(N);
    for (int i = 0; i < N-1; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        a[u].emplace_back(v);
        cost[u].emplace_back(w);
        a[v].emplace_back(u);
        cost[v].emplace_back(w);
    }

    vector<int> ans(N, -1);
    queue<int> q;
    ans[0] = 0;
    q.push(0);

    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        for (int i=0; i < a[v].size(); i++)
        {
            int u = a[v][i];
            int w = cost[v][i];

            if (ans[u] != -1)
                continue;
            ans[u] = (ans[v] + w) % 2;
            q.push(u);
        }
    }

    for (auto iter:ans)
    {
        cout << iter << endl;
    }
}

Measured memory_bytes: 11904
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vi2;
typedef vector<vi2> vi3;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vll> vll2;
typedef vector<vll2> vll3;
typedef vector<bool> vb;

#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define umap unordered_map
#define uset unordered_set
#define vec vector
#define loop(a) for (auto &x : a)
#define all(a) a.begin(), a.end()
#define mp make_pair

int n;
vi a, b;
vll2 cache;

ll dfs(int left, int right) {
    if (left > right) {
        return 0;
    }
    if (cache[left][right] != -1) {
        return cache[left][right];
    }
    int which = n - (right - left + 1);
    ll ans1 = dfs(left + 1, right) + abs(left - b[which]) * a[b[which]];
    ll ans2 = dfs(left, right - 1) + abs(right - b[which]) * a[b[which]];
    return cache[left][right] = max(ans1, ans2);
}

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

    cin >> n;
    a = vi(n);
    loop(a) {
        cin >> x;
    }
    b = vi(n);
    rep(i, 0, n) {
        b[i] = i;
    }
    sort(all(b), [&](int x, int y) {
        return a[x] > a[y];
    });
    cache = vll2(n, vll(n, -1));
    cout << dfs(0, n - 1) << el;
}


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

typedef long long ll;

int main()
{
    int n,x;
    cin>>n>>x;
    vector<int>a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll ret=0;
    for(int i=1;i<n;i++){
        if(a[i-1]+a[i]<=x)continue;
        ret+=a[i]+a[i-1]-x;
        a[i]=max(0,x-a[i-1]);



    }
     cout<<ret;


}


Measured memory_bytes: 768
use std::collections::HashMap;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: i64 = sc.read();
    let mut a = Vec::new();
    for _ in 0..n {
        let ai: i64 = sc.read();
        a.push(ai);
    }
    // let mut cum = Vec::new();
    let mut counts: HashMap<i64, i64> = HashMap::new();
    let mut s: i64 = 0;
    *counts.entry(s).or_insert(0) += 1;
    for ai in a.iter() {
        s += *ai;
        *counts.entry(s).or_insert(0) += 1;
    }
    let mut ans: i64 = 0;
    for (_, count) in counts.iter() {
        ans += count * (count - 1) / 2;
    }
    println!("{}", ans);
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 18500
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int a, p; cin >> a >> p;
    cout << (int)((3*a+p)/2) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100000007

ll dp_5[100001],dp_3[100001];
char buf[100001];


void func(){

	ll ans = 1;
	int left = 0,right;

	while(buf[left] != '\0'){
		for(right = left; buf[right] != '\0' && buf[right] == buf[left]; right++);
		right--;

		if(buf[left] == '8' || buf[left] == '0'){
			ans *= dp_3[right-left+1];
			ans %= NUM;
		}else{
			ans *= dp_5[right-left+1];
			ans %= NUM;
		}
		left = right+1;
	}

	printf("%lld\n",ans%NUM);
}

int main(){

	for(int length = 1; length <= 6; length++){
		dp_5[length] = pow(2,length-1);
	}
	for(int length = 7; length <= 100000; length++){
		dp_5[length] = (1+dp_5[length-1]+dp_5[length-2]+dp_5[length-3]+dp_5[length-4]+dp_5[length-5])%NUM;
	}

	for(int length = 1; length <= 4; length++){
		dp_3[length] = pow(2,length-1);
	}
	for(int length = 5; length <= 100000; length++){
		dp_3[length] = (1+dp_3[length-1]+dp_3[length-2]+dp_3[length-3])%NUM;
	}

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		func();
	}

	return 0;
}

Measured memory_bytes: 5048
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int num;
	vector<int> primeList;
	bool used[51000];
	memset(used, true, sizeof(used));

	for(int i = 2; i < 1000; i++)
	{
		if(used[i] == false)
		{
			continue;
		}
		for(int j = i*2; j < 51000; j += i)
		{
			used[j] = false;
		}
	}
	for(int i = 2; i < 51000; i++)
	{
		if(used[i] == true)
		{
			primeList.push_back(i);
		}
	}
	
	while(cin >> num)
	{
		if(binary_search(primeList.begin(), primeList.end(), num))
		{
			printf("%d %d\n",*(upper_bound(primeList.begin(), primeList.end(), num)-2), *upper_bound(primeList.begin(), primeList.end(), num));
		}
		else
		{
			printf("%d %d\n",*(upper_bound(primeList.begin(), primeList.end(), num)-1), *upper_bound(primeList.begin(), primeList.end(), num));
		}	
	}
}

Measured memory_bytes: 1304
N = int(input())
A = list(map(int,input().split()))

dic = {}
L = set([]) #2本以上
S = set([]) #4本以上
for i in range(N):
  if A[i] not in dic:
    dic[A[i]] = 1
  else:
    dic[A[i]] += 1
    if dic[A[i]] == 2:
      L.add(A[i])
    elif dic[A[i]] == 4:
      S.add(A[i])
L = list(L)
L.sort(reverse = True)
if len(L) >= 2:
  tyo = L[0]*L[1]
else:
  tyo = 0
S = list(S)
S.sort(reverse = True)
if S:
  sei = S[0]**2
else:
  sei = 0
#print(L,S)
print(max(tyo,sei))
      
    

Measured memory_bytes: 18316
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
        int N = sc.nextInt();
		int[] a = new int[100];
		for (int i=0; i <N; i++)
			a[i]=sc.nextInt();
		
		Arrays.sort(a);	
		
		int Alice = 0;
		int Bob = 0;

		for (int i=99; i >99-N; i--)
			if ( i % 2 == 1 )
			   Alice += a[i];
			else 
			Bob +=a[i];
			
		System.out.println( Alice - Bob );
	}
}

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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, M;
int dist[101][101], graph[101][101];
bool used[101][101];

void Warshall_Floyd() {
    rep(k, N) rep(i, N) rep(j, N) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    rep(i, 101) rep(j, 101) dist[i][j] = graph[i][j] = INF;
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        dist[a][b] = dist[b][a] = c;
        graph[a][b] = graph[b][a] = c;
    }
    Warshall_Floyd();
    memset(used, false, sizeof(used));
    int res = 0;
    rep(i, N) rep(j, N) {
        if(!used[i][j] && graph[i][j] != INF && dist[i][j] < graph[i][j]) {
            ++res;
            used[i][j] = used[j][i] = true;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=55;
int n,x,d,fa[N],c[N*N*N];
struct node
{
	int v,id;
	long long w;
	bool operator<(const node k)const
	{
		return v*k.w>w*k.v;
	}
}a[N];
long long dp[N*N*N],ans;
int main()
{
	ios::sync_with_stdio();
	cin>>n>>x>>d;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].w;
		if(i>1)
			cin>>fa[i];
		a[i].id=i;
		a[i].v=1;
	}
	for(int i=n;i>=1;i--)
	{
		a[fa[i]].w+=a[i].w;
		a[fa[i]].v+=a[i].v;
	}
	sort(a+1,a+n+1);
	int m=min(n,d);
	for(int j=1;j<=n*n*n;j++)
		dp[j]=1e18;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=n*n*n;j++)
			c[j]=0;
		for(int j=0;j<=n*n*n;j++)
		{
			if(j+a[i].v>n*n*n)
				continue;
			if(c[j]==m)
				continue;
			if(dp[j+a[i].v]>dp[j]+a[i].w)
			{
				dp[j+a[i].v]=dp[j]+a[i].w;
				c[j+a[i].v]=c[j]+1;
			}
			else if(dp[j+a[i].v]==dp[j]+a[i].w&&c[j+a[i].v]>c[j]+1)
				c[j+a[i].v]=c[j]+1;
		}
	}
	for(int i=0;i<=n*n*n;i++)
	{
		if(dp[i]>x)
			continue;
		long long w=dp[i],v=i;
		for(int j=1;j<=n;j++)
		{
			if(a[j].id==1)
			{
				long long zh=(x-w)/a[j].w;
				w+=zh*a[j].w,v+=zh*a[j].v;
				continue;
			}
			long long zh=min((long long)d-m,(x-w)/a[j].w);
			w+=zh*a[j].w,v+=zh*a[j].v;
		}
		ans=max(ans,v);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5072
#include <stdio.h>

int main(void)
{
	int i, j, H, W;

	while (1) {
		
		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0) {
			break;
		}
			
			for (i = 0; i < H; i++) {
				
				for (j = 0; j < W; j++) {
					
					putchar('#');

				}
				
				putchar('\n');

			}

			putchar('\n');
		}
	

	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s,t;
	cin>>s>>t;
	ll ans=0;
	for(ll i=0;i<3;i++){
		if(s[i]==t[i]){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for (int i = 0; i < n; i++)
#define Rep(i,n) for (int i = n; i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define P pair<int, int>
#define prique priority_queue<P, vector<P>, greater<P>>
struct edge { int to, cost; };
using namespace std;

signed main() {
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	int cnt = 0;
	rep(i, n + 1) {
		rep(j, n - i + 1) {
			int sum = r * i + g * j;
			if (n - sum < 0) continue;
			if ((n - sum) % b == 0) {
				cnt++;
				
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		int numTown = input.nextInt();
		input.nextInt();
		int[] val = new int[numTown];
		for (int i = 0; i < numTown; i++) {
			val[i] = input.nextInt();
		}
		
		int maxdiff = 0;
		int count = 0;
		
		
		int[] maxright = new int[numTown];
		int[] minleft = new int[numTown];
		maxright[numTown-1] = val[numTown-1];
		minleft[0] = val[0];
		
		for(int i = 1; i < numTown; i++){
			minleft[i] = Math.min(minleft[i-1], val[i]);
		}

		for(int i = numTown-2; i >= 0; i--){
			maxright[i] = Math.max(maxright[i+1], val[i]);
		}
		
		for (int i = 0; i < numTown; i++) {
		//	System.out.println(i +" "+ minleft[i] +" "+ maxright[i]);
				if (maxright[i] - minleft[i] > maxdiff) {
					int mr = maxright[i];
					int ml = minleft[i];
					maxdiff = maxright[i] - minleft[i];
					count = 1;
					while (i < numTown && maxright[i] == mr && minleft[i] == ml) {
						i++;
					}
				} else if (maxright[i] - minleft[i] == maxdiff) {
					count++;
					int mr = maxright[i];
					int ml = minleft[i];
					while (i < numTown && maxright[i] == mr && minleft[i] == ml) {
						i++;
					}
				}
		}
		System.out.println(count);
	}
}


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

int main() {
  int a,b,c,flag;
  cin>>a>>b>>c;
  flag=0;
  if((a==b) && (a!=c)){
    flag=1;
  }
  if((a==c) && (b!=c)){
    flag=1;
  }
  if((b==c) && (a!=c)){
    flag=1;
  }
  if(flag==1){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 3608
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

const MOD: u64 = 1_000_000_007;

pub fn pow_mod(mut x: u64, mut y: u64, modv: u64) -> u64 {
    let mut ret: u64 = 1;
    while y > 0 {
        if (y & 1) != 0 {
            ret = ret * x % modv;
        }
        y >>= 1;
        x = x * x % modv;
    }
    ret
}

fn main() {
    proconio::input! {
        n: u64
    }

    println!("{}", (2*MOD + pow_mod(10, n, MOD) -2* pow_mod(9, n, MOD) + pow_mod(8,n, MOD)) % MOD);
}


Measured memory_bytes: 2152
#define _USE_MATH_DEFINES
    #include <bits/stdc++.h>
    #define ll  long long
    #define pb push_back
    #define mp make_pair
    #define ff first
    #define ss second
    #define vi vector<int>
    #define br cout <<"\n";
    #define all(x)  (x).begin(),(x).end()
    #define tr(c,i) for(auto i : c)
    #define pii pair< int,int >
    #define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
    #define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
    #define er(x) cout << x << " "
    #define err(x,y) cout << x << " "<<y
    const int M = 200005;
    using namespace std;
    clock_t time_p=clock();
    void dem()
    {
        time_p=clock()-time_p;
        cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
    }
    using namespace std ;
    const int MAX =  1000 * 1000 + 10;
    const int dx[] = { 1, -1 , 0 , 0  };
    const int dy [] = { 0 ,0 , 1 , -1  };
    const int MOD = 1000 * 1000 * 1000 + 9 ;
    int main (){
    int n ;
     cin >> n ;
     vector <int > v( n ,  0 ) ;
     for ( auto & x : v )cin >> x ;
    ll  sum  = 0 ;
    for ( int i = 0 ; i < n ; ++ i ){
        for ( int j = i + 1 ; j < n ; ++ j )
            sum += 1ll* v[i] * v[ j ] ;
    }

     cout << sum ;

        return 0 ;
    }



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

struct edge{ int to,cost; };

signed main(){
	int n,m,d[100000];
	vector<edge> G[100000];
	cin >> n >> m;
	for(int i = 0;i < n;i++) d[i] = INF;
	for(int i = 0;i < m;i++){
		int l,r,d;
		cin >> l >> r >> d; l--;r--;
		G[l].push_back({r,d});
		G[r].push_back({l,-d});
	}
	for(int i = 0;i < n;i++){
		if(d[i] == INF){
			d[i] = 0;
			queue<int> que;
			que.push(i);
			while(!que.empty()){
				int v = que.front();que.pop();
				for(edge e : G[v]){
					if(d[e.to] == INF){
						d[e.to] = d[v] + e.cost;
						que.push(e.to);
					}else if(d[e.to] != d[v] + e.cost){
						No();
						return 0;
					}
				}
			}
		}
	}
	Yes();
	return 0;
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
using pii = pair<int,int>;
#define all(a) a.begin(), a.end()

const int MAX_N = 50;
int N;

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

vector<vector<int> > G;
map<pii, int> mp;
int used[MAX_N], dist[MAX_N];

vector<int> bfs(int s, int t){
    for(int i = 0; i < N; i++) dist[i] = 1e9;
    for(int i = 0; i < N; i++) used[i] = 0;
    vector<int> res, point;

    queue<int> Q;
    Q.push(s);
    dist[s] = 0;

    while(!Q.empty()){
        int v = Q.front(); Q.pop();
        used[v] = 1;
        for(auto nv: G[v]){
            if(used[nv] == 0){
                dist[nv] = dist[v] + 1;
                Q.push(nv);
            }
        }
    }

    while(dist[t] != 0){
        for(auto nv: G[t]){
            if(dist[nv] == dist[t] - 1) {
                point.push_back(t);
                t = nv;
            }
        }
    }
    point.push_back(t);
    for(int i = 0; i < (int)point.size() - 1; i++){
        res.push_back(mp[{point[i], point[i+1]}]);
    }
    return res;
}

int main(){
    cin >> N;
    G.resize(N);
    int idx = 0;
    rep(i, 0, N - 1){
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
        mp[{a,b}] = idx;
        mp[{b,a}] = idx;
        idx++;
    }
    int M; cin >> M;
    //vector<vector<int> > edges(M);
    vector<int> tmp;
    vector<ll> edges(50);
    rep(i, 0, M){
        int u, v; cin >> u >> v; u--, v--;
        tmp = bfs(u, v);
        for(auto e : tmp) edges[i] |= (1LL << e);
    }
    ll ans = 0;

    ll dp[50];
    dp[0] = 1;
    rep(i, 1, 50) dp[i] = dp[i-1] * 2;

    for(int i = 0; i < (1 << M); i++){
        //int kcnt = 0;
        //vector<int> tmp;
        ll mask = 0;
        rep(j, 0, M){
            if(i >> j & 1) mask |= edges[j];
        }
        int white = __builtin_popcountll(mask);
        ll now = 1ll << (N - 1 - white);
        if(__builtin_popcountll(i) % 2 == 0) ans += now;
        else ans -= now;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    X, Y, Z = MI()
    X -= Z
    print(X//(Y+Z))
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include<stdio.h>
main(){
  int n,i,l,dos[6]={0};
  double a;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%lf",&a);
    if(a<165){
      dos[0]++;
    }
    else if(a<170){
      dos[1]++;
    }
    else if(a<175){
      dos[2]++;
    }
    else if(a<180){
      dos[3]++;
    }
    else if(a<185){
      dos[4]++;
    }
    else{
      dos[5]++;
    }
  }

  for(i=0;i<6;i++){
    printf("%d:",i+1);
    for(l=0;l<dos[i];l++)
      printf("*");
    puts("");
  }
  return 0;
}

Measured memory_bytes: 0