akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
D - Decayed Bridges
https://atcoder.jp/contests/abc120/tasks/abc120_d#
AC
"""
import sys

class DisjointSet(object):
    def __init__(self, n):
        self.rank = [0] * n
        self.p = list(range(n))
        self.size = [1] * n

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.size[self.p[x]] += self.size[self.p[y]]
            self.p[y] = self.findSet(x)
        else:
            self.size[self.p[y]] += self.size[self.p[x]]
            self.p[x] = self.findSet(y)
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]


def solve(bridges, N, M):
    ans = [(N**2 - N)//2]
    d = DisjointSet(N+1)
    for f, t in reversed(bridges):
        if d.same(f, t):
            ans.append(ans[-1])
        else:
            n1 = d.size[d.p[f]]
            n2 = d.size[d.p[t]]
            ans.append(ans[-1] - (n1*n2))
            d.unite(f, t)
    return ans


def main(args):
    N, M = map(int, input().split())
    bridges = []
    for _ in range(M):
        f, t = map(int, input().split())
        bridges.append([f, t])
    ans = solve(bridges, N, M)

    for a in (ans[::-1])[1:]:
        print(a)


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


Measured memory_bytes: 27188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 

// void chmod(ll &M){
//     if(M >= mod) M %= mod;
//     else if(M < 0){
//         M += (abs(M)/mod + 1)*mod;
//         M %= mod;
//     }
// }

const int MAX = 1000005;
const int mod = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
 
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}


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

    ll n, k; cin >> n >> k;
    COMinit();


    vector<ll> ans(k+1, 0);
    for(int i=1; i<=k; ++i){
        if(n-k-i+1 < 0) ans[i] = 0;
        else{
            ans[i] = COM(k-1, i-1)*COM(n-k+1, i)%mod;
        }
    }

    for(int i=1; i<=k; ++i) cout << ans[i] << endl;
    

    return 0;
}

Measured memory_bytes: 23680
// finish date: 2018/03/04

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N;
    cin>>N;
    cout<<N/3<<endl;


    return 0;
}





Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;

int main() {
	string s, t; cin >> s >> t;

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

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

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	char c;
	cin >> c;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')cout << "vowel";
	else cout << "consonant";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

int MOD = 1000000007;

signed main(){

    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];

    vector<ll> ans(k+1);
    for(int i = 0;i <= k;i++){
        rep(j,n){
            if(i-a[j] >= 0 && ans[i-a[j]] == 0)ans[i] = 1;
        }
    }
    if(ans[k] == 1)cout << "First" << endl;
    else cout << "Second" << endl;
    // rep(i,k+1){
    //     cerr << i << " " << ans[i] << endl;
    // }


    
      
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://dp.contest.atcoder.jp/tasks/dp_f

Measured memory_bytes: 1024
using System;

public class Test
{
	public static void Main()
	{
            string[] data;
            int ans = 0;
            
            while (true)
            {
                data = Console.ReadLine().Split();
                switch (data[1])
                {
                    case "+":
                        ans = int.Parse(data[0]) + int.Parse(data[2]);
                        break;

                    case "-":
                        ans = int.Parse(data[0]) - int.Parse(data[2]);
                        break;

                    case "*":
                        ans = int.Parse(data[0]) * int.Parse(data[2]);
                        break;

                    case "/":
                        ans = int.Parse(data[0]) / int.Parse(data[2]);
                        break;
                }

                if (data[1] == "?")
                {
                    break;
                }
                else
                {
                    Console.WriteLine(ans);
                }
            }
	}
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<int> cnt(N, 1), can(N);
  can[0] = true;
  for(int i=0,fr,to;i<M;++i){
    cin >> fr >> to;
    --fr, --to;
    if (can[fr]) 
      can[to] = true;
    ++cnt[to];
    if(--cnt[fr] == 0){      
      can[fr] = false;
    }
  }
  cout << count(can.begin(), can.end(), true) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <set>

using namespace std;

int a[100000];
int b[100000];

bool check(set <int> &s, int x) {
    int y, z;
    
    if (s.size() != 3) return true;
    
    s.erase(x);
    y = *s.begin();
    z = *s.rbegin();
    s.insert(x);
    
    if (a[y] == z && a[z] == y) return false;
    
    return true;
}

int main() {
    int n, i;
    vector <int> v;
    set <int> s;
    set <pair<int, int>> s2;
    set <int>::iterator it;
    
    scanf("%d", &n);
    
    if (n == 2) {
        puts("-1");
        
        return 0;
    }
    
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        
        a[i]--;
        b[a[i]]++;
    }
    
    for (i = 0; i < n; i++) s.insert(i);
    for (i = 0; i < n; i++) s2.insert(make_pair(b[i], i));
    
    for (i = 0; i < n; i++) {
        int x;
        
        if (s2.size() > 0 && s2.rbegin()->first == n - i - 1) {
            x = s2.rbegin()->second;
        } else {
            for (it = s.begin(); it != s.end(); it++) {
                if (i > 0 && a[v.back()] == *it) continue;
                if (!check(s, *it)) continue;
                x = *it;
                break;
            }
            
            if (it == s.end()) {
                puts("-1");
                
                return 0;
            }
        }
        
        v.push_back(x);
        s.erase(x);
        s2.erase(make_pair(b[x], x));
        s2.erase(make_pair(b[a[x]], a[x]));
        b[a[x]]--;
        if (b[a[x]] > 0 && s.count(a[x])) s2.insert(make_pair(b[a[x]], a[x]));
    }
    
    for (i = 0; i < n; i++) {
        if (i > 0) putchar(' ');
        printf("%d", v[i] + 1);
    }
    puts("");
    
    return 0;
}


Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long s,i=1;
    map<long long ,long long>x;
    cin>>s;
    x[s]++;
    while(1)
    {
        if(s%2==0)
            s/=2;
        else
            s=((3*s)+1);
        x[s]++;
        if(x[s]==2)
        {
            break;
        }
        i++;
    }
    cout<<i+1<<endl;
}



Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

#1000000000000001
alpha = 'abcdefghijklmnopqrstuvwxyz'
n = ii()
tmp = n
ans = ''
while tmp > 26:
    ans += alpha[tmp%26-1]
    if tmp%26 == 0:
        tmp //= 26
        tmp -= 1
    else:
        tmp //= 26
#    print(ans,tmp)

ans += alpha[tmp%26-1]
print(ans[::-1])

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

int main() {
	static int N, X, A[200000], B[200000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X;
		A[i] = X, B[i] = X;
	}
	sort(B, B + N);
	int median = B[N / 2];
	for (int i = 0; i < N; i++) {
		if (A[i] < median) cout << median;
		else cout << B[N / 2 - 1];
		cout << endl;
	}
}

Measured memory_bytes: 3712
n = int(input())

# AC_count = 0
# WA_count = 0
# TLE_count = 0
# RE_count = 0

d = {key:0 for key in ["AC", "WA", "TLE", "RE"]}
for _ in range(n):
    s = input()
    # print(s)
    
    d[s] += 1

print(f"AC x {d['AC']}")
print(f"WA x {d['WA']}")
print(f"TLE x {d['TLE']}")
print(f"RE x {d['RE']}")


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> vec(M);
  
  for(int i = 0;i < M;i++){
    int k;
    cin >> k;
    vec[i].resize(k);
    for(int j = 0;j < k;j++){
      cin >> vec[i][j];
      vec[i][j]--;
    }
  }
  
  vector<int> p(M);
  for(int i =0;i < M;i++){
    cin >> p[i];
  }
  
  int ans = 0;
  
  for(int i = 0;i < (1 << N);i++){
    bool ok = true;
    for(int j = 0;j < M;j++){
      int cnt = 0;
      for(int id : vec[j]){
        if((i >> id) & 1){
          cnt++;
        }
      }
      if(cnt % 2 != p[j]){
        ok = false;
      }
    }
    if(ok){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
// E - Sequence Sum
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main(){
	ll n; int x, m; cin>>n>>x>>m;
	vector<int> X(m, -1);
	vector<int> P;
	ll sum_p = 0;
	while(X[x] < 0){ // preset
		X[x] = P.size(); // pre length
		P.push_back(sum_p); // pre sum_p
		sum_p += x; // now sum_p
		x = (ll)x*x % m;
	}
	int nxt_len = (n - X[x]) % (P.size() - X[x]);
	ll cyc_times = (n - X[x]) / (P.size() - X[x]);
	ll cyc = (sum_p - P[X[x]]) * cyc_times;
	ll remain = P[X[x] + nxt_len];
	cout<< cyc + remain <<endl;
}


Measured memory_bytes: 4016
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String args[]){
        
        int ans = 0;
	int dif = 0;
	int min = 753;
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

	for (int i = 0; i <= s.length()-3; i++) {
	    dif = Math.abs(753 -
			   Integer.parseInt(s.substring(i, i+3)));
	    if(dif < min){
		min = dif;
	    }
	}

	ans = min;
	    
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> L;
  REP(i,N){
    ll a;
    cin>>a;
    L.PB(a);
  }
  SORT(L);
  
  ll ans=0;
  REP(i,K) ans+=L[i];
  co(ans);
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
vector<ll> A;

int main() {
	cin >> N;
	A.resize(N);
	ll asum = 0;
	for (ll n = 0; n < N; n++) {
		ll a, b;
		cin >> a >> b;
		asum += a;
		A[n] = a + b;
	}
	sort(A.begin(), A.end(), [](ll a, ll b) {return a > b; });
	for (ll n = 1; n < N; n += 2) {
		asum -= A[n];
	}
	cout << asum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  long long int ans=0,n,a[200005],k,i;
  cin >> n >> k;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n,greater<int>());
  for(i=k;i<n;i++){
    ans=ans+a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
s = list(input())

flg = 0

for i in range(len(s)):
    if i % 2 ==1:
        if str(s[i]) == "R":
            flg = 1
    else:
        if str(s[i]) == "L":
            flg = 1

if flg == 0:
    print("Yes")
else:
    print("No")



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

int main() {
    string S;
    cin >> S;
    int maxLen = 0;
    for (int i = 0; i < S.size(); i++) {
        int len = 0;
        for (int w = i; i + w < S.size(); w++) {
             char c = S[i + w];
             if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
                 len += 1;
             }
             else {
                 maxLen = max(len, maxLen);
                 len = 0;
             }
        }
        maxLen = max(len, maxLen);
    }
    cout << maxLen << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 10000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main() 
{ 
    fastio
    string s;
    cin>>s;
    int n = s.length();
    string s2 = s;
    reverse(s2.begin(), s2.end());
    if(s != s2)
    {
        cout<<"No"<<endl;
        return 0;
    }

    string s3 = string(s.begin(), s.begin() + (n-1)/2);
    string s4 = s3;
    reverse(all(s4));

    if(s4 != s3)
    {
        cout<<"No"<<endl;
        return 0;
    }

    string s5 = string(s.begin()+(n+3)/2-1, s.end());
    string s6 = s5;
    reverse(all(s6));

    if(s6 != s5)
    {
        cout<<"No"<<endl;
        return 0;
    }

    cout<<"Yes"<<endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S, T, U; int A, B; 
	cin >> S >> T >> A >> B >> U; 
	if(S == U) cout << A-1 << " " << B << endl; 
	else cout << A << " " << B-1 << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), ans(n);
    rep(i, 0, n){
        cin >> a[i];
        a[i]--;
        ans[a[i]] = i + 1;
    }
    for(int ii = 0; ii < ans.size(); ii++){
        if(ii) cout << ' ';
        cout << ans[ii];
    }
    cout << endl;
}

Measured memory_bytes: 2432
import queue
n,m = map(int,input().split())
load = [list() for _ in range(n)]
ans = [None]*n
q = queue.Queue()
q.put(0)

for i in range(m):
    tmpa, tmpb = map(int,input().split())
    tmpa, tmpb = tmpa-1, tmpb-1
    load[tmpa].append(tmpb)
    load[tmpb].append(tmpa)

while not q.empty():
    log = q.get()
    for i in load[log]:
        if ans[i] is None:
            ans[i] = log
            q.put(i)

for i in range(n):
    if i==0 and ans[i]is None:
        print('No')
        break
    elif i==0:
        print('Yes')
    else:
        print(ans[i]+1)

Measured memory_bytes: 34368
#include<bits/stdc++.h>
using namespace std;
string s;
bool a=false,b=false;
int main()
{
    cin>>s;
    for(int i=0;i<s.size();i++)
        if(s[i]=='C')
            a=true;
        else
            if(s[i]=='F'&&a)
                b=true;
    if(b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] list = str.split(" ");

		if(list[0].equals("H")){
			if(list[1].equals("H")){
				System.out.println("H");
			}else{
				System.out.println("D");
			}
		}else{
			if(list[1].equals("H")){
				System.out.println("D");
			}else{
				System.out.println("H");
			}
		}

	}

}


Measured memory_bytes: 20564
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;
typedef pair<int, int> pii;

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N);
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a --;
        b --;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    queue<int> q;
    vector<int> colors(N, -1);
    q.push(0);
    colors[0] = 0;

    bool  bi = true;

    while(! q.empty()){
        int p = q.front();
        q.pop();
        rep(i, g[p].size()){
            int v = g[p][i];
            if(colors[p] == colors[v]){
                bi = false;
                break;
            }
            if(colors[v] != -1){
                continue;
            }
            colors[v] = 1 - colors[p];
            q.push(v);
        }
        if(bi == false){
            break;
        }
    }
    ll ans = (ll) (N - 1) * (N) / 2 - M;
    if(bi){
        ll tmp = 0;
        rep(i, colors.size()){
            tmp += colors[i];
        }
        ans = tmp * (N - tmp) - M;
    }
    cout << ans << endl;

}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=998244353;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

using BS = bitset<4000>;

int N;
string X;
LL pw2[4010];
BS bases[4010];
vector<BS> A;

void Add(LL &t, LL v) {
  t += v;
  while (t >= MOD) t -= MOD;
}

BS MakeBitset(string &s) {
  BS ret;
  int idx = 3999;
  rrep(i, s.size()) {
    if (s[i] == '1') ret[idx] = 1;
    else if (s[i] == '0') ret[idx] = 0;
    else assert(0);
    idx--;
  }
  return ret;
}

int RegBase(BS &v) {
  while (1) {
    int idx = v._Find_first();
    if (idx == v.size()) {
      assert(v.count() == 0);
      return -1;
    }

    if (bases[idx].count() == 0) {
      bases[idx] = v;
      return idx;
    }

    v ^= bases[idx];
    assert(v._Find_first() > idx);
  }
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  
  cin >> N >> X;
  rep(i, N) {
    string s;
    cin >> s;
    A.eb(MakeBitset(s));
  }
  //sort(all(A), [](const BS &a, const BS &b) {
  //  return a._Find_first() < b._Find_first();
  //});
  //while (!A.empty() && !A.back().count()) A.pop_back();
  //reverse(all(A));

  //if (A.empty()) {
  //  cout << "1\n";
  //  return 0;
  //}

  int idx = A[0]._Find_first();
  BS v = A[0];
  while (1) {
    int res = RegBase(v);
    assert(res == idx);
    if (res == -1) break;
    v = bases[res] >> 1;
    if (idx == 0) break;
    idx--;
  }

  reps(i, 1, N) {
    v = A[i];
    idx = A[i]._Find_first();
    while (1) {
      int res = RegBase(v);
      if (res == -1) break;
      v = bases[res] >> 1;
    }
  }

  int m = 0;
  pw2[0] = 1;
  rep(i, 4000) {
    if (bases[i].count()) m++;
    if (i > 0) {
      Add(pw2[i], pw2[i-1]);
      Add(pw2[i], pw2[i-1]);
    }
  }

  X = string(4000-X.size(), '0') + X;
  assert(X.size() == 4000);

  BS cur;
  LL ans = 1;
  rep(i, 4000) {
    if (!bases[i].count()) {
      if (cur[i] > X[i]-'0') {
        Add(ans, MOD-1);
        break;
      } else if (cur[i] < X[i] - '0') {
        Add(ans, pw2[m]);
        Add(ans, MOD-1);
        break;
      }
      continue;
    }

    if (X[i] == '1') {
      assert(m > 0);
      Add(ans, pw2[m-1]);
      if (!cur[i]) cur ^= bases[i];
    } else if (X[i] == '0') {
      if (cur[i]) cur ^= bases[i];
    }

    --m;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int all[51];
int pate[51];

int dfs(int level, int remain){
  int ret = 0;

  if(remain >= 1) remain--;

  if(remain >= 1){
    if(all[level-1] <= remain){
      remain -= all[level-1];
      ret += pate[level-1];
    }else{
      ret += dfs(level-1, remain);
      remain = 0;
    }
  }

  if(remain >= 1){
    remain--;
    ret++;
  }

  if(remain >= 1){
    if(all[level-1] <= remain){
      remain -= all[level-1];
      ret += pate[level-1];
    }else{
      ret += dfs(level-1, remain);
      remain = 0;
    }
  }

  if(remain >= 1) remain--;

  return ret;
}

signed main() {
  int N, X; 
  cin >> N >> X;

  all[0] = 1;
  pate[0] = 1;
  FOR(i, 1, 50){
    all[i] += all[i-1]*2+3;
    pate[i] += pate[i-1]*2+1;
  }

  cout << dfs(N, X) << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string s, t; cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != 'x') {
			t.push_back(s[i]);
		}
	}
	bool ok = true;
	int j = t.size() - 1;
	for (int i = 0; i < t.size() / 2; i++) {
		if (t[i] != t[j]) {
			ok = false;
		}
		j--;
	}
	if (ok) {
		int ans = 0, cnt1 = 0, cnt2 = 0;
		int i = 0, j = s.size() - 1;
		for (int k = 0; k < (t.size() + 1) / 2; k++) {
			cnt1 = 0; cnt2 = 0;
			while (s[i] != t[k]) {
				cnt1++;
				i++;
			}
			while (s[j] != t[k]) {
				cnt2++;
				j--;
			}
			i++; j--;
			ans += abs(cnt1 - cnt2);
		}
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}
}



Measured memory_bytes: 640
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int x, y; string s; vector<int> v[2]; bool dp[8009][16009];
int main() {
	cin >> s >> x >> y;
	while (s.size() && s[0] == 'F') s = s.substr(1), x--;
	x = abs(x);
	y = abs(y);
	int cnt = 0, pl = 0;
	for (int i = 0; i <= s.size(); i++) {
		if (i == s.size() || s[i] == 'T') {
			if(i != 0) v[cnt].push_back(i - pl - 1);
			cnt ^= 1;
			pl = i;
		}
	}
	bool ret = true;
	for (int i = 0; i < 2; i++) {
		int a = (i == 0 ? x : y);
		int sum = 0;
		for (int j = 0; j < v[i].size(); j++) sum += v[i][j];
		if (sum < a) {
			ret = false;
			continue;
		}
		fill(dp[0], dp[0] + 2 * sum + 1, false); dp[0][sum] = true;
		for (int j = 0; j < v[i].size(); j++) {
			int val = v[i][j];
			fill(dp[j + 1], dp[j + 1] + 2 * sum + 1, false);
			for (int k = -sum; k <= sum; k++) {
				if (k + val <= sum && dp[j][k + val + sum]) dp[j + 1][k + sum] = true;
				if (k - val >= -sum && dp[j][k - val + sum]) dp[j + 1][k + sum] = true;
			}
		}
		if (!dp[v[i].size()][sum + a]) ret = false;
	}
	cout << (ret ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 62208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;


int cal(vector<int> vec,int p) {
  int ans = 0;
  for (int i = 0;i<vec.size();i++) {
    ans += (vec.at(i) - p)*(vec.at(i)-p);
  }
  return ans;
}

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0;i<N;i++) {
    cin >> vec.at(i);
  }
  ll min = INF;
  int ans = 0;
  for (int i = 1;i<=100;i++) {
    if (min > cal(vec,i)) {
      min = cal(vec,i);
      ans = i;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18,MOD=1e9+7;
const int iINF=1e9;
int main(){
    ll n,k,ans=0,tmp=0;
    cin>>n>>k;
    vector<ll>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]>a[j])ans++;
        }
    }
    for(int i=n-1;i>0;i--){//逆順の大小比較
        for(int j=i-1;j>=0;j--){
            if(a[i]>a[j])tmp++;
        }
    }
    ans=(k*(k+1)/2)%MOD*ans%MOD;//昇順でみた転倒数k個ある
    ans+=((k-1)*k/2)%MOD*tmp%MOD;//k-1個tmpがある
    cout<<ans%MOD<<endl;

}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
vector< pair<int, int> > g[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    g[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int v, u, w;
    scanf("%d%d%d", &v, &u, &w);
    v--;
    u--;
    g[v].push_back(make_pair(u, w));
    g[u].push_back(make_pair(v, w));
  }
  return true;
}

int ts[maxn];
int pe[maxn];

void getTs(int v, int p) {
  ts[v] = 1;
  for (int i = 0; i < sz(g[v]); i++) {
    int u = g[v][i].first;
    if (u == p) {
      continue;
    }
    pe[u] = g[v][i].second;
    getTs(u, v);
    ts[v] += ts[u];
  }
}

int getCentroid() {
  int v = 0;
  getTs(v, -1);
  int p = -1;
  while (true) {
    int nv = -1;
    for (int i = 0; i < sz(g[v]); i++) {
      int u = g[v][i].first;
      if (u == p) {
        continue;
      }
      if (2 * ts[u] > n) {
        nv = u;
      }
    }
    if (nv == -1) {
      break;
    }
    p = v;
    v = nv;
  }
  return v;
}

void solve() {
  int v = getCentroid();
  getTs(v, -1);
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (i == v) {
      continue;
    }
    res += (long long) pe[i] * ts[i] * 2ll;
  }
  bool c2 = false;
  for (int i = 0; i < sz(g[v]); i++) {
    int u = g[v][i].first;
    if (2 * ts[u] >= n) {
      res -= g[v][i].second;
      c2 = true;
    }
  }
  if (!c2) {
    int mine = inf;
    for (int i = 0; i < sz(g[v]); i++) {
      mine = min(mine, g[v][i].second);
    }
    res -= mine;
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 13184
#include<iostream>
#include<cstring>
#include<map>
#include<cmath>
#include<vector>
using namespace std;
#define EPS 1e-10

double entropy(int s,int a,int c,vector<int> v){
	map<int,int> mp;
	for(int i=0;i<v.size();i++){
		s = (a*s+c)&255;
		++mp[(s+v[i])&255];
	}
	map<int,int>::iterator it;
	double res=0,n=v.size();
	for(it=mp.begin();it!=mp.end();++it){
		res -= it->second/n*log(it->second/n);
	}
	return res;
}

int main(){
	int n;
	while(cin>>n&&n){
		vector<int> v(n);
		for(int i=0;i<n;i++)cin>>v[i];
		double maxe=1e10;
		int anss,ansa,ansc;
		for(int s=0;s<=15;s++){
			for(int a=0;a<=15;a++){
				for(int c=0;c<=15;c++){
					double e=entropy(s,a,c,v);
					if(e+EPS<maxe){
						maxe=e;
						anss=s;
						ansa=a;
						ansc=c;
					}
				}
			}
		}
		cout<<anss<<' '<<ansa<<' '<<ansc<<endl;
	}
	return 0;
}

Measured memory_bytes: 1272
n = int(input())

INF = 1 << 20
dp = [[INF] * (n + 1) for _ in range(3)]

# dp初期化
for i in range(3):
    dp[i][-1] = 0

for i in range(n):
    a, b, c = map(int, input().split())
    dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a
    dp[1][i] = max(dp[2][i - 1], dp[0][i - 1]) + b
    dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + c

print(max(list(zip(*dp))[n - 1]))

Measured memory_bytes: 22936
#include <iostream>
#include <string>
#define ll long long
#define endl '\n'
using namespace std;

int main(void)
{
  cin.tie(NULL); ios_base::sync_with_stdio(false);
  string str; cin >> str;
  for(int i = 0; i < str.size(); i++)
    {
      if(i % 2 != 0) continue;
      cout << str[i];
    }
  
  return 0;
}



Measured memory_bytes: 576
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

#include <complex>
typedef complex<double> P;
typedef vector<P> vP;
typedef vector<double> vd;

#define EQ(x,y) (abs((x)-(y))<EPS)

double rad(double deg) {
	return deg*PI/180.0;
}

double dot(P a, P b) {
	return (a.real()*b.real() + a.imag()*b.imag());
}

double cross(P a, P b) {
	return (a.real()*b.imag() - a.imag()*b.real());
}

int is_point_on_line(P a, P b, P c) {
	return EQ(cross(b-a, c-a), 0.0);
}

int is_point_on_ls(P a, P b, P c) {
	return (abs(a-c) + abs(c-b) < abs(a-b) + EPS);
}

int is_intersected_ls(P a1, P a2, P b1, P b2) {
	if((cross(a2-a1, b1-a1)*cross(a2-a1, b2-a1) < -EPS) &&
	   (cross(b2-b1, a1-b1)*cross(b2-b1, a2-b1) < -EPS))
	   return true;
	return is_point_on_ls(a1, a2, b1) || is_point_on_ls(a1, a2, b2) ||
		   is_point_on_ls(b1, b2, a1) || is_point_on_ls(b1, b2, a2);
}

double distance_ls_p(P a, P b, P c) {
	if(dot(b-a, c-a) < -EPS) return abs(c-a);
	if(dot(a-b, c-b) < -EPS) return abs(c-b);
	return abs(cross(b-a, c-a)) / abs(b-a);
}

double distance_ls(P a1, P a2, P b1, P b2) {
	if(is_intersected_ls(a1, a2, b1, b2)) {
		return 0.0;
	}
	return min(min(distance_ls_p(a1, a2, b1), distance_ls_p(a1, a2, b2)),
			   min(distance_ls_p(b1, b2, a1), distance_ls_p(b1, b2, a2)));
}

int main() {
	int N, M, L;
	while(cin >> N >> M >> L, N) {
		vector<vP> points(N, vP(5));
		double x, y, a, r;
		REP(i, N) {
			cin >> x >> y >> a >> r;
			REP(j, 5) {
				points[i][j] = P(x-r*sin(rad(a+72*j)), y+r*cos(rad(a+72*j)));
			}
		}

		vector<vd> cost(N, vd(N, INF));
		REP(i, N) {
			FOR(j, i+1, N-1) {
				REP(k, 5) {
					REP(l, 5) {
						cost[i][j] = cost[j][i] = min(cost[i][j], distance_ls(points[i][k], points[i][(k+2)%5], points[j][l], points[j][(l+2)%5]));
					}
				}
			}
		}

		REP(k, N) {
			REP(i, N) {
				REP(j, N) {
					cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
				}
			}
		}

		if(M == L){
			cost[M-1][L-1] = 0.0;
		}
		
		printf("%.8f\n", cost[M-1][L-1]);
	}

	return 0;
}

Measured memory_bytes: 1376
#include <stdio.h>
int main(){
	int n,b=1,i;
	scanf("%d", &n);
	int x[n];
	for(i=0;i<n;i++) {
		scanf("%d", &x[i]);
	}
	for(i=0;i<n;i++) {
		if(x[i]==b){
			b++;
		}
	}
	if(b==1) b=n+2;
	printf("%d\n", n-b+1);
	return 0;
}

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

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <typename T>
vector<T> pows(int n) {
	vector<T> ret;
	T x = 1;
	while (ret.size() < n) {
		ret.push_back(x);
		x *= 10;
	}
	return ret;
}

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }

template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }



int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N;
	string ans = "";
	if (N == 0) {
		ans = "0";
	} else {
		while (N != 0) {
			if (N % -2 != 0) {
				N--;
				ans = "1" + ans;
			} else {
				ans = "0" + ans;
			}
			N /= -2;
		}
	}
	cout << ans << endl;

	return 0;
}

//*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
std::vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
#define size_t ll
const int mod = 1000000007;
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
const int INF = 1001001001;
int h,n;
int main(){
  cin >> h >> n;
  std::vector<int> dp(h+1,INF);
  dp[0] = 0;
  for (size_t i = 0; i < n; i++) {
    int a,b;
    cin >> a >> b;
    for (int l = 0; l <= h; l++) {
      int nj = min(l+a,h);
      dp[nj] = min(dp[nj], dp[l]+b);
    }
  }

  cout << dp[h] << endl;
}


Measured memory_bytes: 256
A,B,K = map(int, input().split())

if A > B:
  C=A
  A=B
  B=C
k = 0
cnt = 0
while True:
  if A % (A-cnt) == 0 and B % (A-cnt) == 0:
    k += 1
    if k == K:
      print(A-cnt)
      break
  cnt += 1

Measured memory_bytes: 3060
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

char s1[110], s2[110];

int main()
{
	int N;

	cin >> N;

	cin >> s1 >> s2;


	int mx = 0;
	for (int i = 0; i < N; ++i)
	{
		int j;
		for (j = 0; i+j < N; ++j)
		{
			if (s1[i+j] != s2[j])
				break;
		}
		if(i+j>=N)
			mx = max(mx, j);

	}

	cout << 2*N- mx;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main()
{
  int a, b;
  string op;
  while(1)
  {

    cin >> a >> op >> b;
    if(op == "?") break;

    if(op == "+")
    {
      cout << a + b << endl;
    }
    if(op == "-")
    {
      cout << a - b << endl;
    }
    if(op == "*")
    {
      cout << a * b << endl;
    }
    if(op == "/")
    {
      cout << a / b << endl;
    }
  }


  return 0;
}


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

int main() {

    long double a, b, c;
    cin >> a >> b >> c;

    if(sqrt(a/c) + sqrt(b/c) < 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

int X;

void Main() {
  cin >> X;

  int min_n = 0;
  int max_n = X / 100;

  int left = X % 100;
  for (int i = 5; i >= 1; i--) {
    min_n += left / i;
    left = left % i;
  }

  if (max_n >= min_n) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}

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

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int main() {
    int n, ans = 0;
    string a, b, c;
    cin >> n >> a >> b >> c;
    for (int i = 0; i < n; ++i) {
        int cnt = 0;
        if (a[i] == b[i])
            cnt++;
        if (b[i] == c[i])
            cnt++;
        if (c[i] == a[i])
            cnt++;
        if (cnt == 1)
            ans += 1;
        if (cnt == 0)
            ans += 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
class UnionFind {
private:
	int size_; vector<int> g; vector<vector<int> > v;
public:
	UnionFind() : size_(0), g(vector<int>()), v(vector<vector<int> >()) {};
	UnionFind(int size__) : size_(size__) { g.resize(size_), v.resize(size_); for (int i = 0; i < size_; i++) g[i] = i, v[i] = { i }; };
	int size() { return size_; }
	int root(int x) { return g[x]; }
	int size(int x) { return v[x].size(); }
	bool same(int x, int y) { return g[x] == g[y]; }
	void unite(int x, int y) {
		x = g[x], y = g[y];
		if (x == y) return;
		if (v[x].size() < v[y].size()) swap(x, y);
		v[x].insert(v[x].end(), v[y].begin(), v[y].end());
		for (auto &e : v[y]) g[e] = x;
		v[y].clear();
	}
	bool operator==(const UnionFind& u) { return g == u.g; }
	bool operator!=(const UnionFind& u) { return g != u.g; }
	int operator[](int x) { return g[x]; }
};
struct edge { int s, to, cost; };
bool operator<(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int V, E, x[10009], y[10009], s, t; edge e[99999];
int main() {
	scanf("%d%d", &V, &E);
	for (int i = 0; i < V; i++) scanf("%d%d", x + i, y + i);
	for (int i = 0; i < E; i++) {
		scanf("%d%d", &s, &t); s--, t--;
		int dist = (x[s] - x[t]) * (x[s] - x[t]) + (y[s] - y[t]) * (y[s] - y[t]);
		e[i] = edge{ s, t, dist };
	}
	sort(e, e + E);
	reverse(e, e + E);
	UnionFind u(V);
	double ret = 0;
	for (auto &v: e) {
		if (u.same(v.s, v.to)) ret += sqrt(v.cost);
		else u.unite(v.s, v.to);
	}
	printf("%.9f\n", ret);
	return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m,ans = 0;
    cin>>n>>m;
    vector<bool>l(n,true);
    vector<int>h(n),a(m),b(m);
    rep(i,n)cin>>h[i];
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        if(h[a[i]] == h[b[i]]){
            l[b[i]] = false;
            l[a[i]] = false;
        }
        else if(h[a[i]] > h[b[i]]){
            if(l[b[i]]){
                l[b[i]] = false;
            }
        }
        else {
            if(l[a[i]]){
                l[a[i]] = false;
            }
        }
    }
    rep(i,n)if(l[i])ans++;
    cout<<ans<<endl;
    return 0;
}


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

int nearestInt(double x) {
    if (x - floor(x) < ceil(x) - x) {
        return (int)floor(x);
    }
    else
    {
        return (int)ceil(x);
    }
}

int main() {
    int sum, powsum;
    sum = 0;
    powsum = 0;
    int n, temp;
    int x;
    cin >> n;
    vector<int> X(n);
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        sum += temp;
        powsum += temp * temp;
        X[i] = temp;
    }
    x = nearestInt((double)sum / (double)n);
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += (X[i] - x) * (X[i] - x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256