akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}

template<typename T>
T gcd(T x, T y){
    if (x == 0 || y == 0) {
        return 0;
    }

    while (x != y){
        if (x > y) {
            x -= y;
        }else{
            y -= x;
        }
    }
    return x;
}

// }}}
/* vim:set foldmethod=marker: */

void solve(){
    string a,b,c;
    cin >> a >> b >> c;


    char A,B,C;
    A = (char)toupper(a[0]);
    B = (char)toupper(b[0]);
    C = (char)toupper(c[0]);

    cout << A << B << C << endl;
    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


// map の key, value を全て抜き出す。
// for (auto itr = mp.begin(); itr != mp.end(); itr++) {
//     cout << "key" << itr->first << " value" << itr->second << endl;
// }

// 文字列の検索
// string s="abc";
// if (s.find('d') == string::npos){
//     cout << "find" << endl;
// }else{
//     cout << "not find" << endl;
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll mod=1e9+7;
string s;ll f[N],dp[N],g[N],p[N];
int n;ll ans=3;
void slove(int id,ll pow){
    if(id<0)return;
    for(int i=id;i>=0;i--){
        if(s[i]=='1'){
            ans+=pow*g[i];//这个地方00
            ans%=mod;
        }else{
            slove(i-1,pow*2%mod);//10or01
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    f[0]=1;for(int i=1;i<=100000;i++)f[i]=f[i-1]*2%mod;
    g[0]=1;for(int i=1;i<=100000;i++)g[i]=g[i-1]*3%mod;
    cin>>s;
    n = s.length();
    reverse(s.begin(),s.end());
//    int cnt=-1;

    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            if(i==0)p[i]=3;
            else p[i]=(p[i-1]*2+g[i])%mod;
        }else{
            if(i==0)p[i]=1;
            else p[i]=p[i-1];
        }
    }
    dp[0]=3;
    for(int i=1;i<n;i++){
        if(i==n-1){
            ans+=p[i]-g[i];
            break;
        }else {
            dp[i] = 2ll * g[i] % mod;
            ans += dp[i];
        }
        dp[i]%=mod;
        ans%=mod;
    }
    cout<<ans%mod<<endl;
}


Measured memory_bytes: 3664
a=-1,A=65,d;
char
*N="GKSOCNWLDFVTBRXHAJUPEMQI",
*E="PHLTIDOXQAGWECSUMBKVJFNR",
*R="BCDAFGHEJKLINOPMRSTQVWXU",
s[9];
main(c)
{
for(;c-48&&scanf("%s",s);a+=d/4+1)
{
(c=*s)<A?~a&&printf("%d\n",a),a=d=0:0;
d=c==78?d=N[d]-A:d;
d=c==69?d=E[d]-A:d;
if(c==82)d=R[d]-A;
if(c==83)d=N[N[N[d]-A]-A]-A;
if(c==87)d=E[E[E[d]-A]-A]-A;
if(c==76)d=R[R[R[d]-A]-A]-A;
}}

Measured memory_bytes: 0
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
$abc = [a,b,c]
$x = gets.chomp.to_i

$coin = [500, 100, 50]
def calc(sum, now)
	pattern = 0
	return 1 if sum == $x
	return 0 if now >= 3
	(0..$abc[now]).each do |i|
		pattern += calc(sum + $coin[now] * i, now + 1)
	end
	#puts "sum:#{sum} now:#{now} pattern:#{pattern}"
	return pattern
end

puts calc(0, 0)

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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  int ignore = 0;
  for (int i = 0; i < N - 1; i++){
    ignore = max(ignore, A[i + 1] - A[i]);
  }
  ignore = max(ignore, K + A[0] - A[N - 1]);
  cout << K - ignore << endl;
}


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

vector<int> adj[100001];
bool visited[100001];

void floodfill(int x) {
    visited[x] = true;
    for (int nx : adj[x]) {
        if (!visited[nx]) floodfill(nx);
    }
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y, z; cin >> x >> y >> z;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (!visited[i]) {
            cnt++;
            floodfill(i);
        }
    }
    
    cout << cnt << '\n';
    
    return 0;
}


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

#define endl '\n'

char s[23];

bool isDigit(char c) {
    if(c >= '0' && c <= '9') return true;
    return false;
}

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

    int a, b;
    cin >> a >> b >> s;
    int id = 0;
    for(int i = 0; i < a; i++) {
        if(!isDigit(s[id++])) {
            cout << "No";
            return 0;
        }
    }
    if(s[id++] != '-') {
            cout << "No";
            return 0;
    }
    for(int i = 0; i < b; i++) {
        if(!isDigit(s[id++])) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";

    return 0;
}

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

class Deer:
    def __init__(self):
        self.x = 0
        self.y = 0
        self.t = 0

    def move(self, ti, xi, yi):
        time_interval = ti - self.t
        manhattan_distance = abs(xi - self.x) + abs(yi - self.y)
        val = time_interval - manhattan_distance
        if (val >= 0) and (val % 2 == 0):
            self.x = xi
            self.y = yi
            self.t = ti
            return True
        else:
            return False

AtCoDeer = Deer()
N = int(input())
flag = True
for _ in range(N):
    ti, xi, yi = map(int, input().split())
    flag = flag and AtCoDeer.move(ti, xi, yi)


if flag:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3064
from itertools import accumulate
import sys
sys.setrecursionlimit(10**8)

n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
p = [i-1 for i in p]

seen = [False]*n
ans = -float('inf')
for i in range(n):
    if not seen[i]:
        sc = []
        stop = i
        while True:
            seen[i] = True
            sc.append(c[i])
            if p[i] == stop:
                break
            i = p[i]

        lens = len(sc)
        for j in range(lens):
            if j != 0:
                sc = sc[1:] + [sc[0]]
            ac = list(accumulate(sc))

            if sum(sc) <= 0:
                ans = max(ans, max(ac[:min(k, lens)]))
            else:
                if k%lens == 0:
                    ans = max(ans, ac[-1]*(k//lens-1) + max(ac))
                else:
                    ans = max(ans, ac[-1]*(k//lens) + max(ac[:k%lens]))
print(ans)

Measured memory_bytes: 10144
N = int(input())
DX = input().split()
D=int(DX[0])
X=int(DX[1])
a =[input() for i in range(N)]

sam = N + X
i= 1
n=0
while n < N:
    if 1 + i * int(a[n])  < D+1:
        sam += 1
        i += 1
    else:
        n += 1
        i = 1

print(sam)


Measured memory_bytes: 3060
#include <stdio.h>

int main(int argc, char **argv)
{
    char c;
    scanf("%c", &c);

    if (c == 'a'
        || c == 'e'
        || c == 'i'
        || c == 'o'
        || c == 'u'
    ) {
        puts("vowel");
    } else {
        puts ("consonant");
    }
    return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}

	dp := make([]bool, 100*100+200)
	dp[0] = true

	max := 0
	for i := 0; i < n; i++ {
		for j := 10000; j >= 0; j-- {
			if !dp[j] {
				continue
			}
			v := j + s[i]
			dp[v] = true
			if v%10 != 0 && max < v {
				max = v
			}
		}
	}

	fmt.Println(max)
}


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

int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
    return 0;
}



Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = ~(1 << 31);

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

    int n;
    cin >> n;
    vector<string> blue(n+1);
    rep(i, n){cin >> blue[i];}

    int m;
    cin >> m;
    vector<string> red(m+1);
    rep(i, m){cin >> red[i];}
    int maxV = 0;
    int cur;
    rep(i, n){
        cur = 0;
        rep(j, n){
            if(blue[i] == blue[j]){
                cur++;
            }
        }
        
        rep(j, m){
            if(blue[i] == red[j]){
                cur--;
            }
        }
        maxV = max(cur, maxV);
    }
    cout << maxV << endl;

    return 0;
}

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

main() {
  int a, b, c; cin >> a >> b >> c;
  bool ans = false;
  if (a + b == c) ans = true;
  if (b + c == a) ans = true;
  if (c + a == b) ans = true;
  cout << ( (ans) ? "Yes" : "No" ) << endl;
}


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

typedef long long ll;
typedef unsigned short int unsi;
typedef unsigned int uni;
typedef unsigned long int unli;

using namespace std;

int main(){
	int N, K;
	
	cin >> N >> K;
	
	int Count = 0;
	int h = 0;
	
	for (int i = 0; i < N; i++) {
		cin >> h;
		if (h >= K) {
			Count++;
		}
	}
	cout << Count << endl;
}

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

using namespace std;

#define all(v)   v.begin(), v.end()
#define sz(x)    (int) (x.size())
#define Unique(x) x.erase(unique(all(x)), x.end())
#define endl "\n"
#define isOdd(n)    (n&1)
#define pow(n, m) (ll)powl(n, m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define clr(x, val)    memset(x, val, sizeof(x)) //be careful of value and TLE
#define MOD 1000000007
#define EPS 1e-7


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



int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("test cases\\in.txt", "r", stdin);
    //freopen("test cases\\in.txt", "w", stdout);
    ll n; cin >> n;
    int a[n];
    int x = 0;
    for(int i = 0; i<n; i++)  cin >> a[i], x ^= a[i];
    for(int i = 0; i<n; i++)
        cout<<(x^a[i])<<" ";
    return 0;
}


Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[300001],b[300001];
int main(){
    int n;
    string s;
    cin>>n>>s;
    rep(i,n){
        if(s[i]=='W') a[i+1]=1;
        else b[i+1]=1;
    }
    rep(i,n){
        a[i+1]+=a[i];
        b[i+1]+=b[i];
    }
    int mn=1000100010;
    FOR(i,0,n){
        int aa=a[i]-a[0];
        int bb=b[n]-b[i+1];
        mn=min(mn,aa+bb);
    }
    cout<<mn<<endl;
    return 0;
}

Measured memory_bytes: 3076
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define MAXN 100000
#define LL long long
#define DB double
#define FR first
#define SE second
LL K,A,B;
int main()
{
    scanf("%lld%lld%lld",&K,&A,&B);
    if(K<=A-1)printf("%lld",K+1);
    else
    {
    	K-=A-1;
    	if(B-A>1)printf("%lld",(K/2)*(B-A)+(K%2)+A);
    	else printf("%lld",K+A);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  int m  = std::ceil( (double)N / 1.08 );
  int mm = m + 1;
  
  int n1 = m*1.08;
  int n2 = mm*1.08;
  if ( n1 == N ) std::cout << m << std::endl;
  else if ( n2 == N ) std::cout << mm << std::endl;
  else std::cout << ":(" << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;

int main(){
    int N;
    cin >> N;
    priority_queue<int, vector<int>, greater<int>> que;
    for(int i = 0; i < N; ++i){
        int a;
        cin >> a;
        que.push(a);
    }
    
    int res = 0;
    ll sum = 0;
    int cnt = 0;
    sum += que.top();
    que.pop();
    cnt++;
    int index = 0;
    while(!que.empty()){
        int temp = que.top();
        que.pop();
        if(2 * sum < temp){
            index = cnt;
        }
        sum += temp;
        cnt++;
    }
    res = N - index;
    
    cout << res << endl;
}

Measured memory_bytes: 892
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#define re register
using namespace std;
typedef long long ll;

inline ll read() {
    ll X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=1000+10;
const int mod=1e9+7;
inline int qpow(int a,ll b) { int c=1;
    for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod;
    return c;
}

int n,m; ll k;
char s[N][N];

struct Matrix {
    int s[2][2];
    Matrix() { s[0][0]=s[0][1]=s[1][0]=s[1][1]=0; }
    int* operator [](int i) { return s[i]; }
} M;
Matrix operator *(Matrix a,Matrix b) { Matrix c;
    for (re int i=0;i<2;++i)
        for (re int k=0;k<2;++k)
            for (re int j=0;j<2;++j)
                c[i][j]=(c[i][j]+1ll*a[i][k]*b[k][j])%mod;
    return c;
}
inline Matrix qpow(Matrix a,ll b) { Matrix c; c[0][0]=c[1][1]=1;
    for (;b;b>>=1,a=a*a) if (b&1) c=c*a;
    return c;
}

int main() {
    n=read(),m=read(),k=read();
    for (re int i=1;i<=n;++i) scanf("%s",s[i]+1);
    int ud=0,lr=0,c=0,ud_=0,lr_=0;
    for (re int i=1;i<=m;++i)
        if (s[1][i]=='#'&&s[n][i]=='#') ++ud;
    for (re int i=1;i<=n;++i)
        if (s[i][1]=='#'&&s[i][m]=='#') ++lr;
    for (re int i=1;i<=n;++i)
        for (re int j=1;j<=m;++j)
            if (s[i][j]=='#') ++c;
    for (re int i=1;i<n;++i)
        for (re int j=1;j<=m;++j)
            if (s[i][j]=='#'&&s[i+1][j]=='#') ++ud_;
    for (re int i=1;i<=n;++i)
        for (re int j=1;j<m;++j)
            if (s[i][j]=='#'&&s[i][j+1]=='#') ++lr_;
    if (ud&&lr) puts("1");
    else if (!ud&&!lr) printf("%d\n",qpow(c,k-1));
    else if (ud) {
        M[0][0]=c,M[0][1]=ud_,M[1][0]=0,M[1][1]=ud;
        M=qpow(M,k-1);
        printf("%d\n",(M[0][0]-M[0][1]+mod)%mod);
    } else {
        M[0][0]=c,M[0][1]=lr_,M[1][0]=0,M[1][1]=lr;
        M=qpow(M,k-1);
        printf("%d\n",(M[0][0]-M[0][1]+mod)%mod);
    }
    return 0;
}


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

int n, m, q;
vector<int> a, b, c, d;

long long score(const vector<int> &A) {
    long long sum = 0;
    for (int i=0; i<q; ++i) {
        if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
    }
    return sum;
}

long long dfs(vector<int> &A) {
    long long ans = 0;
    if (A.size() == n) {
        return score(A);
    }

    int pre_last = A.empty() ? 1 : A.back();

    for (int i = pre_last; i <= m; ++i) {
        A.push_back(i);
        ans = max(ans, dfs(A));
        A.pop_back();
    }
    return ans;
}

int main() {
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for (int i=0; i<q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    vector<int> A;
    cout << dfs(A) << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

int main()
{
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(q);
	rep(i, q) cin >> a.at(i);
	vector<int> score(n, k-q);
	rep(i, q) {
		score.at(a.at(i) - 1)++;
	}
	rep(i, n) {
		if (score.at(i) > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 1408
n = int(input())
h_list = list(map(int, input().split()))
h = 0
result = 'Yes'
for i in range(n):
  if h <= h_list[i]-1:
    h = h_list[i]-1
  elif h == h_list[i]:
    h = h_list[i]
  else:
    result = 'No'
print(result)


Measured memory_bytes: 15020
import bisect
m = 10**9+7
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = sorted(a)
cc = 0
ca = 0
for i in range(n):
  c = 0
  for j in range(i+1,n):
    if a[i] > a[j]:
      c += 1
  cc += c
  ca += bisect.bisect_left(b,a[i])
cc %= m; ca %= m
print(((cc * k) % m + (((((k-1) * k)//2) % m) * ca) % m) % m)

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

int main() {
  int N, W;
  std::cin >> N >> W;
  std::vector<int> w(N), v(N);
  for (int i = 0; i < N; ++i)
    std::cin >> w[i] >> v[i];
  std::vector<int64_t> dp(W + 1, 0);
  for (int i = 0; i < N; ++i) {
    for (int j = W; j >= w[i]; --j) {
      dp[j] = std::max(dp[j], dp[j - w[i]] + v[i]);
    }
  }
  int64_t ans = dp[W];
  std::cout << ans << std::endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 50005
typedef pair<int,int> P;

int N,K,D,R;
int f[MAX_N][4];
vector<int> G[MAX_N];
int C[MAX_N];
int flg[MAX_N];
int type[MAX_N];
int t[4];
bool visited[MAX_N];

vector<int>  mp[10000];
priority_queue< P > mq[10000];

struct data{
  int id;
  bool operator < ( const data &p ) const {
    for(int i=0;i<K;i++){
      int a=f[id][t[i]];
      int b=f[p.id][t[i]];
      if(a!=b)return (a<b);
    }
    return false;
  }
};

data temp[MAX_N];
void func(vector<int> &v){
  v.resize(N);
  for(int i=0;i<N;i++)temp[i].id=i;
  sort(temp,temp+N);
  for(int i=0;i<N;i++){
    v[ temp[i].id ]=i;
  }
}

int main(){
  scanf("%d %d",&N,&K);
  for(int i=0;i<N;i++)
    for(int j=0;j<K;j++)
      scanf("%d",&f[i][j]);
  scanf("%d",&D);
  for(int i=0;i<D;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    a--,b--;
    G[a].push_back(b);
    C[b]++;
  }

  int num=0;
  for(int j=0;j<K;j++){
    scanf("%d",&t[j]);
    t[j]--;
    num=num*10+t[j];
  }
  if(mp[num].empty())func(mp[num]);
  int si=num;
  
  scanf("%d",&R);
  for(int i=0;i<R;i++){
    
    int m;
    num=0;
    scanf("%d",&m);
    for(int j=0;j<K;j++){
      scanf("%d",&t[j]);
      t[j]--;
      num=num*10+t[j];
    }


    
    flg[m]=true;
    type[m]=num;
    if(mp[num].empty())func(mp[num]);


  }


  
  int count=0;
  vector<int> keys;
  
  for(int i=0;i<10000;i++)
    if(!mp[i].empty())keys.push_back(i);
  
  for(int i=0;i<N;i++){
    if(C[i]!=0)continue;
    for(int j=0;j<(int)keys.size();j++){
      mq[ keys[j] ].push( P(mp[ keys[j] ][i],i) );
    }
  }
  

  while(!mq[si].empty()){
    P p=mq[si].top();mq[si].pop();
    if(visited[p.second])continue;
    visited[p.second]=true;
    count++;
    printf("%d\n",p.second+1);
    
    if(flg[count])si=type[count];
    
    for(int i=0;i<(int)G[p.second].size();i++){
      int to=G[p.second][i];
      C[to]--;
      if(C[to]!=0)continue;
      for(int j=0;j<(int)keys.size();j++){
        mq[ keys[j] ].push( P(mp[ keys[j] ][to],to) );
      }
    }
  }
  return 0;
}

Measured memory_bytes: 21840
import java.util.*;
public class Main {

  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }

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

    int k = sc.nextInt();
    int ans = 0;

    for (int a = 1; a <= k; a++) {
      for (int b = 1; b <= k; b++) {
        for (int c = 1; c <= k; c++) {
          ans += gcd(a, gcd(b,c));
        }
      }
    }
    System.out.println(ans);

    sc.close();

  }
}

Measured memory_bytes: 36236
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef pair<double,int> PDI;
const double eps=1e-12;
const int INF=0x3f3f3f3f;
const LL inf=1e18;
const double pi=acos(-1.0);
const int mod=1e9+7;
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
map<int,int>p;
int main(){
//    freopen("in.txt","r",stdin);
//    freopen("outt.txt","w",stdout);
    int n,a;
    cin>>n;
    LL ans=0;
    LL b=-1,c=-1;
    for(int i=0;i<n;i++){
        cin>>a;
        p[a]++;
        if(p[a]>=4) ans=max(ans,1LL*a*a);
        if(p[a]>=2){
            if(a>b){
                c=b;
                b=a;
            }
            else if(a<b&&a>c){
                c=a;
            }
        }
    }
//    cout<<b<<" "<<c<<endl;
    if(b!=-1&&c!=-1){
        ans=max(ans,b*c);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<queue>
#include<set>
typedef long long ll;
using namespace std;


int main(){
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n-1;i++){
        cin>>v[i];
    }
    int sum = 2*v[0];
    for(int i=1;i<n-1;i++){
        if(v[i]>=v[i-1]){
            sum += v[i];
        }
        else{
            sum -= v[i-1];
            sum += v[i] + v[i];
        }
    }
    cout<<sum<<endl;
    return 0;
}

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


int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a),greater<int>());

    int ascore=0, bscore=0;
    rep(i,n){
        if(i%2==0) ascore += a[i];
        else bscore += a[i];
    }

    cout << ascore - bscore << endl;

}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <bitset>
#include <numeric>

#define ll long long

using namespace std;

int main() {
    int N; cin >> N;
    vector<ll> A(N); for (int i = 0; i < N; ++i) cin >> A[i];

    int x1 = accumulate(A.begin(), A.end(), 0);
    for(int i = 1; i < N; i+=2) x1 -= 2 * A[i];

    vector<ll> X(N); X[0] = x1;

    for(int i = 1; i < N; ++i) X[i] = 2 * (A[i-1] - X[i-1]/2);
    for (int i = 0; i < N; ++i) {
        if (i > 0) cout << " ";
        cout << X[i];
    }
    cout << endl;

}


Measured memory_bytes: 2944
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[1000][1000];
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)
		for(int j=0;j<a;j++)
			scanf("%d",&d[i][j]);
	long long ret=0;
	for(int i=0;i<a;i++)
		for(int j=i+1;j<a;j++)
			ret+=min(d[i][j],d[j][i]);
	printf("%lld\n",ret);
}

Measured memory_bytes: 1412
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 * Surf Smelt Fishing Contest II
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		Main main = new Main();

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int q = Integer.parseInt(line.substring(line.indexOf(' ') + 1));

			Angler[] anglers = new Angler[n + 1];
			for (int i = 1; i <= n; i++) {
				anglers[i] = main.new Angler(i);
			}

			Queue<Angler> pq = new PriorityQueue<>(new Comparator<Angler>() {
				@Override
				public int compare(Angler o1, Angler o2) {
					if (o1.catch_ == o2.catch_) {
						return Integer.compare(o1.id, o2.id);
					} else {
						return Integer.compare(o2.catch_, o1.catch_);
					}
				}
			});

			StringBuilder sb = new StringBuilder();

			for (int i = 0; i < q; i++) {
				line = br.readLine();
				int a, v;
				a = Integer.parseInt(line.substring(0, line.indexOf(' ')));
				v = Integer.parseInt(line.substring(line.indexOf(' ') + 1));

				pq.remove(anglers[a]);
				anglers[a].catch_ += v;
				pq.add(anglers[a]);
				//
				sb.append(pq.peek().id + " " + pq.peek().catch_ + "\n");
			}
			System.out.print(sb.toString());

		} //end while
	} //end main

	class Angler {
		int id;
		int catch_ = 0;

		Angler(int id) {
			this.id = id;
		}
	}
}

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

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

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

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

int main() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

typedef long long ll;
using namespace std;

ll N, M, V, P;
vector<ll> A(1e5, 0);

bool bin(ll i) {
    ll sm = 0;
    ll k = A[i] + M;
    if (k < A[P - 1]) {
        return false;
    }
    sm += (P - 1) * M + (N - i) * M;
    for (ll x = P - 1; x < i; x++) {
        sm += max(ll(0), k - A[x]);
    }
    return (sm >= M * V);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> V >> P;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    ll l = P - 1;
    ll r = N;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        if (bin(mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << l + 1 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;

P a[100000];
int Par[10000], Rank[10000];
int saiki(int b) {
	if (Par[b] == b)return b;
	return Par[b]=saiki(Par[b]);
}
void unite(int b, int c) {
	b = saiki(b); c = saiki(c);
	if (Rank[b] > Rank[c]) {
		Par[c] = b;
	}
	else if (Rank[b] < Rank[c]) {
		Par[b] = c;
	}
	else {
		Par[c] = b;
		Rank[b]++;
	}
}
signed main() {
	int b, c; cin >> b >> c;
	for (int k = 0; k < b; k++)Par[k] = k;
	for (int d = 0; d < c; d++) {
		int e, f, g;
		scanf("%d%d%d", &e, &f, &g);
		if (e) {
			cout << (saiki(f) == saiki(g)) << endl;
		}
		else {
			unite(f, g);
		}
	}
}

Measured memory_bytes: 3304
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a); 
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}	
};


map<int,int> h;
int dp[2007];
vector <int> arraySort(vector <int> v) {
	vector<int> ans;
	for(int i = 1; i <= (int)v.size(); i++){
		dp[i] = 1;
	}
	
	for(int i = 1; i <= (int)v.size(); i++){
		for(int j = 1; j < i; j++){
			if(v[j-1] <= v[i-1]){ 
				if(dp[i] < dp[j] + 1){
					dp[i] = dp[j] + 1;
					h[i] = j;
				}
				else if(dp[i] == dp[j] + 1){					
					int index = h[i];
					int val = v[index-1];
					if(v[j-1] < val){
						h[i] = j;
					}
				}
			}
		}
	}
	int index, maxi = 0, minval = inf;
	for(int i = 1; i <= (int)v.size(); i++){
		if(maxi <= dp[i] ){
			maxi = dp[i];
		}
	} 
	
	for(int i = 1; i<= (int)v.size(); i++){
		if(maxi == dp[i]){
			if(minval > v[i-1]){
				minval = v[i-1];
				index = i;
			}
		}
	}
	
	cout<<minval<<" "<<index<<endl;
	
	int next = index;
	
	while(next){
		cout<<next<<" ";
		next = h[next];
	}
	return ans;
}

int p[107];
int main(){
	int n; cin>> n;
	
	for(int i = 1; i <= n; i++){
		cin>> p[i];
	}
	int ans = inf;
	for(int i = 1; i <= 100;i++){
		int cost = 0;
		for(int j = 1; j <= n; j++){
			cost += (p[j] - i)*(p[j] - i);
		}
		ans = min(ans, cost);
	}
	cout<<ans;
	
	return 0;
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
st a,b;
  	ci(a>>b);
  if(a.sz>b.sz) co("GREATER")
    else if(a.sz<b.sz) co("LESS")
      
      else{
        FOR(i,0,a.sz){
          if(a[i]>b[i]){
            co("GREATER")
              break;
          }
          else if(a[i]<b[i]){
            co("LESS")
              break;
          }
          if(i==a.sz-1) co("EQUAL")
      }
      }
}

Measured memory_bytes: 256
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
//#define int long long
#define double long double

int n,m,k;
int32_t main()
{
    IOS;
    cin>>n>>m>>k;
    map<int,int>ct1,ct2;
    map<pair<int,int>,int>finmp;
    int arr[k][2];
    for(int i=0;i<k;i++)
    {
        cin>>arr[i][0]>>arr[i][1];
        ct1[arr[i][0]]++;
        ct2[arr[i][1]]++;
        finmp[{arr[i][0],arr[i][1]}]++;
    }
    vector<pair<int,int>>v1,v2;
    set<pair<int,int>>s1,s2;
    for(auto i:ct1)
        s1.insert({i.second,i.first});
    for(auto i:ct2)
        s2.insert({i.second,i.first});

    for(auto i:s1)
        v1.push_back({i.second,i.first});
    for(auto i:s2)
        v2.push_back({i.second,i.first});

    int maxans=0;
    int l1=v1.size();
    int l2=v2.size();

    for(int i=l1-1;i>=max(0,l1-20);i--)
        for(int j=l2-1;j>=0;j--)
        {
            int ct1=v1[i].second;
            int ct2=v2[j].second;
            int ispre=0;
            if(finmp.find({v1[i].first,v2[j].first})!=finmp.end())
                ispre=1;
            maxans=max(maxans,ct1+ct2-ispre);
        }
    for(int j=l2-1;j>=max(0,l2-20);j--)
        for(int i=l1-1;i>=0;i--)
        {
            int ct1=v1[i].second;
            int ct2=v2[j].second;
            int ispre=0;
            if(finmp.find({v1[i].first,v2[j].first})!=finmp.end())
                ispre=1;
            maxans=max(maxans,ct1+ct2-ispre);
        }
    print(maxans);
}


Measured memory_bytes: 88924
package main

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

func solve() {
	n := getInt()
	as := getIntSlice(n)

	cnt := 1
	ans := 0
	for i := 1; i < n; i++ {
		if as[i] == as[i-1] {
			cnt++
		}

		if (i == n-1) || (as[i] != as[i-1]) {
			ans += cnt/2
			cnt = 1
		}
	}

	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

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

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


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

int main() {
  string s;
  cin >> s;
  if(s.at(0) == s.at(2)) cout << "Yes" << endl;
  else  cout << "No" << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define MAX 10000000000
#define rep(i,n) for(int i = 0; i < n;i++)
ll v, n, e, u, k, ans = 0,sum,d[50];
int main(void) {
	int n;cin >> n;
	rep(i, n) cin >> d[i];
	rep(i, n - 1) {
		for (int j = i + 1; j < n;j++) {
			sum += d[i] * d[j];
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    string s[110];
    rep(i, 0, h) cin >> s[i];
    int b[26] = {};
    rep(i, 0, h){
        rep(j, 0, w){
            b[s[i][j] - 'a']++;
        }
    }
    int res = (h / 2) * (w / 2);
    rep(i, 0, 26){
        int tmp = b[i] / 4;
        if(res > 0){
            if(res >= tmp){
                res -= tmp;
                b[i] -= tmp * 4;
            }else if(res < tmp){
                b[i] -= res * 4;
                res = 0;
            }
        }
    }
    bool f = true;
    if(res > 0) f = false;
    int res2 = 0;
    if(h % 2 && w % 2){
        res2 = h / 2 + w / 2;
    }else if(h % 2){
        res2 = w / 2;
    }else if(w % 2){
        res2 = h / 2;
    }
    rep(i, 0, 26){
        int tmp = b[i] / 2;
        if(res2 > 0){
            if(res2 >= tmp){
                res2 -= tmp;
                b[i] -= tmp * 2;
            }else if(res2 < tmp){
                b[i] -= res * 2;
                res2 = 0;
            }
        }
    }
    if(res2 > 0) f = false;
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

const int MAXN = 100100;

int arr[MAXN];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, i;
	int sol = 0;
	
	cin>>n;
	
	for (i = 0; i < n; ++i)
	{
		cin>>arr[i];
		--arr[i];
	}
	
	for (i = 0; i < n - 1; ++i) if (arr[i] == i)
		swap(arr[i], arr[i + 1]), ++sol;
	
	cout<<sol + (arr[n - 1] == n - 1)<<'\n';
}


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

int main()
{
    int A;
    int B;
    int C;
    std::cin >> A >> B >> C;

    int ans = C - (A - B);
    if (ans < 0) ans = 0;
    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())

asi = y - x * 2
if asi % 2 == 0:
    kame = asi / 2
else:
    print("No")
    exit()
turu = x - kame

if kame >= 0 and turu >= 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9208
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;


vector<int> a,b,c;

bool aisOK(int index, int key){
	if(a[index]>=key)return true;
	else return false;
}
int asearch(int key){
	int ng = -1;
	int ok = a.size();
	while(abs(ok - ng) > 1){
		int mid = (ok + ng) / 2;
		if(aisOK(mid,key))ok = mid;
		else ng = mid;
	}
	return ok;
}

bool cisOK(int index, int key){
	if(c[index] > key)return true;
	else return false;
}
int csearch(int key){
	int ng = -1;
	int ok = c.size();
	while(abs(ng - ok) > 1){
		int mid = (ng + ok) / 2;
		if(cisOK(mid, key))ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(void) {
	int n;
	cin >> n;
	int temp;
	for(int i=0; i<n; i++){
		cin >> temp;
		a.push_back(temp);
	}
	for(int i=0; i<n; i++){
		cin >> temp;
		b.push_back(temp);
	}
	for(int i=0; i<n; i++){
		cin >> temp;
		c.push_back(temp);
	}
	sort(a.begin(),a.end());
	sort(c.begin(),c.end());
	long long ans=0;
	//めぐる式二分探索の気持ち
	for(int i=0; i<n; i++){
		ans+=(long long)asearch(b[i])*(n-csearch(b[i]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 3001;
int dp[N][N];

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

  string s,t;
  cin>>s>>t;
  string ans="";

  int n=s.size(),m=t.size();
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      (s[i-1]==t[j-1]) and (dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1));
      dp[i][j] = max(dp[i][j],dp[i-1][j]);
      dp[i][j] = max(dp[i][j],dp[i][j-1]);
    }
  }
  int i=n,j=m;
  while(i>0 and j>0){
    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<<endl;

  return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;
    int t;
    cin>>t;

    map<string,int> m;
    int ans=0;

    while(t--) {
        string s;
        cin>>s;

        if(m.find(s)==m.end()) {
            m[s]=1;
            ans++;
        }
    }

    map<string,int>::iterator it;

    //for(it=m.begin();it!=m.end();it++) {
    //    cout<<"key: "<<it->first<<' '<<"value: "<<it->second<<endl;
    //}
    cout<<ans<<endl;

}




Measured memory_bytes: 19164
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;

    int A,B;
    // (X)=G*2-R
int main(){
    cin>>A>>B;
    cout<<(B*2)-A;
}


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

using namespace std;

int main() {
	vector<int> p;
	vector<int> op;

	for (int i = 1;;i++) {
		int n = ((i + 1) * (i + 2) * (i)) / 6;
		if (n >= 1000000)break;
		if (n % 2 == 1) {
			op.push_back(n);
		}
		p.push_back(n);
	}

	int *ans = new int[1000000];
	int *oans=new int[1000000];

	for (int i = 0;i < 1000000;i++) {
		ans[i] = oans[i] = i;
	}
	for (int i = 1;i < 1000000;i++) {
		for (int j = 0;;j++) {
			if (j >= p.size())break;
			if (p[j] > i)break;
			ans[i] = min(ans[i], 1 + ans[i - p[j]]);
		}
		for (int j = 0;;j++) {
			if (j >= op.size())break;
			if (op[j] > i)break;
			oans[i] = min(oans[i], 1 + oans[i - op[j]]);
		}
	}
	int tmp;
	while (1) {
		cin >> tmp;
		if (tmp == 0)break;
		cout << ans[tmp] << " " << oans[tmp] << endl;
	}
}


Measured memory_bytes: 10972
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n, k; cin >> n >> k;
  cout << n - k + 1 << endl;
}


Measured memory_bytes: 256
/*⠀⠀, --- 、⠀⠀⠀゜
⠀⠀⠀/;;;;;;;;;;;;', 　゜
⠀⠀⠀i二二二i     ゜
⠀⠀  , ' 　    　ヽ 
⠀⠀i　ﾉﾉﾉﾉﾉﾍ .', ⠀⠀<I can't solve...
⠀  〉ﾘi'= _ =ﾉﾚく　 <WAyon....
○⊂}〈lﾄ--ｲl〉{つ● 　　
⠀⠀⠀,ｒ/ー i-ヽヽ 　　　
⠀⠀｀｀i_⊃i_⊃ */
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N,M;
  cin >> N >> M;
  if(N==M){
  cout << "Yes" << endl; 
  }
  else{
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>



int diccmp(char *a, char *b) {
  int i=0;
  while(1) {
    if(a[i] == '\0' && b[i] == '\0') return 0;
    if(a[i] > b[i]) return 1;
    if(a[i] < b[i]) return 2;
    i++;
  }
}


int main() {
  int n,tp,hp;
  char taro[101], hanako[101];

  tp = 0; hp = 0;
  scanf("%d", &n);
  for(; n > 0; n--) {
    scanf("%s %s", taro, hanako);
    switch (diccmp(taro, hanako)) {
    case 0:
      tp++;
      hp++;
      break;
    case 1:
      tp += 3;
      break;
    case 2:
      hp += 3;
      break;
    }
  }
  
  printf("%d %d\n", tp, hp);
  return 0;
}

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

int main()
{
	/*
	// 整数の入力
	int a;
	cin >> a;
	// スペース区切りの整数の入力
	int b, c;
	cin >> b >> c;
	// 文字列の入力
	string s;
	cin >> s;
	// 出力
	cout << (a + b + c) << " " << s << endl;
	*/

	char s[20];
	cin >> s;
	char sv[3][20];
	int v = 0;
	int m = 0;

	for (int n = 0; n < 20; n++) {

		if (s[n] == '\0')break;
		if (s[n] == ',') { v++; m = 0; continue; }


		sv[v][m] = s[n];
		sv[v][m+1] = '\0';

		m++;

	}



	cout << sv[0] << " " << sv[1] << " " << sv[2] <<  endl;



	return 0;
}


Measured memory_bytes: 256