akhauriyash/Code-Regression huggingface dataset:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n):
        a = [LS() for _ in range(n)]
        sn = {}
        for i in range(n):
            sn[a[i][0]] = i
        b = []
        bs = {}
        bb = {}
        kr = int(a[0][1])
        for i in range(1, n):
            ai = a[i]
            if a[0][0] in ai[3:]:
                continue
            if ai[2] == '0':
                kr += int(ai[1])
                continue
            b.append([2**sn[ai[0]],int(ai[1]), sum(map(lambda x: 2**sn[x],ai[3:]))])
            bs[b[-1][0]] = b[-1][-1]
            bb[b[-1][0]] = b[-1][1]

        fm = {}
        def _f(i):
            if i == 0:
                return 0
            if i in fm:
                return fm[i]
            r = 0
            si = 0
            kr = 0
            nsi = 0
            while i > si:
                ti = i - si
                ni = ti - (ti & (ti-1))
                si += ni
                if (bs[ni] & i) == 0:
                    nsi += ni
                    kr += bb[ni]

            si = nsi
            while i > si:
                ti = i - si
                ni = ti - (ti & (ti-1))
                nr = bb[ni]
                si += ni
                nr += _f(i - nsi - ni - (i & bs[ni]))
                if r < nr:
                    r = nr

            fm[i] = r + kr
            return r + kr

        r = 0
        l = len(b)
        l2 = l//2
        ii = [b[i][0] for i in range(l2)]
        ab = sum(map(lambda x: x[0], b))
        anb = sum(map(lambda x: x[0], b[l2:]))
        # print('ii',ii)
        # print('b',b)
        # print('bb',bb)
        # print('bs',bs)
        # return _f(anb)
        for i in range(l2+1):
            for ia in itertools.combinations(ii, i):
                ti = sum(ia)
                tf = False
                tr = 0
                ts = 0
                for j in ia:
                    if bs[j] & ti:
                        tf = True
                        break
                    tr += bb[j]
                    ts |= bs[j]
                if tf:
                    continue
                # print('tr',tr)
                tr += _f(anb - (anb & ts))
                # print('i',i,ti,tr,ts)
                if r < tr:
                    r = tr

        return r + kr

    while 1:
        n = I()
        if n == 0:
            break
        rr.append(f(n))
        # print(n, rr[-1])

    return '\n'.join(map(str, rr))


print(main())



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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

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

int a[10];

bool dfs(int n, int l, int r) {
  if (n >= 10) return true;
  if (l < a[n]) if (dfs(n+1, a[n], r)) return true;
  if (r < a[n]) if (dfs(n+1, l, a[n])) return true;
  return false;
};

int main() {
  int N;
  cin >> N;
  rep(i, 0, N) {
    rep(j, 0, 10) {
      cin >> a[j];
    }
    if (dfs(0, -1, -1)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

  return 0;
};



Measured memory_bytes: 3088
n,k=(int(i) for i in input().split())
r,s,p=(int(i) for i in input().split( ))
T=input()
hand=[]
point=0

for i in range(n):
	if k-1<i:
		if hand[i-k]!=T[i]:
			if T[i]=='r':
				point+=p
			elif T[i]=='s':
				point+=r
			else:
				point+=s
			hand.append(T[i])
			
		else:
			hand.append('atcoder')
	else:
		if T[i]=='r':
			point+=p
		elif T[i]=='s':
			point+=r
		else:
			point+=s
		hand.append(T[i])

print(point)

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int k,s;cin>>k>>s;
  ll res=0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      int t = x + y;
      int z = s - t;
      if(0<= z && z <= k)res++;
    }
  }

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


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

int main(){
  int N,K;
  cin >> N >> K;
  int64_t sum = 0;
  int64_t mod = pow(10,9) + 7; 
  for(int64_t i = K; i <= N+1; i++){
    
    //最小値
    int64_t min = (i - 1) * i / 2;
    //最大値
    int64_t max = i * ( 2 * N - i + 1) / 2;
    //和の数
    int64_t d = max - min + 1;
    sum += d;
  }
  cout << sum%mod << endl;
  
}
    

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  cout.precision(17);

  int n;cin>>n;
  ld ans=0;
  while(n--){
    ld a;string s;cin>>a>>s;
    if(s=="JPY")ans+=a;
    else ans+=a*380000.0;
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3724
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N;
	cin >> N;
	vector<ll> b;
	for (ll i = 0; i < N; ++i){
		ll tmp;cin>>tmp;tmp--;
		b.pb(tmp);
	}
 
	// 解法
	bool ans =true;
	REP(i,N){
		if (b[i]>i){
			ans = false;
			break;
		}
	}
	if (!ans){
		cout << -1 << endl;
	}
	else{
		vector<ll> a;
		while (b.size()>0){
			for (ll i = b.size()-1; i >=0; --i){
				if (b[i]==i){
					a.pb(i);
					b.erase(b.begin()+i);
					break;
				}
			}
		}
		REP(i,N){
			cout << a[N-i-1]+1 << endl;
		}
	}
}


Measured memory_bytes: 256
n, m = map(int, input().split())
A = [[0] * m for _ in range(n)]
B = [0] * m
for i in range(n):
    M = list(map(int, input().split()))
    for j in range(m):
        A[i][j] = M[j]
for i in range(m):
    M = int(input())
    B[i] = M
C = [0] * n
for i in range(n):
    for j in range(m):
        C[i] += A[i][j] * B[j]
for c in C:
    print(c)


Measured memory_bytes: 6016
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>

#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

using namespace std;

int main(){

  int r,c;
  int sum=0;
  int i,j;
  int m[256][256]={0};

  cin >>r >>c;

  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      cin >>m[i][j];
    }
  }
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      m[r][j]+=m[i][j];
      m[i][c]+=m[i][j];
    }
      sum+=m[i][c];
  }

  m[r][c]=sum;

  for(i=0;i<r+1;i++){
    for(j=0;j<c;j++){
      cout <<m[i][j] <<" ";
    }
    cout <<m[i][c] <<endl;
  }

  return 0;
}

Measured memory_bytes: 1424
#include<bits/stdc++.h>
using namespace std; typedef long long int ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";
const ll M = ll(1e9 + 7);
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{os << "("; os << v.first << ", " << v.second << ")"; return os;}
/***********************************************************************/
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (auto& x : a)   cin >> x;
    vector<ll> dp(n, 1e15);
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for (ll i = 2; i < n; i++)
    {
        for (ll j = 1; j <= k; j++)
        {
            if (i >= j)
            {
                dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
            }
        }
    }
    cout << dp[n - 1] << '\n';
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int a,b;
  cin>>a>>b;
  for(int i=1;i<=3;i++){
    if(a!=i&&b!=i){
      cout<<i<<endl;
      return 0;
    }
  }



  return 0;
}

Measured memory_bytes: 888
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	private static final boolean TEST = false;
	public static void main(String[] args) {
		// 1. 入力データの処理
//		int N = 100000;
//		Integer[] A = new Integer[N];
//		for(int i = 0; i < N; i++) {
//			A[i] = 1024*1024;
//		}
		int N = 2;
		Integer[] A = {1000000000,1000000000};
		if(!TEST) {
			Scanner sc = new Scanner(System.in);
			N = sc.nextInt();
			A = new Integer[N];
			for(int i = 0; i < N; i++) {
				A[i] = sc.nextInt();
			}
			sc.close();
		}

		// 2.N通りのGCDを計算し最大を出力
		printMaxGCD(A, N);

	}

	private static void printMaxGCD(Integer[] A, int N) {
		int sample1 = A[0];
		int sample2 = A[1];

		List<Integer> divisors = new ArrayList<>();

		for(int i = 1; i * i <= sample1; i++) {
			if(sample1 % i == 0) {
				divisors.add(i);
				if(i * i != sample1) {
					divisors.add(sample1 / i);
				}
			}
		}

		for(int i = 1; i * i <= sample2; i++) {
			if(sample2 % i == 0) {
				divisors.add(i);
				if(i * i != sample2) {
					divisors.add(sample2 / i);
				}
			}
		}


		//System.out.println(divisors.size());
		int divisorTmp = 0;
		int divisorMax = 0;
		for(Integer divisor : divisors) {
			// n-1個以上割れたら候補
			int counter = 0;
			for(int i = 0; i < A.length; i++) {
				if(A[i] % divisor == 0) {
					counter++;
				}
			}
			if(counter >= A.length - 1) {
				divisorTmp = divisor;
				if(divisorTmp > divisorMax) {
					divisorMax = divisorTmp;
				}
			}
		}
		System.out.println(divisorMax);
	}

}


Measured memory_bytes: 61232
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	for(int a,b,c,d,e;cin>>a>>b>>c>>d>>e,a|b|c|d|e;){
		int na,nb,nc; cin>>na>>nb>>nc;
		int res=na*a+nb*b+nc*c;
		for(int i=0;i<=na+nb;i++){
			int s=nc+i;
			int set_price=max(s,d)*e;
			
			int nb2=max(nb-i,0);
			int na2=na-(i-(nb-nb2));
			int std_price=na2*a+nb2*b;
			res=min(res,set_price+std_price);
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1164
/* Arthur Conmy / arthurconmy */
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
#include <chrono>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<int,int> pii;
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)
#define REPb(j, d, c) for (int j = int(d); j >= int(c); j--)
#define ff first
#define ss second
#define pb push_back
#define len(x) int((x).size())
#define endl "\n"

int n,k;
vector<int> adj[100001];
bool vis[100001];
int cols[100001];

void dfs(int v)
{
	vis[v]=1;
	int child_no=1;

	for(auto u:adj[v])
	{
		if(vis[u]) continue;
		vis[u]=1;

		cols[u]=k-child_no++;
		if(v!=1) cols[u]--;

		dfs(u);
	}
}

int main() // LL OR INT??
{
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>k;

	REP(i,1,n-1)
	{
		int u,v;
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	cols[1]=k;
	dfs(1);

	// REP(i,1,4)
	// {
	// 	cout << i << " " << cols[i] << endl;
	// }

	ll ans=1;

	REP(i,1,n)
	{
		ans*=cols[i];
		ans%=1000000007;
	}

	cout << ans << endl;
}

Measured memory_bytes: 9728
from fractions import gcd

N = int(input())
AAA = list(map(int, input().split()))

dp = [0] * (N + 1)
dp[0] = AAA[0]

for i, A in enumerate(AAA):
    if i == N:
        break
    dp[i + 1] = gcd(dp[i], A)

print(dp[N])


Measured memory_bytes: 16280
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
		int t = sc.nextInt();
        int[] tt = new int[n];
		int count = 0;
		for (int i=0;i<n;i++){
        	tt[i] = sc.nextInt();
        }
		for (int j=1;j<n;j++){
        	if (tt[j]-tt[j-1]>=t){
            	count+=t;
            }else{
            	count+=tt[j]-tt[j-1];
            }
        } 
		System.out.print(t+count);
    }
}

Measured memory_bytes: 65212
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

def segfunc(x, y):
    return min(x, y)

ide_ele = float('inf')

class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

N, M = getNM()
seg = SegTree([float('inf')] * (N + 1), segfunc, ide_ele)
L = [getList() for i in range(M)]
L.sort()
seg.update(0, 0)

# ARC026 C - 蛍光灯と同じ　繋いで繋いでセグ木
# [0, 1, 2, 3, 4, 5]
# seg.query(0, 2): [0, 1]の最小値
# seg.query(2, 2 + 1): [2]の最小値
# seg.update(2, min(vs, opt + c)): 2をmin(vs, opt + c)に更新
for l, r, c in L:
    l -= 1
    r -= 1
    opt = seg.query(l, r)
    vs = seg.query(r, r + 1)
    seg.update(r, min(vs, opt + c))
ans = seg.query(N - 1, N)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 111792
#include<bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

const int MAX=500000;

int fac[MAX],finv[MAX],inv[MAX];
 
void t(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  repi(i,2,MAX){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
 
int calc(int n,int k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


signed main(){
  cin.tie(0);	
  //ios::sync_with_stdio(false);
  int n,m,k;
  cin>>n>>m>>k;
  int cn[n];
  int now=m;
  rep(i,n){
    cn[i]=now;
    //cout<<cn[i]<<endl;
    now*=(m-1);
    now%=MOD;
  }
  int ans=0;
  t();
  rep(i,k+1){
    int num=cn[n-1-i];
    int x=calc(n-1,i);
    // cout<<x<<endl;
    x=x*num%MOD;
    //cout<<x<<endl;
    ans+=x;
    ans%=MOD;
  }
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 16888
# 問題文
# X秒を測れる砂時計があります。
# はじめ上のパーツに砂が X[g] あり、1秒間に 1[g] 砂が落ちます。
# なお、上のパーツにもう砂が残っていない場合は砂は落ちません。
# t秒後に上のパーツに残っている砂は何gでしょう。

# x（秒）、t（秒後）：標準入力（数値）
x,t = map(int, input().split())

# x>tの時、砂が残っている x-tが存在する
# x<=tの時、砂は残っておらず砂は落ちない
weight = 0
if x > t:
    weight = x - t
else:
    weight = 0

print(weight)

Measured memory_bytes: 9064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
///////////////////////////////////////////////////////
int r;
cin >> r;
cout << 3*r*r << endl;

///////////////////////////////////////////////////////
return 0;}

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int64_t> A(N);
    //   int64_t total = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        //       total += A[i];
    }
    sort(A.begin(), A.end());

    vector<pair<int64_t, int>> V(M);
    for (int i = 0; i < M; i++)
    {
        int B, C;
        cin >> B >> C;
        V[i] = {C, B};
    }
    sort(V.rbegin(), V.rend());
    int index = 0;
    for (auto p : V)
    {
        int B = p.second;
        while (B > 0 && A[index] < p.first && index < N)
        {
            A[index] = p.first;
            B--;
            index++;
        }
    }
    int64_t ans = 0;
    for (int64_t v : A)
        ans += v;
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N){
    cin >> p.at(i);
  }
  int s = 0;
  int t = 0;
  int u = 0;
  rep(i, K){
    t += p.at(i);
  }
  s = t;
  rep(i, N-K){
    t -= p.at(i);
    t += p.at(i+K);
    if(chmax(s, t)){
      u = i+1;
    }
  }
  double ans = 0;
  rep(i, K){
    ans += (p.at(u+i)+1) / 2.0;
  }
  cout << fixed << setprecision(12);
  cout << ans << endl;
}

Measured memory_bytes: 1024
function fib(fibs, time) {
    if(time === 0 || time === 1) return fibs[time] = 1;
    if(fibs[time]) return fibs[time];

    return fibs[time] = fib(fibs, time - 1) + fib(fibs, time - 2);
}

function main(_stdin){
    const stdin = _stdin.split('\n');
    const a = parseInt(stdin.shift(), 10);

   console.log(fib([1], a));
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 15128
import java.util.*;

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

        int ans = Integer.MAX_VALUE;
        for(int i=0;i<N;i++){
            int cnt = 0;
            int cur = sc.nextInt();
            while((cur&1)==0){
                cnt++;
                cur = cur/2;
            }
            ans = Math.min(ans,cnt);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<functional>
#include<set>
using namespace std;
#define int long long

signed main() {
	int n;
	cin >> n;
	set<char>S;
	for (int i = 0; i < n; i++) {
		char a;
		cin >> a;
		S.insert(a);
	}
	if (S.size() == 3)puts("Three");
	else puts("Four");
}

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

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;

    if (a <= c && c <= b || a >= c && c >= b) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int d[4][2] = {
  {1, 0},
  {0, 1},
  {-1, 0},
  {0, -1}
};

int search(int a[21][21], int s, int t, int h, int w, int c)
{
  int m = 11, s2, t2, v;
  if(c > 10){
    return 11;
  }

  for(int i = 0; i < 4; i++){
    s2 = s;
    t2 = t;
    if(a[s+d[i][0]][t+d[i][1]] == 1){
      continue;
    }
    while(1){
      s2 += d[i][0];
      t2 += d[i][1];
      if(!(s2 >= 0 && t2 >= 0 && s2 < h && t2 < w)){
	break;
      } else if(a[s2][t2] == 3){
	return c;
      } else if(a[s2][t2] == 1){
	a[s2][t2] = 0;
	v = search(a, s2-d[i][0], t2-d[i][1], h, w, c+1);
	m = (m > v)? v : m;
	a[s2][t2] = 1;
	break;
      }
    }
  }
  
  return m;
}


int main()
{
  int a[21][21], w, h, s, t;

  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0){
      break;
    }

    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	cin >> a[i][j];
	if(a[i][j] == 2){
	  s = i;
	  t = j;
	}
      }
    }
    t = search(a, s, t, h, w, 1);
    if(t == 11){
      t = -1;
    }

    cout << t << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,m) for(int j=0;j<m;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef vector< vector <int> >vee;
typedef vector<pair<int,int> >vepa;
typedef set<char>se;
typedef map<ll,ll> mpp;
const int N=1e5+5;
bool f;
ll dp[105][N],v[N],w[N],n,m;
ll solve(int i=0,int rem=m)
{
    if(i==n)return 0;
    ll &ret=dp[i][rem];
    if(~ret)
    return ret;
    return ret=max(solve(i+1,rem),rem>=w[i]?solve(i+1,rem-w[i])+v[i]:0);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
     memset(dp,-1,sizeof dp);
     cin>>n>>m;
     rep(i,n&&cin>>w[i]>>v[i]);
      cout<<solve();

go;
}


Measured memory_bytes: 82432
use std::io::stdin;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let string = buf.trim().to_string();

    println!("{}", solve(string));
}

fn solve(string: String) -> i32 {
    let separated: Vec<&str> = string.split(|char| char != 'A' && char != 'C' && char != 'G' && char != 'T').collect();
    let separated: Vec<String> = separated.iter().map(|iter| iter.to_string()).collect();
    let separated: Vec<String> = separated.iter().filter(|&str| str != "").map(|iter| iter.to_string()).collect();

    if separated.len() == 0 {
        return 0;
    }

    let mut len_array: Vec<usize> = separated.iter().map(|str| (*str).chars().count()).collect();

    len_array.sort();
    len_array[len_array.len()-1] as i32
}

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

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define MAXX 100005

#define PI 3.14159265358979323846264338327950

#define ll signed long long int
int main()
{
	int a,b,c,d,e,k;
	cin>>a>>b>>c>>d>>e>>k;
	if ((e-a)>k)
	{
		cout<<":(";
	}
	else
	cout<<"Yay!";
}

Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline())

primes = set()
exists = set()
for i in range(2, 55555):
    if i in exists:
        continue
    primes.add(i)
    for j in range(i, 55555, i):
        if j in exists:
            continue
        exists.add(j)

# % 5 == 1となるもの
ans = []
for prime in primes:
    if prime % 5 == 1:
        ans.append(prime)
    if len(ans) == N:
        break

print(*ans)

Measured memory_bytes: 13228
#include<bits/stdc++.h>
using namespace std;
#define int long long
int MOD=1000000009LL;
typedef vector<int> arr;
typedef vector<arr> mat;
inline arr mul(mat a,arr& b,int mod){
  arr res(b.size(),0);
  for(int i=0;i<(int)b.size();i++)
    for(int j=0;j<(int)a[i].size();j++)
      (res[i]+=a[i][j]*b[j])%=mod;
  return res;
}
inline mat mul(mat& a,mat& b,int mod){
  mat res(a.size(),arr(b[0].size(),0));
  for(int i=0;i<(int)a.size();i++)
    for(int j=0;j<(int)b[0].size();j++)
      for(int k=0;k<(int)b.size();k++)
	(res[i][j]+=a[i][k]*b[k][j])%=mod;
  return res;
}
mat memo[100],base;
inline mat mat_pow(mat a,int n,int mod){
  mat res(base);
  while(n){
    if(n&1) res=mul(a,res,mod);
    a=mul(a,a,mod);
    n>>=1;
  }
  return res;
}
void init(mat a,int mod){
  base=mat(a);
  for(int i=0;i<(int)base.size();i++)
    for(int j=0;j<(int)base.size();j++)
      base[i][j]=i==j;
  memo[0]=a;
  for(int k=1;k<70;k++)
    memo[k]=mul(memo[k-1],memo[k-1],mod);
}
inline mat mat_pow2(int w,int n,int mod){
  mat res(base);
  int k=0;
  while(n){
    if(n&1) res=mul(memo[k],res,mod);
    n>>=1;
    k++;
  }
  return res;
}

typedef pair<int,int> P;
signed main(){
  int w,h,n,cnt=0;
  while(cin>>w>>h>>n,w||h||n){
    int x[n],y[n];
    for(int i=0;i<n;i++) cin>>x[i]>>y[i];
    P p[n];
    for(int i=0;i<n;i++) p[i]=P(y[i],x[i]);
    sort(p,p+n);
    for(int i=0;i<n;i++) x[i]=p[i].second,y[i]=p[i].first;
    arr a(w,0);
    a[0]=1;
    mat b(w,arr(w,0));
    for(int i=0;i<w;i++){
      for(int j=0;j<w;j++) b[i][j]=0;
      b[i][i]=1;
      if(i-1>=0) b[i][i-1]=1;
      if(i+1<w)  b[i][i+1]=1;
    }
    init(b,MOD);
    int d=1;
    for(int k=0;k<n;k++){
      if(y[k]==d) continue;
      //cout<<k<<endl;
      a=mul(mat_pow2(w,y[k]-d-1,MOD),a,MOD);
      int j=k;
      mat c=b;
      while(j<n&&y[k]==y[j]){
	for(int i=0;i<w;i++) c[x[j]-1][i]=0;
	j++;
      }
      a=mul(c,a,MOD);
      d=y[k];
      //cout<<"a:";for(int i=0;i<w;i++) cout<<a[i]<<" ";cout<<endl;
    }
    //cout<<"a:";for(int i=0;i<w;i++) cout<<a[i]<<" ";cout<<endl;
    a=mul(mat_pow2(w,h-d,MOD),a,MOD);
    //cout<<"a:";for(int i=0;i<w;i++) cout<<a[i]<<" ";cout<<endl;
    cout<<"Case "<<++cnt<<": "<<a[w-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 6484
#include <stdio.h>
#include <stdlib.h>
#define LENGTH 105
void bfs(int, int);
void enqueue(int);         /* use queue*/
int  dequeue(void);
int array[100][100],dis[100],queue[LENGTH],head=0,tail=0;
int main(){
  int num,i,j,id,nextnum,next;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    for(j=0;j<num;j++){
      array[i][j]=0;
    }
  }
  for(i=0;i<num;i++){
    scanf("%d %d",&id,&nextnum);
    for(j=0;j<nextnum;j++){
     
      scanf("%d",&next);
      array[id-1][next-1]=1;
    }
  }
  bfs(0,num);
  for(i=0;i<num;i++){
    printf("%d %d\n",i+1,dis[i]);
  }
  return 0;
}
void bfs(int val,int num){
  int i,res;
  enqueue(val);
  for(i=0;i<num;i++) dis[i]=-1;
  dis[val]=0;
  while(1){
    res=dequeue();
    if(res==-1) break;
    for(i=0;i<num;i++){
      if(array[res][i]==0) continue;
      if(dis[i]!=-1) continue;
      dis[i]=dis[res]+1;
      enqueue(i);
    }
  }
  
}

void enqueue (int data){
  int next;
  next=(tail+1)%LENGTH;
  
  if(next==head) exit(2);
  queue[tail]=data;
  tail=next;
}

int  dequeue(){
  int data;
  if(head==tail) return -1;
  data=queue[head];
  head=(head+1)%LENGTH;
  return data;
}


  



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ans = 0;
    for(int i=1;i<=n;i+=2){
      int sum_of_divisors=0;
      for(int j=1;j<=i;j++){
        if(i%j==0){
          sum_of_divisors++;
          }
        }
      if(sum_of_divisors==8){
        ans++;
        }
      }
  cout<<ans<<endl;
  }

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

typedef long long int llint;

int main()
{
  int a, b, c, d;
  cin>> a >> b >> c >> d;

  if(abs(a - b) <= d && abs(b - c) <= d || abs(a - c) <= d) {
    cout<< "Yes" <<endl;
  } else {
    cout<< "No" <<endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		int area = a*b;
		int length = 2 * a + 2 * b;
		System.out.println(area + " " + length);
	}
}


Measured memory_bytes: 25904
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class A
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int A = Int32.Parse(args[0]);
		int B = Int32.Parse(args[1]);
		int C = Int32.Parse(args[2]);

		Console.WriteLine((A == B) ? C : (A == C) ? B : A);
	}
}





Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main(){
     int a,b;
     string s,d,f;
     cin>>s>>d>>a>>b>>f;
     if(s==f){
     	a--;
	 }
	 else{
	 b--;
} 
     cout<<a<<" "<<b;
}

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

int main() {
  int c = 0;
  string s;
  string t;
  cin >> s >> t;
  for(int i = 0;i < 3;i++){
    if(s.at(i) == t.at(i)) c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b==c) cout<<"1"<<endl;
  else if(a!=b&&b==c) cout<<"2"<<endl;
  else if(a==b&&b!=c) cout<<"2"<<endl;
  else if(a==c&&b!=c) cout<<"2"<<endl;
  else if(a!=b&&b!=c) cout<<"3"<<endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    while(x!=0||y!=0){
        if(x>y){
            cout<<y<<" "<<x<<'\n';
        }
        else{
            cout<<x<<" "<<y<<'\n';
        }
        cin>>x>>y;
    }
    return 0;
}


Measured memory_bytes: 3056
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int calc(string S, int s, int t) {
    int res = 0;
    FOR(i, s, t) {
        res *= 10;
        res += S[i] - '0';
    }
    return res;
}

void solve(int Q) {
    while (Q--) {
        int cnt = 0;
        string R; cin >> R;
        int num = atoi(R.c_str());
        for (;num >= 10; cnt++) {
            num = atoi(R.c_str());
            int newnum = 0;
            FOR(i, 1, R.length()) {
                int buf = calc(R, 0, i) * calc(R, i, R.length());
                ///DEBUG(buf)
                newnum = max(newnum, buf);
            }
            R = to_string(newnum);
            if (R.size() == 1) {
                cnt++;
                break;
            }
            if (newnum >= num) {
                cnt = -1;
                break;
            }
        }
        cout << cnt << endl;
    }
    return;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n) {
        solve(n);
        return 0;
    }
}

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  
  cin >> a >> b >> c;
  
  if( (a==b&&b==c&&c==a) || (a!=b&&b!=c&&c!=a)){
    cout << "No";
  }
  else{
    cout << "Yes"; 
  }
  
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=set()
l=list()
s.add(0)
d=dict()
ind=0
l.append(0)
d[0]=0
s.add(0)
ind+=1
while(True):
    if a[l[-1]]-1 in s:
        break
    d[a[l[-1]]-1]=ind
    s.add(a[l[-1]]-1)
    l.append(a[l[-1]]-1)
    ind+=1
# print(d)
ind=d[a[l[-1]]-1]
# print(ind,a[l[-1]]-1)
if k==len(l):
    r=0
    print(l[ind+r]+1)
elif k>len(l):
    r=(k-len(l))%(len(l)-ind)
    print(l[ind+r]+1)
else:
    r=k
    print(l[r]+1)
# print(l)
# print(r)


Measured memory_bytes: 65044
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

ll f(string s, int n) {
  string t;
  rep(i,n) t += s;
  ll res = 0;
  char pre = '-';
  rep(i,sz(t)) {
    if (t[i] == pre) {
      res++;
      pre = '-';
    } else {
      pre = t[i];
    }
  }
  return res;
}

int main() {
  string s;
  int n;
  cin>>s>>n;
  int c = 0;
  if (n > 100) {
    c = n-100;
    if (c&1) c++;
    n -= c;
  }
  ll x = f(s,n+2);
  ll ans = f(s,n);
  ll d = x-ans;
  ans += d*(c/2);
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 3552
#include <stdio.h>

int main(void)
{
    int num_integer;
    if (scanf("%d", &num_integer) != 1)
    {
        puts("num_integer input error.");
        return 1;
    }

    int integer, sum_p = 0, sum_m = 0;
    long long op_count_p = 0, op_count_m = 0;
    for (int i = 0; i < num_integer; i++)
    {
        if(scanf("%d", &integer) != 1)
        {
            puts("integer input error.");
        }

        sum_p += integer;
        sum_m += integer;
        if (i % 2 == 0) 
        {
            if (sum_p <= 0)
            {
                op_count_p += -sum_p + 1;
                sum_p = 1; 
            }

            if (sum_m >= 0)
            {
                op_count_m += sum_m + 1;
                sum_m = -1;
            }
        }
        else 
        {
            if (sum_p >= 0)
            {
                op_count_p += sum_p + 1;
                sum_p = -1; 
            }

            if (sum_m <= 0)
            {
                op_count_m += -sum_m + 1;
                sum_m = 1;
            } 
        }
    }

    printf("%lld", (op_count_p < op_count_m) ? op_count_p : op_count_m); 

    return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<bits/stdc++.h>
#include<deque> 
#include<bitset>
#include<string>
#define N 40
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

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

int32_t main(){
	int n, w;
	cin>>n>>w;
	int we[n], v[n];
	for(int i=0;i<n;i++){
		cin>>we[i]>>v[i];
	}
	int dp[105][100005];
	int maxva = 0;

	//memset(dp, INT_MAX , sizeof(dp));
    for(int i=0;i<=100;i++){
        for(int j=0;j<=1e5;j++){
            dp[i][j] = 1e10;
        }
        dp[i][0] = 0;
    }
	

	for(int it = 0; it<n; it++){
		for(int va = 1; va <= 1e5; va++){
			if(it == 0){
				if(va <= v[0]){
                    //cout<<va<<endl;
					dp[it][va] = we[0];
				}
			}
			else{
				dp[it][va] = dp[it - 1][va];
				if(va >= v[it]){
					dp[it][va] = min(dp[it][va], we[it] + dp[it-1][va - v[it]]);
				}
			}
			if(dp[it][va] <= w){
                //cout<<it<<" "<<va<<" "<<dp[it][va]<<endl;
				maxva = max(maxva, va);
			}
		}
	}
    //cout<<dp[0][40]<<endl;
	cout<<maxva<<endl;
	
}

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

using namespace std;

using ll = long long;

ll sn(ll n){
  return (ll)n*(n+1)/2;
}

ll calc_ans(ll x){
  ll ans = 0;
  for(int i=1; i<=x; ++i){
    ans += sn(x/i)*i;
  }

  return ans;
}


int main(){
  ll N;
  cin >> N;
  
  cout << calc_ans(N) << endl;

  return 0;
}

Measured memory_bytes: 3604
N = int(input())
A = list(map(int,input().split()))
A.sort()
cums = [0]
for i in range(N):
    cums.append(cums[-1] + A[i])
#print(A)
cums.pop(0)
#print(cums)
ans = 1
for i in range(N-2,-1,-1):
    if A[i+1] <= 2*cums[i]:
        #print(A[i])
        ans += 1
    else:
        print(ans)
        exit()
print(ans)

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

int main(){
  int N,L;
  cin>>N>>L;
  vector<int> a(N);
  int sum=0;
  for(int i=0;i<N;i++){
    a.at(i)=L+i;
    sum+=L+i;
  }
  if(L>0){
    sum-=L;
  }else if(N<-L+1){
    sum-=L+N-1;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 10000
int N,A,B,C;
int L[9];
int dfs(int x,int a,int b,int c){
  if(x==N){
    if(a==0||b==0||c==0) return INF;
    else return abs(a-A)+abs(b-B)+abs(c-C);
  }
  int r[4];
  r[0]=dfs(x+1,a,b,c);
  r[1]=dfs(x+1,a+L[x],b,c)+10*(a>0);
  r[2]=dfs(x+1,a,b+L[x],c)+10*(b>0);
  r[3]=dfs(x+1,a,b,c+L[x])+10*(c>0);
  sort(r,r+4);
  return r[0];
}
int main(){
  cin>>N>>A>>B>>C;
  rep(i,N) cin>>L[i];
  cout<<dfs(0,0,0,0)<<endl;
}

Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

S = str(input())

ans = 0
N = len(S)
for i in range(1,N+1): # 文字数
    for j in range(N-i+1):
        left = max(len(S[:j])-1,0)
        right = max(len(S[j+i:])-1,0)

        ans += int(S[j:j+i]) * (2**(left+right))

print(ans)


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

using namespace std;

char c[111111];

int main()
{
	long long n, l;
	cin >> n >> l;
	vector<string> v;
	for (int i = 0; i < n; i++) {
		scanf("%s", c);
		v.push_back(c);
	}
	sort(v.begin(), v.end());
	v.push_back("a");
	fill(c, c + v.front().length(), 0);
	auto x = 0ll;
	for (auto it = v.begin() + 1;; ++it) {
		int r = 0;
		while (it[0][r] == it[-1][r])
			r++;
		if (*it == "a") r = -1;
		for (int i = r + 1; i < it[-1].length(); i++) {
			if (c[i]) continue;
			auto y = l - i;
			for (n = 1; y % 2 == 0; n *= 2)
				y /= 2;
			x ^= n;
		}
		if (r < 0) break;
		c[r] = 1;
		fill(c + r + 1, c + it->length(), 0);
	}
	cout << (x ? "Alice" : "Bob") << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
	int N;
	scanf("%d", &N);
	int L[N];
	for (int i = 0; i < N; i++) {
		scanf("%d", &L[i]);
	}
	int counter = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			for (int k = j + 1; k < N; k++) {
				if(L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i]) {
                    if(L [i] != L[j] && L[i] != L[k] && L[j] != L[k]) {
                        counter++;
					}
				}
			}
		}
	}
	printf("%d", counter);
	
	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
int main(){
  int n,m;
  cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;
  return 0;
}

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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define ull unsigned long long
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define pl(x) cout << #x << "= " << x << endl;
const int inf=0x3f3f3f3f;
const int N=3e5+10;

string s;

int  main(){
    cin>>s;
    int n=s.size();
    int st=0, ed=n-1;
    for(int i=0; i<n; i++)if(s[i]=='A'){
        st=i; break;
    }
    for(int i=n-1; i>=0; i--)if(s[i]=='Z'){
        ed=i; break;
    }
    if(ed<st)cout<<0<<endl;
    else cout<<ed-st+1<<endl;
    return 0;
}

Measured memory_bytes: 644
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

using namespace std;

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

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

	
	vector<int> a(n);

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

		mx = max(mx, a[i]);
	}

	if (n == 1) {
		
		if (a[0] == k) {
			cout << "POSSIBLE" << endl;
		}
		else {
			cout << "IMPOSSIBLE" << endl;
		}
		return 0;
	}

	int g = a[0];

	for (int i = 1; i < n; i++) {
		g = gcd(g, a[i]);
	}

	if (k <= mx && k%g == 0) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;

}


Measured memory_bytes: 640