akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

struct UnionFind {
    
    vector < int > node;
    UnionFind(int n) : node(n, -1) {}
    
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (node[y] < node[x]) swap(x, y);
            node[x] += node[y];
            node[y] = x;
        }
        return x != y;
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    int root(int x) {
        return node[x] < 0 ? x : node[x] = root(node[x]);
    }
    
    int size(int x) {
        return -node[root(x)];
    }
    
};
/*
 usage:
 
 初期化:
 UnionFind  UF(N);//ノードの数
 unite(x,y);// xとyノード連結
 same(a,b);// aとbが同じ所属かどうかを判別
 root(a); //aのルートのノードを計算
 */

ll N , M ;
vector<ll> rut;

map<ll, vector<pair<ll,ll> > >to;
ll ans[100005];


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    rep(i,100005) ans[i] = -1e18;// initialize

    cin >> N >> M ;

    
    UnionFind UF(N);
    
    rep(i,M){
        ll l, r , d;
        cin >> l >> r >> d;
        l--; r--;
        
        UF.unite(l,r);
        to[l].pb(mp(r, d));
        to[r].pb(mp(l, d*(-1)));
    }
    
    rep(i,N){
        rut.pb(UF.root(i));
    }
    rmsame(rut);

    rep(i, rut.size()){
        ans[rut[i]] = 0;
    }
    
    while(rut.size() != 0){
        ll siz = rut.size();

        rep(i,siz){
            ll now = rut[0];
            rep(j, to[now].size()){
                ll next = to[now][j].first;
                ll dis = to[now][j].second;
                if(ans[next] == -1e18){
                    ans[next] = ans[now] + dis;
                    rut.pb(next);
                }
                else{
                    if(ans[next] != ans[now] + dis){
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
            rut.erase(rut.begin());
        }
    }
    cout << "Yes" << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 21240
#include <iostream>
#include <string>
#include <stdio.h>

int main(void){
    std::string weather;
    std::cin >> weather;
    if (weather == "Sunny"){
        std::cout << "Cloudy" << std::endl;
    } else if (weather == "Cloudy"){
        std::cout << "Rainy" << std::endl;
    } else if (weather == "Rainy"){
        std::cout << "Sunny" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a)cout<<k<<endl;
  else if(k>a&&(k-a)<=b)cout<<a<<endl;
  else if((k-a-b)>=c)cout<<a-c<<endl;
  else if((k-a-b)<c)cout<<2*a+b-k<<endl;

  
}

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

int GCD(int a, int b){
    if(b){
        return GCD(b, a % b);
    }else{
        return a;
    }
}

int GCD_back(int a, int b){
    return GCD(max(a, b), min(a, b));
}

int main(){
    int N, K;
    cin >> N >> K;
    int GCD_all;
    cin >> GCD_all;
    int max_all = GCD_all;
    for(int i = 1; i < N; i++){
        int num;
        cin >> num;
        max_all = max(max_all, num);
        GCD_all = GCD_back(GCD_all, num);
    }
    if(K % GCD_all == 0 && K <= max_all){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 384
str = gets.split
N,Y = str[0].to_i, str[1].to_i/1000

y = Y - N
if y / 9.0 > N || y < 0
  puts("-1 -1 -1")
  exit(0)
end
r = y%4
if r > y/8 || r > N
  puts("-1 -1 -1")
  exit(0)
end
a = r
b = y/4 - a*2
c = N - a - b
if c < 0
  d = b/9
  b = b%9
  a += d*4
  c += d*5
  if c < 0
    puts("-1 -1 -1")
    exit(0)
  end
end
print(a," ",b," ",c)
puts()

Measured memory_bytes: 3836
import itertools
import bisect

N = int(input())
L = list(map(int, input().split(' ')))

L = sorted(L)

count = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        x, y = L[i], L[j]
        limit = x + y
        index = bisect.bisect_left(L, limit)
        count += max(0, index - j - 1)

print(count)

Measured memory_bytes: 3188
n=int(input())
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
ans=0
for i in range(n):
    top=sum(a1[:i+1])
    bottom=sum(a2[i:])
    tmp=top+bottom
    ans=max(tmp,ans)
print(ans)

Measured memory_bytes: 3060
n = gets.to_i
a = gets.split(" ").map(&:to_i)
sum=0

sum_tmp=0

a[0]=a[0]%(1000000007)

for i in 1..n-1
  a[i]=a[i]%(1000000007)
  sum_tmp+=a[i]
end

for i in 0..n-2
  sum=(sum+a[i]*(sum_tmp))
  sum_tmp=sum_tmp-a[i+1]
end
sum=sum%(1000000007)

puts sum

Measured memory_bytes: 33712
import sys

input = sys.stdin.readline

# input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


def main():
    a = int(input())
    s = input()

    if a >= 3200:
        print(s)
    else:
        print('red')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
n, k = list(map(int,input().split()))

if n <= k//2:
  print(n)
elif n < k:
  print(k-n)
elif n == k:
  print(0)
else:
  plus = n-n//k*k
  minus = abs(n-n//k*k-k)
  print(min(plus,minus)) 

Measured memory_bytes: 9124
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N, M, C;
int A[100][100], B[100];

void input() {
  cin >> N >> M >> C;
  loop(m,0,M) cin >> B[m];
  loop(n,0,N) loop(m,0,M) {
    cin >> A[n][m];
  }
}

void solve() {
  int count = 0;
  loop(n,0,N) {
    int sum = C;
    loop(m,0,M) {
      sum += A[n][m] * B[m];
    }
    count += sum > 0;
  }
  cout << count << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    string s;
    int k;
    cin >> s >> k;
    int n = s.length();
    set<string> S;
    for(int i = 0; i < n; ++i){
        for(int j = 1; j <= k; ++j){
            if(i + j > n)   break;
            S.insert(s.substr(i, j));
        }
    }
    auto it = S.begin();
    int cnt = 0;
    while(cnt < k){
        if(++cnt == k){
            cout << *it << endl;
            return 0;
        }
        else{
            ++it;
        }
    }
}

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

#define ll long long
#define pll pair<ll, ll>
#define vll vector<ll>
#define rep(x, l, r) for (x = l; x < r; x++)

const ll mod=1000000007;


void solve()
{
	ll i, j, k, l, m, n, x, y, u, v, r, p,a,b,d;
	string s,t;
    cin>>s>>t;
    ll ans=0;
    i=0;
    n=(ll)s.size();
    while(i<n){
        if(s[i]!=t[i]) ans++;
        i++;
    }
    cout<<ans;

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
//    cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N;

int main(void){
    
    scanf("%d", &N);
    vector<int> v(8, 0);
    int w = 0;
    for(int i = 0; i < N; ++i){
        int a; scanf("%d", &a);
        if(1 <= a && a <= 399) ++v[0];
        else if(400 <= a && a <= 799) ++v[1];
        else if(800 <= a && a <= 1199) ++v[2];
        else if(1200 <= a && a <= 1599) ++v[3];
        else if(1600 <= a && a <= 1999) ++v[4];
        else if(2000 <= a && a <= 2399) ++v[5];
        else if(2400 <= a && a <= 2799) ++v[6];
        else if(2800 <= a && a <= 3199) ++v[7];
        else ++w;
    }
    
    int cnt = 0;
    for(int i = 0; i < v.size(); ++i) if(v[i]) ++cnt;
    
    if(w){
        if(cnt) printf("%d %d\n", cnt, cnt + w);
        else printf("%d %d\n", 1, w);
    }
    else printf("%d %d\n", cnt, cnt);
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int h[100000+10];
    int n, k, nr=0;
    cin>>n>>k;
    for (int i=1; i<=n; i++)
    {
        cin >> h[i];
        if(h[i]>=k)
        {
            nr++;
        }
    }
    cout<<nr;
    return 0;
}


Measured memory_bytes: 640
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {

			int n = sc.nextInt();
			int m = sc.nextInt();
			if (n == 0 && m == 0) {
				break;
			}
			String b[] = new String[n];

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

			Map<String, Integer> map = new HashMap<String, Integer>();
			map.put(zero(m), 0);

			for (int i = 0; i < n; i++) {
				Map<String, Integer> next = new HashMap<String, Integer>();

				next.putAll(map);
				for (Entry<String, Integer> e : map.entrySet()) {
					String str = xor(e.getKey(), b[i]);
					int value = e.getValue()+1;
					if(!next.containsKey(str) || value > next.get(str) ){
						next.put(str, e.getValue()+1);
					}
				}
				
				map = next;
			}
			System.out.println(map.get(zero(m)));
		}
	}

	String zero(int m) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < m; i++) {
			sb.append("0");
		}
		return sb.toString();
	}

	String xor(String a, String b){
		StringBuilder sb =new StringBuilder();
		for(int i =0 ; i< a.length() ;i++){
			if(a.charAt(i) == b.charAt(i)){
				sb.append("0");
			}else{
				sb.append("1");
			}
		}
		return sb.toString();
		
	}
}



Measured memory_bytes: 626668
#include<bits/stdc++.h>
using namespace std;
long long x,y;
int main()
{
	cin>>x>>y;
	long long ans=0;
	if(x<=y) ans++;
	while(1)
	{
		x=x*2;
		if(x<=y) ans++;
		else break;
	}
	cout<<ans;
}

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

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 3000 + 5;

/***************************************************************************/

ld P[N];
ld dp[N][N];

int main() {

	boost;
	int n; cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>P[i];
	}
	dp[0][0] = 1;
	for(int i=1; i<=n; i++) {
		dp[i][0] = dp[i-1][0] * (1 - P[i]);
		for(int j=1; j<=i; j++) {
			dp[i][j] = dp[i-1][j] * (1 - P[i]) + dp[i-1][j-1] * P[i];
		}
	}
	ld ans = 0;
	for(int i=n/2+1; i<=n; i++) {
		ans += dp[n][i];
	}
	cout<<setprecision(15)<<fixed<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 69120
import java.util.Scanner;

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

        String[] split = line.split(" ");
        
        System.out.println(calculate(Integer.parseInt(split[0]), Integer.parseInt(split[1])));
	}
	
	public static int calculate(int apples, int pieces) {
		
		
		return (apples*3 + pieces)/2;
	}
}


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

int main(){
    int K,X; cin >> K >> X;
    if(500 * K >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define N 100000

int main(void){
    vector<bool> prime(N+1,true);
    prime[0]=prime[1]=false;
    const int sqrtN = sqrt(N);
    for (size_t i = 2; i <= sqrtN; i++)
    {
        if (prime[i])
        {
            for (size_t j = 2; i*j <= N; j++)
            {
                prime[i*j]=false;
            }
        }
    }
    int likeCnt[N+1];
    for (size_t i = 3; i <= N; i+=2)
    {
        likeCnt[i]=likeCnt[i-1];
        if (i%2==1&&prime[i]&&prime[(i+1)/2]) likeCnt[i]++;
        likeCnt[i+1]=likeCnt[i];
    }
    /**************************************/
    int q;
    scanf("%d", &q);
    int l,r;
    for (size_t i = 0; i < q; i++)
    {
        scanf("%d%d", &l, &r);
        printf("%d\n", likeCnt[r] - likeCnt[l-1]);
    }
    return 0;
}

Measured memory_bytes: 1024
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    K, S = li_input()

    ans = 0

    for X in range(K+1):
        for Y in range(K+1):
            Z = S - X - Y

            if 0 <= Z <= K:
                ans += 1
    
    print(ans)


main()


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

struct card{
   char suit;
   int value;
};

const int SENTINEL=2000000000;
int cnt=0;
void merge(card A[],int n,int left,int mid,int right){
	int n1=mid-left;
	int n2=right-mid;
	card *L=new card[n1+1];
	card *R=new card[n2+1];
	for(int i=0;i<n1;++i) L[i]=A[left+i];
	for(int i=0;i<n2;++i) R[i]=A[mid+i];
	L[n1].value=R[n2].value=SENTINEL;
    int i=0,j=0;
    for(int k=left;k<right;k++){
    	cnt++;
    	if(L[i].value<=R[j].value)A[k]=L[i++];
    	else A[k]=R[j++];
    }
    delete L;
    delete R;

}
void mergeSort(card A[],int n,int left,int right){
   if(left+1<right){
   		int mid=(left+right)/2;
   		mergeSort(A,n,left,mid);
   		mergeSort(A,n,mid,right);
   		merge(A,n,left,mid,right);
   }
}

int  partition(card A[],int n,int p,int r){
	int i=p;
	card x=A[r];
	for(int j=p;j<r;j++){
		if(A[j].value<=x.value){
			
			card t=A[j];
			A[j]=A[i];
			A[i]=t;
			++i;
		}
	}
	A[r]=A[i];
	A[i]=x;

	return i;
}
void quickSort(card A[],int n,int p,int r){
	if(p<r){
		int q=partition(A,n,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}

int main(){
	int n;
	cin>>n;
	card *A=new card[n];
	card *B=new card[n];

	for(int i=0;i<n;i++){
		cin>>A[i].suit>>A[i].value;
		B[i]=A[i];
    }
    
    quickSort(A,n,0,n-1);
    mergeSort(B,n,0,n);
    int stable=1;
    for(int i=0;i<n;i++){
    	if(A[i].suit != B[i].suit ) {
    		stable=0;break;
    	}
    }

    if(stable==1)cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;

    for(int i=0;i<n;i++){
       	cout<<A[i].suit<<" "<<A[i].value<<endl;
    }

    

    return 0;
}


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


int main()
{

        int n;
        scanf("%d", &n);
        map< int, int > mp;
        vector<int>v;
        for(int i = 0; i < n ; i++) {
                int x;
                scanf("%d", &x);
                v.push_back(x);
                mp[x]++;
        }

        long long ret = 0LL;

        for(int x : v) {
                if(mp[x] >= 2) {
                        ret = max(ret, (long long) x  );
                }
        }

        if(ret) {
                mp[ret] -= 2;
        }

        long long ret2 = 0LL;

        for(int x : v) {
                if(mp[x] >= 2) {
                        ret2 = max( ret2, (long long) x );
                }
        }

        cout << ret*ret2 << "\n";





        return 0;
}


Measured memory_bytes: 5368
d = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
N = int(input())
for i in range(N):
    d[input()] += 1
print("AC x "+str(d["AC"]))
print("WA x "+str(d["WA"]))
print("TLE x "+str(d["TLE"]))
print("RE x "+str(d["RE"]))


Measured memory_bytes: 9128
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long N, std::vector<long double> x, std::vector<std::string> u){
	long double res = 0;
	for(int i = 0; i < N; ++i) {
		if (u[i] == "JPY") {
			res += x[i];
		} else {
			res += x[i] * 380000;
		}
	}
	printf("%.10Lf\n", res);
}

signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long double> x(N);
    std::vector<std::string> u(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%Lf",&x[i]);
        std::cin >> u[i];
    }
    solve(N, std::move(x), std::move(u));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    int A[N];
    cins(A, A + N);
    pair<int, int> nums[N];
    for(int i = 0; i < N; i++){
        nums[i] = {A[i], i};
    }
    sort(nums, nums + N, greater<>());
    int ans[N];
    for(int i = 0; i < N; i++){
        if(i != nums[0].second){
            ans[i] = nums[0].first;
        }else{
            ans[i] = nums[1].first;
        }
        cout << ans[i] << endl;
    }
}


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


int main(void){
  int n;
  int ans=0;
  int sum=0;
  int a[2][110];
  cin >> n;
  for(int i=0; i<2; i++){
    for(int j=0; j<n; j++){
      cin >> a[i][j];
    }
  }

  for(int k=0; k<n; k++){
    sum=0;
    for(int j=0; j<=k; j++){
      sum+=a[0][j];

    }
    for(int j=n-1; j>=k; j--){
      sum+=a[1][j];
    }
    if(ans<sum){
      ans=sum;
    }
  }


  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;
whei(int) G;
whei(bool) b;
int main() {
	int n, m;
	cin >> n >> m;
	G.resize(n);
	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(b);
	}
	int s, t;
	cin >> s >> t;
	s--;
	t--;
	queue<Pint> que;
	que.push(Pint(s,0));
	whei(int) dist(n,hei(int)(3,-1));
	dist[s][0] = 0;
	while (!que.empty()) {
		Pint p = que.front();
		que.pop();
		for (int x : G[p.first]) {
				if (dist[x][(p.second+1)%3]!= -1)continue;
				dist[x][(p.second+1)%3] = dist[p.first][p.second] + 1;
				que.push(Pint(x,(p.second+1)%3));
		}
	}

	int ans = dist[t][0];
	if (ans != -1)ans /= 3;
	cout << ans << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;

ifstream fin ("hps.in");
ofstream fout ("hps.out");

#define f first
#define s second
#define pb push_back

int h, n, a, sum;


int main()
{
  cin >> h >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    sum += a;
  }
  cout << (h <= sum ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
//Created by Aminul on 8/22/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        long n = in.nextInt(), x = in.nextInt(), t = in.nextInt();
        long res = (n / x) * t;
        if(n % x != 0) res += t;
        pw.println(res);

        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

Measured memory_bytes: 27132
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//C++17以上
template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
    int n;cin >> n;
    vector<int> p(n);
    rep(i,n)cin >> p[i];
    vector<int> ord(n);
    iota(ALL(ord),1);
    int count = 0;
    rep(i,n){
        if(p[i]!=ord[i])count++;
    }
    if(count<=2)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
	ll n;
	cin >> n;
	ll a[n];
	for(int i=0;i<n;i++) {
		cin >> a[i];
	}
	ll hash[200005]={0};
	for(int i=0;i<n;i++) {
		hash[a[i]]++;
	}
	ll sum = 0;
	for(int i=0;i<200005;i++) {
		if(hash[i]>=1) {
			sum +=  (hash[i]*(hash[i]-1))/2;
		}
	}	
	for(int i=0;i<n;i++) {
		int x = a[i];
		if(hash[x]>2) {
			ll ans = sum - (hash[x]*(hash[x]-1))/2 + ((hash[x]-1)*(hash[x]-2))/2;
			cout << ans <<endl;
		}
		else if(hash[x]==2) {
			ll ans = sum - (hash[x]*(hash[x]-1))/2;
			cout << ans <<endl;
		}
		else {
			ll ans = sum;
			cout << sum <<endl;
		}
	}
	
}

signed main() {
	boost;
	solve();
}

Measured memory_bytes: 5760
/*package whatever //do not write package name here */

import java.util.*;

class Main{
	public static void main (String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	    int arr[]=new int[n];
	    for(int i=0;i<n;i++)
	    arr[i]=sc.nextInt();
	    int dp[]=new int[100];
	    System.out.println(frog(arr,arr.length));
	}
static int frog(int arr[],int n)
{
    int dp[]=new int[n];
    for(int i=1;i<n;i++)
    {
        int option1=Math.abs(arr[i]-arr[i-1])+dp[i-1];
        int option2=(i==1)?Integer.MAX_VALUE:Math.abs(arr[i]-arr[i-2])+dp[i-2];
        dp[i]=Math.min(option1,option2);
    }
    return dp[n-1];
}
}

Measured memory_bytes: 49928
#include<stdio.h>
int main(void){
  long long n,i,ans=0,t;
  scanf("%lld",&n);
  while(n--){
    scanf("%lld",&i);
    while((i%2)==0){
      ans++;
      i/=2;
    }
  }
  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <ctype.h>

int main(void){
  char ch;
  int chi;

  while(1){
    scanf("%c", &ch);
    chi = (int)ch;
    if(isupper(chi)){
      chi = tolower(chi);
    }else if(islower(chi)){
      chi = toupper(chi);
    }
    ch = (char)chi;
    printf("%c", ch);
    if(ch == '\n')  break;
  }
  return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	int n, a[100];
	vector<long long> dp(21);

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

	dp[a[0]] = 1;
	for (int i = 1; i < n - 1; ++i) {
		vector<long long> temp = dp;
		fill(dp.begin(), dp.end(), 0LL);
		for (int j = 0; j <= 20; ++j) {
			if (temp[j] > 0) {
				if (j - a[i] >= 0)
					dp[j - a[i]] += temp[j];
				if (j + a[i] <= 20)
					dp[j + a[i]] += temp[j];
			}
		}
	}

	cout << dp[a[n - 1]] << endl;

	return 0;
}

Measured memory_bytes: 3156
#include <iostream>
using namespace std;
int main(){
	string s;
	cin >> s;

	string ans="Good";
	for(int i=0;i<s.length()-1;i++){
		if(s[i]==s[i+1]){
			ans="Bad";
			break;
		}
	}

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

Measured memory_bytes: 256
let () =
  let x = read_line () in
  Array.init (String.length x) (fun i -> x.[i])
  |> Array.fold_left (fun (h, m) -> function
    | 'S' -> (h + 1, m)
    | 'T' -> (h - 1, min m (h - 1))) (0, 0)
  |> (fun (h, m) ->
      let offset = min 0 m in
      let correct = h - offset in
      Printf.printf "%d\n" @@ correct - offset)

Measured memory_bytes: 6400
#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 = 1e8;

signed main() {
	int N, M;
	cin >> N;
	map<string, int>m;
	string s;
	rep(i, N) {
		cin >> s;
		m[s]++;
	}
	cin >> M;
	rep(i, M) {
		cin >> s;
		m[s]--;
	}
	int mx = -1e5;
	for (auto i : m)mx = max(mx, i.second);
	cout << max(0ll, mx);
}

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

using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int H, W;
vector<vector<int> > field;
vector<vector<bool> > used;

int main() {
    cin >> H >> W;
    field.assign(H, vector<int>(W));
    used.assign(H, vector<bool>(W, false));
    int count=0;
    for(int h=0; h<H; h++) {
        for(int w=0; w<W; w++) {
            cin >> field[h][w];
            if(field[h][w]%2!=0) {
                count++;
            }
        }
    }
    
    vector<pair<pair<int, int>, pair<int, int> > > ans;
    for(int h=0; h<H; h++) {
        if(h%2==0) {
            for(int w=0; w<W; w++) {
                if(field[h][w]%2==0) continue;

                if(w<W-1) {
                    ans.push_back(make_pair(make_pair(h+1, w+1), make_pair(h+1, w+2)));
                    field[h][w]--;
                    field[h][w+1]++;
                } else {
                    if(h+1>=H) continue;
                    ans.push_back(make_pair(make_pair(h+1, w+1), make_pair(h+2, w+1)));
                    field[h][w]--;
                    field[h+1][w]++;
                }
            }
        } else {
            for(int w=W-1; w>=0; w--) {
                if(field[h][w]%2==0) continue;
                
                if(w>0) {
                    ans.push_back(make_pair(make_pair(h+1, w+1), make_pair(h+1, w)));
                    field[h][w]--;
                    field[h][w-1]++;
                } else {
                    if(h+1>=H) continue;
                    ans.push_back(make_pair(make_pair(h+1, w+1), make_pair(h+2, w+1)));
                    field[h][w]--;
                    field[h+1][w]++;
                }
            }
        }
    }
    
    cout << ans.size() << endl;
    for(int ai=0; ai<ans.size(); ai++) {
        cout << ans[ai].first.first << " ";
        cout << ans[ai].first.second << " ";
        cout << ans[ai].second.first << " ";
        cout << ans[ai].second.second << endl;
    }


    return 0;
    
}

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

const ll INF = -100000000000000;
ll dp[100001];//dp[i]ちょうどi本のマッチ棒を用いて，作れる最大の桁数
ll N,M,A[9];
ll SIZE[10] = {0,2,5,5,4,5,6,3,7,6};

int main(void){
    cin >> N >> M;
    rep(i,M)cin>>A[i];
    sort(A,A+M,greater<ll>());
    fill(dp,dp+N+1,INF);
    dp[0] = 0;
    
    for(ll i=1;i<=N;i++){
        rep(j,M){
            if(dp[i-SIZE[A[j]]] != INF && i>=SIZE[A[j]])dp[i] = max(dp[i],dp[i-SIZE[A[j]]]+1);
        }
    }
    //一桁ずつ確定していく
    ll i = N;
    while(i>0){
        rep(j,M){
            if(i>=SIZE[A[j]] && dp[i] == dp[i-SIZE[A[j]]]+1){
                cout << A[j];
                i -=SIZE[A[j]];
                break;
            }
        } 
    }
    cout << endl;
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

from collections import Counter

c = Counter(a)

c = [(length,cnt) for length,cnt in sorted(c.items(), key=lambda x:(-x[0], -x[1])) if cnt>=2]
if len(c)<2:
    print(0)
else:
    if c[0][1]>=4:
        print(c[0][0]*c[0][0])
    else:
        print(c[0][0]*c[1][0])

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

int main() {
  int n;
  cin>>n;
  vector<int>a(n),l(n),r(n);
  rep(i,n){
    cin>>a.at(i);
  }
  l.at(0)=a.at(0);
  r.at(n-1)=a.at(n-1);
  rep2(i,1,n){
    l.at(i)=__gcd(l.at(i-1),a.at(i));
  }
  for(int i=n-2;i>=0;i--){
    r.at(i)=__gcd(r.at(i+1),a.at(i));
  }
  int ans=max(l.at(n-2),r.at(1));
  rep2(i,1,n-1){
    ans=max(ans,__gcd(l.at(i-1),r.at(i+1)));
  }
  cout<<ans<<endl;
}
            

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 2000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int fie[501][501];
int res[2][501][501];
bool used[501][501];
int h,w;


int main(void){
	scanf("%d%d%*c",&h,&w);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char c;
			scanf("%c",&c);
			fie[i][j]=(c=='#');
		}
		scanf("%*c");
	}
	int color=0;
	for(int i=0;i<h;i++){
		res[0][i][0]=1;
		res[1][i][w-1]=1;
		for(int j=1;j<w-1;j++){
			res[i%2][i][j]=1;
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			printf("%c",(fie[i][j] || res[0][i][j])==1?'#':'.');
		}
		printf("\n");
	}
	printf("\n");
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			printf("%c",(fie[i][j] || res[1][i][j])==1?'#':'.');
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3712
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> Int -> VU.Vector Int -> Int
solve !n !m !ws = (\(x, _, _) -> x) $ foldl'
  ( \(!p, !pp, wn) !n -> if not (null wn) && head wn == n
    then (0, p, tail wn)
    else ((p + pp) `mod` 1000000007, p, wn)
  )
  (1, 0, VU.toList ws)
  [1 .. n]

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, m) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  an <-
    VU.replicateM m $ (\vec -> vec VU.! 0) . VU.unfoldrN 1 readInt <$> B.getLine
  print $ solve n m an


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

string s;
ll ans, n, t, rem[2020], mul = 1;

int main() {
	fastio; cin >> s;
	n = s.length(); s = " " + s;
	rem[0] = 1; t = 0;
	DEC(i, n, 1) {
		t = (t + mul*(s[i]-'0')) % 2019;
		rem[t]++; mul = (10*mul) % 2019;
	}
	FOR(i, 0, 2018) ans += (rem[i] * (rem[i]-1))/2;
	cout << ans;
}


Measured memory_bytes: 3780
n = int(input())
a = [input() for _ in range(n)]
al = [[0]*26 for _ in range(n)]
alph = 'abcdefghijklmnopqrstuvwxyz'
for i,s in enumerate(a):
    for k in s:
        al[i][alph.index(k)] += 1

ans = ''
for i in range(26):
    cnt = float('inf')
    for j in range(n):
        cnt = min(cnt, al[j][i])
    ans += alph[i]*cnt
print(ans)


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

class union_find {
  vector<int> data;
  
public:
  void init(int size) {
    data.assign(size, -1);
  }
  
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  
  int find(int k) {
    if (data[k] <  0) return k;
    return data[k] = find(data[k]);
  }
  
  int size(int k) {
    return -data[find(k)];
  }
  
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main(void) {
  int n, k, l;
  map<pair<int, int>, int> cnt;
  union_find roads, rails;
  
  cin >> n >> k >> l;
  roads.init(n);
  rails.init(n);
  
  for (int i = 0; i < k; i++) {
    int p, q;
    cin >> p >> q;
    p--; q--;
    roads.unite(p, q);
  }
  
  for (int i = 0; i < l; i++) {
    int r, s;
    cin >> r >> s;
    r--; s--;
    rails.unite(r, s);
  }
  
  for (int i = 0; i < n; i++) {
    int a = roads.find(i), b = rails.find(i);
    cnt[{a, b}]++;
  }
  
  for (int i = 0; i < n; i++) {
    int a = roads.find(i), b = rails.find(i);
    cout << cnt[{a, b}] << (i != n - 1 ? ' ' : '\n');
  }
  cout << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


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

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(void){
	int N,M;
	ll result=1;
	cin>>N>>M;
	if(abs(N-M)>1){
		result=0;
	}else if(abs(N-M)==1){
		FOR(i,2,M+1) result=(result*i)%MOD;
		FOR(i,2,N+1) result=(result*i)%MOD;
	}else{
		FOR(i,2,M+1) result=(result*i)%MOD;
		FOR(i,2,N+1) result=(result*i)%MOD;
		result=(result*2)%MOD;
	}
	printf("%lld\n",result);
	return 0;
}



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
ll MOD = 1e+9 + 7;

// A:3, B:2 => A B A B A
// A:3, B:3 => A B A B A B , B A B A B A
// A:4, B:2 => A B A B A A

int main() {
    ll n, m;
    cin >> n >> m;

    if (abs(n - m) == 0) {
        ll ans = 1;
        for (ll i = n; i > 0; i--) {
            ans *= i;
            ans %= MOD;
            ans *= i;
            ans %= MOD;
        }
        ans *= 2;
        ans %= MOD;
        cout << ans << endl;
    } else if (abs(n - m) == 1) {
        ll ans = 1;
        for (ll i = n; i > 0; i--){
            ans *= i;
            ans %= MOD;
        }
        for (ll i = m; i > 0; i--){
            ans *= i;
            ans %= MOD;
        }

        cout << ans << endl;

    } else {
        cout << 0 << endl;
    }

    return 0;
}


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

using namespace std;

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

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

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

ll A[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X, N;
    cin >> X >> N;
    REP(i, N) {
        cin >> A[i];
    }

    ll ans = -1;
    for (ll n = -1; n <= 101; ++n) {
        bool e = true;
        REP(i, N) {
            if (A[i] == n)
                e = false;
        }
        if (!e)
            continue;

        if (abs(X - n) < abs(X - ans))
            ans = n;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
w, h, n = map(int, input().split())

x_min = 0
x_max = w
y_min = 0
y_max = h

for _ in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    x_min = max(x_min, x)
  elif a == 2:
    x_max = min(x_max, x)
  elif a == 3:
    y_min = max(y_min, y)
  else:
    y_max = min(y_max, y)

print(
  (x_max - x_min) * (y_max - y_min)
  if x_min < x_max and y_min < y_max else 0
)


Measured memory_bytes: 62740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;


int main(){
    char S[200100];
    scanf("%s", S);
    int N = strlen(S);
    int B = 0;
    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == 'B')B++;
        else ans += B;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(){
 int h,m,s,S;
 scanf("%d",&S);

 if(S < 0 || 86400 <= S){
  return 0;
 }
 
 h = S / 3600;
 m = (S % 3600) / 60;
 s = S % 60;

 printf("%d:%d:%d\n",h,m,s);
 return 0;
}


Measured memory_bytes: 2048
package main

import (
    "fmt"
    "math"
)

func main() {
    var n, m, ans int
    mod := 1000000007

    fmt.Scan(&n, &m)

    ans = 1
    if math.Abs(float64(n-m)) >= 2 {
        ans = 0
    } else {
        for i := 1; i <= n; i++ {
            ans *= i
            ans %= mod
        }
        for i := 1; i <= m; i++ {
            ans *= i
            ans %= mod
        }
    }
    if n == m {
        ans *= 2
        ans %= mod
    }
    fmt.Println(ans)
}

Measured memory_bytes: 512
from fractions import gcd

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(numbers):
    t = 1
    for n in numbers:
        t = lcm_base(t, n)
    return t

N = int(input())
A = [int(x) for x in input().split()]

mod = 10**9+7
ans = 0
t = lcm(A)
t %= mod
for i in range(N):
    ans = (ans + t*pow(A[i],mod-2, mod))%mod

print(ans)


Measured memory_bytes: 69384
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    string s, t;
    cin>>s>>t;
    int n = s.size();
    int m = t.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1,0));
    for(int i = 1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(s[i-1] == t[j-1])
                dp[i][j] = 1 + dp[i-1][j-1];
            else
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            
        }
    }
    
    string ans = "";
    int i = n, j = m;
    while(i>=1 && j>=1)
    {
        if(s[i-1] == t[j-1])
        {
            ans += s[i-1];
            i--;
            j--;
        }
        else
        {
            if(dp[i-1][j] > dp[i][j-1])
                i--;
            else
                j--;
        }
            
    }
    reverse(ans.begin(), ans.end());
    cout<<ans<<"\n";
    // cout<<dp[n][m]<<"\n";
	return 0;
}


Measured memory_bytes: 38564
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9

vector<int> dijk(int s, int v, vector<vector<pair<int, int> > > adjlist){
    
    priority_queue <pair<int, int> > wait;
    vector<int> result(v, INF);

    //スタート地点を追加
    result[s] = 0;
    wait.push(make_pair(0, s));

    //ダイクストラ本体
    while(!wait.empty()){    //waitが空になるまで

        int nowpoint = wait.top().second;
        int nowcost = -wait.top().first;
        wait.pop();

        if(result[nowpoint] < nowcost) continue;


        //今いる頂点と隣接しているすべての頂点をなめる
        for(int i = 0; i < adjlist[nowpoint].size(); i++){

            int nextpoint = adjlist[nowpoint][i].second;
            int nextcost = nowcost + adjlist[nowpoint][i].first;
            //現時点より安く到達できそうであれば、結果を更新して優先度付きキューに格納
            if(result[nextpoint] > nextcost){
                result[nextpoint] = nextcost;
                wait.push(make_pair(-nextcost, nextpoint));
            }
        }
    }
    
    return result;         //結果列を返す
}

int dfs(set<int>& S, int now, vector<int>& go, vector<int>& x){

    if(go[now] != -1) return go[now];
    else if(S.find(now) != S.end()){
        go[now] = -2;
        return -2;
    }
    else if(x[now] == 0) return now;
    else{
        S.insert(now);
        go[now] = dfs(S, now + x[now], go, x);
        return go[now];
    }
}

int main(){

    int n; cin >> n;
    vector<int> x(n); 
    for(int i = 0; i < n; i++) cin >> x[i];
    vector<int> go(n, -1);
    for(int i = 0; i < n; i++){
        set<int> S;
        S.insert(i);
        if(x[i] != 0 && go[i] == -1)  go[i] = dfs(S, i + x[i], go, x);
    }

    //for(int i = 0; i < n; i++) cout << go[i] << " ";
    vector<vector<pair<int, int> > > adjlist(n);      //first := コスト　second := 行先

    //入力
    for(int i = 0; i < n; i++){
        if(x[i] == 0) for(int j = 1; j <= 6 && i + j < n; j++){
            if(go[i + j] == -1) adjlist[i].push_back(make_pair(1, i + j));
            else if(go[i + j] != -2) adjlist[i].push_back(make_pair(1, go[i + j]));
        }
    }

    vector<int> result(n);
    result = dijk(0, n, adjlist);
    //cout << result[G] << endl;

    /*for(int i = 0; i < n; i++){
        cout << i << ": " << result[i] << endl;
    }*/

    cout << result[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 16396