akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{

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

  string a, b;
  cin >> a >> b;
  int n = a.size();
  int cnt = 0;
  for (int i = 0; i < n; i++)
  {
    if (a[i] != b[i])
    {
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

int main(){
  int x;
  cin >> x;
  int a, b;
  int c;
  a = x / 500;
  b = x % 500; 
  c = b / 5;
  cout << 1000 * a + 5 * c << endl;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
int n;
string s;
int dp[6000][6000];
signed main() {
	cin >> n >> s;
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= n; j++) {
			(dp[i + 1][j + 1] += dp[i][j] * 2) %= mod;
			(dp[i + 1][(j > 0 ? j - 1 : j)] += dp[i][j]) %= mod;
		}
	}
	int k = mod_pow(2, s.size(), mod);
	cout << dp[n][s.size()] * mod_pow(k, mod - 2, mod) % mod << endl;
}

Measured memory_bytes: 237568
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.PriorityQueue;
import java.math.BigInteger;
import java.math.BigDecimal;
       
public class Main{
   
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE/2;
static final long LINF=Long.MAX_VALUE/2;
static int MAX=1500;
static char[] str=new char[MAX+1];
   
public static void main(String[] args) throws IOException{
  BufferedReader br=new BufferedReader(new InputStreamReader(in));
  int n=Integer.parseInt(br.readLine());
  while(n-->0){
    String line=br.readLine();
    int cur=0;
    Arrays.fill(str,'-');
    for(int i=0;i<line.length();i++) str[i]=line.charAt(i);
    int m=Integer.parseInt(br.readLine());
    while(m-->0){
      String com=br.readLine(),com0,com1;
      for(int i=0;;i++){
        if(com.charAt(i)==' '){
          com0=com.substring(0,i);
          com1=com.substring(i+1);
          break;
        }
      }
      if("forward".equals(com0)){
        if("char".equals(com1)){
          if(str[cur]!='-') cur++;
        }
        else if("word".equals(com1)){
          while(str[cur]==' ') cur++;
          while(str[cur]!=' '&&str[cur]!='-') cur++;
        }
      }
      else if("backward".equals(com0)){
        if("char".equals(com1)){
          if(cur>0) cur--;
        }
        else if("word".equals(com1)){
          while(cur>0&&str[cur-1]==' ') cur--;
          while(cur>0&&str[cur-1]!=' ') cur--;
        }
      }
      else if("insert".equals(com0)){
        if(com1.length()>2){
          String insertionStr=com1.substring(1,com1.length()-1);
          for(int i=MAX-insertionStr.length();i>=cur;i--){
            if(str[i]!='-') str[i+insertionStr.length()]=str[i];
          }
          for(int i=0;i<insertionStr.length();i++){
            str[cur+i]=insertionStr.charAt(i);
          }
          cur+=insertionStr.length();
        }
      }
      else if("delete".equals(com0)){
        if("char".equals(com1)){
          if(str[cur]!='-'){
            for(int i=cur;;i++){
              if(str[i]=='-') break;
              str[i]=str[i+1];
            }
          }
        }
        else if("word".equals(com1)){
          int cnt=cur;
          while(str[cnt]==' ') cnt++;
          if(str[cnt]!='-'){
            while(str[cnt]!=' '&&str[cnt]!='-') cnt++;
            for(int i=cur;;i++){
              if(str[i]=='-') break;
              str[i]=str[i-cur+cnt];
            }
          }
        }
      }
    }
    StringBuilder sb=new StringBuilder();
    for(int i=0;;i++){
      if(i==cur) sb.append("^");
      if(str[i]=='-') break;
      sb.append(String.valueOf(str[i]));
    }
    out.println(sb);
  }
out.flush();
}
}

Measured memory_bytes: 20576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vec vector
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << a << endl
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

struct Point {
  ll x; ll y;
  Point(ll a=0,ll b=0) { x=a; y=b; }
  Point &operator+=(const Point &p) { x+=p.x; y+=p.y; return *this; }
  Point &operator+=(const ll c) { x+=c; y+=c; return *this; }
  Point &operator-=(const Point &p) { x-=p.x; y-=p.y; return *this; }
  Point &operator-=(const ll c) { x-=c; y-=c; return *this; }
  Point &operator*=(const Point &p) { x*=p.x; y*=p.y; return *this; }
  Point &operator*=(const ll &c) { x*=c; y*=c; return *this; }
  Point operator-() const{ return Point(-x,-y); }
  Point operator+(const Point &p) const { return Point(*this)+=p; }
  Point operator-(const Point &p) const { return Point(*this)-=p; }
  Point operator*(const Point &p) const { return Point(*this)*=p; }
  friend Point operator*(const Point &p, const ll c) { return Point(p) *= c; }
  friend Point operator*(const ll c, const Point &p) { return Point(p) *= c; }
  bool operator==(const Point &p) const { return x==p.x && y==p.y; }
  bool operator!=(const Point &p) const { return x!=p.x || y!=p.y; }
  Point swap() const { return Point(y,x); }
  friend ostream &operator<<(ostream &os, const Point &p) { return os << p.x << "," << p.y; }
  friend istream &operator>>(istream &is, Point &p) {
    ll a,b;
    is >> a >> b;
    p = Point(a,b);
    return (is);
  }
  ld distance(const Point &p) {
    ld x_2,y_2;
    x_2 = (x-p.x)*(x-p.x);
    y_2 = (y-p.y)*(y-p.y);
    return sqrtl(x_2+y_2);
  }
};


//Dijkstra (no minus cost path)
const int MAX_V = 1002;
const ld INF = 1e20;
typedef struct{
  int to;
  ld cost;
} Edge;
typedef pair<ld, int> P; //first:dis second:num

ld d[MAX_V];
vector<Edge> G[MAX_V];

void dijkstra(int s) {
  fill(d, d+MAX_V, INF);
  d[s] = 0;

  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (auto &e: G[v]) {
      if (d[e.to] > d[v]+e.cost) {
        d[e.to] = d[v]+e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}


int N;
vec<pair<Point,int>> circle(1002);


int main() {
  cin >> circle[0].first >> circle[1].first;
  circle[0].second = 0; circle[1].second = 0;
  cin >> N;
  rep(i,N) cin >> circle[2+i].first >> circle[2+i].second;
  rep(i,N+1) {
    reps(j,i+1,N+2) {
      ld t;
      t = circle[i].first.distance(circle[j].first) - circle[i].second - circle[j].second;
      t = max((ld)0.0,t);
      G[i].push_back({j,t});
      G[j].push_back({i,t});
    }
  }
  dijkstra(0);
  cout.precision(20);
  print(d[1]);
  return 0;
}

Measured memory_bytes: 44208
#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define fi first
#define se second
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define MOD 1000000007
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 200009
#define M 1e6 + 9
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll, ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
#define int long long
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}



void test_case()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;

    int ans = LONG_MIN;

    ans = max(ans, a*c);
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);

    cout<<ans<<endl;
    
    
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 3640
def e_active_infants():
    # 参考: https://kmjp.hatenablog.jp/entry/2020/04/20/0900
    N = int(input())
    A = [int(i) for i in input().split()]
    # どこから移動するかの情報が必要なので、付与する
    p = sorted([(a, k) for k, a in enumerate(A)], reverse=True)

    # dp[x][y]: 元の場所から (元の場所を含んで) 左に動いた人数が x 人、
    # 右に動いた人数が y 人のときのうれしさの最大値
    dp = [[-float('inf')] * (N + 1) for _ in range(N + 1)]
    dp[0][0] = 0  # 誰も動いていなければうれしさは 0
    for i in range(N):
        a, r = p[i]
        for x in range(i + 1):
            y = i - x
            # 左右の埋まっていない端に動かしたときの場合の遷移
            dp[x + 1][y] = max(dp[x + 1][y], dp[x][y] + abs(r - x) * a)
            dp[x][y + 1] = max(dp[x][y + 1], dp[x][y] + abs(r - (N - 1 - y)) * a)
    return max(dp[i][N - i] for i in range(N + 1))

print(e_active_infants())

Measured memory_bytes: 136036
#include<iostream>
#include<cstdlib>
using namespace std ;
int N,A,B,C,arr[100];
int ret_cost(int n,int a,int b,int c)
{
    if(n==N)
    {   if(a==0 || b==0 || c==0){return 100000000;}
        else { return  (abs(A-a)+abs(B-b)+abs(C-c)) ; }
    }
    int ret = (a>0 ? 10:0) + ret_cost(n+1,a+arr[n],b,c);
    ret = min ( ret ,(b>0 ? 10:0) + ret_cost(n+1,a,b+arr[n],c));
    ret = min (ret ,(c>0 ? 10:0) + ret_cost(n+1,a,b,c+arr[n]));
    ret = min(ret,ret_cost(n+1,a,b,c));
    return ret ;
}
int main()
{
    cin >> N >> A >> B >> C ;
    for(int i=0;i<N;i++)
    {
        int x ; cin >> x ; arr[i]=x ;
    }
     cout << ret_cost(0,0,0,0) << endl;;
}

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

int main()
{
    long long N;
    long long mod = 1000000007;
    long long power = 1;

    cin >> N;
    for(int i=1; i<=N; i++)
    {
        power = (power * i)%mod;
    }
    cout << power << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    println(problem075a(a, b, c))
}

fun problem075a(a: Int, b: Int, c: Int): Int {
    return if (a == c) b else if (a == b) c else a
}

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

using namespace std;

int main () {
    char str[100005];
    scanf("%s", str);
    int len=strlen(str);
    if(str[0]==str[len-1]) {
        if(len&1) puts("Second");
        else puts("First");
    } else {
        if(len&1) puts("First");
        else puts("Second");
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        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);
    }
};
 
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n;
int a[3000];
int dp[3000][3000];

void play(int i, int j, int p = 1) {
	if (i == j) {
		if (p&1)
			dp[i][j] = a[i];
		return;
	} else if (dp[i][j] != 0) {
		return;
	}
	play(i + 1, j, p^1);
	play(i, j - 1, p^1);
	if (p&1) {
		int s1 = a[i] + dp[i+1][j];
		int s2 = a[j] + dp[i][j-1];
		dp[i][j] = max(s1, s2);
	} else {
		dp[i][j] = min(dp[i+1][j], dp[i][j-1]);
	}
}

void solve() {
	int su = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	cin >> a[i];
    	su += a[i];
    }
    play(0, n-1);
    // for (int i = 0; i < n; i++) {
    // 	for (int j = 0; j < n; j++) {
    // 		cout << i << " " << j << " " << dp[i][j] << endl;
    // 	}
    // }
    cout << 2*dp[0][n-1] - su;
}
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
		
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007ll
#define INF (1 << 28)    // for x <= 10^9
#define INFL (1ll << 60) // for x <=10^19
#define EPS (1e-10)

using namespace std;

using ll = long long;

int main() {
  int n, k;
  cin >> n >> k;
  int ans = (k == 1) ? 0 : n - k;
  cout << ans;
}


Measured memory_bytes: 256
using System;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		long[,] h=new long[s[0]*s[1]+1,2];
		long[] a=new long[s[0]*s[1]+1];
		long[][] arr=new long[s[0]][];
		for(int i=0;i<s[0];i++){
			arr[i]=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
			for(int j=0;j<s[1];j++){
				h[arr[i][j],0]=i;
				h[arr[i][j],1]=j;
			}
		}
		for(int i=1;i<=s[0]*s[1]-s[2];i++){
			a[i+s[2]]=Math.Abs(h[i+s[2],0]-h[i,0])+Math.Abs(h[i+s[2],1]-h[i,1])+a[i];
		}
		int n=int.Parse(Console.ReadLine());
		for(int i=0;i<n;i++){
			int[] q=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			Console.WriteLine("{0}",a[q[1]]-a[q[0]]);
		}
	}
}

Measured memory_bytes: 20276
#include <stdio.h>

int main() {
  char table[26] = {'X','Y','Z','A','B','C','D','E','F','G','H','I','J',		    'K','L','M','N','O','P','Q','R','S','T','U','V','W'};
  char input[1001];
  scanf("%s",input);
  char c = input[0];
  int i;
  for(i=0; c!='\0'; i++){
    printf("%c",table[(c-65)]);
    c=input[i+1];
  }
printf("\n");
  return 0;
}

Measured memory_bytes: 0
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    vector<pair<pair<string, int>, int>> v(n);
    rep(i, n){
        string s;
        int p;
        cin >> s >> p;
        v[i] = make_pair(make_pair(s, -p), i + 1);
    }
    sort(ALL(v));
    rep(i, n){
        cout << v[i].second << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), 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 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


void solve(int n, int x){
    int ans = 0;
    for(int i=1; i<=n; i++){
        for(int j=i+1; j<=n; j++){
            for(int k=j+1; k<=n; k++){
                if(x == i+j+k) ans++;
            }
        }
    }

    cout << ans << endl;
}

int main(){
    int n, x;
    while(1){
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        solve(n, x);
    }
}


Measured memory_bytes: 3036
#include <stdio.h>

int isprime(int n) {
	int i;
	for(i = 2; i * i <= n; i++) {
		if(n % i == 0) {
			return 0;
		}
	}
	return 1;
}

int main() {
	int n,i;
	int sousi[2];
	int prime[10100][2];
	for (i = 0; i < 10100; i++) {
		prime[i][0] = i;
		prime[i][1] = isprime(i);
	}
	while(1) {
		sousi[0] = 0;
		sousi[1] = 0;	 
		scanf("%d",&n);
		if(n == 0) {
			break;
		}
		for(i = n; i > 2; i--) {
			if(prime[i][1] == 1 && prime[i - 2][1] == 1) {
				sousi[0] = prime[i - 2][0];
				sousi[1] = prime[i][0];
				break;
			}
		}
		printf("%d %d\n",sousi[0],sousi[1]);
	}
	return 0;
}

Measured memory_bytes: 1104
#include <iostream>

using namespace std;

int main(void) {

	int N, M = 0;

	scanf("%d %d", &N, &M);

	int *A = NULL;
	A = (int*)malloc(sizeof(int)*M);

	for( int ii = 0; ii < M; ii++ ) {
		scanf("%d", &A[ii]);
	}

	int sum = N;
	for( int ii = 0; ii < M; ii++) {
		sum = sum - A[ii];
	}

	if( sum >= 0 ) {
		cout << sum;
	} 
	else {
		cout << "-1";
	}

	if( A != NULL ) {
		free( A );
	}

	return 0;
}

Measured memory_bytes: 3716
import java.util.*;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			ArrayDeque<StringBuffer> q = new ArrayDeque<StringBuffer>();
			HashSet<String> hs = new HashSet<String>();
			String in_str;
			in_str = sc.next();
			StringBuffer sb = new StringBuffer(in_str);
			if(in_str.equals("0"))
				break;
			q.add(sb);
			hs.add(in_str);
			boolean flg_continue = true;
			for(int t = 0; flg_continue; t++) {
				ArrayDeque<StringBuffer> nex = new ArrayDeque<StringBuffer>();
				while(q.size() != 0 && flg_continue) {
					String a = q.poll().toString();
					boolean flg = true;
					for(int i = 1; i < a.length(); i++) {
						if(a.charAt(i-1) != a.charAt(i)) {
							StringBuffer push = new StringBuffer(a);
							char c = (char)((int)'r'+(int)'g'+(int)'b'-(int)a.charAt(i-1)-(int)a.charAt(i));
							push.setCharAt(i-1,c);
							push.setCharAt(i,c);
							if(!hs.contains(push.toString())) {
								hs.add(push.toString());
								nex.add(push);
							}
							flg = false;
						}
					}
					if(flg) {
						System.out.println(t);
						flg_continue = false;
					}
				}
				q = nex;
				if(flg_continue && nex.isEmpty()) {
					System.out.println("NA");
					flg_continue = false;
				}
//				System.out.print("t:");
//				System.out.print(t);
//				System.out.print(" size:");
//				System.out.println(q.size());
			}
		}
	}
}

Measured memory_bytes: 68264
import sys

def prim(E):
    V = [0]
    for i in range(len(E)):
        E[i][0] = -1
    n = len(E)
    sum = 0

    while len(V) != n:
        mini, minj, mine = -1, -1, 2001
        for i in V:
            for j in range(len(E[i])):
                if E[i][j] != -1 and E[i][j] < mine:
                    mini, minj, mine = i, j, E[i][j]
        V.append(minj)
        for i in range(len(E)):
            E[i][minj] = -1
        sum += mine

    return sum

lines = sys.stdin.readlines()
del lines[0]

E = []
for line in lines:
    E.append(map(int, line.split()))

print prim(E)

Measured memory_bytes: 6456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a,int b)
{
	if(b==0)return a;
	return gcd(b,a%b);
}
int g(int a,int b,int c)
{
	int x=gcd(a,b);
	int y=gcd(x,c);
	return y;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int k;
	cin>>k;
	ll sum=0;
	for(int a=1;a<=k;a++)
	{
		for(int b=1;b<=k;b++)
		{
			for(int c=1;c<=k;c++)
			{
				sum+=g(a,b,c);
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3640
import sys
input = sys.stdin.buffer.readline

from collections import deque

N = int(input())
neighbor = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    neighbor[a-1].append(b-1)
    neighbor[b-1].append(a-1)

c = list(map(int, input().split()))
c.sort(reverse = True)

d = deque([0])
ans = [c[0]] + [0]*(N-1)
M = 0
c_idx = 1

while d:
    p = d.popleft()
    for n in neighbor[p]:
        if not ans[n]:
            ans[n] = c[c_idx]
            M += c[c_idx]
            c_idx += 1
            d.append(n)

print(M)
print(*ans)

Measured memory_bytes: 6288
#include<bits/stdc++.h>
const int N=3e5+7;
int n,m;
struct pos{
	int x,y;
	bool operator<(const pos&w)const{return x>w.x;}
}ps[N];
int bit[N],as[N],bs[N];
void inc(int w){
	++bs[w];
	for(;w<=m;w+=w&-w)++bit[w];
}
int sum(int w){
	if(w>m)w=m;
	int s=0;
	for(;w;w-=w&-w)s+=bit[w];
	return s;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;++i)scanf("%d%d",&ps[i].x,&ps[i].y);
	std::sort(ps,ps+n);
	for(int i=m,p=0;;--i){
		for(;p<n&&ps[p].x>i;inc(ps[p++].y));
		if(!i)break;
		for(int j=1;j*j<=i;++j)if(i%j==0){
			as[j]+=sum(i+j-1);
			if(j*j!=i)as[i/j]+=sum(i+i/j-1);
		}
	}
	for(int i=1,s=0;i<=m;++i){
		as[i]+=s;
		s+=bs[i];
	}
	for(int i=1;i<=m;++i)printf("%d\n",n-as[i]);
	return 0;
}

Measured memory_bytes: 5504
A, B, C, X, Y = list(map(int, input().split(' ')))
x = X
y = Y
ans = 0
flag = True
if X > Y:
    flag = False
if A+B >= 2*C:
    if flag:
        ans += X * 2*C
        x -= X
        y -= X
    else:
        ans += Y * 2*C
        x -= Y
        y -= Y

ans += x*min(A, 2*C)
ans += y*min(B, 2*C)

print(ans)


Measured memory_bytes: 3188
// 1_2_C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CARDSIZE 2

typedef struct {
    char suit;
    int num;
} card_t;

void Swap(card_t *card1, card_t *card2){
    card_t tmp;
    tmp = *card1;
    *card1 = *card2;
    *card2 = tmp;
    return;
}

void SetCard(card_t *card, char input[]){
    card->suit = input[0];
    card->num = atoi(&input[1]);
    return;
}

void PrintCards(card_t cards[], int length){
    int i;
    for(i = 0; i < length; i++){
        printf("%c", cards[i].suit);
        printf("%d", cards[i].num);
        if(i == length - 1){
            printf("\n");
        } else {
            printf(" ");
        }
    }
    return;
}

card_t *BubbleSort(card_t *cards, int length){
    int i, flag = 1;
    while(flag){
        flag = 0;
        for(i = length - 1; i >= 1; i--){
            if(cards[i].num < cards[i-1].num){
                Swap(&cards[i], &cards[i-1]);
                flag = 1;
            }
        }
    }
    PrintCards(cards, length);
    return cards;
}

card_t *SelectionSort(card_t *cards, int length){
    int i, j, minj;
    for(i = 0; i < length; i++){
        minj = i;
        for(j = i; j < length; j++){
            if(cards[j].num < cards[minj].num) minj = j;
        }
        Swap(&cards[minj], &cards[i]);
    }
    PrintCards(cards, length);
    return cards;
}

int main(){
    int n, i;
    char input[CARDSIZE + 1];
    card_t *cards_bub, *cards_sel;
    scanf("%d", &n);

    cards_bub = (card_t *)malloc(sizeof(card_t) * n);
    cards_sel = (card_t *)malloc(sizeof(card_t) * n);

    for(i = 0; i < n; i++){
        scanf("%s", input);
        SetCard(&cards_bub[i], input);
    }
    memcpy(cards_sel, cards_bub, sizeof(card_t) * n);

    cards_bub = BubbleSort(cards_bub, n);
    printf("Stable\n");
    cards_sel = SelectionSort(cards_sel, n);
    if(memcmp(cards_bub, cards_sel, sizeof(card_t) * n) == 0){
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }

    free(cards_bub);
    free(cards_sel);
    return 0;
}

Measured memory_bytes: 636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, p[10100];
	while (scanf("%d", &n), n)
	{
		for (int i = 0; i < n; ++i)
			scanf("%d", p + i);

		int res = n;
		for (int i = 0; i < n; ++i)
		{
			for (int c = 1; c <= 3; ++c)
			{
				int low, high;
				low = i - 1, high = i + 1;
				int same = 1, color = c;
				int vanish = 0;
				while (true)
				{
					while (low >= 0 && p[low] == color)
						--low, ++same;
					while (high < n && p[high] == color)
						++high, ++same;

					if (same < 4)
						break;
					
					vanish += same;
					same = 0;
					color = p[low];
				}

				min_swap(res, n - vanish);
			}
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		if(n>=1 && n<=999) {
			System.out.println("ABC");
		}else if(n>999 && n<=1998) {
			System.out.println("ABD");
		}
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,a,b;
	string s;
	cin >> n >> a >> b >> s;
	int counta=0,countb=0;
	a+=b;
	rep(i,n){
		if(s[i]=='a'&&counta<a){
			puts("Yes");
			counta++;
		}else if(s[i]=='b'&&counta<a&&countb<b){
			puts("Yes");
			counta++;countb++;
		}else{
			puts("No");
		}
	}
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

bool isPallindrome(string s)
{
    rep(i, 0, s.size() / 2)
    {
        if (s[i] != s[s.size() - i - 1])
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string S;
    input(S);

    cout << ((isPallindrome(S) && isPallindrome(S.substr(0, (S.size() - 1) / 2)) && isPallindrome(S.substr((S.size() + 3) / 2 - 1))) ? "Yes" : "No") << endl;
    return 0;
}

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

int need(int current_score, int needed){
    
    int res = 0;
    while(current_score < needed){
        res += 1;
        current_score <<= 1;
    }
    
    return res;
    
}



double solve(int n, int k){
    
    double first_part = (1/(double)n);
    
    double total = 0;
    for(int i = 1; i <= n; i++){
        int heads_needed = need(i, k);
        double second_part = pow(0.5, heads_needed);
        total += second_part;
    }
    
    return first_part*total;
    
}




int main(){
    
    int n, k;
    cin >> n >> k;
    
    cout << setprecision(16) ;
    
    cout << solve(n, k) << endl;
    
    
}


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

int main() {
  string s; cin >> s;
  int K; cin >> K;
  
  vector<int> A(s.size());
  for (int i = 0; i < s.size(); i++) A[i] = ('z' - s[i] + 1) % 26;
  
  for (int i = 0; i < s.size(); i++) {
    if (K >= A[i]) {
      K -= A[i];
      s[i] = 'a';
    }
  }
  
  s[s.size()-1] = (char)(s[s.size()-1] + K % 26);
  
  cout << s << endl;
}

Measured memory_bytes: 1024
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: i32 = read();
    let a: Vec<i64> = read_vec();

    const MOD: i64 = 1000000007;
    let mut ans: i64 = 0;
    let mut sum: i64 = a[0];
    for i in 1..n {
        ans += a[i as usize] * sum;
        ans %= MOD;
        sum += a[i as usize];
        sum %= MOD;
    }
    println!("{}", ans);
}


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

typedef long long ll;
 
 
ll N, M;
 
inline ll read() {
	ll out = 0;
	bool flag = false;
	register char cc = getchar();
	while (cc < '0' || cc > '9') {
		if (cc == '-') flag = true;
		cc = getchar();
	}
	while (cc >= '0' && cc <= '9') {
		out = (out << 3) + (out << 1) + (cc ^ 48);
		cc = getchar();
	}
	return flag ? -out : out;
} 
 
inline void write(ll x) {
	if (x < 0) putchar('-'), x = -x;
	if (x == 0) putchar('0');
	else {
		int num = 0;
		char cc[20];
		while (x) cc[++num] = x % 10 + 48, x /= 10;
		while (num) putchar(cc[num--]);
	}
	putchar(' ');
}

int main() {
	N = read(), M = read();
	write(min(N % M, M - N % M));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
	int a, b;
  	cin >> a >> b;
  	if (b < a)
      cout << a - 1 << endl;
  	else
      cout << a << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();

        int[] a = new int[n];

        for(int i=0; i < n; i++){
            a[i] = sc.nextInt();
        }

        int sum = x;
        for(int i=0; i<n; i++){
            sum += ( d + a[i] - 1 ) / a[i];
        }
        System.out.println(sum);

    }
}

Measured memory_bytes: 23636
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

class BIT:
	def __init__(self, n):
		self.n = n
		self.nums = [0] * (n+1)
		
	def add(self, i, x):
		n, nums = self.n, self.nums
		i += 1
		while i <= n:
			nums[i] += x
			i += i & -i
	
	def sum(self, i):
		nums = self.nums
		s = 0
		i += 1
		while i:
			s += nums[i]
			i -= i & -i
		return s
	
	def search(self, x):
		n, nums = self.n, self.nums
		s, p = 0, 0
		for i in range(n.bit_length(), -1, -1):
			np = p + (1<<i)
			if np <= n and s+nums[np] < x:
				s += nums[np]
				p = np
		return p

N, M = rl()
S = rl()
T = rl()

h = defaultdict(list)
for i, t in enumerate(T):
	h[t].append(i)
bit = BIT(M+1)
for i, s in enumerate(S):
	vals = []
	for j in h[s]:
		vals.append((j, bit.sum(j)+1))
	for j, v in vals:
		bit.add(j+1, v%mod)
print((bit.sum(M)+1)%mod)


Measured memory_bytes: 95116
/*
A0506
 */

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

struct im {int runlen;char num;} interm[100000];
char buffer[100000];
char buffer2[100000];

void step1(char *b,struct im * imb)
{
  if(!*b)
    return;

  imb->runlen = 1;
  imb->num    = *b - '0';

  while(*++b)
    {  
      if(imb->num == (*b - '0'))
	{
	  imb->runlen++;
	}
      else
	{ imb++;
	  imb->runlen = 1;
	  imb->num = *b - '0';
	}
    }
  imb++;
  imb->runlen=0;
}

void step2(struct im * imb,char * b)
{
  char cnt;

  while(imb->runlen)
    {
      cnt=sprintf(b,"%d%d",imb->runlen,imb->num);
      b += cnt;
      imb++;
    }

}


int main()
{ 
  int times,i;
   
  while(EOF!=scanf("%d",&times) && times)
    {
      scanf("%s",buffer);

      for(i=0;i<times;i++)
	{
	  step1(buffer,interm);
	  step2(interm,buffer2);
	  strcpy(buffer,buffer2);
	}
      printf("%s\n",buffer2);
    }
  return(0);
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main() {
  string s;
  cin >> s;

  rep(i, 0, s.length() - 1) {
    if(s[i] == 'A' && s[i + 1] == 'C') {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}


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


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

 int total = 0;
 rep(i,m) total +=a[i];
 if(total>n) cout << -1 << endl;
 else cout << n-total << endl;
   }

Measured memory_bytes: 3644
#include <stdio.h>
int a[1000000],n;
int binarysearch(int key){
    int left=0;
    int right=n;
    int mid;
    while(left<right){
        mid=(left+right)/2;
        if(key==a[mid]) return 1;
        if(key>a[mid]) left=mid+1;
        else if(key<a[mid]) right=mid;
    }
    return 0;
}
int main() {
    int i,q,k,sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&k);
        if(binarysearch(k)) sum++;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 2236
import java.io.*;
import java.util.*;
public class Main {
public static void main (String[]args) {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try {
   
    int N = Integer.parseInt(br.readLine());
    String res = "";

    if((N%10 == 2)||(N%10 == 4)||(N%10 == 5)||(N%10 == 7)||(N%10 == 9)) {
        res = "hon";
    }
    else if((N%10 == 0) || (N%10 == 1) || (N%10 == 6) || (N%10==8)) {
        res = "pon";
    } 
    else{
        res = "bon";
    }
    System.out.println(res);
 


       
    }catch (Exception e) {
       }
       }
   }

Measured memory_bytes: 32360
import sys
from itertools import combinations
from collections import Counter
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    s = [input()[0] for _ in range(n)]
    s = [v for v in s if v in 'MARCH']
    c = Counter(s)
    ans = 0
    for x, y, z in combinations(c, 3):
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()


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

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, AC = 0, WA = 0, TLE = 0, RE = 0;
  string s;
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> s;
    if (s == "AC")
      AC++;
    else if (s == "WA")
      WA++;
    else if (s == "TLE")
      TLE++;
    else if (s == "RE")
      RE++;
  }
  cout << "AC x " << AC << '\n';
  cout << "WA x " << WA << '\n';
  cout << "TLE x " << TLE << '\n';
  cout << "RE x " << RE << '\n';
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
#define MAX 300001

int main (void){
	int p[MAX];
	p[0] = p[1] = 1;
	for(int i = 0; i < MAX; i++){
		if(i % 7 == 1 || i % 7 == 6){
			if(!p[i]){
				for(int j = 2 * i; j < MAX; j +=i){
					p[j] = 1;
				}
			}
		}
	}
	int n;
	while(true){
		cin >> n;
		if(n == 1)break;
		cout << n << ":";
		for(int i = 0; i <= n; i++){
			if(!p[i] && (i % 7 == 1 || i % 7 == 6) && n % i == 0){
				cout << " " << i;
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-13
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.9lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios::sync_with_stdio(false); cin.tie(0)
#define endl '\n'
ll d[104];
ll a[1003],b[1003],c[1003],v[1003];
vector<pll>x[1003];vector<ll>ver[103];
int main()
{
    sws;
   int n,m;
   cin>>n>>m;
   for(int i=1;i<=m;i++)
   {
       cin>>a[i]>>b[i]>>c[i];
       if(a[i]!=b[i]){x[a[i]].pb(mp(b[i],i));x[b[i]].pb(mp(a[i],i));}
   }
   set<pll>s;
   for(long i=1;i<=n;i++)
   {
       for(long j=1;j<=n;j++){d[j]=inf;ver[j].clear();}
       d[i]=0;
       s.clear();
       s.insert(mp(0,i));
       while(!s.empty())
       {
           ll t=s.begin()->FF;
           int p=s.begin()->SS;
           s.erase(s.begin());
           for(int j=0;j<ver[p].size();j++)v[ver[p][j]]=1;
           for(int j=0;j<x[p].size();j++)
           {
               int h=x[p][j].FF;
               int  w=x[p][j].SS;
                if(d[h]>d[p]+c[w])
                {
                    s.erase(mp(d[h],h));d[h]=d[p]+c[w];s.insert(mp(d[h],h));ver[h].clear();
                    if(v[w]==0){ver[h].pb(w);}
                }
                else
                {
                    if(d[h]==d[p]+c[w]&&v[w]==0)ver[h].pb(w);
                }

           }

        }
   }
   int ans=0;
    for(int i=1;i<=m;i++)if(v[i]==0){ans++;}
cout<<ans<<endl;




}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,m;
    cin >> n >> m;
    string s,t;
    cin >> s >> t;
    long g = __gcd(n,m);
    long a = n/g,b=m/g,flag = 0;
    for(long i=0;i<g;i++){
      if(s[a*i]!=t[b*i]){
        flag = 1;
        break;
      }
    }  
    if(flag) cout << -1 << endl;
    else cout << g*a*b << endl;
}


Measured memory_bytes: 512
N = int(input())

A = []
B = []
C = []

A = input().split()
A = [int(n) for n in A]

B = input().split()
B = [int(n) for n in B]

C = input().split()
C = [int(n) for n in C]

sati = 0

A.append(-100)

for i in range(N) :
  sati = sati + B[A[i] - 1] 
#  print(B[A[i]-1])
  if A[i + 1] == A[i] + 1 :
    sati = sati + C[A[i] - 1]
#    print(C[A[i]-1])

#print(N)
#print(A)
#print(B)
#print(C)
print(sati)

Measured memory_bytes: 3064
n = int(input())
S = list(map(int,input().split()))
if 0 in S:
    print(0)
else:
    i = 0
    m = 1
    while i < n:
        m = m*S[i]
        if m > 1000000000000000000:
            print(-1)
            break
        i += 1
    else:
        print(m)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> d(n);
	rep (i, n) cin >> d[i];
	int res = 0;
	rep (i, n) {
	  FOR (j, i + 1, n) res += d[i] * d[j];
	}
	cout << res << endl;
    
    return 0;
}



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

int main() {
  int n,ans;
  cin >> n;
  ans = n;
  vector<P>data(n);
  rep(i,0,n){
    int x,l;
    cin >> x >> l;
    data[i].second = x-l;
    data[i].first = x+l;
  }
  sort(data.begin(),data.end());
  ll r = data[0].first;
  rep(i,1,n){
    if(data[i].second < r) ans--;
    else r = data[i].first;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
object Main extends App{
    val n = scala.io.StdIn.readInt

    def check(n: Int): Boolean = {
        for (i <- 0 to n/4) {
            if ((n-4*i) % 7 == 0){
              return true
            }
        }
        return false
    }

    if (check(n)) println("Yes") else println("No")
}

Measured memory_bytes: 27212
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>

int is_equal(char a[],char b[]){
	for(int i=0;i<105;i++){
		if(a[i]<'a'||a[i]>'z')break;
		if(a[i]!=b[i])return 0;
	}
	return 1;
}

int main(){
	char s[105],t[105];
	scanf("%s %s",s,t);
	int num = strlen(s);

	for(int i=0;i<105;i++){
		int a = s[0];
		for(int i=1;i<num;i++){
			s[i-1]=s[i];
		}
		s[num-1]=a;
		if(is_equal(s,t)){
			printf("Yes");
			return 0;
		}
	}
	
	
	printf("No");	
	return 0;
}

Measured memory_bytes: 128
import heapq

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

L = A[:N]
heapq.heapify(L)
Lmax = [0] * (N + 1)
Lsum = sum(L)
Lmax[0] = Lsum
for i in range(N, 2 * N):
    m = heapq.heappushpop(L, A[i])
    Lsum += A[i] - m
    Lmax[i - N + 1] = Lsum

R = [-x for x in A[2 * N:]]
heapq.heapify(R)
Rmin = [0] * (N + 1)
Rsum = -sum(R)
Rmin[N] = Rsum
for i in range(2 * N - 1, N - 1, -1):
    M = -heapq.heappushpop(R, -A[i])
    Rsum -= M - A[i]
    Rmin[i - N] = Rsum

print(max(Lmax[i] - Rmin[i] for i in range(N + 1)))


Measured memory_bytes: 42788
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int r, g, b;
    cin >> r >> g >> b;
    
    int num = r * 100 + g * 10 + b;
    
    if ( num % 4  == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let mut a:String = read!();
    let vv:Vec<char> = a.chars().collect_vec();
    let mut v:Vec<usize> = Vec::new();
    for i in 0..vv.len() {
        if vv[i]=='0' {v.push(0) }
        if vv[i]=='1' {v.push(1) }
        if vv[i]=='2' {v.push(2) }
        if vv[i]=='3' {v.push(3) }
        if vv[i]=='4' {v.push(4) }
        if vv[i]=='5' {v.push(5) }
        if vv[i]=='6' {v.push(6) }
        if vv[i]=='7' {v.push(7) }
        if vv[i]=='8' {v.push(8) }
        if vv[i]=='9' {v.push(9) }
    }
    let mut s:usize = 0;
    for i in 0..1<<(v.len()-1) {
        let mut c:usize = 1;
        for j in 0..v.len() {
            s += c*v[v.len()-j-1];
            if (i>>j)%2==0 {
                c*=10;
            }
            else {
                c=1;
            }
        }
    }
    println!("{}",s);
}

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

int main(){
	int N, M;
	cin >> N >> M;
	int ans = 100*(N-M) + 1900*M;
	rep(i,M) ans *= 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
N,M = map(int,input().split())
SC = []
for _ in range(M):
    sc = list(map(int,input().split()))
    SC.append(sc)
#print(SC)

for num in range(1000):
    ans = True
    #znum = str(num).zfill(3)
    znum = str(num).zfill(N)
    #print(znum)
    for sc in SC:
        if znum[sc[0]-1] != str(sc[1]):
            ans = False
    if ans:
        if len(str(num)) == N:
            print(num)
            #print(znum)
            exit()
print(-1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define N (int)(1e5+7)
#define inf (int)(1e9+7)
#define INF (long long) (1e18+7)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int M = (int)(2e6 + 239);

void solve(){
    string s,x,xx;
    cin>>s>>xx;
    int n=(int)s.size();
    for(int i=0;i<n;i++){
        x+=xx[i];
    }
    //cout<<s<<' '<<x<<'\n';
    if(s.compare(x) == 0){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return;
}
 
int main(){
    fastio;
    solve();
    return 0;
}

Measured memory_bytes: 3620