akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

void trace(int*,int);
void insertionSort(int*,int);
int main()
{
  int hiroshi,mika,takuro,i,j,k;
  int takeshi[1000];

  scanf("%d",&k);
  for(i=0;i<k;i++)
    scanf("%d",&takeshi[i]);
    trace(takeshi,k);
    insertionSort(takeshi,k);
  
    return 0;
}

void trace(int takeshi[],int k){
  int i;
  for(i=0;i<k;i++){
    if(i>0)printf(" ");
    printf("%d",takeshi[i]);
  }
  printf("\n");
}

void insertionSort(int takeshi[],int k){
  int j,mika,takuro;
  for(j=1;j<k;j++){
    takuro=takeshi[j];
    mika=j-1;
    while(mika>=0 && takeshi[mika]>takuro){
      takeshi[mika+1]=takeshi[mika];
      mika--;
    }
    takeshi[mika+1]=takuro;
    trace(takeshi,k);
  }
}



Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        int total = 0;
        for(int i = 0; i < n; i++){
            ar[i] = sc.nextInt();
            total += ar[i];
        }
        int a = total / n;
        int b = a + 1;
        long costa = 0;
        long costb = 0;
        for(int i = 0; i < n; i++){
                costa += (ar[i] - a) * (ar[i] - a);
                costb += (ar[i] - b) * (ar[i] - b);
        }
        if(costa < costb)
                System.out.println(costa);
        else{
                System.out.println(costb);
        }

    }
}


Measured memory_bytes: 21972
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N,M,X;
    cin >> N >> M >> X;
    ll C[15];
    ll A[15][15];
    rep(i,0,N){
        cin >> C[i];
        rep(j,0,M){
            cin >> A[i][j];
        }
    }
    ll ans = INF;
    rep(bit,0,(1LL<<N)){
        ll cnt[15] = {};
        ll cost = 0; 
        rep(i,0,N){
            if((bit>>i)&1){
                cost += C[i];
                rep(j,0,M){
                    cnt[j] += A[i][j];
                }
            }
        }
        bool ok = true;
        rep(i,0,M){
            if(cnt[i] < X) ok = false;
        }
        if(ok){
            ans = min(ans, cost);
        }
    }
    if(ans == INF){
        print(-1);
    }else{
        print(ans);
    }


}

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

Measured memory_bytes: 3672
#include <vector>
#include <algorithm>
#include <iostream>
#include <iomanip>
using namespace std;
typedef vector<int> VI;
#define PB push_back
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0)return 0;
		VI v;
		int s=0;
		REP(i,n){
			int tmp;
			cin >> tmp;
			v.PB(tmp);
		}
		SORT(v);
		FOR(i, 1, n-1)s+=v[i];
		cout << s/(n-2) << endl;
	}
}

Measured memory_bytes: 1220
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(K):

    g = defaultdict(dict)
    for i in range(1, K+1):
        g[i % K][(i+1) % K] = 1
        g[i % K][(i*10) % K] = 0

    q = deque()
    q.append((1, 0))

    vis = {}
    while q:
        u, cc = q.popleft()
        if u == 0:
            return cc + 1
        vis[u] = True
        for v, c in g[u].items():
            if v in vis:
                continue
            if c == 0:
                q.appendleft((v, cc))
            else:
                q.append((v, cc+c))


def main():
    K = read_int()
    print(slv(K))


if __name__ == '__main__':
    main()


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

int main(){
	string str;
	
	while(cin >> str){
		if(str == "#") break;
		bool ret = false;
		bool sable = true;
		map<char,bool> m;
		for(int i=0;i<str.size();i++){
			if(str[i] == '(' || str[i] == '&' || str[i] == ')') continue;
			else if(str[i] == '|'){
				if(sable == true){
					ret = true;
					break;
				}
				sable = true;
				m.clear();
			}else{
				bool tmpb = true;
				char tmpc;
				if(str[i] == '~'){
					tmpb = false;
					i++;
				}
				tmpc = str[i];
				if(m.find(tmpc) != m.end() && m[tmpc] != tmpb){
					sable = false;
				}
				m[tmpc] = tmpb;
			}
		}
		sable?ret=true:ret=false;
		ret?cout<< "yes" << endl:cout << "no" << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

struct STX {
    int s, t, x;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n, q;
    cin >> n >> q;
    vector<STX> stx(n);
    rep(i, n) cin >> stx[i].s >> stx[i].t >> stx[i].x;
    set<pair<int, int>> d;
    vector<int> ans(q, -1);
    rep(i, q) {
        int tmp;
        cin >> tmp;
        d.insert(make_pair(tmp, i));
    }
    sort(all(stx), [](const STX &a, const STX &b) { return a.x < b.x; });
    rep(i, n) {
        int l = stx[i].s - stx[i].x;
        int r = stx[i].t - stx[i].x;
        for (auto it = d.lower_bound(make_pair(l, -1)); it != d.end(); ) {
            if (it->first >= r) break;
            ans[it->second] = stx[i].x;
            d.erase(it++);
        }
    }
    rep(i, q) printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 14464
#include <iostream>
using namespace std;
 
int main() {
	long long n,m;
	cin >> n >> m;
	long long ans=0;
	if (2*n>m){
		ans = m/2;
	}
	else{
		m = m - 2*n;
		ans = n + m/4;
	}
	cout << ans;
	return 0;
}

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

using namespace std;

int main()
{
    int n,ac=0,wa=0,tle=0,re=0;
    cin>>n;
    string s;
 int a[n];
 for(int i=0;i<n;i++)
 {
     cin>>s;
     if(s[0]=='A')
     {
         ac++;

     }
     else if(s[0]=='T')
     {
         tle++;

     }

     else if(s[0]=='W')
     {
         wa++;
     }
       else if(s[0]=='R')
     {
         re++;
     }
 }
  cout<<"AC x "<<ac<<"\n"<<"WA x "<<wa<<"\n"<<"TLE x "<<tle<<"\n"<<"RE x "<<re<<"\n";


    return 0;
}


Measured memory_bytes: 3620
S = input()
Q = int(input())

rev = 0
head = ""
foot = ""
for i in range(Q) :
    query = input()
    if query == "1" :
        rev += 1
    else :
        a, F, C = query.split()
        if F == "1" and rev%2 == 0:
            head = C + head
        elif F == "1" and rev%2 == 1:
            foot = foot + C
        elif F == "2" and rev%2 == 0:
            foot = foot + C
        else :
            head = C + head

if rev%2 == 0 :
    print("".join(list(head + S + foot)))
else :
    print("".join(list(reversed(head + S + foot))))


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

int main() {
	string S;
	cin >> S;
	long long n = 0, m = 0, ans = 0;
	for (int i = 0; i < S.size(); i++) {
		n++;
		if (i == S.size() - 1 && S[i] == '>') {
			ans += n * (n - 1) / 2;
			ans += max(m, n);
		} else if (i == S.size() - 1 && S[i] == '<') {
			ans += n * (n + 1) / 2;
		} else if (S[i] == S[i + 1]) {
			continue;
		} else if (S[i + 1] == '>') {
			ans += n * (n - 1) / 2;
			m = n;
			n = 0;
		} else if (S[i + 1] == '<') {
			ans += n * (n - 1) / 2;
			ans += max(n, m);
			m = n;
			n = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 900
/*************************************************************************
  >         File: E.cc
  >       Author: lyyllyyl
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Fri 02 Sep 2016 07:59:53 PM CST
*************************************************************************/
#include <bits/stdc++.h>
using LL = long long;
 
int main() {
  std::vector<LL> stack;
  int n, m;
  scanf("%d%d", &n, &m);
  stack.emplace_back(n);
  for (int i = 0; i < m; i++) {
    LL x;
    scanf("%lld", &x);
    while (stack.size() && stack.back() >= x) stack.pop_back();
    stack.emplace_back(x);
  }
  std::map<LL, LL> positions;
  positions.insert({stack.back(), 1});
  while (stack.size()) {
    LL position = stack.back(); stack.pop_back();
    auto pos = positions.upper_bound(position);
    for(auto itr = pos; itr != positions.end(); itr = positions.erase(itr)) {
      LL x, y;
      std::tie(x, y) = *itr;
      LL k = x / position, b = x % position;
      positions[position] += y * k;
      positions[b] += y;
    }
  }
  LL now = 0;
  std::vector<LL> answer(n, 0);
  for (int i = n; i >= 1; i--) {
    now += positions[i];
    answer[i - 1] = now;
  }
  for (auto x: answer) {
    printf("%lld\n", x);
  }
  return 0;
}


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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

long d[kMax5][13];

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

  string s;
  cin >> s;
  int idx = 0;
  while (1) {
    int countr = 0, countl = 0;
    while (idx < s.size() && s[idx] == 'R') {
      ++countr;
      ++idx;
      continue;
    }
    while (idx < s.size() && s[idx] == 'L') {
      ++countl;
      ++idx;
      continue;
    }
    rep(i, 1, countr - 1) cout << "0 ";
    cout << (countr + 1) / 2 + countl / 2;
    if (countl) cout << " " << (countl + 1) / 2 + countr / 2;
    rep(i, 1, countl - 1) cout << " 0";
    if (idx == s.size()) { break; }
    else { cout << " "; }
  }
  cout << "\n";

  return 0;
}


Measured memory_bytes: 720
cd=[]
suits=['S','H','C','D']
for i in range(int(input())):
    s,n=map(str,input().split())
    cd.append(suits.index(s)*13+int(n)-1)
for i in range(52):
    if not(i in cd):
        print(suits[i//13],i%13+1)


Measured memory_bytes: 5600
def resolve():
    '''
    code here
    '''

    N = int(input())
    S_list = [int(input()) for _ in range(N)]
    all_sum = sum(S_list)

    if all_sum % 10 == 0:
        no_10_nums = [item for item in S_list if item % 10 != 0]
        if no_10_nums:
            res =  all_sum - min(no_10_nums)
        else:
            res = 0
        
    else:
        res = all_sum

    
    print(res)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
import numpy as np
from collections import defaultdict
from functools import reduce
from itertools import permutations

# s = input()
n = int(input())
# A = list(map(int, input().split()))
# a, b = map(int, input().split())

lis = []
dic = {}
for i in range(n):
    x, y = map(int, input().split())
    lis.append((x,y,i))
    dic[(x,y)] = i

res = n

for n1, n2 in permutations(range(n) ,2):
    p = lis[n1][0] - lis[n2][0]
    q = lis[n1][1] - lis[n2][1]
    s = set(range(n))
    s.remove(n1)
    s.remove(n2)

    score = 1
    x = lis[n1][0]
    y = lis[n1][1]

    while True:
        x2 = x
        y2 = y
        while True:
            if ((x2+p), (y2+q)) in dic:
                i = dic[((x2+p), (y2+q))]
                if i in s:
                    s.remove(i)
                x2 = lis[i][0]
                y2 = lis[i][1]
            else:
                break
        x2 = x
        y2 = y
        while True:
            if ((x2-p), (y2-q)) in dic:
                i = dic[((x2-p), (y2-q))]
                if i in s:
                    s.remove(i)
                x2 = lis[i][0]
                y2 = lis[i][1]
            else:
                break

        if len(s) == 0:
            break
        i = s.pop()
        x = lis[i][0]
        y = lis[i][1]
        score += 1
    res = min(res, score)
print(res)



Measured memory_bytes: 21520
#include <stdio.h>
int main(void)
{
	int a,b,w,h;
	while(1){scanf("%d %d",&w ,&h);

	if (w==0 && h==0){break;
	   }
	for(b=1; b<=w; b++){
	   for(a=1; a<=h; a++){
	   putchar('#');
	   }
	   putchar('\n');
	   }
	   putchar('\n');
	}
	return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String ans = "No";

        for (int i = 0; i<n; i++){
            for (int j = 0; j<n; j++){
                if ((i*4)+(j*7) == n){
                    ans = "Yes";
                    break;
                }
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 35628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	long long A, B;
	cin >> A >> B;
	if (A > B) swap(A, B);
	long long C = B - A;
	if (C % 2 == 0) cout << C / 2 + A << endl;
	else cout << "IMPOSSIBLE" << endl;
	
	return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N);
  int ans = INF;
  REP(i, N) {
    CIN(a);
    int cnt = 0;
    while (a % 2 == 0) {
      a >>= 1;
      cnt++;
    }
    ans = min(cnt, ans);
  }

  cout << ans << endl;

  return 0;
}



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

static const int INFTY = 2000000000;
static const int MAX_N = 200001;
static int L[MAX_N / 2 + 2], R[MAX_N / 2 + 2];

int64_t merge(int A[], int left, int mid, int right) {
    auto n1 = mid - left;
    auto n2 = right - mid;
    auto i = 0;

    for (i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for (i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }

    L[n1] = INFTY;
    R[n2] = INFTY;

    i = 0;
    int j = 0;
    int64_t cnt = 0;

    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i += 1;
        } else {
            A[k] = R[j];
            j += 1;
            cnt += n1 - i;
        }
    }
    return cnt;
}

int64_t mergeSort(int A[], int left, int right) {
    int64_t inv = 0;
    if (left + 1 < right)
    {
        auto mid = (left + right) / 2;
        inv += mergeSort(A, left, mid);
        inv += mergeSort(A, mid, right);
        inv += merge(A, left, mid, right);
    }
    return inv;
}

int main() {

    int A[MAX_N], N, i = 0;
    cin >> N;
    for(i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    int64_t inv = mergeSort(A, 0, N);

    cout << inv << endl;

    return 0;
}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n, m; cin >> n >> m;
	vector<int>coin; coin.push_back(0);
	rep(i, 0, m) {
		int d; cin >> d; coin.push_back(d);
	}
	vector<int>dp(n + 1, INF);
	dp[0] = 0;
	rep(i, 1, m + 1) {
		rep(j, coin[i], n + 1) {
			dp[j] = min(dp[j], dp[j - coin[i]] + 1);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 3204
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;




int main(){
    map<string,int> data;
    data.clear();
    
    int n,m;
    cin>>n;
    rep(i,n){
        string a;
        cin>>a;
        data[a]=1;
    }
    
    cin>>m;
    bool now=true;

    rep(i,m){
        string a;
        cin>>a;
        if(data[a]==1){
            if(now){
                cout<<"Opened by ";
            }
            else{
                cout<<"Closed by ";
            }
            now=!now;
            cout<<a<<endl;
            
        }
        else{
            cout<<"Unknown "<<a<<endl;
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 1240
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000009;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int R[410000];
char in[210000];
char tmp[410000];
int cnt[26];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	long long ret=(long long)n*(n+1)/2+1;
	for(int i=0;i<n;i++)cnt[in[i]-'a']++;
	for(int i=0;i<26;i++)ret-=(long long)cnt[i]*(cnt[i]+1)/2;
/*	int i = 0, j = 0;
	int sz=0;
	for(i=0;i<n;i++){
		tmp[sz++]=in[i];
		if(i<n-1)tmp[sz++]='*';
	}
	i=0;
	string S=tmp;

while (i < S.size()) {
  while (i-j >= 0 && i+j < S.size() && S[i-j] == S[i+j]) ++j;
  R[i] = j;
  int k = 1;
  while (i-k >= 0 && i+k < S.size() && k+R[i-k] < j) R[i+k] = R[i-k], ++k;
  i += k; j -= k;
}
	printf("%lld\n",ret);
	for(int i=0;i<2*n-1;i++){
		if(i%2==0)ret-=(R[i]+1)/2;
		else ret-=R[i]/2;
	}*/
	printf("%lld\n",ret);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = (1 << 29);
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  sort(ALL(a), greater<ll>());

  ll prev = 0;
  ll x = 0;
  ll y = 0;
  rep(i, n) {
    if (prev == a[i]) {
      if (x == 0) {
        x = a[i];
      } else {
        y = a[i];
        break;
      }
      prev = 0;
    } else {
      prev = a[i];
    }
  }

  cout << x * y << endl;

  return 0;
}


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

int main(){
	int n;
	vector<int> a;
	
	cin >> n;
	
	int mostLargestNum = 0;
	int secondLargestNum = 0;
	bool largestJuhuku = false;
	for(int i = 0; i < n; i++){
		int input;
		cin >> input;
		a.push_back(input);
		if(input == mostLargestNum){
			largestJuhuku = true;
		}
		if(input > mostLargestNum){
			secondLargestNum = mostLargestNum;
			mostLargestNum = input;
			largestJuhuku = false;
		}
		if(input > secondLargestNum && input < mostLargestNum){
			secondLargestNum = input;
		}
	}
	
	for(int i = 0; i < n; i++){
		if(a[i] == mostLargestNum){
			if(largestJuhuku){
				cout << mostLargestNum << endl;
			}else{
				cout << secondLargestNum << endl;
			}
		}else{
			cout << mostLargestNum << endl;
		}
	}
	
	return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 100010;

ll l[maxn], len[maxn];

ll ladd, radd, mini;

multiset<ll> lt, rt;

void add(int p) {
	ladd -= len[p];
	radd += len[p-1];

	if (*lt.rbegin() + ladd > l[p]) {
		lt.insert(l[p] - ladd); lt.insert(l[p] - ladd);
		mini += abs(l[p] - (*lt.rbegin() + ladd));
		auto it = --lt.end();
		rt.insert(*it + ladd - radd);
		lt.erase(it);
	} else if (*rt.begin() + radd < l[p]) {
		rt.insert(l[p] - radd); rt.insert(l[p] - radd);
		mini += abs(l[p] - (*rt.begin() + radd));
		auto it = rt.begin();
		lt.insert(*it + radd - ladd);
		rt.erase(it);
	} else { //between
		lt.insert(l[p] - ladd); rt.insert(l[p] - radd);
	}
}

int main() {
	int N; cin >> N;
	rep(i, N) {
		int p, q;
		cin >> p >> q;
		l[i] = p;
		len[i] = q - p;
	}

	lt.insert(l[0]); rt.insert(l[0]);

	for (int i = 1; i < N; ++i) {
		add(i);
	}

	cout << mini << endl;

	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;


int main ()
{
    int x,y;
    char op;
    cin>>x;
    cin>>op;
    cin>>y;
    if (op=='+')
        cout<<x+y;
    else cout<<x-y;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int K = Integer.parseInt(sc.nextLine());
    int X = Integer.parseInt(sc.nextLine());
    int Y = Integer.parseInt(sc.nextLine());
    
    int ans = 0;
    for(int i = 0; i < N; i++){
      if(i < K){
        ans += X;
      }else{
        ans += Y;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#define print(n) std::cout << n << std::endl
#define print_no_indention(n) std::cout << n
using namespace std;


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

   int count = n / 15;
   
   int sum = n * 800 - count * 200;
   print(sum);
}

Measured memory_bytes: 256
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
  
    ll n,x,i,j,ans=LLONG_MAX,ind=-1;
    cin>>x>>n;
    ll ma[200] = {0};
    for(i=0;i<n;i++)
    {
    	ll xi;
    	cin>>xi;
    	ma[xi]++;
    }
    for(i=0;i<=200;i++)
    {
    	if(!ma[i] )
    	{
    		ll ha = abs(i-x);
    		if(ha<ans)
    		{
    			ans = ha;
    			ind = i;
    		}
    	}
    }

    cout<<ind;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int A, L, d[6];

void toarray(int a) {
  REP(i, 0, L) {
    d[i] = a % 10;
    a /= 10;
  }
}

int number() {
  int n = 0;
  REP(i, 0, L) n = n * 10 + d[i];
  return n;
}

int find(int n, vector<int> &v) {
  REP(i, 0, v.size()) if(v[i] == n) return i;
  return -1;
}

int main(void) {
  while(cin >> A >> L, A || L) {
    vector<int> v;
    for(int i = 0; true; i++) {
      int idx;
      if((idx = find(A, v)) >= 0) {
        cout << idx << " " << A << " " << (i - idx) << endl;
        break;
      }
      v.push_back(A);
      toarray(A);
      sort(d, d + L);
      int nmin = number();
      reverse(d, d + L);
      int nmax = number();
      A = nmax - nmin;
    }
  }

  return 0;
}

Measured memory_bytes: 3132
#include <iostream>
using namespace std;
int main(void){
 int N;
 int K;
 cin>>N;
 cin>>K;
 int P[100]={};
 for (int i=0;i<N;i++)
     cin>>P[i];
 int answer=0;
 for (int i=0;i<N;i++){
     if(K/2>=P[i]){
         answer+=2*P[i];
    }
    else {
        answer+=2*(K-P[i]);
    }
 }
 cout<<answer<<endl;
}


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

using namespace std;

int main(){
 ios::sync_with_stdio(0);
 cin.tie(0);
 int n,K;
 cin >> n >> K;
 vector<int> v(n+3),ret(n+3,INT_MAX);
 for (int i=0; i<n; ++i) cin >> v[i];
 ret[0]=0;
 for (int i=0; i<n; ++i){
  for (int k=1; k<=K; ++k) ret[i+k] = min(ret[i+k],abs(v[i]-v[i+k])+ret[i]);
 }
 cout << ret[n-1];
 return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
    int i, d = 0, day = 0;
    char s[3];
    scanf("%s",&s);
    for(i=0;i<3;i++){
        if(s[i] == 'S'){
            d += 1;
            continue;
        }else{
            day += 1;
        }
        if(s[1] == 'S' && day == 2){
            day = 1;
        }
    }
    printf("%d\n", day);
    return 0;
}

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

int year(int y){
    if( y%400 == 0 ) return 366;
    if( y%100 == 0 ) return 365;
    if( y%4 == 0 ) return 366;
    return 365;
}

int daysOfMonth(int y, int m){
    static int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    if( m != 2 ) return days[m];
    if( year(y) == 366 ) return 29;
    return 28;
}

int daysFromBegin(int y, int m, int d){
    int ans = 0;
    for(int i = 1; i < m; i++){
        ans += daysOfMonth(y, i);
    }
    ans += d - 1;
    return ans;
}

int main(){
    int y1, m1, d1, y2, m2, d2;
    while( cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2 ){
        if( y1 < 0 || y1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0 ){
            break;
        }
        int ans = 0;
        ans += -daysFromBegin(y1, m1, d1) + daysFromBegin(y2, m2, d2);
        for(int yy = y1; yy < y2; yy++){
            ans += year(yy);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#  変数宣言
start_index=0
gorl_index=3
ite=0
num=[]
ans=[]

# 入力をリストとして取得
N = list(input())

# リストとして三つづつ取り出し
while ite != len(N)-2: 
    tmp=''.join(N[start_index:gorl_index])
    num.append(tmp)
    start_index+=1
    gorl_index+=1
    ite+=1

# 753との差分を出しソート
for numcmp in num:
    diff_ans = 753 - int(numcmp)
    ans.append(abs(diff_ans))
    ans.sort()

print(ans[0])

Measured memory_bytes: 3064
K = int(input())

array = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(array[K-1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" "<<x<<endl;
#define f(i,n) for(ll i=0; i<n; i++)
#define f1(i,n) for(ll i=1; i<=n; i++)
#define fr(i,n) for(ll i=n-1; i>=0; i--)
#define f1r(i,n) for(ll i=n; i>0; i--)
#define mst(arr,val) memset(arr,val,sizeof(arr))
#define all(x) x.begin(),x.end()

typedef long long int ll;
typedef pair<ll,ll> pii;
ll M=1e9+7;
ll M2=998244353;
void show(vector<ll> v)
{
    for(ll i=0; i<v.size(); i++)
        cout<<v[i]<<" ";
    cout<<"\n";
}
void showrev(vector<ll> v)
{
    for(ll i=0; i<v.size(); i++)
        cout<<v[v.size()-i-1]<<" ";
    cout<<"\n";
}
void showarr(ll arr[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<arr[i]<<" ";
    cout<<"\n";
}
void showpv(vector<pair<ll,ll> > v)
{
    f(i,v.size())
        cout<<"("<<v[i].ff<<","<<v[i].ss<<")"<<" ";
    cout<<"\n";
}
int main()
{
    IOS
    ll T = 1,Q=1;
    //cin>>T;
    while(T--)
    {
        ll n,x,y; cin>>n>>x>>y;
        ll dis[n+1][n+1]; mst(dis,0);
        f1(i,n-1) dis[i][i+1] = 1;
        dis[x][y] = 1;
        f1(i,n)
        {
            for(ll j=i+1; j<=n; j++)
            {
                if(i == j) continue;

                dis[i][j] = min(min(abs(i-j),abs(y-i)+abs(x-j)+1),abs(x-i)+abs(y-j)+1);
            }
        }
        ll ans[n+1]; mst(ans,0);
        f1(i,n)
        {
            for(ll j=i+1; j<=n; j++)
                ans[dis[i][j]]++;
        }
        f1(i,n-1)
        {
            cout<<ans[i]<<"\n";
        }
    }
    return 0;
}


Measured memory_bytes: 31616
main=do
 n<-readLn
 let x=f n 0
 let m=x*(x+1)`div`2-n
 putStr$unlines$map show[i|i<-[1..x],i/=m]
f n i
 |2*n<=i*(i+1)=i
 |otherwise=f n$i+1

Measured memory_bytes: 1020
#include<iostream>


using namespace std;

int main(){
	const int maxsize=20;
	int size;
	int E[maxsize][maxsize];
	int qqq = 999999999;
	int cost[maxsize];
	bool used[maxsize];

	int m;

	cin >> size;
	cin >> m;

	for(int i=0;i<size;i++){
		used[i] = false;
		cost[i] = qqq;
		for(int j=0;j<size;j++){
			E[i][j] = qqq;
		}
	}

	for(int i=0;i<m;i++){
		int a,b,c,d;
		char cnm;
		cin >> a >> cnm >> b >> cnm >> c >> cnm >> d;
		E[a-1][b-1] = c;
		E[b-1][a-1] = d;
	}
	int x,y,xx,yy;
	char cnm;
	cin >> x >> cnm >> y >> cnm >> xx >> cnm >> yy;
	cost[x-1] = 0;
	xx -= yy;
	while(true){
		int v=-1;
		for(int i=0;i<size;i++){
			if(!used[i] && (v==-1 || cost[v] > cost[i])){
				v = i;
			}
		}		
		if(v==-1 || v == y-1){
			break;
		}
		used[v] = true;
		for(int i=0;i<size;i++){
			cost[i] = min(cost[i],cost[v]+E[v][i]);
		}
	}
	xx -= cost[y-1];
	for(int i=0;i<size;i++){
		used[i] = false;
		cost[i] = qqq;
	}
	cost[y-1] = 0;
	while(true){
		int v=-1;
		for(int i=0;i<size;i++){
			if(!used[i] && (v==-1 || cost[v] > cost[i])){
				v = i;
			}
		}		
		if(v==-1 || v == x-1){
			break;
		}
		used[v] = true;
		for(int i=0;i<size;i++){
			cost[i] = min(cost[i],cost[v]+E[v][i]);
		}
	}
	xx -= cost[x-1];
	cout << xx << endl;
}

Measured memory_bytes: 1160
n = int(input())

count = 0
b = 0
a = 0
ba = 0

for _ in range(n):
  s = input()
  count += s.count("AB")
  if s[0] is "B":
    if s[-1] is "A":
      ba += 1
    else:
      b += 1
  elif s[-1] is "A":
      a += 1

if ba > 0:
  count+= ba-1
  if a>0 or b>0:
    count+=1
count += min(a,b) 
    
print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
#define endl '\n'

void solve() {
    ll a, b, n;
    cin >> a >> b >> n;

    ll x = min(b - 1, n);

    ll res = floor((1.0*a*x)/b) - a*floor((1.0 * x)/b);
    cout << res << endl;
}

int main() {
    FAST_IO;

    int t;
    // cin >> t;
    t = 1;

    while (t--) {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <stack>
using namespace std;


#define REP(i,x)for(int i=0;i<(int)x;i++)

// 逆ポーランド記法
// op!=0なら演算子
struct Parsed{
	char op;
	int value;
	int priority;
};
vector<Parsed> parse(const string &s){
	int op[256] = {}; // 演算子の情報
	// 演算子の情報を入れる
	op['+']=op['-']=2;
	op['*']=op['/']=3;
	op['(']=100;
	op[')']=1;
	stack<Parsed> stack;
	vector<Parsed> res;
	int it=0;
	while(it<(int)s.size()){
		int pri=0,value=0,opd=0;
		if(op[(int)s[it]]){
			pri=op[(int)s[it]];
			value=0;
			opd=s[it];
		}else{
			value=0;
			while(it<(int)s.size()&&isdigit(s[it])){
				value=value*10+s[it]-'0';
				it++;
			}
			it--;
			pri=99;
		}
		while(!stack.empty()&&pri<=stack.top().priority&&stack.top().op != '('){
			res.push_back(stack.top());
			stack.pop();
		}
		if(opd!=')'){
			stack.push((Parsed){opd,value,pri});
		}else{
			stack.pop();
		}
		it++;
	}
	while(!stack.empty()){
		res.push_back(stack.top());
		stack.pop();
	}
	return res;
}
int main() {
	string in;
	for(cin>>in;cin>>in;){
		in=in.substr(0,in.size()-1);
		vector<Parsed> parsed = parse(in);
		stack<int> stack;
		for(int i=0;i<(int)parsed.size();i++){
			if(parsed[i].op=='+'){
				int a=stack.top();stack.pop();
				int b=stack.top();stack.pop();
				stack.push(a+b);
			}else if(parsed[i].op=='-'){
				int a=stack.top();stack.pop();
				int b=stack.top();stack.pop();
				stack.push(b-a);
			}else if(parsed[i].op=='*'){
				int a=stack.top();stack.pop();
				int b=stack.top();stack.pop();
				stack.push(a*b);
			}else if(parsed[i].op=='/'){
				int a=stack.top();stack.pop();
				int b=stack.top();stack.pop();
				stack.push(b/a);
			}else{
				stack.push(parsed[i].value);
			}
		}
		cout<<stack.top()<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import itertools
n = int(input())
#li = list(itertools.product([0,1], repeat=n))
alp = list('abcdefghijklmnopqrstuvwxyz')

ans_li = ['0']
for _ in range(n-1):
    tmp = []
    for a in ans_li:
        last = 0
        for an in a:
            if int(an)>last:
                last = int(an)
        for i in range(last+2):
            tmp.append(a+str(i))
    ans_li = tmp
for bb in ans_li:
    ans = ''
    for b in bb:
        ans += alp[int(b)]
    print(ans)

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

int main() {
  ll X;
  cin >> X;

  ll x = 100;
  ll ans = 0;
  while (x < X) {
    x += x / 100;
    ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3644
import java.util.Scanner;
import java.lang.String;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while(true){
      String str = sc.next();
      if(str.equals("-")){
        break;
      }
      
      int n = sc.nextInt();
      for(int i = 0; i < n; i++){
        int h = sc.nextInt();
        str = str.substring(h) + str.substring(0,h);
      }
      
      System.out.println(str);
    }
    
  }
}



Measured memory_bytes: 26256
#include <cstdio>

typedef long long ll;

const ll mod = 1000000007;

ll pow(ll n, ll r){// n^r % mod
    if(r == 0){
        return 1;
    }
    if(r == 1){
        return n;
    }
    if((r%2) == 0){
        ll a = pow(n, r/2);
        return (a*a)%mod;
    } else{
        ll a = pow(n, r/2);
        return (((a*a)%mod)*n)%mod;
    }
}


int main(void){

    /*
        all - no 0 - no 9 + no0 ans no9;
        = 10^n - 2*9^n + 8^n
    */
   int n;
   scanf("%d",&n);

   printf("%lld\n",(pow(10,n)- 2 * pow(9,n) + pow(8,n) + 3*mod)%mod);



    return 0;
}

Measured memory_bytes: 1736
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
int main(){
  ll n,m;cin>>n>>m;
  ll count=0;
  if(n%2==1){
    while(true){
      cout<<count+1<<" "<<n-1-count<<endl;
      count++;
      if(count==m)break;
    }
    return 0;
  }
  /*while(true){
    cout<<count+1<<" "<<n-1-count<<endl;
    count++;
    if(count==m)break;
  }*/
  ll k=n/2;
  ll i=0,j=0;
  while(true){
    cout<<i+1<<" "<<k-i<<endl;
    i++;
    if(i+j==m)break;
    cout<<k+1+j<<" "<<n-j-1<<endl;
    j++;
    if(i+j==m)break;
  }
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
string S[2000];
int A[2000][2000];
int B[2000][2000];
int C[2000][2000];
int main() {
	int N, M, Q;
	cin >> N >> M >> Q;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		for (int j = 0; j < M; j++) {
			A[i][j] = S[i][j] - '0';
			if (i > 0 && S[i][j] == '1' && S[i][j] == S[i - 1][j]) B[i][j] = 1;
			if (j > 0 && S[i][j] == '1' && S[i][j] == S[i][j - 1]) C[i][j] = 1;
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 1; j < M; j++) {
			A[i][j] += A[i][j - 1];
			B[i][j] += B[i][j - 1];
			C[i][j] += C[i][j - 1];
		}
	}
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < M; j++) {
			A[i][j] += A[i - 1][j];
			B[i][j] += B[i - 1][j];
			C[i][j] += C[i - 1][j];
		}
	}
	for (int i = 0; i < Q; i++) {
		int y1, x1, y2, x2;
		cin >> y1 >> x1 >> y2 >> x2;
		y1--; x1--; y2--; x2--;
		int a = A[y2][x2];
		if (x1 > 0) a -= A[y2][x1 - 1];
		if (y1 > 0) a -= A[y1 - 1][x2];
		if (x1 > 0 && y1 > 0) a += A[y1 - 1][x1 - 1];
		int b = B[y2][x2];
		if (x1 > 0) b -= B[y2][x1 - 1];
		b -= B[y1][x2];
		if (x1 > 0) b += B[y1][x1 - 1];
		int c = C[y2][x2];
		c -= C[y2][x1];
		if (y1 > 0) c -= C[y1 - 1][x2];
		if (y1 > 0) c += C[y1 - 1][x1];
		cout << a - b - c << endl;
	}
}


Measured memory_bytes: 52736
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {s:String}
    let mut s = s.chars().collect::<Vec<char>>();
    for i in 0..s.len() {
        for j in i + 1..s.len() {
            if s[i] == s[j] {
                println!("no");
                return;
            }
        }
    }
    println!("yes");
}


Measured memory_bytes: 4352
//_nebula_
#include<bits/stdc++.h>
using namespace std;
#define int long  long
#define double long double
int t;
const int M=1e9+7;
const int inf=INT64_MAX;
int factt(int n){
    int ans=1;
    for(int i=1;i<=n;i++){
        ans*=i;
        ans=ans%M;
    }
    return ans;
}
int max(int a,int b,int c){
    return max(a,max(b,c));
}
int min(int a,int b,int c){
    return min(a,min(b,c));
}
int fspow(int x,int y){
    int ans;
    if(y==0) return 1;
    ans=fspow(x, y/2);
    if(y%2==0) return ((ans*ans)%M);
    return (x*((ans*ans)%M))%M;
}
int gcd(int x,int y){
    if(x<y) swap(x,y);
    if(y==0) return x;
    return gcd(x%y,y);
}
int p2(int x){
    int ans=0;
    while(x>=1){
        ans++;
        x/=2;
    }
    return ans;
}
int prod(int a,int b) {
    return ((a % M) * (b % M)) % M;
}
int fact[2005];
int nCr(int n,int r){
    if(r>n||r<0) return 0;
    int z=fact[n];
    z=prod(z,fspow(fact[n-r],M-2));
    z=prod(z,fspow(fact[r],M-2));
    return z;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    t=1;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
   //  cin>>t;
    //int tmp=t;
    while(t--){
        fact[0]=1;
        for(int i=1;i<=2001;i++){
         fact[i]=prod(i,fact[i-1]);
        }
        int ans=0;
        int s;
        cin>>s;
        int n=s/3;
        for(int i=n;i>0;i--){
            int nn=s-i*3;
            int r=i-1;
            ans=ans+(nCr(nn+r,r)%M);
            ans%=M;
        }
        cout<<ans<<"\n";
    }
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
char arr[21][21];
int vis[21][21];
int path[21][21];
int best = 0;
int main(){
	int n,m;
	cin>>n>>m;
	int dp[n][m];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin>>arr[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			for(int k = 0; k < n; k++){
				for(int f = 0; f < m; f++){
					vis[k][f] = 0;
					path[k][f] = 0;
				}
			}
			queue<pair<int,int>> q;
			if(arr[i][j] == '.') { q.push({i,j}); vis[i][j] = 1;}
			while(!q.empty()){
				pair<int,int> p = q.front();
				q.pop();
				if(p.first+1 < n){
					if(arr[p.first+1][p.second] == '.' && !vis[p.first+1][p.second]){
						vis[p.first+1][p.second] = 1;
						path[p.first+1][p.second] = path[p.first][p.second] + 1;
						q.push({p.first+1,p.second});
					}
				}
				if(p.first-1 >= 0){
					if(arr[p.first-1][p.second] == '.' && !vis[p.first-1][p.second]){
						vis[p.first-1][p.second] = 1;
						path[p.first-1][p.second] = path[p.first][p.second] + 1;
						q.push({p.first-1,p.second});
					}
				}
				if(p.second+1 < m){
					if(arr[p.first][p.second+1] == '.' && !vis[p.first][p.second+1]){
						vis[p.first][p.second+1] = 1;
						path[p.first][p.second+1] = path[p.first][p.second] + 1;
						q.push({p.first,p.second+1});
					}
				}
				if(p.second-1 >= 0){
					if(arr[p.first][p.second-1] == '.' && !vis[p.first][p.second-1]){
						vis[p.first][p.second-1] = 1;
						path[p.first][p.second-1] = path[p.first][p.second] + 1;
						q.push({p.first,p.second-1});
					}
				}
			}
			for(int k = 0; k < n; k++){
				for(int f = 0; f < m; f++){
					best = max(path[k][f],best);
				}
			}
		}
	}
	cout<<best<<"\n";
}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
macro_rules ! chmin {($ base : expr , $ ($ cmps : expr ) ,+ $ (, ) * ) => {{let cmp_min = min ! ($ ($ cmps ) ,+ ) ; if $ base > cmp_min {$ base = cmp_min ; true } else {false } } } ; }
macro_rules ! chmax {($ base : expr , $ ($ cmps : expr ) ,+ $ (, ) * ) => {{let cmp_max = max ! ($ ($ cmps ) ,+ ) ; if $ base < cmp_max {$ base = cmp_max ; true } else {false } } } ; }
macro_rules ! min {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: min ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: min ($ a , min ! ($ ($ rest ) ,+ ) ) } } ; }
macro_rules ! max {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: max ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: max ($ a , max ! ($ ($ rest ) ,+ ) ) } } ; }
fn main() {
    input! {//
        t:usize,
        mut nabcd:[(i128,i128,i128,i128,i128);t]
    }
    for &(n, a, b, c, d) in nabcd.iter() {
        let mut g = G {
            n: n,
            a: a,
            b: b,
            c: c,
            d: d,
            dp: HashMap::new(),
        };
        println!("{}", g.solve(n));
    }
}
struct G {
    n: i128,
    a: i128,
    b: i128,
    c: i128,
    d: i128,
    dp: HashMap<i128, i128>,
}
impl G {
    fn solve(&mut self, n: i128) -> i128 {
        if n == 1 {
            return self.d;
        }
        if n == 0 {
            // return 0;
            return INF;
        }
        let dp = *self.dp.entry(n).or_insert(0);
        if dp > 0 {
            return dp;
        }
        let mut ret = n * self.d;
        ret = min(
            ret,
            self.solve(n / 2) + self.a + (n - (n / 2 * 2)) * (self.d),
        );
        ret = min(
            ret,
            self.solve((n + 1) / 2) + self.a + ((n + 1) / 2 * 2 - n) * (self.d),
        );
        ret = min(ret, self.solve(n / 3) + self.b + (n - (n / 3 * 3)) * self.d);
        ret = min(
            ret,
            self.solve((n + 2) / 3) + self.b + ((n + 2) / 3 * 3 - n) * self.d,
        );
        ret = min(ret, self.solve(n / 5) + self.c + (n - n / 5 * 5) * self.d);
        ret = min(
            ret,
            self.solve((n + 4) / 5) + self.c + ((n + 4) / 5 * 5 - n) * self.d,
        );
        *self.dp.entry(n).or_insert(0) = ret;
        ret
    }
}
// fn rec(n:i128,a:i128,b:i128,c:i128,d:i128)
const INF: i128 = 1 << 120;


Measured memory_bytes: 3048