akhauriyash/Code-Regression huggingface dataset:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
p = list(map(int, input().split()))

d = [None] * (n**2)
for i in range(n):
    for j in range(n):
        d[i*n+j] = min(i, n-1-i, j, n-1-j)
vacant = [False] * (n**2)

ans = 0
for pos in p:
    pos -= 1
    ans += d[pos]
    vacant[pos] = True
    q = [pos]
    while q:
        pos = q.pop()
        tmp = not vacant[pos]
#         for diff in (-1, 1, -n, n):
#             ppos = diff+pos
#             if ppos<0 or ppos>=n*n:
#                 continue
#             if d[ppos]>d[pos]+tmp:
#                 d[ppos] = d[pos] + tmp
#                 q.append(ppos)
        if pos+n<n*n:
            ppos = pos + n
            if d[ppos]>d[pos]+tmp:
                d[ppos] = d[pos] + tmp
                q.append(ppos)
        if pos-n>=0:
            ppos = pos - n
            if d[ppos]>d[pos]+tmp:
                d[ppos] = d[pos] + tmp
                q.append(ppos)
        if pos+1<n*n:
            ppos = pos + 1
            if d[ppos]>d[pos]+tmp:
                d[ppos] = d[pos] + tmp
                q.append(ppos)
        if pos-1>=0:
            ppos = pos - 1
            if d[ppos]>d[pos]+tmp:
                d[ppos] = d[pos] + tmp
                q.append(ppos)
print(ans)

Measured memory_bytes: 188980
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.math.BigDecimal;

public class Main{

    public static void main(String[] args){
        //START

        Scanner sc=new Scanner(System.in);

        int X=sc.nextInt();
        int N=sc.nextInt();

        int[] p=new int[N+10];

        int[] up=new int[200];
        int[] dw=new int[200];

        Arrays.fill(up, 0);
        Arrays.fill(dw, 0);

        int i=0;
        dw[0]=1;

        for(i=0;i<N;i++){
            p[i]=sc.nextInt();
            int sa=p[i]-X;

            if(sa>=0){
                up[sa]=1;
                //System.out.println("plus");
            }else{
                sa=sa*(-1);
                dw[sa]=1;
                //System.out.println("minus");
            }
            //System.out.println(dw[1]);
        }

        int hit=0;

        for(i=0;i<100;i++){
            if(dw[i]==0){
                hit=-i;
                //System.out.println(hit);
                break;
            }else if(up[i]==0){
                hit=i;
                //System.out.println(hit);
                break;
            }else if(i==X){
                //System.out.println("a"+"0");
                break;
            }
        }

        int ans=X+hit;

        //if(i!=X){
            System.out.println(ans);
        //}

        //END
    }
}





Measured memory_bytes: 35576
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  string s;
  char c = '*';
  int i , n ;
  cin >> s;
  n = s.size();
  int ans = 0;
  for(i=0;i<n;i++)
  {
    if(s[i] == c)
      continue;
    else {
      c = s[i];
      ans++;
    }
  }
  cout << ans -1 ;
  return 0;
}


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

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

    string s;
    vector<string> S(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        S.at(i) = s;
    }

    sort(S.begin(), S.end());
    string ans = "";
    for (int i = 0; i < n; i++)
    {
        ans += S.at(i);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int> F(100);
	int n;
	cin>>n;
	F[0]=1;
	F[1]=1;
	for(int i=2;i<=n;i++){
	    F[i]=F[i-2]+F[i-1];
	}
	cout<<F[n]<<'\n';
	return 0;       
}


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

using namespace std;

#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

/*
f(n) = f(n-1) + f(n-3); n >= 6
f(3) = 1;	
f(4) = 1;
f(5) = 1;
*/

int f[2001];

constexpr void pre() {
	f[3] = f[4] = f[5] = 1;
	for (int i = 6; i <= 2000; i++) {
		f[i] = f[i-1] + f[i-3];
		f[i] %= MOD;
	}
}

int main() {
	fast;
	cin.tie(0);
	pre();
	
	lld n;
	cin >> n;
	
	cout << f[n] << endl;
}


Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main(){
	int a, b, c, temp;
	cin >> a >> b >> c;
	if (a>b){
		temp = a;
		a = b;
		b = temp;
	}
	if (b>c){
		temp = b;
		b = c;
		c = temp;
	}
	if (a>b){
		temp = a;
		a = b;
		b = temp;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,m,d[2],b[100001];
bool f[100001];

void nhap()
{
    scanf("%d %d",&n,&m);
    for (int i=1;i<=m;++i)
    {
        int x;
        string s;
        cin>>x>>s;
        if (s=="AC")
        {
            d[0]+=(!f[x]);
            f[x]=1;
        }
        else
        {
            b[x]+=(!f[x]);
        }
    }
    for (int i=1;i<=n;++i)
        if (f[i]) d[1]+=b[i];
    cout<<d[0]<<" "<<d[1];
}

int main()
{
    nhap();
    return 0;
}


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

string a[101], temp;

int main()
{
	int n, l;
	cin >> n >> l;
	for(int i = 0 ; i < n; i++)
	{
		cin >> a[i];
	}
	for(int i = 0; i < n - 1; ++i)
	{
		for( int j = i + 1; j < n; ++j)
		{
			if(a[i] > a[j])
			{
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	for(int i = 0; i < n; ++i)
    {
       cout << a[i];
    }

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int w = sc.nextInt();
        int i = 0;
        String ans = "";
        while(i < s.length()){
            ans += s.charAt(i);
            i += w;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
//B - Lucas Number: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

vector<ll> lucas(90, 0);

ll solve(int x) {
    if(lucas[x]) return lucas[x];
    ll a = solve(x - 1) + solve(x - 2);
    return lucas[x] = a;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n;
    ll ans;
    lucas[0] = 2; lucas[1] = 1;
    cin >> n;
    ans = solve(n);
    cout << ans << "\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        int m = 0;
        for (int i = 0; i < n; i++) {
            int minj = i;
            for (int j = i; j < n; j++) {
                if (a[j] < a[minj]) minj = j;
            }
            if (i != minj) m++;
            int tmp = a[i];
            a[i] = a[minj];
            a[minj] = tmp;
        }

        for (int i = 0; i < n-1; i++) {
            System.out.printf("%d ", a[i]);
        }
        System.out.println(a[n-1]);
        System.out.println(m);
        scanner.close();
    }
}



Measured memory_bytes: 26500
#include <cstdio>
#include <cctype>
#include <array>
#include <set>
#include <queue>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int n = 0, c = gcu();
	// bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	return n; }
	// return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
//template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

struct board {
	enum {size = 3};
	struct pos {int r, c;};
	typedef array<array<int, size>, size> arr;
	arr b;
	pos p;
	int max;
	int cnt = 0;

	int f(arr &a) {
		int l = 0;
		for (int i = 0; i < size; i++)
			for (int j = 0; j < size; j++) {
				int c = a[i][j];
				if (c == 0)
					c = size * size - 1;
				else
					c--;
				l += abs(i - c / 3) + abs(j - c % 3);
			}
		return l;
	}

	void read() {
		for (int i = 0; i < size; i++)
			for (int j = 0; j < size; j++) {
				b[i][j] = in();
				if (!b[i][j])
					p.r = i, p.c = j;
			}
		max = f(b);
	}
	void print() {
		for (auto &r: b) {
			for (int &c: r)
				out(&c == &r[0]?"":" ", c);
			out('\n');
		}
		out('\n');
	}


	int solver() {
		set<arr> m;
		queue<board> q;
		q.push(*this);
		while (!q.empty()) {
			board a = q.front();
			q.pop();
			//a.print();
			int dis = f(a.b);
			if (dis > max * 2.1 - a.cnt)
				continue;
			//out(dis, "\n");
			auto it = m.find(a.b);
			if (it != m.end())
				continue;
			m.insert(a.b);
			if (!dis)
				return a.cnt;
			pos to[] = {
				a.p.r + 1, a.p.c,
				a.p.r, a.p.c + 1,
				a.p.r - 1, a.p.c,
				a.p.r, a.p.c - 1
			};
			for (pos o: to) {
				if (0 <= o.r && o.r < size && 0 <= o.c && o.c < size) {
					board c = a;
					swap(c.b[a.p.r][a.p.c], c.b[o.r][o.c]);
					c.p = o;
					c.cnt = a.cnt + 1;
					q.push(c);
				}
			}
		}
		return -1;
	}
};

int main() {
	board b;
	b.read();
	out(b.solver(), '\n');
}



Measured memory_bytes: 17644
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a += b;
  c += d;
  if(a == c){
    cout << "Balanced\n";
    return 0;
  }
  if(a < c){
    cout << "Right\n";
    return 0;
  }
  cout << "Left\n";
}
  

Measured memory_bytes: 3604
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]

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

tree = UnionFind(N)

for i in range(M):
    a, b = list(map(int, input().split()))
    tree.union(a-1, b-1)

group_size_max = 0
for j in range(N):
    group_size_max = max(group_size_max, tree.size(j))

print(group_size_max)

Measured memory_bytes: 75240
use proconio::input;

fn main() {
    input! {
        k: usize,
        a: usize,
        b: usize,
    };
    let mut ok = false;
    for i in a..=b {
        if i % k == 0 {
            ok = true;
        }
    }
    let ans = if ok { "OK" } else { "NG" };
    println!("{}", ans);
}


Measured memory_bytes: 2144
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

/*
n
t1 ... tn
m
p1 x1
...
pm xm
 */
int n,m;
int t[101];
int main(){
  int t_sum = 0;
  cin >> n;
  REP(i,n){
    cin >> t[i];
    t_sum += t[i];
  }


  cin >> m;
  REP(j,m){
    int p,x;
    cin >> p>>x;
    cout << t_sum - (t[p-1] - x) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
while true
	data = gets.split
	data[0] = data[0].to_i
	data[2] = data[2].to_i
	if data[1] == '+'
		puts data[0] + data[2]
	elsif data[1] == '-'
		puts data[0] - data[2]
	elsif data[1] == '*'
		puts data[0] * data[2]
	elsif data[1] == '/'
		puts data[0] / data[2]
	else
		break
	end
end

Measured memory_bytes: 8580
//
// Created by 10034 on 2020/7/27.
//

#include <iostream>
using namespace std;
#define int long long
int a[100];
signed main(){
    int n;
    cin>>n;
    int tn=0;
    a[0]=201;
    for(int i=1;i<=n;++i) {
        cin>>a[++tn];
//        if(a[tn-1]==a[tn]) --tn;
    }
    int sum=1000,cnt=0,ans=1000;

    for(int i=1;i<=tn;++i) {
        if (a[i - 1] >= a[i] && a[i] <= a[i + 1]) {
            cnt += sum / a[i];
            sum %= a[i];
        }
        if (a[i - 1] <= a[i] && a[i] >= a[i + 1]) {
            sum += cnt * a[i];
            cnt = 0;
        }
        ans = max(ans, sum);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3200
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program {
    static void Main(string[] args) {
        var N = int.Parse(ReadLine());
        int res = 0;

        for (int i = 0; i < N; i++) {
            int[] inp = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            for (int j = inp[0]; j <= inp[1]; j++) {
                res++;
            }
        }

        WriteLine(res);
    }
}



Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
int n;
int a[200009];
int b[200009];
int c[200009];
int dpa[200009];
int dpb[200009];
int dpc[200009];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> a[i] >> b[i] >> c[i];
    dpa[0] = a[0];
    dpb[0] = b[0];
    dpc[0] = c[0];
    for(int i = 1; i < n; ++i){
        dpa[i] = max(dpb[i-1], dpc[i-1]) + a[i];
        dpb[i] = max(dpa[i-1], dpc[i-1]) + b[i];
        dpc[i] = max(dpb[i-1], dpa[i-1]) + c[i];
    }
    cout << max(dpa[n-1], max(dpb[n-1], dpc[n-1]));
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl
template<typename T>
T ncr(T left, T right) {
	right = min(left - right, right);
	T ans = 1;
	for (T i = 1; i <= right; i++) {
		ans = ans * (left - right + i) / i;
	}
	return ans;
}

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int a, b, t;
	cin >> a >> b >> t;
	cout << b * (t/a) << endl;
	return 0;
}



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

int main(){
  int A,B; cin >>A >>B;
  cout <<(A+B)%24 <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>

using namespace std;


class DICE
{
private:
	void swapMap(string a, string b);
public:
	map<string,int> dice;
	DICE(vector<int> &v);
	~DICE();
	void turnDice(char c);
	void printDice();
};

DICE::DICE(vector<int> &v){
	dice["top"] = v[0];
	dice["front"] = v[1];
	dice["right"] = v[2];
	dice["left"] = v[3];
	dice["back"] = v[4];
	dice["bottom"] = v[5];
}

DICE::~DICE(){
	
}

void DICE::swapMap(string a, string b){
	if(dice.end() == dice.find(a) || dice.end() == dice.find(b)) return;
	int tmp;
	tmp = dice[a];
	dice[a] = dice[b];
	dice[b] = tmp;
}

void DICE::turnDice(char c){
	switch(c){
		case 'N':
			swapMap("top","back");
			swapMap("top","bottom");
			swapMap("top","front");
			break;
		case 'E':
			swapMap("top","right");
			swapMap("top","bottom");
			swapMap("top","left");
			break;
		case 'S':
			swapMap("top","front");
			swapMap("top","bottom");
			swapMap("top","back");
			break;
		case 'W':
			swapMap("top","left");
			swapMap("top","bottom");
			swapMap("top","right");
			break;
		default :
			break;
	}
}

void DICE::printDice(){
	cout << dice["top"] << endl;
}

int main(){
	vector<int> v;
	string cmd;
	for(int i = 0; i < 6; i++){
		int tmp;
		cin >> tmp;
		v.push_back(tmp);
	}
	cin >> cmd;

	DICE data(v);
	for(int i = 0; i < cmd.size(); i++)
		data.turnDice(cmd[i]);
	data.printDice();
}

Measured memory_bytes: 1252
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			String st=in.next();
			if(st.equals("0"))
				return;
			LinkedList<String> que=new LinkedList<String>();
			HashMap<String, Integer> map=new HashMap<String, Integer>();
			int ans=0;
			int flag=0;
			char ch[]=new char[10];
			char ch2[]=new char[10];
			que.add(st);
			while(!que.isEmpty())
			{
				int size=que.size();
				for(int i=0;i<size;i++)
				{
					ch=que.poll().toCharArray();
					for(int j=0;j<ch.length-1;j++)//全ての色が同じかチェック
					{
						if(ch[j]==ch[j+1])
							flag=1;
						else
						{
							flag=0;
							break;
						}
					}
					if(flag==1)
						break;
					for(int j=0;j<ch.length-1;j++)
					{
						for(int k=0;k<ch.length;k++)
							ch2[k]=ch[k];
						if(ch[j]!=ch[j+1])
						{
							String tmp="";
							if(ch2[j]!='r'&&ch2[j+1]!='r')
								ch2[j]=ch2[j+1]='r';
							else if(ch2[j]!='g'&&ch2[j+1]!='g')
								ch2[j]=ch2[j+1]='g';
							else if(ch2[j]!='b'&&ch2[j+1]!='b')
								ch2[j]=ch2[j+1]='b';
							for(int k=0;k<ch.length;k++)
								tmp+=ch2[k];
							if(map.get(tmp)==null)
								que.add(tmp);
							map.put(tmp, 1);
						}
					}
				}
				if(flag==1)
					break;
				ans++;
			}
			System.out.println(flag==1 ? ans:"NA");
		}
	}
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n), id(n);
  rep(i, n) {
    cin >> A[i];
    id[i] = i;
  }
  sort(all(id), [&](int i, int j) {
    return A[i] < A[j];
  });
  int cnt = 0;
  rep(i, n) {
    if(i%2==0 && id[i]%2==1) cnt++;
  }
  cout << cnt << endk;
  return 0;
}


Measured memory_bytes: 4776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read(){
    ll x = 0,f = 1;char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
    return x*f;
}
void write(int x){
    if(x > 9) write(x/10);
    putchar('0'+x%10);
}
void wri(int x){
    write(x); putchar(' ');
}

const int N = 500005;
int n,k;
int a[N],b[N];
int Mi[N<<2];
int head[N],nxt[N*2],to[N*2],cnt;
int ru[N],m;

inline void insert(int x,int y){
	to[++cnt] = y; nxt[cnt] = head[x]; head[x] = cnt;
}

int query(int num,int l,int r,int x,int y){
	if(x <= l && r <= y) return Mi[num];
	int mid = (l+r)>>1,ans = 1e9;
	if(x <= mid) ans = query(num<<1,l,mid,x,y);
	if(y > mid) ans = min(ans,query(num<<1|1,mid+1,r,x,y));
	return ans;
}

void change(int num,int l,int r,int x,int y){
	Mi[num] = min(Mi[num],y);
	if(l == r) return;
	int mid = (l+r)>>1;
	if(x <= mid) change(num<<1,l,mid,x,y);
	else change(num<<1|1,mid+1,r,x,y);
}

void toposort(){
	priority_queue<int,vector<int>,greater<int> > Q;
	for(int i = 1;i <= n;++i)
		if(ru[i] == 0) Q.push(i);
	while(!Q.empty()){
		int x = Q.top(); Q.pop();
		b[x] = ++m;
		for(int i = head[x];i;i = nxt[i]){
			--ru[to[i]];
			if(ru[to[i]] == 0) Q.push(to[i]);
		}
	}
}

signed main(){
	n = read(); k = read();
	for(int i = 1;i <= n;++i){ int x = read(); a[x] = i; }
	memset(Mi,0x3f,sizeof Mi);
	for(int i = n;i >= 1;--i){
		int x;
		if(a[i] < n){
			x = query(1,1,n,a[i]+1,min(a[i]+k-1,n));
			if(x >= 1 && x <= n) insert(a[i],a[x]),++ru[a[x]];
		}
		if(a[i] > 1){
			x = query(1,1,n,max(a[i]-k+1,1),a[i]-1);
			if(x >= 1 && x <= n) insert(a[i],a[x]),++ru[a[x]];
		}
		change(1,1,n,a[i],i);
	}
	toposort();
	for(int i = 1;i <= n;++i) write(b[i]),puts("");
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll x1, x2, y1, y2, x3, x4, y3, y4;
  cin >> x1 >> y1 >> x2 >> y2;
  ll a, b;
  a = x2 - x1, b = y2 - y1;
  //if(a > 0 && b > 0) {
    x3 = x2 - b, y3 = y2 + a;
    x4 = x3 - a, y4 = y3 - b;
 // } else if(a < 0 && b < 0) {

  //}
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>  
    #include <string.h>  
    #include <queue>  
    #include <iostream>  
    #include <algorithm>  
    using namespace std;  
    const int maxn=10050;  
    const int maxe=2005000;  
    const int INF=1e9;  
    struct note  
    {  
        int to;  
        int w;  
        int c;  
        int next;  
    };  
    note edge[maxe];  
    int head[maxn];  
    int ip;  
    void init()  
    {  
        memset(head,-1,sizeof(head));  
        ip=0;  
    }  
    void addedge(int u,int v,int w,int c)  
    {  
        edge[ip].to=v;  
        edge[ip].c=c;  
        edge[ip].w=w;  
        edge[ip].next=head[u];  
        head[u]=ip++;  
    }  
    int cost[maxn];  
    int dis[maxn];  
    bool vis[maxn];  
    queue<int>q;  
    void spfa(int s,int n)  
    {  
        while(!q.empty())q.pop();  
        for(int i=1;i<=n;i++)  
            cost[i]=dis[i]=INF;  
        memset(vis,false,sizeof(vis));  
        dis[s]=0;  
        cost[s]=0;  
        vis[s]=true;  
        q.push(s);  
        while(!q.empty())  
        {  
            int u=q.front();  
            q.pop();  
            vis[u]=false;  
            for(int i=head[u];i!=-1;i=edge[i].next)  
            {  
                int to=edge[i].to;  
                int val=edge[i].w;  
                if(dis[to]>dis[u]+val||(dis[to]==dis[u]+val&&cost[to]>edge[i].c))//有多条最短路时，取花费最小的  
                {  
                    dis[to]=dis[u]+val;  
                    cost[to]=edge[i].c;  
                    if(!vis[to])  
                    {  
                        q.push(to);  
                        vis[to]=true;  
                    }  
                }  
            }  
        }  
    }  
    int main()  
    {  
       // freopen("cin.txt","r",stdin);  
        int n,m;  
        int u,v,w,c;  
        while(~scanf("%d%d",&n,&m))  
        {  
            if(n==0&&m==0) break;  
            init();  
            for(int i=0;i<m;i++)  
            {  
                scanf("%d%d%d%d",&u,&v,&c,&w);  
                addedge(u,v,c,w);  
                addedge(v,u,c,w);  
            }  
            spfa(1,n);  
            int ans=0;  
            for(int i=1;i<=n;i++)  
                ans+=cost[i];  
            printf("%d\n",ans);  
        }  
        return 0;  
    }  


Measured memory_bytes: 4044
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll a;
    set<ll>chk;
    for(ll i=0;i<3;i++){
        cin>>a;
        chk.in(a);
    }
    if(chk.size()==2){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 764
S = input()
if 'W' not in S:
    print(0)
elif 'B' not in S:
    print(0)
else:
    if S[0] == 'B':
        count = S.count('BW')
        if S[-1] == 'B':
            print(count*2)
        else:
            print(count*2 - 1)
    else:
        count = S.count('WB')
        if S[-1] == 'W':
            print(count*2)
        else:
            print(count*2 - 1)

Measured memory_bytes: 3188
var lines = []; var div = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var div_t = Array(N).fill(0)

    // [約数, 個数]の二次元配列を作成
    for (var i = 2; i <= N; i++) {
        var t = calc(i);
        for (var value of t) {
            div_t[value[0]] += value[1];
        }
    }
    div = [];
    for (var i = 0; i < N; i++) {
        if (div_t[i] !== 0) { div.push([i + 1, div_t[i]]) }
    }

    // 結果を表示
    console.log(dfs(div.concat(), 0, 75));

});

// 75数を全パターン深さ優先探索
function dfs(p, index, mul) {

    if (p[index] === div[div.length - 1]) {
        if (mul === 1) { return (1); }
        else { return (0) }
    }

    var res = 0;
    for (var i = 0; i < p[index][1] + 1; i++) {
        if (mul % (i + 1) === 0) {
            res += dfs(p.concat(), index + 1, mul / (i + 1));
        }
    }
    return (res);
}

function calc(n) {
    var arr = []

    // 約数を検索
    for (var i = 2; i * i <= n; i++) {
        if (n % i !== 0) { continue }

        var cnt = 0;
        while (n % i === 0) { cnt++; n /= i; }

        arr.push([i, cnt])
    }

    if (n !== 1) { arr.push([n, 1]) }
    return (arr);
}

Measured memory_bytes: 9548
/*
______________________________
                              |
Shubham Singhal               |
                              |
CodeChef          torque      |
HackerEarth       torque      |
SPOJ              torque      |
HackerRank        torquecode  |
CodeForces        torquecode  |
AtCoder           torque            |
______________________________| */


// If Tyrion dies, I am gonna riot :P


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

# define MOD         1000000007
# define gc          getchar
# define LL          long long
# define L           long
# define pb          push_back
# define mp          make_pair
# define vi          vector<int>
# define MAXN        100005
# define INF         1e9



int main()
{

    int n,l;
    cin>>n>>l;
    vector<string> v;
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        v.pb(s);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
        cout<<v[i];
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
N, D = map(int, input().split())
xy = []
for i in range(N):
    xy.append(list(map(int, input().split())))

# print(xy)
ans = 0

for i in range(N):
    x = xy[i][0]
    y = xy[i][1]
    if (x**2 + y**2) ** 0.5 <= D:
        ans += 1

print(ans)

Measured memory_bytes: 102996
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,ans=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    ans+=b-a+1;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());

            if (X == 7 || X == 5 || X == 3)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 11092
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<typeinfo>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





    
int main(){
    stack<ll> S;
    string s;
    while(cin>>s){
        if(s=="+"){
            ll a=S.top(); S.pop();
            ll b=S.top(); S.pop();
            S.push(a+b);
        }
        else if(s=="-"){
            ll a=S.top(); S.pop();
            ll b=S.top(); S.pop();
            S.push(b-a);
        }
        else if(s=="*"){
            ll a=S.top(); S.pop();
            ll b=S.top(); S.pop();
            S.push(a*b);
        }
        else{
            ll a=atoi(s.c_str());
            S.push(a);
        }
    }
    cout<<(ll)S.top()<<endl;
    
    
    return 0;
}



Measured memory_bytes: 3220
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

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;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];

int main(){
    int n;
    cin>>n;
    double x=(n%2)?((double)(n+1)/2)/n:(double)n/2/n;
    printf("%.10lf\n",x);
    return 0; 
}




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

int main() {
  int64_t n, m;
  std::cin >> n >> m;

  std::multiset<int64_t> p;

  for (int64_t i = 2; i <= static_cast<int64_t>(std::sqrt(m)); i++) {
    if (m < i) {
      break;
    }

    while (m % i == 0) {
      p.insert(i);
      m /= i;
    }
  }

  if (m != 1) {
    p.insert(m);
  }

  std::map<int64_t, int64_t> t;
  int64_t count = 1;

  while (!p.empty()) {
    const auto p1 = *p.cbegin();
    const auto c = p.count(p1) + 1;
    p.erase(p1);

    if (t.find(c) != t.end()) {
      count *= t[c];
      count %= 1000000007;
    } else {
      std::vector<int64_t> po(c, 1);
      for (int64_t i = 0; i < n - 1; i++) {
        for (int j = c - 1; 0 <= j; j--) {
          for (int k = j - 1; 0 <= k; k--) {
            po[j] += po[k];
            po[j] %= 1000000007;
          }
        }
      }
      t[c] = po[c - 1] % 1000000007;
      count *= po[c - 1] % 1000000007;
      count %= 1000000007;
    }
  }

  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> A(H);
	for(int i=0; i<H; i++) cin >> A[i];

	int sx, sy;
	for(int i=0; i<H; i++) for(int j=0; j<W; j++){
		if(A[i][j]=='S'){
			sx = i;
			sy = j;
		}
	}

	vector<vector<int>> dist(H, vector<int>(W, 1e9));
	queue<pair<pair<int, int>, int>> que;
	que.push({{sx, sy}, 0});
	int mdiff = 1e9;
	while(!que.empty()){
		int x = que.front().first.first;
		int y = que.front().first.second;
		int d = que.front().second;
		que.pop();
		if(d>K) continue;
		if(dist[x][y]<=d) continue;
		dist[x][y] = d;
		debug(any{x, y, d});

		mdiff = min(mdiff, min(min(x, y), min(H-x-1, W-y-1)));
		int dx[] = {1, -1, 0, 0};
		int dy[] = {0, 0, 1, -1};
		for(int n=0; n<4; n++){
			int nx = x+dx[n];
			int ny = y+dy[n];
			if(nx<0||H<=nx||ny<0||W<=ny) continue;
			if(A[nx][ny]!='.') continue;
			que.push({{nx, ny}, d+1});
		}
	}

	cout << 1+(mdiff+K-1)/K << endl;

	return 0;
}


Measured memory_bytes: 3712
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <cstdio> 
#include <iostream> 
#include <cmath> 
#include <string> 
#include <list> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <utility> 
#include <set> 
#include <map> 
#include <complex> 
#include <queue> 
#include <stack> 
#include <cstdlib> 
#include <ctime> 
#include <cstring> 
#include <string.h> 
#include <unordered_set>
#include <unordered_map>
#include <cassert>

using namespace std; 

typedef unsigned int uint; 
typedef long long int64; 
typedef unsigned long long uint64; 
typedef unsigned short ushort; 
typedef unsigned char uchar; 
typedef pair<int,int> ipair; 
typedef vector<int> VI; 
typedef vector<string> VS; 
typedef vector<double> VD; 
#define SIZE(A) ((int)(A.size()))
#define LENGTH(A) ((int)(A.length()))
#define MP(A,B) make_pair(A,B)
const double pi=acos(-1.0); 
const double eps=1e-11; 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(a) (a).begin(),(a).end()

template<class T> T sqr(const T &x) { return x*x; } 
template<class T> T lowbit(const T &x) { return (x^(x-1))&x; } 
template<class T> int countbit(const T &n) { return (n==0)?0:(1+countbit(n&(n-1))); } 
template<class T> void ckmin(T &a,const T &b) { if (b<a) a=b; } 
template<class T> void ckmax(T &a,const T &b) { if (b>a) a=b; } 

const int maxn=256;
const int MOD=998244353;

inline int multiply(int a,int b)
{
	return ((int64)a*(int64)b)%MOD;
}
inline void addto(int &a,int b)
{
	a+=b;
	if (a>=MOD) a-=MOD;
}
inline void delto(int &a,int b)
{
	a-=b;
	if (a<0) a+=MOD;
}

int n;
int x[maxn],y[maxn];
int c[maxn][maxn][maxn];
int s[maxn][maxn][maxn];
int l[maxn][maxn];
int f[maxn][maxn];
int p2[maxn];

bool is_middle(int a,int b,int c)
{
	return a==b || c==b || (a<b)!=(c<b);
}
int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	std::ios_base::sync_with_stdio(false);
	cin>>n;
	REP(i,n) cin>>x[i]>>y[i];
	REP(i,n) REP(j,n) REP(k,n)
	{
		int t=(x[j]-x[i])*(y[k]-y[i])-(x[k]-x[i])*(y[j]-y[i]);
		c[i][j][k]=((t==0)?0:(t<0?-1:1));
	}
	REP(i,n+1) p2[i]=(i==0?1:multiply(p2[i-1],2));
	memset(l,0,sizeof(l));
	REP(i,n) REP(j,n)
	{
		int w=0;
		REP(p,n) if (c[i][j][p]==0 && is_middle(x[i],x[p],x[j]) && is_middle(y[i],y[p],y[j])) ++w;
		l[i][j]=w-2;
	}
	memset(s,0,sizeof(s));
	REP(i,n) REP(j,n) REP(k,n) if (c[i][j][k]>0)
	{
		if (j<i) { s[i][j][k]=s[j][k][i]; continue; }
		if (k<i) { s[i][j][k]=s[k][i][j]; continue; }
		int w=0;
		REP(p,n) if (c[i][j][p]>=0 && c[j][k][p]>=0 && c[k][i][p]>=0) ++w;
		s[i][j][k]=w-3;
	}
	int ret=0;
	REP(key,n)
	{
		int size=0,p[maxn];
		REP(i,n) if (x[i]>x[key] || x[i]==x[key] && y[i]>y[key]) p[size++]=i;
		sort(p,p+size,[&](int a,int b) { return c[key][a][b]>0; });
		memset(f,0,sizeof(f));
		REP(s1,size) FOR(s2,s1+1,size) if (c[key][p[s1]][p[s2]]>0)
		{
			int e=s[key][p[s1]][p[s2]];
			f[s1][s2]=p2[e];
			REP(s0,s1) if (c[key][p[s0]][p[s1]]>0 && c[p[s0]][p[s1]][p[s2]]>0) 
				addto(f[s1][s2],multiply(f[s0][s1],p2[e-l[key][p[s1]]]));
			addto(ret,f[s1][s2]);
		}
	}
	printf("%d\n",ret);
	return 0;
}

Measured memory_bytes: 119040
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
        if (a[i] >= a[i - 1] && a[i] <= a[i + 1]) {
            ans++;
        } else if (a[i - 1] >= a[i] && a[i] >= a[i + 1]) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<"Case "<<x<<": "
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	ll n;
	cin>>n;
	ll a[n+5],b[n+5];
	rep(i,n)cin>>a[i],b[i]=a[i];
	sort(a,a+n);
	ll maxi=a[n-1];
	ll secmaxi=a[n-2];
	rep(i,n)
	{
		if(b[i]!=maxi)
			cout<<maxi<<endl;
		else 
			cout<<secmaxi<<endl;
	}
	return 0;
}


Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {
  static Scanner in = new Scanner(System.in);
  public static void main(String[] args) {
    int n = in.nextInt();
    long ans = 0;
    for (long i = 1; i <= n; i++) {
      for (long j = 1; j * i < n; j++) {
        ans++;
      }
    }
    System.out.println(ans);

  }
}


Measured memory_bytes: 35648
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

typedef long long ll;
typedef pair<ll, ll> P;

bool check(vector<int>& pat, vector<vector<int>> vv)
{
  for (int i = 0; i < 3; i++) {
    bool flag = true;
    for (auto to : vv[pat[i]]) {
      if (to == pat[i + 1]) {
        flag = false;
        break;
      }
    }
    if (flag) return false;
  }
  return true;
}

int main()
{
  vector<vector<int>> vv(4);
  for (int i = 0; i < 3; i++) {
    int a, b; cin >> a >> b;
    a--, b--;
    vv[a].PB(b);
    vv[b].PB(a);
  }

  vector<int> pat = {0, 1, 2, 3};
  do {
    if (check(pat, vv)) {
      cout << "YES" << endl;
      return 0;
    }
  } while (next_permutation(ALL(pat)));

  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long int i,n,count;
    scanf("%lld",&n);
    count=0;
    for(i=1;i<=n;i++)
    {
            count=count+i;
        
if(i%3==0||i%5==0)
            count=count-i;
    }
    printf("%lld\n",count);
}

Measured memory_bytes: 1728
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12
//priority_queue<int,vector<int>, greater<int> > q2;



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

	/*
	double A, B;
	cin >> A >> B;
	B += eps;
	int C = A * B;
	cout << C << endl;
	*/
	int A;
	string S;
	cin >> A >> S;

	int ans = A * (S[0] - '0');
	int tmp = A * (S[2] - '0') * 10;
	tmp += A * (S[3] - '0');
	ans += tmp / 100;


	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3596
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
typedef pair<pii,int>piii;
int main(){
    int n,m;
    while(cin>>n>>m,n+m){
        vvi hoge(n+1,vi(n+1,INF));
        //edge[index]=(distance,next_vertex)
        vector<vector<pii>>edge(n,vector<pii>());
        vector<vector<pii>>temp(n,vector<pii>());
        rep(i,m){
            int a,b,c; cin>>a>>b>>c;
            --a,--b;
            edge[a].push_back(pii(b,c));
            edge[b].push_back(pii(a,c));
        }
        vvi d(3,vi(n,INF));
        d[0][0]=0;
        priority_queue<piii,vector<piii>,greater<piii>>que;
        que.push(piii(pii(0,0),0));
        
        while(!que.empty()){
            piii now=que.top();que.pop();
         //   cout<<now.first.first<<" "<<now.first.second<<" "<<now.second<<endl;
            for(int i=0; i<edge[now.second].size();i++){
                pii next=edge[now.second][i];
                if(now.first.second==0){
                    if(now.first.second==0&&d[0][next.first]>d[0][now.second]+next.second){
                        que.push(piii(pii(d[0][now.second]+next.second,0),next.first));
                        d[0][next.first]=d[0][now.second]+next.second;
                    }
                    if(now.first.second==0){
                        d[1][next.first]=d[0][now.second];
                        que.push(piii(pii(now.first.first,1),next.first));
                    }
                }else if(now.first.second==1){
                    if(d[2][next.first]>d[1][now.second]){
                        que.push(piii(pii(d[1][now.second],2),next.first));
                        d[2][next.first]=d[1][now.second];
                    }
                }else if(now.first.second==2&&d[2][next.first]>d[2][now.second]+next.second){
                    d[2][next.first]=d[2][now.second]+next.second;
                    que.push(piii(pii(now.first.first+next.second,2),next.first));
                }
            }
        }
        cout<<min(d[0][n-1],d[2][n-1])<<endl;
    }
}

Measured memory_bytes: 3168