akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	int s=n;
	
	
	int a;
	int c=1;
	int sum=0;
	int w=10;
	while (1) {

		
		
		a = s% w;
		s = s / w;
		
		sum = sum + a;
		if (s == 0) {
			break;
		}
	
	}
	if (n%sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}
//1234
//123 4
//12 3
//1 2



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

string S;

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

  cin >> S;

  if (S.substr(0, 7) == "keyence" || S.substr(S.length()-7) == "keyence") {
      cout << "YES" << endl;
      return 0;
  }

  for (int l = 0; l < S.length()-1; ++l) {
      for (int r = l+1; r < S.length(); ++r) {
          string tmp;
          tmp = S.substr(0, l+1);
          tmp += S.substr(r);
          if (tmp == "keyence") {
              cout << "YES" << endl;
              return 0;
          }
      }
  }

  cout << "NO" << endl;

  return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x,ll n,int md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}

int main(){
    fastio;
    //clock_t tm = clock();
    int n;string s;
    cin>>s;n=s.length();
    if(n%2==1){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<n;i+=2){
        if(s[i]!='h' or s[i+1]!='i'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,q = LI()
    s = "$" + S()

    lst = [0 for _ in range(n+1)]
    for i in range(n):
        before = s[i]
        after = s[i+1]
        if before == "A" and after == "C":
            lst[i+1] = lst[i] + 1
        else:
            lst[i+1] = lst[i]
    for _ in range(q):
        l,r = LI()
        ans = lst[r] - lst[l]
        print(ans)
main()

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

public class Main {
  private static int solve(int h, int w, int n) {
    int max = Math.max(h, w);
    if (n % max == 0) {
      return n / max;
    } else {
      return n / max + 1;
    }
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int h = reader.nextInt();
    int w = reader.nextInt();
    int n = reader.nextInt();
    out.println(solve(h, w, n));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 23252
package main

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

var mat [][]int
var visited []bool
var ans []int
var outindex map[string]int
var k int

func dfs(cur, color int) {
	nexts := mat[cur]
	i, nxcolor := 0, 1
	for i < len(nexts) {
		if visited[nexts[i]] {
			i++
			continue
		}
		if nxcolor == color {
			nxcolor++
			continue
		}

		visited[cur] = true
		outi := outindex[strconv.Itoa(cur)+"-"+strconv.Itoa(nexts[i])]
		ans[outi] = nxcolor

		dfs(nexts[i], nxcolor)

		k = max(k, nxcolor)
		nxcolor++
		i++
	}
}

func main() {
	n := readInt()

	mat = make([][]int, n)
	for i := range mat {
		mat[i] = make([]int, 0)
	}

	outindex = make(map[string]int)
	for i := 0; i < n-1; i++ {
		a, b := readInt()-1, readInt()-1
		mat[a] = append(mat[a], b)
		mat[b] = append(mat[b], a)

		aa, bb := strconv.Itoa(a), strconv.Itoa(b)
		outindex[aa+"-"+bb] = i
		outindex[bb+"-"+aa] = i

	}

	visited = make([]bool, n)
	visited[0] = true
	ans = make([]int, n-1)

	dfs(0, -1)

	fmt.Println(k)
	for i := range ans {
		fmt.Println(ans[i])
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 47488
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    int N;
    cin >> N;
    int T[100];
    int sum = 0;
    for(int i=0; i<N; i++){
        cin >> T[i];
        sum += T[i];
    }
    int M;
    cin >> M;
    for(int i=0; i<M; i++){
        int p,x;
        cin >> p >> x;
        cout << sum - T[p-1] + x << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
  ll n,ans=0; cin>>n;
  vector<ll>v(n);
  rep(i,n) cin>>v[i];
  sort(all(v));
  for(ll i=0;i<n-2;i++){
  	for(ll j=i+1;j<n-1;j++){
    	for(ll k=j+1;k<n;k++){
      		if(v[k]<v[i]+v[j]) ans++;
      }
    }
  }  
  cout<<ans<<endl;
}

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

void resuelveCaso(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) {
		cout << "ACL";
	}
	cout << '\n';
}

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


Measured memory_bytes: 3592
c_mod=1000000007
n,m = map(int,input().split())

step=[0]*(n+1)
for _ in range(m):
    a=int(input())
    step[a-1]=-1

if step[0]!=-1:
    step[0]=1
if step[1]!=-1:
    step[1]=1
for i in range(n-1):
    if step[i]==-1:
        continue
    if step[i+1]!=-1:
        step[i+1]+=step[i]
    if step[i+2]!=-1:
        step[i+2]+=step[i]
print(step[n-1]%c_mod)


Measured memory_bytes: 462708
object Main extends App {
	override def main(args: Array[String]){
		val sc = new java.util.Scanner(System.in)
		
		val h = sc.nextInt
		val w = sc.nextInt
		
		val s = new SpreadSheet(h,w);
		for(i <- (0 until h) ; j <- (0 until w)){
			s(i,j) = sc.nextInt
		}
		s.calc
		
		for(i <- (0 to h); j<- (0 to w)){
			print(s(i,j))
			j match{
				case n:Int if n == w => println
				case _ => print(" ")
			}
		}
	}
	
}

class SpreadSheet(val h: Int , val w :Int){
	val matrix = Array.ofDim[Int](h+1,w+1)
	def update(i:Int , j:Int , newValue:Int):Unit = {
		matrix(i)(j) = newValue
	}
	def apply(i:Int,j:Int): Int = matrix(i)(j)
	
	def calc:Unit = {
		for(i <- (0 until h) ; j <- (0 until w)){
			matrix(h)(w) = matrix(h)(w) + matrix(i)(j)
			matrix(h)(j) = matrix(h)(j) + matrix(i)(j)
			matrix(i)(w) = matrix(i)(w) + matrix(i)(j)
		}
	}
}

Measured memory_bytes: 60908
#include <iostream>

int main()
{
	int N;
	std::cin >> N;
	int P;
	int sum;
	int JK = 1;
	std::cin >> sum;
	for (int i = 1; i < N; i++) {
		std::cin >> P;
		if (P < sum) {
			sum = P;
			JK++;
		}
	}

	std::cout << JK;
}

Measured memory_bytes: 256
object Main extends App{
import scala.io.StdIn._
val Array(h,w) = readLine.split("\\s").map(_.toInt)

var a:Seq[String] = Seq()

for (i<- 1 to h){
  a = a :+ ("#" + readLine() + "#")
}

a = ("#" *(w+2)) +: a :+ ("#" *(w+2))

a.foreach {println}
}

Measured memory_bytes: 26308
import java.util.*;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        list.add(s);

        int index = 1;
        while(true) {
            index++;
            int value = s % 2 == 0 ? s / 2 : 3 * s + 1;
            if (list.contains(value)) {
                break;
            } else {
                list.add(value);
                s = value;
            }
        }

        // 出力
        System.out.println(index);
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
int[] X;
int n=0;
X=new int[10001];
Scanner sc = new Scanner(System.in);
for (int i = 1; ; i++) {
int x = sc.nextInt();
if(x==0)break;
System.out.println("Case "+i+": "+x);
}
}
}


Measured memory_bytes: 41196
#!/usr/bin/env python3
import sys


def solve(N: int):
    if N > 999:
        print("ABD")
    else:
        print("ABC")

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
//max=({});
//条件式が真ならwhileの中身を回し続ける

bool flag[1050000];

int main() {
	double k, n;
	cin >> n >> k;
	vector<double>p(n);
	rep(i, n) {
		cin >> p[i];
		p[i] = (1 + p[i]) / 2;
	}
	double ans = 0;
	vector<double>S(n, 0);
	for (int i = 0;i < k;++i) {
		ans += p[i];
	}
	S[0] = ans;
	for (int i = 0;i < n - k;++i) {
		double res = S[i] + p[k + i] - p[i];
		ans = max(ans, res);
		S[i + 1] = res;
	}
	printf("%.12f\n", ans);
	return 0;
}


Measured memory_bytes: 3328
import sys
from itertools import combinations
n = int(input())

for i in range(1, 1000):
  if n == i*(i+1)//2:
    print("Yes")
    print(i+1)
    anslist = [[] for _ in range(i+1)]
    for j, v in enumerate(combinations([int(x) for x in range(i+1)], r=2)):
      anslist[v[0]].append(j+1)
      anslist[v[1]].append(j+1)
    for ans in anslist:
      print(len(ans), *ans)
    sys.exit()

print("No")

Measured memory_bytes: 17360
N, x = map(int, input().split())
a = list(map(int, input().split()))
B = a[:] # 魔法の回数がk以下のときのスライムjをてに入れる最小の時間（ただし、魔法を唱える時間は最後に
         # 加えるのでここでは除いている
ans = 10 ** 13
for i in range(N):
    for j in range(N):
        if B[j] > a[j - i]:
            B[j] = a[j - i]
    tmp = sum(B) + i * x
    if ans > tmp:
        ans = tmp

print(ans)


Measured memory_bytes: 3188
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    XL=LLIN(N)
    XL.sort(key=lambda x: x[0]+x[1])
    dp = [1]*N
    now = -inf
    ans = 0
    for i,(x,l) in enumerate(XL):
        if now <= x-l:
            now = x+l
            ans += 1

        idx = bisect_left(XL,[x-l,0])
        if idx:
            dp[i] = dp[idx-1] + 1
        if i:
            dp[i] = dp[i-1]

        # dp[i] = bisect_left(XL,x-l)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 32996
import java.io.*;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{	
		
		 Scanner cthanh = new Scanner(System.in);
        int x;
        int y;
        x= cthanh.nextInt(); y= cthanh.nextInt();
        System.out.println((x * y) + " " + (2*x + 2*y));		
	}
}
		
    
    
   

Measured memory_bytes: 25900
def main():
    _ = input()
    A = list(map(int, input().split()))
    max_step = 0
    tmp = 0
    for i in range(len(A)-1):
        if A[i] >= A[i+1]:
            tmp += 1
        else:
            max_step = max(max_step, tmp)
            tmp = 0

    else:
        max_step = max(max_step, tmp)

    print(max_step)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15020
/*
float like a butterfly
sting like a Bee

?#%^*&~`!  YOUR ONLY LIMIT IS YOUR MIND

*/

#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_bsck
#define pop pop-back
#define S second
#define F first
#define q '\n'
#define w .size()

using namespace std;

int main() {
	fast;
	long long int delta = 998244353, a, b, c, d, dp[4000][4000];
	cin >> a >> b >> c >> d;
	dp[a][b] = 1;
	for (long long int i = b + 1; i <= 3020; i++){
		dp[a][i] = dp[a][i - 1] * a;
		dp[a][i] %= delta;
	}
	for (long long int i = a + 1; i <= 3020; i++){
		dp[i][b] = dp[i - 1][b] * b;
		dp[i][b] %= delta;
	}
	for (long long int i = a + 1; i <= 3020; i++){
		for (long long int j = b + 1; j <= 3020; j++){
			long long int x, y, z;
			x = (i * dp[i][j - 1]) % delta;
			y = (j * dp[i - 1][j]) % delta;
			z = (((i - 1) * (j - 1) * dp[i - 1][j - 1])) % delta;
			dp[i][j] = x + y;
			dp[i][j] += delta;
			dp[i][j] -= z;
			dp[i][j] %= delta;
		}
	}
	cout << dp[c][d];
}


Measured memory_bytes: 87444
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int n;
    cin>>n;
    unordered_map <int,int> mp;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    vector <pair<int,int>> arr;
    for(auto i = mp.begin();i!=mp.end();i++)
    {
        arr.push_back({i->first,i->second});
    }
    int count = 0;
    for(int i=0;i<arr.size();i++)
    {
        for(int j=i+1;j<arr.size();j++)
        {
            for(int k = j+1;k<arr.size();k++)
            {
                if(arr[i].first+arr[j].first>arr[k].first&&arr[i].first+arr[k].first>arr[j].first&&arr[k].first+arr[j].first>arr[i].first)
                {
                    count+=arr[i].second*arr[j].second*arr[k].second;
                }
            }
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int n;
map<int, int> m;

int solve()
{
  int ans = 0;
  for (auto e : m) {
    int k = e.first;
    int v = e.second;
    if (v < k)
      ans += v;
    else
      ans += v - k;
  }
  return ans;
}

int main()
{
  cin >> n;
  int a;
  REP(i, n) {
    cin >> a;
    m[a]++;
  }
  cout << solve() << endl;
}


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

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

    vector<double> v(n);
    vector<double> d(n-1);

    for(int i=0; i<n; i++){
        cin>>v[i];
    }

    sort(v.begin(),v.end());

    d[0]=(v[0]+v[1])/2;

    for(int i=1; i<n-1; i++){
        d[i]=(d[i-1]+v[i+1])/2;
    }

    cout<<d[n-2]<<endl;
}



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

main(){
    string num;
    cin >> num;
    int soma = 0;
    bool f = 0;
    int sz = num.size();
    for(int i= sz-1;i>=0;i--){
        int d = num[i]-'0';
        if(f)
            d++;
        f = 0;

        if(d > 5 or (d == 5 and i > 0 and num[i-1] >= '5')){
            soma += (10-d);
            f = 1;
        }else {
            soma += d;
        }
    }
    if(f) soma++;

    cout<<soma<<endl;


}

Measured memory_bytes: 1412
#include <iostream>
#include <string>
#include <algorithm>
int main() {
	int N, A = 0;
	char S[100];
	std::cin >> N;
	for (int i = 0; i < N; i++)
		std::cin >> S[i];

	for (int i = 0; i < N; i++)
		if (S[i] == 'Y') {
	std::cout << "Four" << std::endl;
	return 0;
}
	std::cout << "Three" << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using i64=long long int;

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

    int cnt[3] = {};
    cnt[0] = 1;
    long long int n = 3;
    int ans = 0;
    while (n <= N) {
        bool f = true;
        for (int i = 0; i < 3; ++i) {
            if (cnt[i] == 0) {
                f = false;
                break;
            }
        }
        if (f) ++ans;


        int cr = 1;
        long long int dgt = 1;
        while (cr > 0) {
            cr = 0;
            long long int dn = (n%(dgt*10))/dgt;
            if (dn == 0) {
                ++cnt[0];
                n += 3 * dgt;
            } else if (dn == 3) {
                --cnt[0];
                ++cnt[1];
                n += 2 * dgt;
            } else if (dn == 5) {
                --cnt[1];
                ++cnt[2];
                n += 2 * dgt;
            } else {
                --cnt[2];
                ++cnt[0];
                cr = 1;
                n -= 4 * dgt;
            }
            dgt *= 10;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define ll long long 

int main()
{
	ll a,b,c,d;
	vector<ll> v,ve;
	
	cin >> a >> b;
	for(ll i=0;i<a;i++)
	{
		cin >> c;
		v.push_back(c);
	}
	sort(v.begin(),v.end());
	ve.assign(b+1,0);
	ve[v[0]]=1;
	for(ll i=v[0]+1;i<=b;i++)
	{
		for(ll int j=0;j<v.size();j++)
		{
			if(i-v[j]<0)
			break;
			if(ve[i-v[j]]==0)
			{
				ve[i]=1;
			}
		}
	}
	if(ve[b]==1)
	{
		cout << "First";
	}
	else
	{
		cout << "Second";
	}
}

Measured memory_bytes: 1024
n = int(input())
if n==3:
    print(2,5,63)
elif n==4:
    print(2,5,20,63)
elif n==5:
    print(2,5,20,63,1260)
else:
    ans = []
    if n<1000:
        ans = [2,3,4,8,9,10]
        for i in range(n-6):
            ans.append(6*(i+1))
    else:
        m=-(-n//8)
        a = []
        for i in range(1, 12*m+1):
            if i % 2 == 0 or i % 3 == 0:
                a.append(i)
        b = 8*m-n
        for x in a:
            if x%6==0 and b>0:
                b-=1
            else:
                ans.append(x)
    print(' '.join(map(str, ans)))

Measured memory_bytes: 41840
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    H, W = map(int, readline().split())
    C = [list(map(int, readline().split())) for _ in range(10)]
    A = list(map(int, read().split()))

    counter = Counter(A)

    for k in range(10):
        for i in range(10):
            for j in range(10):
                if C[i][j] > C[i][k] + C[k][j]:
                    C[i][j] = C[i][k] + C[k][j]

    ans = 0
    for n, freq in counter.items():
        if n not in (-1, 1):
            ans += C[n][1] * freq

    print(ans)
    return


if __name__ == '__main__':
    main()


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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;}
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

template<class T,class F>
struct segtree{
  int n;
  T e;
  F f;
  std::vector<T> dat;

  segtree(){}
  segtree(int sz,T _e,F _f):e(_e),f(_f){
    n = 1;
    while(n<=sz)n<<=1;
    dat.resize(2*n,e);
  }
  segtree(std::vector<T> const& v,T _e,F _f):e(_e),f(_f){
    build(v);
  }
  void build(std::vector<T> const& v){
    n = 1;
    int sz = v.size();
    while(n<=sz)n<<=1;
    dat.resize(2*n,e);
    for(int i=0;i<sz;++i){
      dat[i+n] = v[i];
    }
    for(int i=n-1;i>0;--i){
      dat[i] = f(dat[i<<1],dat[i<<1|1]);
    }
  }
  void modify(int p,T v){
    for(dat[p+=n]+=v;p>1;p>>=1){
      dat[p>>1] = f(dat[p],dat[p^1]);
    }
  }
  T query(int l,int r){
    T res = e;
    for(l+=n,r+=n;l<r;l>>=1,r>>=1){
      if(l&1){
        res = f(res,dat[l]);
        l++;
      }
      if(r&1){
        r--;
        res = f(res,dat[r]);
      }
    }
    return res;
  }
  T operator[](int k){
    return query(k,k+1);
  }
};

int main(){

  int n,k;
  cin>>n>>k;
  vector<ll> a(n);
  cin>>a;
  rep(i,n)a[i]-=k;

  vector<ll> sum(n+1);
  rep(i,n)sum[i+1]=sum[i]+a[i];

  auto compress = [](vector<ll> v){
    auto s = v;
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(),s.end()),s.end());
    for(auto& vi:v){
      int idx = lower_bound(s.begin(),s.end(),vi)-s.begin();
      vi = idx;
    }
    return v;
  };

  auto v = compress(sum);
  //for(auto x:sum)cout<<x<<" ";cout<<endl;
  //for(auto x:v)cout<<x<<" ";cout<<endl;
  auto f =[](auto a,auto b){return a+b;};
  segtree<ll,decltype(f)> seg(n+1,0,f);
  auto calc = [](ll x){return x*(x-1)/2;};
  ll ans = 0;
  rep(i,n+1){
    ll t = seg.query(v[i]+1,n+1);
    seg.modify(v[i],1);
    ans += i-t;
    //dump(t);
  }
  cout<<(ans)<<endl;

}


Measured memory_bytes: 7216
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

template <class T>
class EdgeBase
{
public:
    int to, rev;
    T cap;
    EdgeBase(){};
    EdgeBase(int to0, T cap0){to = to0; cap = cap0;}
    EdgeBase(int to0, T cap0, int rev0){to = to0; cap = cap0; rev = rev0;}
};
typedef EdgeBase<long long> Edge;

template<class T>
T maxFlow(const vector<vector<EdgeBase<T> > >& edges0, int source, int sink)
{
    static const T INF = numeric_limits<T>::max();
    static const T EPS = static_cast<T>(1.0e-10);
    static vector<vector<EdgeBase<T> > > edges;
    static vector<bool> used;

    class Func{
    public:
        static T dfs(int s, int t, T f){
            if(s == t)
                return f;
            used[s] = true;
            for(auto& e : edges[s]){
                if(!used[e.to] && e.cap > EPS){
                    T g = dfs(e.to, t, min(f, e.cap));
                    if(g > EPS){
                        e.cap -= g;
                        edges[e.to][e.rev].cap += g;
                        return g;
                    }
                }
            }
            return 0;
        }
    };

    if(source == sink)
        return INF;

    int n = edges0.size();
    edges.assign(n, vector<EdgeBase<T> >());
    for(int i=0; i<n; ++i){
        for(const auto& e : edges0[i]){
            edges[i].push_back(EdgeBase<T>(e.to, e.cap, edges[e.to].size()));
            edges[e.to].push_back(EdgeBase<T>(i, 0, edges[i].size()-1));
        }
    }

    T ret = 0;
    for(;;){
        used.assign(n, false);
        T f = Func::dfs(source, sink, INF);
        if(f <= EPS)
            return ret;
        ret += f;
    }
}


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

    int source = 0;
    int sink = n + 1;
    vector<vector<Edge> > edges(n+2);
    long long ans = 0;
    for(int i=1; i<=n; ++i){
        edges[source].push_back(Edge(i, max(0, a[i-1])));
        edges[i].push_back(Edge(sink, max(0, -a[i-1])));
        ans += max(0, a[i-1]);
        for(int j=i*2; j<=n; j+=i)
            edges[j].push_back(Edge(i, LLONG_MAX/2));
    }

    ans -= maxFlow(edges, source, sink);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long

using namespace std;

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

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int main()
{
    LL n, t;
    cin >> n >> t;

    LL ans = 0, x = 0;
    for(int i = 0; i < n; i++){
        LL a;
        cin >> a;

        if(x < a)
            ans += t;
        else
            ans += a + t - x;
        x = a + t;
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		String s;
		for(;;)
		{
			s = sc.nextLine();
			if (s.charAt(0) == '.') break;
			
			s = uvoa(s);
			for(;;)
			{
				int before = s.length();
				s = s.replaceAll("\\(\\)|\\[\\]", "");
				if (before == s.length()) break;
			}
			System.out.println(s.charAt(0) == '.' ? "yes" : "no");
		}
	}
	
	private static String uvoa(String s)
	{
		StringBuilder buf = new StringBuilder();
		for (int i = 0; i < s.length(); i++)
		{
			char c = s.charAt(i);
			if ("()[].".indexOf(c) != -1) buf.append(c);
		}
		return buf.toString();
	}
}

Measured memory_bytes: 13000
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i = 1;
        while(true){
            int x = sc.nextInt();
            
            if(x==0){
                break;
                
            }
            System.out.println("Case "+i+": "+x);
      	  i++;
        }
    }
}


Measured memory_bytes: 41696
import bisect

def solve():
    N, K = map(int, input().split())
    x = list(map(int, input().split()))
    if K == 0:
        return 0
    if 0 in x:
        x.remove(0)
        K -= 1
    if K == 0:
        return 0

    x.sort()

    mid = bisect.bisect_left(x, 0)
    p = [0]
    m = [0]
    for i in range(mid, N):
        p.append(x[i])
    for i in range(mid - 1, -1, -1):
        m.append(-x[i])
    pcnt = len(p) - 1
    mcnt = len(m) - 1
    inf = 1 << 60
    min_sc = inf
    for i in range(K+1):
        if mcnt < K - i:
            continue
        if pcnt < i:
            continue
        if m[K - i] > p[i]:
            sc = m[K - i] + p[i] * 2
        else:
            sc = m[K - i] * 2 + p[i]
        min_sc = min(min_sc, sc)
    return min_sc

ans = solve()
print(ans)


Measured memory_bytes: 14660
#include <bits/stdc++.h>
#define forna(i,a,n) for(int i=a;i<n;i++)
typedef long long int lli;
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli t,n,m;string s;

cin>>n>>m;
lli a[n],sum=0;
forna(i,0,n) cin>>a[i];
sort(a,a+n);
forna(i,0,m) sum+=a[i];
cout<<sum<<"\n";
}


Measured memory_bytes: 3656
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_UN = MAX_N * 2;

const int INF = 1 << 28;

/* typedef */

typedef map<string,int> msi;

/* global variables */

int n, un;
msi umap;
int dp[MAX_UN][MAX_UN];

/* subroutines */

int unit2id(string unit) {
  msi::iterator mit = umap.find(unit);
  if (mit == umap.end()) {
    umap[unit] = un;
    return un++;
  }
  return mit->second;
}

/* main */

int main() {
  for (;;) {
    cin >> n;
    if (n == 0) break;

    un = 0;
    umap.clear();

    for (int i = 0; i < 2 * n; i++) {
      for (int j = 0; j < 2 * n; j++) dp[i][j] = INF;
      dp[i][i] = 0;
    }

    for (int i = 0; i < n; i++) {
      string dmy0, ua, dmy1, exp, ub;
      cin >> dmy0 >> ua >> dmy1 >> exp >> ub;

      int aid = unit2id(ua);
      int bid = unit2id(ub);

      int sign = 1;
      int e = 0;
      int pos = 3;
      if (exp[pos] == '-') {
	sign = -1;
	pos++;
      }
      while (pos < exp.length())
	e = (10 * e) + (exp[pos++] - '0');
      e *= sign;

      dp[aid][bid] = e;
      dp[bid][aid] = -e;
      //printf("aid=%d,bid=%d,e=%d\n", aid, bid, e);
    }

    bool ok = true;
    for (int k = 0; ok && k < un; k++)
      for (int i = 0; ok && i < un; i++)
	for (int j = 0; ok && j < un; j++) {
	  if (dp[i][k] < INF && dp[k][j] < INF) {
	    int dij = dp[i][k] + dp[k][j];
	    if (dp[i][j] >= INF) {
	      dp[i][j] = dij;
	      dp[j][i] = -dij;
	    }
	    else if (dp[i][j] != dij) {
	      ok = false;
	      //printf("i,j,k=%d,%d,%d: %d,%d,%d\n",
	      //i, j, k, dp[i][j], dp[i][k], dp[k][j]);
	    }
	  }
	}

    cout << (ok ? "Yes" : "No") << endl;
  }

  return 0;
}

Measured memory_bytes: 1388
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

//ライブラリ終わり

int main() {
  string S, T;
  cin >> S >> T;
  int SS = S.size();
  S += S;
  int M = 0;
  for (int i = 0; i < SS; i++) {
    int C = 0;
    for (int j = 0; j < SS; j++) {
      if (S.at(i + j) == T.at(j)) {
        C++;
      }
    }
    M = max(M, C);
  }
  if (M == SS) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
  
  
  

Measured memory_bytes: 3600
X,Y,Z,K = map(int,input().split())
*A, = map(int,input().split())
*B, = map(int,input().split())
*C, = map(int,input().split())
AB = sorted(a+b for a in A for b in B)[::-1][:K]
ABC = sorted(ab+c for ab in AB for c in C)[::-1][:K]
print(*ABC,sep="\n")

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


int main(){
	int a,b,c,x,ans=0;

	cin>>a>>b>>c>>x;

	for(int i=0;i<=min(a,x/500);i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(500*i+100*j+50*k==x)ans++;
			}
		}
	}
	cout<<ans<<endl;
}

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

void Main()
{
    int s, w;
    cin >> s >> w;
    if(s > w)
    {
        cout << "safe" << endl;
    }else{
        cout << "unsafe" << endl;
    }
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() { 
	string s; cin >> s;
	
	int ans = 0;
	
	int now = 0;
	REP(i, s.size()) {
		if (s[i] == 'T') now--;
		else now++;
		if (now < 0) {
			ans++;
			now = 0;
		}
	}
	
	ans += now;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

int n;

vector<int> tovec(long long a, int n) {
    vector<int> res;
    while (true) {
        if (a < n) {res.push_back(a); break;}
        else {res.push_back((int)(a%n)); a /= n;}
    }
    return res;
}

int base[8] = {0, 1, 2, 3, 5, 7, 8, 9};

int main() {
    while (cin >> n) {
        if (n == 0) break;
        vint vec = tovec(n, 8);
        reverse(ALL(vec));
        long long res = 0;
        for (int i = 0; i < vec.size(); ++i) {
            res += base[vec[i]];
            if (i != vec.size()-1) res *= 10;
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1208
dd = int(input())
c = list(list(map(int, input().split())))
s = [[0]*26]*dd
v = [[0]*26]*dd
vs = [[-10000000]*26]*dd
vs1 = [[-10000000]*26]*dd
vs2 = [[-10000000]*26]*dd
vs3 = [[-10000000]*26]*dd
ans = [0]*dd
ans2 = [0]*dd
fdate = [0]*26
for i in range(dd):
    s[i] = list(list(map(int, input().split())))



for i in range(dd):

    for j in range(26):
        v[i][j] = s[i][j] + c[j] *(i-fdate[j]) *(i-fdate[j])
        if not i+1 == dd:
            vs[i][j] =s[i+1][j] + c[j] *(i-fdate[j]) *(i-fdate[j])- c[j] *(i-fdate[j]+1)
        if i+2 < dd:
            vs1[i][j] =s[i+2][j] + c[j] *(i-fdate[j]) *(i-fdate[j])- c[j] *(2*i-2*fdate[j]+3)
        if i+3 < dd:
            vs2[i][j] =s[i+3][j] + c[j] *(i-fdate[j]) *(i-fdate[j])- c[j] *(3*i-3*fdate[j]+6)
    vm = max(v[i])
    vsm = max(vs[i])
    vs1m = max(vs1[i])
    vs2m = max(v[i])


    maxv = -100000000
    for j in range(26):
        if maxv < v[i][j] and vs[i][j]<v[i][j]:
            maxv = v[i][j]
            ans[i]=j+1
    fdate[ans[i]-1] =i+1

for a in ans:
    print(a)

Measured memory_bytes: 68916
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

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

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

	int N;
	cin >> N;
	vector<int> A(100010, 0);
	for (int i = 0; i < N; i++) {
		int tmp;
		cin>>tmp;
		A[tmp]++;
	}

	bool flg = true;
	if(N%2==1){
		//Nが奇数
		for (int i = 0; i < N; i++) {
			if(i==0){
				if(A[i]!=1){
					flg = false;
				}
			}else if(i%2==0){
				if(A[i]!=2){
					flg = false;
				}
			}else{
				if(A[i]>0){
					flg = false;
				}
			}
		}
	}else{
		//Nが偶数
		for (int i = 0; i < N; i++) {
			if(i%2==1){
				if(A[i]!=2){
					flg = false;
				}
			}else{
				if(A[i]>0){
					flg = false;
				}
			}
		}
	}

	int ans = 1;
	for (int i = 0; i < N/2; i++) {
		ans *= 2;
		ans %= MOD;
	}

	if(flg){
		cout << ans << endl;
	}else{
		cout << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
def main():
	n,m,q = map(int,input().split())
	qu = [list(map(int,input().split())) for x in range(q)]
	ans = 0
	import itertools

	ans_list = set()
	for i in itertools.combinations_with_replacement(list(range(1,m+1)),n):
		for qul in range(q):
			if i[ qu[qul][1]-1 ] - i[ qu[qul][0]-1 ] == qu[qul][2]:
				ans += qu[qul][3]
		ans_list.add(ans)
		ans = 0
	print(max(ans_list))

if __name__ == '__main__':
	main()

Measured memory_bytes: 68484
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    LL x;
    int ans;
    for(int i=0; i<5; i++){
        cin >> x;
        if(x==0){
            ans=i+1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3644
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        bool[,] map = new bool[hw[0], hw[1]];
        for (int i = 0; i < hw[0]; i++)
        {
            for (int j = 0; j < hw[1]; j++)
            {
                map[i, j] = Read();
            }
        }
        List<Point> points = new List<Point>();
        for (int i = 0; i < hw[0]; i++)
            for (int j = 0; j < hw[1]; j++)
                if (map[i, j])
                {
                    points.Add(new Point() { y = i + 1, x = j });
                    points.Add(new Point() { y = i, x = j + 1 });
                    points.Add(new Point() { y = i - 1, x = j });
                    points.Add(new Point() { y = i, x = j - 1 });
                }
        int step = 0;
        while (true)
        {
            bool update = false;
            List<Point> newpoints = new List<Point>();
            foreach (var point in points)
            {
                int i = point.y;
                int j = point.x;
                if (i < 0 || hw[0] <= i || j < 0 || hw[1] <= j || map[i, j]) continue;
                update = true;
                map[i, j] = true;
                newpoints.Add(new Point() { y = i + 1, x = j });
                newpoints.Add(new Point() { y = i, x = j + 1 });
                newpoints.Add(new Point() { y = i - 1, x = j });
                newpoints.Add(new Point() { y = i, x = j - 1 });
            }
            if (newpoints.Count == 0) break;
            step++;
            points = newpoints;
        }
        Console.WriteLine(step);
    }
    struct Point
    {
        public int y;
        public int x;
    }

    static readonly TextReader In = Console.In;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static bool Read()
    {
        int res = 0;
        int next = In.Read();
        while (46 != next && next != 35) next = In.Read();
        return next == '#';
    }
}


Measured memory_bytes: 61764