akhauriyash/Code-Regression huggingface dataset:
d=list(map(int,input().split()))
o=list(map(int,input().split()))
if o[0]==d[1]:
	d[0],d[1],d[4],d[5]=d[1],d[5],d[0],d[4]		
elif o[0]==d[2]:
	d[0],d[2],d[3],d[5]=d[2],d[5],d[0],d[3]
elif o[0]==d[3]:
	d[0],d[2],d[3],d[5]=d[3],d[0],d[5],d[2]	
elif o[0]==d[4]:
	d[0],d[1],d[4],d[5]=d[4],d[0],d[5],d[1]		
elif o[0]==d[5]:
	d[0],d[1],d[4],d[5]=d[5],d[4],d[1],d[0]
while o[1]!=d[1]:
	d[1],d[2],d[4],d[3]=d[3],d[1],d[2],d[4]
if d==o:
	print('Yes')
else:
	print('No')



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int N,M;
    cin >> N >> M;
    vector<int> ans(N);
    rep(i,0,M){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        ++ans[a];
        ++ans[b];
    }
    rep(i,0,N) cout << ans[i] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<=(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
  
int main()
{
  int n;
  cin >> n;

  int a[n];
  int i, first = 0, second = 0;
  rep(i, n-1){
      cin >> a[i];
      if(a[i] >= first){second = first; first = a[i]; continue;}
      if(a[i] >= second){second = a[i];}
      }

  rep(i,n-1){
      if(a[i] == first){cout << second << endl;}
      else{cout << first << endl;}
      }

  return 0;
}


Measured memory_bytes: 2432
package main

import "fmt"

func main() {
	var r, g, b, n int
	fmt.Scan(&r, &g, &b, &n)

	ans := 0
	for i := 0; i*r <= n; i++ {
		for j := 0; i*r+j*g <= n; j++ {
			if (n-i*r-j*g)%b == 0 {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    int a[n];
    REP(i,n){
        cin >> a[i];
    }
    ll sum = 0;
    ll ans = 0;
    REP(i,n){
        if(a[i] != 0){
            sum += a[i];
        }else{
            ans += sum / 2;
            sum = 0;
        }
    }
    ans += sum / 2;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define V vector
#define pb push_back
#define mkp make_pair
#define pi pair<int,int>//struct pi {int fi,se;};
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define ln length()
#define sz size()
const int N=100005;
///////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    // int t;cin>>t;while(t--)
    {
        int i,j,k,n,m,ans=0,cnt=0,sum=0;
        cin>>n >> m;
        rep(i,0,n){
            cin >> j >> k;
            if((j*j) + (k*k) <= (m*m)){
                ans++;
            }
        }
        cout << ans <<endl;
    }
}

Measured memory_bytes: 3652
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

A, B = inm()


def solve():
    for x in range(200000):
        a = int(x * 0.08 + 1e-9)
        b = int(x * 0.10 + 1e-9)
        if a == A and b == B:
            return x

    return -1


print(solve())


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


int main() {
    long long int n;
    cin >> n;
    long long int ans = 0;
    if (n%2 != 0) cout << ans << endl;
    else{
        while (n /5 > 0) {
            ans += n / 10;
            n = n /5;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
def f(n):
    s=str(n)
    return sum([int(s[i]) for i in range(len(s))])

sunuke=[]
for i in range(16):
    for j in range(1,200):
        sunuke.append(j*(10**i)-1)

sunuke=list(set(sunuke))
sunuke.sort()
sunuke.pop(0)
L=len(sunuke)

tmp1,tmp2=sunuke[L-1],f(sunuke[L-1])
ans=[sunuke[L-1]]
for i in range(len(sunuke)-2,-1,-1):
    x=sunuke[i]
    if x*tmp2<=tmp1*f(x):
        ans.append(x)
        tmp1,tmp2=x,f(x)

ans.sort()

    

for i in range(int(input())):
    print(ans[i])

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 999999999

    /*Solve*/
int main(){
    string str;
    stack<int> stk;
    cin >> str;
    rep(i,str.size()){
        if(i==0){
            stk.push(str[i]);
        }else if(str[i]=='S'){
            stk.push(str[i]);
        }else if(str[i]=='T'){
            if(stk.empty() || stk.top()=='T'){
            stk.push(str[i]);
            }else if(stk.top()=='S'){
                stk.pop();
            }
        }
    }
    cout << stk.size() ;
}

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

int n, a[23];

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


Measured memory_bytes: 256
import java.util.*;
public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			if (n==0) break;
			List<Character> be = new ArrayList<Character>(n);
			List<Character> af = new ArrayList<Character>(n);
			for (int i=0; i<n; i++) {
				be.add(sc.next().charAt(0));
				af.add(sc.next().charAt(0));
			}
			int m = sc.nextInt();
			for (int i=0; i<m; i++) {
				char now = sc.next().charAt(0);
				int in = be.indexOf(now);
				if (in<0) {
					System.out.print(now);
				} else {
					System.out.print(af.get(in));
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 66044
import java.util.*;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    
    int x = sc.nextInt();
    int n = sc.nextInt();
    List<Integer> intList = new ArrayList<Integer>();
    
    for(int i = 0; i < n; i++){
      intList.add(sc.nextInt());
    }
    
    int ans = x;
    for(int i = 0; i < 100; i++){
      if(!(intList.contains(x-i))){
        ans = x - i;
        break;
      } else if (!(intList.contains(x+i))){
        ans = x + i;
        break;
      }
    }
    
    System.out.println(ans);

  }
}

Measured memory_bytes: 35816
import math
a, b, x = map(int, input().split())
d = x / (a * a)
e = (a * d * 2) / b
g = (b-d) * 2
if ((b / 2) < d):
    print(math.degrees(math.atan(g/a)))
else:
    print(math.degrees(math.atan(b/e)))


Measured memory_bytes: 3060
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1)


def main():
    N = int(readline())
    S = readline().strip()
    Q = int(readline())

    bit = [BIT(N) for _ in range(26)]
    for i, c in enumerate(S):
        bit[ord(c) - ord('a')].add(i)

    S = list(S)
    ans = []

    for _ in range(Q):
        n, a, b = readline().split()
        if n == '1':
            i = int(a) - 1
            if b != S[i]:
                bit[ord(S[i]) - ord('a')].add(i, -1)
                bit[ord(b) - ord('a')].add(i, 1)
                S[i] = b
        else:
            res = 0
            for i in range(26):
                if bit[i].get_sum_range(int(a) - 1, int(b)):
                    res += 1
            ans.append(res)

    print(*ans, sep='\n')

    return


if __name__ == '__main__':
    main()


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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

    string s;
    cin >> s;
    if(s[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    else {
        if('A' <= s[s.size() - 1] && s[s.size() - 1] <= 'Z') {
            cout << "WA" << endl;
            return 0;
        }
        FOR(i, 2, s.size() - 1) {
            if(s[i] == 'C') {
                rep(j, s.size()) {
                    if(j == i || j == 0) continue;
                    if('A' <= s[j] && s[j] <= 'Z') {
                        cout << "WA" << endl;
                        return 0;
                    }
                }
                cout << "AC" << endl;
                return 0;
            }
            else if('A' <= s[i] && s[i] <= 'Z') {
                cout << "WA" << endl;
                return 0;
            }
        }
    }
    cout << "WA" << endl;
    return 0;
}


Measured memory_bytes: 256
#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 main(){
  vector<int> v(3);
  rep (i, 3) cin >> v[i];

  int count = 0;
  rep (i, 3){
    if (v[i] % 2 == 0) ++count;
  }

  int ans = 0;
  if (count == 2){
    rep (i, 3){
      if (v[i] % 2 == 0) ++v[i];
    }
    ++ans;
  } else if (count == 1){
    rep (i, 3){
      if (v[i] % 2 == 1) ++v[i];
    }
    ++ans;
  }
  sort(v.begin(), v.end());
  ans += (v[2] - v[0]) / 2;
  ans += (v[2] - v[1]) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
N, Q = map(int, input().split())
S = input()
l, r = [],[]
for _ in range(Q):
    x, y = map(int, input().split())
    l.append(x)
    r.append(y)

def m():
    t = [0] * len(S)
    ans = [0] * len(S)
    prev = S[0]
    for i in range(1, len(S)):
        if prev != 'A':
            prev = S[i]
            continue
        if S[i] == 'C':
            t[i] += 1
        prev = S[i]
    ans[0] = t[0]
    for i in range(1, len(t)):
        ans[i] = ans[i-1] + t[i]

    for i in range(Q):
        print(ans[r[i]-1] - ans[l[i]-1])

m()

Measured memory_bytes: 16588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,ans; cin>>N;
  if(1 <= N && N <= 9) ans=N;
  else if(10 <= N && N <= 99) ans=9;
  else if(100 <= N && N <= 999) ans=N-90;
  else if(1000 <= N && N <= 9999) ans=909;
  else if(10000 <= N && N <= 99999) ans=N-9090;
  else if(100000 <= N && N <= 999999) ans=90909;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, int> pli;
const int N = 2e5 + 10;
int n, a[N], b[N];
ll tot, suma, sumb, sum, res;
pli all[N];
bool vis[N];

int main() {
    cin >> n;
    rep(i, 1, n) {
        scanf("%d%d", &a[i], &b[i]);
        tot += a[i] + b[i];
        suma += a[i], sumb += b[i];
        all[i << 1] = make_pair(a[i], i);
        all[i << 1 | 1] = make_pair(b[i], i);
    }
    sort(all + 1, all + (n << 1) + 2, greater<pli>());
    bool ff = 0;
    res = max(suma, sumb);
    rep(i, 1, n) {
        if (vis[all[i].second]) {
            ff = 1;
        }
        vis[all[i].second] = 1;
        sum += all[i].first;
    }
    if (ff) {
        res = max(res, sum);
    } else {
        rep(i, n + 1, n << 1) {
            if (all[n].second == all[i].second)
                res = max(res, sum + all[i].first - all[n - 1].first);
            else
                res = max(res, sum + all[i].first - all[n].first);
        }
    }
    printf("%lld\n", tot - res);
    return 0;
}

Measured memory_bytes: 7836
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    int n,k;
    cin >> n>> k;
    if((n-1)%(k-1)==0)cout << (n-1)/(k-1) << endl;
    else cout << (n-1)/(k-1)+1 << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define REP(i,n) for (int i=1;i<=n;i++)

int main() {
	int n, ans = 0, now1, now2, now3; char s[40000]; cin >> n;
	char t[10] = {'0','1','2','3','4','5','6','7','8','9'};
	rep(i, n) cin >> s[i];
	rep(i, 10)rep(j, 10)rep(k, 10) {
		bool Q = false;
		now1 = find(s, s+n, t[i]) - s;
		if (now1 != n-1 && now1 != n) {
			now2 = find(s + now1 + 1, s + n, t[j]) - s;
			if (now2 != n - 1&& now2!= n) {
				now3 = find(s + now2 + 1, s + n, t[k]) - s;
				if (now3 != n) {
					Q = true;
				}
			}
		}
		if (Q) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;
import java.util.Arrays;
import java.lang.Math;

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

		int n = sc.nextInt();
		String[] s = new String[n];
		for(int i = 0; i < n; i++) {
			s[i] = sc.next();
		}

		int size = 'z' - 'a' + 1;
		int[][] count = new int[n][size];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < s[i].length(); j++) {
				char c = s[i].charAt(j);
				int k = c - 'a';
				count[i][k]++;
			}
		}

		int[] cnt = new int[size];
		for(int i = 0; i < size; i++) {
			int min = Integer.MAX_VALUE / 2;
			for(int j = 0; j < n; j++) {
				int val = count[j][i];
				min = Math.min(count[j][i], min);
			}
			cnt[i] = min;
		}

		char c = 'a';
		for(int i = 0; i < size; i++) {
			for(int j = 0; j < cnt[i]; j++) {
				System.out.print(String.valueOf(c));
			}
			c++;
		}
		System.out.println();

	}
}


Measured memory_bytes: 23764
H,W = map(int,input().split())
S = [list(input()) for i in range(0,H,1)]

teraseru_H = [[0 for i in range(0,W,1)]for j in range(0,H,1)]
teraseru_W = [[0 for i in range(0,W,1)]for j in range(0,H,1)]

left = -1
for i in range(0,H,1):
    left=-1
    for j in range(0,W,1):
        if S[i][j]=="#":
            if left!=-1:
                for k in range(left,j,1):
                    teraseru_H[i][k] = j-left
                left=-1

        else:#"."
            if left==-1:
                left=j
    if left!=-1:
        for k in range(left,W,1):
            teraseru_H[i][k] = W-left
    left=-1

left = -1
for j in range(0,W,1):
    left=-1
    for i in range(0,H,1):
        if S[i][j]=="#":
            if left!=-1:
                for k in range(left,i,1):
                    teraseru_W[k][j] = i-left
                left=-1
        else:#"."
            if left==-1:
                left=i
    if left!=-1:
        for k in range(left,H,1):
            teraseru_W[k][j] = H-left
    left=-1

ans = 0

for i in range(0,H,1):
    for j in range(0,W,1):
        ans = max(ans,teraseru_H[i][j]+teraseru_W[i][j]-1)
print(ans)

Measured memory_bytes: 252296
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s;
    cin>>s;
    int cnt=0,mx=0;
    for(int i=0;i<3;i++){
        if(s[i]=='R')
            cnt++;
        else{
            mx=max(mx,cnt);
            cnt=0;
        }
    }
    mx=max(mx,cnt);
    cout<<mx<<endl;


    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int main(){
  int x, n;  scanf("%d %d", &x, &n);
  int table[105] = {0};
  for(int i=0; i<n; i++){
    int p;  scanf("%d", &p);
    table[p] = 1;
  }

  int up = x;
  while(table[up])  up++;
  int under = x;
  while(table[under]) under--;

  int ans;
  if(up-x < x-under)  ans = up;
  else                ans = under;
  
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

class UnionFind {
    vector<int> par;
    int n;

public:
    UnionFind(int n) : par(n, -1) {}

    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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

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

    int n, m;
    cin >> n >> m;
    UnionFind uf(100005);
    int p[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (uf.same(p[i], i+1)) ans++;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include<iomanip>
using namespace std;
using P = pair<int, int>;

int H, N;
int A[200010], B[200010];

int dp[2010][60010];
int INF = 1000000007;

int main()
{
	cin >> H >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
	}
	for (int i = 0; i <= N; i++) {
		for (int j = H; j >= 0; j--) {
			dp[i][j] = INF;
		}
	}
	dp[0][H] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = H; j >= 0; j--) {
			if (j + A[i] <= H)
				dp[i][j] = min(dp[i - 1][j], min(dp[i - 1][j + A[i]] + B[i], dp[i][j + A[i]] + B[i]));
			else
				dp[i][j] = dp[i - 1][j];
		}
		for (int j = 0; j <= A[i]; j++) {
			dp[i][0] = min(dp[i][0], min(dp[i - 1][j] + B[i], dp[i][j] + B[i]));
		}
	}
	cout << dp[N][0] << endl;
}

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

using namespace std;

int main()
{
    long long n, ac = 0, wa = 0, tle = 0, re = 0;
    cin >> n;
    string s;
    for (long long i = 0; i < n; i++) {
        cin >> s;
        if (s == "AC") ac++;
        else if (s == "WA") wa++;
        else if (s == "TLE") tle++;
        else re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il int max(int x,int y){return x>y?x:y;}
il int min(int x,int y){return x<y?x:y;}
il int abs(int x){return x>0?x:-x;}
il void swap(int &x,int &y){int t=x;x=y;y=t;}
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 100010
int a[N],n;
int main(){
	in1(n);int ans=0;
	for(int i=1;i<=n;i++)in1(a[i]),ans+=a[i]-1;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
double ABS(const double &a){
	if(a < 0)return -a;
	return a;
}
int main(){
	int n,ans = 1;
	double T,A,dis,nowH,nd;
	scanf("%d", &n);
	scanf("%lf%lf", &T, &A);
	scanf("%lf", &nowH);
	nowH = T - (nowH * 0.006);
	dis = ABS(nowH - A);
	for(int i=2; i<=n; i++){
		scanf("%lf", &nowH);
		nowH = T - (nowH * 0.006);
		if(ABS(nowH - A) < dis){
			dis = ABS(nowH - A);
			ans = i;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	set <int> S;
	int a=read(),b=read(),k=read();
	rep(i,a,min(a+k,b))S.insert(i);
	per(i,b,max(a,b-k+1))S.insert(i);
	Forenska(it,S)cout<<*it<<endl; 
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define F first
#define S second
const int N = 1e5 + 87;
int d[N];
int main()
{
    int k;
    cin >> k;
    fill_n(d,k+1,N);
    d[0] = 0;
    priority_queue<pii,vector<pii>,greater<pii>> pq;
    pq.push(pii{0,0});
    while (pq.size()) {
        int u,w;
        tie(w,u) = pq.top();
        pq.pop();
        if (w > d[u])
            continue;
        for (int i = 0; i < 10; ++i) {
            int v = u * 10 + i;
            if (v % k == 0 && v)
                v = k;
            else
                v %= k;
            int nw = w + i;
            if (nw < d[v]) {
                d[v] = nw;
                pq.push({nw,v});
            }
        }
    }
    cout << d[k] << '\n';
}


Measured memory_bytes: 2804
from collections import Counter
from itertools import combinations as comb


def main():
    n = int(input())
    ls = list(map(int, input().split()))
    ls_count = Counter(ls)
    ls_keys = list(ls_count.keys())
    m = len(ls_keys)
    ans = 0
    for i in range(m-2):
        c = ls_keys[i]
        pairs = list(comb(ls_keys[(i+1):], 2))
        for a, b in pairs:
            if c + a > b and a + b > c and b + c > a:
                ans += ls_count[c] * ls_count[a] * ls_count[b]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10020
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a=n;
	int s=0;
	do{
		s+=a%10;
		a=a/10;
	}while(a!=0);
	if(n%s==0)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    if(n<1000) cout <<"ABC"<<endl;
    else cout << "ABD"<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
// #include <xmmintrin.h>
// #include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, less<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define MOD 1000000007LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[&](auto f,auto... args){return f(f,args...);};

int main(){
    lint n;
    cin>>n;
    lint ans=0;
    irep(i){
        if(n==0)break;
        n/=2;
        ans+=pow(2,i);
    }
    cout<<ans<<endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> c(N), s(N), f(N);
    for(int i = 0; i < N-1; ++i) {
        cin >> c[i] >> s[i] >> f[i];
    }
    for(int i = 0; i < N-1; ++i) {
        int ret = 0;
        for(int j = i; j < N-1; ++j) {
            if(ret < s[j])
                ret = s[j];
            while(ret%f[j]!=0) ret++;
            ret+=c[j];
        }
        cout << ret << endl;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  vl a(n),b(n),c(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  rep(i,n)cin>>c[i];
  vl count(n);
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  for(ll i=n-1;i>=0;i--){
    ll x=b[i];
    if(c[n-1]<=x){
      count[i]=0;
      continue;
    }
    ll idx_upper = distance(c.begin(), upper_bound(c.begin(),c.end(),x));
    count[i]=n-idx_upper;
  }
  vl sum(n);
  sum[n-1]=count[n-1];
  for(ll i=n-1;i>=1;i--){
    sum[i-1]=sum[i]+count[i-1];
  }
  ll ans=0;
  for(ll i=n-1;i>=0;i--){
    ll x=a[i];
    if(b[n-1]<=x){
      continue;
    }
    ll idx_upper = distance(b.begin(), upper_bound(b.begin(),b.end(),x));
    ans+=sum[idx_upper];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	ll H, W;
	cin >> H >> W;

	ll rsl = 1e18;
	rep(h, 0, H) {
		ll sa = h * W;
		ll w = W / 2;
		ll sb = (H - h) * w;
		ll sc = (H - h) * (W - w);
		if(sa == 0 or sb == 0 or sc == 0) continue;

		ll s_max = max(sa, max(sb, sc));
		ll s_min = min(sa, min(sb, sc));
		rsl = min(rsl, s_max - s_min);
		
		ll hh = (H - h) / 2;
		sb = hh * W;
		sc = (H - h - hh) * W;
		if(sa == 0 or sb == 0 or sc == 0) continue;
		s_max = max(sa, max(sb, sc));
		s_min = min(sa, min(sb, sc));
		rsl = min(rsl, s_max - s_min);
	}

	swap(H, W);
	rep(h, 0, H) {
		ll sa = h * W;
		ll w = W / 2;
		ll sb = (H - h) * w;
		ll sc = (H - h) * (W - w);
		if(sa == 0 or sb == 0 or sc == 0) continue;

		ll s_max = max(sa, max(sb, sc));
		ll s_min = min(sa, min(sb, sc));
		rsl = min(rsl, s_max - s_min);
		
		ll hh = (H - h) / 2;
		sb = hh * W;
		sc = (H - h - hh) * W;
		if(sa == 0 or sb == 0 or sc == 0) continue;
		s_max = max(sa, max(sb, sc));
		s_min = min(sa, min(sb, sc));
		rsl = min(rsl, s_max - s_min);
	}
	cout << rsl << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    int x,y;
};
int h,w,sx,sy,ex,ey,k;
main(){
    cin>>h>>w>>k;
    cin>>sx>>sy>>ex>>ey;
    char g[h][w];
    int step[h][w],vis[h][w];
    memset(vis,0,sizeof(vis));
    memset(step,0,sizeof(step));
    for(int i=0;i<h;i++){
        scanf("%s",g[i]);
    }
    sx--,sy--,ex--,ey--;
    queue<node>q;
    node a,b;
    a.x=sx;a.y=sy;step[a.x][a.y]=0;vis[a.x][a.y]=1;
    q.push(a);
    int ans=1e9;
    while(!q.empty()){
        a=q.front();
        q.pop();
        if(a.x==ex && a.y==ey) ans=min(ans,step[a.x][a.y]);
        for(int i=0;i<4;i++){
            int mx,my;
            if(i==0) mx=1,my=0;
            if(i==1) mx=-1,my=0;
            if(i==2) mx=0,my=1;
            if(i==3) mx=0,my=-1;
            for(int j=1;j<=k;j++){
                b.x=a.x+mx*j;
                b.y=a.y+my*j;
                if(b.x<0||b.x>=h||b.y<0||b.y>=w||(step[b.x][b.y]&&step[b.x][b.y]<=step[a.x][a.y])) break;
                else{
                    if(g[b.x][b.y]=='.'&&vis[b.x][b.y]==0){
                        vis[b.x][b.y]=1;
                        step[b.x][b.y]=step[a.x][a.y]+1;
                        q.push(b);
                    }
                    else if(g[b.x][b.y]=='@') break;
                }
            }
        }
    }
    ans==1e9?cout<<-1:cout<<ans;
}




Measured memory_bytes: 12984
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    int cnt = 0;
    int num = 1;
    rep(i,N){
    	if(A[i]==num){
    		cnt++;
    		num++;
    	}
    }
    
    if(cnt>0)
 		cout << A.size()-cnt << endl;
 	else cout << -1 << endl;
}

Measured memory_bytes: 1024
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()
t = input()

ans = 10**5

len_s = len(s)
len_t = len(t)

S = []

for i in range(len_s):
    S.append(s[i])

for i in range(len_s - len_t+1):
    tmp = 0
    ss = S[i:i+len_t]
    for j in range(len_t):
        if t[j] != ss[j]:
            tmp += 1
    if tmp < ans:
        ans = tmp

print(ans)

Measured memory_bytes: 9164
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

struct Dice{
	int top;
	int front;
	int right;
	int left;
	int back;
	int bottom;
};
void roll_n(Dice &dice2)
{
	int a = dice2.top;
	dice2.top = dice2.front;
	dice2.front = dice2.bottom;
	dice2.bottom = dice2.back;
	dice2.back = a;
}
void roll_e(Dice &dice2)
{
	int a = dice2.top;
	dice2.top = dice2.left;
	dice2.left = dice2.bottom;
	dice2.bottom = dice2.right;
	dice2.right = a;
}
void roll_w(Dice &dice2)
{
	int a = dice2.top;
	dice2.top = dice2.right;
	dice2.right = dice2.bottom;
	dice2.bottom = dice2.left;
	dice2.left = a;
}
void roll_s(Dice &dice2)
{
	int a = dice2.top;
	dice2.top = dice2.back;
	dice2.back = dice2.bottom;
	dice2.bottom = dice2.front;
	dice2.front = a;
}
void roll(Dice &dice, char direction)
{
	if(direction == 'N'){
		roll_n(dice);
	}
	else if(direction == 'E'){
		roll_e(dice);
	}
	else if(direction == 'W'){
		roll_w(dice);
	}
	else{
		roll_s(dice);
	}
}
bool kakunin_6dimensions(Dice &a, Dice &b)
{	
	if(a.top == b.top
	&& a.front == b.front
	&& a.right == b.right
	&& a.left == b.left
	&& a.back == b.back
	&& a.bottom == b.bottom
	){
		return true;
	}
	return false;
}
bool kakunin_4dimensions(Dice &dice, Dice &dice2)//front????????????E????????????4?????¢???top????????´??????????¢????
{
	for(int i = 0; i < 4; i ++){
		roll_e(dice2);
		if(kakunin_6dimensions(dice, dice2) == true){
			return true;
		}
	}
	return false;
}
bool kakunin_6tops(Dice &dice, Dice &dice2)//6?????????top?????????????????????
{
	string str = "ESESES";
	for(int i = 0; i < str.size(); i++){
		roll_s(dice2);
		if(kakunin_4dimensions(dice, dice2) == true){
			return true;
		}
		roll_n(dice2);
		roll(dice2, str[i]);
	}
	return false;
}
bool kakunin_difference(vector<Dice> dice)
{
	for(int i = 0; i < dice.size() - 1; i++){
		for(int j = i + 1; j < dice.size(); j++){
			if(kakunin_6tops(dice[i], dice[j]) == true){
				return false;
			}
		}
	}
	return true;
}
int main(void)
{	
	
	int n;//????????????????????°
	cin >> n;
	
	vector<Dice> dice(n);
	
	for(int i = 0; i < n; i++){
		cin >> dice[i].top >> dice[i].front >> dice[i].right >> dice[i].left >> dice[i].back >> dice[i].bottom;
	}
	
	if(kakunin_difference(dice) == true){//???????????°?????£????????????
		cout << "Yes" << endl;
	}
	else{							//????????§???????????????????????????????????????
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll h, w, a, b;
    cin >> h >> w >> a >> b;

    int ans[h][w];
    rep(i, h)rep(j, w){
        if(i < b){
            if(j < a)ans[i][j] = 1;
            else ans[i][j] = 0;
        }
        else {
            if(j < a)ans[i][j] = 0;
            else ans[i][j] = 1;
        }
    }

    rep(i, h){
        rep(j, w)cout << ans[i][j];
        cout << endl;
    }

}

Measured memory_bytes: 5120
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let hwab = readn::<usize>(" ");
    let h = hwab[0];
    let w = hwab[1];
    let a = hwab[2];
    let b = hwab[3];

    let mut s = vec![vec!['0'; w]; h];

    for i in 0..h {
        for j in 0..w {
            if i >= b && j < a {
                s[i][j] = '1';
            } else if i < b && j >= a {
                s[i][j] = '1';
            }
        }
    }

    let mut ans = "".to_string();
    for i in 0..h {
        ans = ans + &(s[i].iter().map(|&c| c).collect::<String>()) + "\n";
    }
    print!("{}", ans);
}

Measured memory_bytes: 9340
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <initializer_list>
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;

const int dx44[5] = { 0,-1,-1,1,1 };
const int dy44[5] = { 0,-1,1,-1,1 };

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int maxn = 1e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes");}// exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No");}// exit(0); }
void one() { puts("-1"); exit(0); }

int n,m;
int col[maxn];
ll cnt1,cnt2;
vector<int>edge[maxn];

bool dfs(int x,int c)
{
	if(col[x]!=-1)
	{
		return col[x]==c;
	}
	col[x]=c;
	int res=1;
	for(int i=0;i<edge[x].size();i++)
	{
		int nxt=edge[x][i];
		res&=dfs(nxt,1-c);
	}
	return res;
}

void solve()
{
	sa(n),sa(m);
	
	repp(i,1,m)
	{
		int x,y;
		sa(x),sa(y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	memset(col,-1,sizeof(col));
	bool res = dfs(1,0);
	repp(i,1,n)
	{
		if(col[i])cnt1++;
		else cnt2++;
	}
	ll ans=-m;
	if(res)
	{
		ans+=cnt1*cnt2;
	}
	else
	{
		ans+=1LL*n*(n-1)/2;
	}
	cout<<ans<<endl;
}

int main()
{
	solve();
	// system("pause");
	return 0;
}


Measured memory_bytes: 6912
import sys
from heapq import heappush, heappushpop

readline = sys.stdin.readline


def solve():
    N = int(readline())

    left = [[] for _ in range(N)]
    right = [[] for _ in range(N)]
    ans = 0
    for _ in range(N):
        K, L, R = map(int, readline().split())
        if L > R:
            ans += R
            left[K - 1].append(L - R)
        else:
            ans += L
            if 0 <= N - K - 1:
                right[N - K - 1].append(R - L)

    for vec in (left, right):
        hq = []
        n = len(vec)

        for i in range(n):
            for p in vec[i]:
                if len(hq) >= i + 1:
                    heappushpop(hq, p)
                else:
                    heappush(hq, p)

        for i in range(n, N):
            for p in vec[i]:
                if len(hq) >= n:
                    heappushpop(hq, p)
                else:
                    heappush(hq, p)

        ans += sum(hq)

    return ans


def main():
    T = int(readline())

    ans = [0] * T
    for i in range(T):
        ans[i] = solve()

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 47620
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll       =    long long;
using   ld       =    long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int>vi;
typedef vector<ll>vii;
typedef set<int>si;
typedef set<ll>sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const ll MOD =(ll)1e9+1147483647;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    int n;
    string s;
    cin>>n>>s;
    int i=0,j=n-1,ans=0;
    while(i<=j)
    {
        if(s[i]=='W'&&s[j]=='R')
        {
            ans++;
            i++;
            j--;
        }
        else
        {
            if(s[i]=='R')i++;
            if(s[j]=='W')j--;
        }
    }
    cout<<ans<<nl;
    return 0;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(fabs(b-a)<=d)
	{
		if(fabs(c-b)<=d)
		{
			cout<<"Yes";
			return 0;
		}
	}
	else
	{
		if(fabs(a-c)<=d)
		{
			cout<<"Yes";
			return 0;	
			
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int n, x, y, z;
	int i;

	scanf("%d", &n);
	if (n == 2) {
		scanf("%d%d", &x, &y);
		for (i = 1; i <= (x < y ? x : y); i++)
			if (x % i == 0 && y % i == 0)
				printf("%d\n", i);
	} else if (n == 3) {
		scanf("%d%d%d", &x, &y, &z);
		n = x > y ? x : y;
		n = n > z ? n : z;
		for(i = 1; i <= n; i++) 
			if (x % i == 0 && y % i == 0 && z % i == 0)
				printf("%d\n", i);
	}
	return 0;
}

		
				


	

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int a[1000000];
bool vis[1000000];
#define MOD 1000000007
long long inv(long long a)
{
    long long b=MOD;
	long long b0 = b, t, q;
	long long x0 = 0, x1 = 1;
	if (b == 1) return 1;
	while (a > 1) {
		q = a / b;
		t = b, b = a % b, a = t;
		t = x0, x0 = x1 - q * x0, x1 = t;
	}
	if (x1 < 0) x1 += b0;
	return x1;
}
long long fact[1000000];
long long C(int n,int m)
{
    if (n==0)return 0;
    if (n<m)return 0;
    if (m==0)return 1;
    return (((fact[n]*inv(fact[n-m]))%MOD)*inv(fact[m]))%MOD;
}
int main()
{
    fact[0]=1;
    for (int i=1;i<=100003;i++)
        fact[i]=(fact[i-1]*i)%MOD;
    int n;
    cin>>n;
    int ret=0;
    int nxt=0;
    for (int i=0;i<=n;i++)
    {
        cin>>a[i];
        if (vis[a[i]])
            ret=i;
        vis[a[i]]=!vis[a[i]];
    }
    while(vis[a[nxt]])nxt++;
    int after=n-ret;
    for (int i=1;i<=n+1;i++)
    {
        if (i==1)cout<<n<<endl;
        else
        cout<<(C(n+1,i)-C(nxt+after,i-1)+2*MOD)%MOD<<endl;
    }
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = 1e15;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "03"
const int mxN = 1e5+5;
int n,m,ss,t;
vii G[mxN];
int cnt1[mxN], cnt2[mxN];
int dist1[mxN], dist2[mxN];
bool visited[mxN];
int Pow(int val)
{
	return val*val%mod;
}
void djikstra(int s, int* dist, int* cnt)
{
	priority_queue<pii,vii,greater<pii>> pq;
	pq.push(mp(0,s));
	for(int i=0;i<=n;i++)
	{
		dist[i]=mx;
		visited[i]=false;
	}
	cnt[s]=1;
	dist[s]=0;
	while(!pq.empty())
	{
		int u=pq.top().se;
		int d=pq.top().fi;
		pq.pop();
		if(visited[u] or d!=dist[u])
			continue;
		visited[u]=true;
		for(auto v:G[u])
		{
			if(!visited[v.fi] and dist[v.fi]>dist[u]+v.se)
			{
				cnt[v.fi]=cnt[u];
				dist[v.fi]=dist[u]+v.se;
				pq.push(mp(dist[v.fi],v.fi));
			}
			else if(dist[v.fi]==dist[u]+v.se)
			{
				cnt[v.fi]+=cnt[u];
				cnt[v.fi]%=mod;
			}
		}
	}
}
signed main()
{
//    freopen(file".inp","r",stdin);
//    freopen(file".out","w",stdout);
//    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m>>ss>>t;
    for(int i=0,u,v,w;i<m;i++)
	{
		cin>>u>>v>>w;
		G[u].eb(v,w);
		G[v].eb(u,w);
	}
//	cout<<"here";
	djikstra(ss,dist1,cnt1);
	djikstra(t,dist2,cnt2);
//	cout<<"here";
//	cout<<cnt1[t]<<" "<<cnt2[s]<<endl;
	int Dist=dist1[t], ans=cnt1[t]*cnt2[ss]%mod;
	if(Dist%2==0)
		for(int i=1;i<=n;i++)
			if(dist1[i]*2==Dist and dist1[i]+dist2[i]==Dist)
				ans = (ans-Pow(cnt1[i]*cnt2[i]%mod)%mod+mod)%mod;
	for(int u=1;u<=n;u++)
		for(auto v:G[u])
			if(dist1[u]+dist2[v.fi]+v.se==Dist and dist1[u]*2<Dist and dist2[v.fi]*2<Dist)
//				cout<<u<<" "<<v.fi<<endl;
				ans = (ans-Pow(cnt1[u]*cnt2[v.fi]%mod)%mod+mod)%mod;
	while(ans<0) ans+=mod;
	cout<<ans%mod;
}


Measured memory_bytes: 21924
#include <bits/stdc++.h>
#define ll long long
#define fop(i,m,n) for(ll i=m;i<n;i++)
#define MOD 1000000007
using namespace std;
bool a[1010][1010];
ll dp[1010][1010];
int main(){
	ll n, m;
	cin >> n >> m;
	fop(i,1,n+1){
		string k;
		cin >> k;
		fop(j,1,m+1){
			if(k[j-1] == '.') a[i][j] = true;
			else a[i][j] = false;
		}
	}
	memset(dp,0,sizeof(dp));
	int f = 1;
	fop(i,1,n+1){
		if(a[i][1] == false) f = 0;
		dp[i][1] = f;
	}
	f = 1;
	fop(i,1,m+1){
		if(a[1][i] == false) f = 0;
		dp[1][i] = f;
	}
	fop(i,2,n+1){
		fop(j,2,m+1){
			if(a[i][j] == false){
				dp[i][j] = 0;
				continue;
			}
			dp[i][j] = dp[i-1][j] + dp[i][j-1];
			dp[i][j] %= MOD;
		}
	}
	cout << dp[n][m];
}

Measured memory_bytes: 9216