akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    string s;
    string t;
    cin >> s >> t;

    bool ok = true;
    rep(i, s.size()) {
        if (s[i] != t[i]) ok = false;
    }
    if (s.size() != t.size() - 1) ok = false;

    if (ok)
        CYES;
    else
        CNO;

    return 0;
}


Measured memory_bytes: 3668
def solve():
    a, b = map(int, input().split())
    s_i, s_j = 1, 0
    t_i, t_j = 0, 1
    while b:
        q, r = divmod(a, b)
        s_i, s_j = s_j, s_i - q * s_j
        t_i, t_j = t_j, t_i - q * t_j
        a, b = b, r
    print(s_i, t_i)

solve()

Measured memory_bytes: 7788
public class Main {

	/**
	 * ????????????????????????
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < 10; j++) {
				System.out.println(i + "x" + j + "=" + i * j);
			}
		}
	}
}

Measured memory_bytes: 24204
using System;
using System.Collections.Generic;

namespace _087_StrangeMathematicalExpression
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				string[] splits = inputStr.Split (' ');
				Stack<decimal> content = new Stack<decimal> (inputStr.Length);

				for (int lp = 0; lp < splits.Length; lp++)
				{
					decimal value;
					bool isOperator = !decimal.TryParse (splits[lp], out value);

					if (isOperator)
					{
						decimal operand1 = content.Pop ();
						decimal operand2 = content.Pop ();
						decimal result = 0m;

						switch (splits[lp])
						{
							case "+": result = operand2 + operand1; break;
							case "-": result = operand2 - operand1; break;
							case "*": result = operand2 * operand1; break;
							case "/": result = operand2 / operand1; break;
						}
						
						content.Push (result);
					}
					else
					{
						content.Push (value);
					}
				}

				Console.WriteLine (content.Peek ());
			}
		}
	}
}

Measured memory_bytes: 10332
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int[] a = new int[2];
        while(s.hasNext()){
            for(int i=0; i < 2; i++)
                a[i] = s.nextInt();
            int gcd = 1;
            Arrays.sort(a);
            for(int j=2; j<=a[0];j++){
                if ((a[0]%j == 0) && (a[1]%j == 0))
                    gcd = j;               
            }
            int lcm =a[1];
            int k = 1;
            boolean b = true;
            
            while(b){
                if((gcd*k)%a[0]==0 && (gcd*k)%a[1]==0){
                    lcm = gcd*k;
                    b = false;
                }
                k++;
            }
            System.out.println(gcd + " " + lcm);
        }
        
    }
}

Measured memory_bytes: 12000
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0050
Apple and Peach
"""
import sys


def main(args):
    text = input()
    non_exist = 'qwertyuiop'
    while non_exist in text:
        non_exist += '@'
    text = text.replace('apple', non_exist)
    text = text.replace('peach', 'apple')
    text = text.replace(non_exist, 'peach')
    print(text)

if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7436
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
from collections import Counter

def check(v):
    an = 0
    i = 1
    subsum = 0
    while v - subsum >= i:
        subsum += i
        i += 1
        an += 1
    return an

# print(check(16))

def Main(N):
    p = prime_factorize(N)
    c = Counter(p)
    ans = 0
    for v in c.values():
        ans += check(v)
    return ans

print(Main(N))

Measured memory_bytes: 9464
n = int(input())
SP = []
for i in range(n):
  sp = input().split()
  sp.append(i+1)
  SP.append(sp)
sortedSP = sorted(SP, key = lambda x:x[0])
for i in range(n-1):
  for j in range(n-1-i):
    if sortedSP[j][0] == sortedSP[j+1][0] and int(sortedSP[j][1]) < int(sortedSP[j+1][1]):
      sortedSP[j], sortedSP[j+1] = sortedSP[j+1], sortedSP[j]
for i in range(n):
  print(sortedSP[i][2])

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

using namespace std;

int main(){
  int a;
  int b;
  int sum = 0;

  cin >> a >> b;

  if(a < 0 || b < 0) return -1;
  if(a < 3 || b > 20) return -1;

  for(int i = 0; i < 2; i++){
    if(a >= b){
      sum += a;
      a--;
    }
    else if(a < b){
      sum += b;
      b--;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
typedef long long int ll;

ll a, b, c;

int main(void){
	cin >> a >> b >> c;
	ll ans = 0, div = 1;
	while(true){
		if(a % div != 0 || b % div != 0 || c % div != 0) break;
		div *= 2;
		if((a + b) % div != 0 || (b + c) % div != 0 || (c + a) % div != 0) break;
		ans++;
	}
	if(a % 2 != 0 || b % 2 != 0 || c % 2 != 0) ans = 0;
	else if(a == b && b == c) ans = -1;
	cout << ans << endl;
	return 0;
}


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

int main() {
  int N,i,count;
  cin >> N;
  int p,q,r;
  count=0;
  cin >> p;
  cin >> q;
  for(i=2;i<N;i++){
    cin >> r;
	if((p-q)*(q-r)>=0)
      count+=1;
    p=q;
    q=r;
  }
  cout << count << endl;
}


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

int main(){
  multiset<int> m;
  int a;
  for(int i=0; i<10; i++){
    cin >> a;
    m.insert(a);
  }

  multiset<int>::reverse_iterator it = m.rbegin();
  for(int i=0; i<3; i++)
    cout << *it++ << endl;

  return 0;
}

Measured memory_bytes: 1192
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
///////////////////PnC/////////////////////
vl Fac(MAX),Inv(MAX);
void CalcFac()
{
	Fac[0]=Inv[0]=1;
	for(int i=1;i<MAX;i++)
	{
		Fac[i]=(Fac[i-1]*i)%MOD;
		Inv[i]=powN(Fac[i],MOD-2);
	}
}

ll NCR(int n,int r)
{
	if(r>n) return 0;
	return (((Fac[n]*Inv[r])%MOD)*Inv[n-r])%MOD;
}
///////////////////PnC/////////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vi MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

int main()
{
	int n;
	cin>>n;
	int ans=0;
	int lim = sqrt(4*n);
	vi SUM(n+1);
	for(int x=1;x<=lim;x++)
	{
		for(int y=1;y<=lim;y++)
		{
			for(int z=1;z<=lim;z++)
			{
				ll sum = (ll)(x+y)*(x+y)+(ll)(y+z)*(y+z)+(ll)(x+z)*(x+z);
				if(sum<=2*n)
				{
					SUM[sum/2]++;
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		cout<<SUM[i]<<endl;
	}

}	

Measured memory_bytes: 22896
import java.util.Scanner;

public class Main {
    static int N;
    static int A;
    static int B;
    static int C;
    static int[] l;
    static int INF = 1000000000;

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

        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();

        l = new int[N];

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

        sc.close();

        System.out.println(dfs(0, 0, 0, 0));
    }

    public static int dfs(int cur, int a, int b, int c) {
        if (cur == N) {
            if (a > 0 && b > 0 && c > 0) {
                return Math.abs(a - A) + Math.abs(b - B) + Math.abs(c - C) - 30;
            } else {
                return INF;
            }
        }

        int ret0 = dfs(cur + 1, a, b, c);
        int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
        int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
        int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;
        return Math.min(Math.min(Math.min(ret0, ret1), ret2), ret3);
    }
}

Measured memory_bytes: 24512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;

vector<long long> vc;

int main() {
  int a1;
  cin >> a1;
  long long tmp = a1;
  long long count = 0;
  while(true) {
    vc.push_back(tmp);
    count++;
    if(tmp % 2 == 1) {
      tmp = 3*tmp + 1;
    }else {
      tmp = tmp/2;
    }
    if(find(vc.begin(),vc.end(),tmp) != vc.end()) {
      count++;
      break;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
c = [list(map(int,input().split())) for _ in range(3)]

#aとbをチェック
a = []
b = []
for i in range(1,3):
	for j in range(3):
		a.append(c[i][j]-c[0][j])
		b.append(c[j][i]-c[j][0])

ans = 'No'
if a[0] == a[1] and a[0] == a[2] and a[3] == a[4] and a[3] == a[5]:
	if b[0] == b[1] and b[0] == b[2] and b[3] == b[4] and b[3] == b[5]:
		ans = 'Yes'

print(ans)


Measured memory_bytes: 3064
w,h,n=map(int,input().split())
x1=0
y1=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x1,x)
    elif a==2:
        w=min(w,x)
    elif a==3:
        y1=max(y,y1)
    elif a==4:
        h=min(h,y)
print((w-x1)*(h-y1) if w > x1 and h > y1 else 0)

Measured memory_bytes: 3064
class PQueue
    def initialize(n,&block)
        @buf = [nil]*n
        @cmp = block
        @size = 0
    end
    def size
        @size
    end

    def push val
#        p "push"
        @size += 1
        n = @size
        while n > 1
            nextn = n/2
            vnextn = @buf[nextn]
            break unless @cmp.call(val,vnextn)
            @buf[n] = vnextn
            n = nextn
        end
        @buf[n] = val
#        p [val,@buf[1,@size]]
    end
    def pop
#        p "pop"
#        raise "empty" if @size == 0
        if @size == 1
            ret = @buf[1]
            @size = 0
        else
            vn = @buf[@size]
            ret = @buf[1]
            @size -= 1
            n = 1
            n2 = 2
            n21 = 3
            while n2 <= @size
                vn2,vn21 = @buf[n2],@buf[n21]
                if n21 > @size || @cmp.call(vn2,vn21)
                    upper = n2
                    vupper = vn2
                else
                    upper = n21
                    vupper = vn21
                end
                break unless @cmp.call(vupper,vn)
                @buf[n] = vupper
                n = upper
                n2 = n*2
                n21 = n2+1
            end
            @buf[n] = vn
        end
#        p [ret,@buf[1,@size]]
        ret
    end
end


n,m = gets.split.map(&:to_i)
node = [[],[]]+(2..n).map{|i|[[i-1,0]]}

m.times{
    l,r,c=gets.split.map(&:to_i)
    node[l] << [r,c]
}

path_list = PQueue.new(n+m){|(a,_),(b,_)|a < b}
path_list.push([0,1])
costs = [1e20]*(n+1)
ans = nil
while path_list.size > 0
    ncost,l = path_list.pop
    cost = costs[l]
    next if cost < ncost
    if n == l
        ans = cost
        break
    end
    node[l].each{|r,c|
        rcost = ncost+c
        if costs[r] > rcost
            costs[r] = rcost
            path_list.push([rcost,r])
        end
    }
end
p ans||-1


Measured memory_bytes: 29436
N=int(input())
A=[int(i) for i in input().split()]
print(*A)
for i in range(1, len(A)):
    key = A[i]
    j = i-1
    while j>=0 and A[j]>key:
        A[j+1]=A[j]
        j -= 1
    A[j+1]=key
    print(*A)


Measured memory_bytes: 5976
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int T = sc.nextInt();
    int[] t = new int[N];

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

    sc.close();

    long time = 0;

    for (int i = 0; i < N; i++) {
      if (i == N - 1) {
        time += T;
      } else {
        time += Math.min(T,t[i+1] - t[i]);
      }
    }
  
    System.out.println(time);

  }

}

Measured memory_bytes: 86496
#include <bits/stdc++.h>
#define ll long long 
#define ld long double
using namespace std;
const ll INF = 1e18;
const ll MOD = 998244353;

int t[5000000];

void update(int v, int tl, int tr, int pos, int val) {
	if(tl == tr)	t[v] = val;
	else {
		int tm = (tl + tr) / 2;

		if(pos <= tm)	update(v*2, tl, tm, pos, val);
		else	update(v*2 + 1, tm + 1, tr, pos, val);

		t[v] = t[v*2] + t[v*2 + 1];
	}
}

int query(int v, int tl, int tr, int l, int r) {
	if(l > r)	return 0;
	else if(tl == l and tr == r)	return t[v];
	else {
		int tm = (tl + tr) / 2;
		return query(v*2, tl, tm, l, min(tm, r)) + query(v*2 + 1, tm + 1, tr, max(tm + 1, l), r);
	}
}

int32_t main() {
	ios::sync_with_stdio(!cin.tie(NULL));

	int n, q;
	cin >> n >> q;

	vector<pair<int, int>> quer[n + 1];
	vector<int> arr(n);
	for(int i = 0; i < n; i++)	cin >> arr[i];

	int l, r;
	for(int i = 0; i < q; i++) {
		cin >> l >> r;
		quer[r].emplace_back(l, i);
	}

	memset(t, 0, sizeof(t));

	vector<int> last(n + 1, -1);
	int cur = 0;
	vector<int> ans(q + 10);
	for(int i = 0; i < n; i++) {
		if(last[arr[i]] != -1)	update(1, 0, n - 1, last[arr[i]], 0);
		last[arr[i]] = i;

		update(1, 0, n - 1, i, 1);
		for(auto x : quer[i + 1]) {
			ans[x.second] = query(1, 0, n - 1, x.first - 1, i);
		}

	}

	for(int i = 0; i < q; i++)	cout << ans[i] << "\n";
}



Measured memory_bytes: 50776
fun main(array: Array<String>) {
    var (a, b) = readLine()!!.split(" ").map { it.toInt() }
    var cnt = 0
    var ans = ""
    while(a <= b) {
        if(a < 0) cnt++
        if(a == 0) {
            print("Zero")
            return
        }
        a++
    }
    ans = if(cnt % 2 == 0) {
        "Positive"
    }
    else {
        "Negative"
    }
    print(ans)
}

Measured memory_bytes: 38048
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

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

/*int char_cnt(string s,char a){
  int cnt=0;
  for(unsigned int i=0;i<s.size();i++){
    if(s[i]==a){
      cnt++;
    }
  }
  return cnt;
}

int main() {
  int n=0;
  string s;
  cin>>n>>s;
  ll ans=0;
  ans=(char_cnt(s,'R')*char_cnt(s,'B')*char_cnt(s,'G'));
  ll ans2=0;
  int r=0;
  int g=0;
  int b=0;
  rep(l, n) {
        if (s[l] == 'R') r++;
        if (s[l] == 'G') g++;
        if (s[l] == 'B') b++;
    }
  ans2=r*g*b;
  cerr<<ans-ans2;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int k=2 * j - i;
      if(k>=n)continue;
      if((s[k]!=s[j])&&(s[j]!=s[i])&&(s[i]!=s[k]))ans--;
    }
  }
  cout<<ans;
}*/
int main() {
    int n; string s;
    cin >> n >> s;
 
    ll r=0, g=0, b=0;
    rep(i, n) {
        if (s[i] == 'R') r++;
        if (s[i] == 'G') g++;
        if (s[i] == 'B') b++;
    }
    ll ans = r*g*b;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int k = 2 * j - i;
            if (k >= n) continue;
            if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ans--;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	vector<P> a;

	cin >> N;
	a.resize(N);
	llong in;
	for(int i = 0; i < N; i++){
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(BE(a));

	llong ans = 0;
	set<llong> use;
	use.insert(-1);
	use.insert(N);
	for(int i = 0; i < N; i++){
		auto f = use.upper_bound(a[i].second);
		auto b = f;
		b--;

		llong fdis = *f - a[i].second;
		llong bdis = a[i].second - *b;
		// cerr << fdis << " " << bdis << " " << a[i].first << endl;
		ans += fdis*bdis*a[i].first;
		use.insert(a[i].second);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int input() { int r; cin >> r; return r; }
signed main() {
	int n = input(), ans = 0;
	for (int i = 2; i <= sqrt(n); i++) {
		int cnt = 0;
		while (n % i == 0) {
			n /= i; cnt++;
		}
		int k = 1;
		while (cnt - k >= 0) { ans++; cnt -= k; k++; }
	}
	if (n > 1)ans++;
	puts(ans);
}

Measured memory_bytes: 3680
n = int(input())
a = list(map(int, input().split()))

maxi = max(range(n), key=lambda x: a[x])
maxa = a[maxi]
mini = min(range(n), key=lambda x: a[x])
mina = a[mini]
out = []
if maxa > -mina:
    for i in range(1, n):
        while a[i] < a[i-1]:
            out.append((maxi+1, i+1))
            a[i] = a[i] + maxa
        if a[i] > maxa:
            maxa = a[i]
            maxi = i
else:
    for i in range(n-2, -1, -1):
        while a[i+1] < a[i]:
            out.append((mini+1, i+1))
            a[i] = a[i] + mina
        if a[i] < mina:
            mina = a[i]
            mini = i

print(len(out))
for o in out:
    print(o[0], o[1])


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { 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;}

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, k;
    cin>>n>>k;

    vector<mint> ss(n + 2);
    rep(i, n + 1) ss[i + 1] = ss[i] + i;
    mint ans = 0;
    for (int i = k; i < n + 2; ++i) ans += (ss.back() - ss[n - i + 1]) - (ss[i] - ss[0]) + 1;
    cout<<ans<<endl;
}

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

int main(){
	char s[3][3];
  	for(int i=0;i<3;++i){
    	for(int j=0;j<3;++j)cin>>s[i][j];
    }cout<<s[0][0]<<s[1][1]<<s[2][2]<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, c, k;
vector<i64> t;
int main() {
  cin >> n >> c >> k;
  read_n(t, n);
  sort(begin(t), end(t));
  i64 ans = 0;
  i64 u = 0;
  for (i64 i = 0, p = 1; i < n; ++i, ++p) {
    if (t[i] > u || p > c) {
      u = t[i] + k;
      p = 1;
      ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as U

-- n := V.length v + 1
-- v ! i = 表が i 枚、裏が n - i 枚出る確率
solve :: U.Vector Double -> U.Vector Double
solve ps = U.foldl' step (U.singleton 1) ps
  where
    step !vec !p = U.zipWith (\u v -> p * u + (1 - p) * v) (0 `U.cons` vec) (vec `U.snoc` 0)

main = do
  n <- readLn
  -- 1 <= n <= 2999, n is odd
  ps <- U.unfoldrN n (readDoubleBS . BS.dropWhile isSpace) <$> BS.getLine
  let result = solve ps
  -- U.length result == n + 1
  print $ U.sum $ U.drop (n `quot` 2 + 1) result

readDoubleBS :: BS.ByteString -> Maybe (Double, BS.ByteString)
readDoubleBS s = case BS.readInt s of
                   Just (ipart, s') -> case BS.uncons s' of
                                         Just ('.', s'') -> case BS.readInt s'' of
                                                              Just (fpart, s''') ->
                                                                let !l = BS.length s'' - BS.length s'''
                                                                    !x | ipart >= 0 = fromIntegral ipart + fromIntegral fpart / 10^l
                                                                       | otherwise = fromIntegral ipart - fromIntegral fpart / 10^l
                                                                in Just (x, s''')
                                                              Nothing -> Just (fromIntegral ipart, s')
                                         _ -> Just (fromIntegral ipart, s')
                   Nothing -> Nothing


Measured memory_bytes: 2428
Imports System

Public Class Program


    Public Shared Sub Main(args As String())

        Dim input() As String = Console.ReadLine.Split(" ")
        If input(0) = input(1) Then

            If Not (input(0) = input(2)) Then
                Console.WriteLine("Yes")
            Else
                Console.WriteLine("No")
            End If

        ElseIf input(0) = input(2) Then
            Console.WriteLine("Yes")

        ElseIf input(1) = input(2) Then
            Console.WriteLine("Yes")

        Else
            Console.WriteLine("No")
        End If


    End Sub



End Class


Measured memory_bytes: 19792
# -*- coding: utf-8 -*-

import io
import sys
import math

def solve(x):
    # implement process
    if x == 2:
        return 2
    if x%2 == 0:
        x+=1
    sosuu_lst = []
    i = 3
    while True:
        is_sosuu = True
        for a in sosuu_lst:
            if i % a == 0:
                is_sosuu = False
                break
        if is_sosuu:
            if i >= x:
                break
            sosuu_lst.append(i)
        i += 2

    return i

def main():
    # input
    x = int(input())
    
    # process
    ans = str( solve(x) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
99992
"""
_EXPECTED = """\
100003
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Measured memory_bytes: 9272
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

int main() {
	fast();
 
    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    ll r, c;
    cin >> r >> c;
    if(r==1||c==1){
        cout << 1 << endl;
        return 0;
    }
    ll x = (c/2) + (c%2);
    ll y = c/2;
    ll z = r/2;
    ll ans = (x+y)*z;
    z = r%2;
    if(z){
        ans+=x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import collections as c

n = int(input())

a = list(map(int,input().split()))

q = int(input())

s = sum(a)

cnt = c.Counter(a)

for i in range(q):
    b,c = map(int,input().split())
    s += (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(s)

Measured memory_bytes: 24016
package main

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

func main() {
	a, b, k := readI(), readI(), readI()
	if k <= a {
		fmt.Println(a-k, b)
	} else if k <= a+b {
		fmt.Println(0, b-k+a)
	} else {
		fmt.Println(0, 0)
	}
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

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

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


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

int main(){
    int n;
    cin >> n;
    vector <int> p(n);
    rep(i,n) cin >> p[i];
    int no = 0;
    rep(i,n-1){
        if(p[i]<p[i+1]){
            p[i+1]=p[i];
            no++;
            continue;
        }
    }
    int ans = n - no;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> cnt(3,0);
    rep(i,n){
        int a;
        cin>>a;
        if(a%4==0) cnt[0]++;
        else if(a%2==0) cnt[1]++;
        else cnt[2]++;
    }
    if(cnt[2]){
        if(cnt[2]<=cnt[0]) cout<<"Yes"<<endl;
        else{
            if(cnt[2]==cnt[0]+1 && !cnt[1]) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }else{
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
#pragma GCC diagnostic error "-std=c++14"
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cctype>
using namespace std;
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
void print(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)print(x/10);
	putchar(x%10+48);
}
double sj=6.2831853;
int main()
{
	double r;
    scanf("%lf",&r);
    printf("%.2lf",sj*r);
	return 0;
}



Measured memory_bytes: 1752
n=int(input())
a,b=map(int,input().split())
p=sorted(list(map(int,input().split())))

import bisect
abis = bisect.bisect_right(p,a)
bbis = bisect.bisect_right(p,b)
print(min(abis-0, bbis-abis, len(p)-bbis))


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

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

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  char b;
  cin >> b;
  char ret;
  switch (b) {
    case 'A': ret = 'T'; break;
    case 'C': ret = 'G'; break;
    case 'G': ret = 'C'; break;
    case 'T': ret = 'A'; break;
  }

  cout << ret << endl;
  return 0;
}


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

int main() {

	int H, W;

	cin >> H >> W;

	while (H != 0 && W != 0)
	{
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				if ((i+j)%2 == 0) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	}

	return 0;
}


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

int main(int argc, char **argv)
{
	int n, i, tmp, j;
	char *str = (char *)malloc(100*sizeof(char));
	char array[9] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
	
	while(scanf("%s", str) != EOF){
		n = strlen(str)-1;
		for(i = 0; i <= n; i++){
			if(str[i] == '@'){
				i++;
				for(j = 0; j < 9; j++){
					if(array[j] == str[i]){
						tmp = j;
						break;
					}
				}
				i++;
				for(j = 0; j <= tmp; j++){
					printf("%c", str[i]);
				}
			} else {
				printf("%c", str[i]);
			}
		}
		printf("\n");
		
		free(str);
		str = (char *)malloc(100*sizeof(char));
	}
	
	free(str);
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { 1, 0, -1, 0};
const int dy[4] = { 0, 1, 0, -1};

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;

//==============================================
int n, q;

class Disjoint {
	public:
		vi rank, p;
		Disjoint() {};
		Disjoint(int size) {
			rank.resize(size);
			p.resize(size);
			REP(i, n) makeSet(i);
		}

		void makeSet(int x) {
			p[x] = x;
			rank[x] = x;
		}

		bool same(int x, int y) {
			return findSet(x) == findSet(y);
		}

		void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}

		void link(int x, int y) {
			if (rank[x] > rank[y]) {
				p[y] = x;
			} else {
				p[x] = y;
				if (rank[x] == rank[y]) {
					rank[y]++;
				}
			}
		}

		int findSet(int x) {
			if (x != p[x]) {
				p[x] = findSet(p[x]);
			}
			return p[x];
		}
};

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

	cin >> n >> q;
	Disjoint ds = Disjoint(n);

	int t, a, b;
	REP(i, q) {
		cin >> t >> a >> b;
		if (!t) ds.unite(a, b);
		else {
			cout << (ds.same(a, b) ? 1 : 0) << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3480
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(void){
    int k,n;

    scanf("%d%d",&k,&n);

    int a[n];

    for(int i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }

int dif[n];

dif[0] = a[0]+(k-a[n-1]);

for(int i = 1; i < n; i++){
    dif[i] = a[i] - a[i-1];
}

qsort(dif,n,sizeof(int),asc);
int ans = 0;
for(int i = 0; i < n-1; i++){
ans += dif[i];
}
printf("%d",ans);
return 0;
}


Measured memory_bytes: 2556
N=int(input())
#約数の個数メモ化

"""
A*B+C=N
N-C=A*B
AB+C=Nの組み合わせは、N-1通り
NlogNは
"""
ans=0
# 約数の個数を一斉取得
def getNumsOfDivisorsOfEachNumbers(n: int):
    # validation check
    if not isinstance(n, int):
        raise("[ERROR] parameter must be integer")
    if n < 0:
        raise("[ERROR] parameter must be not less than 0 (n >= 0)")
    nums = [0] * (n + 1) # 0-indexed
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            nums[j] += 1
    nums.pop(0)
    return nums


# 約数の個数を一斉取得
all_=getNumsOfDivisorsOfEachNumbers(N-1)
#c=1のとき、all_[N-1](N-1の約数)を見ればいい
for i in range(1,N):
    c=N-i
    ans+=(all_[i-1]//2)*2+all_[i-1]%2
print(ans)

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
    	cin >> a[i];
    }
    int ans = 0;
    for(int i=0; i<n-1; i++){
    	if(a[i+1] > a[i]){
    		ans++;
    	}
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M=3010;
int a[M],n;
ll dp[2][M][M],sum;
ll dfs(int u,int l,int r,ll s)
{
    ll &re=dp[u][l][r];
    if(re)
        return re;
    if(l==r)
        return re=a[l];
    ll tmp[2]={dfs(!u,l+1,r,s-a[l]),dfs(!u,l,r-1,s-a[r])};
    if(tmp[0]<tmp[1]) re=s-tmp[0];
    else re=s-tmp[1];
    //printf("%d %d %d %lld\n",u,l,r,re);
    return re;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]),sum+=a[i];
    printf("%lld\n",dfs(0,1,n,sum)-(sum-dfs(0,1,n,sum)));
    return 0;
}


Measured memory_bytes: 141824
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define in freopen("in.txt","r",stdin)
//#define out freopen("out.txt","w",stdout) 
ll n,m,j,k,t,l,r;
ll a,b,c,d,x,Q;
ll ans,MAX,MIN=40,sum;
ll ax[1000000];
char str[100000];
ll dx[12];
ll bx[2000500];
vector<vector<int>>ABCD;

void dfs(vector<int> A, int pre) {
  if (A.size() == n) {
    sum = 0;
    for (auto a : ABCD) if (A[a[1]] - A[a[0]] == a[2]) sum += a[3];
    ans=max(ans,sum);
    return;
  }
  for (int i = pre; i <= m; i++) {
    vector<int> newA = A;
    newA.push_back(i);
    dfs(newA, i);
  }
}

int main() {
    ll i;
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {

        cin >> n >> m >> Q;
        for (int a, b, c, d; cin >> a >> b >> c >> d;) ABCD.push_back({--a, --b, c, d});
        vector<int> A;
        dfs(A, 1);
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
int main(void){
  int i,a,b,c,N,l;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
      l=b;
      b=a;
      a=l;
    }
    if(b>c){
      l=c;
      c=b;
      b=l;
    }
    if(c*c==(b*b+a*a))
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;



double dis(int i, int j, const vector<pair<int,int>> & pos ){
    return sqrt(pow(pos[i].first-pos[j].first,2)+pow(pos[i].second-pos[j].second,2));
}

int main(){
    int num=1;
    double sum=0.0;
    int n;
    cin>>n;
    vector<pair<int,int>> pos(n);
    vector<int> v(n);
    for(int i=0; i<n;i++) v[i]=i;
    for(auto & e : pos){int a,b=0; cin>>a>>b; e = make_pair(a,b);}
    std::iota(v.begin(),v.end(),0);
    do{
        for(int i=0;i<n-1;i++){
            //cout << v[i] << " " << v[]endl;
            sum += dis(v[i],v[i+1],pos);
        }
        //cout << "==" << endl;
    }while(next_permutation(v.begin(),v.end()));

    for(int i=2; i<n+1;i++) num*=i;
    //cout << num << endl;
    cout <<setprecision(10)<<sum/num<<endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
using namespace std;
int		cnt;

int		main(void)
{
	string	a;
	cin >> a;
	int		j = a.size() - 1;
	for (int i = 0; i < (a.size() + 1) / 2; i++, j--)
	{
		if (a.at(i) != a.at(j))
			cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int a[100005];
int p[100005];
int main()
{

    int n;
    cin>>n;
    memset(p,-1,sizeof(p));
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        p[a[i]]++;
    }
    int sum=0;
    for (int i=1;i<=n;++i){
        sum+=p[a[i]];
        p[a[i]]=0;
    }
    cout<<n-sum-(sum&1)<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stack>

using namespace std;

void Solution()
{
    int a;
    int b;
    int c;
    
    int rect = 0; //initializing
    int lozen = 0;
    
    char comma;
    
    while (cin>>a>>comma>>b>>comma>>c)
    {
        if (a * a + b * b == c * c)
        {
            rect++;
        }
        else if (a == b)
        {
            lozen++;
        }
    }
    cout<<rect<<endl;
    cout<<lozen<<endl;
}

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

Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int n;
ll a[200010];
ll b[200010];

int main() {
    cin >> n;
    imfor(i, n) {
        cin >> a[i];
    }
    int counter = 0;
    if (n % 2 == 1) {
        for (int i = n - 1; i >= 0; i -= 2) {
            b[counter] = a[i];
            counter++;
        }
        for (int i = 1; i <= n - 2; i += 2) {
            b[counter] = a[i];
            counter++;
        }
    }
    else {
        for (int i = n - 1; i >= 1; i -= 2) {
            b[counter] = a[i];
            counter++;
        }
        for (int i = 0; i <= n - 2; i += 2) {
            b[counter] = a[i];
            counter++;
        }
    }
    imfor(i, n) {
        cout << b[i] << " ";
    }
    cout << endl;
}

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

ll choose(ll n, ll k) {
    if (k == 0) return 1;
    return (n * choose(n-1, k-1)) / k;
}

ll combination(int n, int r) {
    if(n < r)
        return 0;
    if(n-r < r)
        r = n-r;
    long long ret = 1;
    for(int i=0; i<r; i++){
        ret *= (n--);
        ret /= i+1;
    }
    return ret;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int A_orig = A;
    auto weights = map<ll, int>();
    auto v = vector<ll>(N);
    for (auto i=0; i<N; i++) { 
        cin >> v[i];
        weights[v[i]]++;
    }
    sort(v.rbegin(), v.rend());
    double ans1 = accumulate(v.begin(), v.begin() + A, 0.0) / A;
    printf("%.15f\n", ans1);

    while (!weights.empty()) {  
        int x = weights.rbegin()->second;
        if (x > A) break;
        A -= x;
        B = A;
        weights.erase(--weights.end());
    }
    int x = 0;
    if (!weights.empty())
        x = weights.rbegin()->second;
    ll ans2 = 0;
    for (int i=A; i<=min(x, B); i++) 
        ans2 += combination(x, i);
    cout << ans2 << endl;

    /*
    ll num_ways = 1;
    if (weights.size() == 1) {
        ll count = weights.begin()->second;
        if (count > A) {
            num_ways--;
            ll i = A;
            while (i <= count) {
                num_ways += combination(count, i);
                i++;
            }
        }
    }
    else {
        for (auto rit = weights.rbegin(); rit != weights.rend(); rit++) {
            if (A <= 0) 
                break;
            else if (rit->second > A) 
                num_ways = combination(rit->second, A);     
            A -= rit->second;
        }
    }
    cout << num_ways << endl;
    */
    return 0;
}


Measured memory_bytes: 256