akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
int sr, sc, gr, gc;
int n;
map<P, bool> fur;
int lr, lc;
vector<int> dr1 = {0, 1, 1, 0, -1, -1}, dc1 = {1, 0, -1, -1, -1, 0}, dr2 = {0, 1, 1, 0, -1, -1}, dc2 = {1, 1, 0, -1, 0, 1};
struct Elm {
  int cnt, r, c, t;
};
bool operator< (const Elm &e1, const Elm &e2) {
  return e1.cnt > e2.cnt;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin >> sr >> sc >> gr >> gc;
  cin >> n;
  for(int i=0;i<n;++i) {
    int r, c; cin >> r >> c;
    fur[{r, c}] = true;
  }
  cin >> lr >> lc;
  map<pair<int, P>, int> dist;
  priority_queue<Elm> pq;
  dist[{sr, {sc, 0}}] = 1;
  pq.push({1, sr, sc, 0});
  int ans = -1;
  while(!pq.empty()) {
    auto now = pq.top(); pq.pop();
    if(dist[{now.r, {now.c, now.t % 6}}] < now.cnt) continue;
    if(now.r == gr && now.c == gc) {
      ans = now.cnt - 1;
      break;
    }
    int dir = abs(now.r * now.c * now.t) % 6;
    for(int i=0;i<6;++i) {
      int nr, nc;
      if(now.r % 2 == 0) nr = now.r + dr1[i], nc = now.c + dc1[i];
      else nr = now.r + dr2[i], nc = now.c + dc2[i];
      if(fur[{nr, nc}]) continue;
      if(abs(nr) > lr || abs(nc) > lc) continue;
      int nt = now.t + 1;
      int ncnt = now.cnt + (i != dir);
      if(dist[{nr, {nc, nt % 6}}] == 0 || dist[{nr, {nc, nt % 6}}] > ncnt) {
        dist[{nr, {nc, nt % 6}}] = ncnt;
        pq.push({ncnt, nr, nc, nt % 6});
      }
    }
    if(dist[{now.r, {now.c, (now.t + 1) % 6}}] == 0 || dist[{now.r, {now.c, (now.t + 1) % 6}}] > now.cnt + 1) {
      dist[{now.r, {now.c, (now.t + 1) % 6}}] = now.cnt + 1;
      pq.push({now.cnt + 1, now.r, now.c, (now.t + 1) % 6});
    }
  }
  cout << ans << endl;
}



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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t[3];
	cin>>t[0]>>t[1]>>t[2];
	sort(t, t+3);
	if(t[0]==t[1] && t[1] != t[2])
		cout<<"Yes";
	else if(t[1]==t[2] && t[0] != t[1])
		cout<<"Yes";
	else
		cout<<"No";
}


Measured memory_bytes: 256
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);

	REP(i, N) {
		cin >> a[i];
	}

	int max_mod = 0;
	REP(i, N) {
		max_mod += a[i];
	}
	max_mod -= N;

	cout << max_mod << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int N, ans, countW, countR;
  ans = countW = countR = 0;
  cin >> N;
  string s;
  cin >> s;
  for (int i = 0; i < N; ++i) {
    if (s[i] == 'W') {
      ++countW;
    }
    if (s[i] == 'R') {
      ++countR;
    }
  }
  // printf("%d %d\n", countW, countR);
  int mid = countR;
  int countW2, countR2;
  countW2 = countR2 = 0;
  for (int i = 0; i < N; ++i) {
    if (s[i] == 'W' && i < mid) {
      ++countW2;
    }
    if (s[i] == 'R' && i >= mid) {
      ++countR2;
    }
  }
  ans = min(countW2, countR2);
  printf("%d\n", ans);
  return 0;
}

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if (u == s)
        a--;
    else
        b--;
    cout << a << " " << b << endl;
}


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

char s[1001];
int sum[3][1001][1001];
int main() {
	int m, n, k; scanf("%d%d%d", &m, &n, &k);
	rep(i, m) {
		scanf("%s", s);
		rep(j, n) {
			if (s[j] == 'J')sum[0][i + 1][j + 1]++;
			else if (s[j] == 'O')sum[1][i + 1][j + 1]++;
			else sum[2][i + 1][j + 1]++;
		}
	}
	rep(k, 3)for (int i = 1; i <= m; i++)for (int j = 1; j <= n; j++)
		sum[k][i][j] += sum[k][i][j - 1];
	rep(k, 3)for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)
		sum[k][j][i] += sum[k][j - 1][i];
	rep(i, k) {
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
		rep(t, 3) {
			int ans = sum[t][c][d];
			if (a)ans -= sum[t][a - 1][d];
			if (b)ans -= sum[t][c][b - 1];
			if (a&&b)ans += sum[t][a - 1][b - 1];
			if (t)printf(" ");
			printf("%d", ans);
		}
		printf("\n");
	}
}

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

int main() {
  long N;
  cin>>N;
  vector<vector<long>> a(100005,vector<long>(2));
  vector<vector<long>> b(100005,vector<long>(2));
  long al=0,bl=0;
  for(int i=0;i<N;i++){
    long v;
    cin>>v;
    if(i%2==0) a[v][0]++,al++;
    else b[v][0]++,bl++;
  }
  for(int i=0;i<100005;i++) a[i][1]=i,b[i][1]=i;

  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  reverse(a.begin(),a.end());
  reverse(b.begin(),b.end());
  long ans1=1234567890;
  long x=a[0][0];
  long y=b[0][0];
  if(a[0][1]!=b[0][1]){
    ans1=(al-x)+(bl-y);
  }
  long ans2=1234567890;
  x=a[1][0];
  y=b[0][0];
  if(a[1][1]!=b[0][1]){
    ans2=(al-x)+(bl-y);
  }
  long ans3=1234567890;
  x=a[0][0];
  y=b[1][0];
  if(a[0][1]!=b[1][1]){
    ans3=(al-x)+(bl-y);
  }
  cout<<min(min(ans1,ans2),ans3)<<endl;
  }


Measured memory_bytes: 14348
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        List<String> list = new ArrayList<>(Arrays.asList(new String[] { "3", "5", "7" }));
        for (int i = 0; i < 10000; i++) {
            String base = list.get(i);
            list.add(base + 3);
            list.add(base + 5);
            list.add(base + 7);
        }

        List<Long> longList = list.stream().filter(i -> i.contains("3") && i.contains("5") && i.contains("7"))
                .map(i -> Long.parseLong(i)).collect(Collectors.toList());

        int result = 0;
        for (int i = 0; i < longList.size(); i++) {
            if (longList.get(i) <= (long) n) {
                result++;
            }
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 33036
#include <stdio.h>
#include <string.h>
 
int main(void){
  int i,trial,judge,tpoint=0,hpoint=0;
  char taro[110],hanako[110];
 
  scanf("%d",&trial);
  for(i=0;i<trial;i++){
    scanf("%s",taro);  scanf("%s",hanako);
    judge=strcmp(taro,hanako);
    if(judge>0)  tpoint+=3;
    else if(judge<0)  hpoint+=3;
    else {
      tpoint++;  hpoint++;
    }
  }
  printf("%d %d\n",tpoint,hpoint);
 
  return 0;
}

Measured memory_bytes: 604
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
void solve(){
    ll n, t;
    cin >> n >> t;
    vll a(n);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        a[i] = x;
    }
    ll sum = t;
    for (int i = 1; i < n; ++i) {
        sum += min(t, a[i] - a[i-1]);
    }
    cout << sum;
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 1792
N,K=map(int,input().split())
A=list(map(int,input().split()))
ret = 0
for a in range(N):
  for b in range(N-a+1):
    cmax = K-a-b
    if cmax >= 0:
      W=A[:a]+A[N-b:]
      W.sort()
      c=min(sum([1 for i in W if i<0]),cmax)
      ret=max(ret,sum(W[c:]))
print(ret)

Measured memory_bytes: 3064
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{

		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		System.out.println(x*y+" "+(x+y)*2);
	}
}

Measured memory_bytes: 17160
MOD = 10 ** 9 + 7
S = input()
N = len(S)
mod13 = [0] * 13
mod13[0] = 1
exponent = 1
for i in range(1, N + 1):
    mod13_new = [0] * 13
    c = S[-i]
    if c == "?":
        for n in range(10):
            m = n * exponent % 13
            for r in range(13):
                mod13_new[(r + m) % 13] += mod13[r]
    else:
        for r in range(13):
            mod13_new[(r + int(c) * exponent) % 13] = mod13[r]
    exponent = exponent * 10 % 13
    for r in range(13):
        mod13_new[r] %= MOD
    mod13 = mod13_new
print(mod13[5])

Measured memory_bytes: 42988
#include <iostream>

using namespace std;

int main(){
    unsigned long  A,B,N;
    cin >> A >> B >> N;

    unsigned long i = B-1;
    if(B > N){
        i=N;
    }
    unsigned long R = (long)(((A*i)/B) - A * ((long)i/B));
    cout << R << '\n';
    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int top = (1 << 12) - 1;
	int N, M, X, ans = 2e9;
	cin >> N >> M >> X;
	vector<int> val(N);
	vector<vector<int> > A(N, vector<int>(M));
	for (int i = 0; i < N; ++i) {
		cin >> val[i];
		for (int j = 0; j < M; ++j) cin >> A[i][j];
	}
	auto check = [&](vector<int> tmp) {
		bool f = true;
		vector<int> sum(M, 0);
		for (int i = 0; i < N; ++i)
			if (tmp[i])
				for (int j = 0; j < M; ++j)
					sum[j] += A[i][j];
		for (auto i : sum)
			if (i < X)
				f = false;
		return f;
	};

	for (int i = 1; i <= top; ++i) {
		int num = i;
		vector<int> tmp(N, 0);
		for (int i = 0; i < N; ++i) {
			tmp[i] = (num % 2);
			num >>= 1;
		}
		if (check(tmp)) {
			int res = 0;
			for (int i = 0; i < N; ++i)
				if (tmp[i])
					res += val[i];
			ans = min(ans, res);
		}
	}
	cout << (ans == 2e9 ? -1 : ans);
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

template <unsigned long long mod > class modint{
public:
    ll x;
    constexpr modint(){x = 0;}
    constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){}
    constexpr modint operator-(){
        return x == 0 ? 0 : mod - x;
    }
    constexpr modint& operator+=(const modint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint operator+(const modint& a) const{
        return modint(*this) += a;
    }
    constexpr modint& operator-=(const modint& a){
        if((x -= a.x) < 0) x += mod;
        return *this;
    }
    constexpr modint operator-(const modint& a) const{
        return modint(*this) -= a;
    }
    constexpr modint& operator*=(const modint& a){
        (x *= a.x)%=mod;
        return *this;
    }
    constexpr modint operator*(const modint& a) const{
        return modint(*this) *= a;
    }
    constexpr modint pow(unsigned long long pw) const{
        modint res(1), comp(*this);
        while(pw){
            if(pw&1) res *= comp;
            comp *= comp;
            pw >>= 1;
        }
        return res;
    }
    //以下、modが素数のときのみ
    constexpr modint inv() const{
        return modint(*this).pow(mod - 2);
    }
    constexpr modint& operator/=(const modint &a){
        (x *= a.inv().x)%=mod;
        return *this;
    }
    constexpr modint operator/(const modint &a) const{
        return modint(*this) /= a;
    }
};
#define mod1 998244353
using mint = modint<mod1>;

ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
using vm = vector<mint>;

int main() {
    class BIT{
            ll n;
      		vector<mint> bitree;
        public:
        	BIT(unsigned long _n) : bitree(_n + 1, 0){
              n = _n;
            }
        	void add(ll id, mint x){
              while(id <= n){
                bitree[id] += x;
                id += id & -id;
              }
              return;
            }
        	mint sum(ll id){
              mint temp = 0;
              while(id > 0){
                temp += bitree[id];
                id -= id & -id;
              }
              return temp;
            }
      };
    cin>>N>>K;
    vec l(K), r(K);
    rep(i, K) {
        cin>>l[i]>>r[i];
        ++r[i];
    }
    BIT bit(N + 10);
    bit.add(1, 1);
    bit.add(2, -1);
    reps(i, 1, N + 1){
        mint now = bit.sum(i);
        rep(j, K){
            if(i + l[j] <= N) bit.add(i + l[j], now);
            if(i + r[j] <= N) bit.add(i + r[j], -now);
        }
    }
    cout<<bit.sum(N)<<endl;
}


Measured memory_bytes: 4836
X, K, D = map(int, input().split())
X = abs(X)
if X == D:
    if K % 2 != 0:
        print('0')
    else:
        print(D)
else:
    span = X // D
    if span < K:
        if (K - span) % 2 == 0:
            print(X % D)
        else:
            print(abs(X % D - D))
    else:
        print(X - K * D)

Measured memory_bytes: 61836
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int r,g;
  cin >> r >> g;

  cout << 2*g - r << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
   int x;
   cin >>x;
   if(x==1)cout <<2;
   else{
   for(int i=x;i<x+1000;i++)
   {
       int c=0;
       for(int j=2;j<i;j++)
       {
           if(i%j==0)c++;
       }
       if(c==0){
        cout <<i<<endl;
        break;
       }
   }
   }
}


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

using namespace std;

#define For(i, a, b) for(int i = a; i <= b; ++ i)
const int N = 1e5 + 5;

int n, l, q;
int x[N], rmq[N][20];

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
	cin >> n;
	For(i, 1, n) cin >> x[i];
	cin >> l >> q;
	For(i, 1, n){
		int pos = upper_bound(x + 1, x + n + 1, x[i] + l) - x;
		rmq[i][0] = pos - 1;
	}	
	for(int j = 1; j <= 18; ++j)
		for(int i = 1; i <= n; ++ i)
			rmq[i][j] = rmq[ rmq[i][j - 1]][j - 1];

	while(q --){
		int a, b, ans = 0; cin >> a >> b;
		if(a > b) swap(a, b);
		for(int i = 18; i >= 0; -- i) if(rmq[a][i] < b) a = rmq[a][i], ans += 1 << i;
		cout << ans + 1 << "\n";
	}
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int o[n];
  for(int i =0; i < n; i++){
    o[a[i]-1] = i+1;
  }
  for(int i =0; i < n; i++){
    cout << o[i] << " ";
  }

  
  return 0;
}

Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<String> w = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            w.add(sc.next());
        }
        for (int i = 1; i < n; i++) {
            String word = w.get(i);
            String prev = w.get(i - 1);
            for (int j = 0; j < i; j++) {
                if (word.equals(w.get(j))) {
                    System.out.println("No");
                    return;
                }
            }
            if (!word.substring(0, 1).equals(prev.substring(prev.length() - 1))) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}


void solve_old(long long N, long long A, long long B){
    ll ret;
    ll dif = abs(A-B);
    if(dif%2){
        if(N-min(A,B)>max(A,B)-1){
            // ret = max(A,B)-1;
            ret = min(A,B)-1+1 + (max(A,B)-1 - min(A,B)-1+1)/2;
        }else{
            // ret = N-min(A,B);
            ret = N-max(A,B)+1 + (N-min(A,B) - N-max(A,B)+1)/2;
        }
    }else{
        ret = dif/2;
    }
    cout << ret << "\n";
}

void solve_old2(long long N, long long A, long long B){
    ll ret;
    ll dif = B-A;
    if(dif%2){
        // if(N-A>B-1){
        if(A-1<N-B){
            ret = A-1+1 + (B-1 - A-1+1)/2;
        }else{
            ret = N-B+1 + (N-A - N-B+1)/2;
        }
    }else{
        ret = dif/2;
    }
    cout << ret << "\n";
}

void solve(long long N, long long A, long long B){
    ll ret;
    ll dab = B-A, da1 = A-1, dbn = N-B;
    // debg(da1);
    // debg(dbn);
    if(dab%2){
        if(da1<dbn){
            ret = da1+1 + (B-1 - (da1+1))/2;
    // debg(da1+1);
    // debg(B-1);
    // debg(da1+1);
    // debg((B-1 - da1+1));
    // debg((B-1 - da1+1)/2);
        }else{
            ret = dbn+1 + (N-A - (dbn+1))/2;
        }
    }else{
        ret = dab/2;
    }
    cout << ret << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int a[200000];
int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;++i)
    cin >> a[i];
  if(n%2){
    for(int i=n-1;i>=0;i-=2)
      cout << a[i] << " ";
    for(int i=1;i<n;i+=2)
      cout << a[i] << " ";
  }
  else{
    for(int i=n-1;i>=0;i-=2)
      cout << a[i] << " ";
    for(int i=0;i<n;i+=2)
      cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2944
if __name__ == '__main__':
	l = input().split()

	for i in range(len(l)):
		l[i] = int(l[i])
	W, H, x, y, r = l[0], l[1], l[2], l[3], l[4]

	if x >= r and y >= r:
		if x <= W - r and y <= H - r:
			print("Yes")
		else:
			print("No")
	else:
		print("No")



Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n;
int l=1;

bool f(){
  int r=1;

  while(n>=r){
    if(r==n) return false;
    l++;
    r+=l;
  }
  return true;
}

int main(){
  cin>>n;

  if(f()){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;

  int k=l+1;
  int s[500][500]={};
  cout<<k<<endl;
  int t=1;
  rep(i,k){
    int j=0;
    while(j<i){
      s[i][j]=s[j][i-1];
      j++;
    }
    while(j<k){
      s[i][j]=t;
      t++;
      j++;
    }
    t--;
  }

  rep(i,k){
    cout<<k-1<<' ';
    rep(j,k-1){
      cout<<s[i][j]<<' ';
    }
    cout<<endl;
  }
}  


Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=100000;

int main(){
    
    ll ans=0;
    int streaka=0;
    string s;
    cin >> s;
    
    rep(i,s.size()){
        if(s[i]=='A'){
            streaka++;
        }else if(i+1<s.size()&&s[i]=='B'&&s[i+1]=='C'){
                i++;
                ans+=streaka;
        }else{
                streaka=0;
        }
    }
    
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

#include <math.h>

using namespace std;

int main(){

   int x, n;
   int ans = -1;
   int ans_diff;

   cin >> x >> n;

   ans_diff = x + 1;

   int p[103] = {0};

   for(int i = 0; i < n; i++){
      int num;
      cin >> num;
      p[num]++;
   }

   for(int i = 0; i < 102; i++){
      if(p[i]){
         continue;
      }
      int diff = abs(x - i);
      if(diff < ans_diff){
         ans_diff = diff;
         ans = i;
      }
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;


int main(){
    int N;
    cin >> N;
    vector<vector<int>> tree(N, vector<int>(0));

    int a,b;
    for(int i=0; i<N-1; i++) {
        cin >> a >> b;
        tree[a-1].push_back(b-1);
        tree[b-1].push_back(a-1);
    }

    vector<int> nodes(N, 0);
    nodes[0] = 1;
    nodes[N-1] = 2;

    queue<int> q;
    q.push(0);
    q.push(N-1);

    int now, tmp;
    while(!q.empty()){
        now = q.front(); q.pop();
        for(int i=0; i<tree[now].size(); i++){
            if(nodes[tree[now][i]] == 0 ){
                nodes[tree[now][i]] = nodes[now];
                q.push(tree[now][i]);
            }
        }
    }

    int fennec = 0, snuke = 0;
    for(int i=0; i<N; i++){
        if(nodes[i] == 1) fennec++;
        else snuke++;
    }

    if(fennec > snuke) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> k(m), p(m);
    vector<vector<int>> s(m, vector<int>(n));
    rep(i, m){
        cin >> k.at(i);
        s[i].resize(k.at(i));
        rep(j, k.at(i)){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    rep(i, m)cin >> p.at(i);
    int swi[(1<<n)][n], ans = 0;
    for(int bit = 0; bit < (1<<n); bit++){
        for(int i = 0; i < n; i++){
            if(bit & (1<<i)){
                swi[bit][i] = 1;
            }
            else swi[bit][i] = 0;
        }
    }
    rep(bit, (1<<n)){
        bool ok = true;
        int now = 0;
        rep(i, m){
            rep(j, k.at(i)){
                now += swi[bit][s[i][j]];
            }
            if(now % 2 != p.at(i))ok = false;
            now = 0;
        }
        if(ok)ans++;
    }
    cout << ans << endl;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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 main() {
  int n;
  cin >> n;
  int moji[26];
  for (char c = 'a'; c <= 'z'; c++) {
    moji[c - 'a'] = INF;
  }
  rep (i, n) {
    string tmp;
    cin >> tmp;

    int moji2[26];
    for (char c = 'a'; c <= 'z'; c++) {
      moji2[c - 'a'] = 0;
    }

    rep (j, tmp.size()) {
      moji2[tmp[j] - 'a']++;
    }

    for (char c = 'a'; c <= 'z'; c++) {
      moji[c - 'a'] = min(moji[c - 'a'], moji2[c - 'a']);
    }
  }

  // for (char c = 'a'; c <= 'z'; c++) {
  //   P(moji[c - 'a']);
  // }

  string ans = "";
  for (char c = 'a'; c <= 'z'; c++) {
    string tmp{c};
    rep (i, moji[c - 'a']) ans += tmp;
  }
  P(ans);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  typedef function<E(E,E)> H;
  typedef function<E(E,int)> P;
  int n;
  F f;
  G g;
  H h;
  P p;
  T d1;
  E d0;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T d1,E d0,
	      vector<T> v=vector<T>(),P p=[](E a,int b){return a;}):
    f(f),g(g),h(h),d1(d1),d0(d0),p(p){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
    laz.clear();
    laz.resize(2*n-1,d0);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(int len,int k){
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=d0;
  }
  T update(int a,int b,E x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return g(dat[k],p(laz[k],r-l));
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(int a,int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return d1;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
};
//END CUT HERE
signed main(){
  int n,q;
  cin>>n>>q;
  SegmentTree<Int,Int> ch(n,
			  [](Int a,Int b){return a+b;},
			  [](Int a,Int b){return a+b;},
			  [](Int a,Int b){return a+b;},
			  0,0,vector<Int>(n,0),
			  [](Int a,int b){return a*b;});
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>s>>t;
      cout<<ch.query(s-1,t)<<endl;
    }else{
      cin>>s>>t>>x;
      ch.update(s-1,t,x);
    }
  }
}

/*
verified on 2017/10/15
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G
*/

Measured memory_bytes: 8412
#include <cstdio>
#include <algorithm>
using namespace std;

int n;
int m;
int ans[1000];

int main() {
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    ans[i] = i;
  }

  scanf("%d", &m);
  for (int i=0; i<m; i++) {
    int a, b;
    scanf("%d,%d", &a, &b);
    swap(ans[a], ans[b]);
  }

  for (int i=1; i<=n; i++) {
    printf("%d\n", ans[i]);
  }
}

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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const int MAXN = 16;

void ri(int &n){
    scanf("%d",&n);
}
ll sumas[1<<MAXN];
ll dp[1<<MAXN];

ll go(int mask){
    ll &r = dp[mask];
    if(mask==0) return r=0;
    if(__builtin_popcount(mask)==1) return r=0;
    if(r!=-INF){
        return r;
    }
    r= sumas[mask];
    for(int subset= mask; subset; subset= (subset-1) & mask){
        r= max(r, sumas[subset]+ sumas[subset^mask]);
        if(subset != mask){
            r= max(r, go(subset)+ go(subset^mask));
        }
    }
    return r;
}

int main(){
    int n;
    ri(n);
    int matrix[n][n];
    forn(i,n){
        forn(j,n){
            ri(matrix[i][j]);
        }
    }
    for(int mask= 0; mask< (1<<n); ++mask){
        forn(i,n){
            if((1<<i)&mask){
                fore(j,i+1,n-1){
                    if((1<<j)&mask){
                        sumas[mask]+= matrix[i][j];
                    }
                }
            }
        }
    }
    forn(i,(1<<MAXN)){
        dp[i]=-INF;
    }
    ll r = sumas[(1<<n)-1];
    r= max(r, go((1<<n)-1));
    printf("%lld\n", r);
}



Measured memory_bytes: 1280
#include<stdio.h>
#define N 1000000
int par(int *,int ,int);
void swich(int, int);
int main()
{
  int A[N];
  int i,n,x;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }

  x = par(A,0,n-1);

  for(i=0; i<n; i++){
    if(i>0) printf(" ");
    if(x==i){
      printf("[%d]",A[i]);
      continue;
    }
    printf("%d",A[i]);
  }

  printf("\n");
  
  return 0;
}

int par(int *A,int p,int r){
  int x,i,j,tmp;

  x = A[r];
  i = p-1;

  for(j=p; j<r; j++){
    if(A[j] <= x){
      i = i+1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
      continue;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  return i+1;
}

  

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

int main(void){
	int a,b,c;
	
	while(cin>>a>>b>>c && (a||b||c)){
		int i,n;
		cin>>n;
		
		int res[a+b+c+1];
		int tmp[n][3];
		fill(res,res+a+b+c+1,2);
		
		for(i=0;i<n;i++){
			int I,J,K,R;
			cin>>I>>J>>K>>R;
			if(R == 1){
				res[I] = res[J] = res[K] = 1;
				i--;
				n--;
			}
			else{
				tmp[i][0] = I;
				tmp[i][1] = J;
				tmp[i][2] = K;
			}
		}
		int size = i;
		for(i=0;i<size;i++){
			if(res[tmp[i][0]] == 1 && res[tmp[i][1]] == 1) res[tmp[i][2]] = 0;
			else if(res[tmp[i][0]] == 1 && res[tmp[i][2]] == 1) res[tmp[i][1]] = 0;
			else if(res[tmp[i][1]] == 1 && res[tmp[i][2]] == 1) res[tmp[i][0]] = 0;
		}
		for(i=1;i<=a+b+c;i++){
			cout<<res[i]<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int w=sc.nextInt();
    int[] val=new int[n];
    int[] weights=new int[n];
    for(int i=0;i<n;i++)
    {
      weights[i]=sc.nextInt();
      val[i]=sc.nextInt();
      
    }
    long[] dp=new long[w+1];
    for(int i=1;i<=n;i++)
    {
      for(int j=w;j>=weights[i-1];j--)
      {
        dp[j]=Math.max(dp[j],dp[j-weights[i-1]]+val[i-1]);
      }
    }
    System.out.println(dp[w]);
  }
}
    

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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    int p = 0; int f = -1; int ans = 0;
    while(p < n){
        if(p == n-1){
            ans++; p++;
        } else if(a[p] == a[p+1])  {
            p++;
        } else if(a[p] < a[p+1]) {
            while(a[p] <= a[p+1]) {p++;}
            ans++; p++;
        } else {
            while(a[p] >= a[p+1]) {p++;}
            ans++; p++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
def divisor_all(n): # 約数全列挙
    l = [1,n]
    for i in range(2,int(pow(n,1/2))+1):
        if n % i == 0:
            if i == n//i:
                l.append(i)
            else:
                l.append(i)
                l.append(n//i)
    l.sort()
    return l # list
N = int(input())
ans = 0
for i in range(1,N+1,2):
    if len(divisor_all(i))==8:
        ans += 1
print(ans)

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

#ifdef LOCAL
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define dbgv(x) cerr << #x << " = " << x << endl
#define dbga(arr, len) {cerr << #arr << " = "; for (int _ = 0; _ < len; _++)\
cerr << arr[_] << " "; cerr << endl;}
#define dbgi(it) {cerr << #it << " = "; for (const auto& _ : it)\
cerr << _ << " "; cerr << endl;}
#else
#define dbg(...) (void)0
#define dbgv(x) (void)0
#define dbga(arr, len) (void)0
#define dbgi(it) (void)0
#endif

using ll = long long;
using dbl = long double;
using pii = pair<int, int>;

void solve() {
    int n;
    scanf("%d", &n);
    for (int a = 1; a <= 9; ++a) {
        for (int b = a; b <= 9; ++b) {
            if (a * b == n) {
                puts("Yes");
                return;
            }
        }
    }
    puts("No");
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    solve();

    dbg("\n\ntime = %.3lf\n", (double)clock() / CLOCKS_PER_SEC);
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, total = 0, over = 0, a, b;
    string s;
    cin >> n >> a >> b;
    cin >> s;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'a') {
            if(total < a+b) {
                cout << "Yes\n";
                total++;
            } else {
                cout << "No\n";
            }
        } else if(s[i] == 'b') {
            if(total < a+b && over < b) {
                cout << "Yes\n";
                over++;
                total++;
            } else {
                cout << "No\n";
            }
        } else {
            cout << "No\n";
        }
    }
    return 0;
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;


int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i,n) cin >> l[i];
  sort(rng(l));
  ll ans = 0;
  rep(i,n-2) {
    for(int j = i+1; j < n-1; j++) {
      for(int k = j+1; k < n; k++) {
        if(l[i]==l[j]||l[i]==l[k]||l[j]==l[k]) continue;
        if(l[i]+l[j]>l[k]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
//
//AtCoder Beginner Contest 162
//B - FizzBuzz Sum 
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define zero(a) memset(a, 0, sizeof(a))

using ll = long long;

int main()
{
    int n;

    cin >> n;

    ll ans = 0;

    rep(i, n){
        if (((i+1)%3 == 0) || ((i+1)%5 == 0)){

        }else{
            ans += (i+1);
        }

    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,m;
string s,t="keyence";
int main(void){
    cin>>s;
    n=s.size();
    if(n<7){
        cout<<"NO\n";
        return 0;
    }
    m=n-7;
    for(int i=0;i<n;i++){
        string x;
        x.clear();
        for(int j=0;j<=i;j++)x+=s[j];
        for(int j=i+m+1;j<n;j++)x+=s[j];
        if(x==t){
            cout<<"YES\n";
            return 0;
        }
    }
    cout<<"NO\n";
}


Measured memory_bytes: 256
inp = int(input())
sequ = []
se = 1

incp = inp
while incp:
    if incp > se:
        incp -= se
        sequ.append(se)
        se = se << 1
        # print(incp)
    else:
        break

res=[]
for i in range(len(sequ)):
    res.append([i+1, i+2, 0])
    res.append([i+1, i+2, sequ[i]])

sd = 2**len(sequ)
# print(sd)
for i, elem in reversed(list(enumerate(sequ))):
    if 2**(i+1) + sd <= inp:
        # print('add')
        res.append([i+2, len(sequ)+1, sd])
        sd += 2**(i+1)
        # print(sd)
if sd == inp - 1:
    res.append([1, len(sequ)+1, sd])

print(len(sequ)+1, len(res))
for r in res:
    print(*r)


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	//for(int i=0;i<N;i++) {}
	static int a[]=new int[51];
	static int b[]=new int[51];
	static int c[]=new int[51];
	static int d[]=new int[51];
	
	
	
	
	public static void main(String[] args) {
		//String S=sc.next();
		
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		int N=sc.nextInt();
		int M=sc.nextInt();
		
		int a=0,b=N+1;
	
		
		
		
		for(int i=M;i>0;i--) {
			if(i%2==0) {
				a++;
				p(a+" "+(a+i));
				
			}else {
				b--;
				p((b-i)+" "+b);	
			}
		}
		
		
		
	}
	
	
	/*int sum=0;
	 * for(int i=0;i<Q;i++) {
						if(t[b[i]-1]-t[a[i]-1]==c[i]) {
							sum+=d[i];
						}
					}
					ans=Math.max(ans, sum);
					*/
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

int recS(int x, int y){
    return x*y;
}

int main (){
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    if(recS(a, b)>=recS(c,d)){
        cout << recS(a, b) << endl;
    }else if(recS(c,d) > recS(a,b)){
        cout << recS(c,d) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int n, y;
    cin >> n >> y;
    int ans = 0;
    for(int i = 0; i < n + 1; i++){
        for(int j = 0; j < n + 1 - i; j++){
            //for(int k = 0; k < n + 1 - i - j; k++){
                int k = n - i -j;
                if(10000*i + 5000*j + 1000*k == y){
                    cout << i << " " << j << " " << k << endl;
                    ans = 1;
                    return 0;
                }
        }
    }

    if(ans == 0) cout << -1 << " " << -1 << " " << -1 << endl;
}

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

using namespace std;

int main()
{
    int n, s, ans=0;
    cin>>n;
    vector<int> v;
    for(int t=0;t<n;t++)
    {
        cin>>s;
        v.push_back(s);
    }
    sort(v.begin(),v.end(), greater<int>());
    for(int i=0;i<n;i++)
    {
        for(int j=n-1;j>i+1;j--)
        {
            for(int k=j-1;k>i;k--)
            {
                if(v[i]<v[j]+v[k])
                {
                    ans+=k-i;
                    break;
                }
            }
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		Reader.init(System.in);

		int n=Reader.nextInt();
		int[] h= new int[n+1];
		for(int i=1; i<=n; i++) {
			h[i]=Reader.nextInt();
		}
		
		int[] dp= new int[n+1];
		dp[1]=0;
		dp[2]= Math.abs(h[2]-h[1]);
		
		for(int i=3; i<=n; i++) {
			dp[i]= Math.min(dp[i-1]+ Math.abs(h[i]-h[i-1]),
					dp[i-2]+ Math.abs(h[i]-h[i-2]));
		}
		System.out.println(dp[n]);
}
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {

        	tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
	
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    

}

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

int toTime(int start, int& w){
    int m = start%100;
    int h = start/100;
    if( h >= 24 ){
        h -= 24;
        w++;
    }
    return ( m + h*60 + w*60*24 ) ;
}

int main(){
    int n,p,w,start;
    string name;
	
    while( cin >> n , n ){
        map<string,int> f;
        vector<int> favTime, Time;
        int ans = 0;
        bool flag = true;

        for(int i=0 ; i<n ; i++ ){
            cin >> name >> w >> start;
            int t = toTime( start , w ) + 30;
            f[name] = t;
            Time.push_back( t );
        }
		
        cin >> p;
        for(int i=0 ; i<p ; i++ ){
            cin >> name;
            favTime.push_back( f[name] );
        }

        sort( favTime.begin() , favTime.end() );
        for(int i=1 ; i < (int)favTime.size() ; i++ ){
            if( favTime[i] - favTime[i-1] < 30 ){
                flag = false;
            }
        }

        sort( Time.begin() , Time.end() );
        for(int i=0 ; i < (int)Time.size() ; i++ ){
            bool flag_ = true;
            for(int k=0 ; k < (int)favTime.size() ; k++ ){
                if( max(favTime[k],Time[i]) - min(favTime[k],Time[i]) < 30 ){
                     flag_ = false;
                }
            }
            if( flag_ ){
                ans++;
                favTime.push_back( Time[i] );
            }
        }
        cout << ((flag)? (ans+p) : -1 ) << endl;
    }
}

Measured memory_bytes: 1304
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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; }
void SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


class D {
	int h, w;
	static const int v{ 10 };
	int H, W, C[10][10];

public:
	D()
	{
		cin >> H >> W;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				cin >> C[i][j];
			}
		}
	}

	void init()
	{
		for (int k = 0; k < 10; k++) {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
				}
			}
		}
	}

	void solve()
	{
		init();

		long long ret = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				int x;
				cin >> x;
				if (~x) ret += C[x][1];
			}
		}

		cout << ret << endl;

	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256