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

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val K = sc.nextInt
    val R = sc.nextInt
    val S = sc.nextInt
    val P = sc.nextInt
    val T = sc.next

    var result = 0
    for (k <- 0 until K) {
      val tb = new ArrayBuffer[Char]();
      var i = k
      while (i < T.length) {
        tb.append(T(i))
        i += K
      }

//      println(tb.mkString(""))
      var a = 0
      var prev = '.'
      for (t <- tb) {
        val next = if (t == 'r') 'p' else if (t == 's') 'r' else if (t == 'p') 's' else '.'
        if (prev != next) {
          a = a + (if (t == 'r') P else if (t == 's') R else if (t == 'p') S else 0)
          prev = next
        } else {
          prev = '.'
        }
      }
//      println(a)

      result += a
    }
    result.toString
  }
}


Measured memory_bytes: 40432
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,cal,i,count=0,j,sum;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
        a--;
        for(i=a;i<b;i++)
        {
            //cout<<a<<endl;
             a++;
             //cout<<a<<endl;
             if(c%a==0)
             {
                 count++;
             }
        }
        cout<<count<<endl;
        count=0;

    }
}



Measured memory_bytes: 3172
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n-1];
        int sum = 0;

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

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

        for(int i = 0;i<n-1;i++){
            c[i] = sc.nextInt();
        }

        for(int i = 0; i<n;i++){
            sum += b[a[i]-1];
            if(i>0 && a[i]==a[i-1]+1){
                sum+=c[a[i]-2];
            }
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 23252
s = input()
k = int(input())

ans = 0
c = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        c +=1
    elif s[i] != s[i+1]:
        if c == 2:
            ans += 1
        else:
            ans += c // 2
        c = 1
if c == 2:
    ans += 1
else:
    ans += c // 2

if c == len(s):
    print(c * k // 2)

elif s[0] != s[-1]:
    print(ans * k)
elif s[0] == s[-1]:
    a = 0
    for i in range(len(s)-1):
        if s[0] == s[i]:
            a +=1
        else:
            break

    b = 0
    r_s = s[::-1]
    for i in range(len(s)-1):
        if r_s[0] == r_s[i]:
            b +=1
        else:
            break

    print(ans * k - (a // 2 + b // 2 - (a+b) // 2) * (k - 1))


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;

int main(){
    ll n;cin>>n;
    vector<ll> b(n);
    map<ll,ll> mp;
    rep(i,n){
        cin>>b[i];
        mp[b[i]]++;
    }
    ll sum=0;
    for(auto p:mp){
        sum+=p.second*(p.second-1)/2;
    }
    rep(i,n){
        cout<<sum-(mp[b[i]]-1)<<endl;
    }
    return 0;
}


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

int main() {
  int a,b;
  cin>>a>>b;
  string s;
  cin>>s;
  s[b-1]=char(int(s[b-1])-'A'+'a');
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int n; cin >> n;
    ll x=1; rep(i,3) x*=n;
    cout << x << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	ll dog, monkey;
	cin >> dog >> monkey;

	ll ans = 1;
	if (dog == monkey) {
		for (ll i = 1; i < (dog + 1); i++) {
			ans = ans * i % mod;
		}
		ans = (ans * ans * 2) % mod;
	}
	else if ((dog + 1) == monkey) {
		for (ll i = 1; i < monkey; i++) {
			ans = (ans * i) % mod;
		}
		ans = (ans * ans) % mod;
		ans = monkey * ans % mod;
	}
	else if ((monkey + 1) == dog) {
		for (ll i = 1; i < dog; i++) {
			ans = (ans * i) % mod;
		}
		ans = (ans * ans) % mod;
		ans = ans * dog % mod;
	}
	else {
		ans = 0;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
d = int(input())

c = list(map(int, input().split()))
s = []
for i in range(d):
    s.append(list(map(int, input().split())))
t = []
for i in range(d):
    t.append(int(input()))

s_rate = 0

last_days = [0] * 26

for day in range(d):
    s_rate += s[day][t[day]-1]
    last_days[t[day]-1] = day + 1
    for j in range(26):
        s_rate -= c[j] * (day + 1 - last_days[j])
    print(s_rate)

Measured memory_bytes: 9264
n = int(input())
sqn = int(n**0.5)+1
f = [0] * (n+1)
for x in range(1,sqn):
    for y in range(1, sqn):
        for z in range(1, sqn):
            nn = x*x + y*y + z*z + x*y + y*z + z*x
            if nn <= n : f[nn]+=1
for i in range(1,n+1):
    print(f[i])

Measured memory_bytes: 75176
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def ints(): return list(map(int, readline().split()))


def read_map_as(H, replace={'#': 1, '.': 0}, pad=None):
    '''
    文字列のmapを置換して読み込み。デフォでは#→1,.→0
    '''
    if pad is None:
        ret = []
        for _ in range(H):
            ret.append([replace[s] for s in read()[:-1]])
            # 内包表記はpypyでは若干遅いことに注意
            # #numpy使うだろうからこれを残しておくけど
    else:  # paddingする
        ret = [[pad] * (W + 2)]  # Wはどっかで定義しておくことに注意
        for _ in range(H):
            ret.append([pad] + [replace[s] for s in read()[:-1]] + [pad])
        ret.append([pad] * (W + 2))

    return ret


MOD = 10**9 + 7

import numpy as np
H, W = ints()
A = np.array(read_map_as(H))


from numba import njit


@njit('(i8,i8,i8[:,:])', cache=True)
def solve(H, W, A):
    dp = np.zeros((H, W), dtype=np.int64)
    dp[0, 0] = 1
    for i in range(H):
        for j in range(W):
            if A[i, j] == 0:
                if i > 0:
                    dp[i, j] += dp[i - 1, j]
                if j > 0:
                    dp[i, j] += dp[i, j - 1]
                dp[i, j] %= MOD
    print(dp[H - 1, W - 1])


solve(H, W, A)


Measured memory_bytes: 126996
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;

LL n, ans;

int main()
{
	scanf("%lld", &n);
	ans = n - 1;
	for (int i = 2; 1LL * i * i <= n; i ++)
		if (n % i == 0)
			ans = min(ans, i + (n / i) - 2);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

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

    int n, d, x;
    cin >> n >> d >> x;
    int sum = x;
    REP(i, n){
        int a;
        cin >> a;
        sum += (d-1) / a + 1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
import sys
import re
import random
# import numpy as np
from math import sqrt,log,floor
from fractions import gcd  # python<=3.4
from collections import Counter, defaultdict

def lcm(a,b):
  return a // gcd(a,b) * b

## INPUT

def read_int():
  return int(input())

def read_ints():
  # return map(int,raw_input().split())
  return [int(x) for x in input().split()]

def read_field():
  return input().rstrip()

def read_fields():
  return input().rstrip().split()

def print_array(ar):
  n = len(ar)
  for i in range(n-1):
    print(ar[i], end=' ')
  print(ar[-1])

def say_bool(val, strs=['Yes','No']):
  print(strs[int(val)])

def say_Yes(val):
  say_bool(val, ['Yes', 'No'])

def say_YES(val):
  say_bool(val, ['YES', 'NO'])

def say_Alice(val):
  say_bool(val, ['Alice', 'Bob'])

def say_TAKAHASHI(val):
  say_bool(val, ['TAKAHASHI', 'AOKI'])


## MOD

MOD=1000000007

def ADD(x, y):
  return (x + y) % MOD

def SUB(x, y):
  return (x - y + MOD) % MOD

def MUL(x, y):
  return x * y % MOD

def POW(x, e):
  v = 1
  while e:
    if e & 1:
      v = MUL(v, x)
    x = MUL(x, x)
    e >>= 1
  return v

def INV(x):
  return POW(x, MOD-2)

def DIV(x, y):
  return MUL(x, INV(y))




###############
# st = Counter(input())

def solve(a,b):
    b = int(round(b*100))
    return a * b // 100

a,b = input().rstrip().split()
#a = int(input().rstrip())
#b = float(input().rstrip())
a=int(a)
b=float(b)


print(solve(a,b))


Measured memory_bytes: 10840
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int xx=0,ff=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
	return xx*ff;
}
const int maxn=100010;
int N,M,Q,lin[maxn],len;
struct edge{
	int y,next;
}e[maxn*2];
inline void insert(int xx,int yy){
	e[++len].next=lin[xx];
	lin[xx]=len;
	e[len].y=yy;
}
inline void ins(int xx,int yy){
	insert(xx,yy);
	insert(yy,xx);
}
int col[maxn],v[maxn],d[maxn],c[maxn];
bool opt[maxn][11];
void dfs(int x,int d,int c){
	if(opt[x][d])
		return;
	for(int i=d;i>=0;i--)
		opt[x][i]=1;
	if(!col[x])
		col[x]=c;
	if(!d)return;
	for(int i=lin[x];i;i=e[i].next)
		dfs(e[i].y,d-1,c);
}
int main(){
	//freopen("in.txt","r",stdin);
	N=read(),M=read();
	for(int i=1;i<=M;i++)
		ins(read(),read());
	Q=read();
	for(int i=1;i<=Q;i++)
		v[i]=read(),d[i]=read(),c[i]=read();
	for(int i=Q;i>=1;i--)
		dfs(v[i],d[i],c[i]);
	for(int i=1;i<=N;i++)
		printf("%d\n",col[i]);
	return 0;
} 



Measured memory_bytes: 5248
x,y,z,k=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
b=sorted(list(map(int,input().split())),reverse=True)
c=sorted(list(map(int,input().split())),reverse=True)
l=[]
for i in range(x):
  if i+1>k:
    break
  for j in range(y):
    if (i+1)*(j+1)>k:
      break
    for h in range(z):
      if (i+1)*(j+1)*(h+1)>k:
        break
      l.append(a[i]+b[j]+c[h])
l=sorted(l,reverse=True)
for i in l[:k]:
  print(i)

Measured memory_bytes: 9548
#include <stdio.h>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iomanip>
using namespace std;


int main()
{
	string str[3];

	for (int i = 0; i < 3; i++) {
		cin >> str[i];
	}
	
	cout << "A" << str[1].front() << "C" << endl;

	return 0;
}

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

inline int read() {
	register int x = 0, v = 1;
	register char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') v = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * v;
}

int p[100];
int tot;

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	printf("%d\n", std::min(b / a, c));
	return 0;
}



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

int main(){
	int k;
	cin >> k;
	int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (empty($l)) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->N = $a[0];
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->A=$a;
  }
}
$n=0;
for($i=0;$i<$key->N;$i++) {
  $n=$n+($i+1);
}
printf("%d\n",$n);


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;


signed main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * b, c * d) << endl;    
}

Measured memory_bytes: 256
N = int(input())
if 0<N<10:
  num = N
 
if 10<=N<100:
  num = 9
 
if 100<=N<1000:
  num = 9 + N - 99
  
if 1000<=N<10000:
  num = 9 + 900
 
if 10000<=N<100000:
  num = 909 + N - 9999
 
if N==100000:
  num=909+90000
  
print(num)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	int n, k;
	vector<int> s;
	int dp[100020] = {};
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i] = 1000000000;
		for (int j = i - k; j < i; j++) {
			if (j < 0) {
				continue;
			}
			dp[i] = min(dp[i], abs(s[j] - s[i]) + dp[j]);
		}
		if (i == n - 1) {
			cout << dp[i];
		}
	}
}

Measured memory_bytes: 1276
#include <stdio.h>
typedef struct {
  char mark;
  int num;
  int prev;
} Card;
int Partition(Card *,int,int);
void QuickSort(Card *,int ,int);
int Stable(Card *,int);
int main()
{
  Card A[100001];
  int i,n,a=0;
  scanf("%d ",&n);
  //printf("%d\n",n);
  for(i=1;i<=n;i++)
    {
      scanf("%c%d ",&A[i].mark,&A[i].num);
      A[i].prev = a++;
      // printf("%c %d %d\n",A[i].mark,A[i].num,A[i].prev);
    }
  QuickSort(A,1,n);
  if(Stable(A,n)==0) printf("Stable\n");
  else printf("Not stable\n");
  for(i=1;i<=n;i++)
    {
      printf("%c %d\n",A[i].mark,A[i].num);
    }
  return 0;
}
int Partition (Card *A,int p,int r)
{
  int x,i,j;
  Card temp;
  x=A[r].num;
  i=p-1;
  for(j=p;j<r;j++)
    {
      if(A[j].num<=x)
	{
	  i++;
	  temp.mark=A[i].mark;
	  temp.num=A[i].num;
	  temp.prev=A[i].prev;
	  A[i].mark=A[j].mark;
	  A[i].num=A[j].num;
	  A[i].prev=A[j].prev;
	  A[j].mark=temp.mark;
	  A[j].num=temp.num;
	  A[j].prev=temp.prev;
	}
    }
  temp.mark=A[i+1].mark;
  temp.num=A[i+1].num;
  temp.prev=A[i+1].prev;
  A[i+1].mark=A[r].mark;
  A[i+1].num=A[r].num;
  A[i+1].prev=A[r].prev;
  A[r].mark=temp.mark;
  A[r].num=temp.num;
  A[r].prev=temp.prev;
  return i+1;
}
void QuickSort(Card *A,int p,int r)
{
  int q;
  if(p<r)
    {
      q = Partition(A,p,r);
      QuickSort(A,p,q-1);
      QuickSort(A,q+1,r);
    }
}
int Stable(Card *A,int n)
{
  int i;
  for(i=1;i<n;i++)
    {
      if(A[i].num == A[i+1].num)
	{
	  // printf("%c %d %d\n",A[i].mark,A[i].num,A[i].prev);
	  //printf("%c %d %d\n",A[i+1].mark,A[i+1].num,A[i+1].prev);
	  if(A[i].prev >A[i+1].prev) return 1;
	}
    }
  return 0;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	// your code goes here
	ll n;
	cin>>n;
	ll a[n];
	map<ll,ll> m;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		m[a[i]]++;
	}
	ll out=0;
	for(auto it=m.begin();it!=m.end();it++)
	{
		ll r=(it->second);
		out+=(r*(r-1))/2;
	}
	for(ll i=0;i<n;i++)
	{
		cout<<out-max(m[a[i]]-1,(ll)0)<<"\n";
	}
	return 0;
}

Measured memory_bytes: 11008
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int[] a=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    Arrays.sort(a);
//    System.out.println(Arrays.toString(a));
    Pair[] ps=new Pair[m];
    for(int i=0;i<m;i++){
      ps[i]=new Pair(sc.nextInt(),sc.nextInt());
    }
    Arrays.sort(ps,(s1,s2)->s2.alte-s1.alte);
//    System.out.println(Arrays.toString(ps));
    int idx=0;
    for(int i=0;i<m;i++){
      while(ps[i].many>0){
        if(idx>=a.length){
          break;
        }
        if(a[idx]>=ps[i].alte){
          break;
        }else{
          a[idx]=ps[i].alte;
          ps[i].many--;
          idx++;
        }
      }
    }
//    System.out.println(Arrays.toString(a));
    long sum=0;
    for(int i=0;i<a.length;i++){
      sum+=a[i];
    }
    System.out.println(sum);
  }
  static class Pair{
    int many;
    int alte;
    Pair(int b,int c){
      many=b;
      alte=c;
    }
    public String toString(){
      return String.valueOf(many)+":"+String.valueOf(alte);
    }
  }
}

Measured memory_bytes: 93280
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }
 
 
void main() {
    int m, d; readf("%d %d\n",&m,&d);
    writeln(m - 1 + (d >= m));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i, n) for (ll i=0;i<(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
//using ll=long long;
typedef long long ll;
typedef pair<ll, ll> pi;
 
 
 
int main(){
  ll n,k;

  cin >> n;

  string s;

  cin >> s;
  vector<ll> S(n+1);
  vector<ll> A(n+1);
  S[0] = 0;
  
  rep(i,n){
    if(s[i]=='#') S[i+1]=1;
    S[i+1]+=S[i];
  }

  ll ans = min(S[n], n-S[n]);
  ll tmp = 0;
  rep(i,n){
    tmp = S[i+1];
    // left kuro
    tmp += n - (i+1) - S[n] + S[i+1];
    // right shiro
    ans = min(ans, tmp);
      }  
  
  cout << ans <<endl;
  
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000


int main() {
	
	int N;
	cin>>N;
	
	vector<pair<int,int>> X(N);
	for(int i=0;i<N;i++)cin>>X[i].first;
	for(int i=0;i<N;i++)cin>>X[i].second;
	
	sort(X.begin(),X.end());
	
	vector<int> A(N);
	
	for(int i=0;i<N;i++){
		A[i] = X[i].first;
		swap(X[i].first,X[i].second);
		X[i].second=i;
	}
	
	sort(X.begin(),X.end());
	
	for(int i=0;i<N;i++){
		if(X[i].first<A[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	
	for(int i=0;i<N-1;i++){
		if(X[i+1].first>=A[i]&&X[i].first>=A[i+1]){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	
	int now = X[0].second;
	set<int> S;
	
	while(true){
		if(S.count(now))break;
		S.insert(now);
		now = X[now].second;
	}
	
	if(S.size()==N)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 6144
import math

long, short, hour, minutes = map(int, input().split())


minutes_x = math.sin(math.radians(minutes * 6)) * short
minutes_y = math.cos(math.radians(minutes * 6)) * short

diff = 360 / 12 * minutes / 60

hour_x = math.sin(math.radians(hour * 30 + diff)) * long
hour_y = math.cos(math.radians(hour * 30 + diff)) * long


print(math.sqrt((hour_x - minutes_x) ** 2 + (hour_y - minutes_y) ** 2))

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

int main() {
  
  string a;
  cin>>a;
  
  int ans=0;
  if(a.at(2)==a.at(3)){ans++;}
  if(a.at(4)==a.at(5)){ans++;}
  
  if(ans==2){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  
}


Measured memory_bytes: 256
n=int(input())
a=[]
for i in range(11,55556):
    if i%5==1 and i%2==1:
        f=0
        for j in range(2,round(i**0.5)+1):
            if i%j==0:
                f=1
                break
        if f==0:
            a.append(i)
print(*a[:n])

Measured memory_bytes: 3188
n,k=gets.split.map(&:to_i)
h=Array.new(n+k,0)
h=gets.split.map(&:to_i)
k.times do
    h<<0
end

dp=Array.new(n+k,10**10)
dp[0]=0
n.times do |i|
    1.upto(k) do |j|
        dp[i+j]=[dp[i]+(h[i+j]-h[i]).abs,dp[i+j]].min
    end
end
puts dp[n-1]


Measured memory_bytes: 21784
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
bool sortDescByFirst(const pair<int,int>&a, const pair<int,int>&b){
    return a.first>=b.first;
}
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string str;
    while(cin>>str){
        int y=stoi(str.substr(0,4));
        int m=stoi(str.substr(5,2));
        int d=stoi(str.substr(8,2));
        if(y<2019){
            cout<<"Heisei"<<endl;
        }else if(y==2019 && m<4){
            cout<<"Heisei"<<endl;
        }else if(y==2019 && m==4 && d<=30){
            cout<<"Heisei"<<endl;
        }else{
            cout<<"TBD"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cassert>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef pair<int,int> pii;
const int N = 10000;

void compute(int i,int *buf){
  buf[0]=i/1000%10;
  buf[1]=i/100%10;
  buf[2]=i/10%10;
  buf[3]=i%10;
}

pii hitAndBlow(int n,int q){
  int hit=0,blow=0;
  int buf1[5],buf2[5];
  compute(n,buf1);
  compute(q,buf2);
  rep(i,4){
    rep(j,4){
      if (buf1[i] == buf2[j]){
	if (i == j)hit++;
	else blow++;
      }
    }
  }
  return make_pair(hit,blow);
}

int solve(vector<int> &a,vector<int> all){
  if (a.size() > 15)return -1;
  rep(i,all.size()){
    int buf[5];
    bool isok=true;
    int cnt[5][5]={0};
    rep(j,a.size()){
      pii tmp = hitAndBlow(a[j],all[i]);
      cnt[tmp.first][tmp.second]++;
      if (cnt[tmp.first][tmp.second] > 1)isok=false;
    }
    if (isok)return all[i];
  }
  return -1;
}

main(){
  int n;
  vector<int> all(N);
  rep(i,N){
    int buf[4];
    compute(i,buf);
    bool isok=true;
    rep(j,4)REP(k,j+1,4)if (buf[j] == buf[k]){isok=false;}
    all[i]=(isok?i:-1);
  }
  sort(all.begin(),all.end());
  all.erase(remove(all.begin(),all.end(),-1),all.end());
  while(cin>>n && n){
    vector<pii> in(n);
    vector<int> cand,query(n);
    rep(i,n)cin>>query[i]>>in[i].first>>in[i].second;
    rep(i,all.size()){
      bool isok=true;
      int buf[5];
      rep(j,n){
	pii tmp =hitAndBlow(all[i],query[j]);
	if (tmp.first == in[j].first && tmp.second == in[j].second);
	else {
	  isok=false;
	}
      }
      if (isok)cand.push_back(all[i]);
    }
    sort(cand.begin(),cand.end());
    int ans = cand.size() == 1?cand[0]:solve(cand,all);
    if (ans !=-1)printf("%04d\n",ans);
    else puts("????");
  }
  return false;
}

Measured memory_bytes: 996
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>

using namespace std;

int main(){

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

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

	int now = 0;
	for (int i = 0; i < N - 1; i++)
		now += L[i];

	now > L[L.size() - 1] ? cout << "Yes" : cout << "No";
	cout << endl;

	return 0;
}

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

int main() {
  int a,b;
  1<=a,b<=10000;
  cin >>a>>b;

  if (a*b%2==1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

  for(int n;cin>>n,n;){
    vector <int> a[51][2];
    for(int j=0;j<n+1;j++){
      int m,x0,y0,x1,y1,bx,by;
      cin>>m>>x0>>y0>>x1>>y1;
      bx=x1-x0; by=y1-y0;
      a[j][0].push_back(abs(bx?bx:by));
      for(int i=2;i<m;i++){
	int cx,cy;
	x0=x1;y0=y1;
	cin>>x1>>y1;
        cx=x1-x0;cy=y1-y0;
        a[j][0].push_back(bx*cy-cx*by>0?1:-1);
        a[j][0].push_back(abs(cx?cx:cy));
        bx=cx; by=cy;
      }
      a[j][1]=a[j][0];
      reverse(a[j][1].begin(),a[j][1].end());
      for(int i=0;i<(int)a[j][1].size();i++) if(i%2) a[j][1][i]*=-1;
    }
    /*  for(int i=0;i<n+1;i++){                                                                                                
      for(int j=0;j<(int)a[i][0].size();j++) cout<<a[i][0][j]<<" ";                                                            
      cout<<endl;                                                                                                              
      for(int j=0;j<(int)a[i][1].size();j++) cout<<a[i][1][j]<<" ";                                                            
      cout<<endl;                                                                                                              
      } */
    for(int i=1;i<n+1;i++) if(a[0][0]==a[i][0]||a[0][0]==a[i][1]) cout<<i<<endl;
    cout<<"+++++"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3068
#include <stdio.h>

int main(void){
  int n;
  scanf("%d" ,&n);
  char s[4] = {'\0'};
  char ans[7];
  sprintf(s, "%d", n);
  ans[0] = 'A';
  ans[1] = 'B';
  ans[2] = 'C';
  ans[3] = s[0];
  ans[4] = s[1];
  ans[5] = s[2];
  ans[6] = '\0';
  printf("%s\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  i64 W, H;
  cin >> W >> H;
  dynarr<dynarr<i64>> s(H, dynarr<i64>(W));
  rep(i,0,H) rep(j,0,W) cin >> s[i][j];
  dynarr<dynarr<i64>> Hsum(H + 1, dynarr<i64>(W));
  dynarr<dynarr<i64>> Wsum(H, dynarr<i64>(W + 1));
  rep(j,0,W) rep(i,0,H) {
    Hsum[i + 1][j] = Hsum[i][j] + s[i][j];
  }
  rep(i,0,H) rep(j,0,W) {
    Wsum[i][j + 1] = Wsum[i][j] + s[i][j];
  }
  dynarr<dynarr<i64>> dp(H + 1, dynarr<i64>(W + 1));
  dp[H][W] = 0;
  for(int i = H; i >= 0; i--) {
    for(int j = W;j >= 0;j--) {
      if(i == H && j == W) continue;
      if((i + j) % 2 == 0) {
        dp[i][j] = -1e18;
        // left ... +
        if(j + 1 <= W) {
          dp[i][j] = max(dp[i][j], dp[i][j + 1] + Hsum[i][j]);
        }
        // up ... -
        if(i + 1 <= H) {
          dp[i][j] = max(dp[i][j], dp[i + 1][j] - Wsum[i][j]);
        }
      }
      else {
        dp[i][j] = 1e18;
        if(j + 1 <= W) {
          dp[i][j] = min(dp[i][j], dp[i][j + 1] + Hsum[i][j]);
        }
        // up ... +
        if(i + 1 <= H) {
          dp[i][j] = min(dp[i][j], dp[i + 1][j] - Wsum[i][j]);
        }
      }
    }
  }
  cout << abs(dp[0][0]) << endl;
}



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

int main(){
  string str,command,p;
  int i,n,a,b;

  cin >> str >> n;

  for(i = 0; i < n; i++){
    cin >> command >> a >> b;
    if(command == "replace"){
      cin >> p;
      str.replace(a,b - a + 1,p);
    }
    else if(command == "reverse"){
      p = str.substr(a,b - a + 1);
      reverse(p.begin(),p.end());
      str.replace(a, b - a + 1, p);
    }
    else cout << str.substr(a, b - a + 1) << endl;
  }
}

Measured memory_bytes: 1224
#!/usr/bin/env python3
import sys
import heapq
from collections import Counter
INF = float("inf")

# 無向グラフを仮定する。


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.V = list(range(N))
        self.E = [[] for _ in range(N)]

    def add_edge(self, edge):
        """辺を加える。edgeは(始点, 終点、重み)からなるリスト
        重みがなければ、重み1とする。
        """
        if len(edge) == 2:
            edge.append(1)
        elif len(edge) != 3:
            print("error in add_edge")
            pass

        s, t, w = edge
        self.E[s].append([t, w])

        pass


def shortestPath(g: Graph, s: int):
    """ グラフgにおいて、始点sから各頂点への最短路を求める
    引数
    g: グラフ, s: 始点
    返り値
    dist: 始点からの距離が格納されたリスト
    prev: 始点から最短経路で移動する場合、各頂点に至る前の頂点のリスト
    """
    dist = [INF]*g.N
    dist[s] = 0

    prev = [None]*g.N
    Q = []
    heapq.heappush(Q, (dist[s], s))

    while len(Q) > 0:
        _, u = heapq.heappop(Q)
        for v, w in g.E[u]:
            if dist[v] > dist[u] + w:
                dist[v] = dist[u] + w
                prev[v] = u
                heapq.heappush(Q, (dist[v], v))
    return dist, prev


def solve(H: int, W: int, c: "List[List[int]]", A: "List[List[int]]"):
    g = Graph(10)
    # 向きを逆向きにuとｒ
    for i in range(10):
        for j in range(10):
            g.add_edge([j, i, c[i][j]])

    c = Counter()
    for a in A:
        c.update(a)

    # 逆向きにとった効果として、１から他の数字への距離を求めれば良い
    dist, prev = shortestPath(g, 1)
    # print(dist)
    # print(c)
    ans = 0
    for key in c:
        if key == 1 or key == -1:
            continue
        ans += dist[key]*c[key]

    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    c = [[int(next(tokens)) for _ in range(9-0+1)]
         for _ in range(9-0+1)]  # type: "List[List[int]]"
    A = [[int(next(tokens)) for _ in range(W)]
         for _ in range(H)]  # type: "List[List[int]]"
    solve(H, W, c, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

x, y = MAP()

if x*y < 0:
	print(1+abs(abs(x)-abs(y)))
elif x == 0 or y == 0:
	if x < y:
		print(max(abs(x), abs(y)))
	else:
		print(1+max(abs(x), abs(y)))

else:
	if x < y:
		print(y-x)
	else:
		print(x-y+2)

Measured memory_bytes: 5204
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
# from numba import njit


def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    s = []
    ord = [-1] * (N+1)
    v = 1

    while ord[v] == -1:
        ord[v] = len(s)
        s.append(v)
        v = A[v-1]

    c = len(s) - ord[v]
    l = ord[v]

    if K < l:
        res = s[K]
    else:
        K -= l
        K %= c
        res = s[l+K]

    print(res)



main()


Measured memory_bytes: 30852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); 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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  string s;
  cin >> s;
  ll res = INF;
  for (ll i = 0; i <= s.size()-3; i++) {
        ll tmp = 100*ctoi(s.at(i)) + 10*ctoi(s.at(i+1)) + ctoi(s.at(i+2));
        chmin(res, abs(753-tmp));
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import sys

#sys.stdin = open('input2.txt', 'r')

N = int(raw_input())
seq = []
for x in range(N):
	a = long(raw_input())
	seq.append((a, x))
seq.sort()

count = 0
for x in range(N):
	a, i = seq[x][0], seq[x][1]
	if ((x - i) % 2):
		count += 1

print str(count / 2)


Measured memory_bytes: 19164
#include <iostream>
#include <math.h>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;

int main(void){
    int r,d,ans=0;
    int x[11];

    cin >> r >> d >> x[0];

    REP(i,10){
        x[i+1] = r * x[i] - d;
        cout << x[i+1] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*
	Name: Lamp
	Author: Jerryjiang090210
	Date: 30/06/19 16:12
	Description: Jerryjiang090210's code <Lamp>
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn=2010;
int n,m,mx=0;
char iomap[maxn][maxn];
vector<int> row[maxn],col[maxn];
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
		col[i].push_back(-1);
	for(int i=0;i<n;i++)
	{
		row[i].push_back(-1);
		for(int j=0;j<m;j++)
		{
			cin>>iomap[i][j];
			if(iomap[i][j]=='#')
			{
				row[i].push_back(j);
				col[j].push_back(i);
			}
		}
		row[i].push_back(m);
	}
	for(int i=0;i<m;i++)
		col[i].push_back(n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int r1=*(lower_bound(row[i].begin(),row[i].end(),j))\
			-*(lower_bound(row[i].begin(),row[i].end(),j)-1)-1;
			int r2=*(lower_bound(col[j].begin(),col[j].end(),i))\
			-*(lower_bound(col[j].begin(),col[j].end(),i)-1)-1;
			mx=max(mx,r1+r2-1);
		}
	}
	cout<<mx<<endl;
	return 0;
} 

Measured memory_bytes: 38400
fun main(args: Array<String>) {
    val (n, k) = readIntList()
    val h = readIntList().sorted().reversed()
    var ans = 0L
    for (i in k until n) {
        ans += h[i]
    }
    println(ans)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 85312
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<string,string> pss;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;

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

    int n,m;
    cin >> n >> m;
    int p1=(m+1)/2;
    int d=(p1*2)+1;
    for(int i=1;i<=m;i+=2)
    {
        cout << p1 << ' ' << p1+i << '\n';
        p1--;
    }

    for(int j=(m-(m&1));j>=2;j-=2)
    {
        cout << d << ' ' << d+j << '\n';
        d++;
    }

    return 0;
}


Measured memory_bytes: 3656
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;


class P
{
    static void Main()
    {
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] Count = Enumerable.Repeat(1, nm[0]).ToArray();
        bool[] IsContainRed = new bool[nm[0]];
        IsContainRed[0] = true;
        for (int i = 0; i < nm[1]; i++)
        {
            int[] xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int x = xy[0] - 1;
            int y = xy[1] - 1;
            if (IsContainRed[x])
            {
                IsContainRed[y] = true;
                if (Count[x] == 1)
                {
                    IsContainRed[x] = false;
                }
            }
            Count[x]--;
            Count[y]++;
        }
        Console.WriteLine(IsContainRed.Count(x => x));
    }
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const ll N = 1e5 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};


int main() {
    ll a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans=0;
    for (int i=a; i<=b; i++){
        if(i%c == 0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

// I'm trying to ~~~
int main(){
    string A,B,C; cin >> A >> B >> C;
    cout << A[0]<<B[1]<<C[2] << endl;
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1e9+7;
#define INF (1 << 30)
#define REP(i,m,n) for(int i=(int)m; i < (int)n; ++i)
#define rep(i,n) REP(i,0,n)

typedef vector<vector<P> > Graph;
vector<int> dijkstra(int s, Graph &G){
	priority_queue<P,vector<P>,greater<P>> que;
	int n = G.size();
	vector<int> dist(n);
	dist.assign(n,INF);
	dist[s] = 0;
	que.push(P(0, s));

	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		rep(i,G[v].size()) {
			if(dist[G[v][i].first] > dist[v]+G[v][i].second){
				dist[G[v][i].first] = dist[v]+G[v][i].second;
				que.push(P(dist[G[v][i].first],G[v][i].first));
			}
		}
	}
	return dist;
}

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

	int n; cin >> n;
	Graph edge(100010);
	rep(i, 100010) {
		edge[i].push_back(P(i+1, 1));

		int x = 6;
		while(i+x <= n) x *= 6;
		edge[i].push_back(P(i+x/6, 1));
		int y = 9;
		while(i+y <= n) y *= 9;
		edge[i].push_back(P(i+y/9, 1));
	}
	vector<int> dist = dijkstra(0, edge);
	cout << dist[n] << '\n';
	return 0;
}

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

int N, W;
int v[110], w[110];
int dp[11010]; 

void put_in_knapsack() {
    rep(i, W+1) dp[i] = 0;

    rep(d, W+1) {
        rep(n, N) {
            dp[d+w[n]] = max(dp[d+w[n]], dp[d] + v[n]);
        }
    }
}

int main() {
    cin >> N >> W;
    rep(i, N) cin >> v[i] >> w[i];

    put_in_knapsack();
    cout << dp[W] << endl;

    return 0;
}




Measured memory_bytes: 3148
import sys
from collections import Counter

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


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


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    c = Counter()
    for i in range(n):
        a = read_int()
        c[a] += 1

    res = 0
    for j in c:
        if c[j] % 2 != 0:
            res += 1
    print(res)


main()


Measured memory_bytes: 15444
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

n = iinput()
a = iarr()

cum = []; sum = 0
for num in a: sum += num; cum.append(sum)

ans = 1
now = 1
for i in range(n+1):
    next = min(2*(now - a[i]), cum[n]-cum[i])
    now = next
    if n==i and next<0 : ans = -1; break
    if n!=i and next<=0 : ans = -1; break
    ans += next

if a[n] > 2**n: ans = -1
print(ans)



Measured memory_bytes: 49172
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int maze[105][105] = {0};
int d[105][105] = { 0 };//1???????????´
int w, h;

void dfs(int hpos,int wpos) {
	d[wpos][hpos] = 1;
	maze[wpos][hpos] = 1;
	if (hpos % 2 == 0) {
		int dw[6] = { -1,0,1,0,-1,-1 }, dh[6] = { -1,-1,0,1,1,0 };
		for (int i = 0; i < 6; i++) {
			int nw = wpos + dw[i], nh = hpos + dh[i];
			if (0 <= nw&&nw <= w+1 && 0 <= nh&&nh <= h+1&&maze[nw][nh] == 0)dfs(nh, nw);
		}
	}
	else {
		int dw[6] = { 0,1,1,1,0,-1 }, dh[6] = { -1,-1,0,1,1,0 };
		for (int i = 0; i < 6; i++) {
			int nw = wpos + dw[i], nh = hpos + dh[i];
			if (0 <= nw&&nw <= w+1 && 0 <= nh&&nh <= h+1&&maze[nw][nh] == 0)dfs(nh, nw);
		}
	}
}


int calc(int hpos, int wpos) {
	int count = 0;
	if (d[wpos][hpos] == 0) {
		if (hpos % 2 == 0) {
			int dw[6] = { -1,0,1,0,-1,-1 }, dh[6] = { -1,-1,0,1,1,0 };
			for (int i = 0; i < 6; i++) {
				int nw = wpos + dw[i], nh = hpos + dh[i];
				if (0 <= nw&&nw <= w+1 && 0 <= nh&&nh <= h+1 && d[nw][nh] == 1)count++;
			}
		}
		else {
			int dw[6] = { 0,1,1,1,0,-1 }, dh[6] = { -1,-1,0,1,1,0 };
			for (int i = 0; i < 6; i++) {
				int nw = wpos + dw[i], nh = hpos + dh[i];
				if (0 <= nw&&nw <= w+1  && 0 <= nh&&nh <= h+1 && d[nw][nh] == 1)count++;
			}
		}
	}
	return count;
}

int main() {
	cin >> w >> h;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> maze[j][i];
		}
	}
	dfs(0, 0);
	int ans = 0;
	for (int i = 0; i <= h + 1; i++) {
		for (int j = 0; j < w + 1; j++) {
			ans += calc(i, j);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3804
n = int(input())
list = map(int,input().split())

list2=[]
for i in list:
    if i%2==0:
        list2.append(i)

if list2:
    if all(i%3==0 or i%5==0 for i in list2):
        print('APPROVED')
    else:
        print('DENIED')
else:
    print('APPROVED')
    
          




Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    int bef = -1,j=0;
    rep(i,n){
        if(bef != a[i])j=0;
        if(a[i] == b[i]){
            for(;j<n;j++){
                if(a[j] != b[i] && a[i] != b[j]){
                    swap(b[j],b[i]);
                    break;
                }
            }
            if(a[i] == b[i]){
                cout << "No" << endl;
                return 0;
            }
        }
        bef = a[i];
    }
    cout << "Yes" << endl;
    rep(i,n){
        if(i) cout << " ";
        cout << b[i];
    }
    cout << endl;
}

Measured memory_bytes: 4824
# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG

using namespace std;

const int N = 1e2 + 7;
const int mod = 1e9 + 7;

int x, k;
set < int > st;

int main()
{
    speed;
    /// Author: Dilshod--Imomov
    #ifdef DEBUGd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG
    cin >> k >> x;
    for ( int i = 0; i < k; i++ ) {
        st.insert(x - i);
        st.insert(x + i);
    }
    for ( auto i: st ) cout << i << ' ';
}



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

public class MainClass
{
	public const long Giri = 1000000007;

	
	public static void Main(string[] args)
	{
		var s = Input().ToInt();
		for(int i = 1; i<= 3; i++)
		{
			if(s[0]*s[1]*i%2==1)
			{
				Console.WriteLine("Yes");
				return;
			}
		}
		Console.WriteLine("No");
		
	}


	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 11092
cost,n = map(int,input().split())
cash = [int(x) for x in input().split()]

#account = cost - 1
flag = False
while flag == False :
    flag = True
    for i in range(len(cash)):
        if str(cash[i]) in str(cost):
            flag = False
            break
    if flag == False:
        cost += 1
    else:flag=True
        

print(cost)

Measured memory_bytes: 3060