akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>

using namespace std;

int main(){
    string s,t;

    cin >> s >> t;
    int N = s.size();
    int M = t.size();
    //printf("s : %s\n",s);
    sort(s.begin(), s.end());
    sort(t.rbegin(),t.rend());
    for (int i = 0; i < N; i++){
        //printf("sorted s : %s\n",s[i]);
        if(s[i] < t[i]){
            puts("Yes");
            return 0;
        }else if(s[i] == t[i]){
            //continue;
        }else{
            puts("No");
            return 0;
        }
    }
    if(N < M){
        puts("Yes");
        return 0;
    }else{
        puts("No");
        return 0;
    }


    return 0;
}


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

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

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

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

int main()
{
    string A, B, C;
    cin >> A >> B >> C;
    if (A[A.length() - 1] == B[0] && B[B.length() - 1] == C[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int count = 0;
  int light = 0;
  while (count <= N+3) {
    light = A[light]-1;
    count++;
    if (light == 1) {
      cout << count << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
  

Measured memory_bytes: 640
n,x,mod=map(int,input().split())
d=[-1]*mod
ans=0
syu=0
al=[]
for i in range(n):
    if d[x]!=-1:
        en=i
        syu=i-d[x]    
        break
    ans+=x
    al.append(x)
    d[x]=i
    x=x*x%mod   
if syu==0:
    print(ans)
    exit()
ans+=((n-en)//syu)*sum(al[d[x]:en])
for i in range((n-en)%syu):
    ans+=x%mod
    x=x*x%mod
print(ans)

Measured memory_bytes: 13528
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a,b;
	cin>>a>>b;
	cout<<a*a-b<<endl;
}








Measured memory_bytes: 256
class Node(object):
    def __init__(self, parent, left, right):
        self.parent = parent
        self.left = left
        self.right = right
        self.height = None

    def get_type(self):
        if self.parent == -1:
            return 'root'
        elif self.left == -1 and self.right == -1:
            return 'leaf'
        else:
            return 'internal node'

    def get_depth(self):
        if self.parent == -1:
            return 0
        else:
            depth = 1
            t = Nodes[self.parent]
            while t.parent != -1:
                t = Nodes[t.parent]
                depth += 1
            return depth

    def get_height(self):
        h_left = 0
        h_right = 0
        if self.left != -1:
            h_left = Nodes[self.left].get_height() + 1
        if self.right != -1:
            h_right = Nodes[self.right].get_height() + 1
        self.height = max(h_left, h_right)
        return self.height

    def get_degree(self):
        degree = 0
        if self.left != -1:
            degree += 1
        if self.right != -1:
            degree += 1
        return degree

    def get_sigling(self):
        if self.parent == -1:
            return -1
        p = Nodes[self.parent]
        if Nodes[p.left] != self and  Nodes[p.left] != -1:
            return p.left
        if Nodes[p.right] != self and  Nodes[p.right] != -1:
            return p.right


def process_node_data(data):
    global Nodes
    num_of_elem = len(data)
    if num_of_elem != 3:
        raise ValueError
    else:
        my_id, left, right = data
        Nodes[my_id].left = left
        if left != -1:
            Nodes[left].parent = my_id
        Nodes[my_id].right = right
        if right != -1:
            Nodes[right].parent = my_id



MAX_NODES = 25
Nodes = [Node(-1, None, None) for _ in range(MAX_NODES)]  # ????´???? [Node(None, None, None)] * MAX_NODES ????????¨????????????????????????????????§??¨???

if __name__ == '__main__':
    # ??????????????\???
    num_of_nodes = int(input())
    node_data = []
    for i in range(num_of_nodes):
        t = [int(x) for x in input().split(' ')]
        node_data.append(t)

    # ???????????????
    for d in node_data:
        process_node_data(d)

    # ???????????????
    for i in range(num_of_nodes):
        p = Nodes[i]
        print('node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}'.format(
            i, p.parent, p.get_sigling(), p.get_degree(), p.get_depth(), p.get_height(), p.get_type()
        ))

Measured memory_bytes: 7784
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var n = Integer.parseInt(br.readLine());

      var result = pow(10, n) % modulo;

      result = result - pow(9, n);
      if (result < 0) result += modulo;
      result = result % modulo;

      result = result - pow(9, n);
      if (result < 0) result += modulo;
      result = result % modulo;

      result = result + pow(8, n) % modulo;
      if (result < 0) result += modulo;
      result = result % modulo;

      System.out.println(result);
    }
  }

  private static Map<Integer, Map<Integer, Long>> cache = new HashMap<>();
  private static final long modulo = (long) Math.pow(10, 9) + 7;

  private static long pow(int a, int n) {
    if (n == 1) {
      return a;
    }

    cache.computeIfAbsent(a, t -> new HashMap<>());
    final var c = cache.get(a);
    if (c.containsKey(n)) {
      return c.get(n);
    }

    if (n % 2 == 0) {
      final var result = (pow(a, n / 2) * pow(a, n / 2)) % modulo;
      c.put(n, result);

      return result;
    } else {
      final var result = (((pow(a, n / 2) * pow(a, n / 2)) % modulo) * a) % modulo;
      c.put(n, result);

      return result;
    }
  }
}


Measured memory_bytes: 33656
// https://atcoder.jp/contests/abc122/submissions/5411240

#include <bits/stdc++.h>
using namespace std;

int N,Q,l,r,ans,sum;
string s;

int main(){
    cin >> N >> Q;
    cin >> s;
    vector<int> vec;
    vector<int> ans_vec;
    ans_vec.push_back(sum);
    for(int i=1;i<N;i++){
        if(s[i-1]=='A' and s[i]=='C'){
            sum++;
        }
        ans_vec.push_back(sum);
    }
    for(int i=0;i<Q;i++){
        cin >> l >> r;
        ans = ans_vec.at(r-1)-ans_vec.at(l-1);
        vec.push_back(ans);
    }
    for(int i=0;i<Q;i++){
        cout << vec[i] << "\n";
    }
    
}

Measured memory_bytes: 1976
import sys
n = int(input())

for i in range(1, 3501):
    for j in range(1, 3501):
        if 4*i*j-n*i-n*j > 0:
            if (n*i*j)%(4*i*j-n*i-n*j) == 0:
                print(i, j, n*i*j//(4*i*j-n*i-n*j))
                sys.exit()

Measured memory_bytes: 40556
#include <iostream>
#include <utility>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#define llint long long
#define mod 998244353
#define eps 1e-8

using namespace std;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = 0;
	}
	
	void update(int i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = (seg[i*2] + seg[i*2+1]) % mod;
		}
	}

	llint query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return 0;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return (lval + rval) % mod;
	}
	llint query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

llint n, k, a;
SegTree seg(18);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k >> a;
	a = a * modpow(100, mod-2) % mod;
	
	for(int i = k; i <= 200000; i++) seg.update(i, 1);
	for(llint i = k-1; i >= 0; i--){
		llint tmp = 0, l, r;
		l = i+1, r = min(k-1, i+n);
		if(l <= r) tmp = seg.query(l, r) * a % mod, tmp %= mod;
		l = max(i+1, k), r = i+n;
		if(l <= r) tmp += seg.query(l, r), tmp %= mod;
		tmp *= modpow(n, mod-2);
		seg.update(i, tmp);
	}
	cout << seg.query(0, 0) << endl;
	
	return 0;
}


Measured memory_bytes: 6968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define input(n) scanf("%d",&n)
#define llinput(n) scnaf("%lld",&n)

int main()
{
  string s;
  cin>>s;
  if(s=="ABC")
  cout<<"ARC";
  else
  cout<<"ABC";
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
struct Node {
    Int parentIndex = -1;
};

int main() {
    Int n, m;
    cin >> n >> m;
    auto p = vector<Int>(n);
    rep(i, n) {
        Int a;
        cin >> a;
        a--;
        p[i] = a;
    }

    auto nodes = vector<Node>(n);

    function<Int(const Int)> rootIndex = [&](const Int targetIndex) {
        auto &targetNode = nodes[targetIndex];
        auto parentIndex = targetNode.parentIndex;
        if (parentIndex == -1) {
            return targetIndex;
        } else {
            auto result = rootIndex(parentIndex);
            targetNode.parentIndex = result;
            return result;
        }
    };

    rep(j, m) {
        Int x, y;
        cin >> x >> y;
        x--;
        y--;
        auto rx = rootIndex(x);
        auto ry = rootIndex(y);
        if (rx != ry) {
            nodes[rx].parentIndex = ry;
        }
    }

    Int ans = 0;
    rep(i, n) {
        if (rootIndex(p[i]) == rootIndex(i)) ans++;
    }

    PUTS(ans);
}


Measured memory_bytes: 1792
while True:
    n=input()
    if n=='0': break
    a,b=0,0
    for i in range(1,len(n)):
        if n[i]=='A':
            a+=1
        else:
            b+=1
    if a>b:
        a+=1
    else:
        b+=1
    print(a,b)


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

int main()
{
    string S;
    cin >> S;
    int ans1 = 0;

    for (int i = 0; i < S.length(); i++)
    {
        if (i % 2 == 0)
        {
            if (S[i] == '0')
            {
                ans1 += 1;
            }
        }
        else
        {
            if (S[i] == '1')
            {
                ans1 += 1;
            }
        }
    }

    int ans2 = 0;
    for (int i = 0; i < S.length(); i++)
    {
        if (i % 2 == 1)
        {
            if (S[i] == '0')
            {
                ans2 += 1;
            }
        }
        else
        {
            if (S[i] == '1')
            {
                ans2 += 1;
            }
        }
    }

    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
    char s[5];
    scanf("%s",s);
    if(s[0]=='S' && s[1]=='U' && s[2] =='N')
        printf("%d",7);
     if(s[0]=='M' && s[1]=='O' && s[2] =='N')
        printf("%d",6);
     if(s[0]=='T' && s[1]=='U' && s[2] =='E')
        printf("%d",5);
     if(s[0]=='W' && s[1]=='E' && s[2] =='D')
        printf("%d",4);
     if(s[0]=='T' && s[1]=='H' && s[2] =='U')
        printf("%d",3);
     if(s[0]=='F' && s[1]=='R' && s[2] =='I')
        printf("%d",2);
     if(s[0]=='S' && s[1]=='A' && s[2] =='T')
        printf("%d",1);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    char dif = 'A' - 'a';
    printf("%c%c%c\n", a[0] + dif, b[0] + dif, c[0] + dif);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
int N, M;
vector<int> v[200010];
bool ans = false;
bool visit[200010];
/*==================================================*/
/*function*/
void dfs(int node, int cnt){
    if(node == N-1){
        ans = true;
    }
    if(cnt == 0){
        return;
    }
    REP(i,0,v[node].size()){
        if(!visit[v[node][i]]){
            visit[v[node][i]] = true;
            dfs(v[node][i], cnt-1);
            visit[v[node][i]] = false;
        }
    }

}
/*==================================================*/

int main() {
    cin>>N>>M;
    REP(i,0,M){
        int a, b;
        cin>>a>>b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }

    visit[0] = true;
    dfs(0, 2);

    if(ans) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;

    return 0;
}


Measured memory_bytes: 12144
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    int n; 
    cin >> n;
    long double a[n];
    rep(i,n) cin >> a[i];
    long double p = 1;
    rep(i,n){
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i,n){
        p*=a[i];
        if(p>1e18){
            cout << -1 << endl;
            return 0;
        }
    }
    long long ans = p;
    cout << ans << endl;

}


Measured memory_bytes: 5276
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstring>

using namespace std;
char o[10000];
int ans;
int main()
{
	cin>>o;
	int p=strlen(o);
	for(int i=2;i<=p-1;i++)
	{
		if(o[i])
		ans++;
	}
	cout<<o[0]<<ans<<o[p-1];
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

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

using namespace std;
typedef long long int lint;

string abacus[] = { "* = ****","* =* ***","* =** **","* =*** *","* =**** "," *= ****"," *=* ***"," *=** **"," *=*** *"," *=**** " };

bool AOJ0128(bool flag)
{
	int n;
	if (!(cin >> n)) return false;

	char pic[8][5] = { 0 };
	RREP(j, 5) {
		int m = n % 10;
		REP(i, 8) {
			pic[i][j] = abacus[m][i];
		}
		n /= 10;
	}

	if (flag) cout << endl;

	REP(i, 8) {
		REP(j, 5) {
			cout << pic[i][j];
		}
		cout << endl;
	}

	return true;
}

int main()
{
	bool flag = false;
	while (AOJ0128(flag)) {
		flag = true;
	}

	return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
  using namespace std;
  #define ll  long long int
  #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
  int main()
  {

    

    fastio; 
   ll n;
   cin>>n;
   ll a[n];
   for (int i = 0; i < n; ++i)
   {
     cin>>a[i];
   }
   ll maxi=a[0],sum=0;
   for (int i = 0; i < n; ++i)
   {
     if(a[i]<=maxi)
     {
      sum+=maxi-a[i];
     }
     else
     {
      maxi=a[i];
       sum+=maxi-a[i];
     }
   }

   cout<<sum;


  return 0;   
  }

Measured memory_bytes: 5204
var     n,i,g,b,l,c,d,y,o,u,r: longint;
        a:array[0..100000] of longint;
procedure xuli;
begin
        g:=0; b:=0; l:=0; c:=0; d:=0; y:=0; o:=0; r:=0; u:=0;
        for i:=1 to n do
        case a[i] of
        1..399: g:=1;
        400..799: b:=1;
        800..1199: l:=1;
        1200..1599: c:=1;
        1600..1999: d:=1;
        2000..2399: y:=1;
        2400..2799: o:=1;
        2800..3199: r:=1;
        3200..4800: inc(u);
end;
end;
procedure xuat;
begin
        if (u=g+b+l+c+d+y+o+r+u) then writeln(1,' ',u)
        else writeln(g+b+l+c+d+y+o+r,' ',g+b+l+c+d+y+o+r+u);
end;
begin
       
        readln(N);
        for i:=1 to n do read(A[i]);
        xuli;
        xuat;
      
end.


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const int N = 100000;
const int sqrt_N = 317; // sqrt(10^5)

struct SqrtDecomposition{
    int n, K;
    vector<int> bucket_add;
    vector<int> data;

    SqrtDecomposition(int n): n(n) {
        bucket_add.assign(sqrt_N, 0);
        data.assign(N, 0);
        K = (n + sqrt_N - 1) / sqrt_N;
    }

    void add(int s, int t, int x){
        t++;
        for(int k=0;k<K;k++){
            int l = k * sqrt_N, r = (k+1) * sqrt_N;
            if(t < l || r < s) continue;
            if(s <= l&& r <= t){
                bucket_add[k] += x;
            }else{
                for(int i=max(s,l);i<min(t,r);i++){
                    data[i] += x;
                }
            }
        }
    }

    int get(int i){
        return data[i] + bucket_add[i/sqrt_N];
    }
};

int main(){
    int n,nq,q,s,t,x;
    cin >> n >> nq;
    
    SqrtDecomposition sd = SqrtDecomposition(n);
    for(int i=0;i<nq;i++){
        cin >> q;
        if(q){
            cin >> x;
            cout << sd.get(x-1) << endl;
        }else{
            cin >> s >> t >> x;
            sd.add(s-1, t-1, x);
        }
    }
}



Measured memory_bytes: 3344
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans;
		
		ArrayList<Integer> numArray = new ArrayList<>();
		
		for(int i=0; i<N; i++) {
			numArray.add(sc.nextInt());
		}
		
		Collections.sort(numArray);
		
		ans = numArray.get(N-1) - numArray.get(0);
		System.out.println(ans);
			
		
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(200005)
#define fim endl
#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 max3(x, y, z) max(x, max(y, z))
#define log2(k) int(log2(k))
using namespace std;
typedef pair<ll, int> pii;
typedef pair<string, int> psi;
typedef pair<int, pair<int, int> > piii;
typedef pair<char, int> pci;
typedef pair<int, bool> pib;

int main() {
    int vet[3];
    cin >> vet[0] >> vet[1] >> vet[2];
    sort(vet, vet+3);
    cout << ((vet[0] == vet[1] && vet[1] != vet[2] or vet[1] == vet[2] && vet[1] != vet[0]) ? "Yes" : "No") << fim;

}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
	int r,g;
	cin >> r;
	cin >> g;
	cout << 2*g-r << endl;
 
	return 0;
}

Measured memory_bytes: 256
#B
from itertools import accumulate

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
accum = list(accumulate(a))

accum.reverse()
a.reverse()
ind = 1
while(ind < n):
    if accum[ind]*2 >= a[ind-1]:
        ind += 1
    else:
        break
    
print(ind)
    

Measured memory_bytes: 14428
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, a[16][16];
ll DP[1 << 16];

int main() {
	cin >> N;
	for (int i = 0; i != N; ++i)
		for (int j = 0; j != N; ++j)
			cin >> a[i][j];
	for (int i = 1; i != 1 << N; ++i) {
		vector<int>v;
		for (int j = 0; j != N; ++j) {
			if (i&(1 << j))
				v.push_back(j);
		}
		for (int j = 0; j != v.size(); ++j) {
			for (int k = j + 1; k != v.size(); ++k) {
				DP[i] += a[v[j]][v[k]];
			}
		}
		for (int j = 1; j != 1 << v.size(); ++j) {
			int t = 0;
			for (int k = 0; k != v.size(); ++k) {
				if (j&(1 << k))
					t += (1 << v[k]);
			}
			DP[i] = max(DP[i], DP[t] + DP[i - t]);
		}
	}
	cout << DP[(1 << N) - 1] << endl;
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

int main(void){
    int x[3];
    scanf("%d %d %d\n",&x[0],&x[1],&x[2]);
    int i,j, tmp;
	do{
		i = 0;
		for(j=0;j<2;j++){
			if(x[j] > x[j+1]){
				tmp = x[j];
				x[j] = x[j+1];
				x[j+1] = tmp;
				i =i +1;
			}
		}
	}while(i > 0);
    printf("%d %d %d\n",x[0],x[1],x[2]);
    return 0;
}


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

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

  vector<ll> lucas(87);
  lucas.at(0) = 2;
  lucas.at(1) = 1;
  for (int i = 2; i <= 86; i++) {
    lucas.at(i) = lucas.at(i - 1) + lucas.at(i - 2);
  }

  cout << lucas.at(N) << endl;
  return 0;
}

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

using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<int>> v(100);
    int cur = 0, turn = 0;
    for(int i = 0; i < n - 1; i++) {
        if(a[i] < a[i+1]) {
            turn = 1;
            v[cur].push_back(i);
        } else {
            if(turn == 1) {
                turn = 0;
                cur++;
            }
        }
    }
    long long start = 1000;
    for(int i = 0; i < 100; i++) {
        if(v[i].size() > 0) {
            int sz = v[i].size();
            int rest = start % a[v[i][0]];
            start /= a[v[i][0]];
            start *= a[v[i][sz-1]+1];
            start += rest;
        }
    }
    cout << start << "\n";
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>

using namespace std;
typedef long long ll;
#define MOD 1000000007

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

    cout << 3 * r * r << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextLong();
            }
            int flag = 0;
            for (int i = n-2; i >= 0; i--) {
                if (arr[i] > arr[i+1]){
                    if (arr[i] - 1 <= arr[i+1]){
                        arr[i]--;
                    }else {
                        flag = 1;
                        break;
                    }
                }
            }
            if (flag == 1){
                out.println("No");
            }else {
                out.println("Yes");
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


Measured memory_bytes: 38324
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
int  dp [1001][1001];
char arr[1001][1001];
int  n,m;
int  dpf(int i,int j)
{
       if(dp[i][j]!=-1)                   {return dp[i][j];                               }
  else if(arr[i][j]=='#'||i==0||j==0)     {return dp[i][j]=0;                             }
  else if((i==n&&j==m-1)||(i==n-1&&j==m)) {return dp[i][j]=1;                             }
  else if(arr[i][j]=='.'&&i==n)           {return dp[i][j]=dpf(i,j+1);                    }
  else if(arr[i][j]=='.'&&j==m)           {return dp[i][j]=dpf(i+1,j);                    }
  else if(arr[i][j]=='.')                 {return dp[i][j]=(dpf(i+1,j)+dpf(i,j+1))%mod;   }
  return 0;
}
int main()
{
 memset(dp,-1,sizeof(dp));
 cin>>n>>m;
 for(int i=1;i<=n;i++)
 {
   for(int j=1;j<=m;j++)
   {
     cin>>arr[i][j];
   }
 }
 cout<<dpf(1,1);
return 0;
}


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

#define mx 100005
#define ll long long

int tc = 1, n;
const ll mod  = 1e9+7;

void solve(int kk)
{
    string s1, s2;
    cin >> s1 >> s2;
    int ans = s2.size();
    for(int i=0; s1[i]; i++){
        int cc = 0, yes=0;
        for(int j=i, k=0; s1[j] && s2[k]; k++, j++){
            cc+=(s1[j]!=s2[k]);
            ++yes;
        }
        if(yes == s2.size())
            ans = min(ans, cc);
    }
    cout << ans << "\n";
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("D:\\Codings\\CPP\\input.in", "r", stdin);
    freopen("D:\\Codings\\CPP\\output.in", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int kk = 0;
    //cin >> tc;
    //scanf("%d", &tc);
    while (++kk <= tc)
        solve(kk);

    return 0;
}

Measured memory_bytes: 3664
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#define ll long long
#define mod 1000000007
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
struct Data{
	int x,y;
}a[maxn];
std::priority_queue<int>q;
int n;
bool cmp(Data a,Data b){return a.y<b.y;}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i].x=read(),a[i].y=read();
	std::sort(a+1,a+n+1,cmp);
	int now=0,ans=0;
	for(int i=1;i<=n;i++)
		if(now+a[i].x<=a[i].y){
			q.push(a[i].x);
			now+=a[i].x; ++ans;
		}
		else if(!q.empty()){
			int k=q.top();
			if(k>a[i].x){
				q.pop(); q.push(a[i].x);
				now-=k-a[i].x;
			}
		}
	puts(ans==n?"Yes":"No");
	return 0;
}

Measured memory_bytes: 2936
#include<iostream>
int main()
{
	int m,n;
	std::cin >> n >> m;
	int a[100][100], b[100][1];
	int c[100];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			std::cin >> a[i][j];
		}
	}
	for ( int i=0; i<m; i++)
	{
		for ( int j=0; j<1; j++)
		{
			std::cin >> b[i][j];
		}
	}

	for (int i=0; i<n; i++)
	{
		c[i] = 0;
	}
	
	for ( int i=0; i<n; i++ )
	{
		for ( int j=0; j<1; j++ )
		{
			for ( int h=0; h<m; h++ )
			{
				c[i] += a[i][h]*b[h][j]; 
			}
		}
	}

	for (int i=0; i<n; i++)
	{
		std::cout << c[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 3148
#include <stdio.h>

int main(int argc, char** argv)
{
	typedef struct {
		int cur;
		int n;
		int s;
		int e;
		int w;
	} Dice;

	int i, num[6];
	char cmd[101];
	Dice dice;

	for (i = 0; i < 6; i++) {
		scanf("%d", &num[i]);
	}

	dice.cur = 1;
	dice.n = 5;
	dice.s = 2;
	dice.e = 3;
	dice.w = 4;

	memset(cmd, '\0', sizeof(cmd));
	scanf("%s", cmd);

	for (i = 0; cmd[i] != '\0'; i++) {
		if (cmd[i] == 'N') {
			int tmp = dice.cur;

			dice.cur = dice.s;
			dice.n = tmp;
			dice.s = 7 - tmp;
		}
		else if (cmd[i] == 'S') {
			int tmp = dice.cur;

			dice.cur = dice.n;
			dice.n = 7 - tmp;
			dice.s = tmp;
		}
		else if (cmd[i] == 'E') {
			int tmp = dice.cur;

			dice.cur = dice.w;
			dice.e = tmp;
			dice.w = 7 - tmp;

		}
		else if (cmd[i] == 'W') {
			int tmp = dice.cur;

			dice.cur = dice.e;
			dice.e = 7 - tmp;
			dice.w = tmp;
		}
		else {
		}
	}

	printf("%d\n", num[dice.cur-1]);

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

#define MAX (10000000)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int memo[1001][1001][5];

int sx, sy;
int gx, gy;
vector<int> px[5];
vector<int> py[5];

#define ABS(x) ((x) < 0 ? -(x) : (x))
inline int dist(int x1, int x2, int y1, int y2){
  return ABS(x1 - x2) + ABS(y1 - y2);
}

int dp(int x, int y, int now, int last){
  if(now == last){
    return memo[x][y][now] = dist(x, gx, y, gy);
  }
  if(memo[x][y][now] != MAX) return memo[x][y][now];
  int ret = MAX;
  int n = px[now].size();
  REP(i, n){
    int d = dist(x, px[now][i], y, py[now][i]);
    int tmp = d + dp(px[now][i], py[now][i], (now+1)%5, last);
    ret = min(ret, tmp);
  }
  return memo[x][y][now] = ret;
}

int main(){
  int w,h;
  while(scanf("%d%d ",&w,&h), w+h){
    REP(i,5) px[i] = vector<int>();
    REP(i,5) py[i] = vector<int>();
    REP(i,h) REP(j,w){
      char tmp;
      scanf("%c ",&tmp);
      if(isdigit(tmp)){
        px[tmp- '1'].push_back(j);
        py[tmp- '1'].push_back(i);
      }else if(tmp == 'S'){
        sx = j;
        sy = i;
      }else if(tmp == 'G'){
        gx = j;
        gy = i;
      }
    }
    int ans = MAX;
    int type = -1;
    REP(s,5){
      int x = sx;
      int y = sy;
      REP(xx,w+1) REP(yy,h+1) REP(i,5) memo[xx][yy][i] = MAX;
      int ret = dp(x, y, (s+1)%5, s);
      if(ans > ret){
        ans = ret;
        type = s;
      }
    }
    if(ans == MAX){
      puts("NA");
    }else{
      printf("%d %d\n",type+1,ans);
    }
  }
  return 0;
}

Measured memory_bytes: 20000
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import product
def main():
    n=int(input())
    XY=[[] for _ in range(n)]
    for i in range(n):
        a=int(input())
        for j in range(a):
            x,y=map(int,input().split())
            XY[i].append((x-1,y))
    tf=list(product([1,0],repeat=n)) #i人目の正直か嘘か
    ans=0
    for tfx in tf:
        for i,x in enumerate(tfx):
            if x==1: #i番目が正直人なら
                for xxy in XY[i]:#i番目の証言を
                    if tfx[xxy[0]]!=xxy[1]:
                        break
                else:
                    continue
                break
        else:
            ans=max(ans,sum(1 if a==1 else 0 for a in tfx))
    print(ans)


        
if __name__=='__main__':
    main()

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

int main() {
  int N;
  cin >> N;
  vector<string> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
    sort(p.at(i).begin(), p.at(i).end());
  }
  sort(p.begin(), p.end());
  long long int c = 0;
  long long int t = 0;
  while (t < N - 1) {
    long long int a = 1;
    for (int i = t + 1; i < N; i++) {
      if (p.at(t) == p.at(i)) {
        a++;
      }
      else {
        t = i;
        c += a * (a - 1) / 2;
        break;
      }
      if (i == N - 1) {
        c += a * (a - 1) / 2;
        t = N - 1;
      }
    }
  }
  printf("%lld\n", c);      
}


Measured memory_bytes: 7296
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
tree = [[] for _ in range(n)]
dic = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)
    dic[(a - 1, b - 1)] = i
ans = [0 for _ in range(n - 1)]
max_color = 0

def dfs(pos, before_pos, before_color):
    global max_color
    color = 1
    for next_pos in tree[pos]:
        if color == before_color:
            color += 1
        if next_pos == before_pos:
            continue
        before = min(pos, next_pos)
        after = max(pos, next_pos)
        ans_ind = dic[(before, after)]
        if pos < next_pos:
            ans[ans_ind] = color
        else:
            ans[ans_ind] = color
        max_color = max(color, max_color)
        dfs(next_pos, pos, color)
        color += 1
dfs(0, -1, -1)

print(max_color)
for i in ans:
    print(i)


Measured memory_bytes: 81948
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000007

using namespace std;

inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

int main()
{
    int a, b;
    scanf("%d%d",&a,&b);
    cout << a*b << endl;
    return 0;
}


Measured memory_bytes: 3688
from fractions import gcd

N, M = map(int, input().split())
A = list(map(int, input().split()))
flag = False
n = 1

# 全てを2で割る
for i in range(N):
    A[i] //= 2

for i in range(N):
    n *= A[i]//gcd(n, A[i])
    # 最小公倍数がMより大きくなる場合
    if n>M:
        flag = True
        break

for i in range(N):
    if (n//A[i])%2==0:
        flag = True
        break

if flag==False and M>=n:
    ans = 1
    M -= n
    ans += M//(2*n)
    print(ans)
else:
    print(0)

Measured memory_bytes: 16280
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> v(n);
    vector<int> u(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        a[i] = i + 1;

    }
    for (int i = 0; i < n; i++)
    {
        cin >> u[i];

    }
    int ans = 0;
    int distv = 0;
    int distu = 0;
    while (v != a)
    {
        prev_permutation(v.begin(), v.end());
        distv++;
    }
    while (u != a)
    {
        prev_permutation(u.begin(), u.end());
        distu++;
    }
    ans = abs(distu - distv);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[1<<16];
int d[16][17];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)
			for(int j=0;j<a+1;j++)
				scanf("%d",&d[i][j]);
		for(int i=0;i<(1<<16);i++)dp[i]=999999999;
		dp[0]=0;
		for(int i=0;i<(1<<a);i++){
			for(int j=0;j<a;j++){
				if(!(i&(1<<j))){
					int v=d[j][0];
					for(int k=0;k<a;k++)if(i&(1<<k))v=min(v,d[j][k+1]);
					dp[i+(1<<j)]=min(dp[i+(1<<j)],dp[i]+v);
				}
			}
		}
		printf("%d\n",dp[(1<<a)-1]);
	}
}

Measured memory_bytes: 1284
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int a[92][92],b[92][92];
int f(int x,int y){
  int mx=1;
  if(a[x][y]&&b[x][y]){
    b[x][y]=0;
    mx=max(mx,f(x-1,y)+1);
    mx=max(mx,f(x,y-1)+1);
    mx=max(mx,f(x+1,y)+1);
    mx=max(mx,f(x,y+1)+1);
    b[x][y]=-1;
  }else
    mx=0;
  return mx;
}
int main(){
  int i,j;
  int w,h;
  int mx;
  while(cin>>w&&w){
    cin>>h;
    memset(a,0,sizeof(a));
    for(i=1;i<h+1;i++)
      for(j=1;j<w+1;j++)
	cin>>a[j][i];
    mx=0;
    for(i=1;i<h+1;i++){
      for(j=1;j<w+1;j++){
	memset(b,-1,sizeof(b));
	mx=max(mx,f(j,i));
      }
    }	
    cout<<mx<<endl;
  }
  return 0;
}

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

int n;
int c[4]; // 寿司がi個載っている皿の枚数
double ev[310][310][310];
bool memo[310][310][310];

double dp(int c0, int c1, int c2) {
    int c3 = n - c0 - c1 - c2;
    if(c0 < 0 || c1 < 0 || c2 < 0 || c3 < 0 || n <= c0)
        return 0;
    if(memo[c0][c1][c2])
        return ev[c0][c1][c2];
    memo[c0][c1][c2] = true;

    double ret = 0;
    ret += double(c0) / double(n - c0);
    ret += double(c1) / double(n - c0) * (1 + dp(c0+1, c1-1, c2));
    ret += double(c2) / double(n - c0) * (1 + dp(c0, c1+1, c2-1));
    ret += double(c3) / double(n - c0) * (1 + dp(c0, c1, c2+1));
    ev[c0][c1][c2] = ret;
    return ret;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        c[a]++;
    }

    cout << setprecision(10) << dp(c[0], c[1], c[2]) << endl;
}



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

const int mod=1000000007;

int main(void){
    int n;
    cin>>n;
    vector<ll>v(n);
    rep(i, n) cin>>v[i];
    ll ans=0;
    rep(i, 60){
        ll x=0;
        rep(j, n){
            if(v[j]>>i&1) x++;
        }
        ll tmp=x*(n-x)%mod;
        rep(s, i){
            tmp*=2;
            tmp%=mod;
        }
        ans+=tmp;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
fun main(args:Array<String>) {
  val (a, b) = readLine()!!.split(" ").map(String::toInt)

  (a..b).map {
    val str = it.toString().toList()
    val size = str.size
    (0..size/2).map {
      str[it] == str[size-1-it]
    }.all{ it == true }
  }.filter { it == true }.size.let(::println)
}

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

const int maxn = 1e5 + 3;
int X, K, rev[maxn], Q, ti[maxn], ai[maxn], l, r, u, v;

void trans(int dt) {
	if(u + dt < 0) {
		l -= u + dt;
		u = 0;
	} else if(u + dt > X) {
		u = X;
		l = X;
	} else {
		u += dt;
	}
	if(v + dt < 0) {
		v = 0;
		r = 0;
	} else if(v + dt > X) {
		r -= v + dt - X;
		v = X;
	} else {
		v += dt;
	}
}

int calc(int x) {
	if(x <= l)
		return u;
	if(x >= r)
		return v;
	return u + x - l;
}

int main() {
	scanf("%d%d", &X, &K);
	l = u = 0;
	r = v = X;
	rev[0] = 0;
	for(int i = 1; i <= K; ++i)
		scanf("%d", rev + i);
	scanf("%d", &Q);
	for(int i = 0; i < Q; ++i)
		scanf("%d%d", ti + i, ai + i);
	ti[Q] = 0x7fffffff;
	for(int i = 1, j = 0, t = rev[0]; i <= K || j < Q;) {
		if(i <= K && rev[i] <= ti[j]) {
			trans((i & 1) ? t - rev[i] : rev[i] - t);
			t = rev[i++];
		} else {
			trans((i & 1) ? t - ti[j] : ti[j] - t);
			printf("%d\n", calc(ai[j]));
			t = ti[j++];
		}
	}
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2;
typedef pair<int, P2> P3; typedef long long ll; typedef long double ld;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<10> fact; constexpr Prime<10> prime;
constexpr int comb(int a, int b){long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b];return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr int sqrtN = 512, logN = 32;
constexpr ld PI = abs(acos(-1));
constexpr ll LINF=1e18;

ll n,m;
vector<int> g[100010];

ll color(){
	int li[100010]; queue<int> qu; qu.push(0);
	for(int i = 0; i < 100010; i++) li[i] = -1; li[0] = 0;
	
	ll a = 1, b = 0;
	while(!qu.empty()){
		auto p = qu.front(); qu.pop();
		
		for(auto e:g[p]){
			if(li[e] != -1 and li[e] == li[p]) return n * (n - 1) / 2 - m;
			if(li[e] != -1) continue;
			li[e] = 1 - li[p];
			if(li[e]) b++;
			else a++;
			qu.push(e);
		}
	}
	
	return a * b - m;
}

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b; cin >> a >> b;
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}
	
	cout << color() << endl;
	return 0;
}


Measured memory_bytes: 6272
#include <cstdio>
#include <iostream>
using namespace std;
int n,a[303][303],b[303][303];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	    for(int j=1;j<=n;++j)scanf("%d",&a[i][j]);
	for(int i=1;i<=n;++i)
	    for(int j=1;j<=n;++j)
	        for(int k=1;k<=n;++k)if(k!=i && k!=j)
	            if(a[i][j]>a[i][k]+a[k][j]){
	            	printf("-1");
	            	return 0;
	            }
	            else if(a[i][j]==a[i][k]+a[k][j])b[i][j]=1;
	long long ans=0;
	for(int i=1;i<n;++i)
	    for(int j=i+1;j<=n;++j)
	        if(!b[i][j])ans+=a[i][j];
	printf("%lld",ans);
}

Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,M,V,P = map(int,readline().split())
A = np.array(read().split(),np.int64)

A.sort()

def test(i):
    """
    i 番の人を勝者にできる
    """
    # はじめから上位P以内の場合
    if N - i <= P:
        return True
    # 他人に入ることを許容できる票数を計算する
    me = A[i] + M
    C = np.zeros(N,np.int64)
    C = me - A
    C = np.minimum(C,M)
    C[N-P+1:] = M # この層は負け前提
    if (C < 0).any():
        return False
    C[i] = 0
    x = C.sum()
    return C.sum() >= M * (V-1)

left = -1 # 勝てない
right = N-1 # 勝てる
while left + 1 < right:
    x = (left + right) // 2
    if test(x):
        right = x
    else:
        left = x

answer = N - right
print(answer)

Measured memory_bytes: 21528
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10;
int tot = 0;
ll d[N], pw[20], gg[20];

int check(ll x) {
  int ans = 0;
  for(; x; x /= 10) ans += x % 10;
  return ans;
}

int c[N];
void gao(ll x) {
  c[0] = 0;
  for(; x; x /= 10) c[++c[0]] = x % 10;
}

ll sz[N];

ll find(ll x) {
  gao(x);
  ll now = 0;
  int res = 0;
  for(int i = c[0]; i >= 1; --i) {
    for(int j = c[i]; j <= 9; ++j) {
      sz[++res] = now + pw[i - 1] * j + gg[i - 1];
    }
    now += c[i] * pw[i - 1];
  }
  int be = 1;
  for(int i = 2; i <= res; ++i) {
    ll pos = sz[i] * check(sz[be]) - sz[be] * check(sz[i]);
    if(pos < 0) be = i;
    else if(pos == 0 && sz[i] < sz[be]) be = i;    
  }
  return sz[be];
}

int main() {
  for(int i = 1; i <= 16; ++i) gg[i] = gg[i - 1] * 10 + 9;
  pw[0] = 1;
  for(int i = 1; i <= 16; ++i) pw[i] = pw[i - 1] * 10;
  int k;
  scanf("%d", &k);
  ll lst = 0;
  for(int o = 1; o <= k; ++o) {
    lst = find(lst + 1);
    printf("%lld\n", lst);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef int ftype;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
#define FIRSTWIN do{cout << "Monocarp\n"; return 0;}while(0)
#define SECONDWIN do{cout << "Bicarp\n"; return 0;}while(0)

const int MAXN = 2e5+4;
const int MOD = 1e9+7;
const int INF = 1e9+1;

int N;
LL K;
int A[MAXN], B[MAXN];

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> K;
    fori(i, N) cin >> A[i];
    fori(i, N) cin >> B[i];

    sort(A,A+N);
    sort(B,B+N);
    reverse(B,B+N);

    //fori(i,N) cout << A[i] << ' ';
    //cout << endl;
    //fori(i,N) cout << B[i] << ' ';
    //cout << endl;

    LL mx = 0;
    fori(i,N) mx = max(mx, 1LL*A[i]*B[i]);

    LL r = mx+1, l = -1;
    while(r-l > 1) {
        LL m = l+(r-l)/2;
        LL need = 0;
        fori(i,N) {
            need += max(0LL, A[i]-m/B[i]);
        }

        if(need <= K) r = m;
        else l = m;
    }

    cout << r << endl;
    return 0;
}


Measured memory_bytes: 1792
/**
 *      ABC 91 B
 *      author  : kyomukyomupurin
 *      created : 2018-08-31 03:47:27
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, M;
    cin >> N;
    vector<string> s, t;
    for (int i = 0; i < N; ++i) {
        string x; cin >> x;
        s.push_back(x);
    }
    cin >> M;
    for (int i = 0; i < M; ++i) {
        string x; cin >> x;
        t.push_back(x);        
    }
    int max = 0;
    
    for (int i = 0; i < N; ++i) {
        int count = 0;
        for (int j = 0; j < N; ++j) {
            if (s[i] == s[j]){
                ++count;
            }            
        }
        for (int j = 0; j < M; ++j) {
            if (s[i] == t[j]){
                --count;
            }    
        }
        if (count > max) max = count;
    }

    cout << max << endl;

    return 0;
}



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

using namespace std;

int main(){
	
	string s, t;

	cin >> s >> t;

	t.pop_back();

	if(s.compare(t) == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}


Measured memory_bytes: 3536