akhauriyash/Code-Regression huggingface dataset:
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;

long long gcd(long long x, long long y){
			if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

int main(){
int N;
cin >> N;
vector<long long> X(N);
for(int i = 0; i < N;i++){
	cin >> X[i];
}
vector<long long> x = X;
sort(x.begin(),x.end());
long long med_1 = x[N/2];
long long med_2 = x[(N/2)-1];
for(int i = 0; i<N;i++){
	if(X[i]<=med_2){
		cout << med_1 << endl;
	}
	else cout << med_2 << endl;
}
}

Measured memory_bytes: 5376
from collections import deque
n = int(input())
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    graph[a-1].append((b-1, i))
    graph[b-1].append((a-1, i))

queue = deque([0])
seen = [False]*n
seen[0] = True
colors = [None]*n
ans = [None]*(n-1)
while len(queue)>0:
    node = queue.popleft()
    c = 1
    for c_node, edge in graph[node]:
        if seen[c_node]:
            continue
        if colors[node]==c:
            c += 1
        ans[edge] = c
        colors[c_node] = c
        seen[c_node] = True
        queue.append(c_node)
        c += 1
print(max(ans))
for i in ans:
    print(i)

Measured memory_bytes: 40776
package main

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

func main() {
	s := getIntSlice(4)

	ans := ""
	for i := 0; i < (1 << 3); i++ {
		x := s[0]
		ops := make([]string, 3)
		for j := uint(0); j < 3; j++ {
			if (i & (1 << j)) > 0 {
				ops[j] = "+"
				x += s[j+1]
			} else {
				ops[j] = "-"
				x -= s[j+1]
			}
		}
		if x == 7 {
			a := strconv.Itoa(s[0])
			for k := 0; k < 3; k++ {
				a += ops[k] + strconv.Itoa(s[k+1])
			}
			a += "=7"

			ans = a
		}
	}

	fmt.Println(ans)
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanRunes)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    long double a, b, h, m;
    cin >> a >> b >> h >> m;

//    long double hs = 360.0 * h / 12.0 + 30.0 * m / 60.0;
//    long double ms = 360.0 * m / 60.0;
    long double hs = 360.0 * h * 5.0 + 30.0 * m;
    long double ms = 360.0 * m;

    long double t;
    if (hs >= ms) {
        t = hs - ms;
    } else {
        t = ms - hs;
    }

//    if ((int)t > 180) {
//        t = 360.0 - t;
//    }

    long double ans;
    if ((int)t == 0) {
        ans = abs(a - b);
    } else if ((int)t == 180) {
        ans = a + b;
    } else {
        //余弦定理
        long double res = a * a + b * b - 2.0 * a * b * cos(t * M_PI / (180.0 * 60.0));
        ans = sqrt(res);
    }

    cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 4164
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,a[55];
	cin >>n;
	double s=0;
	for(int i=0;i<n;i++) {
		cin >> a[i];
	}
	sort(a,a+n) ;
	s=a[0];
	for(int i=1;i<n;i++) {
		s=(s+a[i]) /2.0;
	}
	cout << s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;

int n, m, k;
int a[N];
map<int, int> mp;

void solve(int test)
{
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++mp[a[i]];
  }
  sort(a, a + n, greater<int>());
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    auto it = mp.find(a[i]);
    if (it->second) {
      --it->second;
      for (int j = 1 << 30; j; j >>= 1) {
        it = mp.find(j - a[i]);
        if (it != mp.end() && it->second) {
          --it->second;
          ++ans;
        }
      }
    }
  }
  cout << ans;
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cout << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


Measured memory_bytes: 10368
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
#define INF (1<<20)
typedef pair<int,int> P;
int fie[111][111];
int mie[111][111];
int cie[4][111][111];
int n,m;
void solves(){
  int x=0,y=0;
  for(int i=y;i<y+m;i++){
    for(int j=x;j<x+m;j++){
      int nx=j-x;
      int ny=i-y;
      cie[0][j][i]=mie[nx][ny];
    }
  }

  for(int i=y;i<y+m;i++){
    for(int j=x;j<x+m;j++){
      int nx=i-y;
      int ny=m-(j-x)-1;
      cie[1][j][i]=mie[nx][ny];
    }
  }

  for(int i=y;i<y+m;i++){
    for(int j=x;j<x+m;j++){
      int nx=m-(i-y)-1;
      int ny=j-x;
      cie[2][j][i]=mie[nx][ny];
    }
  }
  for(int i=y;i<y+m;i++){
    for(int j=x;j<x+m;j++){
      int nx=m-(j-x)-1;
      int ny=m-(i-y)-1;
      cie[3][j][i]=mie[nx][ny];
    }
  }
}
P solve(int x,int y){
  P res=P(INF,INF);
  for(int l=0;l<4;l++){
    P tmp=P(INF,INF);
    for(int i=0;i<m;i++){
      for(int j=0;j<m;j++){
	int nx=j+x;
	int ny=i+y;
	if(cie[l][j][i]==-1) continue;
	if(fie[nx][ny]!=cie[l][j][i]){
	  tmp = P(INF,INF);
	  break;
	}else{
	  tmp=min(tmp,P(ny,nx));
	}
      }
      if(tmp.first==INF) break;
    }
    //    printf(" %d %d\n",tmp.second,res.first);
    res = min(res,tmp);
  }
  return res;
}
main(){
  while(1){
    scanf("%d %d",&n,&m);
    if(!n && !m) break;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	scanf("%d",&fie[j][i]);
    for(int i=0;i<m;i++)
      for(int j=0;j<m;j++)
	scanf("%d",&mie[j][i]);
    solves();
    /*    for(int l=0;l<4;l++){
      for(int i=0;i<m;i++){
	for(int j=0;j<m;j++)
	  printf(" %2d",cie[l][j][i]);
	puts("");
      }
      puts("");
      }*/

    P res=P(INF,INF);
    for(int i=0;i+m<=n;i++){
      for(int j=0;j+m<=n;j++){
	P t=solve(j,i);
	//       	printf("%d %d P:%d %d\n",j,i,t.second+1,t.first+1);
	res = min(t,res);
      }
    }
    if(res.first==INF) puts("NA");
    else printf("%d %d\n",res.second+1,res.first+1);
    
  }
}

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

int main(void){
    string s; cin >> s;
    if(s[0] == s[s.length()-1]){
        if(s.length() % 2 == 0){
            cout << "First" << endl;
        }else{
            cout << "Second" << endl;
        }
    }else{
        if(s.length() % 2 == 0){
            cout << "Second" << endl;
        }else{
            cout << "First" << endl;
        }
    }
    return 0;
}


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

int N;
string S;

int main(){
    cin>>N;
    cin>>S;
    if(N%2==0&&S.substr(0,N/2)==S.substr(N/2,N))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
    #include <iostream>
    #include <vector>
    #include <map>
    #include <cstdio>
    #include <string>
    #include <cmath>
    #include <queue>
    #include <tuple>
    #include <set>
    #include <assert.h>
    #include <sstream>
    #include <string>
    //#include <bits/stdc++.h>
    #define maxs(x,y) x = max(x,y)
    #define mins(x,y) x = min(x,y)
    #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,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
    #define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
    #define SORT(x) sort(x.begin(),x.end())
    #define rn return
    #define fi first
    #define se second
    #define pb push_back
    #define eb emplace_back
    #define mp make_pair
    #define mt make_tuple
    typedef std::pair<int,int> P;
    using namespace std;
    using ll = long long;



    int  MOD = 1e9 + 7;
    uint64_t inverseModp(uint64_t a, uint64_t p) {
        assert(p < (1ull << 63));
        assert(a < p);
        assert(a != 0);
        uint64_t ex = p-2, result = 1;
        while (ex > 0) {
            if (ex % 2 == 1) {
                result = (result*a) % p;
            }
            a = (a*a) % p;
            ex /= 2;
        }
        return result;
    }


    uint32_t nCrModp(uint32_t n, uint32_t r, uint32_t p)
    {
        assert(r <= n);
        if (r > n-r) r = n-r;
        if (r == 0) return 1;
        if(n/p - (n-r)/p > r/p) return 0;
        
        uint64_t result = 1; //intermediary results may overflow 32 bits
        
        for (uint32_t i = n, x = 1; i > r; --i, ++x) {
            if( i % p != 0) {
                result *= i % p;
                result %= p;
            }
            if( x % p != 0) {
                result *= inverseModp(x % p, p);
                result %= p;
            }
        }
        return 0;
    }





    int main1(){
        int m1,m2,d2,d1;
        cin >> m1 >> m2 >> d1 >> d2;
        if (m1!=m2){
            if (d2==1){
                cout << 1;
                rn 0;
            }
        }
        cout << 0;
        rn 0;
    }




    int main(){
        int x;
        cin >> x;
        
        int r = x%100;
        int ans = 0;

        rep(i,5){
            //cout << r << endl;
            ans += (r/(5-i));
            r = r - (r/(5-i))*(5-i);
        }
        if (ans <= x/100){
            cout << 1;

        }
        else{
            cout << 0;
        }
        rn 0;
    }




    int main3(){
        double n,x;
        cin >> n;
        x = n/1.08;


        //cout << x2 << x1;
        rn 0;
    }


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

int main(){
    long long int A,B,C;
    cin>>A>>B>>C;
    if(A%2==0||B%2==0||C%2==0){
        cout<<0<<endl;
    }else{
        cout<<min({A*B,B*C,C*A})<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
    int n,m,mo[1001],bo[1001],ans[1001],A=0,i2;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        ans[i]=0;
    }
    for(int i=0;i<n;i++){
        cin>>mo[i];
    }
    for(int i=0;i<m;i++){
        cin>>bo[i];
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(mo[j]<=bo[i]){
                i2=j;
                break;
            }

        }
        ans[i2]+=1;
    }
    for(int i=0;i<n;i++){
        if(A<ans[i]){
            A=ans[i];
            i2=i;
        }
    }
    cout<<i2+1<<"\n";
}

Measured memory_bytes: 1176
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;

int main(){
    int N;
    cin >> N;
    int count = 0;
    for(int j = 11; j <= N; j+=2){
        int divisor_count = 1;
        for(int i = 2; i < sqrt(j); i++){
            if(j % i == 0){
                divisor_count++;
            }
        }
        if(divisor_count == 4){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
n,a,b,c=map(int,input().split())
l=[]
for i in range(n):
    l.append(int(input()))

def solve(w,x,y,z):
    if w==n:
        if min(x,y,z)>0:
            return abs(x-a)+abs(y-b)+abs(z-c)-30
        else:
            return 10e4
    can0=solve(w+1,x,y,z)
    can1=solve(w+1,x+l[w],y,z)+10
    can2=solve(w+1,x,y+l[w],z)+10
    can3=solve(w+1,x,y,z+l[w])+10
    return min(can0,can1,can2,can3)

print(solve(0,0,0,0))


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

vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
   	res.erase(res.begin());
    return res;
}
long long calc(long long N, long long K)
{
	if(N % K == 0) return calc(N/K,K);
	else return N % K;
}
int main() {
    long long N;
    cin >> N;
    long long answer = 0;
    const auto &res = enum_divisors(N);
    for (long long i = 0; i < res.size(); i++)
    {
    	if ( calc(N,res[i]) == 1 ) answer += 1;
    }
    const auto &res2 = enum_divisors(N-1);
    answer += res2.size();
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 384
from itertools import permutations
from scipy.sparse.csgraph import dijkstra, csgraph_from_dense
N, M, R = map(int, input().split())
t = set(map(int, input().split()))
ABC = [map(int, input().split()) for i in range(M)]

root = [[10**9]*N for i in range(N)]
for a, b, c in ABC:
    root[a-1][b-1] = c
    root[b-1][a-1] = c
g = csgraph_from_dense(root, null_value=10**9)
G = dijkstra(g)
ans = 10**9
for l in permutations(t):
    tmp = 0
    for i in range(1, R):
        tmp += min(root[l[i-1]-1][l[i]-1], G[l[i-1]-1][l[i]-1])
    ans = min(tmp, ans)
print(int(ans))


Measured memory_bytes: 31120
package main

import (
	_ "bufio"
	"fmt"
	_ "math"
	_ "os"
    _ "sort"
	_ "strconv"
	_ "strings"
)

func main() {
    
    var X int
    fmt.Scan(&X)
    
    if X >= 30 {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}

Measured memory_bytes: 1772
def main():
    n, m = map(int, input().split())
    P = [0] * m
    S = [0] * m
    for i in range(m):
        P[i], S[i] = map(str , input().split())
    # p = [int(s) for s in p]
    # 問題によってカウントしたい
    WA = [0] * (n+1)
    # 全体として何個かがわかればいい
    AC = [False] * (n+1)
    cnt = 0
    for i in range(m):
        p = int(P[i])
        if AC[p]:
            continue
        else:
            if S[i] == 'WA':
                WA[p] += 1
            else:
                AC[p] = True
                cnt += WA[p]
    # wa = sum(WA)
    ac = sum(AC)
    print(ac, cnt)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 24620
def main():
    N=int(input())
    A=list(map(int,input().split()))
    if N==0 and A[0]!=1:
        print(-1)
        return 
    if N!=0 and A[0]!=0:
        print(-1)
        return 
    tmp=[0]
    for i,v in enumerate(A[1:][::-1]):
        tmp.append(tmp[-1]+v)
    tmp.pop(0)
    ans=1
    t=1
    for i,v in enumerate(tmp[::-1]):
        t*=2
        if A[i+1]==0:
            if t < A[i+1]:
                print(-1)
                return
            t=min(t,v)
            ans+=t
        else:
            t=min(t,v)
            if t < A[i+1]:
                print(-1)
                return
            ans+=t
            t-=A[i+1]
    print(ans)

main()

Measured memory_bytes: 20168
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; cin >> s;
	int len = s.size();
	vector<int> a(len + 1, 0);
	for(int i = 0, j = 0; i < len; i = j){
		while(j < len && s[i] == s[j]) j++;
		int sz = j - i;
		if(s[i] == '<'){
			for(int k = i; k <= j; k++) a[k] = max(a[k], k - i);
		} else {
			for(int k = j; k >= i; k--) a[k] = max(a[k], j - k);
		}
	}
	long long ans = 0;
	for(int i = 0; i <= len; i++) ans += a[i];
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, a;
	cin>>n;
	ll b=1<<30, c=-(1<<30);
	REP(i, n){
		cin>>a;
		b=min(b, a);
		c=max(c, a);
	}
	cout<<c-b<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int ans[100005];
int n,x,y;
int main(){
    cin>>n>>x>>y;
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            ans[min(abs(i-j),min(abs(i-x)+abs(j-x),min(abs(i-y)+abs(j-y),abs(i-x)+abs(j-y)+1)))]++;
        }
    }
    for(int i=1;i<=n-1;i++)
        printf("%d\n",ans[i]);
    return 0;
}








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

#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
inline int in() { int x; cin >> x; return x; }

void solve() {
  int n = in();
  if (n%2!=0) {
    cout << 0 << endl;
    return;
  }
  int ans = 0;
  n /= 2;
  while(n) {
    n /= 5;
    ans += n;
  }
  cout << ans << endl;
}

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

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

using namespace std;
using ll = long long;

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

int main() {
    ll N = 0;
    cin >> N;
    ll X;
    cin >> X;
    vector<ll> A(N + 1,X);
    for(ll i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    if(N == 1) {
        cout << abs(A.at(1) - A.at(0)) << endl;
        return 0;
    }
    sort(A.begin(),A.end());
    for(ll i = 0; i < N; i++) {
        A.at(i) = A.at(i + 1) - A.at(i);
    }
    for(int i = 0; i < N + 1; i++) {
        //cout << A.at(i);
    }
    //cout << endl;
    ll ans = 1e18;
    if(N == 1) {
        cout << abs(A.at(1) - A.at(0)) << endl;
        return 0;
    }
    for(ll i = 0; i < N - 1; i++) {
        ans = min(ans, gcd(A.at(i), A.at(i + 1)));
        //cout << A.at(i) << ':' << A.at(i + 1) << '=' << gcd(A.at(i), A.at(i + 1)) << endl;
        //cout << ans << endl;
    }
    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 100;

int n, q, x[N];
ll sum[N], f[N], fen[2][N];

void update(int id, int p, ll val) {
  if (p <= 0) return;
  for (; p; p -= p & -p) fen[id][p] = min(fen[id][p], val);
}

ll query(int id, int p) {
  ll res = 1e18;
  if (p <= 0) return res;
  for (; p <= n; p += p & -p) res = min(res, fen[id][p]);
  return res;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> q; q += 2;
  for (int i = 1; i <= q; ++i) {
    cin >> x[i];
    if (i > 1) sum[i] = sum[i - 1] + abs(x[i] - x[i - 1]);
  }
  memset(fen, 0x3f, sizeof(fen));
  for (int i = q - 1; i; --i) {
    f[i] = 1e18;
    f[i] = min(f[i], sum[q] - sum[i + 1] + f[q]);
    f[i] = min(f[i], query(0, x[i]) - x[i] - sum[i + 1]);
    f[i] = min(f[i], query(1, n + 1 - x[i]) + x[i] - sum[i + 1]);
    update(0, x[i + 1], f[i] + sum[i] + x[i + 1]);
    update(1, n + 1 - x[i + 1], f[i] + sum[i] - x[i + 1]);
  }
  cout << f[1];
  return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,N;
    cin >> H >> N;
    int sum = 0;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A.at(i);
        sum += A.at(i);
    }

    if(H<=sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define rep0(i,n) rep(i,0,n)
#define MD 1000000007

char sep[2] = {' ', '\n'};

int main() {
  int i, j, k, l, m, n, x, y, z;

    while(true) {
    cin >> n >> x;
    if (n == 0 && x == 0) break;
    z = 0;
    rep(i,1,n) rep(j,i+1,n) rep(k,j+1,n+1) if (i+j+k == x) z++;
    cout << z << endl;
  }
    

  return 0;
}
  

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int mod =1000000007;
const double PI = acos(-1);

int main(){
    int a,b;cin>>a;
    rep(i,8){
    int l =200+200*(i+1);
    if(l<=a&&a<l+200){
    cout<<8-i<<endl;
    }
    }
}

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

int digit_sum (int n);

int main () {

    int N;
    cin >> N;

    if (N % digit_sum(N) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

int digit_sum (int n) {

    int sum = 0;

    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

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

const int MOD = 1e9+7;

using ll = long long;
template<int MOD> struct MInt {
  ll val;
  MInt() : val(0) {}
  MInt(ll val) : val(val) {
    if (val > MOD) val %= MOD;
    if (val < 0) val += MOD;
  }
  MInt operator-() const {return MInt(-val);}
  MInt operator+(const MInt& n) const {return MInt(val) += n;}
  MInt operator-(const MInt& n) const {return MInt(val) -= n;}
  MInt operator*(const MInt& n) const {return MInt(val) *= n;}
  MInt operator/(const MInt& n) const {return MInt(val) /= n;}
  MInt& operator+=(const MInt& n) {val = (val + n.val) % MOD; return *this;}
  MInt& operator-=(const MInt& n) {val = (MOD + val - n.val) % MOD; return *this;}
  MInt& operator*=(const MInt& n) {val = (val * n.val) % MOD; return *this;}
  MInt& operator/=(const MInt& n) {val = (*this * n.inv()).val; return *this;}
  MInt inv() const {
    MInt pow = val, ans = 1;
    for (int p = MOD - 2; p > 0; p >>= 1) {
      if (p & 1) ans *= pow;
      pow *= pow ;
    }
    return ans;
  }
  friend ostream& operator<<(ostream& os,const MInt& n){os<<n.val;return os;}
};
using mint = MInt<MOD>;

template<typename T>T gcd(T a, T b){return b?gcd(b,a%b):a;}

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

  int A[N], B[N];
  map<int, int> factor[N];
  map<int, int> lcm;
  rep(i, N) {
    cin >> A[i];
    int a = A[i];
    for (int k = 2; k * k <= A[i]; ++k) {
      while (a % k == 0) {
        ++factor[i][k];
        a /= k;
        lcm[k] = max(lcm[k], factor[i][k]);
      }
    }
    if (a > 1) {
      ++factor[i][a];
        lcm[a] = max(lcm[a], factor[i][a]);
    }
  }
  mint ans = 0;
  mint LCM = 1;
  for (const auto& e : lcm) {
    rep(k, e.second)
      LCM *= e.first;
  }
  rep(i, N) {
    ans += LCM / A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3072
use proconio::input;

#[allow(unused_variables)]
fn main() {
    input! {
      n: usize, a: usize, b: usize,
      mut s: String
    };

    // let a_c = s.chars().filter(|x| *x == 'a').count();
    // let b_c = s.chars().filter(|x| *x == 'b').count();
    let mut ans = String::new();

    let mut limit = a + b;
    let mut b_limit = b;

    let mut count = 0;

    for c in s.chars() {
        match c {
            'a' => {
                if limit > 0 {
                    limit -= 1;
                    ans.push_str("Yes\n");
                } else {
                    ans.push_str("No\n");
                }
            }
            'b' => {
                if limit > 0 && b_limit > 0 {
                    limit -= 1;
                    b_limit -= 1;
                    ans.push_str("Yes\n");
                } else {
                    ans.push_str("No\n");
                }
            }
            _ => {
                ans.push_str("No\n");
            }
        };

        count += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f,oo = inf;
#define pi 3.14159265358979323846
#define IL inline
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define Rep(i,a,b) for(int i=(a);i<=(b);++i)
#define Dep(i,a,b) for(int i=(a);i>=(b);--i)
#define pc putchar
#define gc getchar
IL ll read(){
    ll x=0;char f=0;char c=gc();
    for(;!isdigit(c);c=gc())f|=(c=='-');
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return f?-x:x;
}
IL void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);pc(x%10+'0');}
IL void writeln(ll x){write(x);pc('\n');}
IL void wri(ll x){write(x),pc(' ');}
#define debug(x) printf(#x" = %d\n",x);
#define rd() read()
#define rdb() readdb()
#define mem(x,v) memset(x,v,sizeof(x))
#define pb push_back
#define mp make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define y1 ____y1
#define hash __hash
#define union _union
#define ramdom ((double)rand() / RAND_MAX)
#define x first
#define y second
const int maxn = 2005+233;
struct Edge{
	int to,nxt;
	Edge(){}
	Edge(int to,int nxt):to(to),nxt(nxt){}
}edge[maxn*2];
int first[maxn],nume;
void Addedge(int a,int b){
	edge[nume] = Edge(b,first[a]);
	first[a] = nume++;
}
int mxdep[maxn],wson[maxn],sz[maxn];
int dfn[maxn],dfx[maxn],n,k;
int dp_array[maxn];
int *f[maxn];
void init(int u,int fa){
	mxdep[u] = 0;wson[u] = 0;sz[u] = 1;
	for(int e=first[u];~e;e=edge[e].nxt){
		int v=edge[e].to;
		if(v == fa) continue;
		init(v,u);
		mxdep[u] = max(mxdep[u],mxdep[v] + 1);
		sz[u] += sz[v];
		if(!wson[u] || mxdep[v] > mxdep[wson[u]])
			wson[u] = v;
	}
}
void pre(int u,int fa){
	dfx[dfn[u] = ++*dfn] = u;
	f[u] = dp_array + dfn[u];
	if(wson[u]) pre(wson[u],u);
	for(int e=first[u];~e;e=edge[e].nxt){
		int v=edge[e].to;
		if(v==fa || v==wson[u]) continue;
		pre(v,u);
	}
}
int g[maxn],h[maxn],ans;
void dfs(int u,int fa){
	if(wson[u]) dfs(wson[u],u);
	f[u][0] = wson[u] ? sz[wson[u]] : 0;
//	printf("#8999 %d %d\n",u,mxdep[u]);
	int m = min(k,mxdep[u]);
//	Rep(i,0,m) wri(f[u][i]);puts("");
	for(int e=first[u];~e;e=edge[e].nxt){
		int v = edge[e].to;
		if(v==wson[u] || v==fa) continue;
		dfs(v,u);
		int len = min(k,mxdep[v] + 1);
		g[0] = sz[v];Rep(i,1,len) g[i] = f[v][i-1];
		Rep(i,0,len) h[i] = f[u][i];
//		puts("~~"); 
//		wri(g[0]),writeln(h[0]);

//		Rep(i,0,len) wri(g[i]);puts("");
//		Rep(i,0,len) wri(h[i]);puts("");
//		puts("~~~~~~~~~~~~");

		Rep(i,0,len)
			f[u][i] = min(g[i]+h[min(i,k-i)],g[min(i,k-i)] + h[i]);
		
//		Rep(i,0,m) wri(f[u][i]);puts("");
//		Rep(i,0,len) wri(f[u][i]);puts("");
		
		Rep(i,0,len) if(k-i>len && k-i<=m) f[u][k-i] += g[i];
		Rep(i,len+1,k-len-1) if(i<=m) f[u][i] += g[len];
		Rep(i,1,m) f[u][i] = min(f[u][i],f[u][i-1]);
	}
//	Rep(i,0,m) wri(f[u][i]);puts("");
	ans = min(ans,n - sz[u] + f[u][min(k,m)]);
	//从root往上搞一格
}
int main(){
	mem(first,-1);nume = 0;
	n = read();k = read();ans = n;
	rep(i,1,n) {
		int x = read(),y = read();
		Addedge(x,y);
		Addedge(y,x);
	} init(1,0);
	*dfn = 0;
	pre(1,0);
	dfs(1,0);
	writeln(ans);
	return 0;
}


Measured memory_bytes: 3836
n=int(input())
red=[]
blue=[]
for _ in range(n):
    x,y=map(int,input().split())
    red.append((x,y))
for _ in range(n):
    x,y=map(int,input().split())
    blue.append((x,y))

blue.sort()

found=[0]*n
for bx, by in blue:
    y=-1
    pair=-1

    for i,r in enumerate(red):
        rx, ry=r
        if found[i]:
            continue
        if bx>rx and by>ry:
            if ry>y:
                pair=i
                y=ry

    if pair!=-1:
        found[pair]=1

print(sum(found))

Measured memory_bytes: 3064
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >


int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
void solve(){
    int n,r;
    cin>>n>>r;
    if(n>=10) cout<<r<<endl;
    else cout<<r+(100*(10-n))<<endl;
}

signed main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    int t;
    t=1;
    while(t--){
        solve();
    }

     return 0;

}
///Alhamdulillah




Measured memory_bytes: 256
N, X = gets.split(/ /).collect{|n| n.to_i}

sum = X

form = :t
a = X
b = N - X

while a > 0
	if form == :t
		
		sum += b
		form = :p
	else
		if a > b
			form = :t
			count = a / b
			sum += b * (count * 2 - 1)
			a = a % b
		else
			form = :t
			count = b / a
			sum += a * (count * 2 - 1)
			next_a = b % a
			b = a
			a = next_a
		end
	end
end
puts sum



Measured memory_bytes: 1788
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);

    let vec = vec![111,222,333,444,555,666,777,888,999];
    for i in vec {
        if n <= i {
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define sort stable_sort
using namespace std; 
 
int _;
 
int n,m,t,x[300050],y[300050],r[300050],c[300050],rm,cm,cr,cc,cnt;
  
int main()
{
	//for(scanf("%d",&_);_;_--)
	scanf("%d%d%d",&n,&m,&t);	
	for(int i=0;i<t;i++)
	{
		scanf("%d%d",x+i,y+i);
		r[x[i]-1]++;
		c[y[i]-1]++;
	}
	for(int i=0;i<300050;i++)
	{	
		if(r[i]>rm)
		{
			cr=1;
			rm=r[i];
		} 
		else
			if(r[i] == rm)
				cr++;
		if(c[i]>cm)
		{
			cc=1;
			cm=c[i];
		} 
		else
			if(c[i] == cm)
				cc++; 
	}  
	for(int i=0;i<t;i++)
		if(r[x[i]-1] == rm && c[y[i]-1] == cm)
			cnt++;
	printf("%d\n",rm+cm-(cr*cc == cnt)); 
	return 0;
}

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

int main() {
    string s;
    ll k;
    cin >> s >> k;
    ll res, base = 0;
    char pre = s[0];
    string tmp = s;
    for(int i = 1; i < tmp.size(); i++) {
        if (tmp[i] == pre) {
            tmp[i] = '*';
            base++;
        }
        pre = tmp[i];
    }
    if (s[0] != s[s.size()-1]) res = base * k;
    else {
        ll left = 1, right = 1, i = 0;
        while (i < s.size() - 1) {
            if (s[i] != s[++i]) break;
            left++;
        }
        i = s.size() - 1;
        while (i > 0) {
            if (s[i] != s[--i])
                break;
            right++;
        }
        
        if (left % 2 == 0 && right % 2 == 0) res = base * k;
        else {
            if (left == s.size()) {
                ll length = s.size() * k;
                res = length / 2;
            }
            else if (left % 2 == 1 && right % 2 == 1)
                res = (base + 1) * k - 1;
            else res = base * k;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	ll k;
	cin >> k;

	ll ans = 0;
	rrep (a, k) rrep (b, k) rrep (c, k) {
		ans += gcd(gcd(a, b), c);
	}

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(1e3)+5
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << fim
#define max3(x, y, z) max(x, max(y, z))
#define ull unsigned long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll MOD = 1e9+7;

int main() {
	ll n, k;
	cin >> n >> k;
	int ans = 0;
	while(n) {
		ans++;
		n /= k;
	}
	cout << ans << endl;
}


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

int n;
int a[2000];

int binary_search(int key,int left,int right) {
  while (right - left > 1) {
      int mid = left + (right - left) / 2;

      if (a[mid]>key) right = mid;
      else left = mid;
  }
  return right;
}

int main(void){
  int i,j;

  cin>>n;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);

  int cnt=0;
  int left,right;
  for(i=n-1;i>1;i--){
    for(left=0;left<i-1;left++){
      right=binary_search(a[i]-a[left],left,i);
      cnt+=(i-right);
    }
  }

  cout<<cnt<<endl;

  return 0;
}


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

int main(){
    ll N;
    cin >> N;
    vector<ll> d(N);
    rep(i, 0, N) cin >> d[i];
    sort(d.begin(), d.end());
    ll ans = d[N/2] - d[N/2 - 1];
    cout << ans << endl;
    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    auto ca = count(S.begin(), S.end(), 'a');
    auto cb = count(S.begin(), S.end(), 'b');
    auto cc = count(S.begin(), S.end(), 'c');
    auto cmax = max(ca, max(cb, cc));
    auto cmin = min(ca, min(cb, cc));
    if(cmax-cmin<2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using edges = vector<int>;
using graph = vector<edges>;

ll N, M;
graph G;
vector<int> color;

bool dfs(int s, int c) {
  color[s] = c;
  for (auto&& t : G[s]) {
    if (color[t] == c) return false;
    if (color[t] == 0 && !dfs(t, -c)) return false;
  }
  return true;
}

main() {
  cin >> N >> M;
  G.resize(N);
  color.assign(N, 0);
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  ll ans;
  if (!dfs(0, 1)) {
    ans = N * (N - 1) / 2 - M;
  } else {
    ll cnt = 0;
    for (int i = 0; i < N; i++) if (color[i] == 1) cnt++;
    ans = cnt * (N - cnt) - M;
  }

  cout << ans << endl;
}


Measured memory_bytes: 6528
#include <iostream>
using namespace std;
long f(long n){
      return (1 + n) * n / 2;
}
int main(void){
    long n;
    cin >> n;
    
    long ans = 0;
    for(int i = 1;i <= n;i++){
          ans +=  i * f(n / i);
    }
    cout <<  ans << endl;
    
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mxn = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i, j, n;
    cin >> n;
    ll ans = 0;
    for(i = 1; i<n; i++){
        for(j = 1; j<n; j++){
            if(i*j >= n){
                break;
            }
            else{
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}


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

int main(){
	string b("");
	cin >> b;
	char w[10] = {0};
	int l;
	l = b.size();
	for (int i = 0 ;i<l ;i++) {
		w[i]=b[i];
		if ( w[i] >= 'A' && w[i] <= 'Z' ) w[i]-='A'-'a';
	}
	int a = 0;
	char c;
	while(cin >> b) {
		if ( b == "END_OF_TEXT" ) break;
		if ( b.size() == l ) {
			for (int i = 0 ;i<l ;i++) {
				c=b[i];
				if ( c >= 'A' && c <= 'Z' ) c-='A'-'a';
				if ( c != w[i] ) break;
				if ( i == l-1 ) a++;
			}
		}
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 1196
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int N = int.Parse(Console.ReadLine());
            long[] c = new long[N + 1];
            int ans = 0;
            for(int i = 1; i <= N; i++)
            {
                if (i % 2 == 0) { continue; }
                int k = i;
                c[i]++;
                for(int j = 1; j <= i; j++)
                {
                    
                    if (j == 1) { continue; }
                    long cnt = 0;
                    while (k % j == 0)
                    {
                        cnt++;
                        k /= j;
                    }
                    c[i] *= cnt + 1;
                }
                if (c[i] == 8) { ans++; }
            }
            Console.WriteLine(ans);

            Console.Out.Flush();
        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}
    

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main(){
  int x, n;
  I2(x, n);
  int ar[1001];
  SET(ar);
  for(int i = 1;i<=n;i++){
    int x1;
    I(x1);
    ar[x1] ++;
  }

  int res = 0;
  
  for(int i = 0;i<=1000;i++){
    if(ar[i])continue;

    if(abs(res-x) > abs(x-i)){
      res = i;
    }
  }
    
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3636
a,b,c,k = map(int,input().split())
l = list()
if a <= k:
  l.append(1*a)
  k = k-a
  if b <= k:
    k = k-b
    if c <= k:
      l.append(-1*k)
    else:
      l.append(-1*k)
  else:
    l.append(0)
else:
  l.append(k)
print(sum(l))

Measured memory_bytes: 9192
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int N = 500000;

int w, h;

class C{
    public:
        int y, x, cost, type;
        C(int _y, int _x, int _c, int _t){
            y = _y;
            x = _x;
            cost = _c;
            type = _t;
        }
        bool operator>(const C &c) const{
            return cost > c.cost;
        }
};

bool isOK(int y, int x){
    if(y < 0 || x < 0 || y >= h || x >= w) return false;
    return true;
}

int main(){
    while(cin >>w >>h && w){
        vector< vector<int> > v(h, vector<int>(w));
        REP(i, h) REP(j, w) cin >>v[i][j];
        int c[4];
        REP(i, 4) cin >>c[i];

        priority_queue< C, vector<C>, greater<C> > open;
        open.push( C(0, 0, 0, 1) );
        vector< vector< vector<int> > > closed(h, vector< vector<int> >(w, vector<int>(4, INF)));

        while(!open.empty()){
            C now = open.top();
            open.pop();

            //debug
            //cout <<now.y <<", " <<now.x <<", " <<now.cost <<", " <<now.type <<endl;

            if(now.cost >= closed[now.y][now.x][now.type]) continue;
            closed[now.y][now.x][now.type] = now.cost;

            if(now.y == h - 1 && now.x == w - 1){
                cout <<now.cost <<endl;
                break;
            }

            int my[] = {-1, 0, 1, 0};
            int mx[] = {0, 1, 0, -1};

            REP(i, 4){
                int next_cost = (i == v[now.y][now.x]? 0 : c[i]);
                int next_type;
                //debug
                //cout <<"! " <<i <<", " <<next_cost <<", " <<now.cost + next_cost <<endl;
                if(i == 0) next_type = now.type;
                if(i == 1) next_type = (now.type + 1) % 4;
                if(i == 2) next_type = (now.type + 2) % 4;
                if(i == 3) next_type = (now.type + 3) % 4;
                int ny = now.y + my[next_type], nx = now.x + mx[next_type];
                if(!isOK(ny, nx)) continue;
                open.push( C(ny, nx, now.cost + next_cost, next_type) );
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1352