akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

N = int(input())
Ls = []
Rs = []
l0 = 0
r0 = 0
for i in range(N):
    l, r = map(int, input().split())
    Ls.append((l, i))
    Rs.append((r, i))
    if l > 0:
        l0 += 1
    if r < 0:
        r0 += 1

Ls.sort(reverse=True)
Rs.sort()

used = [False]*N
if l0 > r0:
    toright = True
else:
    toright = False 

l = 0
r = 0
ans = 0
now = 0
for _ in range(N):
    if toright:
        while True:
            nl, ind = Ls[l]
            if used[ind]:
                l += 1
            else:
                used[ind] = True
                break
        if nl-now > 0:
            ans += nl - now
            now = nl
        toright = False
    else:
        while True:
            nr, ind = Rs[r]
            if used[ind]:
                r += 1
            else:
                used[ind] = True
                break
        if now-nr > 0:
            ans += now-nr
            now = nr
        toright = True

ans += abs(now)

print(ans)

Measured memory_bytes: 28452
from itertools import *
from math import *

INF = int(1e18)
N = int(input())
H = list(map(int, input().split()))

flag = True
for j in range(N - 2, -1, -1):
    if H[j] <= H[j + 1]:
        pass  # OK
    elif H[j] == H[j + 1] + 1:
        H[j] -= 1
    else:
        flag = False
        break

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 63984
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
S = [input() for _ in range(N)]
d = defaultdict()
d[S[0]] = 1
for i in range(1, N):
    if S[i] in d.keys():
        print('No')
        exit()
    d[S[i]] = 1
    if S[i][0] != S[i-1][-1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3316
N,M,Q=map(int,input().split())
L,R=0,0
X=[[0]*N for i in range(N)]
for i in range(M):
  L,R=map(int,input().split())
  X[L-1][R-1]+=1
Y=[[0]*(N+1) for i in range(N+1)]
for i in range(N):
  for j in range(N):
    Y[i+1][j+1]=X[i][j]+Y[i+1][j]+Y[i][j+1]-Y[i][j]
for i in range(Q):
  L,R=list(map(int,input().split()))
  print(Y[N][R]-Y[L-1][R])

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

using namespace std;

#define li long long int

const int N = 1e5 + 3;
const li mod = 1e9 + 7;

int n, m;
int broken[N];
li dp[N];

li go(int pos) {
	if (broken[pos]) return 0;
	if (pos >= n) return pos == n;
	if (dp[pos] != -1) return dp[pos];
	li ans = go(pos + 1) + go(pos + 2);
	ans %= mod;
	return dp[pos] = ans;
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int x;
		cin >> x;
		broken[x] = 1;
	}
	memset(dp, -1, sizeof(dp));
	li ans = go(0);
	cout << ans;
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 4480
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
    while (1) {
        int h, w;
        cin >> h >> w;

        if (h == 0 && w == 0) {
            break;
        }

        for (int row = 0; row < h; row++) {
            for (int col = 0; col < w; col++) {
                if ((row + col) % 2 == 0) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }

        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int t = sc.nextInt();
		int cost[] = new int[n];
        int time[] = new int[n];
        int i;
        int ans = 0;
        for(i = 0;i < n;i++){
          cost[i] = sc.nextInt();
          time[i] = sc.nextInt();
          if(time[i] <= t){
            if(ans > cost[i] || ans == 0){
              
            ans = cost[i];
            }
          }
        }
      	if(ans == 0){
           System.out.println("TLE");   
        }else{
     	   System.out.println(ans);   
        }
    }
}

Measured memory_bytes: 35952
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	_, M := sc.nextInt(), sc.nextInt()
	An := sc.nextInts()
	sort.Ints(An)
	var total int
	for _, v := range An {
		total += v
	}

	for i := 0; i < M; i++ {
		tmp := float64(An[len(An)-i-1])
		// fmt.Println(tmp)
		if tmp < (float64(total) / float64(4*M)) {
			no()
			return
		}
	}
	yes()
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <utility>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define MOD 1000000007
#define pb push_back
#define loop(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define loope(i, b) for (int i = 1; i <= (int)b; i++)
#define loopl(i, a, b) for (ll i = ll(a); i < (ll)b; i++)

int main()
{
    cpp_int a, sum;
    cin >> a;
    if (a % 9 == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,q;

int main(){
    cin >> n;
    ll a[100001]; memset(a,0LL,sizeof(a));
    ll num; for(int i=0; i<n; i++){
        cin >> num; a[num]++;
    }
    ll sum = 0LL; for(int i=1; i<100001; i++){
        sum+=i*a[i];
    }
    cin >> q;
    ll b,c;
    while(q--){
        cin >> b >> c;
        sum+=(c-b)*a[b];
        a[c]+=a[b]; a[b]=0LL;
        cout << sum << endl;
    }
}


Measured memory_bytes: 4364
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static Scanner scanner;
    static PrintWriter out;
    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        out = new PrintWriter(System.out);
        long a = nextLong();
        long b =nextLong();
        long c = nextLong();
        long d = (long) Math.ceil(a*1.0/(b*1.0));
        out.println(c*d);
        out.flush();
    }

    public static void println(Object o) {
        out.println(o);
    }

    public static void print(Object o) {
        out.print(o);
    }

    public static void printf(String format, Object... o) {
        out.printf(format, o);
    }

    public static String next() {
        return scanner.next();
    }

    public static int nextInt() {
        return Integer.parseInt(scanner.next());
    }

    public static long nextLong() {
        return Long.parseLong(scanner.next());
    }

    public static double nextDouble() {
        return Double.parseDouble(scanner.next());
    }

    public static short nextShort() {
        return Short.parseShort(scanner.next());
    }

    public static float nextFloat() {
        return Float.parseFloat(scanner.next());
    }

    public static void printYes() {
        System.out.println("Yes");
    }

    public static void printYES() {
        System.out.println("YES");
    }

    public static void printNo() {
        System.out.println("No");
    }

    public static void printNO() {
        System.out.println("NO");
    }

    public static String nextLine() {
        return scanner.nextLine();
    }

    public static double distance(double x, double y, double x2, double y2) {
        return Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
    }

    public static int MOD = 1_000_000_007;
    public static int MAX = 100000;
    public static long[] fac = new long[MAX];
    public static long[] finv = new long[MAX];
    public static long[] inv = new long[MAX];

    public static void combinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    public static long combination(int n, int k) {
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    public static long factorial(long n) {
        return n <= 0 ? 1 : n * factorial(n - 1);
    }
}

Measured memory_bytes: 29272
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
s = input()
color = 0
ans = 0
for i in range(n):
  if i == 0:
    color = s[0]
    ans = 1
  else:
    if color != s[i]:
      color = s[i]
      ans += 1
print(ans)


Measured memory_bytes: 5836
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>

using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

#define rep(i,s,n)for(int i = s;i<n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define repe_r(i,s,n)for(int i = n;i>=s;i--)

ll d[100001] = {};
int main() {
	ll n; cin >> n;
	ll sum = 0;
	repe(i, 1, n)cin >> d[i];
	sort(d + 1, d + 1 + n);
	ll t = d[n / 2 + 1] - d[n / 2];
	cout << t << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include<map>
#include <algorithm>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if(a.second != b.second){
		return a.second > b.second;
	}else{
		return a.first > b.first;
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	vector<pair<int, ll>> cards(N + M);
	REP(i, N) {
		cin >> cards[i].second;
		cards[i].first = 1;
	}
	for (int i = N; i < N + M; ++i) {
		cin >> cards[i].first >> cards[i].second;
	}
	sort(cards.begin(), cards.end(),compare_by_b);
	ll ans = 0;
	ll cnt = 0;
	REP(i, N + M) {
		if (cnt > N)break;
		if (cnt + cards[i].first >= N) {
			ans += cards[i].second*(N - cnt);
			break;
		}
		else {
			ans += cards[i].first*cards[i].second;
			cnt += cards[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
n, k = map(int, input().split())
a_in = list(map(int, input().split()))

diff_list = [0 for num in range(n)]
diff_list[0] = a_in[0]
for i in range(1, n):
    diff_list[i] = a_in[i] - a_in[i-1]

itr = k
if k > 41:
    itr = 41
for i in range(itr):
    new_list = [0 for num in range(n)]
    d_sum = 0
    for j, d in enumerate(diff_list):
        d_sum += d
        if j-d_sum > 0:
            new_list[j-d_sum] += 1
        else:
            new_list[0] += 1
        if d_sum+j+1 < n:
            new_list[j+d_sum+1] -= 1
    # print(new_list)
    diff_list = new_list.copy()

ans = 0
for d in diff_list:
    ans += d
    print(ans, end= ' ')


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    for(ll i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<int> s;
    vector<int> ord(n + 1, -1);
    int c = 1, l = 0, v = 1;
    while(ord[v] == -1) {
        ord[v] = s.size();
        s.push_back(v);
        v = a[v - 1];
    }
    // c = 周期, l = 周期に含まれない部分の長さ
    c = s.size() - ord[v];
    l = ord[v];

    if(k < l)
        cout << s[k] << endl;
    else {
        k -= l;
        k %= c;
        cout << s[l + k] << endl;
    }
    return 0;
}

Measured memory_bytes: 5884
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int main () {
  int A,B;
  cin >> A >> B;
  int num=0;
  if(A<B) {
    num+=B;
    B--;
  } else {
    num+=A;
    A--;
  }
  if(A<B) {
    num+=B;
    B--;
  } else {
    num+=A;
    A--;
  }
  cout << num << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define each(i, c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef pair<int, int> pi;
typedef complex<double> P;

const double EPS = 1e-8, INF = 1e12;
double cross(const P &a, const P &b){
	return imag(conj(a) * b);
}
double dot(const P &a, const P &b){
	return real(conj(a) * b);
}
struct L : public vector<P> {
	L(const P &a, const P &b){
		pb(a); pb(b);
	}
};
typedef vector<P> G;
int ccw(P a, P b, P c){
	b -= a; c -= a;
	if(cross(b, c) > EPS) return 1;
	if(cross(b, c) < -EPS) return -1;
	if(dot(b, c) < -EPS) return 2;
	if(norm(b) < norm(c)) return -2;
	return 0;
}

bool intersectSP(const L &s, const P &p){
	return ccw(p, s[0], s[1]) == 2;
}
bool intersectSS(const L &s, const L &t){
	return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
	ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
P projection(const L &l, const P &p){
	double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
	return l[0] + t * (l[0] - l[1]);
}
double distanceSP(const L &s, const P &p){
	const P r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t){
	if(intersectSS(s, t)) return 0;
	return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
		min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
const double PI = acos(-1);
int n, m, l;
int x[100], y[100], a[100], r[100];
double dist[100][100];

int main(){
	while(cin >> n >> m >> l, n){
		rep(i, n) cin >> x[i] >> y[i] >> a[i] >> r[i];
		vector<G> stars;
		rep(i, n){
			double t = a[i] * PI / 180;
			G star;
			rep(j, 5){
				double tt = PI / 2 + t + PI * 0.4 * j;
				star.pb(P(cos(tt), sin(tt)) * (double)r[i] + P(x[i], y[i]));
			}
			stars.pb(star);
		}
		rep(i, n) rep(j, i){
			double mn = INF;
			rep(l, 5) rep(k, 5){
				L la(stars[i][l], stars[i][(l + 2) % 5]);
				L lb(stars[j][k], stars[j][(k + 2) % 5]);
				mn = min(mn, distanceSS(la, lb));
			}
			dist[i][j] = dist[j][i] = mn;
		}
		priority_queue<pair<double, int> > q;
		q.push(mp(0, m - 1));
		set<int> s;
		while(!q.empty()){
			int c = q.top().second;
			double cc = q.top().first;
			q.pop();
			
			if(s.count(c)) continue;
			s.insert(c);
			
			if(c == l - 1){
				printf("%.9f\n", abs(cc));
				break;
			}
			
			rep(i, n) q.push(mp(cc - dist[c][i], i));
		}
	}
	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
int main()
{
    using namespace std;
    int K, n(10);
    long t;
    unsigned int x;
    cin >> K;
    unsigned int result[K];
    queue<unsigned int> m_queue;
    for (int i = 1; i < 10; i++)
    {
        m_queue.push(i);
    }
    for (int i = 0; i < K; i++)
    {
        x = m_queue.front();
        result[i] = x;
        m_queue.pop();
        t = 10 * x + x % 10;
        if (n <= K)
        {
            if (x % 10 != 0)
            {
                m_queue.push(t - 1);
                n++;
            }
            m_queue.push(t);
            n++;
            if (x % 10 != 9)
            {
                m_queue.push(t + 1);
                n++;
            }
        }
    }
    cout << result[K - 1] << endl;
}

Measured memory_bytes: 896
#include<cstdio>
#include<complex>
#include<cmath>
using namespace std;
typedef complex<double> xy;


int main() {
	xy p[30];
	int n = 0;
	double x, y;
	while (~scanf("%lf,%lf", &x, &y)) {
		p[n++] = xy(x, y);
	}

	double sum = 0.0;
	for (int i = 1; i <= n - 2; i++) {
		xy a = p[0], b = p[i], c = p[i + 1];
		sum += (conj(b - a)*(c - a)).imag() / 2.0;
	}
	printf("%.6f\n", abs(sum));

	return 0;
}

Measured memory_bytes: 1088
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  rep(i,n*2){
    if(i % 2 == 0)cout << s[i / 2];
    else cout <<t[i / 2];
  }
  cout << endl;
  return 0;
}

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

#define ll long long
#define ull unsigned ll
#define vi vector <int>
#define ii pair <int, int>
#define vii vector <ii>
#define INF 2e9
#define EPS 1e-9
#define pb push_back
#define emp push_back
#define PI acos(-1.0)
#define endl "\n"
#define mp make_pair
#define DEBUG 0

ll maximum(ll a, ll b){
	if (a >= b) return a;
	return b;
}

ll minimum(ll a, ll b){
	if (a >= b) return b;
	return a;
}


int main ()
{
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #define int ll

	int n;
	cin >> n;

	vector <int> height(n);
	for (auto& i:height){
		cin >> i;
	}
	int dp[n];
	memset (dp, 0, sizeof(dp));
	dp[0] = 0;
	dp[1] = abs(height[1] - height[0]) + dp[0];
	for (int i=2; i<n; i++){
		int contender1 = dp[i-1] + abs(height[i] - height[i-1]);
		int contender2 = dp[i-2] + abs(height[i] - height[i-2]);
		dp[i] = min(contender1, contender2);
		
	}
	cout << dp[n-1] << endl;
	
    
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(len(B)):
  if B[i] <= A[i]:
    ans += B[i]
  else:
    if B[i] >= A[i]+A[i+1]:
      ans += A[i]+A[i+1]
      A[i] = 0
      A[i+1] = 0
    else:
      ans += B[i]
      A[i+1] -= B[i]-A[i]
print(ans)

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

// Sを１回回転させる関数
string rotation1(string S){
	vector<char> a(S.size());
	for(int i = 0; i < S.size() - 1; i++){
		a.at(i + 1) = S[i];
	}
	a.at(0) = S[S.size() - 1];
	string ret = "";
	for(int i = 0; i < S.size(); i++){
		ret += a.at(i);
	}
	return ret;
}

// SをN回回転させる関数
string rotationN(int N, string S){
	for(int i = 0; i < N; i++){
		S = rotation1(S);
	}
	return S;
}

int main() {
	string S;
	string T;
	cin >> S >> T;
	bool Yes = false;
	for(int i = 0; i < S.size(); i++){
		if(rotationN(i, S) == T){
			Yes = true;
			break;
		}
	}
	if(Yes){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n+1);
    vector<ll> ruiseki(n+2);
    vector<ll> b(n+1);
    rep(i,n+1) {cin >> a[i]; ruiseki[i] = a[i];}

    
    ll ans=0;
    b[0] = 1 - a[0];
    for(int i=n; i>0; i--) ruiseki[i-1] += ruiseki[i];
    rep(i,n){
        b[i+1] = min(ruiseki[i+2], 2*b[i] - a[i+1]);
        if(b[i+1]<0){
            ans=-1;
            break;
        }
    }
    if(b[0] < 0) ans=-1;
    if(ans!=-1) rep(i,n+1) ans += a[i] + b[i];
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

struct mint {
  int n;
  mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { return (a.n += b.n) >= mod ? a.n - mod : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + mod : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n % mod; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

int n;
mint a[100000];
mint sum[202020];
mint inv[100002];
mint fact[100002];
mint ifact[100002];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i].n);
    sum[i + 1] = sum[i] + a[i];
  }
  inv[1] = 1;
  for (int i = 2; i <= n; i++) {
    inv[i] = inv[mod % i] * (mod - mod / i);
  }
  fact[0] = 1;
  ifact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = i * fact[i - 1];
    ifact[i] = inv[i] * ifact[i - 1];
  }

  mint ans = sum[n] * fact[n];
  for (int i = 1; i <= n - 1; i++) {
    ans += sum[i] * fact[i] * ifact[i + 1] * fact[n];
    ans += (sum[n] - sum[n - i]) * fact[i] * ifact[i + 1] * fact[n];
  }
  mint curr = 0;
  for (int i = 1; i <= n - 2; i++) {
    curr += sum[n - 1] - sum[i];
    ans += curr * fact[2] * fact[i] * fact[n] * ifact[2 + i];
    curr -= sum[n - 1] - sum[n - 1 - i];
  }
  printf("%d\n", ans.n);
}



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

int main() {
		int A,B,C,D;
	int AB,CD;
	cin >> A >> B >> C >> D;
	AB=A*B;
	CD=C*D;
	if(AB>=CD){
	cout << AB;
	}
	else  {
	cout << CD;
	}
	return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,string> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

bool comp(tpl a, tpl b){
    int l1,r1, l2,r2;
    string t1,t2;
    tie(l1,r1,t1) = a;
    tie(l2,r2,t2) = b;
    return l1-r1 > l2-r2;
}
int main(void){
    int N; cin >> N;
    string s1 = "", s2 = "", s3 = "";
    vector<tpl> S;
    REP(i,N){
        string s; cin >> s;
        stack<char> stk;
        for(char c : s){
            if(c == ')'){
                if(stk.size() && stk.top() == '(') stk.pop();
                else stk.push(c);
            }
            else stk.push(c);
        }
        int l = 0, r = 0;
        string t = "";
        while(!stk.empty()){
            char c = stk.top(); stk.pop();
            if(c == ')') r++;
            else l++;
            t += c;
        }
        REVERSE(t);
        if(l>0 && r>0) S.emplace_back(l, r, t);
        else if(r == 0) s1 += t;
        else s3 += t;
    }
    sort(ALL(S), comp);
    REP(i,S.size()) s2 += get<2>(S[i]);
    string t = s1 + s2 + s3;
    stack<char> stk;
    for(char c : t){
        if(c == ')'){
            if(stk.size() && stk.top() == '(') stk.pop();
            else stk.push(c);
        }
        else stk.push(c);
    }

    cout << (stk.empty() ? "Yes" : "No") << en;
    return 0;
}

Measured memory_bytes: 13764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingContest
{
    class MainClass
    {
        Scanner sc;
        static void Main(string[] args)
        {
            new MainClass().Solve();
        }

        void Solve()
        {
#if DEBUG
            string backPath = "..";
            char dirSep = System.IO.Path.DirectorySeparatorChar;
            string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
            sc = new Scanner(new System.IO.StreamReader(inFilePath));
#else
            sc = new Scanner();
#endif

            string s = sc.Next;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.Length; i += 2)
            {
                sb.Append(s[i]);
            }
            Write(sb);
        }

        void Write(object val)
        {
            Console.WriteLine(val.ToString());
        }
        void Write(string format, params object[] vals)
        {
            Console.WriteLine(format, vals);
        }
        void fill<T>(T[] ar, T val)
        {
            for (int i = 0; i < ar.Length; i++)
            {
                ar[i] = val;
            }
        }
    }
    class Scanner
    {
        Queue<String> buffer;
        char[] sep;
        System.IO.TextReader reader;
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.buffer.Count == 0 && this.reader.Peek() >= 0)
            {
                string[] sreArray = this.reader.ReadLine().Split(this.sep);
                foreach (String elStr in sreArray)
                {
                    this.buffer.Enqueue(elStr);
                }
            }
        }

        public String Next
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }
        public bool IsEmpty
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}


Measured memory_bytes: 14176
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int MAX = 50;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int p = parseInt(sc.next());
		int[] a = new int[n];
		int odd=0;
		int even=0;
		for (i = 0; i < a.length; i++) {
			a[i] = parseInt(sc.next());
			if(a[i]%2==0) {
				even++;
			} else {
				odd++;
			}
		}
		sc.close();
		long[][] comb = new long[MAX+1][MAX+1];
		comb[0][0] = 1;
		for (i = 1; i <= MAX; i++) {
			for (j = 0; j <= i; j++) {
				comb[i][j] = (j>0?comb[i-1][j-1]:0) + comb[i-1][j]; 
			}
		}
		long evencnt=0;
		for (i = 0; i <= even; i++) {
			evencnt+=comb[even][i];
		}
//		out.println(evencnt);
		long oddcnt=0;
		for (i = p; i <= odd; i+=2) {
			oddcnt+=comb[odd][i];
		}
//		out.println(oddcnt);
		out.println(oddcnt*evencnt);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

int getAbs(int x);

int getMin(vector<int> v);

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b);
    return 0;
}

int getAbs(int x){
    return (x > 0)? x : -x;
}

int getMin(vector<int> v){
    int res = 40000;
    for(int i = 0; i < v.size(); i++){
        res = min(res, v[i]);
    }
    return res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD               1000000007
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
bool cmp(ll x,ll y)
{
   return x>y;
}
int main(void)
{
   long long int t,n,m,k,x,y,a[200001];
   vector<ll> v,v1,v2;
   vector< pair <ll,ll> >p,p1,p2;
   set<ll> st;
   priority_queue<ll> pq;
   priority_queue< ll,vector<ll>,greater<ll> > lpq;
   priority_queue< pair<ll,ll> > phpq;
   priority_queue< pair<ll,ll>,vector< pair<ll,ll> >,greater< pair <ll,ll> > > plpq;
   string s;
   //cin>>t;
   //while(t--)
   //{
      cin>>n;
      for(ll i=0;i<n;i++)
      {
         cin>>a[i];
      }
         ll ans=0;
      for(ll i=1;i<n;i++)
      {
         if(a[i]<a[i-1])
         {
            ans+=(a[i-1]-a[i]);
            a[i]=a[i-1];
         }
      }
      cout<<ans<<endl;
   //}
   return 0;
}


Measured memory_bytes: 5152
## DP問題
 
N,M = map(int,input().split())
As = list(map(str,input().split()))
match = {"1":2, "2":5, "3":5,
         "4":4, "5":5, "6":6,
         "7":3, "8":7, "9":6}
 
# test
# N, M = 10000, 9
# As = [str(i) for i in range(1,10)]
 
 
ws = {} #マッチの数に対しての、作れる数字の最大値を算出
for a in As:
    w = match[a] #数aに使うマッチの数
    try: 
        ws[str(w)] = max(a,ws[str(w)])
    except:
        ws[str(w)] = a
ks = list(map(int,ws.keys()))
ns = list(ws.values())
 
dp = ["0" for _ in range(N+1)]
for i in range(1,min(ks)):#最小
    dp[i] = "-1"
 
for i in range(N+1):
    # print(i)
    for a,k in zip(ns,ks):
        if i+k <= N:
            if dp[i] == "-1":
                dp[i+k] = str(max(int(dp[i]+a),int(dp[i+k])))
            elif dp[i] == "0":
                dp[i+k] = str(max(int(a),int(dp[i+k])))
            elif len(dp[i+k]) < len(dp[i])+1:
                    dp[i+k] = dp[i]+a
            elif len(dp[i+k]) == len(dp[i])+1:
                dp[i+k] = max(dp[i+k],dp[i]+a)
            else:
                dp[i+k] = str(max(int(dp[i+k]),int(dp[i]+a)))

        else:
            continue
print(dp[N])

Measured memory_bytes: 30452
import java.util.*;
import java.math.*;
import java.util.Scanner;
import java.math.BigInteger;

public class Main {
	static final long mod = (int) (1e9 + 7);
	static final int inf = (int) (1e9);
	static final int maxn = (int) (1e5 + 10);

	static long ksm(long a, long b) {
		long ret = 1;
		while (b != 0) {
			if (b % 2 == 1) {
				ret = ret * a % mod;
			}
			b >>= 1;
			a = a * a % mod;
		}
		return ret;
	}

	static int n, q;
	static String s;
	static long[][][][] dp = new long[110][5][5][5];

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		n = cin.nextInt();
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				for (int k = 0; k < 4; k++) {
					if (i == 0 && j == 1 && k == 2)
						continue;
					if (i == 1 && j == 0 && k == 2)
						continue;
					if (i == 0 && j == 2 && k == 1)
						continue;
					dp[3][i][j][k] = 1;
				}
			}
		}
		for (int i = 4; i <= n; i++) {
			for(int a=0;a<4;a++) {
				for(int b=0;b<4;b++) {
					for(int c=0;c<4;c++) {
						for(int d=0;d<4;d++) {
							if (a == 0 && b == 1 && c == 2)
								continue;
							if (a == 1 && b == 0 && c == 2)
								continue;
							if (a == 0 && b == 2 && c == 1)
								continue;
							if(d==0&&b==1&&c==2) continue;
							if(d==0&&a==1&&c==2) continue;
							dp[i][a][b][c]=(dp[i][a][b][c]+dp[i-1][d][a][b])%mod;
						}
					}
				}
			}
		}
		long ans=0;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				for (int k = 0; k < 4; k++) {
					ans=(ans+dp[n][i][j][k])%mod;
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

bool dp[85][85][6500];

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

    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> a[i][j];
        }
    }
    vector<vector<int>> b(h, vector<int>(w));
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> b[i][j];
        }
    }
    int val = abs(a[0][0] - b[0][0]);
    dp[0][0][val] = true;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(i == 0 && j == 0)    continue;
            for(int k = 0; k <= 6400; ++k){
                val = abs(a[i][j] - b[i][j]);
                if(i - 1 >= 0 && i - 1 < h){
                    if(dp[i - 1][j][k]){
                        dp[i][j][k + val] = true;
                        dp[i][j][abs(val - k)] = true;
                    }
                }
                if(j - 1 >= 0 && j - 1 < w){
                    if(dp[i][j - 1][k]){
                        dp[i][j][k + val] = true;
                        dp[i][j][abs(val - k)] = true;
                    }
                }
            }
        }
    }
    for(int i = 0; i < 6400; ++i){
        if(dp[h - 1][w - 1][i]){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 45184
loop do
    n, m, a = gets.split.map(&:to_i)
    break if n == 0 && m == 0 && a == 0
    d = m.times.map{gets.split.map(&:to_i)}
    d.sort! { |a, b| b[0] <=> a[0]}
    pos = a
    d.each do |dd|
        if dd[1] == pos
            pos = dd[2]
        elsif dd[2] == pos
            pos = dd[1]
        end
    end
    puts pos
end

Measured memory_bytes: 6116
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (int i = 0; i < v.size(); ++i) {
        if(i) os << ",";
        os << v[i];
    }
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}
int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &&i : v) scanf("%lld", &i);
    bool nega = false;
    ll p = 0, q = 0;
    for (int j = 0; j < n; ++j) {
        if(llabs(v[j]) > llabs(p)) p = v[j], q = j;
    }
    vector<ll> u = v;
    vector<pair<int, int>> ans;
    if(p < 0) {
        nega = true;
        for (int i = 0; i < n; ++i) {
            v[i] = -v[i];
        }
        q = n-1-q;
        reverse(v.begin(), v.end());
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 1 + (v[i] < 0); ++j) {
            if(nega) ans.emplace_back(n-q, n-i);
            else ans.emplace_back(q+1, i+1);
        }
        q = i;
    }
    cout << ans.size() << "\n";
    for (auto &&i : ans) {
        u[i.second-1] += u[i.first-1];
        cout << i.first << " " << i.second << "\n";
    }
    return 0;
}


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

using namespace std;

int main(){
  int n,p;

  while(cin>>n>>p,n||p){
    int i=0;
    vector<int> t(n,0);
    int pp=p;
    while(1){
      if(p>0){
	p--;
	t[i]++;
      }
      else if(p==0){
	p=t[i];
	t[i]=0;
      }
      
      if(t[i]==pp)
	break;

      i++;
      if(i==n)
	i=0;
    }
    cout<<i<<endl;
  }
}

Measured memory_bytes: 3004
///
// File:  alds1_3_c.cpp
// Author: ymiyamoto
//
// Created on Sat Oct  7 15:06:49 2017
//

#include <cstdint>
#include <cstring>
#include <iostream>

using namespace std;

struct linked_list_t {
  linked_list_t *prev;
  linked_list_t *next;
  int64_t val;
};

static void delete_list(linked_list_t *list)
{
  linked_list_t *prev = list->prev;
  linked_list_t *next = list->next;
  prev->next = next;
  next->prev = prev;
  delete list;
}

int32_t main()
{
  uint64_t n;
  cin >> n;

  linked_list_t list;
  list.prev = &list;
  list.next = &list;
  list.val = -1;

  for (uint64_t i = 0; i < n; i++) {
    char str[20];
    scanf("%s", str);

    if (str[0] == 'i') {
      int64_t val;
      scanf("%lld", &val);
      linked_list_t *new_list = new linked_list_t;
      linked_list_t *next = list.next;
      linked_list_t *prev = &list;
      next->prev = new_list;
      prev->next = new_list;

      new_list->val = val;
      new_list->next = next;
      new_list->prev = prev;
    } else if (str[0] == 'd') {
      if (strlen(str) == 6) {
        int64_t val;
        scanf("%lld", &val);
        linked_list_t *l = list.next;
        while (true) {
          if (l->val == val) {
            delete_list(l);
            break;
          }
          l = l->next;
          if (l->val == -1) break;
        }
      } else if (str[6] == 'F') {
        delete_list(list.next);
      } else {
        delete_list(list.prev);
      }
    }
  }

  linked_list_t *l = list.next;
  while (l->val != -1) {
    if (l != list.next) cout << " ";
    cout << l->val;
    l = l->next;
  }

  cout << endl;

  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<int> > a(n, vector<int>(n));
    for(int i=0; i<n; ++i) {
        for(int j=0; j<n; ++j) {
            cin >> a[i][j];
        }
    }
    vector<vector<int> > sum(n, vector<int>(n+1));
    for(int i=0; i<n; ++i) {
        for(int j=0; j<n; ++j) {
            sum[i][j+1] += sum[i][j] + a[i][j];
        }
    }
    int res = -1e9;
    for(int i=0; i<=n; ++i) {
        for(int j=i+1; j<=n; ++j) {
            int t = 0;
            for(int k=0; k<n; ++k) {
                if(t < 0) {
                    t = sum[k][j] - sum[k][i];
                } else {
                    t += sum[k][j] - sum[k][i];
                }
                res = max(res, t);
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;

int H, W, K, a, b, c, d;
vector<vector<char>> kek;
vector<vector<int>> dp;

class UnionFind {
public:
    vector<int> to;
    vector<int> ba;
    vector<bool> keep;
    UnionFind(int n = 0) {
        to.resize(n + 2);
        ba.resize(n + 2);
        keep.resize(n + 2);
        for (int i = 1; i <= n; i++) {
            to[i] = i + 1;
            ba[i] = i - 1;
            keep[i] = true;
        }
        keep[0] = keep[n + 1] = true;
    }
    void cut(int i) {
        keep[i] = false;
    }
    int inc(int i) {
        if (keep[to[i]]) {
            return to[i];
        }
        return to[i] = inc(to[i]);
    }
    int dec(int i) {
        if (keep[ba[i]]) {
            return ba[i];
        }
        return ba[i] = dec(ba[i]);
    }
};

vector<UnionFind> rows;
vector<UnionFind> cols;

void kill(int x, int y) {
    rows[x].cut(y);
    cols[y].cut(x);
}

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

    cin >> H >> W >> K >> a >> b >> c >> d;
    kek.resize(H + 1);
    dp.resize(H + 1);
    for (int i = 1; i <= H; i++) {
        kek[i].resize(W + 1);
        dp[i].resize(W + 1, -1);
        for (int j = 1; j <= W; j++) {
            cin >> kek[i][j];
        }
    }
    rows.resize(H + 1);
    for (int i = 1; i <= H; i++) {
        rows[i] = UnionFind(W);
    }
    cols.resize(W + 1);
    for (int i = 1; i <= W; i++) {
        cols[i] = UnionFind(H);
    }
    queue<pair<int, int>> qp;
    qp.push({a, b});
    dp[a][b] = 0;
    kill(a, b);
    while (!qp.empty()) {
        pair<int, int> pr = qp.front();
        qp.pop();
        int x = pr.first;
        int y = pr.second;
        for (int i = x + 1; i <= min(H, x + K); i = cols[y].inc(i)) {
            if (kek[i][y] == '@') break;
            if (dp[i][y] != -1) continue;
            dp[i][y] = dp[x][y] + 1;
            kill(i, y);
            qp.push({i, y});
        }
        for (int i = x - 1; i >= max(1LL, x - K); i = cols[y].dec(i)) {
            if (kek[i][y] == '@') break;
            if (dp[i][y] != -1) continue;
            dp[i][y] = dp[x][y] + 1;
            kill(i, y);
            qp.push({i, y});
        }
        for (int i = y + 1; i <= min(W, y + K); i = rows[x].inc(i)) {
            if (kek[x][i] == '@') break;
            if (dp[x][i] != -1) continue;
            dp[x][i] = dp[x][y] + 1;
            kill(x, i);
            qp.push({x, i});
        }
        for (int i = y - 1; i >= max(1LL, y - K); i = rows[x].dec(i)) {
            if (kek[x][i] == '@') break;
            if (dp[x][i] != -1) continue;
            dp[x][i] = dp[x][y] + 1;
            kill(x, i);
            qp.push({x, i});
        }
    }
    cout << dp[c][d] << '\n';

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 207552
#include<iostream>
using namespace std;
long long N;
void func(long long cur,int use,long long &counter){
    if(cur>N)return;
    if(use==0b111)++counter;
    func(cur*10+7,use|0b001,counter);
    func(cur*10+5,use|0b010,counter);
    func(cur*10+3,use|0b100,counter);
}

int main(){
    cin>>N;
    long long res=0;
    func(0,0,res);
    cout<<res<<endl;
}

Measured memory_bytes: 256