akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<int> t(N), v(N);
  for(int i = 0; i < N; i++) cin >> t[i];
  for(int i = 0; i < N; i++) cin >> v[i];

  int T = 0;
  for(int i = 0; i < N; i++){
    T += t[i];
  }

  vector<double> maxV(2 * T + 1, (double)(1e9));

  int nowT = 0;
  for(int i = 0; i < N; i++){
    for(int ti=0; ti < t[i]; ti++){
      int t1 = nowT + ti * 2;
      int t2 = nowT + ti * 2 + 1;
      maxV[t1] = min(maxV[t1], double(v[i]));
      maxV[t2] = min(maxV[t2], double(v[i]));
    }
    nowT += t[i] * 2;
    maxV[nowT] = min(maxV[nowT], double(v[i]));
  }

  maxV[0] = maxV[T*2] = 0.0;
  for(int ti = 0; ti < 2*T+1; ti++){
    maxV[ti+1] = min(maxV[ti+1], maxV[ti]+0.5);
  }

  for(int ti = 2*T; ti >= 0; ti--){
    maxV[ti] = min(maxV[ti], maxV[ti+1] + 0.5);
  }

  double ans = 0.0;
  for(int i =0; i < 2 * T + 1; i++){
    ans += (maxV[i] + maxV[i+1]) * 0.5 / 2.0;
  }
  cout << setprecision(10) << ans << endl;

  return 0;
}


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

int main (){
    int n,j;

    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> j;
        if(j % 2 == 0 && j % 3 != 0 && j % 5 != 0) {
            cout << "DENIED" << endl;
            return 0;
        }
    }

    cout << "APPROVED" << endl;

    return 0;

}

Measured memory_bytes: 3644
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int box[] = new int[N];
		for (int i = 0; i < N; i++) {
			box[i] = Integer.parseInt(sc.next());
		}

		double ans = java.util.Arrays.stream(box).mapToDouble(s -> 1.0 / s).sum();

		ans = 1.0 / ans;
		
		PrintWriter out = new PrintWriter(System.out);
		out.println(ans);
		out.flush();
	}

}



Measured memory_bytes: 29268
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

long dp[31];

int main(){
  fill(dp, dp+31, 0);
  dp[0]=1;
  for(int i=1; i<=30; i++){
    for(int j=1; j<=3; j++){
      if(i-j>=0) dp[i] += dp[i-j];
    }
  }
  int n;
  while(cin>>n, n){
    long res = (((dp[n]+9)/10)+364)/365;
    cout<<res<<endl;
  }

  return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
const char a[5]={'M','A','R','C','H'};
int main(){
	int n;
	cin>>n;
	map<char,ll> m;
	rep(i,n){
		string s;
		cin>>s;
		m[s[0]]++;
	} 
	ll ans=0;
	rep(i,5){
		REP(j,i+1,5){
			REP(k,j+1,5){
				ans+=m[a[i]]*m[a[j]]*m[a[k]];
			}
		}
	}
	cout<<ans<<endl;
	re 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n;

	cin >> n;

	vector<ll> v(n);

	REP(i, n) {
		cin >> v[i];
		v[i] -= i + 1;
	}

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

	ll sum = 0;

	REP(i, n) {
		sum += abs(v[i] - v[0]);
	}

	ll prev = INF;
	ll now = 0;

	while (now < n - 1) {
		now++;
		ll d = v[now] - v[now - 1];
		sum -= d * (n - now);
		sum += d * now;
		if (sum > prev) {
			sum = prev;
			break;
		}
		prev = sum;
	}

	cout << sum << endl;
}

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

int main() {
    long long  N,K;
    cin >> N >> K;
    int a,b;
    map<int,long long> num;
    for(int i=0;i<N;i++){
        cin >> a >> b;
        auto itr=num.find(a);
        if(itr!=num.end()){
            itr->second+=b;
        }else{
            num[a]=b;
        }
    }
    long long sum=0;
    auto it=num.begin();
    while(it!=num.end()){
        sum+=it->second;
        if(sum>=K){
            cout << it->first << endl;
            return 0;
        }
        it++;
    }
}

Measured memory_bytes: 4224
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter, defaultdict

def compress(s):
    ret = []
    for i, si in enumerate(s):
        if i == 0:
            ret.append(si)
        else:
            if si == ret[-1]:
                continue
            else:
                ret.append(si)
                
    return ret

def removeonly1(s):
    cnt = Counter(s)
    ret = []
    
    for si in s:
        if cnt[si] == 1:
            continue
        else:
            ret.append(si)
            
    return ret

n = ni()
c = [ni() for _ in range(n)]
MOD = 10**9+7

colors = removeonly1(compress(c))


dp = [0 for _ in range(len(colors)+1)]

dp[0] = 1
idxs = defaultdict(list)
keys = set()

for i, ci in enumerate(colors):
    dp[i+1] = dp[i]
    
    if ci in keys:
        dp[i+1] += dp[idxs[ci][-1]+1]
        dp[i+1] %= MOD
        
    idxs[ci].append(i)
    keys.add(ci)
        
print(dp[len(colors)])
    

Measured memory_bytes: 91396
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i,n) for (int i=0; i<(int)(n); i++)
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int L[100000];
	int R[100000];
	int mM = 1;
	int Mm = n;
	rep(i, m) {
		cin >> L[i] >> R[i];
		mM = max(mM, L[i]);
		Mm = min(Mm, R[i]);
	}
	if (Mm < mM) {
		cout << "0" << endl;
	}
	else {
		cout << Mm - mM + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
x=set([int(input()) for _ in range(m)])
f=[0]*(n+1)
f[0]=1
for i in range(1,n+1):
  f[i]=(f[i-1]+f[i-2])%(10**9+7)
  if i in x:
    f[i]=0
print(f[n]%(10**9+7))

Measured memory_bytes: 13192
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_V = 100050;
int X, Y, Z;
long long A[MAX_V], B[MAX_V], C[MAX_V];

long long y_ac[MAX_V], x_ac[MAX_V];

int main(int argc, char **argv) {
    std::cin >> X >> Y >> Z;

    for (int i = 0; i < X + Y + Z; i++) {
        std::cin >> A[i] >> B[i] >> C[i];
    }

    std::vector<std::pair<int, long long>> sg_vec;
    for (int i = 0; i < X + Y + Z; i++) {
        sg_vec.push_back(std::pair<int, long long>({i, A[i] - B[i]}));
    }

    std::sort(sg_vec.begin(), sg_vec.end(),
        [](const std::pair<int, long long>& a, const std::pair<int, long long>& b) { return a.second < b.second; }    
    );

    long long tmp_sum_y = 0;
    long long tmp_sum_x = 0;
    long long tmp_sum_z = 0;
    std::priority_queue<long long, std::vector<long long>> pqy, pqx;
    for (int i = 0; i < X + Y + Z; i++) {
        //std::cout << "order:" << sg_vec[i].first << std::endl;
        if (i < Y) {
            tmp_sum_y += B[sg_vec[i].first];
            pqy.push(C[sg_vec[i].first] - B[sg_vec[i].first]);
        } else if (i < Y + Z) {
            tmp_sum_z += C[sg_vec[i].first];
        } else {
            tmp_sum_x += A[sg_vec[i].first];
            pqx.push(C[sg_vec[i].first] - A[sg_vec[i].first]);
        }
    }

    y_ac[Y-1] = tmp_sum_y;
    for (int i = Y; i <= Y + Z - 1; i++) {
        pqy.push(C[sg_vec[i].first] - B[sg_vec[i].first]);
        //std::cout << "y_ac:" << i << " " << y_ac[i-1] << " " << pqy.top() << " " << B[sg_vec[i].first] << std::endl;
        y_ac[i] = y_ac[i-1] + pqy.top() + B[sg_vec[i].first];
        pqy.pop();
    }

    x_ac[Y+Z] = tmp_sum_x;
    for (int i = Y + Z - 1; Y <= i; i--) {
        pqx.push(C[sg_vec[i].first] - A[sg_vec[i].first]);
        x_ac[i] = x_ac[i+1] + pqx.top() + A[sg_vec[i].first];
        pqx.pop();
    }

    long long ret = 0;
    for (int i = 0; i <= Z; i++) {
        //std::cout << i << " " << y_ac[Y - 1 + i] << " " << x_ac[Y + i] << std::endl;
        ret = std::max(ret, y_ac[Y - 1 + i] + x_ac[Y + i]);
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 6128
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  int count=0;
  vector<int>vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(vec.at(i)==vec.at(j)||vec.at(j)==vec.at(k)||vec.at(k)==vec.at(i)){
          continue;}
        else if((vec.at(k)-vec.at(j))<vec.at(i)){
          count++;
        }
      }
    }
  }
  cout<<count<<endl;
}

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

map<ll, ll> hm;

void primes(ll n){
    ll num=0;
    for(ll i=2; ((i*i)<=n); i++){
        if(n%i==0){
            hm[i]++;
            num=i;
            break;
        }
    }
    if(num!=0){
        primes(n/num);
    }
    else{
        hm[n]++;
    }
}

ll find_total(ll a){
    for(ll i=1; i<100; i++){
        if(((i*(i+1))/2) > a){
            return (i-1);
        }
    }
}

int main(){
    ll n;
    cin>>n;
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    primes(n);
    map<ll, ll>::iterator it;
    ll ans=0;
    for(it=hm.begin(); it!=hm.end(); it++){
        ans+=find_total(it->second);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    ll k;
    cin >> k;
    vector<int> a(k+1);
    a[0] = 7 % k;
    rep(i,k){
        a[i + 1] = (a[i] * 10 + 7) % k;
        if(a[i] == 0){
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 7124
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>


using namespace std;
using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A & a, const B & b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A & a, const B & b) { a = max(a, (A)b); };

struct edge {
	int from, to;
	ll cost;
};

struct node {
	ll dist;
	bool flag;
	vector<int> edto;
	vector<int> edfrom;
};

void f(vector<node>& nod, vector<edge>& ed, int ind) {
	nod[ind].flag = true;
	for (int e : nod[ind].edfrom) if (!nod[ed[e].from].flag) f(nod, ed, ed[e].from);
}

int main() {
	ll inf = 1e18;
	ll N, M; cin >> N >> M;
	vector<edge> ed(M);
	vector<node> nod(N);
	REP(i, 0, M) {
		cin >> ed[i].from >> ed[i].to >> ed[i].cost;
		ed[i].from--;
		ed[i].to--;
		ed[i].cost *= -1;
		nod[ed[i].from].edto.push_back(i);
		nod[ed[i].to].edfrom.push_back(i);
	}
	REP(i, 0, N) {
		nod[i].dist = i == 0 ? 0 : inf;
		nod[i].flag = false;
	}
	f(nod, ed, N - 1);
	REP(i, 0, N) {
		REP(j, 0, M) {
			edge& e = ed[j];
			if (nod[e.to].dist > nod[e.from].dist + e.cost) {
				nod[e.to].dist = nod[e.from].dist + e.cost;
				if (i == N - 1 && nod[e.to].flag) {
					PRI("inf");
					return 0;
				}
			}
		}
	}
	PRI(-nod[N - 1].dist);
	return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
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;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


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

    ll N ;
    cin >> N ;
    ll ans = 0;
    
    for(ll i = 1; i <= N; i++){
        for(ll j = 1; j <= N ; j++){
            ll aim = gcd(i,j);
            for(ll k =1; k <= N; k++){
                ans += gcd(aim, k);
            }
        }
    }

    cout << ans << endl;
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

int a,b,c;
int f[100];

int main() 
{
	cin>>a>>b>>c;
	int j=a%b;
	while (1)
	{
		if (j==c)
		{
			cout<<"YES"<<endl;
			return 0;
		}
		if (f[j])
		{
			cout<<"NO"<<endl;
			return 0;
		}else f[j]=1;
		j=(j+a)%b;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String w = sc.next();
        char[] c = w.toCharArray();
        HashMap<Character,Integer> map = new HashMap<Character,Integer>();
        for(int i = 0;i < w.length();i++){
            if(map.containsKey(c[i])){
                map.put(c[i],map.get(c[i])+1);
                continue;
            }
            map.put(c[i],1);
        }
        for(Character key : map.keySet()){
            if(map.get(key) % 2 == 1){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 23764
N,M =map(int,input().split())
H = list(map(int,input().split()))
a = []
for i in range(N):
    a.append(1)
for i in range(M):
    A = list(map(int,input().split()))
    if H[A[0]-1] >= H[A[1]-1]:
        a[A[1]-1] = 0
    if H[A[0]-1] <= H[A[1]-1]:
        a[A[0]-1] = 0
ans = 0
for i in range(N):
    ans = ans + a[i]
print(ans)



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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    long long cnt[3];
    fill(cnt,cnt+3,0);
    for(int i=0; i<n; i++){
        if(s[i]=='R') cnt[0]++;
        else if(s[i]=='G') cnt[1]++;
        else cnt[2]++;
    }
    long long ans = cnt[0]*cnt[1]*cnt[2];
    for(int i=1; i<=n/2; i++){
        for(int j=0; j+2*i<n; j++){
            if(s[j]!=s[j+i] && s[j+i]!=s[j+2*i] && s[j]!=s[j+2*i]) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


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

long long ans, n;

int main() {
	cin >> n;
	if (n == 1)
		return cout << 0, 0;
	for (long long i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			long long a, b;
			a = n / i;
			b = i;
			if (n % (a - 1) == n / a)
				ans += a - 1;
			if (b != a && n % (b - 1) == n / b)
				ans += b - 1;
		}
	}
	if (n / (n - 1) == 1)
		ans += n - 1;
	cout << ans;
}

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

int main(){
    string s,t; cin>>s>>t;
    for(int i=0;i<s.length();i++){
        if(s==t){
            cout<<"Yes"<<endl;
            return 0;
        }
        s=s[s.length()-1]+s;
        s.erase(s.begin()+s.length()-1);
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
n = int(input())
div = prime_factorize(n)

ans = 11
m = len(div)
for i in range(1<<m):
    a, b = 1, 1
    for j in range(m):
        if i & (1<<j):
            a *= div[j]
        else:
            b *= div[j]
    tmp = max(a, b)
    ans = min(ans, len(str(tmp)))
print(ans)

Measured memory_bytes: 68272
import java.util.Scanner;

/*
 * 3
 * 0.30 0.60 0.80
 * */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        double[] a = new double[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextDouble();
        }
        Double[][] dp = new Double[n][(n + 1) / 2+1];
        System.out.println(coinsMajorityHeadProbablity(a, (n + 1) / 2, dp, 0));
    }

    private static Double coinsMajorityHeadProbablity(double[] a, int x, Double[][] dp, int i) {
        if (x == 0) return 1.0;
        if (i == a.length) return 0.0;

        if (dp[i][x] != null) return dp[i][x];
        double res = a[i] * coinsMajorityHeadProbablity(a, x - 1, dp, i + 1)
                + (1 - a[i]) * coinsMajorityHeadProbablity(a, x, dp, i + 1);
        dp[i][x] = res;
        return res;
    }
}

Measured memory_bytes: 175052
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <cstring>
#define ll long long int
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define PI 3.141592653589793
using namespace std;

ll hit(ll H, ll i, ll ans){
    if(H > 1) {
        ans += pow(2,i);
        i++;
        hit(H/2,i,ans);
    }
    else return ans += pow(2,i);
}
int main() {
    ll H,i=0,ans=0;
    cin >> H;
    ans = hit(H,i,ans);
    cout << ans << endl;

    return 0;
}

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

int s(int x){
int ans,y=x;
y%=5;
x=(x-y)/5;
if(x<5)ans=x;
if(x>=5)ans=s(x)+x;
return ans;}

int main(){
int n,ans;
while(cin>>n){
if(n==0){break;}
ans=s(n);
cout<<ans<<endl;}}

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


int main(){
    string a,b;
    cin>>a;
    cin>>b;
    a=' '+a;
    b=' '+b;
    int A=a.length();
    int B=b.length();
    int dp[A][B];
    for(int i=0; i<A; i++){
        for(int j=0; j<B; j++){
            if(i==0 || j==0){
                dp[i][j]=0;
                continue;
            }
            else if(a[i]==b[j]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i=A-1,j=B-1;
    string ans="";
    while(i>0 && j>0){
        if(a[i]==b[j]){
            ans=a[i]+ans;
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1]){
            i--;
        }
        else{
            j--;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 38836
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
using namespace std;

int main(void){
	string s;
	long long int ans=0;
	cin>>s;
	int b=0;
	for(int i=0;i<s.length();i++){
//		cout<<s[i]<<" "<<i<<" "<<b<<" "<<ans<<endl;
		if(s[i]=='W'){
			ans+=i-b;
			b++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	
	ll n;
	ll sum=0;
	ll i,j,k,z;
	cin>>n;
	for(i=1;i<=n;i++)
	{
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
            	z=__gcd(j,k);
            	sum=sum+__gcd(i,z);
            }
        }  
	}
	cout<<sum;
	return 0;
	
}

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

int main(){
  int n,b;
  cin>>n;
  int a[35];
  a[0]=1;
  for(int i=1;i<32;i++){
    a[i]=a[i-1]*(-2);
    //cout<<a[i]<<endl;
  }
  vector<int> ans;
  for(int i=1;i<33;i++){
    if(n%a[i]==0) ans.push_back(0);
    else{ans.push_back(1);n-=a[i-1];}
    if(n==0) break;
  }
  for(int i=ans.size()-1;i>=0;i--){
    cout<<ans[i];
  }
  cout<<endl;
  return 0;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;

void turn(int i, vector<int> &dp, vector<vector<int>> &map) {
    if(map.at(i).size() == 0) {
        dp.at(i) = 0;
    } else {
        rp(k, 0, map.at(i).size()) {
            if(dp.at(map.at(i).at(k)) < 0) turn(map.at(i).at(k), dp, map);
            chmax(dp.at(i), dp.at(map.at(i).at(k)) + 1);
        }
    }
}


int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<vector<int>> map(n+1);
    rp(i, 0, m) {
        int x, y;
        scanf("%d%d", &x, &y);
        map.at(x).push_back(y);
    }
    vector<int> dp(n+1, -1);
    rp(i, 1, n+1) {
        turn(i, dp, map);
    }
    int res = *max_element(dp.begin(), dp.end());
    printf("%d", res);
    return 0;
} 

Measured memory_bytes: 9472
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;
typedef pair<int, int> ii;
#define int long long int

const lli MOD = 1000000007LL;

inline lli mod_add(lli x, lli y) {
    return (x + y) % MOD;
}

inline lli mod_mul(lli x, lli y) {
    return (x * y) % MOD;
}

inline lli mod_sub(lli x, lli y) {
    return x - y >= 0 ? (x - y) % MOD : (x - y + MOD) % MOD;
}

inline lli mod_pow(lli x, lli y) {
    lli ret = 1;
    while (y > 0) {
        if (y & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        y = y >> 1;
    }
    return ret;
}

inline lli mod_inv(lli x) {
    return mod_pow(x, MOD - 2);
}

inline lli mod_div(lli x, lli y) {
    return x * mod_inv(y) % MOD;
}

#define MAX_FAC 2001
lli fac[MAX_FAC], finv[MAX_FAC];
void init_fac() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < MAX_FAC; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        finv[i] = finv[i - 1] * mod_inv(i) % MOD;
    }
}
inline lli com(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main() {
    int N, K; cin >> N >> K;

    init_fac();

    for (int i = 1; i <= K; i++) {
        int c1 = com(N - K + 1, i);
        int c2 = com(K - 1, i - 1);
        cout << mod_mul(c1, c2) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int dp[1010][1010];
int H,W;
string s[1010];

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>H>>W;
    rep(i,0,H)cin>>s[i];
    dp[0][0]=1;
    rep(i,0,H){
        rep(j,0,W){
            if(s[i][j]=='#')continue;
            if(i==0&&j==0)continue;
            else if(i==0)dp[i][j]+=dp[i][j-1];
            else if(j==0)dp[i][j]+=dp[i-1][j];
            else dp[i][j]+=dp[i-1][j]+dp[i][j-1];
            dp[i][j]%=MOD;
        }
    }
    cout<<dp[H-1][W-1]<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#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 LLINF (llong)1e18+5
#define INF 1e9+1
#define endl '\n'

using namespace std;
using llong = long long;
using VI = vector<int>;
using VLL = vector<long long>;
using PII = pair<int, int>;

//struct cmp {
//	bool operator() (pair<PII, int> a, pair<PII, int> b)
//	{
//		return a.ss > b.ss;
//	}
//};

int n, k;
VI a;
VI dp;

int dfs(int kk) { // 승리시 1, 패배시 -1
	int& ret = dp[kk];
	if (ret != 0) return ret;
	int ans = -1;
	rep(i, 0, n) {
		if (kk >= a[i])
		{
			ans = max(ans, -dfs(kk - a[i]));
			if (ans == 1) break;
		}
	}
	return ret=ans;
}

int main()
{
	cin >> n >> k;
	a = VI(n);
	dp = VI(k+1);
	rep(i, 0, n) cin >> a[i];
	int ans = dfs(k);
	if (ans==1) cout << "First";
	else cout << "Second";
}

Measured memory_bytes: 8268
#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[i];
  }
  int i = 0;
  int cnt = 0;
  bool flg = false;
  while (true) {
    i = a[i] - 1;
    ++cnt;
    if (i == 1) {
      flg = true;
      break;
    }
    if (N <= cnt) {
      break;
    }
  }
  if (flg) {
    cout << cnt << endl;
  } else {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 640
n, k = map(int,input().split())
s = list(input())

Nums = []
now = 1#今見てる数(１を見て判定していくために最初を１として判定を始める)
cnt = 0#nowがいくつ並んでるか

for i in range(0,n):
    if s[i] == str(now):
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now#０と１の切り替え
        cnt = 1#新しいのをカウントし始める
if cnt != 0:Nums.append(cnt)

#長さが２の倍数であるならば任意の数を最後に加える．ながさを奇数倍にしたい
if len(Nums) % 2 == 0:Nums.append(0)
sum = [0]*(len(Nums)+1)

for i in range(len(Nums)):
    sum[i+1] = sum[i] + Nums[i]

add = 2 * k + 1
ans = 0

for i in range(0,len(sum),2):
    tmp = 0
    left = i
    right = min(i+add,len(Nums))
    tmp = sum[right] - sum[left]
    ans = max(ans,tmp)

print(ans)

Measured memory_bytes: 8568
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  string x=a+b;
  int z=stoi(x);
  int w=sqrt(z);
  if(w*w==z) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,i,ans=0,A;cin>>N;
  vector<ll>X(100001,0);
  REP(i,N){
    cin>>A;ans+=A;X.at(A)++;
  }
  cin>>A;
  REP(i,A){
    ll B,C;cin>>B>>C;
    ans+=X.at(B)*(C-B);
    cout<<ans<<endl;
    X.at(C)+=X.at(B);
    X.at(B)=0;
  }
  return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> x(M), y(M);
  for (int i=0; i<M; i++) cin >> x[i] >> y[i];
  vector<int> num(N, 1);
  vector<bool> red(N, false);
  red[0] = true;
  for (int i=0; i<M; i++) {
    if (red[x[i]-1]) red[y[i]-1] = true;
    num[x[i]-1]--;
    num[y[i]-1]++;
    if (num[x[i]-1]==0) red[x[i]-1] = false;
  }
  cout << count(red.begin(), red.end(), true) << endl;
}

Measured memory_bytes: 1408
import java.util.*

fun main(args: Array<String>){
  val (N,A,B) = readLine()!!.split(' ').map(String::toLong)
  val min = (N-1)*A+B
  val max = (N-1)*B+A
  val res = if (max-min<0) 0 else max-min+1
  println(res)
}


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

#define MOD (1000000000+7)

int main()
{
	int N, K;

	cin >> N >> K;
	vector<vector<int>> G( N );
	for( int i = 0; i < N - 1; i++ ) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back( b );
		G[b].push_back( a );
	}

	vector<int> visit( N );
	queue<tuple<int, int>> que;
	que.push( make_tuple( 0, -1 ) );
	visit[0] = 1;
	long long ans = K;
	while( !que.empty() ) {
		int now, from;
		tie(now, from) = que.front();
		que.pop();
		int use_color;
		if( from < 0 ) {
			use_color = K - 1;
		}
		else {
			use_color = K - 2;
		}
		for( auto e : G[now] ) {
			if( visit[e] ) continue;
			ans *= use_color;
			use_color--;
			ans %= MOD;
			que.push( make_tuple( e, now ) );
			visit[e] = 1;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 7288
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

std::vector<std::vector<LL>>G;
std::vector<bool>vis;
std::vector<LL>depth;

void dfs(LL v, LL d)
{
	if (vis[v]) return;
	vis[v] = true;
	depth[v] = d;
	for (auto u : G[v]) dfs(u, d + 1);
}

int main()
{
	LL N, K;
	in >> N >> K;
	std::vector<LL>A(N - 1), B(N - 1);
	rep(i, N - 1) in >> A[i] >> B[i];

	G.resize(N + 1);
	rep(i, N - 1)
	{
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}

	LL ans = N;
	if (K % 2 == 0)
	{
		for (int i = 1; i <= N; ++i)
		{
			vis.clear(); vis.resize(N + 1, false);
			depth.clear(); depth.resize(N + 1, 0);
			dfs(i, 0);

			LL res = 0;
			for (int j = 1; j <= N; ++j) if (depth[j] <= K / 2) ++res;
			ans = std::min(ans, N - res);
		}
	}
	else
	{
		rep(i, N - 1)
		{
			vis.clear(); vis.resize(N + 1, false);
			depth.clear(); depth.resize(N + 1, 0);
			vis[B[i]] = true;
			dfs(A[i], 0);
			vis[B[i]] = false;
			dfs(B[i], 0);

			LL res = 0;
			for (int j = 1; j <= N; ++j) if (depth[j] <= K / 2) ++res;
			ans = std::min(ans, N - res);
		}
	}

	out << ans << std::endl;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out,false);
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        char[][] output = new char[h][w];
        for(char[] cc: output) Arrays.fill(cc, '0');
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                if (i < b && j >= a) output[i][j] = '1';
                else if (i >= b && j < a) output[i][j] = '1';
            }
        }
        for(char[] cc: output) out.println(cc);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

#define ii pair<int,int>
#define ll long long
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

int n;
const int MAXS = 5e5;
int fen[MAXS + 3];
int a[MAXS + 3];
queue<int> elems[MAXS + 3];
vii queries[MAXS + 3];
int ans[MAXS+3];

void update(int pos, int delta){
    while(pos <= n){
        fen[pos] += delta;
        pos += pos & (-pos);
    }
}

int query(int pos){
    int answer = 0;
    while(pos){
        answer += fen[pos];
        pos -= pos & (-pos);
    }
    return answer;
}

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
    cin>>n;
    int q; cin>>q;
    vii arq;
    bool vis[n+2] = {};
    for (int i=1; i<=n; i++){
        cin>>a[i];
        elems[a[i]].push(i);
        if (!vis[a[i]]){
            update(i, 1);
            vis[a[i]] = 1;
        }
    }
    for (int i=0; i<q; i++){
        int l,r; cin>>l>>r;
        queries[l].pb(ii(i, r));
    }
    
    for (int i=1; i<=n; i++){
        //first answer all, then update:
        for (int j=0; j<queries[i].size(); ++j){
            int r = queries[i][j].second;
            int index = queries[i][j].first;
            int cans = query(r);
            ans[index] = cans;
        }
        queries[i].clear();
        int el = a[i];
        int pos = elems[el].front();
        elems[el].pop();
        update(pos, -1);
        if (!elems[el].empty()) update(elems[el].front(), 1);
    }
    for (int i=0; i<q; i++){
        cout<<ans[i]<<'\n';
    }
    
	return 0;
}
/*
NARCO
*/


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

int main(){
  int a, b, c;
  int keta;

  while(cin >> a){
    cin >> b;
    c=a+b;
    keta=1;
    while((c/=10)>0) keta++;
    cout << keta << endl;
  }
  
  return 0;
}

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


int main() {

    int n;
    cin >> n;
    int tmp = 1;
    int cnt = 0;
    int t = 0;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        if (tmp == a) ++tmp;
        else ++cnt;
        if (a != 1) ++t;
    }
    if (t == n) {
        cout << -1 << endl;
        return 0;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1e9;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

void warshall_floyd(const int& n, vector<vector<int>>& d) {
  rep(k, n) rep(i, n) rep(j, n) chmin(d[i][j], d[i][k] + d[k][j]);
}

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

  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> to(n);
  vector<vector<int>> d(n, vector<int>(n, INF));
  rep(i, n) d[i][i] = 0;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    d[a][b] = c;
    d[b][a] = c;
    to[a].push_back({b, c});
    to[b].push_back({a, c});
  }

  warshall_floyd(n, d);

  set<pair<int, int>> paths;

  rep(a, n) rep(b, n) {       // a -> b の最短経路
    if (a == b) continue;
    for (auto& p : to[a]) {   // a に隣接しているノード
      int c = p.first;
      if (p.second + d[c][b] == d[a][b]) {
        paths.insert({min(a, c), max(a, c)});
      }
    }
  }

  cout << m - paths.size() << endl;

  return 0;
}


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

int main(){
  int k, x;
  // vector<int> hoge;
  cin >> k >> x;
  int first = x - (k - 1);
  int min = -1000000;
  if(first < min){
    first = min;
  }

  int last = x + (k - 1);
  int max = 1000000;
  if(last > max){
    last = max;
  }

  for (int i = first; i <= last; i++){
    if(i == last){
      cout << i << endl;
    }else{
      cout << i << " ";
    }
  }
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;

  ll m = a*c;
  m = max(m,a*d);
  m = max(m,b*c);
  m = max(m,b*d);
  
  cout << m << endl;
    

  return 0;
}



Measured memory_bytes: 3684
while True:
    a, op, b = input().split()
    if op == "?":
        break
    a, b = int(a), int(b)
    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "/":
        print("%d" % (a / b))
    else:
        print(a * b)



Measured memory_bytes: 5600
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
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;}



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

  ll N; cin >> N ;
  vector<ll> A,B;

  
  rep(i,N){
    ll inp;cin >> inp;
    A.pb(inp);
  }
  rep(i,N){
    ll inp; cin >> inp;
    B.pb(inp);
  }

  ll suma = 0;
  ll sumb = 0;

  rep(i,N){
    suma += A[i];
    sumb += B[i];
  }
  
  ll times = sumb - suma;
  ll at = 0 ,bt = 0;
  
  rep(i,N){
    if(A[i] < B[i]){
      at += ((B[i]-A[i])/2 + ((B[i]-A[i])%2));
      if((B[i]-A[i]) %2) bt ++;
    }
    else
      bt += A[i]-B[i];
  }
  
  
  
  if(  at <= times && bt <= times ) cout << "Yes" << endl;
  else cout <<"No" << endl;
  

  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

class Card
{
    public:
    char mark;
    int num;
};

void bubble_sort(Card R[],int n);
void selection_sort(Card R[],int n);
void print(Card R[],int n);
bool check_stable(Card R1[],Card R2[],int n);

int main(int argc, char const *argv[])
{
    Card C1[40],C2[40];
    int n;

    std::cin >> n;

    for(int i = 0;i < n;i++){
        std::cin >> C1[i].mark >> C1[i].num;
        C2[i].mark = C1[i].mark;
        C2[i].num = C1[i].num;
    }

    bubble_sort(C1,n);
    print(C1,n);
    if(check_stable(C1,C2,n)) std::cout << "Stable" << std::endl;
    else std::cout << "Not stable" << std::endl;

    selection_sort(C2,n);
    print(C2,n);

    for(int i = 0;i < n;i++){
        if(C1[i].mark != C2[i].mark){
             std::cout << "Not stable" << std::endl;
             break;
        }
        
        if(i == n - 1) std::cout << "Stable" << std::endl;
    } 

    return 0;
}

void bubble_sort(Card R[],int n){
    for(int i = 0;i < n - 1;i++){        
        for(int j = n - 1;j > i;j--){
            if(R[j].num < R[j-1].num){
                Card tmp = R[j];
                R[j] = R[j-1];
                R[j-1] = tmp;
            }
        }
    }
}

void selection_sort(Card R[],int n){
    for(int i = 0;i < n - 1;i++){
        int minj = i;
        
        for(int j = i + 1;j < n;j++){
            if(R[j].num < R[minj].num) minj = j;
        }
        
        Card tmp = R[i];
        R[i] = R[minj];
        R[minj] = tmp;
    }

}

void print(Card R[],int n){
    for(int i = 0;i < n;i++){
            if(i != n - 1) std::cout << R[i].mark << R[i].num << " ";
            else std::cout << R[i].mark << R[i].num << std::endl;
    }
}

bool check_stable(Card in[],Card out[],int n){
    for(int i = 0;i < n;i++){
        for(int j = i+ 1;j < n;j++){
            for(int a = 0;a < n;a++){
                for(int b = a + 1;b < n;b++){
                    if((in[i].num == in[j].num) && (in[i].mark == out[b].mark) && ((in[i].num == out[b].num)) && (in[j].mark == out[a].mark) && ((in[j].num == out[a].num))) return false;
                }
            }
        }
    }

    return true;
}


Measured memory_bytes: 3140
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9+7;

int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}

int h,w;

bool inside(int y,int x){
	return (x < w && y < h && x >= 0 && y >= 0);
}

int nx[] = {1,0,-1,0};
int ny[] = {0,-1,0,1};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> h >> w;
	vector<string> s(h);
	int cnt = 0,sum = 0;
	rep(i,h){
		cin >> s[i];
		rep(j,w){
			sum += (s[i][j] == '#');
		}
	}
	rep(i,h){
		rep(j,w){
			bool flg = true;
			if(s[i][j] == '#'){
				rep(k,4){
					if(inside(i + ny[k],j + nx[k]) && s[i + ny[k]][j + nx[k]] == '#'){
						++cnt;
						break;
					}
				}
			}
		}
	}
	cout <<(cnt == sum ? "Yes\n" : "No\n");
	return 0;	
}


Measured memory_bytes: 256