akhauriyash/Code-Regression huggingface dataset:
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

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

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

X = In.int()

cur = 100
steps = 0
while cur<X:
    cur += cur//100
    steps+=1

Out.int(steps)
        
######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

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

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

int n, fact[N], ifact[N], f[N];

int binpow(int a, int b) {
	int ret = 1;
	while(b) {
		if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod;
		b >>= 1;
	}
	return ret;
}

int C(int n, int k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return 1LL * fact[n] * (1LL * ifact[k] * ifact[n - k] % mod) % mod;
}

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

	cin >> n;
	fact[0] = 1;
	for (int i = 1; i < N; ++i) fact[i] = 1LL * fact[i - 1] * i % mod;
	ifact[0] = 1;
	for (int i = 1; i < N; ++i) ifact[i] = binpow(fact[i], mod - 2);

	for (int k = 1; k <= n - 1; ++k) {
		f[k] = 1LL * C(k - 1, n - k - 1) * (1LL * fact[k] * fact[n - k - 1] % mod) % mod;
	}

	int res = 0;
	for (int k = 1; k <= n - 1; ++k) {
		int cur = (f[k] - f[k - 1] + mod) % mod;
		res = (res + 1LL * cur * k) % mod;
	}

	cout << res << '\n';
}

Measured memory_bytes: 12032
#include<stdio.h>
int main(){
  int i;
  int a[33]={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};
  scanf("%d",&i);
  printf("%d\n",a[i-1]);
  return 0;
}
  

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

int N, M;
vector<vector<int>> T(9);
bitset<9> dp;

int rec(int corrent = 1, int count = 1){
    
    if(count == N){
        return 1;
    }
    
    int res = 0;
    for(int i = 0; i < T[corrent].size(); ++i){
        if(corrent == 1){
            dp.reset(), dp.set(corrent);
        }
        if(!dp[T[corrent][i]]){
            dp.set(T[corrent][i]);
            res += rec(T[corrent][i], count + 1);
            dp.reset(T[corrent][i]);
        }
    }
    
    return res;
}

int main(void){
    
	cin >> N >> M;
	for(int i = 0; i < M; ++i){
	    int temp1, temp2;
	    cin >> temp1 >> temp2;
	    T[temp1].push_back(temp2);
	    T[temp2].push_back(temp1);
	}
	
	int ans = 0;
	ans += rec();
	cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)]

# dp[i][j] := i日目までにjを選んだときのmax幸福度
# j={A=0,B=1,C=2}の添え字を使うことにする
dp = [[0]*3 for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:  # 前日と同じActivityは除外
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j]+ABC[i][k])

print(max(dp[N][0], dp[N][1], dp[N][2]))

Measured memory_bytes: 74072
#include <iostream>
#include <vector>
using namespace std;
int main(){
  long long N;
  cin >> N;
  
  vector<long long>A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
 
  vector<long long>B(N+1,0);
  for(int i=0;i<N;i++){
    B[A[i]]++;
  }
  
  long long ans = 0;
  for(int i=0;i<N+1;i++){
    ans += B[i] * (B[i] - 1) / 2;
  }
  
  
  for(int i=0;i<N;i++){
    cout << ans - B[A[i]] + 1 << endl;
  }
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
  Node m,n;
  
  if(u->key == k) return u;
  else if(u->key > k){
    if(u->left != NIL){
      n = treeSearch(u->left,k);
      if(n!=NIL) return n;  
    }
  }
  else if(u->key < k){
    if(u->right != NIL){
      m = treeSearch(u->right,k);
      if(m!=NIL) return m;
    }
  }
  return NIL;
}
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

}

void inorder(Node u){
  if(u->left != NIL) inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NIL) inorder(u->right);  
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



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

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       




        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = Reads();
            long j = 1;
            for (int i = 0; i < n; i++)
            {
                if (a[i] == j) j++;
            }
            Console.WriteLine(j == 1 ? -1 : n - (j - 1));

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 36420
#include<iostream>

#define ll long long

ll unsigned int MOD = 1000000007;
ll int N;

int main(){
    ll unsigned int ans = 1;
    std::cin >> N;
    for(int i = 1; i <= N; i++){
        ans = (ans*i) % MOD;
    }

    std::cout << ans;

    return 0;
}

Measured memory_bytes: 256
ABCD=input()
f=""
for bit in range(1<<3):
  f=ABCD[0]
  for i in range(3):
    if bit&(1<<i):
      f+="+"
    else:
      f+="-"
    f+=ABCD[i+1]
  if eval(f)==7:
    print(f+"=7")
    exit()


Measured memory_bytes: 9048
n,k_ = map(int,input().split())
a_li = list(map(int,input().split()))
a_li_o = [0]*n
for i in range(k_):
    for l in range(n):
        a_li_o[l] = a_li[l]
    dum_li = [0]*n
    for j in range(n):
        left = j - a_li[j]
        right = j + a_li[j] + 1
        if left < 0:
            left = 0
        dum_li[left] += 1
        if right > n-1:
            continue
        dum_li[right] -= 1
    total = 0
    for k in range(n):
        total += dum_li[k]
        dum_li[k] = total
    for k in range(n):
        a_li[k] = dum_li[k]
    if a_li_o == a_li:
        break
print(" ".join(map(str,a_li)))

Measured memory_bytes: 148080
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
min_price = min(a) + min(b)
for i in range(m):
    x,y,c = map(int,input().split())
    temp = a[x-1] + b[y-1] - c
    if temp < min_price:
        min_price = temp
print(min_price)

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

int main()
{
    int r, g, b, K;
    cin >> r >> g >> b >> K;

    for (int i = 0; i < K;i++)
    {
        if(g<=r)
        {
            g *= 2;
        }else
        {
            b *= 2;
        }
    }
    if(r<g&&g<b)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
#include <queue>
#include <utility>
#define MAXHW 1000 + 1

using namespace std;
typedef pair<int, int> P;

int n, m, H, W, N, d[MAXHW][MAXHW];
char fac[MAXHW][MAXHW];

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

int bfs(int a, int b, int s){
	memset(d, -1, sizeof(d));
	queue<P> q;
	d[a][b] = 0;
	q.push(P(a, b));
	
	while(!q.empty()){
		P p = q.front();
		q.pop();
		
		if(fac[p.first][p.second] == char(s + '0')){
			n = p.first, m = p.second;
			return d[p.first][p.second];
		}
		
		for(int i = 0; i < 4; i++){
			int h = p.first + dy[i];
			int k = p.second + dx[i];
			if(h >= 0 && h < H && k >= 0 && k < W && fac[h][k] != 'X' && d[h][k] == -1){
				d[h][k] = d[p.first][p.second] + 1;
				q.push(P(h, k));
			}
		}
	}
}

int main(){
	int sum = 0;
	scanf("%d %d %d", &H, &W, &N);
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> fac[i][j];
			if(fac[i][j] == 'S')
				n = i, m = j;
		}
	}
	for(int i = 1; i <= N; i++)
		sum += bfs(n, m, i);
	
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 8088
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
int encode[1 << 17];
int decode[150000];
int cnt = 0;
ll dp[41][150000];
ll mod_pow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll x = mod_pow(a, b / 2);
		return (x*x) % MOD;
	}
	return (a*mod_pow(a, b - 1)) % MOD;
}
void dfs(ll bit, int sum) {
	decode[cnt] = bit;
	encode[bit] = cnt++;
	for (int i = 1; i <= 10; i++) {
		if (sum + i <= 17) {
			dfs((bit << i) | (1 << (i - 1)), sum + i);
		}
	}
}
int main() {
	dfs(0, 0);
	int N, X, Y, Z;
	cin >> N >> X >> Y >> Z;
	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < cnt; j++) {
			if (dp[i][j] == 0) continue;
			int bit = decode[j];
			for (int k = 1; k <= 10; k++) {
				int nbit = (bit << k) | (1 << (k - 1));
				int tmp = nbit;
				if ((tmp&(1 << (Z - 1)))) {
					tmp >>= Z;
					if ((tmp&(1 << (Y - 1)))) {
						tmp >>= Y;
						if ((tmp&(1 << (X - 1)))) continue;
					}
				}
				nbit &= (1 << (X + Y + Z)) - 1;
				(dp[i + 1][encode[nbit]] += dp[i][j]) %= MOD;
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < cnt; i++) (ans += dp[N][i]) %= MOD;
	ans = (mod_pow(10, N) + MOD - ans) % MOD;
	cout << ans << endl;
}


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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int N, maxA = 0, max2A = 0, count = 0;
   cin >> N;

   vector<int> A(N);
   rep(i, N) {
     cin >> A.at(i);
     maxA = max(maxA, A.at(i));
   }
   rep(i, N) {
     if (maxA == A.at(i)) count++;
     if (count >= 2) break;
   }

   if (count == 1) {
     rep(i, N) {
       if (A.at(i) == maxA) continue;
       else max2A = max(max2A, A.at(i));
     }
   }

   if (count == 1) {
     rep(i, N) {
       if (A.at(i) == maxA) cout << max2A << endl;
       else cout << maxA << endl;
     }
   }

   else rep(i, N) cout << maxA << endl;
 }


Measured memory_bytes: 2432
#!/usr/bin/env python3
#ABC138 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
graph = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = LI()
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
cnt = [0]*n
for _ in range(q):
    p,x = LI()
    cnt[p-1] += x
#オイラーツアー
def dfs(x,p):
    for i in graph[x]:
        if i != p:
            cnt[i] += cnt[x]
            dfs(i,x)
dfs(0,-1)
print(*cnt)


Measured memory_bytes: 237684
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()
#define INPUT1(var) FOR(i,countof(var)) var[i] = ri() - 1

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri();
    int k = ri();
    int x[n];
    INPUT(x);
    int res = INF;
    FOR(i, n-k+1) {
        int l = x[i];
        int r = x[i+k-1];
        // cout << l << "  " << r << endl;
        if ((l <= 0 && r <= 0) || (l >= 0 && r >= 0)) res = min(res, max(abs(r),abs(l)));
        else res = min(res, 2*min(abs(r),abs(l))+max(abs(l),abs(r)));
    }
    cout << res << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <random>
#include <deque>
#define INF_LL 1e18
#define INF 1e9

typedef long long ll;

using namespace std;

int devide_with_two(int x)
{
  int y = 0;
  while (x % 2 == 0)
  {
    x = x / 2;
    y++;
  }

  return y;
}

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

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

  int res = 0;
  for (int i = 0; i < n; i++)
  {
    res += devide_with_two(a[i]);
  }

  cout << res << endl;
  return 0;
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    cout << ((v > w && abs(b - a) <= t * (v - w)) ? "YES" : "NO") << newl;
    return 0;
}

Measured memory_bytes: 3604
fun main(args: Array<String>) {
    val s = readLine()!!
    var num = 0
    if(s[0] == '1') {
        num += 1
    }
    if(s[1] == '1') {
        num += 1
    }
    if(s[2] == '1') {
        num += 1
    }
    println(num)
}

Measured memory_bytes: 31644
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
using pqueg = priority_queue<int, vector<int>, greater<int>>;
using pquel = priority_queue<int, vector<int>, less<int>>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
int lcm(int a, int b){
  return a / __gcd(a, b) * b;
}
int r_int(int a, int b){
  return rand() % b + a;
}
const lint mod=1e9+7;



int main()
{
  lint n;
  cin >> n;
  set<lint> a;
  REP(i,n){
    lint tmp;
    cin >> tmp;
    a.insert(tmp);
  }

  cout << (n == a.size() ? "YES" : "NO") << "\n";
  return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main(){
	ios;
	ll x,y;
	cin>>x>>y;
	cout<<min(y-x%y,x%y);
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;  //ansを出力する時は (ans % mod + mod) % mod とする(負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    ll n; cin >> n;
    vector<pair<ll,pair<ll,ll> > > v;
    ll ans = 0;
    rep(i,n){
        ll x,y; cin >> x >> y;
        v.push_back(make_pair(x+y,make_pair(x,y)));
    }
    sort(v.begin(),v.end());
    
    rep(i,n){
        if(i % 2 == 0) ans += v[(n-1-i)].second.first;
        else ans -= v[n-1-i].second.second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4980
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  int64_t result = 0;
  int64_t sum = 0;
  for (int64_t i = 0; i < N; ++i) {
    sum += A[i];
    if (i + 1 < N && sum * 2 < A[i + 1]) {
      result = 0;
    } else {
      ++result;
    }
  }
  cout << result << endl;
  return 0;
}


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

std::array<std::vector<long>,26> map;

int main(void){
    size_t n, q;
    std::string s;
    std::cin >> n >> q >> s;
    for(size_t i=0; i<n; i++){
        char c = s[i] - 'A';
        map[c].push_back(i);
    }
    std::vector<char> t(q), d(q);
    for(size_t i=0; i<q; i++){
        std::cin >> t[i] >> d[i];
    }
    long remove = 0;
    std::vector<long> area(n,1L);
    auto removep = [&](size_t pos){
        for(size_t i=0; i<q; i++){
            if(s[pos] == t[i]){
                if(d[i]=='R'){
                    if(pos==n-1){
                        return 1;
                    }
                    pos++;
                }else{
                    if(pos==0){
                        return -1;
                    }
                    pos--;
                }
            }
        }
        return 0;
    };
    //右端が左で消える
    if(removep(n-1)==-1){
        std::cout << 0 << std::endl;
        return 0;
    }
    //左端が右で消える
    if(removep(0)==1){
        std::cout << 0 << std::endl;
        return 0;
    }
    size_t ll, hh;
    {
        size_t low = 0;
        size_t high = n;
        while(high-low>1){
            auto mid = (low + high)/2;
            if(removep(mid)==-1){
                low = mid;
            }else{
                high = mid;
            }
        }
        ll = low;
    }
    {
        size_t low = 0;
        size_t high = n;
        while(high-low>1){
            auto mid = (low + high)/2;
            if(removep(mid)==1){
                high = mid;
            }else{
                low = mid;
            }
        }
        hh = low;
    }
    std::cout << hh - ll << std::endl;
#if 0
    for(size_t i=0; i<q; i++){
        char c = t[i] - 'A';
        const auto& m = map[c];
        size_t len = m.size();
        if(d[i]=='L'){
            for(size_t j=0; j<len; j++){
                const auto p = m[j];
                if(p==0){
                    remove += area[0];
                    area[p] = 0;
                }else{
                    area[p-1] += area[p];
                    area[p] = 0;
                }
            }
        }else{
            for(ssize_t j=len-1; j>=0; j--){
                const auto p = m[j];
                if(p==n-1){
                    remove += area[n-1];
                    area[p] = 0;
                }else{
                    area[p+1] += area[p];
                    area[p] = 0;
                }
            }
        }
        /*
           for(size_t j=0; j<n; j++){
           std::cout << area[j] << " ";
           }
           std::cout << std::endl;
           */
    }
    std::cout << n-remove << std::endl;
#endif
    return 0;
}


Measured memory_bytes: 4228
N = int(input())
A = list(map(int, input().split()))

def insertion_sort(A):
    for idx, target in enumerate(A[1:]):
        j = idx
        while j >= 0 and A[j] > target:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = target
        disp(A)

def disp(A):
    for i in A[:-1]:
        print(i, end=" ")
    print(A[-1])

disp(A)
insertion_sort(A)


Measured memory_bytes: 5984
#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//ruogu_alter
const int N=2e5+5;
const int inv2=(MOD+1)/2;
int n,a[N],b[N],cnt[N],ib[N],pre[N],dx[N],dy[N];
//
inline void add(int &x,int y){
	x+=y;if(x>=MOD)x-=MOD;
}
inline void sub(int &x,int y){
	x-=y;if(x<0)x+=MOD;
}
inline int sub2(int x,int y){
	x-=y;
	return (x<0)?x+MOD:x;
}
inline int mul(int x,int y){
	ll ans=1ll*x*y;
	return ans%MOD;
}
inline int modpow(int x,int y){
	int ans=1;
	while(y){
		if(y&1)ans=mul(ans,x);
		x=mul(x,x);
		y>>=1;
	}
	return ans;
}
inline int modinv(int x){
	return modpow(x,MOD-2);
}
inline void upd(int x,int y){
	while(x<N){
		add(dy[x],y);
		dx[x]++;
		x+=x&-x;
	}
}	
inline int qry(int *d,int x){
	int ans=0;
	while(x){
		add(ans,d[x]);
		x-=x&-x;
	}
	return ans;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=getint();
	for(int i=1;i<=n;i++){
		a[i]=getint();
		cnt[a[i]]++;
	}
	for(int i=n-1;i>=1;i--)cnt[i]+=cnt[i+1];
	for(int i=1;i<=n;i++)cnt[i]-=n-i;
	for(int i=1;i<=n;i++)if(cnt[i]<=0){
		return !printf("%d\n",0);
	}
	int s=1;pre[0]=b[0]=1;
	for(int i=1;i<=n;i++)s=mul(s,cnt[i]);
	for(int i=1;i<=n;i++){
		b[i]=mul(cnt[i]-1,modinv(cnt[i]));
		if(!b[i])pre[i]=i,b[i]=b[i-1];
		else pre[i]=pre[i-1],b[i]=mul(b[i-1],b[i]);
		ib[i]=modinv(b[i]);
	}
	int res=0;
	for(int i=1;i<=n;i++){
		add(res,mul(b[a[i]],mul(s,mul(inv2,sub2(qry(dy,a[i]),qry(dy,pre[a[i]]-1))))));	
//		cout<<res<<endl;
		upd(a[i],ib[a[i]]);
	}
//	cout<<res<<endl;
	memset(dx,0,sizeof(dx));
	memset(dy,0,sizeof(dy));
	for(int i=n;i>=1;i--){
		sub(res,mul(b[a[i]],mul(s,mul(inv2,sub2(qry(dy,a[i]-1),qry(dy,pre[a[i]]-1))))));
		add(res,mul(s,qry(dx,a[i]-1)));
		upd(a[i],ib[a[i]]);
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 5760
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,child,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int h[100];
int main(){
  int s;
  cin >> s;
  if(s == 1 || s == 2 || s == 4){
    cout << 4 << endl;
    return 0;
  }
  int ans = 4;
  rep(i, 1000000){
    if(s == 4) break;
    if(s % 2){
      s = s * 3 + 1;
    }else{
      s /= 2;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        int c = 0;
        while(n>0)
        {
            n/=k;
            c++;
        }
        System.out.println(c);
    }
}

Measured memory_bytes: 23252
#include<stdio.h>
#define MAX 100
void Graph(int **);
void Clear();
void Jugde(int);

int A[MAX][MAX],JDGE[MAX],DWN[MAX],FLT[MAX];
int *B[MAX];
int N;
int time = 0;
int i,j;


//Aの初期化、出力
int main(){

  scanf("%d",&N);

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      A[i][j] = 0;
    }
  }

  for(i = 0; i < N; i++){
    B[i] = A[i];
  }

  Graph(B);
  Clear();

  for(i = 0; i < N; i++){
    printf("%d %d %d\n",i+1,DWN[i],FLT[i]);
  }

  return 0;
}


//グラフ構築
void Graph(int **A){
  int u,k,v;

  for(i = 0; i < N; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0; j< k; j++){
      scanf("%d",&v);
      v--;
      A[u][v] = 1;
    }
  }
}


//訪問判定配列の初期化
void Clear(){
  int a;
  for(a = 0; a < N; a++){
    JDGE[a] = 0;
  }

  for(a = 0; a < N; a++){
    if(JDGE[a] == 0) Judge(a);
  }

}


//探索、再帰
void Judge(int a){
  int b;
  JDGE[a] = 1;
  DWN[a] = ++time;
  for(b = 0; b < N; b++){
    if(A[a][b] == 0) continue;
    if(JDGE[b] == 0) Judge(b);
  }
  FLT[a] = ++time;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(2e1 + 5);

int n;
int v[MAX_N];
int c[MAX_N];

int ans;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%d", &(v[i]));
  }

  for (int i = 0; i < n; ++i) {
    scanf("%d", &(c[i]));
  }

  ans = -1;

  for (int i = 0; i < 1 << n; ++i) {
    int cv = 0;
    int cc = 0;
    for (int j = 0; j < n; ++j) {
      if (i >> j & 1) {
        cv += v[j];
        cc += c[j];
      }
    }
    ans = max(ans, cv - cc);
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v,i) macro_v.begin()+i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> v = divisor(n);

    ll mi = 1e18;
    for(auto x : v){
        ll y = n/x;
        dd(x,y)
        x--,y--;
        mi = min(mi, y+x);
    }
    cout << mi << endl;
    return 0;
}

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

n, a, b = map(int, input().split())

res = 0
for i in range(1, n + 1):
    si = "%05d" % i
    su = 0
    for c in si:
        su += int(c)
    if a <= su <= b:
        res += i

print(res)


Measured memory_bytes: 2940
#include<stdio.h>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int gcd(int x, int y)
{
    if(y==0)
        return x;
    return gcd(y, x%y);
}
int main()
{
    int a,b,c=0,i,j,k,n;
    cin>>n;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                c=c+gcd(gcd(i,j),k);
            }
        }
    }
    cout<<c<<endl;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define SZ(x) (long long)x.size()
#define endl '\n'
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
bool comp(pair<int, int> v, int val) { return v.ff < val; }
inline int read() {
  int t = 0;
  char c;
  while ((c = getchar_unlocked()) != '\n' && c != ' ' && c != EOF) {
    t = t * 10 + c - 48;
  }
  return t;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
int32_t main() {
  FAST;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("output.txt", "w", stderr);
#endif
  string S;
  cin >> S;
  int i = 1;
  int ans = 0;
  if (S == "RSR" || S == "RSS" || S == "SSR" || S == "SRS")
    cout << 1;
  else if (S == "RRR")
    cout << 3;
  else if (S == "RRS" || S == "SRR")
    cout << 2;
  else
    cout << 0;
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n;
int a[1005];

bool check() {
  for(int i = 2; i <= n; i++)
    if(a[i - 1] > a[i])
      return false;
  return true;
}

int main() {
    ios_base::sync_with_stdio(false);
	cin >> n;
  	for(int i = 1; i <= n; i++)
      cin >> a[i];
  bool res = false;
  	for(int i = 1; i <= n; i++)
      for(int j = 1; j <= n; j++) {
        swap(a[i], a[j]);
        res |= check();
        swap(a[i], a[j]);
      }
  cout << (res ? "YES" : "NO");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n-1);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int inc=-1;
  int ans=1;
  for(int i=1;i<n;i++){
    if(a[i-1]==a[i]){
      continue;
    }
    if(a[i-1]<a[i]){
      if(inc==0){
        ans++;
        inc=-1;
      }
      else if(inc==-1){
        inc=1;
      }
    }
    if(a[i-1]>a[i]){
      if(inc==1){
        ans++;
        inc=-1;
      }
      else if(inc==-1){
        inc=0;
      }
    }
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M,K;
ll ans[100010];
ll deg[100010];
class UnionFind {
  vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
  void init(ll n) {
    par.resize(n, 1); rank.resize(n, 0);
  }
  ll getSize(ll x) {
    return par[find(x)];
  }
  ll find(ll x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(ll x, ll y) {
    return find(x) == find(y);
  }
};
int main(){
    cin>>N>>M>>K;
    UnionFind UF;
    UF.init(N+1);
    for(ll i=0;i<M;i++){
        ll a,b;
        cin>>a>>b;
        deg[a]++;
        deg[b]++;
        UF.merge(a,b);
    }
    for(ll i=1;i<=N;i++){
        ans[i]+=UF.getSize(i)-1;
        ans[i]-=deg[i];
    }
    for(ll i=0;i<K;i++){
        ll c,d;
        cin>>c>>d;
        if(UF.isSame(c,d)){
            ans[c]--;
            ans[d]--;
        }
    }
    for(ll i=1;i<=N;i++){
        cout<<ans[i]<<" ";
    }cout<<endl;
    return 0;
}

Measured memory_bytes: 3968
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
try (Scanner sc = new Scanner(System.in)) {
while (true) {
int max=0,min=1000,mini=0,maxi=0,point=0;
int n = sc.nextInt();
if (n == 0) { break; }
int[] scores = new int[n];
for (int i = 0; i < scores.length; i++) {
    scores[i] = sc.nextInt();
    if(scores[i]>max){
        max=scores[i];
        maxi=i;
    }
    else if(scores[i]<min){
        min=scores[i];
        mini=i;
    }
}
scores[maxi]=0;
scores[mini]=0;
for (int i = 0; i < scores.length; i++)point+=scores[i];

System.out.println(point/=n-2);
}
}
}
}


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

int main(){
    int N, M, x, sum = 0;
    cin >> N >> M;
    vector<int> X, gap;

    for(int i = 0; i < M ; i++){
        cin >> x;
        X.push_back(x);
    }
    sort(X.begin(), X.end());
    for(int i = 0; i < M-1; i++){
        gap.push_back(X[i+1] - X[i]);
    }
    sort(gap.begin(), gap.end());
    for(int i = 0; i < M - N; i++){
        sum += gap[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

int a, b, res;

int get(int a) {
	if (a == 1) return 300000;
	if (a == 2) return 200000;
	if (a == 3) return 100000;
	return 0;
}

int main() {
scanf("%d %d", &a, &b);
res = get(a) + get(b);
if (a + b == 2) res += 400000;
printf("%d\n", res);
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=305;
int n,m,mod,dp[N][N][N];
#define upd(x,y) x=(x+y>=mod?x+y-mod:x+y)
int main()
{
	scanf("%d%d%d",&n,&m,&mod);
	dp[0][1][0]=1;
	for(int i=0;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			for(int k=i;k>=0;k--)
			{
				if(k) upd(dp[i][j][k-1],dp[i][j][k]);
				else upd(dp[i][j+1][i],dp[i][j][k]);
				upd(dp[i+1][j][k],1ll*dp[i][j][k]*(k+1)%mod);
			}
		}
	}
	printf("%d\n",dp[n][m][0]);
	return 0;
}

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

const int N = 2e5;
set<int> edges[N][2];
int used[N];

void solve() {
	int n, m;
	cin >> n >> m;

	string s;
	cin >> s;
	for (auto &x: s)
	 	x -= 'A';

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		edges[a][s[b]].insert(b);
		edges[b][s[a]].insert(a);
	}

	int cnt = n;

	queue<int> q;
	for (int i = 0; i < n; i++)
		if (edges[i][0].empty() || edges[i][1].empty()) {
			q.push(i);
			used[i] = 1;
			cnt--;
		}

	while (!q.empty()) {
		int v = q.front(); q.pop();
		for (int t = 0; t < 2; t++)
			for (auto u: edges[v][t]) {
				if (used[u])
					continue;
				edges[u][s[v]].erase(v);
				if (edges[u][s[v]].empty()) {
					q.push(u);
					used[u] = 1;
					cnt--;
				}
			}
	}

	cout << (cnt >= 2 ? "Yes" : "No");
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	solve();
}


Measured memory_bytes: 38352
# A - Libra
# https://atcoder.jp/contests/abc083/tasks/abc083_a

A, B, C, D = map(int, input().split())

ab = A + B
cd = C + D
result = 'Balanced'

if ab > cd:
    result = 'Left'
elif ab < cd:
    result = 'Right'

print(result)


Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    long double N, K;
    cin >> N >> K;

    long double ans = 0;
    for(long double i = 1; i <= N; i++){
        long double pw = 1; 
        while(i*pw < K) pw *= 2;
        ans += 1/pw;
    }
    ans /= N;
    cout << setprecision(15) << ans << endl;
}



Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Control.Monad.State

type Count = (Int, Int)
type Nums = [Int]
type CountState = (Count, Nums)

toSpace :: String -> String
toSpace [] = []
toSpace (x:xs) = if x == ','
                      then ' ' : toSpace xs
                      else x : toSpace xs

solve :: State CountState Count
solve = do
  ((rec, loz), numList) <- get
  if numList == []
    then return (rec, loz)
    else do
      let (x:y:z:zs) = numList
      case (x, y, z) of
        (x, y, z) | x^2 + y^2 == z^2 -> put ((rec + 1, loz), zs)
                  | x == y           -> put ((rec, loz + 1), zs)
                  | otherwise        -> put ((rec, loz), zs)
      solve

main = do
  contents <- join <$> map (map (read :: String -> Int) . words . toSpace) . lines <$> getContents
  let ans = evalState solve ((0, 0), contents)
  print $ fst ans
  print $ snd ans

Measured memory_bytes: 3796
import sys
sys.setrecursionlimit(10**8)
def line_to_int(): return int(sys.stdin.readline())
def line_to_each_int(): return map(int, sys.stdin.readline().split())
def line_to_list(): return list(map(int, sys.stdin.readline().split()))
def line_to_list_in_iteration(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
# def dp(init, i, j): return [[init]*i for i2 in range(j)]
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #A = [0]+list(accumulate(A))
# import bisect #bisect.bisect_left(B, a), bisect.bisect_right(B,a)

x, y = line_to_each_int()
a = 4*x - y
b = y - 2*x
if a >= 0 and b >= 0 and a % 2 == 0 and b % 2 == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9140
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long x = Long.parseLong(sc.next());
		
		long c = Math.floorDiv(a, x);
		long d = Math.floorDiv(b, x);
		
		if(a % x != 0 && b % x != 0) {
			System.out.println(d - c);
		}
		else if(a % x == 0 && b % x != 0){
			System.out.println(d - c + 1);
		}
		else if(a % x != 0 && b % x == 0) {
			System.out.println(d - c);
		}
		else {
			System.out.println(d - c + 1);
		}
	}
}


Measured memory_bytes: 21716
function Main(input) {
	const inputList = input.split(" ");
	const firstValue = inputList[0]
	const secondValue = inputList[1]

	const result = firstValue * secondValue % 2

	if (result === 0) {
		console.log('Even')
	} else {
		console.log('Odd')
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 21064
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> a(n);

    rep(i, n)
    {
        cin >> a[i];
    }

    int64_t result = numeric_limits<int64_t>::max();
    vector<int> minCost(n);
    copy(a.begin(), a.end(), minCost.begin());
    rep(i, n)
    {
        rep(j, n)
        {
            minCost[j] = min(minCost[j], a[(j - i + n) % n]);
        }

        int64_t total = i * x;
        rep(j, n)
        {
            total += minCost[j];
        }
        result = min(result, total);
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
A = list(map(int,input().split()))
t = 0
wareru = 0

while t==0:
    for j, i  in enumerate(A):

        c = i%2
        A[j] = A[j]/2
        if c == 1:
            t = 1
            break
    if c == 0:
        wareru += 1

print(wareru)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    ll y;
    int ans=1;
    int a,s,d;
    int sum;
    cin>>n>>y;
    for(int i=0;i<=n;i++){
        for(int j=0;i+j<=n;j++){
            sum=10000*i+5000*j;
            if((y-sum)/1000==(n-i-j)){
                ans=0;
                a=i;s=j;d=n-i-j;
            }
        }
    }
    if(ans==1)cout<<"-1 -1 -1"<<endl;
    else cout<<a<<" "<<s<<" "<<d<<endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <complex>
#include <algorithm>

using namespace std;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using i32 = int_fast32_t;
using u32 = uint_fast32_t;

#define int i64

template<class T>
inline bool chmin(T &a, T b) { if(a > b) {a = b; return true;} return false; }
template <class T>
inline bool chmax(T &a, T b) { if(a < b) {a = b; return true;} return false; }
const int INF = 1LL << 60;

signed main() {
	int x, y, z;
	cin >> x >> y >> z;

	int buf = x;
	x = y;
	y = buf;

	buf = x;
	x = z;
	z = buf;

	cout << x << " " << y << " " << z << endl;

	return 0;
}


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

int main() {

	int a, b, k;

	cin >> a >> b;
	k = (a + b) / 2;
	if (abs(a - k) == abs(b - k))
		cout << k << "\n";
	else 
		cout << "IMPOSSIBLE\n";
	return 0;
}

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

struct NODE{
    int m[7];

    bool operator<(const NODE &n)const{
        for(int i=0;i<7;i++)if(m[i]!=n.m[i])return m[i]<n.m[i];
        return false;
    }
};

int to[]={0,2,3,4,1};
int table[]={0,60,10,10,-80};
int score[]={0,0,60,70,80};
int fld[5][5];

void solve(){
    for(int i=0;i<5;i++)
        for(int j=0;j<5;j++)
            cin>>fld[i][j];

    map<NODE,int>prev;
    NODE start;
    for(int i=0;i<5;i++)start.m[6-i]=fld[0][i];
    for(int i=0;i<2;i++)start.m[1-i]=fld[1][i];
    int sum=0;
    for(int i=0;i<5;i++)
        for(int j=0;j<5;j++)
            sum+=score[fld[i][j]];
    prev[start]=sum;

    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            map<NODE,int>next;
            for(map<NODE,int>::iterator it=prev.begin();it!=prev.end();it++){

                NODE d=it->first;
                int val=it->second;
                for(int k=0;k<4;k++){
                    for(int l=0;l<7;l++)if(l<2||l>=5){

                        val+=table[d.m[l]];
                        d.m[l]=to[d.m[l]];
                    }
                    NODE e=d;
                    if(j!=3){
                        for(int l=6;l>0;l--)e.m[l]=e.m[l-1];
                        e.m[0]=fld[i+1][j+2];
                    }
                    else{
                        for(int l=6;l>1;l--)e.m[l]=e.m[l-2];
                        e.m[1]=fld[i+2][0];
                        e.m[0]=fld[i+2][1];
                    }
                    if(next.find(e)!=next.end())next[e]=max(next[e],val);
                    else next[e]=val;
                }
            }
            prev=next;
        }

    }

    int ans=0;
    for(map<NODE,int>::iterator it=prev.begin();it!=prev.end();it++){
        ans=max(ans,it->second);
    }

    cout<<ans<<endl;


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

    while(n--)solve();
    return 0;
}

Measured memory_bytes: 1356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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

int n, f[105][15], p[105][15], cnt, ans=-(1<<30), c;


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

    cin >> n;
    rep (i, n) rep (j, 10) cin >>f[i][j];
    rep (i, n) rep (j, 11) cin >> p[i][j];

    for (int i = 1; i < (1<<10); i++) {
        cnt = 0;
        rep (j, n) {
            c = 0;
            for (int k = 0; k < 10; k++) {
                if ((i >> k & 1)  && f[j][k]) c++;
            }
            cnt += p[j][c];
        }
        ans = max(ans, cnt);
    }
    COUT(ans);
}


Measured memory_bytes: 256
import itertools

n = int(input())
a = [i+1 for i in range(n)]
p = list(map(int,input().split()))
q = list(map(int,input().split()))

r = list(itertools.permutations(a,len(a)))
r.sort()

for i in range(len(r)):
    if list(r[i]) == p:
        x = i
    if list(r[i]) == q:
        y = i
        
print(abs(x-y))

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

int main() {
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  cout << (60 * h2 + m2) - k - (60 * h1 + m1); 
}

Measured memory_bytes: 3636
n,a,b = map(int,input().split())
 
count = 0
for i in range(1,n+1) :
	s = str(i)
	l = len(s)
	x = 0
	for j in range(l):
		x += int(s[j])
	if 	x >= a and x <= b:

		count += i
 
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX=200000;

int main(){
	int R[MAX],n;
	
	cin >> n;
	for(int i=0;i<n;i++)cin >> R[i];
	
	int maxv = -2000000000;
	int minv=R[0];
	
	for(int i=1;i<n;i++){
		//cout <<"debug:MAX R[i]" << R[i] << "とminv"<<minv<<endl;
		//if(maxv<R[i]-minv)cout<<"debug:max更新"<<R[i]-minv<<endl;
		maxv=max(maxv,R[i]-minv);
		
		//cout <<"debug:min minv" <<minv << "とR[i]"<<R[i]<<endl;
		//if(minv>R[i])cout<<"debug:minv更新"<<R[i]<<endl;
		minv=min(minv,R[i]);
		
		//cout<<"----"<<endl;
	}
	
	cout<<maxv<<endl;
	
	return 0;
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
    int i,j,n,m;
    string x;
    cin>>x;
    int flag=1;
    if(x.size()%2==1)flag=0;
    for(i=0;i<x.size();i++)
    {
        if(i%2)
        {
            if(x[i]!='i')flag=0;
        }
        else
        {
            if(x[i]!='h')flag=0;
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256