akhauriyash/Code-Regression huggingface dataset:
program prob6
    implicit none
    integer, allocatable::a(:), ans(:,:)
    integer::n, i, j
    read(*,*) n
    allocate(a(n),ans(n,2))
    read(*,*) a
    call hsort(n,1,1,a)
    if(a(n) < 0) then
        do i = 1, n-1
            ans(i,1) = a(n)
            ans(i,2) = a(n-i)
            a(n) = a(n) - a(n-i)
        end do
    else if(a(1) >= 0 .and. a(n) >= 0) then
        do i = 1, n-2
            ans(i,1) = a(1)
            ans(i,2) = a(i+1)
            a(1) = a(1) - a(i+1)
        end do
        ans(n-1,1) = a(n)
        ans(n-1,2) = a(1)
        a(n) = a(n) - a(1)
    else
        do i = 1, n
            if(a(i) >= 0) then
                do j = i, n-1
                    ans(j-i+1,1) = a(1)
                    ans(j-i+1,2) = a(j)
                    a(1) = a(1) - a(j)
                end do
                do j = 1, i-1
                    ans(n-i+j,1) = a(n)
                    ans(n-i+j,2) = a(j)
                    a(n) = a(n) - a(j)
                end do
                exit
            end if
        end do
    end if
    write(*,*) a(n)
    do i = 1, n-1
        write(*,'(i14,x,i14)') ans(i,1), ans(i,2)
    end do
    deallocate(a, ans)
    stop
contains
    ! n行m列の配列をp列目でsort
    ! 1次元配列ならm=p=1
    subroutine hsort(n,m,p,array)
        implicit none
        integer,intent(in)::n, m, p
        integer,intent(inout)::array(n,m)

        integer ::i,k,j,l
        integer::t(m)

        if(n.le.0)then
        write(6,*)"Error, at heapsort"; stop
        end if
        if(n.eq.1)return

        l=n/2+1
        k=n
        do while(k.ne.1)
        if(l.gt.1)then
            l=l-1
            t=array(L,:)
        else
            t=array(k,:)
            array(k,:)=array(1,:)
            k=k-1
            if(k.eq.1) then
                array(1,:)=t
                exit
            end if
        end if
        i=l
        j=l+l
        do while(j.le.k)
            if(j.lt.k)then
                if(array(j,p).lt.array(j+1,p))j=j+1
            end if
            if (t(p).lt.array(j,p))then
                array(i,:)=array(j,:)
                i=j
                j=j+j
            else
                j=k+1
            end if
        end do
        array(i,:)=t
        end do

        return
    end subroutine hsort
end program

Measured memory_bytes: 5188
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")

def main():
    N = I()
    ABCDE = IR(5)
    print(5 + N // min(ABCDE) - int(min(ABCDE) == 1))

if __name__ == '__main__':
    main()

Measured memory_bytes: 77248
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		long K = Long.parseLong(sc.get());
		int[] A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()) - 1);

		BitSet visited = new BitSet();
		int pos = 0;
		int[] path = new int[N];
		int start = -1;
		int[] circular = null;
		for (int i = 0; i < N; i++) {
			path[i] = pos;
			if (visited.get(pos)) {
				start = indexOf(path, pos);
				circular = Arrays.copyOfRange(path, start, i);
				break;
			}
			visited.set(pos);
			pos = A[pos];
		}

		if (K <= start) {
			System.out.println(path[(int) K] + 1);
		} else {
			System.out.println(circular[(int) ((K - start) % circular.length)] + 1);
		}
	}

	int indexOf(int[] array, int value){
		for (int i = 0; i < array.length; i++) {
			if (array[i] == value) return i;
		}
		return -1;
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 54872
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> P;

int main(){
	int N, Q;

	while(cin >> N >> Q, N || Q){
		map<string, P> m;
		vector<string> v;
		
		for(int i = 0; i < N; i++){
			string name;
			int y1, y2;
			
			cin >> name >> y1 >> y2;
			
			if(m.count(name)){
				if(m[name].second < y2){
					m[name] = P(y1, y2);
				}
			}else{
				m[name] = P(y1, y2);
				v.push_back(name);
			}
		}
		
		for(int i = 0; i < Q; i++){
			int q;
			cin >> q;
			
			bool flag = false;
			
			for(int j = 0; j< v.size(); j++){
				int y1 = m[v[j]].first;
				int y2 = m[v[j]].second;
				
				if(y2 - y1 + 1 <= q && q <= y2){
					flag = true;
					
					int ans = q - (y2 - y1);
					
					cout << v[j] << " " << ans << endl;
					
					break;
				}
			}
			
			if(!flag){
				cout << "Unknown" << endl;
			}
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  int odd = (n+1)/2;
  // ceil(a/b) = (a+b-1)/b
  double ans = (double)odd/n;
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		long[] l = new long[N+1];


		Arrays.fill(l, 0);

		l[0] = 2;

		l[1] = 1;

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


			long l_i = l[i-1] + l[i-2];

			l[i] = l_i;
		}

		System.out.println(l[N]);
	}

}


Measured memory_bytes: 23636
import numpy as np
import copy
D = int(input())
c = list(map(int,input().split()))
score = [0]*26
last = [0]*26
s = []
point = 0

for i in range(D):
  x = np.array(list(map(int, input().split())))
  for j in range(26):
    tmp = copy.copy(last)
    tmp[j] = i;
    for k in range(26):
  	  x[j] = x[j]-(c[k]*(i-tmp[k]))+point
  s.append(x.argmax())
  last[x.argmax()] = i
  point+=max(x)
for i in range(D):
  print(s[i]+1)

Measured memory_bytes: 27392
from collections import Counter

N=int(input())
S=[]
for i in range(N):
  S.append(input())
S=Counter(S)

common = S.most_common()
keys = []
for i, pair in enumerate(common):
  key, val = pair
  if i == 0:
    MAX = val
  else:
    if val < MAX:break
  keys.append(key)
keys = sorted(keys)
for i in range(len(keys)):
  print(keys[i])

Measured memory_bytes: 50272
#include <bits/stdc++.h>
using namespace std;
 
inline void chmax(int &a, int b) { a = max(a, b); }
 
int n, m;
int v[3005], h[3005];
int t[1005], s[1005];
int isok[3005][1005] = {};
int dp[1005][3005][2];
 
int main()
{
  bool ans = false;
  cin >> n >> m;
   
  fill_n(**dp, 1005 * 3005 * 2, -1);

  v[0] = 0;
  for(int i = 1; i <= n; i++) {
    cin >> v[i] >> h[i];
  }
 
  t[0] = 0;
  for(int i = 1; i <= m; i++) {
    cin >> t[i] >> s[i];
  }
   
  {
    int sum = 0;
    for(int i = 0; i <= n; i++) {
      sum += v[i];
      for(int j = 0; j <= m; j++) {
        isok[i][j] = t[j] - sum;
      }
    }
  }
   
  dp[0][0][0] = 0;
  for(int i = 0; i < m; i++) {
    for(int j = 0; j <= n; j++) {
      for(int l = 0; l < 2; l++) {
	int sum = 0;
	if(dp[i][j][l] == -1) continue;
	if(isok[j + 1][i] >= 0) {
	  int val = dp[i][j][l] + h[j + 1];
	  if(l == 0) val += abs(h[j + 1] - h[j]);
	  chmax(dp[i][j + 1][0], val);
	}
	if(dp[i][j][l] >= s[i + 1]) { chmax(dp[i + 1][j][1], dp[i][j][l]); continue; }
	sum += h[j + 1];
	if(dp[i][j][l] + sum >= s[i + 1] && isok[j + 1][i + 1] >= 0) { chmax(dp[i + 1][j + 1][0], dp[i][j][l] + sum); continue; }
	for(int k = j + 2; k <= n && isok[k][i + 1] >= 0; k++) {
	  sum += h[k] + abs(h[k] - h[k - 1]);
	  if(dp[i][j][l] + sum >= s[i + 1]) { chmax(dp[i + 1][k][0], dp[i][j][l] + sum); break; }
	}
      }
    }
  }
  
  for(int i = 0; i <= n; i++) {
    for(int j = 0; j < 2; j++) {
      if(!ans && dp[m][i][j] != -1) {
	ans = true;
	cout << isok[i][m] << endl;
      }
    }
  }
 
  if(!ans) cout << -1 << endl;
 
  return (0);
}

Measured memory_bytes: 38512
#include<iostream>
#include<stdio.h>

int combi(int n, int k);
int main(void){
  int N,M;
  scanf("%d %d",&N,&M);
  printf("%d",combi(N,2)+combi(M,2));
  return 0;
}

int combi(int n, int k) {
  if (n < k)return 0;
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

Measured memory_bytes: 256
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int R; cin >> R;
  double l;
  l = 2 * R * M_PI;
  cout << l << endl;
}

Measured memory_bytes: 3804
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Array.Sort(A);
		Array.Reverse(A);
		
		var di = new Dictionary<int,int>();
		for(int i=0;i<N;i++){
			if(!di.ContainsKey(A[i])) di.Add(A[i], 0);
			di[A[i]]++;
		}
		
		var l = di.Keys.ToList();
		l.Sort();
		l.Reverse();
		
		int gr = 0;
		int h = 0;
		for(int i=0;i<l.Count;i++){
			h += di[l[i]];
			int w = 0;
			if(i + 1 < l.Count){
				w = l[i] - l[i + 1];
			} else {
				w = l[i];
			}
			
			gr ^= (w % 2) * h;
		}
		Console.WriteLine(gr == 0 ? "second" : "first");
		
		
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = new int[N];
		for(int i=0;i<N;i++) A[i] = ri();

	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 23132
#pragma region Template
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}
#pragma endregion Template

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

    int N;
    scan(N);
    vector<pair<ll, ll>> v(N);
    rep(i, N) {
        ll x, l;
        scan(x, l);
        v[i].first  = x + l;
        v[i].second = x - l;
    }
    sort_(v);
    ll ans = 0, now = -INF64;
    rep(i, N) {
        if (now <= v[i].second) {
            ans++;
            now = v[i].first;
        }
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <set>
#include <queue>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define pb(x) push_back(x)
typedef long long ll;
typedef unsigned long long ull;
const int mod=1e9+7;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int N=100+5;
int main()
{
    int a,b,c;
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        int ans=0;
        ans^=a;
        ans^=b;
        ans^=c;
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

#define NIL -1

using namespace std;

struct Node
{
	int key;
	Node * parent, * lchild, * rchild;
};


void insert(Node * &T, int key);
void insert_rec(Node * &T, int key);
void print(Node * T);
void inorder(Node * T);
void preorder(Node * T);
void find_rec(Node * T, int key);
void find(Node * T, int key);



int main()
{
	int n;
	Node * T = NULL;
	
	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		string cmd;
		
		cin >> cmd;
		if (cmd == "insert")
		{
			int key;
			cin >> key;
			insert_rec(T, key);
			
		}
		else if (cmd == "print")
		{
			print(T);
		}
		else if (cmd == "find")
		{
			int key;
			cin >> key;
			find_rec(T, key);
		}
	}
}


void insert(Node * &T, int key)
{
	Node * p = new Node;
	p->key = key;
	p->lchild = p->rchild = NULL;
	
	if (T == NULL) T = p;
	else
	{
		Node * q = NULL, * r = T;
		while (r != NULL)
		{
			q = r;
			if (p->key < r->key)
				r = r->lchild;
			else 
				r = r->rchild;
		}
	
		if (p->key < q->key)
			q->lchild = p;
		else
			q->rchild = p;
	}
}


void insert_rec(Node * &T, int key)
{
	if (T == NULL)
	{
		Node * p = new Node;
		p->key = key;
		p->lchild = p->rchild = NULL;
		T = p;
	}
	else if (key < T->key)
		insert_rec(T->lchild, key);
	else
		insert_rec(T->rchild, key);
}


void print(Node * T)
{
	inorder(T);
	cout<< endl;
	preorder(T);
	cout << endl;
}


void inorder(Node * T)
{
	if (T == NULL) return;
	inorder(T->lchild);
	cout << ' ' << T->key;
	inorder(T->rchild);
}


void preorder(Node * T)
{
	if (T == NULL) return;
	cout << ' ' << T->key;	
	preorder(T->lchild);
	preorder(T->rchild);
}


void find_rec(Node * T, int key)
{
	if (T == NULL)
		cout << "no" << endl;
	else if (key == T->key)
		cout << "yes" << endl;
	else if (key < T->key)
		find_rec(T->lchild, key);
	else
		find_rec(T->rchild, key);
}


void find(Node * T, int key)
{
	
}


Measured memory_bytes: 21756
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL solve(LL n,LL a){
	if(n==0) return a;
 
	LL c=1;
	LL ans=0;
	while(c<=n){
		c*=10;
		ans+=solve(n/c,n%c+a);
	}
	return ans;
}
int main(){
	LL n;
	cin >> n;
	cout << solve(n,0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, Q, q, t, x;
    cin >> n >> Q;
    priority_queue<int> v[n];

    rep(i, Q) {
        cin >> q >> t;
        if(q == 0) {
            cin >> x;
            v[t].push(x);
        } else if(q == 1) {
            if(v[t].size()) cout << v[t].top() << "\n";
        } else {
            if(v[t].size()) v[t].pop();
        }
    }
}



Measured memory_bytes: 4092
from collections import Counter


def mod_pow(a, n, mod):
    """
    二分累乗法による a^n (mod m)の実装
    :param a: 累乗の底
    :param n: 累乗の指数
    :param mod: 法
    :return: a^n (mod m)
    """

    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


N = int(input())
A = Counter(tuple(map(int, input().split(' '))))
MOD = 10 ** 9 + 7

if A[0] > 1:
    print(0)
elif sum([key for key, value in A.items() if value == 1]) != 0:
    print(0)
else:
    print(mod_pow(2, N // 2, MOD))


Measured memory_bytes: 20920
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(); in.nextLine();
		int[] ary = new int[n];
		for ( int i = 0; i < n; i++ ) {
			ary[i] = in.nextInt();
		}
		Arrays.sort(ary);
		int d = 0;
		for ( int i = 1; i < n; i++ ) {
			d += ary[i]-ary[i-1];
		}
		System.out.println(d);
	}
}

Measured memory_bytes: 20692
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        int i=0;
        String st=tan.next();
        char []c=new char[st.length()];
        for(char ch : st.toCharArray()){
            c[i]=ch;
            i++;
        }
        if(c[2]==c[3] && c[4]==c[5])
            System.out.println("Yes");
        else 
            System.out.println("No");
    }
}


Measured memory_bytes: 35500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
struct UnionFind{
vector<int> par,depth,Size;
UnionFind(int n){
par.resize(n); depth.resize(n); Size.resize(n);
for(int i=0; i<n; i++){
par[i]=i;
depth[i]=0;
Size[i]=1;
}
}
int find(int x){
if(par[x]==x){
return x;
}
else{
return par[x]=find(par[x]);
}
}
bool same(int x, int y){
return find(x)==find(y);
}
void unite(int x, int y){
x=find(x); y=find(y);
if(x==y) return;
if(depth[x]<depth[y]) swap(x,y);
if(depth[x]==depth[y]) depth[x]++;
par[y]=x;
Size[x]+=Size[y];
}
int size(int x){
return Size[find(x)];
}
};
int main(){
    ll n,m;cin >> n >> m;
    vector<int> a(m),b(m);
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
    }
    vector<ll> ans(m);
    ans[m-1]=n*(n-1)/2;
    UnionFind uf(n+1);
    for(int i=m-1;i>=1;i--){
        if(uf.same(a[i],b[i])){
            ans[i-1]=ans[i];
        }
        else{
            ll x=uf.size(a[i]);
            ll y=uf.size(b[i]);
            ans[i-1]=ans[i]-x*y;
            uf.unite(a[i],b[i]);
        }
    }
    for(int i=0;i<m;i++) cout << ans[i] << endl;
    return 0;
}

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

int main() {
    vector<int> x(5);
    for (int i = 0; i < 5; i++) {
        cin >> x.at(i);
    }

    int ans = 0;
    for (int i = 0; i < 5; i++) {
        if (x.at(i) == 0) {
            ans = i + 1;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	Rapid_pleaseAC_fast;

	int a, b;
	cin >> a >> b;
	if (a > 8 || b > 8) {
		cout << ":(" << rt;
	}
	else {
		cout << "Yay!" << rt;
	}

	please AC;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    for (int i = 0; i <= x; i++) {
        if (i * 2 + 4 * (x-i) == y) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


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

int X, Y;

pair<int, int> gcd_count(int X, int Y)
{
	int count = 0;

	do
	{
		X = X % Y;
		swap(X, Y);
		count++;
	} while (Y != 0);

	return make_pair(X, count);
}

signed main()
{
	while (true)
	{
		cin >> X >> Y;
		if (X == 0 && Y == 0) break;

		if (X < Y) swap(X, Y);
		pair<int, int> ans = gcd_count(X, Y);
		
		cout << ans.first << " " << ans.second << endl;
	}
}

Measured memory_bytes: 1160
#include <stdio.h> 
 
 
 int main(){ 
     int h, w; 
     int i, j; 
     while(1){ 
         scanf("%d %d ", &h, &w); 
         if(h==0&&w==0)break; 
         for(i=0;i<h;i++){ 
             for(j=0;j<w;j++){ 
                 if(i==0||i==h-1||j==0||j==w-1){ 
                     printf("#"); 
                 }else{ 
                     printf("."); 
                 } 
             } 
             printf("\n"); 
         } 
         printf("\n"); 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2040
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int ll
#define For(a, b, c) for(int a = b; a <= c; ++a)
#define Ford(a, b, c) for(int a = b; a >= c; --a)
#define All(a, b) for(auto &a : b)
#define Rep(a, b, c) for(int a = b; a < c; ++a)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define reset(a, b) memset(a, b, sizeof(a))
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))
#define bitone(i) __builtin_popcountll(i)
#define bitl(i) __builtin_clz(i)
#define bitr(i) __builtin_ctz(i)
#define vll vector<ll>
/********************************************************

Digvijay Bahadur Singh
MNNIT

*********************************************************/
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}


const int MOD=1e9+7;
const int N = 1e6+100;
/********************************************************************/
                 /* GRAPH*/
//vector<vector<ll>> g;
//vector<bool> vis1,vis2;
/*******************************************************************/
ll power(ll a,ll b)
{
   ll ans =1;
   while(b>0){
   if(b&1) ans = (ans%MOD * a%MOD)%MOD;
   a = (a%MOD * a%MOD)%MOD;
   b=b>>1;
   }
   return ans%MOD;
}


signed main(){
  ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
  ll n;

  
  ll T=1;
 // cin>>T;
  
   // T=1;
    
        while(T--)
        {
          int k,n;
          cin>>k>>n;
          int a[2*n];
          int ans=0;
          for(int i=0;i<n;i++)
          {
            cin>>a[i];
           // cout<<a[i]<<" ";
            
            
          }
          for(int i=n;i<2*n;i++)
          {
            a[i]=a[i-n]+k;
          //  cout<<a[i]<<" ";
          }
          int diff[2*n-1];
         // cout<<endl;
            for(int i=1;i<2*n;i++)
            {
              diff[i-1]=a[i]-a[i-1];
             // cout<<diff[i-1]<<" ";
            }
          int sum=0;
          for(int i=0;i<2*n-1;i++)
          {
            if(i<n-1)
            {
              sum+=diff[i];
            }
          }
         // cout<<sum<<"\n";
          ans=sum;
          for(int i=n-1;i<2*n-1;i++)
          {
            ans=ans+diff[i]-diff[i-n+1];
            sum=min(ans,sum);
          }
          cout<<sum<<"\n";

          
        }
    
      

  }

  



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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;

ll MOD=1000000007;

signed main(){
	llin(a);
	llin(b);
	sal(double(a)/double(b));
}


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

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(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999


int h,w,n;
string data[1100];

//void dfs(int y,int x,int fie[1100][1100],bool used[1100][1100],int dir){
//    fie[y][x]=dir;
//    int dx[]={0,1,0,-1};
//    int dy[]={1,0,1,-1};
//    rep(i,4){
//        int ddy=y+dy[i];
//        int ddx=x+dx[i];
//        if(ddy>=0 && ddy<h && ddx>=0 && ddx<w && fie[ddy][ddx]!='X' && !used[ddy][ddx]){
//            used[ddy][ddx]=true;
//            dfs(ddy,ddx,fie,used,dir+1);
//        }
//    }
//}

int main(){
    while(cin>>h>>w>>n){
        rep(i,h)cin>>data[i];
        
        pii ce[10];
        rep(i,h)rep(j,w){
            if(data[i][j]=='S'){
                ce[0]=pii(i,j);
            }
            if(isdigit(data[i][j])){
                ce[data[i][j]-'0']=pii(i,j);
            }
        }
        int sum=0;
        rep(i,n){
            int fie[1100][1100];
            rep(i,1100)rep(j,1100)fie[i][j]=INF;
            bool used[1100][1100]={};

            fie[ce[i].first][ce[i].second]=0;
            used[ce[i].first][ce[i].second]=true;
            queue<pii> que;
            que.push(ce[i]);
            while(que.size()){
                int y=que.front().first;
                int x=que.front().second;
                que.pop();
                int dx[]={0,1,0,-1};
                int dy[]={1,0,-1,0};
                rep(i,4){
                    int ddy=y+dy[i];
                    int ddx=x+dx[i];
                    if(ddy>=0 && ddy<h && ddx>=0 && ddx<w && data[ddy][ddx]!='X' && !used[ddy][ddx]){
                        used[ddy][ddx]=true;
                        fie[ddy][ddx]=fie[y][x]+1;
                        que.push(pii(ddy,ddx));
                    }
                }
            }
            
            
            sum+=fie[ce[i+1].first][ce[i+1].second];
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 8180
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 200000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

int arr[MAX + 5];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int n, i, a;
    cin >> n;
    for (i = a = 0; i < n; ++i) {
        cin >> arr[i];
        a ^= arr[i];
    }
    for (i = 0; i < n; ++i) {
        cout << (a ^ arr[i]) << " ";
    }


    return 0;
}

Measured memory_bytes: 3928
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  4007
ll m1[N];
ll m2[N];
ll m3[N];
void func1(string a,string b)
{
	rep(i,0,a.length())
	{
		ll fl=0;
		rep(j,0,b.length())
		{
			if(i+j>=a.length())
				break;
			if(a[i+j]==b[j] || a[i+j]=='?' || b[j]=='?')
				continue;
			fl=1;
			break;
		}
		m1[i]=(!fl);
	}
}	
void func2(string a,string b)
{
	rep(i,0,a.length())
	{
		ll fl=0;
		rep(j,0,b.length())
		{
			if(i+j>=a.length())
				break;
			if(a[i+j]==b[j] || a[i+j]=='?' || b[j]=='?')
				continue;
			fl=1;
			break;
		}
		m2[i]=(!fl);
	}
}	
void func3(string a,string b)
{
	rep(i,0,a.length())
	{
		ll fl=0;
		rep(j,0,b.length())
		{
			if(i+j>=a.length())
				break;
			if(a[i+j]==b[j] || a[i+j]=='?' || b[j]=='?')
				continue;
			fl=1;
			break;
		}
		m3[i]=(!fl);
	}
}	
ll func(string a,string b,string c)
{
	memset(m1,1,sizeof(m1));
	memset(m2,1,sizeof(m2));
	memset(m3,1,sizeof(m3));
	func1(a,b);
	func2(b,c);
	func3(a,c);
	ll res=1e18;
	ll n1=a.length();
	ll n2=b.length();
	ll n3=c.length();
	rep(i,0,N)
	{
		rep(j,0,N)
		{
			if(m1[i] && m2[j] && (m3[i+j]||(i+j)>=N))
			{
				ll z=max(n1,n2+i);
				z=max(z,n3+i+j);
				res=min(res,z);
			}
		}
	}
	return res;
}
int main()
{
	
	io
	string a,b,c;
	cin>>a>>b>>c;
	ll res=func(a,b,c);
	res=min(res,func(a,c,b));
	res=min(res,func(c,a,b));
	res=min(res,func(c,b,a));
	res=min(res,func(b,a,c));
	res=min(res,func(b,c,a));
	cout<<res;
	
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    ll n, t;
    cin >> n >> t;
    ll st = 0, en = 0;
    ll dur = 0;
    int time[n];
    for(int i = 0; i < n; i++){
        cin >> time[i];
    }
    for(int i = 0; i < n; i++){
        if(en >= time[i]){
            en = t + time[i];
        }else{
            dur += en - st;
            st = time[i];
            en = time[i] + t;
        }
    }
    dur += en - st;
    cout << dur;
}

Measured memory_bytes: 1024
/*

road to the IOI
&author : kair011a_

*/
#include <bits/stdc++.h>

#define PB push_back
#define F first
#define S second
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()

#define open(name) \
    freopen(name".in", "r", stdin); \
    freopen (name".out", "w", stdout);

using namespace std;

const int N = 1e5 + 7;
const int logg = 20;
const int INF = (1 << 30) + 7;
const int p = 31;

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

int n;
int a[N], dp[N], ans[N];

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i ++)
        cin >> a[i];
    dp[0] = 0;
    dp[2] = abs(a[2] - a[1]);
    for (int i = 3; i <= n; i ++) {
        int q1 = abs(a[i] - a[i - 1]) + dp[i - 1];
        int q2 = abs(a[i] - a[i - 2]) + dp[i - 2];
        if (q1 < q2) {
            dp[i] = q1;
        } else {
            dp[i] = q2;
        }
    }
    cout << dp[n];
}

main() {
    ios::sync_with_stdio(false);
    //open("LOSER");
    solve();
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

#define datatype int

typedef enum{
	false,
	true
}Boolean;

typedef struct edge_sub{
	int v;
	struct edge_sub *next;
}edge;

typedef struct {
	int num;
	int parent;
	int dis;
	Boolean is_path;
	edge *near;
}vertex;

typedef struct node_sub{
	datatype data;
	struct node_sub *next;
}node;

typedef struct {
	node *fst;
	node *last;
	int num;
}queue;

queue *make_queue(){
	queue *q = (queue *)malloc(sizeof(queue));
	q->fst = NULL;
	q->last = NULL;
	q->num = 0;
	return q;
}

Boolean is_empty_q(queue *q){
	if(q->num == 0){
		return true;
	}
	else{
		return false;
	}
}

void add_data_q(datatype val, queue *q){
	node *last = (node *)malloc(sizeof(node));
	last->data = val;
	last->next = NULL;
	if(is_empty_q(q) == true){
		q->fst = last;
	}
	else{
		q->last->next = last;
	}
	q->last = last;
	q->num++;
}

datatype take_data_q(queue *q){
	if(q->num == 0){
		printf("no data in the queue\n");
	}
	datatype ans = q->fst->data;
	node *fst = q->fst;
	if(q->num == 1){
		q->fst = NULL;
		q->last = NULL;
	}
	else{
		q->fst = fst->next;
	}
	free(fst);
	q->num--;
	return ans;
}

void to_empty(queue *q){
	datatype a;
	while(is_empty_q(q) == false){
		a = take_data_q(q);
	}
}

int main(){
	int N, a, b, i, ans = 0;
	scanf("%d", &N);
	vertex *v = (vertex *)malloc(sizeof(vertex) * N);
	for(i = 0; i < N; i++){
		v[i].num = i;
		v[i].parent = -1;
		v[i].dis = 0;
		v[i].is_path = false;
		v[i].near = NULL;
	}
	edge *new;
	for(i = 1; i < N; i++){
		scanf("%d%d", &a, &b);
		a--;
		b--;
		new = (edge *)malloc(sizeof(edge));
		new->v = b;
		new->next = v[a].near;
		v[a].near = new;
		new = (edge *)malloc(sizeof(edge));
		new->v = a;
		new->next = v[b].near;
		v[b].near = new;
	}
	queue *q = make_queue();
	add_data_q(0, q);
	int nowv;
	edge *e;
	while(is_empty_q(q) == false){
		nowv = take_data_q(q);
		//printf("nowv = %d\n", nowv);
		e = v[nowv].near;
		while(e != NULL){
			if(e->v != v[nowv].parent){
				v[e->v].parent = nowv;
				v[e->v].dis  = v[nowv].dis + 1;
				add_data_q(e->v, q);
			}
			e = e->next;
		}
	}
	//printf("test1\n");
	nowv = N - 1;
	while(nowv != -1){
		//printf("nowv = %d\n", nowv);
		v[nowv].is_path = true;
		nowv = v[nowv].parent;
	}
	//printf("test2\n");
	to_empty(q);
	add_data_q(0, q);
	//printf("v[N - 1].dis = %d\n", v[N - 1].dis);
	while(is_empty_q(q) == false){
		nowv = take_data_q(q);
		ans++;
		//printf("nowv = %d\n", nowv);
		e = v[nowv].near;
		while(e != NULL){
			if(e->v != v[nowv].parent){
				if(v[e->v].is_path == false || v[e->v].dis < v[N - 1].dis / 2 + 1){
					add_data_q(e->v, q);
				}
			}
			e = e->next;
		}
	}
	//printf("%d\n", ans);
	if(ans > N / 2){
		printf("Fennec\n");
	}
	else{
		printf("Snuke\n");
	}
	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m ,p;
  while(cin >> n >> m >> p && (n || m || p)){
    vary(double,x,n,0);
    double pool = 0;
    rep(i,n){
      cin >> x[i];
      pool += x[i] ;
    }
    pool *= (100-p);
//     debug(pool);
    if(x[m-1] != 0){
      cout << (int)(pool / x[m-1])<<endl;
    }
    else{
      cout << 0 << endl;
    }
  }
  return 0;
}

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


int main()
{
	int a,b,c,x,sum=0;
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if(i*500+j*100+k*50==x)
				{
					sum++;
				}
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
n, m  = gets.chomp.split(" ").map(&:to_i)

if n%2 != 0
  m.times do |i|
    l = i+1
    r = n-l
    puts "#{l} #{r}"
  end
else
  l = 1
  r = n
  flag = false
  m.times do |i|
    if n/4 < l && !flag
      flag = true
      l+=1
    end
    puts "#{l} #{r}"
    l+=1
    r-=1
  end
end

Measured memory_bytes: 14272
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c,mx=0;
	cin >> a >> b >> c;
	mx = max(a * 10 + b + c , a + c + 10 * b);
	mx = max(mx, a + b + 10 * c);
	cout << mx;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x=1e9+7;
ll a[1000110],bq[1000110],bl[1000110];
int main()
{
	ll n,k;
	cin>>n>>k;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sizeof(bq,0,sizeof(bq));
	sizeof(bl,0,sizeof(bl));
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<i;j++)
		{
			if(a[i]>a[j])
			bq[i]++;
		}
		for(ll j=i+1;j<n;j++)
		{
			if(a[i]>a[j])
			bl[i]++;
		}
	}
	ll sum1=(k-1)*k/2;
	sum1=sum1%x; 
	long long sum3=0;
	for(ll i=0;i<n;i++)
	{
		sum3+=bq[i]*sum1;
		sum3=sum3%x;
		sum3+=bl[i]*(sum1+k);
		sum3=sum3%x;
	}
	cout<<sum3%x<<endl;
 } 

Measured memory_bytes: 4352
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

import math

def main():
    a, b, h, m = map(int, input().split())
    p = 30 * (h + m / 60)
    q = 6 * m
    r = abs(p - q)
    if r > 180:
        r = 360 - r
    r = math.radians(r)
    ans = ((a - b * math.cos(r)) ** 2 + (b * math.sin(r)) ** 2) ** (1 / 2)
    print('{:.9f}'.format(ans))
main()

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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
ll nmax = 200005;
vll lis(nmax,LLINF);


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    lis[0] = -(LLINF);
    ll n;
    cin >> n;
    vll a(n);
    REP(i,n) cin >> a[i];
    vvll nei(n);
    REP(i,n-1){
        ll u,v;
        cin >> u >> v;
        u--; v--;
        nei[u].pb(v);
        nei[v].pb(u);
    }
    vll par(n);
    par[0] = -1;
    stack<ll> st;
    st.push(0);
    vll ans(n,-1);
    vector<pair<ll,ll> > cng(n);
    while(!st.empty()){
        ll now = st.top();
        if(ans[now]>=0){
            st.pop();
            lis[cng[now].fi] = cng[now].se;
            continue;
        }
        ll ok = 0;
        ll ng = n;
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            if(lis[mid]<a[now]){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        cng[now] = make_pair(ng, lis[ng]);
        lis[ng] = a[now];
        for(ll i : nei[now]){
            if(i!=par[now]){
                st.push(i);
                par[i] = now;
            }
        }
        ok = 0;
        ng = n+1;
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            if(lis[mid]<LLINF){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        ans[now] = ok;
    }
    REP(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 29000
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

int main(void){
    int N, K;
    
    cin >> N >> K;
    
    if(K == 1){
        cout << 0 << endl;
    }else{
        cout << N - K << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define ll long long
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    ll c=0;
    cin>>s;
    for(ll i=0;i<(ll)s.length();i++){
        if(s[i]=='C' && i>=2 && i<(ll)s.length()-1)c++;
        if((s[i]!='A' && !i) || (c>1) || (s[i]=='C' && (i<2 || i==(ll)s.length()-1)) || ((ll)s[i]<=90 && s[i]!='A' && s[i]!='C')){
            cout<<"WA";
            return 0;
        }
    }
    cout<<((!c)?"WA":"AC");
    return 0;
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  string s;
  cin>>s;
  int res=700;
  if(s[0]=='o'){
    res+=100;
  }
  if(s[1]=='o'){
    res+=100;
  }
  if(s[2]=='o'){
    res+=100;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }
    int d4 = 0;
    int d2 = 0;
    int d0 = 0;
    REP(i,n){
        if(a[i]%4==0){
            d4++;
        }else if(a[i]%2==0){
            d2++;
        }else{
            d0++;
        }
    }
    if(d2>0){
        if(d4>=d0)put("Yes");
        else put("No");
    }else{
        if(d4>=d0-1)put("Yes");
        else put("No");
    }
    
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
typedef long long ll;
int main(){
	int n,sum4,sum2,sum;
	ll a[100100];
	while(cin>>n){
		sum=(n)/2;
		sum4=0;sum2=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			if(a[i]%4==0)sum4++;
			else if(a[i]%2==0)sum2++;
		}
		if(sum4>=sum||sum2/2+sum4>=sum){
			cout<<"Yes"<<endl;
			
		}
		else cout<<"No"<<endl;
	} 
	return 0;
}

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


void solve(long long A, long long B, long long C, long long K){
    ll ans = 0;
    if(K <= A){
        cout<<K<<endl;
        return;
    }else{
        ans += A;
        K -= A;
    }
    if(K <= B){
        cout<<ans<<endl;
        return;
    }else{
        K -= B;
    }
    cout<<ans - K<<endl;
}

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


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define INF 1e9

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

    int k;
    cin >> k;

    if (k % 2 == 0) {
        cout << (k/2)*(k/2) << endl;
    } else {
        cout << (k/2)*(k/2 + 1) << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
   int h1,h2,k1,k2,a,b,c,d;
   int m,n;
   scanf("%d%d%d%d%d%d%d%d",&h1,&h2,&k1,&k2,&a,&b,&c,&d);
   m = h1*a+h2*b+(h1/10)*c+(h2/20)*d;
   n = k1*a+k2*b+(k1/10)*c+(k2/20)*d;
   if (m > n) {
      /* code */
      printf("hiroshi\n");
   } else if (m < n) {
      /* code */
      printf("kenjiro\n");
   } else {
      printf("even\n");
   }
   return 0;
}

Measured memory_bytes: 1848