akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
  int x,y,a[7]={1,3,5,7,8,10,12},b[4]={4,6,9,11},c=2;
  char x1,y1;
  cin>>x>>y;
  for(int i=0;i<7;i++){
    if(x==a[i]) x1='a';
    if(y==a[i]) y1='a';
  }
  for(int i=0;i<4;i++){
    if(x==b[i]) x1='b';
    if(y==b[i]) y1='b';
  }
  if(x==2) x1='c';
  if(y==2) y1='c';
  if(x1==y1) cout<<"Yes";
  else cout<<"No";
  
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a > max(b, c)){
        if(a == b + c){
            cout << "Yes" << endl;
            return 0;
        }
    }else if(b > max(a, c)){
        if(b == a + c){
            cout << "Yes" << endl;
            return 0;
        }
    }else if(c > max(a, b)){
        if(c == a + b){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int[] xs = new int[n];
		int[] ys = new int[m];
		String msg = "No War";

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

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

		Arrays.sort(xs);
		Arrays.sort(ys);

		if (Math.max(x, xs[n - 1]) >= Math.min(y, ys[0])) {
			msg = "War";
		}
		System.out.println(msg);

	}
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
const int mod  = 998244353;
using namespace std;
const int d = 24 * 60;

int main(){
	int n, aux;
	vector<int>ps, v;
	cin >> n;
	ps.push_back(0);

	for (int i=0; i<n; i++){
		cin >> aux;
		v.push_back(aux);
	}
	for (int i=0; i<n; i++){
		ps.push_back(v[i] + ps[i]);
	}

	int differ = 10000000;

	for (int i=1; i<=100; i++){
		differ = min(differ, abs((ps[i]) - (ps[n] - ps[i])));
	}
	cout << differ << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n,fact,count=0;
    while(1){
        scanf("%d",&n);
        if(n==0)
            break;
        if(n>=5*5*5*5*5*5)
            count+=n/(5*5*5*5*5*5);
        if(n>=5*5*5*5*5)
            count+=n/(5*5*5*5*5);
        if(n>=5*5*5*5)
            count+=n/(5*5*5*5);
        if(n>=5*5*5)
            count+=n/(5*5*5);
        if(n>=5*5)
            count+=n/(5*5);
        if(n>=5)
            count+=n/(5);
        printf("%d\n",count);
        count=0;
    }
    return 0;
}

Measured memory_bytes: 1848
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, X, Y; cin >> N >> X >> Y;

    vector<int> D(N);
    for (int i = 1; i <= N; i++) {
        for(int j = i + 1; j <= N; j++) {
            int d = j - i;
            if (i != X && j != Y) {
                d = min(d, abs(i - X) + abs(j - Y) + 1);
            } else {
                if (i == X && j != Y) {
                    d = min(d, abs(j - Y) + 1);
                } else if (j == Y && i != X) {
                    d = min(d, abs(i - X) + 1);
                } else {
                    d = 1;
                }
            }
            // cout << "i : " << i << " j : " << j << " d : " << d << endl;
            D[d]++;
        }
    }

    REP(i, 1, N) cout << D[i] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <limits>
#include <map>

int main(){
	int n,m;
  	std::cin >> n >> m;
  	if(n!=m){
      std::cout<<"No"<<std::endl;
    }else{
      std::cout<<"Yes"<<std::endl;
    }
  	return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d", $in_n, $in_m);
for($i = 0; $i < $in_m; $i++){
    fscanf(STDIN, "%d %d", $in_a[$i], $in_b[$i]);
    $next[$in_a[$i]][] = $in_b[$i];
    $next[$in_b[$i]][] = $in_a[$i];
}
$nokori = $in_n - 1;
$ans = "Yes";
$mitisirube = array_fill(0, $in_n, 0);
$mitisirube[1] = 1;

//for($i = 1; $i <= $in_n; $i++) {
//    var_dump($next[$i]);
//}

$next_hop_room[] = 1;
$next2_hop_room = [];
do{
    foreach ($next_hop_room as $now_room) {
//        var_dump($now_room);
//        var_dump($next[$now_room]);
        foreach ($next[$now_room] as $next_room) {
//            echo "now$now_room next$next_room nokori$nokori\n";
            if($mitisirube[$next_room] == 0) {
                $mitisirube[$next_room] = $now_room;
                $next2_hop_room[] = $next_room;
                $nokori--;
//                echo "now$now_room next$next_room nokori$nokori mitituika.\n";
//                var_dump($next2_hop_room);
            }
        }
    }
//    var_dump($next2_hop_room);
    if(count($next2_hop_room) == 0){
        $ans = "No";
        $nokori = -1;
    }else {
        $next_hop_room = $next2_hop_room;
        $next2_hop_room = [];
    }
}while($nokori > 0);

echo "$ans\n";
for($i = 2; $i <= $in_n; $i++) {
    echo "$mitisirube[$i]\n";
}


Measured memory_bytes: 92940
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<vector>
#include<iostream>
#include<set>
#include<map>
#include<algorithm>
using namespace std;




int main() {
	int n;
	cin >> n;
	
	map<string,int> ma;
	string s;
	for(int i=0;i<n;++i){
		cin >> s;
		if(ma.find(s) == ma.end()) ma[s] = 1;
		else ma[s]++;
	}
	
	int mv = 0;
	for(auto itr = ma.begin(); itr != ma.end(); ++itr) {
        string key =  itr->first;
		int value = itr->second;
		mv = max(mv,value);
		//cout << key << " " << value <<endl;
    }
	
	vector<string> vs;
	for(auto itr = ma.begin(); itr != ma.end(); ++itr) {
        string key =  itr->first;
		int value = itr->second;
		if(mv== value){
			//cout << "mv" << mv << " " << key << " " << value <<endl;
			vs.push_back(key);
		}
    }
	
	sort(vs.begin(),vs.end());
	
	for(auto v:vs){
		//cout << "--" <<endl;
		cout << v <<endl;
	}

	
	
    return 0;
}


Measured memory_bytes: 24176
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

n = int(input())

def func(n):
    rtn = 0
    for i in range(1,n+1):
        if (n % i == 0):
            rtn += 1
    return rtn

ans = 0
for i in range(1, n+1,2):
    if 8 == func(i):
        ans+=1
print(ans)


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N; cin >> N;
  int X[N]; rep(i,N) cin >> X[i];
  int result = INF;
  repr(i,0,101) {
    int tmp = 0;
    rep(j,N) tmp += pow(X[j]-i,2);
    result = min(result,tmp);
  }
  cout << result << endl;
  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> x(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i);
  }
  
  int ans = INT_MAX;
  for (int i = 0; i <= N - K; i++) {
    int d = min(abs(x.at(i)), abs(x.at(i + K - 1)));
    d += x.at(i + K - 1) - x.at(i);
    if (ans > d) ans = d;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
pair<long long, int> P = make_pair(1, 0);
vector<vector<int>> child(vector<vector<int>> &E, int r){
  int N = E.size();
  vector<vector<int>> c(N);
  queue<int> Q;
  Q.push(r);
  while (!Q.empty()){
    int v = Q.front();
    Q.pop();
    for (int w : E[v]){
      if (c[w].empty()){
        c[v].push_back(w);
        Q.push(w);
      }
    }
  }
  return c;
}
long long modpow(long long a, long long b){
	a %= MOD;
	long long res = 1;
	while (b > 0){
		if (b % 2 == 1) res = res * a % MOD;
		a = a * a % MOD;
		b = b / 2;
	}
	return res;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
long long moddiv(long long a, long long b){
  return a * modinv(b) % MOD;
}
vector<long long> mf;
long long modfact(long long n){
	if (n < mf.size()){
		return mf[n];
	} else {
		if (mf.empty()) mf.push_back(1);
		long long res = mf.back();
		for (int i = mf.size(); i <= n; i++){
			res = res * i % MOD;
			mf.push_back(res);
		}
		return res;
	}
}
long long modbinom1(long long n, long long r){
	long long res;
	res = modfact(n);
	res = moddiv(res, modfact(r));
	res = moddiv(res, modfact(n - r));
	return res;
}
pair<long long, int> add(pair<long long, int> A, pair<long long, int> B){
  return make_pair((A.first * B.first) % MOD * modbinom1(A.second + B.second, B.second) % MOD, A.second + B.second);
}
pair<long long, int> sub(pair<long long, int> A, pair<long long, int> B){
  return make_pair(moddiv(A.first, B.first * modbinom1(A.second, B.second) % MOD), A.second - B.second);
}
pair<long long, int> root(pair<long long, int> A){
  return make_pair(A.first, A.second + 1);
}
pair<long long, int> dfs1(vector<pair<long long, int>> &dp, vector<vector<int>> &c, int v){
  for (int w : c[v]) dp[v] = add(dp[v], root(dfs1(dp, c, w)));
  return dp[v];
}
void dfs2(vector<pair<long long, int>> &dp, vector<vector<int>> &c, int v){
  for (int w : c[v]){
    dp[w] = add(dp[w], root(sub(dp[v], root(dp[w]))));
    dfs2(dp, c, w);
  }
}
int main(){
  int N;
  cin >> N;
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    E[x].push_back(y);
    E[y].push_back(x);
  }
  vector<vector<int>> c = child(E, 0);
  vector<pair<long long, int>> dp(N, P);
  dfs1(dp, c, 0);
  dfs2(dp, c, 0);
  for (int i = 0; i < N; i++){
    cout << dp[i].first << endl;
  }
}

Measured memory_bytes: 27248
// C - HonestOrUnkind2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int A[15], X[15][15], Y[15][15];

int main(){
	int N; scanf("%d",&N);
	rp(i, 0, N){ scanf("%d",A+i); rp(j, 0, A[i]){ scanf("%d%d",X[i]+j,Y[i]+j); X[i][j]--; } }

	int ans = 0;
	for(int ok=1, bits=1; bits<1<<N; ++bits, ok=1){
		for(int i=0; i<N && ok; ++i)
			if((bits>>i)&1)
				for(int j=0; j<A[i] && ok; ++j) if(((bits>>X[i][j])&1) != Y[i][j]) ok = 0;
		if(ok) ans = max(ans, (int)bitset<16>(bits).count());
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int N, L;cin >> N >> L;
  vector<string> v(N);
  rep(i,N) cin >> v[i];

  sort(ALL(v));
  rep(i,N) cout << v[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import math
def main():
  n = int(input())
  array=[]
  ans=0
  for i in range(1,n+1,2):
    num=0
    for j in range(1,i+1,2):
      if i%j==0:
        num+=1
    if num==8:
      ans+=1
  print(ans)
main()

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

using namespace std;
ll ma=1000000007;
ll power(ll p,ll t){
if(t==0)
    return 1;
ll y=power(p,t/2);
y=(y*y)%ma;
if(t%2==1)
    y=(y*p)%ma;
return y;
}






 int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string a;
cin>>a;
for(int i=0;i<3;i++)
if(a[i]==a[i+1]){
    cout<<"Bad"<<endl;
    return 0;
}
cout<<"Good"<<endl;
}











Measured memory_bytes: 256
//////////////////////////
//      _        ____   //
//  U  /"\  u U /"___|  //
//   \/ _ \/  \| | u    //
//   / ___ \   | |/__   //
//  /_/   \_\   \____|  //
//   \\    >>  _// \\   //
//  (__)  (__)(__)(__)  //
//  Compro by NULL_CT©  //
//////////////////////////
// STL libs
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(I, LIM) for (int I = 0; I < (LIM); I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;

constexpr int MOD = 10000007;
constexpr long INF = LONG_MAX;

vector<long> divisor(long n) {
  vector<long> head, tail;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      head.push_back(i);
      if (i * i != n)
        tail.push_back(n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return (head);
}

struct init {
  init() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // cout<<fixed<<setprecision(20);
  }
} init;

/*----------------------------*/

int main() {
  long long x,k,d;
  cin>>x>>k>>d;
  x=llabs(x);

  if(k <= x/d){//往復しないパターン
    cout<<x-k*d<<"\n";
    return 0;
  }
  k=k-x/d;
  x%=d;
  k%=2;
  if(k == 0){
    cout<<x<<"\n";
    return 0;
  }else{
    cout<<llabs(x-d)<<"\n";
    return 0;
  }
}


Measured memory_bytes: 3148
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
 
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(c-1>=a+b)cout << b+a+b+1 << endl;
  else cout << b+c << endl;
return 0;}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<n;i++)
#define ll long long
#define ld long double
#define pi 3.1415926535897932384626433832795028841971693993
#define mod 1000000007
#define MOD mod
#define sec setprecision
#define RAND_MAX 0x7fffffff
using namespace std;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int ketasuu(ll h) {
	if (h < 0)return(-(ketasuu(-h)));
	else if (h < 10)return(1);
	else return(1 + ketasuu(h / 10));
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a)%mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	
}
int main() {
	int n;
	cin >> n;
	int k = n % 100;
	int h = n / 100;
	if (h < 13 && k < 13&&k>0&&h>0)cout << "AMBIGUOUS" << endl;
	else if (h < 13&&h>0)cout << "MMYY" << endl;
	else if (k < 13&&k>0)cout << "YYMM" << endl;
	else cout << "NA" << endl;
}

Measured memory_bytes: 256
package main

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

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

	n := nextInt(sc)
	x := make([]float64, n)
	y := make([]float64, n)
	for i := int64(0); i < n; i++ {
		x[i] = nextFloat(sc)
	}
	for i := int64(0); i < n; i++ {
		y[i] = nextFloat(sc)
	}

	fmt.Println(minkowski(x, y, 1.0))
	fmt.Println(minkowski(x, y, 2.0))
	fmt.Println(minkowski(x, y, 3.0))
	fmt.Println(chebyshev(x, y))
}

func minkowski(x []float64, y []float64, p float64) float64 {
	var s float64
	for i := 0; i < len(x); i++ {
		s += math.Pow(math.Abs(x[i]-y[i]), p)
	}
	return math.Pow(s, 1.0/p)
}

func chebyshev(x []float64, y []float64) float64 {
	var m float64
	for i := 0; i < len(x); i++ {
		c := math.Abs(x[i] - y[i])
		if c > m {
			m = c
		}
	}
	return m
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextFloat(sc *bufio.Scanner) float64 {
	i, err := strconv.ParseFloat(nextString(sc), 64)
	if err != nil {
		panic(err)
	}
	return i
}



Measured memory_bytes: 1128
import collections
N = int(input())
A = sorted([int(i) for i in input().split()])
C = collections.Counter(A)
tested = [True for i in range(10**7+1)]

ans = 0
for i in range(N):
    if tested[A[i]] is True:
        for j in range(A[i], 10**6+1, A[i]):
            tested[j] = False
        if C[A[i]] == 1:
            ans += 1
print(ans)


Measured memory_bytes: 300016
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

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

bool check(int h, int w, int n, vector<string> a) {
	for (;;) {
		for (int j = 0; j < w; j++)
			for (int i = h - 1; i >= 0; i--) {
				if (a[i][j] == '.') continue;
				int tmp = a[i][j];
				a[i][j] = '.';
				for (int i = h - 1; i >= 0; i--)
					if (a[i][j] == '.') {
						a[i][j] = tmp;
						break;
					}
			}
		vector< vector<bool> > b(h, vector<bool>(w));
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w;) {
				int _j;
				for (_j = j + 1; _j < w && a[i][_j] == a[i][j]; _j++);
				if (a[i][j] != '.' && _j - j >= n)
					for (int k = j; k < _j; k++)
						b[i][k] = true;
				j = _j;
			}
		for (int j = 0; j < w; j++)
			for (int i = 0; i < h;) {
				int _i;
				for (_i = i + 1; _i < h && a[_i][j] == a[i][j]; _i++);
				if (a[i][j] != '.' && _i - i >= n)
					for (int k = i; k < _i; k++)
						b[k][j] = true;
				i = _i;
			}
		bool flag = false;
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++) {
				if (b[i][j]) {
					a[i][j] = '.';
					flag = true;
				}
			}
		if (!flag) {
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++)
					if (a[i][j] != '.') return false;
			return true;
		}
	}
}

int main() {
	int h, w, n; cin >> h >> w >> n;
	vector<string> a(h);
	for (int i = 0; i < h; i++) cin >> a[i];
	for (int i = 0; i < h; i++)
		for (int j = 0; j + 1 < w; j++) {
			swap(a[i][j], a[i][j + 1]);
			if (check(h, w, n, a)) {
				cout << "YES" << endl;
				return 0;
			}
			swap(a[i][j], a[i][j + 1]);
		}
	cout << "NO" << endl;
}

Measured memory_bytes: 1212
fn main() {
    let n: usize = read();
    let mut ok: HashSet<(char, usize)> = HashSet::new();
    for _ in 0..n {
        ok.insert((read::<String>().chars().next().expect("wrong"), read()));
    }
    for c in ['S', 'H', 'C', 'D'].iter() {
        for i in 1..14 {
            if !ok.contains(&(*c, i)) {
                println!("{} {}", c, i);
            }
        }
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: isize = 1000000007;

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

// =========



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

string s;
int p;

int expr();

int num() {
  int res = 0;
  while (p < s.size() && '0' <= s[p] && s[p] <= '9') {
    res *= 10;
    res += s[p] - '0';
    p++;
  }
  return res;
}

int factor() {
  int res = 0;
  if (s[p] == '(') {
    p++;
    res = expr();
    p++;
  } else {
    res = num();
  }
  return res;
}

int term() {
  int res = factor();
  while (p < s.size()) {
    if (s[p] == '*') {
      p++;
      res *= factor();
    } else if (s[p] == '/') {
      p++;
      res /= factor();
    } else {
      break;
    }
  }
  return res;
}

int expr() {
  int res = term();
  while (p < s.size()) {
    if (s[p] == '+') {
      p++;
      res += term();
    } else if (s[p] == '-') {
      p++;
      res -= term();
    } else {
      break;
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    cin >> s;
    p = 0;
    cout << expr() << endl;
  }
}



Measured memory_bytes: 3060
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i,_ := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	fmt.Println(a[len(a) - 1] - a[0])
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <set>

#define rep2(i, b, n) for(int i=b; i < n; ++i)
#define repm(i, b, n) for(int i=b; i > n; --i)
#define rep(i, n) rep2(i, 0, n)
#define sz(v) v.size()
#define mk(x, y) make_pair(x, y)
#define fst first
#define scd second
#define MEMSET(x, n) memset(x, n, sizeof(x))
#define MEMZERO(x) MEMSET(x, 0)
#define URU(y) (!(y % 4) && y % 100 || !(y % 400))

using namespace std;

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

struct Line
{
	double l;
	double r;
	int num;
};

enum Check
{
	LOW = 0,
	MID,
	HIGH,
};

double cross_product( float x1, float y1, float x2, float y2 )
{
	return ((x1 * y2) - (x2 * y1));
}

inline Check inRange( Line l, Line h, double x, double y, double w )
{
	double v1, v2;
	
	v1 = cross_product(w, (l.r - l.l), x, (y - l.l));
	v2 = cross_product(w, (h.r - h.l), x, (y - h.l));
	
	if (0 < v1 && 0 < v2)
		return HIGH;
	if (0 > v1 && 0 > v2)
		return LOW;
	else
		return MID;
}

int main( void )
{
	int n, m, w, h, S;
	Line T[30010];
	int N1[30010], S1[30010];
	
	while ( cin >> n >> m >> w >> h >> S, n | m | w | h | S )
	{
		MEMZERO(T);
		
		rep2 (i, 1, (m + 1))
		{
			cin >> T[i].l >> T[i].r;
		}
		
		rep (i, n)
		{
			double x, y;
			cin >> x >> y;
			
			int low = 1, high = m;
			while (low <= high)
			{
				int mid = (low + high) / 2;
				Check c = inRange(T[mid-1], T[mid], x, y, (double)w);
				
				if (c == LOW)
					high = mid;
				else if (c == HIGH)
					low = mid + 1;
				else // c == Check::MID
				{
					// cout << mid << endl;
					++T[mid].num;
					break;
				}
			}
/*
			rep2 (j, 1, (m + 1))
			{
				if (inRange(T[j-1], T[j], x, y, (double)w))
				{
					++T[j].num;
					break;
				}
			}
*/
		}
		
		int ans = n, sum = 0;
		
		rep (i, (m + 1))
		{
			sum += T[i].num;
			N1[i] = sum;
			if (ans <= sum)
				break;
			if ((S * 2) <= (S1[i] = ((T[i].l + T[i].r) * w)))
			{
				ans = sum;
				break;
			}
		}
		// cout << ans << endl;
/*
		sum = 0;
		repm (i, m, 0)
		{
			sum += T[i].num;
			N2[i] = sum;
			if (ans <= sum)
				break;
			if((S * 2) <= (S2[i] = ((2 * h - (T[i-1].l + T[i-1].r)) * w)))
			{
				ans = sum;
				break;
			}
		}
*/
		// cout << ans << endl;
		
		sum = 0;
		rep2 (i, 0, m)
		{
			if (ans <= N1[i])
				break;
			int sub_sum = 0;
			repm (j, m, (i + 1))
			{
				sub_sum += T[j].num;
				if (ans <= (N1[i] + sub_sum))
					break;
				if ((S * 2) <= (((2 * h - (T[j-1].l + T[j-1].r)) * w) + S1[i]))
				{
					ans = N1[i] + sub_sum;
					break;
				}
			}
		}

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

Measured memory_bytes: 2096
# -*- coding: utf-8 -*-
 
S = input()

if ( S[0]=='R' ):
  # R
  if ( S[1]=='R' ):
    # RR
    if ( S[2]=='R' ):
      # RRR
      print(3)
    else:
      # RRS
      print(2)
  else:
    # RS_
    print(1)
# 0
else:
  if ( S[1]=='R' ):
    # SR
    if ( S[2]=='R' ):
      # SRR
      print(2)
    else:
      # SRS
      print(1)
  else:
    # SS
    if ( S[2]=='R' ):
      # SSR
      print(1)
    else:
      # SSS
      print(0)


Measured memory_bytes: 9052
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
    ll x, y;
    cin >> x >> y;

    if(x*2>y) {
        cout << '1' << endl;
        return 0;
    }

    ll cnt=0;
    for(ll i=x; i<=y; i*=2) {
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main()
{
	long long n,jwb=0,l,r;
	cin >> n;
	while (n--)
	{
		cin >> l >> r;
		jwb += (r-l+1);
	}
	cout << jwb << endl;
	return 0;
}

Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

const int mod = 1e9 + 7;

long long pow(long long a, long long b, long long mod){
	a %= mod;
	long long res = 1;
	while(b){
		if(b & 1){res *= a;res %= mod;}
		b >>= 1;
		a = a * a % mod;
	}
	return res % mod;
}

int main(){
	FIO
	
	int a, b;
	cin >> a >> b;
	cout << pow(a, b, mod) << '\n';
	return 0;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
inline void chmax (int& a, int b) {
  if (a < b) a = b;
}
void err() {
  cout << -1 << '\n';
  exit(0);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> dp(394, -1);
  dp[0] = 0;
  while (n--) {
    int s, l, p;
    cin >> s >> l >> p;
    for (int i = s; i <= 393; i++) {
      int &crr = dp[i];
      for (int j = max(0, i - l); j <= i - s; j++) {
        int &prv = dp[j];
        if (prv == -1) continue;
        chmax(crr, prv + p);
      }
    }
  }
  int q;
  cin >> q;
  vector<int> que;
  while (q--) {
    int w;
    cin >> w;
    int ret = dp[w];
    if (ret == -1) err();
    que.push_back(ret);
  }
  for (int ret : que) {
    cout << ret << '\n';
  }
  return 0;
}


Measured memory_bytes: 3184
#include<iostream>
#include<algorithm>
using namespace std;
int gcd(int n,int m){
    if(n>m) swap(n,m);
    int temp;
    while(n>0){
        temp=n;
    if(m%temp==0) return n;
        n=m%n;
    if(n==0) break;
        m=temp;
    }
}
int main(){
    int n;
    cin>>n;
    long long sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                    sum+=gcd(gcd(i,j),k);
            }
        }
    }
    cout<<sum;

}

Measured memory_bytes: 3548
#include <cstdio>
using namespace std;
long long a,b;
int main()
{
	scanf("%lld%lld",&a,&b);
	for(long long i=1;i<=10000;i++)
	{
		if(i*8/100==a&&i/10==b)
		{
			printf("%lld",i);
			return 0;
		}
	}
	printf("-1");
	return 0;
}

Measured memory_bytes: 128
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;



void main() {
    int a, b;
    scan(a, b);

    if (a + b == 15) {
        writeln("+");
    }
    else if (a * b == 15) {
        writeln("*");
    }
    else {
        writeln("x");
    }
}












































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

//istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
//ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

vector<vector<int> > E;
bool v[200100];

int dfs(int n) {
	if(v[n]) return 0;
	v[n] = true;
	int res = 0;
	rep(i,E[n].size()) {
		res += dfs(E[n][i]);
	}
	return res;
}

int main() {
	int N, M;
	cin >> N >> M;
	E.resize(N+M);
	rep(i,N) {
		int K;
		cin >> K;
		rep(j,K) {
			int L;
			cin >> L;
			L = L-1 + N;
			E[L].push_back(i);
			E[i].push_back(L);
		}
	}
	dfs(0);
	bool f = true;
	for(int i = 0; i < N; i++) {
		if(!v[i]) f = false;
	}
	if(f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


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

int main() {
  int a,b,c;
  cin >> a>>b>>c ;
  int A=b-a,B=c-b;
  if(A==B){
    cout <<"YES"<<endl;
  }
  else{cout << "NO"<<endl;}
      
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = (int)1e7 + 7;
ll sum[MAX_N];
bool visit[MAX_N];

int main()
{
	memset(sum, 0LL, sizeof(sum));
	memset(visit, false, sizeof(visit));
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	for (int i = 1; i < MAX_N; ++i){
		sum[i] = sum[i-1] + (ll)i;
	} // end for

	ll N; cin >> N;

	vector<ll> res; res.clear();

	if (N == 1LL){
		res.push_back(1LL);
	}else
	if (N == 2LL){
		res.push_back(2LL);
	}else
	if (N == 3LL){
		res.push_back(2LL);
		res.push_back(1LL);

	}else{
		ll ans = (ll)(lower_bound(sum, sum + MAX_N, N) - sum);
		res.push_back(ans);
		visit[ans] |= true;
		ll remain = N - ans;
		ll curr = ans - 1LL;
		while(remain > 0LL){
			for (int i = curr; i > 0; --i){
				if (!visit[i] && remain - i >= 0LL){
					visit[i] |= true;
					res.push_back((ll)i);
					remain -= (ll)i;
					break;
				 } // end if
			} // end for
		} // end while
	} // end if

//	ll test = 0LL;
	rep (i, res.size()){
		cout << res[i] << endl;
//		test += res[i];
	} // end rep
//	cerr << "test: " << test << endl;		

	return 0;
}

Measured memory_bytes: 88320
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<vector<int> > xy(N, vector<int>(N, -1));
  REP(i, N){
    int A; cin >> A;
    REP(j, A){
      int x, y; cin >> x >> y; x--;
      xy[i][x] = y;
    }
  }
  int ans = 0;
  REP(i, 1 << N){
    vector<int> XY(N, 0);
    REP(j, N){
      if((i >> j) & 1) XY[j] = 1;
    }
    bool flag = true;
    REP(j, N){
      if(XY[j] == 1){
        REP(k, N){
          if(xy[j][k] == -1) continue;
          if(xy[j][k] != XY[k]) flag = false;
        }
      }
    }
    if(flag){
      int tmp = 0;
      for(auto j : XY) tmp += j; 
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():    
    from collections import deque
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    e = [[] for i in range(n)]

    for i in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        e[a].append([b,c])
        e[b].append([a,-c])


    dis = [float("INF")]*n

    def search(x):

        q = deque([])
        dis[x] = 0
        q.append(x)
        while q:
            now = q.popleft()
            for nex,d in e[now]:
                if dis[nex] == float("INF"):
                    dis[nex] = dis[now]+d
                    q.append(nex)
                else:
                    if dis[nex] != dis[now]+d:
                        print("No")
                        exit()
            
    for i in range(n):
        if e[i] and dis[i] == float("INF"):
            search(i)
    print("Yes")

if __name__ == "__main__":
    main()

Measured memory_bytes: 78888
// 問題の URL を書いておく
// 

#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(int, const char**)
{
    string s;
    cin >> s;
    if(s[0] >= 'a' && s[0] <= 'z')
    {
        cout << "a" << endl;
    }
    else
    {
        cout << "A" << endl;
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for(auto& i:mp)

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n+10),d(n+10),b(n+10);
  int tmp,dd;
  rep(i,k){
    cin >> dd;
    rep(j,dd){
      cin >> tmp;
      b[tmp] = 1;
    }
  }

  ll ans = 0;
  repr(i,1,n+1){
    if (b[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
from heapq import *

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

# 0 <= i <= N
# left_Nth_max_sum[i] == sum( sorted(As[:N+i], reverse=True)[:N] )
# right_Nth_min_sum[i] == sum( sorted(As[N+i:])[:N] )

left_Nth_max_sum = [0] * (N+1)
lpq = As[:N] # left priority queue
heapify(lpq)
left_Nth_max_sum[0] = sum(lpq)
for i in range(N):
    popped_A = heappushpop(lpq, As[N+i])
    left_Nth_max_sum[i+1] = left_Nth_max_sum[i] + As[N+i] - popped_A

right_Nth_min_sum = [0] * (N+1)
rpq = [-A for A in As[2*N:]]
heapify(rpq)
right_Nth_min_sum[N] = -sum(rpq)
for i in range(N-1, -1, -1):
    popped_A = -heappushpop(rpq, -As[N+i])
    right_Nth_min_sum[i] = right_Nth_min_sum[i+1] + As[N+i] - popped_A

"""
for i in range(N+1):
    assert left_Nth_max_sum[i] == sum( sorted(As[:N+i], reverse=True)[:N] )
    assert right_Nth_min_sum[i] == sum( sorted(As[N+i:])[:N] )
"""

print(max( (left_Nth_max_sum[i] - right_Nth_min_sum[i] for i in range(N+1)) ))

Measured memory_bytes: 117292
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9 + 7;
const ll LINF = 1LL << 60;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

int n, dp[50];
int dfs(int i) {
  if(dp[i] >= 0) return dp[i];
  if(i == 0 || i == 1) return dp[i] = 1;
  int res = dfs(i-1) + dfs(i-2);
  return dp[i] = res;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  rep(i,50) dp[i] = -1;
  cin >> n;
  cout << dfs(n) << '\n';
  return 0;
}


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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define int ll

int32_t main(){
    FAST
    int n; cin >> n;
    int sum;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        if(i == 0)sum = arr[i];
        else sum ^= arr[i];
    }
    for(int i = 0; i < n; i++){
        sum ^= arr[i];
        cout << sum << " ";
        sum ^= arr[i];
    }
    return 0;
}


Measured memory_bytes: 5052
#include <iostream>
using namespace std;
int main()
{
    // スペース区切りの整数の入力
    int n,a,b;
    cin >> n >> a >> b;
    
    //calcu
    int train = n * a;
    int taxi = b;
    //min
    int mine = min(train, taxi);
    
    cout << mine << endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
INF = float("inf")
def dijkstra(N, G, s):
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
    return dist

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

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

Q,K = map(int,input().split())

dist = dijkstra(N,edge,K-1)

for _ in range(Q):
    x,y = map(int,input().split())
    print(dist[x-1]+dist[y-1])

Measured memory_bytes: 47388
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll k,n ;
	cin >> k >> n ;
	vll a(n+1) ;
	for(int i=0;i<n;i++) cin >> a.at(i) ;
	a.at(n) = a.at(0)+k ;
	ll mx = 0 ;
	for(int i=0;i<n;i++){
		ll sub = a.at(i+1)-a.at(i) ;
		if(mx<sub) mx = sub ;
	}
	cout << k-mx << endl ;
}


Measured memory_bytes: 1792
N, M = map(int, input().split())
d = {}
for i in range(N):
    lst = list(map(int, input().split()))
    for a in range(1, len(lst)):
        if lst[a] in d:
            d[lst[a]] += 1
        else:
            d[lst[a]] = 1
ans = 0
for key in d:
    if d[key] == N:
        ans += 1
print(ans)

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

int main() {
  long n,ans=0;
  cin >> n;
  vector<long> a;
  for(long i=1;i*i<=n;i++) {
    if(n%i==0) {
      if(i!=1) a.push_back(i);
      if(i*i!=n) a.push_back(n/i);
    }
  }
  sort(a.begin(),a.end());
  for(long i=0;i<a.size();i++) {
    if(n%a[i]==0) {
      bool so=true;
      long aaa=sqrt(a[i]);
      for(long j=2;j*j<=a[i];j++) if(a[i]%j==0) so=false;
      for(long j=aaa-3;j<=aaa+3;j++) {
        if(j*j==a[i]) {
          if(!so) {
            so=true;
            for(long k=2;k*k<j;k++) if(j%k==0) so=false;
          }
        }
      }
      aaa=cbrt(a[i]);
      for(long j=aaa-3;j<=aaa+3;j++) {
        if(j*j*j==a[i]) {
          if(!so) {
            so=true;
            for(long k=2;k*k<j;k++) if(j%k==0) so=false;
          }
        }
      }
      for(long j=2;j<=1000;j++) {
        for(long k=4;pow(j,k)<=a[i];k++) {
          if(pow(j,k)==a[i]) {
            if(!so) {
              so=true;
              for(long l=2;l*l<j;l++) if(j%l==0) so=false;
            }
          }
        }
      }
      if(so) {
        n/=a[i];
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4108
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[210000];
int main(){
	ll m,n;
	cin>>m>>n;
	ll i,j;
	for(i=0;i<m;i++)
		cin>>a[i];
	if(n>=m)
		cout<<"0"<<endl;
	else{
		sort(a,a+m);
		ll s=0;
		for(i=0;i<m-n;i++)
			s+=a[i];
		cout<<s<<endl;
	}
}


Measured memory_bytes: 1792
f=lambda:[*map(int,input().split())]
n,k=f()
a=f()
a=[i*100 for i in a]
# Binary Search
def ok(x):
    c=0
    for i in a:
      c+=0--i//x
    return c<=n+k
l,r=0,10**11+1
while r-l>1:
  m=l+r>>1
  if ok(m): r=m
  else: l=m
t=0--r//100
print(t-ok(t-1) if t>1 else t)

Measured memory_bytes: 30848
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    string s;
    cin >> s;
    int ans = 9999;
    int len = s.size();

    char a = 'a';
    char z = 'z';


    srep(i,(int)a,(int)z+1){
        int count = 0;
        int mi = 0;
        rep(j,len){
            if((int)s[j]==i){
                mi = max(mi,count);
                count = 0;
            }else{
                count++;
            }
        }
        mi = max(mi,count);
        ans = min(ans,mi);
    }
    
    cout << ans << endl; 
    return 0;
}
 
 


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

int main () {
  int N;
  cin >> N;
  long long sum = 0;
  vector<long long>A(N);
  vector<long long>B(N);
     
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  
  for (int i = 0; i < N; i++) {
    B.at(i) = sum;
    sum += A.at(i);
  }
  
  vector<int>C(N,0);
  for (int i = 0; i < N; i++) {
    if (A.at(i) <= B.at(i)*2){
      C.at(i)++;
    }
  }
  
  int ans = 1;
  reverse(C.begin(), C.end());
  for (int i = 0; i < N; i++) {
    if (C.at(i) > 0){
      ans++;
    }
    else {
      break;
    }
  }
  
  cout << ans << endl;
}
  
  

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int n = in.nextInt();
        if (n == 0) {
            System.out.println(x);
            return;
        }
        
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = in.nextInt();
        }

        Arrays.sort(p);

        int dist = 0;
        while (true) {
            if (Arrays.binarySearch(p, x - dist) < 0) {
                System.out.println(x - dist);
                return;
            }
            if (Arrays.binarySearch(p, x + dist) < 0) {
                System.out.println(x + dist);
                return;
            }
            dist++;
        }
    }
}


Measured memory_bytes: 36032
#include<iostream>
using namespace std;
int main(){
  int K,A,B;
  cin>>K>>A>>B;
  int ans=0;
  for(int i=0;i<1000;i++){
    int k=K*i;
    if(A<=k&&k<=B)ans=1;
  }
  if(ans==1)cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}
  

Measured memory_bytes: 3652
n = int(input())
a = list(map(int, input().split()))
q = int(input())
d = dict()

for i in range(n):
    if a[i] not in d.keys():
        d[a[i]] = 1
    else:
        d[a[i]] += 1

s = sum([k * v for k, v in d.items()])

for i in range(q):
    b, c = list(map(int, input().split()))
    if b in d.keys():
        s += (c - b) * d[b]
        if c in d.keys():
            d[c] += d[b]
            d[b] = 0
        else:
            d[c] = d[b]
            d[b] = 0
    print(s)

Measured memory_bytes: 20880
#include <stdio.h>
int main(){
int n,m,temp;
scanf("%d%d",&n,&m);
int a[n+1][m+1];
for(int i=0;i<n;i++){
temp=0;
for(int j=0;j<m;j++){
scanf("%d",&a[i][j]);
temp+=a[i][j];
}
a[i][m]=temp;
}
for(int j=0;j<=m;j++){
temp=0;
for(int i=0;i<n;i++){
temp+=a[i][j];
}
a[n][j]=temp;
}
for(int i=0;i<=n;i++){
printf("%d",a[i][0]);
for(int j=1;j<=m;j++){
printf(" %d",a[i][j]);
}
printf("\n");
}

}

Measured memory_bytes: 2712