akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
  int n,k;
  while(cin >>n>>k,n||k){
    int log[100]={0},nlog[100]={0},c,ans=0;
    for(int i=0; i<n; i++){cin >>log[i];}
    int x = 1;
    for(int i=0; i<k; i++){x*=log[i];}
    c = x;
    for(int i=k; i<n; i++){
      x = x*log[i]/log[i-k];
      if(c<x){c = x;}
    }
    for(int i=0; i<n; i++){
      for(int j=i+1; j<n; j++){
	for(int r=0; r<n; r++){
	  if(r == i){nlog[r] = log[j];}
	  else if(r == j){nlog[r] = log[i];}
	  else{nlog[r] = log[r];}
	}
	int f = 1;
	for(int r=0; r<k; r++){f*=nlog[r];}
	if(ans<f){ans = f;}
	for(int r=k; r<n; r++){
	  f = f*nlog[r]/nlog[r-k];
	  if(ans<f){ans = f;}
	}
      }
    }
    if(c<=ans){cout <<ans-c<<endl;}
    else{cout <<"NO GAME"<<endl;}
  }
  return 0;
}

Measured memory_bytes: 864
/*input
4 972439611840
*/
#include <bits/stdc++.h>
using namespace std;
#define lol long long
#define MAX 1000010

vector<lol> v;
int a[MAX], cnt[80000];
lol n, p;
lol ans = 1;

void build() {
    memset(cnt, 0, sizeof(cnt));
    memset(a, 0, sizeof(a));
    for (int i = 2; i < MAX; i++) if (!a[i]) {
        v.push_back(i);
        
        int now = i + i;
        while (now < MAX) {
            a[now] = 1;
            now += i;
        }
    }
}

int main() {
    build();
    cin >> n >> p;
    if (n == 1) {
        cout << p << '\n';
        return 0;
    }
    for (int i = 0; i < v.size(); i++) {
        while (p % v[i] == 0) {
            p /= v[i];
            cnt[i]++;
        }
        if (cnt[i]) {
            ans = ans * pow(v[i], cnt[i] / n);
        }
    }
    if (n >= 2 && ans == 1) {
        long long k = sqrt(p);
        if (k * k == p) {
            cout << k << '\n';
            return 0;
        }
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
int n,a[111111],pos,ans,res;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	pos=1;
	for (int i=2;i<n;i++)
	{
		if (a[i]<0) pos=i;
		else break; 
	}
	for (int i=1;i<=n;i++)
	{
		if (i<=pos) ans-=a[i];
		else ans+=a[i];
	}
	printf("%d\n",ans);
	res=a[1];
	if (pos+1!=n)
	{
		printf("%d %d\n",a[1],a[pos+1]);
		res=a[1]-a[pos+1];
		for (int i=pos+1;i<n-1;i++) 
		{
			printf("%d %d\n",res,a[i+1]);
			res-=a[i+1];
		}
	}
	printf("%d %d\n",a[n],res);
	res=a[n]-res;
	for (int i=2;i<=pos;i++)
	{
		printf("%d %d\n",res,a[i]);
		res-=a[i];
	}
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <math.h>

using namespace std;
typedef pair<int, int> pii;
typedef pair<int, long double> pild;
typedef pair<long double, int> pldi;

void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;

//最小公倍数
//O(log max(a,b))
template<class T>
T GCD(T a, T b) {
	if (b == 0)return a;
	return GCD(b,(T)(a%b));
}

//最大公約数(複数)
//O(nlog max(a_i))?
template<class T>
T GCD(vector<T> v) {
	for (int n = 1; n < v.size(); n++) {
		v[n] = GCD(v[n],v[n-1]);
	}
	return v[v.size()-1];
}

//最小公倍数
template<class T>
T LCM(T a, T b) {
	return a * b / GCD(a, b);
}

//最小公倍数(複数)
template<class T>
T LCM(vector<T> v) {
	for (int n = 1; n < v.size(); n++) {
		v[n] = LCM(v[n],v[n-1]);
	}
	return v[v.size()-1];
}

vector<cpp_int> arr;

void solve() {
	int N;
	cin >> N;
	arr.resize(N);
	for (int i = 0; i < N; i++)cin >> arr[i];
	cout << LCM(arr) << endl;
	return;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  set<int> st;
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    if (a == 0) {
      st.insert(b);
      cout << st.size() << endl;
    } else {
      cout << (st.find(b) == st.end() ? 0 : 1) << endl;
    }
  }
  return 0;
}


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

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 58;

int main()
{
  int64 N, A[300000];

  cin >> N;
  for(int i = 0; i < 3 * N; i++) cin >> A[i];

  set< pair< int64, int > > latte, malta, beet;

  int64 sum1 = 0, sum2 = 0;
  for(int i = 0; i < N; i++) {
    latte.emplace(A[i], i);
    sum1 += A[i];
  }
  for(int i = N; i < 3 * N; i++) {
    malta.emplace(A[i], i);
    sum2 += A[i];
  }

  while(malta.size() > N) {
    sum2 -= (--malta.end())->first;
    beet.emplace(*--malta.end());
    malta.erase(--malta.end());
  }

  int64 ret = -INF;
  for(int i = N; i < 2 * N; i++) {
    ret = max(ret, sum1 - sum2);

    latte.emplace(A[i], i);
    sum1 += A[i];
    if(malta.count({A[i], i})) {
      malta.erase({A[i], i});
      sum2 -= A[i];
    } else {
      beet.erase({A[i], i});
    }
    while(latte.size() > N) {
      sum1 -= latte.begin()->first;
      latte.erase(latte.begin());
    }
    while(malta.size() < N) {
      sum2 += beet.begin()->first;
      malta.emplace(*beet.begin());
      beet.erase(beet.begin());
    }
  }

  cout << max(ret, sum1 - sum2) << endl;
}

Measured memory_bytes: 21376
#include <iostream>
using namespace std;
int n;
int main(){
	while(cin>>n&&n){
		int p;
		int pmax=-10000000,pmin=1000000;
		int sum=0;
		for(int i=0;i<n;i++){
			cin>>p;
			pmax=max(p,pmax);
			pmin=min(p,pmin);
			sum+=p;
		}
		cout<<(sum-(pmax+pmin))/(n-2)<<endl;
	}
	return 0;
}

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

int main()
{
    int n,a,b=0,c=0;
    string s;

    cin>>n;
    cin>>s;

    a=(n/2);
    if(n%2==0)
    {
         for(int i=0;i<a;i++)
    {

        if(s[i]==s[i+a])
        {
           b++;

        }
          else
          {
         c++;
          }

    }


    if(c==0)
        cout<<"Yes"<<endl;
    else
         cout<<"No"<<endl;

    }
     else
         cout<<"No"<<endl;







}


Measured memory_bytes: 256
N = int(input())
S = input()

r = 0
g = 0
b = 0
for s in S:
    if s == "R":
        r += 1
    elif s == "G":
        g += 1
    else:
        b += 1

cnt = r * g * b
for i in range(N):
    for j in range(i, N):
        k = 2 * j - i
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            cnt -= 1
        
print(cnt)

Measured memory_bytes: 68296
#include<bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ll long long

long long const N = 2e5 + 1, M = 1e9 + 7;
long long fn[N], fd[N], iv[N];

void initnck(){
    iv[1] = fn[1] = fd[1] = fn[0] = fd[0] = 1;
    for (long long i=2; i<N; i++){
        iv[i] = (M - (M/i) * iv[M%i] % M) % M;
        fn[i] = fn[i-1]*i%M;
        fd[i] = fd[i-1]*iv[i]%M;
    }
}

long long nck(long long n, long long k){
    return fn[n] * fd[n-k] % M * fd[k] % M;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    initnck();
 
    ll n,k; cin >> n >> k;
    k = min(n-1, k);
 
    ll ans = 0;
    for (ll x=0; x <= k; x++){
        ans = (ans + nck(n, x) * nck(n-1, x)%M)%M;
    }
    cout << ans << endl;
}

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

ll n,ben[102][11],ans=-1*(1LL<<62);
bool op[102][11],my[11];

void cal(){
	for(int i=0;i<10;i++){
		if(my[i]==1){
			break;
		}
		if(i==9){
			return;
		}
	}
	ll sum=0;
	for(int i=0;i<n;i++){
		ll cnt=0;
		for(int j=0;j<10;j++){
			if(op[i][j]==1&&my[j]==1){
				cnt++;
			}
		}
		sum+=ben[i][cnt];
	}
	ans=max(ans,sum);
}

void dep(ll d){
	if(d==10){
		cal();
		return;
	}
	my[d]=0;dep(d+1);
	my[d]=1;dep(d+1);
}

int main() {
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>op[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<11;j++){
			cin>>ben[i][j];
		}
	}
	dep(0);
	cout <<ans;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr size_t HW_MAX = 510;
char A[HW_MAX][HW_MAX], B[HW_MAX][HW_MAX], C[HW_MAX][HW_MAX];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, W;
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        cin >> (A[i] + 1);
        B[i][1] = '#', B[i][W] = '.';
        C[i][1] = '.', C[i][W] = '#';
        for (int j = 2; j < W; j++) {
            if (A[i][j] == '#') {
                B[i][j] = C[i][j] = '#';
            } else if (i & 1) {
                B[i][j] = '#', C[i][j] = '.';
            } else {
                B[i][j] = '.', C[i][j] = '#';
            }
        }
    }
    for (int i = 1; i <= H; i++) cout << B[i] + 1 << '\n';
    cout << '\n';
    for (int i = 1; i <= H; i++) cout << C[i] + 1 << '\n';
    return 0;
}


Measured memory_bytes: 1536
def d_no_need(N, K, A):
    card = sorted(A, reverse=True)
    s = 0
    ans = 0
    for a in card:
        if s + a < K:
            s += a
            ans += 1
        else:
            ans = 0
    return ans

N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(d_no_need(N, K, A))


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

using namespace std;

int main() {
    int t, n, height, height_before;
    cin >> t;
    for (int i=0; i<t; i++) {
        int up_max = 0;
        int down_max = 0;
        cin >> n;
        cin >> height_before;
        for (int j=1; j<n; j++) {
            cin >> height;
            up_max = max(up_max, height-height_before);
            down_max = max(down_max, -height+height_before);
            height_before = height;
        }
        cout << up_max << ' ' << down_max << endl;
    }
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int x = 0;
  for (int i = 0; i < 4; i++){
    if (S.at(i) == '+'){
      x++;
      
    }
    else {
      x--;
    }
    //cout << "[" << x << "]" << endl;
  }
  cout << x << endl;
  
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc063/tasks/abc063_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int a, b;
  string r;

  cin >> a >> b;

  if (9 < a + b)
    cout << "error" << '\n';
  else
    cout << a + b << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int a,b,d,r;
  double f;
  scanf("%d%d",&a,&b);
  d=a/b;
  r=a%b;
  f=(double)a/b;
  printf("%d %d %6.5f\n",d,r,f);
  return 0;
}

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

/*Atcoder用
 * 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int a = Integer.parseInt(tmp[0]);
		int b = Integer.parseInt(tmp[1]);
		int c = Integer.parseInt(tmp[2]);


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String get = br.readLine();
		char[] s = get.toCharArray();
		for(char c:s)System.out.println(c);

		List<Integer> ls = new ArrayList<Integer>();
		String[] tmp = br.readLine().split(" ");
		for (int n = 0; n < N; n++) {
			ls.add(Integer.parseInt(tmp[n]));
		}
 */

public class Main {

	public static void main(String[] args) throws IOException {
 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 		String[] tmp = br.readLine().split(" ");
		int D = Integer.parseInt(tmp[0]);
		int N = Integer.parseInt(tmp[1]);
		int k;
		switch(D){
		case 0:
			k = 1;
			break;
		case 1:
			k = 100;
			break;
		case 2:
			k = 10000;
			break;
		default:
			k = 1;
		}
		if(N == 100){
			System.out.println((k*N) + k);
		}else{
			System.out.println(k * N);
		}
	}

}


Measured memory_bytes: 22484
#include<stdio.h>
#include<stdlib.h>
 
int main(){
  int Q, l[100000], r[100000], i, j, P[100001], R[100001], S[100001];
  scanf("%d", &Q);

  for(i=0; i<Q; i++){
    scanf(" %d%d", &l[i], &r[i]);
  }

  P[0]=0; P[1]=0;
  for(i=2; i<=100000; i++)P[i]=1;

  for(i=2; i<=100000; i++){
    if(P[i]==1){
      for(j=2*i;j<=100000;j+=i)P[j]=0;
    }    
  }

  R[0]=0; R[1]=0;
  for(i=2; i<=100000; i++){
    if(P[i] & P[(i+1)/2])
      R[i]=1;
    else
      R[i]=0;
  }

  S[0]=0; S[1]=0;
  for(i=2; i<=100000; i++){
    S[i]=S[i-1]+R[i];
  }
  
  for(i=0; i<Q; i++){
    printf("%d\n",S[r[i]]-S[l[i]-1]);
  }

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF      5000000000000000000
#define EPS      1e-10
#define MOD      1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

ll n, e, t;
ll x[100001];
ll dp[100001];
ll pos = 0;
priority_queue<P,vector<P>,greater<P> > que1, que2;

int main(){
    cin >> n >> e >> t;
    rep(i,n) cin >> x[i+1];
    rep(i,n+1) dp[i] = INF;
    dp[0] = 0;
    for(int i = 1; i <= n; i++){
        que1.push(P(dp[i-1]-x[i-1],i-1));
        while((x[i]-x[pos+1])*2 > t){
            que2.push(P(dp[pos]-x[pos]-2*x[pos+1],pos+1));
            pos++;
        }
        while(true){
            if(que1.size() == 0) break;
            P p = que1.top();
            if(p.second < pos) que1.pop();
            else break;
        }
        if(que1.size() > 0){
            P p = que1.top();
            dp[i] = min(dp[i],x[i]+t+p.first);
        }
        if(que2.size() > 0){
            P p = que2.top();
            dp[i] = min(dp[i],3*x[i]+p.first);
        }
    }
    cout << dp[n]+e-x[n] << endl;
}


Measured memory_bytes: 4468
a,b,c,k = map(int,input().split())

if k<=a:
	amount=k

elif k<=a+b:
	if b>0:
		amount=a
	else:
		amount=a+(-1)*(k-a)
else:
	amount=a+(-1)*(k-a-b)
    
print(amount)

Measured memory_bytes: 9184
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
int n,m,q,ans=0;
vector<int> a,b,c,d;
void dfs(vector<int> A){
    if(A.size()==n+1){
        int now=0;
        rep(i,q){
            if(A[b[i]]-A[a[i]]==c[i])now+=d[i];
        }
        ans=max(ans,now);
        return;
    }
    A.push_back(A.back());
    while(A.back()<=m){
        dfs(A);
        A.back()++;

    }
    return;
}

 
int main() {
cin>>n>>m>>q;
a=b=c=d=vector<int>(q);
rep(i,q){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
}
dfs(vector<int>(1,1));
cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
int n;
ll a[300001];
int main(){
    cin>>n;
    rep(i,n) cin>>a[i];
    ll c1,c2;
    ll ans=0;
    rep(i,60){
        c1=0,c2=0;
        rep(j,n){
            if(a[j]>>i&1) ++c1;
            else ++c2;
        }
        ans+=(ll)(1ll<<i)%mod*c1%mod*c2%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

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

bool solve() {
	string s;
	cin >> s;
	string rs = s;
	reverse(rs.begin(), rs.end());
	if (s != rs) return false;
	int n = s.length();
	string s1 = s.substr(0, (n-1)/2);
	string rs1 = s1;
	reverse(rs1.begin(), rs1.end());
	if (s1 != rs1) return false;
	string s2 = s.substr((n+3)/2-1);
	string rs2 = s2;
	reverse(rs2.begin(), rs2.end());
	if (s2 != rs2) return false;
	return true;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cout << (solve() ? "Yes" : "No") << endl;
}

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

int main() {
    string s; cin >> s;
    rep(i, s.size()) {
        if (s.at(i) == ',')
            s.at(i) = ' ';
    }

    cout << s << endl;
}

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>;

bool isPalindrome(string s){
    string t = s;
    reverse(t.begin(), t.end());
    return s == t;
}

int main() {
    string s;
    cin >> s;
    bool ans = true;
    if (!isPalindrome(s)) ans = false;
    if (!isPalindrome(s.substr(0, s.size()/2))) ans = false;
    cout << (ans ? "Yes":"No") << endl;
    return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

struct SegmentTree{
  int N;
  vector <int> Tree[20];
  void Make(){
    for (int i = 0; i <= N; i++){
      Tree[i].resize((1<<i));
    }
  }

  void Solve(){
    for (int i = N - 1; i >= 0; i--){
      for (int j = 0; j < (1<<i); j++){
        if (Tree[i+1][2*j] == Tree[i+1][2*j+1]){
          Tree[i][j] = Tree[i+1][2*j];
        }else{
          Tree[i][j] = abs(Tree[i+1][2*j] - Tree[i+1][2*j+1]);
        }
      }
    }
  }
};

int main(){
  int N; cin >> N;
  SegmentTree T; T.N = N;
  T.Make();
  for (int i = 0; i < (1<<N); i++){
    cin >> T.Tree[N][i];
  }
  T.Solve();
  cout << T.Tree[0][0] << endl;

  return 0;
}


Measured memory_bytes: 5368
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[6],k;
    for(int i=0;i<5;i++)
        cin>>a[i];
        int sum=0,mins=1e9;
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
         for(int k=0;k<5;k++){
          for(int s=0;s<5;s++){
        for(int w=0;w<5;w++){
           if(i==j||i==k||i==s||i==w||j==k||s==j||w==j||k==s||k==w||s==w)
            continue;
              sum=a[i];
             sum+=(sum%10==0?0:10-sum%10);
             sum+=a[j];
             sum+=(sum%10==0?0:10-sum%10);
             sum+=a[k];
             sum+=(sum%10==0?0:10-sum%10);
             sum+=a[s];
             sum+=(sum%10==0?0:10-sum%10);
             sum+=a[w];
          
             mins=min(sum,mins);

        }}}}}
        cout<<mins<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,i; cin >> n >> m;
  if(n>=m){cout<<"0"<<endl;}
  else{
  vector<int> num(m);
  for(i=0;i<m;i++){cin>>num[i];}
  sort(num.begin(),num.end());
  vector<int> length(m-1);
  for(i=0;i<m-1;i++){length[i]=num[i+1]-num[i];}
  sort(length.begin(),length.end());
  int ans=0;
  for(i=0;i<m-n;i++){ans+=length[i];}
  cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		// for(int i=0;i<n;i++){
		// 	ar[i]=sc.nextInt();
		// }
		long ans = 0;
		HashMap<Integer,Integer> map = new HashMap<>();
		for(int i=0;i<n;i++){
			//arr[i]=sc.nextInt();
			arr[i] = sc.nextInt();
			// if(map.get(i-h)!=null){
			// 	ans+=map.get(i-h);
			// }
			if(map.get(i+arr[i])==null){
				map.put(i+arr[i],1);
			}
            else{
				map.put(i+arr[i], map.get(i+arr[i])+1);
            }
		}
		for(int i=0;i<n;i++){
			//if(map.get(i-arr[i])!=null){
				ans=ans+map.getOrDefault(i-arr[i],0);
			//}
		}
		System.out.println(ans);

	}

		
		
		// int[] arr1 = new int[n+max+1];
		// // //int ans =0;
		// for(int i=0;i<n;i++){
		//  	if(i-arr[i]>=0){
		//  	arr1[i-arr[i]]++;
		//  	}
		// // 	arr1[i+arr[i]]++;
		// }
 
		// for(int i=0;i<n;i++){
		//  	//if(i-arr[i]>=0){
		//  	ans+=arr1[i+arr[i]];
		//  	//}
		// // 	arr1[i+arr[i]]++;
		// }
		
		// // System.out.println(ans);
}


Measured memory_bytes: 69520
#include<bits/stdc++.h>
using namespace std;
int main(){
long long A,B,K;
cin>>A>>B>>K;
if(A>K)
    A=A-K;
else{
            K=K-A;
A=0;
    if(B>K)
        B=B-K;
    else
        B=0;
}
cout<<A<<" "<<B<<"\n";
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	digitSum := 0
	num := n
	for {
		digitSum += num % 10
		num = num / 10

		if num == 0 {
			break
		}
	}

	if n%digitSum == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using namespace std;

int main() {
  int64_t N;
  long double D;
  cin >> N >> D;

  int64_t res = 0;
  for (int64_t n = 0; n < N; ++n) {
    long double X, Y;
    cin >> X >> Y;
    if (sqrt(X * X + Y * Y) <= D) {
      ++res;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

bool p(string s){
   string t = s;
   reverse(all(t));
   return s == t;
}

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   string s;
   cin >> s;
   int n = s.length();
   if(p(s) and p(s.substr(0,(n-1)/2)) and p(s.substr((n+3)/2-1))){
      cout << "Yes\n";
   }else{
      cout << "No\n";
   }
   return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
LL z = 1;
int read(){
	int x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
int ksm(int a, int b, int p){
	int s = 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
string s[105], ans[105], t;
int cnt, tot;
int ok(string s){
	for(int i = 0; i < s.size(); i++) if(s[i] == '#') return 1;
	return 0;
}
int main(){
	int i, j, n, m;
	n = read(); m = read();
	for(i = 0; i < n; i++){
		cin >> t;
		if(ok(t)) s[cnt++] = t;
	}
	for(i = 0; i < m; i++){
		t = "";
		for(j = 0; j < cnt; j++) t += s[j][i];
		if(ok(t)) ans[tot++] = t;
	}
	for(i = 0; i < cnt; i++){
		for(j = 0; j < tot; j++) cout << ans[j][i];
		printf("\n");
	}
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	int ret=0;
	while(N) {
		ret+=(N%10==2);
		N/=10;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  vi x(5);
  rep(i,5) cin >> x.at(i);
  rep(i,5){
    if(x.at(i) == 0){
      cout << i+1 << endl;
    }
  }
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> vec(h);
  for (int i = 0; i < h; i++) {
    cin >> vec.at(i);
  }

  for (int j = 0; j < h; j++) {
    for (int y = 0; y < w; y++) {
      if (vec.at(j).at(y) == '#') {
        cout << '#';
        continue;
      } else {
        int count = 0;
        for (int k = -1; k < 2; k++) {
          for (int l = -1; l < 2; l++) {
            if (j + k <= -1 || y + l <= -1 || j + k >= h || y + l >= w) {
              continue;
            } else {
              if (vec.at(j + k).at(y + l) == '#') {
                count++;
              }
            }
          }
        }
        cout << count;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
graph = [list(map(int, input().split())) for _ in range(M)]
ans = 0
for i in range(M):
    uf = UnionFind(N)
    for k in range(M):
        if i == k:
            continue
        uf.union(graph[k][0]-1,graph[k][1]-1)
    if uf.group_count() != 1:
        ans += 1
print(ans)

Measured memory_bytes: 40944
#include <stdio.h>
#define MN 2005
int n,m,q,pnt[MN][MN],row[MN][MN],col[MN][MN];
bool b[MN][MN];
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%1d",&b[i][j]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			pnt[i][j]=pnt[i-1][j]+pnt[i][j-1]-pnt[i-1][j-1]; if(b[i][j])pnt[i][j]++;
//			printf("%d ",pnt[i][j]);
		}
//		printf("\n");
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<=m;j++){
			row[i][j]=row[i-1][j]+row[i][j-1]-row[i-1][j-1]; if(b[i][j]&&b[i+1][j])row[i][j]++;
//			printf("%d ",row[i][j]);
		}
//		printf("\n");
	}
//	printf("\n");
	for(int i=1;i<=n;i++){
		for(int j=1;j<m;j++){
			col[i][j]=col[i-1][j]+col[i][j-1]-col[i-1][j-1]; if(b[i][j]&&b[i][j+1])col[i][j]++;
//			printf("%d ",col[i][j]);
		}
//		printf("\n");
	}
//	printf("\n");
	for(int i=1;i<=q;i++){
		int xa,xb,ya,yb;
		scanf("%d%d%d%d",&xa,&ya,&xb,&yb);
//		printf("%d ",(pnt[xb][yb]-pnt[xa-1][yb]-pnt[xb][ya-1]+pnt[xa-1][ya-1]));
//		printf("%d ",(row[xb-1][yb]-row[xa-1][yb]-row[xb-1][ya-1]+row[xa-1][ya-1]));
//		printf("%d ",(col[xb][yb-1]-col[xa-1][yb-1]-col[xb][ya-1]+col[xa-1][ya-1]));
		printf("%d\n",
			 (pnt[xb][yb]-pnt[xa-1][yb]-pnt[xb][ya-1]+pnt[xa-1][ya-1])
			-(row[xb-1][yb]-row[xa-1][yb]-row[xb-1][ya-1]+row[xa-1][ya-1])
			-(col[xb][yb-1]-col[xa-1][yb-1]-col[xb][ya-1]+col[xa-1][ya-1])
		);
	}
}

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

using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    int mn = ceil(A / 0.08);
    int mx = ceil((A + 1) / 0.08);
    for (int i = mn; i < mx; i++) {
        if ((int) (i * 0.1) == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)

using namespace std;

const int N=1e5+100;
int n,m,a[N];

int main(){
	scanf("%d%d",&n,&m);
	rep (i,1,n) scanf("%d",&a[i]);
	int p=0;
	rep (i,2,n) if (a[i-1]+a[i]>=m){p=i-1; break;}
	if (!p) return puts("Impossible"),0;
	puts("Possible");
	rep (i,1,p-1) printf("%d\n",i);
	for (int i=n-1;i>p;i--) printf("%d\n",i);
	printf("%d\n",p);
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int maxn=205;
const int inf=0x3f3f3f3f;
int h,w,k;
string s[maxn];
int a[maxn][maxn]; 
int row[maxn],col[maxn],sum,ans;
int b1[maxn],b2[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>h>>w>>k;
	for(int i=1;i<=h;i++)
	{
		cin>>s[i];
		for(int j=0;j<=s[i].size()-1;j++)
		{
			if(s[i][j]=='.')
				a[i][j+1]=0;
			else if(s[i][j]=='#')
			{
				a[i][j+1]=1;
				sum++;
			}
		}
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
			row[i]+=a[i][j];
	}
	for(int i=1;i<=w;i++)
	{
		for(int j=1;j<=h;j++)
			col[i]+=a[j][i];
	}
	
	while(b1[0]==0)
	{
//		cout<<"b1:"<<endl;
//		for(int i=1;i<=h;i++)
//			cout<<b1[i]<<" ";
//		cout<<endl;
		while(b2[0]==0)
		{
			int x=sum;
//			cout<<"b2:"<<endl;
//			for(int i=1;i<=w;i++)
//				cout<<b2[i]<<" ";
//			cout<<endl;
			for(int i=1;i<=h;i++)
			{
				if(b1[i]==1)
				{
					x-=row[i];
					for(int j=1;j<=w;j++)
					{
						if(b2[j]==1)
							x+=a[i][j];
					}
				}
			}
			for(int i=1;i<=w;i++)
			{
				if(b2[i]==1)
					x-=col[i];
			}
			if(x==k)
			{
				ans++;
//				cout<<"111111111111";
			}
			b2[w]++;
			for(int i=w;i>=1;i--)
			{
				if(b2[i]==2)
				{
					b2[i]=0;
					b2[i-1]+=1;
				}
			}
		}
		memset(b2,0,sizeof(b2));
		b1[h]++;
		for(int i=h;i>=1;i--)
		{
			if(b1[i]==2)
			{
				b1[i]=0;
				b1[i-1]+=1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}




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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int h, w, n, a, ans = 0;
  cin >> h >> w >> n;
  queue<int> q;
  rep(i, n) {
    cin >> a;
    rep(j, a) q.push(i + 1);
  }

  int c[h][w];
  int cnt = 0, t;
  rep(i, h) {
    if (cnt % 2 == 0) {
      rep(j, w) {
        c[i][j] = q.front();
        q.pop();
      }
    } else {
      for (int j = w - 1; j >= 0; --j) {
        c[i][j] = q.front();
        q.pop();
      }
    }
      cnt++;
  }

  rep(i, h) {
    rep(j, w) cout << c[i][j] << " ";
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 384
a, b, c = input().split()
x = int(a)
y = int(b)
z = int(c)
if z >= x:
    z -= x
    x = 0

else:
    x -= z
    z = 0

if z >= y:
    z -= y
    y = 0

else:
    y -= z
    z = 0

print(str(x),str(y))


Measured memory_bytes: 9108
n = int(input())
a = list(map(int, input().split()))

first_flg = 0
ans_num=0
def ans(calc_list):
    b = []
    for i in calc_list:
        if i%2 != 0:
            return 'stop'
        else:
            b.append(int(i/2))
    return b

while True:
    if 0 == first_flg:
        first_flg = 1
        output = ans(a)
    else:
        output = ans(output)

    if output == 'stop':
        break
    else:
        ans_num+=1
        
print(ans_num)

Measured memory_bytes: 8896
raw = raw_input()
a = int(raw)
raw = raw_input()                                  
b = int(raw)
raw = raw_input()                                  
c = int(raw)
raw = raw_input()                                  
d = int(raw)
raw = raw_input()                                  
e = int(raw)
raw = raw_input()                                  
k = int(raw)
                                                                                                       
if e - a > k:
    print ':('
else:                                                                                                  
    print 'Yay!'

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
  ll n = 0, a = 0, b = 0;
  cin >> n;
  for (ll i = 0; a <= n; i++) {
    a = pow(i, 5);
    b = 0;
    for (ll j = 0; a + b <= n; j++) {
      b = pow(j, 5);
      if (a + b == n) {
        cout << j << " " << -i;
        return 0;
      }
    }
  }
  a = 0;
  for (ll i = 0;; i++) {
    a = pow(i, 5);
    b = 0;
    for (ll j = i; b - a <= n; j++) {
      b = pow(j, 5);
      if (b - a == n) {
        cout << j << " " << i;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 4028
/*input
0 2 3 4 5
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long 
#define ld long double
#define pii pair<int,int>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=(res*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+2;
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    REP1(i,5){
        int a;
        cin>>a;
        if(!a){
            cout<<i;
            return 0;
        }
    }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  int a;
  cin >> a;
  int c_a = a/100;
  int c_b = a%10;
  cout << ((c_a==c_b)?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;
using pr  = pair<ll, ll>;

const ll MOD = 998244353;

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

	map<ll, ll> mp;

	for (ll i = 0;; ++i)
	{
		ll i5 = i*i*i*i*i;

		mp[i5] = i;

		if (mp.count(X - i5))
		{
			cout << mp[X - i5] << " " << -i << endl;
			return 0;
		}

		if (mp.count(i5 - X))
		{
			cout << i << " " << mp[i5 - X] << endl;
			return 0;
		}

		if (mp.count(i5 + X))
		{
			cout << mp[i5 + X] << " " << i << endl;
			return 0;
		}
	}




	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
using namespace std;
int main()
{
    // 整数の入力
    string a;
    cin >> a;

  
  	// 出力
  	string ret;
  	if(a[0] == a[2]) ret = "Yes";
  	else ret = "No";
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, c = 0, z = 0, a[5003] = {}, b[10004] = {1};
    bitset<5000> d[10004];
    clock_t cl = clock();
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        c = min(k + k, c + a[i]);
        for (int j = c; j >= a[i]; j--) {
            if (b[j - a[i]]) {
                b[j] = 1;
                d[j] |= d[j - a[i]];
                d[j][i] = 1;
            }
        }
        if (clock() - cl > 1900000) {
            cout << 0;
            return 0;
        }
    }
    for (int i = 0; i < n; i++) if (a[i] < k) {
        bool y = 1;
        for (int j = k; j < k + a[i]; j++) if (d[j][i]) y = 0;
        z += y;
    }
    cout << z;
}


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

using namespace std;

typedef long long llint;

const int MAXN = 100005;
const int MAXM = 200005;

int n, m, cnt;
int ea[MAXM], eb[MAXM], ec[MAXM];
vector <int> v[MAXN], ind[MAXN];
vector < pair <int, int> > g[MAXN * 5];
deque < pair <int, int> > dq;
int bio[MAXN * 5], dist[MAXN * 5];

void gen () {
    cnt = n;
    for (int i = 1; i <= n; i++) {
        sort(v[i].begin(), v[i].end());
        v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
        for (auto x : v[i]) {
            ind[i].push_back(++cnt);
            g[i].push_back({cnt, 1});
            g[cnt].push_back({i, 1});
        }
    }
    for (int i = 0; i < m; i++) {
        int pa = lower_bound(v[ea[i]].begin(), v[ea[i]].end(), ec[i]) - v[ea[i]].begin();
        int pb = lower_bound(v[eb[i]].begin(), v[eb[i]].end(), ec[i]) - v[eb[i]].begin();
        pa = ind[ea[i]][pa];
        pb = ind[eb[i]][pb];
        g[pa].push_back({pb, 0});
        g[pb].push_back({pa, 0});
    }
}

void bfs () {
    dq.push_back({1, 0});
    while (!dq.empty()) {
        int x = dq.front().first;
        int d = dq.front().second;
        dq.pop_front();
        if (bio[x]) continue;
        bio[x] = 1;
        dist[x] = d;
        for (auto par : g[x]) {
            int sus = par.first, cost = par.second;
            if (cost == 0) {
                dq.push_front({sus, d});
            } else {
                dq.push_back({sus, d + 1});
            }
        }
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> ea[i] >> eb[i] >> ec[i];
        v[ea[i]].push_back(ec[i]);
        v[eb[i]].push_back(ec[i]);
    }
    gen();
    bfs();
    if (dist[n] == 0) cout << -1; else cout << dist[n] / 2;
    return 0;
}


Measured memory_bytes: 50420
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var ans = 'NO';
	if(n===3 || n === 5 || n === 7) ans = 'YES';

	console.log(ans);
}

Measured memory_bytes: 22076
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define dbg(n) cout<<#n<<' '<<n<<endl;
int main(){ 
	int n;
	cin>>n;
	ll a[n];
	ll ans=1,c=0;
	ll mx=-1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mx=max(mx,a[i]);
		if(a[i]==0)
			c=1;
	}
	if(c)
		cout<<0<<endl;
	else{
	int f=0;
	for(int i=0;i<n;i++){
		ans*=a[i];
		if(ans>(ll)1e18)
			{
				f=1;
				break;	
			}
	}
	if(f||ans<mx)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
	}
	
}



Measured memory_bytes: 4416
#別解
def main():
    S = input()
    Ans = [0]*len(S)
    # 左隣までに Rがr個, Lがl個連続して並んでいる.
    r, l = 1, 0
    
    # 左からS+'R'をcheckしていく.
    # RRRRRは全て0.
    # RLが出てきたら 続くLLLLLの部分は全て0で
    # 次にRが出れば初めのRLを決定できる.
    for i, s in enumerate(S[1:]+'R', 1):            
        if s == 'R':
            # Rの左隣がLのとき
            if l :
                Ans[i - l] = r//2 + (l+1)//2
                Ans[i - l - 1] = (r+1)//2 + l//2
                r, l = 1, 0
                
            # Rの左隣がRのとき
            else: 
                r += 1
                
        else:
            l += 1
    print(*Ans)
main()

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  set <ll> s;
  s.insert(n);
  ll res = 1;
  while (true) {
    res++;
    if (n%2 == 0) {
      if (s.count(n/2)) {
        cout << res << endl;
        break;
      } else {
        s.insert(n/2);
        n /= 2;
      }
    } else {
      if (s.count(3*n+1)) {
        cout << res << endl;
        break;
      } else {
        s.insert(3*n+1);
        n = 3*n+1;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  vector<char> vec(0);
  int64_t pos = 0;
  while(pos < S.size()){
    if(S.at(pos) == 'A'){
      vec.push_back('A');
      pos++;
    }
    else if(S.at(pos) == 'C'){
      vec.push_back('C');
      pos++;
    }
    else{
      if(pos+1< S.size()){
        if(S.at(pos) == 'B' && S.at(pos+1) == 'C'){
          vec.push_back('X');
          pos += 2;
        }
        else{
          vec.push_back('B');
          pos++;
        }
      }
      else{
        vec.push_back('B');
        pos++;
      }
    }
  }
  
  int64_t ans = 0;
  pos = 0;
  int64_t cnt_a = 0;
  while(pos < vec.size()){
    if(cnt_a == 0 && vec.at(pos) != 'A'){
      pos++;
    }
    else if(vec.at(pos) == 'A'){
      cnt_a++;
      pos++;
    }
    else if(vec.at(pos) == 'X'){
      ans += cnt_a;
      pos++;
    }
    else if(cnt_a != 0 && (vec.at(pos) == 'B' || vec.at(pos) == 'C')){
      cnt_a = 0;
    }
  }
  cout << ans << endl;
}    

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

#define ll long long
#define ld long double
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define For(i, a, b) for(long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for(long long int i = (a); i >= (b); i--)
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
const int MOD=1e9+7;
const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1};
const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	if(s.back()=='s')
	s+="es";
	else s+='s';
	cout<<s;
	return 0;
}


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

const int MAX_N = 1e5 + 10;
const int MAX_Q = 1e5 + 10;

int ac_cnt[MAX_N], ans[MAX_Q];

int main() {
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    for (int i = 1; i < S.length(); i++) {
        if (S[i - 1] == 'A' && S[i] == 'C') {
            ac_cnt[i + 1]++;
        }
        ac_cnt[i + 1] += ac_cnt[i];
    }
    int L, R;
    for (int i = 0; i < Q; i++) {
        cin >> L >> R;
        ans[i] = ac_cnt[R] - ac_cnt[L - 1];
        if (L - 2 >= 0 && ans[i] > 0 && S[L - 2] == 'A' && S[L - 1] == 'C') ans[i]--;
    }
    for (int i = 0; i < Q; i++) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();

		if (s.charAt(s.length() - 1) == 's') {
			System.out.println(s + "es");
		} else {
			System.out.println(s + "s");
		}
	}
}


Measured memory_bytes: 38548
// 0556.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//


#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	roop(i, m) {
		ll a, b;
		cin >> a >> b;
		a = min(a, n + 1 - a);
		b = min(b, n + 1 - b);
		if (b <= a) 
		{
			if (b % 3 == 0) { cout << 3; } 
			else { cout << b % 3; } 
		}
		else {
			if (a % 3 == 0) { cout << 3; }
			else { cout << a % 3; }
		}
		cout << endl;
	}
	return 0;
}


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

int main()
{
    int N;
    map<int, int> A;

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        if (A[a] == 0)
        {
            A[a] = 1;
        }
        else
        {
            A[a] = 0;
        }
    }

    int ans = 0;
    for (auto x : A)
    {
        ans += x.second;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>

using namespace std;

int main() {
    int p[5];
    int total = 0;

    for (int i = 0; i < 5; i++) {
        cin >> p[i];
        total += p[i];
        if(p[i]%10 != 0) total += 10 - (p[i]%10);
    }

    int min = 10000;
    int time = 0;

    for(int i = 0; i < 5; i++) {
        time = 0;
        time = total;
        if(p[i]%10 != 0) {
            //cout << "test:" << total << ", " << i << "," << 10 - (p[i]%10)<< endl;
            time -= 10 - (p[i]%10);
            //cout << "ret:" << time << endl;
        }
        if(time < min) min = time;
    }

    cout << min << endl;
}

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

int main(){
  int N;
  cin>>N;
  int d[100];
  for(int i=0;i<N;i++){
    cin>>d[i];
  }
  sort(d,d+N,greater<int>());
  int cnt=1;
  for(int i=1;i<N;i++){
    if(d[i-1]>d[i]) cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256