akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
-- import Data.Array
import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST
import Data.Char
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = B.getLine >>= print . solve . B.unpack

solve = (!5) . foldl' f initial . zip [0..] . reverse 
  where
    initial = listArray (0, 12) $ 1:replicate 12 0
    f :: UArray Int Int -> (Int, Char) -> UArray Int Int
    f prev (!i, !c)
      | c == '?'  = runSTUArray $ do
        arr <- newArray (0, 12) 0
        forM_ [0..9] $ \i -> do
          forM_ [0..12] $ \j -> do
            let d = (i * tens + j) `mod` 13
            v <- readArray arr d
            writeArray arr d $ v `modadd` (prev!j)
        return arr
      | otherwise = listArray (0, 12) $ map g [0..12]
        where
          si = digitToInt c
          tens = power 10 i
          rem = (si * tens) `mod` 13
          g j = prev ! ((j - rem) `mod` 13)

divConst = 10^9 + 7
modadd x y = (x + y) `mod` divConst
modsub x y = (x - y) `mod` divConst
modmul x y = ((x `mod` divConst) * (y `mod` divConst)) `mod` divConst
moddiv x y = modmul x (power y (divConst - 2))

power x y
  | y == 0 = 1
  | y == 1 = x `mod` 13
  | y `mod` 2 == 0 = (power x (y `div` 2))^2 `mod` 13
  | otherwise = (power x (y `div` 2))^2 * x `mod` 13
          

    


Measured memory_bytes: 5628
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
ans = 0

for i in counter.values():
	ans += i * (i - 1) // 2

for j in A:
	cnt = counter[j]
	if cnt <= 1:
		print(ans)
	else:
		print(ans - cnt + 1)

Measured memory_bytes: 26780
#include<stdio.h>
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int i, j;
	int p[5003];
	for (i = 0; i < n; i++)
		scanf("%d", &p[i]);
	long long int c[5003];
	for (i = 0; i < n; i++)
		scanf("%lld", &c[i]);
	long long int v[5003];
	long long int max, now, ans = -10000000000000, cc, a, maxa;
	int kk;
	for (j = 0; j < n; j++)
	{
		max = now = 0;
		for (i = 0; i < n; i++)
			v[i] = -1;
		i = j;
		v[i] = 0;
		for (kk = 0; kk < k; kk++)
		{
			i = p[i] - 1;
			now += c[i];
			if (v[i] < 0)
			{
				v[i] = kk + 1;
				if (ans < now)
					ans = now;
			}
			else
			{
				cc = kk + 1 - v[i];
				max = c[i];
				for (a = p[i] - 1; a != i; a = p[a] - 1)
					max += c[a];
				now -= max;
				if (max > 0)
				{
					if (k - v[i] > 2 * cc)
					{
						now += (k - v[i] - 2 * cc) / cc * max;
						a = v[i] + (k - v[i] - 2 * cc) / cc * cc;
					}
					else
						a = v[i];
					for (; a < k; a++)
					{
						if (ans < now)
							ans = now;
						i = p[i] - 1;
						now += c[i];
						if (ans < now)
							ans = now;
					}
				}
				break;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1820
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod)) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) { return *this *= p.inverse(); }
  ModInt operator-() const { return ModInt() - *this; }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b) t = a / b, swap(a -= t * b, b), swap(u -= t * v, v);
    return ModInt(u);
  }
  ModInt pow(int64_t e) const {
    ModInt ret(1);
    for (ModInt b = *this; e; e >>= 1, b *= b)
      if (e & 1) ret *= b;
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int modulo() { return mod; }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  using Mint = ModInt<int(1e9 + 7)>;
  int N;
  cin >> N;
  int C[N];
  for (int i = 0; i < N; i++) cin >> C[i];
  sort(C, C + N);
  Mint ans = 0;
  for (int i = 0; i < N; i++) {
    ans += Mint(C[i]) * Mint(N - i + 1);
  }
  ans *= Mint(2).pow(2 * N - 2);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4348
import java.util.Scanner;
class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int day = scan.nextInt();
        int homework = scan.nextInt();
        int sum = 0;
        int suji[] = new int[homework];
        for(int j = 0; j < suji.length; j++){
            suji[j] = scan.nextInt();
        }
        for(int i = 0; i < suji.length; i++){
            sum += suji[i];
        }
        int canPlay;
        canPlay = day - sum; 
        if(canPlay >=0){
            System.out.println(canPlay);
        }else{
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 46620
#include<iostream>

using namespace std;

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

  if(a < b) {
    cout << "a" << " < " << "b" << endl;
  } else if(a > b) {
    cout << "a" << " > " << "b" << endl;
  } else {
    cout << "a" << " == " << "b" << endl;
  }
  
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>

int main() {
  std::string S;

  std::cin >> S;

  if (S.length() == 3) {
    for (auto i=S.crbegin(); i!=S.crend(); i++) {
      std::cout << *i;
    }
  } else {
    std::cout << S;
  }
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for _ in range(D)])


def s8(c, s, last_date, di, i, mul):
    score = s[di - 1][i]
    score += 0.1 * mul * c[i] * (di - last_date[i])
    return score


def f9(D, c, s):
    last_date = np.zeros(26)

    t = []
    for di in range(1, D + 1):
        mul = np.mean(s[di - 1]) / np.mean(c)
        score_list = []
        for i in range(26):
            score_list.append(s8(c, s, last_date, di, i, mul))

        select_index = score_list.index(max(score_list))
        t.append(select_index)
        last_date[select_index] = di

    return t


for ti in f9(D, c, s):
    print(ti + 1)

Measured memory_bytes: 27292
import Data.Char

main = do
    [d, n] <- map read . words <$> getLine
    putStrLn $ show $ ans d n

ans 0 n = last . take n $ filter (\x -> x `mod` 100 /= 0) [1..]
ans 1 n = last . take n $ filter (\x -> x `mod` 100 == 0 && x `mod` 10000 /= 0) [1..]
ans 2 n = last . take n $ filter (\x -> x `mod` 10000 == 0 && x `mod` 1000000 /= 0) [1..]


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

int main()
{
  
  int x,y;
  cin >> x>>y;
  long ans=0;
  switch(x){
    case 1:
      ans += 300000;
      break;
    case 2:
      ans += 200000;
      break;
    case 3:
      ans += 100000;
      break;
  }
  
  switch (y)
  {
  case 1:
    ans += 300000;
    break;
  case 2:
    ans += 200000;
    break;
  case 3:
    ans += 100000;
    break;
  }
if(x==y and x==1){
  ans +=
      400000;}
       cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    static int n;
    static int f;
    static Scanner sc = new Scanner(System.in);
    static int count;
    public static void main(String[] args){
        n = sc.nextInt();
        System.out.println(fib(n));
    }

    public static int fib(int n){
        if(n < 2){
            return 1;
        }else{
            int f = 1;
            int f1 = 1;
            int f2;
            for(int i=2; i<=n; i++){
                f2 = f1;
                f1 = f;
                f = f1 + f2;
            }
            return f;
        }
    } 
}


Measured memory_bytes: 26092
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  ll N, A, B;
  cin >> N >> A >> B;
  
  ll res = 0;
  ll res1 = 0;
  ll res2 = 0;
  
  if((A-B)%2 == 0){
    res = (abs(A-B))/2;
  }else{
    res1 = min(max(A-1, B-1), max(N-A, N-B));    
    if(N-B+1 < A){
      res2 += N-B+1;
      res2 +=(B-A-1)/2;
    }else{
      res2 += A;
      res2 +=(B-A-1)/2;
    }
    res = min(res1, res2);
  }
  
  
  cout << res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,p;
  cin >> n >> p;
  vector<ll> x(1000000);
  if(n==1){
    cout << p << endl;
  }
  else{
  for(ll i=2;i<=1000000;i++){
    while(p%i==0){
      x[i]++;
      p/=i;
    }
  }
  ll ans=1;
  for(ll i=2;i<=1000000;i++){
    for(int j=1;j<=x[i]/n;j++){
      ans*=i;
    }
  }
  cout << ans << endl;
  }
}

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

int main(void){
    string s;
    cin >> s;
    int count = 0;

    for(int i = 0; i < 3; i++){
        if(s[i] == '1')
            count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())
result = 0
for num in range(1,N+1):
    if(num%2>0 and len(make_divisors(num))==8):
        result = result + 1
print(result)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
typedef long long int ll;
#define lld long double
#define endl "\n"
#define For(i, a, b) for(long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for(long long int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define vi vector<int>
#define vch vector<char>
#define sll set<ll>
#define sch set<ch>
#define vpll vector< pair<ll,ll> >
#define vpii vector< pair<int,int> >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mll map<ll, ll>
#define mcll map<char,ll>
#define sz(container) ll((container).size())
#define fill(a,b) memset(a, b, sizeof(a))
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
lld pi=3.1415926535897932;
const ll MOD=1e9+7;
const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1};
const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};
ll lcm(ll a, ll b)
{
    ll g=__gcd(a, b);
    return a/g*b;
}
ll binpow(ll a, ll b, ll m) 
{
    a %= m;
    ll res = 1;
    while (b > 0) 
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
bool isPrime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_io;
    ll T=1;
    For(i,1,T)
    {
        ll n;cin>>n;
        ll num=0,ans=0;
        For(j,0,1ll*1e8)
        {
            num+=7;num%=n;num*=10;
            ans++;
            if(num==0) break;
        }
        (num)?cout<<"-1":cout<<ans;
    }
}

Measured memory_bytes: 3648
N=int(input())
import queue
q=queue.Queue()
for i in range(1,10):
    q.put(i)
while N!=1:
    a=q.get()
    b=a%10
    c=[10*a+i for i in range(max(0,b-1),min(10,b+2))]
    for j in c:
        q.put(j)
    N-=1
print(q.get())

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

namespace codeTester.contest190720
{
    class ProblemB
    {
        static List<long> nd = new List<long>();
        static long answer = 0;

        public static void Main(string[] args)
        {
            Input();
            Logic();
            Output();
        }

        static void Input()
        {
            nd = ReadSpaceSeparatedValues();
        }

        public static List<long> ReadSpaceSeparatedValues()
        {
            List<long> values = new List<long>();
            string[] inputs = Console.ReadLine().Split(' ');
            foreach (string input in inputs)
            {
                values.Add(long.Parse(input));
            }

            return values;
        }

        static void Logic()
        {
            long n = nd[0];
            long d = nd[1];
            if (n % (2 * d + 1) == 0)
            {
                answer = n / (2 * d + 1);

            } else
            {
                answer = n / (2 * d + 1) + 1;
            }
        }

        static void Output()
        {
            Console.WriteLine(answer.ToString());
        }

        static void DebugPrint(string msg)
        {
            // 提出時に消す
            // Console.WriteLine(msg);
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

vector<ll> sosu;
void Sosu(ll x){
    bool s[x+1];
    fill(s,s+x+1,true);
    ll i;
    for(i=2;i*i<=x;i=i+2){
        if(s[i]){
            sosu.pb(i);
            for(ll j=2;j*i<=x;j++){
                s[j*i]=false;
            }
        }
        if(i==2)i--;
    }
    for(i=i;i<=x;i=i+2){
        if(s[i]){
            sosu.pb(i);
        }
    }
}

ll hpow(ll x,ll y){
    ll ans=1;
    ll i=x;
    if(y==0)return 1;
    while(y>0){
        if(y%2==1){
            ans=(ans*i)%i_7;
        }
        i=(i*i)%i_7;
        y=y/2;
        
    }
    return ans;
}

ll memop[2000000];
ll mkai(ll i){
    if(i==0){
        return 1;
    }
    if(memop[i]!=0){
        return memop[i];
    }else{
        ll ans=(mkai(i-1)*hpow(i,i_7-2))%i_7;
        memop[i]=ans;
        return ans;
    }
}

ll memok[2000000];
ll kai(ll i){
    if(i==0){
        return 1;
    }
    if(memok[i]!=0){
        return memok[i];
    }else{
        ll ans=(kai(i-1)*i)%i_7;
        memok[i]=ans;
        return ans;
    }
}

ll comb(ll n,ll k){
    ll ans=(kai(n)*mkai(k))%i_7;
    ans=(ans*mkai(n-k))%i_7;
    return ans;
}

int main(){
    ll n,m;cin>>n>>m;
    ll ans=1;
    Sosu((ll)sqrt(m)+2);
    ll k;
    rep(i,0,sosu.size()-1){
        k=0;
        while(m%sosu[i]==0){
            k++;
            m=m/sosu[i];
        }
        ans=(ans*comb(n-1+k,n-1))%i_7;
        //cout<<sosu[i]<<' '<<k<<endl;
    }
    if(m==1){
        cout<<ans<<endl;
    }else{
        cout<<(ans*n)%i_7<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 6784
#11:57
a,b = map(int,input().split())
a -= 1
b -= 1
ap = a // 50
bp = b // 50
ar = a % 50
br = b % 50
print(ap*2 + 4 + bp*2,100)
for _ in range(ap):
  print('.#' * 50)
  print('##' * 50)
print('.#' * ar + '##' * (50-ar))
print('##' * 50)
print('..' * 50)
print('.#' * br + '..' * (50-br))
for _ in range(bp):
  print('..' * 50)
  print('.#' * 50)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;
typedef long long ll;

ll k;

void solve() {
  ll minimum = k / 50;
  ll mod = k % 50;
  cout << 50 << endl;
  for (int i=0;i<mod;i++) {
    if (i != 0) {
      cout << " ";
    }
    cout << (minimum + 50 - i);
  }
  for (int i=mod;i<50;i++) {
    cout << " " << (minimum + 49 - i);
  }
  cout << endl;
}

int main() {
  cin >> k;
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int student[28] = {0} ;
    int Count = 0 ;
    for ( int i = 0 ; i < 28 ; i++ )
    {
        cin >> student[i] ;
    }
    sort( student,student+28 ) ;
    for( int i = 0 ; i < 28 ; i++ )
    {
        if ( student[i] == (student[i-1] + 2) )
        {
            cout << student[i] - 1 << endl ;
            Count++ ;
        }
    }
    switch ( Count )
    {
        case 0:
        {
            cout << 29 << endl ;
        }
        case 1:
        {
            cout << 30 << endl ;
        }
    }
    return 0 ;
}

Measured memory_bytes: 3080
import java.io.IOException;
import java.util.Scanner;

public class Main{
	public static int n;
	public static int A[];
	public static int B[];
	public static int C[] = new int[10000];
	public static StringBuilder sb = new StringBuilder();

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		A = new int[n];
		B = new int[n];

		for(int i = 0; i<n ;i++){
			A[i] = scan.nextInt();
			C[A[i]]++;
		}

		for(int i=1;i<10000;i++){
			C[i] = C[i-1]+C[i];
		}

		for(int i = n-1;i>=0;i--){
			B[C[A[i]]-1] = A[i];
			C[A[i]]--;
		}

		for(int i = 0; i < n-1 ;i++){
			sb.append(B[i]);
			sb.append(" ");
		}
		System.out.println(sb.toString()+B[n-1]);

	}

}

Measured memory_bytes: 601360
/*input
46 4 40 5
*/

#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility> 
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ld = long double;

const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define all(c)      (c).begin(),(c).end()
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(auto x: v) {
    os << x << " ";
  }
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

/******************************** START *********************************/
const int N = 100005;

int main()
{
  ifalse;
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(1) {
    c -= b;
    if(c <= 0) {
      cout << "Yes";
      return 0;
    }
    a -= d;
    if(a <= 0) {
      cout << "No";
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3584
n = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

total = 0
arr = factorization(n)
for [insu, num] in arr:
  if insu == 1:
    break
  i = 1
  while num >= 0:
    num -= i
    total += 1
    i += 1
  total -= 1
print(total)

Measured memory_bytes: 9492
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long LL;

const int N = 4010;

int r[N], g[N], b[N];
char s[N];

int main()
{
    int n;
    scanf("%d", &n);
    scanf("%s", s + 1);
    
    for(int i = 1; i <= n; i ++)
    {
        r[i] = r[i - 1], g[i] = g[i - 1], b[i] = b[i - 1];
        if(s[i] == 'R')  r[i] ++;
        else if(s[i] == 'G')  g[i] ++;
        else  b[i] ++;
    }
    
    LL res = 0;
    for(int i = 1; i <= n; i ++)
        for(int j = i + 1; j <= n; j ++)
            if(s[i] != s[j])
            {
                char c = (int)'R' + 'G' + 'B' - s[i] - s[j];
                if(c == 'R')  res += r[i - 1];
                else if(c == 'G')  res += g[i - 1];
                else  res += b[i - 1];
                if(i - (j - i) >= 1 and s[i - (j - i)] == c)  res --;
            }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 1756
x, y, a, b, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)

A = A[len(A)-x:]
B = B[len(B)-y:]
C = list(map(lambda x: x*(-1), C))

import heapq
heapq.heapify(A)
heapq.heapify(B)
heapq.heapify(C)

flag = True
while flag:
  a = heapq.heappop(A)
  b = heapq.heappop(B)
  c = heapq.heappop(C)*(-1)
  if c < a and c < b:
    heapq.heappush(A, a)
    heapq.heappush(B, b)
    flag = False
  else:
    if a > b:
      heapq.heappush(A, a)
      heapq.heappush(B, c)
      if not C:
        break
    else:
      heapq.heappush(A, c)
      heapq.heappush(B, b)
      if not C:
        break
print(sum(A) + sum(B))

Measured memory_bytes: 23328
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()

    val g = Graph(N, 0L, 1e15.toLong()) {a,b -> a + b}

    for (i in 1..N-1) {
        val (a, b, c) = readLine()!!.split(" ").map{it.toInt() - 1}

        g.edges[a].add(Edge(a, b, c + 1L))
        g.edges[b].add(Edge(b, a, c + 1L))
    }

    val (Q, K) = readLine()!!.split(" ").map{it.toInt()}
    val dist = dijkstra(g, K - 1).first
    for (i in 1..Q) {
        val (x, y) = readLine()!!.split(" ").map{it.toInt() - 1}
        println(dist[x] + dist[y])
    }
}

data class Edge<T: Comparable<T>>(val from: Int, val to: Int, val weight: T): Comparable<Edge<T>> {
    constructor(from: Long, to: Long, weight: T) : this(from.toInt(), to.toInt(), weight)

    override fun compareTo(other: Edge<T>) = weight.compareTo(other.weight)
}

class Graph<T: Comparable<T>>(val n: Int, val zero: T, val inf: T, val plus: (T, T) -> T) {
    val edges = Array(n) { ArrayList<Edge<T>>() }
}

inline fun <reified T: Comparable<T>>dijkstra(g: Graph<T>, s: Int): Pair<Array<T>, Array<Int>> {
    val N = g.n
    val dist = Array(N) { g.inf }
    val prev = Array(N) {-1}

    val Q = PriorityQueue<Edge<T>>()

    dist[s] = g.zero
    Q.add(Edge(-2, s, g.zero))

    while(Q.isNotEmpty()) {
        val e = Q.peek()
        val v = e.to
        Q.poll()

        if (prev[v] != -1) continue
        prev[v] = e.from
        for (i in g.edges[v]) {
            val d = g.plus(dist[v], i.weight)
            if (dist[i.to] > d) {
                dist[i.to] = d
                Q.add(Edge(i.from, i.to, d))
            }
        }
    }

    return Pair(dist, prev)
}


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

int main() {
  long N,D,X;
  cin>>N>>D>>X;
  vector<int> a(N);

  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int ans=X;
  for(int i=0;i<N;i++){
    if(D%a[i]==0) ans+=D/a[i];
    else ans += D/a[i]+1;
  }

  cout<<ans<<endl;
}


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

using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;


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

    int C = X/100;

    if(C*100 <= X && X <= C*105)cout << 1 << endl;
    else cout << 0 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define endl        	"\n"
#define int         	long long int  
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define pll         	pair<ll,ll>
#define vec     		vector<ll>
#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b)
{
    ll res = 1;
    while(b)
    {
        if(b&1) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a)
{
	return mod_pow(a,mod-2);
}

void solve()
{
	string s;
	
	cin >> s;
	
	int n = s.size() - 1;
	
	map< int , string > mp1;
	
	mp1[0] = mp1[1] = mp1[6]= mp1[8] = "pon";
	
	mp1[2] = mp1[4] = mp1[5] = mp1[7] = mp1[9] = "hon";
	
	mp1[3] = "bon";
	
	cout<<mp1[s[n]-'0'];
}

signed main()
{
    fast;
	
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}


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

using namespace std;

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

int ans[100002];
vector<pair<int,int> >adj[100002];

void DFS(int x,int y,int cost)
{
    if(ans[y] != -1)return;
    if(x == 0)ans[y]=0;
    else ans[y]=(ans[x]+cost)%2;
    for(pair<int,int> z : adj[y])DFS(y,z.first,z.second);
}

int main()
{
    FAST();
    int i,n,x,y,z;
    cin >> n;
    ans[1]=-1;
    for(i=2;i<=n;i++)
    {
        ans[i]=-1;
        cin >> x >> y >> z;
        z%=2;
        adj[x].emplace_back(y,z);
        adj[y].emplace_back(x,z);
    }
    DFS(0,1,1);
    for(i=1;i<=n;i++)cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 7552
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
  ll H,W;
  cin >>H >> W;
  ll N;
  cin >> N;
  ll a[200000]={0},c[200][200]={0};
  //cは出力
  rep(i,N)cin >> a[i];
  ll col=0,row=0;
  bool flag =true;//if(true)left to right
  rep(i,N){
    rep(j,a[i]){
      if(flag){
        c[col][row]=i+1;
        row++;
        if(row==W){
          flag=false;
          row=0;
          col++;
        }
      }else{
        c[col][W-1-row]=i+1;
        row++;
        if(row==W){
          flag=true;
          row=0;
          col++;
        }
      }
    }
  }
  rep(i,H){
    rep(j,W){
      cout << c[i][j] << " ";
    }
    cout << endl;
  }
}


Measured memory_bytes: 2176
import sys
import numpy as np
from numba import njit, i4
read = sys.stdin.readline


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('unko')

    @cc.export('main', '(i4, i4, i4[:])')
    def main(n, k, a):
        for i in np.arange(n, 100000):
            ok = 1
            j = i
            while j:
                m = j % 10
                for l in a:
                    if m == l:
                        ok = 0
                j //= 10
            if ok:
                print(i)
                break
    cc.compile()
    exit()


if __name__ == '__main__':
    from unko import main
    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
    a = np.fromstring(read(), dtype=np.int32, sep=' ')
    main(n, k, a)


Measured memory_bytes: 92760
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main()
{
  string s;
  cin >> s;
  int size = s.size();
  vector<int> ret(size, 1);
  int leftStreak = 0, rightStreak = 0;
  int lastLR = 0;
  for (int i = 0; i <= size - 1; ++i)
  {
    if (i == size - 1)
    {
      ret[i] = 0;
      ++leftStreak;
      break;
    }
    if (s[i] == 'R' && s[i + 1] == 'L')
    {
      if (rightStreak % 2 == 1)
      {
        ret[i + 1] += rightStreak / 2 + rightStreak % 2;
        ret[i] += rightStreak / 2;
      }
      else
      {
        ret[i + 1] += rightStreak / 2;
        ret[i] += rightStreak / 2;
      }
      if (leftStreak % 2 == 1)
      {
        ret[lastLR + 1] += leftStreak / 2;
        ret[lastLR] += leftStreak / 2 + leftStreak % 2;
      }
      else
      {
        ret[lastLR + 1] += leftStreak / 2;
        ret[lastLR] += leftStreak / 2;
      }

      leftStreak = 0, rightStreak = 0;
      lastLR = i;
      i++;
    }
    else
    {
      ret[i] = 0;
      if (s[i] == 'R')
        ++rightStreak;
      else
      {
        ++leftStreak;
      }
    }
  }

  if (leftStreak != 0)
  {
    if (leftStreak % 2 == 1)
    {
      ret[lastLR + 1] += leftStreak / 2;
      ret[lastLR] += leftStreak / 2 + leftStreak % 2;
    }
    else
    {
      ret[lastLR + 1] += leftStreak / 2;
      ret[lastLR] += leftStreak / 2;
    }
  }

  for (int i = 0; i < size; i++)
  {
    cout << ret[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> p(n);
    REP(i, n){ cin >> p.at(i); }

    ll count = 1;
    vector<bool> is_sorted(n, false);
    for(ll i = 1; i < n; ++i){
        if(p.at(i - 1) < p.at(i)){
            count++;
        }else{
            count = 1;
        }
        if(count >= k){
            is_sorted.at(i - (k - 1)) = true;
        }
    }

    set<ll> s;
    REP(i, k){ s.insert(p.at(i)); }
    ll ans = !is_sorted.at(0);
    for(ll i = 1; i + k - 1 < n; ++i){
        s.erase(p.at(i - 1));
        s.insert(p.at(i + k - 1));
        if(!is_sorted.at(i) &&
           !(p.at(i - 1) < *s.begin() &&
             p.at(i + k - 1) == *s.rbegin())){
            ans++;
        }
    }
    if(any_of(ALL(is_sorted), [](bool x){ return x; })){
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11264
from itertools import permutations
from math import factorial
n = int(input())
towns = [list(map(int, input().split())) for _ in range(n)]
path_length = 0
for p in permutations(towns):
    for (x1, y1), (x2, y2) in zip(p, p[1:]):
        path_length += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 
ans = path_length / factorial(n)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int A, B;
  cin >> A >> B;
  int mx;
  mx = std::max(A+B, std::max(A-B, A*B));

  cout << mx << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int n[3]; rep(i, 3) cin >> n[i];
  sort(n, n+3);
  int result = n[0]+(n[2]*10+n[1]);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    long long a[100001];
    for (long long i = 0; i < n; i++)
        cin >> a[i];

    long long sum;

    sum = 0;
    long long ret1 = 0;
    for (long long i = 0; i < n; i++) {
        sum += a[i];
        if (i % 2 == 0 && sum <= 0) {
            ret1 += abs(sum) + 1;
            sum = 1;
        } else if (i % 2 == 1 && sum >= 0) {
            ret1 += abs(sum) + 1;
            sum = -1;
        }
    }

    sum = 0;
    long long ret2 = 0;
    for (long long i = 0; i < n; i++) {
        sum += a[i];
        if (i % 2 == 0 && sum >= 0) {
            ret2 += abs(sum) + 1;
            sum = -1;
        } else if (i % 2 == 1 && sum <= 0) {
            ret2 += abs(sum) + 1;
            sum = 1;
        }
    }

    cout << min(ret1, ret2) << endl;

    return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin>>s;

    string ans="Yes";
    for(int i=0; i<s.length(); i++)
    {
        if(i%2==0 && s[i]=='L') ans="No";
        else if(i%2==1 && s[i]=='R') ans="No";

        if(ans=="No")
        {
            break;
        }
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#
# abc144 b
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """10"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """50"""
        output = """No"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """81"""
        output = """Yes"""
        self.assertIO(input, output)


def resolve():
    N = int(input())

    ans = "No"
    for i in range(1, 10):
        if ans == "Yes":
            break
        for j in range(1, 10):
            if i*j == N:
                ans = "Yes"
                break
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16116
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#define MAX 100001
using namespace std;
vector<int> v[MAX];
int color[MAX];

void dfs(int x,int value){
	stack<int> s;
	s.push(x);
	color[x] = value;
	while(!s.empty()){
		int u = s.top();
		s.pop();
		for(int i = 0;i < v[u].size();i++){
			int a = v[u][i];
			if(color[a] == -1){
				color[a] = value;
				s.push(a);
			}
		}
	}
}

int main(){
	int n,m,q,x,y,value;
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}

	value = 1;
	for(int i = 0;i < n;i++){
		color[i] = -1;
	}
	for(int i = 0;i < n;i++){
		if(color[i] == -1)dfs(i,value++);
	}

	cin >> q;
	for(int i = 0;i < q;i++){
		cin >> x >> y;
		if(color[x] == color[y])cout << "yes" <<endl;
		else cout << "no" <<endl;
	}
	return 0;
}

Measured memory_bytes: 7060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int p[5005];
int main(){
    int n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        for(int j=i-1;j>=0;j--){
            if(s[j]==s[i]) p[i-j]=min(p[i-j]+1,i-j);
            else p[i-j]=0;
            ans=max(ans,p[i-j]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
#-------------------------------------------------------------------
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N,M = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

AC=[0]*(N+1)
WA=[0]*(N+1)

for i in range(M):
	q,s = input().split()
	p=int(q)
	
	if s=="AC":
		AC[p]=1
	
	if s=="WA":
		if AC[p]==0:
			WA[p]+=1

for i,ac in enumerate(AC):
	if ac==0: WA[i]=0

print(sum(AC),sum(WA))


Measured memory_bytes: 4596
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M; cin >> N >> M;
	cout << N * M << endl;
	return 0;
}



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

typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d;

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

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

int main(){
    int N,M,R,*r,*A,*B,*C,i,dis=0,minim=INF;
    cin >> N >> M >> R;
    r = new int[R];
    A = new int[M];
    B = new int[M];
    C = new int[M];
    d = Matrix(N, vector<int>(N, INF));
    for (int i = 0; i < N; i++) d[i][i] = 0;

    for(i=0;i<R;i++){
        cin >> r[i];
        --r[i];
    }
  
    for(i=0;i<M;i++){
        cin >> A[i] >> B[i] >> C[i];
        d[--A[i]][--B[i]] = C[i];
        d[B[i]][A[i]] = C[i];
    }

    warshall_floyd(N);
    //cout << "OK" << endl;
    qsort(r,R,sizeof(int),compare_int);
    //cout << "OK" << endl; 
    do{
        // for(i=0; i<R; i++){
        //     cout<<r[i];
        //     if(i!=R-1)cout<<" ";
        // }
        // cout<<endl;
        for(i=0; i<R-1; i++){
            dis += d[r[i]][r[i+1]];
        }
        minim = min(dis,minim);
        //cout << minim << endl;
        dis = 0;
    }while(next_permutation(r,r+R));

    cout << minim << endl;

    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template <typename T> using order_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1, typename T2> using order_map = tree <T1, T2, less <T1>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T> bool MIN(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool MAX(T &a, T b) { return a < b ? (a = b, true) : false; }

#define ll              long long int
#define endl            '\n'
#define pii             pair <int, int>
#define pll             pair <ll, ll>
#define mk              make_pair
#define ff              first
#define ss              second
#define all(a)          (a).begin(), (a).end()
#define rall(a)         (a).rbegin(), (a).rend()
#define eb              emplace_back
#define pb              push_back
#define LINE            __LINE__

static const int maxn = 2e5 + 5;
static const int logn = 19;

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);


      int n;
      cin >> n;
      n = n % 10;
      string s = "hon";
      if (n == 3) {
            s = "bon";
      }
      else if (n == 0 or n == 1 or n == 6 or n == 8) {
            s = "pon";
      }
      cout << s << endl;

      #ifndef ONLINE_JUDGE
            cerr << endl << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
      #endif // ONLINE_JUDGE
}


Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int n, i, j, k;
    int H, X, Y;
    cin >> n;
    int val[n][3];
    for (i = 0; i < n; i++)
        for (j = 0; j < 3; j++)
            cin >> val[i][j];

    for (X = 0; X <= 100; X++)
    {
        for (Y = 0; Y <= 100; Y++)
        {
            for (k = 0; k < n && val[k][2] == 0; k++)
                ;

            H = abs(X - val[k][0]) + abs(Y - val[k][1]) + val[k][2];
            for (i = 0; i < n; i++)
            {
                if (val[i][2] != max((H - abs(X - val[i][0]) - abs(Y - val[i][1])), 0))
                    break;
            }
            if (i == n)
            {
                cout << X << " " << Y << " " << H << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        long dp[]=new long[n+1],M=1000000007;
        if(n<3) {System.out.print(0); return;}
        dp[0]=1;
        int i,j;
        for(i=1;i<=n;i++)
        for(j=3;j<=n;j++)
        if(i>=j)
        dp[i]=(dp[i]+dp[i-j])%M;
        System.out.print(dp[n]);
    }
}


Measured memory_bytes: 32644
#include<bits/stdc++.h> 
using namespace std;
char a[20];
int main()
{
	cin>>a;
	int su=0,i;
	for(i=0;i<strlen(a);i++)
	{
		su++;
		if(su==4)
		{
			cout<<a[i]<<' ';
			su++;
			continue;
		}
		cout<<a[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){

    int N,K,ans=1;
    cin>>N>>K;

    for(int i=1;i<=N;i++){
        if(ans<K){
            ans*=2;
        }else{
            ans+=K;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <fstream>
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;using std::swap;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::vector<int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}

namespace ndifix{
template<class T> void sort(T &v){std::sort(v.begin(),v.end());}
template<class T> void rsort(T &v){std::sort(v.rbegin(),v.rend());}
}
vector<int> par;
int findpar(int i){
  if(par[i]==i)return i;
  return findpar(par[i]);
}

int main(){
  int n;cin>>n;par.resize(n);
  vector<pair<int,int>> xy(n);for(int i=0;i<n;i++)cin>>xy[i].first>>xy[i].second;
  int ans=n;
  for(int i=0;i<n;i++){
  for(int j=0;j<n;j++){
    if(i==j)continue;
    int p,q;
    p=xy[j].first-xy[i].first;q=xy[j].second-xy[i].second;
    
    for(int i=0;i<n;i++)par[i]=i;
    par[j]=i;
    for(int k=0;k<n;k++){
    for(int l=0;l<n;l++){
      if(xy[k].first+p==xy[l].first && xy[k].second+q==xy[l].second)par[l]=k;
      if(xy[l].first+p==xy[k].first && xy[l].second+q==xy[k].second)par[k]=l;
    }}
    for(int k=0;k<n;k++)par[k]=findpar(k);
    set<int> buf;
    for(int k=0;k<n;k++)buf.insert(par[k]);
    ans = min(ans, int(buf.size()));
  }}
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	int w,h,n;
	cin >> w >> h >> n;
	int l=0,r=w,u=h,d=0;
	for(int i=0;i<n;i++)
	{
		int x,y,a;
		cin >> x >> y >> a;
		if(a==1)
		{
			l=max(l,x);
		}
		else if(a==2)
		{
			r=min(r,x);
		}
		else if(a==3)
		{
			d=max(d,y);
		}
		else if(a==4)
			u=min(u,y);
	}
	int ans=(r-l)*(u-d);
	if(ans<0 || r<l || u<d)
		cout << "0";
	else
		cout << (r-l)*(u-d);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (lint i = 0; i < lint(n); ++i)
#define Rep(i, n) for (lint i = lint(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
using DI = pair<double, int>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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;
}

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

lint n, k, cnt;
int main() {
	cin >> n >> k;
	for (lint b = k + 1; b <= n; ++b) {
		cnt += n / b * (b - k);
		cnt += max(0LL, n % b - k + 1);
	}
	if (k == 0) cnt -= n;
	cout << cnt << endl;
}

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

using namespace std;
using ll = long long;
using p = pair<ll,ll>;
#define rep(i,k) for(ll i = 0; i<(ll)k;i++)

int main()
{
    int a,b,c,n;
    cin>>a>>b>>c>>n;
    if(n <= a){
        cout<<n<<endl;
    }
    else if(n <= a+b){
        cout<<a<<endl;
    }
    else{
        cout<<a- (n-a-b)<<endl;
    }

    return 0;
}

Measured memory_bytes: 3640