akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
        int a,b,h,m;cin>>a>>b>>h>>m;
    long double angle=abs(30*h-5.5*m);
    long double Cos=cos((angle*PI)/180.0);
    long double ans=-2*a*b*Cos+a*a+b*b;
    ans=sqrt(ans);
    cout<<setprecision(15)<<fixed<<ans<<endl;    
    return 0;
}

Measured memory_bytes: 4156
# coding=utf-8
N=int(1e5+10)
n=input()
a=map(int,raw_input().split())
ans=1;lst=a[0];up=-1;
for i in range(1,len(a)):
    if up==-1:
        if(lst>a[i]): up=0
        if(lst<a[i]): up=1
    else:
        if(up==0 and lst<a[i]): ans=ans+1;up=-1
        if(up==1 and lst>a[i]): ans=ans+1;up=-1
    lst=a[i]
print ans


Measured memory_bytes: 11320
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N):
    ans = 0
    for a in range(1, N):
        b = N // a
        if N % a == 0: b -= 1
        ans += b
    print(ans)


if __name__ == '__main__':
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    # A = [int(i) for i in input().split()]
    # B = [int(i) for i in input().split()]
    # AB = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


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

const int INF = 100000000;
const int NMAX = 210;

int main() {
  int h, w, c[10][10], A[NMAX][NMAX];
  cin >> h >> w;

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> c[i][j];
    }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
      }
    }
  }

  int ans = 0;
  int x;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> x;
      if (x >= 0) ans += c[x][1];
    }
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var s = [];
	var x,y,z;
	if(n===0){
		console.log(0);
		return 0;
	}
	while(n!==0){
		if(n>0){
			x = (Math.ceil(Math.log2(3*n+1)/2)-1)*2;
		}else{
			x = (Math.ceil(Math.log2(1-3*n/2)/2))*2-1;
		}
		s[Math.floor(x)] = 1;
		n -= Math.pow(-2,x);
	}
	var l = s.length;
	var ans = '';
	for(var i = l-1; i > -1; i--){
		if(s[i]!==1) s[i] = 0;
		ans += s[i].toString(10);
	}
	console.log(ans);
	

}

Measured memory_bytes: 21064
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
int main(void)
{
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	printf("%f\n",sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2)));
}

Measured memory_bytes: 1228
# https://atcoder.jp/contests/abc146/tasks/abc146_b
A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

N = int(input())
S = list(input())

A_LIST = list(A)

result = []

for i in range(len(S)):
    for wi in range(len(A_LIST)):
        # S[i] 文字は wi番目のアルファベット
        if S[i] == A_LIST[wi]:
            ss = (N + wi) % 26
            result.append(A_LIST[ss])

print("".join(result))


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

typedef long long ll;
typedef pair<int,int>P;
#define INF 99999999
#define MOD (ll)(1e9+7)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

/*--------------------------------------------*/
/*ll factorial(ll);
void list_Prime(ll);
ll divisor(ll);*/
/*--------------------------------------------*/


int main(){
    int n;cin>>n;
    vector<ll> a(5,0);//marchの順に個数を格納
    rep(i,n){
       string s;cin>>s;
       if(s[0]=='M')a[0]++;
       if(s[0]=='A')a[1]++;
       if(s[0]=='R')a[2]++;
       if(s[0]=='C')a[3]++;
       if(s[0]=='H')a[4]++;
    }
    //rep(i,5)printf("a[%d]=%d\n",i,a[i]);
    ll cnt=0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                cnt+=a[i]*a[j]*a[k];
            }
        }
    }
    cout<<cnt<<endl;
}



/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}


void list_Prime(ll n){//n以下の素数を全て見つける
    ll Limit=(int)sqrt((double)n);
    for(ll i=2;i<=n;i++)prime[i]=1;//最初はみんな素数かも
    //素数の整数倍を消していく(ルートnまで)
    for(ll i=2;i<=Limit;i++){
        if(prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    prime[j]=0;                
                }
            }
        }
    }
}

ll divisor(ll n){
    for(ll i=2;i<=n;i++){
        ll d=1;
        ll tmp=i;
        while(tmp>0){
            d++;
            while(tmp%d==0){
                prime[i]++;
                tmp/=i;
            }
        }
    }
    ll sum=1;
    for(ll i=2;;i<=n;i++){
        sum*=(prime[i]+1)/MOD;
    }    
    cout<<"sum="<<sum<<endl;

    return sum%MOD;
}
*/


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

using namespace std;

int H, W;
int cnt[26];
vector<int> demand;

int main(void)
{
	cin >> H >> W;
	char c;
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> c;
			cnt[c - 'a']++;
		}
	}
	
	for(int i = 0; i < H/2; i++){
		for(int j = 0; j < W/2; j++){
			demand.push_back(4);
		}
	}
	if(H % 2){
		for(int i = 0; i < W/2; i++) demand.push_back(2);
	}
	if(W % 2){
		for(int i = 0; i < H/2; i++) demand.push_back(2);
	}
	if(H * W % 2){
		demand.push_back(1);
	}
	
	bool flag;
	bool ans;
	
	for(int i = 0; i < (int)demand.size(); i++){
		flag = false;
		for(int j = 0; j < 26; j++){
			if(cnt[j] <= 0) continue;
			if(cnt[j] >= demand[i]){
				cnt[j] -= demand[i];
				flag = true;
				break;
			}
		}
		if(!flag){
			ans = false;
			goto end;
		}
	}
	ans = true;
	
	end:
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
/*input
5
10
8
5
3
2
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 100090
#define INF 0x3f3f3f3f

int n , x[MAX] , a[MAX];
int32_t main(){
    IOS;
    cin >> n;
    REP(i , 1 , n + 1) cin >> x[i] , a[i] = x[i];
    sort(a + 1 , a + 1 + n);
    map<int , int> cc;
    REP(i , 1 , n + 1) cc[a[i]] = i;
    int ans = 0;
    REP(i , 1 , n + 1) if(i % 2 != cc[x[i]] % 2) ans ++;
    cout << (ans + 1) / 2 << endl;
    return 0;
}

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

int main()
{
	string str;
	int a[26] = { 0 };
	char c;

	while (cin >> str) {

		int n = 0;

		for (unsigned int i = 0; i < str.size(); i++) {
			if (str[i] >= 'a' && str[i] <= 'z') {
				n = str[i] - 'a';
				a[n]++;
			}
			else if (str[i] >= 'A' && str[i] <= 'Z') {
				n = str[i] - 'A';
				a[n]++;
			}
		}
	}

	for (int i = 0; i < 26; i++) {
		c = 'a' + i;
		cout << c << " : " << a[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3172
let N=Int(readLine()!)!,A=readLine()!.characters.split(" ").map{Int(String($0))!}
var ope=0,ans=1
for i in 1..<N{
  if A[i-1]<A[i]{
    if ope<0{
      ans++
      ope=0
    }else{
      ope=1
    }
  }else if A[i-1]>A[i]{
    if ope>0{
      ans++
      ope=0
    }else{
      ope=(-1)
    }
  }
}
print(ans) 

Measured memory_bytes: 7736
#include<bits/stdc++.h>
using namespace std;
int W;
int main()
{
	while(true){
		scanf("%d",&W);
		if(W==-1)break;
		int cost=1150;
		if(W>=10){
			cost+=125*min(10,W-10);
		}
		if(W>=20){
			cost+=140*min(10,W-20);
		}
		if(W>=30){
			cost+=160*(W-30);
		}
		printf("%d\n",4280-cost);
	}
	return 0;
}

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

// Macros
#define F  first
#define S  second
#define PB push_back

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// HELPERS
//  Tedious Grid Movements
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
inline bool move_okay(int x, int y, int n, int m) { return 0 <= x and x < n and 0 <= y and y < m; }
//  Remember:
//   * vec.assign() GOOD; vec.resize() BAD
//   * comparator uses <


// CODE STARTS HERE

void solve(){
	int k;
	cin >> k;

	const ll MOD = k;

	ll term = 0;
	for(int i = 1; i <= 2 * k; ++i){
		term = (10 * term + 7) % MOD;

		if(term == 0){
			cout << i << "\n";
			return;
		}
	}

	cout << "-1\n";
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


Measured memory_bytes: 3648
defmodule Main do
  def main do
    [a, b] =
      IO.read(:line)
      |> String.trim
      |> String.split(" ")
    a = String.to_integer(a)
    b = String.to_integer(b)
    IO.puts(a..b |> Enum.to_list |> Enum.filter(fn x -> Integer.digits(x) == Enum.reverse(Integer.digits(x)) end) |> length)
  end
end


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

int main(){
  int N,k;
  cin>>N>>k;
  string S;
  cin>>S;
  k--;
  if(S[k]=='A'){
    S[k]='a';
  }
  if(S[k]=='B'){
    S[k]='b';
  }
  if(S[k]=='C'){
    S[k]='c';
  }
  cout<<S<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 333, mod = 998244353;
bitset<maxn> e[maxn];
int power(int x){
	int v = 1;
	for(int i = 0; i < x; i++){
		v *= 2;
		if(v >= mod) v -= mod;
	}
	return v;
}
int main(){
	int n, m; cin >> n >> m; int rnk = 0;
	for(int i = 0; i < n; i++){
		bitset<maxn> now;
		for(int j = 0; j < m; j++){
			int v; cin >> v;
			now[j] = v == 1;
		}
		for(int j = 0; j < m; j++){
			if(e[j][j] && now[j]){
				now ^= e[j];
			} else if(now[j]){
				e[j] = now;
				rnk++;
				break;
			}
		}
	}
	int ans = power(n + m - 1);
	ans += mod - power(n + m - 1 - rnk);
	if(ans >= mod) ans -= mod;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
while True :
    n, m, a = map(int, input().split())
    if n == 0 and m == 0 and a == 0 :
        break
    
    org_num = []
    for i in range(n) :
        org_num.append(i+1)
        
    amida = []
    for i in range(m) :
        h, p, q = map(int, input().split())
        amida.append([h, p, q])
    amida.sort(reverse=True) # 横線の高い順にソート
    
    for i in range(m) :
        org_num[amida[i][1]-1], org_num[amida[i][2]-1] = org_num[amida[i][2]-1], org_num[amida[i][1]-1]
    
    print(org_num.index(a)+1)
        


Measured memory_bytes: 5624
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<long long>> vvi;

int main() {
	int N;
	cin>>N;
	vector<pair<long long,int>> a(N);
	for (int i = 0; i < N; i++){
		cin>>a[i].first;
		a[i].second=i;
	}
	sort(a.begin(),a.end(),[](auto &a, auto &b){return a.first>b.first;});
	vvi dp(N+1,vector<long long>(N+1));
	for (int i = 0; i < N; i++){
		for (int l = 0; l <= i+1; l++){
			int r=i+1-l;
			if(l==0)dp[l][r]=dp[l][r-1]+a[i].first*abs(N-r-a[i].second);
			else if(l==i+1)dp[l][r]=dp[l-1][r]+a[i].first*abs(l-1-a[i].second);
			else dp[l][r]=max(dp[l-1][r]+a[i].first*abs(l-1-a[i].second),
				dp[l][r-1]+a[i].first*abs(N-r-a[i].second));
		}
	}
	long long ans=0;
	for (int i = 0; i < N+1; i++){
		ans=max(ans,dp[i][N-i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 34728
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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 operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return 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;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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

int main() {
	double A, B, H, M;
	cin >> A >> B >> H >> M;

	double m = 60.0 * H + M;

	double pi = acos(-1);

	double x = B * cos(m / 30.0 * pi) - A * cos(m / 360.0 * pi);
	double y = B * sin(m / 30.0 * pi) - A * sin(m / 360.0 * pi);

	cout << fixed << setprecision(12);
	double ans = sqrt(x * x + y * y);
	cout << ans << endl;
}


Measured memory_bytes: 4100
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

signed main(){
  std::vector<string> v(8,"########");
  v[0]=v[2]=v[4]=v[6]="#.#.#.#.";
  int q;cin>>q;
  std::vector<int> ans;
  for(int k=0;k<q;k++){
    int a,b,c,d;cin>>a>>b>>c>>d;
    a--;b--;c--;d--;
    int res=0;
    for(int i=a;i<=c;i++){
      for(int j=b;j<=d;j++){
        if(v[i][j]=='#')res++;
      }
    }
    ans.push_back(res);
  }
  for(int o:ans)cout<<o<<endl;
}



Measured memory_bytes: 3852
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<iostream>
#include<string>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define REP(i,x) for (int i=0;i<x;i++)
#define REPP(i,x,y) for (int i=x;i<=y;i++)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define MX3(x,y,z) max({x,y,z})
#define MX4(x,y,z,p) max({x,y,z,p})
#define MX5(x,y,z,p,q) max({x,y,z,p,q})
#define MN3(x,y,z) min({x,y,z})
#define MN4(x,y,z,p) min({x,y,z,p})
#define MN5(x,y,z,p,q) min({x,y,z,p,q})
#define amax(x,y) x=max(x,y)
#define amin(x,y) x=min(x,y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef tuple<int,int,int> ti;
typedef tuple<ll,ll,ll> tl;
// #####################################################################

map<ll,ll> mp;
const int MAX = 200000 +10;
ll rec[MAX];
ll tmp[MAX];

void solve() {

    ll n, k;
    SL(n); SL(k);
    if(k == 1) {
        puts("0");
        return;
    }
    ll sum = 0;
    ll ans = 0;
    mp[0] = 1;
    tmp[0] = 0;
    REPP(i, 1, n) {
        if(i >= k) {
            mp[tmp[i-k]]--;
        }
        SL(rec[i]);
        sum += rec[i];
        ll pos = ((sum - i) % k + k) % k;
        ans += mp[pos];
        mp[pos]++;
        tmp[i] = pos;
    }
    printf("%lld\n", ans);
}

void init() {
    


}

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


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

int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	int c = x - a;
	if (x - a < 0) {
		c = -x + a;
	}
	int d = x - b;
	if (x - b < 0) {
		d = -x + b;
	}
	if (c > d) {
		cout << "B" << endl;
	}
	else if (c < d) {
		cout << "A" << endl;
	}
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a=0,w=0,t=0,r=0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s=="AC"){
			a++;
		}
		else if(s=="WA"){
			w++;
		}
		else if(s=="TLE"){
			t++;
		}
		else if(s=="RE"){
			r++;
		}
	}
	cout<<"AC"<<" "<<"x"<<" "<<a<<endl;
	cout<<"WA"<<" "<<"x"<<" "<<w<<endl;
	cout<<"TLE"<<" "<<"x"<<" "<<t<<endl;
	cout<<"RE"<<" "<<"x"<<" "<<r<<endl;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

struct UnionFind {
  UnionFind(int n) : data(n, -1) {}

  int root(int ver) { return data[ver] < 0 ? ver : data[ver] = root(data[ver]); }

  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return false;
    if (data[u] > data[v]) swap(u, v);
    data[u] += data[v];
    data[v] = u;
    return true;
  }

  bool same(int u, int v) { return root(u) == root(v); }

  int size(int ver) { return -data[root(ver)]; }

private:
  vector<int> data;
};

int main() {
  int n, m, k; cin >> n >> m >> k;
  UnionFind uf(n);
  vector<int> ans(n, 0);
  while (m--) {
    int a, b; cin >> a >> b; --a; --b;
    uf.unite(a, b);
    --ans[a]; --ans[b];
  }
  REP(i, n) ans[i] += uf.size(i) - 1;
  while (k--) {
    int c, d; cin >> c >> d; --c; --d;
    if (uf.same(c, d)) --ans[c], --ans[d];
  }
  REP(i, n) cout << ans[i] << " \n"[i + 1 == n];
  return 0;
}


Measured memory_bytes: 1664
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    xs <- U.unfoldrN n (C.readInt.C.dropWhile isSpace) <$> C.getLine
    print $ solve n xs

solve :: Int -> U.Vector Int -> Int
solve n xs = U.foldl1' max . U.zipWith gcd ls $ U.tail rs
  where
    ls = U.scanl' gcd 0 xs
    rs = U.scanr' gcd 0 xs

Measured memory_bytes: 5756
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vs vector<string>
#define pb push_back
#define rep(i,n) for(int i = 0;i<n;i++)
#define repk(k,n) for(int i = k;i<n;i++)
#define all(v) v.begin(),v.end()
#define print(v) for(auto n:v){cout << n << "\t";}
#define input(v) for(auto &i:v){cin >> i;}
#define mod 1000000007
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
using namespace std;

void solve(){
	ll n;
	cin >> n;
	vll v(n);
	ll sum = 0;
	for(int i =0;i<n;i++){
		cin >> v[i];
		sum+=v[i];
		sum%=mod;
	}
	vll add(n+1,0);
	for(int i = n-1;i>=0;i--){
		add[i]+=v[i]+add[i+1];
		add[i]%=mod;
	}
	ll result = 0;
	for(int i =0;i<n-1;i++){
		ll k = v[i]*add[i+1];
		k%=mod;
		result+=k;
		result%=mod;
		
	}
	cout << result << endl;
	

}


int main(){
	ll t = 1;
	// cin >> t;
	while(t--){
		solve();
	}

	return 0;
}

Measured memory_bytes: 6364
n=int(input())
A=list(map(int,input().split()))
def convert(list):
    s=[str(i) for i in list]
    res = " ".join(s)
    return res
print(convert(A))
for i in range(1,n):
    v=A[i]
    j=i-1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    print(convert(A))


Measured memory_bytes: 5608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int[] check = new int[6];
		int[] high = {165,170,175,180,185,Integer.MAX_VALUE};
		for (int i = 0; i < n; i++) {
			double d = Double.parseDouble(br.readLine());
			for (int j = 0; j < high.length; j++) {
				if (d < high[j]) {
					check[j]++;
					break;
				}
			}
		}

		for (int i = 0; i < check.length; i++) {
			System.out.print((i + 1) + ":");
			for (int j = 0; j < check[i]; j++)
				System.out.print("*");
			System.out.println();
		}

	}

}

Measured memory_bytes: 17016
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
	int n,m,x[100],a[100];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[i];
	}
	cin>>m;
	for(int j=0;j<m;j++){
		cin>>a[j];
		if(a[j]<n){
		if(x[a[j]-1]!=x[a[j]]-1&&x[a[j]-1]+1<=2019){
		x[a[j]-1]=x[a[j]-1]+1;
		}
		else if(x[a[j]-1]+1==x[a[j]]){
		x[a[j]-1]=x[a[j]-1];
		}
		}
		else{
			if(x[a[j]-1]+1<=2019)
				{x[a[j]-1]=x[a[j]-1]+1;
			}
			 
		}
	}
	for(int i=0;i<n;i++){
		cout<<x[i]<<endl;}
	return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>
 
int con[101][101]={0};
int d[101]={0};
int f[101]={0};
int used[101] = {0};
int n;
int cd = 0;



void dfs(int now)
{
  int i;
  cd++;
  d[now] = cd;
 
  for(i = 0; i < n; i++){
    if(con[now][i]){
       if(d[i] == 0){
    dfs(i);
       }
    }
  }
  cd++;
  f[now] = cd;
}
 
int main(void)
{
  int u, k, v;
  int i, j;

  
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d %d", &u, &k);
    u--;
    for(j = 0; j < k; j++){
      scanf("%d", &v);
      v--;
      con[u][v] = 1;
    }
  }
  for(i = 0; i < n; i++){
    if(d[i] == 0) dfs(i);
  }
  for(i = 0; i < n; i++)
    printf("%d %d %d\n", i+1, d[i], f[i]);
  return 0;
}



Measured memory_bytes: 2112
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	for i := len(s) - len(t); i >= 0; i-- {
		com := true
		for j := 0; j < len(t); j++ {
			if s[i+j] == '?' {
				continue
			}
			if t[j] != s[i+j] {
				com = false
				break
			}
		}
		if com {
			v := s[:i] + t + s[i+len(t):]
			ans := ""
			for _, c := range v {
				if c == '?' {
					ans += "a"
				} else {
					ans += string(c)
				}
			}
			fmt.Println(ans)
			return
		}
	}
	fmt.Println("UNRESTORABLE")
}


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

/*
  REMEMBER:
  1.Think TWICE, code ONCE!
  Are there any counterexamples to your algo?
	
  2.Be careful about the BOUNDARIES in your algo!
  N=1? P=1? Is P a prime? Something about 0?
	
  3.Never make STUPID MISTAKES!
  Integer overflow? Array size? Time complexity? Memory usage? Precition error?
*/

const int _ = 1e5 + 7;
struct test{
	long long B , L , R , benefit;
	friend bool operator <(test p , test q){return p.benefit > q.benefit;}
}now[_]; long long N , X , cost;

bool check(long long mid){
	int t = mid / X + 1; long long lft = mid % X; long long sum = 0 , mx = 0;
	for(int i = 1 ; i <= t ; ++i) sum += now[i].benefit;
	for(int i = 1 ; i <= N ; ++i)
		mx = max(mx , sum - now[min(i , t)].benefit + min(now[i].B , lft) * now[i].L + max(0ll , lft - now[i].B) * now[i].R);
	return mx >= cost;
}

int main(){
	cin >> N >> X;
	for(int i = 1 ; i <= N ; ++i){
		cin >> now[i].B >> now[i].L >> now[i].R;
		cost += now[i].B * now[i].L;
		now[i].benefit = now[i].L * now[i].B + now[i].R * (X - now[i].B);
	}
	sort(now + 1 , now + N + 1);
	long long L = 0 , R = N * X;
	while(L < R){
		long long mid = (L + R) >> 1;
		check(mid) ? R = mid : L = mid + 1;
	}
	cout << L; return 0;
}

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


void solve(long long N){

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;cin >> N;
    long long ans = (((N-1)*(N))/2);

    cout << ans << endl;
}


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

int main ()
{
    string S , T , U ;
    int A , B ;
    cin >> S >> T ;
    cin >> A >> B ;
    cin >> U ;

    if (S == U )
        A-- ;
    if (T == U)
        B--;
    cout << A  << " " << B ;



}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <tuple>

using namespace std;

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(n, a) for(int i = 0; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES" : "NO")
#define mod(a, b) (b + (a % b)) % b
#define MOD (ll)1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

void solve(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) cout << 'x';
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}


Measured memory_bytes: 256
N, K = map(int,input().split())
S = input()

flag = 0

happiness = 0

for i in range(N - 1):
    if S[i] == S[i + 1]:
        happiness += 1
    else:
        if flag == 0 and K > 0:
            K -= 1
            flag = 1
        elif flag == 1:
            flag = 0
            happiness += 2

print(happiness + flag)

Measured memory_bytes: 3316
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()


def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    dist = [abs(X - y) for y in x]
    D = dist[0]
    for d in dist:
        D = gcd(D, d)
    print(D)

if __name__ == "__main__":
    main()


Measured memory_bytes: 88172
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long min = 100;
        for(long i = 1; i * i <= n; i++) {
            if(n % i == 0) {
                long devider = n / i;
                long maxDigits = countMaxDigits(i, devider);
                min = Math.min(min, maxDigits);
            }
        }
        System.out.println(min);
    }

    static long countMaxDigits(long dev1, long dev2) {
        long count = 0;
        while(dev1 != 0 || dev2 != 0) {
            count++;
            dev1 /= 10;
            dev2 /= 10;
        }
        return count;
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define mp(a,b) make_pair(a, b)
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; for(const auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; for(const auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; for(const auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

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

const int M = 26;
int T, n, m;
string s;
int nxt[222222][M];
int dp[222222][M];
int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin >> s;
    for (int i = 0; i < M; ++i) {
        nxt[s.size()][i] = static_cast<int>(s.size()) + 1;
        dp[s.size()][i] = 1;
    }
    for (int i = (int) s.size() - 1; i >= 0; --i) {
        for (int j = 0; j < M; ++j) {
            if (s[i] - 'a' == j){
                nxt[i][j] = i + 1;
                dp[i][j] = *min_element(&dp[i+1][0], &dp[i+2][0]) + 1;
            }
            else {
                nxt[i][j] = nxt[i+1][j];
                dp[i][j] = dp[i+1][j];
            }
        }
    }
    int i = 0;
    string ans = "";
    while(i < s.size() + 1) {
        int d = *min_element(&dp[i][0], &dp[i+1][0]);
        for (int j = 0; j < M; ++j) {
            if (dp[i][j] == d) {
                ans.push_back(static_cast<char>('a' + j));
                i = nxt[i][j];
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 41492
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cout<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int h,w;
string s;

main(){
    cin>>s;
    rep(i,12){
        cout<<s[i];
        if(i==3)cout<<' ';
    }
    cout<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		int m = n%1000;
		if(m == 0) {
			System.out.println(0);
		}else {
			System.out.println(1000 - m);
		}
		
		
		in.close();
	}
}


Measured memory_bytes: 35648
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;

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;
}


int main() {
  int N; cin >> N;
  ll h[100010];
  rep(i,N) cin >>h[i];

  ll dp[100010];
  rep(i,100010) dp[i] = INF;
  dp[0] = 0;

  rep(i,N){
    dp[i + 1] = min(dp[i + 1],dp[i] + abs(h[i] - h[i + 1]));
    dp[i + 2] = min(dp[i + 2],dp[i] + abs(h[i] - h[i + 2]));
  }

  cout << dp[N-1] << endl;

	return 0;
}



Measured memory_bytes: 5192
// F
// DeP
#include <cstdio>

typedef long long LL;
const int MAXN = 5e3+5;

int K, q;
LL d[MAXN], A[MAXN];

int main() {
    // input
    scanf("%d%d", &K, &q);
    for (int i = 0; i < K; ++i) scanf("%lld", d+i);
    // solve
    while (q--) {
        static int n, x, m;
        scanf("%d%d%d", &n, &x, &m);
        --n;
        int eq =  0;
        for (int i = 1; i <= K; ++i) {
            A[i] = A[i-1] + d[i-1] % m;
            if (d[i-1] % m == 0) eq += (n / K) + (i <= n % K);
        }
        LL sum = A[K] * (n / K) + A[n % K] + x % m;
        printf("%lld\n", n - eq - sum / m);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nfs ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,a,b) for(i=a;i>=b;i--)
#define m_p make_pair
#define p_b push_back
#define MOD 1000000007
int main()
{
	nfs;
	int t;
	t=1;
//	cin >> t;

	while(t--)
	{
		ll n;
		cin >> n;
		ll a,ab,b,c;
		a = ab = b = c = 0;
		ll i;
		ll count = 0;
		F(i,0,n)
		{
			string x ;
			cin >> x;
			ll l = x.length();
			ll j;
			if(x[0]=='B'&&x[l-1]=='A')
			{
				ab++;
			}
			else if(x[0]=='B')
			{
				b++;
			}
			else if(x[l-1]=='A')
			{
				a++;
			}
			else
			{
				c++;
			}
			F(j,0,l-1)
			{
				if(x[j]=='A'&&x[j+1]=='B')
				{
					count++;
				}
			}
		}
		//cout << count << endl;
		
		if(a==0)
		{
			if(b==0)
			{
				ll lol = 0;
				count += max((ab-1),lol);
			}
			else
			{
				count += ab ;
			}
		}
		else
		{
			if(b==0)
			{
				count += ab;
			}
			else
			{
				count += ab ;
				count += 1;
				ll tempo= min(a-1,b-1);
				ll yay = 0;
				count += max(tempo,yay);
				
			}
		}
		
		cout << count << endl;
		
		
	}
	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 50+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<vector<ll>> mult(vector<vector<ll>> m1, const vector<vector<ll>> m2) {
    vector<vector<ll>> m(m1.size(), vector<ll>(m1.size()));
    for (int i = 0; i < m1.size(); ++i) {
        for (int j = 0; j < m1.size(); ++j) {
            for (int k = 0; k < m1.size(); ++k) {
                m[i][j] = add(m[i][j], mult(m1[i][k], m2[k][j]));
            }
        }
    }
    return m;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, k; cin >> n >> k;
    vector<vector<ll>> m(n, vector<ll>(n)), ans(n, vector<ll>(n));
    rep (i, 0, n) rep (j, 0, n) cin >> m[i][j];
    rep (i, 0, n) rep (j, 0, n) if (i == j) ans[i][j] = 1;
    while (k > 0) {
        if (k & 1) ans = mult(ans, m);
        m = mult(m, m);
        k >>= 1;
    }
    ll sum = 0;
    rep (i, 0, n) rep (j, 0, n) sum = add(sum, ans[i][j]);
    cout << sum << endl;
    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int H, W, N;
    cin >> W >> H >> N;
    int minx = 0, miny = 0, maxx = W, maxy = H;
    REP(i, N)
    {
        int x, y, a;
        cin >> x >> y >> a;
        switch (a)
        {
        case 1:
            minx = std::max(x, minx);
            break;
        case 2:
            maxx = std::min(x, maxx);
            break;
        case 3:
            miny = std::max(y, miny);
            break;
        case 4:
            maxy = std::min(y, maxy);
            break;
        }
    }
    cout << std::max(maxx - minx, 0) * std::max(maxy - miny, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		
		
		int a=sc.nextInt();
		int b=sc.nextInt();
		int h=sc.nextInt();
		
		
		System.out.println((a+b)*h/2);
}
}
		

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

const ll mod = linf;
ll mul(ll a, ll b) {
    return a * b % mod;
}
ll add(ll a, ll b) {
    return (a + b) % mod;
}
ll sub(ll a, ll b) {
    return (a - b + mod) % mod;
}
ll power(ll x, ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i <<= 1) {
        if (i & n) res = mul(res, x);
        x = mul(x, x);
    }
    return res;
}
ll inv(ll n) {
    return power(n, mod-2);
}
ll divi(ll a, ll b) {
    return mul(a, inv(b));
}
vector<ll> fact;
void init_fact(ll n) {
    fact.assign(n+1, 1);
    FOR(i, 1, fact.size()) {
        fact[i] = mul(fact[i-1], i);
    }
}
vector<vector<ll>> memo;
ll comb(ll n, ll r) {
    if (n == r || r == 0) return 1;
    if (r > n || r < 0) return 0;
    if (memo[n][r] >= 0) return memo[n][r];
    return memo[n][r] = comb(n-1, r) + comb(n-1, r-1);
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n, A, B; cin >> n >> A >> B;
    memo.assign(100, vector<ll>(100, -1));
    vector<ll> v(n); cin >> v;
    sort(ALL(v), greater<ll>());
    ll sum = 0;
    REP(i, A) sum += v[i];
    ll m = v[A-1];
    ll cnt1 = 0, cnt2 = 0;
    REP(i, A) {
        if (v[i] == m) {
            ++cnt1;
            ++cnt2;
        }
    }
    FOR(i, A, n) {
        if (v[i] == m) ++cnt1;
    }
    cout << fixed << setprecision(10);
    if (sum/A/10 > 0) cout << sum/A/10;
    cout << sum/A%10 + (ld)(sum%A)/A << endl;
    if (cnt2 < A) {
        cout << comb(cnt1, cnt2) << endl;
    }
    else {
        ll a = 0;
        FOR(i, A, B+1) {
            a += comb(cnt1, i);
        }
        cout << a << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll ans = 0;
    for(int i = 0; i < N; i++) {
        ans += (ll)(i + 1) * (N - i);
    }
    for(int i = 0; i < N - 1; i++) {
        ll u, v;
        cin >> u >> v;
        if(u > v) {
            swap(u, v);
        }
        ans -= u * (N - v + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int P = sc.nextInt();
        int Q = sc.nextInt();
        Q /= gcd(P, Q);
        int ans = 1;
        for (int i = 2; i * i <= Q; i++) {
            if (Q % i == 0) {
                while (Q % i == 0) {
                    Q /= i;
                }
                ans *= i;
            }
        }
        ans *= Q;
        System.out.println(ans);
    }


    static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }
}

Measured memory_bytes: 26396
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <cstdio>

using namespace std;

typedef pair<int, int> P;

const int INF = 100000000;

class State{
public:
  int pos, v, pre;
  double time;
  State(){}
  State(int pos, int v, int pre, double time) : pos(pos), v(v), pre(pre), time(time) {}
  bool operator < (const State& s) const { return time > s.time; }
};

int n, m, s, g;
P edge[30][30];
double cost[30][30][31];
bool vis[30][30][31];

void solve(){
  State u, v;
  u = State(s, 0, 0, 0.0);
  priority_queue<State> que;
  fill(vis[0][0], vis[30][0], (double)INF);
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) for(int k=0;k<31;k++) cost[i][j][k] = INF, vis[i][j][k] = false;
  for(int i=0;i<n;i++) if(edge[s][i].first != INF) cost[s][i][1] = edge[s][i].first, que.push(State(i, 1, s, (double)edge[s][i].first));
  while(!que.empty()){
    u = que.top(); que.pop();
    if(vis[u.pre][u.pos][u.v]) continue;
    vis[u.pre][u.pos][u.v] = true;
    if(u.pos == g && u.v == 1){
      printf("%.5f\n", u.time);
      return;
    }
    for(int i=0;i<n;i++){
      if(edge[u.pos][i].first == INF) continue;
      if(u.pre == i) continue;
      for(int k=-1;k<=1;k++){
        if(u.v + k > edge[u.pos][i].second) continue;
        if(u.v + k <= 0) continue;
        v = State(i, u.v + k, u.pos, u.time + edge[u.pos][i].first / (double)(u.v + k));
        if(cost[v.pre][v.pos][v.v] > v.time){
          cost[v.pre][v.pos][v.v] = v.time;
          que.push(v);
        }
      }
    }
  }
  printf("unreachable\n");
}

main(){
  while(scanf("%d%d", &n, &m) && (n|m)){
    scanf("%d%d", &s, &g);
    s--; g--;
    fill(edge[0], edge[30], P(INF, 0));
    for(int i=0;i<m;i++){
      int a, b, c, d;
      scanf("%d%d%d%d", &a, &b, &c, &d);
      a--; b--;
      edge[a][b] = edge[b][a] = P(c, d);
    }
    solve();
  }
}

Measured memory_bytes: 2392