akhauriyash/Code-Regression huggingface dataset:
s=input()
len_s=len(s)
dp=[[0]*((len_s)+1) for _ in range(4)]
dp[0][0]=1

for j in range(1,len_s+1):
    if(s[j-1]=="?"):
        dp[0][j]=3*dp[0][j-1]
    else:
        dp[0][j]=dp[0][j-1]
    
    if(s[j-1]=="?"):
        dp[1][j]=dp[0][j-1] + 3*dp[1][j-1]
    elif(s[j-1]=="A"):
        dp[1][j]=dp[0][j-1] + dp[1][j-1]
    else:
        dp[1][j]=dp[1][j-1]

    if(s[j-1]=="?"):
        dp[2][j]=dp[1][j-1] + 3*dp[2][j-1]
    elif(s[j-1]=="B"):
        dp[2][j]=dp[1][j-1] + dp[2][j-1]
    else:
        dp[2][j]=dp[2][j-1]

    if(s[j-1]=="?"):
        dp[3][j]=dp[2][j-1] + 3*dp[3][j-1]
    elif(s[j-1]=="C"):
        dp[3][j]=dp[2][j-1] + dp[3][j-1]
    else:
        dp[3][j]=dp[3][j-1]

    for k in range(4):
        dp[k][j]%=10**9+7

print(dp[-1][-1])    

Measured memory_bytes: 19116
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=2010;
const int inf=2147483647;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x*f;
}
int n,a[Maxn<<1],c[Maxn<<1],s[2][Maxn<<1][Maxn],pos[2][Maxn];LL f[Maxn][Maxn];
char str[3];
int main()
{
	n=read();
	for(int i=1;i<=(n<<1);i++)
	{
		scanf("%s",str);
		a[i]=read();
		if(str[0]=='W')c[i]=0;else c[i]=1;
		pos[c[i]][a[i]]=i;
		for(int o=0;o<2;o++)
		for(int j=1;j<=n;j++)
		s[o][i][j]=s[o][i-1][j];
		for(int j=a[i];j<=n;j++)
		s[c[i]][i][j]++;
	}
	f[0][0]=0;
	for(int i=0;i<=n;i++)
	for(int j=0;j<=n;j++)
	{
		if(!i&&!j)continue;
		f[i][j]=1LL<<60;
		int p;
		if(i)
		{
			p=pos[0][i];
			f[i][j]=min(f[i][j],f[i-1][j]+((LL)i+j-1-s[0][p][i-1]-s[1][p][j]));
		}
		if(j)
		{
			p=pos[1][j];
			f[i][j]=min(f[i][j],f[i][j-1]+((LL)i+j-1-s[0][p][i]-s[1][p][j-1]));
		}
//		printf("%d %d %lld\n",i,j,f[i][j]);
	}
	printf("%lld",f[n][n]);
}

Measured memory_bytes: 94848
import sys
readline = sys.stdin.readline
N = int(readline())
S = tuple(map(ord, readline().strip()))

dp = [[0]*(N+1) for _ in range(N+1)]

for j in range(N-1, -1, -1):
    for i in range(j-1, -1, -1):
        k = dp[i+1][j+1]
        if S[i] != S[j]:
            continue
        if i+k == j:
            dp[i][j] = k
        else:
            dp[i][j] = k+1
print(max(max(d) for d in dp))


Measured memory_bytes: 231944
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func main() {
	io := NewIo()
	defer io.Flush()

	list := make([]int, 5)
	for i := range list {
		list[i] = io.NextInt()
	}

	k := io.NextInt()

	if list[4]-list[0] > k {
		io.PrintLn(":(")
		return
	}
	io.PrintLn("Yay!")
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            int n;
            while((n = scn.nextInt()) > 0) {
                LinkedList<Integer> list = new LinkedList<>();
                for(int i = 1; i <= n; i++) {
                    list.add(i);
                }
                int k = scn.nextInt();
                int m = scn.nextInt() - 1;
                while(list.size() != 1) {
                    list.remove(m);
                    m = (k + m - 1) % list.size();
                }
                System.out.println(list.remove(0));
            }
        }
    }
}

Measured memory_bytes: 49088
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define o 200005
using namespace std;
int n,ans;
int a[o],f[o];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) f[a[i]]=f[a[i]-1]+1;
	for(int i=1;i<=n;i++) ans=max(ans,f[i]);
	cout<<n-ans<<endl;
}

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

int main() {
  int n,k,a[100000],ans=2000000000;
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  sort(a,a+n);
  for(int i=0; i<n-k+1; i++) {
    ans=min(ans,a[i+k-1]-a[i]);
  }
  cout << ans << endl;
}

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

int main(){
    string s;
    cin >> s;

    int a, z;
    for(int i=0; i<s.length(); i++){
        if(s[i] == 'A'){
            a = i;
            break;
        }
    }
    for(int i=s.length()-1; i>=0; i--){
        if(s[i] == 'Z'){
            z = i;
            break;
        }
    }
    cout << z - a + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt(), x[] = new int[n], y[] = new int[n];
		Integer[] indices = new Integer[n];
		for (int i = 0; i < n; i++) {
			indices[i] = i;
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		Arrays.sort(indices, Comparator.comparingInt(i -> x[i]));
		edge[] edges = new edge[2 * (n - 1)];
		for (int i = 0; i + 1 < n; i++)
			edges[i] = new edge(indices[i], indices[i + 1], x[indices[i + 1]] - x[indices[i]]);
		Arrays.sort(indices, Comparator.comparingInt(i -> y[i]));

		for (int i = 0; i + 1 < n; i++)
			edges[i + n - 1] = new edge(indices[i], indices[i + 1], y[indices[i + 1]] - y[indices[i]]);
		DSU dsu = new DSU(n);
		Arrays.sort(edges, (a, b) -> a.c - b.c);
		long ans = 0;
		for (edge edge : edges)
			if (dsu.union(edge.u, edge.v))
				ans += edge.c;
		out.println(ans);
		out.close();

	}

	static class DSU {
		int[] p, r;

		DSU(int n) {
			p = new int[n];
			r = new int[n];
			for (int i = 0; i < n; i++)
				p[i] = i;
		}

		boolean union(int x, int y) {
			x = findSet(x);
			y = findSet(y);
			if (x == y)
				return false;
			if (r[x] > r[y]) {
				p[y] = x;
			} else {
				p[x] = y;
				if (r[x] == r[y])
					r[y]++;
			}
			return true;

		}

		int findSet(int x) {
			if (p[x] == x)
				return x;
			else
				return p[x] = findSet(p[x]);
		}
	}

	static class edge {
		int u, v, c;

		edge(int x, int y, int z) {
			u = x;
			v = y;
			c = z;
		}
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

}

Measured memory_bytes: 51544
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

using namespace std;

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
typedef long long ll;

ll mod = 1e9+7;


int main(){
    int H,W;
    cin >> H >> W;
    vector<string> v(H+1);
    vector<vector<ll>> vr(H+1,vector<ll> (W+1,0));
    map<char,int> mp={{'.',1},{'#',0}};

    FOR(i,1,H+1) {
        cin >> v[i];}

    vr[1][1] = 1;
    FOR(i,1,H+1) {
        FOR(j,1,W+1) {
            if (v[i][j-1] == '.') {
                vr[i][j] += (vr[i-1][j]*mp[v[i-1][j-1]] + vr[i][j-1]*mp[v[i][j-2]])%mod;
                }

            else vr[i][j] = 0;
        }
    }

    cout << vr[H][W]%mod << endl;

}

Measured memory_bytes: 9216
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    L,R = ints_raw()
    neoR = min(L+2019,R+1)
    ans = 2019
    for i in range(L,neoR):
        for j in range(i+1,neoR):
            ans = min((i*j)%2019,ans)
    return ans
print(main())


Measured memory_bytes: 39408
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
int N,P,A[55];
int odd,even;
LL F[55];
void solve()
{
    if(P)
    {
        if(odd==0) cout << 0 << endl;
        else 
        {
            LL ans = F[max(0,odd-1)]*F[even];
            cout << ans << endl;
        }
    }
    else
    {
        if(even==0 && odd == 1) cout << 0 << endl;
        else
        {
            LL ans = F[max(0,odd-1)]*F[even];
            cout << ans << endl;
        }
           
    }
}
void init()
{
    F[0] = 1;
    for(int i=1;i<=50;i++) F[i] = F[i-1]*2;
}
int main()
{
    std::ios::sync_with_stdio(false);
    init();
    while(cin >> N >> P)
    {
        odd = even = 0;
        for(int i=1;i<=N;i++)
        {
            int x;
            cin >> x;
            if(x&1) odd++;
            else even++;
        }
        solve();
    }
    //system("pause");
    //printf("%lld\n", (x%mod+mod)%mod );
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;
typedef long long ll;

bool cmp(const tuple<string, int, int> &s1, const tuple<string, int, int > &s2) {
  if (get<0>(s1) < get<0>(s2)) {
    return true;
  }
  if (get<0>(s1) == get<0>(s2)) {
    return get<1>(s1) > get<1>(s2);
  } else {
    return false;
  }
}

int main() {
  int N;
  scanf("%d", &N);
  vector<tuple<string, int, int>> SP(N);
  for (int i = 0; i < N; i++) {
    char buf[100];
    int P;
    scanf("%s%d", buf, &P);
    SP[i] = make_tuple(string(buf), P, i+1);
  }
  sort(SP.begin(), SP.end(), cmp);
  for (int i = 0; i < N; i++) {
    printf("%d\n", get<2>(SP[i]));
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
int n, m, d;
double ans = 0;
signed main() {
	#ifdef aome
	in("aome.inp");	
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m >> d;
	/*
	Look at position i and i + 1. Number of ways for these 2 values to differ by d is
	2 * (n - d). Also the other m - 2 positions have n ^ (m - 2)
	This is repeated m - 1 times.
	*/
	double ans = 1.0 * (m - 1) * 2 * (n - d) / (1.0 * n * n);
	cout << fixed << setprecision(10);
	if (d == 0) cout << ans / 2.0;
	else cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處
char s[100005];
LL a[100005];
LL ab[100005];
LL abc[100005];
const LL m = 1000000007;
int main() {
    scanf("%s", s);
    int len = strlen(s);


    LL n = 1;
    if (s[0] == 'A') {
        a[0] = 1;
    } else if (s[0] == '?') {
        a[0] = 1;
        n = 3;
    }

    for (int i = 1; i < len; i++) {
        switch (s[i]) {
            case 'A':
            a[i] = (a[i-1] + n) % m;
            ab[i] = ab[i-1];
            abc[i] = abc[i-1];
            break;
            case 'B':
            a[i] = a[i-1];
            ab[i] = (ab[i-1] + a[i-1]) % m;
            abc[i] = abc[i-1];
            break;
            case 'C':
            a[i] = a[i-1];
            ab[i] = ab[i-1];
            abc[i] = (abc[i-1] + ab[i-1]) % m;
            break;
            case '?':
            a[i] = (a[i-1]*3 + n) % m;
            ab[i] = (ab[i-1]*3 + a[i-1]) % m;
            abc[i] = (abc[i-1]*3 + ab[i-1]) % m;
            n *= 3;
            n %= m;
            break;
        }
    }
    printf("%lld\n", abc[len-1]);
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int sum = tmp[0] + tmp[1];

	if ((sum&1) == 0)
	{
	    WriteLine(sum/2);
	}
	else
	{
	    WriteLine("IMPOSSIBLE");
	}
	    
    }
}


Measured memory_bytes: 13396
N,K,Q = map(int,input().split())
A =[input() for i in range(Q)]

import numpy as np
a = np.array([K]*N)
a -= Q

for i in range(Q):
    b = int(A[i])
    a[b-1] += 1

for j in range(N):
    if a[j]<=0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 20144
def solve(s):
    L = len(s)
    L -= 1
    if L % 2 == 1:
        L -= 1
    while L >= 2:
        if s[:L/2] == s[L/2:L]:
            return L
        L -= 2
    return 0


def main():
    s = raw_input().rstrip()
    print solve(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    if(a * b <= 0) {
        cout << "Zero" << endl;
    } else if(b > 0) {
        cout << "Positive" << endl;
    } else if(a < 0){
        cout << ((b - a + 1) % 2 == 0 ? "Positive" : "Negative") << endl;
    } else {
        cout << (abs(b) % 2 == 0 ? "Positive" : "Negative") << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		int sakoda = scan.nextInt();
		
		if (sakoda == 22) {
			System.out.println("Christmas Eve Eve Eve");
		}else if (sakoda == 23) {
			System.out.println("Christmas Eve Eve");
		}else if (sakoda == 24) {
			System.out.println("Christmas Eve");
		}else if (sakoda == 25) {
			System.out.println("Christmas");
		}
	}
}

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

void Main() {
  int n;
  cin >> n;
  int e[n + 1];
  memset(e, 0, sizeof(e));

  for (int i = 2; i < n + 1; i++) {
    int tmp = i;
    for (int j = 2; j < i + 1; j++) {
      while (tmp % j == 0) {
        e[j]++;
        tmp /= j;
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i < n + 1; i++) {
    if (e[i] >= 74) ans++;
    for (int j = i + 1; j < n + 1; j++) {
      if (e[i] >= 14 && e[j] >= 4) ans++;
      if (e[i] >= 4 && e[j] >= 14) ans++;
      if (e[i] >= 24 && e[j] >= 2) ans++;
      if (e[i] >= 2 && e[j] >= 24) ans++;
      for (int k = j + 1; k < n + 1; k++) {
        if (e[i] >= 4 && e[j] >= 4 && e[k] >= 2) ans++;
        if (e[i] >= 2 && e[j] >= 4 && e[k] >= 4) ans++;
        if (e[i] >= 4 && e[j] >= 2 && e[k] >= 4) ans++;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;
const int  Inv2 = (MOD+1)/2;

     signed main(){
  int x,y,z;
  cin>>x>>y>>z;swap(x,y);swap(x,z);
  cout<<x<<' '<<y<<' '<<z<<endl;

      
      
      }

        


Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap};
use std::io::{Write, BufWriter, stdout};
use std::iter::FromIterator;
fn main() {
    input! {
        N: usize,
        p: [usize1; N],
    }

    let mut count = 0;
    let mut ind = 0;
    for ind in 0..N {
        if ind == p[ind] {
            if ind == N-1 {
                p.swap(ind-1, ind);
            } else {
                p.swap(ind, ind+1);
            }
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 4352
//============================================================================
// Name        : k
// Date        : Wed Feb 20 21:33:22 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define pvi(x, v) if(v) pvar(x); fora(a, x) cout << a << " "; cout << "\n"
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

void solve() {
    int n, k; cin >> n >> k;
    vi aa(n, 0);
    fori (i, 0, n) {
        cin >> aa[i];
    }

    // dp[i] is true for first player if there are `i` stones left.
    vi dp(k + 1, 0);
    fori (i, 0, k + 1) {
        fora (a, aa) {
            if (i - a >= 0 && !dp[i - a]) {
                dp[i] = true;
            }
        }
    }
    output((dp[k] ? "First" : "Second"));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}



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

int main(){
  long long N,K;
  cin >> N >> K;
  vector<long long> A(N),F(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);
  for(int i=0;i<N;i++)  cin >> F.at(i);

  sort(A.begin(),A.end());
  sort(F.begin(),F.end(),greater<long long>());
  long long ng=-1;
  long long ok=1e13;
  while(ok-ng>1){
    long long mid=(ng+ok)/2;
    
    long long count=0;
    for(int i=0;i<N;i++){
      long long tmp=mid/F.at(i);
      count+=max((long long)0,A.at(i)-tmp);
    }
    if(count<=K)  ok=mid;
    else  ng=mid;
  }
  cout << ok << endl;

	return 0;
}


Measured memory_bytes: 3456
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			while (sc.hasNextInt()) {
				int d = sc.nextInt();
				int loopCount = 600 / d - 1;
				long sum = 0L;

				for (int i = 1; i <= loopCount; i++) {
					int x = i * d;
					int p = x * x;
					sum += p * d;
				}
				System.out.println(sum);
			}
		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 26136
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>

#define INF 1000000000000000000
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n";
long long parent[500001];
long long res[500001];
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if(a==b) return;
    res[a]+=res[b];
    res[b]=0;
    parent[b] = a;
}
int main()
{
    IOS;
    long long a,b,c,d,e,h,l,n,t,f,m,x,y,z,f1=0,flag=0,flag1=0,co=0,co1=0,co2=0,sum=0,sum1=0,ma=0,ma1=0,mi=1000000000000000001;
    long long g,co3=0,co4=0,co5=0,co6=0,co7=0,co8=0,mul=1,sum2=0,sum3=0,mu=1,mu1=1;
    double pi=2 * acos (0.0), dou;
    char ch,ch1,ch2;
    string str,str1,str2;
    cin>>a>>b;
    for(int i=1; i<=a; i++)
    {
        parent[i]=i;
        res[i]=1;
    }
    for(int i=0; i<b; i++)
    {
        cin>>c>>d;
        if(c>d)
        {
            union_sets(c,d);
        }
        else
        {
            union_sets(d,c);
        }
    }
    for(int i=1; i<=a; i++)
    {
        e=find_set(i);
        ma=max(ma,res[e]);
    }
    cout<<ma<<endl;
    return 0;
}


Measured memory_bytes: 12876
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

long long const MOD = 1000000007LL;

int main() {
    string s;
    cin >> s;

    int n = s.size();

    // 何人子供が集まるかをまとめるもの
    vector<int> res(n);
    // R に関する処理と L に関する処理の2つがあるので、2回ループする
    for (int i = 0; i < 2; i++) {
        // L が登場するまでの R の数を数える
        // もし L が出てきた時、その地点もしくは一つ前の地点に集まった子供たちを集めてあげて、捌けさせる
        int counter = 0;
        for (int j = 0; j < n; j++) {
            if (s[j] == 'L') {
                res[j] += counter / 2;
                // 切り上げをするための特殊処理
                res[j - 1] += (counter + 1) / 2;
                counter = 0;
            } else ++counter;
        }

        // 文字列を反転して、RとLを入れ替える。
        reverse(s.begin(), s.end());
        reverse(res.begin(), res.end());
        for (int i = 0; i < n; i++) {
            if (s[i] == 'L') s[i] = 'R';
            else s[i] = 'L';
        }
    }

    for (int i = 0; i < n; i++) cout << res[i] << endl;
}


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 min = 1000;
        int max = 1;
        for (int i = 0; i < n; ++i) {
            int a = sc.nextInt();
            min = Math.min(min, a);
            max = Math.max(max, a);
        }

        System.out.println(max - min);
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int b[10],z,x,n,i;
  cin >> n;
  for (n;n>0;n--) {
	  cin >> b[0] >> b[1] >> b[2] >> b[3] >> b[4] >> b[5] >> b[6] >> b[7] >> b[8] >> b[9];
      z=0; x=0;
	  for (i=0;i<10;i++) {
		  if (b[i]<x && b[i]<z) { i=20; break; }
		  if (z>x) { if (b[i]<z) x=b[i]; else z=b[i];} 
		  else {if (b[i]<x) z=b[i]; else x=b[i];} 
		   
	  }
	  if (i<20) cout << "YES" << endl; else cout << "NO" << endl;
  }
 return 0;
  }

Measured memory_bytes: 1152
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,K,Q = map(int,input().split())
A = (int(x) for x in sys.stdin.read().split())

score = [K-Q] * (N+1) 
for x in A:
    score[x] += 1

answer = '\n'.join('No' if x <= 0 else 'Yes' for x in score[1:])
print(answer)

Measured memory_bytes: 60980
from math import gcd
n,start = map(int,input().split())
x_ls = list(map(int, input().split()))
diff_ls = [0] * n

for i in range(n):
    diff_ls[i] = abs(start-x_ls[i])

ans = diff_ls[0]
for i in range(1,n):
    ans = gcd(ans,diff_ls[i])

print(ans)

Measured memory_bytes: 85572
#include <iostream>
#include <vector>

int main(){
  int N;
  std::cin >> N;

  std::vector<int> p_arr(N);
  for(int i = 0; i < N; i++) std::cin >> p_arr[i];

  int ans = 0;
  int ncont = 0;
  for(int i = 0; i < N; i++){
    if(p_arr[i] == i+1) ncont++;
    else{
      ans += (ncont+1)/2;
      ncont = 0;
    }
  }
  ans += (ncont+1)/2;
  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 640
#include <iostream>

using namespace std;
int memo_tmp[2002];
int memo[4002];

void solve()
{
	for(int i = 0; i <= 1000; ++i)
	{
		for(int j = 0; j <= 1000; ++j)
		{
			++memo_tmp[i + j];
		}
	}
	for(int i = 0; i <= 2000; ++i)
	{
		for(int j = 0; j <= 2000; ++j)
		{
			memo[i + j] += memo_tmp[i] * memo_tmp[j];
		}
	}
	int n;
	while(cin >> n)
	{
		cout << memo[n] << endl;
	}
}

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

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Union Find tree
//-------------------------------------------------
class UnionFind
{
private:
    ::std::vector<int> par;
    ::std::vector<int> rank;
public:
    UnionFind(int n):par(n), rank(n){
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x] = root(par[x]);
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx==ry) return;
        if (rank[rx]>rank[ry]){
            par[ry] = rx;
        }else{
            par[rx] = ry;
            if (rx==ry) rank[ry]++;
        }
    }
};

const int V = 101010;

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    UnionFind uf(2*V);
    rep(i,n){
        int x,y; cin>>x>>y; y+=V;
        uf.unite(x,y);
    }
    map<int,vi> conn;
    rep(i,2*V){
        int r = uf.root(i);
        conn[r].pb(i);
    }
    ll ans=0;
    for(auto &c:conn){
        vll cnt(2);
        for(auto v:c.se){
            cnt[v/V]++;
        }
        ans+=cnt[0]*cnt[1];
    }
    ans-=n;
    cout<<ans<<endl;
    return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, k;
    cin >> n >> k;
    vi h(n);
    rep(i, n) cin >> h[i];
    int ans = 0;
    rep(i, n) {
        if (h[i]>=k) ++ans;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int x;
	cin >> x;
	
	int ans = (x / 500) * 1000;
	x %= 500;
	ans += (x / 5) * 5;
	
	cout << ans << endl;
	
	return 0;
}


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

int main() {
    char X, Y;
    cin >> X >> Y;

    int x = X - 'A' + 10, y = Y - 'A' + 10;
    if (x < y) cout << '<' << endl;
    else if (x > y) cout << ">" << endl;
    else cout << '=' << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define mod 1000000007

long long calc(long long a,long long b){
  if(b == 0) return 1;
  if(b%2 == 0){
    long long d = calc(a,b/2);
    return (d*d)%mod;
  }
  return (a*calc(a,b-1))%mod;
}

long long comb(long long n,long long r){
  long long tmp = 1,ttmp = 1;
  for(int i = n;i >= n-r+1;i--) tmp = (tmp*i)%mod;
  for(int i = 1;i <= r;i++) ttmp = (ttmp*i)%mod;
  return (tmp*calc(ttmp,mod-2))%mod;
}

int main(void){
  int n, k;
  scanf("%d%d", &n, &k);

  for (int i = 1; i <= k; i++) {
    printf("%lld\n", (comb(n-k+1, i)*comb(k-1, i-1))%mod);
  }
  

  return 0;
}

Measured memory_bytes: 128
using System;

namespace codefestival_2016_qualC_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s.IndexOf("C") < s.LastIndexOf("F") && -1 < s.IndexOf("C"))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 3032
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
map<int, int> factor(int m) {
	map<int, int>res;
	for (int i = 2; i*i <= m; i++) {
		while (m%i == 0) {
			res[i]++;
			m /= i;
		}
	}
	if (m != 1)res[m]++;
	return res;
}

/*--------Library Zone!--------*/

int par[100005], Rank[100005];

void init(int n) {
	rep(i, n) {
		par[i] = i;
		Rank[i] = 0;
	}
}

int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (Rank[x] < Rank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

int n, m, p[100005], xx, yy;
signed main() {
	cin >> n >> m;
	init(n);
	rep(i, n) {
		cin >> p[i];
		p[i]--;
	}
	rep(i, m) {
		cin >> xx >> yy;
		unite(xx - 1, yy - 1);
	}
	int ans = 0;
	rep(i, n) {
		if (same(i, p[i]))ans++;
	}
	cout << ans << endl;
	endre;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double total = 0;
        for(int i=0;i<N;i++){
            double x = sc.nextDouble();
            String u = sc.next();
            if(u.equals("JPY")){
                total += x;
            } else {
                total += x * 380000;
        }

        }
        System.out.println(total);

    }
}

Measured memory_bytes: 24020
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int max;
		int min;
		int n = 0;
		int score;
		while(true) {
			int sum = 0;
			int ave = 0;
			n = sc.nextInt();
			if(n == 0){ break; }
			score = sc.nextInt();
			max = score;
			min = score;
			sum += score; 
			for(int i = 0 ; i < n-1; i++){
				score = sc.nextInt();
				if(score > max) {
					max = score;
				}
				if(score < min) {
					min = score;
				}
				sum += score; 	
			}
			sum = sum - max - min;
			ave = sum / (n-2);
			System.out.println(ave);
		}
	}
}

Measured memory_bytes: 20952
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* struct for mod Calculation*/
struct mint {
    ll x;
    mint(ll x = 0):x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
/* global variables */
int H, W, K;
vector<vector<int> > lines;
vector<vector<mint> > dp;
/* function */
void makeLines() {
    int upper = 1 << (W - 1);
    vector<int> tmp(W - 1);
    for (int b = 0; b < upper; b++) {
        for (int i = 0; i < W - 1; i++) tmp[i] = b >> i & 1;
        bool canLine = true;
        for (int i = 0; i < W - 2; i++) {
            if (tmp[i] + tmp [i + 1] == 2) {
                canLine = false;
                break;
            }
        }
        if (canLine) lines.push_back(tmp);
    }
}
void calcDPTable() {
    dp.assign(H + 1, vector<mint>(W));
    dp[0][0] = 1;
    for (int i = 0; i < H; i++) {
        for (vector<int> line : lines) {
            for (int j = 0; j < W; j++) {
                if (j > 0 && line[j - 1]) { dp[i + 1][j - 1] += dp[i][j]; }
                else if (j < W - 1 && line[j]) { dp[i + 1][j + 1] += dp[i][j]; }
                else { dp[i + 1][j] += dp[i][j]; }
            }
        }
    }
}

void calcAns() { cout << dp[H][K - 1].x << '\n'; }
/* main */
int main(){
    cin >> H >> W >> K;
    if (W == 1) { cout << 1 << '\n'; return 0; }
    makeLines();
    calcDPTable();
    calcAns();
}


Measured memory_bytes: 256
import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [n, k] <- readInts
  print $ k * product (replicate (n - 1) (k - 1))

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

toTup2 :: [[a]] -> [(a, a)]
toTup2 = map (\ys -> case ys of y : z : zs -> (y, z))

encIdx2 :: Int -> (Int, Int) -> Int
encIdx2 mx (y, x) = y * mx + x

decIdx2 :: Int -> Int -> (Int, Int)
decIdx2 mx idx = (idx `div` mx, idx `mod` mx)

encIdx3 :: (Int, Int) -> (Int, Int, Int) -> Int
encIdx3 (my, mx) (z, y, x) = z * my * mx + y * mx + x

decIdx3 :: (Int, Int) -> Int -> (Int, Int, Int)
decIdx3 (my, mx) idx = (z, y, x)
  where
    basez = my * mx
    z = idx `div` basez
    y = (idx `mod` basez) `div` mx
    x = idx `mod` mx


Measured memory_bytes: 380
N,M=map(int,input().split())
S=input()
r=[]
p=N
while p>0:
    try:
        n=p-max(0,p-M)-S[max(0,p-M):p].index('0')
    except:
        print(-1)
        exit()
    r.append(n)
    p-=n
print(*r[::-1])

Measured memory_bytes: 6372
#include <iostream>
#include <queue>
#include <tuple>
#include <algorithm>
#include <limits>

using namespace std;
using lli = long long int;
using tiiii = std::tuple<lli, lli, lli, lli>;
using pii = std::pair<int, int>;
using vpii = std::vector<pii>;

vpii A[100001];

lli P[100001];

bool B[100001] = {};

int main() {

	int N, M;
	cin >> N >> M;

	for (int i = 0; i < N; i++) {
		P[i] = numeric_limits<lli>().max();
	}

	for (int i = 0; i < M; i++) {
		int l, r, d;
		std::cin >> l >> r >> d;

		A[l - 1].push_back({ r - 1,d });
		A[r - 1].push_back({ l - 1,-1 * d });
	}

	std::queue<int> q;
	for (int i = 0; i < N; i++) {
		q.push(i);

		while (!q.empty()) {
			int i = q.front();
			q.pop();
			if (!B[i]) {
				B[i] = true;
				if (P[i] == numeric_limits<lli>().max()) {
					P[i] = 0;
				}

				for (int j = 0; j < A[i].size(); j++) {
					if (P[A[i][j].first] == numeric_limits<lli>().max()) {
						P[A[i][j].first] = P[i] + A[i][j].second;
					}
					else {
						if (P[A[i][j].first] != P[i] + A[i][j].second) {
							std::cout << "No" << endl;
							return 0;
						}
					}
					q.push(A[i][j].first);
				}
			}
		}
	}
	std::cout << "Yes" << std::endl;

	return 0;
}

Measured memory_bytes: 10484
M=2019
A=[false]*-~M
gets
a=gets.split.map &:to_i
a.each{|e|
	A[e]=true
}
gets
gets.split.map(&:to_i).each{|i|
	i-=1
	if a[i]+1<=M && !A[a[i]+1]
		A[a[i]]=false
		a[i]+=1
		A[a[i]]=true
	end
}
p *a


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

int main() {
 int n;
 cin >> n;
 vector<int> p(n);
 for(int i = 0; i < n; i++) cin >> p[i];
 int ans = 0;
 for(int i = 1; i < n - 1; i++) {
 if((p[i - 1] < p[i]) && (p[i] < p[i + 1])) ans++;
 else if((p[i - 1] > p[i]) && (p[i] > p[i + 1])) ans++;
 }
 cout << ans << endl;
 return 0;
}


Measured memory_bytes: 3600
import math
A, B, X = map(int, input().split())
h = X / (A*A)
r = 0
deg = 0
if (2 * X) - (B * A * A) > 0:
  r = math.atan(2 * (B-h) / A)
elif (2 * X) - (B * A * A) == 0:
  r = math.atan(B / A)
else:
  h = (2 * X) / (A * B)
  r = math.atan(B / h)
deg = math.degrees(r)
print(deg)

Measured memory_bytes: 62356
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int read()
{
	char c=getchar();int x=0,f=1;
	while(c>'9'||c<'0'){if(c='-'){f=-1;}c=getchar();}
	
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*f;
}
int main()
{cin>>a>>b>>c;
	cout<<(a+b)*c/2<<endl;
	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

const int MX = 100005;

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

	int q;
	cin >> q;
	for(int i=0;i<q;++i){
		int b,c;
		cin >> b >> c;
		tot -= b*cnt[b];
		tot -= c*cnt[c];
		cnt[c] += cnt[b]; cnt[b] = 0;
		tot += b*cnt[b];
		tot += c*cnt[c];
		cout << tot << endl;
	}
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    vector<int> h(n);
    for(int &i : h) cin >> i;

    bool flg=1;
    for(int i=n-2; i>=0; --i){
        if(h[i]<=h[i+1]){
            continue;
        }else if(h[i]-1==h[i+1]){
            --h[i];
        }else{
            flg=0;
            break;
        }
    }
    cout << (flg ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int ans;
int main(void){
	int r,g,b,n; cin>>r>>g>>b>>n;
	for(int i=0;i<3005;i++){
		for(int j=0;j<3005;j++){
			int k=n-r*i-g*j;
			if(k>=0&&k%b==0){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 256
import collections

n = int(input())

s = set()
que = collections.deque()
que.appendleft(0)
while que:
    v = que.pop()
    for c in '357':
        nv = v*10 + int(c)
        if nv <= n and nv not in s:
            s.add(str(nv))
            que.appendleft(nv)

ans = 0
for i in s:
    add = 1
    for c in '357':
        if c not in i:
            add = 0
    ans += add
print(ans)


Measured memory_bytes: 8008
#include <iostream>

using namespace std;

int main()
{
    ios :: sync_with_stdio(false);
    cin.tie(0);
    
     int n,a,b;
     
     cin>>n>>a>>b;
     
     if((n*a)>=b)
     {
         cout <<b << "\n";
     }
     else
     {
         cout << n*a<<"\n";
     }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
    if(b>a)
    {
        cout<<1;
        return 0;
    }
    int ans=a/((b*2)+1);
    if(a%((b*2)+1)!=0) ans++;
    cout<<ans;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
const int MAX_V = 330;
int V;

long long dist[MAX_V][MAX_V];

void init_dist() {
  for (int i = 0; i < MAX_V; ++i) {
    for (int j = 0; j < MAX_V; ++j) {
      if (i == j) {
        dist[i][j] = 0;
      } else {
        dist[i][j] = INF;
      }
    }
  }
}

void warshall_floyd() {
  // 1-indexed
  for (int k = 1; k <= V; ++k) {
    for (int i = 1; i <= V; ++i) {
      for (int j = 1; j <= V; ++j) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}

ll N, M;
struct edge {
  ll from, to, cost;
};
edge es[2000];

int main() {
  cin >> N >> M;
  V = N;
  init_dist();
  rep(i, 0, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    dist[a][b] = c;
    dist[b][a] = c;
    es[i] = edge{a, b, c};
  }

  warshall_floyd();

  ll ans = 0;
  rep(i, 0, M) {
    auto cv = es[i];
    bool used = false;
    repe(i, 1, N) {
      if (dist[i][cv.from] + cv.cost == dist[i][cv.to]) {
        used = true;
        break;
      }
    }
    if (!used) {
      ans++;
    }
  }

  cout << ans;
}


Measured memory_bytes: 4508
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100006;
int a[] = {100,101,102,103,104,105};
bool ok[maxn];
int main() {
    ios::sync_with_stdio(0);
    ok[0] =1;
    int x;
    cin>>x;
    for(int i=1;i<=x;i++) {
        for(int j=0;j<6;j++) {
            int pre = i-a[j];
            if(pre<0) continue;
            ok[i] |= ok[pre];
        }
    }
    int ans = ok[x];
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 384
import sys

f = sys.stdin
N = int(f.readline())
T = []
S = {}
for i in range(N):
    s, t = f.readline().split(' ')
    T.append(int(t))
    S[s] = i
X = f.readline()[:-1]
time = sum(T[S[X]+1:])
print(time)

Measured memory_bytes: 3060