akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,a[2005][2005];
bitset<2005>win[2005];
bitset<2005>dp[2][2005];
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
	    char s[2005]; scanf("%s",&s);
		for(int j=1;j<i;j++){
			a[i][j] = s[j-1]-'0';
			a[j][i] = 1-a[i][j];
		}
	}
	repn(i,n) repn(j,n) win[i][j] = a[i][j];
	repn(i,n){
		dp[0][i][i] = 1;
		dp[1][i][i] = 1;
	}
	for(int L=2;L<=n;L++){
		for(int i=1;i+L-1<=n;i++){
			//dp[0][i][i+L-1]
			bool f = (win[i]&dp[1][i+1]&dp[0][i+L-1]).any();
			if(f) dp[0][i+L-1][i] = 1;
			//dp[1][i][i+L-1]
			f = (win[i+L-1]&dp[1][i]&dp[0][i+L-2]).any();
			if(f) dp[1][i][i+L-1] = 1;
		}
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		if(dp[1][1][i] && dp[0][n][i]) ans++;
	}
	cout << ans << endl;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(void){
    lli n, k, q;
    cin >> n >> k >> q;
    vector<lli> a(q);
    for(auto& i : a) cin >> i;
    vector<lli> p(n, k-q);
    for(int i = 0; i < q; i++){
        p.at(a.at(i)-1)++;
    }
    for(auto i : p){
        if(i > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


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


int a()
{
    int s, w;
    std::cin >> s >> w;
    
    if(s <= w)
    {
        std::cout << "unsafe" << std::endl;
    }
    else
    {
        std::cout << "safe" << std::endl;
    }
    
    return 0;
}



int main(int argc, const char * argv[])
{
    a();
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define maxn 600100
#define base 1000000007

using namespace std;

int n,m,l,r;
ll fac[maxn],finv[maxn],inv[maxn],ans;

void init() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2;i<maxn;i++) {
        inv[i] = base - inv[base%i]*(base/i)%base;
        fac[i] = (1ll*fac[i-1]*i)%base;
        finv[i] = (finv[i-1]*inv[i])%base;
    }
}

ll C(int k,int n) {
    if (n<k||k<0) return 0;
    return fac[n]*finv[k]%base*finv[n-k]%base;
}

ll solve2(int R1,int n,int m,int x) {
    ll tmp=0;
    if (R1<0) return 0;
    for (int k=0;k<=n-m&&k*x<=R1;k++) {
        int R2 = R1-k*x;
        ll ea = C(k,n-m) * C(R2,R2+n)%base;
        if (k%2==0) tmp = (tmp+ea)%base;
        else tmp = (tmp-ea+base)%base;
    }
    return tmp;
}

ll solve(int R,int n,int m) {
    ll tmp = C(R,R+n);
    for (int x=1;m*x<=R;x++) tmp = (tmp - C(m,n)*(solve2(R-x*m,n,m,x) - solve2(R-(x+1)*m,n,m,x)+base)%base + base)%base;
    return tmp;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin);
    cin>>n>>m>>l>>r;
    init();
    ans = (solve(r,n,m) - solve(l-1,n,m) + base)%base;
    cout << ans;
}


Measured memory_bytes: 14336
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;
int P;
vector<int> J;
int main()
{
	int p, j;
	long long sum,max_m;
	int N;
	while (1) {
		sum = 0;
		max_m = 0;
		cin >> N;
		if (N == 0) break;
		for (int i = 0; i < N; i++) {
			cin >> p;
			sum += p;
		}
		for (int i = 0; i < N - 1 ; i++) {
			cin >> j;
			J.push_back(j);
		}
		sort(J.begin(), J.end(), greater<int>());
		max_m = sum * N;
		for (int i = 1; i < N; i++) {
			max_m = max(max_m, (sum + J[i - 1])*(N - i));
			sum += J[i - 1];
		}
		cout << max_m << endl;
		J.clear();
	}
	return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int DAYS;
const int TYPES = 26;

vector<int> c;
vector<vector<ll>> s;

vector<ll> simulate(vector<int> &t) {
    vector<vector<int>> last(TYPES, {-1});
    vector<ll> ret(DAYS);
    ll now = 0;
    for (int i = 0; i < DAYS; i++) {
        now += s[i][t[i]], last[t[i]].push_back(i);
        for (int j = 0; j < TYPES; j++) {
            now -= c[j] * (i - last[j].back());
        }
        ret[i] = now;
    }
    return ret;
}

ll scoring(vector<ll> &&satisfying) {
    ll score = 0;
    for (auto &x:satisfying)score += max(1000000 + x, 0LL);
    return score;
}

int main() {
    cin >> DAYS;
    c.resize(TYPES);
    for (int i = 0; i < TYPES; i++)cin >> c[i];
    s.assign(DAYS, vector<ll>(TYPES));
    for (int i = 0; i < DAYS; i++) {
        for (int j = 0; j < TYPES; j++) {
            cin >> s[i][j];
        }
    }

    vector<int> t(DAYS);
    for (int i = 0; i < DAYS; i++) cin >> t[i], t[i]--;

    for (auto x:simulate(t))cout << x << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cstdio>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;
const ll mod = 1000000007;

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

Measured memory_bytes: 256
// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int n; 

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int T;
 //    cin >> T;
 
 //    while (T--) {
        
 //    }

	cin>>n;
	if(n%1000 == 0) {
		cout<<0<<endl;
	} else {
		cout<<1000-(n%1000)<<endl;
	}
	return 0;
}

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


def main():
    n, k = map(int, input().split())
    ans = 0

    for i in range(1, n + 1):
        if i >= k:
            ans += 1
        else:
            m = 1

            while i * 2 ** m < k:
                m += 1

            ans += (1 / 2) ** m

    print(ans / n)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner scan =new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int total;

		if(a==b && b==c) total=1;
		else if((a==b && b!=c)||(b==c && c!=a)||(a==c && b!=c)) total=2;
		else total=3;
		System.out.println(total);
	}
	
}

Measured memory_bytes: 20692
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007

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

    int a,b,c,x,y;
    int ans = 0;
    cin >> a >> b >> c >> x >> y;
    if(x>=y){
        if(a+b>=2*c){
            ans += 2*c*y;
            if(a>=2*c){
                ans += 2*c*(x-y);
                cout << ans;
                return 0;
            }else
            {
                ans += a*(x-y);
                cout << ans;
                return 0;
            }
            
        }else
        {
            ans += a*y+b*y;
            if(a>=2*c){
                ans += 2*c*(x-y);
                cout << ans;
                return 0;
            }else
            {
                ans += a*(x-y);
                cout << ans;
                return 0;
            }
        }
        
    }else{
        if(a+b>=2*c){
            ans += 2*c*x;
            if(b>=2*c){
                ans += 2*c*(y-x);
                cout << ans;
                return 0;
            }else
            {
                ans += b*(y-x);
                cout << ans;
                return 0;
            }
            
        }else
        {
            ans += a*x+b*x;
            if(b>=2*c){
                ans += 2*c*(y-x);
                cout << ans;
                return 0;
            }else
            {
                ans += b*(y-x);
                cout << ans;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define sqr(x) ((x)*(x))

long long a, b, c, Rem;

int main()
{
	cin >> a >> b >> c;
	Rem = (c - (a + b));
	if ((sqr(Rem) > a * b * 4) && (Rem > 0)) puts("Yes");
	else puts("No");
}

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

using namespace std;

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

double pr[100001][50];
double dp[100001];

int main() {
  pr[0][0] = 1;
  rep (i, 100000) {
    pr[i + 1][0] = 1;
    rep (j, 49) pr[i + 1][0] -= pr[i + 1][j + 1] = pr[i][j] / (1 << j);
    dp[i + 1] = dp[i] + 1 - pr[i + 1][0];
  }
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    printf("%.12lf\n", dp[n]);
  }
}

Measured memory_bytes: 41036
s = input()
n = len(s)
dp = [ [0,0] for i in range(n) ]
dp[0][0] = ord(s[0])-ord('0')
dp[0][1] = 11-(ord(s[0])-ord('0'))
for i in range(n-1):
  d = ord(s[i+1])-ord('0')
  dp[i+1][0] = min(dp[i][0], dp[i][1]) + d
  dp[i+1][1] = min(dp[i][0]+11-d, dp[i][1]+9-d)
print(min(dp[n-1][0],dp[n-1][1]))

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
  	if(a-b >= 0) 
    cout << (b * c) + (a-b) * d << endl;
  else
    cout << a * c << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

struct UnionFind {
    vector<int> node;
    int N;

    UnionFind(){}
    UnionFind(int N) : N(N), node(N,-1) {}

    void init(int x) {
        node.assign(x,-1);
        N = x;
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (node[x] > node[y]) swap(x,y);
        node[x] += node[y];
        node[y] = x;
        N--;
        return true; 
    }

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

    int root(int x) {
        if (node[x] < 0) return x;
        return node[x] = root(node[x]);
    }

    int size(int x) {return -node[root(x)];}

    int count() const {return N;}
};

void YES() {
    cout << "Yes" << ln;
    exit(0);
}
void NO() {
    cout << "No" << ln;
    exit(0);
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    
    vector<int> idx(N);
    iota(all(idx),0);
    sort(all(idx),[&](int i, int j){return B[i] < B[j];});

    vector<int> arr(N);
    rep(i,N) arr[i] = A[idx[i]];
    swap(arr,A);
    sort(all(B));
    iota(all(idx),0);
    sort(all(idx),[&](int i, int j){return A[i] < A[j];});
    UnionFind uf(N);
    rep(i,N) {
        if (A[idx[i]] > B[i]) NO();
        uf.merge(i,idx[i]);
    }
    if (uf.count()!=1) YES();
    rep(i,N-1) {
        if (A[idx[i+1]] <= B[i]) YES();
    }

    NO();

}

Measured memory_bytes: 2176
import java.util
import java.util.Scanner

object Main {
  val MOD = 1000000007

  def solve(N: Int, A: Array[Int]): Long = {
    util.Arrays.sort(A)

    if (N % 2 == 1) {
      def testExpected(i: Int): Boolean = {
        val expected = if (i == 0) 0 else (i + 1) / 2 * 2
        A(i) == expected
      }
      if (A.indices.forall(testExpected)) pow_mod(2, (N - 1) / 2, MOD) else 0
    } else {
      def testExpected(i: Int): Boolean = {
        val expected = i / 2 * 2 + 1
        A(i) == expected
      }
      if (A.indices.forall(testExpected)) pow_mod(2, N / 2, MOD) else 0
    }
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val A = Array.ofDim[Int](N)
    A.indices foreach (i => A(i) = sc.nextInt())
    println(solve(N, A))
  }

  /**
    *
    * 7 = (2 * 3) + 1 = (2 * (2 + 1)) + 1
    *
    */
  def pow_mod(x: Int, n: Int, m: Int): Int = {
    def step(x0: Long, n0: Int): Long = {
      n0 match {
        case 0 => 1
        case _ =>
          val r = step(x0 * x0 % m, n0 / 2)
          if (n0 % 2 == 1) r * x0 % m else r
      }
    }
    step(x.toLong, n).toInt
  }
}


Measured memory_bytes: 51388
def divisor(n):
    divisors = []
    i = 1
    while i * i <= n:
        if n % i == 0:
            divisors.append(i)
            if i * i < n:
                divisors.append(n // i)
        i += 1
    divisors.sort()
    return divisors

N, K = map(int, input().split())
A = list(map(int, input().split()))
divisors = divisor(sum(A))
for d in divisors[::-1]:
    r = [a % d for a in A]
    r.sort(reverse=True)
    i = sum(r) // d
    if sum(r[i:]) <= K:
        print(d)
        exit()

Measured memory_bytes: 41820
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    int alice = 0;
    int bob = 0;
    rep(i, n) {
        if (i % 2)
            bob += a.back();
        else
            alice += a.back();
        a.pop_back();
    }
    cout << alice - bob << endl;
}

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

int main()
{
	int A, B, C, X;
	int count = 0;
	cin >> A >> B >> C >> X;

	if (X % 50 != 0)
	{
		cout << "0";
		return 0;
	}

	int num = X / 50;

	for (int i = 0; i <= A; i++)
	{
		for (int j = 0; j <= B; j++)
		{
			for (int k = 0; k <= C; k++)
			{
				if (10 * i + 2 * j + k == num)
				{
					count++;
				}
			}
		}
	}
	cout << count;

}

Measured memory_bytes: 256
n,m,k=map(int,input().split())
mod=10**9+7
A=n*m-2
from math import factorial
def Comb(N, K):
    a = factorial(N) % mod
    b = factorial(K) % mod
    c = factorial(N-K) % mod
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
v=Comb(A,k-2)
t=0
y=0
for i in range(1,n):
  t+=i*(n-i)*m*m%mod
for i in range(1,m):
  y+=i*(m-i)*n*n%mod

ans=v*(t+y)
print(ans%mod)

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

using namespace std;

int main()
{
    int H1, M1, H2, M2, K;

    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int Htemp = H2 - H1;
    int HhenkanM = Htemp * 60;

    int Ans = HhenkanM + M2 - M1 - K;

    cout << Ans << endl;
}

Measured memory_bytes: 3620
-- Integral

main = getContents >>= putStr . solve

solve :: String -> String
solve = unlines . map (show . integral . read) . lines

integral :: Int -> Int
integral d = sum . map (d *) . map (\x -> x*x) $ xs
  where
    xs = [x' * d | x' <- [1..(600 `div` d) - 1]]

Measured memory_bytes: 4008
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

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

        string ioi = "I";
        for(int i=0; i < n; i++) ioi += "OI";
        string s;
        cin >> s;

        int count = 0;
        for(int i=0; i < s.size()-ioi.size(); i++){
            if(s.substr(i, ioi.size()) == ioi) count++;
        }

        cout << count << endl;
    }
}

Measured memory_bytes: 2136
n, m = map(int, input().split())
p = list(int(x) - 1 for x in input().split())
s = [tuple(int(x) - 1 for x in input().split()) for _ in range(m)]

a = {i:i for i in range(n)}

def root(t):
    if a[t] == t:
        return t
    else:
        a[t] = root(a[t])
        return  a[t]

for x, y in s:
    a[root(x)] = root(y)
    
ans = 0
for i in range(n):
    if root(i) == root(p[i]):
        ans += 1

print(ans)

Measured memory_bytes: 33996
#include <iostream>
#include <complex>
#include <string>

using namespace std;

int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};
char dice[6][4] = {
	{5,1,2,4}, {1,3,1,0}, {0,2,3,2},
	{2,4,5,1}, {4,0,4,3}, {3,5,0,5}
};
char side[] = {1,2,4,5};
int dice_color[6] = {1, 4, 2, 6, 3, 5};

int getUpper(int a, int b){
	if(a%3 == 0) return dice_color[a+0];
	if(b%3 == 0) return dice_color[b+1];
	for(int i=0;i<4;i++)
		if(a==side[i]&&b==side[(i+1)%4]) return dice_color[2];
	return dice_color[5];
}


int main(){
	int n;
	while(cin >> n, n){
		string s;
		int a = 0, b = 1, c = 0;
		int res = 1;
		for(int i=0;i<n;i++){
			cin >> s;
			int d = -1;
			if(s[0]=='L') c = (c+3)%4; 
			if(s[0]=='R') c = (c+1)%4;
			if(s[0]=='W') d = 1;
			if(s[0]=='N') d = 0;
			if(s[0]=='E') d = 3;
			if(s[0]=='S') d = 2;
			if(d!=-1){
				a = dice[a][(d+c)%4];
				b = dice[b][(d+c)%4];
			}
			res += getUpper(a, b);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
 
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

const ll mod = (int)1e9 + 7;
const int maxN = (int)2e5 + 100;
 

ll sum(ll a, ll b) {
    return (a + b) % mod;
}
 
ll calc(int n) {
  return (ll)(n) * (ll)(n + 1) / (ll)2;
}

ll getMax(int n, int i) {
  return calc(n) - calc(n - i);
}

ll getMin(int n, int i) {
  return calc(i - 1);
}
 
void solve() {
  ll dp[maxN];
  int n, k;
  cin >> n >> k;
  dp[1] = n + 1;
  for (int i = 2 ; i <= n + 1 ; i++) {
    dp[i] = getMax(n, i) - getMin(n, i) + (ll)1;
  }
  ll res = 0;
  for (int i = k ; i <= n + 1 ; i++) res = sum(res, dp[i]);
  cout << res;
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
 
  return 0;
}

Measured memory_bytes: 5216
# 2019-11-22 16:25:33(JST)
import sys


def main():
    n, a, b = [int(x) for x in sys.stdin.readline().split()]

    min_possible = a * (n - 1) + b
    max_possible = b * (n - 1) + a

    ans = max_possible - min_possible + 1
    print(max(ans, 0))

if __name__ == '__main__':
    main()


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

#define ll long long int
#define f(i,n) for(ll i = 0; i < n ; i++)
#define fn(i,n) for(ll i = 1; i < n ; i++)
#define F first 
#define pb push_back
#define S second
using namespace std;
ll dp[100005][4];
ll n;
ll mn = INT_MAX;
ll sol(ll a[][3], ll i, ll k)
{
   
  
  if(i == n-1){
    if(k == 0)
        return dp[i][k] = max(a[i][1],a[i][2]);
    if(k == 1)
        return dp[i][k] = max(a[i][0],a[i][2]);
    if(k == 2)
        return dp[i][k] = max(a[i][1],a[i][0]);

    return dp[i][k] = max(a[i][0], max(a[i][1],a[i][2]));
  }
      if(dp[i][0] == -1 || dp[i][1] == -1 || dp[i][2] == -1){
      dp[i][0] = a[i][0] + sol(a, i+1,0);
      dp[i][1] = a[i][1] + sol(a, i+1,1);
      dp[i][2] = a[i][2] + sol(a, i+1,2);}
       

  if(k == 0)
  {
       
      return  max(dp[i][1],dp[i][2]);

  }

  if(k == 1)
  {
     
      return  max(dp[i][0],dp[i][2]);

  }

  if(k == 2)
  {
     
      return  max(dp[i][1],dp[i][0]);

  }
  
          
  return dp[i][k] = max(a[i][1] + sol(a, i+1, 1), max(a[i][0] + sol(a, i+1, 0),a[i][2] + sol(a,i+1,2)));
  
}


 
int main()
{

     #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
     #endif
     
         //ll n;
         cin>>n;
         ll a[n][3];
         bool l[3];
         f(i,3) l[i] = 0;
         f(i,n)
         {
            cin>>a[i][0]>>a[i][1]>>a[i][2];
         }
         //f(i,10) dp[i] = 100;
         memset(dp,-1,sizeof(dp));
         sol(a,0,3);
         cout<<dp[0][3]<<endl;
         
        
         
   return 0;
}


Measured memory_bytes: 19868
// abc151_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;

    vector<int> wa(N);
    vector<bool> ac(N);
    int pena = 0;
    int ac_num = 0;
    REP(i, M){
        int p; string S;
        cin >> p >> S; p--;

        if (S == "AC"){
            if (ac[p] == false){
                ac[p] = true;
                ac_num++;
                pena += wa[p];
            }
        } else {
            wa[p]++;
        }
    }
    print(ac_num, pena);

    return 0;
}


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

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

struct Node {
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = x;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

Node *find(Node *x, int k) {
  while (x != NIL && k != x->key) {
    if (k < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  return x;
}

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, x;
  string s;
  cin >> n;
  rep(i,n) {
    cin >> s;
    if (s == "insert") {
      cin >> x;
      insert(x);
    } else if (s == "print") {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    } else if (s == "find") {
      cin >> x;
      Node *ans = find(root, x);
      if (ans == NIL) cout << "no" << endl;
      else cout << "yes" << endl;
    } else {
      cout << "Invalid command: " << s << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 21912
# -*- coding: utf-8 -*-
"""
C - Dice and Coin
https://atcoder.jp/contests/abc126/tasks/abc126_c

"""
import sys


from decimal import *
from math import log2, ceil

#TLE
def __solve(N, K):
    getcontext().prec = 30
    ans = Decimal(0)
    for i in range(1, N+1):
        if i >= K:
            t = Decimal (1/N)
        else:
            t = Decimal(1/N/2**ceil(log2(K/i)))
        ans += t
    return ans


def solve(N, K):
    ans = 0
    for i in range(1, N+1):
        if i >= K:
            t = 1 / N
        else:
            t = 1/N/2**ceil(log2(K/i))
        ans += t
    return ans


def main(args):
    N, K = map(int, input().split())
    ans = solve(N, K)
    print(ans)


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


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

// 素数判定
int isPrime(int x) {
    int i;
    if (x < 2) return 0;
    else if (x == 2) return 1; // 2は素数
    if (x % 2 == 0) return 0; //偶数は素数ではない
    for (i = 3; i*i <= x; i += 2) { // i が x の平方根以下の間
        if (x % i == 0) return 0;
    }
    return 1;
}

int main() {
    int n, x, i;
    int cnt = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        if (isPrime(x)) cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll x[110], y[110], h[110];
ll n;

ll mem[110][110];

int main(){
    cin >> n;
    int zero_cou = 0;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] == 0)   ++zero_cou;
    }

    for(int k = 0; k < n; k++){
        if(h[k] == 0)   continue;
        for(int i = 0; i < 101; i++){
            for(int j = 0; j < 101; j++){
                mem[i][j] = abs(i-y[k]) + abs(j-x[k]) + h[k];
            }
        }
    }

    for(int i = 0; i < 101; i++){
        for(int j = 0; j < 101; j++){
            bool f = true;
            for(int k = 0; k < n; k++){
                if(max((ll)0, mem[i][j] - abs(x[k]-j) - abs(y[k]-i)) != h[k]){
                    f = false;
                    break;
                }
            }
            if(f){
                cout << j << ' ' << i << ' ' << mem[i][j] << endl;
                return 0;
            }
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i, n){
    int a;
    cin >> a;
    if(i % 2 == 0 && a % 2 == 1)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
num = []
for i in range(3):
    v1,v2 = map(int,input().split())
    num.append(v1)
    num.append(v2)

a = num.count(1)
b = num.count(2)
c = num.count(3)
d = num.count(4)

if a>2 or b>2 or c>2 or d>2:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
int i,min=1000,t;
char s[11];
scanf("%s",s);
for (i=0;s[i+2];i++){
t=((int)s[i]-48)*100+((int)s[i+1]-48)*10+(int)s[i+2]-48;
t-=753;
if (t<0) t*=-1;
if (min>t) min=t;
}
printf("%d",min);
return 0;
}


Measured memory_bytes: 128
import sys
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
for i in range(X+1,Y+1):
    if max(x) < i <= min(y):
        print("No War")
        sys.exit()
print("War")


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

using namespace std;

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

void solve() {
    int n; cin >> n;
    vector<bool> a(n);
    {
        string s; cin >> s;
        for (int i = 0; i < n; i++) {
            a[i] = s[i]=='x';
        }
    }
    vector<bool> res(n);
    rep(_x)rep(_y){
        res[0] = _x; res[1] = _y;
        for (int i = 2; i < n; i++) {
            res[i] = res[i-1]^a[i-1]^res[i-2];
        }
        if ((res[0]^res[1]^res[n-1]) == a[0] && a[n-1] == (res[n-2]^res[n-1]^res[0])) {
            for (bool x: res) {
                cout << (x?'W':'S');
            }
            return;
        }
    }
    cout << -1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int co = 0;
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '+') co++;
    else co--;
  }
  cout << co << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 305
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
char s[MN];
int a[MN][MN],n,res;
int main()
{
	n=in();
	for (int i=0;i<n;++i){
		scanf("%s",s);
		for (int j=0;j<n;++j) a[i][j]=s[j]-'a';
	}
	for (int i=0;i<n;++i){
		bool mk=1;
		for (int j=0;j<n;++j)
		for (int k=0;k<n;++k){
			int dx=(n+j)%n,dy=(n+k-i)%n;
			if (a[j][k]!=a[dy][(i+dx)%n]) {mk=0;break;}
		}res+=(mk*n);
	}
	printf("%d",res);return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl
int gcd(int x, int y){
    if ((x==1)||(y==1)) return 1;
    if (x>y) {
        if (x%y==0) {
            return y;
        }else{
            return gcd(y, x%y);
        }
    }else{
        if (y%x==0) {
            return x;
        }else{
            return gcd(x, y%x);
        }
    }
}
int main() {
    IN(int, r);
    IN(int, d);
    IN(int, x);
    REP(i, 10){
        x = r*x-d;
        COUT(x);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a,b,k; cin >> k >> a >> b;
    if(a/k == b/k && a%k != 0) cout << "NG" << endl;
    else cout << "OK" << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;   //author: madmin2619/mintu_agarwal
     
#define nfs() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define pf push_front
#define forin(i, n) for(int i=0;i<n;i++)
#define tr(c, it) for(auto it=c.begin();it!=c.end();it++)
#define sz(c) c.size()
#define all(c) c.begin(),c.end()
#define ff first
#define ss second
#define m_p(x, y) make_pair(x, y)

const int inf = 1e15L; 

const int M = 1e9 + 7;
const int N = 100050;
int vis[N+1];
int dp[N+1];
vector<int> adj[N];

int DP(int u){
    if(vis[u])
        return dp[u];
    for(int v: adj[u]){
        dp[u]=max(dp[u], DP(v)+1);
    }
    vis[u]=1;
    return dp[u];
}

int32_t main(){
    nfs()
    int n, i, j, k, W, sum=0, m, u, v;
    cin >> n >> m;
    fill(dp, dp+n+1, 0);
    fill(vis, vis+n+1, 0);
    map<int, bool> mp;
    forin(i, m){
        cin >> u >> v;
        adj[u].pb(v);
        mp[v]=true;
    }
    int res=0;
    forin(i ,n){
        if(!mp[i+1])
            res=max(res, DP(i+1));
    }
    cout << res << "\n";
}

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

int main(){
    int r,g,b,n; cin>>r>>g>>b>>n;

    long long ans=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(n-i*r-j*g>=0&&(n-i*r-j*g)%b==0) ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>l>>r>>d;
    for(i=l;i<=r;i++)
    {
        if(i%d==0)c++;
    }
    cout<<c<<endl;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll INF=100000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}
vector<ll> vectorprime(ll x){
	vector<bool> is_prime(x+1);
	vector<ll> prime;
	rep(i,x+1) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=x;i++){
		if(is_prime[i]){
			prime.pb(i);
		}
		for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
	}
	return prime;
}
//a,b x
int main(){
	ll N,M; cin>>N>>M;
	vector<P> place(N);
	vector<P> point(M);
	vector<ll> ans(N);
	vector<ll> dis(N,INF);
	rep(i,N){
		ll A,B; cin>>A>>B;
		place[i]=mp(A,B);
	}
	rep(j,M){
		ll A,B; cin>>A>>B;
		point[j]=mp(A,B);
	}
	rep(i,N){
		rep(j,M){
			if(abs(place[i].a-point[j].a)+abs(place[i].b-point[j].b)<dis[i]){
				dis[i]=abs(place[i].a-point[j].a)+abs(place[i].b-point[j].b);
				ans[i]=j;
			}
		}
	}
	rep(i,N) cout<<ans[i]+1<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

using namespace std;

int n, sum, t, tot, flag, ans;
int a[105], p[105];
int main()
{
	ans = 0;
	flag = 0;
	tot = 0;
	t = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++) 
	{
		if(a[i] % 10 == 0) ans += a[i];
		else {
			p[++t] = a[i];
			tot += a[i];
		}
	}
	sort(p + 1, p + 1 + t);
	if(tot % 10 == 0) {
		for(int i = 1; i <= t; i++)
		{
			tot -= p[i];
			if(tot % 10 != 0) {flag = 1; break;}
		}
	}
	else flag = 1;
	if(flag == 1) printf("%d\n", tot + ans);
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 128
q = [int(input()) for _ in range(5)]
ans = sum(q) + 10000
for i in range(5):
    m = 0
    for j in range(5):
        if i == j:
            m += q[i]
        else:
            if q[j]%10 == 0:
                m += q[j]
            else:
                m += (q[j]//10+1)*10
    ans = min(ans,m)

print(ans)


Measured memory_bytes: 38384
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    #a>=b>=c (a,b,c)->(x,y,z) no junnretu kakeru
    ans=[0]*N
    for a in range(1,101):
        for b in range(1,a+1):
            for c in range(1,b+1):
                temp=((a+b)**2+(c+b)**2+(a+c)**2)//2
                if temp>N:break
                #print(a,b,c,temp)

                if a==b:
                    if b==c:
                        cnt=1
                    else:
                        cnt=3
                elif b==c:cnt=3
                else:cnt=6
                ans[temp-1]+=cnt
    print(*ans,sep="\n")
#%%submit!
resolve()

Measured memory_bytes: 69028
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 998244353; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


void solve() {
	int N, A, B; cin >> N >> A >> B;
	if (A > B)swap(A, B);
	int l = min(N - A, B - 1);

	if ((B - A) % 2 == 0)print((B - A) / 2);
	else {
		ll res = 1e18;
		ll tmp = A - 1 + 1 + (B - A) / 2;
		res = min(res, tmp);
		swap(A, B);
		A = N - A + 1;
		B = N - B + 1;
		tmp = A - 1 + 1 + (B - A) / 2;
		res = min(res, tmp);
		print(res);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 256
#include <cstdio>

#define Swap(a, b) ((a)^=(b),(b)^=(a),(a)^=(b))

int main()
{
    int N ,cnt;
    scanf (" %d", &N);
    int A[N];
    
    for (int i = 0; i < N; i++){
        scanf (" %d", &A[i]);
    }

    cnt = 0;
    for (int i = 0; i <= N - 1; i++){
        for (int j = N - 1; j >= i + 1; j--){
            if (A[j] < A[j-1]){
                cnt++;
                Swap(A[j], A[j-1]);
            }
        }
    }

    for (int i = 0; i < N; i++){
        if (i != N - 1){
            printf("%d ", A[i]);
        }
        if (i == N - 1){
            printf("%d\n", A[i]);
        }
    }

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

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

int main()
{
    for (int i = 1; i < 10; i++){
        for (int j = 1; j < 10; j++){
            cout << i << "x" << j << "=" << i * j << endl;
        }
    }
    return (0);
}



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

int64_t n,res=0,a[305][305];
bool Free[305][305];

int main()
{
    cin>>n;
    for(int64_t i=1;i<=n;i++)
        for(int64_t j=1;j<=n;j++)
            cin>>a[i][j];
    for(int64_t t=1;t<=n;t++)
        for(int64_t i=1;i<=n;i++)
            for(int64_t j=1;j<=n;j++)
            {
                if(a[i][j]>a[i][t]+a[t][j])
                {
                    cout<<-1;
                    return 0;
                }
                if(a[i][j]==a[i][t]+a[t][j]&&a[i][t]>0&&a[t][j]>0)
                    Free[i][j]=true;
            }
    for(int64_t i=1;i<=n;i++)
        for(int64_t j=i+1;j<=n;j++)
            if(Free[i][j]==false)
                res+=a[i][j];
    cout<<res;
}


Measured memory_bytes: 1024
#include <stdio.h>

#define Notfound -1;
int S_number, T_number;
int S_array[100000], T_array[500];
int findlineserch(int ti);

int main(void) {


	int ti;
	int return_find_or_not = 0;
	int overraycount = 0;

	scanf("%d", &S_number);

	for (int si = 0; si<S_number; si++) {
		scanf("%d", &S_array[si]);
	}
	scanf("%d", &T_number);

	for (int ti = 0; ti<T_number; ti++) {
		scanf("%d", &T_array[ti]);
	}

	ti = 0;

	while (T_number--) {

		return_find_or_not = findlineserch(ti);
		if (return_find_or_not != -1) {
			overraycount++;
		}
		ti++;
	}

	printf("%d\n", overraycount);

	return 0;
}

int findlineserch(int ti) {
	int si = 0;
	S_array[S_number] = T_array[ti];

	while (S_array[si] != T_array[ti]) {

		si++;
	}
	if (si == S_number) {
		return Notfound;
	}
	else return si;
}



Measured memory_bytes: 2112
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if(b < 0) {
        if(d < 0) {
            out(a*c);
        }
        else if(0 < c) {
            out(b*c);
        }
        else {
            out(a*c);
        }
    }
    else if(0 < a) {
        if(d < 0) {
            out(a*d);
        }
        else if(0 < c) {
            out(b*d);
        }
        else {
            out(b*d);
        }
    }
    else {
        if(d < 0) {
            out(a*c);
        }
        else if(0 < c) {
            out(b*d);
        }
        else {
            out(max(a*c, b*d));
        }
    }
    
    re0;
}

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

typedef long long ll;
int N;
const int MOD = 1e9 + 7;
using namespace std;

ll F (ll n) {
  // compute 0 (+) 1 (+) ... (+) n
  if (n < 0)
    return 0;
    
  ll y = n % 4;
  if (y == 0)
    return n;
  else if (y == 1)
    return 1;
  else if (y == 2)
    return 1 ^ n;
  else
    return 0;
}


int main() {
  ll A, B; cin >> A >> B;
  ll f1 = F(A - 1);
  ll f2 = F(B);
  cout << (f1 ^ f2) << endl;
}

Measured memory_bytes: 256
local n=io.read("n")
for i=1,3500 do
    for j=1,3500 do
        local a=n*i*j
        local b=(4*i*j-n*j-n*i)
        if b>0 and a%b==0 then
            print(i.." "..j.." "..a//b)
            return
        end
    end
end

Measured memory_bytes: 2788