akhauriyash/Code-Regression huggingface dataset:
from collections import *
from itertools import *
import copy
from heapq import *


N,M,R=map(int,input().split())
Rlst=list(map(int,input().split()))
ABC=[list(map(int,input().split())) for i in range(M)]

data=[[] for i in range(N+1)]
nagasa={}
for a,b,c in ABC:
    data[a].append(b)
    data[b].append(a)
    A,B=min(a,b),max(a,b)
    nagasa.update({str(A)+" "+str(B):c})
mokutekiti=[[100000*200+1 for i in range(R)] for m in range(R)]
for r1i in range(R-1):
    for r2i in range(r1i+1,R):
        r1=Rlst[r1i]
        r2=Rlst[r2i]
        visited=set()
        stack=[0]
        heapify(stack)
        dic={0:[r1]}
        kyori=set([0])
        while stack:
            m=heappop(stack)
            #if not m in visited:
            #visited.add(m)
            a=dic[m].pop()
            if a==r2:
                break
            if not a in visited:
                visited.add(a)
                for b in data[a]:
                    if not b in visited or b==r2:
                        A,B=min(a,b),max(a,b)
                        tempm=m+nagasa[str(A)+" "+str(B)]
                        if b==r2:
                            if mokutekiti[r1i][r2i]>tempm:
                                mokutekiti[r1i][r2i]=tempm
                                mokutekiti[r2i][r1i]=tempm
                            heappush(stack,tempm)
                            if tempm in kyori:
                                dic[tempm].append(b)
                            else:
                                kyori.add(tempm)
                                dic.update({tempm:[b]})

                        else:
                            heappush(stack,tempm)
                            if tempm in dic:
                                dic[tempm].append(b)
                            else:
                                dic.update({tempm:[b]})



value=[]
for lst in permutations([i for i in range(R)],R):
    nagasa=0
    for i in range(R-1):
        nagasa+=mokutekiti[lst[i]][lst[i+1]]
    value.append(nagasa)
print(min(value))


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_d() {
	ll n;
	ll ans = 0;

	cin >> n;

	V p(n);
	rep(i, n) {
		cin >> p[i];
		p[i] -= i + 1;
	}

	rep(i, n) {
		if (p[i]== 0) {
			if (i < n - 1) {
				if (p[i + 1] != -1) {
					p[i + 1]--;
					p[i]++;
					swap(p[i], p[i + 1]);
					ans++;
				}
			}
			else {
				if (p[i - 1] != -1) {
					p[i]--;
					p[i - 1]++;
					swap(p[i - 1], p[i]);
					ans++;
				}
			}
		}
	}

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

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

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,l,r) for(int i=0l;i<r;i++)
typedef long long ll;
ll n, a;
int asc(const void* a, const void* b) { return -*(int*)a + *(int*)b; }

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

int main() {
	scanf("%lld", &n);
	scanf("%lld", &a);
	ll ans = a;
	rep(i, 1, n) {
		scanf("%lld", &a);
		ans = gcd(ans, a);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 2148
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
       string st;
        cin>>st;
        int fl=1;
        map<char,int> fr;
        FOR(i,0,st.size())
          fr[st[i]]++;
        for(auto it:fr)
          if(it.s%2!=0)
            fl=0;
        if(fl)
          cout<<"Yes\n";
        else
          cout<<"No\n";
    }
}

Measured memory_bytes: 3624
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
            int a = Input.ScanInt();
          Console.WriteLine(a<1200 ? "ABC" : "ARC");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int main(void) {
    int a, b, seki;
    int ret;

    ret = scanf("%d %d", &a, &b);

    seki = a * b;

    if(seki % 2 == 0) {
        printf("Even\n");
    } else { 
        printf("Odd\n");
    }

    return 0;
}

Measured memory_bytes: 128
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b):return (a + b - 1) // b


def solve(N, H, a_b):
    max_a = -1
    for a, b in a_b:
        max_a = max(max_a, a)

    good_b = []
    for a, b in a_b:
        if b >= max_a:
            good_b.append(b)

    ans = 0
    for b in sorted(good_b, reverse=True):
        ans += 1
        H -= b
        if H <= 0:
            return ans

    return ans + ceil(H, max_a)


def main():
    N, H = map(int, input().split())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        l.append((a, b))
    print(solve(N, H, l))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62808
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;

const int maxn = 16;
const int maxm = 65536;

int n, tot, a[maxn][maxn];
long long g[maxm+2], f[maxm+2];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			cin >> a[i][j];

	tot = (1<<n)-1;
	for (int i = 1; i <= tot; ++i) {
		for (int j = 0; j < n-1; ++j)
			if (i&(1<<j))
				for (int k = j+1; k < n; ++k)
					if (i&(1<<k))
						g[i] += a[j][k];
	}

	for (int i = 1; i <= tot; ++i) {
		// printf("%d:%lld\n", i, g[i]);
		f[i] = g[i];
		for (int j = 1; j < i; ++j)
			if ((i|j) == i)
				f[i] = max(f[i], f[i-j] + g[j]);
	}
	
	cout << f[tot] << endl;

	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

int main(){
	int n;
	scanf("%d",&n);
	int x;
	bool flag=true;
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		if(x%2==0 && x%3!=0 && x%5!=0){
			flag=false;
		}
	}
	if(flag)
		printf("APPROVED");
	else
		printf("DENIED");	
	
    return 0;
}

Measured memory_bytes: 256
def Eratosthenes(n):
	N = [1 for i in range(0,n+1)]
	i = 3
	while i*i<=n:
		if N[i]:
			j = i*i
			while j<=n:
				N[j] = 0
				j += i*2
		i += 2
	return N

N = Eratosthenes(999999)
while True:
	try:
		n = int(input())
	except EOFError:
		break
	cnt = 0
	if n>=2:
		cnt = 1
	for i in range(3, n+1, 2):
		cnt += N[i]
	print(cnt)

Measured memory_bytes: 14536
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
      int n,k;cin>>n>>k;
      auto p = vec(ll,n);
      auto sum = vec(ll,n);
      rep(i,n)sum[i] = 0;
      rep(i,n){
          cin>>p[i];
         if(i<1)sum[0] = p[0];
          else sum[i] = sum[i-1]+p[i];
        }

      int r = k-1,mx = sum[k-1];
      REP(i,k-1,n-1){
          if(mx<sum[i]-sum[i-k]){
              r = i;
              mx = sum[i]-sum[i-k];
          }
      }
      double res = 0;
      rep(i,k){
          //res += (1+p[r+i])/2*p[r+i];
        res += (double)p[r-i]*(1+p[r-i])/(2*p[r-i]);
        //cout<<(double)(1+p[r+i])/(2*p[r+i])<<endl;
      }
      cout << std::fixed << std::setprecision(6);
      cout<<res;
      //cout<<sum[r]-sum[r-k];
    }
    


Measured memory_bytes: 3328
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;

const double PI  = 3.141592653589793238463;

int main() {
    int a, b;
    cin >> a >> b;
    int r = b;
    for(int i = 0; i < a-1; i++){
        r *= (b-1);
    }
    cout << r;
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define vec vector <int>
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define bg begin()
#define en end()
#define endl "\n"
#define ff first
#define ss second
#define all(x) x.bg,x.en
#define fill(a,b) memset(a,b,sizeof(a))
#define fr(i,n) for(int i=0;i<n;i++)
#define rp(i,a,b) for(int i=a;i<b;i++)
#define rr(i,a,b) for(int i=a;i>=b;i--)
#define ft(it,x) for(auto it : x)
#define dbg(x) cout<<#x<<" "<<x<<endl;
#define dbga(arr,n) cout<<#arr<<": "; rp(tt,0,n) cout<<arr[tt]<<" "; cout<<endl;
#define mapi map<int,int>
#define test(t) int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
const int mod=1e9+7,mex=1e12,md=998244353;
signed main()
{
	fast
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;;
	int ra[a],ga[b],ca[c];
	fr(i,a) cin>>ra[i];
	fr(i,b) cin>>ga[i];
	fr(i,c) cin>>ca[i];
	sort(ra,ra+a,greater<int>());
	sort(ga,ga+b,greater<int>());
	sort(ca,ca+c);
	int i=x-1,j=y-1,k=c-1;
	// dbga(ra,x);
	// dbga(ga,y);
	// dbga(ca,c);
	while(i>=0 && j>=0 && k>=0 && (max(ra[i],ga[j])<ca[k]))
	{
		if(ra[i]<ga[j])
		{
			swap(ra[i],ca[k]);
			i--;
			k--;
		}
		else
		{
			swap(ga[j],ca[k]);
			j--;
			k--;
		}
	}
	while(i>=0 && k>=0 && (ra[i]<ca[k]))
	{
		swap(ra[i],ca[k]);
		i--;
		k--;
	}
	while(j>=0 && k>=0 && (ga[j]<ca[k]))
	{
		swap(ga[j],ca[k]);
		j--;
		k--;
	}
	// dbga(ra,x);
	// dbga(ga,y);
	// dbga(ca,c);
	int ans=0;
	fr(i,x) ans+=ra[i];
	fr(i,y) ans+=ga[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A
 */
#include <iostream>
#include <sstream>
#include <string>
#include <stack>

using namespace std;

int
main()
{
    string exp;
    getline(cin, exp);
    stringstream ss(exp);
    stack<int> numerics;

    while (!ss.eof()) {
        string a;
        ss >> a; ss.ignore();
        if (a == "+") {
            int t = numerics.top();
            numerics.pop();
            t += numerics.top();
            numerics.pop();
            numerics.push(t);
        } else if (a == "-") {
            int t = numerics.top();
            numerics.pop();
            t = numerics.top() - t;
            numerics.pop();
            numerics.push(t);
        } else if (a == "*") {
            int t = numerics.top();
            numerics.pop();
            t *= numerics.top();
            numerics.pop();
            numerics.push(t);
        } else {
            numerics.push(stoi(a));
        }
    }
    cout << numerics.top() << endl;

    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

class WarchallFloyd {

    int n;
    vector<vector<ll>> distances;

public:
    WarchallFloyd(int n) : n(n), distances(n, vector<ll>(n, INF)) {
        rep(i, n) distances[i][i] = 0;
    };

    void warshall_floyd() {
        for (int k = 0; k < n; k++) {       // 経由する頂点
            for (int i = 0; i < n; i++) {    // 始点
                for (int j = 0; j < n; j++) {  // 終点
                    if (distances[i][j] == INF && (distances[i][k] == INF || distances[k][j] == INF)) {
                        distances[i][j] = INF;
                    } else {
                        distances[i][j] = min(distances[i][j], distances[i][k] + distances[k][j]);
                    }
                }
            }
        }
    }

    ll distance(int from, int to) {
        return distances[from][to];
    }

    void add(int from, int to, ll cost) {
        distances[from][to] = cost;
        distances[to][from] = cost;
    }


    friend std::istream &operator>>(std::istream &in, WarchallFloyd &o) {
        int from, to;
        ll c;
        cin >> from >> to >> c;
        from--;
        to--;

        o.distances[from][to] = c;
        o.distances[to][from] = c;
        return in;
    }
};


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

    WarchallFloyd wf(n);
    rep(i, n) {
        rep(j, n) {
            char c;
            cin >> c;
            if (c == '1') {
                wf.add(i, j, 1);
            }
        }
    }
    wf.warshall_floyd();

    rep(i, n) {
        rep(j, n) {
            rep(k, n) {
                int a = wf.distance(i, k) + wf.distance(k, j);
                int b = wf.distance(i, j);
                a %= 2;
                b %= 2;

                if (a != b) {
                    cout << -1 << endl;
                    ret();
                }
            }
        }
    }
    int ans = 0;
    rep(i, n) {
        rep(j, n) cmax(ans, int(wf.distance(i, j)));
    }
    cout << ans + 1 << endl;

}


Measured memory_bytes: 3932
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int a, b, c, x = 1;
    sc(a) sc(b) sc(c)
    bool check = false;
    for (int i = 1; i <= b; i++){
        if (a * i % b == c) check = true;
    }
    if (check) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>> R(M);
	vec(P)
	fx(M) {
		int k;
		cin >> k;
		fy(k) {
			vecp(R.at(x))
		}
	}
	fx(M) {
		vecp(P)
	}
	vector<int> S(M);
	ll ans = 0;
	fx(1<<N) {

		fy(N) {
			if (((x>>y)&1)==1) {      // y番目のスイッチがついてる
				fz(M) {
					fw(R.at(z).size()) {
						if (R.at(z).at(w) == y+1) {
							S.at(z)++;
							break;
						}
					}
				}
			}
		}
		bool flag = true;
		fy(M) {
		//	ce(S.at(y))
			if (S.at(y) % 2 != P.at(y)) {
				flag = false;
				break;
			}
		}
		if (flag) {
			ans++;
		}

		fx(M) {
			S.at(x) = 0;
		}
	}

	ce(ans)
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<cstring>
#include<map>
#include<sstream>
 
using namespace std;
 
int main(){
 
long H;
  
cin>>H;
    
long long count = 1;
long long x = 1;
  
  while(H != 1){
  H /= 2;
  count += pow(2, x);
  x++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <stdio.h>
using namespace std;
int main() {
    string W, T;
    cin >> W;
    transform (W.begin(), W.end(), W.begin(), ::tolower);
    int cnt = 0;
    while(cin >> T, T != "END_OF_TEXT"){
        transform (T.begin(), T.end(), T.begin(), ::tolower);
        if(W == T){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num):>, lower_bound(A, A+N, num):>=
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>	// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>		// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>	// push(x), front(), pop()
#include <deque>
#include <stack>	// push(x), top(), pop()
#include <map>		// M[key],  insert(key, val), erase(key), find(key), 
#include <set>		// insert(key), erase(key), find(key)

using namespace std;
typedef long long ll;
// typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007

int a[20000], b[20000];

void solve() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		a[i] = 20001 + 20000 * i;
		b[n - 1 - i] = 20001 + 20000 * i;
	}
	for (int i = 0; i < n; i++) {
		int p; cin >> p;
		p--;
		b[p] += i;
	}
	for (int i = 0; i < n-1; i++) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl;

	for (int i = 0; i < n - 1; i++) {
		cout << b[i] << " ";
	}
	cout << b[n - 1] << endl;
}

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

Measured memory_bytes: 768
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;


int main(){
  ll x;cin>>x;
  if(x>=30)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}



Measured memory_bytes: 3636
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
def ggcd(a,b):
    if(b==0):
        return a
    return ggcd(b,a%b)
import math
import fractions
import collections
import itertools
import pprint
N=int(input())
l1=[]
adivb=[]
bis0=0
bdiva=[]
ais0=0
both0=0
p=10**9+7
fish=[list(map(int,input().split())) for _ in range(N)]
fishcomp=[]
d={}
for i in range(N):
    a=fish[i][0]
    b=fish[i][1]
    g=ggcd(abs(a),abs(b))
    if g!=0:
        a=a//g
        b=b//g
    if (b==0)and(a>0):
        a=1
    elif b<0:
        a=-a
        b=-b
    if (a!=0)or(b!=0):
        if d.get(a)==None:
            d[a]={}
            d[a][b]=1
        else:
            if d[a].get(b)==None:
                d[a][b]=1
            else:
                val=d[a].get(b)
                d[a][b]=val+1
        fishcomp.append([a, b])
    else:
        both0=both0+1
#print(d)
#print(fishcomp)
fishcomp=list(map(list,set(map(tuple,fishcomp))))
#print(fishcomp)
length=N-both0
sets=[]
for i in fishcomp:
    a=i[0]
    b=i[1]
    val1=d[a][b]
    #print(a,b,val1)
    if d.get(-b)!=None:
        if d[-b].get(a)!=None:
            val2=d[-b][a]
            sets.append([val1,val2])
            length=length-(val2+val1)
#print(sets,length)
pro=1
for i in sets:
    pro=(pro*(pow(2,i[0],p)+pow(2,i[1],p)-1))%p
#print(pro)
print((pow(2,length,p)*pro-1+both0)%p)

Measured memory_bytes: 227356
import java.util.Random;
import java.util.Scanner;

public class Main {
    static int d = 365;
    static int[] c = new int[26];
    static int[][] s = new int[d][26];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random random = new Random();
        sc.nextInt();
        for (int i=0;i<26;i++){
            c[i]=sc.nextInt();
        }
        for (int i=0;i<d;i++){
            for (int j=0;j<26;j++){
                s[i][j]=sc.nextInt();
            }
        }
        int[] contest = new int[d];
        int count = 100000;
        for (int i=0;i<d;i++)contest[i]=random.nextInt(26);
        for (int i=0;i<count;i++){
            int[] instance = contest.clone();
            int times = 1;
            int[] choose = new int[times];
            for (int j=0;j<times;j++)choose[j]=random.nextInt(d);
            for (int j=0;j<times;j++)instance[choose[j]]=random.nextInt(26);
            if (function(contest)<function(instance))contest=instance;
        }
        for (int i=0;i<d;i++)System.out.println(contest[i]+1);
    }
    static long function(int[] contest){
        long satisfaction = 0;
        int[] interval = new int[26];
        for (int i=0;i<d;i++){
            satisfaction+=s[i][contest[i]];
            for (int j=0;j<26;j++)interval[j]++;
            interval[contest[i]]=0;
            for (int j=0;j<26;j++)satisfaction-=c[j]*interval[j];
        }
        return  satisfaction;
    }
}


Measured memory_bytes: 57392
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


if __name__ == '__main__':
    r = int(input())
    ans = 2 * r * math.pi
    #print('ans') # debug
    print(ans)

    #print('\33[32m' + 'end' + '\033[0m') # debug


Measured memory_bytes: 68684
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int A, B;
	scanf("%d %d", &A, &B);
	
	int i, j, c[41][101] = {};
	for (i = 0; i < 40; i++) {
		for (j = 0; j < 100; j++) c[i][j] = i / 20;
	}
	for (i = 0, j = 0, A--; A > 0; A--) {
		c[i][j] = 1;
		j += 2;
		if (j >= 100) {
			j = 0;
			i += 2;
		}
	}
	for (i = 21, j = 0, B--; B > 0; B--) {
		c[i][j] = 0;
		j += 2;
		if (j >= 100) {
			j = 0;
			i += 2;
		}
	}
	
	printf("40 100\n");
	for (i = 0; i < 40; i++) {
		for (j = 0; j < 100; j++) printf("%c", (c[i][j] == 0)? '#': '.');
		printf("\n");
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;
    cin >> H >> W;
    vvec<char> F(H,vec<char>(W));
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin >> F[i][j];
    vec<int> dx = {-1,0,1,0},dy = {0,-1,0,1};
    auto in = [&](int x,int y){
        return 0<=x && x<H && 0<=y && y<W;
    };
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) if(F[i][j]=='#'){
        bool ok = false;
        for(int k=0;k<4;k++){
            int nx = i+dx[k],ny = j+dy[k];
            if(!in(nx,ny)) continue;
            ok |= F[nx][ny]=='#';
        }
        if(!ok){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef long long ll;
#define int ll
typedef pair<int,int> PP;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define Endl endl

int diff(PP Y){
    return Y.first-Y.second;
}

signed main(void){
    int N,E;
    const int MEM = 114514;
    int x[MEM],v[MEM];
    cin >> N >> E;
    REP(i,N){
        cin >> x[i] >> v[i];
    }
    PP A[MEM],B[MEM],C[MEM],D[MEM];
    
    A[0]={0,0};
    for(int i=1;i<=N;i++){
        A[i]={A[i-1].first+v[i-1],x[i-1]};
    }
    B[N]={0,0};
    RREP(i,N){
        B[i]={B[i+1].first+v[i],E-x[i]};
    }
    
    C[0]=A[0];
    for(int i=1;i<=N;i++){
        if(diff(C[i-1])<diff(A[i])){
            C[i]=A[i];
        }else{
            C[i]=C[i-1];
        }
    }
    
    D[N]=B[N];
    RREP(i,N){
        if(diff(D[i+1])<diff(B[i])){
            D[i]=B[i];
        }else{
            D[i]=D[i+1];
        }
    }
    int Ans=max(diff(C[N]),diff(D[0]));
    /*
    REP(i,N+1){cout << A[i].first << " ";}cout << endl;
    REP(i,N+1){cout << A[i].second << " ";}cout << endl<<endl;
    REP(i,N+1){cout << B[i].first << " ";}cout << endl;
    REP(i,N+1){cout << B[i].second << " ";}cout << endl<<endl;
    REP(i,N+1){cout << C[i].first << " ";}cout << endl;
    REP(i,N+1){cout << C[i].second << " ";}cout << endl<<endl;
    REP(i,N+1){cout << D[i].first << " ";}cout << endl;
    REP(i,N+1){cout << D[i].second << " ";}cout << endl<<endl;
    */
    
    
    REP(i,N+1){
        Ans=max(Ans,diff(C[i])+diff(D[i])-min(C[i].second,D[i].second));
    }
    
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
vector<vector<char>> field;
vector<vector<char>> field2;

int bfs(int N,int M,int sx,int sy,int gx, int gy);
int res = 0;
int main(){ 
    int N,M;
   
    cin >> N;
    cin >> M;
	field.resize(N,vector<char>(M));
    field2.resize(N,vector<char>(M));
    int res = 0;
    int sx,sy,gx,gy;
    for (int i = 0;i < N;i++){
        for (int j = 0;j < M;j++){
            cin >> field.at(i).at(j); 
			if (field[i][j] == '.'){
				field2[i][j] = '#';
			}
			else{
				field2[i][j] = '.';
			}
        } 
    }
	int ans = 0;
	
    ans += bfs(N,M,0,0,N - 1,M - 1);
    cout << ans << endl;
}

int bfs(int N,int M,int sx,int sy,int gx, int gy){
    int dx[2] = {1,0}, dy[2] = {0,1};
    P d[N][M];//距離の配列
    for (int i = 0;i < N;i++){
        for (int j = 0;j < M;j++){
            d[i][j] = mp(INF,0);//初期化
        }
    }
    queue<P> que;
    que.push(P(sx,sy));
	if (field[0][0] == '#'){
		d[sx][sy] = mp(1,1);
	}
	else{
		d[sx][sy] = mp(0,0);
	}

    //キューが空になるまでループ
    while(que.size()){
        P p = que.front();
        que.pop();//先頭を取り出す
        if (p.fs == gx && p.sc == gy){
            break;//探索終わり
        }
        for (int i = 0;i < 2;i++){
            int nx = p.fs + dx[i], ny = p.sc + dy[i];
            //nx,nyが進めるマスか、行ったことのないマスかどうかを判定
            if (0 <= nx && nx < N && 0 <= ny && ny < M){
				if (d[p.fs][p.sc].sc == 0){
					if (field[nx][ny] == '#'){
						if (d[nx][ny].fs>d[p.fs][p.sc].fs+ 1){
							que.push(P(nx,ny));//追加
							d[nx][ny] = mp(d[p.fs][p.sc].fs + 1,1);//距離を確定 
						}
					}
					else{
						if (d[nx][ny].fs >d[p.fs][p.sc].fs){
							que.push(P(nx,ny));//追加
							d[nx][ny] = mp(d[p.fs][p.sc].fs,0);//距離を確定 
						}
					}
				}
				else{
					if (field[nx][ny] == '.'){
						if (d[nx][ny].fs>d[p.fs][p.sc].fs){
							que.push(P(nx,ny));//追加
							d[nx][ny] = mp(d[p.fs][p.sc].fs,0);//距離を確定 
						}
					}
					else{
						if (d[nx][ny].fs >d[p.fs][p.sc].fs){
							que.push(P(nx,ny));//追加
							d[nx][ny] = mp(d[p.fs][p.sc].fs,1);//距離を確定 
						}
					}
				}		
				     
       		}
		}
    }
	// for(int i = 0; i < N; i++) {
	// 	for(int j = 0; j < M; j++) {
	// 		cout << d[i][j].fs << " ";
	// 	}
	// 	cout << endl;
	// }
    return d[gx][gy].fs;
}


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


int main() {
  string s;
  cin >> s;
  replace(s.begin(), s.end(), ',', ' ');
    
  cout << s << endl;  
  return 0;
  
}

Measured memory_bytes: 256
using namespace std;
#include<iostream>;
int main(){
int N,b,ans;
b=1;
ans=0;
cin>>N;
int a[N];
for(int i=0;i<N;i++){
cin>>a[i]; 
if(a[i]!=b){ans++;}else{b++;}
}
if(ans==N){ans=-1;}
cout<<ans;


}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  ll n;cin>>n;
  ll a[n+10];
  ll sum=0;
  rep(i,0,n){
    cin>>a[i];
    sum+=a[i];
  }

  ll lsum=0;ll mi=1e18;
  rep(i,0,n-1){
    lsum+=a[i];
    mi=min(mi,abs(2*lsum-sum));
  }
  out(mi);




  return 0;
}


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

#define INF (1 << 30)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    int point[N];
    rep(i, N){
        point[i] = 0;
    }
    int tmp;
    rep(i, Q){
        cin >> tmp;
        point[tmp-1]++;
    }
    rep(i, N){
        if(K - (Q - point[i]) <= 0){
            out("No");
        }else{
            out("Yes");
        }
    }
    return 0;
}

Measured memory_bytes: 1024
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    s=S()
    num=[0]*len(s)
    R=True
    rle=[]
    cnt=0
    for i in range(len(s)):
        if R and s[i]=='R':
            if cnt!=0: rle.append(cnt)
            cnt=0
            R=False
            rle.append('R')
        elif not R and s[i]=='L':
            rle.append(cnt)
            cnt=0
            R=True
            rle.append('L')
        cnt+=1
    rle.append(cnt)
    #print(rle)
    R=True
    i=0
    index=0
    while i<len(rle):
        if R:
            R=False
            i+=1
            n=""
            while rle[i]!='L':
                n+=str(rle[i])
                i+=1
            n=int(n)
            odd=(n-1)//2+(n-1)%2
            eve=(n-1)//2+1
            num[index+(n-1)]+=eve #R
            num[index+n]+=odd #L
            index+=n#move to L's index
            
        else:
            R=True
            i+=1
            n=""
            while i<len(rle) and rle[i]!='R':
                n+=str(rle[i])
                i+=1
            n=int(n)
            odd=(n-1)//2+(n-1)%2
            eve=(n-1)//2+1
            num[index-1]+=odd #R
            num[index]+=eve #L
            index+=n#move to R's index
        
        #print(num)
    
    for i in range(len(num)):
        print(num[i],end=" ")
    print()

if __name__=='__main__':
    main()

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, m) cin >> b[i];

    int ans = 0;
    rep(i, n) {
        vector<int> a(m);
        rep(i, m) cin >> a[i];
        int sum = c;
        rep(i, m) {
            sum += a[i]*b[i];
        }
        if (sum>0) ans++;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
# n = 3
# k = 2
#
# def binom(m, n)
#   res = 1
#   (1..n).each do |i|
#     res = res * (m - i + 1) / i
#   end
#   return res
# end
#
# def multi_choose(m, n)
#   binom(m + n - 1, n)
# end

if (k % 2 == 0)
  # kの倍数の個数
  multiple_k = n / k
  a = multiple_k**3
  # mod kで k/2 になる数の個数
  middle_mod = (n + k/2) / k
  b = middle_mod**3

  puts a + b
else
  # kの倍数の個数
  multiple_k = n / k
  puts multiple_k**3
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n, k;
    cin >> n >> k;
    if (n%k != 0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int[] pasta = new int[3];
		int[] juice = new int[2];
		int i, k;
		int min;
		Scanner sc = new Scanner(System.in);
		for(i=0; i<pasta.length; i++){
			pasta[i] = sc.nextInt();
		}
		for(i=0; i<2; i++){
			juice[i] = sc.nextInt();
		}
		min = pasta[0] + juice[0] - 50;
		for(i=0; i<3; i++){
			for(k=0; k<2; k++){
				if(min > pasta[i] + juice[k] - 50){
					min = pasta[i] + juice[k] - 50;
				}
			}
		}
		System.out.println(min);

	}

}

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

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
int n;
int a[maxn], b[maxn];

void input() {
cin>>n;
}

void solve() {

    if(n>=30)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}




int main() {
    std::ios::sync_with_stdio(false);
    int test = 1;
    while (test--) {
        input();
        solve();
    }
    return 0;
}


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

typedef pair<int, int> II;
typedef vector< II > VII;
typedef vector<int> VI;

#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ll long long
#define fr(i,n) for(i=0;i<n;i++)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,k,cnt=0,i;
    cin>>n>>k;
    if(k==0)
        cout<<n*n<<endl;
    else
    {
        for(i=k+1;i<=n;i++)
        {
            cnt+=((n/i)*(i-k));
            cnt+=max((ll)0,(n%i)-k+1);
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);

	//0501
	static class DataConversion {
		HashMap<String, String> map;
		void convert() {
			for(;;) {
				int n = Integer.parseInt(sc.nextLine());
				if(n==0) break;
				map = new HashMap<String, String>();
				for(int i=0; i<n; i++) {
					String[] str = sc.nextLine().split(" ");
					//System.out.println(str[0] + ":" + str[1]);
					map.put(str[0], str[1]);
				}
				int m = Integer.parseInt(sc.nextLine());
				StringBuilder sb = new StringBuilder();
				for(int i=0; i<m; i++) {
					String c = sc.nextLine();
					if(map.get(c) == null) sb.append(c);
					else sb.append(map.get(c));
				}
				System.out.println(new String(sb));
			}
		}
	}

	public static void main(String[] args) {
		DataConversion dc = new DataConversion();
		dc.convert();
	}
}

Measured memory_bytes: 13000
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())

if(A<=B and A+V*T>=B+W*T):
  print("YES")
elif(A>=B and A-V*T<=B-W*T):
  print("YES")
else:
  print("NO")

Measured memory_bytes: 9188
def solve
  n = gets.to_i
  a = []
  n.times do |i|
    if (i+1) % 15 != 0 and (i+1) % 3 != 0 and (i+1) % 5 != 0
      a.push(i+1)
    end
  end

  print a.sum
end
solve



Measured memory_bytes: 18512
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

bool bi = true;

void dfs(const vv<int>& graph, vector<int>& depth, int v, int p) {
    if (p != -1) depth[v] = depth[p] + 1;

    for (int u : graph[v]) {
        if (u == p) continue;
        else if (depth[u] != -1) {
            if (depth[u] % 2 == depth[v] % 2) {
                bi = false;
            }
        }
        else {
            dfs(graph, depth, u, v);
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vv<int> graph(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> depth(N, -1);
    depth[0] = 0;
    dfs(graph, depth, 0, -1);

    if (bi) {
        int n = 0;
        rep(i, N) n += depth[i] % 2;
        write((ll)n * (N - n) - M);
    }
    else {
        write((ll)N * (N - 1) / 2 - M);
    }
}

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

#define DB	double
#define lf	else if
#define	I64	long long
#define Rd()	(rand() << 15 | rand())
#define For(i,a,b)	for(int i=a;i<=b;i++)
#define Rep(i,a,b)	for(int i=a;i>=b;i--)
	
#define fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

#define CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for (; CH < '0' || ch > '9';)	f= (ch == '-');
		for (; ch >= '0' && ch <= '9'; CH)	(x*= 10)+= ch - '0';
		return	f ? -x : x;
}

int		A, B, C, X,ans;

int		main()	{
		scanf("%d%d%d%d", &A, &B, &C, &X);
		
		For(i, 0, A)	For(j, 0, B)	For(k, 0, C)
			if	(i * 500 + j * 100 + k * 50 == X)	ans++;
		
		cout << ans<<endl;
	
	
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

signed main(){
	int n;
	cin>>n;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	vector<ll>idx(n);//順列Pに含まれる数字がどの位置にあるか
	rep(i,n){
		a[i]--;
		idx[a[i]]=i+1;//0オリジン
	}
	multiset<ll>s;//multisetでないと0を2回、nを2回挿入出来ない
	s.emplace(n+1);s.emplace(n+1);
	s.emplace(0);s.emplace(0);//番兵2個ずつ(p=nのときにはみ出すから)
	ll ans=0;
	for(int p=n-1;p>=0;--p){
		auto right=s.upper_bound(idx[p]);
		auto left=right;
		left--;
		ans+=(p+1)*((*next(right)-*right)*(idx[p]-*left)+(*left-*prev(left))*(*right-idx[p]));
		s.emplace(idx[p]);//大きい方から見ていってmultisetに追加すれば自分より大きいものがどこにいるかわかる
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>

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

    std::vector<int> no_sums = {1, 2, 3, 5, 6, 9, 10, 13, 17};
    if (std::find(no_sums.begin(), no_sums.end(), N) != no_sums.end()) {
        std::cout << "No" << std::endl;;
    } else {
        std::cout << "Yes" << std::endl;
    }
}


Measured memory_bytes: 256
gets
cards = gets.split

def bubble_sort(cards)
	(cards.size - 1).times do |i|
		(cards.size - 1).downto(i + 1) do |j|
			if cards[j][1] < cards[j - 1][1]
				cards[j - 1], cards[j] = cards[j], cards[j - 1]
			end
		end
	end

	return cards
end
bubble_sorted = bubble_sort(cards.dup)
puts bubble_sorted.join(' ')
puts 'Stable'

def selection(cards)
	cards.size.times do |i|
		mini = i
		(i + 1).upto(cards.size - 1) do |j|
			mini = j if cards[j][1] < cards[mini][1]
		end

		if i != mini
			cards[i], cards[mini] = cards[mini], cards[i]
		end
	end

	return cards
end
selection_sorted = selection(cards)
puts selection_sorted.join(' ')
puts bubble_sorted == selection_sorted ? 'Stable' : 'Not stable'



Measured memory_bytes: 6880
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


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

    int N;
    cin >> N;

    bool possible = false;
    for(int i = 0; 7 * i <= N; i++){
        if((N-7 * i) % 4 == 0){
            possible = true;
        }
    }

    if(possible){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
//Contest with Drinks Easy

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
const int inf = 2147483647;

int main (){
    int n,m;cin>>n;
    vector<int>t(n),tt;
    rep(i,0,n)cin>>t[i];
    cin>>m;
    rep(i,0,m){
        int p,x;cin>>p>>x;
        tt=t;
        tt[p-1]=x;
        cout << accumulate(range(tt),0LL) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, K, Q = map(int, input().split())
member = [K] * N
flag = False

for i in range(0, Q):
    n = int(input())
    member[n-1] = member[n-1] + 1

for j in range(0, N):
    member[j] = member[j] - Q
    if member[j] <= 0:
        print("No")
    else:
        print("Yes")


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

LLi gcd(LLi a, LLi b) {
	if(a<0) a=b;
	if(b<0) b=a;
    if (b == 0) return a;
    return gcd(b, a%b);
}

LLi lcm(LLi a, LLi b) {
    return a/gcd(a, b)*b;
}

int main(){

	LLi n, m, tmp;
	cin>> n >> m;
  
  	rep(i, n-1){
      cin>> tmp;
      m=lcm(m, tmp);
    }
     
  	cout<< m <<endl;
  
  	return 0;
}

Measured memory_bytes: 256
/*
[agc026] C - String Coloring
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef pair<string, string> pss;

int N;
string S;

ll solve() {
    string s[2];
    map<pss, ll> m[2];
    s[0] = string(S.begin(), S.begin() + N);
    s[1] = string(S.rbegin(), S.rbegin() + N);

    for (int k = 0; k < 2; k++) {
        for (ll b = 0; b < (1LL << N); b++) {
            pss key;
            for (int i = 0; i < N; i++) {
                if (b & (1LL << i)) {
                    key.first.push_back(s[k][i]);
                } else {
                    key.second.push_back(s[k][i]);
                }
            }
            m[k][key]++;
        }
    }

    ll ans = 0;
    for (auto& kv : m[0]) {
        pss key = kv.first;
        ll val = kv.second;
        ans += val * m[1][key];
    }

    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 108288