akhauriyash/Code-Regression huggingface dataset:
package main

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

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

const yes = "Yes"
const no = "No"

func solve(w int64, h int64, x int64, y int64, r int64) bool {
	if x < r || w - r < x {
		return false
	}
	if y < r || h - r < y {
		return false
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	w:= nextInt()
	h := nextInt()
	x := nextInt()
	y := nextInt()
	r := nextInt()
	if solve(w, h, x, y, r) {
		fmt.Fprintln(out, yes)
	} else {
		fmt.Fprintln(out, no)
	}
}

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

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

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

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}



Measured memory_bytes: 1112
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int MOD = 1e9 + 7;

void solve()
{
    string s;
    cin >> s;
    int count[3] = {0};
    rep(i, s.length())
    {
        count[s[i] - 'a']++;
    }
    int mini = min(count[0], min(count[1], count[2]));
    int maxi = max(count[0], max(count[1], count[2]));
    P(abs(mini - maxi) >= 2 ? "NO" : "YES");
}

int main()
{
    solve();
    return 0;
}


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

#define x first
#define y second
#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;
const LL MAX = 1e11;

int n, ans;
map<LL, int> cnt;
map<LL, LL> M;

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

	while(n--){
		LL x;
		scanf("%lld", &x);

		int r = pow(x, 1.0 / 3) + 3;
		LL sqr = 1, single = 1;

		For(i, 2, r) if(x % i == 0){
			int c = 0;
			while(x % i == 0) x /= i, ++c;
			c %= 3;

			if(c == 1) single *= i;
			else if(c == 2) sqr *= i;
		}

		LL s = LL(sqrt(x) + 1e-9);
		if(s * s == x) sqr *= s;
		else single *= x;

		if(single * sqr > MAX / single){
			++ans;
			continue;
		}

		LL b = single * single * sqr, a = sqr * sqr * single;
		cnt[a]++;
		M[a] = b;

	}

	for(auto s : cnt){
		LL y = M[s.x];

		if(s.x == y){
			++ans;
			continue;
		}

		if(!cnt.count(y)) ans += s.y;
		else if(s.x > y) ans += max(s.y, cnt[y]);
	}

	printf("%d\n", ans);
	return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;


int main(){
    ll n, m;
    cin >> n >> m;

    ll mod = pow(10, 9) + 7;

    if(2 <= abs(n - m)){
        cout << 0 << endl;
        return 0;
    }

    ll left = 1;
    ll right = 1;

    rep(i, n){
        left *= (i+1);
        left %= mod;
    }

    rep(i, m){
        right *= (i+1);
        right %= mod;
    }

    ll res = (left * right)%mod;
    if(abs(n - m) == 0){
        res *= 2;
        res %= mod;
    }

    cout << res << endl;

    


    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


from collections import defaultdict


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, f, t, w=1):
        self.E[f].append((t, w))


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    # シミュレーションでループを検出
    g = Graph(N)
    for X, Y in zip(range(1, N+1), A):
        g.add_edge(X-1, Y-1)

    seen = [False]*N
    prev = []
    state = 0

    while True:
        seen[state] = True
        prev.append(state)
        for dest, _ in g.E[state]:
            state = dest
        if seen[state]:
            break
    amari = prev.index(state)
    period = len(prev)-amari
    # print(state, amari, period, prev)
    if K < amari:
        print(prev[K]+1)
    else:
        print(prev[amari + (K-amari) % period]+1)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 75984
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	int N;
  	cin >> N;
	int a[110]={},mac=0,mina=MOD;
	REP(i,N){
		cin >> a[i];
		mac=max(mac,a[i]);
		mina=min(mina,a[i]);
	}
	cout << mac-mina << endl;
	return 0;
}

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

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

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

    long long ans = 0, mx = 0;
    for (int i = 0; i < n; i++){
        if (a[i] < mx){
            ans += mx - a[i];
        }
        mx = max(a[i], mx);
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 4776
#include <stdio.h>
#include <stdlib.h>

#define MAX_N   100
#define MAX_W   10000

int max2(int x, int y) {

    return x > y ? x : y;
}

// ??????b??????????????????????????????0???n?????\??????????????????????????§???
int m(int b, int n, int *v, int *w) {
    static int memo[MAX_W][MAX_N] = { 0 };
    int rep;
    int i;

    if( memo[b][n] != 0 ) return memo[b][n];

    if( n < 0 ) {
        rep = 0;
    } else if( b < w[n] ) {
        rep = m(b, n - 1, v, w);
    } else {
        rep = max2(m(b, n - 1, v, w), m(b - w[n], n - 1, v, w) + v[n]);
    }

    return memo[b][n] = rep;
}

int main(void) {
    int N, W;
    int *v, *w;
    int i;

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

    v = (int *)malloc(sizeof(int) * N);
    w = (int *)malloc(sizeof(int) * N);

    for( i = 0; i < N; i++ ) {
        scanf("%d %d", v + i, w + i);
    }

    printf("%d\n", m(W, N - 1, v, w));

    free(v);
    free(w);

    return 0;
}

Measured memory_bytes: 4504
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353



D =int(sys.stdin.buffer.readline())
s = 'Christmas' + ' Eve' * (25 - D)
print(s)



Measured memory_bytes: 13436
S = input()

for i in range(len(S)):
    if i % 2 == 0:
        if not S[i] in ('R', 'U', 'D'):
            print("No")
            break
    else:
        if not S[i] in ('L', 'U', 'D'):
            print("No")
            break
else:
    print("Yes")

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define NUM_MAX 30000
#define BUF_SIZE (NUM_MAX+5)
#define INF 0x01010101

#define SECRET_DIGIT 3

int get_int(void) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
#else
#error
#endif
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  int num;
  sscanf(line, "%d", &num);
  return num;
}

int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int main(void) {
    char lucky_str[BUF_SIZE];
    int digits = get_int();
    static int cum[NUM_MAX+1][10];
    static int first_idx[10];
    static int last_idx[10];
    int i, j;

    // initialization
    memset(first_idx, 0x01, sizeof(int)*10);
    for(i = 0; i < 10; i++) last_idx[i] = -1;

    get_str(lucky_str, BUF_SIZE);

    // calc cumulative sum of each digit
    for(i = 0; i < digits; i++) {
        char d = lucky_str[i] - '0';
        if(first_idx[d] == INF) first_idx[d] = i;
        last_idx[d] = i;
        for(j = 0; j < 10; j++) {
            cum[i+1][j] = cum[i][j] + (j == d);
        }
    }
    int first, last, middle;
    int cnt = 0;
    for(first = 0; first < 10; first++) {
        int fidx = first_idx[first];
        if(fidx == INF) continue;
        for(last = 0; last < 10; last++) {
            int lidx = last_idx[last];
            if(lidx == -1) continue;
            for(middle = 0; middle < 10; middle++) {
                // [fidx+1, lidx)
                if(cum[lidx][middle] - cum[fidx+1][middle] > 0) cnt++;
            }
        }
    }
    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 1408
def solve():
    from math import atan2, degrees, hypot
    n = int(input())
    txy = []
    sx, sy = 0, 0
    for i in range(n):
        a, b = map(int, input().split())
        theta_0 = degrees(atan2(b, a))
        sx += a
        sy += b
        txy.append([theta_0, a, b])
    txy.sort()
    ans = hypot(sx, sy)
    for i in range(n):
        for j in range(i + 1, n):
            tx, ty = 0, 0
            for k in range(i, j):
                theta, x, y = txy[k]
                tx += x
                ty += y
                ans = max(ans, hypot(tx, ty))
                ans = max(ans, hypot(sx - tx, sy - ty))
    print(ans)

solve()


Measured memory_bytes: 9492
#include<stdio.h>
#include<string.h>
int main()
{
	char s[100005];
	scanf("%s", s);
	int i, n = strlen(s);
	int ans = 0;
	for (i = 1; i < n; i++)
		if (s[i] != s[i - 1])
			ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,A,B;
  cin >> K >> A >> B;
  int R=0;
  bool X=1;
  while(R<A){
    R+=K;
    if (R>B){
      X=0;
      break;
    }
  }
  if(X){
    cout <<"OK" << endl;
  }
  else {
    cout << "NG" << endl;
  }
}


Measured memory_bytes: 3648
s = gets.chomp
a = s[0,2].to_i
b = s[2,2].to_i
f = g = false
f = true if b <= 12 && b > 0
g = true if a <= 12 && a > 0
if f && g
    puts "AMBIGUOUS"
elsif f
    puts "YYMM"
elsif g
    puts "MMYY"
else
    puts "NA"
end

Measured memory_bytes: 1788
/*twitter:@chigaphys
  atcoder:chiga
  所属:久留米大学附設中学校
  color:gray*/
#include <bits/stdc++.h>
using namespace std;

int gcd(int x,int y){/*最大公約数,x≧yじゃないといけない*/if(x%y==0)return y;return gcd(y,x%y);}

int lcm(int x,int y){/*最小公約数*/return x*y/gcd(x,y);}

int main(){
  int x;
  cin>>x;
  cout<<lcm(x,360)/x<<endl;
}

Measured memory_bytes: 3628
i = [input() for i in range(6)]

i0 = int(i[0])

i1 = int(i[1])

i2 = int(i[2])

i3 = int(i[3])

i4 = int(i[4])

i5 = int(i[5])



if  i4 - i0 > i5:
    print(":(")

else:
    print("Yay!")

Measured memory_bytes: 3064
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,m;
vvi in,out;
vi S,L;
int im;
int dp[100010];
signed main(){
    I(n); I(m);
    in.resize(n+1);
    out.resize(n+1);
    REP(i,m){
        int a,b;
        I(a); I(b);
        out[a].pb(b);
        in[b].pb(a);
    }
    REPS(i,n){
        if (sz(in[i]) == 0) S.pb(i);
    }
    while(sz(S)){
        im = S.back();
        L.pb(im);
        S.pop_back();
        for (auto m: out[im]){
            auto result = remove_if( all(in[m]), [](int x){return x == im;});
            in[m].erase(result,in[m].end());
            if(sz(in[m]) == 0) S.pb(m);
        }
    }
    for(auto i: L){
        for (auto n: out[i]){
            dp[n] = max(dp[n], dp[i]+1);
        }
    }
    cout << *max_element(dp, dp+n+1) << endl;;
}

Measured memory_bytes: 12920
#include<bits/stdc++.h>
using namespace std;
int main(){
   int f=0,s=0,x;
   for(int i=0;i<3;i++)
   {
       cin>>x;
       if(x==5) f++;
       else s++;
   }
   if(f==2 && s==1) cout<<"YES";
   else cout<<"NO";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string s;cin>>s;
  for(int i = 0; s.size() > i; i++){
    if(i%2 == 0){
      if(s[i]=='L'){
        cout << "No" << endl;
        return 0;
      }
    }else{
      if(s[i]=='R'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int x,a;
    cin >> x >> a;
    if (x < a)
        cout << 0 << endl;
    else 
        cout << 10 << endl;
    return 0;
}


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



int main(){
    string s;
    cin>>s;
    bool ans=true;

    if(s[2]!=s[3])ans=false;
    if(s[4]!=s[5])ans=false;

    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d\t%d\t%d",&a,&b,&c);
	if(a<b&&b<c)
	{
		printf("Yes\n");
	}
	else
	{
	    printf("No\n");
	}
	return 0;
	
}


Measured memory_bytes: 2144
import sys
    
def shortest_path(GRAPH, distance):
    
    nodes = set()
    p1 = 0
    distance[p1] = 0

    while True:
        dp1 = distance[p1]
        gp1 = GRAPH[p1]
        status[p1]=1
        for p2 in gp1.keys():
            tmp = gp1[p2] + dp1
            if status[p2]==0 and tmp < distance[p2]:
                distance[p2] = tmp
                nodes.add(p2)

        p1 = -1
        mini = 1000000
            
        for p2 in nodes:
            if distance[p2]<mini:
                p1 = p2
                mini = distance[p2]
        if mini == 1000000:
            break
        nodes.remove(p1)
    return

def resultout(distance):
    for i in xrange(len(distance)):
        print "%d %d" %(i, distance[i])
    return

n = int(raw_input())
x = [{} for i in xrange(n)]
status = [0 for i in xrange(n)]
distance = [1000000 for i in xrange(n)]

for i in xrange(n):
    seq = map(int, raw_input().split())
    tmp={}
    for j in xrange(2, len(seq), 2):
        j2, weight = seq[j:j+2]
        tmp[j2] = weight
    x[seq[0]] = tmp
    status[i] = 0

shortest_path(x, distance)
resultout(distance)

Measured memory_bytes: 72264
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
ll A[MAX_N],used[MAX_N];

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> A[i];
	}
	deque<int> d;
	rep(i,N)
	{
		int p = lower_bound(d.begin(),d.end(),A[i]) - d.begin();
		if (p == 0)
		{
			d.push_front(A[i]);
		}
		else
		{
			d[p-1] = A[i];
		}
	}
	cout << d.size() << endl;
	return 0;
}

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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    ll a;
    cin>>a;
    ll ans=a+a*a+a*a*a;
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

int main(){
  int a,b,ans=0;
  cin>>a>>b;
  if(a>=13) ans=b;
  else if(a>=6 && a<=12) ans=b/2;
  cout<<ans<<endl;
}

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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), V(N,0);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  for (int i=0; i<N; i++) {
    V[A[i]-1]++;
  }
  
  ll S=0;
  for (int i=0; i<N; i++) {
    ll m;
    if (V[i]*(V[i]-1)/2>0) {m=V[i]*(V[i]-1)/2;}
    else {m=0;}
    S+=m;
  }
  //cout << S << endl;
  for (int i=0; i<N; i++) {
    ll m;
    m=V[A[i]-1]-1;
    cout << S-m << endl;
  }
}


Measured memory_bytes: 6428
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <queue>

using namespace std;

typedef unsigned long long ll;


int main() {

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

   vector<pair<int,int>> ids(m);

   int counter = 0;

   pair<int,int> minFirst;
   minFirst.first = 10e9;

   pair<int,int> maxFirst;
   maxFirst.first = 0;

   pair<int,int> maxSecond;
   maxSecond.second = 0;
   pair<int,int> minSecond;
   minSecond.second = 10e9;

   for(int i = 0; i < m; i++)
   {
       pair<int,int> temp;
       cin >> temp.first;
       cin >> temp.second;

       if(temp.first < minFirst.first)
           minFirst = temp;
       if(temp.first > maxFirst.first)
           maxFirst = temp;
       if(temp.second < minSecond.second)
           minSecond = temp;
       if(temp.second > maxSecond.second)
           maxSecond = temp;

       ids[i] = temp;

   }


   for(int i = 1; i <= n; i++)
   {
       bool all = true;

       if(i >= minFirst.first && i <= minFirst.second && i >= maxFirst.first && i <= maxFirst.second && i >= minSecond.first && i <= minSecond.second
       && i >= maxSecond.first && i <= maxSecond.second)
       {
           counter++;
       }


   }

   cout << counter;
   return 0;

}

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

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


int main(){
    int n,m; cin>>n>>m;
    long long int dp[n+1]={0};//dp[i]=i段目にたどり着くまでの移動方法
    dp[1]=1; dp[0]=1;

//壊れてる階段用配列
   int vec[n+1]={0};
   for(int i=0;i<m;i++){
       int a;
       cin>>a;
       vec[a]=-1;
   }

    for(int i=1;i<=n;i++){ //１段目からみてく
        if(vec[i]==-1)dp[i]=0;
        else if(i>=2)dp[i]=(dp[i-1]+dp[i-2])%1000000007;
 
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n;
std::vector<int> to[maxn];
int cnt[maxn][20],id[maxn];
void dfs(int x,int f=0){
	for(auto i:to[x])if(i!=f){
		dfs(i,x);
		rep(j,0,19)cnt[x][j]+=cnt[i][j];
	}
	int&min=id[x]=0;
	rep(j,0,19)if(cnt[x][j]>=2)min=j+1;
	for(;min<20&&cnt[x][min];)++min;
	rep(j,0,min-1)cnt[x][j]=0;
	cnt[x][min]=1;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 1, n - 1) {
		int x, y; cin >> x >> y;
		to[x].push_back(y);
		to[y].push_back(x);
	}
	dfs(1), cout<<*std::max_element(id+1,id+n+1)<<'\n';;
}


Measured memory_bytes: 23680
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll h[100001];
int main() {
	ll n, k; cin >> n >> k;
	ll ans = 0;
	rep(i, 0, n) {
		cin >> h[i];
		if (h[i] >= k)ans++;
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
  int N, A, B, sum = 0;
  cin >> N >> A >> B;

  for(int i = 1; i <= N; i++) {
    int n = 0;
    int _i = i;
    while (_i > 0) {
      n += _i % 10;
      _i /= 10;
    }

    if (A <= n && n <= B)
      sum += i;
  }

  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int a,b,k;
  cin>>a>>b>>k;
  
  for(int i = 0; i < k; i++)
  {
    if(i % 2 == 0) {
      if(a % 2 == 1) {
        a -= 1;
      }
      b += a / 2;
      a = a / 2;
    } else {
      if(b % 2 == 1) {
        b -= 1;
      }
      a += b / 2;
      b = b / 2;
    }
  }
  cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 256
n,a=$<.map{|m|m.split.map(&:to_i)}

lgcd = [0]
rgcd = [0]
size = n[0]
size.times do |i|
  l = i
  r = -i-1
  lgcd << a[l].gcd(lgcd.last)
  rgcd << a[r].gcd(rgcd.last)
end

p size.times.map {|i| lgcd[i].gcd(rgcd[size-i-1]) }.max


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

using namespace std;


int main()
{
    
  int i{};
  cin >> i;   
  
  if(i%1000 == 0)
  {
      cout <<   0;     
  }
  else
  {
      int mul = i/1000;
      int res = i - (mul * 1000);    
      cout <<   1000 - res;    
    
      
  }
    
    
    
 return 0;   
}

Measured memory_bytes: 3640
n,m=map(int,input().split())
if abs(n-m)>=2:
  ans=0
elif abs(n-m)==1:
  ans=1
  for i in range(1,n+1):
    ans=(ans*i)%(10**9+7)
  for j in range(1,m+1):
    ans=(ans*j)%(10**9+7)
else:
  ans=1
  for i in range(1,n+1):
    ans=(ans*i)%(10**9+7)
  ans=(2*ans**2)%(10**9+7)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 1;
  rep(i, s.size() - 1) if (s[i] != s[i + 1]) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3752
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        char[] c = sc.next().toCharArray();
        for (int i = 0; i < n; i++) {
            a[i] = c[i] - '0';
        }
        int res = 0;

        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                A:
                for (int k = 0; k < 10; k++) {
                    int pos = 0;
                    while (a[pos] != i) {
                        pos++;
                        if (pos == n)
                            continue A;
                    }
                    pos++;
                    if (pos == n)
                        continue A;
                    while (a[pos] != j) {
                        pos++;
                        if (pos == n)
                            continue A;
                    }
                    pos++;
                    if (pos == n)
                        continue A;
                    while (a[pos] != k) {
                        pos++;
                        if (pos == n)
                            continue A;
                    }
                    if (a[pos] == k)
                        res++;
                }
            }
        }

        System.out.println(res);
    }
}


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

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

	if(K * 500 >= X)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

using namespace std;

int main(){

  int A,B,C,D,L;

  int a,b;
  int day;

  cin >> L >> A >> B >> C >> D;

  a=(A+C-1)/C;
  b=(B+D-1)/D;

  if(a>b){
    day=a;
  }
  else{
    day=b;
  }

  cout << L-day << endl;
 
  
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define en '\n'
#define fs first
#define sd second

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    set<int> s;
    for(int i = 1; i <= n; ++i){
        s.insert(i);
    }
    int d, el;
    for(int i = 0; i < k; ++i){
        cin >> d;
        for(int j = 0; j < d; ++j){
            cin >> el;
            s.erase(el);
        }
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 3672
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> as;
  for (int i = 0; i < N; ++i) {
    int ai;
    cin >> ai;
    as.push_back(ai);
  }
  int one_idx = distance(as.begin(), min_element(as.begin(), as.end()));
  int lower_cnt = one_idx;
  int upper_cnt = N - one_idx - 1;
  int K_dash = K - 1;

  int ans = 0;
  ans += lower_cnt / K_dash;
  int r = lower_cnt % K_dash;
  if (r != 0) {
    ++ans;
    upper_cnt -= (K_dash - r);
    upper_cnt = max(0, upper_cnt);
  }

  ans += upper_cnt / K_dash;
  if (upper_cnt % K_dash != 0) {
    ++ans;
  }

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

Measured memory_bytes: 892
#include<stdio.h>
int main()
{
    long long n,sum=0,T,max,min;
    scanf("%lld",&T);
    for(int i=1; i<=T; i++)
    {
        scanf("%lld ",&n);
        if(i==1)
            max=min=n;
        if(max<n)
            max=n;
        else if(min>n)
            min=n;
        sum=sum+n;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}


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

int INF = 1000000007;

int main() {
	int n, q;
	string s;
	cin >> n >> s >> q;
	vector<set<int>> S(26);
	rep(i, n) S[s[i] - 'a'].insert(i);
	rep(i, q) {
		int l;
		cin >> l;
		if (l == 1) {
			int k;
			char c;
			cin >> k >> c;
			S[s[k - 1] - 'a'].erase(k - 1);
			s[k - 1] = c;
			S[c - 'a'].insert(k - 1);
		}
		else {
			int a, b;
			cin >> a >> b;
			int cnt = 0;
			rep(i, 26) {
              if(S[i].lower_bound(a-1)!=S[i].lower_bound(b)) cnt++;
			}
			cout << cnt << endl;
		}
	}
}

Measured memory_bytes: 24324
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin>>S;
    int N=S.size();
    bool ok=true;
    if(S[0]!='A')
        ok = false;
    int cnt=0;
    for(int i=2; i<N-1; ++i)
    {
        if(S[i]=='C')
            cnt++;
    }
    if(cnt!=1)
        ok=false;
    for(int i=0; i<N; ++i)
    {
        if(S[i]=='A' || S[i]-'a' >=0 || S[i]=='C')
            continue;
        ok=false;
    }
    if(ok)
        cout<<"AC"<<endl;
    else
        cout<<"WA"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    ll n, m;
    pair<ll, ll> a[110000];
    cin >> n >> m;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i].first >> a[i].second;
    }
    sort(a, a + n);
    ll i = 0;
    ll hon = 0;
    ll ans = 0;
    while (1)
    {
        if (m >= hon + a[i].second)
        {
            hon += a[i].second;
            ans += a[i].first * a[i].second;
        }
        else
        {
            ans += a[i].first * (m - hon);
            hon += (m - hon);
        }
        if (m == hon)
        {
            cout << ans << endl;
            return 0;
        }
        i++;
    }
}


Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
int main(){
    long long int j[100000];
    int n;
    std::cin >> n;
    for(int q = 0;q<n;q++){
        std::cin >> j[q];
    }
    std::sort(&j[0],&j[n]);
    int h = j[0];
    long long int k1;
    int pos = 0;
    for(int q = 1;q<n;q++){
        if(j[q] == h){
            k1 = j[q];
            pos = q;
        }
        else h = j[q];
    }
    if(pos == 0){
        std::cout << "0";
        return 0;
    }
    long long int k2;
    h = j[0];
    int pos2 = 0;
    for(int q = 1;q<pos - 1;q++){
        if(j[q] == h){
            k2 = j[q];
            pos2 = 2;
        }
        else{
            h = j[q];
        }
    }
    if(pos2 == 0){
        std::cout << "0";
        return 0;
    }
    std::cout << k1 * k2;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define s(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)

int main()
{
#ifdef WIN32
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

#ifndef WIN32
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#endif
    string s, t;
    cin >> s >> t;
    int ans = INT_MAX;
    for (int i = 0; i <= s.size() - t.size(); i++)
    {
        int c = 0;
        for (int j = 0; j < t.size(); j++)
        {
            //  cout << s[j + i] << t[j] << "\n";
            if (s[j + i] != t[j])
            {
                c++;
            }
        }
        //  cout << c << "\n";
        ans = min(c, ans);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3660
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

int bit_n;
int dat[10010];
void init(int n){
    bit_n=n;
    memset(dat,0,sizeof(dat));
}
void add(int k,int x){
    for(k++;k<=bit_n;k+=k&-k)dat[k]+=x;
}
int sum(int k){
    int ret=0;
    for(k++;k;k-=k&-k)ret+=dat[k];
    return ret;
}

struct event{
    int y,id,in;
    event(int y,int id,int in):y(y),id(id),in(in){}
    bool operator<(const event &e)const{
        return y<e.y;
    }
};

int N,r;
vector<event>es;
int x1[10000],y1[10000],x2[10000],y2[10000];

int cnt[10020];
void solve1(){
    int ret=0;
    memset(cnt,0,sizeof(cnt));
    int cur=0,prevy=0;
    while(cur<es.size()){
        int sum=0;
        for(int i=0;i<10010;i++)if(cnt[i])sum++;
        ret+=sum*(es[cur].y-prevy);
        prevy=es[cur].y;
        int next=cur;
        while(next<es.size()&&es[next].y==es[cur].y){
            int id=es[next].id;
            for(int i=x1[id];i<x2[id];i++){
                if(es[next].in)cnt[i]++;
                else cnt[i]--;
            }
            next++;
        }
        cur=next;

    }

    cout<<ret<<endl;
}

void solve2(){
    int ret=0;
    memset(cnt,0,sizeof(cnt));
    int cur=0,prevy=0;
    while(cur<es.size()){
        int sum=0;
        for(int i=0;i<10010;i++){
            if(cnt[i]!=0)continue;
            if(i&&cnt[i-1])sum++;
            if(cnt[i+1])sum++;
        }
        ret+=sum*(es[cur].y-prevy);
        prevy=es[cur].y;
        int next=cur;
        int memo[10020];
        for(int i=0;i<10020;i++)memo[i]=cnt[i];
        while(next<es.size()&&es[next].y==es[cur].y){
            int id=es[next].id;
            for(int i=x1[id];i<x2[id];i++){
                if(es[next].in)cnt[i]++;
                else cnt[i]--;
            }
            next++;
        }
        for(int i=0;i<10020;i++)if(memo[i]!=cnt[i]&&(memo[i]==0||cnt[i]==0))ret++;
        cur=next;

    }

    cout<<ret<<endl;
}

int paint[10][10];
int main(){
    while(cin>>N>>r,N||r){
        es.clear();
        for(int i=0;i<N;i++){
            cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
            x1[i]++;y1[i]++;x2[i]++;y2[i]++;
        }

        for(int i=0;i<N;i++){
            es.push_back(event(y1[i],i,1));
            es.push_back(event(y2[i],i,0));
        }

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

        /*
        memset(paint,0,sizeof(memo));
        for(int k=0;k<N;k++){
            for(int i=y1[k];i<y2[k];i++){
                for(int j=x1[k];j<x2[k];j++){
                    paint[i][j]=min(1,paint[i][j]+1);
                }
            }
        }
        for(int i=1;i<15;i++){
            for(int j=1;j<15;j++){
                cout<<paint[i][j]<<" ";
            }cout<<endl;
        }
        */
        solve1();
        if(r==2)solve2();
    }
    return 0;
}

Measured memory_bytes: 1860
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n,x; cin >> n >> x;
    int ans = n;
    int Min = 1000;
    rep(i,n) {
        int m; cin >> m;
        Min = min(m, Min);
        x -= m;
    }
    while (x >= Min) {
        ans++;
        x -= Min;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

struct unionFind {
    vector<int> par; // 親を指すvector,-par[親]は木のサイズ
    unionFind(int n):par(n, -1) {} // 自分で親を埋め込んでいく必要あり
    int root(int x) { // 親をたどる&データの整理
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) { // データの結合
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);} // 所属判定
    int size(int x) {return -par[root(x)];} // 木のサイズ
} uft(100000);

int main() {
    int n, m;
    cin >> n >> m;
    vi vec(n), vec_(n);
    rep(i, n) {
        cin >> vec[i];
        --vec[i];
        vec_[vec[i]] = i;
    }
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        uft.unite(x, y);
    }

    int ans=0;
    rep(i, n) {
        if(uft.same(i, vec_[i])) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using boost::math::lcm;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

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

  vector<long long> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }

  long long x = 1;
  for (auto& elem : arr) {
    x = lcm(x, elem / 2);
    if (x > m) {
      cout << 0 << endl;
      return 0;
    }
  }

  for (auto& elem : arr) {
    if ((x / (elem / 2)) % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long y = 1;
  for (auto& elem : arr) {
    y = lcm(y, elem);
    if (y > m) {
      cout << 1 << endl;
      return 0;
    }
  }

  cout << 1 + (m - x) / y << endl;
}


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

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

    long int sum = 0; 

    for(int A=1;A<=N;A++) {
        long int r = N/A;
        sum += r;
        if(N%A==0) {
            sum -= 1;
        }
    }

    cout << sum << endl;
}

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

#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d",x)
#define prl(x) printf("%lld",x)
#define LL long long
#define pb push_back
#define PB pop_back
#define PF pop_front
#define F first
#define S second
#define inrow(vec)    for(int i=0;i<vec.size();i++)cout<<vec[i]<<" ";
#define incoloum(vec) for(int i=0;i<vec.size();i++)cout<<vec[i]<<endl;

const double PI=3.1415926;
const int KL=1e6;

using namespace std;

LL q,x,y,z,n,m,p[KL],mn=1e9,mx=-1e9,ans;
string t;
vector <LL> vec;
set <int> s;
map <int,int> M;


int main()
{
    scl(x);scl(n);
    for(int i=0;i<n;i++)scl(p[i]);
    LL sum=p[n-1]-p[0];
    for(int i=1;i<n;i++)
    {
        sum=min(sum,p[i-1]+(x-p[i]));
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 1792
#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 = 1e9;

int main() {
  int n, nn, cnt = 0;
  cin >> n;
  nn = n;

  while (n != 0) {
    cnt += n % 10;
    n /= 10;
  }
  cout << (nn % cnt == 0 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int h, w, s;
    while (readf("%d %d %d\n", &h, &w, &s), h || w || s) {
        int[][] u = new int[][h];
        foreach (i; 0 .. h) {
            u[i] = readln.chomp.split(" ").map!(to!int).array;
        }

        int[][] z = new int[][](h + 1, w + 1);
        foreach (i; 0 .. w + 1) z[0][i] = 0;
        foreach (i; 1 .. h + 1) {
            int x = 0;
            foreach (j; 1 .. w + 1) {
                x += u[i - 1][j - 1];
                z[i][j] = z[i - 1][j] + x;
            }
        }

        int f(int sy, int sx, int gy, int gx) {
            return z[gy][gx] - z[sy][gx] - z[gy][sx] + z[sy][sx];
        }

        struct A {
            int c, r;
            const int opCmp(const ref A a) const {
                if (c == a.c) {
                    return r - a.r;
                }
                return c - a.c;
            }
            string toString() {
                return text(c, " ", r);
            }
        }

        int L = z[h][w] - s;

        auto cache = new A[][][][](h, w, h + 1, w + 1);
        A dfs(int sy, int sx, int gy, int gx) {
            //[sy, sx, gy, gx].writeln;
            if (cache[sy][sx][gy][gx].c > 0) 
                return cache[sy][sx][gy][gx];
            auto ret = A(1, f(sy, sx, gy, gx) - L);
            foreach (int y; sy .. gy) {
                int z1 = f(sy, sx, y, gx);
                if (z1 < L) continue;
                int z2 = f(y, sx, gy, gx);
                if (z2 < L) continue;
                auto a = dfs(sy, sx, y, gx);
                auto b = dfs(y, sx, gy, gx);
                ret = max(ret, A(a.c + b.c, min(a.r, b.r)));
            }
            foreach (int x; sx .. gx) {
                int z1 = f(sy, sx, gy, x);
                if (z1 < L) continue;
                int z2 = f(sy, x, gy, gx);
                if (z2 < L) continue;
                auto a = dfs(sy, sx, gy, x);
                auto b = dfs(sy, x, gy, gx);
                ret = max(ret, A(a.c + b.c, min(a.r, b.r)));
            }
            return cache[sy][sx][gy][gx] = ret;
        }

        dfs(0, 0, h, w).writeln;
    }
}

Measured memory_bytes: 57472
#include <stdio.h>

int main(void) 
{
	unsigned int i = 1;
	unsigned int x;
	
	for(i = 0; i <= 10000; i++)
	{
		scanf("%d", &x);
		if(x == 0)
		{
			break;
		}
		printf("Case %d: %d\n", i + 1, x);
	}
	return 0;
}

Measured memory_bytes: 600
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np 
import itertools as it
def main():
    H, W = map(int, readline().split())
    G = np.zeros((H+2, W+2), np.int16)
    G[1:-1, 1:] = (np.frombuffer(read(H*(W+1)), dtype='B') == ord('.')).reshape((H, W+1))
    def solve(G):
        left = np.zeros(G.shape, np.int16)
        for i in range(G.shape[0]):
            left[i, ] = np.arange(G.shape[1])
        left[G>0] = 0
        np.maximum.accumulate(left, out=left, axis=1)

        rG = G[..., ::-1]
        right = np.zeros(G.shape, np.int16)
        for i in range(G.shape[0]): 
            right[i, ] = np.arange(G.shape[1])
        right[rG>0] = 0
        np.maximum.accumulate(right, out=right, axis=1)

        right = G.shape[1] - right[..., ::-1]-1
        scoreres = (right-left-1) 
        scoreres[G==0] = 0
        return scoreres

    print((solve(G)+solve(G.T).T-1).max())
if __name__ == '__main__':
    main()


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
//Write From this Line

// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
mint f(int n ) {
	if (n == 0) return 1 ;
	mint x = f(n/2);
	x *= x;
	if(n%2 == 1) x*= 2;
	return x;
}
mint choose(int n, int a){
	mint x = 1 , y = 1;
	rep(i,a){
		x *= (n-i) ;
		y *= i + 1;
	}
	return x / y;
}
int main()
{
	int n , a , b ;
	cin >> n >> a >> b ;
	//mint(a).pow(b) a^bを返す。
	mint ans = f(n);
	ans -= 1 ;//0本の場合
	ans -= choose(n,a);
	ans -= choose(n,b);
	cout << ans.x << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    static int n = 5;
    static int max;
    static int g[][];

    public static void go(int x, int y, int cur) {
        cur += g[x][y];
        if (x == 0)
            go(x + 1, y, cur);
        if (y < n - 1)
            go(x, y + 1, cur);
        max = Math.max(max, cur);
    }

    public static void main(String... args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        g = new int[2][n];
        for (int i = 0; i < g.length; i++) {
            for (int j = 0; j < g[i].length; j++) {
                g[i][j] = in.nextInt();
            }
        }
        go(0, 0, 0);
        System.out.println(max);
    }
}



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

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

int main()
{
    ll i,j;
    ll n;
    string s;
    cin >> n >> s;
    for(i = 0;i < s.size();++i){
        char tmp = s.at(i);
        tmp = (tmp - 'A' + n)%26 + 'A';
        cout << tmp;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long Q=sc.nextLong();
		long H=sc.nextLong();
		long S=sc.nextLong();
		long D=sc.nextLong();
		
		long[] ichi_li=new long[3];
		long[] ni_li=new long[4];
		
		ichi_li[0]=Q*4;
		ichi_li[1]=H*2;
		ichi_li[2]=S;
		long ichi_saiyasu=Math.min(Math.min(ichi_li[0], ichi_li[1]), ichi_li[2]);
		
		ni_li[0]=Q*8;
		ni_li[1]=H*4;
		ni_li[2]=S*2;
		ni_li[3]=D;
		long ni_saiyasu=Math.min(Math.min(ni_li[0], ni_li[1]), Math.min(ni_li[2], ni_li[3]));
		
		long N=sc.nextLong();
		long sum=0;
		
		if(ichi_saiyasu*2>=ni_saiyasu) {
			System.out.println((N/2)*ni_saiyasu+(N%2)*ichi_saiyasu);
		}
		
		else if(ichi_saiyasu*2<ni_saiyasu) {
			System.out.println(N*ichi_saiyasu);
		}
	}
}

Measured memory_bytes: 23252