akhauriyash/Code-Regression huggingface dataset:
N, M = readline.split(' ').map(&:to_i)
Edges = Hash.new {|h,k| h[k]=Hash.new }

M.times do |idx|
  n1, n2, dist = readline.split(' ').map(&:to_i)
  Edges[n1-1][n2-1] = [dist, idx]
  Edges[n2-1][n1-1] = [dist, idx]
end

# flooding
minimum_distance_matrix = Array.new(N) {Array.new(N)}
N.times do |i|
  minimum_distance_matrix[i][i]=0
end

N.times do
  changed = false
  Edges.each_pair do |src, h|
    h.each_pair do |dst, edge|
      N.times do |i|
	next unless minimum_distance_matrix[i][src]

	#e = Edges[src][dst]
	current = minimum_distance_matrix[i][dst]
	next_cand = minimum_distance_matrix[i][src]+edge[0]
	if !current or current>next_cand then
	  minimum_distance_matrix[i][dst] = next_cand
	  changed = true
	end
      end
    end
  end
  break unless changed
end
<<END
N.times do |i|
  N.times do |j|
    current_distance = minimum_distance_matrix[i][j]
    next unless current_distance
    Edges[j].each_pair do |dest, e|
      dist, = e
      next_distance_candidate = current_distance + dist
      next_distance = minimum_distance_matrix[i][dest]
      if !next_distance or next_distance>next_distance_candidate then
	minimum_distance_matrix[i][dest] = next_distance_candidate
      end
    end 
  end
end
END
#p minimum_distance_matrix

count=0
Edges.keys.sort.each do |src|
  Edges[src].keys.sort.each do |dst|
    if src<=dst then
      break
    end

    e = Edges[src][dst]
    if minimum_distance_matrix[src][dst] < e[0]
      count += 1
    end
  end
end

puts count



__END__
class Path
  attr_reader :distance, :node_seq
  def initialize(distance, node_seq)
    @distance = distance
    @node_seq = node_seq
  end
end

def merge_sorted_paths(a, b)
  return b if a.length==0
  return a if b.length==0

  # build a holder array that is the size of both input arrays
  # O(n) space
  result = []

  # get lower head value
  if a[0].distance < b[0].distance
    result << a.shift
  else
    result << b.shift
  end

  # check to see if either array is empty
  if a.length == 0
    return result + b
  elsif b.length ==0
    return result + b
  else
    return result + merge_sorted_paths(a, b)
  end
end

def find_a_path_less_than(src, dest, max)
  sorted_paths = [Path.new(0, [src])] # sorted_paths: [Path] sorted by Path.distance

  while head = sorted_paths.shift
    if head.distance >= max
      return nil
    end

    if head.node_seq[-1]==dest
      return head.node_seq
    end

    new_paths = []
    Edges[head.node_seq[-1]].each do |dest2, edge|
      distance, = *edge
      if head.distance + distance < max
        p = Path.new(head.distance + distance, head.node_seq+[dest2])
        new_paths.unshift(p)
      end
    end

    #sorted_paths.push(*new_paths)
    #sorted_paths.sort_by!(&:distance)
    new_paths.sort_by!(&:distance)
    sorted_paths = merge_sorted_paths(sorted_paths, new_paths)
  end

  return nil
end


count=0
Edges.keys.sort.each do |src|
  Edges[src].keys.sort.each do |dst|
    if src<=dst then
      break
    end

    e = Edges[src][dst]
    if find_a_path_less_than(src, dst, e[0])
      count += 1
    end
  end
end

puts count




Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef pair<int,int> P;

const int MAX_N=2e5;

int N,K,L;

vector<int> G[2][MAX_N];
bool flg[2][MAX_N];
set<int> vs[2][MAX_N];
int C[2];
int con[2][MAX_N];
int ans[MAX_N];

void dfs(int n,int v){
	con[n][v]=C[n];
	flg[n][v]=true;
	REP(u,(int)G[n][v].size()){
		int to=G[n][v][u];
		if (!flg[n][to]){
			dfs(n,to);
		}
	}
}

int main(){
	scanf("%d %d %d",&N,&K,&L);
	REP(i,K){
		int p,q;
		scanf("%d %d",&p,&q);
		p--;
		q--;
		G[0][p].push_back(q);
		G[0][q].push_back(p);
	}
	REP(i,L){
		int p,q;
		scanf("%d %d",&p,&q);
		p--;
		q--;
		G[1][p].push_back(q);
		G[1][q].push_back(p);
	}
	REP(i,2){
		REP(v,N){
			if (!flg[i][v]){
				dfs(i,v);
				C[i]++;
			}
		}
	}
	map<P,int> mp;
	REP(v,N){
		mp[P(con[0][v],con[1][v])]++;
	}
	REP(i,N){
		if (i) printf(" ");
		printf("%d",mp[P(con[0][i],con[1][i])]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll base = 1e6;
int D;
int C[30];
int S[400][30];
int last[400][30];

ll score(vector<int>& t)
{
  ll s = 0LL;
  REP(i,D){
    s += S[i][t[i]];
    REP(j,26) last[i+1][j] = last[i][j];
    last[i+1][t[i]] = i+1;
    REP(j,26){
      s -= C[j] * (i+1-last[i+1][j]);
    } 
  }
  return s;
}

ll score_2(vector<int>& t, ll before, int d, int old, int q)
{
  ll s = before;
  s += S[d][q] - S[d][old];
  FOR(i,d,D){
    if(t[i]==old) break;
    s += C[old] * ((i+1) - last[i+1][old]);
    s -= C[old] * ((i+1) - last[d][old]);
  }
  FOR(i,d,D){
    if(t[i]==q) break;
    s += C[q] * ((i+1) - last[i+1][q]);
    s -= C[q] * ((i+1) - (d+1));
  }

  return s;
}

vector<int> init(int sub)
{
  vector<int> t(D);
  REP(i,D) t[i] = (i+sub)%26;
  return t;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand365(0, 364);
  uniform_int_distribution<> rand26(0, 25);

  cin >> D;
  REP(i,26) cin >> C[i];
  REP(i,D) REP(j,26) cin >> S[i][j];

  auto T = init(0);
  ll max_score = 0LL;
  REP(sub,26){
    auto tmp = init(sub);
    ll sc = max(base+score(tmp), 0LL);
    if(max_score<sc){
      max_score = sc;
      T = tmp;
    }
  }
  int ti = clock();
  while(clock() - ti < 190 * CLOCKS_PER_SEC / 100){ 
    int d = rand365(mt);
    int q = rand26(mt);
    int old = T[d];
    T[d] = q;
    ll tmp = max(base + score_2(T, max_score, d, old, q), 0LL);
    if(max_score<tmp){
      max_score = tmp;
      FOR(i,d,D){
        if(T[i]==old) break;
        last[i+1][old] = last[d][old];
      }
      FOR(i,d,D){
        if(T[i]==q) break;
        last[i+1][q] = (d+1);
      }
    }else{
      T[d] = old;
    }
  }
  REP(i,D) cout << T[i]+1 << '\n';
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define endl '\n'
#define len(x) (int)x.size()
#define rep(a, b, i) for (int i = a; i < b; i++)
#define repi(a, b, i) for (int i = a; i > b; i--)
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define binary_search
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define __                                                                                                             \
    ios_base::sync_with_stdio(false);                                                                                  \
    cin.tie(0);                                                                              
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
const ld PI = 3.141592653589793;
const int MAXN = 1e5 + 5;

int32_t main() {
    __;

	ll n, k; cin >> n >> k;
	
	if (k == 1) cout << "0\n";
	else cout << min(k-n%k, n%k);

    return 0;
}


















Measured memory_bytes: 256
import math
n = int(input())
S = input()
 
RL = [None]*2*n
 
for i in range(2*n):
    if i % 2 == 0:
        if S[i] == 'B':
            RL[i] = 'L'
        else:
            RL[i] = 'R'
 
    else:
        if S[i] == 'B':
            RL[i] = 'R'
        else:
            RL[i] = 'L'
 
if S[0] == 'W' or S[-1] == 'W':
    print(0)
    exit()
 
left = 0
count = 1
mod = 10**9 + 7
 
for check in RL:
    if check == 'L':
        left += 1
    else:
        count = count * left % mod
        left -= 1
 
    if left < 0:
        print(0)
        exit()
 
count = count * math.factorial(n) % mod
 
if left != 0:
    print(0)
else:
    print(count)

Measured memory_bytes: 46560
#include <iostream>
using namespace std;
int n,a,c;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(i+1!=a)c++;
    }
    if(c<3)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
def add_adj(adj, k, v):
    if k not in adj:
        adj[k] = set()
    adj[k].add(v)


def all_visited(N):
    x = 0
    for i in range(N):
        x += 1 << i
    return x


def dfs(adj, cur, visited, N):
    if visited == all_visited(N):
        return 1
    cnt = 0
    for nex in adj[cur]:
        if (visited >> (nex - 1)) & 1 == 1:
            continue
        cnt += dfs(adj, nex, (visited | (1 << (nex - 1))), N)
    return cnt


def main():
    N, M = map(int, input().split())
    adj = {}
    for i in range(M):
        a, b = map(int, input().split())
        add_adj(adj, a, b)
        add_adj(adj, b, a)
    print(dfs(adj, 1, 1, N))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
vector<double> p;

// DP テーブル
double dp[3100][3100];

int main() {
    cin >> N;
    p.resize(N);
    for (int i = 0; i < N; ++i) cin >> p[i];

    // 初期条件
    dp[0][0] = 1.0;

    // DP ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= i; ++j) {
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }

    // 答え
    double res = 0.0;
    for (int j = (N+1)/2; j <= N; ++j) res += dp[N][j];
    cout << fixed << setprecision(10) << res << endl;
}

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

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main()
{
    string s;
    cin >> s;
    ll cnt = 0;
    ll ans = 0;
    rep(i, 0, s.size()){
        if(s[i] == 'W') cnt++;
    }
    if(cnt == s.size() || cnt == 0){
        cout << 0 << endl;
    }
    else{
        cnt = 0;
        rep(i, 0, s.size()){
            if(s[i] == 'W') cnt++;
            else break;
        }
        rep(i, cnt, s.size()){
            if(s[i] == 'W'){
                ans += i - cnt;
                cnt++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3764
package main

import (
        "fmt"
        "sort"
)

func main() {
        var n, x int
        fmt.Scan(&n, &x)
        m := make([]int, n)
        for i := range m {
                fmt.Scan(&m[i])
        }
        sort.Ints(m)

        n = 0
        for i := range m {
                if x < m[i] {
                        break
                }
                x -= m[i]
                n++
        }
        for x >= m[0] {
                x -= m[0]
                n++
        }
        fmt.Println(n)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define forep(i, k, n) for (int i = k; i < n; i++)
const int MAX = 2000000;
const ll MOD = 1000000007;

vector<ll> fac(MAX), finv(MAX), inv(MAX);
void comb_init()
{
  fac.at(0) = fac.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inv.at(1) = 1;
  forep(i, 2, MAX)
  {
    fac.at(i) = fac.at(i - 1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inv.at(i) % MOD;
  }
}

ll comb(int n, int k)
{
  if (n < k)
  {
    return 0;
  }
  if (n < 0 || k < 0)
  {
    return 0;
  }
  return fac.at(n) * (finv.at(k) * finv.at(n - k) % MOD) % MOD;
}

int main()
{
  comb_init();
  int x, y;
  cin >> x >> y;
  if ((x + y) % 3 != 0)
  {
    cout << 0 << endl;
    return 0;
  }
  int a = y - (x + y) / 3, b = x - (x + y) / 3;
  cout << comb(a + b, a) << endl;
}

Measured memory_bytes: 47232
n,*a=$<.read.split.map(&:to_i)
a.sort!
i,j=0,n-1
while i<j
  next i+=1 if a[i]<a[i+1]
  next j-=1 if a[j-1]<a[j]
  i+=1
  j-=1
  n-=2
end
p n

Measured memory_bytes: 9712
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	K := nextInt()
	X := nextInt()
	if K*500 >= X {
		fmt.Println("Yes")
		return
	}
	fmt.Print("No")
}


Measured memory_bytes: 640
function main(input) {
	const arr = input.split('');
  	let cnt = 0;
	for (let i = 0; i < arr.length; i++) {
      if (arr[i] === '1') {
        cnt++;
      }
    }
  	console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29520
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main()
{
	int a;
	ll b, n;
	ll x;

	cin >> a >> b >> n;
	x = min(n, b - 1);
	ll max = floor(a * x / b) - a * floor(x / b);

	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<deque>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int k;
	string s;
	cin>>k>>s;
	if(s.size()<=k){
		cout<<s<<endl;
	}
	else{
		rep(i, k){
			cout<<s[i];
		}
		cout<<"..."<<endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long long ll;
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("amusing.in", "r", stdin);
    //freopen("amusing.out", "w", stdout);
}

void solve() {
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0){
        cout << "Zero\n";
        return;
    }
    if (b < 0 && abs(b - a) % 2 == 0){
        cout << "Negative\n";
        return;
    }
    cout << "Positive\n";
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
using namespace std;
int main() {
	int N, K; 
	string S;
	cin >> N >> K >> S;
	K -= 1;
	if (S[K] == 'A') {
		S[K] = 'a';
	}
	else if (S[K] == 'B') {
		S[K] = 'b';
	}
	else if (S[K] == 'C') {
		S[K] = 'c';
	}
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    N, L = map(int, open(0).read().split())

    T = []
    T_abs = []
    for i in range(1, N + 1):
        T.append(L + i - 1)
        T_abs.append(abs(L + i - 1))
    
    Remv = T[T_abs.index(min(T_abs))]
    print(sum(T) - Remv)


main()

Measured memory_bytes: 3060
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int r = scanner.nextInt();
        int D = scanner.nextInt();
        int x = scanner.nextInt();
        for (int i = 0; i < 10; i++) {
            x *= r;
            x -= D;
            System.out.println(x);
        }
    }

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
2^10000
仮定して進めて行くんだけど、最初の4通りくらい？
あとは五月雨式に決まっていくかな
2文字確認かな
*/
int main(){
  ll N; cin>>N;
  string S; cin>>S;
  char ans[100010];
  string test[4]={"SS","SW","WS","WW"};
  for(ll i=0; i<4; i++){
    for(ll j=0; j<2; j++) ans[j]=test[i][j];
    for(ll j=1; j<=N; j++){
      ll jj=(j>=N)?j-N:j;
      if(ans[j]=='S' && S[jj]=='o' || ans[j]=='W' && S[jj]=='x') ans[j+1]=ans[j-1];
      else ans[j+1]=(ans[j-1]=='S')?'W':'S';
    }
    if(ans[0]!=ans[N] || ans[1]!=ans[N+1]) continue;    
    for(ll i=0; i<N; i++)cout<<ans[i];
    cout<<endl;
    return 0;
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

int main(){
  int N, K; cin>>N>>K;
  int p[N];
  for(int i=0; i<N; i++){
    cin>>p[i];
  }
  int S[N];
  fill(S, S+N, 0);
  for(int i=0; i<K; i++){
    S[0]+=p[i];
  }
  int j=S[0];
  for(int i=1; i<=N-K; i++){
    S[i]=S[i-1]-p[i-1]+p[i-1+K];
    j=max(j, S[i]);
  }
  double ans=((double)j+(double)K)/(double)2;
  cout << fixed << setprecision(13)<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007
using namespace std;


int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,k,n,m;
     ll t;
     cin>>n>>k;
     if(k>=n)
     {
         cout<<"unsafe";
     }
     else
         cout<<"safe";
}  


Measured memory_bytes: 3640
import math

def calc_order(A, N):
    l = [i + 1 for i in range(N)]
    order = 1
    for i in range(N):
        a = A[i]
        len_l = len(l)
        index = l.index(a)
        # print(a, index, math.factorial(len_l - 1), order)
        order += index * math.factorial(len_l - 1)
        del l[index]
    return order

def main():
    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    ord_p = calc_order(P, N)
    ord_q = calc_order(Q, N)
    ans = abs(ord_p - ord_q)
    # print(ord_p, ord_q)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9204
#include <cstdio>
bool A[200001];
inline char tc(){
  static char fl[1000],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,1000,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}
int main(){
  int n,m,a,b;n=read();m=read();
  while(m--){a=read();b=read();
    if(a==1){
      if(A[b])return puts("POSSIBLE"),0;
      A[b]=1;
    }
    if(b==n){
      if(A[a])return puts("POSSIBLE"),0;
      A[a]=1;
    }
  }
  puts("IMPOSSIBLE");
  return 0;
}

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

//一つの証言を表す構造体
using pint = pair<int, int>; //「人」と「0 or 1」

//入力
int N;
vector<vector<pint>> v;

//整数bitに対応する「決め打ち」が整合しているかを判定
bool judge(int bit) {
    
    //i人目の証言を検証する
    for (int i = 0; i < N; i++) {
        
        //i人目が「不親切」だったら，証言はすべて無意味
        if ( !(bit & (1 << i)) ) continue;

        //それぞれ確認
        for (pint xy : v[i]) {
            int x = xy.first; //xが
            int y = xy.second; //y = 1: 正直，y = 0: 不親切

            // y = 1なのに「不親切」だったら駄目
            if (y == 1 && !(bit & (1 << x))) return false;

            // y = 0なのに「正直者」だったら駄目
            if (y == 0 && (bit & (1 << x))) return false;
        }
    }
  return true;
}

int main () {
    cin >> N;
    v.resize(N);
    for (int i = 0; i < N; ++i) {
        int A; cin >> A;
        v[i].resize(A);
        for (int j = 0; j < A; ++j) {
            cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first; // 0-indexed に
        }
    }

    int res = 0;
    for (int bit = 0; bit < (1 << N); bit++) {
        
        //矛盾　check
        if (judge(bit)) {

            //bitに含まれる人数を数える
            int count = 0;
            for (int i = 0; i < N; i++) {
                if (bit & (1 << i)) ++ count;
            }
            res = max(res, count);
        }
    }

    cout << res << endl; 
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fi first
#define se second
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7,inv2=(P+1)>>1;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int inc(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
typedef pair<int,int> pi;
const int N=105;
int a[N],n,res;pi p;
pi calc(int l,int r,int x){
	R int mn=1e9,mx=0;
	fp(i,l,r)cmin(mn,a[i]),cmax(mx,a[i]);
	if(mn==mx)return pi(ksm(2,mn-x),ksm(2,r-l+1)-2);
	int f=1,s=1,w=0,np=1,coef=1;
	for(int i=l-1,j=l;i<=r;i=j++){
		while(j<=r&&a[j]!=mn)++j;
		if(i+1<=j-1){
			if(i+1==j-1)coef=mul(coef,ksm(2,a[i+1]-mn)),++w;
			else{
				p=calc(i+1,j-1,mn);
				f=mul(f,p.fi);
//				if(mn-x>1)s=mul(s,inc(p.fi,p.se));
//				else 
				s=mul(s,inc(p.fi,inc(p.fi,p.se)));
//				printf("Calc %d %d %d %d\n",i+1,j-1,p.fi,p.se);
				np=mul(np,p.fi);
			}
		}
		w+=j<=r;
	}
//	printf("%d %d %d %d %d %d %d\n",l,r,f,s,w,np,coef);
	if(w==r-l+1)return pi(mul(ksm(2,mn-x),coef),mul(ksm(2,r-l+1)-2,coef));
	f=mul(f,ksm(2,mn-x)),s=mul(s,ksm(2,w)),np=mul(np,2);
//	if(mn-x==1)
//	np=mul(np,2);
	f=mul(f,coef),s=mul(s,coef),np=mul(np,coef);
//	printf("%d %d %d\n",f,s,np);
	return pi(f,inc(s,P-np));
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	pi p=calc(1,n,0);
	printf("%d\n",inc(p.fi,p.se));
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int x,a,b;
    scanf ("%d %d %d", &x, &a, &b);
    int ans1, ans2;
    
    if(x-a<0){
        ans1 = (x-a) * -1; //998
    } else if(x-a>=0){
        ans1 = x-a;
    }
    
    if(x-b<0){
        ans2 = (x-b) * -1; //999
    } else if(x-b>=0){
        ans2 = x-b;
    }

    if(ans1 < ans2){
        printf("A\n");
    } else {
        printf("B\n");
    }

}

Measured memory_bytes: 1628
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll n,k;
    cin>>n>>k;
    cout<<min(n%k,k-n%k);


}

Measured memory_bytes: 256
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f,N=2e5+5;
ll n,T;
struct node{
	ll x,y;
}a[N];
bool cmp(node x,node y)
{
	return y.x*(x.y+1)<x.x*(y.y+1);
}
bool cmp2(node x,node y)
{
	return x.y<y.y;
}
ll dp[N][35];
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	ll i,j;
	cin>>n>>T;
	for(i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a[i].x,&a[i].y);
	}
	sort(a+1,a+n+1,cmp);
	
	ll tot=n;
	while(a[tot].x==0&&tot)
		tot--;
	ll	m=min(tot,(ll)log2(T)+1);
	for(i=0;i<=tot;i++)
		for(j=1;j<=m;j++)
		{
			dp[i][j]=T+1;
		}
	for(i=1;i<=tot;i++)
		for(j=1;j<=m;j++)
		{
			dp[i][j]=dp[i-1][j];
			dp[i][j]=min(dp[i][j],dp[i-1][j-1]+1+(dp[i-1][j-1]+1)*a[i].x+a[i].y);
		}


//	for(i=1;i<=tot;i++)
//	{
//		for(j=1;j<=m;j++)
//		{
//			cout<<dp[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	
	sort(a+tot+1,a+n+1,cmp2);
	
//	for(i=1;i<=n;i++)
//		cout<<a[i].x<<" "<<a[i].y<<endl;	
	ll ans=0;
	for(i=0;i<=m;i++)
	{
		ll t=dp[tot][i],s=i;
		if(t>T) break;
		for(j=tot+1;j<=n;j++)
		{
			if(t+1+a[j].y<=T)
			{
				s++;
				t=t+1+a[j].y;
			}
			else
				break;
		}
		ans=max(ans,s);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 58112
package main

import "fmt"

func main() {
	var N int
	var S string
	fmt.Scan(&N)
	fmt.Scan(&S)
	ans := 0
	for n := 0; n < N-2; n++ {
		if S[n] == 65 && S[n+1] == 66 && S[n+2] == 67 {
			ans ++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
/*
 * Matheus Oliveira
 * 09:09:18 12/04/2020
 * c.cpp
*/

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

#define EPS
#define INF
#define MAXN
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define sc(x) scanf("%d", &x);
#define sc2(x, y) scanf("%d %d", &x, &y);
#define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define debug(x) printf("%s: %d\n", #x, x);
#define debugarr(x, bg, ed) printf("%s: ", #x); for(int i = bg; i < ed; i++) printf("%d%c", x[i], (i == ed-1) ? '\n' : ' ');

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

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

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

	int ans = 0;
	for(int a = 1; a <= k; a++) {
		for(int b = 1; b <= k; b++) {
			for(int c = 1; c <= k; c++) ans += gcd(a, gcd(b, c));
		}
	}

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

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

int main(){


    string s; cin >> s;
    int w; cin >> w;
    string ans;
    for(signed int i = 0; i < s.size(); i++){
        if(i % w == 0){
            ans += s[i];
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int D; cin>>D;
  if (D == 22) cout<<"Christmas Eve Eve Eve"<<endl;
  else if (D==23) cout<<"Christmas Eve Eve"<<endl;
  else if (D==24) cout<<"Christmas Eve"<<endl;
  else cout<<"Christmas"<<endl;
  return 0;
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	string s ;
	cin>> s ;
	int n = s.size();
	int l = 0 , r = n -1 ;
	int ans = 0 ;
	bool flag = true;
	while(flag){
		if(l == r || l > r  ) break;
		char cl = s[l] , cr = s[r];
		if(cl == cr){
			l ++ ;
			r -- ;
		}else if(cl == 'x' || cr == 'x'){
			if(cl == 'x' ){
				l++;
			}else{
				r -- ;
			}
			ans ++ ;
		}else{
			flag = false;
			cout << -1 << endl;
			return 0 ;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
a,b,c = map(int, input().split())
d,e,f = map(int, input().split())
g,h,i = map(int, input().split())
n = int(input())

ab = False
bb = False
cb = False
db = False
eb = False
fb = False
gb = False
hb = False
ib = False

for k in range(n):
  inp = int(input())
  if inp == a:
    ab = True
  elif inp == b:
    bb = True
  elif inp == c:
    cb = True
  elif inp == d:
    db = True
  elif inp == e:
    eb = True
  elif inp == f:
    fb = True
  elif inp == g:
    gb = True
  elif inp == h:
    hb = True
  elif inp == i:
    ib = True
    
if ab and bb and cb:
  print('Yes')
elif db and eb and fb:
  print('Yes')
elif gb and hb and ib:
  print('Yes')
elif ab and db and gb:
  print('Yes')
elif bb and eb and hb:
  print('Yes')
elif cb and fb and ib:
  print('Yes')
elif ab and eb and ib:
  print('Yes')
elif cb and eb and gb:
  print('Yes')
else:
  print('No')
    

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

ll calc1(ll s1, ll s2, ll mid){
  ll S1 = mid * s2;
  ll S2 = (s1-mid) * (s2/2);
  ll S3 = (s1-mid) * (s2 - s2/2);
  ll Smax = max(S1, max(S2, S3));
  ll Smin = min(S1, min(S2, S3));
  return Smax-Smin;
}

ll calc2(ll s1, ll s2, ll mid){
  ll S1 = mid * s2;
  ll S2 = (s1-mid)/2 * s2;
  ll S3 = (s1 - mid - (s1-mid)/2) * s2;
  ll Smax = max(S1, max(S2, S3));
  ll Smin = min(S1, min(S2, S3));
  return Smax-Smin;
}

int main()
{
  ll H,W;
  ll res=INF;
  cin >> H>>W;

  ll s1 = max(H,W);
  ll s2 = min(H,W);

  for(ll i=1;i<s1;i++){
    res = min(res, min(calc1(s1,s2,i),calc2(s1,s2,i)));
  }

  for(ll i=1;i<s2;i++){
    res = min(res, min(calc1(s2,s1,i),calc2(s2,s1,i)));
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    if (s[0]==s[1] || s[1]==s[2] || s[2]==s[3])
        cout<<"Bad"<<endl;
    else
        cout<<"Good"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int cnt = 0;
	for(int i=11; ; i+=10){
		bool prime = 1;
		for(int j=2; j*j<=i; j++){
			if(i % j == 0){
				prime = 0;
				break;
			}
		}
		if(prime){
			cnt++;
			cout << i << " ";
		}

		if(cnt >= n) break;
	}	
	return 0;
}

Measured memory_bytes: 256
// AOJ ALDS1_3_A Stack
// 2018.4.27 bal4u

#include <stdio.h>
#include <ctype.h>

int stack[102]; int top;
char buf[2000];

int main()
{
	int  v1, v2;
	char *p;

	fgets(p=buf, 500, stdin);
	top = 0;
	while (*p >= ' ') {
		while (isspace(*p)) p++;
		if (isdigit(*p)) {
			v1 = 0;
			while (isdigit(*p)) v1 = 10*v1 + (*p++ & 0xf);
			stack[top++] = v1;
		} else {
			v1 = stack[--top];
			v2 = stack[--top];
			if      (*p == '+') v2 += v1;
			else if (*p == '-') v2 -= v1;
			else if (*p == '*') v2 *= v1;
			stack[top++] = v2;
			p++;
		}
	}
	printf("%d\n", stack[--top]);
	return 0;
}



Measured memory_bytes: 2100
n, m = map(int, input().split())
prices = []
keymap = []
for _ in range(m):
    a, b = map(int, input().split())
    prices.append(a)
    c = list(map(int, input().split()))
    state = 0
    for ck in c:
        state |= 1 << ck - 1
        # print(format(state, "b"))
    keymap.append(state)

# print(keymap)

dp = [float("inf")] * (1 << n)  # 2 ** n
dp[0] = 0

for price, keyto in zip(prices, keymap):
    # print("--- step start ---")
    # print(dp)
    dp_new = dp[:]
    for s, d in enumerate(dp):
        # print("=== DP ===")
        # print("s:", format(s, "b"))
        # print("c:", format(keyto, "b"))
        dp_new[s | keyto] = min(d + price, dp_new[s | keyto])

    dp = dp_new
    # print(dp)

cost = dp[-1]
print(cost if cost != float("inf") else -1)

Measured memory_bytes: 50008
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	if(y==0) return x;
	return gcd(y,x%y);	
}

ll lcm(ll x, ll y) {
	ll z=gcd(x,y);
	return x/z*y;
}

int main()
{
	ll n,a,ans=0;
	cin >> n;
	rep(i,n){
		cin >> a;
		ans+=a-1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int t,a,b,c,mini;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b)
	{t=a;a=b;b=t;}
	if(a>c)
	{t=a;a=c;c=t;}
	if(b>c)
	{t=c;c=b;b=t;}
	mini=c-a;
	printf("%d",mini);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int n, m;
	cin >> n >> m;
	int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
	cout << ans;
	return 0;
}

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

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

//素数判別じゃなかったです
//ll s( ll n){
//	bool k[n+1]={};
//	ll ans=0;
//	for(ll i=2; i<n; i++){
//		if(!k[i]){
//			ll d=i;
//			if(n%i==0){
//				ans++;
//				cout<<i<<endl;
//			}
//			//cout<<i<<" "<<ans<<endl;
//			while(d<=n){
//				k[d]=true;
//				d+=i;
//			}
//		}
//		///cout<<ans<<endl;
//	}
//	//cout<<ans<<endl;
//	return ans;
//}
		


int main(){
	ll n,a,b;
	cin>>a>>b;
	n=u( max(a,b),min(a,b));
	//cout<<n<<endl;
	ll ans=1;
	ll k=2;
	//ans+=s(n);
	//ルートn以上の素因数は１コまで
	while(n>=k*k){
		if(n%k==0) ans++;
		
		
		while(n%k==0){
			n/=k;
		}
		//cout<<n<<endl;
		k++;
	}
	if(n>1){
		ans++;
	}
	//cout<<n<<endl;
	cout<< ans <<endl;
}

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

int main(){
    int N,T,A;
    cin >> N >> T >> A;
    A *= 1000;
    T *= 1000;
    int x ,Abs;
    int mn = 100000000, mnd = -1; 
    rep(i,N){
        cin >> x;
        Abs = abs((T-x*6)-A);
        if(mn > Abs){
            mn = Abs;
            mnd = i;
        }
    }

    cout << mnd + 1 << endl;
}   

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  long long n;
  cin>>n;
  long long arr[n];
  for(long long i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  long long sum=0;
  for(long long i=0;i<n-1;i++)
  {
    if(arr[i]>arr[i+1])
    {
      sum+=arr[i]-arr[i+1];
      arr[i+1]+=arr[i]-arr[i+1];
    }
  }
  cout<<sum<<"\n";
}

Measured memory_bytes: 5188
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int n = sc.nextInt();

		long[] task = new long[n];
		long mod = 10000000000l;

		for(int i=0;i<n;i++)task[i]=(sc.nextLong()+sc.nextLong()*mod);

		Arrays.sort(task);
		long sum = 0;
		boolean flg = true;

		for(int j=0;j<n;j++){
			sum += task[j]%mod;
			if(sum>task[j]/mod){
				flg = false;
				break;
			}
		}

		// 出力
		System.out.println(flg?"Yes":"No");
	}
}

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

int main()
{
    int x, y;

    while(true){
        cin >> x >> y;

        if( x==0 and y==0 )
            break;
        else if( x < y )
            cout << x << ' ' << y << endl;
        else
            cout << y << ' ' << x << endl;
    }

    return 0;
}


Measured memory_bytes: 3096
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    ll n, k;
    cin >> n >> k;

    vector<pair<ll,ll>> l(n);
    for(int i = 0; i < n; i++){
        cin >> l[i].first >> l[i].second;
    }
    sort(l.begin(), l.end());

    ll index = 0;
    for(int i = 0; i < n; i++){
        if(index + l[i].second >= k){
            cout << l[i].first << endl;
            return 0;
        }
        index += l[i].second;
    }
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

int main() {
  int W, H, N;
  std::cin >> W >> H >> N;
  std::vector<int> x(N), y(N), a(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> x[i] >> y[i] >> a[i];
  }

  int x1, x2, y1, y2;
  x1 = y1 = 0;
  x2 = W;
  y2 = H;
  for (int i = 0; i < N; ++i) {
    if ( a[i] == 1 ) {
      if ( x1 < x[i] ) x1 = x[i];
    } else if ( a[i] == 2 ) {
      if ( x2 > x[i] ) x2 = x[i];
    } else if ( a[i] == 3 ) {
      if ( y1 < y[i] ) y1 = y[i];
    } else if ( a[i] == 4 ){
      if ( y2 > y[i] ) y2 = y[i];
    }
  }
  int area = std::max((x2 - x1), 0) * std::max((y2 - y1), 0);
  if ( area <= 0 ) area = 0;
  std::cout << area << std::endl;

  return 0;
}


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

int n,m;
int link[9][9]={};

int dfs(int v,int d,int* visit){
	if(d==n-1) return 1;
	int vis[9];
	for(int i=0;i<9;i++) vis[i]=visit[i];
	vis[v]=1;
	int res=0;
	for(int i=1;i<=n;i++){
		if(visit[i]) continue;
		if(link[v][i]) res+=dfs(i,d+1,vis);
	}
	return res;
}

int main(){
	cin >> n >> m;
	for(int i=1;i<=m;i++){
		int a,b;
		cin >> a >> b;
		link[a][b]=1;
		link[b][a]=1;
	}
	int visit[9]={};
	cout << dfs(1,0,visit) << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,A[2][103],i,ans=0,j,t;
	cin>>N;
	for(i=0;i<N;i++)
		cin>>A[0][i];
	for(i=0;i<N;i++)
		cin>>A[1][i];
	for(i=0;i<N;i++){
		t=0;
		for(j=0;j<=i;j++)
			t=t+A[0][j];
		for(j=j-1;j<N;j++)
			t=t+A[1][j];
		if(t>ans) ans=t;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
if N == 1:
    print(1)
    exit()
D = []
for i in range(N):
    x, y = map(int, input().split())
    D.append((x, y))
D = sorted(D)

d = set()
for i in range(N):
    for j in range(N):
        d.add((D[i][0] - D[j][0], D[i][1] - D[j][1]))


d = list(d)
num = float('inf')
for p, q in d:
    if p == 0 and q == 0:
        continue
    used = [0] * N
    prex, prey = D[0][0], D[0][1]
    used[0] = 1
    tmp = 1
    for k in range(N - 1):
        for i in range(N):
            if used[i]:
                continue
            if D[i][0] - prex == p and D[i][1] - prey == q:
                prex = D[i][0]
                prey = D[i][1]
                used[i] = 1
                break
        else:
            tmp += 1
            for i in range(N):
                if not used[i]:
                    prex = D[i][0]
                    prey = D[i][1]
                    used[i] = 1
                    break
    num = min(tmp, num)

print(num)


Measured memory_bytes: 3444
#include <stdio.h>


int main(void){
	int N,A,B,c;
    scanf("%d %d", &A, &B);
    
    if(A>=13){
        printf("%d\n", B);
    }else if(A<6){
        printf("0");
    }else{
        printf("%d\n", B/2);
    }
}

Measured memory_bytes: 128
#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);
  }
  
  int flag = 1;
  int counter = 0;
  
  while(flag == 1){
    for(int i=0;i<N;i++){
      if(A.at(i)%2 == 1){
        flag = 0;
        break;
      }
      A.at(i) /= 2;
    }
    
    if(flag == 0) break;
    
    counter++;
  }
  
  
  cout << counter << endl;
  
  
}

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

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

	int n, k;
	cin >> n >> k;
	vector<int> V(n);
	rep(i, n)
		cin >> V.at(i);
	sort(V.begin(), V.end());
	int minv;
	minv = INT_MAX;
	rep(i, n - k + 1)
		minv = min(V.at(i + k - 1) - V.at(i), minv);
	cout << minv << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> i_i;

const int MX = 100;

int a, b;
int grid[MX][MX], req[2];

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> req[0] >> req[1];
    --req[0], --req[1];
    
    cout << "100 100\n";
    for (int i = 50; i < MX; ++i) {
        for (int j = 0; j < MX; ++j) {
            grid[i][j] = 1;
        }
    }

    for (int i = 0; i < 49; i += 2) {
        for (int j = 0; j < MX; j += 2) {
            if (req[1]) {
                grid[i][j] = 1;
                --req[1];
            }
        }
    }

    for (int i = 51; i < MX; i += 2) {
        for (int j = 0; j < MX; j += 2) {
            if (req[0]) {
                grid[i][j] = 0;
                --req[0];
            }
        }
    }

    for (int i = 0; i < MX; ++i) {
        for (int j = 0; j < MX; ++j) {
            if (grid[i][j]) cout << '#';
            else cout << '.';
        }
        cout << '\n';
    }
}


Measured memory_bytes: 3660
apart = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

n = int(input())
for i in range(1,n+1):
    b,f,r,v = map(int,input().split())
    apart[b-1][f-1][r-1] += v

for index,build in enumerate(apart) :
    for floor in build:
        for room in floor:
            print(" %d" % room,end="")
        print()
    if index != len(apart)-1:
        print("####################")


Measured memory_bytes: 5624
#include<stdio.h>
#include<string.h>

int main(){
  char s[11];
  int n,flag[3]={},cnt=0;
  scanf("%s",s);
  n=strlen(s);
  if(s[0]=='A')
    flag[0]=1;
  for(int i=2;i<n-1;i++)
    if(s[i]=='C')
      cnt++;
  if(cnt==1)
    flag[1]=1;
  cnt=0;
  for(int i=0;i<n;i++)
    if(s[i]<='z'&&s[i]>='a')
      cnt++;
  if(cnt==n-2)
    flag[2]=1;
  if(flag[0]&&flag[1]&&flag[2])
    printf("AC\n");
  else
    printf("WA\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>

using namespace std;

int combi(int n){
	return n*(n-1)/2;
}

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<int> x,y;
		x.push_back(0);
		y.push_back(0);

		for(int i=0;i<n;i++){
			int h;
			cin>>h;
			h+=y[i];
			y.push_back(h);
		}

		for(int i=0;i<m;i++){
			int w;
			cin>>w;
			w+=x[i];
			x.push_back(w);
		}
		//y=x+b → y-x=bとなる
		map<int,int> cnt;
		for(int i=0;i<n+1;i++){
			for(int j=0;j<m+1;j++){
				int diff=y[i]-x[j];
				cnt[diff]++;
			}
		}
		
		//全探索
		int ans=0;
		for(int i=-x[m];i<y[n]+1;i++){
			ans+=combi(cnt[i]);
		}
		
		cout<<ans<<endl;
	}
}

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

typedef long long ll;
const int MAX_N = 100000;

int main() {
	int N, A[MAX_N + 2] = {};

	std::cin >> N;
	for(int i = 1; i <= N; ++i) {
		std::cin >> A[i];
	}

	ll cumsum[MAX_N + 2] = {};
	for(int i = 1; i <= N + 1; ++i) {
		cumsum[i] = cumsum[i - 1] + std::abs(A[i] - A[i - 1]);
	}

	for(int i = 1; i <= N; ++i) {
		ll ans = cumsum[N + 1] - std::abs(A[i] - A[i - 1]) - std::abs(A[i + 1] - A[i]) + std::abs(A[i + 1] - A[i - 1]);
		std::cout << ans << std::endl;
	}

}


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

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0 ; i < 3 ; i++){
        if(s[i] == '1'){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
	string A,B,C;
	cin >> A;
	if (A.size()%2) {
		cout << "No";
		return 0;
	}
	for (size_t i = 0; i < A.size(); i+=2)
	{
		if (A.substr(i, 2) != "hi") {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   long[] a= new long[5];
   char[] c;
   for(int i=0;i<N;i++)
   {
     c = sc.next().toCharArray();
     if(c[0]=='M') a[0]++;
     else if(c[0]=='A') a[1]++;
     else if(c[0]=='R') a[2]++;
     else if(c[0]=='C') a[3]++;
     else if(c[0]=='H') a[4]++;
   }

   long sum = 0;
   
   for(int i=0;i<3;i++)
   {
     for(int k=i+1;k<4;k++)
     {
       for(int j=k+1;j<5;j++)
       {
         sum+= a[i]*a[k]*a[j];
       }
     }
   }
   System.out.println(sum);
 }
}

Measured memory_bytes: 47052