akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 2000000

int size, A[MAX+1];
void maxHeapify(int);


  main(){
  int i;
  scanf("%d", &size);

  for ( i = 1; i <= size; i++ ) scanf("%d", &A[i]);
  
  for ( i = size/2; i >= 1; i-- ) maxHeapify(i);

  for ( i = 1; i <= size; i++ ) {

    printf(" %d", A[i]);

  }

  printf("\n");
  

  
  return 0;
}
void maxHeapify(int i){
  int l, r, largest, t;
  l = 2*i;
  r = 2*i+1;
  if ( l <= size && A[l] > A[i] ) largest = l;

  else largest = i;

  if ( r <= size && A[r] > A[largest] ) largest = r;

  if ( largest != i ){
    t = A[i];
    A[i] = A[largest];
    A[largest] = t;
    maxHeapify(largest);

  }

}

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

int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    int f=0;
    int mid=n/2;
    //cout<<s[mid];
     if(n%2==1)
         cout<<"No"<<endl;
         else{
    for(int i=0;i<mid;i++){
            if(s[i]==s[mid+i])
             f=1;
             else{
              f=0;
              break;
             }
        }
            if(f==1)
  	     cout<<"Yes"<<endl;
         	else
         	 cout<<"No"<<endl;
             
         }
    
    
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    int ans = a*(a-1)/2+b*(b-1)/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{	
	int a, b;
	int num;
	int count = 1;
	//int ans[100];
	//int i = 0;
	
	while(scanf("%d %d", &a, &b) != EOF){

		num = a + b;
		while(num >= 10){
			num /= 10;
			count++;
		}
		printf("%d\n", count);
		count = 1;
	}


	return 0;
}

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

int main(){

    int n,m;
    cin >> n >> m;

    vector<int> a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];

    vector<int> c(m),d(m);
    rep(i,m)cin >> c[i]>>d[i];

    rep(i,n){
        int x=c[0];
        int y=d[0];
        int t=1;
        rep(j,m){
            if(abs(a[i]-x)+abs(b[i]-y)>abs(a[i]-c[j])+abs(b[i]-d[j])){
                x=c[j];
                y=d[j];
                t=j+1;
            }
        }
        cout << t << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int s2n(string s){
	int l = (int)s.length();

	int res = 0;
	for (int i = l - 1; i >= 0; --i){
		res += (int)(s[i] == '1');
		res *= 2;
	} // end for

	return res;
}

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

	string S; cin >> S;

	int d = s2n(S);
	int res = __builtin_popcount(d);

	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    a87(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}


fun a87(args: Array<String>) {
    if (args.size != 3) {
        throw IllegalArgumentException()
    }
    val (x, a, b) = args.map { it.toInt() }
    println((x - a) % b)
}

Measured memory_bytes: 33868
using System;
using System.Linq;
class Program
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        Array.Sort(a);
        Array.Reverse(a);
        int al = 0, bo = 0;
        for (int i = 0; i < n; i++)
        {
            if (i % 2 == 0)
                al += a[i];
            else
                bo += a[i];
        }
        Console.WriteLine(al - bo);
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int a,b;
    cin >> a >> b;
    bool flag=false;
    int c;
    rep(i,100000){
        if(i*8/100==a&&i/10==b){
            c=i;
            flag=true;
            break;
        }
    }
    if(flag) cout << c << endl;
    else cout << -1 << endl;

}

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

int check(string str) 
{ 
    int n = str.length(); 
    int digitSum = 0; 
    for (int i=0; i<n; i++) 
        digitSum=(digitSum + (str[i]-'0'))%9; 
    return (digitSum % 9 == 0); 
} 


int main()
{
	string s;
	cin>>s;
	if(check(s))
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

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

ll memo[101][100001];
ll knapsack(int W, int n, int *wt, ll *val)
{
    ll &ans = memo[n][W];
    if (ans != -1)
        return ans;
    if (n == 0 || W == 0)
        return ans = 0;
    ans = knapsack(W, n - 1, wt, val);
    if (W >= wt[n - 1])
        ans = max(ans, val[n - 1] + knapsack(W - wt[n - 1], n - 1, wt, val));
    return ans;
}

int main()
{
    memset(memo, -1, sizeof memo);
    int n, w;
    cin >> n >> w;
    int wt[n];
    ll val[n];
    for (int i = 0; i < n; i++)
        cin >> wt[i] >> val[i];
    cout << knapsack(w, n, wt, val) << "\n";
    return 0;
}

Measured memory_bytes: 79104
import qualified Data.IntMap as M
import Data.Maybe

main = do
  li <- getLine
  let n = read li
  li <- getLine
  let as = map read $ words li
  let ans = compute n as
  print ans

{-
(i,j) (i<j) が j-i = Ai+Aj なら当たり。
それぞれのi,Aiに対して、この関係を満たすようなjの数が知りたい。
移項して j-Aj = i+Ai
Bi=i-Aiとおくと i+Ai = Bj 
jが無関係になるので、各i+Aiについて
そんなBjになるjの個数を先に集計しておいた個数を足すと答え
-}

compute :: Int -> [Int] -> Int
compute n as = sum [ fromMaybe 0 $ m M.!? (i+ai) | (i,ai) <- iai ] 
  where
    iai = zip [1..] as
    m = M.fromListWith (+) [ (j-aj,1) | (j,aj) <- iai ]

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

long long fact(int n);

int main()
{
	int n;

	scanf("%d", &n);

	printf("%lld\n", fact(n));

	return (0);
}

long long fact(int n)
{
	if (n == 0){
		return (1);
	}
	else {
		return (n * fact(n - 1));
	}
}

Measured memory_bytes: 1184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		String S = sc.next();

		String[] str = {"MON","TUE","WED","THU","FRI","SAT","SUN"};

		for(int i = 0;i<str.length;i++) {

			if(str[i].equals(S)) {

				if(i == 6) {
					System.out.println(7);
				}else {
					System.out.println(7-(i+1));
				}
			}

		}


	}

}


Measured memory_bytes: 22100
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  vi l(n);
  REP(i,n){
	  cin>>l[i];
  }
  sort(l.begin(), l.end());
  
  int sum=accumulate(l.begin(),l.end() ,0LL);
  if ((sum-l[n-1])>l[n-1]){
	  cout<<"Yes"<<endl;
  	  return 0;
  }else{
	  cout<<"No"<<endl;
  	  return 0;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456;
long long f[2][maxn];
int main(){
	f[0][0] = 0;
	f[1][0] = -(1ll<<60);
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		int x; cin >> x;
		f[0][i + 1] = max(f[0][i] + x, f[1][i] - x);
		f[1][i + 1] = max(f[0][i] - x, f[1][i] + x);
	}
	cout << f[0][n] << endl;
	return 0;
}



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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;g
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n, r;
    cin >> n >> r;

    cout << (n >= 10 ? r : r + 100 * (10 - n)) << endl;
}


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

int main() {
  long long n;
  cin>>n;
  long long kotae=INT_MAX;
  long long a,e,f;
  string c,d;
  for(long long i=sqrt(n);i>=1;--i){
    if(n%i==0){
      a=n/i;
      c=to_string(a);
      d=to_string(i);
      e=c.size();
      f=d.size();
      kotae=min(kotae,max(e,f));
    } 
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Locale;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);
    int AB = sc.nextInt();
    int BC = sc.nextInt();
    int CA = sc.nextInt();

    System.out.println(AB * BC / 2);
  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }





void solve() {
    int n, m, q;
    cin >> n >> m >> q;
    
    vector<vector<int> > table(n + 1, vector<int>(n + 1));
    rep(i, m) {
        int l, r;
        cin >> l >> r;
        table[l][r]++;
    }
    
    rep3(i, 1, n + 1) rep(j, n + 1) table[i][j] += table[i - 1][j];
    rep3(j, 1, n + 1) rep(i, n + 1) table[i][j] += table[i][j - 1];
    // rep(i, n + 1) { rep(j, n + 1) cout << table[i][j] << " "; cout << endl; }
    
    rep(i, q) {
        int p, q;
        cin >> p >> q;
        if (p > q) swap(p, q);
        cout << table[q][q] - table[p - 1][q] - table[q][p - 1] + table[p - 1][p - 1] << endl;
    }
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}





Measured memory_bytes: 1920
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	K, A, B := nextInt(), nextInt(), nextInt()
	ans := "NG"
	if B%K == 0 || B%K <= B-A {
		ans = "OK"
	}
	fmt.Println(ans)

}


Measured memory_bytes: 1760
import java.util.Scanner;
import java.util.stream.IntStream;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] a = IntStream.range(0,N).map(i->scan.nextInt()).toArray();
        int[] b = IntStream.range(0,N).map(i->scan.nextInt()).toArray();
        long rev = 0;
        long need=0;
        for(int i=0;i<N;++i){
            if(b[i]>a[i])rev += ((long)b[i]-a[i])/2;
            if(a[i]>b[i])need += ((long)a[i]-b[i]);
        }
        System.out.println((rev>=need ? "Yes":"No"));
    }
}

Measured memory_bytes: 45136
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

int main(){
	int n, m, a;
	while (cin >> n >> m >> a, n){
		vector<pair<int, pair<int, int> > > horizon;
		for (int i = 0; i < m; i++){
			int h, p, q;
			cin >> h >> p >> q;
			horizon.push_back(make_pair(h, make_pair(p, q)));
		}
		sort(horizon.begin(), horizon.end(), greater<pair<int, pair<int, int> > >());
		for (int unsigned i = 0; i < horizon.size(); i++){
			if (horizon[i].second.first == a){
				a = horizon[i].second.second;
			} else if (horizon[i].second.second == a){
				a = horizon[i].second.first;
			}
		}
		cout << a << endl;
	}
	return 0;
}

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

const ll mod = 1e9 + 7;
ll dp[2020];

int main() {
	ll s;
    cin >> s;
    dp[0] = 1;
    for (int i = 0; i < 2020; ++i) {
        for (int k = 3; k < 2020; ++k) {
            if(i + k < 2020) {
                dp[i + k] += dp[i];
                dp[i + k] %= mod;
            }
        }
    }
    cout << dp[s] << endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> p(m);
	vector<string> s(m);
	vector<int> ac(n);
	vector<int> wa(n);
	int a, w;
	rep(i, m) {
		cin >> p[i] >> s[i];
		if (s[i] == "AC") ac[p[i] - 1]++;
      else if(ac[p[i]-1]==0){
        wa[p[i]-1]++;w++;
      }
	}
	rep(i, n) {
		if (ac[i]) a++;
      else w-=wa[i];
	}
	cout << a << " " << w << endl;
}

Measured memory_bytes: 6912
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Graph{
	private:
	int V;
	public:
	vvl d;
	Graph(int v){
		V=v;
		d=vvl(v,vl(v,INF));
		for(int i=0;i<v;i++) d[i][i]=0;
	}
	void add_edge(int s,int t,int c){
		d[s][t]=c;
		d[t][s]=c;
	}
	void solve(){
		for(int k=0;k<V;k++) for(int i=0;i<V;i++) for(int j=0;j<V;j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	}
};

int n,m,r;

int main(){
	while(1){
		cin>>n>>m;
		if(!n) break;
		Graph g(n),G(n);
		for(int i=0;i<m;i++){
			int s,t,cost;
			char c;
			cin>>s>>t>>cost>>c;
			s--;t--;
			if(c=='L') g.add_edge(s,t,cost);
			else G.add_edge(s,t,cost);
		}
		g.solve();
		G.solve();
		vl dp(n,INF);
		int v,u;
		cin>>r>>v;
		v--;
		dp[v]=0;
		u=v;
		for(int i=1;i<r;i++){
			cin>>v;
			v--;
			vl DP(n,INF);
			for(int j=0;j<n;j++){
				DP[j]=dp[j]+g.d[u][v];
				for(int k=0;k<n;k++) DP[j]=min(DP[j],dp[k]+g.d[u][k]+G.d[k][j]+g.d[j][v]);
			}
			dp=DP;
			u=v;
		}
		ll res=INF;
		for(int i=0;i<n;i++) res=min(res,dp[i]);
		cout<<res<<endl;
	}
}

Measured memory_bytes: 3348
#include <stdio.h>

int dp[501][501];
int grid[501][501];

int dpdo(int left, int right){
    if(dp[left][right]!=-1) return dp[left][right];
    if(left==right){
        dp[left][right] = grid[left][right];
        return dp[left][right];
    }
    if(right-left==1){
        dp[left][right] = dpdo(left, right-1) + dpdo(left+1, right) + grid[left][right];
        return dpdo(left, right);
    }
    else{
        dp[left][right] = dpdo(left, right-1) + dpdo(left+1, right) + grid[left][right] - dpdo(left+1, right-1);
        return dp[left][right];
    }
}

int main()
{
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);
    
    int i, j, k;
    
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            dp[i][j] = -1;
            grid[i][j] = 0;
        }
    }
    
    int l, r;
    for(i=1;i<=m;i++){
        scanf("%d%d", &l, &r);
        grid[l][r]++;
    }
    
    dpdo(1,n);
    
    int left, right;
    for(i=1;i<=q;i++){
        scanf("%d%d", &left, &right);
        printf("%d\n", dp[left][right]);
    }
    
    return 0;
}

Measured memory_bytes: 2816
N=int(input())
dam_waters = tuple(map(int,input().split()))

rain_falls=[0 for _ in range(N)]
rain_falls[0] = sum(dam_waters[i]*(1-(i%2)*2) for i in range(N))
for i in range(1,N):
    rain_falls[i]=(dam_waters[i-1] - rain_falls[i-1]//2)*2

print(*rain_falls)

Measured memory_bytes: 14156
/*
 *  Author : Jun_SH
 *  Solution for sumitrust2019 146 D
 */
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
    int f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
int a[3];
main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    int n;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<=999;++i){
        int tmp=i;
        for(int j=0;j<3;++j){
            a[j]=(tmp%10);
            tmp/=10;
        }
        int pos=2;
        for(int j=0;s[j]&&pos!=-1;++j){
            if(s[j]-'0'==a[pos])pos--;
        }
        if(pos==-1)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll K = 0;
	//ll T = 0;
	//ll M = 0;
	ll h[1000] = {};
	ll b[100] = {};
	//ll c[100] = {};
	//ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	string S,T,U[52];
	ll count = 0;
	ll count2 = 0;
	float sum = 0;
	ll min = 1000000000000;
	ll max = 0;
	ll smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	//int flag = 0;
	char temp,head;
	//int is = 0;
	bool flag = false;
	
	//char p;


	

	

	//cin >> S;
	
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(50);
	
	cin >> N >> K;
	
	vector<int> ch(N);


	rep(i, 0, N) {
		cin >> ch[i];
	}

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

	rep(i, 0, N-K+1) {
		
		count = ch[i+(K-1)] - ch[i];

		//cout << ch[i+K-1] <<","<<ch[i] << "," << count << endl;

			if (count < min)
				min = count;

		
	}

	

	
		cout << min << endl;

	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	
	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	//cin >> N >> M;

	//vector<pair<int,int>> c(M);
	////vector<pair<int, int>> e(M);
	//vector<ll> d(M);

	//rep(i, 0, M) {
	//	cin >> c[i].first >> c[i].second;
	//	//e[i].first = c[i].first;
	//	//e[i].second = c[i].second;

	//}
	////sort(c.begin(), c.end());

	//

	//rep(i, 0, M) {

	//	
	//	
	//	rep(j, 0, M) {
	//		if (c[i].first == c[j].first && c[j].second < c[i].second) {
	//			d[i]++;
	//			//cout << j << endl;
	//		}
	//	}
	//	cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
	//	cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 << endl;
	//}

	return 0;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}



Measured memory_bytes: 640
# coding: utf-8
# 整数の入力
#a = int(raw_input())
# スペース区切りの整数の入力
import heapq
N = int(input())

Rmax = 0
Rmin = 1000000001
Bmax = 0
Bmin = 1000000001

data = sorted([sorted(list(map(int, input().split()))) for i in range(N)],key=lambda x:x[0])

tempBlues = sorted([d[1] for d in data])
tempReds = [d[0] for d in data]
heapq.heapify(tempReds)

Rmin = data[0][0]
Rmax = data[N-1][0]
Bmax = max(tempBlues)
Bmin = min(tempBlues)

minValue = (Rmax - Rmin)*(Bmax - Bmin)
Bmin = Rmin

for i in range(N):
    heapMin = heapq.heappop(tempReds)
    if heapMin == data[i][0]:
        heapq.heappush(tempReds, data[i][1])
        if  data[i][1] > Rmax:
            Rmax = data[i][1]
        if (Rmax - tempReds[0])*(Bmax - Bmin) < minValue:
            minValue = (Rmax - tempReds[0])*(Bmax - Bmin)
    else:
        break

print(minValue)

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

#define  __  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define  int  long long
#define  endl  '\n'
const double pi = acos(-1);
const int mod = 1e9 + 7;
//______________________

const int N = 1e5+5;
bool vis[N];
int col[N];

vector<pair<int,int> > adj[N];

void dfs(int v,int c=0)
{
  vis[v]=1;
  col[v]=c;

  for(auto it: adj[v])
  {
    if(vis[it.first]) continue;

    if(it.second & 1)
      dfs(it.first,c^1);
    else
      dfs(it.first, c);
  }
}

int32_t main()
{ 
  __
 
  
  
  int n;
  cin>>n;

  for(int i=1;i<n;i++)
  {
    int x,y,w;
    cin>>x>>y>>w;
    adj[x].push_back({y,w});
    adj[y].push_back({x,w});
  }
  
  dfs(1);

  for(int i=1;i<=n;i++)
    cout<<col[i]<<endl;
 return 0;
}

Measured memory_bytes: 10240
#include <stdio.h>

int main(void)
{  
    long long N, A, B, t;

    scanf("%lld %lld %lld", &N, &A, &B);

    while(N > (A+B) && A != 0) {
        t = N / (A+B);
        N = N%(A+B);
    }

    if(N <= A) {
        printf("%lld\n", t*A+N);
    } else {
        printf("%lld\n", t*A+A);
    }

    return 0;
}

Measured memory_bytes: 1732
#include <iostream>

int main(){
    int n, a, b, c, d, p;

    while(std::cin >> n){
        p = 0;
        for(a=0; a<10; a++){
            for(b=0; b<10; b++){
                for(c=0; c<10; c++){
                    for(d=0; d<10; d++){
                        if(a + b + c + d == n){
                            p++;
                        }
                    }
                }
            }
        }
        std::cout << p << std::endl;
    }
}

Measured memory_bytes: 1160
function solve(i,m){
   if(m==0)return true;
   if(i>=n)return false;
   return solve(i+1,m) || solve(i+1,m-A[i]);
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
var A=(Arr.shift()).split(" ").map(Number);
var m=Arr.shift()-0;
var M=(Arr.shift()).split(" ").map(Number);
for(var i=0;i<m;i++){
   var ans=(solve(0,M[i]))?"yes":"no";
   console.log(ans);
}

Measured memory_bytes: 8848
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a, b;
  cin >> a >> b;
  if ((a*b)%2==0) cout << "Even" << endl;
  else cout << "Odd" << endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n,k = LI()
    a = LI()
    dp = [0 for i in range(k+1)]
    f = [0 for i in range(k+1)]
    for i in range(k+1):
        if not f[i]:
            for j in a:
                if i-j >= 0:
                    dp[i] = 1-dp[i-j]
                    if dp[i] == 0:
                        break
            else:
                dp[i] = 1
    print(["First","Second"][dp[k]])
#B
def B():
    n = I()
    a = LI()
    ma = n*(n+1)//2
    su = sum(a)
    s = [1 for i in range(n+1)]
    for i in range(1,n):
        s[i+1] = s[i]+n-i+1
    d = [None for i in range(ma+1)]
    d[0] = 0
    k = 1
    for i in range(1,n+1):
        for j in range(n+1-i):
            d[k+j] = i
        k += n+1-i
    k = n%2
    dp = [su if (d[i]+k)%2 else -su for i in range(ma+1)]
    dp[0] = 0
    if k:
        for i in range(n):
            dp[i+1] = a[n-1-i]
    else:
        for i in range(n):
            dp[i+1] = -a[n-1-i]
    for i in range(1,ma):
        r = n-1-(i-s[d[i]])
        l = r+1-d[i]
        j = i+(n-d[i])
        j2 = j+1
        if (d[i]+k)%2:
            if r < n-1:
                if a[r+1]+dp[i] > dp[j]:
                    dp[j] = a[r+1]+dp[i]
            if l > 0:
                if a[l-1]+dp[i] > dp[j2]:
                    dp[j2] = a[l-1]+dp[i]
        else:
            if r < n-1:
                if -a[r+1]+dp[i] < dp[j]:
                    dp[j] = -a[r+1]+dp[i]
            if l > 0:
                if -a[l-1]+dp[i] < dp[j2]:
                    dp[j2] = -a[l-1]+dp[i]
    print(dp[ma])
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 256860
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    fun f(X: Int): Int {
        return X.toString().map { it.toString().toInt() }.sum()
    }
    println(if (N % f(N) == 0) "Yes" else "No")
}

Measured memory_bytes: 35416
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

struct Main {}

impl Main {}

fn gcd_3(a: u64, b: u64, c: u64) -> u64 {
    gcd(a, gcd(b, c))
}

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let k: u64 = read();
    let mut sum = 0;
    for i in 1..k + 1 {
        for j in 1..k + 1 {
            for l in 1..k + 1 {
                sum += gcd_3(i, j, l)
            }
        }
    }
    println!("{}", sum);
}


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

int main() {
	int n;
	cin >> n;
	long numbers[n], i =0;
	while(cin >> numbers[i]) i++;
	long max = numbers[0], min = numbers[0], sigma = 0;
	for(i = 0; i < sizeof(numbers) / sizeof(numbers[0]); i++){
		if (numbers[i] > max) max = numbers[i];
		if (numbers[i] < min) min = numbers[i];
		sigma += numbers[i];
	}
	cout << min << " " << max << " " << sigma << endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  ll N, M, Q;
  cin >> N >> M >> Q;
  vector<ll> L(M), R(M), p(Q), q(Q);
  rep(i, M){
    cin >> L.at(i) >> R.at(i);
  }
  rep(i, Q){
    cin >> p.at(i) >> q.at(i);
  }
  vector<vector<ll>> d(N+1, vector<ll>(N+1, 0));
  // d.at(i).at(j)は都市iから出発してjで運行を終える列車の数
  rep(j, M){
    d.at(L.at(j)).at(R.at(j))++;
  }
  vector<vector<ll>> s(N+1, vector<ll>(N+1, 0));
  // s.at(i).at(j)は都市iから出発してjまでに運行を終える列車の数
  rep(i, N){
    rep(j, N){
      s.at(i+1).at(j+1) = s.at(i+1).at(j) + d.at(i+1).at(j+1);
    }
  }
  rep(i, Q){
    ll ans = 0;
    rep2(j, p.at(i), q.at(i)+1){
      ans += s.at(j).at(q.at(i));
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int MOD = 1e9 + 7;
 
ll x[100001];
ll y[100001];
 
ll mult(ll a, ll b)
{
	return (a*b)%MOD;
}
 
ll add(ll a, ll b)
{
	return (a+b)%MOD;
}
 
ll a[100001];
ll b[100001];
 
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m;cin>>n>>m;
	for(int i=0;i<n;i++) cin>>x[i];
	for(int i=0;i<m;i++) cin>>y[i];
	for(int i=0;i+1<n;i++) a[i]=x[i+1]-x[i];
	for(int i=0;i+1<m;i++) b[i]=y[i+1]-y[i];
	n--; m--;
	ll ans1 = 0;
	ll ans2 = 0;
	for(int i = 0; i < n; i++)
	{
		ans1 = add(ans1,mult(i+1,mult(n-i,a[i])));
	}
	for(int i = 0; i < m; i++)
	{
		ans2 = add(ans2,mult(i+1,mult(m-i,b[i])));
	}
	cout<<mult(ans1,ans2)<<'\n';
}

Measured memory_bytes: 3456
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
int A[MAX],B[MAX];

int main(){
   int C[VMAX+1];
   int n,i,j;
   scanf("%d",&n);

   for(i=0;i<=VMAX;i++) C[i]=0;

   for(i=0;i<n;i++) {
      scanf("%d",&A[i+1]);
      C[A[i+1]]++;
   }

   for(i=1;i<=VMAX;i++) C[i]=C[i]+C[i-1];

   for(j=1;j<=n;j++){
      B[C[A[j]]] =A[j];
      C[A[j]]--;
   }

   for(i=1;i<=n;i++){
      if(i>1) printf(" ");
      printf("%d",B[i]);
   }
   printf("\n");

   return 0;
}

Measured memory_bytes: 16264
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define Q int q; cin >> q; while (q--)
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    set<int> a;
    REP(i, n) {
        int x; cin >> x;
        a.emplace(x);
    }
    int m;
    cin >> m;
    set<int> b;
    REP(i, m) {
        int x; cin >> x;
        b.emplace(x);
    }
    set<int> c;
    set_symmetric_difference(ALL(a), ALL(b), inserter(c, end(c)));

    for (auto x : c) cout << x << endl;
}



Measured memory_bytes: 40636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

// swap(a,b);
// abs(a,b); a,bの型は問わない
// reverse(a+I,a+r); aは配列,a[i]からa[r-1]までを逆順にする.計算量はN. reverse(str.begin(),str.end());
// sortも上とあまり変わらない.
// ただし,sort(a,a+N,greater<int>());で大きい順にならべかえる.
// stack<int> a; 宣言 上に積み上げたものをとったり、一番上に積み上げる.
// a.push(x); aに要素xをつむ a.pop(); a.size(); a.empty(); これはtrue or false
// a.top;で一番上の要素を返す
// queue<int> a; a.front();
// priority_queue<int,vector<int>,greater<int>> Q1; 最も小さい奴を取り出す
// priority_queue<double,vector<double>,less<double>> Q2;最も大きい値を取り出す
// Q1.top();ができる
// count(a+l,a+r,x);
// find(a+l,a+r,x);
// 文字変換
//char a='a';
//a=a+1;
//cout<<a<<endl;

const long long INF = 1LL<<60;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];

    vector<long long> dp(H+1, INF);
    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= H; ++j) {
            chmin(dp[min(j+A[i], H)], dp[j] + B[i]);
        }
    }
    cout << dp[H] << endl;
}

Measured memory_bytes: 384
n=int(input())
s=list(input())
L=[]
R=[]
ans=0
import collections
for i in range(n):
  if s[i] not in L:
    for j in range(i+1,n):
      if s[j] not in R:
        if len(s[j+1:]) < 1:
          break
        c = collections.Counter(s[j+1:])
        c=c.most_common()
        
        ans += len(c)
        R.append(s[j])
       
    R=[]
    L.append(s[i])
print(ans)
    

Measured memory_bytes: 3828
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
ll INF = 1e6;

void solve()
{
    ll n;
    cin>>n;
    if(n%10==7 || (n/10)%10==7 || (n/100)==7)
        cout<<"Yes";
    else
    cout<<"No";
}

 
int main()
{
    SPEED;
    ll t = 1;
    //cin>>t;
    while(t--) solve();
   return 0;
}


Measured memory_bytes: 3640
use std::io::{ stdin, BufRead };

fn itp1_1_b<R>(input: &mut R) -> String
  where R: BufRead
{
  let mut f = my::AsciiReader::new(input, 8);
  let ans = f.read_int_until_lf::<u32>().pow(3);
  format!("{}\n", ans)
}

fn main() {
  let stdin = stdin();
  print!("{}", itp1_1_b(&mut stdin.lock()));
}

mod my {
  use std::io::BufRead;
  use std::fmt::Debug;
  use std::ops::{ Add, Sub, Mul };

  const SP: u8 = b' ';
  const LF: u8 = b'\n';

  #[derive(Debug)]
  pub struct AsciiReader<R> {
    input : R,
    buf   : Vec<u8>,
  }

  impl<R> AsciiReader<R>
    where R: BufRead
  {
    #[allow(dead_code)]
    pub fn new(input: R, capa: usize) -> Self {
      AsciiReader {
        input : input,
        buf   : Vec::with_capacity(capa),
      }
    }

    fn read_until(&mut self, delim: u8) -> usize {
      self.buf.clear();
      self.input.read_until(delim, &mut self.buf).unwrap()
    }

    // ignore sign(+-) uint only
    fn parse_int<T>(&self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let len = self.buf.len();
      let mut i = 0;
      let mut n = T::default();

      while i < len && b'0' <= self.buf[i] && self.buf[i] <= b'9' {
        n = (n * T::from(10)) + T::from(self.buf[i] - b'0');
        i += 1;
      }
      n
    }

    #[allow(dead_code)]
    pub fn read_int_until_delim<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_until(delim);
      self.parse_int()
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_int_until_lf<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_int_until_delim(LF)
    }
  }
}



Measured memory_bytes: 5012
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set> 
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)


 
int main(){
  int n;
  cin >> n;
  vector<vector<ll>> dist(n,vector<ll> (n,0));
  vector<vector<ll>> dist2(n,vector<ll> (n,0));

  rep(i,n) rep(j,n) {
    cin >> dist[i][j];
    dist2[i][j] = dist[i][j];
  }
  for (int i = 0; i < n;i++){
    for (int j = 0; j < n;j++){
      for (int k = 0; k < n; k++){
        dist[j][k] = min(dist[j][k],dist[j][i] +dist[i][k]); 
      }
    }
  }
  ll ans = 0LL;
  for (int i = 0; i < n;i++){
    for (int j = 0; j < n; j++){
      if (dist[i][j] == dist2[i][j]){
        bool cut = false;
        for (int k = 0; k < n; k++){
          if (dist[i][j] == dist[i][k]+dist[k][j] && k != i && k != j){
            cut = true;
          }
        }
        if (!cut) ans+=(ll)dist[i][j];
      }
      else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << ans/2 << endl;


  return 0; 
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,min,s,c=0;
    vector<int> v;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s;
        v.push_back(s);
    }
    for(int i=0;i<n;i++){
        min=i;
        for(int j=i+1;j<n;j++){
            if(v[j]<v[min]){
                min=j;
            }
        }
        swap(v[i],v[min]);
        if(i!=min)c++;
    }
    for(int i=0;i<n;i++){
        cout << v[i] << ((i==n-1)?"":" ") ;
    }
    cout<<endl<<c<<endl;
}

Measured memory_bytes: 3112
import sys

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

if B == 1:
    print(0)
    sys.exit()

sum = A
count = 1
if sum >= B:
    print(1)
else:
    while(True):
        sum += (A - 1)
        count += 1
        if sum >= B:
            break;
    print(count)


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<ll, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

const int M = 25000;
int A[M];
int B[M];

int main(){
    fastIO;
    int n;
    cin >> n;
    for(int i = 1; i <= n ; i ++ ){
        A[i] = M * i;
        B[i] = M * (n - i + 1);
    }
    int p;
    for(int i = 1; i <= n; i ++ ){
        cin >> p;
        A[p] += i;
    }
    for(int i = 1; i <= n ; i ++ )
        cout << A[i] << " ";
    cout << "\n";
    for(int i = 1; i <= n ; i ++ )
        cout << B[i] << " ";
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    string s;
    cin>>s;
    
    int n=s.size();
    int ans=INF;

    for(char x='a';x<='z';x++){
        bool ok=false;
        rep(i,n){
            if(s[i]==x) ok=true;
        }
        if(!ok) continue;
        int ma=0,tmp=0;
        rep(i,n){
            if(s[i]==x){
                ma=max(ma,tmp);
                tmp=0;
            }
            else tmp++;
        }
        ma=max(ma,tmp);
        //cout<<x<<" "<<ma<<endl;
        ans=min(ans,ma);
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let s: String = read().unwrap();
    if s.contains("7") {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 2168
N=int(input())
S=[input() for _ in range(N)]
march=list('MARCH')
nam=[[] for _ in range(len(march))]
for s in S:
    if s[0] in march:
        nam[march.index(s[0])].append(s)
ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=len(nam[i])*len(nam[j])*len(nam[k])
print(ans)

Measured memory_bytes: 10900
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int d,n;
  cin>>d>>n;
  ll ans=1;
  while(d>0){
    ans*=100;
    d--;
  }
  int z=n;
  int y=z/100;
  ans*=(n+y);
  cout<<ans<<endl;
}

Measured memory_bytes: 3580
#
from collections import Counter

k = input()
p = input()
d = len(k)
f = len(p)
g=""
diff = abs(d-f)

if d>f :
     d = d-diff
     g = k[d:len(k)]
   
else:
    f = f-diff
    g=p[f:len(p)]


r=""
i = 0
for i in range(d):
    r += "".join(k[i]+p[i])
    #print(r)
    
print(r+g)

Measured memory_bytes: 3316
// 再提出3
// 12/19 AIZU ONLINE ALDS1 10_C
// Longest Common Subsequence
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
int edit_distance(const string& s1, const string& s2)
{
    int n= s1.size(), m= s2.size();
    vector<vector<int>> d(n+1, vector<int>(m+1,0));

    REP(i,n+1) d[i][0]= i;
    REP(i,m+1) d[0][i]= i;
    FOR(i,1,n+1){
        FOR(j,1,m+1){
            d[i][j]= min(d[i-1][j-1]+(s1[i-1]==s2[j-1]?0:1), min(d[i-1][j], d[i][j-1]) +1);
        }
    }
    return d[n][m];
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;
    int ans= edit_distance(s1,s2);
    
    cout << ans << endl;
}



Measured memory_bytes: 6848
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>

using namespace std;

int main(void){
    int N,M;
    cin>>N;
    cin>>M;

    vector<pair<long long,int>> AB(N);

    for(int i=0;i<N;i++){
        cin>>AB[i].first;
        cin>>AB[i].second;
    }

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

    long long ans=0;

    for(int i=0;i<N;i++){
        if(AB[i].second<M){
            ans+=AB[i].first*(long long)AB[i].second;
        }else{
            ans+=AB[i].first*(long long)M;
        }
        M-=AB[i].second;
        if(M<=0){
            break;
        }
    }

    cout<<ans<<endl;

    return 0;
}

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

const int MAXN = 110;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int n, a[MAXN], b[MAXN];
int sa[MAXN], sb[MAXN], ans;

int main() {

	int i;
	n = read();
	generate(a+1, a+n+1, read);
	generate(b+1, b+n+1, read);
	for(i = 1; i <= n; i++) sa[i] = sa[i-1]+a[i];
	for(i = n; i >= 1; i--) sb[i] = sb[i+1]+b[i];

	for(i = 1; i <= n; i++) ans = max(ans, sa[i]+sb[i]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

main = do
  s <- getLine

  let countABC [] a b c = (a, b, c)
      countABC (x:xs) a b c | x == 'a' = countABC xs (a+1) b c
                            | x == 'b' = countABC xs a (b+1) c
                            | x == 'c' = countABC xs a b (c+1)

      (na, nb, nc) = countABC s 0 0 0

      mn = min na (min nb nc)

      (na', nb', nc') = (na - mn, nb -mn, nc - mn)

      ans = if na' <= 1 && nb' <= 1 && nc' <= 1
            then "YES"
            else "NO"

  putStrLn ans

Measured memory_bytes: 8572
n = int(input())
L = list(map(int,input().split()))
L = sorted(L)
ans = 0
if n >= 3:
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                if L[i] == L[j] or L[j] == L[k] or L[i] == L[k]:
                    pass
                else:
                    if L[i] + L[j] > L[k]:
                        if L[j] + L[k] > L[i]:
                            if L[i] + L[k] > L[j]:
                                ans += 1
            
print(ans)

Measured memory_bytes: 9212
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()

    cnt = collections.Counter(S)
    n = cnt['N']
    w = cnt['W']
    s = cnt['S']
    e = cnt['E']
    if (n > 0 and s > 0 or n == s == 0) and (w > 0 and e > 0 or w == e == 0):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9964