akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import Data.List

sumAdd :: [Int] -> [Int]
sumAdd x = x ++ [sum x]

solv :: [[Int]] -> [[Int]]
solv l = transpose . map sumAdd . transpose . map sumAdd $ l

showRes :: [[Int]] -> String
showRes [] = ""
showRes (x:xs) = (concat . intersperse " " . map show $ x) ++ "\n" ++ (showRes xs)

main = getLine >>=
       (\l -> return (map read . words $ l)) >>=
       (\(r:c:_) -> replicateM r getLine) >>=
       (\l -> return (map (map read . words) $ l :: [[Int]] )) >>=
       (\a -> return (solv a)) >>=
       putStr . showRes

Measured memory_bytes: 8124
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define soja(i,a,n) for(ll i=a;i<=n;i++)
#define ulta(i,n,a) for(ll i=n;i>=a;i--)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define in insert
#define ve vector<ll>
#define se set<ll>
#define ma map<ll,ll>
#define mp make_pair
#define pll vector<pair<ll,ll>>
#define ff first
#define ss second
const ll maxx=1e9+7;
ll n,m,k,sum,t;
int main()
{
  bool fg=0,mg=0;
  ll a[6];
  a[0]=0;
  fast;
cin>>a[1]>>a[2]>>a[3]>>a[4]>>a[5];
soja(i,1,5)
{
    if(a[i]==0)
        {cout<<i<<endl;
        break;}

}

    return 0;
}


Measured memory_bytes: 3600
using System;

namespace aoj3d
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string[] num = str.Split(' ');
            int a = int.Parse(num[0]);
            int b = int.Parse(num[1]);
            int c = int.Parse(num[2]);

            int cnt = 0;

            for (int i = a ; i <= b; i++)
            {
                if( c % i == 0)
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
            
        }
    }
}

Measured memory_bytes: 9112
MOD = 10 ** 9 + 7

def solve():
  N = int(input())
  S = [s == 'W' for s in input()] # W: True, B: False
  if S[0] or S[2 * N - 1]: return 0

  ans = 1
  cnt = 1
  d = True # L: True, R: False
  for i in range(1, N * 2):
    if S[i] == S[i - 1]: d = not d
    if d: cnt += 1
    else:
      ans = (ans * cnt) % MOD
      cnt -= 1

  for i in range(1, N + 1): ans = (ans * i) % MOD

  return ans if cnt == 0 else 0

print(solve())

Measured memory_bytes: 5096
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
L = get_ints
L.sort!

count = 0
[*0...N-1].combination(2) do |i, j|
  a = L[i]
  b = L[j]
  max = i > j ? i : j
  test = L.lower_bound(a + b)
  test = N - 1 if test.nil?
  count += test - max - 1
end

puts count


Measured memory_bytes: 14744
def is_prime(x: int) -> bool:
    """自然数nが素数であるかを判定する
    計算量: O(sqrt(N))
    """
    if x == 2:
        return True
    if x == 1 or x % 2 == 0:
        return False
    for k in range(3, int(x ** 0.5) + 1, 2):
        if x % k == 0:
            return False
    return True


x = int(input())
while True:
    if is_prime(x):
        print(x)
        exit()
    else:
        x += 1

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    ll H;
    cin >> H;

    ll ans = 0;
    ll index = 0;
    while (H > 0) {
        ans += pow(2, index);
        H /= 2;
        index++;
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int dp[n+1];
    fill(dp,dp+n,inf);
    rep(i,n){
        *lower_bound(dp,dp+n,a[i])=a[i];
    }
    cout<<lower_bound(dp,dp+n,inf)-dp<<endl;
}


Measured memory_bytes: 3656
N,K=map(int,input().split())
P=[0]+list(map(int,input().split()))

S=[0]*(N+1)
for i in range(1,N+1):
    S[i]=S[i-1]+P[i]

M=-1
for j in range(N-K+1):
    M=max(M,S[j+K]-S[j])
print((M+K)/2)


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

int main(){
	int a,b;
	char op;
	
	while(1){
		cin >> a >> op >> b;
		if(op == '?') break;

		if(op == '+') 
			cout << a + b << endl;
		else if(op == '-') 
			cout << a - b << endl;
		else if(op == '*') 
			cout << a * b << endl;
		else
			cout << a / b << endl;

	}

	return 0;

}

Measured memory_bytes: 3068
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp

int dp[105][100005];

int main() {
    int N, W; cin >> N >> W;
    int v[N], w[N];
    REP(i, N) {
        cin >> v[i] >> w[i];
    }
    REP(i, N) {
        REP(j, W+1) {
            if (w[i] > j) {
                dp[i+1][j] = dp[i][j];
            }
            else {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+ v[i]);
            }
        }
    }

    cout << dp[N][W] << "\n";

    return 0;
}



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

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

#define fr first
#define sc second
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)

ll MOD;

ll modpow(ll x,ll k){
	if(k==0)return 1;
	ll ret=modpow(x,k/2);
	ret*=ret; ret%=MOD;
	if(k%2==1){
		ret*=x;
		ret%=MOD;
	}
	return ret;
}

ll modpow2(ll x,ll k){
	if(k==0)return 1;
	ll ret=modpow2(x,k/2);
	ret*=ret; ret%=MOD-1;
	if(k%2==1){
		ret*=x;
		ret%=MOD-1;
	}
	return ret;
}

ll C[3005][3005];
ll D[3005][3005];
void init(){
	for(int i=0;i<3002;i++){
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++){
			C[i][j]=C[i-1][j-1]+C[i-1][j];
			if(C[i][j]>=MOD)C[i][j]-=MOD;
		}
	}
	for(int k=1;k<3002;k++){
		D[k][1]=D[k][k]=1;
		for(int t=2;t<=k-1;t++){
			D[k][t]=t*D[k-1][t]+D[k-1][t-1];
			D[k][t]%=MOD;
		}
	}
}

int main(){
	ll n;
	cin>>n>>MOD;
	init();
	
	ll ret=modpow(2,modpow2(2,n));
	for(int k=1;k<=n;k++){
		ll x=0;
		ll z=modpow(2,n-k);
		ll y=1;
		for(int t=1;t<=k;t++){
			ll y_=y*(z+t); y_%=MOD;
			x+=y_*D[k][t];
			x%=MOD;
			y*=z; y%=MOD;
		}
		x*=C[n][k];
		x%=MOD;
		x*=modpow(2,modpow2(2,n-k));
		x%=MOD;
		if(k%2==0)ret+=x;
		else ret+=MOD-x;
	}
	cout<<ret%MOD<<endl;
}



Measured memory_bytes: 139648
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))


for i in range(min(K, 42)):
    cum_sum = [0]*N
    for j in range(N):
        left = max(0, j - A[j])
        right = min(N-1, j+A[j])
        cum_sum[left] += 1
        if right + 1 < N:
            cum_sum[right+1] -= 1
    A[0] = cum_sum[0]
    for j in range(N-1):
        cum_sum[j+1] += cum_sum[j]
        A[j+1] = cum_sum[j+1]
    
        
for i in range(N):
    print(A[i], " ", end = "")
print()


Measured memory_bytes: 147040
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
   int A,B,C,D;
   cin>>A>>B>>C>>D;
   int E,F;
   E=A*B;
   F=C*D;
   if(E>F){
       cout<<E<<endl;
   }else{
       cout<<F<<endl;
   }
   
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  int c0 = 0, c1 = 0;
  for (auto s : S) {
    if (s == '0')
      c0++;
    else if (s == '1')
      c1++;
  }
  cout << 2 * min(c0, c1) << '\n';
  return 0;
}


Measured memory_bytes: 512
object Main extends App {
  import scala.io.StdIn._

  val n = readInt
  val (even, odd) = readLine.trim.split(' ').map(_.toInt).partition(_ % 2 == 0)
  println(
    if (odd.length % 2 == 1) (even.sum + odd.sum - odd.min) / 2
    else (even.sum + odd.sum) / 2
  )
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}



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

int main() {
	string S, T;
	cin >> S >> T;
	bool ok = true;
	map<char, char> ma, ima;
	for (int n = 0;n<S.size();++n) {
		char s = S[n];
		char t = T[n];
		if (ma.count(s)) {
			if (t != ma[s]) {
				ok = false;
			}
		}
		if (ima.count(t)) {
			if (s != ima[t]) {
				ok = false;
			}
		}
		ma[s] = t;
		ima[t] = s;
	}

	if (ok) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3928
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    a, op, b = input().split()
    a, b = int(a), int(b)

    if op == '?':
        break
    elif op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    else:
        print(a // b)

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

using i64 = int64_t;

i64 cumsum[100005] = {0};

int main(){
    i64 n, m;
    cin >> n >> m;
    for(int i=1;i<=n;++i){
        i64 a;
        cin >> a;
        cumsum[i] = cumsum[i-1] + a;
    }

    map<i64, i64> mp;
    for(int i=0;i<=n;++i){
        mp[cumsum[i]%m]++;
    }

    i64 ans = 0;
    for(auto e: mp){
        i64 num = e.second;
        ans += (num * (num-1)) / 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main () {
  long L, R;
  cin >> L >> R;
  long ans = 2020;
  for(long i = L; i <= L + 2018 && i <= R; i++){
    for(long j = i + 1; j <= L + 2018 && j <= R; j++){
      ans = min(ans,(i * j) % 2019);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);
const bool DEBUG = 0;

ll N;
ll totSum, steps, arr[100005], diff[100005];

int main()
{
	int i, j;

	sll(N);

	ll offset = (N * (N + 1)) / 2;

	fl(i,0,N)
	{
		sll(arr[i]);
		totSum += arr[i];
	}

	if(totSum % offset != 0)
	{
		printf("NO\n");	return 0;
	}

	steps = totSum / offset;
	totSum = 0;

	fl(i,0,N)
	{
		int y = (i + 1) % N;
		diff[i] = arr[y] - arr[i];
	}

	fl(i,0,N)
	{
		if(steps - diff[i] < 0 || (steps - diff[i]) % N != 0)
		{
			printf("NO\n");	return 0;
		}
		totSum += ((steps - diff[i]) / N);
	}

	if(totSum != steps)
	{
		printf("NO\n");	return 0;
	}

	printf("YES\n");


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 1792
#include<stdio.h>

int n;
int S[100000];

int binarySearch(int key);


int main(void){
	int q;
	int i,count=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){			//S入力
		scanf("%d",&S[i]);
		}
	scanf("%d",&q);
	int k;
	for(i=0;i<q;i++){			//T入力
		scanf("%d",&k);
		if(binarySearch(k)){
			count++;
			}
	}
	printf("%d\n",count);
	return 0;
}


int binarySearch(int key){
	int left = 0;
    int right = n;
    while (left < right){
       int mid = (left + right) / 2;
        if (S[mid] == key){
            return 1;
            }
        if(key>S[mid]){
            left = mid + 1;
            }
        else if(key<S[mid]) {
            right = mid;
            }
    }
	 return 0;
}
		


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

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

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

	int N, M;
	cin >> N >> M;

	vector<pair<long long, long long>> PYO;
	unordered_map<long long, vector<long long>> PYS;
	unordered_map<long long, unordered_map<long long, long long>> PYSO;

	int tP;
	long long tY;
	rep(i,M) {
		cin >> tP >> tY;
		PYO.push_back(make_pair(tP, tY));

		PYS[tP].push_back(tY);
	}

	long long c;
	for (auto& v : PYS) {
		sort(all(v.second));
		c = 1;
		for (auto& x : v.second) {
			PYSO[v.first][x] = c;
			c++;
		}
	}

	for (auto& v : PYO) {
		cout << setfill('0') << setw(12) << v.first * 1000000 + PYSO[v.first][v.second] << endl;
	}

	return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n;
    cin>>n;

    int c=0;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
        if(i%2==0 and a[i]%2)
        {
            c++;
        }
    }
    cout<<c;


    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }

int main(){
    int n,k; cin >> n >> k;
    vector<int> d(k);
    vector<bool> have(n, false);
    rep(i,k){
        cin >> d[i];
        rep(j,d[i]){
            int a; cin >> a; a--;
            have[a] = true;
        }
    }
    int ans = 0;
    rep(i,n) {
        if(!have[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long double a, b, c;
  cin >> a >> b >> c;
  if (2 * sqrt(a * b) < c - a - b) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))

cnt = 0
add = 0
for i in range(n):
    tmp = b_list[i] - a_list[i]
    if tmp >= 0:
        if a_list[i+1] <= tmp:
            cnt += (a_list[i] + a_list[i+1])
            a_list[i+1] = 0
        else:
            a_list[i+1] -= tmp
            cnt += b_list[i]
    else:
        cnt += b_list[i]


print(cnt)


Measured memory_bytes: 19116
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string S; cin >> S;
    if(S.size()<3) {cout << 0 << endl; return 0;}
    lint ans = 0, cnt = 0;
    S += 'B';
    int i = 0;
    while(i<S.size()-1){
        if(S[i]=='A') cnt++, i++;
        else{
            if(S[i]=='B' and S[i+1]=='C'){
                ans += cnt, i += 2;
            }
            else{
                cnt = 0, i++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
#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++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    int x,y;
    cin >> x >> y;
    
    for(int i=0;i<=x;i++){
        if(2*i+4*(x-i)==y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" <<endl;

    return 0;
}











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

using namespace std;

const int MaxN = 405;

int n;
int a[MaxN];
long long ps[MaxN], dp[MaxN][MaxN];

long long Cal(int L, int R)
{
    if (L == R)
    {
        return 0;
    }
    if (dp[L][R] != 0)
    {
        return dp[L][R];
    }
    dp[L][R] = 1e18;
    for (int i = L; i < R; i++)
    {
        dp[L][R] = min(dp[L][R], Cal(L, i) + Cal(i + 1, R));
    }
    dp[L][R] += ps[R] - ps[L - 1];
    return dp[L][R];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        ps[i] = ps[i - 1] + a[i];
    }
    cout << Cal(1, n);
    return 0;
}

Measured memory_bytes: 4904
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string s;
    set<char> st;
    cin >> s;
    char tmp;
    REP(i, s.size()) {
        if (st.find(s[i]) == st.end()) {
            st.insert(s[i]);
        } else {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

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


int main(){
	
	int n;
	scanf("%d", &n);
	long long int total = 0;
	for(int i = 1; i<=n ;i++){
		if(i%3!=0 && i%5!=0 && i%15!=0){
			total+=i;
		}
	}
	printf("%lld", total);
}

Measured memory_bytes: 3828
import java.util.Scanner;

class Main {

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        for (int n = scan.nextInt(); n != 0; n = scan.nextInt()) {
            int t[] = new int[n];

            for (int i = 0; i < n; i++) {
                t[i] = scan.nextInt();
            }
            int b = -1000000;

            for (int l = 0; l < n; l++) {
                int g = 0;
                for (int r = l; r < n; r++) {
                    g += t[r];
                    if (g > b) {
                        b = g;
                    }
                }
            }
            System.out.println(b);
        }
    }
}



Measured memory_bytes: 37432
#include <stdio.h>
 
int main(void)
{
    unsigned short a[4], b[4], hit, blow, i, j;
 
    while(scanf("%u%u%u%u%u%u%u%u",
        &a[0], &a[1], &a[2], &a[3],
        &b[0], &b[1], &b[2], &b[3]) != EOF){
            hit = 0;
            blow = 0;
            for(i=0; i<4; i++){
                if(a[i] == b[i]){ hit++; }
                for(j=0; j<4; j++){
                    if(a[i] == b[j]){ blow++; }
                }
            }
            printf("%d %d\n", hit, blow-hit);
    }
    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,l;
  cin >> n >> l;
  if(l <= 0 && 0 <= l + n - 1){
    ANS((2*l+n-1) * n / 2);
  }else if(l > 0){
    ANS((l+1+l+n-1) * (n-1) / 2);
  }else{
    ANS((l+l+n-2) * (n-1) / 2);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

using graph = vector<vector<int>>;

struct circle {
    int s;
    vector<int> next;

    vector<int> get_v() const {
        vector<int> v_s;

        int v = s;
        do {
            v_s.push_back(v);
            assert(next[v] >= 0);
            v = next[v];
        } while (v != s);

        return v_s;
    }
};

pair<bool, int> dfs(const graph& g, vector<int>& next, vector<bool>& vis, int v) {
    vis[v] = true;

    for (int u : g[v]) {
        next[v] = u;
        if (vis[u]) {
            return {true, u}; 
        } else {
            auto res = dfs(g, next, vis, u);
            if (res.first) {
                return res;
            }
        }
    }

    vis[v] = false;

    return {false, -1};
}

circle get_circle(const graph& g) {
    const int n = g.size();

    REP(i, n) {
        vector<int> next(n, -1);
        vector<bool> vis(n, false);

        stack<int> st;
        st.push(i);
    
        auto res = dfs(g, next, vis, i);

        if (res.first) {
            return {res.second, next};
        }
    }

    return {-1, vector<int>()};
}

circle simplify(const graph& g, const circle& c) {
    const int n = g.size();
    vector<bool> in(n, false), used(n, false);

    for (int v : c.get_v()) in[v] = true;
    
    circle nc;
    nc.next = vector<int>(n, -1);

    for (int v = c.s;; ) {
        if (used[v]) {
            nc.s = v;
            return nc;
        } else {
            used[v] = true;
        }
        
        bool update = false;
        for (int u : g[v]) {
            if (in[u] && c.next[v] != u) {
                nc.next[v] = u;
                v = u;
                update = true;
                break;
            }
        }
        
        if (!update) {
            nc.next[v] = c.next[v];
            v = c.next[v];
        }
    }
}

int main() {
    int n, m; cin >> n >> m;
    graph g(n);

    REP(i, m) {
        int a, b; cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
    }

    auto c = get_circle(g);

    if (c.s == -1) {
        cout << -1 << endl;
        return 0;
    }

    auto nc = simplify(g, c);
    while (c.get_v() != nc.get_v()) {
        c = nc;
        nc = simplify(g, c);
    }
    
    auto v_s = nc.get_v();

    cout << v_s.size() << endl;
    for (int v : v_s) cout << v + 1 << endl;
    
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 00) {
				break;
			}
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}

}



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

void dfs(int v, int prev, int color, vector<int> &used, vector<vector<int>> &g, bool &can) {
        used[v] = color;
        for (auto u : g[v]) if (u != prev) {
                if (used[u] == -1) dfs(u, v, 1 - color, used, g, can);
                else if (used[u] != 1 - color) can = true;
        }
}

int main() {
        int n, m;
        cin >> n >> m;
        vector<vector<int>> g(n);
        for (int i = 0; i < m; i ++) {
                int a, b;
                cin >> a >> b;
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        vector<int> used(n, -1);
        bool can = false;
        dfs(0, -1, 0, used, g, can);
        if (can) {
                long long ans = (long long) n * (n - 1) / 2;
                cout << ans - m << endl;
        } else {
                int black = 0;
                for (int i = 0; i < n; i ++) black += used[i];
                long long ans = (long long) black * (n - black);
                cout << ans - m << endl;
        }
        return 0;
}


Measured memory_bytes: 7424
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


class union_find {
public:
	vector<int> dat;
	union_find(int n) {
		dat.assign(n, -1);
	}
	
	bool unite(int a, int b) {
		int da = find(a);
		int db = find(b);
		if (da != db){
			if (dat[da] > dat[db]) swap(da, db);
			dat[da] += dat[db];
			dat[db] = da;
		}
		return (da != db);
	}
	bool check(int a, int b) {
		return (find(a) == find(b));
	}
	int find(int a) {
		return ((dat[a] < 0) ? a : (dat[a] = find(dat[a])));
	}
	int size(int a) {
		return -dat[find(a)];
	}
};

int main(){
	for (int h, w, c; cin >> h >> w >> c, (h | w | c) != 0; ) {
		vector<vi> m(h, vi(w));
		rep(i, h) rep(j, w) cin >> m[i][j];
		int a[5];
		union_find uf(h * w);
		rep(i, h) rep(j, w) {
			if (j > 0) if (m[i][j] == m[i][j - 1]) uf.unite(i * w + j, i * w + j - 1);
			if (i > 0) if (m[i][j] == m[i - 1][j]) uf.unite(i * w + j, (i - 1) * w + j);
		}
		int ans = 0;
		for (a[0] = 1; a[0] <= 6; a[0]++) {
			for (a[1] = 1; a[1] <= 6; a[1]++) {
				for (a[2] = 1; a[2] <= 6; a[2]++) {
					for (a[3] = 1; a[3] <= 6; a[3]++) {
						a[4] = c;
						union_find tuf = uf;
						rep(k, 5) rep(i, h) rep(j, w) {
							if (j > 0) {
								if (tuf.check(0, i * w + j)) if (a[k] == m[i][j - 1]) tuf.unite(i * w + j, i * w + j - 1);
								if (tuf.check(0, i * w + j - 1)) if (a[k] == m[i][j]) tuf.unite(i * w + j - 1, i * w + j);
							}
							if (i > 0) {
								if (tuf.check(0, i * w + j)) if (a[k] == m[i - 1][j]) tuf.unite(i * w + j, (i - 1) * w + j);
								if (tuf.check(0, (i - 1) * w + j)) if (a[k] == m[i][j]) tuf.unite((i - 1) * w + j, i * w + j);
							}
						}
						ans = max(ans, tuf.size(0));
					}
				}
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 912
n, l = map(int, input().split())
dic = []
all_sum = sum([j + l -1 for j in range(1, n+1)])
for i in range(1, n+1):
  item = [j + l -1 for j in range(1, n+1) if j != i]
  dic.append(sum(item))
dist = abs(all_sum - dic[0])
ans = dic[0]
for j in dic:
  tmp = abs(all_sum - j)
  if tmp < dist:
    ans = j
    dist = tmp
print(ans)

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

using namespace std;

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

  vector<int> v(n);
  for(int i=0; i<n; i++) cin >> v[i];

  sort(v.begin(), v.end());

  int fir = n/2-1;
  int sec = n/2;
  int ans = v[sec]-v[fir];

  cout << ans;
}

Measured memory_bytes: 640
d = str(input())
y = int(d[0:4])
m = int(d[5:7])
d = int(d[8:])
if y <= 2018:
    print("Heisei")
    exit()
else:
    if y == 2019 and m <= 4 and d <= 30:
        print("Heisei")
        exit()
print("TBD")


Measured memory_bytes: 2940
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int x = int.Parse(input[1]);
        int t = int.Parse(input[2]);

        Console.WriteLine(((n / x) + (n % x == 0 ? 0 : 1)) * t);
    }
}

Measured memory_bytes: 27188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    if(a%b==0) return b;
    else return gcd(b,a%b);
}

int main()
{
   ll a,b,c;
   scanf("%lld%lld",&a,&b);
   c=gcd(a,b);
   a=c;

   ll ans=0;
   for(long long i=2;i*i<=a;i++)
   {
       if(c%i==0)
       {ans++;
        c/=i;
        while(c%i==0)
            c/=i;
       }
       if(c==1) break;

   }
   if(c!=1) ans+=1;
    ans+=1;
    printf("%lld",ans);
    return 0;

}


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


int main()
{
    // 整数の入力
    long long  N,continue_count,last_color,current_color,total_change;
    last_color = -1;
    continue_count = 0;
    total_change = 0;
    cin >> N;
    for (int i=0;i< N;i++){
        cin >> current_color;
        if (current_color == last_color){
            continue_count++;
        }else{
            total_change += continue_count/2;
            continue_count = 1;
        }
        last_color = current_color;
    }
    total_change += continue_count/2;
    cout << total_change << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
 
int main()
{
    ios::sync_with_stdio(false);
    int N, r, i, min=INT_MAX, max=INT_MIN;
     
    cin >> N;
    rep(i,N) {
        cin >> r;
        if(r-min > max) max = r-min;
        if(r < min) min = r;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 1196
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int a, b, n;
  while (cin >> a >> b >> n) {
    a %= b;
    int s = 0;
    rep(i, n) {
      a *= 10;
      s += a / b % 10;
      a %= b;
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
const long long INF = 1LL << 60;
// map<int,int> mp;

int main() {
  int A, B;
  cin >> A >> B;
  cout << A*B << endl;
}

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

using namespace std;

bool check(char ch) {
    string s = "ATCG";
    return (s.find(ch) != -1);
}

int main() {
    string s;
    cin >> s;
    s = '6' + s + '6';
    int pre_pos, ans = 0;
    for (int i = 1; i < s.size(); i++) {
        if(check(s[i - 1]) && !check(s[i])) {
            ans = max(ans, i - pre_pos);
        }
        if(check(s[i]) && !check(s[i - 1])) {
            pre_pos = i;
        }
    }
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
    while(1){
        int n,i,cnt=0,sw=1,sosuu[100000],t;
        if(scanf("%d",&n)==EOF) break;
        if(n<=1){
            cnt=0;
        }else{
            sosuu[cnt]=2;
            cnt++;
            for(i=3;i<=n;i+=2){
                sw=1;
                for(t=0;t<cnt&&sosuu[t]*sosuu[t]<=i;t++){
                    if(i%sosuu[t]==0){
                        sw=0;
                        break;
                    }
                }
                if(sw==1){
                    sosuu[cnt]=i;
                    cnt++;
                }
            }
            
            
        }
        printf("%d\n",cnt);
        
    }
    return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n,m;cin>>n>>m;
    VI c(n);
    REP(i,m){
        int a,b;cin>>a>>b;
        a--;
        b--;
        c[a]++;
        c[b]++;
    }
    REP(i,n){
        if(c[i]%2!=0){
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fast ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 1e5 + 5;

typedef vector<int>vi;
typedef pair<double,double>ii; 
typedef pair<int,ii>iii; 
typedef pair<int,string>is;
int vis[N],arr[N];
void llenar(int x){
  for(int i=0 ; i<x ; i++)cin >> arr[i];
}
void imprimir(int x){
  for(int i=0 ; i<x ; i++)cout << arr[i] << ' ';
  cout << endl;
}
ll bs(ll x,ll n){
  ll l=0, r=1000, m;
  while(r - l > 1){
    m = (r + l) / 2;    
    if(m*x>=(m+x)*n)r = m;
    else l = m;
  }
  return r;
}
int f(string s){
  int n = s.size();
  for(int i=0 ; i<n/2 ; i++)if(s[i]!=s[n-1-i])return 0;
  return 1;
}
int main() {
  // ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
  ll n,a,b;
  while(cin >> n >> a >> b)
  {
    if(a > b)swap(a,b);
    ll ans = (b - a) % 2;
    if(ans>0){
      // ans = min(b-1,n-a) << endl;
      ll op1 = a + ((b - a)/2);
      ll op2 = (n-b+1) + ((b - a)/ 2);
      cout << min(op1,op2) << endl;
    }else cout << (b - a) / 2 << endl;   
  }
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int W = sc.nextInt();

		int[] v = new int[N];
		int[] w = new int[N];

		for (int i = 0; i < N; i++) {
			v[i] = sc.nextInt();
			w[i] = sc.nextInt();
		}

		sc.close();

		int[][] dp = new int[N + 1][W + 1]; // dp[i][weight] i-1まででweightになるように選んだときの最大のv

		for (int i = 0; i < N; i++) {
			for (int weight = 0; weight <= W; weight++) {
				dp[i + 1][weight] = Math.max(dp[i + 1][weight], dp[i][weight]);

				if(weight+w[i] <= W) {
					dp[i][weight+w[i]] = Math.max(dp[i][weight+w[i]], dp[i][weight] + v[i]);
				}
			}
		}

		out.println(dp[N][W]);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}



Measured memory_bytes: 31180
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
using LL = long long;


int main() {
	string s;
	while (cin >> s) {
		if (s == "-") break;
		int m;
		cin >> m;
		int h;
		queue<char> q;
		for (auto & e : s) {
			q.push(e);
		}
		for (int i = 0; i < m; i++) {
			cin >> h;
			for (int j = 0; j < h; j++) {
				char c = q.front(); q.pop();
				q.push(c);
			}

		}
		while (!q.empty()) {
			cout << q.front();
			q.pop();
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

const int N = 6e6;

vi fac(N), ifac(N);

int ncr(int n, int k){
	if(k > n || k < 0)
		return 0;
	return mul(fac[n], mul(ifac[k], ifac[n - k]));
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	fac[0] = ifac[0] = 1;
	for(int i = 1; i < N; i++)
		fac[i] = mul(i, fac[i - 1]), ifac[i] = inv(fac[i]);
	int k;
	cin >> k;
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	for(int i = 0; i <= k; i++)
		ans = add(ans, mul(power(26, i), mul(power(25, k - i), ncr(k - i + n - 1, n - 1))));
	cout << ans << endl;
	
}

Measured memory_bytes: 51144
#include<stdio.h>

int n, m;

typedef struct {
	int place;
	int vote;
} ANK;

int main(void)
{
	ANK ank[100];
	ANK tmp;
	int i, j;
	int check;
	
	m = 100;
	
	while ( 1 ) {
		
		for( i=0; i<m; i++ ) {
			ank[i].place = i + 1;
			ank[i].vote = 0;
		}
		
		scanf( "%d %d", &n, &m );
		if ( n == 0 ) break;
		
		while ( n-- ) {
			for ( i=0; i<m; i++ ) {
				scanf( " %d", &check );
				if ( check == 1 ) ank[i].vote++;
			}
		}
		
		for ( i=0; i<m; i++ ) {
			for ( j=m; j>i; j-- ) {
				if ( ank[j-1].vote < ank[j].vote ) {
					tmp = ank[j];
					ank[j] = ank[j-1];
					ank[j-1] = tmp;
				}
			}
		}
		
		for ( i=0; i<m; i++ ) {
			printf( "%d", ank[i].place );
			if ( i == m-1 ) break;
			putchar( ' ' );
		}
		
		putchar( '\n' );
		
		for ( i=0; i<m; i++ ) {
			ank[i].place = i+1;
			ank[i].vote = 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  string s;  
  cin>>s;
  if (s=="SUN") cout << 7 << endl;
  else if(s=="MON") cout << 6 << endl;
  else if(s=="TUE") cout << 5 << endl;
  else if(s=="WED") cout << 4 << endl;
  else if(s=="THU") cout << 3 << endl;
  else if(s=="FRI") cout << 2 << endl;
  else if(s=="SAT") cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
N,W=map(int,input().split())
v=[0]*N
w=[0]*N
for i in range(N):
    v[i],w[i]=map(int,input().split())

V=max(v)*N
dp=[-1]*(V+1)
dp[0]=0

for i in range(N):
    for j in range(V+1):
        if dp[V-j]!=-1 and -j+v[i]<=0:
            if dp[V-j+v[i]]==-1:
                dp[V-j+v[i]]=dp[V-j]+w[i]
            else:
                dp[V-j+v[i]]=min(dp[V-j+v[i]],dp[V-j]+w[i])

for i in range(V+1):
    if dp[V-i]!=-1 and dp[V-i]<=W:
        print(V-i)
        break


Measured memory_bytes: 5668
import java.io.*;
import java.util.*;
public class Main implements Runnable{
    
    private void solve()throws IOException{
        String s=nextToken();
        String t=nextToken();
        int a=nextInt();
        int b=nextInt();
        String u=nextToken();
        if(u.equals(s))
            a--;
        else
            b--;
        out.println(a+" "+b);
    }

     
    ///////////////////////////////////////////////////////////

    final long mod=(long)(1e9+7);
    final int inf=(int)(1e9+1);
    final int maxn=(int)(1e6);
    final long lim=(long)(1e18);

    public void run(){
        try{
            br=new BufferedReader(new InputStreamReader(System.in));
            st=null;
            out=new PrintWriter(System.out);

            solve();

            // int t=nextInt();
            // for(int i=1;i<=t;i++){
            //     // out.print("Case #"+i+": ");
            //     solve();
            // }

            br.close();
            out.close();
        }catch(Exception e){
            e.printStackTrace();
            System.exit(1);
        }
    }
    public static void main(String args[])throws IOException{
        new Main().run();
    } 
    int max(int ... a){
        int ret=a[0];
        for(int i=1;i<a.length;i++)
        ret=Math.max(ret,a[i]);
        return ret;
    }
    int min(int ... a){
        int ret=a[0];
        for(int i=1;i<a.length;i++)
        ret=Math.min(ret,a[i]);
        return ret;
    }
    void debug(Object ... a){
        System.out.print("> ");
        for(int i=0;i<a.length;i++)
        System.out.print(a[i]+" ");
        System.out.println();
    }
    void debug(int a[]){debuga(Arrays.stream(a).boxed().toArray());}
    void debug(long a[]){debuga(Arrays.stream(a).boxed().toArray());}
    void debuga(Object a[]){
        System.out.print("> ");
        for(int i=0;i<a.length;i++)
        System.out.print(a[i]+" ");
        System.out.println();
    }
    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;
    String nextToken()throws IOException{
        while(st==null || !st.hasMoreTokens())
        st=new StringTokenizer(br.readLine());
        return st.nextToken();
    }
    String nextLine()throws IOException{
        return br.readLine();
    }
    int nextInt()throws IOException{
        return Integer.parseInt(nextToken());
    }
    long nextLong()throws IOException{
        return Long.parseLong(nextToken());
    }
    double nextDouble()throws IOException{
        return Double.parseDouble(nextToken());
    }
}

Measured memory_bytes: 21076