akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
using namespace std;
int keisan(int i,int j){
	if(i==1) return j*6000;
	else if(i==2) return j*4000;
	else if (i==3) return j*3000;
	else return j*2000;
	}
int main(){
	int i[4],n[4],kane[4];
	for(int j=0;j<4;j++){
		cin>>i[j]>>n[j];
		kane[j]=keisan(i[j],n[j]);
		}
	for(int j=0;j<4;j++){
		cout<<kane[j]<<endl;
		}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define C first
#define S second.first
#define Z second.second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int N = 100;

int n;
bool ok[N][N];
int c[N][N];

bool check();

int main(void){
    for(int m, res; cin >> n >> m, n; cout << res << endl){
        res = 0;
        rep(i, n) rep(j, n) ok[i][j] = false, c[i][j] = 0;

        vector< pair<int, pii> > in;
        while(m--){
            int a, b, cost; cin >> a >> b >> cost;

            ok[a][b] = ok[b][a] = true;
            c[a][b] = c[b][a] = cost;
            in.pb(mp(cost, mp(a, b)));
        }
        sort(ALL(in), greater< pair<int, pii> >());

        rep(i, in.size()){
            int a = in[i].S, b = in[i].Z;
            ok[a][b] = false;
            ok[b][a] = false;

            if(!check()){
                ok[a][b] = true;
                ok[b][a] = true;
            }
        }

        rep(i, n) for(int j = i + 1; j < n; j++) if(ok[i][j]) res += c[i][j];
    }

    return 0;
}

bool check(){
    vector<bool> used(n);
    
    queue<int> q;
    q.push(0);

    while(!q.empty()){
        int cur = q.front(); q.pop();
        if(used[cur]) continue;
        used[cur] = true;

        rep(next, n) if(ok[cur][next]) q.push(next);
    }

    return !count(ALL(used), false);
}

Measured memory_bytes: 1252
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
m,ans=abs(a-(t-0.006*h[0])),0
for i in range(1,n):
  now=abs(a-(t-0.006*h[i]))
  if now<m:
    m=now
    ans=i
print(ans+1)

Measured memory_bytes: 3060
#include<iostream>
#include<string>

using namespace std;

int main(void) {

	string str;
	cin >> str;

	int ans = 0;

	for (int i = 0; i < 4; i++) {
		if (str.substr(i, 1) == "+") { ans++; }
		else { ans--; }
	}
	cout << ans << endl;
	//system("pause");
	return 0;
};

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll,ll> P;

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

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};


int main() {
    int N; cin >>N;
    int a[100010];
    int right[100010], left[100010];
    rep(i,N){
        cin >> a[i];
    }
    right[N-1]=a[N-1];
    left[0]=a[0];

    for(int i=1; i<N; i++){
        left[i]=gcd(left[i-1],a[i]);
    }

    for(int i=N-2; i>=0; i--){
        right[i]=gcd(right[i+1],a[i]);
    }

    int maximum=1;

    for(int i=0; i<N; i++){
        if(i==0){
            maximum=max(maximum, right[1]);
        }else if(i==N-1){
            maximum=max(maximum, left[N-2]);
        }else{
            maximum=max(maximum, (int)gcd(right[i+1], left[i-1]));
        }
    }

    cout << maximum << endl;
    return 0;
}


Measured memory_bytes: 1408
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
to_0 = 0
to_N = 0
for i in range(X):
    if i in A:
        to_0 += 1

for i in range(X+1, N):
    if i in A:
        to_N += 1

answer = min(to_0, to_N)
print(answer)

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

using namespace std;
typedef long long int lli;

const int INF = 100100100;

int main()
{
    // Input numbers
    int n;
    cin >> n;

    vector<int> a;
    for (int i = 0; i < n; ++i) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    int minimum = *std::min_element(a.begin(), a.end());
    int max = *std::max_element(a.begin(), a.end());

    lli ans = INF;

    for (int i = minimum; i < max+1; ++i) {
        lli tmp = 0;
        for (int j = 0; j < (int)a.size(); ++j) {
            tmp += (a[j] - i) * (a[j] - i);
        }

        ans = min(ans, tmp);
    }

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

Measured memory_bytes: 3636
from collections import defaultdict

def main():
    N,M = [int(x) for x in input().split()]
    Hl = [int(x) for x in input().split()]
    Al,Bl = [],[]
    for i in range(M):
        A,B = [int(x) for x in input().split()]
        Al.append(A)
        Bl.append(B)

    is_peek = [1]*N
    m = defaultdict(list)
    for A,B in zip(Al,Bl):
        if Hl[A-1] > Hl[B-1]:
            is_peek[B-1] = 0
        elif Hl[A-1] == Hl[B-1]:
            is_peek[A-1] = 0
            is_peek[B-1] = 0
        else:
            is_peek[A-1] = 0
    print(sum(is_peek))
        

if __name__ == '__main__':
    main()



Measured memory_bytes: 22564
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, k, q = MAP()
b = [0 for _ in range(n)]
for _ in range(q):
    a = INT()
    b[a - 1] += 1
ans = 0
for i in range(n):
    if k + b[i] - q > 0:
        print('Yes')
    else:
        print('No')



Measured memory_bytes: 6772
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,e,f,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s[ohara],co;
bool fl;
struct edge{int to,cost;};
vector<ll> graph[ohara];
map<pair<ll,ll>,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>m;
    rep(i,m){
        cin>>a>>b;
        a--;b--;
        mp[{a,b}]=1;
        mp[{b,a}]=1;
    }
    vector<ll> p(n);
    rep(i,n)p[i]=i;
    do{
        a=0;
        if(p[0]!=0)continue;
        rep(i,n-1){
            if(mp[{p[i],p[i+1]}]==0){
                a=1;
                break;
            }
        }
        if(a==0)ans++;
    }while(next_permutation(all(p)));
    Cout(ans);
    return 0;
}


Measured memory_bytes: 31488
#include <stdio.h>
#include <vector>
#include <iostream>
// #include <bits/stdc++.h>

using namespace std;
#define _GLIBCXX_DEBUG

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

    int N, ans = 0;
    cin >> N;

    vector<int> V(N), C(N);
    for (int i = 0; i < N; i++)
    {
        cin >> V[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
    }

    for (int i = 0; i < N; i++)
    {

        ans += max(V[i] - C[i], 0);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(){
  int N,Q; cin>>N>>Q;
  char temp[2]; temp[1]='B';
  vector<unsigned int>t(N,0);
  for(int i=0;i<N;i++){
   cin>>temp[0];
   t[i]=t[i-1]+(temp[0]=='C'?(temp[1]=='A'?1:0):0);
   temp[1]=temp[0];
  }

  for(int i=0;i<Q;i++){
    int a,b; cin>>a>>b;
    cout<<t[b-1]-t[a-1]<<endl;
  }
  return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int x, a, b;
  cin >> x >> a >> b;
  int da = abs(x - a), db = abs(x - b);
  if (da < db) cout << 'A' << '\n';
  else cout << 'B' << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3652
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto S = readln.chomp;
    if (S.length == 2) {
        if (S[0] == '0' || S[1] == '1') {
            writeln(-1);
        } else {
            writeln("1 2");
        }
        return;
    }
    if (S[0] == '0' || S[$-2] == '0' || S[$-1] == '1') {
        writeln(-1);
        return;
    }

    int[] as, bs;
    int p = 1;
    auto N = S.length.to!int;
    int i, j = N-2;
    while (i <= j) {
        if (S[i] != S[j]) {
            writeln(-1);
            return;
        }
        as ~= p;
        bs ~= i+2;
        if (S[i] == '1') p = i+2;
        ++i; --j;
    }
    for (; i < N-1; ++i) {
        as ~= p;
        bs ~= i+2;
    }
    foreach (k; 0..N-1) writeln(as[k], " ", bs[k]);
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<double, int> d_i;

const int MOD = 1e9 + 7;
const int INF = INT_MAX / 10;

int main() {
	int N, M; cin >> N >> M;
	vector<vector<int> > p(N, vector<int>(M));
	rep(i, N) rep(j, M) scanf("%d", &p[i][j]), p[i][j]--;
	int lb = 0, ub = N;
	while (ub - lb > 1) {
		int mid = (lb + ub) / 2;
		int rest = M;
		vector<bool> a(M, true);
		bool wei = false;
		while (rest) {
			vector<int> num(M);
			rep(i, N) for (int j: p[i]) if (a[j]) { num[j]++; break; }
			bool ok = true;
			rep(j, M) if (a[j] && num[j] > mid) ok = a[j] = false, rest--;
			if (ok) { wei = true; break; }
		}
		if (wei) ub = mid;
		else lb = mid;
	}
	cout << ub << endl;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, K;
  cin >> N >> K;
  map<ll, ll> Kd;
  map<ll, ll> A;
  rep(i, N){
    ll a;
    cin >> a;
    rep(j, 61){
      A[j]+=(a>>j&1?1LL:0LL);
    }
  }
  
  rep(j, 61){
    Kd[j]=(K>>j&1LL? 1LL : 0LL);
  }
  
  ll ans = -1;
  for(ll i=-1;i<=60;i++){
    if(i>=0LL and Kd[i]==0LL)continue;
    ll cand=0;
    for(ll j=60;j>=0;j--){
      //ll mask = 1LL<<j;
      if(j>i){
        ll tmp = (Kd[j]==1LL? N-A[j] : A[j]);
        cand += powl(2LL, j) * tmp;
      }else if(j==i){
        cand += powl(2LL, j) * A[j];
      }else{
        cand += powl(2LL, j) * max(N-A[j], A[j]);          
      }
    }
    ans=max(ans, cand);
  }
  
  
  cout << ans;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 100005;
inline int readint()
{
	int res = 0, f = 1;
	char c = 0;
	while(!isdigit(c))
	{
		c = getchar();
		if(c=='-')
			f = -1;
	}
	while(isdigit(c))
		res = res*10+c-'0', c = getchar();
	return res*f;
}
int n,m,v,p,a[MAXN];
inline ll calc(ll x, ll y)
	{ return (x-1)/y+1; } 

int main()
{
	n = readint(), m = readint(), v = readint(), p = readint();
	for(int i = 1; i<=n; i++)
	    a[i] = readint();
	sort(a+1,a+n+1), reverse(a+1,a+n+1);
	int ans = p;
	ll sum = 0;
	for(int i = p+1; i<=n; i++)
	{
		if(a[i]+m<a[p])
		    break;
    	if(v<=n-i+p)
		    ans++;
		else if(calc(1ll*(v-n+i-p)*m-sum,i-p)+a[p]<=a[i]+m)
		    ans++;
		sum += a[p]-a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int n, m;
  cin >> n >> m;
  if (n >= m) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> x(m);
  rep(i, m) cin >> x[i];
  sort(x.begin(), x.end());
  int ans = 0;
  vector<int> d(m-1);
  rep(i, m-1) {
    d[i] = x[i+1]-x[i];
  }
  sort(d.begin(), d.end());
  rep(i, m-n) ans += d[i];
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <stack>
#include <queue>
#include <set>

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

typedef long long ll;
using namespace std;

int main(){
    string S;
    cin >> S;
    ll N=0;
    rep(i, S.size()) N+=S[i]-'0';
    if(stoi(S)%N==0) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    int h,w;cin>>h>>w;
    vector<string> c(h);
    for(int i=0;i<h;i++)cin>>c[i];
    vector<vector<int>> a(h,vector<int>(w,0));
    for(int j=1;j<w;j++){
        for(int i=1;i<h;i++){
            int co=0;
            if(c[i][j]=='#')co++;
            if(c[i][j-1]=='#')co++;
            if(c[i-1][j]=='#')co++;
            if(c[i-1][j-1]=='#')co++;
            if(co%2==0)a[i][j]=1;
        }
    }
    for(int j=1;j<w;j++){
        for(int i=1;i<h;i++){
            if(a[i][j])a[i][j]+=a[i-1][j];
        }
    }
    int ans=max(h,w);
    for(int i=1;i<h;i++){
        stack<P> st;
        for(int j=1;j<w;j++){
            if(st.empty()){
                st.push(P(a[i][j],j));
            }else if(st.top().first<a[i][j]){
                st.push(P(a[i][j],j));
            }else if(st.top().first>a[i][j]){
                int id=i;
                while(!st.empty()&&st.top().first>=a[i][j]){
                    ans=max(ans,(st.top().first+1)*(j-st.top().second+1));
                    id=st.top().second;
                    st.pop();
                }
                st.push(P(a[i][j],id));
            }
        }
        while(!st.empty()){
            ans=max(ans,(st.top().first+1)*(w-st.top().second+1));
            st.pop();
        }
    }
    cout<<ans<<endl;
}   


Measured memory_bytes: 20096
import java.util.*;
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int data1[] = new int[n];
    int data2[] = new int[n + 1];

    int min = 100;




    for (int i = 0 ; i < n ; i++) {
      data1[i] = sc.nextInt();
    }


    for (int i = 1 ; i < n + 1 ; i++ ) {
      data2[i] = data2[i-1] + data1[i-1] ;
    }


    for (int i = 0 ; i < n+1 ; i++ ) {
      //System.out.println(data2[n] - data2[i] - data2[i]);
      int s1 = data2[i];
      int s2 = data2[n] - data2[i];
      int abs = Math.abs(s1-s2);
      min = Math.min(min,abs);
    }


    System.out.println(min);

  }
}


Measured memory_bytes: 21844
N,Q = map(int, input().split())
S = input()
SUM = [0] * (N + 1)
L = [0]*Q
R = [0]*Q


for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        SUM[i+1] = SUM[i] + 1
    else:
        SUM[i+1] = SUM[i]

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))
    #indexを0からにする
    print(SUM[R[i]-1] - SUM[L[i]-1])

Measured memory_bytes: 14024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	//入力
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int count = 0;
	while (true) {
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 != 0) {
				cout << count;
				return 0;
			}
			else {
				A[i] /= 2;
			}
		}
		count++;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import itertools
import math
input = sys.stdin.readline

def slove():
    n = int(input())
    P = [tuple(map(int,input().split())) for _ in range(n)]
    #print(P)
    
    count = 0
    total_distance = 0
    for item in itertools.permutations(range(n)):
        #print(item)
        count += 1
        for i in range(n-1):
            a = item[i]
            b = item[i+1]

            total_distance += math.sqrt((P[b][0]-P[a][0])**2+(P[b][1]-P[a][1])**2)
    print(total_distance/count)


if __name__ == "__main__":
    slove()


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint()
{
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//
const int maxn=2e6;
int par[maxn],flag[maxn],dis[maxn];
vector<pii >e[maxn];
vector<int>G[maxn];
//
void init(int x)
{
	flag[x]=-1;
	par[x]=x;
}
int fF(int x)
{
	if(par[x]==x)return x;
	return par[x]=fF(par[x]);
}
void fU(int x,int y)
{
	x=fF(x);y=fF(y);
	if(x==y)return;
	par[x]=y;
}
vector<int>v;
int n,m,cnt;
int main()
{
	n=getint();m=getint();
	rep(i,m)
	{
		int x=getint()-1,y=getint()-1,z=getint();
		e[z].push_back(mp(x,y));
	}
	cnt=n;
	rep(i,maxn)if(!e[i].empty())
	{
		v.clear();
		rep(j,e[i].size())
		{
			int x=e[i][j].first,y=e[i][j].second;
			init(x);init(y);
			v.push_back(x);
			v.push_back(y);
		}
		rep(j,e[i].size())
		{
			int x=e[i][j].first,y=e[i][j].second;
			fU(x,y);
		}
		rep(j,v.size())
		{
			int x=v[j],y=fF(x);
			if(flag[y]<0)flag[y]=cnt++;
			G[x].push_back(flag[y]);
			G[flag[y]].push_back(x);
		}
	}
	queue<int>qu;
	rep(i,maxn)dis[i]=-2;
	dis[0]=0;qu.push(0);
	while(!qu.empty())
	{
		int u=qu.front();
		qu.pop();
		rep(i,G[u].size())
		{
			int y=G[u][i];
			if(dis[y]==-2)
			{
				dis[y]=dis[u]+1;
				qu.push(y);
			}
		}
	}
	printf("%d\n",dis[n-1]/2);
	return 0;
}


Measured memory_bytes: 120704
while 0 != n = gets.to_i
  a = b = 0
  n.times do
    c, d = gets.split.map(&:to_i)
    a = a + c + d if c > d
    b = b + c + d if c < d
    a = a + c if c == d
    b = b + c if c == d
  end
  puts "#{a} #{b}"
end

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    ll n,ans=0,t=0;
    cin>>s;
    n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='W'){ans+=i-t;t++;}
    }
    cout<<ans;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int ar[105];
int32_t main(){
	int n,k,ans=0;cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
	}
	for(int i=1;i<=n;i++){
		ans+=2*min(ar[i],k-ar[i]);
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	#include <ext/pb_ds/assoc_container.hpp>
	using namespace __gnu_pbds;
	using namespace std;
	#define mod 1000000007
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define ps push
	#define pll pair<long,long>
	typedef long long ll;
	#define PI 3.14159265
	#define vi vector<pll> 
		 
	typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
	const ll INF=(ll)5e17;	
		
	long long binpow(long long a, long long b, long long m) {
			a %= m;
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = res * a % m;
				a = a * a % m;
				b >>= 1;
			}
			return res;
	}

		
		
	int main()
	{
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		
		ll m;
		cin>>m;
		ll s=0,d=0;
		for(ll i=0;i<m;i++)
		{
			ll d1,c1;
			cin>>d1>>c1;
			d+=c1;
			s+=(d1*c1);
		}
		d--;
		cout<<d+(s-1)/9;
		
	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define x first
#define y second
typedef long long ll;
const int N = 100010;
const int mod = 1000000007;
const int oo = 1e9;
const int base = 27;
typedef pair<int,int> pii;
 
int n , k,v[N];
pii up[N],dw[N];
vector<int> g[N];
 
 
void pull(int u,int par){
  dw[u] = make_pair(-oo,oo);
  for(auto v : g[u]){
    if(v == par)continue;
    pull(v,u);
    dw[u].first = max(dw[u].first,dw[v].first-1);
    dw[u].second = min(dw[u].second,dw[v].second+1);
  }
  if(v[u] != -1)dw[u] = make_pair(v[u],v[u]);
}
void push(int u , int par){
  up[u] = make_pair(-oo,oo);
  if(par != -1)up[u] = make_pair(up[par].first-1,up[par].second+1);
  up[u] = make_pair(max(up[u].first,dw[u].first),min(up[u].second,dw[u].second));
  for(auto v : g[u]){
    if(v == par)continue;
    push(v,u);
  }
}
bool check(){
  for (int i = 1; i <= n; ++i)
    for(auto x : g[i])
      if(abs(v[x] - v[i]) != 1)return false; 
  return true;
}
int main() {
  memset(v,-1,sizeof v);
  cin >> n;
  for (int a,b,i = 0; i < n-1; ++i){
    scanf("%d%d",&a,&b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cin >> k;
  int a = 0;
  for (int i = 0; i < k; ++i){
    scanf("%d",&a);
    scanf("%d",&v[a]);
  }
  pull(a,-1);
  push(a,-1);
  for(int i = 1;i <= n ; ++i){
    if(up[i].first > up[i].second || ((up[i].first%2+2)%2 != up[i].second%2)){
      puts("No");
      return 0;
    }
    v[i] = up[i].second;
  }
  
  puts("Yes");
  for(int i = 1; i <= n ; ++i){
    printf("%d\n", v[i]);
  }
  return 0;
}

Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
int main()
{
    IOS;
    //freopen("inputfile.txt","r",stdin);
    int k;cin>>k;
    string s;cin>>s;
    if(s.size()<=k)
    {
        cout<<s<<endl;
        return 0;
    }
    else
    {
        for(int i=0;i<k;i++)cout<<s[i];
cout<<"..."<<endl;
        return 0;
    }
}
//............ALHAMDULLILAH...........


Measured memory_bytes: 3660
import sys
from collections import namedtuple


INF = sys.maxsize
Item = namedtuple('Item', 'w v')

N, W = map(int, input().split())

items = []

for _ in range(N):
  w, v = map(int, input().split())
  items.append(Item(w, v))
  
max_value = 10 ** 3 * 100  

memo = [0] + [INF] * max_value

for item in items:
  for v in range(max_value, item.v - 1, -1):
    memo[v] = min(memo[v], memo[v - item.v] + item.w)
  
print(max([v for v, w in enumerate(memo) if w <= W]))


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

using ll = long long;
const ll amari = 1e9+7;
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int a,b;
	cin >> a >> b;
	int sum = 0;
	sum += max(a,b);
	if(sum == a)a--;
	else b--;
	sum += max(a,b);
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
/**
*    Username : adhoc_king
*    Name : adhoc_king
*    Institute : IIT Bombay
*/

#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
// #include <map>
// #include <set>
// #include <cassert>
// #include <complex>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map>

using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define FOR(i,n) for(int i=0; i<n; i++)
#define X first
#define Y second
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define arrsum for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);

ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

bool vowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') return true;
    else return false;
}

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
private:
    vi p, rank, setSize;                       // remember: vi is vector<int>
    int numSets;
public:
    UnionFind(int N) {
        setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
        p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
    int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
    bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
    void unionSet(int i, int j) { 
        if (!isSameSet(i, j)) { numSets--; 
        int x = findSet(i), y = findSet(j);
        // rank is used to keep the tree short
        if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
        else                   { p[x] = y; setSize[y] += setSize[x];
                                 if (rank[x] == rank[y]) rank[y]++; } } }
    int numDisjointSets() { return numSets; }
    int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int a, b, c;
    cin>>a>>b>>c;
    cout<<(c/a)*b;

    return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val Seq(largeH, largeW) = io.StdIn.readLine().split(" ").map(_.toInt).toSeq
    val Seq(h, w) = io.StdIn.readLine().split(" ").map(_.toInt).toSeq

    println(largeH * largeW - h * largeW - w * largeH + h * w)
  }
}


Measured memory_bytes: 27340
#include <stdio.h>
#include <stdlib.h>
#define MAX 100010
#define INFTY 10000000
#define NIL -1

struct Node {
	int value;
	struct Node *next;
};
typedef struct Node node_t;


int N;
int M;
node_t *G[MAX];
int color[MAX];

node_t* addNode(node_t *node, int value)
{
	node_t *new = (node_t*)malloc(sizeof(node_t));
	new->value = value;
	new->next = node;
	return new;
}

void dfs(int r, int c)
{
	color[r] = c;
	node_t *n;
	for (n=G[r]; n!=NULL; n=n->next) {
		int v = n->value;
		if (color[v] == NIL) {
			color[v] = c;
			dfs(v, c);
		}
	}
}

void assignColor()
{
	int i, u;
	int id =1;
	for (i=0; i<N; i++) {
		color[i] = NIL;
	}
	for (u=0; u<N; u++) {
		if (color[u] == NIL) dfs(u, id++);
	}
}


int main()
{
	int i, n, u, v;	
	scanf("%d %d", &N, &M);	
	for (i = 0; i < M; i++) {
		scanf("%d %d", &n, &v);
		G[n] = addNode(G[n], v);
		G[v] = addNode(G[v], n);
	}
	
	assignColor();
	
	int Q;
	scanf("%d", &Q);
	for (i = 0; i < Q; i++) {
		scanf("%d %d", &u, &v);
		if (color[u] == color[v]) {
			puts("yes");			
		}
		else {
			puts("no");
		}
	}

	return 0;
}

Measured memory_bytes: 11124
import java.util.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);

		int n=s.nextInt(),m=s.nextInt()*2+1;

		System.out.println((n+m-1)/m);
	}
}


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


vector<int> to[200005];
vector<int> ans;

void dfs(int v,int p=-1){
  for(int u:to[v]){
    if(u == p)continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}


int main(){
  int n, q;
  cin >> n >> q;
  rep(i,n-1){
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);

  rep(i,q){
    int p,x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n){
    cout << ans[i] <<endl;
  }
  return 0;
}


Measured memory_bytes: 24064
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s)
	for _, c := range s {
		switch c {
		case 'B':
			if len(t) > 0 {
				t = t[:len(t)-1]
			}
		default:
			t += string(c)
		}
	}
	fmt.Println(t)
}


Measured memory_bytes: 512
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
vector<int>sosuu2(100001, 0);
vector<int>sosuu3(100001, 0);
vector<int>sosuu;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	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" << "\n";
	}
	else
	{
		cout << "No" << "\n";
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
long double pi = acos(-1);

using namespace std;

int main() {

    long int a,b,c,k;
    cin>>a>>b>>c>>k;
    if (k<=a){
        cout<<k;
    }
    else if(a+b>=k){
        cout << a;
    }else{

        cout<<a-(k-(a+b));
    }

    return 0;

}

Measured memory_bytes: 3600
S = input()
a = 0
b = 0
if (S[0] == '0' and S[1] != '0') or (S[0] == '1' and (S[1] == '0' or S[1] == '1' or S[1] == '2')):
  a = 1
if (S[2] == '0' and S[3] != '0') or (S[2] == '1' and (S[3] == '0' or S[3] == '1' or S[3] == '2')):
  b = 1
if a == 1 and b == 1:
  print("AMBIGUOUS")
elif a == 1:
  print("MMYY")
elif b == 1:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
  int n;
void solve(vector<int> p){
  int tem = 1010100101;
  int count = 0;
  for(int i = 0; i < n; i++){
      tem = min(tem,p[i]);
      if(tem==p[i]) count++;
  }
  cout << count << endl;
}

int main(){

  cin >> n;
  vector<int> p(n);
  
  for(auto &x : p){
    cin >> x;
  }

  solve(p);
  
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n;
int h[100005];
int dp[100005];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&h[i]);
	dp[1]=0;dp[2]=abs(h[1]-h[2]);
	for(int i=3;i<=n;i++){
		dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
 
 
public class Main {
     
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
         
        int[][] A = new int[n][m];
        int[] B = new int[m];
        int[] C = new int[n];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j <  m; j++) {
                A[i][j] = stdIn.nextInt();
            }
        }
        for(int i = 0; i < m; i++) {
            B[i] = stdIn.nextInt();
        }
         
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                C[i] += A[i][j] * B[j];
            }
        }
         
        for(int i = 0; i < n; i++) {
            System.out.println(C[i]);
        }
    }
 
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    cin >> n;
    vector<P> a(n);
    for (int i = 0;i < n;++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(),a.end());
    for (int i = 0;i < n;++i) cout << a[i].second+1 << " \n"[i == n-1];
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;
int a[mx];
int t;
int n,m;
int res;

int main(){
	cin>>n>>m;
	res=1;
	int num=0;
	while(res<m){
		res=(res-1)+n;
		num++;
	}
	cout<<num<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

ll f(ll n, ll x) {
	if( n == -1 ) return -1;
	else return n / x;
}

int main(void) {
	ll a, b, x;
	cin >> a >> b >> x;
	
	cout << f(b, x) - f(a - 1, x) << endl;
	
	return 0;
}


Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

// const (
// 	initialBufSize = bufio.MaxScanTokenSize //65536
// 	maxBufSize     = 10000000000
// )

const inf = 1000000000

func main() {
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, initialBufSize)
	// scanner.Buffer(buf, maxBufSize)

	l, r := nextInt(), nextInt()

	min := inf
LABEL:
	for i := l; i < r; i++ {
		for j := l + 1; j <= r; j++ {
			mod := i * j % 2019
			if mod < min {
				min = mod
			}
			if min == 0 {
				break LABEL
			}
		}
	}
	fmt.Println(min)
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}
func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
namespace Computational_Geometry
{
	const long double eps=1e-10;
	struct Vector2
	{
		long double x,y;
		Vector2(long double X=0.0,long double Y=0.0):x(X),y(Y) {}
		Vector2 *read() {scanf("%Lf%Lf",&x,&y); return this;}
		void print() {printf("%.10Lf %.10Lf",x,y); return;}
		inline Vector2 operator - () const{return Vector2(-x,-y);}
		inline Vector2 operator + (const Vector2 &A) const{return Vector2(x+A.x,y+A.y);}
		inline Vector2 operator - (const Vector2 &A) const{return Vector2(x-A.x,y-A.y);}
		inline Vector2 operator * (const long double &k) const{return Vector2(x*k,y*k);}
		inline Vector2 operator / (const long double &k) const{return Vector2(x/k,y/k);}
		inline long double operator * (const Vector2 &A) const{return x*A.x+y*A.y;}
		inline long double operator ^ (const Vector2 &A) const{return x*A.y-y*A.x;}
		inline long double norm2() const{return x*x+y*y;}
		inline long double norm() const{return sqrtl(x*x+y*y);}
		inline bool operator < (const Vector2 &A) const{return (x<A.x-eps)||(x<=A.x+eps)&&(y<A.y-eps);}
		inline bool operator == (const Vector2 &A) const{return fabsl(x-A.x)<=eps&&fabsl(y-A.y)<=eps;}
		inline bool operator << (const Vector2 &A) const{return (y<-eps)^(A.y<-eps)?A.y<-eps:((*this^A)>eps)||((*this^A)>=-eps)&&(x>=-eps)&&(A.x<-eps);}
		inline Vector2 trans(long double a_11,long double a_12,long double a_21,long double a_22) const{return Vector2(x*a_11+y*a_12,x*a_21+y*a_22);}
	};
	#define Point Vector2
	Point Projection(Point P,Point L1,Point L2)
	{
		long double k1=(L2-L1)*(P-L1),k2=(L2-L1).norm2();
		return L1+((L2-L1)*(k1/k2));
	}
	Point Reflection(Point P,Point L1,Point L2)
	{
		long double k1=(L2-L1)*(P-L1),k2=(L2-L1).norm2();
		Point mid=L1+(L2-L1)*(k1/k2);
		return mid*2-P;
	}
	#define COUNTER_CLOCKWISE 1
	#define CLOCKWISE 2
	#define ONLINE_BACK 3
	#define ONLINE_FRONT 4
	#define ON_SEGMENT 5
	int Counter_Clockwise(Point S,Point T1,Point T2)
	{
		if(((T1-S)^(T2-S))>eps) return COUNTER_CLOCKWISE;
		else if(((T1-S)^(T2-S))<-eps) return CLOCKWISE;
		else if(((T1-S)*(T2-S))<-eps) return ONLINE_BACK;
		else if(((T2-S).norm2()-(T1-S).norm2())>eps) return ONLINE_FRONT;
		else return ON_SEGMENT;
	}
	
};
using namespace Computational_Geometry;
Point P0,P1,P;
int Q;
int main()
{
	P0.read(),P1.read();
	scanf("%d",&Q);
	while(Q--)
	{
		P.read();
		int Ans=Counter_Clockwise(P0,P1,P);
		if(Ans==COUNTER_CLOCKWISE) puts("COUNTER_CLOCKWISE");
		else if(Ans==CLOCKWISE) puts("CLOCKWISE");
		else if(Ans==ONLINE_BACK) puts("ONLINE_BACK");
		else if(Ans==ONLINE_FRONT) puts("ONLINE_FRONT");
		else puts("ON_SEGMENT");
	}
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;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--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    map<string, int> x;
    rep(i, N){
        string y; cin >> y;
        if (x.find(y) != x.end()){
            x[y] += 1;
        } else {
            x[y] = 1;
        }
    }
    cout << x.size() << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 19244
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S, T;
	cin >> S >> T;
	int N = S.size();
	int M = T.size();
	int ans = 0;
	rep(i,N-M+1){
		int cnt = 0;
		rep(j,M){
			if(S[j+i] == T[j]) ++cnt;
		}
		ans = max(ans, cnt);
	}
	cout << M - ans << endl;
}

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

main(){

ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);



long long i,j,k,l,m,n;

while(cin>>m>>n){

if(m*500>=n)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

 return 0;
}


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

int main(void)
{
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    
    int cut = 1;
    int grad = 0;
    for(int i = 1; i < N; i++){
        if(A[i] == A[i-1]) continue;
        int neg = (A[i] > A[i-1]) ? 1 : -1;
        if(grad == 0) grad = neg;
        if(neg == grad) continue;
        else {
            cut++;
            grad = 0;
        }
    }

    cout << cut << endl;

    return 0;
}


Measured memory_bytes: 3748
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt2() (int, int) {
	return nextInt(), nextInt()
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x := nextInt()
	if x == 0 {
		puts(1)
	} else {
		puts(0)
	}
}


Measured memory_bytes: 1784
#include<iostream>
using namespace std;
int main()
{
    int n,a,b,j;
    cin>>n>>a>>b;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
         j=i;
        int sum1=0;
        while(j>0)
        {
            int x=j%10;
            j=j/10;
            sum1=sum1+x;
        }
        if(sum1>=a && sum1<=b)
             sum=sum+i;

    }
    cout<<sum<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int d[n][2];
    bool ans = false;
    for(int i = 0; i < n; i++)
        cin >> d[i][0] >> d[i][1];
    for(int i = 0; i < n - 2; i++)
        if(d[i][0] == d[i][1] && d[i + 1][0] == d[i + 1][1] && d[i + 2][0] == d[i + 2][1])
            ans = true;
    if(ans)
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n,m;
  cin >> n >> m;
  int a[m],b[m];
  vector<int> g[n];
  rep(i,m){
    cin >> a[i] >>b[i];
    a[i]--;b[i]--;
    g[a[i]].pb(b[i]);
    g[b[i]].pb(a[i]);
  }
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int v=q.front();q.pop();
    //    cout << v << endl;
    if(v==0){
      for(auto i:g[v]){
	q.push(i);	
      }
    }
    else{
      for(auto i:g[v]){
	if(i==n-1){
	  cout <<"POSSIBLE" << endl;
	  return 0;
	}
      } 
    }
  }
  cout << "IMPOSSIBLE" << endl;

  
  return 0;
    

}


Measured memory_bytes: 13936
import java.util.Scanner;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] d = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
		Arrays.sort(d);
		int ans = 1;
		for (int i = N - 1; i > 0; i--) {
			if (d[i] > d[i - 1])
				ans++;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	
	n,k := scanInt(),scanInt()

	maxk := (n-2+1)*(n-2)/2
	maxm := (n-1+1)*(n-1)/2

	if maxk < k {
		fmt.Println(-1)
		return
	}

	m := maxm-k
	fmt.Println(m)

	c := 0
	for i := 1; i < n+1; i++ {
		for j := i+1; j < n+1; j++ {
			if c < k && j != n{
				c++
				continue
			}
			fmt.Println(i,j)
		}
	}
}


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


void solve(long long N, std::vector<long long> A){
    long long ans = 1;
    for(auto a: A){
        if(a%2==0) ans *= 2;
        else ans *= 1;
    }
    cout << pow(3, A.size()) - ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 256