akhauriyash/Code-Regression huggingface dataset:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    H, W, K = iim()
    S = [input() for i in range(H)]
    C = "1"

    H1, W1 = H+1, W+1
    S1 = [[0] * (W1) for i in range(H1)]
    ans = 0

    for i in range(1, H1):
        for j in range(1, W1):
            S1[i][j] = S1[i-1][j] + S1[i][j-1] - S1[i-1][j-1] + (1 if S[i-1][j-1] == C else 0)

    #for s1 in S1: print(s1)
    if S1[-1][-1] < K:
        print(0)
        return

    inf = H+W
    ans = inf
    ii = [0] + [1<<i for i in range(H)]
    cnt = 0
    H2 = 1<<H
    for i in range(H2>>1, H2):
        i0 = j0 = 0
        jx = W
        cnt = bin(i).count("1") - 1
        ng = False
        while j0 < W:
            i0 = 0
            for i1 in range(1, H1):
                k = ii[i1]
                if i & k:
                    for j1 in range(j0+1, W1):
                        cx = S1[i1][j1] - S1[i1][j0] - S1[i0][j1] + S1[i0][j0]
                        if cx > K:
                            j1 -= 1
                            break
                    break

            if j1 == j0:
                ng = True
                break


            i0, jx = i1, j1
            for i1 in range(i1, H1):
                k = ii[i1]
                if i & k:
                    for j1 in range(jx, j0, -1):
                        cx = S1[i1][j1] - S1[i1][j0] - S1[i0][j1] + S1[i0][j0]
                        if cx <= K:
                            jx = j1
                            break
                    else:
                        ng = True
                        break
                    i0 = i1
            if ng:
                break
            j0 = jx
            cnt += 1

            if ans <= cnt:
                ng = True
                break

        if not ng:
            ans = cnt
    print(ans-1)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3436
def share_candies(a_candybag, b_candybag, c_candybag):

    sum_of_candy_list = [a_candybag, b_candybag, c_candybag]
    most_candies = sorted(sum_of_candy_list, reverse=True)[0]
    sum_of_candies = a_candybag + b_candybag + c_candybag
    if most_candies == sum_of_candies - most_candies:
        return 'Yes'
    else:
        return 'No'


if __name__ == '__main__':
    a, b, c = map(int, input().split())
    print(share_candies(a, b, c))


Measured memory_bytes: 2940
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

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

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t) fill_v(e, v);
}

template <typename T, typename V>
inline void chmin(T &a, V b) {
  if (a > b) a = b;
}
template <typename T, typename V>
inline void chmax(T &a, V b) {
  if (a < b) a = b;
}

} // namespace null_null

#include <algorithm>
#include <iostream>
#include <map>
#include <utility>

namespace null_null {

void main_() {
  i32 N, Q;
  std::cin >> N >> Q;

  while (Q--) {
    i32 v, w;
    std::cin >> v >> w;

    if (N == 1) {
      std::cout << std::min(v, w) << std::endl;
      continue;
    }

    std::map<i32, i32> mp;

    if (v > w) {
      std::swap(v, w);
    }

    while (v != 1) {
      mp[v] = 1;
      v = (v + N - 2) / N;
    }

    while (true) {
      if (mp[w]) {
        std::cout << w << std::endl;
        break;
      } else if (w == 1) {
        std::cout << 1 << std::endl;
        break;
      }
      w = (w + N - 2) / N;
    }
  }
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


Measured memory_bytes: 1280
#include<cstdio>
int n,a[2][105],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[0][i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[1][i]);
	for(int i=1;i<=n;i++)
	{
		int sum=0;
		bool ml=0;
		for(int j=1;j<=n;j++)
		{
			sum+=a[ml][j];
			if(i==j)
			{
				ml=1;
				sum+=a[1][j];
			}
		}
		ans=ans>sum?ans:sum;
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int h,w,m;
  cin >> h >> w >> m;
  vector<ll> c_y(h,0);
  vector<ll> c_x(w,0);
  set<P> st;
  rep(i,m){
    int y,x;cin >> y >> x;
    y--;x--;
    c_y[y]++;
    c_x[x]++;
    st.insert(make_pair(y,x));
  }
  vector<int> can;
  int mx = *max_element(ALL(c_y));
  rep(i,h){
    if(c_y[i] == mx)can.push_back(i);
  }
  int MX = *max_element(ALL(c_x));
  rep(i,w){
    if(c_x[i] != MX)continue;
    bool is = false;
    for(auto au : can){
      if(st.count(make_pair(au,i)) == 0)is = true;
    }
    if(is){
      cout << mx+MX << "\n";
      return 0;
    }
  }
  cout << mx+MX-1 << "\n";
  
  

  return 0;
}

Measured memory_bytes: 24060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#include <bitset>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <assert.h>
using namespace std;
#define e exp(1.0)
typedef long long ll;
#define MAXN 2005
#define mod 998244353
#define INF 0x3f3f3f3f3f3f3f
#define fe(i,st,en) for(i = (st);i <= (en);++i)
#define fne(i,st,en) for(i = (st);i < (en);++i)
#define ri register int
#define db double
int a[15][15], c[15], p[15];
int main() {
	int n, m;
	cin >> n >> m;
	ri i,j,k;
	fe(i, 1, m) {
		cin >> c[i];
		fe(j, 1, c[i])cin >> a[i][j], a[i][j]--;
	}
	fe(i, 1, m) cin >> p[i];
	int ans = 0;
	fne(i, 0, 1<<n) {
		bool flag = true;
		fe(j, 1, m) {
			int sum = 0;
			fe(k, 1, c[j]) {
				if (i & (1 << a[j][k])) {
					sum++;
				}
			}
			if (sum % 2 != p[j]) {
				flag = false;
				break;
			}
		}
		if (flag) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#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()

int main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < 2 * n; ++i) {
    if (i % 2 == 0) {
      cout << s[i / 2];
    } else {
      cout << t[i / 2];
    }
  }
  cout << "\n";
  return 0;
}

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

int main()
{
    int x, y;
    cin >> x >> y;

    int asimax;
    int asimin;
    string ans = "No";

    if (y % 2 != 0)
    {
        ans = "No";
        cout << ans << endl;
        return 0;
    }
    else
    {
        asimax = 4 * x;
        asimin = 2 * x;
        if (asimin <= y && y <= asimax)
        {
            ans = "Yes";
        }
        else
        {
            ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;

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

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

ll n,P;
cin >> n >> P;

map<ll,ll> mp = prime_factor(P);
ll ans = 1;
for(auto p : mp) ans *= pow(p.first,p.second / n);
cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, W;
main(){
	while(cin >> n >> W){
		vi w(n+1, INF);
		REP(i, n)cin >> w[i];
		sort(ALL(w));
		int sum = 0;
		ll ans = 0;
		REP(i, n+1){
			vector<ll> dp(W+1);
			dp[sum] = 1;
			for(int j=i+1;j<n;j++){
				RREP(k, W+1-w[j]){
					(dp[k+w[j]] += dp[k]) %= MOD;
				}
			}
			(ans += accumulate(dp.begin() + max(W-w[i]+1, 0), dp.end(), 0)) %= MOD;
			sum += w[i];
			if(sum > W) break;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1276
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long s = scanner.nextInt();
        scanner.close();

        long index = 1;

        if (s == 1 || s == 2) {
            System.out.println(4);
            return;
        }

        while (true) {
            if (s == 4) {
                break;
            }

            if (s % 2 == 0) {
                s = s / 2;
                index++;
            } else {
                s = 3 * s + 1;
                index++;
            }

        }

        System.out.println(index + 3);

    }
}


Measured memory_bytes: 22612
N,M= [int(s) for s in input().split()]
lst = [int(s) for s in input().split()]
lst.sort()
gap=[]
for i in range(1,M):
  gap.append(lst[i]-lst[i-1])
gap.sort()
ans=0
for i in range(M-N):
  ans+=gap[i]
print(ans)

Measured memory_bytes: 13840
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
namespace remoon {
    #define re register
    #define de double
    #define le long double
    #define ri register int
    #define ll long long
    #define sh short
    #define ui unsiged int
    #define ull unsigned long long
    #define pii pair<int, int>
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define tpr template <typename ra>
    #define rep(iu, st, ed) for(ri iu = st; iu <= ed; iu ++)
    #define drep(iu, ed, st) for(ri iu = ed; iu >= st; iu --)	
    #define gc getchar
    inline int read() {
        int p = 0, w = 1; char c = gc();
        while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); }
        while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
        return p * w;
    }
    int wr[50], rw;
    #define pc(iw) putchar(iw)
    tpr inline void write(ra o, char c = '\n') {
        if(!o) pc('0');
        if(o < 0) o = -o, pc('-');
        while(o) wr[++ rw] = o % 10, o /= 10;
        while(rw) pc(wr[rw --] + '0');
        pc(c);
    }
    tpr inline void cmin(ra &a, ra b) { if(a > b) a = b; }
    tpr inline void cmax(ra &a, ra b) { if(a < b) a = b; } 
    tpr inline bool ckmin(ra &a, ra b) { return (a > b) ? a = b, 1 : 0; }
    tpr inline bool ckmax(ra &a, ra b) { return (a < b) ? a = b, 1 : 0; }
}
using namespace std;
using namespace remoon;

namespace mod_zone {
    int mod = 0;
    inline void inc(int &a, int b) { a += b; if(a >= mod) a -= mod; }
    inline void dec(int &a, int b) { a -= b; if(a < 0) a += mod; }
    inline int Inc(int a, int b) { return (a + b >= mod) ? a + b - mod : a + b; }
    inline int Dec(int a, int b) { return (a - b < 0) ? a - b + mod : a - b; }
    inline int mul(int a, int b) { return 1ll * a * b % mod; }
    inline int fp(int a, int k) {
        int ret = 1;
        for( ; k; k >>= 1, a = mul(a, a))
        if(k & 1) ret = mul(ret, a);
        return ret;
    }
}
using namespace mod_zone;

#define sid 300500
#define pai acos(-1)

de ans;
int n, tr, top;
int ox = 1, oy = 1;
int sx, sy, tx, ty, st[sid];
struct pq { 
    int x, y; 
    friend bool operator < (pq a, pq b)
    { return a.x < b.x || (a.x == b.x && a.y < b.y); }
} t[sid];

int main() {
	sx = read(); sy = read();
	tx = read(); ty = read(); n = read();
	if(sx > tx) sx = -sx, tx = -tx, ox = -1;
	if(sy > ty) sy = -sy, ty = -ty, oy = -1;
	rep(i, 1, n) {
		int x = read() * ox, y = read() * oy;
		if(x >= sx && x <= tx && y >= sy && y <= ty) 
		{ t[++ tr].x = x; t[tr].y = y; }
	}
	sort(t + 1, t + tr + 1);
	rep(i, 1, tr) {
		if(!top || t[i].y > st[top]) st[++ top] = t[i].y;
		else st[lower_bound(st + 1, st + top + 1, t[i].y) - st] = t[i].y;
	}
	ans = (tx - sx + ty - sy) * 100.0;
	ans -= top * (20.0 - pai * 5.0);
	if(top == min(tx - sx + 1, ty - sy + 1))
		ans += pai * 5.0;
	printf("%.15lf\n", ans);
	return 0;
}

Measured memory_bytes: 2560
import "dart:io";

void main(){
  List<String> inputStrList = stdin.readLineSync().split(' ');
  int n = int.parse(inputStrList[0]);
  int m = int.parse(inputStrList[1]);
  int q = int.parse(inputStrList[2]);
  List<Map<String, int>> abcd = List<Map<String, int>>();
  for(int i=0; i<q; i++){
    inputStrList = stdin.readLineSync().split(" ");
    abcd.add({
      'a': int.parse(inputStrList[0]),
      'b': int.parse(inputStrList[1]),
      'c': int.parse(inputStrList[2]),
      'd': int.parse(inputStrList[3]),
    });
  }

  List<int> capitalA = new List<int>.generate(n, (i) => 1);
  
  int max = 0;
  abcd.forEach((Map<String, int> value){
    if(capitalA[value['b'] - 1] - capitalA[value['a'] - 1] == value['c']){
      max += value['d'];
    }
  });
  
  while(_next(capitalA, m)){
    int sum = 0;
    abcd.forEach((Map<String, int> value){
      if(capitalA[value['b'] - 1] - capitalA[value['a'] - 1] == value['c']){
        sum += value['d'];
      }
    });

    if(max < sum){
      max = sum;
    }
  }

  print(max);
}

bool _next(List<int> list, int m){
  List<int> clone = new List<int>();
  clone.addAll(list);

  int index = clone.length-1;

  int item = clone.removeLast();
  if(item != m){
    list[index] = item + 1;
    return true;
  }
  index--;

  int prevItem;
  while(!clone.isEmpty){
    prevItem = item;
    item = clone.removeLast();
    if(prevItem != item){
      while(index < list.length){
        list[index] = item + 1;
        index++;
      }
      return true;
    }
    index--;
  }

  return false;
}


Measured memory_bytes: 17144
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int main() {
    long double A,B;cin >> A >> B;
    long double C = A*B;
    long long ans = C;
    cout << ans << endl;

}


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

int main() {
        ll n, k;
        cin >> n >> k;
        ll x, ans;
        x = n % k;
        if(x == 0)ans = 0;
        else if(abs(x-k) < abs(x))ans = abs(x-k);
        else ans = abs(x);
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i,j,k,ans=0;cin>>n;
  ll a[n];
  set<ll>  s1,s2;
  map<ll,ll> m;
  for(i=0;i<n;i++) cin>>a[i],m[a[i]]=i+1;
  ll l=0,r=n+1;
  s1.insert(l);
  s1.insert(r);
  s2.insert(-l);
  s2.insert(-r);
  for(i=1;i<=n;i++){
    k=m[i];
    
    l=*s1.lower_bound(k);
    r=-*s2.lower_bound(-k);
    //cout <<i<<":"<<k<<":"<<l<<":"<<r<<":"<<i*(k-l)*(r-k)<< endl;
    
    ans+=i*(k-l)*(r-k);
    s1.insert(k);
    s2.insert(-k);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 33024
n = int(input())
q = list(map(int, input().split()))
s = int(input())
t = list(map(int, input().split()))

ans = 0
for i in range(len(t)):
    low = 0
    high = len(q) - 1
    item = t[i]

    while low <= high:
        mid = (low + high) //2
        guess = q[mid]
        if guess == item:
            break
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    
    if q[mid] == t[i]:
        ans += 1
            
print(ans)


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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n, m;
  string s;
  
  cin >> n >> m >> s;
  vector<int> prev(n + 5, -1);

  for (int i = 1, j = 0; i <= n; ++i) {
    if (s[i] == '0') {
      while (i-j > m || s[j] == '1')  j++;
      if (i != j) prev[i] = j;
    }
  }

  vector<int> ans;
  int cur = n;

  while (cur != -1) {
    ans.push_back(cur);
    cur = prev[cur];
  }

  if (ans.back() != 0) {
    cout << -1 << '\n';
    return 0;
  }

  reverse(ans.begin(), ans.end());
  for (int i = 1; i < (int)ans.size(); ++i)
    cout << ans[i] - ans[i-1] << " ";
  cout << '\n';
}

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

using namespace std;

long long a[1000002];
long long net[10000002];
int main(){
	int n;
	scanf("%d", &n);
	long long sum = 0;
	a[0] = 5000;
	for(int i = 1; i <= n; i++){
		scanf("%lld", &a[i]);
		a[i] += 5000;
		net[i] = abs(a[i - 1] - a[i]);
		sum += net[i];
	}
	a[n + 1] = 5000;
	net[n + 1] = abs(a[n + 1] - a[n]);
	sum += net[n + 1];
	for(int i = 1; i <= n; i++){
		long long ans = sum;
		ans -= net[i + 1];
		ans -= net[i];
		ans += abs(a[i + 1] - a[i - 1]);
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 4096
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    string S;
    cin >> S;
    int N=S.length();
    int K;
    map<string,int> cnt;
    cin >> K;
    string ans[K+1];
    string now;
    rep(i,K) rep(j,N) ans[i]+='z';
    for(int i=0;i<N;i++) for(int j=i;j<N;j++){
        if(j==i) now.clear();
        if(j-i>5) continue;
        now+=S[j];
        if(cnt[now]>0) continue;
        cnt[now]++;
        ans[K]=now;
        sort(ans,ans+K+1);
    }
    cout << ans[K-1] << endl;
}


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

class Main
{
  public static void main (String[] arg)
  {
    Scanner scan = new Scanner(System.in);
    int count = Integer.parseInt(scan.next()); //回数
    int rateIn = Integer.parseInt(scan.next()); //表示レート
    
    /*
    System.out.println(count);
    System.out.println(rateIn);
    */
    
    int rateOut; //今回のレート
    
    if(count >= 10){
      rateOut = rateIn;
    }
    else{
      rateOut = rateIn + (100 * (10 - count));
    }
    
    System.out.println(rateOut);
    
  }
}

Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main()
{
  int n;
  cin>>n;
  ll t[n],a[n];
  rep(i,n) cin>>t[i]>>a[i];

  ll taka=1,ao=1;
  rep(i,n)
  {
    ll aa,tt;
    if(ao%a[i]==0) aa=ao/a[i];
    else aa=ao/a[i]+1;

    if(taka%t[i]==0) tt=taka/t[i];
    else tt=taka/t[i]+1;

    ll times;
    if(tt>aa) times=tt;
    else times=aa;

    taka=t[i]*times,ao=a[i]*times;
  }

  cout<<taka+ao<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
double s, t, d;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s >> t >> d;
  cout << (t >=  s / d ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3736
# coding: utf-8
n = int(raw_input())
L = map(int, raw_input().split())

#昇順にソート
L.sort()

ans = 0



for a in xrange(n-2):
	c = a + 2
	for b in xrange(a+1,n-1):
		while c < n and L[a] + L[b] > L[c]:
			c += 1
		if c > b:
			ans += (c-b-1)
print ans



Measured memory_bytes: 2692
#include <iostream>
using namespace std;
int main(){
  string s;cin>>s;
  if(s.size()==2&&s[0]==s[1]){
    cout << 1 << " " << 2 << endl;
    return 0;
  }
  for(int i = 0; s.size() > i+2; i++){
    if(s[i]==s[i+1] || s[i]==s[i+2] || s[i+1]==s[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << "-1 -1" << endl;
}

Measured memory_bytes: 512
N, X, M = map(int, input().split())

existence = [False] * M
a = []
A = X
for i in range(N):
    if existence[A]:
        break
    existence[A] = True
    a.append(A)
    A = A * A % M

try:
    loop_start = a.index(A)
except:
    loop_start = len(a)

result = sum(a[:loop_start])
N -= loop_start
if N != 0:
    a = a[loop_start:]
    loops = N // len(a)
    remainder = N % len(a)
    result += sum(a) * loops + sum(a[:remainder])
print(result)


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

int i,j,n,m;
int wall[200][3],tx,ty,sx,sy;

int crosscheck(int tx,int ty,int sx,int sy,int wx,int wy,int rr){

	int abx=sx-tx,aby=sy-ty;
	int awx=wx-tx,awy=wy-ty;
	int bwx=wx-sx,bwy=wy-sy;

	int rr2=rr*rr;
	int aw2=awx*awx+awy*awy;
	int bw2=bwx*bwx+bwy*bwy;
	int ab2=abx*abx+aby*aby;

	int tim=abx*awy-aby*awx;
	int abw=abx*awx+aby*awy;

	if(aw2<rr2 && bw2<rr2)return 0;
	if(aw2<rr2 || bw2<rr2)return 1;
	if( tim*tim/ab2 > (double)rr2)return 0;
	if(abw<0)return 0;
	if(abw>ab2)return 0;
	return 1;
}

int main(){
	while(scanf("%d",&n)*n){

		for(i=0;i<n;i++)scanf("%d %d %d",&wall[i][0],&wall[i][1],&wall[i][2]);

		for(scanf("%d",&m);m>0;m--){
			scanf("%d %d %d %d",&tx,&ty,&sx,&sy);
			int sss=0;
			for(i=0;i<n;i++){
				int wx=wall[i][0],wy=wall[i][1],rr=wall[i][2];
				if(crosscheck(tx,ty,sx,sy,wx,wy,rr))break;
			}
			if(i<n)printf("Safe\n"); else printf("Danger\n");
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
  int N, D;
  cin >> N >> D;
  vector<vector<int>> pc;
  for(int i = 0; i < N; i++){
    int x;
    vector<int> coord;
    for(int j = 0; j < D; j++){
      cin >> x;
      coord.push_back(x);
    }
    pc.push_back(coord);
  }

  int count = 0;
  for(auto it1 = pc.begin(); it1 != pc.end(); it1++){
    for(auto it2 = it1; it2 != pc.end(); it2++){
      if(it1 == it2) continue;
      double squ = 0;
      for(int i = 0; i < (*it1).size(); i++){
        squ += ((*it1)[i] - (*it2)[i]) * ((*it1)[i] - (*it2)[i]);
      }
      squ = sqrt(squ);
      if(ceil(squ) == floor(squ)){
        count++;
      }
    }
  }

  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[102];
int main() {
	ll n,ans=INF;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=-100;i<=100;i++){
		ll sum=0;
		for(int j=0;j<n;j++){
			sum+=(a[j]-i)*(a[j]-i);
		}
		ans=min(sum,ans);
	}
	cout <<ans;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        if(a.length > b.length){
            System.out.println("GREATER");
            return;
        }else if(a.length < b.length){
            System.out.println("LESS");
            return;
        }else{
            for(int i = 0; i < a.length; i++){
                if(a[i] > b[i]){
                    System.out.println("GREATER");
                    return;
                }else if(a[i] < b[i]){
                    System.out.println("LESS");
                    return;
                }
            }
        }
        System.out.println("EQUAL");
    }
}

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, t;
    cin >> a >> b >> t;
    vector <int> sol;
    for (int i = 0; i < 1000; i++) {
        sol.push_back((i + 1) * a);
    }
    int ans = 0;
    for (int i = 0; i < 1000; i++) {
        ans += (sol[i] <= t);
    }
    cout << ans * b << '\n';
    return 0;
}


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

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

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;


int main(){
  int N;
  cin >> N;
  ll sum = 0;
  
  int a1;
  cin >> a1;
  
  rep(i, N-1){
    int a2;
    cin >> a2;
    sum += max(0, a1-a2);
    a1 = a2+max(0, a1-a2);
  }
  
  cout << sum << endl;
    
    
}

      
      

Measured memory_bytes: 3616
# for change the recursion limit
import sys
sys.setrecursionlimit(10 ** 6)

# to enable variable use in global
global tree, point

# v : current node, f : parent node 
def dfs(v, f):
    for next_v in tree[v]:
        # parents node is already visited
        if next_v == f:
            continue
    
        point[next_v] += point[v]
        dfs(next_v, v)

n , q = map(int, input().split())
# initalize gloabal variables
tree = [[] for _ in range(n)]
point = [0] * n

for _ in range(n - 1):
    a , b = map(int,input().split())
    tree[b - 1].append(a - 1)
    tree[a - 1].append(b - 1)

for _ in range(q):
    p , x = map(int, input().split())
    point[p - 1] += x

dfs(0, 0)
print(*point)

Measured memory_bytes: 232972
n,k = map(int, input().split())
h = []
for i in range(n):
  h1 = int(input())
  h.append(h1)
h.sort()
hx = []
for i in range(n-k+1):
  h2 = h[i+k-1]-h[i]
  hx.append(h2)
print(min(hx))

Measured memory_bytes: 11288
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
// const ll mod = 1000000007;
const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

bool solve(){
    ll x;cin>>x;
    ll ans=0;
    if(x%11==0)ans=(x/11)*2;
    else if(0<x%11 and x%11<=6)ans=((x/11)*2)+1;
    else ans=((x/11)*2)+2;
    cout<<ans<<endl;
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    solve();
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a;
  int b;
  int ans=0;
  
  scanf("%d %d",&a,&b);
  
  for(int i=1;i>0;i++){
    if(b==1){
      break;
    }
    if(1+(ans+1)*(a-1)<b){
      ans=ans+1;
    }
    if(1+(ans+1)*(a-1)>=b){
      ans=ans+1;
      break;
    }
  }
  printf("%d",ans);
  return 0;
}



Measured memory_bytes: 128
#include<iostream>
    #include<iomanip>
    #include<cmath>
    using namespace std;

    int main ()
    {
        int num;
        double x1,y1,x2,y2,x3,y3;

        cin >> num;

        for( int i = 0; i < num; i++ )
        {
            double px = 0, py = 0, r = 0;
            cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

            px = ((x1*x1-x3*x3+y1*y1-y3*y3)*(y2-y1)-(x1*x1-x2*x2+y1*y1-y2*y2)*(y3-y1)) / (2*(x2-x1)*(y3-y1)-2*(x3-x1)*(y2-y1));
            py = ((x1-x3)*(x1*x1 -x2*x2 +y1*y1 -y2*y2)-(x1-x2)*(x1*x1-x3*x3+y1*y1-y3*y3)) / (2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));
            //py = ((2*(x1-x2)*px+x2*x2-x1*x1+y2*y2-y1*y1)) / (2*(y2-y1));
            r = sqrt((px-x1)*(px-x1) + (py-y1)*(py-y1));

            cout << fixed;
            cout << setprecision(3) << px << " " << py << " " << r << endl;
        }

        return 0;
    }


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

void koch(int n, pair<double, double> p1, pair<double, double> p2)
{
    if (n == 0)
        return;

    pair<double, double> s, t, u;

    s.first = (2 * p1.first + p2.first) / 3;
    s.second = (2 * p1.second + p2.second) / 3;
    t.first = (p1.first + 2 * p2.first) / 3;
    t.second = (p1.second + 2 * p2.second) / 3;

    double th = M_PI * 60 / 180;

    u.first = cos(th) * (t.first - s.first) - sin(th) * (t.second - s.second) + s.first;
    u.second = sin(th) * (t.first - s.first) + cos(th) * (t.second - s.second) + s.second;

    koch(n - 1, p1, s);
    cout << s.first << " " << s.second << endl;
    koch(n - 1, s, u);
    cout << u.first << " " << u.second << endl;
    koch(n - 1, u, t);
    cout << t.first << " " << t.second << endl;
    koch(n - 1, t, p2);
}

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

    pair<double, double> p1, p2;

    p1.first = 0, p2.second = 0;
    p2.first = 100, p2.second = 0;

    cout << p1.first << " " << p1.second << endl;
    koch(n, p1, p2);
    cout << p2.first << " " << p2.second << endl;

    return 0;
}


Measured memory_bytes: 3284
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> v;
int main(void){
  int n;
  char s[11];
  srand(time(NULL));
  scanf("%d",&n);
  for(int i = 0; i < n; i++){
    scanf("%s",s);
    v.push_back(i+1);
  }

  for(int i = 0; i < 1000; i++){
    printf("%d\n",v[rand()%(int)v.size()]); fflush(stdout);
    scanf("%d",&n);
    v.push_back(n);
  }
}

Measured memory_bytes: 1328
#0や1のケースに注意
#index out of range

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,m,x = map(int, input().split())
    c = []
    a = []
    for _ in range(n):
        s, *t = map(int, input().split())
        c.append(s)
        a.append(t)

    res = 10**10

    for i in range(1<<n):
        total = 0
        rikaido = [0]*m
        for j in range(n):
            if (i>>j) & 1:
                total += c[j]
                for k in range(m):
                    rikaido[k] += a[j][k]
        for k in range(m):
            if rikaido[k] < x:
                break
        else:
            res = min(res, total)
    
    if res == 10**10:
        print(-1)
    else:
        print(res)




if __name__ == '__main__':
    main()

Measured memory_bytes: 68940
#include<bits/stdc++.h>
using namespace std;
char a[100],b[100];
int lena,lenb,l,ll;
int main(){
    cin>>a,cin>>b;
    lena=strlen(a),lenb=strlen(b);
    l=min(lena,lenb),ll=max(lena,lenb);
    for(int i=0;i<=l-1;i++)
        cout<<a[i]<<b[i];
    if(lena>lenb)
        for(int i=l;i<=ll-1;i++)
            cout<<a[i];
    else 
        for(int i=l;i<=ll-1;i++)
            cout<<b[i];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 500050
#define INF (1<<29)

#define mid ((l+r)>>1)
#define ls l,mid,t<<1
#define rs mid+1,r,t<<1^1

using namespace std;
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}

priority_queue<int, vector<int>, greater<int> >q;
int n,k,e[N],a[N],p[N],d[N];
int x,ll,rr,res;
int tr[4*N];
vector<int> E[N];

void query(int l,int r,int t) {
	if (!tr[t]) return ;
	if (l >= ll && r <= rr) {
		if (res == 0 || p[ tr[t] ] < p[res] )
			res = tr[t];
		return ;
	}
	if (ll <= mid) query(ls);
	if (rr > mid) query(rs);
}

void update(int l,int r,int t) {
	if (l > x || r < x) return ;
	if (l == r) {tr[t] = x; return ;}
	update(ls), update(rs);
	if (p[tr[t<<1]] < p[tr[t<<1^1]])
		tr[t] = tr[t<<1];
	else
		tr[t] = tr[t<<1^1];
}


bool cmp(int p1,int p2) {return p[p1] < p[p2];}
int main() {
	n = rd(), k = rd();
	for (int _=1;_<=n;_++) p[_] = rd();
	p[0] = INF;
	
	for (int _=1;_<=n;_++) e[_] = _;
	sort(e+1,e+n+1,cmp);
	
	for (int _=n;_>=1;_--) {
		x = e[_];

		ll = x - k + 1, rr = x, res = 0;
		query(1,n,1);
		if (res)
			E[x].push_back(res), d[res]++;
		
		ll = x, rr = x + k - 1, res = 0;
		query(1,n,1);
		if (res)
			E[x].push_back(res), d[res]++;
		
		update(1,n,1);
	}
	
	for (int _=1;_<=n;_++) if (!d[_]) q.push(_);
	for (int _=1;_<=n;_++) {
		int x = q.top(); q.pop();
		a[x] = _;
		for (int i=0;i<(int)E[x].size();i++)
			if (--d[ E[x][i] ]==0) q.push(E[x][i]);
	}
	
	for (int _=1;_<=n;_++) printf("%d\n",a[_]);
	return 0;
}

Measured memory_bytes: 44416
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner stdIn=new Scanner(System.in);

        int M=stdIn.nextInt();
        int N=stdIn.nextInt();

        System.out.println(M*(M-1)/2+N*(N-1)/2);
        
        
        
    }

}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
typedef long long ll;
string S;
int N,Q,K[100];
ll sumd[2000010] = {0},summ[2000010] = {0},sumc[2000010] = {0},sumlmc[2000010] = {0};
int main(){
	cin >> N >> S >> Q;
	for(int i=0;i<Q;i++){
		cin >> K[i];
	}
	ll ans = 0;
	for(int i=1;i<=N;i++){
		sumd[i] = sumd[i-1]+(S[i-1]=='D');
		summ[i] = summ[i-1]+(S[i-1]=='M');
		sumc[i] = sumc[i-1]+(S[i-1]=='C');
	}
	for(int i=N-1;i>=1;i--){
		sumlmc[i] += sumlmc[i+1];
		if(S[i-1]=='M') sumlmc[i] += sumc[N]-sumc[i];
	}
	for(int i=1;i<=N;i++){
		if(S[i-1]=='M'){
			ans += sumd[i-1]*(sumc[N]-sumc[i]);
		}
	}
/*	for(int i=1;i<=N;i++){
		cout << sumlmc[i] << (i!=N? " ":"\n");
	}
	cout << ans << endl;
*/	for(int j=0;j<Q;j++){
		ll sub = 0;
		for(int i=1;i<=N;i++){
			if(S[i-1]=='D'){
				sub += (summ[min(i+K[j]-1,N)]-summ[i])*(sumc[N]-sumc[min(i+K[j]-1,N)]);
				sub += sumlmc[min(i+K[j],N)];
			}
		}
		cout << ans-sub << endl;
	}
}

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

using namespace std;

int a[100200], b[100020], c[100020];
int da[100200], db[100020], dc[100020];

int resiA(int i, int n);
int resiB(int i, int n);
int resiC(int i, int n);

int resiA(int i, int n)
{
    if(i == n-1)
    {
       return a[i];
    }

    if(da[i] == 0)
    {
        
        da[i] = max(resiB(i+1,n)+a[i], resiC(i+1, n)+a[i]);
    }

    return da[i];

}

int resiB(int i, int n)
{
    if(i == n-1)
    {
       return b[i];
    }

    if(db[i] == 0)
    {
        
        db[i] = max(resiA(i+1,n)+b[i], resiC(i+1, n)+b[i]);
    }

    return db[i];

}

int resiC(int i, int n)
{
    if(i == n-1)
    {
       return c[i];
    }

    if(dc[i] == 0)
    {
        
        dc[i] = max(resiA(i+1,n)+c[i], resiB(i+1, n)+c[i]);
    }

    return dc[i];

}

int main()
{
    int n;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        da[i] = 0;
        db[i] = 0;
        dc[i] = 0;
    }

    int rez = max(max(resiB(0,n), resiC(0,n)), resiA(0,n));

    cout << rez;

    return 0;
}

Measured memory_bytes: 7296
N = int(input())
T = list(map(int,input().split()))
M = int(input())
T_sum = sum(T)
ans = []
for i in range(M):
	p,x = map(int,input().split())
	ans.append(T_sum - (T[p-1] - x))
for i in range(M):
	print(ans[i])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll n;
    cin >> n;
    if (n % 2) {
        cout << 0 << endl;
    } else {
        ll ans = 0;
        ll d = 10;
        while (d <= n) {
            ans += n / d;
            d *= 5;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] l = new int[n];
        for (int i = 0; i < n; ++i) {
            l[i] = sc.nextInt();
        }
        if (n <= 2) {
            System.out.println(0);
            return;
        }
        int count = 0;
        for (int i = 0; i < n - 2; ++i) {
            for (int j = i + 1; j < n - 1; ++j) {
                for (int k = j + 1; k < n; ++k) {
                    if (l[i] >= l[j] + l[k] || l[j] >= l[i] + l[k] || l[k] >= l[i] + l[j]) {
                        continue;
                    }
                    if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) {
                        continue;
                    }
                    ++count;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 36844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>

using namespace std;

int main(){

	string str;
	while(getline(cin,str)&&str!="0"){
		vector<int> v;
		int s=0;
		for(int i = 0; i < str.size(); i++){
			if(str[i]==' '||str.size()-1==i){
				int t;
				if(str.size()-1!=i)
					t= atoi(str.substr(s,i-s).c_str());
				else
					t= atoi(str.substr(s,i-s+1).c_str());
				v.push_back(t);
				s=i+1;
			}
		}
		sort(v.begin(),v.end(),greater<int>());
		int sum=0;
		for(int i = 0; i < v.size(); i++){
			if(v[i]>=10){
				sum+=10;
			}
			else if(v[i]<=9&&v[i]>=2){
				sum+=v[i];
			}
			else if(v[i]==1){
				int num = v.size()-i;
				for(int j = 0; j < num; j++){
					if((num-j-1)+sum+11<=21){
						sum+=11;
					}
					else
						sum+=1;
				}
				break;
			}
		}
		if(sum<=21)
			cout<<sum<<endl;
		else
			cout<<0<<endl;
	}

	return 0;
}

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

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int a, b, h, m;
    sc(a), sc(b), sc(h), sc(m);
    double t = (double) 5.5 * m;
    t = (double) 30.0 * h - t;
    double ans = a*a + b*b;
    double z = 2 * a * b;
    t = PI * t / 180.0;
    t = cos(t);
    z = (double) z * t;
    ans = (double) ans - z;
    ans = sqrt(ans);
    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}

Measured memory_bytes: 4288
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int N;
    double ans, k;

    cin >> N;

    k = N - N/2;
    ans = k/N;

    cout << fixed << setprecision(10) << ans << endl;

    return 0;
    
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main()
{
    int a,b,c;
  cin >> a>>b>>c;
  string ans="No";
  if((a<=c)&&(c<=b)) ans="Yes";
     cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 2e5+1;
int n, k, s[N];
map<int, int> m;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  m[0]++;
  ll ans = 0;
  FOR(i, 0, n){
    int a;
    cin >> a;
    s[i+1] = (s[i]+a-1)%k;
    if(i>=k-1) m[s[i-k+1]]--;
    ans += m[s[i+1]]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 10368
#include <iostream>
#include <string>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

Int PerseAndCalc(string& s, Int times) {
    Int result = 0;

    Int length = s.length() - 1;
    Int start = 0;
    for (Int i = 0; i < length; ++i) {
        if (((1 << i) & times) != 0) {
            result += stol(s.substr(start, i - start + 1));
            start = i + 1;
        }
    }
    result += stol(s.substr(start, length - start + 1));
    return result;
}

int main(void) {
    string s;
    cin >> s;
    Int times = (1 << (s.length() - 1));
    Int result = stol(s);
    for (int i = 1; i < times; ++i) {
        result += PerseAndCalc(s, i);
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3628