akhauriyash/Code-Regression huggingface dataset:
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] d = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
		int n = sc.nextInt();
		sc.nextLine();
		char[] s = sc.nextLine().toCharArray();
		int[] dp1 = new int[10];
		int[][] dp2 = new int[10][10];

		Set<String> counted = new HashSet<>();
		long answer = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					String t = String.valueOf(d[j]) + d[k] + s[i];
					if (dp2[j][k] > 0 && !counted.contains(t)) {
						counted.add(t);
						answer++;
					}
				}
			}
			for (int j = 0; j < 10; j++) {
				if (dp1[d[j] - '0'] > 0) {
					dp2[j][s[i] - '0']++;
				}
			}

			dp1[s[i] - '0']++;
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 151032
#!/usr/bin/python3

import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys


def main():
    while True:
        N, M, T, P = read_ints()
        if (N, M, T, P) == (0, 0, 0, 0):
            break
        F = [read_ints() for _ in range(T)]
        H = [read_ints() for _ in range(P)]
        print(*solve(N, M, T, P, F, H), sep='\n')


def solve(N, M, T, P, F, H):
    w = N
    h = M
    paper = [[1] * w for _ in range(h)]

    for d, c in F:
        if d == 1:
            w1 = max(c, w - c)
            npaper = [[0] * w1 for _ in range(h)]
            for y in range(h):
                for dx in range(c):
                    npaper[y][c - 1 - dx] += paper[y][dx]
                for dx in range(c, w):
                    npaper[y][dx - c] += paper[y][dx]
            w = w1
            paper = npaper
            continue

        h1 = max(c, h - c)
        npaper = [[0] * w for _ in range(h1)]
        for x in range(w):
            for dy in range(c):
                npaper[c - 1 - dy][x] += paper[dy][x]
            for dy in range(c, h):
                npaper[dy - c][x] += paper[dy][x]
        h = h1
        paper = npaper

    return [paper[y][x] for x, y in H]


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7088
($d,$G)=glob<>;$\=1e3;
for(<>){
	/ /;$i+=100;
	for$k(sort{1}1..1000){
		for(1..$`){
			last if$_>$k;
			$p[$k]+=$-=$p[$k-$_]+$i*$_+($_==$`&&$')-$p[$k];
			$\-=$-=$\-$k if$p[$k]>=$G;
		}
	}
}
print

Measured memory_bytes: 896
import sys


def main():
    ticket = list(input())

    op = [""] * 3

    for i in range(2):
        if i == 0:
            op[0] = "+"
        else:
            op[0] = "-"
        for j in range(2):
            if j == 0:
                op[1] = "+"
            else:
                op[1] = "-"
            for k in range(2):
                if k == 0:
                    op[2] = "+"
                else:
                    op[2] = "-"

                eq = ""
                for n in range(3):
                    eq += ticket[n] + op[n]
                eq += ticket[-1]

                if eval(eq) == 7:
                    print(eq + "=7")
                    sys.exit()


main()


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

int main () {
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  
  for (int i = 0; i < H; i++) {
    string a;
    cin >> a;
    A.at(i) = a;
  }
  string up;
  up = "##";
  for (int i = 0; i < W; i++) {
    up += "#";
  }
  cout << up << endl;
  for (int i = 0; i < H; i++) {
    cout << "#" << A.at(i) << "#" <<endl;
  }
  cout << up << endl;
}

Measured memory_bytes: 256
N, M = [int(x) for x in input().split(" ")]
L, R = [], []

for i in range(M):
    l, r = [int(x) for x in input().split(" ")]
    L.append(l - 1)
    R.append(r - 1)

L_max = max(L)
R_min = min(R)

count = R_min - L_max + 1 if R_min - L_max >= 0 else 0
print(count)


Measured memory_bytes: 11020
#include <iostream>
#include <vector>
#include <string>
#include <cstring>

using namespace std;

int main(){
	int n;
	int in[1000], out[1000], sum[1000];
	while(cin >> n, n){
		string day, time; char e; int p;
		memset(in,  0, sizeof(in));
		memset(out, 0, sizeof(out));
		memset(sum, 0, sizeof(sum));
		string prevDay = "";
		for(int i=0;i<n;i++){
			cin >> day >> time >> e >> p;
			if(day != prevDay){
				memset(in,  0, sizeof(in));
				memset(out, 0, sizeof(out));
				prevDay = day;
			}
			int h, m;
			sscanf(time.c_str(), "%02d:%02d", &h, &m);
			int t = h*60+m;
			if(e == 'I'){
				in[p] = t;
				out[p] = 1000000;
			} else {
				if(p==0){
					out[0] = t;
					for(int i=1;i<1000;i++){
						if(out[i]==1000000){
							sum[i] += max(0, out[0] - max(in[i], in[0]));
							in[i] = t;
						}
					}
				} else {
					out[p] = t;
					sum[p] += max(0, min(out[p], out[0]) - max(in[p], in[0]));
				}
			}
		}
		int res = 0;
		for(int i=1;i<1000;i++) res = max(res, sum[i]);
		cout << res << endl;
	}
}

Measured memory_bytes: 988
while True:
    (H, W) = [int(i) for i in input().split()]
    if H == W == 0:
        break
    for a in range(H):
        for b in range(W):
            if (a + b) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
        print('')
    print('')

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

int main() {
  int n, m;
  cin >> n >> m;
  int a[m] = {0}, b[m] = {0};
  int i;
  for (i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  vector<int> res(m);
  for (i = 0; i < m; i++) {
    res[i] = (a[i] >= n ? 0 : n - a[i]);
  }
  sort(res.begin(), res.end());
  int cost = 0;
  for (i = 0; i < m - 1; i++) {
    cost += res[i];
  }
  cout << cost << endl;
  return 0;
}



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

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemB solver = new ProblemB();
		solver.solve(1, in, out);
		
		out.close();
	}
	
	static class ProblemB
	{
		void solve(int TestCase, InputReader in, PrintWriter out)
		{
			String s = in.next();
			int res = 0;
			String prev = "";
			for(int i = 0; i < s.length(); )
			{
				int len = 1;
				if(s.substring(i, i + len).equals(prev))
					len++;
				if(i + len > s.length())
					break;
				
				prev = s.substring(i, i + len);
				i += len;
				res++;
			}
			
			out.println(res);
		}
	}
	
	static class InputReader
	{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		
		public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		public long nextLong()
		{
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 37972
# -*- coding: utf-8 -*-

A = []
A += list(map(int, input().split()))
A += list(map(int, input().split()))
A += list(map(int, input().split()))

N = int(input())

for i in range(N):
    value = int(input())
    for j in range(len(A)):
        if value == A[j]:
            A[j] = 101
            break

msg = "No"
if (A[0] == 101 and A[1] == 101 and A[2] == 101):
    msg = "Yes"
elif (A[3] == 101 and A[4] == 101 and A[5] == 101):
    msg = "Yes"
elif (A[6] == 101 and A[7] == 101 and A[8] == 101):
    msg = "Yes"
elif (A[0] == 101 and A[3] == 101 and A[6] == 101):
    msg = "Yes"
elif (A[1] == 101 and A[4] == 101 and A[7] == 101):
    msg = "Yes"
elif (A[2] == 101 and A[5] == 101 and A[8] == 101):
    msg = "Yes"
elif (A[0] == 101 and A[4] == 101 and A[8] == 101):
    msg = "Yes"
elif (A[2] == 101 and A[4] == 101 and A[6] == 101):
    msg = "Yes"
print(msg)

Measured memory_bytes: 3064
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

bool check(vector<int> &lis, int k) {
    int n = lis.size();
    int accum = accumulate(lis.begin(), lis.end(), 0);
    int diff = accum - k;
    if (diff == 0)
        return true;
    if (diff < 0 || diff % 2)
        return false;
    

    // target: diff / 2

    vector<bool> dp(8001, false);
    dp[0] = true;
    for (int i = 1; i <= n; i++) {
        for (int j = 8000; j >= 0; j--) {
            if (j - lis[i - 1] >= 0)
                dp[j] = dp[j] | dp[j - lis[i - 1]];
        }
    }

    return dp[diff / 2];

}


int main() {
    string s;
    cin >> s;
    int n = s.size();
    int x, y;
    cin >> x >> y;

    vector<int> xlist, ylist;
    bool nowx = true;
    int nowseg = 0;
    int iii = 0;
    while (iii < n && s[iii] == 'F') {
        iii++;
        x--;
    }
    for(;iii<n;iii++){
        char c = s[iii];
        if (c == 'T') {
            if (nowseg > 0) {
                if (nowx)
                    xlist.push_back(nowseg);
                else
                    ylist.push_back(nowseg);
            }
            nowseg = 0;
            nowx = !nowx;
        }
        else {
            nowseg++;
        }
    }
    if (nowseg > 0) {
        if (nowx)
            xlist.push_back(nowseg);
        else
            ylist.push_back(nowseg);
    }

    bool xok = check(xlist, x);
    bool yok = check(ylist, y);

    cout << (xok && yok ? "Yes" : "No") << endl;




    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c;cin>>a>>b>>c;
  if(a%2==0||b%2==0||c%2==0) cout << 0 << endl;
  else cout << min(a*b,min(b*c,c*a)) << endl;
  return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <math.h>

int hantei(int x){
  int i;

  if(x==2) return 1;

  else if(x<2) return 0;

  if(x%2==0) return 0;


  for(i=3; i<=sqrt(x); i+=2){
    if(x%i==0) return 0;
    }

  return 1;
}

int main(){

  int n,x,i,cnt=0;

    scanf("%d",&n);


  for(i=1; i<=n; i++){
     scanf("%d",&x);
     if(hantei(x)) cnt++;
  }

  printf("%d\n",cnt);

  return 0;
}




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

int main() {

	int k; cin >> k;
	string s; cin >> s;
	string ans;

	if (s.size() <= k) {
		cout << s << endl;
		return 0;
	}
	else {
		ans = s.substr(0, k);
		ans += "...";
		cout << ans << endl;
		return 0;
	}


	return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

int main () {
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];

    ll ans = 0;
    int mod = 1000000007;
    rep(i, 60) {
        ll b = 1ll << i;
        int z = 0;
        rep(j, N) {
            if ((A[j] & b) == 0) {
                z++;
            }
        }
        ans = (ans + b % mod * z % mod * (N - z) % mod) % mod;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5980
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let n=nin()
  out(n*(n+1)/2)
}
main()

Measured memory_bytes: 7372
#include<stdio.h>

int main()
{
  
  int i,minj,j,tmp,count=0,N;
  int A[100];

  scanf("%d",&N);
  
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  
 
  for(i=0;i<=N-1;i++){
    minj = i;
    for(j=i;j<=N-1;j++){
      if(A[j]<A[minj])minj = j;
    }
    if(i!=minj){
      tmp = A[i];
      A[i] = A[minj];
      A[minj] = tmp;
      count++;    
    }
  }

  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i != N-1) printf(" ");   
  }  
  printf("\n");
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 604
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    readStringList().distinct().size.let {
        if (it == 3) {
            "Three"
        } else {
            "Four"
        }
    }.let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 36008
#include <stdio.h>
int main(){
    int H,W,i,j;
    
    while(scanf("%d%d",&H,&W),H|W){    
        for(i=0;i<H;i++){
            for(j=0;j<W;j++) printf("%c",(i+j)%2?'.':'#');
            printf("\n");    
        }
    printf("\n");       
    }
    return 0;
}

Measured memory_bytes: 2588
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007



typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L;
ll A[300005] = {};
ll B[300005] = {};
ll C[300005] = {};
bool f, ff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;


struct ST
{
	int kaisuu;
	int dan;
	int score;
	char situ[52][2][2];
	

	bool operator<(const ST& another) const
	{
		return dan < another.dan;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


ll minn, maxx;
double ansa;

string SS;
char ca;

ll huka, owari,kaisuu;

double kakuritu,ab,ac,ad;


int main() {

	cin >> N;

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

	sort(vll.begin(), vll.end());
	
	a = 0;
	b = 0;
	for (int i = 0; i < 200000; i++) {
		a += B[i];

		if (a == N / 2) {
			b++;
		}
	}
	
	cout << b << endl;
	//cout << fixed << setprecision(10) << ansa << endl;
	return 0;

}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;
  sort(all(s));
  s.erase(unique(all(s)), s.end());
  if (s.size() == 26)
    cout << "None";
  else {
    int i = 0, j = 0;
    while (j < s.size()) {
      if (s[j++] != ('a' + i))
        break;
      i++;
    }
    cout<<char('a'+i);
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%mood;
		x = x * x%mood;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n;
int p[100010];
int a[100010];
set<int> st;
int b, c, d, e;
int ans;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		a[p[i]] = i;
	}
	st.insert(-1);
	st.insert(n);
	for (int i = n; i >= 1; i--) {
		if (*st.upper_bound(a[i]) == n) {
			d = n;
			e = n;
		}
		else {
			d = *st.upper_bound(a[i]);
			e = *st.upper_bound(d);
		}
		if (*(--st.upper_bound(a[i])) == -1) {
			b = -1;
			c = -1;
		}
		else {
			c = *(--st.upper_bound(a[i]));
			b = *(--st.lower_bound(c));
		}
		ans += i * ((e - d)*(a[i] - c) + (d - a[i])*(c - b));
		st.insert(a[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  string S;
  int N;
  std::cin >> S;
  N = S.size();
  std::vector<char> kuro(N);
  std::vector<char> siro(N);
  range(i, N){
    if(i%2==0){
      kuro[i] = '0';
      siro[i] = '1';
    }else{
      kuro[i] = '1';
      siro[i] = '0';
    }
  }
  int kcount=0, scount=0;
  range(i, N){
    if(S[i] == kuro[i]){
      kcount++;
    }
    if(S[i] == siro[i]){
      scount++;
    }
  }
  std::cout << min(scount, kcount) << '\n';
  return 0;
}


Measured memory_bytes: 888
from collections import Counter
class UnionFind:
    def __init__(self,N):
        self.par=[i for i in range(N)]
        self.siz=[1 for _ in range(N)]
        self.rank=[0 for _ in range(N)]
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def union(self,a,b):
        a=self.find(a)
        b=self.find(b)
        if a==b:
            return 0
        else:
            if self.rank[a]>self.rank[b]:
                self.par[b]=a
                self.siz[a]+=self.siz[b]
            else:
                self.par[a]=b
                self.siz[b]+=self.siz[a]
                if self.rank[a]==self.rank[b]:
                    self.rank[b]+=1
    def size(self,a):
        return self.siz[self.find(a)]
    def same(self,a,b):
        return self.find(a)==self.find(b)

N,K,L=map(int,input().split())
road=UnionFind(N)
train=UnionFind(N)

for i in range(K):
    p,q=map(lambda x:int(x)-1,input().split())
    road.union(p,q)
for i in range(L):
    r,s=map(lambda x:int(x)-1,input().split())
    train.union(r,s)
li=[(road.find(i),train.find(i)) for i in range(N)]
c=Counter(li)
ans=[c[li[i]] for i in range(N)]
print(*ans)

Measured memory_bytes: 156652
N, T = map(int,input().split())
A = list(map(int,input().split()))
MIN = A[0]
ans = 0
diff = 0
for i in range(1, N):
    if MIN > A[i]:
        MIN = A[i]
    elif A[i] - MIN > diff:
        ans = 1
        diff = A[i] - MIN
    elif A[i] - MIN == diff:
        ans += 1

print(ans)

Measured memory_bytes: 15060
#include<iostream>
using namespace std;
int main()
{
	int n, a, b,sum;
	while (cin>>n)
	{
		sum = 0;
		while (n--)
		{
			cin >> a >> b;
			sum += b - a + 1;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
ab = [list(map(int, input().split())) for i in range(3)]

d= {}
d[1] = 0
d[2] = 0
d[3] = 0
d[4] = 0
for tmp in ab:
    d[tmp[0]] += 1
    d[tmp[1]] += 1
if max(d.values()) > 2:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>

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

using namespace std;

typedef long long ll;

const ll M=1000000007;

const int N_BIN=200;
ll nCr[N_BIN+1][N_BIN+1];
void binom(){
	rep(n,N_BIN+1) nCr[n][0]=1;
	rep(n,N_BIN) rep(r,n+1) nCr[n+1][r+1]=(nCr[n][r+1]+nCr[n][r])%M;
}

ll fact[201];

void calc_dp(int n,const int *len,ll dp[200][800]){
	dp[0][0]=1;
	rep(i,n) for(int k=n-1;k>=0;k--) for(int j=4*n-len[i];j>=0;j--) {
		dp[k+1][j+len[i]]=(dp[k+1][j+len[i]]+dp[k][j])%M;
	}
	rep(i,n+1) rep(j,4*n+1) dp[i][j]=dp[i][j]*fact[i]%M; // 並び順が違うものは区別する
}

ll solve(int n,const int *a){
	int len[200];
	rep(i,n){
		char s[8]; sprintf(s,"%d",a[i]);
		len[i]=strlen(s);
	}

	ll cnt[200]={}; // cnt[i] := ( i 個のものからいくつか選んで一列に並べる場合の数 )
	rep(i,n) rep(j,i+1) cnt[i]=(cnt[i]+nCr[i][j]*fact[j])%M;

	// dp[i][j][k] := ( a[0..n-1] から i+1 桁の数を一つ取り除いた数列において, j 個の数をつなげて k 桁の数を作る場合の数 )
	static ll dp[4][200][800];
	rep(i,4) rep(j,n) rep(k,4*n) dp[i][j][k]=0;
	rep(i,4){
		int pos=-1;
		rep(j,n) if(len[j]-1==i) pos=j;
		if(pos!=-1){
			swap(len[pos],len[n-1]);
			calc_dp(n-1,len,dp[i]);
			swap(len[pos],len[n-1]);
		}
	}

	ll ans=0;
	rep(i,n){
		ll ten=1;
		rep(j,4*n){
			rep(k,n){
				ans+=cnt[n-k-1]*dp[len[i]-1][k][j]%M*a[i]%M*ten%M;
				ans%=M;
			}
			ten=ten*10%M;
		}
	}
	return ans;
}

int main(){
	binom();
	fact[0]=1;
	rep(i,200) fact[i+1]=(i+1)*fact[i]%M;

	int n; scanf("%d",&n);
	int a[200],zero=-1;
	rep(i,n){ scanf("%d",a+i); if(a[i]==0) zero=i; }

	ll ans=solve(n,a);
	if(zero!=-1){
		swap(a[zero],a[n-1]);
		ans=(ans-solve(n-1,a)+M)%M;
	}
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 6360
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String[] v = br.readLine().split(" ");
			int a = Integer.parseInt(v[0]);
			int b = Integer.parseInt(v[1]);

			System.out.println((a * b) + " " + (a * 2 + b * 2));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24296
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


template<class T>
class segment_tree_t {
public:
  segment_tree_t(int size = 555555) : size_(1) {
    while (size_ < size)
      size_ *= 2;

    a_ = new T[size_ * 2];

    memset(a_, 0, sizeof(T) * size_ * 2);
  };

  ~segment_tree_t() {
    delete[] a_;
  };

public:
  void update(int i, T x) {	// 0-index
    i += size_ - 1;

    a_[i] = x;

    while (i > 0) {
      i = (i - 1) / 2;

      a_[i] = a_[i * 2 + 1] + a_[i * 2 + 2];
    }
  };

  T query(int a, int b, int i = -1, int l = -1, int r = -1) const {	// [a, b)
    if (i < 0) {
      return query(a, b, 0, 0, size_);
    }
    else {
      if (r <= a || b <= l)
        return 0;

      if (a <= l && r <= b) {
        return a_[i];
      }
      else {
        return
          query(a, b, i * 2 + 1, l, (l + r) / 2) +
          query(a, b, i * 2 + 2, (l + r) / 2, r);
      }
    }
  };

public:
  T operator[](int i) const {
    return a_[size_ + i - 1];
  };

private:
  int size_;

  T* a_;
};


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, Q, t, l, r;

  std::string S;

  char c;

  std::cin >> N >> S >> Q;

  segment_tree_t<int> trees[26];

  for (int i = 0; i < N; i ++) {
    int x = S[i] - 'a';

    trees[x].update(i, trees[x].query(i, i + 1) + 1);
  }

  for (int i = 0; i < Q; i ++) {
    std::cin >> t;

    if (t == 1) {
      std::cin >> l >> c;

      l --;

      char cc = S[l];

      int xx = cc - 'a';
      int yy = trees[xx][l];

      assert(yy > 0);

      trees[xx].update(l, yy - 1);

      int x = c - 'a';
      int y = trees[x].query(l, l + 1);

      trees[x].update(l, y + 1);
      
      S[l] = c;

    }
    else {
      std::cin >> l >> r;

      l --;
      r --;

      int C = 0;

      for (int i = 0; i < 26; i ++)
        if (trees[i].query(l, r + 1))
          C ++;

      std::cout << C << std::endl;
    }
  }

  return 0;
}


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

typedef long long ll;

using namespace std;

string s,t;
ll a[200007], b[200007], pa[200007], pbb[200007];

int main() {
	//freopen("input.txt","r",stdin);
 	//freopen("output.txt","w",stdout);
    int n,m,x,i;
	ll tests=1;
	
	while (tests--)
	{
		cin >> n >> m >> x;
		for (i = 0; i < n; i++)
		{
			cin >> a[i];
			pa[i+1] = pa[i] + a[i];
		}
		for (i = 0; i < m; i++)
		{
			cin >> b[i];
			pbb[i+1] = pbb[i] + b[i];
		}
		int ans = 0;
		for (i = 0; i <= n; i++)
		{
			if (pa[i] <= x)
			   ans = max(ans, i+(int)(upper_bound(pbb, pbb+m+1, x-pa[i])-pbb-1));
			else
				break;
		}
		cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 9792
while True:
    n = int(input())
    if n == 0:
        break
    bridges = []
    for _ in range(n):
        t, b = map(int, input().split())
        bridges.append((t, b))
    bridges.sort(key = lambda x: x[1])

    flag = True
    sumt = 0
    for t, b in bridges:
        sumt += t
        if sumt > b:
            flag = False
            break
    
    if flag:
        print('Yes')
    else:
        print('No')

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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll aa = (n - 1) * a + b;
  ll bb = (n - 1) * b + a;

  cout << max(0ll, bb - aa + 1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  set<int> st;
  rep(i, n) {
    cin >> a[i];
    st.insert(a[i]);
    mp[a[i]]++;
  }

  ll ans = 0;
  SORT(a);
  for(auto itr = st.begin(); itr != st.end(); itr++){
    if(mp[*itr] > *itr) ans += mp[*itr] - *itr;
    else if(mp[*itr] < *itr) ans += mp[*itr];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;

int main(void) {
	long long W, a, b, aw;
	cin >> W >> a >> b;
	if (b > a) {
		if (b - (a+W) > 0) {
			cout << b - (a + W) << endl;
		}
		else
			cout << 0 << endl;
	}
	else if (a > b) {
		if (a - (b + W) > 0) {
			cout << a - (b + W) << endl;
		}
		else
			cout << 0 << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>

int main(int argc, char *argv[]) {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> a(m);
  for (int i = 0; i < m; ++i)
    std::cin >> a.at(i);
  long sum = std::accumulate(a.begin(), a.end(), 0);
  if (n >= sum)
    std::cout << n - sum << std::endl;
  else
    std::cout << -1 << std::endl;
}


Measured memory_bytes: 3196
#![allow(unused_imports)]
use proconio::input;
use std::cmp;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        W: usize,
        WV: [(usize, usize); N],
    }

    let mut dp = vec![vec![0; W + 1]; N + 1];

    for i in 1..=N {
        let (w, v) = WV[i - 1];
        for j in 1..=W {
            //
            if j < w {
                //
                dp[i][j] = dp[i - 1][j];
            } else {
                dp[i][j] = cmp::max(dp[i - 1][j], dp[i - 1][j - w] + v);
            }
        }
    }
    println!("{}", dp[N][W]);
}


Measured memory_bytes: 81176
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memset( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

const int MAXN = 100010;

int n, m, Q, ans[MAXN], f[MAXN][11];
int v[MAXN], d[MAXN], c[MAXN];
vector < int > G[MAXN];

inline void solve(int x, int d, int c)
{
	if( d < 0 || f[ x ][ d ] ) return ;
	for( int i = d ; ~i ; i-- ) f[ x ][ i ] = 1;
	if( !ans[ x ] ) ans[ x ] = c;
	for( auto y : G[ x ] ) solve( y, d - 1, c );
}

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	scanf( "%d%d", &n, &m );
	for( int i = 1, x, y ; i <= m ; i++ ) scanf( "%d%d", &x, &y ), G[ x ].pb( y ), G[ y ].pb( x );
	scanf( "%d", &Q );
	for( int i = 1 ; i <= Q ; i++ ) scanf( "%d%d%d", &v[ i ], &d[ i ], &c[ i ] );
	for( int i = Q ; i ; i-- ) solve( v[ i ], d[ i ], c[ i ] );
	for( int i = 1 ; i <= n ; i++ ) printf( "%d\n", ans[ i ] );
}


Measured memory_bytes: 12408
#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()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

ll modpow(ll a, ll N) {
  ll ans = 1;
  ll tmp = a;
  while(N > 0) {
    if(N % 2 == 1) (ans *= tmp) %= mod;
    (tmp *= tmp) %= mod;
    N /= 2;
  }
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> C(n); rep(i, n) cin >> C[i];
  sort(all(C), greater<ll>());
  ll ans = 0;
  rep(i, n) {
    ll tmp = (modpow(2, i-1) * i % mod + modpow(2, i)) % mod;
    (ans += C[i] * modpow(2, n-i-1) % mod * tmp % mod * modpow(2, n)) %= mod;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4768
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int R, G; cin >> R >> G;
    cout << 2 * G - R << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define fs first
#define sc second
#define P pair<int, int>
#define mk_p make_pair
int a[111], len, K;
LL f[111][5][2];
char s[111];
int main(){
	LL ans = 0;
	cin>>s + 1;
	cin>>K;
	len = strlen(s + 1);
	for(int i = 1;i <= len; i++)a[i] = s[i] - '0';
	f[0][0][1] = 1;
	for(int i = 0;i < len; i++){
		for(int j = 0;j <= K; j++){
			if(!a[i+1])f[i+1][j][1] += f[i][j][1];
			else f[i+1][j+1][1] += f[i][j][1], f[i+1][j+1][0] += f[i][j][1] * (a[i+1] - 1), f[i+1][j][0] += f[i][j][1];
			f[i+1][j][0] += f[i][j][0];
			f[i+1][j+1][0] += f[i][j][0] * 9;
//			printf("i=%d j=%d f0=%lld f1=%lld\n", i, j, f[i][j][0], f[i][j][1]);
		}
	}
	cout<<f[len][K][1] + f[len][K][0]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e18
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

string s;
int ans,ans1;
int main(){
    cin>>s;

    rep(i,(int)s.size()){
        if(i%2==0 && s[i]=='0')ans++;
        if(i%2==1 && s[i]=='1')ans++;
    }
     rep(i,(int)s.size()){
        if(i%2==0 && s[i]=='1')ans1++;
        if(i%2==1 && s[i]=='0')ans1++;
    }
    cout<<min(ans,ans1)<<endl;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

using namespace std;

#define PI			3.14159265
#define OO			1e9
#define SS       	second
#define FF       	first
#define Trace(n)  	cout<< #n <<" = "<< n << endl; 
#define ll			long long
#define endl		"\n"
#define EPS		    1e-9
//#define MOD         1e9 + 7	    
int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
int dy[] = { -1, 1, 0, 0, 1, -1, 1, -1 };

void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main()
{
	fast();
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		int N;
		cin >> N;
		if (N != i)
			cnt++;
	}
	if (cnt == 0 || cnt == 2)
		cout << "YES";
	else
		cout << "NO";
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	text := stdin.Text()

	n, err := strconv.Atoi(text)
	if err != nil {
		panic(fmt.Errorf("unexpected number"))
	}

	var likeL int = 0
	var likeS int = 0

	likeL = n / 500

	if s := n - (likeL * 500); s > 0 {
		likeS = s / 5
	}

	fmt.Printf(fmt.Sprintf("%d", likeL*1000+likeS*5))
}

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

int main(){
  int n, m;
  cin >> n;
    
  map<string,int> maps;

  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    int inum = 1;
    auto itr = maps.find(s);
    
    if(itr != maps.end()){
      inum = maps[s] + 1;
      maps.erase(s);
    }
    maps.insert(make_pair(s,inum));
  }

  cin >> m;
  for(int i=0; i<m; i++){
    string s;
    cin >> s;
    int inum = 1;
    auto itr = maps.find(s);
    
    if(itr != maps.end()){
      inum = maps[s] - 1;
      maps.erase(s);
    }
    maps.insert(make_pair(s,inum));
  }

  int maxs = -300;
  for(auto itr = maps.begin(); itr != maps.end(); ++itr) {
    maxs = max(itr->second, maxs);
  }

  cout << max(maxs,0) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
   int a, b;
   scanf("%d %d", &a, &b);
    
   if(a == b){
      for(int i = 0; i < a; i++){
         printf("%d", a);
      }
   }else if(a > b){
      for(int i = 0; i < a; i++){
         printf("%d", b);
      }
   }else if(a < b){
      for(int i = 0; i < b; i++){
         printf("%d", a);
      }
   }
   printf("\n");
   return 0;
}


Measured memory_bytes: 1696
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int N, C;
int D[30][30];
int c[500][500];
int cal[3][30];

int main() {
	cin >> N >> C;
	REP(i, C) REP(j, C) scanf("%d", &D[i][j]);
	REP(i, N) REP(j, N) scanf("%d", &c[i][j]), c[i][j]--;
	
	REP(i, N) REP(j, N) {
		REP(k, C) cal[(i+j)%3][k] += D[c[i][j]][k];
	}
	
	int ans = INF;
	REP(i, C) REP(j, C) REP(k, C) if (i != j && i != k && j != k)
		chmin(ans, cal[0][i] + cal[1][j] + cal[2][k]);
	
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
#define X real()
#define Y imag()
ld dot(pt u,pt v){
	return (u.X*v.X+v.Y*u.Y);
}
int main(){
	cout<<fixed<<setprecision(12);
	ld x,y; 
	ld xx,yy;
	ld xxx,yyy;
	cin>>x>>y;
	cin>>xx>>yy;
	pt a = {x,y};
	pt b = {xx,yy};
	int q; 
	cin>>q;
	while(q--){
		cin>>xxx>>yyy;
		pt c = {xxx,yyy};
		pt m = a+(b-a)*dot(c-a,b-a)/dot(b-a,b-a);
		cout<<m.X<<" "<<m.Y<<endl;
	}
	return 0;
}



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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 305;

int v[MAXN][MAXN], top[MAXN];
int cnt[MAXN];
int deleted[MAXN];

void solve(){
	int n, m;
	scanf("%d%d", &n, &m);
	int ans = 0;
	REP(i, 0, n) {
		REP(j, 0, m) {
			scanf("%d", &v[i][j]);
		}
		cnt[v[i][0]]++;
		ans = max(ans, cnt[v[i][0]]);
	}
	REP(i, 1, m) {
		int maxi = -1;
		REPN(j, 1, m) {
			if (!deleted[j] && (maxi == -1 || cnt[j] > cnt[maxi])) {
				maxi = j;
			}
		}
		cnt[maxi] = 0;
		deleted[maxi] = 1;
		REP(j, 0, n) {
			int fl = 0;
			for(; deleted[v[j][top[j]]]; top[j]++, fl = 1);
			if (fl) {
				cnt[v[j][top[j]]]++;
			}
		}
		int cur = 0;
		REP(j, 0, n) {
			cur = max(cur, cnt[v[j][top[j]]]);
		}
		ans = min(ans, cur);
		//printf("delete %d, value %d\n", maxi, cur);
	}		
	printf("%d\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int A, B, C;
int main()
{
    cin >> A >> B >> C;
    if(A % 2 == 1 || B % 2 == 1 || C % 2 == 1)
    {
        cout << "0\n";
        return 0;
    }
    if(A == B && B == C)
    {
        cout << "-1\n";
        return 0;
    }
    int ans = 0;
    while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0)
    {
        ++ans;
        int x = A, y = B, z = C;
        A = (y + z) / 2;
        B = (x + z) / 2;
        C = (x + y) / 2;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int i,j;
    int H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0)break;
        for(i=0;i<H;i++){
            if(i%2==0){
                for(j=0;j<W;j++){
                    if(j%2==0)printf("#");
                    if(j%2!=0)printf(".");
                }
                printf("\n");
            }
            if(i%2!=0){
                for(j=0;j<W;j++){
                    if(j%2==0)printf(".");
                    if(j%2!=0)printf("#");
                }
                printf("\n");
            }
        }
        printf("\n");
        
    }
    return 0;
}


Measured memory_bytes: 2092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  int x[100],i=0,j=0,k=0;
  char s[100];
  
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      x[i-2]+=x[i-1];
      i--;
    } else if ( s[0] == '-' ){
      x[i-2]-=x[i-1];
      i--;
    } else if ( s[0] == '*' ){
      x[i-2]*=x[i-1];
      i--;
    } else {
      x[i] = atoi(s);
      i++;
    }
  }
  
  printf("%d\n",x[0]);
  return 0;
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
using namespace std;
namespace FastIO
{
	static char c;
	static int top,buf[12],f;
	template<typename T>
	inline void read(T& x)
	{
		x=0,c=getchar(),f=1;
		while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
		while(isdigit(c))x=x*10+c-'0',c=getchar();x*=f;
	}
	template<typename T>
	inline void write(T x,int f=0)
	{
		top=0;
		if(x<0)putchar('-'),x=-x;
		do buf[top++]=x%10,x/=10;while(x);
		for(int i=top-1;~i;i--)putchar(buf[i]+48);
		if(f)putchar(f&1?' ':'\n');
	}
}
using FastIO::read;
using FastIO::write;
const int maxn=1e5+5;

int N,L,T,st,a[maxn],dt;

int main()
{
	read(N),read(L),read(T),dt=T%L;
	for(int i=0,w;i<N;i++)
	{
		read(a[i]),read(w);
		if(w==1)
		{
			st=(st+T/L)%N;
			a[i]+=dt;
			if(a[i]>=L)a[i]-=L,st=(st+1)%N;
		}
		else
		{
			st=((st-T/L)%N+N)%N;
			a[i]-=dt;
			if(a[i]<0)a[i]+=L,st=(st+N-1)%N;
		}
	}
	sort(a,a+N);
	for(int i=st;i<st+N;i++)write(a[i%N],2);
	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {

    int n,i;
    double x[100],y[100];
    double p1,p2,p22,p3,p33,p4,a;
    
    scanf("%d", &n);
    
    for(i=0; i<n; i++) scanf("%lf",&x[i]);
    for(i=0; i<n; i++) scanf("%lf",&y[i]);
    
    p1=0;
    for(i=0; i<n; i++) p1 += fabs(x[i]-y[i]);
    
    p2=0;
    for(i=0; i<n; i++) p2 += pow(fabs(x[i]-y[i]),2);
    
    p3=0;
    for(i=0; i<n; i++) p3 += pow(fabs(x[i]-y[i]),3);
    
    p4=0;
    a=0;
    for(i=0; i<n; i++) {
        a = fabs(x[i]-y[i]);
        if(a>p4) p4=a;
    }
    
    
    p22 = sqrt(p2);
    p33 = pow(p3, 1.0/3.0);

    
    printf("%lf\n%lf\n%lf\n%lf\n", p1, p22, p33 , p4);
    return 0;
}



Measured memory_bytes: 2104