akhauriyash/Code-Regression huggingface dataset:
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
typedef pair<int, int> pr;
typedef vector<int> VI;
typedef vector<pr> VP;
typedef vector<string> VS;
typedef vector<vector<int>> VV;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
const int INF = 1e9;
int fast_pow(int x, int y, int p);





void solve() {
	string s;cin>>s;
	reverse(ALL(s));
	int pw=1;
	int cur=0;
	vector<int> dp(2020,0);
	dp[0]=1;
	int ans=0;
	for(auto x:s){
		cur = (cur + pw * (x-'0'))%2019;
		ans+=dp[cur];
		dp[cur]++;
		pw=(pw*10)%2019;
	}
	cout<<ans;

}

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	IOS;
	int test = 1;
	// cin>>test;
	for (int i = 1; i <= test; i++) {
//        cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}
int fast_pow(int x, int y, int p) {
	int res = 1;
	x = x % p;
	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

Measured memory_bytes: 3752
import sys

lines = sys.stdin.readlines()

a, b, k = map(int, lines[0].split())

if a <= k:
    k = k - a
    a = 0
    if b <= k:
        k = k - b
        b = 0
    else:
        b = b - k
else:
    a = a - k

print(a, b)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k;
int a[100105];
int dp[100105];
int f(int x)
{ 
  if(x>=n)
    return 1e18;
  if(x==n-1)
    return 0;
  if(dp[x]!=-1)
    return dp[x];
  int ans=1e18;
  for(int i=1;i<=k;i++)
  ans=min(ans,f(x+i)+abs(a[x]-a[x+i]));
  return dp[x]=ans;
}
int32_t main()
{  
  cin>>n>>k;
  for(int i=0;i<n;i++)
    cin>>a[i];
  memset(dp,-1,sizeof(dp));
  cout<<f(0);
}

Measured memory_bytes: 6528
#include<iostream>
#include<cmath>

using namespace std;

int main(){

int a=0,b=0,c=0,t=0;
int x;

cin >> a >> b >> c;

for(x=a ; x<=b ; x++){

if(c%x==0){

t++;
}

}

cout << t << endl;

return 0;

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N;
  cin >> N;
  vector<pair<ll, ll>> AB(N);
  for (int i=0; i<N; i++) cin >> AB[i].first >> AB[i].second;
  sort(AB.begin(), AB.end());
  ll ans = AB[N-1].first+AB[N-1].second;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
N = int(input())
P = [None] + list(map(int, input().split()))

p_to_index = [None] * (N + 1)
for index, x in enumerate(P[1:], 1):
    p_to_index[x] = index


def BIT_add(i):
    while i <= N:
        tree[i] += 1
        i += i & (-i)

def BIT_sum(i):
    s = 0
    while i:
        s += tree[i]
        i -= i & (-i)
    return s

def BIT_search(x):
    i = 0
    s = 0
    step = 1 << (len(bin(N)[2:]) - 1)
    while step:
        if i + step <= N and s + tree[i + step] < x:
            i += step
            s += tree[i]
        step >>= 1
    return i + 1

tree = [0] * (N + 1)
ans = 0
for x in range(N, 0, -1):
    c = p_to_index[x]
    L = BIT_sum(c)
    R = N - x - L
    a = BIT_search(L - 1) if L >= 2 else 0
    b = BIT_search(L) if L >= 1 else 0
    d = BIT_search(L + 1) if R >= 1 else N + 1
    e = BIT_search(L + 2) if R >= 2 else N + 1
    BIT_add(c)
    tmp = 0
    if b != 0:
        tmp += (b - a) * (d - c)
    if d != 0:
        tmp += (e - d) * (c - b)
    ans += tmp * x

print (ans)

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    int n;
    cin >> n;
    FOR1(a, 9)
        FOR1(b, 9)
            if (a*b == n) {
                cout << "Yes" << endl;
                return 0;
            }
    cout << "No";

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = input().replace(" ", "")
q = input().replace(" ", "")
num_list = [0 for _ in range(n)]

def create(N, N_list, num, count):
    if count==num:
        return [N]
    result = []
    for i in range(1,num+1):
        if N_list[i-1]==0:
            next_N_list = N_list.copy()
            next_N_list[i-1] = 1
            result.extend(create(N*10+i, next_N_list, num, count+1))
    return result
dic = sorted(create(0, num_list, n, 0))
print(abs(dic.index(int(p))-dic.index(int(q))))

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());


signed main()
{
    gearup;
    string s; cin >> s;
    int res = 0;
    rep(i,s.size())if(s[i] == '2')res++;
    out(res);
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    ll n, m;
    cin >> n >> m;
    vector<vector<int>> r(n);
    vector<int> s(n);
    int a,b;
    rep(i,m){
        cin >>  a >> b;
        a--; b--;
        r[a].push_back(b);
        r[b].push_back(a);
    } 
    queue<int> que;
    que.push(0);
    int t;

    while(!que.empty()){
        t=que.front();
        que.pop();
        rep(i,r[t].size()){
            if(s[r[t][i]]==0){
                if(r[t][i]==0) continue;
                s[r[t][i]]=t+1;
                que.push(r[t][i]);
            }
        }
    }

    cout << "Yes" << endl;
    rep2(i,1,n) cout << s[i] << endl;
    
    //else cout << "No" << endl;
    //if(ans) cout << "YES" << endl;
    //else cout << "NO" << endl;
return 0;
}

Measured memory_bytes: 10220
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		sc.close();
		int ans = n;
		int cnt[] = new int[n];
		for(int i = 0; i < n; ++i) {
			if(i != 0)cnt[i] = cnt[i - 1];
			if(s.charAt(i) == 'W')++cnt[i];
		}
		for(int i = 0; i < n; ++i) {
			int tmp = i + 1 - cnt[i];
			int tmp2 = n - cnt[n - 1];
			tmp = tmp2 - tmp;
			int tmp3 = cnt[i];
			if(s.charAt(i) == 'W')--tmp3;
			tmp += tmp3;
			ans = Math.min(ans, tmp);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 29260
#include <iostream>
using namespace  std;
int a, b, p=0, q=0, r=0,ma=0;
int main() {
	cin >> a >> b;
	p = a + b;
	q = a - b;
	r = a * b;
	if (p < q)p = q;
	if (p < r)p = r;
	if (q < r)q = r;
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    long A[100];
    int i=0,sw=0,num;
    char s;

    while(scanf("%c",&s)!=EOF)
    {
        //printf("scan %c\n",s);
        if(s=='\n') break;
        switch(s)
        {
            case '+': 
                //printf("input +\n");
                i-=2;
                A[i]=A[i]+A[i+1];
                //printf("A[%d]=%d\n",i,A[i]);
                break;
        
            case '-':
                //printf("input -\n");
                i-=2;
                A[i]=A[i]-A[i+1];
                //printf("A[%d]=%d\n",i,A[i]);
                break;
        
            case '*':
                //printf("input *\n");
                i-=2;
                A[i]=A[i]*A[i+1];
                //printf("A[%d]=%d\n",i,A[i]);
                break;
            
            case '/':
                //printf("input /\n");
                i-=2;
                A[i]=A[i]/A[i+1];
                //printf("A[%d]=%d\n",i,A[i]);
                break;

            case ' ':
                //printf("i++\n");
                i++;
                sw=0;
                break;

            default:
                num=s-'0';
                //printf("input number %d\n",num);
                if(sw)
                {
                    A[i]=A[i]*10+num;
                }else
                {
                    A[i]=num;
                    sw=1;
                }
                //printf("A[%d]=%d\n",i,A[i]);
                break;
        }       
    }
    printf("%d\n",A[0]);

    return 0;

}


Measured memory_bytes: 1940
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << abs(a[0] - a[1]) + abs(a[1] - a[2]) << endl;
}

Measured memory_bytes: 256
from collections import Counter
n,a,b = int(input()),0,0
v = list(map(int,input().split()))
a,b = Counter(v[0::2]).most_common(2),Counter(v[1::2]).most_common(2)
if a[0][0] != b[0][0]:
    print(n-a[0][1]-b[0][1])
elif len(a) == 1 and len(b) == 1:
    print(int(n/2))
else:
    print(n-max(a[0][1]+b[1][1],a[1][1]+b[0][1]))


Measured memory_bytes: 15588
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i = a; i <= b; i++) {
        string s = to_string(i);
        if(s[0] == s[4] and s[1] == s[3]) ans += 1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
from math import factorial
c = 10**9 + 7
N,M = map(int, input().split())
if abs(N - M) == 0:
    print(2 * factorial(N) * factorial(M) % c)
elif abs(N - M) == 1:
    print(factorial(N) * factorial(M) % c)
else:
    print(0)

Measured memory_bytes: 5184
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <map>

using namespace std;

int main() {
	
	int N, T, A;
	int index;
	double min;
	int tmp;
	min = 99999;
	
	cin >> N >> T >> A;
	for (int i = 0; i < N; i++)
	{
		cin >> tmp;
		double x = (T - tmp * 0.006);
		double x1 = std::abs(x - A);
		if (min > x1)
		{
			min = x1;
			index = i;
		}
	}
	
	cout << index + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	int ans = 0;
	ans += (X * min(N, K));
	N -= K;
	if (N >= 0) {
		ans += (Y * (N));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

void dfs(string s,int size){
  if(s.size() == size-1){
    if(size == 1){
      print('a');
      return;
    }
    int last = 0;
    rep(i,size)chmax(last,s[i]-'a');
    rep(i,last+2){
      string t = s + (char)('a'+i);
      print(t);
    }
    return;
  }
  int last = 0;
  rep(i,size)chmax(last,s[i]-'a');
  if(s.size() == 0)last--;
  rep(i,last+2){
    string t = s + (char)('a'+i);
    dfs(t,size);
  }
}

// TODO: write
int main() {
  int n;cin>>n;
  string s;
  dfs(s,n);
  
  return 0;
}


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

int main(void){
	int d;
	int s;
	int i;

	while(cin >> d){
		s=0;
		for(i=0;i<600;i+=d){
			s+=(i*i*d);
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
H, W = map(int, input().split())
lines = []
linesT = []
count = 0

for i in range(H):
    line = input()
    if line.count('.') == W:
        H -= 1
        continue
    else:
        lines.append(line)

for i in range(W):
    string =''
    for j in range(H):
        string += lines[j][i]
    linesT.append(string)

lines = []
for i in range(W):
    if linesT[i].count('.') == H:
        W -= 1
        continue
    else:
        lines.append(linesT[i])

ans = []
for i in range(H):
    string = ''
    for j in range(W):
        string += lines[j][i]
    ans.append(string)

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 38768
from sys import exit

N,K=map(int,input().split())
b=[] #[[種類,美味しさ],...]

for _ in range(N):
    t,d=map(int,input().split())
    b.append([t,d])
b.sort(key=lambda x:-x[1])

f=[0]*(N+1)
x=0
point=0

for [t,d] in b[:K]:
    if f[t]==0: x+=1
    f[t]+=1
    point+=d
maxpoint=point+x*x

h=K-1
for [t,d] in b[K:]:
    if f[t]==0:
        f[t]=1
        x+=1
        point+=d
        for i in range(h,-2,-1):
            if i==-1:
                print(maxpoint)
                exit()
            t=b[i][0]
            d=b[i][1]
            if f[t]>1:
                f[t]-=1
                point-=d
                h=i-1
                break
        maxpoint=max(maxpoint,point+x*x)
print(maxpoint)

Measured memory_bytes: 24556
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
// #define int long long    // %d=>%lld
#define pb push_back
#define INF (1e9+7)
#define llINF 1e17
#define EPS 1e-9
#define pi acos(-1)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;


string s;

int ans_s = 0;
int ans = INF;



signed main(){


    cin >> s;


    for(int i = s.size()/2;i >= 0 ;i--){
        int x = 0;
        ans_s=0;
        for(int j = 0;j < s.size();j++){
            if(s[i] == s[j]){
                ans_s = max(ans_s, x);
                x = 0;
                continue;
            }
            x++;
            if(j == s.size()-1){
                ans_s = max(ans_s, x);
            }
        }
        ans=min(ans, ans_s);
    }


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

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def print_ans(W, H, x, y):
    """Test Case
    >>> print_ans(2, 3, 1, 2)
    3.000000 0
    >>> print_ans(2, 2, 1, 1)
    2.000000 1
    """
    area = W * H / 2
    whether = "1" if x * 2 == W and y *2 == H else "0"
    print("{} {}".format(str(area), whether)) 

if __name__ == '__main__':
    W, H, x, y = map(int, input().rstrip().split())
    print_ans(W, H, x, y)




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

typedef pair<long,long> data;

int main()
{
	long N,M,i,ans=0;
	cin >> N>>M;
	vector<data> Data(N);
	for(i=0;i<N;i++){
		cin >> Data[i].first >> Data[i].second;
	}
	sort(Data.begin(),Data.end());
	for(i=0;i<N;i++){
		if(Data[i].second<M){
			ans += Data[i].second * Data[i].first;
			M-=Data[i].second;
		}else {
			ans += Data[i].first * M;
			break;
		}
	}
	cout << ans;
	return 0;
}


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

# n!の素因数分解での素数pの指数
e = [0] * (n + 1)
for i in range(2, n + 1):
	tmp = i
	for j in range(2, i + 1):
		while tmp % j == 0:
			e[j] += 1
			tmp //= j

# e の要素のうち m-1 以上のものの個数
def num(m):
	return len(list(filter(lambda x: x>=m-1, e)))

print(num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) \
	+ num(5) * (num(5) - 1) * (num(3) - 2) // 2)

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

int main(){
	string str;
	cin >> str;
	transform(str.begin(), str.end(), str.begin(), ::tolower); //全部小文字に
	
	int count=0;
	while(1){
		string tmp;
		cin >> tmp;
		if(tmp=="END_OF_TEXT") break;
		transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
		if(str==tmp) count++;
	}
	cout << count << endl;
	return 0;
}



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

#define FOR(i,a) for(int i=0;i<a;i++)
#define INF 0x3f3f3f3f
using namespace std;

int main()
{
	//dp[a] represents minimum to get to a

	int dp[100001]; 
	int n,k; cin >> n>>k;
	int value[100001];
	FOR(i, n) {
		cin >> value[i];
	}
	dp[0] = 0;

	for(int i=1;i<n;i++){
		dp[i] = INF;
		for (int a = 1; a <= k;a++) {
			if (i >= a) {
				dp[i] = min(dp[i], dp[i - a] + abs(value[i] - value[i - a]));
			}
		}
	}
	cout << dp[n - 1] << "\n";
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>


int main(void) {
	int N, D;

	scanf("%d%d", &N, &D);

	int X[N][D];

	int i, j, k;

	for (i = 0;i < N;i++) {
		for (j = 0;j < D;j++) {
			scanf("%d", &X[i][j]);
		}
	}

	double sam;
	double dis;
	int count = 0;

	for (i = 0;i < N-1;i++) {
		for (j = i+1;j < N;j++) {
			sam = 0;
			for (k = 0;k < D;k++) {
				sam += (X[j][k] - X[i][k]) * (X[j][k] - X[i][k]);
			}
//			printf("%lf\n", sam);
			dis = sqrt(sam);
//			printf("%lf\n", dis);
			if (ceil(dis) == dis) {
				count++;
			}
		}
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc =new Scanner(System.in);
        int N = sc.nextInt();
        int[] H = new int[N];
        int preH = 0;
        int x=0;
        int y=0;
        for(int i=0;i<N;i++){
            if(i==0){
                preH = H[i];
            }else{
                preH=H[i-1];
            }
            H[i]=sc.nextInt();
            if(preH<H[i]){
                x=0;
            }
            else{
                x=x+1;
                preH = H[i];
                if(x>y){
                    y=x;
                }
            }
        }
        System.out.println(y);
        sc.close();

        
        }
    }


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

int judge(int &A, int &B, int &C, int &D){
  int Ans;
  
      for(int j = 1; j <= 2; j++){
        for(int k = 1; k <= 2; k++){
          for(int t = 1; t <= 2; t++){
            Ans = A + B * pow(-1, j) + C * pow(-1, k) + D * pow(-1, t);
            if(Ans == 7){
              B *= pow(-1, j);
              C *= pow(-1, k);
              D *= pow(-1, t);
              return 1;
            }
          }
        }
      }
  
}

int main(){
  int a, b, c, d, In;
  
  cin >> In;
  
  a = In / 1000;
  In %= 1000;
  b = In / 100;
  In %= 100;
  c = In / 10;
  d = In % 10;
  
  judge(a, b, c, d);
  
  cout << a << flush;
  
  if(b >= 0) cout << "+" << b << flush;
  else cout << b << flush;
  
  if(c >= 0) cout << "+" << c << flush;
  else cout << c << flush;
  
  if(d >= 0) cout << "+" << d << flush;
  else cout << d << flush;
  
  cout << "=7" << endl;
  
  return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

struct UnionFind {
    vector<int> par;

    //正の場合、親を表す
    //負の場合、根で数値は連結成分のサイズ
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) {
            return x;
        } else {
            return par[x] = root(par[x]); //経路圧縮
        }
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);

        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); //小さい方を大きい方にくっつけるため

        par[x] += par[y];
        par[y] = x;

        return true;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return -par[root(x)];
    }
};


int main() {

    int n, m; cin >> n >> m;

    vector<int> a(m);
    vector<int> b(m);
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
    }

    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    vector<ll> ans;

    ll t = (ll)n * ((ll)n - 1) / 2;
    ans.push_back(t);

    UnionFind tree(n);

    for (int i = 0; i < m-1; ++i) {
        ll a_size = (ll)tree.size(a[i]);
        ll b_size = (ll)tree.size(b[i]);

        tree.unite(a[i], b[i]);

        ll size = (ll)tree.size(a[i]);

        if (t > 0 && size > a_size && size > b_size) {
            t -= size * (size - 1) / 2 - (a_size) * (a_size - 1) / 2 - (b_size) * (b_size - 1) / 2;
        }

        if (t < 0) t = 0;

        ans.push_back(t);
    }

    reverse(ans.begin(), ans.end());

    for (ll i = 0; i < ans.size(); ++i) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3444
#include<stdio.h>
int fib(int, int *);
int main(){
  int i, n;
  int F[45];
  scanf("%d", &n);
  for(i = 0; i <= n; i++) F[i] = -1;
  printf("%d\n", fib(n, F));
  return 0;
}

int fib(int n, int *F){
  F[0] = 1;
  F[1] = 1;
  if(F[n] != -1) return F[n];
  F[n] =  fib(n-1, F)+fib(n-2, F);
  return F[n];
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<58;
const ll mod=1e9+7;

int main(){
  int i,j,k;
  int n;
  cin>>n;
  string s;
  cin>>s;
  VI v(n);
  for(i=0;i<2;i++){
    for(j=0;j<2;j++) {
      v[0]=i;
      v[1]=j;
      for(k=2;k<n;k++) {
        int cnt=v[k-1]+v[k-2];
        if(s[k-1]=='x') cnt++;
        if(cnt%2==0) v[k]=0;
        else v[k]=1;
      }
      int u1=v[0]+v[1]+v[n-1];
      int u2=v[0]+v[n-1]+v[n-2];
      if(s[0]=='x') u1++;
      if(s[n-1]=='x') u2++;
      if(u1%2==0&&u2%2==0){
        for(k=0;k<n;k++){
          cout<<((v[k]==0) ? "S" : "W"); 
        }
        cout<<endl;
        return 0;
      }
    } 
  }
  cout<<-1<<endl;
  return 0;
  
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(void){
    int W, H;
    char initial;
    cin >> W >> H >> initial;
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            //１行目と最終行
            if(i==0 || i==H-1){
                if(j==0 || j==W-1){
                    cout << '+';
                }
                else cout << '-';
            }
            
            //旗の真ん中
            else if(i == H/2 && j == W/2){
                cout << initial;
            }
            
            //「 | 」
            else if(j==0 || j==W-1){
                cout << '|';
            }
            
            //「 . 」
            else cout << '.';
        }
        cout << endl;
    }
    return 0;
}

/*
　縦と横をループで回します。
　どの位置に何を出力するか，場合分けしましょう。
*/



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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

template <typename T>
T Gcd(T a, T b) {
  if (b == 0) {
    return a;
  }
  return Gcd(b, a % b);
}

template <typename T>
std::map<T, int> Factorize(T x) {
  std::map<T, int> m;
  for (T i = 2; i * i <= x;) {
    if (x % i == 0) {
      m[i]++;
      x /= i;
    } else {
      ++i;
    }
  }
  if (x > 1) m[x]++;
  return m;
}

int main() {
  in(ll, a, b);
  out(Factorize(Gcd(a, b)).size() + 1);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
int main()
{
	char ss[200010] = {0};
	ll cc[26] = {0};
	scanf("%s",ss);
	ll l;
	l = strlen(ss);
	int t,t1;
	for(t=0;t<l;t++)
		cc[ss[t]-'a']++;
	ll s;
	s = l*(l-1)/2+1;
	for(t=0;t<26;t++)
	{
		s -= cc[t]*(cc[t]-1)/2;
	}
	printf("%lld\n",s);
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;

vector<long long> dijkstra(const Graph &g, int s) {
    vector<long long> dist(g.size(), INF);
    using Pi = pair<long long, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0; que.emplace(dist[s], s);
    while (!que.empty()) {
        long long cost; int u; tie(cost, u) = que.top(); que.pop();
        if (dist[u] < cost) continue;
        for (auto &e: g[u]) {
            int v; long long nc; tie(v, nc) = e;
            if (chmin(dist[v], dist[u] + nc)) que.emplace(dist[v], v);
        }
    }
    return dist;
}

int main() {
    int n, m; cin >> n >> m;
    int s, t; cin >> s >> t; s--, t--;
    Graph g1(n), g2(n);
    while (m--) {
        int u, v; cin >> u >> v; u--, v--;
        int a, b; cin >> a >> b;
        g1[u].emplace_back(v, a);
        g1[v].emplace_back(u, a);
        g2[u].emplace_back(v, b);
        g2[v].emplace_back(u, b);
    }
    auto dS = dijkstra(g1, s), dT = dijkstra(g2, t);
    vector<long long> res(n + 1);
    for (int i = 0; i < n; i++) res[i] = dS[i] + dT[i];
    res.back() = INF;
    for (int i = n - 1; i >= 0; i--) chmin(res[i], res[i + 1]);
    for (int i = 0; i < n; i++) cout << (long long)1e15 - res[i] << endl;
    return 0;
}

Measured memory_bytes: 19012
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int h,w;
  cin >> h >> w;

  vector<string> s(h);

  for(int i = 0; i < h; i++){
    string temp;
    cin >> temp;
    s[i] = temp;
  }

  for(int j = 0; j < h + 2; j++){
    if(j == 0 || j == h+1){
      for(int i = 0; i < w + 2; i++){
	cout << '#';
      }
      cout << endl;
    } else {
      for(int i = 0; i < w + 2; i++){
	if(i == 0 || i == w+1){
	  cout << '#';
	} else {
	  cout << s[j-1][i-1];
	}
      }
      cout << endl;
    }
  }
    

  return 0;
}

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

int main() {
    int n;
    long long x,d;
    cin >>n>>x>>d;
    if(d==0) {
        cout << (x == 0 ? 1 : n+ 1) << endl;
        return 0;
    } else if(d < 0) {
        x=x*(-1); d=d*(-1);
    }

    using pp = pair<long long, long long>;
    map<long long, vector<pp>> B;
    for(long long k=0; k<=n; ++k) {
        long long tl = (k * x - (x < 0 ? d : 0)) / d + k * (k - 1) / 2;
        long long tr = (k * x - (x < 0 ? d : 0)) / d + k * (2 * n - k - 1) / 2 + 1;
        B[(k * x % d + d) % d].emplace_back(tl, tr);
    }

    long long res = 0;
    for(auto i : B) {
        auto I = i.second;
        sort(begin(I), end(I));
        long long l = I[0].first, r = I[0].second;
        for(int k=1; k<I.size(); ++k) {
            long long tl = I[k].first, tr = I[k].second;
            if(tr < r) continue;
            else if(tl < r) r = tr;
            else {
                res += r - l;
                l = tl; r = tr;
            }
        }
        res += r - l;
    }
    cout << res << endl;
}


Measured memory_bytes: 22144
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var line = Console.ReadLine();
        var num_array = line.Split(' ').Select(s => int.Parse(s)).ToArray();
        var a = num_array[0];
        var b = num_array[1];
        
        Console.WriteLine(a/b+ " " + a%b + " " + string.Format("{0:f5}", (double)a/b));
    }
}



Measured memory_bytes: 16432
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	string s;
	cin >> n >> s;
	
	ll r = 0;
	for(int i = 0; i < n; ++i) {
		if( s[i] == 'R' ) r++;
	}
	
	ll ans = 0;
	for(int i = 0; i < r; ++i) {
		if( s[i] == 'W' ) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3764
a,b = map(int,input().split())
s = str(input())
t = list(s)
import sys
u = []
for i in range(10):
    u.append(str(i))
    
for i in range(a):
    if t[i] not in u:
        print('No')
        sys.exit()
if t[a] != '-':
    print('No')
    sys.exit()
    
for i in range(b):
    if t[a+i+1] not in u:
        print('No')
        sys.exit()
print('Yes')

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

int N;
const int N_MAX = 200000;
int A[N_MAX];

int main() {
	scanf("%d", &N);
	for(int i=0;i<N;i++) {
		scanf("%d", &A[i]);
		A[i] -= i;
	}
	std::sort(A, A+N);
	long long ans = 0;
	for(int i=0;2*i<N;i++) {
		ans += A[N-1-i] - A[i];
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
    int n; cin >> n;
    long long a, b; cin >> a >> b;
    vector<int> x(n);
    for (auto &xi: x) cin >> xi;
    long long ans = 0;
    for (int i = 0; i + 1 < n; i++) {
        ans += min(a * (x[i + 1] - x[i]), b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"

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

  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (auto& v : A)std::cin >> v;
  std::vector<int> l(N + 2, -1), r(N + 2, -1);
  l[1] = A[0];
  r[N] = A[N - 1];
  for (int i = 0; i < N; ++i)
    l[i + 1] = std::max(l[i], A[i]);
  for (int i = N - 1; i; --i)
    r[i + 1] = std::max(r[i + 2], A[i]);
  for (int i = 1; i <= N; ++i) {
    int ans = std::max(l[i - 1], r[i + 1]);
    std::cout << ans << "\n";
  }

}


Measured memory_bytes: 3968
#include "bits/stdc++.h"

using namespace std;

void Main() {
    long long A;
    string B;
    cin >> A >> B;
    
    long long B_integer = atoi(B.substr(0, 1).c_str());
    long long B_decimal = atoi(B.substr(2, 2).c_str());
    long long B_100 = B_integer * 100 + B_decimal;

    string B_100_str = "00" + to_string(A * B_100);
    string ans = B_100_str.substr(0, B_100_str.size() - 2);
    if (ans.size() >= 1 && ans[0] == '0') {
        ans = ans.substr(1, ans.size() - 1);
    }
    if (ans.size() >= 1 && ans[0] == '0') {
        ans = ans.substr(1, ans.size() - 1);
    }
    if (ans.size() == 0) {
        ans = "0";
    }
    cout << ans << endl;
}

//void Main() {
//    long long A;
//    double B;
//    cin >> A >> B;
//
//    long long ans = (long long)(A * B - 0.5);
//    cout << ans << endl;
//}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		vi ts(n+1),xs(n+1),ys(n+1);
		repi(i,1,n+1) cin>>ts[i]>>xs[i]>>ys[i];
		bool ok=true;
		rep(i,n){
			int dt=ts[i+1]-ts[i];
			int dx=abs(xs[i+1]-xs[i])+abs(ys[i+1]-ys[i]);
			ok&=dt>=dx&&(dt-dx)%2==0;
		}
		cout<<(ok?"Yes":"No")<<endl;
	}
}


Measured memory_bytes: 1408
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18
ll M=1000000007;
vector<ll> fac(1100001);
vector<ll> ifac(1100001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
int main(){
	ll X,Y;
	cin>>X>>Y;
	if(X>Y){
		ll tmp=X;
		X=Y;
		Y=tmp;
	}
	if((X+Y)%3!=0){
		cout<<"0";
		return 0;
	}
	if(X==0 && Y==0){
		cout<<"1";
		return 0;
	}
	if(X==0){
		cout<<"0";
		return 0;
	}
	if(Y>X*2){
		cout<<"0";
		return 0;
	}
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<1100000; i++){
        fac[i+1] = fac[i]*(i+1) % M;
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M;
    }
	cout<<comb((X+Y)/3,X-(X+Y)/3)%M;
	return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

ll dp[401][401];
ll INF = 1e18;
ll sum[401];

ll rec(int l, int r) {
  if (l == r) return dp[l][r] = 0;
  if (dp[l][r] != INF) return dp[l][r];
  ll res = INF;
  for (int i = l; i < r; ++i) {
    res = min(res, rec(l, i) + rec(i + 1, r) + sum[r] - sum[l - 1]);
  }
  return dp[l][r] = res;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  sum[0] = 0;
  REP(i, n) sum[i + 1] = sum[i] + a[i];
  REP(i, n + 1) REP(j, n + 1) dp[i][j] = INF;
  rec(1, n);
  cout << dp[1][n] << endl;
  return 0;
}

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

int main(){

    std::vector<int> a(3, 0);
    for (size_t i = 0; i < 3; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    auto result = unique(a.begin(), a.end());
    a.erase(result, a.end());
    cout << a.size() << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = 1;
		int x = sc.nextInt();

		do {
			if (n % 3 == 0) {
				System.out.print(" " + n);
			}else{
				int i = n;
				while (i != 0) {
					if ((i % 10) == 3) {
						System.out.print(" " + n);
						break;
					}
					i /= 10;
				}
			}
			n++;
		} while (n != x + 1);
		System.out.println();
	}
}

Measured memory_bytes: 28760
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

s = S()
ans = 0
temp = 0
for i in s:
    if i == 'R':
        temp += 1
    else:
        temp = 0
    ans = max(ans,temp)
print(ans)

Measured memory_bytes: 8984
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ll x;
    cin >> x;

    cout << ((x) ? 0 : 1) << endl;
    return 0;
}

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

using namespace std;

#define pb push_back
const long long mo=998244353;
const int maxi=1e6+2;
int a[maxi];
vector<int> v[maxi];
int n,k;
string s;
long long ans;
long long   bin[5003][5003];
long long  dp[5003][5003],sum[5003][5003];
int main()
{
   cin>>k>>n;

   for (int i=0;i<=5001;i++)
    bin[i][0]=1;

   for (int i=1;i<=5001;i++)
    for (int j=1;j<=i;j++)
     bin[i][j]=(1ll*bin[i-1][j]+bin[i-1][j-1])%mo;

   dp[0][0]=1;

   for (int i=0;i<=k;i++)
    sum[0][i]=1;


    for (int i=1;i<=k;i++)
        dp[0][i]=1;

   for (int i=1;i<=5001;i++){
    for (int j=1;j<=5001;j++)
     dp[i][j]=(dp[i][j-1]+ (2ll* sum[i-1][j-1]))%mo;

     for (int j=0;j<=k;j++)
        sum[i][j]=(1ll*sum[i-1][j]+dp[i][j])%mo;
   }

   for(int i=2;i<=2*k;i++)
   {
      int paran=0;
      int dupli=0;
      if (i%2==0) paran=1;

      for (int j=1;j<=k;j++)
        if (i-j>0 && i-j<=k) dupli++;

        dupli-=paran;
        int sami=k-dupli-paran;
        dupli/=2;

        long long ans=0;


        for (int j=0;j<=n;j++){
        if (sami>0)
            ans=(ans+(1ll*bin[n-j+sami-1][sami-1]*dp[j][dupli])%mo)%mo;
        else
            if (j==n)
           ans=(ans+dp[j][dupli])%mo;

         ans%=mo;


        }

   //   if (i==2) cout<<ans<<endl;

        if (paran)  //od n-1 biram, uzeo jedan paran
        {
            for (int j=0;j<=n-1;j++){
             if (sami>0)
               ans=(ans+(1ll*bin[n-j+sami-2][sami-1]*dp[j][dupli])%mo)%mo;
             else
                if (j==n-1)
              ans=(ans+dp[j][dupli])%mo;


         ans%=mo;
        }
        }

        ans%=mo;
        if (ans<0) ans+=mo;

       cout<<ans<<endl;
   }

  return 0;
}
//bicu tuzan ako ne budu dva constructive


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

int main() {
    int N, M; cin >> N >> M;
    map<int, set<int>> E;
    rep(i, M) {
        int a, b; cin >> a >> b;
        a--; b--;
        E[a].insert(b);
        E[b].insert(a);
    }
    vector<int> l;
    rep(i, N) l.push_back(i);
    int ans = 0;
    do {
        bool ok = true;
        rep(i, N - 1) {
            ok &= E[l[i]].count(l[i + 1]) > 0;
        }
        ans += ok;
    } while(next_permutation(l.begin() + 1, l.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 500001
 
int heap[MAX];
int size;
 
int left(int i){
  return 2 * i;
}
 
int right(int i){
  return 2 * i + 1;
}
 
int parent(int i){
  return i / 2;
}
 
void maxHeapify(int i){
  int l, r, n, largest;
 
  l = left(i);
  r = right(i);
 
  if( l < size && heap[l] > heap[i] ){
    largest = l;
  }
  else{
    largest = i;
  }
 
  if( r < size && heap[r] > heap[largest] ){
    largest = r;
  }
 
  if( largest != i ){
    n = heap[i];
    heap[i] = heap[largest];
    heap[largest] = n;
   
    maxHeapify(largest);
  }
}
 
void buildMaxHeap(void){
  int i;
 
  for( i = size /2; i > 0; i--){
    maxHeapify(i);
  } 
}
 
main(){
  int i;
 
  scanf("%d", &size);
 
  size = size + 1;
 
  for( i = 1; i < size; i++){
    scanf("%d", &heap[i]);
  }
 
  buildMaxHeap();
 
  for( i = 1; i < size; i++){    
    printf(" %d", heap[i]);
  }
  printf("\n");
  return 0; 
}

Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a[3];
  int k;
  for(int i=0;i<3;i++)
    {
      cin >> a[i];
    }

  cin >> k;

  sort(a , a + 3,greater<int>());

  long long sum =0;

  sum = a[0] * pow(2 , k);
  sum += a[1] + a[2];
  cout << sum  << endl;
  return 0;
    
    
}


Measured memory_bytes: 512
n = int(input())
t0 = list(map(int, input().split()))
m = int(input())
px = []
while True:
    try:
        px.append(list(map(int, input().split())))
    except:
        break;
import copy

for i in range(m):
    #shallow copy , deep copy の話
    t = []
    t = copy.copy(t0)
    t[px[i][0]-1] = px[i][1]
    print(sum(t))

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

int main(){
  int A,B,count=1;
  cin>>A>>B;
  int a=A;
  if(B==1){
    cout<<0<<endl;
    return 0;
  }
  else{
    while(A<B){
      A=A-1+a;
      count++;
    }
  }
  cout<<count<<endl;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int n = int.Parse(Console.ReadLine());

            int count = 0;

            while (count++ != n)
            {
                sb.AppendLine("Case " + count + ":");

                int input = int.Parse(Console.ReadLine());

                for (int i = 0; i < 10; i++)
                {
                    string temp = string.Format("{0:D8}", input * input);

                    input = int.Parse(temp.Substring(2, 4));

                    sb.AppendLine(input.ToString());
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9120
#include "bits/stdc++.h"
using namespace std;

int main(){
    int r,D,x0,x;
    cin >> r >> D >> x0;
    for(int i = 0; i<10; i++){
        x = r * x0 - D;
        cout << x << endl;
        x0 = x;
    }
    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S  = sc.next();
    char[]ss = S.toCharArray();
    int[]a = new int[S.length()];
    int[]z = new int[S.length()];
    
    for(int i=0; i<S.length(); i++) {
    	if(ss[i] == 'A') {
    		a[i]++;
    	}else if(ss[i] == 'Z'){
    		z[i]++;
    	}
    }
    int A = 0, Z = 0;
    for(int i=S.length()-1; i>=0; i--) {
    	if(a[i] == 1) {
    		A = i;
    	}
    }
    	for(int i=0; i<S.length(); i++) {
        	if(z[i] == 1) {
        		Z = i ;
        	}
    	}
        	System.out.println(Z-A+1);
    }
}


Measured memory_bytes: 42396