akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> da(n);
  for(int i=0;i<n;i++)
    cin >> da[i];
  int ma=da[0],co=1;
  for(int i=1;i<n;i++){
    if(ma<=da[i]){
      co++;
      ma=da[i];
    }
  }
  cout << co << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
#include <deque>
#include <cmath>
#include <iomanip>

using namespace std;

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define MCLR(a) memset((a), -1 ,sizeof(a))
#define SZ(a) (sizeof(a))
#define FILL(a,v) fill((int*)a,(int*)(a+(SZ(a)/SZ(*(a)))),v)
#define SORT(c) sort((c).begin(),(c).end())

bool cheak(int x, int y, int xMax, int yMax)
{
	return x >= 0 && y >= 0 && xMax > x && yMax > y;
}
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 2147483647;


string	A[5010];
bool	d[5010][5010];
vector  <P> xa;
int		s[1010], t[1010];

int main()
{
	int n, m;
	cin >> n;
	REP(i, n)
	{
		int x;
		cin >> A[i] >> x;
		xa.push_back(P(x, i));
	}
	cin >> m;
	REP(i, m)
	{
		string S,T;
		cin >> S >> T;
		REP(j, n)
		{
			if (A[j] == S)
				s[i] = j;
			if (A[j] == T)
				t[i] = j;
		}
	}


	REP(i, m)
	{
		d[s[i]][t[i]] = true;
		d[t[i]][s[i]] = true;
	}

	bool f = true;
	while (f)
	{
		f = false;
		REP(i, n)
		{
			REP(j, n)
			{
				if (d[xa[i].second][xa[j].second])
				{
					if (xa[i].first != xa[j].first)f = true;
					int Min = min(xa[i].first, xa[j].first);
					xa[i].first = Min; xa[j].first = Min;
					
				}
			}
		}
	}

	int ans = 0;
	REP(i, n)
		ans += xa[i].first;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 22948
N, K = map(int, input().split())
ashi = list(map(int, input().split()))
 
if N<=K:    
    print(abs(ashi[-1]-ashi[0]))
    exit()
 
arr = [0]*N
for i in range(1,K+1,1):
    arr[i] = abs(ashi[i]-ashi[0])
 
 
for i in range(K+1,N,1):
    x = arr[i-1]+abs(ashi[i]-ashi[i-1])
    for j in range(1,K+1,1):
        if arr[i-j]+abs(ashi[i]-ashi[i-j]) < x:
            x=arr[i-j]+abs(ashi[i]-ashi[i-j])
    arr[i] = x
 
print(arr[-1])

Measured memory_bytes: 52448
n = int(input())
t = [0]*n
for i in range(n):
    p = int(input())-1
    t[p] = i
l = 1
m = 1
for i in range(n-1):
    if t[i] < t[i+1]:
        l += 1
    else:
        if m < l:
            m = l
        l = 1
if m < l:
    m = l
print(n-m)


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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n, a, b;
    cin>>n>>a>>b;
    cout<<min(n*a, b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#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>;

int main() {
  string s;
  cin >> s;
  if(s.size()%2==1){
    cout << "No" << endl;
    return 0;
  }
  for(int i = 0; i < s.size(); ++i){
    if(!(s[0]=='h' && s[1]=='i')){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
def weight
  master = Array.new(10) { |i| 2**i }.reverse
  while gets
    element = $_.to_i
    puts master.select { |i| i <= element }.each_with_object([]) { |i, tmp|
      (element -= i) && (tmp << i) if i <= element
    }.sort.join(' ')
  end
end

weight

Measured memory_bytes: 8576
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim().split(' ');
  var a = Number(inputs[0]);
  var b = Number(inputs[1]);
  var c = Number(inputs[2]);
 
var sortTable = [a,b,c].sort(function(a,b){
    return a-b;
});
console.log(sortTable.join(' '));
 
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15460
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  bool flag;
  flag=true;
  for(long long int i=1;i<=100000;i++){
    long long int c=i*0.08;
    long long int d=i*0.1;
    if(c==a & d==b){
      cout<<i<<endl;
      flag=false;
      break;
    }
  }
  if(flag){
    cout<<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  string s,t;
  cin >> s >> t;
  
  if(s.size() == t.size()){
    REP(i,s.size()){
      cout << s[i] << t[i];
    }
  }
  
  else{
    REP(i,t.size()){
      cout << s[i] << t[i];
    }
    cout << s[s.size()-1];
  }
  
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
#include<bits/stdc++.h>
typedef long long int ll;
const int maxn=1e6+7;
using namespace std;

int main()
{

    ios::sync_with_stdio(false);

    char ch1[1005],ch2[1005];
    cin>>ch1>>ch2;
    int y=strlen(ch2);
    int Max=0;
    for(int i=0;i<=strlen(ch1)-y;i++)
    {
        int t=i;
        int sum=0;
        for(int j=0;j<strlen(ch2);j++,i++)
        {
            if(ch1[i]==ch2[j])sum++;
        }
        i=t;
        if(sum>Max)Max=sum;
    }
    printf("%d\n",y-Max);
    return 0;
}

Measured memory_bytes: 3784
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <map>
using namespace std;

typedef long long ll;
const ll inf = 1e15;
ll mod = 1000000007;

int main() {
    ll n;
    scanf("%lld",&n);
    map<string,ll> strs;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        strs[s]++;
    }
    ll ans = 0;
    for (const auto& p : strs) {
        ll tmp = p.second * (p.second - 1) / 2;
        ans += tmp;
    } 
    printf("%lld\n",ans);
}

Measured memory_bytes: 11136
#include <cstdio>
#include <vector>
#define MAXN 200005
using namespace std;

int n, m1, m2, cc[MAXN], ccCount[MAXN], sol[MAXN];
int ncc;
bool uz[MAXN];
vector<int> G1[MAXN], G2[MAXN];

void DFS1(int u) {
    cc[u] = ncc;
    for(auto x: G1[u]) {
        if(!cc[x])
            DFS1(x);
    }
}

void DFS2(int u, vector<int> &v) {
    uz[u] = 1;
    v.push_back(u);
    for(auto x: G2[u]) {
        if(!uz[x])
            DFS2(x, v);
    }
}

int main() {
    scanf("%d %d %d", &n, &m1, &m2);
    for(int i = 1; i <= m1; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        G1[x].push_back(y);
        G1[y].push_back(x);
    }

    for(int i = 1; i <= m2; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        G2[x].push_back(y);
        G2[y].push_back(x);
    }

    for(int i = 1; i <= n; ++i) {
        if(!cc[i]) {
            ++ncc;
            DFS1(i);
        }
    }

    for(int i = 1; i <= n; ++i) {
        if(!uz[i]) {
            vector<int> v;
            DFS2(i, v);

            for(auto x: v)
                ++ccCount[cc[x]];
            for(auto x: v)
                sol[x] += ccCount[cc[x]];
            for(auto x: v)
                ccCount[cc[x]] = 0;
        }
    }

    for(int i = 1; i <= n; ++i)
        printf("%d ", sol[i]);
    printf("\n");

    return 0;
}

Measured memory_bytes: 18816
# -*- coding: utf-8 -*-

n,k = list(map(int, list(input().split())))
scores = list(map(int, list(input().split())))

for i in range(k + 1, n + 1):
    remove = scores[i - k - 1]
    add    = scores[i - 1]

    if remove < add:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 32508
package main

import (
	"fmt"
	"math"
)

func main(){
	var n, m, k int
	for {
		fmt.Scan(&n, &m, &k)
		if n == 0 && m == 0 && k == 0{
			break
		}

		dp := make([][]int, n+1)
		for i:= 0; i < n+1; i++{
			dp[i] = make([]int, m*n + 1)
		}

		for i := 1; i <=m ; i++{
			dp[1][i] = 1
		}

		for i:= 1; i < n; i++{
			for j := 0; j <= i * m; j++{
				for k := 1; k <= m; k++{
					dp[i+1][j+k] += dp[i][j]
				}
			}
		}

		count := 0.0
		div := math.Pow(float64(m), float64(n))
		for i := 0; i <= n * m; i++{
			bill := 0.0
			if i <= k{
				bill = 1.0
			} else {
				bill = float64(i - k)
			}
			count += bill * float64(dp[n][i]) / div
		}
		fmt.Printf("%.010f\n", count)
	}
}



Measured memory_bytes: 1496
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
    int n, k;
    cin >> n >> k;

    int ans = 1;
    ans *= k;
    rep (i, n - 1) ans *= k - 1;

    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.split.map(&:to_i)

$cnt = 0
$INF = 10**9

def marge(l, r)
  l.push($INF)
  r.push($INF)
  length = l.length-1 + r.length-1
  return Array.new(length){$cnt+=1; (l.first <= r.first ? l : r).shift}
end

def marge_sort(s)
  if s.length >= 2
    mid = s.length/2
    l = marge_sort(s[0..mid-1])
    r = marge_sort(s[mid..-1])
    s = marge(l, r)
  end
  return s
end

puts marge_sort(s).join(" ")
puts $cnt


Measured memory_bytes: 75460
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e18
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;


ll x,y,z,K;

ll a[1010],b[1010],c[1010];
vector<ll> vec;
int main(){
  cin>>x>>y>>z>>K;
  rep(i,x)cin>>a[i];
  sort(a,a+x);
  reverse(a,a+x);
  rep(i,y)cin>>b[i];
  sort(b,b+y);
  reverse(b,b+y);
  rep(i,z)cin>>c[i];
  sort(c,c+z);
  reverse(c,c+z);

  ll ans=0;
  int ai=0,bi=0,ci=0;

  rep(i,x)rep(j,y)rep(k,z){
    if((i+1)*(j+1)*(k+1)<=K)vec.push_back(a[i]+b[j]+c[k]);
    else break;
  }

  sort(vec.begin(),vec.end(),greater<ll>());
  rep(i,K)cout<<vec[i]<<endl;



}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n,ans=0;
    cin>>n;
    for(int i=n;i>=1;i--){
        int digit=floor(log10(i)+1);//桁数
        if(digit%2==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>

using namespace std;

int main(){
  string w,t;
  int count = 0;
  cin >> w;
  for(int i=0;i < w.size();i++){
    if('A' <= w[i] && w[i] <= 'Z'){
      w[i] += 'a' - 'A';
    }
  }
  cin >> t;
  while(t != "END_OF_TEXT"){
    for(int i=0;i < w.size();i++){
      if('A' <= t[i] && t[i] <= 'Z'){
        t[i] += 'a' - 'A';
      }
    }
    if(w == t) count++;
    cin >> t;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3204
n = gets.to_i
s = Array.new(n)
for i in 0..(n-1)
  s[i] = gets.chomp.split("")
end
flag = 0
wordcnt = Hash.new(0)
for i in 0..(n-1)
  if i > 0
    if s[i-1][-1] != s[i][0]
      flag = 1
      break
    end
  end
  wordcnt[s[i].join] += 1
end
wordcnt.each do |k, v|
  if v > 1
    flag = 1
    break
  end
end
if flag > 0
  puts "No"
else
  puts "Yes"
end

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

int main()
{
 //   printf("Hello world!\n");
    int a, b, c;
    int arr[3] = {a, b, c};
    for(int i = 0; i < 3; i++)
    {
        scanf("%d", &arr[i]);
    }
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3-1; j++)
        {
            if(arr[j] > arr[j+1])
            {
                a = arr[j];
                arr[j]=arr[j+1];
                arr[j+1] =a;
            }
        }
    }
    if(arr[0] + arr[1] == arr[2]){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 1712
import Data.Array

exist_pos::Array Int Char -> [(Char,Maybe (Int,Int))]
exist_pos ar = let (f,l) = bounds ar in
                [(c,let ls = [i |i<-[f..l],(ar!i)==c] in if ls == [] then Nothing else Just(minimum ls,maximum ls))|c<-['a'..'z']]

make_ar::(Int,Int)->[(Char,Maybe (Int,Int))]->[Int]
make_ar (f,l) ls  = [length (filter (cond i) ls)|i<-[f..l]]
                  where cond i (_,v) = case v of
                                  Nothing    -> False
                                  Just (s,e) ->  (s <= i)&&(i < e)

solver::Array Int Char -> Int
solver ar = let (f,l) = bounds ar in
            let ls = exist_pos ar in
            let val = make_ar (f-1,l) ls in
            maximum val

main::IO()
main=do
  _<-getLine
  st<-getLine
  let ar = listArray (1,length st) st
  print (solver ar)

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int n ;
    cin >> n;
    vector<pair<int,int>> a(n);
    int cnt = 0;
    REP(i,n){
        int c,b;
        cin >> c >> b;
        a[i] = make_pair(c,b);
    }
    REP(i,n){
        if(a[i].first == a[i].second){
            cnt++;
        }else{cnt = 0;
        }
        if(cnt >= 3){
            Yes();
            return 0;
        }
    }
    No();
    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
const int MaxN=100010;
int N,M,a[MaxN],b[MaxN];
namespace bf{
	int Q[1<<20],D[1<<20];
	int solve(){
		for(int s=0;s<1<<N;s++)D[s]=-1;
		int*h=Q,*t=Q+1;D[*h=0]=0;
		for(;h<t;h++){
			for(int i=0;i<M;i++)if((*h>>a[i]-1&1)==(*h>>b[i]-1&1)){
				int x=*h^1<<a[i]-1^1<<b[i]-1;
				if(D[x]<0)D[*t++=x]=D[*h]+1;
			}
		}
		return D[(1<<N)-1];
	}
}
namespace tree{
	struct edge{int to;edge*next;}E[MaxN*2],*ne,*fir[MaxN];
	int deg[MaxN];
	void link(int u,int v){*ne=(edge){v,fir[u]};fir[u]=ne++;deg[u]++;}
	int S[MaxN],f[MaxN],C[MaxN];
	long long list[MaxN];
	long long solve(){
		ne=E;
		for(int i=1;i<=N;i++)fir[i]=0,deg[i]=0,f[i]=1;
		for(int i=0;i<M;i++)link(a[i],b[i]),link(b[i],a[i]);
		if(M<N)deg[1]+=2;
		int*t=S;
		for(int i=1;i<=N;i++)deg[i]==1?*++t=i:1;
		long long s=0;
		while(t>S){
			int x=*t--;
			deg[x]=0;
			for(edge*e=fir[x];e;e=e->next)if(deg[e->to]){
				f[e->to]-=f[x];
				if(--deg[e->to]==1)*++t=e->to;
			}
			s+=f[x]>0?f[x]:-f[x];
		}
		if(M<N)return f[1]?-1:s;
		int len=0,x=1;
		while(!deg[x])++x;
		while(deg[x]){
			C[len++]=f[x];
			deg[x]=0;
			for(edge*e=fir[x];e;e=e->next){
				if(deg[e->to]){x=e->to;break;}
			}
		}
		if(len<2)return*C?-1:s;
		for(int i=*list=0;i<len;i++)list[i+1]=list[i]+(i&1?-C[i]:C[i]);
		if(len%2==0){
			if(list[len])return-1;
			std::nth_element(list,list+len/2,list+len);
			for(int i=0;i<len;i++)i<len/2?s-=list[i]:s+=list[i];
		}
		else{
			if(list[len]%2)return-1;
			long long u=list[len]/2;
			for(int i=0;i<len;i++){
				s+=u>0?u:-u;
				u=C[i]-u;
			}
		}
		return s;
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	while(scanf("%d%d",&N,&M)==2){
		for(int i=0;i<M;i++)scanf("%d%d",a+i,b+i);
		long long ans=tree::solve();
		printf("%lld\n",ans);
		/*
		if(ans1!=ans2){
			printf("%d %d\n",N,M);
			for(int i=0;i<M;i++)printf("%d %d\n",a[i],b[i]);
			return puts("WA"),0;
		}
		*/
	}
	//puts("OK");
}

Measured memory_bytes: 8704
#include<stdio.h>
int n,i;
int compare(const void *a,const void *b){
    return *(int*)a-*(int*)b;
}
int main(void){
    int a,b;
    int c[3]={1,2,3};
    scanf("%d%d",&a,&b);
    for(i=0;i<3;i++){
        if(c[i]!=a&&c[i]!=b)
        printf("%d\n",c[i]);
    }
    return 0;

}

Measured memory_bytes: 128
// AOJ 0301: Baton Relay Game
// 2017.10.31

#include <stdio.h>

typedef struct { int pre, nxt, f; } T;
T tbl[200002];
int n, m;
int a[200002];
char buf[800000], *p;

void calc()
{
	int i, j, cur, pre, nxt;
	
	cur = 0;
	for (i = 0; i < m; i++) {
		j = a[i];
		if (j & 1) while (j--) cur = tbl[cur].pre;
		else       while (j--) cur = tbl[cur].nxt;
		tbl[cur].f = 0;
		pre = tbl[cur].pre, nxt = tbl[cur].nxt;
		tbl[pre].nxt = nxt, tbl[nxt].pre = pre;
		cur = nxt;
	}
}

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int q, i;

	fgets(p=buf, 30, stdin), n = getint(), p++, m = getint(), p++, q = getint();

	for (i = 0; i < n; i++) tbl[i].nxt = i+1, tbl[i].pre = i-1, tbl[i].f = 1;
	tbl[0].pre = n-1, tbl[n-1].nxt = 0;

	fgets(p=buf, sizeof(buf), stdin);
	for (i = 0; i < m; i++) a[i] = getint(), p++;

	calc();

	fgets(p=buf, sizeof(buf), stdin);
	while (q--) {
		i = getint(), p++;
		putchar('0' + tbl[i].f), putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 5372
import copy

def main():
	N, M, Q = [int(n) for n in input().split(" ")]
	q = [[int(a) for a in input().split(" ")] for i in range(Q)]
	all_series = get_series(N, M)
	points = [0]
	for l in all_series:
		points.append(get_score(l, q))
	print(max(points))

def get_score(l, q):
	return sum([q[i][3] if l[q[i][1] - 1] - l[q[i][0] - 1] == q[i][2] else 0 for i in range(len(q))])

def get_series(N, M):
	# N: number of elms
	# M: upper limit of val of elm
	all_series = []
	checked = [[0] * M for i in range(N)]
	to_check = [[0, j + 1] for j in range(M)]
	series = [0 for k in range(N)]
	while len(to_check) > 0:
		checking = to_check.pop(-1)
		series[checking[0]] = checking[1]
		if checking[0] == N - 1:
			l = copy.deepcopy(series)
			all_series.append(l)
		else:
			to_check.extend([[checking[0] + 1, k] for k in range(checking[1], M + 1)])
	return all_series

main()

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

void update(vector<int>& A){
    priority_queue<array<int, 2>> q;
    for(int i=0; i<A.size(); i++){
        q.push(array<int,2>{
            -max(i-A[i], (int)0),
            -min(i+A[i], (int)A.size()-1),
        });
    }
    priority_queue<int> q2;
    int count = 0;
    for(int i=0; i<A.size(); i++){
        while(!q.empty() && -q.top()[0] <= i){
            q2.push(q.top()[1]);
            q.pop();
            count++;
        }
        while(!q2.empty() && -q2.top() < i){
            q2.pop();
            count--;
        }
        A[i] = count;
    }
}

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0; i<K; i++){
        update(A);
        bool dobreak = true;
        for(auto v : A){
            if(v != N) dobreak = false;
        }
        if(dobreak) break;
    }
    for(auto v : A) cout << v << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 7692
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

//Nayeem Shahriar Joy,Applied Physics And Electronic Engineering,University of Rajshahi.

int main(void)

{
    unsigned long long int n,i,ans=1;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        ans=(ans*i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3032
#include<iostream>
#include<math.h>

using namespace std;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    float d, t, s;

    cin>>d>>t>>s;

   float time = d/s;

    if((time-t)<=0)
        cout<<"Yes";
    else
        cout<<"No";


    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <iterator>
#include <list>
#include <vector>

int main(void) {
    int n, q;
    std::cin >> n >> q;

    std::vector<std::list<int>> lists{};
    lists.resize(n);
    for (int i = 0; i < q; ++i) {
        int kind;
        std::cin >> kind;

        int t;
        switch (kind) {
            case 0:
                int x;
                std::cin >> t >> x;
                lists[t].push_back(x);
                break;
            case 1:
                std::cin >> t;
                for (auto iter = lists[t].begin(); iter != lists[t].end();
                     ++iter) {
                    std::cout << *iter;
                    if (iter != std::prev(lists[t].end())) std::cout << ' ';
                }
                std::cout << std::endl;
                break;
            case 2:
                int s;
                std::cin >> s >> t;
                lists[t].splice(lists[t].end(), lists[s]);
                break;
            default:
                std::cerr << "kind: ?";
        }
    }
}


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

int main(){
  
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  map<int,int> c;
  rep(i,n) c[a[i]]++;
  sort(all(a));
  int maxValue = a[n-1];
  vector<bool> b(maxValue+1,1);
  rep(i,n){
    ll now = a[i];
    if(b[now] == 0) continue;
    b[now] = 1;
    for(int j=now*2;j<=maxValue;j+=now){
      b[j] = 0;
    }
  }
  int ans = 0;
  rep(i,n){
    int now = a[i];
    if(c[now]>1) continue;
    ans += b[now];
  }
  cout << ans << endl;
}


Measured memory_bytes: 13460
import java.util.Scanner;

public class Main {

	static Scanner in = new Scanner(System.in) ;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String str = in.next() ;
		String a = str.substring(0,2) ;
		String b = str.substring(2,4) ;
		int a1 = Integer.parseInt(a) ;
		int b1 = Integer.parseInt(b) ;
//		System.out.println(a1+" "+b1);
		int a_pre = 0 ;
		int b_pre = 0 ;
		if(a1>=1&&a1<=12){
			a_pre += 1 ;
		}
		if(b1>=1&&b1<=12){
			b_pre += 1 ;
		}
		
		if(a_pre==0&&b_pre!=0){
			System.out.println("YYMM");
		}
		if(a_pre!=0&&b_pre==0){
			System.out.println("MMYY");		
		}
		if(a_pre==0&&b_pre==0){
			System.out.println("NA");
		}
		if(a_pre!=0&&b_pre!=0){
			System.out.println("AMBIGUOUS");
		}
	}

}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0;i < N;i++) {
        cin >> A.at(i);
    }
    vector<int> B(N);
    for(int i = 0;i < N;i++) {
        B.at(i) = A.at(i);
    }
    sort(B.begin(),B.end());
    for(int i = 0;i < N;i++) {
        if(A.at(i) == B.at(N - 1)) {
            cout << B.at(N - 2) << endl;
        }else {
            cout << B.at(N - 1) << endl;
        }
    }
}


Measured memory_bytes: 3200
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;

void main()
{
	int n;
	while (n = readln.chomp.to!int, n) {
		auto p = readln.chomp.split.map!(to!int).array;
		auto x = new int[](p.length);
		x[] = -1;
		int cnt;
		while (1) {
			foreach (i; 0..x.length) {
				x[i] = p.count!(a => a == p[i]).to!int;
			}
			if (x == p) break;
			p = x.dup;
			cnt++;
		}
		cnt.writeln;
		x.map!(to!string).join(" ").writeln;
	}
}

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

int main() {
    int n; cin >> n;
    vector<int> b(n);
    rep(i,n-1) cin >> b[i];
    b[n-1] = 0;
    int ans = 0;
    rep(i,max(n-2,1)) {
        ans += min(b[i], b[i+1]);
    }
    ans += b[0] + b[n-2];
    cout << ans << endl;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    string temp="";
    for(int i=0;i<s.length();i++){
        temp+=s[i];
        temp+=t[i];
    }
    cout<<temp;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
 
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main(void){
  int N;
  cin >> N;
  int streak = 0;
  bool flag = false;
  rep(i,N){
    int d1,d2;
    cin >> d1 >> d2;
    if(d1 == d2){
      streak++;
      if(streak == 3){
        flag = true;
      }
    }
    else{
      streak = 0;
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

      

Measured memory_bytes: 3636
def a():
    n=int(input())
    w=list()
    for i in range(n):
        z=input()
        w.append(z)
    for i in range(1,n):
        if w[i][0]!=w[i-1][len(w[i-1])-1]:
            print("No")
            return 0
    w.sort()
    for i in range(n-1):
        if w[i]==w[i+1]:
            print("No")
            return 0
    print("Yes")
    return 0
a()

Measured memory_bytes: 38384
#include <stdio.h>

int main(void)
{
int N,K,X,Y;

scanf("%d",&N);
scanf("%d",&K);
scanf("%d",&X);
scanf("%d",&Y);

if (K>N){
printf("%d\n", N*X);
}
else
{
printf("%d\n", K*X+(N-K)*Y);
}

return 0;
}

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

using namespace std;

int main()

{

  int h1,h2,m1,m2,k;

  cin >> h1>>m1>>h2>>m2>>k;

  int ans =(h2-h1)*60+m2-m1-k;

  cout<<ans<<endl;

  }//クリップをタップすると、

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7
// https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_b

struct mod_int {
    ll val;
    constexpr mod_int(ll v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr mod_int operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr mod_int operator + (const mod_int& r) const noexcept { return mod_int(*this) += r; }
    constexpr mod_int operator - (const mod_int& r) const noexcept { return mod_int(*this) -= r; }
    constexpr mod_int operator * (const mod_int& r) const noexcept { return mod_int(*this) *= r; }
    constexpr mod_int operator / (const mod_int& r) const noexcept { return mod_int(*this) /= r; }
    constexpr mod_int& operator += (const mod_int& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr mod_int& operator -= (const mod_int& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr mod_int& operator *= (const mod_int& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr mod_int& operator /= (const mod_int& r) noexcept {
        ll a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            ll tmp = 0;
            // tmp = a; a = b; b = tmp; としてるのは、
            // swap()がconstexprじゃなくて使えないから
            a -= t * b; tmp = a; a = b; b = tmp;
            u -= t * v; tmp = u; u = v; v = tmp;
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const mod_int& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const mod_int& r) const noexcept {
        return this->val != r.val;
    }
    friend ostream& operator << (ostream &os, const mod_int& x) noexcept {
        return os << x.val;
    }
    friend constexpr mod_int modpow(const mod_int &a, ll n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = mod_int;

int main() {
    ll n, k; cin >> n >> k;
    vector<int> a(n); rep(i, 0, n) cin >> a[i];

    mint tentou1 = 0;
    rep(i, 0, n - 1) {
        rep(k, i + 1, n) {
            if (a[i] > a[k]) tentou1 += 1;
        }
    }

    mint tentou2 = 0;
    rep(i, 0, n) {
        rep(k, 0, n) {
            if (a[i] > a[k]) tentou2 += 1;
        }
    }

    mint ans = tentou1 * k;
    ans += tentou2 * (mint(k) * (mint(k) - 1) / 2);
    cout << ans << endl;
}


Measured memory_bytes: 256
import math

A, B, N = map(int,input().split())

if N < B:
    temp1 = math.floor(A*1/B) - A*math.floor(1/B)
    temp2 = math.floor(A*N/B) - A*math.floor(N/B)
    ans = max(temp1, temp2)

if N >= B:
    temp1 = math.floor(A*1/B) - A*math.floor(1/B)
    temp2 = math.floor(A*(B-1)/B) - A*math.floor((B-1)/B)
    ans = max(temp1, temp2)

print(ans)

Measured memory_bytes: 9184
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,M=1e6+10,size=1<<20,mod=998244353;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,m,inv[M],c[M],f[M],prime[M],tot,mu[M]; bool v[M];
ll ans;

void upd(int &x){x+=x>>31&mod;}
void upd(ll &x){x+=x>>63&mod;}

void get(int x) {
	inv[1]=1; for(int i=2;i<=x;i++) inv[i]=(ll)inv[mod%i]*(mod-mod/i)%mod;
	mu[1]=1;
	for(int i=2;i<=x;i++) {
		if(!v[i]) 
			prime[++tot]=i,mu[i]=-1;
		for(int j=1;i*prime[j]<=x;j++) {
			v[i*prime[j]]=1;
			if(i%prime[j]) mu[i*prime[j]]=-mu[i];
			else break;
		}
	}
	for(int i=1;i<=x;i++)
		for(int j=i;j<=x;j+=i)
			upd(f[i]+=c[j]-mod);
}

int main() {
	qr(n);
	for(int i=1,x;i<=n;i++) {
		qr(x); m=max(m,x);
		upd(c[x]+=x-mod);
		ans-=x;//
	}
	get(m);
	for(int i=1;i<=m;i++) if(mu[i])
		for(int j=1;i*j<=m;j++) 
			(ans+=(ll)mu[i]*f[i*j]*f[i*j]%mod*inv[j]%mod) %= mod;
	upd(ans%=mod); pr2(ans*inv[2]%mod);
	return 0;
}



Measured memory_bytes: 18688
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    from collections import Counter
    import math
    from functools import lru_cache

    @lru_cache(None)
    def combination(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
    c = Counter(A)
    
    ta = 0
    for k,v in c.items():
        if v >= 2:
            ta += combination(v, 2)
            
    # dp = [-1] * (N+1)
    ans = []
    for i in range(N):
        t = ta
        if c[A[i]] >= 2:
            t -= combination(c[A[i]], 2)
        if c[A[i]]-1 >= 2:
            t += combination(c[A[i]]-1, 2)
        
        ans.append(t)

 
    for i in ans:
        print(i)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 121168
# Minimum Spanning Tree

INF = 10**5
N, *W = map(int, open(0).read().split())
W = tuple(zip(*[iter(INF if w < 0 else w for w in W)]*N))

S = set([0])
ans = 0
while len(S) < N:
    min_w = INF
    u = -1
    for v in S:
        for j, w in enumerate(W[v]):
            if j not in S and w < min_w:
                min_w = w
                u = j

    ans += min_w
    S.add(u)
    
print(ans)



Measured memory_bytes: 6508
#include <iostream>

using namespace std;

int main(){
  int n,i,j;
  cin >> n;
  int c[n],s[n],f[n];
  for(i=0;i<n-1;i++)cin >> c[i] >> s[i] >> f[i];
  for(i=0;i<n;i++){
    int t=0;
    for(j=i;j<n-1;j++){
      if(t<s[j])t=s[j];
      else if(t%f[j]==0);
      else t = t+f[j]-t%f[j];
      t+=c[j];
    }
    cout << t << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(_) for _ in input().split()]

    if 0 in A:
        print(0)
        return

    result = 1
    # count = 0
    for i in A:
        # l = len(str(i)) - 1
        # if l != 0:
        #     count = count + l
        result = result * i
        if result > 1000000000000000000:
            print(-1)
            return

    print(result)

if __name__ == "__main__":
    main()


Measured memory_bytes: 21660
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC059Comparison
{
    class Program
    {
        static void Main(string[] args)
        {
            string A = Console.ReadLine();
            string B = Console.ReadLine();

            if(A.Length > B.Length)
            {
                Console.WriteLine("GREATER");
                return;
            }
            else if(A.Length < B.Length)
            {
                Console.WriteLine("LESS");
                return;
            }
            else
            {
                for(int i=0; i < A.Length; i++)
                {
                    if(A[i] > B[i])
                    {
                        Console.WriteLine("GREATER");
                        return;
                    }
                    else if(A[i] < B[i])
                    {
                        Console.WriteLine("LESS");
                        return;
                    }
                }
                Console.WriteLine("EQUAL");
            }

        }
    }
}


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

int main() {
  int N,M,sum;
  cin >> N;
  M = N;
  while (N > 0) {
    sum += N % 10;
    N = N/10;
  }
  if (M%sum == 0) {
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
    
}


Measured memory_bytes: 764
#include <stdio.h>
#include <math.h>
#define A 0
#define B 1
#define C 2
#define X 0
#define Y 1

void syori1(double a,double b,double c,double d,double e,double f,double *x,double *y){		/*x + y= (ªÓ½Â) Ìûö®ðð­B*/
	*x=( c*(e/b)-f )/( a*(e/b)-d );
	*y=( ( c-(a * *x) )/b );
}

int syori2(double n){	/*	¬_æ4ÊðlÌÜü	yg¢ûzn+=syori2(n) */
	n*=1000;
	n = n - (double)(int)n;
	if(n>=0.5){
		return (0.001);
	}else{
		return 0.;
	}
}

int main(){
	double	xy[3][2],
			xp,yp,r,
			a,b,c,
			cosA,
			as[2],at[2],uhen[2],
			t,s,
			AO[2];					/*AOxNg{x,y}*/
	int n,							/*f[^Zbg*/
		i;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf",&xy[A][X],&xy[A][Y],&xy[B][X],&xy[B][Y],&xy[C][X],&xy[C][Y]);
		
		c=sqrt( pow( xy[A][X] - xy[B][X] ,2) + pow( xy[A][Y] - xy[B][Y] ,2) );	/*	|AB|	(xNgÌå«³)	*/
		a=sqrt( pow( xy[B][X] - xy[C][X] ,2) + pow( xy[B][Y] - xy[C][Y] ,2) );	/*	|BC|						*/
		b=sqrt( pow( xy[C][X] - xy[A][X] ,2) + pow( xy[C][Y] - xy[A][Y] ,2) );	/*	|AC|						*/
			
		cosA	= ( pow(b,2) + pow(c,2) - pow(a,2) ) / (2*b*c);				/*	]·èæè		*/
		
		as[0]	= pow(c,2);													/*	|AB|^2				*/
		at[0]	= c*b*cosA;													/*	|AB|*|AC|*cos (A)	*/
		uhen[0]	= as[0]/2;													/*	sÌWÌQ		*/
		as[1]	= c*b*cosA;													/*	at[0]É¯¶			*/
		at[1]	= pow(b,2);													/*	|AC|^2				*/
		uhen[1]	= at[1]/2;													/*	tÌWÌQ		*/
		
		syori1(at[0],as[0],uhen[0],at[1],as[1],uhen[1],&t,&s);				/*y¨mç¹zsÆtªoÜµ½B()t+s=ÌA§ûö®*/
		
		AO[X]= s*( xy[B][X] - xy[A][X] ) + t*( xy[C][X] - xy[A][X] );		/*	AO = a*AB + t*AC	*/
		AO[Y]= s*( xy[B][Y] - xy[A][Y] ) + t*( xy[C][Y] - xy[A][Y] );
		
		
		r	= a*b*c/sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c));
		xp	= AO[X] + xy[A][X];
		yp	= AO[Y] + xy[A][Y];
		
		r+=0.	;
		xp+=0.	;
		yp+=0.	;
		
		r	+= syori2(r);
		xp	+= syori2(xp);
		yp	+= syori2(yp);
		
		printf("%.3lf %.3lf %.3lf\n",xp,yp,r);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define INF 0x3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n" 
#define pb push_back
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define print(v); for(auto x:v) cout<<x<<" "; cout<<endl;
typedef long long int ll;
int main()
{
    fast;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll flag = 0;
    while(a > 0 && c > 0){
        if(flag == 0){
            c = c - b;
            flag = 1;
        }
        else{
            a = a - d;
            flag = 0;
        }
    }

    if(a > 0 && c <= 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
using namespace std;
#define _inf 10000000

int min(int a, int b) {
    if(a > b) return b;
    else return a;
}

int getTheNumberOfCoin(vector<int> coins, int n, int m) {
    vector<int> dpTable(n+1, _inf);
    dpTable[0]  = 0;
    for(int i = 0; i < m; i++) {
        for(int j = coins[i]; j < n+1; j++) {
            dpTable[j] = min(dpTable[j], dpTable[j-coins[i]]+1);
        }
    }
    return dpTable[n];
}

int main() {
  int n , m;
  cin >> n >> m;
  vector<int> coin_list(m);
  for(int i = 0; i < m; i++) {
    cin >> coin_list[i];
  }
  int answer = getTheNumberOfCoin(coin_list, n, m);
  cout << answer << endl;
  return 0;
}

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

par=[i for i in range(N)]
size=[1 for i in range(N)]

def find(X):
    if par[X]==X:
        return X
    else:
        return find(par[X])

def union(X,Y):
    if size[X]>=size[Y]:
        par[Y]=par[X]
        size[X]+=size[Y]
    elif size[Y]>size[X]:
        par[X]=par[Y]
        size[Y]+=size[X]
    
L=[0 for i in range(M)]
for i in range(M):
    a,b=map(int,input().split())
    L[i]=[a-1,b-1]

L=L[::-1]

A=[]
for i in range(M):
    if find(L[i][0])==find(L[i][1]):
        A.append(0)
    else:
        A.append(size[find(L[i][0])]*size[find(L[i][1])])
        union(par[find(L[i][0])],par[find(L[i][1])])
        
A=A[::-1]
ans=0
for i in range(len(A)):
    ans+=A[i]
    print(ans)

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

using namespace std;
int main(int argc, char const* argv[]) {
    int n;
    cin >> n;
    vector<int> as(n);
    int i = 0;
    for (auto&& a : as) {
        cin >> a;
        while (!(a % 2)) {
            a = a / 2;
            i++;
        }
    }
    cout << i << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
int main()
{
    fastio();
    int n;
    cin >> n;
    int a[n];
    cn(a, n);
    ll amt = 1000;
    ll stocks = 0;
    int i = 0;
    for (int i = 0; i < n; i++)
    {
        while (a[i] >= a[i + 1] and (i + 1) < n)
        {
            i++;
        }
        stocks += amt / a[i];
        amt -= stocks * a[i];
        while (a[i] <= a[i + 1] and (i + 1) < n)
        {
            i++;
        }
        amt += stocks * a[i];
        stocks = 0;
    }
    cout << amt << "\n";
}

Measured memory_bytes: 3596
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 117：B - Polygon


def main():
    N = int(raw_input().strip())
    L = [int(i) for i in raw_input().strip().split(' ')]

    m = max(L)
    s = sum(L)
    if s - m > m:
        print 'Yes'
    else:
        print 'No'


if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

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

typedef long long ll;

int SURP = 1000000007;

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

	int ret[N+1] = {0};

	int s[1000] = {0};
	int n[1000] = {0};

	int tmp = 6;
	int sn = 0;
	while (tmp <= N){
		s[sn] = tmp;
		tmp *= 6;
		sn++;
	}

	tmp = 9;
	int nn = 0;
	while (tmp <= N){
		n[nn] = tmp;
		tmp *= 9;
		nn++;
	}

	ret[0] = 0;
	ret[1] = 1;

	REPI(i,2,N+1){
		ret[i] = ret[i-1]+1;
		REP(j,sn){
			if (i >= s[j]){
				if (ret[i] > ret[i - s[j]] + 1){
					ret[i] = ret[i - s[j]] + 1;
				}
			}else{
				break;
			}
		}

		REP(j,nn){
			if (i >= n[j]){
				if (ret[i] > ret[i - n[j]] + 1){
					ret[i] = ret[i - n[j]] + 1;
				}
			}else{
				break;
			}
		}
	}

	cout << ret[N] << endl;
	return 0;
}




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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  string S; cin >> S;
  ll result = 0, count = 0;
  rep(i,S.length()) {
    if (S[i]=='B') count++;
    else result += count;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  int x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a),q(b);
  rep(i,a) cin >> p[i];
  rep(i,b) cin >> q[i];
  sort(p);
  reverse(p);
  sort(q);
  reverse(q);
  priority_queue<int> pr;
  rep(i,x) pr.push(p[i]);
  rep(i,y) pr.push(q[i]);
  rep(i,c){
    int x;
    cin >> x;
    pr.push(x);
  }
  ll ans = 0;
  rep(i,x+y){
    ans += pr.top();
    pr.pop();
  }
  cout << ans << endl;
}



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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<vector<long long> > dp(n, vector<long long>(2, -1e18));
    vector<long long> a(n,0);
    for(int i=0; i<n; i++) {
        cin>>a[i];
    }
    dp[1][0] = a[0] + a[1];
    dp[1][1] = - a[0] - a[1];
    for(int i = 2; i < n; i++){
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + a[i];
        dp[i][1] = max(dp[i - 1][0] - 2 * a[i - 1] - a[i], dp[i - 1][1] + 2 * a[i - 1] - a[i]   );
    }
    cout<<max(dp[n-1][0], dp[n-1][1]);
    return 0;
}


Measured memory_bytes: 6528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String strText = input.readLine();
    StringBuffer sb = new StringBuffer();

    for (int index = 0; index < strText.length(); index++) {
      // 小文字の場合
      if(Character.isLowerCase(strText.charAt(index))) {
        sb.append(Character.toUpperCase(strText.charAt(index)));
      // 大文字の場合
      } else if (Character.isUpperCase(strText.charAt(index))) {
        sb.append(Character.toLowerCase(strText.charAt(index)));
      } else {
        sb.append(strText.charAt(index));
      }
    }
    System.out.println(sb.toString());
  }

}


Measured memory_bytes: 24240
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n; cin >> n;
    vector<vector<int>>F(n,vector<int>(10));
    rep(i,n)rep(j,10) cin >> F[i][j];
    vector<vector<int>>p(n,vector<int>(11));
    erep(a,p)erep(e,a) cin >> e;
    
    int ans = -INF;
    for (int bit = 1; bit < 1 << 10;bit++){
        int sub = 0;
        for(int i = 0; i < n; i++){
            int cost = 0;
            for(int j = 0; j< 10;j++)
                if(bit & (1 << j))
                    if (F[i][j])cost++;
            sub += p[i][cost];
        }
        cmax(ans, sub);
    }
    cout << ans << endl;
}



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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int N;
    cin >> N;
    vector<int> arrHon = {2, 4, 5, 7, 9};
    vector<int> arrPon = {0, 1, 6, 8};
    if (ALL (find, arrHon, N % 10) != end (arrHon)) {
        cout << "hon" << endl;
        return 0;
    }
    if (ALL (find, arrPon, N % 10) != end (arrPon)) {
        cout << "pon" << endl;
        return 0;
    }
    cout << "bon" << endl;
    return 0;
}


Measured memory_bytes: 3640