akhauriyash/Code-Regression huggingface dataset:
use std::io::prelude::*;

fn main() {
    let stdin_ = std::io::stdin();
    let stdout_ = std::io::stdout();
    let mut stdin = stdin_.lock();
    let mut stdout = stdout_.lock();

    let mut buffer = String::new();
    stdin.read_line(&mut buffer).unwrap();
    let b = buffer.trim();

    let s0 = b
        .as_bytes()
        .iter()
        .zip(['0' as u8, '1' as u8].iter().cycle())
        .map(|(&c0, &c1)| if c0 == c1 { 0 } else { 1 })
        .sum::<u64>();
    let s1 = b
        .as_bytes()
        .iter()
        .zip(['1' as u8, '0' as u8].iter().cycle())
        .map(|(&c0, &c1)| if c0 == c1 as u8 { 0 } else { 1 })
        .sum::<u64>();
    let s = if s0 > s1 { s1 } else { s0 };

    write!(stdout, "{}\n", s).unwrap();
}


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

int main()
{
  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  for (int i = 0; i < N; ++i)
    cin >> s[i] >> t[i];
  string X;
  cin >> X;
  auto itr = find_if(s.rbegin(), s.rend(), [X](const auto & _s){return X == _s;});
  int sum = 0;
  for (auto i = distance(s.begin(), itr.base()); i < s.size(); ++i)
    sum += t[i];
  cout << sum;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
    int N;
    double T, A;
    cin >> N;
    cin >> T >> A;
    int ret = -1;
    double min_diff = 100000000;
    for(size_t i = 0; i < N; i++)
    {
        double h;
        cin >> h;
        double temp_diff = abs(T - 0.006 * h - A);
        if (min_diff > temp_diff)
        {
            min_diff = temp_diff;
            ret = i+1;
        }
    }
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<vector>
#include<stack>

using namespace std;

const int N=1e5+5;
char ch[N];
stack<char>s;
int main()
{
    cin>>ch;
    int l=strlen(ch);
    for(int i=0;i<l;i++)
    {
        if(!s.empty()&&ch[i]!=s.top())
        {
            s.pop();
        }
        else
            s.push(ch[i]);
    }
    int tmp=0;
    while(!s.empty())
    {
        s.pop();
        tmp++;
    }
    cout<<l-tmp<<endl;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  map<int, ll> mp;
  rep(i, N){
    ll tmp;
    cin >> tmp;
    mp[tmp]++;
  }

  ll ans = 0;
  for(auto  it: mp){
    //cout << it.first << " " << it.second << endl;
    ans += (it.second - it.first >= 0)? it.second-it.first : it.second;
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 6272
fun main(args: Array<String>) {
    val N = nextInt()
    val L = listOfInt().sortedDescending()
    var sum = 0
    for (n in 0 .. (N - 1) * 2 step 2) sum += L[n + 1]
    println(sum)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 38000
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;

int main()
{
	int n,cnt=0;
	cin >> n;
	vector<int>p(n);
	for (int i = 0; i < n; i++)cin >> p[i];
	for (int i = 0; i < n-2; i++) {
		if (p[i] < p[i + 1] && p[i + 1] < p[i + 2])cnt++;
		else if (p[i] > p[i + 1] && p[i + 1] > p[i + 2])cnt++;
	}
	cout << cnt << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n, m;
	cin >> n >> m;
	vector<vll> d(n, vll(n, INFL));
	rep(i, n) d[i][i] = 0;
	rep(i, m) {
		ll s, t, _d;
		cin >> s >> t >> _d;
		d[s][t] = _d;
	}
	rep(i, n) rep(j, n) rep(k, n) {
		chmin(d[j][k], d[j][i] + d[i][k]);
	}
	bool neg = false;
	rep(i, n) if(d[i][i] != 0) neg = true;
	if(neg) {
		cout << "NEGATIVE CYCLE" << endl;
		return 0;
	}
	const ll maxd = 10000000000;
	rep(i, n) {
		rep(j, n) {
			if(d[i][j] > maxd) cout << "INF";
			else cout << d[i][j];
			if(j < n-1) cout << ' ';
		}
		cout << endl;
	}
}



Measured memory_bytes: 3228
N = int(input())
ans = [0] * 100000
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            ans[x*x+y*y+z*z+x*y+y*z+z*x-1] += 1
for i in range(N):
    print(ans[i])

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X;
  cin >> X;
  
  if (400 <= X && X <= 599) {
    cout << "8" << endl;
  }
  else if (600 <= X && X <= 799) {
    cout << "7" << endl;
  }
  else if (800 <= X && X <= 999) {
    cout << "6" << endl;
  }
  else if (1000 <= X && X <= 1199) {
    cout << "5" << endl;
  }
  else if (1200 <= X && X <= 1399) {
    cout << "4" << endl;
  }
  else if (1400 <= X && X <= 1599) {
    cout << "3" << endl;
  }
  else if (1600 <= X && X <= 1799) {
    cout << "2" << endl;
  }
  else if (1800 <= X && X <= 1999) {
    cout << "1" << endl;
  }
}

Measured memory_bytes: 3628
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.size())
    {
        if (s[i] == '1')
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
   public static void main(String[] args)
   {
      Scanner stdIn = new Scanner(System.in);
      int a = stdIn.nextInt();
      int b = stdIn.nextInt();
      int c = a*b;
      int d = 2*(a+b);
      System.out.println( c + " " + d );
   }
}

Measured memory_bytes: 26264
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int n, k;
vector<int> p(5050);
vector<int> c(5050);

signed main() {
	cin.tie(nullptr);
	cout.tie(nullptr);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	cin >> n >> k;
	rep(i, n) cin >> p[i], p[i]--;
	rep(i, n) cin >> c[i];
	p.resize(n);
	c.resize(n);

	int ans = LLONG_MIN;
	rep(i, n) {
		int nowv = i;
		int cycle_sum = 0;
		int cycle_cnt = 0;
		while(1) {
			cycle_cnt++;
			cycle_sum += c[nowv];
			nowv = p[nowv];
			if(nowv == i) break;
		}

		int path = 0;
		int cnt = 0;
		while(1) {
			cnt++;
			path += c[nowv];
			if(cnt > k) break;
			int num = (k - cnt) / cycle_cnt;
			int score = path + num * max(0LL, cycle_sum);
			chmax(ans, score);
			nowv = p[nowv];
			if(nowv == i) break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

#define INF 1000000

int t(int x) { return x*(x+1)*(x+2)/6; }

int dp[1000010];

int main() {
  ios_base::sync_with_stdio(false);

  Vi one, two, odd;
  for (int i = 1; t(i) <= 1000000; i++) {
    one.push_back(t(i));
    if (t(i)%2) odd.push_back(t(i));
  }

  for (int a : one) {
    for (int b : one) {
      two.push_back(a+b);
    }
  }
  sort(ALL(two));

  REP(i, 1000001) dp[i] = INF;
  dp[0] = 0;
  REP(i, 1000000) {
    for (int a : odd) {
      if (i+1-a >= 0)
	dp[i+1] = min(dp[i+1-a]+1, dp[i+1]);
    }
  }  

  while (1) {
    int n;
    cin >> n;
    if (n == 0) break;

    if (n == *lower_bound(ALL(one), n)) {
      cout << 1;
    } else if (n == *lower_bound(ALL(two), n)) {
      cout << 2;
    } else {
      bool flag = false;
      for (int a : one) {
	if (n - a == *lower_bound(ALL(two), n - a)) {
	  flag = true;
	  break;
	}
      }
      if (flag) {
	cout << 3;
      } else {
	for (int a : two) {
	  if (n - a == *lower_bound(ALL(two), n - a)) {
	    flag = true;
	    break;
	  }
	}
	cout << (flag ? 4 : 5);
      }
    }

    cout << ' ' << dp[n] << endl;

  }    
  return 0;
}

Measured memory_bytes: 5264
#include <stdio.h>
#include <stdlib.h>
#include <map>

#define MAX_N (100000)

using namespace std;

long num_lr(const long *as, int b, int e, long M) {
  if (e - b <= 0) {
    return 0;
  } else if (e - b == 1) {
    return as[b] % M == 0;
  }
  const int mr = (b + e) / 2, ml = mr - 1;
  const long num_lr_l = num_lr(as, b, ml, M);
  const long num_lr_r = num_lr(as, mr + 1, e, M);
  long sum = 0, num_lr_m = 0;
  map<long, long> num_sum_l, num_sum_r;
  for (int i = ml; i >= b; i--) {
    sum = (sum + as[i]) % M;
    if (num_sum_l.find(sum) != num_sum_l.end()) {
      num_sum_l[sum]++;
    } else {
      num_sum_l[sum] = 1;
    }
  }
  sum = 0;
  for (int i = mr; i < e; i++) {
    sum = (sum + as[i]) % M;
    if (num_sum_r.find(sum) != num_sum_r.end()) {
      num_sum_r[sum]++;
    } else {
      num_sum_r[sum] = 1;
    }
  }
  for (pair<long, long> p : num_sum_l) {
    const long mod_l = p.first, cnt_l = p.second, mod_r = (M - mod_l) % M;
    if (num_sum_r.find(mod_r) != num_sum_r.end()) {
      const long cnt_r = num_sum_r[mod_r];
      if (mod_l != 0) {
        num_lr_m += cnt_l * cnt_r;
      }
    }
  }
  if (num_sum_r.find(0) != num_sum_r.end()) {
    num_lr_m += num_sum_r[0];
  }
  if (num_sum_l.find(0) != num_sum_l.end()) {
    num_lr_m += num_sum_l[0];
  }
  if (num_sum_r.find(0) != num_sum_r.end() &&
      num_sum_l.find(0) != num_sum_l.end()) {
    num_lr_m += num_sum_l[0] * num_sum_r[0];
  }
  return num_lr_l + num_lr_r + num_lr_m;
}

int main(int argc, char *argv[]) {
  // read inputs
  long N, M, as[MAX_N];
  scanf("%ld %ld", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%ld", &as[i]);
  }

  // solve
  printf("%ld\n", num_lr(as, 0, N, M));

  return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
typedef pair<int,int> P;
#define INF 1e9

int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0)break;
        int p[m][n];
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                cin>>p[i][j];
            }
        }
        int ans = 0;
        int res = 0;
        for(int i=0;i<n;i++){
            ans = 0;
            for(int j=0;j<m;j++){
                ans += p[j][i];
            }
            res = max(res,ans);
        }
        cout<<res<<endl;
    }
}


Measured memory_bytes: 3208
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

#define FUTAGO(x) ((x) ? "Yay!" : ":(")
const LL MOD = 1000000007;

int main() {
	LL T1, T2, A1, A2, B1, B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
	A1 *= T1;
	A2 *= T2;
	B1 *= T1;
	B2 *= T2;
	LL C1 = B1 - A1;
	LL C2 = B1 + B2 - A1 - A2;
	if (C2 == 0) {
		cout << "infinity" << endl;
		return 0;
	}
	if ((C1 > 0 && C2 > 0) || (C1 < 0 && C2 < 0)) {
		cout << 0 << endl;
		return 0;
	}
	if (C1 < 0) {
		C1 *= -1;
		C2 *= -1;
	}
	LL n = C1 / (-C2);
	if (n * (-C2) == C1) {
		cout << n * 2 << endl;
		return 0;
	}
	else {
		cout << (n + 1) * 2 - 1 << endl;
		return 0;
	}

	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[] ary = new int[n+1];
		int k = sc.nextInt();
		for(int i=0; i<k; i++){
			int d = sc.nextInt();
			for(int j=0; j<d; j++) {
				int t = sc.nextInt();
				ary[t] = 1;
			}
		}
		int ans = 0;
		for(int i=1; i<ary.length; i++){
			if(ary[i]==0){
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 37636
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(){
    int P,Q,R;

    cin >> P >> Q >> R;
    cout << ((P + Q + R) - max(P,max(Q,R))) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define ll long long
#define int ll
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> A >> B;
    if (A & 1) {
        ans ^= A;
        N = (B - A) / 2;
    } else {
        N = (B - A + 1) / 2;
    }
    if (!(B & 1))
        ans ^= B;
    if (N & 1)
        ans ^= 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}

uintmax_t comb(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
using Graph = vector<vector<int>>;

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


int digsum(int n) {
      int res = 0;
      while(n > 0) {
          res += n%10;
          n /= 10;
      }
      return res;
  }



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

int k;
cin >> k;
string s;
cin >> s;

if(s.length() <= k) cout << s << endl;
else{
    rep(i,k){
        cout << s[i];
    }
    cout << "..." << endl;
}


//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;


signed main(){
	int N;
	cin >> N;
	vector<int>a(N);
	REP(i, N) {
		cin >> a[i];
	}
	int ans = 0;
	REP(i, N) {
		if(i % 2 == 0 && a[i] % 2)++ans;
	}
	out(ans);
}

Measured memory_bytes: 3608
from collections import deque

K = int(input())

G = [((10*i % K, 0), ((i+1) % K, 1)) for i in range(K)]
s = 1

dist = [10**9] * K
S = deque([s])
T = deque()
dist[s] = 0

d = 0
while S:
    while S:
        v = S.popleft()
        for w, c in G[v]:
            if d+c < dist[w]:
                dist[w] = d+c
                if c:
                    T.append(w)
                else:
                    S.append(w)
    S, T = T, S
    d += 1

print(dist[0]+1)

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

void ti(){
  #ifndef ONLINE_JUDGE
    freopen("in.txt", "r+", stdin);
    freopen("out.txt", "w", stdout);
  #endif
}

typedef long long ll;
int hg = 1000000000;

int main(){

  // ti();
  int n,k;
  cin >> n >> k;

  vector <int> v(n + 1, 0);
  for(int i = 1; i <= n; i++)
      cin >> v[i];

  vector <int> mi(n + 1, hg);
  mi[1] = 0;

  for(int i = 2; i <= n; i++)
  {
      for(int j = i - 1; j >= max(1, i - k); j--)
      {
          mi[i] = min(mi[i], mi[j] + abs(v[i] - v[j]));
      }
  }

  cout << mi[n];
  return 0;
}


Measured memory_bytes: 4024
def dfs(island, r, c):
    stack = [(r, c)]
    ans = 0
    while stack:
        r, c = stack.pop()
        if r < 0 or r >= len(island) or c < 0 or c >= len(island[r]):
            continue
        if island[r][c] == 0:
            continue
        ans += 1
        island[r][c] = 0
        for rr in range(-1, 2):
            for cc in range(-1, 2):
                if rr == 0 and cc == 0:
                    continue
                stack.append((r+rr, c+cc))
    return ans


def solve(w, h):
    island = []
    for _ in range(h):
        island.append(list(map(int, input().split())))
    cnt = 0
    for r in range(h):
        for c in range(w):
           if dfs(island, r, c) > 0:
               cnt += 1
    print(cnt)

while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0:
        break
    solve(w, h)




Measured memory_bytes: 5984
s = input()

n = len(s)

ans = 0
for bit in range(1<<(n-1)):
    sum = 0
    insert = [0]
    for i in range(n-1):
        if bit & (1<<i):
            insert.append(i+1)
    insert.append(n+1)
    for j in range(len(insert)-1):
        sum += int(s[insert[j]:insert[j+1]])
    
    ans += sum

print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

x = int(input())

def prime_factorize(n):
    prime_factors = {}
    i = 2
    while i ** 2 <= n:
        exp = 0
        while n % i == 0:
            exp += 1
            n //= i
        if exp:
            prime_factors[i] = exp
        i += 1

    if n != 1:
        prime_factors[n] = 1
    return prime_factors

ans = 1
for i in range(2, x + 1):
    prime_factors = prime_factorize(i)
    exps = set(prime_factors.values())
    if len(exps) == 1 and exps != {1}:
        ans = i
print(ans)


Measured memory_bytes: 69132
#include<iostream>
#include<cstdio>
#define INF 1<<30
#define FinishFunction return 0
#define MAX 1000000
using namespace std;
       
struct edge {
  int from,to,cost,k;
};
     
edge es[MAX];
     
int main(){
  int n,u,k,E,c,v;
  E = 0;
  scanf("%d",&n);
     
  for(int i=0;i<n;i++){
    scanf("%d %d",&u,&k);
        
    for(int j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      es[E].from = u;
      es[E].to = v;
      es[E++].cost = c;
    }
  }
     
  // Ika berumanfo-do
  int d[MAX];
  for(int i=0;i<n;i++)d[i] = INF;
  d[0] = 0;
  while(true){
    bool update = false;
    for(int i=0;i<E;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
    d[e.to] = d[e.from] + e.cost;
    update = true;
      }
    }
    if(!update)break;
  }
  for(int i=0;i<n;i++)cout << i << " " << d[i] << endl;
  FinishFunction;// return 0
}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

int queue[1005];
int v[51][51] = {0};
int node[51];

int main(void){
    int head, tail;
    int n, m;
    int a, b;
    int i, j, k;
    int ans = 0;
    int flag;
    scanf("%d %d", &n, &m);
    for (i = 0; i < m; i++){
        scanf("%d %d", &a, &b);
        v[a][b] = 1;
        v[b][a] = 1;
    }

    for (i = 0; i < 51*51; i++){
        if (v[i/51][i%51] == 1){
            flag = 1;
            for (j = 0; j < 51; j++){
                node[j] = 0;
            }
            v[i/51][i%51] = 0;
            head = 0;
            tail = 0;
            queue[tail] = (i/51);
            tail++;
            while (head < tail){
                for (k = 0; k < 51; k++){
                    if (v[queue[head]][k] == 1){
                        if (node[k] != 1){
                            queue[tail] = k;
                            node[k] = 1;
                            tail++;
                            if (k == i%51){
                                flag = 0;
                            }
                        }
                    }
                }
                head++;
            }
            if (flag == 1){
                ans++;
            }
            v[i/51][i%51] = 1;
        }
    }
    printf("%d\n", ans/2);
    return 0;    
    
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt;
vector<vector<bool>> ab;
vector<bool> br;
void dfs(int i){
  br[i]=true;
  bool f=true;
  for(int j=0;j<n;j++){
    if(!br[j]){
      f=false;
      break;
    }
  }
  if(f){
    cnt++;
  }
  for(int j=0;j<n;j++){
    if(!br[j]&&ab[i][j]){
      dfs(j);
    }
  }
  br[i]=false;
}
int main(){
  cin>>n>>m;
  ab.resize(n);
  br.resize(n);
  for(int i=0;i<n;i++){
    ab[i].resize(n);
    br[i]=false;
    for(int j=0;j<n;j++){
      ab[i][j]=false;
    }
  }
  int a,b;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    ab[a-1][b-1]=true;
    ab[b-1][a-1]=true;
  }
  cnt=0;
  dfs(0);
  cout<<cnt;
}

Measured memory_bytes: 256
X, Y = map(int, input().split())
ans = 10 ** 18

# flipしない
if Y - X >= 0:
    ans = Y - X

# はじめにflip
if Y - (-X) >= 0:
    ans = min(ans, 1 + Y - (-X))

# 最後にflip
if (-Y) - X >= 0:
    ans = min(ans, (-Y) - X + 1)

# 両方flip
if (-Y) - (-X) >= 0:
    ans = min(ans, 1 + (-Y) - (-X) + 1)

print(ans)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string S; cin>>S;
  ll ans = 0, tmp=0;
  rep(i,3){
    if (S[i] == 'S'){
      ans = max(ans, tmp);
      tmp = 0;
    }
    else
      tmp++;
  }
  ans = max(ans, tmp);
  cout<<ans<<endl;
}
  

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,n) for(ll i=0;i<n;i++)
#define nforn(i,n) for(ll i=n-1;i>=0;i--)
#define forne(i,n) for(ll i=1;i<=n;i++)
#define forse(i,s,e) for(ll i=s;i<e;i++)
#define all(v) v.begin(),v.end()
#define MOD 1000000007
#define d1(x) cerr <<"> "<<#x<<" = "<<x<<'\n'
#define d2(x, y) cerr <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<'\n'
#define d3(x, y, z) cerr <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<' '<<#z<<" = "<<z<<'\n'
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
	// cin>>t;
	while(t--){
		int a,b;
		cin>>a>>b;
		ll x = 0,y = 0;
		int temp1 = a,temp2 = b;
		while(temp1--){
			x = x*10 + b;
		}
		while(temp2--){
			y = y * 10 + a;
		}
		cout<<max(x,y)<<"\n";
	}
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);
    ll n;
    cin >> n;
    vector<ll> h(n + 2);
    rep1(i, n) { cin >> h[i]; }

    bool flg = false;
    for (int i = n; i >= 1; i--) {
        if (h[i - 1] - h[i] > 1) {
            flg = false;
            break;
        }
        if (h[i - 1] - h[i] == 1) {
            h[i - 1]--;
        }
        flg = true;
    }

    if (flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

#define MAX_N 150

int x[MAX_N][MAX_N][2];
int n, m, l, minx;
int dp[MAX_N][MAX_N];

int DP(int p, int v) {
	memset(dp, 127, sizeof(dp));
	dp[0][v] = 0;
	for (int i = 0; i < p; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (x[j][k][0] < 1000000) {
					for (int l = 0; l <= v; l++) {
						if (dp[j][l] < 10000000) {
							dp[k][l] = min(dp[k][l], dp[j][l] + x[j][k][1]);
							if(l>=x[j][k][0]){
								dp[k][l - x[j][k][0]] = min(dp[k][l - x[j][k][0]], dp[j][l]);
							}
						}
					}
				}
			}
		}
	}
	minx = 1145141919;
	for (int i = 0; i <= v; i++) {
		minx = min(minx, dp[p - 1][i]);
	}
	return minx;
}

int a, b, c, d;

int main() {
	while (true) {
		memset(x, 127, sizeof(x));
		cin >> n >> m >> l;
		if (n == 0 && m == 0 && l == 0) { break; }
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> c >> d;
			a--;
			b--;
			x[a][b][0] = c;
			x[a][b][1] = d;
			x[b][a][0] = c;
			x[b][a][1] = d;
		}
		cout << DP(n, l) << endl;
	}
}

Measured memory_bytes: 1432
readline()
a=0
b=0
T=zeros(Int,8)
for x=map(x->parse(Int,x),split(readline()))
  if x<3200
    x=div(x,400)
    if T[x+1]==0
      a+=1
    end
    T[x+1]=1
  else
    b+=1
  end
end
println("$(a==0?1:a) $(a+b)")

Measured memory_bytes: 109660
fn main() {
    let (x, n, ps) = read();
    let ans = solve(x, n, ps);
    write(ans);
}

fn read() -> (i32, i32, Vec<i32>) {
    let mut l1 = String::new();
    std::io::stdin().read_line(&mut l1).ok();
    let mut iter1 = l1.trim().split_whitespace();
    let x = iter1.next().unwrap().parse::<i32>().unwrap();
    let n = iter1.next().unwrap().parse::<i32>().unwrap();

    let mut l2 = String::new();
    std::io::stdin().read_line(&mut l2).ok();
    let mut v: Vec<i32> = l2.trim().split_whitespace().map(|x| x.parse::<i32>().unwrap()).collect();
    v.sort();

    (x, n, v)
}

fn write(ans: i32) {
    println!("{}", ans);
}

fn solve(x: i32, n: i32, ps: Vec<i32>) -> i32 {
    //let mut distance = 0;
    let mut i = x;
    let mut j = x;
    loop {

        //if let None = ps.iter().find(|&&e| e == i) {
        if let Err(_) = ps.binary_search(&i) {
            break i;
        } 
        //if let None = ps.iter().find(|&&e| e == j) {
        if let Err(_) = ps.binary_search(&j) {
            break j;
        } 
        //distance += 1;
        //if i > 1 {
            i -= 1;   
        //}
        //if j < 100 {
            j += 1;
        //}
    }
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

struct StronglyConnectedComponents {

  int V;
  vector<vector<int>> G, rG;
  vector<int> vs, cmp;
  vector<bool> used;

  StronglyConnectedComponents(int V) : V(V) {
    used.assign(V, false);
    G.resize(V), rG.resize(V);
    cmp.resize(V);
  }

  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void dfs(int v) {
    used[v] = true;
    for (int c : G[v]) if (not used[c]) dfs(c);
    vs.push_back(v);
  }

  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int c : rG[v]) if (not used[c]) rdfs(c, k);
  }

  int run() {
    fill(used.begin(), used.end(), false);
    vs.clear();
    for (int v = 0; v < V; v++) if (!used[v]) dfs(v);
    fill(used.begin(), used.end(), false);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) if (!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int V, E; cin >> V >> E;
  StronglyConnectedComponents scc(V);

  REP(_, E) {
    int f, t; cin >> f >> t;
    scc.add_edge(f, t);
  }
  scc.run();
  int Q; cin >> Q;
  REP(_, Q) {
    int x, y; cin >> x >> y;
    cout << (scc.cmp[x] == scc.cmp[y]) << endl;
  }
  return 0;
}

Measured memory_bytes: 4472
#include <iostream>

int solve (int);

int main(int argc, char const* argv[])
{
    int times = 0;

    while (true) {
        if(solve(++times) == 1) break;
    }
    return 0;
}

int solve(int times) {
    int max_weight, item_count;
    int prices[1000] = {0};
    int weights[1000] = {0};

    std::cin >> max_weight;
    if (max_weight == 0) return 1;

    std::cin >> item_count;

    for(int i = 0; i < item_count; i++) {
        int p, w;
        char c;
        std::cin >> p >> c >> w;

        prices[i]  = p;
        weights[i] = w;
    }

    int dp[1010] = {0};


    for (int i = 0; i < item_count; i++) {
        int tmp_dp[1010] = {0};

        tmp_dp[weights[i]] = prices[i];

        for (int j = 0; j < 1001; j++) {
            if (dp[j] == 0) continue;

            int plus_weight = j + weights[i];
            int plus_price  = dp[j] + prices[i];
            if (plus_weight > max_weight) continue;
            if (plus_weight >= 1001) continue;
            tmp_dp[plus_weight] = plus_price;
        }

        for (int i = 0; i <= max_weight; i++) {
            dp[i] = std::max(dp[i], tmp_dp[i]);
        }
    }

    int min_weight = 99999;
    int max_price  = 0;
    for (int i = 0; i <= max_weight; i++) {
        if (max_price < dp[i]) {
            max_price  = dp[i];
            min_weight = i;
        } else if (max_price == dp[i]) {
            min_weight = std::min(i, min_weight);
        }
    }

    std::cout << "Case " << times << ":" << std::endl;
    std::cout << max_price << std::endl;
    std::cout << min_weight << std::endl;

    return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T>
using Vec = std::vector<T>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';

#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){if(a < b) a = b;}
template <class T> inline void chmin(T &a, T b){if(a > b) a = b;}
template <class T> inline void reverseSORT(Vec<T> &Array){
  std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1LL << k;}
inline void putsDouble(double d){printf("%.16lf\n", d);}
inline int toInt(const string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res;
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~






int main(void){
    lli r, d, x; scanf("%lld%lld%lld", &r, &d, &x);
    REP(i, 10){
        x *= r; x -= d;
        printf("%lld\n", x);
    }
    return 0;
}

Measured memory_bytes: 888
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Map;
import java.util.Queue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;
import java.util.TreeMap;

public class Main {
	
	public static void main(String[] args) throws IOException {
		String[] input;
		PrintWriter out = new PrintWriter(System.out);
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Scanner s = new Scanner(System.in);
		int n = Integer.parseInt(reader.readLine());
		int[] arr = new int[1000001];
		input = reader.readLine().split(" ");
		for(int i = 0; i < n; i++) {
			arr[Integer.parseInt(input[i])]++;
		}
		boolean[] divisible = new boolean[1000001];
		int ans = 0;
		for(int i = 1; i < arr.length; i++) {
			if(arr[i] > 0 && !divisible[i]) {
				for(int j = i * 2; j < arr.length; j += i) {
					divisible[j] = true;
				}
				if(arr[i] > 1) {
					divisible[i] = true;
				}
			}
			if(!divisible[i]) {
				ans += arr[i];
			}
		}
		out.print(ans);
		out.flush();
		out.close();
	}

}


Measured memory_bytes: 66560
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  cin.tie(0);
  ios::sync_with_stdio(false);


  int n, m;
  cin >> n >> m;
  cout << n*(n - 1)/2 + m*(m -1)/2 << endl;

  return 0;
}


Measured memory_bytes: 256
import random
class Dice:
    def __init__(self, num_list):
        self.top = num_list[0]
        self.dside = num_list[1]
        self.rside = num_list[2]
        self.lside = num_list[3]
        self.uside = num_list[4]
        self.bottom = num_list[5]
        self.dlist = num_list
    def north(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.dside, 
            self.bottom, self.uside, self.top)
    def east(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.lside,
            self.bottom, self.rside, self.top)
    def south(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.uside, 
            self.top, self.dside, self.bottom)

n = int(input())
num = [list(map(int, input().split())) for i in range(n)]
dice = [Dice(num[i]) for i in range(n)]
for idx1, i in enumerate(dice):
    for idx2, j in enumerate(dice):
        if idx2 <= idx1 or len(set(i.dlist)^set(j.dlist)):
            continue
        elif len(set(num[0])) < 4:
            while(i.top != j.top or i.rside != j.rside
                  or i.dside != j.dside):
                mode = random.randint(0, 2)
                if mode == 0:
                    j.north()
                elif mode == 1:
                    j.east()
                else:
                    j.south()
        else:
            while(i.top != j.top or 
                 (i.rside != j.rside and i.uside != j.uside)):
                mode = random.randint(0, 2)
                if mode == 0:
                    j.north()
                elif mode == 1:
                    j.east()
                elif mode == 2:
                    j.south()
        if (i.bottom == j.bottom and i.lside == j.lside 
            and i.dside == j.dside):
            print("No")
            break
    else:
        continue
    break
else:
    print("Yes")



Measured memory_bytes: 8244
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    int sum=0;
    cin>>n;
    int p[n];
    for(int i=0;i<n;i++) cin>>p[i];
    for(int i=1;i<n-1;i++){
        if((p[i-1]>p[i]&&p[i]>=p[i+1])||(p[i-1]<=p[i]&&p[i]<p[i+1])) sum++;
    }
    cout<<sum;
}


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

int main() {

    // input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int K, A, B;
    cin >> K >> A >> B;
    bool flag = false;
    for(int i=A; i<=B; i++){
        if(i %K == 0){
            flag = true;
        }
    }
    
    if(flag){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }
    
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 103, M = 100003;

int n, W;
int w[N], v[N];
LL dp[M];

int main()
{
	//File("");
	n = gi <int> (), W = gi <int> ();
	int sumv = 0;
	for (int i = 1; i <= n; i+=1) w[i] = gi <int> (), v[i] = gi <int> (), sumv += v[i];
	memset(dp, 0x3f, sizeof dp);
	dp[0] = 0;
	for (int i = 1; i <= n; i+=1)
		for (int j = sumv; j >= v[i]; j-=1)
			dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
	int now = sumv;
	while (dp[now] > W) --now;
	printf("%d\n", now);
	return 0;
}


Measured memory_bytes: 4508
#include <iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
bool check(string s,int i,int j) {
    string ss = s.substr(i,j-i+1);
    string sss= ss;
    reverse(ss.begin(),ss.end());
    return ss==sss;
}
long long ok(long long i) {
    return i*(i-1)/2;
}
int main() {
	// your code goes here
int n;
cin>>n;
map<long long,long long>mp;
vector<long long>v(n);
for(int i=0;i<n;i++) {

    cin>>v[i];
    mp[v[i]]++;
   }
   long long ans=0;
   for(auto i:mp) {
       ans+=ok(i.second);
   }
   for(int i=0;i<n;i++) {
       cout<<ans-ok(mp[v[i]])+ok(mp[v[i]]-1)<<endl;
   }

}


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

public class Main
{
	public static void main(String atg[])
	{		
		Scanner sc = new Scanner(System.in);
		String s[] = new String[2002];
		int index = 0;
		while(sc.hasNext())
		{
			String str = sc.next();
			s[index] = str;
			index++;
		}

		int r[] = new int [index];
		boolean flag[] = new boolean[2002];
		//Arrays.fill(flag, true);
		for(int i=0; i<index; i++)
		{
			for(int j=i+1; j<index; j++)
			{
				//&&flag[j]==true
				if(s[i].equals(s[j]))
				{
					r[i]++;
					//flag[j]=false;
				}
			}
		}
		int max=0;
		int maxin=0;
		for(int i=0; i<index; i++)
		{
			if(max < r[i])
			{
				max=r[i];
				maxin = i;
			}
		}
		System.out.print(s[maxin]+" ");
		max =0;
		for(int i=0; i<index; i++)
			if(s[max].length()<s[i].length())
			{
				max =i;
			}
		System.out.println(s[max]);
	}
}

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

int N, A, B;
int X[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> A >> B;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  ll ans = 0;
  for (int i = 0; i + 1 < N; i++) {
    ans += min((ll)A * (X[i + 1] - X[i]), (ll)B);
  }
  cout << ans << endl;

  return 0;
}

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

#define ll long long

#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define output_s(a) printf("%s\n",(a).c_str())

//library----------------------------------------------


int main(){
  string s,t; cin>>s>>t;
  int count=0;
  rep(i,3){
    if(s[i]==t[i]) count++;
  }
  printf("%d\n",count);
  return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N;
  cin >> N;
  N %= 10;
  map<int, string> m{
    {2, "hon"}, {4, "hon"}, {5, "hon"}, {7, "hon"}, {9, "hon"}, {0, "pon"},
        {1, "pon"}, {6, "pon"}, {8, "pon"}, {3, "bon"},

  };
  cout<<m[N]<<endl;

  return 0;
}


Measured memory_bytes: 3604