akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

/*
全品の重さがw0からそう離れていない
w0を基準点

dp[i][j]
i個までで重さjになったときの価値の総和の最大値

dp[0][i][j]w0のみ選び個数jになったときの価値の総和

*/
ll dp[4][101][101];

int main() {

    ll N, W; cin >> N >> W;
    vector<ll> w(N), v(N);
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];
    for (int k = 0; k <= 3; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= N; j++) {
                dp[k][i+1][j] = dp[k][i][j];
                if (j >= 1) chmax(dp[k][i+1][j],dp[k][i+1][j-1]);
                if (w[i] == w[0]+k && j >= 1) {
                    chmax(dp[k][i+1][j],dp[k][i][j-1]+v[i]);
                }
            }
        }
    }
    ll res = 0;


    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N-i; j++) {
            for (int k = 0; k <= N-i-j; k++) {
                int l = 0, r = N-i-j-k+1;
                ll tmp = W - w[0]*i-(w[0]+1)*j-(w[0]+2)*k;
                if (tmp < 0) continue;
                while (r - l > 1) {
                    int mid = (r+l)/2;
                    if (mid * (w[0]+3) <= tmp) l = mid;
                    else r = mid;
                }
                chmax(res,dp[0][N][i]+dp[1][N][j]+dp[2][N][k]+dp[3][N][l]);
            }
        }
    }
    cout << res << endl;










}


Measured memory_bytes: 512
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {

        static void Main(string[] args)
        {
          //var N = int.Parse(Console.ReadLine());
          //var S = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          var S = Console.ReadLine();
          
          if(S == "SUN"){
            Console.WriteLine(7);
          }else if(S == "MON"){
            Console.WriteLine(6);
          }else if(S == "TUE"){
            Console.WriteLine(5);
          }else if(S == "WED"){
            Console.WriteLine(4);
          }else if(S == "THU"){
            Console.WriteLine(3);
          }else if(S == "FRI"){
            Console.WriteLine(2);
          }else if(S == "SAT"){
            Console.WriteLine(1);
          }
        }
  

}







Measured memory_bytes: 11092
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeMap;



public class Main {
	static Scanner InData = new Scanner(System.in);
	static int qType, qVal;
	static String qKey, qLeft, qRight;
	static TreeMap<String, Integer> M = new TreeMap<String, Integer>();
	public static void main(String[] args) {
		getQuery();
	}
	private static void getQuery() {
		int qNum = InData.nextInt();
		for(int indexOfQuery = 0; indexOfQuery < qNum; indexOfQuery++) {
			qType = InData.nextInt();
			qKey = InData.next();
			doQuery(qType, qKey);
		}
	}
	private static void doQuery(int type, String key) {
		switch(type) {
		case 0:
			qVal = InData.nextInt();
				M.put(key, qVal);
			break;
		case 1:
			if(M.containsKey(key)) 
				System.out.println(M.get(key));
			else
				System.out.println(0);
			break;
		case 2:
			M.remove(key);
			break;
		case 3:
			qLeft = key;
			qRight = InData.next();
			Iterator<String> it = M.subMap(qLeft, qRight + 1).keySet().iterator();
			String outKey;
			while(it.hasNext()) {
				outKey = it.next();
				System.out.println(outKey + " " + M.get(outKey));
			}
			break;
		}
	}
}


Measured memory_bytes: 201412
K, N = map(int, input().split())
A = list(map(int, input().split()))
maxim = 0
for i in range(N-1):
    d = A[i+1] - A[i]
    maxim = max(d, maxim)
maxim = max(K-A[N-1]+A[0], maxim)
print(K - maxim)

Measured memory_bytes: 26420
#include <bits/stdc++.h>
using namespace std;
int p[1000], q[1000];
int grid[1000][1000];
int main(){
    int h,w,a,b;
    scanf("%d%d%d%d",&h,&w,&a,&b);
    //printf("%d %d %d %d\n",h,w,a,b);
    for (int x = 0; x <= h; x++){
        if (((2*a - w)*x - h*a + w*b) % (2*b-h) == 0){
            int y = ((2*a - w)*x - h*a + w*b)/(2*b-h);
            //printf("%d %d\n",x,y);
            for (int i = 0; i < x; i++) p[i] = a;
            for (int i = x; i < h; i++) p[i] = w-a;
            for (int i = 0; i < y; i++) q[i] = b;
            for (int i = y; i < w; i++) q[i] = h-b;
            for (int i = 0; i < h; i++){
                for (int j = 0; j < w; j++){
                    //printf("filling %d %d\n",i,j);
                    if (p[i] && q[j]){
                        grid[i][j] = 1;
                        p[i]--, q[j]--;
                    }
                    else grid[i][j] = 0;
                }
            }
            for (int i = 0; i < h; i++){
                for (int j = 0; j < w; j++){
                    printf("%d",grid[i][j]);
                }
                printf("\n");

            }
            return 0;
        }
    }
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <math.h>

using namespace std;

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)
#define SUMV(v)		(accumulate(v.begin(),v.end(),0.0))

#define INF 		2000000007
#define MOD			998244353

#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int ll;

//uint dp[MAX];


int main(){
	int N,K;cin>>N>>K;
	vector<int> a(N);
	REP(i,N)cin>>a[i];

	int ans = ceil((N-1.0)/(K-1));
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
struct cmp
{
	bool operator() (ll a,ll b){
		return (a>b);
	}
};
ll mod=1000000007;
const ll N=100005;
int main()
{
fast;
    ll n;
    cin>>n;
    ll a[n];
    ll ans=0,c=0;
    f(i,n)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    f(i,n)
    {
        for(ll j=i+1;j<n;j++)
        {
            if(a[j]!=a[i])
            {
                for(ll k=j+1;k<n;k++)
                {
                    if(a[k]!=a[j] && a[k]!=a[i])
                    {
                        if(a[i]+a[j]>a[k])
                            c++;
                    }
                }
            }
        }
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 3652
/*
 * Author:heroming
 * File:heroming.cpp
 * Time:2017/01/15 08:16:12
 */
#include <vector>
#include <list>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;

#define px first
#define py second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define clr(v, e) memset(v, e, sizeof(v))
#define rep(it, v) for (auto it : v)
#define forn(i, n) for (int i = 0; i < (n); ++ i)
#define rforn(i, n) for (int i = (n) - 1; i >= 0; -- i)
#define form(i, a, b) for (int i = (a); i <= (b); ++ i)
#define rform(i, a, b) for (int i = (b); i >= (a); -- i)
#define forv(i, v) for (int i = 0; i < sz(v); ++ i)
#define iter(it, v) for (auto it = v.begin(); it != v.end(); ++ it)

typedef long long lint;
typedef vector<int> vint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef vector<lint> vlint;
typedef vector<pint> vpint;

int main() {
    int a, b, c, d;
    while (cin >> a >> b >> c >> d) {
        cout << max(a * b, c * d) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python3

#標準出力からの読み込み

x, y = input().split(" ")
#a+b=x,2a+4b=y <=> 
#a=2x-y, b=y/2-x
x = int(x)
y = int(y)
a = 2*x - y/2
b = y/2 - x
if y%2 == 1:
    print('No')
elif a<0 or b<0:
    print('No')
else:
    print('Yes')


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


int main(){
    
    int a,b;
    cin>>a;
    cin>>b;
    int max1=max(a,b);
    int min1=min(a,b);
    int top=0;
    //int result=0;
    for(int i=0;i<max1;i++){
        top=top*10;
        top+=min1;
    }
    cout<<top<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sum=0,max=0,mi=0;
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] a = new int [N];
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
		}
		for(int i=0;i<K;i++) {
			for(int j=0;j<N;j++) {
				if(max<a[j]) {
					max=a[j];
					mi=j;
				}
			}
			sum += max;
			max=0;
			a[mi]=0;
		}
		System.out.print(sum);
		sc.close();
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <stack>
#include <vector>
#include <utility>
#include <bitset>
using namespace std;

using Pos = pair<int, int>;
using Visited = bitset<80>;

inline void setVisited(Visited& visited, const Pos& pos) {
  visited.set(pos.first * 8 + pos.second);
}
inline bool isVisited(Visited& visited, const Pos& pos) {
  return visited.test(pos.first * 8 + pos.second);
}
inline bool isSharp(vector<string> board, const Pos& pos) {
  if(pos.first >= board.size()) {
    return false;
  }
  if(pos.second >= board[0].size()) {
    return false;
  }
  return board[pos.first][pos.second] == '#';
}

bool solve(vector<string> board, Visited visited, const Pos& pos) {

  if(pos.first == board.size() - 1 && pos.second == board[0].size() - 1) {
    for(int h = 0; h < board.size(); ++h) {
      for(int w = 0; w < board[h].size(); ++w) {
        if(board[h][w] == '#' && !isVisited(visited, {h, w})) {
          return false;
        }
      }
    }
    return true;
  }

  Pos right = {pos.first, pos.second + 1};
  if(isSharp(board, right)) {
    auto v = visited;
    setVisited(v, right);
    if(solve(board, v, right)) {
      return true;
    }
  }
  Pos down = {pos.first + 1, pos.second};
  if(isSharp(board, down)) {
    auto v = visited;
    setVisited(v, down);
    if(solve(board, v, down)) {
      return true;
    }
  }
  return false;
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> bs(H);
  for(int i = 0; i < H; ++i) {
    cin >> bs[i];
  }

  Visited visited;
  setVisited(visited, {0, 0});
  if(solve(bs, visited, {0, 0})) {
    cout << "Possible" << endl;
    return 0;
  }
  cout << "Impossible" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
s = sum(A)
ans = []
val = s-sum(A[::2])
a1 = s-2*val
ans.append(str(a1))
for i in range(1,n):
    a1 = 2*A[i-1]-a1
    ans.append(str(a1))
print(' '.join(ans))

Measured memory_bytes: 93252
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

#define Int long long
#define rep(i, n) for (Int i = 0; i < n; i++)
#define in(params) cin >> params;
#define p(params) cout << params << endl;
#define mod 1000000007LL

using namespace std;

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

    map<string, Int> m;
    string s;
    Int count = 0;

    for (Int i = 0; i < N; i++)
    {
        cin >> s;
        sort(s.begin(), s.end());

        auto f = m.find(s);

        if (f != m.end())
        {
            m[s]++;
        }
        else
        {
            m[s] = 1;
        }
    }

    for (auto i : m)
    {
        Int num = i.second;
        if (num != 1)
        {
            count += (num * (num - 1)) / 2;
        }
    }

    cout << count << endl;

    return 0;
}

// 1: 0
// 2: 1
// 3: 2
// 4:

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define IO {ios_base::sync_with_stdio(false); cin.tie(0);}
#define ll  long long
#define pi pair<ll,ll>
ll vs[2000], a[2000], b[2000], c[30000];

string s;
int main()
{
    IO;
    ll i, j, k, cnt=0, n, m, mod=1e9, t, mx=0, mn=LLONG_MAX, l, h, r=0, w=0, ovr=0, x, d;
    // cin>>t;
        //while(t--){
            cin>>x>>k>>d; j = k/2-x/(2*d);
            if(j>k) j=k-5; if(j<0)j=0;
            for(i=max(j-5,r); i<=j+5; i++){
                if(i<=k && k-i>=0){
                    mn=min(mn,abs(d*(2*i-k)+x));
                }
            }
            cout<<mn<<endl;
        //}
    return 0;
}


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


int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	
	sort(a, a + 3);
	
	cout << a[0] << " " << a[1] << " " << a[2] << "\n";

	return 0;
}

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

using namespace std;

int MAX_N = 100;

int main(){
	int N, x, a[MAX_N];
	cin >> N >> x;
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}

	sort(a, a + N);
	int ans = 0;
	for(int i = 0; i < N; i++){
		x -= a[i];
		if(x >= 0){
			ans++;
		}else{
			break;
		}
	}
	if(x > 0) ans--;

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


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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
int main(int argc, char const *argv[])
{
	int n;
	scanf("%d",&n);
	vector<int>v(n);
	for(register int i = 0;i < n;i++)	scanf("%d",&v[i]);
	int ans = 0;
	for(register int i = 0;i < n;i++)
		for(register int j = i + 1;j < n;j++)
			for(register int k = j + 1;k < n;k++)
			{
				if(v[i] == v[j] || v[i] == v[k] || v[j] == v[k])	continue;
				ans += v[i] + v[j] > v[k] && v[i] + v[k] > v[j] && v[j] + v[k] > v[i]? 1:0;
			}
	printf("%d\n",ans );
	return 0;
} 

Measured memory_bytes: 3732
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    inf = 10 ** 6
    s = input()
    n = len(s)
    land = [0] * (n + 1)
    for i, c in enumerate(s):
        if c == "/":
            land[i + 1] = land[i] + 1
        elif c == "_":
            land[i + 1] = land[i]
        else:
            land[i + 1] = land[i] - 1
    # print(land)

    water = [0] * (n + 1)
    w = -inf
    i = n
    for l in land[::-1]:
        if l > w: w = l
        water[i] = w
        i -= 1
    w = -inf
    for i, l in enumerate(land):
        if l > w: w = l
        water[i] = min(water[i], w)
    # print(water)

    mm = []
    sum_d = 0
    for w, l in zip(water, land):
        d = w - l
        if d == 0 and sum_d:
            mm.append(sum_d)
            sum_d = 0
        else:
            sum_d += d

    print(sum(mm))
    print(len(mm), *mm)

main()



Measured memory_bytes: 6932
A, B, N = map(int, input().split())

if B > N:
    print(int((A*N)/B)-A*int(N/B))
else:
    print(int((A*(B-1))/B)-A*int((B-1)/B))

# if B > N:
#     ans = floor(A*N/B)
#     print(ans)
# else:
#     ans = floor(A*N/B) - A*floor(N/B)
#     ans_2nd = 0
#     x = (N//B)*B - 1
#     temp = floor((A*x)/B) - A*floor(x/B)
#     # while ans <= temp and x >= 0:
#     #     ans = temp
#     #     temp = floor(A*x/B) - A*floor(x/B)
#     #     x -= B
#     # while ans_2nd <= temp and x >= 0:
#     #     ans_2nd = temp
#     #     temp = floor(A*x/B) - A*floor(x/B)
#     #     x -= B
#     # prfloor(max(ans, ans_2nd))
#     print(max(temp, ans))

Measured memory_bytes: 61544
#include <bits/stdc++.h>
using namespace std;
 
#define  int    long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff         first
#define  ss    second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
 
int32_t main()
{
    fast
    int n,m;
    cin>>n>>m;
    f(i,0,n)
    {
        if(m-2*i>=0 && (m-2*i)%4==0)
        {
            if(i+ (m-2*i)/4 ==n)
            {
                cout<<"Yes";
                exit(0);
            }
        }
    }
    cout<<"No";
}

Measured memory_bytes: 3648
#include<stdio.h>

int main()
{
	int N,a[110],sum=0;
	scanf("%d",&N);
	for(int i=1; i<=N; i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	int M,ans;
	scanf("%d",&M);
	while(M--)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		ans=sum+(y-a[x]);
		printf("%d\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

ll f[105][10];
ll p[105][10];
int main(){FIN
    ll n;cin>>n;
    REP(i,n) REP(j,10){
        cin >> f[i][j];
    }
    REP(i,n) REP(j,11){
        cin>>p[i][j];
    }
    ll ans= (-1) * inf;
    for(ll i=1; i<(1<<10);i++){
        ll val=0;
        REP(j,n){
            ll cnt=0;
            REP(k,10){
                if ((i>>k)&1 && f[j][k]) cnt++;
            }
            val += p[j][cnt];
        }
        ans = max(ans, val);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int a[4500];
int main(){
	int l,r;
	cin>>l>>r;
	int x=min(r-l+1,4038);
	for(int i=1;i<=x;i++){
		a[i]=(i-1+l)%2019;
	}
	int minn=9999;
	for(int i=1;i<=x;i++){
		for(int j=i+1;j<=x;j++){
//			cout<<"i:"<<i<<"j:"<<j;
			minn=min(minn,((a[i]%2019)*(a[j]%2019))%2019);
//			cout<<"minn:"<<minn<<endl;
		}
	}
//	cout<<x<<endl; 
	cout<<minn;
	return 0;
} 

Measured memory_bytes: 256
while True:
    n, r = map(int, input().split())
    if n == 0:
        break
    else:
        cards = list(reversed(range(n)))
        for _ in range(r):
            p, c = map(int, input().split())
            for i,x in enumerate(cards):
                if 0 <= x < p-1:
                    cards[i] += c
                elif p-1 <= x < p-1+c:
                    cards[i] -= p-1
                else:
                    pass
        for i,x in enumerate(cards):
            if x == 0:
                print(i+1)


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  string s;
  cin >> s;
  int count = 0;
  rep(i, s.size()){
    if (s[i] == '1'){
      count++;
    }
  }
  cout << count << endl;
}

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

int d1[4][2] = {
	{0, -1},
	{1, 0},
	{0, 1},
	{-1, 0}
};

int d2[4][2] = {
	{-1, -1},
	{1, -1},
	{-1, 1},
	{1, 1}
};

int main(int argc, char **argv)
{
	int **a = (int *)calloc(10, sizeof(int));
	int n, i, j, x, y, s, tmp, tmp2;
	
	for(i = 0; i < 10; i++){
		a[i] = (int *)calloc(10, sizeof(int));
	}
	
	while(scanf("%d,%d,%d", &x, &y, &s) != EOF){
		a[x][y]++;
		for(i = 0; i < 4; i++){
			tmp = x+d1[i][0];
			tmp2 = y+d1[i][1];
			if(tmp >= 0 && tmp <= 9 && tmp2 >= 0 && tmp2 <= 9){
				a[tmp][tmp2]++;
			}
		}
		if(s == 1){
			continue;
		}
		
		for(i = 0; i < 4; i++){
			tmp = x+d2[i][0];
			tmp2 = y+d2[i][1];
			if(tmp >= 0 && tmp <= 9 && tmp2 >= 0 && tmp2 <= 9){
				a[tmp][tmp2]++;
			}
		}
		
		if(s == 2){
			continue;
		}
		
		for(i = 0; i < 4; i++){
			tmp = x+2*d1[i][0];
			tmp2 = y+2*d1[i][1];
			if(tmp >= 0 && tmp <= 9 && tmp2 >= 0 && tmp2 <= 9){
				a[tmp][tmp2]++;
			}
		}
	}
	tmp = 0;
	tmp2 = 0;
	for(i = 0; i < 10; i++){
		for(j = 0; j < 10; j++){
			if(a[i][j] == 0){
				tmp++;
			} else if(a[i][j] > tmp2){
				tmp2 = a[i][j];
			}
		}
	}
	
	printf("%d\n%d\n", tmp, tmp2);
	
	for(i = 0; i < 10; i++){
		free(a[i]);
	}
	free(a);
	
	return 0;
}

Measured memory_bytes: 0
{-# LANGUAGE ScopedTypeVariables #-}

import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Char
import Control.Monad

solve :: VU.Vector Int -> Int -> Int -> Int -> Int
solve vec n acc i 
    | (acc+v) >= n = i 
    | otherwise = solve vec n (acc+v) (i+1)
    where
        v = vec VU.! i

main = do
    [n, t] <- map read . words <$> getLine :: IO [Int]
    (vec :: VUM.IOVector Int) <- VUM.replicate (10^5+1) 0 
    forM_ [1..n] $ \_ -> do
        bs <- B.getLine
        let
            Just (a, bs') = B.readInt bs
            Just (b, _) = B.readInt $ B.dropWhile isSpace bs'
        VUM.modify vec (+b) a
    vec' <- VU.unsafeFreeze vec
    print $ solve vec' t 0 0

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a=scanner.nextInt(), b= scanner.nextInt(), c= scanner.nextInt(), d= scanner.nextInt();
		
		int left = a+b;
		int right = c+d;
		
		String ans = "default";
		if (left<right) {
			ans = "Right";
		}else if (left==right) {
			ans = "Balanced";
		}else {
			ans = "Left";
		}
		
		System.out.println(ans);
		scanner.close();
	}
}

Measured memory_bytes: 21972
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            long N = cin.ReadLong;
            string S = cin.ReadLine;
            char[] C = S.ToCharArray();
            long count = 1;
            for(long i = 0; i < N-1; i++)
            {
                if (C[i] != C[i + 1])
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
            

                
    }  
            


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}


Measured memory_bytes: 13304
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String t = sc.next();
		sc.close();

		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < n; i++) {
			sb.append(s.charAt(i));
			sb.append(t.charAt(i));
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=150;
//↑templete
#define int long long
signed main(){

	string S;
	cin>>S;
	int K;
	cin>>K;

	int N=S.length();
	reverse(S.begin(), S.end());

	ll DP[SIZE][SIZE][2]={};	//DP[i][j]=i桁の数字でSの上からi桁より小さいもののなかで、0でない数字がj個のものの数
	DP[N][0][0]=1;
	for(int i=N;i>=1;i--){
		for(int j=0;j<=K;j++){
			for(int k=0;k<=9;k++){
				int now=S[i-1]-'0';

				//すでに小さいことが確定している遷移
				if(k==0)
					DP[i-1][j][1] += DP[i][j][1];
				else
					DP[i-1][j+1][1] += DP[i][j][1];
				
				//まだ小さいことが確定していない遷移
				if(k==0){
					if(now==0)
						DP[i-1][j][0] += DP[i][j][0];
					else
						DP[i-1][j][1] += DP[i][j][0];
				}
				else{
					if(k<now)
						DP[i-1][j+1][1] += DP[i][j][0];
					else if(k==now)
						DP[i-1][j+1][0] += DP[i][j][0];
				}

			}
		}
	}
	ll ans=0;
	cout<<DP[0][K][0]+DP[0][K][1]<<endl;
	return 0;
}

Measured memory_bytes: 640
/*...................bismillahir rahmanir rahim.....................*/
/*
  author :
    Muhammad Najmul hasan Nayeem
    Sust Math 17
*/
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// using namespace __gnu_pbds;
 
using namespace std;

#define m_p make_pair
#define PB push_back
#define eb emplace_back
#define FF first
#define SS second
#define MX5 100005
#define MX6 1000006
#define MOD 1000000007
#define in()({int a;scanf("%d",&a);a;})
#define SI(a) scanf("%d",&a)
#define SII(a,b) scanf("%d%d",&a,&b)
#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SC()({char a;scanf("%c",&a);a;})
#define SL()({long long a;scanf("%lld",&a);a;})
#define SD()({double a;scanf("%f",&a);a;})
#define nl '\n'
#define For(_,n) for(int i=_;i<=n;i++)
#define once "once upon a time\n"
#define FI freopen("input.txt","r+",stdin);
#define FO freopen("output.txt","w+",stdout);
 
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<string,string> PSS;
// typedef tree<PII,null_type,less<PII>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out << "(" << a.FF << ", " << a.SS << ")";
}
 
template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
    out << "[";
    for(int i=0;i<v.size();i++) {
        if(i) out << ", ";
        out << v[i];
    }
    return out << "]";
}
 
#define chk(a) cout<<(#a)<<" = "<<a<<endl;
#define chka(a,_) cout<<(#a)<<"["<<_<<"] = "<<a[_]<<"\n";

// int Set(int n,int pos){ return n | (1<<pos); }
// int Reset(int n,int pos){ return n=n & ~(1<<pos); }
// bool Check(int n,int pos){ return (bool)(n & (1<<pos)); }
 
/*............start.............*/

void solve()
{
    int n;
    cin>>n;
    LL res=0;
    for(int i=1;i<=n;i++)
    {
        res+=(n-1)/i;
    }
    cout<<res<<nl;
}
int main()
{
    // clock_t time_start=clock();
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int q=1;
    // cin>>q;
    // SI(q);
    for(int kase=1;kase<=q;kase++)
    {
        // cout<<"Case "<<kase<<": ";
        // printf("Case %d: ",kase );
        solve();
    }
    // clock_t time_end=clock();
    // cerr<<float((time_end-time_start)/CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 3648
N=int(input())
A=list(map(int,input().split()))+[0]

data=[[] for i in range(2**N)]

for i in range(1,2**N):
    for j in range(N):
        if i&(1<<j)==0:
            continue
        else:
            data[i].append(i-(1<<j))

MAX=[0]*2**N
semiMAX=[0]*2**N

semiMAX[0]=2**N

if MAX[0]<A[1]:
    MAX[1]=1
    semiMAX[1]=0
else:
    MAX[1]=0
    semiMAX[1]=1

K=[A[0]+A[1]]
for k in range(2,2**N):
    a,b=k,2**N
    for u in data[k]:
        c,d=MAX[u],semiMAX[u]
        if A[c]<=A[b]:
            c=c
        elif A[d]>=A[a]:
            a,b=c,d
        elif A[c]>A[a]:
            a,b=c,a
        elif A[a]>=A[c]>A[b] and a!=c:
            b=c
        elif A[a]>=A[d]>A[b] and a!=d:
            b=d
    MAX[k]=a
    semiMAX[k]=b
    K.append(max(K[-1],A[a]+A[b]))

for u in K:
    print(u)

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

int main(){
int n;
int x;
cin >> n >> x;
vector<int>a(n);
for (int i = 0; i < n; i++)
{
  cin >> a.at(i);
}
sort(a.begin(), a.end());
int ans = 0;
int j = 0;
while (x>0 && ans <n){
  x -= a.at(j);
  j++;
  ans++;
}

if(x != 0){
  ans--;
}   
  cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

class UnionFind {
public:
  vector<int> Parent;
  UnionFind(int n) {
    Parent = vector<int>(n, -1);
  }
  int root(int a) {
    if (Parent[a]<0) return a;
    return Parent[a] = root(Parent[a]);
  }
  int size(int a) {
    return -Parent[root(a)];
  }
  bool connect(int a, int b) {
    a = root(a);
    b = root(b);
    if (a==b) return false;
    if (size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;
    return true;
  }
};

void solve()
{
  ll n,m; cin>>n>>m;
  vector<ll> a(m, 0);
  vector<ll> b(m, 0);
  for (int i=0; i<m; i++) {
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
  }
  vector<ll> ans(m);
  ans[m-1] = n * (n-1) / 2;

  UnionFind uni(n);

  for (int i=m-1; i>=1; i--) {
    ans[i-1] = ans[i];
    if (uni.root(a[i]) != uni.root(b[i])) {
      ans[i-1] -= (ll)uni.size(a[i])*uni.size(b[i]);
      uni.connect(a[i], b[i]);
    }
  }
  for (int i=0; i<m; i++) {
    cout << ans[i] << endl;
  }
}

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


Measured memory_bytes: 4096
#include <iostream>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main(){
  int n,i,j;
  cin >> n;
  double x[n];
  double y[n];
  double d1,d2,d3,di=0;
  for(i = 0; i < 2; i++){
    for(j = 0; j < n; j++){
      if(i == 0) cin >> x[j];
      if(i == 1) cin >> y[j];
    }
  }
  for(i = 0; i < n; i++){
    d1 += pow(fabs(x[i] - y[i]), 1);
  }
  for(i = 0; i < n; i++){
    d2 += pow(fabs(x[i] - y[i]), 2);
  }
  for(i = 0; i < n; i++){
    d3 += pow(fabs(x[i] - y[i]), 3);
  }
  for(i = 0; i < n; i++){
    di = max( di, (double)abs(x[i] - y[i]) );
  }

  cout << fixed << setprecision(10) << pow(d1,1.0/1)   << endl;
  cout << fixed << setprecision(10) <<pow(d2,1.0/2)   << endl;
  cout << fixed << setprecision(10) <<pow(d3,1.0/3)   << endl;
  cout << fixed << setprecision(10) << di << endl;
}



Measured memory_bytes: 3456
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { A: number[] } => {
  const A = lines.map(line => +line)
  A.shift()
  const obj = { A }
  debug(obj)
  return obj
}

// solver
export const solve = (lines: string[]): string => {
  const { A } = parseLines(lines)
  const sorted = [...A].sort((a, b) => b - a)
  return A.map(n => n === sorted[0] ? sorted[1] : sorted[0]).join('\n')
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 47704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
constexpr int mod = 1e9 + 7;
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
vector<long long> divisor(long long n){
    vector<long long> res;
    for(long long i = 1; i*i <= n; i++){
        if(n%i==0){
            res.push_back(i);
            if(n/i != i)res.push_back(n/i);
        }
    }
    return res;
}
int main() {
  int n, k;
  cin >> n >> k;

  mint res = 0;

  map<int,mint> mp;
  vector<mint> cnt(k + 1, 0);

  for (int x = 1; x <= k; x++) {
    auto div = divisor(x);
    for (auto e : div) mp[e] += 1;
  }
  for (int x = k; x >= 1; x--) {
    mint tmp = mp[x].pow(n);
    for (ll y = x + x; y <= k; y += x) {
      tmp -= cnt[y];
    }
    cnt[x] = tmp;
    res += tmp * x;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 10336
using System;

namespace Sorts
{
    class Program
    {
        public struct Card
        {
            public readonly char m;
            public readonly int n;
            public Card(char m, int n)
            {
                this.m = m;
                this.n = n;
            }
        }

        private static Card[] B_Sort(Card[] ca)
        {
            var c = new Card[ca.Length];
            Array.Copy(ca, 0, c, 0, c.Length);
            for (var i = 0; i < c.Length; i++)
                for (var j = c.Length - 1; j > i; j--)
                    if (c[j].n < c[j - 1].n)
                    {
                        var t = c[j];
                        c[j] = c[j - 1];
                        c[j - 1] = t;
                    }
            return c;
        }

        private static Card[] S_Sort(Card[] ca)
        {
            var c = new Card[ca.Length];
            Array.Copy(ca, 0, c, 0, c.Length);
            for (var i = 0; i < c.Length; i++)
            {
                var m = i;
                for (var j = i; j < c.Length; j++)
                {
                    if (c[m].n > c[j].n)
                        m = j;
                }
                var t = c[m];
                c[m] = c[i]; c[i] = t;
            }
            return c;
        }

        private static string Join(Card[] ca)
        {
            var s = string.Join(" ", Array.ConvertAll(ca, 
                    e => string.Format("{0}{1}", e.m, e.n)));
            return s;
        }

        public static void Main()
        {
            Console.ReadLine();
            var i = Console.ReadLine().Split();
            var cards = new Card[i.Length];
            for(int j = 0; j < i.Length; j++)
            {
                var m = i[j][0];
                var n = int.Parse(i[j].Remove(0, 1));
                cards[j] = new Card(m, n);
            }
            var b_cards = Join(B_Sort(cards));
            var s_cards = Join(S_Sort(cards));
            Console.WriteLine("{0}", b_cards);
            Console.WriteLine("Stable");
            Console.WriteLine("{0}", s_cards);
            Console.WriteLine("{0}", b_cards == s_cards ? "Stable" : "Not stable");
        }
    }
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

int n, k;
const int N = 2e5 + 10;
double a[N];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int l = 1, h = 1e9 + 10, ans = h;
    while(l <= h) {
        int m = l + h >> 1;
        int cut = 0;
        for(int i = 1; i <= n; i++) {
            cut += ceil(a[i]/m) - 1;
        }
        if(cut <= k) {
            ans = min(ans, m);
            h = m - 1;
        }
        else {
            l = m + 1;
        }
    }
    cout << ans << endl;

    return 0;
}



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

int n;
vector<vector<vector<double>>> dp;

double f(int a, int b, int c){
    if(dp[a][b][c] != -1) return dp[a][b][c];

    //cout << a << " " << b << " " << c << endl;
    double ev = 1;
    if(a >= 1) ev += a / (double)n * f(a-1, b,   c  );
    if(b >= 1) ev += b / (double)n * f(a+1, b-1, c  );
    if(c >= 1) ev += c / (double)n * f(a,   b+1, c-1);
    //cout << ev << endl;
    ev /= (a+b+c) / (double)n;//1 - (n-a-b-c) / n;

    dp[a][b][c] = ev;
    return ev;
}

int main(){
    cin >> n;
    dp.assign(n+1, vector<vector<double>>(n+1, vector<double>(n+1, -1)));
    dp[0][0][0] = 0;

    vector<int> sushi(4);
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        sushi[a] += 1;
    }
    cout << fixed << setprecision(12) << f(sushi[1], sushi[2], sushi[3]) << endl;
    return 0;
}

Measured memory_bytes: 216960
#include <iostream>

#include <fstream>

#include <vector>
#include <set>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

#include <algorithm>
#include <iomanip>
#include <cmath>
#include <random>
#include <cstdlib>
#include <ctime>
#include <utility>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define F first
#define S second
#define forcin(n, a) for(int i = 0; i < n; ++i) {cin >> a[i];}
#define forcout(n, a) for(int i = 0; i < n; ++i) {cout << a[i] << " ";}
#define PI acos(-1)
#define forup(st, fin) for(int i = st; i < fin; ++i)
#define fordown(st, fin) for(int i = st; i >= fin; --i)
#define reverse_all(v) reverse(v.begin(), v.end())
#define sort_all(v) sort(v.begin(), v.end())
#define sort_allr(v) sort(v.rbegin(), v.rend())
#define mmin(a, b, c) min(min(a, b), c)
#define mmax(a, b, c) max(max(a, b), c)

///#define cin in
///#define cout out
///#define int long long

const ll MAXL = 1e18;
const int N = 10005000;
const int MAXN = 1e9 + 7;

vector<ll> v;

ll check(ll val) {
    ll ans = 0;
    for (auto i : v) {
        ans += abs(i - val);
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(time(NULL));
    ll n, sum = 0, mini = MAXN, maxi = -MAXN;
    cin >> n;
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        v[i] -= ll(i + 1);
        sum += v[i];
        mini = min(mini, v[i]);
        maxi = max(maxi, v[i]);
    }
    ll l = mini, r = maxi;
    while (l < r - 2) {
        ll tl = l + (r - l) / 3, tr = r - (r - l) / 3;
        if (check(tl) < check(tr)) {
            r = tr;
        } else {
            l = tl;
        }
    }
    cout << min(min(check(l), check(r)), min(check(l + 1), check(r - 1)));
    return 0;
}

/*
 *
 */

Measured memory_bytes: 1792
#include <cstdio>
#include <vector>

int main() {
  std::vector<int> ans;
  while (1) {
    int n, x;
    scanf("%d %d", &n, &x);
    int ans_cnt = 0;
    if (n == 0 && x == 0)
    {
      break;
    }
    for (int i = 1; i <= n; i++)
    {
      for (int j = i + 1; j <= n; j++)
      {
        for (int k = j + 1; k <= n; k++)
        {
          if (i + j + k == x){
            ans_cnt++;
          }
        }
      }
    }
    ans.push_back(ans_cnt);
  }
  if (!ans.empty()) {
    for (int i = 0; i < ans.size(); i++)
    {
      printf("%d\n", ans[i]);
    }
  }
  return 0;
}


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

  using namespace std;
  using namespace std::chrono; 

  typedef long long int ll;

  #define MOD (ll)(1e9+7)
  #define endl "\n"
  #define pb push_back
  #define TEST_CASES  ll t;cin>>t;while(t--)
  #define forn(i,a,n) for (int i = a; i < n; ++i)
  #define f first
  #define s second
  #define all(x) x.begin(), x.end()
  
  ll powD(ll x,ll y){
    ll res = 1;
    while(y > 0){
      if(y & 1)
        res = (res*x)%MOD;
      x = (x*x)%MOD;
      y = y>>1;
    }
    return res;
  }


  int main()
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x;
    cin>>x;
    if(x >= 400 && x <= 599)
      cout<<8<<endl;
    else if(x >= 600 && x <= 799)
      cout<<7<<endl;
    else if(x >= 800 && x <= 999)
      cout<<6<<endl;
    else if(x >= 1000 && x <= 1199)
      cout<<5<<endl;
    else if(x >= 1200 && x <= 1399)
      cout<<4<<endl;
    else if(x >= 1400 && x <= 1599)
      cout<<3<<endl;
    else if(x >= 1600 && x <= 1799)
      cout<<2<<endl;
    else if(x >= 1800 && x <= 1999)
      cout<<1<<endl;
  }
   
  

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	constexpr Int MOD = 1e9 + 7;
	Int N, K;
	cin >> N >> K;
	vector<Int> a(N), pos, neg;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		if (a[i] > 0) { pos.emplace_back(a[i]); }
		if (a[i] < 0) { neg.emplace_back(abs(a[i])); }
	}

	int pos_sz = pos.size(), neg_sz = neg.size();
	if ((pos_sz + neg_sz/2*2 >= K) && (pos_sz > 0 || K % 2 == 0)) {
		sort(pos.rbegin(), pos.rend());
		sort(neg.rbegin(), neg.rend());
		Int ans = (K % 2 ? pos[0] : 1);
		vector<Int> X;
		for (int i = K % 2; i + 1 < pos_sz; i += 2) {
			X.emplace_back(pos[i] * pos[i + 1]);
		}
		for (int i = 0; i + 1 < neg_sz; i += 2) {
			X.emplace_back(neg[i] * neg[i + 1]);
		}
		sort(X.rbegin(), X.rend());
		for (int i = 0; i < K / 2; ++i) { (ans *= X[i] % MOD) %= MOD; }
		cout << ans % MOD << endl;
	} else {
		for (int i = 0; i < N; ++i) { a[i] = abs(a[i]); }
		sort(a.begin(), a.end());
		Int ans = 1;
		for (int i = 0; i < K; ++i) { (ans *= a[i]) %= MOD; }
		cout << (MOD - ans) % MOD << endl;
	}

	return 0;
}


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

int main(){
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  int vec[110000];
  vec[0]=0;
  for(int i=0;i<s.size()+1;i++){
    if(i==0){
      vec[i+1]=0;
    }
    else{
      if(s[i-1]=='A'&&s[i]=='C'){
        vec[i+1]=vec[i]+1;
      }
      else{
        vec[i+1]=vec[i];
      }
    }
  }
  for(int i=0;i<q;i++){
    int a,b;
    cin>>a>>b;
    cout<<vec[b]-vec[a]<<endl;
  }
}

Measured memory_bytes: 4180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer stok;

    String nextToken() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            stok = new StringTokenizer(s);
        }
        return stok.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    char nextChar() throws IOException {
        return (char) (br.read());
    }

    String nextLine() throws IOException {
        return br.readLine();
    }

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
//        if (k == 1) {
//            if (n == 1 || m == 1) {
//                out.println("Yes");
//            } else {
//                out.println("No");
//            }
//            return;
//        }
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= m; j++) {
                int cur = i * m + j * n - 2* i * j;
                if (cur == k) {
                    out.println("Yes");
                    return;
                }
            }
        }
        out.println("No");

    }

    void run() throws IOException {
        // br = new BufferedReader(new FileReader("dragons.in"));
        //out = new PrintWriter("dragons.out");
        // br = new BufferedReader(new FileReader("input.txt"));
        // out = new PrintWriter("output.txt");
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        br.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        // Locale.setDefault(Locale.US);
        new Main().run();
    }
}

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

int main(){
	int n,a[5000];
	while(cin>>n){
		if(n==0)break;
		int c=0,k=-100000;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;i<n;i++){
			c=0;
			for(int j=i;j<n;j++){
				c+=a[j];
				if(k<c)k=c;
			}
		}
		cout<<k<<endl;
	}
	return 0;
}


Measured memory_bytes: 3056