akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.NoSuchElementException

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = sc.nextLongArray(n)
    val minus = a.count { it < 0 }
    val b = a.map { Math.abs(it) }.sorted()
    val ans = b.subList(1, n).sum() + if (minus % 2 == 0) b[0] else -b[0]
    println(ans)
}

class Scanner(private val `in`: InputStream) {
    private val buffer = ByteArray(1024)
    private var ptr = 0
    private var buflen = 0

    companion object {
        private fun isPrintableChar(b: Byte): Boolean = b in 33..126
        private fun isNumericChar(b: Byte): Boolean = b in 48..57
        private fun digit(b: Byte): Int = b - 48
    }

    fun hasNextByte(): Boolean {
        if (ptr < buflen) return true
        ptr = 0
        try {
            buflen = `in`.read(buffer)
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return 0 < buflen
    }

    private fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        return buildString {
            var b = readByte()
            while (isPrintableChar(b)) {
                appendCodePoint(b.toInt())
                b = readByte()
            }
        }
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        val minus = b.toChar() == '-'
        if (minus) b = readByte()
        if (!isNumericChar(b)) throw NumberFormatException()
        do {
            n *= 10
            n += digit(b)
            b = readByte()
        } while (isNumericChar(b))
        return if (minus) -n else n
    }

    fun nextInts(n: Int): Array<Int> = Array(n) { nextInt() }

    fun nextIntArray(n: Int): IntArray = IntArray(n) { nextInt() }

    fun nextIntArrays(n: Int, m: Int): Array<IntArray> {
        val arrays = Array(m) { IntArray(n) }
        repeat(n) { i -> repeat(m) { j -> arrays[j][i] = nextInt() } }
        return arrays
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        val minus = b.toChar() == '-'
        if (minus) b = readByte()
        if (!isNumericChar(b)) throw NumberFormatException()
        do {
            n *= 10
            n += digit(b)
            b = readByte()
        } while (isNumericChar(b))
        return if (minus) -n else n
    }

    fun nextLongs(n: Int): Array<Long> = Array(n) { nextLong() }

    fun nextLongArray(n: Int): LongArray = LongArray(n) { nextLong() }

    fun nextLongArrays(n: Int, m: Int): Array<LongArray> {
        val arrays = Array(m) { LongArray(n) }
        repeat(n) { i -> repeat(m) { j -> arrays[j][i] = nextLong() } }
        return arrays
    }

}

Measured memory_bytes: 41948
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <cstring>
#include <climits>
#include <set>
#include <map>
#include <algorithm>  
#include <cmath>
#include <iomanip>
#define ll long long
using namespace std;
ll n,k;
ll mod=pow(10,9)+7;
ll arr[100005];
ll dp[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    for(ll i=0;i<n;++i)
    {
        cin>>arr[i];
    }
    dp[0]=0;
    for(ll i=1;i<n;++i)
    {
        ll add=INT_MAX;
        for(ll j=1;j<=k;++j)
        {
            if(i-j>=0)
            {
                add=min(add,abs(arr[i-j]-arr[i])+dp[i-j]);
            }
        }
        dp[i]=add;
    }
    cout<<dp[n-1]<<endl;
}






































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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,sum = 0,q;
    cin>>n>>m>>q;
    map<int,int>mp;
    vector<int>v;
    int a[q];
    for(i = 0;i < q;i++)
    {
        cin>>a[i];
       mp[a[i]]++;
    }
    for(i = 1;i <= n;i++)
    {
        j = mp[i] + m - q;
        if(j>0)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }

    return 0;
}


Measured memory_bytes: 5760
A = list(map(int,input().split()))
A.sort()
ret = 0
ret += A[2]-A[1]
A[1] += ret
A[0] += ret
while A[0] < A[1]:
  ret += 1
  A[0] += 2
if A[0] > A[1]:
  ret += 1
print(ret)

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var n = Read();
        var w = new string[n];
        for(int i = 0; i < n; i++)
        {
            w[i] = Console.ReadLine();
        }
        bool b = false;
        for(int i = 0; i < n-1; i++)
        {
            if (w[i][w[i].Length-1] != w[i + 1][0])
                b = true;
            for(int j = i+1; j < n; j++)
            {
                if (w[i] == w[j])
                    b = true;
            }
        }
        if (!b)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
        
        Console.Out.Flush();
    }
}




Measured memory_bytes: 13140
from collections import deque 

def main():
    H, W = map(int, input().split())
    s = []
    num = 0
    for i in range(H):
        s.append(list(input()))
        num += s[i].count("#")
    ans = -1    
    cnt = [[0 for _ in range(W)] for _ in range(H)]
    queue = deque()
    queue.append((0, 0))
    while queue:
        x, y = queue.popleft()
        if(s[x][y] == "#"):
            continue
        if(x == H-1 and y == W-1):
            ans = cnt[x][y]
        s[x][y] = "#"
        
        d = [(-1, 0), (1, 0), (0, 1), (0, -1)]
        for dx, dy in d:
            nx = x + dx
            ny = y + dy
            if(nx < 0 or nx >= H or ny < 0 or ny >= W):
                continue
            queue.append((nx, ny))
            if(s[nx][ny] != "#"):
                cnt[nx][ny] = cnt[x][y]+1
    if(ans == -1):
        print(-1)
    else:
        print(H*W-ans-num-1)
    
main()

Measured memory_bytes: 3316
#include <cstdio>

using namespace std;

// row, column
int S[11][5];

int main() {
    for (;;) {
        int H;
        scanf("%d", &H);

        if (!H) { break; }

        for (int i = H - 1; i >= 0; i--) {
            scanf("%d%d%d%d%d", &S[i][0], &S[i][1], &S[i][2], &S[i][3], &S[i][4]);
        }

        for (int i = H; i < 11; i++) {
            S[i][0] = S[i][1] = S[i][2] = S[i][3] = S[i][4] = -2;
        }

        int p = 0;
        for (;;) {
            bool disappear = false;
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 3; j++) {
                    if (S[i][j] < 0) { break; }

                    int k = 1;
                    for (; j + k < 5 && S[i][j + k] == S[i][j]; k++);

                    if (k >= 3) {
                        disappear = true;
                        p += S[i][j] * k;
                        for (int l = 0; l < k; l++) {
                            S[i][j + l] = -1;
                        }
                    }
                }
            }

            if (!disappear) { break; }

            for (int i = 0; i < 5; i++) {
                for (int j = 0; ; j++) {
                    if (S[j][i] == -2) { break; }
                    else if (S[j][i] == -1) {
                        int k = 1;
                        for (;; k++) {
                            if (S[j + k][i] == -2) { S[j][i] = -2; goto next_col; }
                            if (S[j + k][i] != -1) { break; }
                        }

                        for (int l = 0; ; l++) {
                            S[j + l][i] = S[j + k + l][i];
                            if (S[j + k + l][i] == -2) { break; }
                        }
                    }
                }
next_col:;
            }

#if 0
            for (int i = 10; i >= 0; i--) {
                printf("%d %d %d %d %d\n", S[i][0], S[i][1], S[i][2], S[i][3], S[i][4]);
            }
#endif
        }

        printf("%d\n", p);
    }
    return 0;
}

Measured memory_bytes: 1028
#include<stdio.h>

int main(){
  int a,b,s,t,n;
  for(;;){
    scanf("%d",&n); if(!n)break;
    s=t=0;
    while(n--){
      scanf("%d%d",&a,&b);
      if(a>b) s+=a+b;
      if(a<b) t+=a+b;
      if(a==b) s+=a, t+=b;
    }
    printf("%d %d\n",s,t);
  }
  return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        string s = sc.Next();

        int answer = 0;
        for (int i = 0; i < n; i++)
        {
            string s1 = s.Substring(0, i);
            string s2 = s.Substring(i);

            int tmpAnswer = 0;
            for (int j = 0; j < 26; j++)
            {
                if (s1.Contains((char)('a' + j)) && s2.Contains((char)('a' + j)))
                {
                    tmpAnswer++;
                }
            }
            answer = Math.Max(answer, tmpAnswer);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13268
package main

import "fmt"

func main() {
	var n, k int
	var s string
	fmt.Scan(&n, &k, &s)

	ans := 0
	for l, r := -1, 0; r < len(s); r++ {
		for r < len(s) && s[r] == '1' {
			r++
		}
		for k > 0 {
			k--
			for r < len(s) && s[r] == '0' {
				if r > len(s)-1 {
					break
				}
				r++
			}
			for r < len(s) && s[r] == '1' {
				if r > len(s)-1 {
					break
				}
				r++
			}
		}
		r--
		//fmt.Println(l, r)
		if v := r - l; v > ans {
			ans = v
		}
		k++
		l++
		for l < len(s) && s[l] == '1' {
			l++
		}
		for l < len(s) && s[l] == '0' {
			l++
		}
		l--
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1280
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];

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

        for (int i=0; i<n; i++){
            System.out.print(a[i]+" ");
        }

    }
}

Measured memory_bytes: 62112
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

char S[4];
char T[4];

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


    cin >> S >> T;

    int ret = 0;
    rep (i, 3)
    {
        if (S[i] == T[i])
        {
            ++ret;
        }
    }

    cout << ret << "\n";

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  ll D, G;
  cin >> D >> G;
  G /= 100;
  vector<ll> P(D), C(D);
  for (ll i = 0; i < D; i++)
  {
    cin >> P.at(i) >> C.at(i);
    C.at(i) /= 100;
  }

  vector<ll> prm(D);
  for (ll i = 0; i < D; i++)
  {
    prm.at(i) = i;
  }

  ll ans = INF;
  do
  {
    ll tmp = 0;
    ll pnt = 0;
    for (ll i = 0; i < D; i++)
    {
      if (pnt + P.at(prm.at(i)) * (prm.at(i) + 1) <= G)
      {
        pnt += P.at(prm.at(i)) * (prm.at(i) + 1) + C.at(prm.at(i));
        tmp += P.at(prm.at(i));
      }
      else
      {
        tmp += min(P.at(prm.at(i)), divCeil(G - pnt, prm.at(i) + 1));
        if (P.at(prm.at(i)) <= divCeil(G - pnt, prm.at(i) + 1))
        {
          pnt += (prm.at(i) + 1) * P.at(prm.at(i));
          pnt += C.at(prm.at(i));
        }
        else
          pnt += (prm.at(i) + 1) * divCeil(G - pnt, prm.at(i) + 1);
      }
      //cerr << prm.at(i) << " " << pnt << " " << tmp << endl;

      if (pnt >= G)
        break;
    }
    chmin(ans, tmp);
    //cerr << endl;

  } while (next_permutation(prm.begin(), prm.end()));

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
typedef long long ll;


int main(void) {
  ll s;
  cin >> s;
  ll a = sqrt(s);
  while(a*a < s) {
    ++a;
  }
  ll x1, y2;
  ll rest = a*a - s;
  if(rest == 0) {
    x1 = y2 = 0;
  } else {
    for(x1 = 1; ; ++x1) {
      if(rest % x1 == 0 && rest / x1 <= 1000000000) {
        y2 = rest / x1;
        break;
      }
    }
  }
  printf("0 0 %lld %lld %lld %lld\n", x1, a, a, y2);
  
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

n,t=MI()
costs=[]
for i in range(n):
    c,ti=MI()
    if ti<=t:
        costs.append(c)
if len(costs)==0:
    print("TLE")
else:
    costs.sort()
    print(costs[0])

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

int main() {
  int N;
  cin >> N;
  int counter;
  for (int i = 1; i <= N; i++) {
    for (int x = 1; x <= sqrt(N)+1; x++) {
      for (int y = 1; y <= x; y++) {
        for (int z = 1; z <= y; z++) {
          int A = 0;
          int B = 0;
          int C = 0;
          if (x == y)
            A = 1;
          if (y == z)
            B = 1;
          if (z == x)
            C = 1;
          if ((x+y)*(x+y)+(y+z)*(y+z)+(z+x)*(z+x) == 2*i && A+B+C == 3)
            counter += 1;
          if ((x+y)*(x+y)+(y+z)*(y+z)+(z+x)*(z+x) == 2*i && A+B+C == 1)
            counter += 3;
          if ((x+y)*(x+y)+(y+z)*(y+z)+(z+x)*(z+x) == 2*i && A+B+C == 0)
            counter += 6;
        }
      }
    }
    cout << counter << endl;
    counter = 0;
  }
}


Measured memory_bytes: 3652
h,w = map(int,input().split())

mat = []
for i in range(h):
    mat.append(input())
def outrange(i,j,h,w):
    if i<0 or i>=h:
        return True
    if j<0 or j>=w:
        return True
    return False
for i in range(h):
    for j in range(w):
        if mat[i][j] == '.':
            continue
        #up
        if not outrange(i-1,j,h,w) and mat[i-1][j]=='#':
            continue
        if not outrange(i,j-1,h,w) and mat[i][j-1]=='#':
            continue
        if not outrange(i+1,j,h,w) and mat[i+1][j]=='#':
            continue
        if not outrange(i,j+1,h,w) and mat[i][j+1]=='#':
            continue

        print("No")
        exit(0)
print("Yes")
            


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

using ll = long long;

const int MAXN = 1.1e5;
int N; ll C;
ll X[MAXN];
ll V[MAXN];

ll cost[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> C;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> V[i];
	}

	ll ans = 0;
	X[N] = C;
	for (int z = 0; z < 2; z++) {
		cost[N] = 0;
		for (int i = N-1; i >= 0; i--) {
			cost[i] = cost[i+1] - 2 * (X[i+1]-X[i]) + V[i];
		}

		for (int i = N-1; i >= 0; i--) {
			cost[i] = max(cost[i], cost[i+1]);
		}

		ll sum = 0;
		for (int i = 0; i < N; i++) {
			sum += V[i];
			ans = max(ans, sum - X[i] + cost[i+1]);
		}

		for (int i = 0; i < N; i++) {
			X[i] = C-X[i];
		}
		reverse(X,X+N);
		reverse(V,V+N);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 2560
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

int main() {
	int N;
	bool odd[100010] = {};
	cin >> N;
	int ans = 0;
	for (int i = 1; i <= 9; i++) {
		odd[i] = true;
	}
	for (int i = 100; i <= 999; i++) {
		odd[i] = true;
	}
	for (int i = 10000; i <= 99999; i++) {
		odd[i] = true;
	}
	for (int i = 1; i <= N; i++) {
		if (odd[i]) ans++;
	}
	cout << ans << endl;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL ex_gcd(LL a, LL b, LL & x, LL & y) {
	LL d = a;
	if(b != 0) {
		d = ex_gcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else { x = 1; y = 0; }
	return d;
}
LL divmod(LL x, LL y, LL MOD) {
	LL inv, m;
	ex_gcd(y, MOD, inv, m);
	if(inv < 0) { inv += MOD; }
	return x * inv % MOD;
}

LL n, a[100001], b[100001], v, MOD = 1e9 + 7;

int main() {
	cin >> n;
	inc(i, n + 1) { cin >> a[i]; }
	
	inc(i, n + 1) { b[i] = -1; }
	inc(i, n + 1) {
		if(b[ a[i] ] != -1) {
			v = n + 1 - (abs(b[ a[i] ] - i) + 1);
			break;
		}
		b[ a[i] ] = i;
	}
	
	LL p = 1, q = n - 1, r = 1, s;
	inc1(k, n + 1) {
		LL ans = 0;
		if(k - 1 <= v) { ans += MOD - p; }
		if(inII(k - 0, 0, n - 1)) { ans += q; }
		if(inII(k - 1, 0, n - 1)) { ans += r * 2; }
		if(inII(k - 2, 0, n - 1)) { ans += s; }
		ans %= MOD;
		
		cout << ans << "\n";
		
		s = r;
		r = q;
		(q *= n - 1 - k) %= MOD;
		q = divmod(q, k + 1, MOD);
		(p *= v - (k - 1)) %= MOD;
		p = divmod(p, k, MOD);
	}
	
	return 0;
}


Measured memory_bytes: 2816
// https://atcoder.jp/contests/abc079/tasks/abc079_c

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eps 1e-15

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef tuple<int,int,int> ti3;

const int MOD_A = 1000000007;
const int MOD_B = 1000000009;
const int MOD_C = 998244353;

// 負の数にも対応した % 演算
ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}

string S;

void Main()
{
    cin >> S;
    int A = atoi(S.substr(0, 1).c_str());
    int B = atoi(S.substr(1, 1).c_str());
    int C = atoi(S.substr(2, 1).c_str());
    int D = atoi(S.substr(3, 1).c_str());

    rep(i,2)
    {
        rep(j,2)
        {
            rep(k,2)
            {
                int res = i == 0 ? (A + B) : (A - B);
                res += j == 0 ? (C) : (-C);
                res += k == 0 ? (D) : (-D);
                if (res == 7) {
                    cout << A;
                    cout << (i == 0 ? "+" : "-");
                    cout << B;
                    cout << (j == 0 ? "+" : "-");
                    cout << C;
                    cout << (k == 0 ? "+" : "-");
                    cout << D;
                    cout << "=7";
                    return;
                }
            }
        }
    }
}

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


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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
typedef unsigned long long ull;
typedef long long ll;

const int MAXN=1e9;
ll cc,n;
vector<ll> A;
map<int,int> M;

/*bool check(ll x){
    string s=to_string(x);
    bool ss=false,t=false,f=false;
    for(auto c: s){
        if(c!='7' || c!='5' || c!='3')
            return false;
        if(c=='7')
            ss=true;
        if(c=='3')
            t=true;
        if(c=='5')
            f=true;
    }
    if(ss && t && f)
        return true;
    else
        return false;
}*/

bool check(ll x){
    M.clear();
    while(x){
        M[x%10]++;
        x/=10;
    }

    return (M[3]>0 && M[5]>0 && M[7]>0);
}

void gen(ll x){
    if(x>n)
        return;
    if(check(x))
        cc++;
    gen(x*10+3);
    gen(x*10+5);
    gen(x*10+7);
}

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

    cc=0;

    cin >> n;
    gen(0);

    cout << cc << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main{
public static void main(String[] args){
Scanner stdIn = new Scanner(System.in);

int a = stdIn.nextInt();
int b = stdIn.nextInt();
while(a!=0||b!=0){
if (a<b){
System.out.println(a + " " + b);
} else {
System.out.println(b + " " + a);
}
a = stdIn.nextInt();
b = stdIn.nextInt();
}
}
}


Measured memory_bytes: 35660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    int M,D;
    cin>>M>>D;
    int ans = 0;
    rep1(m,M+1){
        rep1(d,D+1){
            int d1 = d%10;
            int d10 = d/10;
            //cerr<<d1<<" "<<d10<<endl;
            if(d1>=2&&d10>=2&&d1*d10 == m){
                ans++;
            }
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 10010
#define llg long long 
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,mid,ans,x;
int main()
{
	scanf("%lld",&x);
	llg l=1,r=1e9;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if ((llg)mid*(mid+1)/2>=x) {r=mid-1,ans=mid;} else l=mid+1;
	}
	printf("%lld",ans);
	return 0;
}


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

using namespace std;

#define tie() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define ff first
#define ss second

void solve()
{
    int n;cin>>n;
    cout<<n*n*n<<endl;
    return;
}


int32_t main()
{
    tie();
    int t = 1;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}
template<class T> T gcd( T a, T b ) {
    return !b ? a : gcd( b, a % b );
}
template<class T> T lcm( T a, T b ) {
    return a / gcd( a, b ) * b;
}


typedef long long LL;
const int SIZE = 11;
int n;
LL D[SIZE], V[SIZE];
LL T[SIZE];

void solve() {
    for ( int i = 0; i < n; ++ i ) {
        LL t = gcd( D[i], V[i] );
        D[i] /= t;
        V[i] /= t;
    }
    LL vgcd = V[0];
    for ( int i = 1; i < n; ++ i ) {
        vgcd = gcd( vgcd, V[i] );
    }
    LL dlcm = D[0];
    for ( int i = 1; i < n; ++ i ) {
        dlcm = lcm( dlcm, D[i] );
    }
    for ( int i = 0; i < n; ++ i ) {
        cout << ( dlcm * V[i] / D[i] / vgcd ) << endl;
    }
    return;
}

int main() {
    while ( cin >> n && n ) {
        for ( int i = 0; i < n; ++ i ) {
            cin >> D[i] >> V[i];
        }
        solve();
    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

int N;
ll A[200000 + 10];

ll cnt_ox[200000 + 10], cnt_xo[200000 + 10];
ll dp_ox[200000 + 10][3];

int main() {
	for (int i = 0; i < 200000; i++) {
		for (int j = 0; j < 3; j++)
			dp_ox[i][j] = -1e18;
	}
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i];

	for (int i = 0; i < N; i++) {
		cnt_ox[i + 1] = cnt_ox[i];
		cnt_xo[i + 1] = cnt_xo[i];
		if (i % 2 == 0)cnt_ox[i + 1] += A[i];
		else if (i % 2 == 1)cnt_xo[i + 1] += A[i];
	}

	ll ans = max(cnt_xo[N], cnt_ox[N]);
	//1回変化  (ox)(xo)
	for (int i = 0; i < N; i += 2) {
		ans = max(ans, cnt_ox[i] + (cnt_xo[N] - cnt_xo[i]));
	}

	//奇数限定　1回飛ばし (ox)x(xo)
	if (N % 2 == 1) {
		ll tmp = A[0];
		for (int i = 0; i < N; i++) {
			tmp = min(tmp, A[i]);
		}
		ans = max(ans, cnt_ox[N] - tmp);
	}

	//奇数限定　(xoxoxox) たぶん偶数の中で包含されてるけど
	if (N % 2 == 1) {
		ans = max(ans, cnt_xo[N]);
	}

	//奇数限定 (ox)(xo)x(xo) 2回変化
	if (N % 2 == 1) {
		dp_ox[1][0] = A[0];
		for (int i = 0; i < N - 1; i++) {
			for (int j = 0; j < 3; j++) {
				if (dp_ox[i][j] == -1e18)continue;
				if (j == 0) {
					//oxを継続させる。
					dp_ox[i + 2][0] = dp_ox[i][j] + A[i + 1];
					//xoへシフトする。
					dp_ox[i + 2][1] = max(dp_ox[i + 2][1], dp_ox[i][j] + A[i + 2]);
				}
				else if (j == 1) {
					//xoを継続させる。
					dp_ox[i + 2][1] = max(dp_ox[i + 2][1], dp_ox[i][j] + A[i + 2]);
					//oxへシフトする。
					dp_ox[i + 3][2] = max(dp_ox[i + 3][2], dp_ox[i][j] + A[i + 3]);
				}
				else if (j == 2) {
					//oxを継続させる。
					dp_ox[i + 2][2] = max(dp_ox[i + 2][2], dp_ox[i][j] + A[i + 2]);
				}
			}
		}
		ans = max(ans, dp_ox[N - 1][2]);
	}

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

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

int main() {
	int n, c = 1;
	cin >> n;
	int p[n];
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	int min=p[0];
	for (int i = 1; i < n; ++i) {
		if(p[i]<min){
			++c;
			min=p[i];
		}
	}
	cout << c << endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  if (n%10==3)
    cout << "bon" << endl;
  if (n%10==0|| n%10==1 || n%10==6 || n%10==8)
    cout << "pon" << endl;
  if (n%10==2 || n%10==4 ||n%10==5 ||n%10==7 ||n%10==9)
    cout << "hon" << endl;
}

Measured memory_bytes: 3588
A=[]
for _ in range(3):
    A+=list(map(int, input().split()))
N=int(input())
b=[]
for _ in range(N):
    b.append(int(input()))


BINGO=[{0,1,2}, {3,4,5}, {6,7,8}, {0,3,6}, {1,4,7}, {2,5,8}, {0,4,8}, {2,4,6}]

hole=set()
for num in b:
    for i in range(9):
        if num==A[i]:
            hole.add(i)

for tri in BINGO:

    if tri <= hole:
        print('Yes')
        break
else:
    print('No')



Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
            int N=sc.nextInt();
            int A=sc.nextInt();
            int B=sc.nextInt();
            String str = sc.next();
            String[] spt = str.split("");
            int win=0;
            int b=0;
            
            for(int i=0;i<N;i++){
                
                if(spt[i].equals("a")){
                    if(win<A+B){
                        win++;
                        System.out.println("Yes");
                    }else{
                        System.out.println("No");
                    }
                }
                if(spt[i].equals("b")){
                    b++;
                    if(win<A+B && b<=B){
                        win++;
                        System.out.println("Yes");
                    }else{
                        System.out.println("No");
                    }
                }
                if(spt[i].equals("c")){
                    System.out.println("No");
                }
            }
            
            
    }
}


Measured memory_bytes: 62160
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
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);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
	inv[0]=1;
	inv[1] = 1;
	for(int i = 2; i <=1e6 ; ++i)
		inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
	invf[0]=1;invf[1]=1;
	for(int i=2;i<=1e6;i++){
		invf[i]=invf[i-1]*inv[i]%mod;
	}
}*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
int solve()
{
	int n,x,t;
	cin>>n>>x>>t;
	int cnt=0;
	int idx=0;
	while(cnt<n){
		cnt+=x;
		idx++;
	}
	cout<<idx*t<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}



Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
using namespace std;
using boost::irange;

// 定義
typedef long long           ll;
typedef pair<ll, ll>        P;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
const ll                    INF = 2e9;
const ll                    INF_LL = 1LL<<60;
const ll                    MOD = 998244353;

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 処理
void Solve()
{
	ll N;
	cin >> N;
	vector<P> A(N);
	for_each(ALL(A), [](P &one){ cin >> one.first, one.second = 1; });
	
	priority_queue<P, vector<P>, greater<P>> que;
	for (auto one : A) {
		que.push(one);
	}

	while (que.size() != 1) {
		P now = que.top(); que.pop();
		P next = que.top(); que.pop();
		if (next.first <= now.first * 2) {
			next.second += now.second;
		}
		next.first += now.first;
		que.push(next);
	}

	P ans = que.top();
	cout << ans.second << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>

#define PI 3.1415926535897

typedef long long ll;

using namespace std;



int main() {
    ll s, w;
    cin >> s >> w;
    if (w >= s) {
        cout << "unsafe";
   }
    else {
        cout << "safe";
    }

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n,x;
    cin >> n >> x;
    int l[n];
    for(int i=0;i<n;i++) cin >> l[i];

    int sum=0;
    int counter=1;
    for(int i=0;i<n;i++){
        sum += l[i];
        if(sum<=x){
            counter++;
        }
    }

    cout << counter << endl;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main { 
	public static void main(String argsp[]) 
    {	
      	Scanner sc = new Scanner(System.in);
      	String input = sc.nextLine();
      	String[] inputs = input.split(" ");
      	int N = Integer.valueOf(inputs[0]);
      	int M = Integer.valueOf(inputs[1]);
      	int[] likedFood  = new int[M+1];
      	
      	for( int i = 0 ; i<N ; i++ )
        {
          	input  = sc.nextLine();
          	inputs = input.split(" ");
          	int foodLiked = Integer.valueOf(inputs[0]);
          	for(int j = 1 ;j<=foodLiked ; j++)
            {
               int value = Integer.valueOf(inputs[j]);
               likedFood[value]+=1;
            }
        }
      int ans = 0; 
      for( int i = 1 ; i<=M ; i++) {
      	if(likedFood[i]==N)
        {
          ans++;
        }
      }
      System.out.println(ans);
    }
}

Measured memory_bytes: 23508
class UnionFind
  attr :parent, :rank
  def initialize
    @parent = Hash.new
    @rank = Hash.new
  end
  def make(x)
    @parent[x] = x
    @rank[x] = 0
  end
  def union(a, b)
    x, y = find(a), find(b)
    x, y = y, x if @rank[x] < @rank[y]
    @parent[y] = x
    @rank[x] += 1 if @rank[x] == @rank[y]
  end
  def find(x)
    @parent[x] == x ? x : @parent[x] = find(@parent[x])
  end
  def size
    @parent.keys.map{|k| find(k)}.sort.uniq.size
  end
end

class Point
  attr :id, :x, :y
  def initialize(id, x, y)
    @id, @x, @y = id, x, y
  end
end

require 'set'

P = gets.to_i.times.map{|i| Point.new(i, *gets.split.map(&:to_i))}

uf = UnionFind.new
P.each do |p|
  uf.make(p.id)
end
P.sort{|l, r| l.x <=> r.x}.each_cons(2) do |l, r|
  uf.union(l.id, r.id) if l.x == r.x
end
P.sort{|l, r| l.y <=> r.y}.each_cons(2) do |l, r|
  uf.union(l.id, r.id) if l.y == r.y
end

X = Hash.new{|h, k| h[k] = Set.new}
Y = Hash.new{|h, k| h[k] = Set.new}
G = Set.new
P.each do |p|
  g = uf.find(p.id)
  G << g
  X[g] << p.x
  Y[g] << p.y
end
p G.map{|g| X[g].size * Y[g].size}.inject(:+) - P.size


Measured memory_bytes: 30696
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
using namespace std;

int main(){
    int n;
    cin >> n;
    long mod;
    mod = pow(10,9) + 7;

    long ans = 1;
    for(int i = 2 ; i <= n ; i++){
        ans *= i;
        ans %= mod;
    }

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool f(int a)
{
	for(int i=2;i*i<=a;i++)
	{
		if(a%i==0)
		{
			return false;
		}
	}
	return true;
}
int s[1<<17];
int q,l,r;
main()
{
	for(int i=3;i<=1e5;i+=2)
	{
		if(f(i)&&f((i+1)/2))s[i]=1;
	}
	for(int i=1;i<=1e5;i++)s[i]+=s[i-1];
	cin>>q;
	for(int i=0;i<q;i++)
	{
		cin>>l>>r;
		cout<<s[r]-s[l-1]<<endl;
	}
}

Measured memory_bytes: 1024
n, y = (int(s) for s in input().split())

i_max = min(y // 10000, n)
i_min = max((y - n * 5000 + 4000) // 5000, 0)

for i in range(i_min, i_max + 1):
    j_4 = y // 1000 - n - i * 9
    if not j_4 % 4:
        j = j_4 // 4
        k = n - i - j_4 // 4
        if j >= 0 and k >= 0:
            print(i, j, k)
            break
        else:
            continue
    else:
        continue
else:
    print(-1, -1, -1)


Measured memory_bytes: 3064
from collections import deque
N = int(input())
X = str(input())
X = list(X)
#motokosu = X.count("1")
motokosu = 0
only = float("inf")
for i in range(N):
  if X[i] == "1":
    motokosu += 1
    only = i
if motokosu != 1:
  only = float("inf")
#print(motosuji,motokosu)
MAX = 2*pow(10,5)+10
base = [0 for _ in range(MAX)] #0から19までの答えを保存
for i in range(MAX):
  now = i
  temp = 0
  while now != 0:
    ones = 0
    tnow = now*1
    for t in range(len(bin(now))-2):
      if (now>>t)&1 == 1:
        ones += 1
    #print(i,ones,now)
    now = now%ones
    #print(now,base[now])
    base[i] = base[now] + 1
    break
    #temp += 1
  #base[i] = temp
#print(base)
A = []
pkosu = motokosu+1
mkosu = motokosu-1
P = deque([])
M = deque([])
ptemp = 1; mtemp = 1
for i in range(N):
  P.appendleft(ptemp%pkosu)
  ptemp = ptemp*2%pkosu
  if mkosu < 1:
    M.appendleft(0)
  else:
    M.appendleft(mtemp%mkosu)
    mtemp = mtemp*2%mkosu

pmotosuji = 0; mmotosuji = 0
for i in range(N):
  if X[i] == "1":
    pmotosuji = (pmotosuji+P[i])%pkosu
    if mkosu >= 1:
      mmotosuji = (mmotosuji+M[i])%mkosu
#print(P,M,pkosu,mkosu,pmotosuji,mmotosuji)

for i in range(N): #i桁目を入れ替える
  if only == i:
    print(0)
    continue
  if X[i] == "0": #その桁が0なら1にする
    kosu = motokosu + 1
    suji = (pmotosuji + P[i])%kosu
  else: #その桁が1なら0にする
    kosu = motokosu - 1
    if kosu == 0:
      suji = -1
    else:
      suji = (mmotosuji - M[i])%kosu
    
  #print(suji,kosu)
  #if suji == 0:
  #  ans = 0
  if suji == -1:
    ans = 1
  else:
    nxt = suji%kosu
    ans = 1+base[nxt]
  #A.append(ans)
  print(ans)

#print(*A,sep="\n")
#print(2**17)
#print(motokosu)

  

        

Measured memory_bytes: 94508
# 入力
a, b = input().split()

# 出力
# a = 'H' のときatくんは正直者
if a == 'H' and b == 'H':
    print('H')
elif a == 'D' and b == 'H':
    print('D')
elif a == 'H' and b =='D':
    print('D')
elif a == 'D' and b == 'D':
    print('H')

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

using namespace std;

int main(){
    int n;
    cin >> n;
    priority_queue<double, vector<double>, greater<double>> v;
    while(n--){
        int a;
        cin >> a;
        v.push(a);
    }

    while(v.size() > 1){
        double a = v.top(); v.pop();
        double b = v.top(); v.pop();

        v.push((a+b) / 2);
    }

    cout << setprecision(7) << fixed << v.top() << endl;
}


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

const int N = 105;
typedef unsigned long long ULL;

int n, head[N], tot, a[N], b[N];
struct edge { int to, nxt; } e[N << 1];

void link(int x, int y) {
	e[++tot] = (edge) { y, head[x] }, head[x] = tot;
	e[++tot] = (edge) { x, head[y] }, head[y] = tot;
}

int max_dep = 0, max_number[N];
void dfs(int x, int f = 0, int dep = 1) {
	max_dep = std::max(max_dep, dep);
	int son_num = 0;
	for (int i = head[x]; i; i = e[i].nxt) if (e[i].to != f) {
		++son_num, dfs(e[i].to, x, dep + 1);
	}
	max_number[dep] = std::max(max_number[dep], son_num);
}

void check(ULL &ans, int t = 1) {
	ULL tmp = ans / t;
	for (int i = 1; i < max_dep; ++i)
		tmp /= max_number[i];
	if (tmp) {
		ans = t;
		for (int i = 1; i < max_dep; ++i)
			ans *= max_number[i];
	}
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i < n; ++i)
		std::cin >> a[i] >> b[i], link(a[i], b[i]);
		
	int min_color = n;
	ULL ans = -1;
	
	for (int i = 1; i <= n; ++i) {
		max_dep = 0, std::memset(max_number, 0, sizeof max_number);
		dfs(i);
		if (max_dep < min_color) {
			min_color = max_dep;
			ans = -1, check(ans);
		} else if (max_dep == min_color) {
			check(ans);
		}
	}
	for (int i = 1; i < n; ++i) {
		max_dep = 0, std::memset(max_number, 0, sizeof max_number);
		dfs(a[i], b[i]), dfs(b[i], a[i]);
		if (max_dep < min_color) {
			min_color = max_dep;
			ans = -1, check(ans, 2);
		} else if (max_dep == min_color) {
			check(ans, 2);
		}
	}
	
	std::cout << min_color << ' ' << ans << '\n';
	return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>

using namespace std;

typedef long long ll;

int main() {
  int N, Y;
  cin >> N >> Y;
  rep(i, N + 1) {
    rep(j, N - i + 1) {
      int z = N - i - j;
      if (Y == 10000 * i + 5000 * j + 1000 * z) {
        cout << i << ' ' << j << ' ' << z << endl;
        return 0;
      }
    }
  }
  cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  return 0;
}

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

using namespace std;

#define int long long

signed main(){
	const int NUM = 10;
	
	int N, K;
	vector<int> a;
	vector<deque<int>> d(NUM);
	
	cin>>N>>K;
	
	a.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
		d[a[i]].push_back(i);
	}
	
	for(int i = 0, b = -1; i < N - K; i++){
		int num = 0;
		bool flag = false;
		
		for(int j = NUM-1; j >= 0; j--){
			int temp = -1;
		
			// cout<<"j = "<<j<<" size = "<<d[j].size()<<endl;
			
			while(d[j].size()){
				temp = d[j].front();
				
				// cout<<"i = "<<i<<" j = "<<j<<" temp = "<<temp<<" K+i = "<<K+i<<" b = "<<b<<endl;
				
				if(temp <= K+i) {
					if(b < temp){
						flag = true;
						
						b = temp;
						
						cout<<j;
						
						break;
					}
					
					d[j].pop_front(); 
					
				} else {
					break;
				}
			}
			
			if(flag) break;
		}
	}
	
	cout<<endl;
	
}


Measured memory_bytes: 5976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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 main(void) {
    ll s;
    cin>>s;
    ll a,b,c,d;
    a=1e9;
    b=1;
    d=ceil((long double)s/(double)a);
    c=a*d-s;
    cout<<"0 0 "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    S = input()
    max_ACGT_length = 0
    for start in range(len(S)):
        if not (ACGT(S[start])):
            continue
        ACGT_length = 1
        for index in range(start+1,len(S)):
            if ACGT(S[index]):
                ACGT_length += 1
            else:
                break
        if ACGT_length > max_ACGT_length:
            max_ACGT_length = ACGT_length

    print(max_ACGT_length)

def ACGT(chr):
    return (chr == 'A' or chr == 'C' or chr == 'G' or chr == 'T')

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  string a,b,c;
  cin >> a;
  int cflag=0;
  int flag=0;
  for (int i=0;i<a.length();i++){
    if(a[i]=='C') cflag=1;
    if(a[i]=='F' && cflag==1) flag=1;
  }
  if(flag){  
    cout <<"Yes" <<endl;
  }else{
	cout << "No" <<endl; 
  }
  return 0;
}


Measured memory_bytes: 256
package main
import (
	"fmt"
)
func main() {
	var s string
	fmt.Scanf("%s", &s)
	answer := coffeeLike(s)
	if answer {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func coffeeLike(s string) bool{
	return s[2] == s[3] && s[4] == s[5]
}

Measured memory_bytes: 512