akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int[] A = new int[N];

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

    sc.close();

    int[] L = new int[N+1];
    int[] R = new int[N+1];
    
    L[0] = A[0];
    R[N] = A[N-1];

    for (int i = 1; i < N; i++) {
      L[i] = gcd(L[i-1], A[i]);
    }

    for (int i = N - 1; 0 < i; i--) {
      R[i] = gcd(A[i-1],R[i+1]);
    }

    int[] M = new int[N+1];

    for (int i = 1; i <= N; i++) {
      if (i == 1) {
        M[i] = R[i+1];
      } else if(i == N){
        M[i] = L[i-2];
      } else {
        M[i] = gcd(L[i-2],R[i+1]);
      }
      
    }

    int max = 0;

    for (int i = 1; i < N+1; i++) {
      max = Math.max(M[i],max);
    }    
    
    System.out.println(max);
 
  }

  public static int gcd(int x, int y){

    if (x < y) {
      int t = x;
      x = y;
      y = t;
    }

    while (y > 0) {
      int r = x % y;
      x = y;
      y = r;
    }

    return x;
    
  }

}

Measured memory_bytes: 50256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using Int = int64_t;
using P = pair<Int, Int>;
const Int INF = 1<<30;
const Int MOD = (Int)1e9 + 7;
const Int MAX_N = (Int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
#define debug2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int d, t, s;
    cin >> d >> t >> s;
    if(d <= s * t)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

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


Measured memory_bytes: 3608
#include <stdio.h>

int main()
{
    int a[5] = {0},k=0,i=0,j=0,l=0;
    scanf("%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&k);

    for(i=0; i<5; i++)
    {

            for(j=i; j>=0; j--)
            {

                if(j!=i)
                {

                    if((a[i]-a[j]>k))
                    {

                        l=1;
                        continue;
                    }
                }

            }


    }
    if(l==0)
    {
        printf("Yay!\n");
    }
    else if (l==1)
    {
        printf(":(\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)

using namespace std;

int main(){
    
    int a,b,g=0;
    long double t=0;
    cin>>a>>b;
    vector<int> v(a);
    rep(i,a) {cin>>v[i];t+=v[i];}
    t/=(4*b);
    rep(i,a){
        if(v[i]>=t) g++;
    }
    if(g>=b) cout<<"Yes";
    else cout<<"No";
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn = 2e5 + 10;
char T[maxn], D[maxn];
char s[maxn];
int n, q;
bool vis[maxn];

int check(int x) {
    for (int i = 1; i <= q; i++) {
        if (s[x] == T[i]) {
            x += (D[i] == 'L' ? -1 : 1);
            if (x < 1) return 1;
            if (x > n) return 2;
        }
    }
    return 0;
}

int main() {
    scanf("%d%d%s", &n, &q, s + 1);
    char str[10];
    for (int i = 1; i <= q; i++) scanf("%s", str), T[i] = str[0], scanf("%s", str), D[i] = str[0];
    int posr = n + 1, posl = 0;
    int l = 1, r = n;
    while (l <= r) {
        int mid = l + r >> 1;
        if (check(mid) == 1) l = mid + 1, posl = mid;
        else r = mid - 1; 
    }
    for (int i = 1; i <= posl; i++) vis[i] = true;
    l = 1, r = n;
    while (l <= r) {
        int mid = l + r >> 1;
        if (check(mid) == 2) r = mid - 1, posr = mid;
        else l = mid + 1;
    }
    for (int i = posr; i <= n; i++) vis[i] = true;
    int ans = 0;
    for (int i = 1; i <= n; i++) 
        ans += !vis[i];
    printf("%d\n", ans);
    return 0;
}

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

char s[10];
int N, k;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
	}
	cin >> k;

	for (int i = 0; i < N; i++) {
		if (s[i] != s[k - 1]) {
			cout<<'*';
		}
		else {
			cout << s[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 10101010;

const int E = 1<<4;
const int N = 100;
const int R = 101;

int d[E][N][R];
int event[N];
vector<int> G[E][N];

struct state{
    int mask, pos, day;
};

int main(){
    int n,m,e,s,t,r;
    cin >>n >>m >>e >>s >>t >>r;

    rep(i,m){
        int a,b;
        scanf(" %d %d", &a, &b);
        rep(j,1<<e){
            G[j][a].pb(b);
            G[j][b].pb(a);
        }
    }

    int smask = 0;
    fill(event, event+N, -1);
    rep(i,e){
        int a,b,c;
        scanf(" %d %d %d", &a, &b, &c);
        event[c] = i;
        if(c==s) smask = 1<<i;

        rep(j,1<<e)if(j>>i&1){
            G[j][a].pb(b);
            G[j][b].pb(a);
        }
    }

    rep(i,E)rep(j,N)rep(k,R) d[i][j][k] = INF;
    d[smask][s][0] = 0;
    queue<state> que;
    que.push({smask,s,0});

    while(!que.empty()){
        state c = que.front();
        que.pop();

        int D = d[c.mask][c.pos][c.day];

        // move
        if(c.day<r){
            int nd = c.day+1;
            for(int nx:G[c.mask][c.pos]){
                int nmask = c.mask;
                if(event[nx]!=-1) nmask |= (1<<event[nx]);

                if(d[nmask][nx][nd] > D+1){
                    d[nmask][nx][nd] = D+1;
                    que.push({nmask,nx,nd});
                }
            }
        }

        // ocarina
        if(d[c.mask][s][0] > D+1){
            d[c.mask][s][0] = D+1;
            que.push({c.mask,s,0});
        }
    }

    int ans = INF;
    rep(mask,1<<e)rep(i,r+1) ans = min(ans,d[mask][t][i]);
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}



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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    rep(i,pow(2,n)){
        if(i == 0){
            printf("0:\n");
        }else{
            printf("%d:", i);
            bitset<18> A(i);
            rep(j,18){
                if(A.test(j)) printf(" %d", j);
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3412
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

int main(){FIN;
	ll n,l; cin>>n>>l;
	ll t[n];
	fore(i,0,n)cin>>t[i];
	long double x=0,y=0;
	fore(i,0,n){
		fore(j,i+1,n){
			ll ad=j-i-1;
			x+=cos(acos(-1)*(t[i]+t[j]+l)/l)*(ad)+cos(acos(-1)*(t[i]+t[j])/l)*(n-2-ad);
			y+=sin(acos(-1)*(t[i]+t[j]+l)/l)*(ad)+sin(acos(-1)*(t[i]+t[j])/l)*(n-2-ad);
			//cout<<cos(acos(-1)*(t[i]+t[j]+l)/l)<<" "<<sin(acos(-1)*(t[i]+t[j]+l)/l)<<"\n";
		}
	}
	x/=(n*(n-1)*(n-2)/6);
	y/=(n*(n-1)*(n-2)/6);
	cout<<fixed<<setprecision(15)<<x<<" "<<y<<"\n";
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

// we want the ascending-priority-queue.
// So we use less than here.
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = j
	pq[j].index = i
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}



Measured memory_bytes: 1220
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    long[] mod = new long[s.length()];
    mod[0] = 1;
    for(int i = 1; i < s.length(); i++) {
      mod[i] = (mod[i - 1] * 10) % 13;
    }
    long M = (long)Math.pow(10, 9) + 7;
    long[][] dp = new long[s.length()][13];
    for(int i = 0; i < s.length(); i++) {
      String str = String.valueOf(s.charAt(s.length() - 1 - i));
      if(i == 0) {
        if(str.equals("?")) {
          for(int j = 0; j < 10; j++) {
            dp[i][j] = 1;
          }
        } else {
          int d = Integer.parseInt(str);
          dp[i][d] = 1;
        }
      } else {
        if(str.equals("?")) {
          for(int j = 0; j < 10; j++) {
            for(int k = 0; k < 13; k++) {
              dp[i][(int)((k + mod[i] * j) % 13)] = (dp[i][(int)((k + mod[i] * j) % 13)] + dp[i - 1][k]) % M;
            }
          }          
        } else {
          int d = Integer.parseInt(str);
          for(int j = 0; j < 13; j++) {
            dp[i][(int)((j + mod[i] * d) % 13)] = (dp[i][(int)((j + mod[i] * d) % 13)] + dp[i - 1][j]) % M;
          }          
        }        
      }
    }
    System.out.println(dp[s.length() - 1][5]);
  }
}


Measured memory_bytes: 54692
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N;
    cin>>N;
    vector<int> s(N);
    rep(i,N) cin>>s.at(i);
    //結果が10の倍数なら、10の倍数以外で最小の数を引けばいい
    sort(s.begin(),s.end());
    ll ans=0;
    rep(i,N){
        ans+=s.at(i);
    }
    if(ans%10==0){
        bool ok=false;
        rep(i,N){
            if(s.at(i)%10){
                ok=true;
                ans-=s.at(i);
                break;
            }
        }
        if(ok){
            cout<<ans<<endl;
        }else{
            cout<<"0"<<endl;
        }
    }else{
        cout<<ans<<endl;
    }
}


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

void Main() {
  string S;
  cin >> S;
  if (S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

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

int main()
{
	int a, b; 
	cin >> a >> b; 
	int c, d, e; 
	c = a + b; 
	d = a - b; 
	e = a * b; 
	for(int i = 0; i < 3; i ++)
	{
		d = max(c, d); 
		e = max(d, e); 
	}
	cout << e << endl; 
	return 0; 
}

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

using namespace std;

typedef long long ll;
int main(){
	ll n,m;
	ll k;
	ll t;
	cin>>n>>m;
	priority_queue<ll>q;
	for(int i=0;i<n;i++){
		cin>>k;
		q.push(k);	
	}
	while(m--){
		t=q.top()/2;
		q.pop();
		q.push(t);
	}
	ll sum=0;
	while(!q.empty()){
		sum+=q.top();
		q.pop();
	}
	cout<<sum<<endl;
	return 0;
}

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


using namespace std;

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

#define mp make_pair

int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}



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

    init();

    int n, m;
    cin>>n>>m;
    if (n==m+1 || n==m-1) cout<<mul(facs[n], facs[m]);
    else if (n==m)
    {
        cout<<mul(2, mul(facs[n], facs[m]));
    }
    else cout<<0;



}



Measured memory_bytes: 9600
#include <stdio.h>

#define NMAX 1000
#define VMAX 10000

int main() {
    int A[NMAX + 10], C[VMAX + 10], V[NMAX + 10], n;
    int m = VMAX + 10; // smallest element in A
    scanf("%d", &n);
    for (int i = 0; i <= VMAX; i++) {
        C[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &A[i]);
        V[i] = 0;
        C[A[i]]++;
        if (A[i] < m) {
            m = A[i];
        }
    }
    for (int i = 1; i <= VMAX; i++) {
        C[i] += C[i - 1];
    }
    int cost = 0;

    for (int i = 1; i <= n; i++) {
        if (V[i]) {
            continue;
        }
        // found a new ring, whose head is A[i]
        V[i] = 1;
        int k = C[A[i]]; // iterator
        int len = 1;     // length of the ring
        int min = A[i];  // smallest element of the ring
        int sum = A[i];  // sum of the ring
        while (k != i) {
            V[k] = 1;
            len++;
            sum += A[k];
            if (A[k] < min) {
                min = A[k];
            }
            k = C[A[k]];
        }
        if (len > 1) {
            int v1 = sum + (len - 2) * min;
            int v2 = sum + (len + 1) * m + min;
            cost += (v1 < v2 ? v1 : v2);
        }
    }

    printf("%d\n", cost);
    return 0;
}


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

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

	bool flag = false;
	for (int i = 0; i < 100; i++) {
		if (s[i] < t[i]) {
			flag = true;
			break;
		}
		else if (s[i] > t[i]) break;
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3548
num_1 , num_2 = input().split()
num_1 = int(num_1)
num_2 = int(num_2)
count = 0
count = abs(abs(num_2) - abs(num_1))

if (num_1 < num_2) and (num_1 * num_2 < 0):
    count += 1
if (num_1 > num_2):
    count += 1
    if (num_1 * num_2 > 0):
        count += 1
print(count)


Measured memory_bytes: 3060
# ABC088 D
h, w = map(int, input().split())
maze = []
wall = 0
for _ in range(h):
    row = list(input())
    wall += row.count('#')
    maze.append(row)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

def bfs():
    from collections import deque
    que = deque([])

    d = [[float("inf")] * w for _ in range(h)]
    que.append((0, 0))
    d[0][0] = 0
    step = 0

    while que:
        step += 1
        p = que.popleft()
        if p == (h - 1, w - 1):
            break
        for i in range(4):
            ny = p[0] + dy[i]
            nx = p[1] + dx[i]

            if 0 <= nx and nx < w and 0 <= ny and ny < h and maze[ny][nx] != '#' and d[ny][nx] == float("inf"):
                que.append((ny, nx))
                d[ny][nx] = d[p[0]][p[1]] + 1

    return d[h - 1][w - 1]

print(-1 if bfs() == float("inf") else h * w - wall - bfs() - 1)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  long long ans = 0;
  int k = n / 2;
  for(int i = 0; i < n; i++){
    if(i < k){
      if(i == k-1){
        if(n % 2 == 0) ans -= a.at(i);
        else ans -= a.at(i) * 2;
      }
      else ans -= a.at(i) * 2;
    }
    else if(i == k) ans += a.at(i);
    else if(n % 2 && i == k+1) ans += a.at(i);
    else ans += a.at(i) * 2;
  }
  long long ne = 0;
  k = (n+1) / 2;
  for(int i = 0; i < n; i++){
    if(i < k){
      if(i == k-1) ne -= a.at(i);
      else if(i == k-2){
        if(n % 2) ne -= a.at(i);
        else ne -= a.at(i) * 2;
      }
      else ne -= a.at(i) * 2;
    }
    else if(i == k){
      if(n % 2) ne += a.at(i) * 2;
      else ne += a.at(i);
    }
    else ne += a.at(i) * 2;
  }
  ans = max(ans, ne);
  
  cout << ans << endl;
}

Measured memory_bytes: 3780
N,M = map(int, input().split())
inf = 10**8
d = [[inf]*N for _ in range(N)]
E = [[] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
    E[a-1].append((b-1, c))

for i in range(N):
    d[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])

cnt = 0
for i in range(N):
    for e in E[i]:
        j = e[0]
        c = e[1]
        flag = False
        for k in range(N):
            for l in range(k+1, N):
                if d[k][l] == d[k][i]+c+d[j][l] or d[k][l] == d[k][j]+c+d[i][l]:
                    cnt += 1
                    flag = True
                    break
            if flag:
                break
print(M-cnt)

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

using namespace std;

std::vector<int> rr;
vector<vector<int>> length;

int bfs(int ans, int now, vector<bool> visited){
	visited[now] = false;
	std::vector<int> v;
	for (size_t i = 0; i < rr.size(); i++) {
		if (visited[rr[i]]) {
			v.push_back(bfs(ans+length[now][rr[i]], rr[i], visited));
		}
	}
	if (v.size() == 0) {
		return ans;
	}
	int mmin = v[0];
	for (size_t i = 0; i < v.size(); i++) {
		mmin = min(mmin,v[i]);
	}
	return mmin;
}

int main(int argc, char const *argv[]) {
	int n,m,r;
	cin >> n >> m >> r;
	rr.resize(r);
	for (size_t i = 0; i < r; i++) {
		cin >> rr[i];
		rr[i]--;
	}
	vector<int> a(m),b(m),c(m);
	for (size_t i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
	}

	length.resize(n);
	// 初期化
	for (size_t i = 0; i < n; i++) {
		for (size_t j = 0; j < n; j++) {
			length[i].push_back(1000000000);
		}
	}
	for (size_t i = 0; i < a.size(); i++) {
		length[a[i]][b[i]] = c[i];
		length[b[i]][a[i]] = c[i];
	}
	// ワーシャルフロイト法
	for (size_t i = 0; i < n; i++) {
		for (size_t j = 0; j < n; j++) {
			for (size_t k = 0; k < n; k++) {
				length[j][k] = min(length[j][k],length[j][i] + length[i][k]);
			}
		}
	}

	int ans = 1000000000;
	for (size_t i = 0; i < rr.size(); i++) {
		ans = min(ans,bfs(0,rr[i],std::vector<bool> (n,true)));
	}
	std::cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.Arrays;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x = sc.nextLong();
        long a[] = new long[n];
        
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        Arrays.sort(a);
        int count = 0;
        int c;
        int max = 0;
        for(c = 0; c < n; c++){
            if(x >= a[c]){
                x -= a[c];
                count++;
            }else{
                break;
            }
        }
        if(x > 0 && count > 0 && c == n){
                count --;
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 25172
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1163&lang=jp
typedef long long ll;
#define INF 1<<30

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

/* MAX_FLOW */

#define MAX_V 1010
struct edge {
	int to; int cap; int rev;
	edge() {}
	edge(int to, int cap, int rev) :to(to), cap(cap), rev(rev) {}
};
vector<edge> G[MAX_V];

bool used[MAX_V];

void add_edge(int from, int to, int cap) {
	G[from].push_back(edge(to, cap, (int)G[to].size()));
	G[to].push_back(edge(from, 0, (int)G[from].size() - 1));
}

int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;

	for (int i = 0; i < (int)G[v].size();i++) {
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
	}
	return -1;
}
int main() {
	cin.tie(0); ios::sync_with_stdio(false);

	int m, n;
	while (cin >> m >> n, m | n) {
		for (int i = 0; i < MAX_V;i++) {
			G[i].clear();
		}
		vector<int> b(m + 1);
		vector<int> r(n + 1);
		for (int i = 1; i <= m;i++) {
			cin >> b[i];
			add_edge(0, i, 1);
		}
		for (int i = 1; i <= n;i++) {
			cin >> r[i];
			add_edge(m + i, m + n + 1, 1);
		}

		for (int i = 1; i <= m;i++) {
			for (int j = 1;j <= n;j++) {
				if (gcd(b[i], r[j]) == 1) continue;
				add_edge(i, m + j, 1);
			}
		}

		cout << max_flow(0, m + n + 1) << endl;
	}
}

Measured memory_bytes: 9456
n=int(input())
d=dict()

for i in range(n):
  s="".join(sorted(input()))
  #print(s)
  if s in d:
    d[s]+=1
  else:
    d[s]=1
ans=0
for x in d.values():
  ans+=x*(x-1)//2
print(ans)

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

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

Measured memory_bytes: 256
s=list(input())
s1="".join(s[:2])
s2="".join(s[2:])
if 0<int(s1)<=12 and 0<int(s2)<=12:
    print("AMBIGUOUS")
elif 0<int(s1)<=12 and (int(s2)>12 or int(s2)==0):
    print("MMYY")
elif 0<int(s2)<=12 and (int(s1)>12 or int(s1)==0):
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 9200
N, K, Q = map(int, input().split())
A = []
for i in range(Q):
  A.append(int(input()))
B = [0 for b in range(N)]

for j in range(len(A)):
  B[A[j]-1] += 1
  
for l in range(len(B)):
  if B[l] > Q - K:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 8628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

struct dice
{
  vector<int> num;

  dice(int t[]) : num(7){
    for(int i=0;i<6;++i)num[i+1]=t[i];
  };
  int state(){return num[1];}
  int right(){return num[3];}

  void s()
  {
    vector<int> tmp(7);
    tmp[1] = num[5];
    tmp[2] = num[1];
    tmp[3] = num[3];
    tmp[4] = num[4];
    tmp[5] = num[6];
    tmp[6] = num[2];
    num = tmp;
  }
  void n()
  {
    vector<int> tmp(7);
    tmp[5] = num[1];
    tmp[1] = num[2];
    tmp[3] = num[3];
    tmp[4] = num[4];
    tmp[6] = num[5];
    tmp[2] = num[6];
    num = tmp;
  }
  void e()
  {
    vector<int> tmp(7);
    tmp[1] = num[4];
    tmp[2] = num[2];
    tmp[3] = num[1];
    tmp[4] = num[6];
    tmp[5] = num[5];
    tmp[6] = num[3];
    num = tmp;
  }
  void w()
  {
    vector<int> tmp(7);
    tmp[4] = num[1];
    tmp[2] = num[2];
    tmp[1] = num[3];
    tmp[6] = num[4];
    tmp[5] = num[5];
    tmp[3] = num[6];
    num = tmp;
  }
  void r()
  {
    vector<int>tmp(7);
    tmp[1]=num[1];
    tmp[2]=num[3];
    tmp[3]=num[5];
    tmp[4]=num[2];
    tmp[5]=num[4];
    tmp[6]=num[6];
    num = tmp;
  }

  void top(int val)
  {
    if(num[1]==val)
      return;
    else if(num[2]==val)
      n();
    else if(num[3]==val)
      w();
    else if(num[4]==val)
      e();
    else if(num[5]==val)
      s();
    else
    {
      n(); n();
    }
  }
  void front(int val)
  {
    if(num[2]==val)
      return;
    else if(num[3]==val)
      r();
    else if(num[4]==val)
    {
      r(); r(); r();
    }
    else if(num[5]==val)
    {
      r(); r();
    }
  }
};

int main()
{
  int n[6];
  for(int i=0;i<6;++i)cin>>n[i];
  dice d(n);
  dice a(n);
  for(int i=0;i<6;++i)cin>>n[i];
  dice e(n);
  dice b(n);

  for(int i=1;i<=6;++i)
  {
    for(int j=1;j<=6;++j)
    {
      if(i==2)e.n();
      else if(i==3)e.w();
      else if(i==4)e.e();
      else if(i==5)e.s();
      else if(i==6)
      {
        e.n();e.n();
      }
      if(j==1)e.s();
      else if(j==3)e.r();
      else if(j==4)
      {
        e.r(); e.r(); e.r();
      }
      else if(j==5)
      {
        e.r(); e.r();
      }
      else if(j==6)e.n();
      bool tmp=true;
      for(int k=1;k<=6;++k)
      {
        if(d.num[k]!=e.num[k])
          tmp=false;
      }
      e=b;
      if(tmp)
      {
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;

  return 0;
}



Measured memory_bytes: 3160
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	return scanInt(sc)
}

func resolve(n int) int {
	return (1000 - (n % 1000)) % 1000
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
    };
    a.sort();
    let s = a
        .iter()
        .scan(0, |acc, a_i| {
            *acc += a_i;
            Some(*acc)
        })
        .collect::<Vec<_>>();
    let mut c = 0;
    let mut a_p = a[0];
    for (i, &a_i) in a.iter().enumerate().skip(1) {
        if a_p * 2 >= a_i {
            a_p += a_i;
        } else {
            a_p = s[i];
            c = i;
        }
    }
    let ans = n - c;
    println!("{}", ans);
}


Measured memory_bytes: 4916
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  long minimum = 1000000000, maximum = 0;
  rep (i, N) {
    long a;
    cin >> a;
    minimum = min(minimum, a);
    maximum = max(maximum, a);
  }
  cout << maximum - minimum << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long mod = (long) 1e9 + 7;
		long ans = 1;
		for(int i=1;i<=N;i++){
			ans = ans * i % mod;
		}
		Console.WriteLine(ans);
	}
	long N;
	public Sol(){
		N = rl();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int a[20],mx,b[12];

int get(int l,int r){
	int x=0;
	for(int i=r;i>=l;i--) x=x*10+a[i];
	//printf("->>>%d %d %d\n",l,r,x);
	return x;
}
int check(int x){
	long long ans=0;
	memset(b,0,sizeof b);
	for(int i=0;i<mx;i++)
		if((1<<i)&x) b[i+1]=1;
	/*for(int i=0;i<mx;i++)
		printf("%d ",b[i+1]);
	puts("");*/
	int l=1;b[mx]=1;
	for(int i=1;i<=mx;i++)
		if(b[i]) ans+=get(l,i),l=i+1;
	return ans;

}

int main(){
	long long x;
	scanf("%lld",&x);
	mx=10;
	for(int i=1,k=1;k<=10;k++,i*=10){
		a[k] =x/i%10; 
		if(a[k]==0){mx=k-1;break;}
	}
	//printf("%d\n",mx);
	long long ans=0;
	for(int i=1;i<(1<<(mx-1));i++)
		ans += check(i);
	ans+=x;
	printf("%lld\n",ans);
}

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


int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(202020), dist(202020, 0);
  rep(i, n) cin >> a[i + 1];
  
  int pos = 1, cnt = 0;
  while(k > 0)
  {
    int npos = a[pos];
    k--;
    
    //dist[npos] = dist[pos] + 1;
    ///*
    if(dist[npos] == 0)
    {
      dist[npos] = dist[pos] + 1;
    }
    else
    {
      int loop = cnt - dist[npos] + 1;
      //cout << k << " " << loop << endl;
      k %= loop;
      rep(i, n + 1) dist[i] = 0;
    }
    //*/
    
    
    //cout << cnt <<" "<< k <<" "<< pos << endl;
    
    cnt++;
    pos = npos;
   
    
  }
  
  cout << pos << endl;
  
  
  return 0;
}

Measured memory_bytes: 4844
N, M = map(int, input().split())
K = []
X = []
for _ in range(M):
    k, *x = list(map(int, input().split()))
    K.append(k)
    X.append(x)
P = list(map(int, input().split()))

ans = 0
for bit in range(2 ** N):
    light_on = [False] * M
    for i in range(M):
        tmp = 0
        for s in X[i]:
            tmp += bit >> (s - 1) & 1
        light_on[i] = tmp % 2 == P[i]

    ans += all(light_on)

print(ans)


Measured memory_bytes: 73832
n = int(input())
d = list(map(int,input().split()))
sorted_d = sorted(d)

halfLength = int(len(sorted_d) / 2)

if sorted_d[halfLength-1] ==  sorted_d[halfLength]:
	print(0)
else:
	print(sorted_d[halfLength] - sorted_d[halfLength-1])

Measured memory_bytes: 83872
import math
target = int(input())
answer = dict()
for factorial in range(2,target + 1):
    while factorial > 1:
        for inner in range(2,math.ceil(math.sqrt(factorial))+1):
            if factorial % inner == 0:
                factorial //= inner
                answer[inner] = answer.get(inner,0) + 1
                break
        else:
            answer[factorial] = answer.get(factorial,0) + 1
            factorial = 1
            
sum_answer = 1
for ans in answer.values():
    sum_answer = (sum_answer * (ans + 1)) % (10**9 + 7)

print(sum_answer)


Measured memory_bytes: 3188
#include <stdio.h>
#include <math.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, d, ans = 0, now;
  scanf("%lld%lld", &n, &d);
  ll x[n][d];
  for(i = 0; i < n; ++i) for(j = 0; j < d; ++j) scanf("%lld", &x[i][j]);
  for(i = 0; i < n; ++i) for(j = i + 1; j < n; ++j) {
    now = 0;
    for(k = 0; k < d; ++k) now += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
    if(sqrt(now) == (int)sqrt(now)) ++ans;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int r;
    cin >> r;
    if (r < 1200){
        cout << "ABC" << endl;
    } else if (r < 2800){
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    return 0;
}


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

int fr[200000];
int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	string en;
	cin>>en;
	int b = 1;
	fr[0]  =1;
	int s = 0;
	long long res = 0;
	for(int i=en.length()-1;i>=0;i--){
		s = (s+b*(en[i]-'0'))%2019;
		res+=fr[s];
		fr[s]++;
		b = (b*10)%2019;
	}
	cout<<res<<endl;
	
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int N, T;
int ans;

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

	cin >> N >> T;

	ans = 100000;

	for (int i = 0;i < N;i++){
		int c,t; cin >> c >> t;
		if(t <= T) ans = min(ans,c);
	}


	cout << (ans == 100000 ? "TLE" : to_string(ans)) << endl;

	return 0;

}


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


int table[50000];

signed main(){

	int n, q, a[20], m[200];
	cin >> n;
	rep(i, n) cin >> a[i];
	cin >> q;
	rep(i, q) cin >> m[i];

	rep(k, 1 << n){
		int t = 0;
		rep(bit, n){
			if ((1 << bit) & k) t += a[bit];
		}
		table[t]++;
	}

	rep(i, q){
		if (table[m[i]]) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}



Measured memory_bytes: 3076
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Thu Jan 10 22:05:32 2019
//
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	ans := 0
	for _, n := range []int{1, 2, 4, 8, 16, 32, 64} {
		if n <= N {
			ans = n
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;

bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  ll n;
  cin>> n;
  vector<string> s(n+10);
  
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  sort(s.begin(),s.end());
  reverse(s.begin(),s.end());

  vector<pair<int, string>> p(n);
  int count =1;
  int j=0;
  int ans =1;
  for(int i = 0; i < n; i++){
    if(s[i]==s[i+1]){
      count ++;
    }
    else{
      p[j] = make_pair(count, s[i]);
      count =1;
      j++;
      
    }
  }
  sort(p.begin(), p.end());
  reverse(p.begin(),p.end());
  vector<string> kotae(j);
  int k=0;
  while(p[0].first==p[k].first){
    
    kotae[k]=p[k].second;
    k++;
  }
  sort(kotae.begin(),kotae.end());
  for(int i=0; i<j;i++){
    cout<<kotae[i]<<endl;
  }

  
  
}



Measured memory_bytes: 18944
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	string S;
	cin>>S;
	int l=sz(S);
	
	string T;
	rep(i,l){
		if(S[i]=='A'){
			T.push_back('A');
		}
		else{
			if(i==l-1)continue;
			if(S[i]=='B' && S[i+1]=='C'){
				T.push_back('D');
				i++;
			}
			else{
				T.push_back('X');
			}
		}
	}
	
	int N=sz(T);
	ll ans=0;
	ll cta=0;
	rep(i,N){
		if(T[i]=='A'){
			cta++;
		}
		if(T[i]=='D'){
			ans+=cta;
		}
		if(T[i]=='X'){
			cta=0;
		}
	}
	cout<<ans;
}

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

int main() {
  long long n,m,k;
  int maxi = 0;
  cin >> n >> m >> k;
  vector<long long> a(n + 1,0),b(m + 1,0);
  for(int i = 1;i <= n;i++){
    cin >> a[i];
    a[i] += a[i - 1];
  }

  for(int i = 1;i <= m;i++){
    cin >> b[i];
    b[i] += b[i - 1];
  }

  int j = m;
  for(int i = 0;i <= n;i++){
    if(a[i] > k)break;
    while(b[j] > k - a[i])j--;
    maxi = max(maxi,i + j);
  }
  cout << maxi << endl;
}


Measured memory_bytes: 6412
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll n;
	cin>>n;
	ll arr[n];
	input(arr,n);
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		int flag=1;
		for(ll j=0;j<i;j++)
		if(arr[j]>arr[i])
		flag=0;
		if(flag)ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a[10][10],t;
    cin>>a[1][1]>>a[1][2]>>a[2][2];
    t=a[2][2]*3;
    a[1][3]=t-a[1][1]-a[1][2];
    a[3][3]=t-a[1][1]-a[2][2];
    a[3][1]=t-a[1][3]-a[2][2];
    a[2][1]=t-a[1][1]-a[3][1];
    a[3][2]=t-a[3][1]-a[3][3];
    a[2][3]=t-a[2][1]-a[2][2];
    for(int i=1;i<=3;i++)
    {
      for(int j=1;j<=3;j++)
        cout<<a[i][j]<<' ';
    cout<<endl;
    }    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG



int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> save(N+1, -1);

  for(ll i=0; i<M; i++){
    ll a, b;
    cin >> a >> b;
    if(save[a] == -1){
        save[a] = b;
    }else if (save[a] == b)
    {
        save[a] = b;
    }else{
        cout  << "-1" << endl;
        return 0;
    }
  }
  if(save[1] == 0 && N!=1){
      cout  << "-1" << endl;
      return 0;
  }

  for(ll i=1; i<=N; i++){      
      if(save[i]!=-1){
          cout << save[i];
      }else{
          if(i==1){
              if(N==1) cout << 0;
              else  cout << 1;
          }

          else cout << 0;
      }
  }
  
 
  cout << endl;
  return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;

int main() {
    int a,b,c;
    cin >> a >> b>> c;
    int m = max(a,max(b,c));
    bool M = ((3*m)%2 == 0), abc = ((a+b+c) % 2) == 0;
    if(M == abc) {
        cout << (3*m-(a+b+c))/2 << endl;
    } else {
        cout << (3*(m+1)-(a+b+c))/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> pii;

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

const int N = 100005;
int n, m, fl, col[N];
LL cnt2, cnt1, cnt3, sz;
VI E[N];

void dfs(int x, int c){
	if (col[x]){
		if (col[x] != c) fl = 0;
		return;
	}
	++sz;
	col[x] = c;
	RVC(i, E[x]) dfs(E[x][i], 3 - c);
}

int main(){
	n = read(), m = read();
	REP(i, 1, m){
		int u = read(), v = read();
		E[u].pb(v);
		E[v].pb(u);
	}
	LL ans = 0;
	REP(i, 1, n) if (!col[i]){
		fl = 1;
		sz = 0;
		dfs(i, 1);
		if (sz == 1) ++cnt1;
		else if (fl) ++cnt2;
		else ++cnt3;
	}
	ans += 1ll * cnt1 * (n - cnt1) * 2 + cnt1 * cnt1;
	ans += cnt2 * cnt2 * 2;
	ans += cnt3 * cnt2 * 2 + cnt3 * cnt3;
	//cerr << cnt1 << ' ' << cnt2 << ' ' << cnt3 << endl;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9984
from datetime import date
while 1:
	input_data = map(int,raw_input().split())
	day = 0
	if input_data[0] == 0:
		break
	day = date(2004,int(input_data[0]),int(input_data[1])).weekday()
	if day == 6:
		print("Sunday")
	elif day == 0:
		print("Monday")
	elif day == 1:
		print("Tuesday")
	elif day == 2:
		print("Wednesday")
	elif day == 3:
		print("Thursday")
	elif day == 4:
		print("Friday")
	elif day == 5:
		print("Saturday")

Measured memory_bytes: 6472
#include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int inf = 1 << 30;
const int INF = INT_MAX;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n;
  cin >> s;
  int r = 0, b = 0;
  for(char c : s) {
    if (c == 'R') {
      ++r;
    } else {
      ++b;
    }
  }
  if(r > b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int min(int a,int b)
{
    return((a<b)?a:b);
}
int main()
{
    int n,k,i,m,j;
    cin>>n>>k;
    int h[n],dp[n];
    for(i=0;i<n;i++)
        cin>>h[i];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++)
    {
        int min=INT_MAX;
        if((i-k)<0)
            m=0;
        else
            m=i-k;
        for(j=m;j<i;j++)
        {
            if(dp[j]+abs(h[i]-h[j])<min)
            {
                min=dp[j]+abs(h[i]-h[j]);
            }
        }
        dp[i]=min;
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1024
package main
 
import (
  "fmt"
)
 
func main() {
  var W, a, b int
  fmt.Scan(&W)
  fmt.Scan(&a)
  fmt.Scan(&b)
  
  ans := abs(a - b)
  if ans <= W {
    ans = 0
  } else {
    ans -= W
  }
  fmt.Printf("%d\n", ans)
}

func abs(a int) int {
  if a < 0 {
    a *= -1
  }
  return a
}

Measured memory_bytes: 1832
#include<stdio.h>
#include<string.h>
#include<math.h>

int main(){
  int x, y;
  scanf("%x %x", &x, &y);
  if(x<y)printf("<\n");
  if(x>y)printf(">\n");
  if(x==y)printf("=\n");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 1002;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,m;cin>>n>>m;
	vector<ll> ca[3];
	FOR(i,0,3)ca[i].resize(n);
	FOR(i,0,n)FOR(j,0,3)cin>>ca[j][i];
	ll ans=0;
	FOR(i,0,8){
		priority_queue<P> q;
		FOR(j,0,n){
			ll k=0;
			if(i&1)k+=ca[0][j];else k-=ca[0][j];
			if(i&2)k+=ca[1][j];else k-=ca[1][j];
			if(i&4)k+=ca[2][j];else k-=ca[2][j];
			q.push(mp(k,j));
		}
		ll x[]={0,0,0};
		FOR(j,0,m){
			FOR(l,0,3)x[l]+=ca[l][q.top().se];
			q.pop();
		}
		ans=max(ans,abs(x[0])+abs(x[1])+abs(x[2]));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
/**
 * Author : Dhakad_123
 * Created: 28.06.2020
 **/


#include<bits/stdc++.h>
using namespace std;

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

	string s, t;

	cin >> s >> t;

	int ans = 0;

	for(int i = 0; i < s.length(); i++){
		if(s[i] != t[i]){
			ans++;
		}
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3788
#include <stdio.h>
const int MAXN = 2e7 + 1;
int n, x, y, f, c, i, j, spf[MAXN];
long long ans = 1, z;
signed main()
{
	for (i = 2; i < MAXN; i += 2)
        spf[i] = 2;
	for (i = 3; i < MAXN; i += 2)
        spf[i] = i;
    for (i = 3; i < 3162; i += 2)
        if (spf[i] == i)
            for (j = i * i; j < MAXN; j += i)
                if (spf[j] == j)
                    spf[j] = i;
	scanf("%d", &n);
	for (i = 2; i <= n; ++i)
	{
		x = i, f = 1, c = 1, z = 1;
		while (x > 1)
			y = spf[x], x /= y, y > f ? z *= c, c = 2, f = y : ++c;
		ans += i * z * c;
	}
	printf("%lld", ans);
}

Measured memory_bytes: 79824
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  int A1, A2, A3;

  cin >> A1 >> A2 >> A3;

  if( (A1+A2+A3) >= 22)  cout << "bust" << endl;
  else  cout << "win" << endl;

  return 0;
}


Measured memory_bytes: 256