akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            abc112_b();
        }

        static void abc112_b()
        {
            // B - Time Limit Exceeded
            int[] NT = Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
            int cost = 100100;
            for (int i=0; i < NT[0]; i++)
            {
                int[] CT = Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
                if (CT[1] <= NT[1]) cost = Math.Min(CT[0], cost);
            }
            if (cost < 100100) Console.WriteLine(cost);
            else Console.WriteLine("TLE");
        }
    }
}

Measured memory_bytes: 13268
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    READV(N);
    READAR(A,N);
    ll sum=0;
    FORI(i,0,N)
    {
        sum+=A[i];
    }
    ll sum1=0;
    ll ans=inf;
    FORI(i,0,N)
    {
        sum1+=A[i];
        ans=min(ans,abs(sum-2*sum1));
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
N = int(input())
s1 = input()
s2 = input()
i = 0
pat = []
while i < N:
  if s1[i]==s2[i]:
    pat.append('t')
    i += 1
  else:
    pat.append('y')
    i += 2
if pat[0]=='t':
  ans = 3
else:
  ans = 6
pat2 = pat[1:]
l = len(pat)
i = 1
while i < l:
  if pat[i]=='t' and pat[i-1]=='t':
    ans = (ans*2)%(10**9+7)
  elif pat[i]=='t' and pat[i-1]=='y':
    pass
  elif pat[i]=='y' and pat[i-1]=='t':
    ans = (ans*2)%(10**9+7)
  elif pat[i]=='y' and pat[i-1]=='y':
    ans = (ans*3)%(10**9+7)
  i += 1
print(ans)

Measured memory_bytes: 3064
n,k=map(int,input().split())
if (n-2)*(n-1)//2<k:
    print(-1)
else:
    print(n-1+(n-2)*(n-1)//2-k)
    for i in range(2,n+1):
        print(1,i)
    c=(n-2)*(n-1)//2-k
    for i in range(2,n+1):
        for j in range(2,n+1):
            if i<j:
                if c==0:
                    exit()
                print(i,j)
                c-=1
                

Measured memory_bytes: 43116
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main() {
  long long int N, A, B, n, tmp, ans;
  scanf("%lld %lld %lld", &N, &A, &B);
  n = A + B;
  tmp = N % n;	// 余り
  N /= n;		// 何セットできたか
  if(tmp > A) {// 余りがAより多いか少ないか
    ans = (N+1) * A;
  } else {
    ans = N * A + tmp;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
    if (p[i - 1] < p[i] < p[i + 1]) or (p[i - 1] > p[i] > p[i + 1]):
        ans += 1

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

const int MAX = 40;

int ans;
int n;
int c[MAX];

int main(void) {
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];

    rep(i, 0, MAX) {
        rep(j, 0, n) c[i] += (a[j]&(1LL<<i))/(1LL<<i);
    }

    rep(i, 0, n) {
        rep(j, 0, MAX) {
            if (c[j]%2==1) {
                if (a[i]&(1LL<<j)) a[i] -= (1LL<<j);
                else a[i] += (1LL<<j);
            }
        }

    }

    rep(i, 0, n) {
        if (i>0) printf(" ");
        printf("%lld", a[i]);
    }

    cout << "\n";
    return 0;
}



Measured memory_bytes: 4792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func debug(a ...interface{}) {
	if os.Getenv("ONLINE_JUDGE") == "false" {
		fmt.Fprintln(os.Stderr, a...)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1001), 1001001)

	k := scanInt()
	fmt.Fprintln(wr, strings.Repeat("ACL", k))
}


Measured memory_bytes: 1776
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n;
	cin >> n;
    int p[n];
    int ans=0;
    fr(i,n){
      cin >> p[i];
    }
    sort(p,p+n);
    
      cout << p[n/2]-p[n/2-1] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ode(ld x){ cout << fixed << setprecision(10) << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

int main(){
    ll N=ii();
    ll ret=0;
    REP(i,1,N+1){
        if(i%3!=0&&i%5!=0){
            ret+=i;
        }
    }
    oie(ret);

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n;
double sum;
int main()
{
	scanf("%d",&n);
	for(register int i=1,x;i<=n;i++)
	{
		scanf("%d",&x);
		sum+=1./x;
	}
	printf("%.6lf",1./sum);
	return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int>H(N);
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
    }
    sort(H.begin(), H.end());
    for (int i = 0; i < K; ++i) {
        H.pop_back();
        if (H.size() == 0) break;
    }
    ll ans = 0;
    for (auto x: H) {
        ans += x;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
package main

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

func main() {
	Xs := nextInts(5)
	for i := 0; i < 5; i++ {
		if Xs[i] != i+1 {
			fmt.Println(i + 1)
		}
	}
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}


Measured memory_bytes: 1756
import java.util.*;

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

	int ans = t/a*b;
    
    System.out.println(ans);
  }
}


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

using namespace std;

int f(int n, int k) {
    int result = 1;
    for (int i = 0; i < n; i++) {
        if (result < k) {
            result *= 2;
        } else {
            result += k;
        }
    }

    return result;
}

int main() {

    int n;
    cin >> n;

    int k;
    cin >> k;

    int result = f(n, k);
    cout << result << endl;

    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    i64 s = 0;
    map<i64, i64> dist;
    REP(i, N) {
        i64 a; cin >> a;
        dist[a]++;
        s += a;
    }

    i64 Q; cin >> Q;
    vector<i64> ans(Q);
    REP(q, Q) {
        i64 b, c; cin >> b >> c;
        i64 cnt = dist[b];
        dist[b] = 0;
        dist[c] += cnt;
        s += (c - b) * cnt;
        ans[q] = s;
    }

    REP(i, Q) cout << ans[i] << endl;

    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a;
    cin >> a;
    n -= a;
  }
  if (n < 0) n= -1;
  cout << n << endl;
  return 0;
}

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

/*int main(int argc, char **argv)
{
	int a, b, c, d, e;
	std::cin >> a >> b >> c >> d >> e;
	std::cout << std::min(a, std::min(b, c)) + std::min(d, e) - 50 << std::endl;
	return 0;
}*/
/*int main()
{
	int l, a, b, c, d;
	std::cin >> l >> a >> b >> c >> d;
	int japa, math;
	japa = a / c;
	if(a % c != 0){
		japa++;
	}
	math = b / d;
	if(b % d != 0){
		math++;
	}
	std::cout << l - std::max(japa, math) << std::endl;
}*/
int main()
{
	bool sub[31];
	int input;
	for(int i = 0; i < 31; i++){
		sub[i] = false;
	}
	for(int i = 0; i < 28; i++){
		std::cin >> input;
		sub[input] = true;
	}
	for(int i = 1; i < 31; i++){
		if(!sub[i]) std::cout << i << std::endl;
	}
}

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

#define mod 1000000007
#define LOCAL 0
#define pb push_back
#define ll long long

ll po(ll a,ll b){
	ll x = 1,y=a;
	while(b>0){
		if(b%2){
			x = x*y;
			x %= mod;
		}
		y=y*y;
		y%=mod;
		b/=2;
	}
	return x;
}

int main(){
	if(LOCAL){
    	freopen("C:/Users/gold/Desktop/sublime IO/input.txt","r",stdin);
    	freopen("C:/Users/gold/Desktop/sublime IO/output.txt","w",stdout);
	}
	int T = 1;
	//scanf("%d",&T);
	while(T--){
		int n,c,k;
		scanf("%d %d %d",&n,&c,&k);
		static int a[2000005];
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		int s = 0;
		int ans = 0;
		for(int i=0;i<n;i++){
			while(s<i&&(a[i]-a[s])>k){
				s = min(s+c,i);
				ans++;
			}
		}
		while(s<=n-1){
			s = min(s+c,n);
			ans++;
		}
		printf("%d\n",ans);
	}
	return 0;	
}

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

int main()
{
	int m, nmi, nma;
	while (cin >> m >> nmi >> nma, m || nmi || nma) {
		vector<int> P(m);
		for (int i = 0; i < m; i++) {
			cin >> P[i];
		}
		sort(P.begin(), P.end());
		int res = -1, gap = -1;
		for (int i = nmi; i <= nma; i++) {
			if (P[m - i] - P[m - i - 1] >= gap) {
				gap = P[m - i] - P[m - i - 1];
				res = i;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;

int main(){

	int N,M,C;

	cin >> N >> M >> C;
	std::vector<int> B(M);
	int A;
	int sum;
	int count = 0;

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

	for (int i = 0; i < N; i++){
		sum = 0;
		for (int j = 0; j < M; j++){
			cin >> A;
			sum+= A*B[j];
		}

		if(sum > -C)
			count += 1;
	}

	cout << count << "\n";
	
	return 0;
}

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

const int MAX_N = 100005;
int mem[MAX_N][4];
int aa[MAX_N], ab[MAX_N], ac[MAX_N];
int N;

int dp(int n, int pa) {
  if (n == N) return 0;
  if (mem[n][pa] != 0) return mem[n][pa];
  if (pa != 1) mem[n][pa] =
    std::max(mem[n][pa], dp(n + 1, 1) + aa[n]);
  if (pa != 2) mem[n][pa] =
    std::max(mem[n][pa], dp(n + 1, 2) + ab[n]);
  if (pa != 3) mem[n][pa] =
    std::max(mem[n][pa], dp(n + 1, 3) + ac[n]);
  return mem[n][pa];
}

int main() {
  scanf("%d", &N);
  memset(mem, 0, sizeof(mem));
  for (int i = 0; i < N; ++i) {
    scanf("%d %d %d", aa + i, ab + i, ac + i);
  }
  printf("%d\n", dp(0, 0));
}


Measured memory_bytes: 12668
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    string s;
    cin >> s;
    int cnt1 = 0;
    int cnt2 = 0;
    char x = '1';
    for(int i = 0; i < s.size(); i++){
        if(x != s[i]) cnt1++;
        if(x == '1') x = '0';
        else x = '1';
    }
    x = '0';
    for(int i = 0; i < s.size(); i++){
        if(x != s[i]) cnt2++;
        if(x == '1') x = '0';
        else x = '1';
    }
    cout << min(cnt1, cnt2);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
    long long int i,j,k,x,c=0,n;
    map<long long int,long long int>m;
   
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        
        m[x]++;
    }
    for(auto z:m)
    {
        if(z.second%2==1)
        {
            c++;
        }
    }
    cout<<c<<endl;
    return 0;

}


Measured memory_bytes: 6528
#include <iostream>
using namespace std;
int main(void){
    int A, B, C;
    cin >> A >> B >> C;
    int max_num = max(C, max(A, B));
    int A_diff = max_num - A;
    int B_diff = max_num - B;
    int C_diff = max_num - C;
    int res;
    if ((A_diff + B_diff + C_diff) % 2 == 0) {
        res = (A_diff + B_diff + C_diff) / 2;
    } else {
        res = (A_diff + B_diff + C_diff + 3) / 2;
    }
    cout << res << endl;
}


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

int main()
{
    int N;
    map < int64_t , int > mp;
    int64_t sum = 0;
    
    cin >> N;
    mp[0] = 0;
    
    for ( int i = 0; i < N; i++ ) {
        int a;
        cin >> a;
        sum += a;
        if ( mp.count(sum) > 0 ) {
            mp[sum]++;
        } else {
            mp[sum] = 0;
        }
    }

    int64_t ans = 0; 
    for ( auto &x : mp ) {
        ans += (int64_t)(x.second) * (x.second + 1) / 2;
    }

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


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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const LL INF = 1LL * MX * MX;

int main(){
	int n;
	scanf("%d", &n);
	printf("%d\n", (n - 1) / 2);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
flag = 0
cnt = 0
for i in range(n-1):
    if flag == 0:
        if a[i] > a[i+1]:
            flag = -1
        if a[i] < a[i+1]:
            flag = 1
    if flag == 1:
        if a[i] > a[i+1]:
            flag = 0
            cnt += 1
    if flag == -1:
        if a[i] < a[i+1]:
            flag = 0
            cnt += 1
print(cnt+1)


Measured memory_bytes: 14224
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    var x = n
    val sb = new StringBuilder(":")
    while (x % 2 == 0) {x /= 2; sb.append(" 2")}
    val pfs = Primes.primeFactorize(x).sorted
    pfs foreach (p => while (x % p == 0) {x /= p; sb.append(s" $p")})
    println(n + sb.toString())
  }

  object Primes {
    private def mod_exp(x: BigInt, n: Int, m: Int): BigInt = {
      def loop(x: BigInt, n: Int, acc: BigInt): BigInt = {
        if (n == 0) acc
        else loop (
          (x * x) % m,
          n >> 1,
          if ((n & 1) == 1) (acc * x) % m else acc
        )
      }
      loop(x,n,1)
    }
    private def div_pow_2(d: Int, s: Int = 0): (Int, Int) ={
      if ((d % 2) != 0) (d,s)
      else div_pow_2(d/2, s+1)
    }

    private def miller_rabin(n: Int, a: Int): Boolean = {
      val (d,s): (Int, Int) = div_pow_2(n-1)
      val a_exp_d: BigInt = mod_exp(a,d,n)
      def double(x: BigInt): BigInt = mod_exp(x,2,n)
      def loop(e: BigInt, i: Int): Boolean = {
        if (i == 0) false
        else if (e == n-1) true
        else loop(double(e), i-1)
      }
      a_exp_d == 1 || loop(a_exp_d, s)
    }
    def miller_rabin_test(n: Int, k: Int = 20): Boolean = {
      def loop(i: Int): Boolean = {
        if (i == 0) true
        else {
          val a = scala.util.Random.nextInt(n-1)+1
          if (miller_rabin(n,a)) loop(i-1)
          else false
        }
      }
      if (n < 2) false
      else loop(k)
    }
    def primeFactorize(n: Int): Seq[Int] = {
      val ab = collection.mutable.ArrayBuffer.empty[Int]
      var x = n
      while (x !=1) {
        if (isPrime(x)) {ab += x; x = 1}
        else {
          val p = rho(x)
          if (isPrime(p)) {
            while (x % p == 0) x /= p
            ab += p
          } else {
            val ps = primeFactorize(p)
            ps foreach {p => while (x % p == 0) x /= p; ab += p}
          }
        }
      }
      ab
    }
    def rho(n: Int): Int = {
      def f(x: Int, c: Int): Int = (x * x + c) % n
      def loop(x: Int, y: Int, d: Int, c: Int = 1): Int =
        if (d != 1) {
          if (d == n) loop(2,2,1,c+1)
          else d
        }
        else {
          val a = f(x, c)
          val b = f(f(y, c), c)
          loop(a, b, gcd(Math.abs(a-b), n), c)
        }
      if (n % 2 == 0) 2
      else loop(2,2,1)
    }
    def gcd(x: Int, y: Int): Int = {
      if (x < y) gcd(y, x)
      else {
        if (y > 0) {
          val r = x % y
          gcd(y, r)
        } else x
      }
    }
    def isPrime(n: Int): Boolean = Primes.miller_rabin_test(n)
  }
}

Measured memory_bytes: 44440
#if 0
10000までの素数の配列のうち、指定の値までを尺取り法でみていき、
可能な表現の数を出力する。ヒントがわかりやすかった。
#endif
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
bool not_prime[10001];
vector<int> prime;
int sum;
void write_pattern_num() {
    int start_i = 0;
    int end_i = 0;
    int pattern_num = 0; 
    int tmp_sum = 2;

    while (end_i < prime.size() && prime[end_i] <= sum) {
        if (tmp_sum == sum) {
            ++pattern_num;
            ++end_i;
            tmp_sum += prime[end_i];
        } else if (tmp_sum < sum) {
            ++end_i;
            tmp_sum += prime[end_i];
        } else {
            tmp_sum -= prime[start_i];
            ++start_i;
        }
    }

    cout << pattern_num << endl;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    #define ll int

    for (int i = 2; i < 100; ++i) {
        if (not_prime[i] == false) {
            prime.push_back(i);
            for (int j = 2 * i; j <= 10000; j += i) {
                not_prime[j] = true;
            }
        }
    }
    for (int i = 100; i < 10000; ++i) {
        if (not_prime[i] == false) {
            prime.push_back(i);
        }
    }

    while (cin >> sum) {
        if (sum == 0) return 0;
        write_pattern_num();
    }

    return 0;
}


Measured memory_bytes: 3064
inH, inW = map(int, input().split())
inMap = list()

for i in range(inH):
  inMap.append(list(input()))

def cntB(x,y):

  mv = [-1, 0, 1]
  cnt=0
  for dx in mv:
    if x+dx < 0 or x+dx>inH-1:
      continue
    for dy in mv:
      if y+dy<0 or y+dy>inW-1:
        continue
      if inMap[x+dx][y+dy]=="#":
        cnt+=1
      dy+=1
    dx+=1
    
  return cnt

for i in range(inH):
  s=""
  for j in range(inW):
    if inMap[i][j] == ".":
      s+=str(cntB(i,j))
    else:
      s+=str((inMap[i][j]))
  print(s)



Measured memory_bytes: 3064
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n;
    scan(n);
    auto a = iota(n).map!(i => readln.chomp.to!int).array.sort().group.filter!"a[1] & 1".count;
    writeln(a);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int  A,B,C;
  cin >> A >> B >> C;
  if(C>=A && C<=B){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
  
  
  
  
  

  



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.IOException;
import java.util.stream.Stream;
import java.util.Arrays;
import java.util.function.Function;
import java.util.function.LongBinaryOperator;
import java.util.stream.Collectors;
import java.util.List;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class Main {
    public static void main(String[] args) throws Exception {
        String[] A = new BufferedReader(new InputStreamReader(System.in)).readLine().split(" ");
        Map<String, LongBinaryOperator> map = new HashMap<String, LongBinaryOperator>() {
            {
                put("+", (a, b) -> a + b);
                put("-", (a, b) -> a - b);
                put("*", (a, b) -> a * b);
            }
        };
        Stack<Long> stack = new Stack<Long>();
        for(String s : A){
            if(map.containsKey(s)){
                long b = stack.pop();
                stack.push(map.get(s).applyAsLong(stack.pop(), b));
            }else{
                stack.push(Long.parseLong(s));
            }
        }
        System.out.println(stack.peek());
    }
}


Measured memory_bytes: 30676
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }




int main() {
	int N;
	int a = 0, b = 0, ans = 0;
	scanf("%d", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	qsort(A, N, sizeof(int), cmp_r);
	for (int i = 0; i < N; i++) {
		if (i % 2) {
			b += A[i];
		}
		else {
			a += A[i];
		}
	}
	ans = a - b;

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


#ifdef DEBUGF
	getch();
#endif
	return 0;
	}

Measured memory_bytes: 128
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();
    std::io::stdin()
        .read_line(&mut line)
        .map_err(|err| format!("{:?}", err))?;

    let xs = line.trim().split_whitespace();
    let mut result = Vec::new();

    for x in xs {
        let ans = x.parse::<T>().map_err(|_| format!("{}", "parse error"))?;
        result.push(ans);
    }
    Ok(result)
}

fn main() {
    let x = read_parameters::<usize>().unwrap();
    let x = x[0];

    println!("{}", x * x * x);
}



Measured memory_bytes: 5032
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define foritr(itr, A) for(set<ll>::iterator itr = A.begin(); itr != A.end(); itr++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define cr(x) cerr << #x << " = " << x << "\n";
#define crA(x, A) cerr << #x << " = " << A[x] << "\n";
#define spacing if(db)cout << " ";
#define mmst(x, v) memset((x), v, sizeof ((x)));
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, A[MAXN];
struct convex_hull
{
	deque <pi> dq;
	ll f(pi line, ll x) //y = mx + c;
	{
		return line.f * x + line.s;
	}
	ll query(ll x)
	{
		while(dq.size() > 1)
		{
			if(f(dq[0], x) > f(dq[1], x)) dq.pop_front();
			else break;
		}
		return f(dq[0], x);
	}
	ld intersect(ll m1, ll c1, ll m2, ll c2)
	{
		return (ld)(c2-c1)/(ld)(m1-m2);
	}
	ld intersect(pi line1, pi line2)
	{
		return intersect(line1.f, line1.s, line2.f, line2.s);
	}
	void insert(ll m, ll c)  //y=mx+c,give m and c,query x,find y
	{
		pi line = pi(m, c);
		while(dq.size() > 1)
		{
			ll s = dq.size();
			if(intersect(dq[s-1], line) >= intersect(dq[s-2], line)) dq.pop_back();
			else break;
		}
		dq.pb(line);
	}
} ch;   /* this convex hull finds the minimum y*/
ll dp[MAXN],c;
int main()
{
	cin >> n >> c;
	FOR(i,0,n) cin >> A[i];
	ch.dq.clear();
	ch.insert(0, LLINF);
	FOR(i,1,n)
	{
		ch.insert(2*A[i-1], (i>=0 ? dp[i-1] : 0) + A[i-1]*A[i-1]);
		dp[i] = ch.query(-A[i]) + A[i]*A[i] + c;
	}
	cout << dp[n-1] << '\n';
}


Measured memory_bytes: 6016
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	long long H, W;
	std::cin >> H >> W;
	vector<string> S(H);
	rep(i, 0, H) {
		std::cin >> S[i];
	}

	const vector<pair<ll, ll>> mov = { {1,0},{0,1},{-1,0},{0,-1} };


	vector<vector<bool>> flg(H, vector<bool>(W, true));

	ll ans = 0;
	rep(i, 0, H) {
		rep(j, 0, W) {
			if ( flg[i][j]&&S[i][j]=='#') {
				flg[i][j] = false;
				ll cnt_b = 1;
				ll cnt_w = 0;
				queue<pair<ll, ll>> q;
				q.push({ i,j });
				while (!q.empty()) {
					queue<pair<ll, ll>> r;
					while (!q.empty()) {
						rep(k, 0, 4) {

							ll x = q.front().first + mov[k].first;
							ll y = q.front().second + mov[k].second;
							if (0 <= x && x < H && 0 <= y && y < W && flg[x][y] && (S[q.front().first][q.front().second] != S[x][y])) {
								flg[x][y] = false;
								r.push({ x,y });
								if (S[x][y] == '.') {
									// デバッグ
									// std::cout << i << " " << j << " " << x << " " << y << endl;
									ans += cnt_b;
									cnt_w++;
								}
								else {
									ans += cnt_w;
									cnt_b++;
								}
							}
						}
						q.pop();
					}
					q = r;
				}
			}
		
		}
	}
	std::cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3892
/*****include*****/
#include <iostream>
#include <fstream>
#include <string>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	
	/*****処理部*****/
	for(int i=1;i<10;i++)
		for(int j=1;j<10;j++)
			cout << i << "x" << j << "=" << i*j << endl;
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

Measured memory_bytes: 1116
/* 
 * Project: AtCoder Beginners Contest 147 A - Blackjack
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/05
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

int sum;

void solve() {

    if (sum > 21)
        printf("bust\n");
    else
        printf("win\n");

}

int main() {

    for (int i=0;i<3;i++) {
        int tmp = 0;
        scanf("%d", &tmp);
        sum += tmp;
    }

    solve();

}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
inline int max(int a , int  b){
  if(a > b) return a;
  else return b;

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

long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int gcd(int a , int b){
  if (b == 0) 
        return a; 
    return gcd(b, a % b);
}
int32_t main() 
{ 
  fast;
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  if(a == 0) cout << "1\n";
  else if(b == 0) cout << "2\n";
  else if(c == 0) cout << "3\n";
  else if(d  == 0) cout << "4\n"; 
  else cout << "5\n";
  return 0; 
}

Measured memory_bytes: 3540
#include <iostream>
#include <cmath>
#include <sstream>
using namespace std;

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

  int limit = sqrt(n);
  stringstream ss;
  ss << n << ":" ;

  for (int i = 2; i <= sqrt(n); i++) {
    //int count;
    while (n % i == 0) {
      n /= i;
      ss << " " << i;
      //count ++;
    }
  }
  if(n != 1)
    ss << " " << n;

  cout << ss.str() << endl;
  return 0;
}
  

Measured memory_bytes: 3164
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  
  int ans = 0;
  int sum = 0;
  int h1;
  cin >> h1;
  REP(i,n-1){
    int h2;
    cin >> h2;
    if(h1 >= h2){
      sum++;
    }
    else sum = 0;
    
    ans = max(sum,ans);
    h1 = h2;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3596
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define double long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define eb emplace_back
//#define ll long long
#define int long long
using namespace std;

const int INF = 2e9;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	while (n) {
		ans++;
		n /= k;
	}
	cout << ans;
}

signed main() {
	/*
	freopen("caves.in", "r", stdin);
	freopen("caves.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long gcd(long long m, long long n) {
  if (!n) return m;
  while (n) {
    const auto r = m % n;
    m = n;
    n = r;
  }
  return m;
}

long long lcm(long long m, long long n) { return m / gcd(m, n) * n; }

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

  int n;
  cin >> n;
  long long T[100] = {0};
  for (int i = 0; i < n; ++i) {
    cin >> T[i];
  }
  long long ans = T[0];
  for (int i = 1; i < n; ++i) {
    ans = lcm(ans, T[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include<cstdio>
typedef long long i64;
using namespace std;
 
i64 cross(pair<i64,i64>P,pair<i64,i64>Q,pair<i64,i64> R)//if return >0 then point R is upper of lineseg PQ else down
{
    return  (Q.first-P.first)*(R.second-P.second)-(R.first-P.first)*(Q.second-P.second);
}
void hull(vector<pair<i64,i64> > &P,vector<pair<i64,i64> > &L,vector<pair<i64,i64> > &U)
{
    int j=0,k=0,n=P.size();
    sort(P.begin(),P.end());
    U.resize(2*n);
    L.resize(2*n);
    for(int i=0;i<n;i++)
     {
        while(j>=2 && cross(L[j-2],L[j-1],P[i])<=0)//p[i] is making right turn we need left turn
            j--;
        while(k>=2 && cross(U[k-2],U[k-1],P[i])>=0)//p[i] is making left turn we need right
            k--;
        L[j++]=P[i];
        U[k++]=P[i];
    }
    U.resize(k);
    L.resize(j);
}
i64 fun(pair<i64,i64> P ,pair<i64,i64> Q)
{
    return abs(P.first-Q.first)+abs(P.second-Q.second);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    i64 t,n,k1,k2;
    vector<pair<i64,i64> >v,U,L;
    cin>>n;
    for(int i=0;i<n;i++)
     cin>>k1>>k2,v.push_back(make_pair(k1,k2));
    hull(v,L,U);
    int i=0,j,m;
    j=L.size()-1;
    m=U.size()-1;
    i64 dist=-1;
    while(i<m || j>0)
    {
        dist=max(dist,fun(U[i],L[j]));
        if(i==m)
            j--;
        else if(j==0)
            i++;
        else
        {
            if ( (U[i+1].second-U[i].second) * (L[j].first-L[j-1].first) > (L[j].second-L[j-1].second) * (U[i+1].first-U[i].first) )
            i++;
        else
            j--;
        }
    }
    cout<<dist<<endl;
} 

Measured memory_bytes: 19004
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		switch(s) {
		case "A":
			System.out.println("T");
			break;
		case "T":
			System.out.println("A");
			break;
		case "C":
			System.out.println("G");
			break;
		case "G":
			System.out.println("C");
			break;
		}
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD =  998244353;

signed main(){
	ll n, s; cin >> n >> s;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	vector<vector<ll> > dp(n + 1, vector<ll> (s + 1, 0));
	dp[0][0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= s; j++){
			dp[i + 1][j] += 2 * dp[i][j];
			dp[i + 1][j] %= MOD;
			if(j - a[i] >= 0) dp[i + 1][j] += dp[i][j - a[i]];
			dp[i + 1][j] %= MOD;
		}
	}
	cout << dp[n][s] << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    ll cost = 1000;
    ll stock = 0;
    for(int i = 0; i < N - 1; i++) {
        if(stock == 0 && A[i] < A[i + 1]) {
            stock = cost / A[i];
            cost -= stock * A[i];
        } else if(stock != 0 && A[i] > A[i + 1]) {
            cost += stock * A[i];
            stock = 0;
        }
    }
    if(stock != 0 && A[N - 2] <= A[N - 1])
        cost += stock * A[N - 1];

    cout << cost << endl;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long int n, m, k, now = 0;
	cin >> n >> m >> k;
	vector <long long int> a(n);
	for (auto &i : a) cin >> i;
	vector <long long int> b(m);
	for (auto &i : b) cin >> i;
	int cnt = 0;
	vector <long long int> suma, sumb;
	suma.push_back(0);
	sumb.push_back(0);	
	for (int i = 0; i < n; ++i){
		suma.push_back(suma.back() + a[i]);
	}
	suma.push_back(k);
	for (int i = 0; i < m; ++i){
		sumb.push_back(sumb.back() + b[i]);
	}
	long long int ans = 0;
	auto it = lower_bound(suma.begin(),suma.end(),k);
//	cout << *it << "\n";
	if (*it > k) it = prev(it);
//	cout << *it << "\n";
	for (auto p = suma.begin(); p <= it; ++p){
		auto pb = upper_bound(sumb.begin(),sumb.end(),k - *p);
	       if (pb == sumb.begin()){
		continue;
	       }
		pb = prev(pb);
		int x = (pb - sumb.begin()) + (p - suma.begin());
		if (x > ans) ans = x;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 11080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll a[15];
int x=1,y=1;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        x*=3;
        if(a[i]%2==0){
            y*=2;
        }else{
            y*=1;
        }
    }
    cout<<x-y<<endl;

}



Measured memory_bytes: 3584
N=int(input())
A=list(map(int,input().split()))
A=[0]+A+[0]

dist=0
diff=[0]*(len(A)-2)
for i in range(len(A)-1):
  dist+=abs(A[i+1]-A[i])
  if 1<=i<=len(A)-2:
    diff[i-1]=abs(A[i]-A[i-1])+abs(A[i+1]-A[i])-abs(A[i+1]-A[i-1])
  
for i in range(len(diff)):
  print(dist-diff[i])

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

int main() {
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    queue<char> q[3];

    rep(i, 3) {

        rep(j, s[i].length()) {
            q[i].push(s[i][j]);
        }
    }

    int turn = 0;
    char winner;

    while (1) {      
        char f = q[turn].front();
        q[turn].pop();
        turn = (int) (f - 'a');

        if (q[turn].empty()) {
            winner = turn + 'A';
            break;
        }
        
    }

    cout << winner << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int N, a, b, c;
int ans = 5000;
vector<int> l(10);

void dfs(int x, int y, int z, int d, int count);

int main()
{
    cin >> N >> a >> b >> c;
    rep(i, 0, N)
    {
        cin >> l.at(i);
    }
    dfs(0, 0, 0, 0, 0);
    cout << ans << endl;
}

void dfs(int x, int y, int z, int d, int count)
{
    if (count == N)
    {
        if ((x == 0) || (y == 0) || (z == 0))
        {
            return;
        }
        else
        {
            int key = abs(a - x) + abs(b - y) + abs(c - z) + 10 * (d - 3);
            ans = min(ans, key);
            return;
        }
    }
    dfs(x, y, z, d, count + 1);
    dfs(x + l.at(count), y, z, d + 1, count + 1);
    dfs(x, y + l.at(count), z, d + 1, count + 1);
    dfs(x, y, z + l.at(count), d + 1, count + 1);
}

Measured memory_bytes: 256
n, x, m = map(int, input().split())

s = set()
idx = {i: -1 for i in range(m)}
cumsum = [0]
val = x
idx[val] = 0
for i in range(n):
    cumsum.append(cumsum[-1] + val)
    val = pow(val, 2, m)
    if idx[val] != -1:
        break
    idx[val] = i + 1

if len(cumsum) > n:
    print(cumsum[n])
else:
    loop_len = i + 1 - idx[val]
    print((cumsum[i+1]-cumsum[idx[val]]) * ((n-idx[val])//loop_len) + cumsum[idx[val]+(n-idx[val])%loop_len])


Measured memory_bytes: 20824
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    for(int i = 1; i <= N; i++){
      if((i * (i+1))/2 >= N){
        System.out.println(i);
        return;
      }
    }
  }
}

Measured memory_bytes: 21712
#include<stdio.h>
#define N 256

int main(){
  int i=0,j,k=0,m,n;
  int H[N],W[N];
  while(1){
    scanf("%d %d",&H[i],&W[i]);
    if(H[i]==0 && W[i]==0){
      break;
    }
    i++;
  }
  for(m=0;m<i;m++){
    for(j=0;j<H[m];j++){
      for(n=0;n<W[m];n++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572