akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

// Manages Union-Find Forest.
class UnionFindForest {
  std::vector<int> parent_;
  std::vector<int> rank_;
  std::vector<int> size_;

 public:
  // Initialize forest.
  // parent[i]=i, rank[i]=0.
  UnionFindForest(int n);
  // Get the number of the root of the node q.
  int Root(int q);
  // Return true if the roots of x and y is same.
  bool IsSame(int x, int y);
  // Unite the tree x and tree y.
  void Unite(int x, int y);
  int Size(int q);
};
int UnionFindForest::Size(int q) {
  return size_[Root(q)];
}
UnionFindForest::UnionFindForest(int n) {
  for (int i = 0; i < n; i++) {
    parent_.push_back(i);
    rank_.push_back(0);
    size_.push_back(1);
  }
}
int UnionFindForest::Root(int q) {
  if (parent_[q] == q) {
    return q;
  } else {
    return parent_[q] = Root(parent_[q]);
  }
}

bool UnionFindForest::IsSame(int x, int y) {
  return Root(x) == Root(y);
}

void UnionFindForest::Unite(int x, int y) {
  x = Root(x);
  y = Root(y);
  if (x == y) return;
  if (rank_[x] < rank_[y]) {
    parent_[x] = y;
    size_[y] += size_[x];
    size_[x] = 0;

  } else {
    parent_[y] = x;
    size_[x] += size_[y];
    size_[y] = 0;
    if (rank_[x] == rank_[y]) rank_[x]++;
  }
}

struct Queue {
  int a, b;
  Queue(int x, int y) {
    a = x;
    b = y;
  }
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t n, m;
  cin >> n >> m;
  UnionFindForest UFF(n + 1);
  std::vector<Queue> q;
  std::vector<int64_t> result;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    q.push_back(Queue(x, y));
  }
  int64_t answer = n * (n - 1) / 2;
  result.push_back(answer);
  for (int i = m - 1; i >= 0; i--) {
    int a = q[i].a;
    int b = q[i].b;
    // cout << a << " " << b << endl;
    if (UFF.IsSame(a, b)) {
      result.push_back(answer);
    } else {
      cerr << UFF.Size(a) << "\t" << UFF.Size(b) << endl;
      answer -= UFF.Size(a) * UFF.Size(b);
      result.push_back(answer);
      UFF.Unite(a, b);
    }
  }

  for (int i = m - 1; i >= 0; i--) {
    cout << result[i] << endl;
  }

  return 0;
}


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

int main(void){
  int n;
  string s;
  
  int rcount = 0, bcount = 0;

  cin >> n >> s;

  for(int i = 0; i < n; i ++){
    if(s.at(i) == 'R')
      rcount ++;
    else 
      bcount ++;
  }

  if(rcount > bcount) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = l[0], X = l[1];

            var array = new int[N];
            for (var i = 0; i < N; i++)
                array[i] = int.Parse(Console.ReadLine());

            long oneTotal = array.Sum();
            var ret = X - oneTotal;

            Console.WriteLine(ret / array.Min() + N);
        }
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;
import java.util.Arrays;

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

	int n = scan.nextInt();
	String s = scan.next();

	int[] a = new int[26];
	int[] b = new int[26];
	int max = 0;
	for(int i = 0; i < n; i++){
	    int count = 0;
	    for(int j = i; j >= 0; j--){
		a[s.charAt(j)-97]++;
	    }
	    for(int j = i+1; j < n; j++){
		b[s.charAt(j)-97]++;
	    }
	    for(int j = 0; j < 26; j++){
		if(a[j] >= 1 && b[j] >= 1){
		    count++;
		}
	    }
	    if(count > max){
		max = count;
	    }
	    Arrays.fill(a, 0);
	    Arrays.fill(b, 0);
	}

	System.out.println(max);
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

ll x, y;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> x >> y;
    int ans = 0;
    while(x <= y){
        ans++;
        x *= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define mp std::make_pair
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
#define Yes std::cout << "Yes" << std::endl
#define No std::cout << "No" << std::endl
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;
int main()
{
	stat();
	int x;
	cin>>x;
	if(x==1){cout<<0<<endl;}else{
		cout<<1<<endl;
	}

    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}


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


int main(){
string S;
  int c=0;
  cin >> S;
  rep(i,(int)S.size()-1){
  if(S.at(i)==S.at(i+1))
    c++;
  }
 if(c==0)
   cout << "Good" << endl;
  else
    cout << "Bad" << endl;
   
  
}



Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
int time, t;
int hour, min, sec; 

scanf("%d",&time);
 
hour = time/3600;
t = time%3600;
min = t/60;
sec = t%60;
 
printf("%d:%d:%d\n",hour,min,sec);
 
return 0;
 
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define IOS                 ios::sync_with_stdio(false); cin.tie(nullptr)
#define deb(x)              cout << #x << " = " << x << endl
#define deb2(x, y)          cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define f0(i, a, n)         for(i = a; i < n; i++)
#define f1(i, a, n)         for(i = a; i <= n; i++)
#define tc(t)               int t; cin >> t; while(t--)
#define ini(x, y)           memset(x, y, sizeof(x))
#define all(x)              x.begin(),x.end()
#define sz(x)               x.size()
#define ll                  long long int
#define vi                  vector<int>
#define si                  set<int>
#define pb                  emplace_back
#define ppb                 pop_back
#define mp                  make_pair
#define M                   1000000007
#define endl                '\n'
#define bits(x)             __builtin_popcountll(x)
#define zrbits(x)           __builtin_ctzll(x)

using namespace std;

void solve() {
        int a, b, c, i;
        cin >> a >> b >> c;
        if(b * c >= a) cout << "Yes" << endl;
        else cout << "No" << endl;
}

int main () {
        IOS;
        // tc(t)
        solve();
        return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,all=0; cin>>n;
    vector <int>ans(n+2);
    vector <int> place(n+2);
    place[0]=0;
    for(int i=1;i<=n;i++) {
        cin>>place[i];
    }
    place[n+1]=0;
    for(int i=0;i<n+1;i++){
        all+=abs(place[i]-place[i+1]);
    }
    for(int i=1;i<=n;i++){
        if((place[i]>=place[i-1]&&place[i]<=place[i+1])||(place[i]<=place[i-1]&&place[i]>=place[i+1])){
            cout<<all<<endl; 
        }else{
            cout<<all-2*min(abs(place[i]-place[i-1]),abs(place[i]-place[i+1]) )<<endl; 
        }
    }
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n;
vec<int> v;
map<int, int> mp;

signed main() {
   cin >> n;
   v.resize(n);
   rep (i, n) {
      cin >> v[i];
      mp[v[i]]++;
   }

   int cnt = 0;
   std::map<int,int>::reverse_iterator i = mp.rbegin();
   for( ; i != mp.rend() ; ++i ) {
      // i.firstのついとなるtを探す
      int t = 0;
      for (int j = 0; j < 40; j++) {
         if (i->first <= (1LL<<j)) {
            t = (1LL<<j) - i->first;
            break;
         }
      }

      if (mp[t] >= 1 && mp[i->first] >= 1) {
         // mp[i->first]--;
         // mp[t]--;
         int hoge = min(mp[i->first], mp[t]);
         mp[i->first] -= hoge;
         mp[t] -= hoge;
         cnt += hoge;
         // cnt++;
      }
   }

   int cnt2 = 0;
   for (auto x : mp) {
      for (int i = 0; i < 40; i++) {
         if (x.first == (1LL<<i)) {
            cnt2 += x.second / 2;
            break;
         }
      }
   }

   cout << cnt + cnt2 << endl;

   return 0;
}


Measured memory_bytes: 87168
# A
N = int(input())
h = list(map(int, input().split()))

cost = [0]*N

cost[0] = 0
cost[1] = abs(h[1]-h[0])
for i in range(2,N):
    cost1 = abs(h[i]-h[i-1]) + cost[i-1]
    cost2 = abs(h[i]-h[i-2]) + cost[i-2]
    cost[i] = min(cost1, cost2)
print(cost[-1])

Measured memory_bytes: 13980
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define N 200005
 
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	

	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ans = min(k,a);
	k=max(0ll,k-a-b);
	ans-=min(k,c);
	cout<<ans<<endl; 	
 	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

#define PI 3.14159265358979

int main()
{
    int a;
    int b;
    int x;

    cin >> a;
    cin >> b;
    cin >> x;

    // total volume
    int total = a * a * b;

    double degree = 0.f;
    
    if (x == 0)
    {
        degree = 90.f;
    }
    else if (total == x)
    {
        degree = 0.f;
    }
    else if (static_cast<double>(total) / 2.f >= x)
    // less than half
    {
        double length = static_cast<double>(x) * 2.0f / (static_cast<double>(a) * static_cast<double>(b));
        double radian = std::atan(static_cast<double>(b) / length);
        degree = radian * 180.f / PI;
    }
    else
    // larger than half
    {
        double empty = total - x;
        double length = static_cast<double>(empty) * 2.0f / (static_cast<double>(a) * static_cast<double>(a));
        double radian = std::atan(length / static_cast<double>(a));
        degree = radian * 180.f / PI;
    }

    std::cout<<std::fixed<<std::setprecision(10);
    cout << degree << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#define _CRT_DISABLE_PERFCRIT_LOCKS
#include <bits/stdc++.h>

using namespace std;
#define BOOST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define x first
#define y second
#define fileIn freopen("1.txt", "r", stdin)
#define fileOut freopen("output.txt", "w", stdout)
#define dbg(n) cout << n <<"\n"
#define dbg2(n) cout << n <<" "
#define all(a) a.begin(), a.end()
#define cinArr(arr) for(auto &v : arr) cin>>v
#define coutArr(arr) for(auto &v : arr) cout<<v<<" "
#define FOR(i, a, b) for(int i = a; i < b; i++)
typedef int64_t ll;
typedef uint64_t ull;
typedef vector<int> vi;
typedef vector<vi > vii;


int main()
{
    BOOST;
    int n, k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<pair<int, int> > a;
    int i = 0;
    while(true){
        while(i < n && s[i] == '1') i++;
        if(i >= n) break;
        int st = i;
        while(i < n && s[i] == '0') i++;
        a.pb(make_pair(st, i - 1));
    }
    int ans = 0;
    if(a.size() < k) ans = s.size();
    else
    FOR(i, 0, a.size() - k + 1){
        int cur = 0;
        int j = a[i].x - 1, jj = a[i + k - 1].y + 1;
        while(j >= 0 && s[j] == '1') j--;
        while(jj < n && s[jj] == '1') jj++;
        j++;
        cur += jj - j;
        //dbg2(j); dbg(jj);
        ans = max(cur, ans);
    }

    cout<<ans;

    return 0;
}





















Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))

int main()
{
	int n, res = 0;
	cin >> n;
	vector<int> b(100000);
	rep(i, 0, n - 1)
	{
		int a;
		cin >> a;
		++b[a];
	}
	rep(i, 1, 99998)
	{
		int count = b[i - 1] + b[i] + b[i + 1];
		res = max(res, count);
	}
	cout << res << endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll a;
    long double b;
    cin>>a>>b;
    ll c=(b*100+0.5);
    cout <<a*c/100<<endl;
    return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

class UnionFind {
private:
	int n;
	int* par;
	int* hight;

	
public:
	UnionFind(int num) {
		n = num;
		par = new int[n];
		hight = new int[n];
		for (int i = 0; i < n; ++i) {
			par[i] = i;
			hight[i] = 1;
		}
	}
	~UnionFind() {
		delete[] par;
	}

	void unite(int a, int b) {
		int ra = root(a);
		int rb = root(b);
		if (ra == rb) return;

		if (hight[ra] > hight[rb]) {
			par[rb] = ra;
		}
		else if (hight[ra] < hight[rb]) {
			par[ra] = rb;
		}
		else {
			par[ra] = rb;
			++hight[rb];
		}
	}
	bool same(int a, int b) {
		return root(a) == root(b);
	}

	int numofRoot() {
		int counter = 0;
		for (int i = 0; i < n; ++i) if (par[i] == i) ++counter;
		return counter;
	}

	int root(int a) {
		while (par[a] != a) a = par[a];
		return a;
	}
};

using UF = UnionFind;

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

	int n, m;
	cin >> n >> m;
	pii* ab = new pii[m];
	rep(i, m) cin >> ab[i].first >> ab[i].second;

	UF uf(n);
	rep(i, m) {
		uf.unite(ab[i].first - 1, ab[i].second - 1);
	}

	map<int, int> friends;
	rep(i, n) {
		friends[uf.root(i)] += 1;
	}

	int ans = 0;
	for (auto p = friends.begin(); p != friends.end(); ++p) {
		ans = max(ans, (*p).second);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 14248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define rrep(n,i) for(int i = n-1; i>=0; --i)
#define PI 3.14159265
#define INF 1e9
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
void self_min(int &a,int b){
	a = min(a,b);
}

int main(){
	int n,k; cin >> n >> k;
	vector<int> arr(n+1);
	rep(i,n) cin >> arr[i+1];
	vector<ll> dp(n+1,INT_MAX);
	dp[0] = 0;
	dp[1] = 0;
	
	
	for(int i = 2; i<=n; i++){
		for(int j = 1; j<=k ; j++){
			if(i-j > 0){
				dp[i] = min(dp[i], dp[i-j] + abs(arr[i-j] - arr[i]));
			}
		}
	}	

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

Measured memory_bytes: 1408
import java.util.*;

public class Main{

    int w,h;
    char[][] map;
    int[][] d,dist;
    int[] x,y;
    int[] dx = {0,0,1,-1};
    int[] dy = {1,-1,0,0};
    int n,goal,ans;
    boolean[] v;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            w = sc.nextInt();
            h = sc.nextInt();
            if(w==0 && h==0) break;

            map = new char[h][w];
            x = new int[11];
            y = new int[11];
            int idx = 1;
            for(int i=0; i<h; i++){
                String s = sc.next();
                map[i] = s.toCharArray();
                for(int j=0; j<w; j++){
                    if(map[i][j]=='o'){
                        x[0] = j; y[0] = i;
                    }else if(map[i][j]=='*'){
                        x[idx] = j; y[idx] = i;
                        idx++;
                    }
                }
            }

            boolean end = false;
            dist = new int[idx][idx];
            for(int i=0; i<idx; i++){
                bfs(x[i],y[i]);
                for(int j=0; j<idx; j++){
                    dist[i][j] = d[y[j]][x[j]];
                    if(dist[i][j]==Integer.MAX_VALUE){
                        System.out.println(-1);
                        end = true;
                        break;
                    }
                }
                if(end) break;
            }

            if(end) continue;

            n = idx;
            v = new boolean[idx];
            int min = Integer.MAX_VALUE;
            ans = Integer.MAX_VALUE;
            for(int i=1; i<idx; i++){
                ans = Integer.MAX_VALUE;
                goal = i;
                dfs(0,0,0);
                min = Math.min(min,ans);
            }

            if(min==Integer.MAX_VALUE) System.out.println(-1);
            else System.out.println(min);
        }
    }

    void bfs(int sx, int sy){
        LinkedList<int[]> list = new LinkedList<int[]>();
        list.add(new int[]{sx,sy});
        d = new int[h][w];
        for(int i=0; i<h; i++) Arrays.fill(d[i],Integer.MAX_VALUE);
        d[sy][sx] = 0;

        while(list.size()>0){
            int[] xy = list.poll();
            int xx = xy[0], yy = xy[1];

            for(int i=0; i<4; i++){
                int nx = xx+dx[i], ny = yy+dy[i];
                if(nx>=0 && nx<w && ny>=0 && ny<h
                   && d[ny][nx]==Integer.MAX_VALUE
                   && map[ny][nx]!='x'){
                    list.add(new int[]{nx,ny});
                    d[ny][nx] = d[yy][xx]+1;
                }
            }
        }
    }

    void dfs(int pos, int cnt, int distt){
        if(pos==goal){
            if(cnt==n-1) ans = Math.min(ans,distt);
            return;
        }

        for(int i=1; i<n; i++){
            if(v[i]) continue;
            v[i] = true;
            dfs(i,cnt+1,distt+dist[pos][i]);
            v[i] = false;
        }
    }

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

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    vector<ll> a(3);
    for(i = 0;i < 3;++i){
        cin >> a.at(i);
    }
    sort(all(a));
    if(a.at(0) == 5 && a.at(1) == 5 && a.at(2) == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()

	m := map[string]int{}
	for i := 0; i < n; i++ {
		tmp := nextStr()
		m[tmp]++
	}

	fmt.Printf("AC x %d\n", m["AC"])
	fmt.Printf("WA x %d\n", m["WA"])
	fmt.Printf("TLE x %d\n", m["TLE"])
	fmt.Printf("RE x %d\n", m["RE"])

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n, m;
	ll sum=0;
	cin >> n >> m;
	vector<int>x(m),d(m-1);
	repp(i, 0, m)cin >> x[i];
	sort(x.begin(), x.end());
	if (m>n) {
		repp(i, 0, x.size() - 1) {
			d[i] = x[i + 1] - x[i];
			sum += d[i];
		}
		sort(d.begin(), d.end());
		reverse(d.begin(), d.end());
		repp(i, 0, n - 1)sum -= d[i];
	}
	else sum = 0;
	cout << sum << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
const int maxn=1e6+5;
int a[maxn],b[maxn];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        sint(a[i]);
    int sum=0;
    int k=1;
    for(int i=0;i<n;i++)
    {
        if(a[i]==k)
            k++;
        else
            sum++;
    }
    if(sum!=n)
    cout<<sum<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int H[N];
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        bool flg=true;
        for(int j=0;j<i;j++){
        if(H[j]>H[i]) flg=false;
        }
        if(flg) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def is_stable(A, B, n):
    for i in range(n):
        for j in range(i+1, n):
            if A[i]['value'] == A[j]['value']:
                for a in range(n):
                    for b in range(a+1, n):
                        if A[i] == B[b] and A[j] == B[a]:
                            return False
    return True


def show(Card, n):
    for i in range(n):
        if i != n-1:
            print(Card[i]['suit'] + str(Card[i]['value']), end=' ')
        else:
            print(Card[i]['suit'] + str(Card[i]['value']))


def bubble_sort(A, n):
    Card = A.copy()
    flag = 1
    while flag:
        flag = 0
        for i in range(n-1):
            if Card[i]['value'] > Card[i+1]['value']:
                Card[i], Card[i+1] = Card[i+1], Card[i]
                flag = 1
    show(Card, n)
    return Card


def selection_sort(A, n):
    Card = A.copy()
    for i in range(n-1):
        min_j = i
        for j in range(i+1, n):
            if Card[min_j]['value'] > Card[j]['value']:
                min_j = j
        if min_j != i:
            Card[i], Card[min_j] = Card[min_j], Card[i]
    show(Card, n)
    return Card


def main():
    n = int(input())
    A = list(input().split())
    Card = [
        {'value': int(a[1]), 'suit': a[0]}
        for a in A
    ]
    Card_bubble = bubble_sort(Card, n)
    if is_stable(Card, Card_bubble, n):
        print('Stable')
    else:
        print('Not stable')
    Card_selection = selection_sort(Card, n)
    if is_stable(Card, Card_selection, n):
        print('Stable')
    else:
        print('Not stable')


if __name__ == "__main__":
    main()



Measured memory_bytes: 5624
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    map<string,int>cnt;
    cnt["AC"]=0,cnt["WA"]=0,cnt["TLE"]=0,cnt["RE"]=0;
    int n;cin>>n;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        cnt[s]++;
    }
   cout<<"AC x "<<cnt["AC"]<<endl;
   cout<<"WA x "<<cnt["WA"]<<endl;
   cout<<"TLE x "<<cnt["TLE"]<<endl;
   cout<<"RE x "<<cnt["RE"]<<endl;
    return 0; 
} 

Measured memory_bytes: 3664
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define pb          push_back
#define MP          make_pair
#define int         long long
#define ll          long long
#define inf         0x3f3f3f3f
#define MOD         1000000007
#define ld          long double
#define eb          emplace_back
#define pii         pair<int,int>
#define ull         unsigned long long
#define all(v)      v.begin(), v.end()
#define f(i,x,n)    for(int i=x;i<n;i++)
#define fr(i,x,n)   for(int i=x;i>=n;i--)
#define fastio      ios::sync_with_stdio(false)

void IO() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {
    IO();
    fastio;
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int a, b, c, k; cin >> a >> b >> c >> k;
    int sum = 0;
    sum = min(a, k);
    k -= min(a, k);
    if (k > 0) {
    	k -= min(b, k);
    }
    if (k > 0) {
    	sum -= min(c, k);
    }
    cout << sum << endl;
    

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

void dfs(vector <bool>& visited, vector <int>& nodes, int node, vector <vector <int>>& asd) {
  if (visited[node]) return;
  visited[node] = true;
  for(auto nextnode: asd[node]) {
    if (visited[nextnode] == false) dfs(visited, nodes, nextnode, asd);
  }
  nodes.push_back(node);
}

int main(void) {
  int n, m, a, b;
  cin >> n >> m;
  vector <vector <int>> asd(n);
  ffor(m) {
    cin >> a >> b;
    a--;b--;
    asd[a].push_back(b);
  }
  
  // topological sort
  vector <bool> visited(n);
  vector <int> nodes;
  for(int i = 0; i < n; i++) dfs(visited, nodes, i, asd);
  reverse(nodes.begin(), nodes.end());
  
  vector <int> dp(n); // length of longest cycle up to i
  for(int i = 0; i < n; i++) {
    int node = nodes[i];
    for (int nextnode: asd[node]) {
      dp[nextnode] = max(dp[nextnode], 1 + dp[node]);
    }
  }
  int ans = 0;
  for (auto e: dp) ans = max(ans, e);
  cout << ans << '\n';
}

Measured memory_bytes: 12788
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000000
#define P1 31
#define P2 37
#define M  1000000007
#define M2 1000000009
#define pii pair<ll,ll>
typedef long long ll;
using namespace std;
const int N = 255001;
const int SQRTN = 320;
const int LOGN = 20;
const long double PI = acos(-1);
const long double TAU = 2*PI;

int a,b;

string solve(int a , int b){
    if(a==0||b==0)return "Zero";
    if(a<0&&b>0)return "Zero";
    if(a>0)return "Positive";
    if((b-a)&1)return "Positive";
    return "Negative";
}
string calc(int a , int b){
    int x = 1;
    for(int i = a ; i<=b ; i++)x*=i;
    if(x>0)return "Positive";
    if(x<0)return "Negative";
    return "Zero";
}

signed main(){

    cin >> a>> b;
    cout <<solve(a,b) << endl;




}


Measured memory_bytes: 256
//#include <sstream>
//#include <fstream>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <set>
//#include <list>
//#include <map>
//#include <unordered_map>
//#include <functional>
//#include <utility>
//#include <bitset>
//#include <cstdlib>
//#include <ctime>
//#include <cstdio>


#include <stdlib.h>
#include <iostream>
//#include <chrono> //clock
//#include <vector>
#include <string>
#include <iomanip>  //setprecision function
//#include <cmath>	//math
//#include <cstdio>
#include <vector>	//vector array
//#include <algorithm>	//STL algorithm
//#include <set> //STL library set
//#include <sstream> // for stringstream


using namespace std;
//using namespace std::chrono; 



//c++ templte for help...........................................................

//#define deb(x) cout<<#x<<" "<<x<<endl;/* for debuging  printing variable with name*/
//#define debb(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;										
//#define debbb(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;			

//typedef long long ll;

	
//for taking multiple input
//template<typename... T>
//void input(T&... t){
	//((cin>>t),...);
	//}
	
//for loop
//#define fo(i,n) for(ll i=0;i<(ll)n;i++)
//#define Fo(i,k,n) for(ll i=k;i<n;i++)


//to print vector element 
//template<typename T>
//void printV(T vec){
		//fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
	//}
	







//c++ template for help........................................................


int main() {
	//stringstream ss;
	//ss<<"akhil";
	//cout<<ss.str()<<endl;
	cout<<setprecision(16);
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	
	 // TESTCASE KO DEKH KA BHAUT SARA CONDITION GENERATE MAT KRO 
	 // PAPER PD CONFIRM HO JAO THORA JADA TIME HI KYU NA LGA
	 
	 // WHILE DOING THE QUESTION OF DYNAMIC PROGRAMMING GREEDY KA TRAH SOCHNA BAND KRO
	 // DP M DATA KA BHI USE KRNA PDTA HA BE BHULO MT 
	 // DP BHI WO LEETCODE WALE MATRIX KA QUESTION KI TARAH HA
	 // CONSTRAIN WILL BE THE DIMENSION OF DP
	 // DP MA STATE PTA KRO AUR PHIR FUNCTION GENERATE KRO
	 // OBJECT KO CHOOSE KIA YA NAE KIA AGAR KIA TO KYA HOGA AUR NAE KIA TO KYA HOGA
	 // KYA KYA CHEJ IMPORTANT HA WO STATE BN JYAGA AUR HUM LOG STATE KO CHANGE KR SKTA HA JYSA KNPSACK 2 WALE PROBLEM MA KIA THA
	 

	long long n,k;
	cin>>n>>k;
	
	long long sum=0;
	for(long long i=k-1;i<n;i++){
		sum+=((n*(n+1))/2)-((n-i-1)*(n-i)/2)-(i*(i+1)/2)+1;
	}


	cout<<(sum+1)%1000000007<<endl;




	
	
	return 0;
}





























Measured memory_bytes: 3652
import java.util.Scanner;
public class Main { 
    public static void main(String[] args) { 
        Scanner sc = new Scanner(System.in); 
        int H = sc.nextInt(); 
        int W = sc.nextInt();
        int i,j;
        while (H!=0 || W!=0) {  
            for(i=0;i<H;i++){ 
                for(j=0;j<W;j++){ 
                    if((i%2==0 && j%2==0)||(i%2==1 && j%2==1)){ 
                    System.out.print("#"); 
                    }else{ 
                    System.out.print("."); 
                    } 
                } 
                System.out.print("\n"); 
            } 
            System.out.print("\n"); 
            H = sc.nextInt(); 
            W = sc.nextInt(); 
        } 
    } 
}


Measured memory_bytes: 37872
#include<bits/stdc++.h>
using namespace std;
#define eps (1e-10)
#define INF (1e20)
static const double PI = acos(-1);
bool eq(double a,double b){
  return ( -eps < a-b && a-b < eps);
}
class Point{
public:
  double x, y;
  Point ( double x = 0, double y = 0): x(x), y(y){}
  Point operator + ( Point p ){ return Point(x + p.x, y + p.y); }
  Point operator - ( Point p ){ return Point(x - p.x, y - p.y); }
  Point operator * ( double a ){ return Point(x*a, y*a); }
  Point operator / ( double a ){ return Point(x/a, y/a); }
};
class Segment{
public:
  Point p1, p2;
  Segment(Point s = Point(), Point t = Point()): p1(s), p2(t){}
  Point base(){ return p2-p1;  }
};
typedef Point Vector;
typedef Segment Line;

bool   eq(Point a,Point b){ return (eq(a.x,b.x)&&eq(a.y,b.y)); }
double norm( Vector a ){ return a.x*a.x + a.y*a.y; }
double abs( Vector a ){ return sqrt(norm(a)); }
double dot( Vector a, Vector b ){ return a.x*b.x + a.y*b.y; }
double cross( Vector a, Vector b ){ return a.x*b.y - a.y*b.x; }

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw( Point p0, Point p1, Point p2 ){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if ( cross(a, b) > eps ) return COUNTER_CLOCKWISE;
    if ( cross(a, b) < -eps ) return CLOCKWISE;
    if ( dot(a, b) < -eps ) return ONLINE_BACK;
    if ( norm(a) < norm(b) ) return ONLINE_FRONT;
    return ON_SEGMENT;
}

bool isIntersect(Point p1, Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3) * ccw(p1,p2,p4) <=0 &&
          ccw(p3,p4,p1) * ccw(p3,p4,p2) <=0);
}

bool isIntersect(Segment s1,Segment s2){
  return isIntersect(s1.p1 , s1.p2 , s2.p1 , s2.p2);
}

Point getCrossPoint(Segment s1,Segment s2){
  assert(isIntersect(s1,s2));
  Vector base = s2.p2 - s2.p1;
  double d1 = abs(cross(base, s1.p1-s2.p1));
  double d2 = abs(cross(base, s1.p2-s2.p1));
  double t = d1/(d1+d2);
  return s1.p1 + (s1.p2 - s1.p1)*t;
}


int n;
vector<Segment> t;


int solve(){
  int ans=1;
  for(int i=0;i<n;i++){
    vector<double> A;
    A.push_back(0);
    A.push_back( abs(t[i].base()) );
    for(int j=0;j<i;j++)
      if(isIntersect(t[i],t[j]))
        A.push_back( abs( t[i].p1 - getCrossPoint(t[i],t[j]) ) );
    sort(A.begin(),A.end());
    for(int i=1;i<(int)A.size();i++){
      if(eq(A[i-1],A[i]))continue;
      ans++;
    }
  }
  return ans;
}

int main(){
  while(1){
    cin>>n;
    
    if(n==0)break;
    t.clear();
    double a,b,c,d;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c>>d;
      t.push_back((Segment){(Point){a,b},(Point){c,d}});
    }
    cout<<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1268
/*
author : seryu
title : CODE FESTIVAL 2017 qual B B
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;


void solve()
{
	int n, m;
	cin >> n;
	map<int, int> mp;
	rep(i, n)
	{
		int d;
		cin >> d;
		mp[d]++;
	}
	cin >> m;
	rep(i, m)
	{
		int t;
		cin >> t;
		mp[t]--;
	}
	for (auto e : mp)
	{
		if(e.second < 0)
		{
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
	return;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/06/01  Problem: M-Solutions2019 A / Link: https://atcoder.jp/contests/m-solutions2019  ----- */


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	LL ans = (N - 2) * 180;

	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int findLowerBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{

    auto low = lower_bound(arr.begin(),
                           arr.end(), p);

    return low - arr.begin();
}
int findUpperBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{
    auto up = upper_bound(arr.begin(),
                          arr.end(), p);

    return up - arr.begin();
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int r, g, b;
    cin >> r;
    int arr[r];
    if (r == 1)
    {
        cout << 0 << "\n";
        return 0;
    }
    int max1 = 0, min1 = 10001;
    for (int i = 0; i < r; i++)
    {
        cin >> arr[i];
        min1 = min(min1, arr[i]);
        max1 = max(max1, arr[i]);
    }
    cout << max1 - min1 << "\n";

    return 0;
}


Measured memory_bytes: 3580
import sys
from string import ascii_lowercase as AL

input = sys.stdin.readline


def main():
    S = input().rstrip()
    K = int(input())

    N = len(S)
    sub = set()
    for al in AL:
        for i in range(N):
            if S[i] == al:
                for j in range(1, 6):
                    sub.add(S[i:i + j])
        if len(sub) >= K:
            break

    sub = sorted(sub)
    ans = sub[K - 1]

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e&1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) { return 0; }
    if (n == r || r == 0) { return 1; }
    r = min(r, n-r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n-i+1))/(i); 
    }
    return ans;
}

ll nCr(tuple<ll,ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n+k-1, k);
}

template<typename T>
void print(const T &v) {
    cout << v << " ";
}

template<typename T>
void print(const vector<T> &v) {
    for (auto &i : v) {
        print(i);
    }
    cout << endl;
}

void solve() {
    ll n;
    cin >> n;
    vector<ll> h(n);
    for (auto &i : h) {
        cin >> i;
    }
    vector<ll> dp(n);
    dp[0] = 0;
    dp[1] = dp[0] + abs(h[0] - h[1]);
    for (int i = 2; i < n; ++i) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[n-1] << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

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


int main() {
	int n;
	long long sum = 1, arr[100005], max = 1e18;
	bool zero = false;
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%lld", &arr[i]);
		if(arr[i] == 0) zero = true;
	}if(zero){
		printf("0\n");
		return 0;
	}for(int i = 0;i < n;i++){
		if(arr[i] > max / sum){
			sum = -1;
			break;
		}
		sum *= arr[i];
	}
	
	printf("%lld\n", sum);
	return 0;
}


Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  vint A(n);
  rep(i,0,n) cin >> A[i];
  bitset<24> B(0);
  int right = 0;
  int ans = 0;
  int sum = 0;
  for(int left = 0;left < n;left++){
    if(right <= left) right = left;
    while(right < n && (sum + A[right]) == (B ^ bitset<24>(A[right])).to_ullong()){
      sum += A[right];
      B ^= bitset<24>(A[right]);
      right++;
    }
    ans += right - left;
    B ^= A[left];
    sum -= A[left];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int n,m;
struct Node{
	int x,y,num;
}point[100005];
bool cmp(Node a,Node b){
	if(a.x == b.x){
		return a.y < b.y;
	}
	return a.x < b.x;
}
bool cmp1(Node a,Node b){
	return a.num < b.num;
}
 
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&point[i].x,&point[i].y);
		point[i].num = i;
	}
	sort(point,point+m,cmp);
	int num = 1;
	for(int i=0;i<m-1;i++){
		if(point[i].x == point[i+1].x){
			point[i].y = num++;
		}
		else{
			point[i].y = num;
			num = 1;
		}
	}
	if(point[m-1].x == point[m-1].x) point[m-1].y = num;
	else point[m-1].y = ++num;
	sort(point,point+m,cmp1);
	for(int i=0;i<m;i++){
		printf("%06d%06d\n",point[i].x,point[i].y);
	}
	return 0;
}

Measured memory_bytes: 2688
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

N = int(input())
S = input()

x = 0
d = 0
for s in S:
    if s == '(': d += 1
    else: d -= 1

    x = min(x,d)

ans = '('*(-x) + S + ')'*(d-x)
print(ans)

Measured memory_bytes: 12224
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){
  int a[1001],n,m;

  while(cin >> n >> m,n|m){
    fill(a,a+n+1,0);
    int cnt=0,now=1,fg=0;
    while(true){
      for(int i=1;i<=n;i++){
	if(a[i])continue;
	if(cnt==n-1){
	  for(int j=1;j<=n;j++)
	    if(a[j]==0)cout << j << endl;
	  fg=1;
	  break;
	}
	if(now%m==0)a[i]=1,cnt++,now=0;
	now++;
      }
      if(fg)break;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n,m;
  cin>>n>>m;
  map<long long int,long long int> hoge;
  for(long long int i=0; i<n; i++){
    long long int k;
    cin>>k;
    for(long long int j=0; j<k; j++){
      long long int x;
      cin>>x;
      hoge[x]++;
    }
  }
  long long int ans=0;
  for(long long int i=1; i<=m; i++){
    if(hoge[i]==n){
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

ll dp[101][100001];

int main() {
    int N,W;
    cin >> N >> W;
    vector<int> w(N),v(N);
    // vector< vector<int> > dp(N);
    
    rep(i,N){
        cin >> w[i] >> v[i];    
    }
    
    rep(i,W+1){
        dp[0][i] = 0;
    }

    rep(i,N){
        rep(j,W+1){
            if(j < w[i]){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            }
        }      
    }
    
    cout << dp[N][W] << endl;
    
    return 0;
}

Measured memory_bytes: 82420
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int h,w;
    cin>>h>>w;
    
    char a[h][w];
    
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>a[i][j];
        }
    }
    
    int dp[h][w];
    
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(i==0 && j==0)
            {
                dp[i][j]=1;
            }
            else if(i==0)
            {
                if(a[i][j]=='#')
                {
                    dp[i][j]=0;
                }
                else
                {
                    dp[i][j]=dp[i][j-1];
                }
            }
            else if(j==0)
            {
                if(a[i][j]=='#')
                {
                    dp[i][j]=0;
                }
                else
                {
                    dp[i][j]=dp[i-1][j];
                }
            }
            else
            {
                if(a[i][j]=='#')
                {
                    dp[i][j]=0;
                }
                else
                {
                    dp[i][j]=(dp[i-1][j] + dp[i][j-1])%1000000007;
                }
            }
        }
    }
    
    cout<<dp[h-1][w-1];
    
    return 0;
}

Measured memory_bytes: 5120
n=int(input())
x=list(map(int,input().split()))
d={}
for a in x:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
    if a+1 in d:
        d[a+1]+=1
    else:
        d[a+1]=1
    if a-1 in d:
        d[a-1]+=1
    else:
        d[a-1]=1
print(max(d.values()))


Measured memory_bytes: 61548
#include <stdio.h>

int main() {
	int n;
	int d[50]={};
	int ans=0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &d[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ans+=d[i]*d[j];
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val n = getInt()
    val list = getInts()

    var m = list[0]
    var r = 1
    list.drop(1).forEach {
        if (it <= m) r++
        m = Math.min(m, it)
    }
    println(r)
}

fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }
fun getLong() = readLine()!!.toLong()
fun getLongs() = readLine()!!.split(" ").map { it.toLong() }


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    string S;
    cin >> S;
    int countR = 0, countB = 0;
    REP(i, S.size())
    {
        if (S[i] == '0') countR++;
        else countB++;
    }
    int ans = 2 * min(countR, countB);

    cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  double d,t,s; cin >>d >> t >> s;
  if((double)(d/s)<=t) puts("Yes");
  else puts("No");
}


Measured memory_bytes: 3716