akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<cmath>
typedef long long ll;
int m,k;
int a[200010];

template<typename T>
inline void read(T &x){
    x = 0; char ch = getchar(); int f = 1;
    for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}

int main(){
    read(m); read(k);
    for(int i = 1;i <= m; i++) read(a[i]);
    for(int i = k + 1;i <= m; i++)
        if(a[i] > a[i - k]) printf("Yes\n");
        else printf("No\n");
    return 0;
}
/*
3
1
-1
-1

2
*/

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

//string型文字列をint型整数にして返す
int str_to_num(string s) {return atoi(s.c_str());}
//約数の総数を返す
int count_divisor(int n){int c[n/2] = {1}; int n_half = n/2; for(int i=2;i<n_half;i++){if(n%i==0){n /= i;c[i]+=1;i--;if(n>1) continue;else break;}  }int r = 1;for(int i=2;i<n_half;i++){r *= c[i];}return r;}
//各桁の数の和を返す
int dig_num(int n){return (n<10) ? n: dig_num(n/10) + n%10;}

int dig_ord(int n){return (n<10) ? 1: dig_ord(n/10) + 1;}

int main(){
  int N; cin >> N;
  long double r = 0;
  REP(i,N){
    long double a; cin >> a;
    r += (1./a);
  }
  r = 1./r;
  cout << r << '\n';
}
  

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

u64 over = 1000000007;

u64 kai(u64 n)
{
  u64 ret = 1;
  for (u64 i = 2; i <= n; ++i) {
    ret = ret * i % over;
  }
  return ret;
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  u64 n, m;
  cin >> n >> m;
  if (n > m+1 || m > n+1) {
    cout << 0 << endl;
    return 0;
  }
  if (m > n) {
    u64 b = n;
    n = m;
    m = b;
  }
  if (n == m+1) {
    cout << kai(m) * kai(n) % over << endl;
    return 0;
  }
  cout << kai(m) * kai(m) * 2 % over << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	string res = "Heisei";
	string S; cin >> S;
	int M, D;
	M = stoi(S.substr(5, 2));
	D = stoi(S.substr(8, 2));

	if (M * 40 + D > 200) res = "TBD";

	cout << res << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll dp[2020][2020];
ll posw[2020],posb[2020];
ll costw[4040][2020],costb[4040][2020];

int main(){
  int n;
  cin>>n;
  char c[2*n+1];
  int a[2*n+1];
  for(int i=1;i<=2*n;i++){
    cin>>c[i]>>a[i];
    //a[i]--;
    if(c[i]=='W'){
      posw[a[i]]=i;
      costw[i][a[i]]++;
    }else{
      posb[a[i]]=i;
      costb[i][a[i]]++;
    }
  }

  for(int i=1;i<=2*n;i++){
    for(int j=n-1;j>=0;j--){
      costw[i][j]+=costw[i][j+1];
      costb[i][j]+=costb[i][j+1];
    }
  }

  for(int j=0;j<=n;j++){
    for(int i=0;i<=2*n;i++){
      costw[i+1][j]+=costw[i][j];
      costb[i+1][j]+=costb[i][j];
    }
  }

  for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j]=1e8;
  dp[0][0]=0;

  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if(i<n) dp[i+1][j]=min(dp[i+1][j],dp[i][j]+costw[posw[i+1]-1][i+1]+costb[posw[i+1]-1][j+1]);
      if(j<n) dp[i][j+1]=min(dp[i][j+1],dp[i][j]+costw[posb[j+1]-1][i+1]+costb[posb[j+1]-1][j+1]);
    }
  }

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

  return 0;
}


Measured memory_bytes: 159360
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<30;
const int MOD = 1000000007;

void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
 
    int ai = A[N - 1];
    int aj = A[0];
    rep(i, N - 1) if (abs(A[i] - ai / 2) <= abs(aj - ai / 2)) aj = A[i];
    cout << ai << " " << aj << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
int main(){
 int n,a;
  cin>>n>>a;
  if(n%500==0||n%500<=a)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


}


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

int main() {
	int rail[10]={0};
	int n,i=0;
	while(cin>>n){
		if(n==0){
			cout<<rail[i-1]<<endl;
			i--;
			continue;
		}
		rail[i]=n;
		i++;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

int main(){
    int N;cin>>N;

    int dp[100010][3];
    dp[0][0]=dp[0][1]=dp[0][2]=0;
    int a[3];
    for(int i=1;i<=N;i++){
        for(int j=0;j<3;j++)
            cin>>a[j];

        dp[i][0]=a[0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[1]+max(dp[i-1][2],dp[i-1][0]);
        dp[i][2]=a[2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[N][0],max(dp[N][1],dp[N][2]))<<endl;
    return 0;
}

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

int main(){
string s;
cin >> s;
if(s=="SUN"){
    cout << 7 << endl;
}else if(s=="MON"){
    cout << 6 << endl;
}else if(s=="TUE"){
    cout << 5 << endl;
}else if(s=="WED"){
    cout << 4 << endl;
}else if(s=="THU"){
    cout << 3 << endl;
}else if(s=="FRI"){
    cout << 2 << endl;
}else if(s=="SAT"){
    cout << 1 << endl;
}else{
    return 0;
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
int s[205],x;
ll dp[205][100005];
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[100005],R[100005];
ll R1[200005];
void make(){
	F[0] = 1;
	for(int i=1;i<100005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<100005;i++) R[i] = modpow(F[i],mod-2);
	for(int i=0;i<100005;i++) R1[i] = modpow(1LL*i,mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int RR[200005];

int main(){
	make();
	cin>>n>>x;
	s[0] = x+1;
	for(int i=1;i<=n;i++) cin>>s[i];
	sort(s+1,s+n+1,greater<int>());
	dp[0][x] = 1;
	for(int i=0;i<200005;i++){
	            int hoge = -1;
				for(int d=n;d>=0;d--){
					if(s[d] > i){
						hoge = d+1;
						break;
					}
				}
				RR[i] = hoge;
	}
	
	{
		for(int j=0;j<n;j++){
			for(int k=0;k<s[j];k++){
				if(dp[j][k] == 0) continue;
				int hoge = RR[k];
				for(int x=hoge;x<=n;x++){
				    //cout << dp[j][k] << " " << modpow(n-hoge+1,mod-2) << " " << j << " " << k << " " << x << endl;
					dp[x][k%s[x]] += dp[j][k] * R1[n-hoge+1] % mod;
					if(dp[x][k%s[x]]>=mod) dp[x][k%s[x]] -= mod;
				}
			}
		}
	}
	ll ans = 0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<s[n];j++){
			ans += F[n] * dp[i][j] % mod * 1LL * j % mod;
		}
	}
	cout << (ans%mod+mod)%mod << endl;
}

Measured memory_bytes: 161536
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {

	int N;
	cin >> N;

	ll ans=0;

	repn(i, N) {
		if (i * 27 / 25 == N) { ans = i; }
	}

	if (ans != 0) { cout << ans; }
	else { cout << ":("; }

	system("PAUSE");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int N, A, B;
  cin >> N >> A >> B;
  if ((B - A) % 2 == 0)
    cout << "Alice" << endl;
  else
    cout << "Borys" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> table(n+1, 0);

  rep(j, k) {
    rep(i, n+1) table[i] = 0;

    rep(i, n) {
      table[max(0ll, i-a[i])]++;
      table[min(n, i+a[i]+1)]--;
    }

    rep(i, n) {
      if (0 < i) table[i] += table[i-1];
    }

    bool flag = true;
    rep(i, n) {
      if (a[i] != table[i]) {
        flag = false;
        break;
      }
    }
    if (flag) break;

    rep(i, n) a[i] = table[i];
  }

  rep(i, n) cout << a[i] << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 6416
#include <bits/stdc++.h>
using namespace std;
const int N = 12, M = 100005;

int n, m;
int a[N][N];

bool c[M];
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i * i < M; ++i)
        c[i * i] = true;
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = i + 1; j <= n; ++j)
        {
            int x = 0;
            for (int k = 1; k <= m; ++k)
            {
                x += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
            }
            if (c[x])
                ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void) {

	int a, b;

	string op;

	cin >> a >> op >> b;

	if (op == "+")cout << a + b;
	else cout << a - b;

	cout << "\n";


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;

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

	int x;
	cin >> x;
	if (x <= 3) {
		cout << "1\n";
		return 0;
	}
	
	int ans = 1;
	for (int b = 2; b*b <= x; b++) {
		int y;
		for (y = b*b; y <= x; y *= b) ;
		y /= b;
		ans = max(ans, y);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
str = input()
set1 = set([2, 4, 5, 7, 9])
set2 = set([0, 1, 6, 8])
n = int(str[-1])
if n in set1:
    res = 'hon'
elif n in set2:
    res = 'pon'
else:
    res = 'bon'

print(res)

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin >> s >> t;
	vector<int> a(26);
	vector<int> b(26);
	rep(i,s.size()){
		a.at(s.at(i)-'a')++;
		b.at(t.at(i)-'a')++;
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	bool ans=true;
	rep(i,26){
		if(a.at(i)!=b.at(i)) ans=false;
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 916
n, x = list(map(int, input().split()))
B = 0
blu = []
s = [0 for i in range(n)]

for i in range(n):
  b, l, u = list(map(int, input().split()))
  blu.append((b, l, u, x*u-b*u+b*l))
  B += b*l
blu.sort(key=lambda x: x[3], reverse=True)

for i in range(n):
  if i==0:
    s[i] = blu[i][3]
  else:
    s[i] = s[i-1] + blu[i][3]

ok = n*x
ng = -1
while ok-ng>1:
  A = 0
  mid = (ok+ng)//2
  k = mid//x
  t = mid%x
  for i in range(n):
    if t<=blu[i][0]:
      rm = t*blu[i][1]
    else:
      rm = t*blu[i][2] - blu[i][0]*(blu[i][2]-blu[i][1])
    if k==0:
      A = max(A, rm)
    elif i<k:
      A = max(A, s[k]-blu[i][3]+rm)
    else:
      A = max(A, s[k-1]+rm)
  if A>=B:
    ok = mid
  else:
    ng = mid

print(ok)

Measured memory_bytes: 76320
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let sa = io.chars();
    let sb = io.chars();
    let sc = io.chars();
    let mut ia = 0usize;
    let mut ib = 0usize;
    let mut ic = 0usize;
    let mut turn = 'a';
    loop {
        if turn == 'a' {
            if ia == sa.len() {
                io.writeln("A");
                return;
            }

            turn = sa[ia];
            ia += 1;
        } else if turn == 'b' {
            if ib == sb.len() {
                io.writeln("B");
                return;
            }
            turn = sb[ib];
            ib += 1;
        } else if turn == 'c' {
            if ic == sc.len() {
                io.writeln("C");
                return;
            }
            turn = sc[ic];
            ic += 1;
        }
    }
}

static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


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

int main(void) {
  string str1, str2;
  bool check;
  int n;
  cin >> n;
  getline(cin, str1);
  
  while(n--) {
    check = false;
    getline(cin, str1);
    
    for(int i = 1; i < 26; ++i) {
      if(check) {
        break;
      }
      if(i % 2 == 0 || i % 13 == 0) {
        continue;
      }
      for(int j = 0; j < 26; ++j) {
        str2 = str1;
        for(int k = 0; k < str1.size(); ++k) {
          if(str1[k] == ' ') {
            continue;
          }
          str2[k] = (((str1[k] - 'a') * i + j) % 26) + 'a';
        }
        if(str2.find("that") != -1 || str2.find("this") != -1) {
          check = true;
          cout << str2 << endl;
          break;
        }
      }
    }
  }
}


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

int main(){
  char S[16];
  
  scanf("%s",S);
  int i,j,k,w=0,l=0;
  
  for(i=0;i<strlen(S);i++){
    if(S[i] == 'o')
      w++;
  }
  
  if(w+15-strlen(S) >= 8){
    puts("YES");
  }
  else
    puts("NO");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
void f(long long n,vector<long long>& v){
  v.push_back(n);
  for(long long i=2;i*i<=n;i++){
    if(n%i==0){
      v.push_back(i);
      if(n!=i*i) v.push_back(n/i);
    }
  }
}
int main(){
  long long n;cin>>n;
  if(n==2){
    cout<<1<<endl;
    return 0;
  }
  vector<long long> s1,s2;
  long long c=0;
  f(n-1,s1);c+=s1.size();
  f(n,s2);
  for(auto a:s2){
    long long nn=n;
    while(nn%a==0) nn/=a;
    if(nn%a==1) c++;
  }
  cout<<c<<endl;
  return 0;
}


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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //good luck kittu!
    char c; cin>>c;
    if(c=='A') cout<<"T\n";
    else if(c=='T') cout<<"A\n";
    else if(c=='G') cout<<"C\n";
    else cout<<"G\n";
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    a = LI()
    if sum(a) == 0:
        print("Yes")
        return
    if n%3 != 0:
        print("No")
        return
    d = defaultdict(lambda : 0)
    for i in a:
        d[i] += 1
    if len(list(d.items())) == 2:
        if d[0] == n//3:
            print("Yes")
            return
        else:
            print("No")
            return
    k = 0
    for i,j in d.items():
        k ^= i
        if j != n//3:
            print("No")
            return
    if not k:
        print("Yes")
        return
    print("No")
    return

#B
def B():
    def dfs(x,d):
        for y in v[x]:
            if d[y]:
                d[y] = 0
                dfs(y,d)
                if f[y]:
                    ans[(min(x,y),max(x,y))] ^= 1
                    f[x] ^= 1
                    f[y] ^= 1
    n,m = LI()
    ans = defaultdict(int)
    f = [0]*(n+1)
    v = [[] for i in range(n+1)]
    for i in range(m):
        a,b = LI()
        ans[(min(a,b),max(a,b))] = 1
        v[a].append(b)
        v[b].append(a)
        f[min(a,b)] ^= 1
    if m%2:
        print(-1)
        return
    d = [1]*(n+1)
    d[1] = 0
    dfs(1,d)
    for v,i in ans.items():
        if i:
            print(*v)
        else:
            print(*v[::-1])
    return

#C
def C():
    n = I()
    p = [(1<<i) for i in range(100)]
    if n in p:
        print("No")
        quit()
    if n+1 in p:
        print("Yes")
        for i in range(1,2*n):
            print(i,i+1)
        quit()
    ans = []
    for i in range(1,3):
        ans.append((i,i+1))
    ans.append((3,n+1))
    for i in range(1,3):
        ans.append((i+n,i+n+1))
    u = 1
    d = 1
    for i in range(2,n//2+n%2):
        ans.append((u,2*i))
        ans.append((d,2*i+1))
        ans.append((2*i,2*i+n+1))
        ans.append((2*i+1,2*i+n))
        u = 2*i+n+1
        d = 2*i+n

    if n%2:
        print("Yes")
        for i,j in ans:
            print(i,j)
    else:
        ans.append((n-1,n))
        for i in range(n):
            if p[i]&n:
                break
        ans.append((p[i+1]-2,2*n))
        print("Yes")
        for i,j in ans:
            print(i,j)
    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 201760
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int INF=999999999999999;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


long long int n,m,l[200010],r[200010],d[200010],used[100010]={},unionUsed[100010]={},len[100010]={};
vector< pair<long long int,long long int> >ed[100010];
queue<long long int>task,nexttask,emp;

int main() {
	cout << fixed << setprecision(5);
	cin>>n>>m;
	UnionFind tree(n);
	for(int i=0;i<m;i++){
		cin>>l[i]>>r[i]>>d[i];	
		l[i]-=1;
		r[i]-=1;
		ed[l[i]].push_back({r[i],d[i]});
		ed[r[i]].push_back({l[i],-d[i]});
		tree.unite(l[i],r[i]);
		}
	for(int i=0;i<n;i++)
	{
		len[i]=INF;
		if(unionUsed[tree.root(i)]==0){
			unionUsed[tree.root(i)]=1;
			nexttask.push(i);
			used[i]=1;
			len[i]=0;	
		}
	}
	while(!nexttask.empty()){
		task=nexttask;
		nexttask=emp;
		while(!task.empty()){
			for(int i=0;i<ed[task.front()].size();i++){
				
				if(len[ed[task.front()][i].first]==INF){
					len[ed[task.front()][i].first]=len[task.front()]+ed[task.front()][i].second;	
					nexttask.push(ed[task.front()][i].first);
				}else{
					if(len[ed[task.front()][i].first]!=len[task.front()]+ed[task.front()][i].second){
						cout<<"No "<<endl;
						return 0;	
					}	
				}
			}
			task.pop();	
		}
	}
	cout<<"Yes"<<endl;
	
	return 0;
}


Measured memory_bytes: 21104
n, y = map(int, input().split())

f = False
for i in range(n, -1, -1):
    if f:
        break
    for j in range(n-i, -1, -1):
        if f:
            break
        if (n - i - j < 0):
            break
        if (10000 * i + 5000 * j + 1000 * (n - i - j) == y):
            print(i, j, (n - i - j))
            f = True

if f is False:
    print(-1, -1, -1)


Measured memory_bytes: 40684
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 100005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,k;
   cin>>n>>k;
   vector<pii>v;
   for(int i=0;i<n;i++)
   {
       int y,x;
       cin>>x>>y;
       v.pb({y,x});
   }
   sort(all(v),greater<pii>());
   set<int>s;
   int sum=0,ans=0;
   vector<int>st;
   //debug(v);
   for(int i=0;i<k;i++)
   {
       if(s.count(v[i].S))
       {
           st.pb(v[i].F);
       }
       sum+=v[i].F;
       s.insert(v[i].S);
   }
   int d=(sum + s.size()*s.size());
   ans=d;
   //debug(ans);
   for(int i=k;i<n;i++)
   {
       if(st.empty())break;
       if(s.count(v[i].S))continue;
       sum-=st.back();
       st.pop_back();
       sum+=v[i].F;
       s.insert(v[i].S);
       int cnt=(sum + s.size()*s.size());
       ans=max(ans,cnt);
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 8180
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
vector<int> ch[2020];

i64 modpow(i64 a, int p = MOD - 2)
{
	if (p == 0) return 1;
	i64 ret = modpow(a, p / 2);
	ret = ret * ret % MOD;

	if (p % 2 == 1) ret = ret * a % MOD;
	return ret;
}

i64 fact[2020], facti[2020];

vector<vector<i64>> join(vector<vector<i64>> &data, vector<i64> &ext0, vector<i64> &ext1)
{
	vector<vector<i64>> ret(3, vector<i64>(data[0].size() + ext0.size() - 1, 0LL));
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < data[0].size(); ++j) {
			for (int k = 0; k < ext0.size(); ++k) {
				ADD(ret[i][j + k], data[i][j] * ext0[k]);

				if (i == 0) ADD(ret[i + 1][j + k], data[i][j] * ext1[k]);
				else if (i == 1) ADD(ret[i + 1][j + k], data[i][j] * ext1[k]  % MOD * facti[2]);
			}
		}
	}
	return ret;
}

vector<vector<i64>> solve(int p)
{
	vector<vector<i64>> ret(3, vector<i64>());
	ret[0].push_back(1LL);
	ret[1].push_back(0LL);
	ret[2].push_back(0LL);
	for (int q : ch[p]) {
		auto ans = solve(q);

		// extend
		vector<i64> ext0(ans[0].size() + 1, 0LL), ext1(ans[0].size() + 1, 0LL);
		for (int i = 0; i < ans[0].size(); ++i) {
			ADD(ext0[i], ans[0][i]);
			ADD(ext0[i], ans[1][i]);
			ADD(ext0[i], ans[2][i]);
			ADD(ext1[i + 1], ans[0][i] * 2);
			ADD(ext1[i + 1], ans[1][i]);
			// ADD(ext1[i], ans[2][i]);
		}
		ret = join(ret, ext0, ext1);
	}
	/*
	printf("%d\n", p);
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < ret[0].size(); ++j) printf("%lld ", ret[i][j]);
		puts("");
	}
	puts("---");
	*/
	return ret;
}

int main()
{
	scanf("%d", &N);
	fact[0] = facti[0] = 1;
	for (int i = 1; i <= N; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
		facti[i] = modpow(fact[i]);
	}
	for (int i = 1; i < N; ++i) {
		int p;
		scanf("%d", &p);
		--p;
		ch[p].push_back(i);
	}

	auto ans = solve(0);

	i64 ret = 0;
	for (int i = 0; i < N; ++i) {
		i64 val = 0;
		ADD(val, ans[0][i]);
		ADD(val, ans[1][i]);
		ADD(val, ans[2][i]);

		if (i % 2 == 1) val = MOD - val % MOD;
		ADD(ret, val * fact[N - i]);
	}
	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;
ll mod = 1e9 + 7;
const int N = 1e5 + 10;

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

ll n, s;

bool ok(ll num) {
	ll sum = 0, t = num;
	while (num) {
		sum += num % 10;
		num /= 10;
	}
	return t - sum >= s;
}

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (a >= b)
		cout << "delicious";
	else if (a + x >= b)
		cout << "safe";
	else cout << "dangerous";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
        int e, y;
        scanf("%d %d", &e, &y);

        if(e==1) printf("%d\n", 1867+y);
        else if(e==2) printf("%d\n", 1911+y);
        else if(e==3) printf("%d\n", 1925+y);
        else if(e==4) printf("%d\n", 1988+y);
        else{
                if(1988<y) printf("H%d\n", y-1988);
                else if(1925<y) printf("S%d\n", y-1925);
                else if(1911<y) printf("T%d\n", y-1911);
                else printf("M%d\n", y-1867);
        }
        return 0;
}


Measured memory_bytes: 2148
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      aa: [usize; n],
    }
    let mut acm = vec![0; n+1];
    for i in 0..n {
        acm[i+1] = acm[i] + aa[i];
    }

    const INF: usize = 1 << 60;

    let mut dp = vec![vec![INF; n]; n+1];
    for w in 0..2 {
        for l in 0..n {
            dp[w][l] = 0;
        }
    }

    for w in 2..n+1 {
        for l in 0..n {
            let r = l+w-1;
            if r >= n { break; }
            for pos in l..r {
                // [l,pos] | (pos, r] に分割
                let w1 = pos-l+1;
                let w2 = r-pos;
                dp[w][l] = min(dp[w][l], dp[w1][l] + dp[w2][pos+1] + acm[r+1] - acm[l]);
            }
        }
    }
    println!("{}", dp[n][0]);
}


Measured memory_bytes: 4352
def gcd(n,m):#n,mは正の整数、最大公約数　許容は？
    if n==0:
        return m
    elif m==0:
        return n
    elif n>m:
        n=n%m
        return gcd(n,m)
    else:
        m=m%n
        return gcd(n,m)

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

list1=[1 for i in range(0,N)]
list2=[1 for i in range(0,N)]
list1[0]=A[0]
list2[0]=A[N-1]

for i in range(1,N):
    list1[i]=gcd(list1[i-1],A[i])
    list2[i]=gcd(list2[i-1],A[N-1-i])
m=list2[N-2]
for i in range(0,N-2):
    test=gcd(list1[i],list2[N-3-i])
    if test>m:
        m=test
test=list1[N-2]
if test>m:
    m=test
print(m)

Measured memory_bytes: 65124
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

using Weight=int;
using DArray=vector<Weight>;
using DMatrix=vector<DArray>;

static const Weight INF=1<<29;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

template <class T>
using lp_queue=priority_queue<T, deque<T>, greater<T>>;

vector<Weight> shortest_distance(const Graph &g, size_t s) {
    /* Dijkstra */
    size_t V=g.size();
    vector<Weight> d(V, INF); d[s]=0;

    lp_queue<pair<Weight, size_t>> q; q.push(make_pair(0, s));
    while (!q.empty()) {
        pair<Weight, size_t> p=q.top(); q.pop();
        size_t v=p.second;
        if (d[v] < p.first) continue;

        for (const Edge &e: g[v])
            if (d[e.dst] > d[v] + e.weight) {
                d[e.dst] = d[v] + e.weight;
                q.push(make_pair(d[e.dst], e.dst));
            }
    }
    return d;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Graph g(n);
    for (size_t i=0; i<n; ++i) {
        size_t u, k;
        scanf("%zu %zu", &u, &k);

        for (size_t j=0; j<k; ++j) {
            size_t c;
            Weight v;
            scanf("%zu %d", &c, &v);

            connect(g, u, c, v);
        }
    }

    vector<Weight> d=shortest_distance(g, 0);
    for (size_t i=0; i<n; ++i)
        printf("%zu %d\n", i, d[i]);

    return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	string s;
	cin >> s;
	int b = -1;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'B') {
			b = i;
			break;
		}
	}
	if(b == -1) {
		cout << 0 << endl;
		return 0;
	}
	int to = b;
	long long ans = 0;
	for(int i = b; i < s.size(); i++) {
		if(s[i] == 'W') {
			ans += i - to;
			to++;
		}
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 720
#7916513 保存用
import sys

H, W = map(int, input().split())

if H % 3 == 0 or W % 3 == 0:
	print(0)
	sys.exit()

kai_1 = min(H,W)

def solve_2(a,b):
	w = a // 2
	s_l = (a-w) * b
	s_s = w * b
	s_r = 0

	tmp = s_l

	for i in range(b):
		s_r += a
		s_s -= w
		s_l -= (a-w)

		sa = max(s_r,s_s,s_l) - min(s_r,s_s,s_l)

		if tmp > sa:
			tmp = sa
			continue
		else:
			return tmp

kai_2 = solve_2(H,W)
kai_3 = solve_2(W,H)

print(min(kai_1,kai_2,kai_3))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
    fast;
    lli a;
    cin>>a;
    string s;
    cin>>s;
    lli i;
    vector<lli>v;
    fr(i,s.length())
    {
        if(s[i]!='.')
            v.pb(s[i]-'0');
    }
    lli num=0;
    fr(i,v.size())
    {
        num+=v[i]*pow(10,v.size()-i-1);
    }
    lli x=a*num;
    v.clear();
    while(x>0)
    {
        v.pb(x%10);
        x/=10;
    }
    if(v.size()<=2)
    {
        cout<<0;
        return 0;
    }
    for(i=v.size()-1;i>=2;i--)
    {
        cout<<v[i];
    }
    
    return 0;
}

Measured memory_bytes: 3772
N=int(input())
L=[]
for i in range (N):
	L.append(input())
M=0
A=0
R=0
C=0
H=0
for i in L:
	if i[0]=="M":
		M+=1
	elif i[0]=="A":
		A+=1
	elif i[0]=="R":
		R+=1
	elif i[0]=="C":
		C+=1
	elif i[0]=="H":
		H+=1
ans=(M*A*R)+(M*A*C)+(M*A*H)+(M*R*C)+(M*R*H)+(M*C*H)+(A*R*C)+(A*R*H)+(A*C*H)+(R*C*H)
print(ans)

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define MOD 1000000007
#define INF 9223372036854775807

int n,m,r,a,b,c,dp[200][200],ans=INF;
vector<int> v;

main() {
    rep(i,200) rep(j,200) if (i != j) dp[i][j] = INF/2;
    cin >> n >> m >> r;
    rep(i,r) {
        int hoge;
        cin >> hoge;
        v.pb(--hoge);
    }
    rep(i,m) {
        cin >> a >> b >> c;
        a--,b--;
        dp[a][b] = dp[b][a] = c;
    }
    rep(k,n) rep(i,n) rep(j,n) dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
    sort(all(v));
    do {
        int tmpans = 0;
        rep(i,r-1) tmpans += dp[v[i]][v[i+1]];
        ans = min(ans,tmpans);
    }while(next_permutation(all(v)));
    cout << ans << endl;
}



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

int main(){
//srandom((unsigned long)time(NULL));
string s;
cin>>s;
long long cnt0=0,cnt1=0;
//cnt0 010101
//cnt1 101010
long long n=s.size();
//cout<<"size="<<n<<endl;
for(long long i=0;i<n;i++){
    if(i%2==0){
        if(s[i]!='0')cnt0++;
        else cnt1++;
    }
    if(i%2==1){
        if(s[i]!='1') cnt0++;
        else cnt1++;
    }
}
cout<<min(cnt0,cnt1)<<endl;

return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#include <atcoder/all>
 
typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
 
#define PI 3.14159265358979323846
 
using namespace std;
using namespace atcoder;
 
using mint = modint1000000007;
// using mint = modint998244353;
 
template <typename T>
static inline void ArrayInput(vector<T> &A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}
 
template <typename T>
static inline void ArrayPut(const vector<T> &A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}
 
template <typename T>
static inline T ArraySum(vector<T> &A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}
 
bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first > b.first;
  }
}
 
i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
 
static inline u64 gcd(u64 a, u64 b) { return __gcd(a, b); }
 
static inline u64 lcm(u64 a, u64 b) { return (a / gcd(a, b)) * b; }
 
i64 My_Comb(u64 n, u64 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}
 
vector<i64> p;
std::vector<bool> is_prime(1000000 + 1, true);
void Eratosthenes(const int N) {
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      p.emplace_back(i);
    }
  }
}
 
int main() {
  cout << setprecision(18);
 
  u32 K;
  cin >> K;
 
  string S;
  for (u32 i = 0; i < K; ++i) {
    S += "ACL";
  }
 
  cout << S << endl;
 
  return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=5e5+40,MAXM=1e3+10;
const ll llINF=0x7ffffffffffffff;
const int MOD=1e9+7,INF=0x7fffffff;
#define lowbit(x) x&-x
int a[MAXN];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int temp=a[1];
    for(int i=2;i<=n;i++)
        temp^=a[i];
    if(temp)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <string>
using namespace std;

const char w[6] = {' ', '\'', ',', '-', '.', '?'};
const char v[6] = {' ', '.', ',', '-', '\'', '?'};
const char *enc1[6] = {"101", "000000", "000011", "10010001", "010001", "000001"};
const char *enc2[26] = {"100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"};

void decode(string &buf) {
  int t;
  t = 0;
  for (int i=0; i<5; i++) {
    t <<= 1;
    t += buf[i] - '0';
  }
  if (t < 26) printf("%c", 'A'+t);
  else printf("%c", v[t-26]);
  buf = buf.substr(5);
}

int main() {
  int t;
  char c;
  string buf;

  while ((c = getchar()) != EOF) {
    if (c>='A' && c<='Z') {
      buf += enc2[c-'A'];
    } else {
      for (int i=0; i<6; i++) {
        if (c == w[i]) {
          buf += enc1[i];
          break;
        }
      }
    }
    while (buf.length() >= 5) decode(buf);
    if (c=='\n') {
      t = buf.length();
      if (t && t < 5) {
        for (; t<5; ++t) {
          buf += "0";
        }
        decode(buf);
      }
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 980
#include<cstdio>
#include<map>
using namespace std;
int main()
{
    map<int,bool>mp;
    map<int,bool>::iterator it;
    long long cnt;
    int n,id;
   scanf("%d",&n);
    {
         cnt=0;
         mp.clear();
         while(n--)
         {
             scanf("%d",&id);
             it=mp.find(id);
             if(it==mp.end())
             {
                 mp.insert(make_pair(id,true));
                 cnt++;
             }
             else
             {
                 if(it->second)
                 {
                     it->second=false;
                     cnt--;
                 }
                 else
                 {
                     it->second=true;
                     cnt++;
                 }
             }

         }
    } printf("%lld\n",cnt);
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
typedef long long ll;


using namespace std;

char ch[15];

int main() {
	scanf("%s", ch + 1);
	int s = 0;
	for (int i = 1; i <= strlen(ch + 1); i++) {
		if (ch[i] == 'C') {
			s++;
			if (s >= 2) {
				cout << "WA" << endl;
				return 0;
			}
		}
		if (ch[i] != 'A' and ch[i] != 'C' and ch[i] < 'a') {
			cout << "WA" << endl;
			return 0;
		}
		else {
			if (i == 2 or i == strlen(ch + 1)) {
				if (ch[i] == 'C') {
					cout << "WA" << endl;
					return 0;
				}
			}
			else {
				if (i == 1) {
					if (ch[i] != 'A') {
						cout << "WA" << endl;
						return 0;
					}
				}
			}
		}
	}
	if (s == 0) {
		cout << "WA" << endl;
		return 0;
	}
	
	cout << "AC" << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

bool f[111111];

int a[111111];

signed main(){
    fill_n(f,111111,1);
    f[0]=f[1]=0;
    for(int i=2;i<111111;i++){
        if(!f[i])continue;
        for(int j=i+i;j<111111;j+=i)f[j]=0;
    }
    for(int i=1;i<111111;i++){
        if(f[i]&&f[(i+1)/2])a[i]=1;
    }
    
    rep(i,111111-1)a[i+1]+=a[i];
    
    int Q;cin>>Q;
    while(Q--){
        int l,r;
        cin>>l>>r;
        cout<<a[r]-a[l-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1664
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>
using namespace std;

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

#define F first
#define S second
#define MP make_pair

const int MAX = 1e5+9;
const ll MOD = 1e9+7;

vector <int> e, o;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;
		if (x % 2)
			o.push_back(x);
		else
			e.push_back(x);
	}
	vector <int> ans;
	if (n % 2) {
		if (o.size() > 1)
			return cout << "Impossible\n", 0;
		cout << o[0] << " ";
		for (auto x : e)
			cout << x << " ";
		cout << "\n";
		if (o[0]-1)
			cout << m+1 << "\n" << o[0]-1 << " ";
		else
			cout << m << "\n";
		for (auto x : e)
			cout << x << " "; cout << 1 ;
		cout << "\n";
	} else {
		if (o.size() > 2)
			return cout << "Impossible\n", 0;
		if (o.size()) {
			cout << o[0] << " ";
			for (auto x : e)
				cout << x << " ";
			cout << o[1] << "\n";
			if (o[1]-1)
				cout << m << "\n";
			else
				cout << m-1 << "\n";
			cout << o[0]+1 << " ";
			for (auto x : e)
				cout << x << " ";
			if (o[1]-1)
				cout << o[1]-1 << " ";
			cout << "\n";
		} else {
			for (auto x : e)
				cout << x << " ";
			cout << "\n";
			cout << m + ((m == 1) ? 1 : 0) << "\n";
			cout << e[0]-1 << " ";
			if (m-1) {
				for (int i = 1; i < e.size()-1; i++)
					cout << e[i] << " ";
				cout << e[e.size()-1]+1 << " ";
			} else
				cout << 1 ;
			cout << "\n";
		}
	}
}

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

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int>> s(m);
  for(int i = 0; i < m; i++) {
    int k; cin >> k;
    s[i].resize(k);
    for(int j = 0; j < k; j++) {
      cin >> s[i][j]; s[i][j]--;
    }
  }
  vector<int> p(m);
  for(int i = 0; i < m; i++) cin >> p[i];

  int ans = 0;
  for(int i = 0; i < (1<<n); i++) {
    bool ok = true;
    for(int j = 0; j < m; j++) {
      int cnt = 0;
      for(int v: s[j]) {
        if(i>>v & 1) cnt++;
      }
      if(cnt % 2 != p[j]) ok = false;
    }
    if(ok) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648