akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
	string s[n];
	cin>>s[0];
	for(int i=1;i<n;i++)
	{
		cin>>s[i];
		if(s[i][0]!=s[i-1][s[i-1].size()-1])
		{
			cout<<"No";
			return 0;
		}
		for(int j=0;j<i;j++)
		if(s[i]==s[j])
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
} 

Measured memory_bytes: 256
import java.util.*;

class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();
        int Times = ((int)(T+0.5)/A);
      
     
      System.out.println(B*Times);
    }
}

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

    int main()
    {
        long long int n,i;
        cin>>n;
        vector <long long int>a,b;
        a.resize(n);
        b.resize(n);
        for(i=0;i<n;i++)
            cin>>a[i];

        b[0]=0;
        b[1]=abs(a[1]-a[0]);

        for(i=2;i<n;i++)
            b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));

        cout<<b[n-1];
        return 0;



    }


Measured memory_bytes: 1792
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BTreeSet;

/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars,
        t: chars,
    }

    let mut s_m = HashMap::new();
    for (i, s_c) in s.iter().enumerate() {
        s_m.entry(s_c).or_insert(BTreeSet::new()).insert(i);
    }

    let mut t_m = HashMap::new();
    for (i, t_c) in t.iter().enumerate() {
        t_m.entry(t_c).or_insert(BTreeSet::new()).insert(i);
    }

    let ans = {
        let s_s = s_m.values().collect::<HashSet<_>>();
        let t_s = t_m.values().collect::<HashSet<_>>();

        if s_s == t_s {
            "Yes"
        } else {
            "No"
        }
    };

    println!("{}", ans);
}


Measured memory_bytes: 14588
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, L, Q, W, H, T, X, Y, S;

int main()
{
    cin >> X >> T; cout << max(X-T, (ll)(0)) << endl;

    return 0;
}

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

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;}

int main()
{   
    int k,n; cin >> k >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    ll res = 0;
    rep(i,n-1){
        res = max(res,1LL*abs(a[i]-a[i+1]));
    }
    res = max(res,1LL*(k-a[n-1]+a[0]));
    cout << k-res << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
 
int main(){
  int N,K;
  cin>>N>>K;
  double p[N];
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  
  double ans=0;
  for(int i=0;i<K;i++){
    ans=ans+p[i];
  }
  double d=ans;
  for(int i=0;i<N-K;i++){
    d=d-p[i]+p[K+i];
    ans=max(ans,d);
  }
  ans=(ans+K)/2;
  cout<<fixed<<setprecision(7);
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define mod 1000000007
using namespace std;
ll inv[2000005];
int r1,c1,r2,c2;
void init(){
    inv[1]=1;
    for(int i=2;i<=2000003;i++)
        inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
}
ll C(int n,int k){
	ll ans=1;
	for (int i=1;i<=n;i++)
		ans=ans*i%mod;
	for(int i=1;i<=k;i++)
		ans=ans*inv[i]%mod;
	for(int i=1;i<=n-k;i++)
		ans=ans*inv[i]%mod;
	return ans;
}
int main(){
    init();
 	cin>>r1>>c1>>r2>>c2;
	ll ans=0;
	ans=C(c2+r2+2,c2+1)+C(c1+r1,c1)+mod*2-C(c2+r1+1,c2+1)-C(c1+r2+1,c1);
	ans%=mod;
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    string S;
    bool OK = true;
    cin >> S;

    for(int i = 0; i < (int)S.size(); i++)
    {
        if((i % 2) == 0)
        {
            if(S[i] == 'L')
            {
                cout << "No" << endl;
                OK = false;
                break;
            }
        }
        else
        {
            if(S[i] == 'R')
            {
                cout << "No" << endl;
                OK = false;
                break;
            }
        }   
    }

    if(OK){
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {

    input = input.split("\n");
    var nm = input[0].split(" ");
   var n= parseInt(nm[0], 10);
   var m= parseInt(nm[1], 10);
   var menu = 1;cnt=0;total=0;
   for (menu =1;menu<=m;menu++){

for (var l =1;l<=n;l++){

 var tmp = input[l].split(" ");
 var k= parseInt(tmp[0], 10);
  //var Kl = [];
for (var i = 1; i <= k ; i++){
 var r= parseInt(tmp[i], 10);

 // var menu = 1;cnt=0;
  if(r==menu){cnt++;}

                  }
                }
  if(cnt==n){total++;}
  var cnt=0;
 
 }
 console.log(total);



 
       
     }
 //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 


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

ll h, w;

int main(){
  cin >> h >> w;
  ll res;
  if(h % 2 == 0 || w % 2 == 0){
    res =  (h * w) / 2;
  }else{
    res = (h * w) / 2 + 1;
  }
  if(h == 1 || w == 1){
    res = 1;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
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; }
const int MOD = 1000000007;
int dp[1010][1010];

int main() {
    int H,W;
    scanf("%d%d", &H, &W);
    string a[H];
    rep(i, H) cin >> a[i];
    for(int i=1; i < W; ++i){
        if(a[0][i] == '#') break;
        dp[0][i] = 1;
    }
    for(int i=1; i < H; ++i){
        if(a[i][0] == '#') break;
        dp[i][0] = 1;
    }
    for(int i=1; i < H; ++i){
        for(int j=1; j < W; ++j){
            if(a[i][j] == '#') dp[i][j] = 0;
            else dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
        }
    }
    printf("%d\n", dp[H-1][W-1]);
    return 0;
}

Measured memory_bytes: 5248
N = int(input())
robots = []
for _ in range(N):
    X,L = map(int,input().split(' '))
    x = X-L
    l = 2*L
    robots.append([x,l+x])
robots.sort()
#print(robots)

cnt = 0
start = robots[0][0]
end = robots[0][1]
result = []
for i in range(1,N):
    x = robots[i][0]
    l = robots[i][1]
    if x < end:
        if end < l:
            continue
        else:
            start = x
            end = l
    else:
        result.append([start,end])
        start = x
        end = l
print(len(result)+1)

Measured memory_bytes: 72536
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int main()
{
	cin>>n>>m;
	int a[m];
	for(int i=0;i<m;i++)cin>>a[i];
	for(int i=0;i<m;i++)ans+=a[i];
	if(n-ans>=0)cout<<n-ans;
	else cout<<-1;
	return 0;
}


Measured memory_bytes: 3668
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {

        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };


    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
        y: i32,
    }
    for a in 0..n + 1 {
        for b in 0..n - a + 1 {
            let c = n - a - b;
            if 10000 * a + 5000 * b + 1000 * c == y {
                println!("{} {} {}", a, b, c);
                return;
            }
        }
    }
    println!("{} {} {}", -1, -1, -1);
}


Measured memory_bytes: 4352
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let n = get();
    let h0: i64 = get();
    let a0: i64 = get();
    let d0: i64 = get();
    let s0: i64 = get();
    let mut dur = vec![0i64; n];
    let mut dam = vec![0i64; n];
    let mut tot = 0;
    let mut ok = true;
    for i in 0 .. n {
        let h: i64 = get();
        let a: i64 = get();
        let d: i64 = get();
        let s: i64 = get();
        dur[i] = if d >= a0 { -1 } else { (h + a0 - d - 1) / (a0 - d) };
        dam[i] = max(a - d0, 0);
        if s < s0 {
            tot -= dam[i];
        }
        if dur[i] < 0 && dam[i] > 0 {
            ok = false;
        }
    }
    if ok {
        let mut pool: Vec<(_, _)> = (0 .. n).map(|i| (dur[i], dam[i])).filter(|&(x, _)| x >= 0).collect();
        pool.sort_by(|&(a, b), &(c, d)| (a * d).cmp(&(b * c)));
        let mut dursum = 0;
        for (a, b) in pool {
            dursum += a;
            tot = tot.saturating_add(dursum.saturating_mul(b));
            if tot >= h0 { break; }
        }
    }
    println!("{}", if !ok || tot >= h0 { -1 } else { tot });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}



Measured memory_bytes: 11132
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;



int main(){
  ll N;
  cin >> N;
  vi A(0);
  
  A.push_back(1);
  
  for(int i = 6; i <= 100000; i *= 6){
    A.push_back(i);
  }
  for(int i = 9; i <= 100000; i *= 9){
    A.push_back(i);
  }
  int asize = A.size();
  

  vvll dp(100, vll(100100, INF));
  for(int i = 0; i < 100; i++){
    dp.at(i).at(0) = 0;
  }
  for(int i = 1; i <= 100000; i++){
    dp.at(0).at(i) = i;
  }

  for(int i = 0; i < asize-1; i++){
    for(int j = 1; j <= N; j++){
      chmin(dp.at(i+1).at(j), dp.at(i).at(j));
      if(j >= A.at(i+1)) chmin(dp.at(i+1).at(j), dp.at(i+1).at(j-A.at(i+1)) + 1);
    }
  }

  cout << dp.at(asize-1).at(N) << endl;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
#define ll long long

#define TASKNAME ""

using namespace std;

const ll INF = 1e9 + 7;
const ll MAXN = 5000;
const double EPS = 1e-8;
const ll LOGN = 30;

ll n, m, x;
vector <vector <pair <ll, ll> > > gr;

struct Edge {
    ll v, u, w, id;
};

struct Dsu {
    int n;
    vector <int> p, r;
    Dsu(int n) : n(n), p(n, 0), r(n, 0) {
        iota(p.begin(), p.end(), 0);
    }
    int get(int v) {
        return (p[v] == v ? v : p[v] = get(p[v]));
    }
    bool uni(int v, int u) {
        v = get(v);
        u = get(u);
        if (v == u) {
            return false;
        }
        if (r[v] == r[u]) {
            r[u]++;
        }
        if (r[v] > r[u]) {
            swap(v, u);
        }
        p[v] = u;
        return true;
    }
};

vector <vector <ll> > gr1;
vector <Edge> edges;
vector <vector <ll> > binup, binw;

ll power(ll a, ll k) {
    if (!k) {
        return 1;
    }
    ll b = power(a, k / 2);
    b = b * b % INF;
    if (k % 2) {
        return a * b % INF;
    } else {
        return b;
    }
}

vector <ll> f(MAXN, 0), rf(MAXN, 0);

ll rev(ll a) {
    return power(a, INF - 2);
}

void init() {
    f[0] = 1;
    rf[0] = 1;
    for (ll i = 1; i < MAXN; i++) {
        f[i] = f[i - 1] * i % INF;
        rf[i] = rev(f[i]);
    }
}

ll C(ll n, ll k) {
    return f[n] * rf[k] % INF * rf[n - k] % INF;
}

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    init();
    cin >> n >> m >> x;
    gr.resize(n);
    for (ll i = 0; i < m; i++) {
        ll v, u, w;
        cin >> v >> u >> w;
        v--, u--;
        gr[v].push_back({u, w});
        gr[u].push_back({v, w});
        edges.push_back({v, u, w});
    }
    sort(edges.begin(), edges.end(), [&](Edge a, Edge b) {
        return a.w < b.w;
    });
    ll bad = 0, good = 0;
    for (ll i = 0; i < m; i++) {
        ll w = 0;
        Dsu d(n);
        d.uni(edges[i].v, edges[i].u);
        w += edges[i].w;
        for (auto e : edges) {
            if (e.id == i) {
                continue;
            }
            if (d.uni(e.v, e.u)) {
                w += e.w;
            }
        }
        if (w < x) {
            bad++;
        } else if (w == x) {
            good++;
        }
    }
    if (!good) {
        cout << 0;
        return 0;
    }
    ll res = power(2, m - good - bad) % INF;
    cout << res * 2 % INF * (power(2, good) + INF - 1) % INF;
}


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

string a;

int main()
{
	cin>>a;

	int n=a.size(),ans=0;
	for(int i=0;i<n;i++)
	{
		int l=0;
		while(i<n and a[i]=='R') i++,l++;
		ans=max(ans,l);
	}
	cout<<ans;
}

Measured memory_bytes: 3616
import java.util.*;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a + w <= b)System.out.println(b - (a + w));
        else if(b + w <= a) System.out.println(a - (b + w));
        else System.out.println(0);
    }
}


Measured memory_bytes: 35648
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,d=1;
  string q;
  cin >>a;
  cin >>q;
  if(a%2==1){
  d=0;}
  for(int s=0;s<(a/2);s++){
  if(q.at(s)!=q.at((a/2)+s))
  { d=0;
  break;}
  }
  if(d==1){
  cout <<"Yes"<<endl;}
  else {
  cout <<"No"<<endl;}
return 0;
}

Measured memory_bytes: 256
<?php
while (fscanf(STDIN, "%d", $n) && $n) {
  fscanf(STDIN, "%d %d", $w, $h);
  
  $map = array(array());
  for ($i = 0; $i < $h; $i++) {
    for ($j = 0; $j < $w; $j++) {
      $map[$i][$j] = 0;
    }
  }

  while ($n--) {
    fscanf(STDIN, "%d %d", $x, $y);
    $map[$y - 1][$x - 1] = 1;
  }

  fscanf(STDIN, "%d %d", $s, $t);

  $ans = 0;
  for ($i = 0; $i < $h; $i++) {
    for ($j = 0; $j < $w; $j++) {
      if ($i + $t > $h) continue;
      if ($j + $s > $w) continue;
      $count = 0;
      for ($k = 0; $k < $t; $k++) {
        for ($l = 0; $l < $s; $l++) {
          if ($map[$i + $k][$j + $l]) $count++;
        }
      }
      $ans = max($ans, $count);
    }
  }

  print $ans . "\n";
}

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

using namespace std;

typedef long long int lli;

vector<int> enumDivisor(int n) {
    vector<int> res;
    for (int i=1; i*i<=n; i++) {
        if (n%i == 0) {
            res.push_back(i);
            if (i*i != n) {
                res.push_back(n/i);
            }
        }
    }
    return res;
}

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

    int n;
    cin >> n;

    vector<int> ans;
    for (int i=11; ans.size()<n; i+=10) {
        auto vec = enumDivisor(i);
        if (enumDivisor(i).size() == 2) ans.push_back(i);
    }

    for (auto a=ans.begin(); a!=ans.end(); a++) cout << *a << ((a+1!=ans.end()) ? " " : "\n");

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	
	static int M[][];
	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt(); M=new int[n][n];
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++)M[i][j]=-1;
		}
		
		for(int i=0;i<n;i++) {
			int u=Integer.parseInt(in.next()), k=Integer.parseInt(in.next());
			for(int j=0;j<k;j++) {
				int v=Integer.parseInt(in.next()), c=Integer.parseInt(in.next());
				M[u][v]=c;
			}
		}
		
		dijkstra(n);
	}
	
	static void dijkstra(int n) {
		int INF=2000000000,d[]=new int[n], p[]=new int[n];
		char color[]=new char[n];
		
		for(int i=0;i<n;i++) {
			d[i]=INF;
			color[i]='W';
		}
		
		d[0]=0; p[0]=-1;
		
		while(true) {
			int mincost=INF, u=-1;
			for(int i=0;i<n;i++) {
				if(color[i]!='B' && d[i]<mincost) {
					mincost=d[i];
					u=i;
				}
			}
			
			if(mincost==INF)break;
			color[u]='B';
			
			for(int v=0;v<n;v++) {
				if(color[v]!='B' && M[u][v]!=-1) {
					if(d[v]>M[u][v]+d[u]) {
						p[v]=u;
						d[v]=M[u][v]+d[u];
						color[v]='G'; 
					}
				}
			}
		}
		
		PrintWriter out=new PrintWriter(System.out);
		for(int i=0;i<n;i++) {
			out.println(i+" "+d[i]);
		}
		out.flush();
	}
}



Measured memory_bytes: 38020
H, W = map(int, input().split())

has_visited = [[True]*(W+2)]
has_visited += [[True] + [m == "#" for m in input().rstrip()] + [True] for _ in range(H)]
has_visited += [[True]*(W+2)]

search_que = []
for y in range(1, H+1):
    for x in range(1, W+1):
        if has_visited[y][x]:
            search_que.append((y, x))

count = -1
while search_que:
    count += 1
    next_que = []
    for y, x in search_que:
        if not has_visited[y+1][x]:
            has_visited[y+1][x] = True
            next_que.append((y+1, x))
        if not has_visited[y-1][x]:
            has_visited[y-1][x] = True
            next_que.append((y-1, x))
        if not has_visited[y][x+1]:
            has_visited[y][x+1] = True
            next_que.append((y, x+1))
        if not has_visited[y][x-1]:
            has_visited[y][x-1] = True
            next_que.append((y, x-1))
    search_que = next_que

print(count)

Measured memory_bytes: 106008
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b;

int main()
{
  cin>>n>>m;
  
  vector<bool> visit(n+1,true);
  vector<int> ar(n+1);
  
  for(int i=1;i<=n;i++)
  cin>>ar[i];
  
  
  for(int i=1;i<=m;i++)
  {
    cin>>a>>b;
    
    if(ar[a]<=ar[b])
    visit[a]=false;
    
    if(ar[a]>=ar[b])
    visit[b]=false;
    
  }
  
  int cnt=0;
  for(int i=1;i<=n;i++)
  {
	if(visit[i]==true)
	cnt++;
  
  }
  
  
  cout<<cnt<<endl;
  
  
 return  0;
}


Measured memory_bytes: 3788
using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i < 10; i++)
            {
                for(int w=1;w<10;w++)
                {
                    Console.WriteLine(i + "x" + w + "=" + i * w);
                } 
                }
        }
    }
}

Measured memory_bytes: 9100
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        do_(inp);
        inp.close();
    }
    public static void do_(Scanner inp) {
        double n = inp.nextDouble();
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 2 == 1) ans++;
        }
        System.out.println(((double)ans) / n);
    }
}


Measured memory_bytes: 27092
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<double> v;
    for(int i=0;i<n;i++)
    {
        double temp;
        cin>>temp;
        v.push_back(temp);
    }
    sort(v.begin(),v.end());
     vector<double>::iterator it = v.begin();
     for(int j=0;j<n-1;j++)
     {
         
         double z = (v[0]+v[1])/2;
         v.erase(v.begin());
         v[0] = z;
         
     }
     cout<<v[0]<<endl;
        

}

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

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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m,l;
    string s,t;
    cin >> n >> m >> s >> t;
    l = gcd(n,m);
    n /= l;m /= l;
    ll ans = n * m * l;
    for(int i = 0;i < l;i ++){
        if(s[i*n] != t [i*m]) {ans = -1;break;}
    }
    cout << ans << endl;
    return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 505050

li cnt[2];

inline bool ok(char c) {
    return c == 'A' || c == 'T' || c == 'G' || c == 'C';
}

int main() {
    string s;
    cin >> s;
    li res = 0;
    li tres = 0;
    rep(i, sz(s)) {
        if (ok(s[i])) {
            tres++;
        } else {
            res = max(res, tres);
            tres = 0;
        }
    }
    res = max(res, tres);

    cout << res << endl;


    return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define INF 1000000007
// cin.eof()

int main()
{

  int n,mini=INT_MAX; cin>>n;
  int a[n];

  for(int i=0;i<n;i++)
    cin>>a[i];



 for(int w=0;w<n;w++)
 {   int sum=0,sum1=0;
    for(int j=0;j<n;j++){
        if(j<w)
          sum += a[j];
        else
          sum1 += a[j];
    }
    long long diff = abs(sum-sum1);

      if(diff < mini)
        mini = diff;
 }

  // cout<<"the minimum sum difference in the array is"<<endl;
  cout<<mini<<endl;

  return 0;
}



Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line: Vec<u64> = read_as_vec();
    let (w, h, x, y) = (line[0], line[1], line[2], line[3]);

    /*
    let upper: f64 = ((h - y)*w) as f64;
    let lower: f64 = (y*w) as f64;
    
    let left: f64 = (x*h) as f64;
    let right: f64 = ((w-x)*h) as f64;
     */

    if w as f64/2.0 == x as f64 && h as f64/2.0 == y as f64{
        println!("{} 1",((w*h) as f64/2.0));
    }else{
        println!("{} 0",((w*h) as f64/2.0));        
    }
    
}


Measured memory_bytes: 4352
#include<iostream>
#include<cmath>
#include<algorithm>
#define INF 999999.999999
using namespace std;
string str;
int cnt;
double r[12],n,ans;
double dp[(1<<12)+1][12];
double t[12][12];

int get_num(string);
void input();
void init();
void make_table();

double rec(int S,int pos){

  if(dp[S][pos]!=INF)return dp[S][pos];

  if(S==(1<<(cnt))-1)return r[pos];

  for(int i=0;i<cnt;i++){
    if(((S>>i)&1)==1)continue;
    dp[S][pos]=min(dp[S][pos],rec(S+(1<<i),i)+t[pos][i]);

  }

  return dp[S][pos];
}


int main(){
  while(getline(cin,str)){
    init();
    input();
    make_table();
    ans=rec(1,0)+r[0];
    for(int i=1;i<cnt;i++){
      //cout<<ans<<endl;
      ans=min(ans , rec((1<<i),i)+r[i]);
    }
    if(ans<=n)cout<<"OK"<<endl;
    else cout<<"NA"<<endl;
    
  }
  return 0;
}


void make_table(){
  for(int i=1;i<12;i++){
    for(int j=0;j<i;j++){      
      t[i][j]=t[j][i]=sqrt(pow(r[i]+r[j],2.0)-pow(r[i]-r[j],2.0));
    }
  }
  
}

void init(){
  cnt=0;
  for(int i=0;i<=(1<<12);i++){
    for(int j=0;j<12;j++){
      dp[i][j]=INF;
    }
  }
}



void input(){
  n=get_num(str);
  for(int i=0;i<(int)str.size();i++)if(str[i]==' ')r[cnt++]=get_num(str.substr(i+1));
}


int get_num(string str){
  int res=0;
  for(int i=0;i<(int)str.size();i++){
    if(str[i]==' ')break;
    res*=10;
    res+=(str[i]-'0');
  }
  return res;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string n; cin>>n;
	int ans=0,len=n.size();
	for(auto&&i:n)ans+=(i-'0');
	for(int i=0,tans=0;i<len;++i){
		tans+=n.at(i)-'0';
		ans=max(ans,tans+9*(len-i-1)-1);
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define zero_pad(num) setfill('0') << std::right << setw(num)
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int N,K;cin>>N>>K;
    int A[N];
    int sum=0;
    REP(i,N){
        cin>>A[i];
        sum+=A[i];
    }
    int C=sum;
    map<int,int>memo;
    for(int i=1;i<=sqrt(sum);i++){
        if(C%i==0){
            memo[i]++;
            memo[C/i]++;
        }
    }
    int ans=1;
    for(auto v:memo){
        int d=v.first;
        vector<int>B;
        REP(i,N){
            if(A[i]%d!=0)B.pb(A[i]%d);
        }
      	int W=B.size();
      	if(W==0){
          	ans=max(ans,d);
          	continue;
        }
        sort(B.begin(),B.end());
        int lb[W],rb[W];
        REP(i,W){
            if(i==0)lb[0]=B[0];
            else lb[i]=lb[i-1]+B[i];
        }
        REP(i,W){
            if(i==0)rb[W-1]=d-B[W-1];
            else rb[W-1-i]=rb[W-i]+d-B[W-1-i];
        }
        REP(i,W){
            if(abs(lb[i]-rb[i+1])%d==0&&max(lb[i],rb[i+1])<=K)ans=max(ans,d);
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  if(s[s.length()-1]=='s') {
    s = s + 'e' + 's';
  }
  else {
    s = s + 's';
  }
  cout << s;
  return 0;
}
  

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n,ans=0;cin>>n;
    multiset<ll> v;
    rep(i,n){
        ll a;cin>>a;
        v.insert(a);
    }
    while(!v.empty()){
        auto it=v.end();
        it--;
        ll k=1;
        while(k<=*it)k*=2;
        k=k-*it;
        v.erase(it);
        auto w=v.lower_bound(k);
        if(*w==k){
            ans++;
            v.erase(w);
        }
    }
    out(ans);
}

Measured memory_bytes: 9600
a = []
for i in range(3):
    a += [list(map(int,input().split()))]
n = int(input())
bingo = [[False for i in range(3)] for x in range(3)]

b = [int(input()) for i in range(n)]

for x in b:
    for i in range(3):
        if x in a[i]:
            j = a[i].index(x)
            bingo[i][j] = True

R = True
L = True
hw = False
_bingo = list(zip(*bingo))
for i in range(3):
    if False not in bingo[i] or False not in _bingo[i]:
        hw = True
        break
    if False is bingo[i][i]: L = False
    if False is bingo[i][2-i]: R = False

if hw or R or L:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;

#define len 1e5+1
#define maxwt 1e15

int main(){
  int n,w; cin>>n>>w;

  vector<vector<long long> > tab(n+1);
  vector<long long > temp(len); for(int i=1; i<len; i++) temp[i]=maxwt;
  for(int i=0; i<=n; i++) tab[i]=temp;

  int val,wht;
  for(int i=0; i<n; i++){
    cin>>wht>>val;
    for(int j=0; j<=99000; j++ ){
        if(tab[i][j]!=maxwt){
            tab[i+1][j+val]=tab[i][j]+wht;
        }
    }
    for(int j=0; j<=99000; j++ ){
        if(tab[i][j]<tab[i+1][j]) tab[i+1][j]=tab[i][j];
    }
  }

  int ans;
  for(int j=len-1; j>=0; j--){
    if(tab[n][j]<=w){ ans=j; break; }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 80256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

#define fs first
#define sc second

class UnionFind{
public:
  vector<int> par;
  vector<int> rank;
  vector<int> sz;
  int N;

  UnionFind(int n){N = n;}

  //初期化
  void init(){
      par.resize(N);
      rank.resize(N, 0);
      sz.resize(N, 1);
      for(int i = 0; i < N; i++) par[i] = i;
  }

  //木の根を求める
  int find(int x){
    if(par[x] == x) return x;
    else {
      par[x] = find(par[x]);
      return par[x];
    }
  }

  //xとyの集合の併合
  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じ集合にあるか
  bool same(int x, int y){
      return find(x) == find(y);
  }

  //xの木のサイズ
  int size(int x){
      return sz[find(x)];
  }

  //ufの連結成分の数
  int cnt_connection(){
      int res = 0;
      bool ex[N];
      fill(ex, ex + N, false);
      for(int i = 0; i < N; i++){
          ex[find(i)] = true;
      }

      for(int i = 0; i < N; i++){
          if(ex[i]) res++;
      }

      return res;
  }


};

struct P{
    int x, y, id;
};

bool cmpx(const P &a, const P &b){
    return a.x < b.x;
}

bool cmpy(const P &a, const P &b){
    return a.y < b.y;
}


int main(){
    int N;
    cin >> N;
    P p[N];
    for(int i = 0; i < N; i++){
        cin >> p[i].x >> p[i].y;
        p[i].id = i;
    }

    UnionFind uf = UnionFind(N);
    uf.init();

    sort(p, p + N, cmpx);
    for(int i = 0; i < N - 1; i++){
        if(p[i].x == p[i + 1].x){
            uf.unite(p[i].id, p[i + 1].id);
        }
    }

    sort(p, p + N, cmpy);
    for(int i = 0; i < N - 1; i++){
        if(p[i].y == p[i + 1].y){
            uf.unite(p[i].id, p[i + 1].id);
        }
    }

    map<int, vector<P>> mp;
    for(int i = 0; i < N; i++){
        int par = uf.find(p[i].id);
        mp[par].push_back(p[i]);
    }

    ll ans = 0;
    //各連結成分に対して処理
    for(auto it = mp.begin(); it != mp.end(); it++){
        //種類数を数える
        map<int, int> mpx;
        map<int, int> mpy;

        vector<P> v = it -> second;
        for(int i = 0; i < (int)v.size(); i++){
            mpx[v[i].x]++;
            mpy[v[i].y]++;
        }

        ans += (ll)mpx.size() * (ll)mpy.size() - (ll)v.size();
    }

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

Measured memory_bytes: 9588
#include <iostream>
#include <math.h>

using namespace std;

int main(){

    
    long long a,b,min,max,num=0;

    cin>>a;
    cin>>b;

    if(a<b){
        min = a;
        max = b;
    }else{
        min = b;
        max = a;
    }

    for (int i = min+1; i <= max; i++)
    {   
        if(abs(a-i) == abs(b-i)){
            num = i;
        }
    }

    if(num != 0){
        cout<<num<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	ll N;
	cin >> N;
	vector<ll> A(N);
	for(ll i = 0; i < N; i ++){
		cin >> A[i];
	}
	vector<ll> ANS(N, 0);
	ll cnt = 0;
	for(ll i = N - 1; i >= 0; i --){
		if(A[i] == 1){
			ANS[i] = 1;
			cnt ++;
			for(ll j = 1; j <= sqrt(i + 1); j ++){
				if((i + 1)%j == 0){
					if(A[j - 1] == 1)A[j - 1] = 0;
					else A[j - 1] = 1;
					if(j * j != i + 1){
						if(A[(i + 1) / j - 1] == 1)A[(i + 1) / j - 1] = 0;
						else A[(i + 1) / j - 1] = 1;
					}
				}
			}
		}
	}
	cout << cnt << endl;
	for(ll i = 0; i < N; i ++){
		if(ANS[i] == 1)cout << i + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    long long int n,m,a,b,ans=0,temp;
    string s;
    cin>>n;
    for(int i = 1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
            ans+=i;
    }
    
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {
    sws;

    string s;

    cin >> s;
    set<char> c;

    for( int i = 0; i < 4; i++) {
        c.insert(s[i]);
    }

    if ( c.size() == 2 ) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = 200005;
const LL INF = 0x3f3f3f3f3f3f3f3f;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

template <typename T> inline void cmin(T &x, T y) {
	if (x > y) x = y;
}

template <typename T> inline void cmax(T &x, T y) {
	if (x < y) x = y;
}

int n, q, A, B, p[MAXN];
LL csum[MAXN], dp[MAXN];

struct BIT {
	LL tr[MAXN];
	BIT() {
		mset(tr, 0x3f);
	}
	inline int lowbit(int x) {
		return x & (-x);
	}
	inline void update(int x, LL val) {
		for (int i=x;i<=n;i+=lowbit(i)) {
			cmin(tr[i], val);
		}
	}
	inline LL query(int x) {
		LL ret = INF;
		for (int i=x;i;i-=lowbit(i)) {
			cmin(ret, tr[i]);
		}
		return ret;
	}
}t1, t2;

void init() {
	read(n); read(q);
	read(A); read(B);
	for (int i=1;i<=q;++i) {
		read(p[i]);
	}
	for (int i=2;i<=q;++i) {
		csum[i] = csum[i-1] + abs(p[i]-p[i-1]);
	}
}

void solve() {
	dp[0] = min(abs(A-p[1]), abs(B-p[1]));
	t1.update(A, abs(B-p[1]) - A);
	t2.update(n-A+1, abs(B-p[1]) + A);
	t1.update(B, abs(A-p[1]) - B);
	t2.update(n-B+1, abs(A-p[1]) + B);
	for (int i=1;i<q;++i) {
		dp[i] = min( t1.query(p[i+1]) + csum[i] + p[i+1], 
					 t2.query(n-p[i+1]+1) + csum[i] - p[i+1] );
		t1.update(p[i], dp[i] - csum[i+1] - p[i]);
		t2.update(n-p[i]+1, dp[i] - csum[i+1] + p[i]);
	}
	LL ans = INF;
	for (int i=0;i<q;++i) {
		cmin(ans, dp[i] + csum[q] - csum[i+1]);
	}
	printf("%lld\n", ans);
}

int main() {
	init();
	solve();
	return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<queue>
using namespace std;
int main(){
  int k;
  cin>>k;
  queue<long long> que;
  for(int i=1;i<10;++i) que.push(i);
  for(int i=0;i<k-1;++i){
     long long s=que.front();
     que.pop();
     for(int j=-1;j<=1;++j){
        long long add=(s%10)+j;
       if(add>=0&&add<=9) que.push(s*10+add);
     }
  }
  cout<<que.front()<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
int main(void){
    // Your code here!
    int n,i;
    double a,s[10020],m,a2;
    
    while(1){
        m=0;
        a2=0;
        scanf("%d", &n);
        if(n==0) break;
    
        for(i=0;i<n;i++){
            scanf("%lf", &s[i]);
            m=m+s[i];
        }
        m=m/n;
    
        for(i=0;i<n;i++){
            a2=a2+(s[i]-m)*(s[i]-m);
        }
        a2=a2/n;
    
        printf("%.8lf\n", sqrt(a2));
    }
    return 0;
}



Measured memory_bytes: 2044
#include <stdio.h>

int main() {
	char trans[256];
	char c, c2, str[10];
	long n, m, i;

	while (scanf("%ld", &n), n) {
		for (i = 0; i < 256; ++i)
			trans[i] = i;

		for (i = 0; i < n; ++i) {
			scanf("%s", str); c = str[0];
			scanf("%s", str); c2 = str[0];
			trans[c] = c2;
		}

		scanf("%ld", &m);

		for (i = 0; i < m; ++i) {
			scanf("%s", str); c = str[0];
			printf("%c", trans[c]);
		}
		puts("");
	}

	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
 
typedef long long ll;
// const int INF = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, int> P;
 
int N, P2;
string S;
 
int main() {
    cin >> S;
    P2 = 2019;
    N = S.size();
 
    if (10 % P2 == 0) {
        ll ans = 0;
        rep(i, N) {
            if ((S[i] - '0') % P2 == 0) {
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }
 
    vector<ll> d(N + 1);
    ll ten = 1;
    for (ll i = N - 1; i >= 0; i--) {
        ll a = (S[i] - '0') * ten % P2;
 
        d[i] = (d[i + 1] + a) % P2;
        ten *= 10; ten %= P2;
    }
    vector<ll> cnt(P2);
    ll ans = 0;
    for (ll i = N; i >= 0; i--) {
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    cout << ans << endl;
}

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

int main(){
	string s;
	cin>>s;
	if(s.at(0)!=s.at(1)||s.at(0)!=s.at(1)||s.at(0)!=s.at(2))
		cout<<"Yes\n"s;
	else cout<<"No\n"s;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[500050];
int n,mx[500050];
long long ans;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1)+1;
	for(int i=2;i<=n;++i)if(s[i-1]=='<')mx[i]=mx[i-1]+1;
	for(int i=n-1;i;--i)
		if(s[i]=='>')mx[i]=max(mx[i],mx[i+1]+1);
	for(int i=1;i<=n;++i)ans+=mx[i];
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
import sys
import os
import math


def solve():
    S = int(input())

    X2 = 1
    X3 = 0
    Y3 = 0

    X1 = math.ceil(pow(S, 0.5))
    Y2 = X1
    Y1 = pow(X1, 2) - S

    print('%d %d %d %d %d %d' % (X1, Y1, X2, Y2, X3, Y3))


solve()


Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main(void){
	double sho,lon;
	while(cin>>sho>>lon){
		if(sho<35.50 && lon < 71.00)			cout<<"AAA";
		else if(sho < 37.50 && lon < 77.00)	cout<<"AA";
		else if(sho < 40.00 && lon < 83.00)	cout<<"A";
		else if(sho < 43.00 && lon < 89.00)	cout<<"B";
		else if(sho < 50.00 && lon < 105.00)cout<<"C";
		else if(sho < 55.00 && lon < 116.00)cout<<"D";
		else if(sho < 70.00 && lon < 148.00)cout<<"E";
		else cout<<"NA";
		cout<<endl;
	}

	
}

Measured memory_bytes: 1220
#include<iostream>
using namespace std;
int main(){
	string a;
	string b;
	int s=0;
	cin>>a>>b;
	for(int i=0;i<a.size();i++)
	{
		if(a[i]==b[i])
			s++;
			
	}
	cout<<a.size()-s;
	return 0;
}

Measured memory_bytes: 3852
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)


def lcm(a, b):
    return a / gcd(a, b) * b

try:
    while True:
        a, b = map(int, raw_input().split())
        print gcd(a, b), lcm(a, b)
except:
    pass

Measured memory_bytes: 4204
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; char n;
	for (int i=0; i<4; i++)
		cin>>n, s+=n;
	sort (s.begin(),s.end());
	cout<<(s=="1479"?"YES":"NO")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#define ll long long
using namespace std;

int main() {
	int a, b;
	
	cin >> a >> b;
	if ((b - 1) % (a - 1) == 0) {
		cout << (b - 1) / (a - 1);
	}
	else {
		cout << (b - 1) / (a - 1) + 1;
	}

	return 0;
}

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

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

  int x, y;
  cin >> x >> y;

  for (int i = 0; i <= x; ++i) {
    int j = x - i;
    int leg = i * 2 + j * 4;
    
    if (leg == y) {
      cout << "Yes" << '\n';
      return (0);
    }
  }

  cout << "No" << '\n';

  return (0);
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+5;
ll a[N],k=0,n;
void dfs(ll i){
	if(i>1e10) return;
	a[++k]=i;
	for(ll j=max(ll(0),i%10-1);j<=min(ll(9),i%10+1);j++)
		dfs(i*10+j);
}
int main(){
	cin>>n;
	for(ll i=1;i<=9;i++) dfs(i);
	sort(a+1,a+k+1);
	cout<<a[n]<<endl;
	return 0;
}

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

int main()
{
    char ch;
    cin>>ch;
    if(ch=='A')
        cout<<"T"<<endl;
    else if(ch=='T')
        cout<<"A"<<endl;
    else if(ch=='C')
        cout<<"G"<<endl;
    else if(ch=='G')
        cout<<"C"<<endl;
}


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

int main()
{
	ll n;
	vector<int> cnt(100001);
	cin >> n;
	ll ans = 0;
	for(ll i =0;i<n;i++)
	{
		ll x;
		cin >> x;
		cnt[x]++;
		ans += x;
	}
	ll q;
	cin >> q;
	while (q--)
	{
		ll x,y;
		cin >> x >> y;
		ans -= x*cnt[x];
		ans += y*cnt[x];
		cnt[y] += cnt[x];
		cnt[x] = 0;
		cout<<ans<<endl;
	}
	
}

Measured memory_bytes: 3744