akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long

using namespace std;
const int maxn = 1e5 + 7;
struct Data
{
    int b, l, u;
    void Input()
    {
        cin >> b >> l >> u;
    }
    Data(){};
    Data(int b, int l, int u) : b(b), l(l), u(u) {};
} p[maxn];

int n, x, sum;

bool Check(int need)
{
    int num = need / x;
    int rest = need % x;
    int ricardo = 0;
    vector<pair<int, int>> bonus = {};
    for(int i = 1; i <= n; i++)
    {
        ricardo -= p[i].b * p[i].l;
        bonus.push_back({p[i].u * (x - p[i].b) + p[i].b * p[i].l, i});
    }
    sort(bonus.rbegin(), bonus.rend());
    for(int i = 0; i < num; i++)
    {
        ricardo += bonus[i].first;
    }
    int ans = ricardo;
    if(rest > 0)
    {
        for(int i = num; i < n; i++)
        {
            int val;
            if(rest > p[bonus[i].second].b) val = (rest - p[bonus[i].second].b) * p[bonus[i].second].u;
            else val = -(p[bonus[i].second].b - rest) * p[bonus[i].second].l;
            ans = max(ans, ricardo + p[bonus[i].second].b * p[bonus[i].second].l + val);
        }
        for(int i = 0; i < num; i++)
        {
            int val;
            if(rest > p[bonus[i].second].b) val = (rest - p[bonus[i].second].b) * p[bonus[i].second].u;
            else val = -(p[bonus[i].second].b - rest) * p[bonus[i].second].l;
            ans = max(ans, ricardo - bonus[i].first + bonus[num].first + p[bonus[i].second].b * p[bonus[i].second].l + val);
        }
    }
    return (ans >= 0);
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
    cin >> n >> x;
    for(int i = 1; i <= n; i++)
    {
        p[i].Input();
        sum += p[i].b;
    }
    #define debu
    #ifdef debug
    cout << Check(108) << '\n';
    #else
    int l = 0;
    int r = sum;
    while(l <= r)
    {
        int mid = l + r >> 1;
        if(Check(mid)) r = mid - 1;
        else l = mid + 1;
    }
    cout << l << '\n';
    #endif
}


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

struct point {
    int id, x, y;
    point() : id(-1), x(0), y(0) {}
    point(int id, int x, int y) : id(id), x(x), y(y) {}
    point(int id, pair<int,int> xy) : id(id), x(xy.first), y(xy.second) {}
    bool operator < (const point &p) const {
        return id < p.id;
    }
};
class kdtree {
private:
    struct node {
        int p;
        node *left;
        node *right;
        node() : left(nullptr), right(nullptr) {}
    };

    static bool lessX(const point &a, const point &b) { return a.x < b.x; }
    static bool lessY(const point &a, const point &b) { return a.y < b.y; }

    int N;
    node *root;
    vector<point> &P;

    node *make_kd_tree(int l, int r, int depth) {
        if (!(l < r)) return nullptr;
        int mid = (l + r) / 2;

        if (depth) sort(begin(P) + l, begin(P) + r, lessY);
        else       sort(begin(P) + l, begin(P) + r, lessX);

        node *t = new node();
        t->p = mid;
        t->left = make_kd_tree(l, mid, !depth);
        t->right = make_kd_tree(mid+1, r, !depth);
        return t;
    }
    void find(node *v, int sx, int sy, int tx, int ty, int depth, vector<point> &ans) {
        if (v == nullptr) return;

        int x = P[v->p].x;
        int y = P[v->p].y;

        if (sx <= x && x <= tx && sy <= y && y <= ty) {
            ans.push_back(P[v->p]);
        }

        if (depth ? sy <= y : sx <= x) find(v->left, sx, sy, tx, ty, !depth, ans);
        if (depth ? y <= ty : x <= tx) find(v->right, sx, sy, tx, ty, !depth, ans);
    }

public:
    kdtree(vector<point> &p) : P(p) {
        N = p.size();
        root = make_kd_tree(0, N, 0);
    }
    void query(int sx,int sy,int tx,int ty, vector<point> &p) {
        find(root, sx, sy, tx, ty, 0, p);
    }
};

int main() {
    int n;
    cin >> n;
    vector<point> p(n);
    for (int i = 0; i < n; i++) {
        p[i].id = i;
        scanf("%d %d", &p[i].x, &p[i].y);
    }
    kdtree tree(p);
    int q;
    cin >> q;
    while (q--) {
        int sx, tx, sy, ty;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);

        vector<point> ans;
        tree.query(sx, sy, tx, ty, ans);

        sort(begin(ans), end(ans));
        for (int i = 0; i < (int)ans.size(); i++) {
            printf("%d\n", ans[i].id);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 23768
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll H, W; cin >> H >> W;
  vector<string> grid(H);
  vector<bool> tate(H, false);
  vector<bool> yoko(W, false);
  REP(i, H) cin >> grid[i];
  REP(i, H) REP(j, W) {
    if(grid[i][j] == '#'){
      tate[i] = true;
      yoko[j] = true;
    }
  }
  REP(i, H) REP(j, W){
    if(!tate[i]) continue;
    if(yoko[j]) cout << grid[i][j];
    if(j == W-1) cout << endl;
  } 
}     

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

bool solve(
    int* const a,
    const int n,
    const int i,
    const int m)
{
    if (m < 0) {
        return false;
    }
    if (m == 0) {
        return true;
    }
    if (i == n) {
        return false;
    }

    return solve(a, n, i + 1, m)
        || solve(a, n, i + 1, m - a[i]);
}

int main()
{
    int n;
    std::cin >> n;
    std::cin.ignore();

    int a[20];
    {
        std::string buf;
        std::getline(std::cin, buf);
        std::stringstream stream;
        stream << buf;
        for (int i = 0; std::getline(stream, buf, ' '); ++i) {
            a[i] = std::stoi(buf);
        }
    }

    int q;
    std::cin >> q;
    std::cin.ignore();

    int m[200];
    {
        std::string buf;
        std::getline(std::cin, buf);
        std::stringstream stream;
        stream << buf;
        for (int i = 0; std::getline(stream, buf, ' '); ++i) {
            m[i] = std::stoi(buf);
        }
    }

    for (int i = 0; i < q; ++i) {
        std::cout << (solve(a, n, 0, m[i]) ? "yes" : "no") << std::endl;
    }

    return 0;
}

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

int main()
{
	int n; cin >> n;
	
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int cnt = 0;
		for (int j = 1 + 1; j < i; j++) {
			if (i % j == 0) cnt++;
		}
		if (cnt == 6 and i%2 == 1) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int
main(void)
{
	char w[11];
	char t[1001];
	int c = 0;

	for (scanf("%s", w); scanf("%s", t) != EOF;)
		if (strcasecmp(t, w) == 0)
			c++;

	printf("%d\n", c);

	return 0;
}



Measured memory_bytes: 2060
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;
using namespace std;
ll common_multiple(ll a, ll b) {
	ll  r, x, tmp;
	x = a * b;

	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return x / b;
}


int main() {
	ll n,a,b,t=0;
	cin >> n;
	vector<pair<ll,ll> > pairs(n);
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		pairs[i] = make_pair(b,a);
	}
	sort(pairs.begin(), pairs.end());
	for (int i=0; i < n; i++) {
		a = pairs[i].first, b = pairs[i].second;
		if (t + b > a) {
			cout << "No" << endl;
			return 0;
		}
		else {
			t += b;
		}
	}
	cout << "Yes" << endl;
}




Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        int n,q,key,sum = 0;
        Scanner sc = new Scanner(System.in);
        n = Integer.parseInt(sc.next());
        int[] a = new int[10000+1];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        q = Integer.parseInt(sc.next());
        for (int i = 0; i < q; i++) {
            key = Integer.parseInt(sc.next());
            if(search(a, n , key)) sum++;
        }
        System.out.println(sum);
    }
    
        static boolean search(int a[], int n, int key){
        int i = 0;
        a[n] = key;
        while(a[i] != key) i++;
        return i != n;
    }
}


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

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;
}

// 無限大の値
const long long INF = 1LL << 60;

// 入力
int N;
int K;
long long h[100010];

// DP テーブル
long long dp[100010];

int main()
{
    // input
    cin >> N;
    cin >> K;
    for (int i = 0; i < N; i++)
        cin >> h[i];

    // DP テーブル全体を初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i)
        dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i)
        for (int j = 1; j <= K; ++j)
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));


    // 解を得て出力
    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1792
n,m,q = map(int, input().split())
abcd=[list(map(int,input().split())) for i in range(q)]

def calc(lis):
    ret=0
    for tmp in abcd:
        a,b,c,d=tmp
        a-=1
        b-=1
        if lis[b]-lis[a] == c:
            ret+=d
    return ret

ans=0
from itertools import *
for lis in combinations_with_replacement(range(1,m+1),n):
    ret =calc(lis)
    ans=max(ans,ret)

print(ans)

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

int main() {
    // a. b#
    int a, b;
    cin >> a >> b;
    char grid[100][100];
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            grid[i][j] = i < 50 ? '#' : '.';
        }
    }
    for (int i = 1; i < a; i++) {
        grid[i/50*2][i%50*2] = '.';
    }
    for (int i = 1; i < b; i++) {
        grid[51+i/50*2][i%50*2] = '#';
    }
    cout << 100 << " " << 100 << endl;
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            cout << grid[i][j];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
  public static void main(String[]args)
  {
    Scanner input=new Scanner(System.in);
    int W=input.nextInt();
    int H=input.nextInt();
    int x=input.nextInt();
    int y=input.nextInt();
    int r=input.nextInt();
    
    if(r<=H/2)
    {
      if(x>=r && x<=W-r && y>=r && y<=H-r)
        System.out.println("Yes");
    else
     System.out.println("No");}
    else 
      System.out.println("No");}

}


Measured memory_bytes: 26280
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<string.h>

int gcd(int a, int b) {
	return (b == 0) ? a : gcd(b, a % b);
}

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d\n", gcd(a, b));
	return 0;
}


Measured memory_bytes: 2728
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const int maxn=5;
inline void solve()
{
}
int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	if(s[n-1]=='s')
		s+="es";
	else
		s+="s";
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3656
def examA():
    N = DI()/dec(7)
    ans = N
    print(N)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    def bitdp(l, r):
        n = r.bit_length()
        dp = defaultdict(int)
        dp[0, 0, 0, 0] = 1
        for i, less, greater, start in itertools.product(range(n), (0, 1), (0, 1), (0, 1)):
            R_ = 1 if less else (r>>(n-i-1))&1
            L_ = 0 if greater else (l>>(n-i-1))&1
            for y in range(R_ + 1):
                for x in range(L_, y + 1):
                    less_ = less or y < R_
                    greater_ = greater or L_ < x
                    start_ = start or (y==1 and x==1)

                    if not start and (y==1 and x==0):
                        # xorがあまりを確実に上回る
                        continue

                    dp[i + 1, less_, greater_, start_] += dp[i, less, greater, start]
                    dp[i + 1, less_, greater_, start_] %= mod
                    #print(dp[i + 1, less_, greater_, start_],i+1,less_,greater,start_,start)

        #for i in range(n):
        #    print(dp[i,0,0,0],dp[i,1,0,0],dp[i,0,1,0],dp[i,1,1,0])

        res = sum(dp[n, less, greater, 1] for less, greater in itertools.product((0, 1), (0, 1)))
        return res
    L, R = LI()
    ans = bitdp(L,R) % mod
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examF()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

using LL   =  long long;
using pii  =  pair <int, int>;
using vii  =  vector <pii>;

const int INF = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int cnt[N];
bool prime[N];

void sieve(int n) {
    memset(prime, 1, sizeof(prime));

    prime[0] = prime[1] = 0;

    for(int i = 2; i * i <= n; ++i)
        if(prime[i])
            for(int j = i * i; j <= n; j += i)
                prime[j] = false;
}

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

    sieve(N);

    int s = 0;
    for(int i = 3; i < N; i++)
    {
        if(prime[i] and prime[(i+1)/2]) s++;
        cnt[i] = s;
    }

    int q;
    cin>>q;
    while(q--)
    {
        int l, r;
        cin>>l>>r;
        cout<<cnt[r] - cnt[l-1]<<"\n";
    }

    return 0;
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		if(Math.abs(x - a) > Math.abs(x - b)) {
			System.out.println("B");
		}else {
			System.out.println("A");
		}
	}
}

Measured memory_bytes: 21460
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
ll a[300005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) cin >> a[i];

  ll ans = 0;
  REP(i, 60) {
    ll mask = 1LL << i;

    ll one = 0, zero = 0;
    REP(j, n) {
      if(a[j] & mask) one++;
      else zero++;
    }

    ll tmp = one * zero % mod;
    ll tmp_a = (mask % mod) * tmp % mod;
    ans = (ans + tmp_a) % mod;
  }

  cout << ans << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;

map<int, int> a, b;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    int maxa, maxb, seca, secb;
    maxa=maxb=seca=secb=-1;
    a[-1] = 0;
    b[-1] = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if (i & 1)
        {
            a[x]++;
        } else{
            b[x]++;
        }
    }
    for (auto i: a)
    {
        if (maxa == -1 || i.second > a[maxa])
        {
            seca = maxa;
            maxa = i.first;
        } else if (seca == -1 || i.second > a[seca])
        {
            seca = i.first;
        }
    }
    for (auto i: b)
    {
        if (maxb == -1 || i.second > b[maxb])
        {
            secb = maxb;
            maxb = i.first;
        } else if (secb == -1 || i.second > b[secb])
        {
            secb = i.first;
        }
    }
    if (maxa != maxb)
    {
        cout << n - (a[maxa] + b[maxb]) << endl;
    }
    else{
        cout << n - max(a[maxa]+b[secb],a[seca]+b[maxb]) << endl;
    }
}

Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
using namespace std;
#define LATTE 10000

int main(){
	int A,B,C;
	cin>>A>>B>>C;
	if(A<B && B<C) puts("Yes");
	else puts("No");
    return 0;
}

Measured memory_bytes: 1116
N, K = gets.split.map(&:to_i)
ls = gets.split.map(&:to_i)
ls.sort!
ans = 0
for i in N-K...N
    ans += ls[i]
end
puts ans
=begin
    N, M = gets.split.map(&:to_i)
    AS = N.times{ gets.to_i }
=end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a , b , c ;
  cin >> a >> b >> c ;
  cout << ( a.at(a.size()-1) == b.at(0) 
           && b.at(b.size()-1) == c.at(0) ?
           "YES" :
           "NO")
    << endl;
}
    

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n,m;
  cin >> n >> m;
  UnionFind tree(n);
  int ans=n;
  rep(i,m){
    int x,y,z;
    cin >> x >> y >> z;
    x--;
    y--;
    if(!tree.issame(x,y)){
      tree.merge(x,y);
      ans--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 1e5;
LL enter_count[N+1];
LL exit_count[N+1];
LL exit_len[N+1];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout<<(60*(h2-h1)+(m2-m1)-k)<<endl;

	cout<<flush;
	return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef list<ll> listl;
typedef string str;

#define min(A, B) min(static_cast<ll>(A), static_cast<ll>(B))
#define max(A, B) max(static_cast<ll>(A), static_cast<ll>(B))
#define all(x) (x).begin(), (x).end()
#define mp make_pair

#define rep(i, m)		for(ll i = 0, i_max = m; i < i_max; i++)
#define erep(i, m)		for(ll i = 0, i_max = m; i <= i_max; i++)
#define REP(i, b, m)	for(ll i = b, i_max = m; i < i_max; i++)
#define EREP(i, b, m)	for(ll i = b, i_max = m; i <= i_max; i++)
#define rrep(i, m)		for(ll i = m; i >= 0; i--)
#define errep(i, b, e)	for(ll i = b; i >= e; i--)

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void in(ll& I)
{
	cin >> I;
}

void in(vl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(listl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(str& s)
{
	cin >> s;
}

void out(ll O)
{
	cout << O;
}

void out(vl& O)
{
	for (auto& o : O)
	{
		cout << o;
	}
}

void rout(bool b, str True, str False)
{
	if (b) cout << True.c_str();
	else cout << False.c_str();
}

int main()
{
	ll n;
	in(n);
	vl p(n);
	in(p);

	ll ans = 0;

	REP(i, 1, n - 1)
	{
		if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1]))
		{
			ans++;
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        a:i64,b:i64
    }

    let n = roundup(b - 1, a - 1);
    println!("{}", n);
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i] /= 2;
  }

  ll tmp = 1;
  for (int i = 0; i < N; i++) {
    tmp = tmp * a[i] / __gcd(tmp, a[i]);
  }
  for (int i = 0; i < N; i++) {
    if (tmp / a[i] % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << (tmp <= M) + (M - tmp) / (2 * tmp) << endl;
}

Measured memory_bytes: 1024
n,k = map(int,raw_input().split())
weights = []
for i in range(n):
	weights.append(int(input()))

def check(p):
	i = 0
	for j in range(k):
		w = 0
		while w + weights[i] < p:
			w += weights[i]
			i += 1
			if i == n:
				return True

	return False

left = 0
right = 100000 * 10000
mid = 0

while right - left > 1 :
	mid = (left + right)/2
	if check(mid):
		right = mid
	else : 
		left = mid

print right-1




Measured memory_bytes: 10912
#include<stdio.h>
int main(void)
{
  int h,n,i,atk=0;
  
  scanf("%d%d",&h,&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    atk=a[i]+atk;
  }
  if(atk>=h){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}
 
    
  
  
  

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
int main() {
	int d,n;
	scanf("%d %d", &d, &n);
	if (n == 100) { n = 101 * pow(10, 2 * d); printf("%d", n); }
	else{n = n * pow(10, 2 * d);printf("%d\n", n);}
}

Measured memory_bytes: 128
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let (n, k) = Scanf.sscanf (read_line ()) "%d %d" @@ fun n k -> (n, k)
let s = read_line ()
let s_len = String.length s

let rec f = function
  | ([], x :: xs) -> f ([[x]], xs)
  | (acc, []) -> acc
  | (("L" :: xs as acc) :: xss, "L" :: ys) -> f (("L" :: acc) :: xss, ys)
  | (("R" :: xs as acc) :: xss, "R" :: ys) -> f (("R" :: acc) :: xss, ys)
  | (xxs, y :: ys) -> f ([y] :: xxs, ys)
let ss = f ([], split_string s) |> List.map (String.concat "") |> List.rev

let rec g odd rest acc = function
  | [] -> acc
  | x :: xs ->
    if odd && rest > 0 then 
      let s = String.make (String.length x) (if x.[0] = 'L' then 'R' else 'L') in
      g (not odd) (rest - 1) (s :: acc) xs
    else g (not odd) rest (x :: acc) xs
let ss = g false k [] ss |> List.rev |> String.concat ""

let () =
  Array.init s_len (fun i ->
    if ss.[i] = 'L' then (if i <> 0 && ss.[i - 1] = 'L' then 1 else 0)
    else (if i < s_len - 1 && ss.[i + 1] = 'R' then 1 else 0)
  ) |> Array.fold_left (+) 0 |> Printf.printf "%d\n"

Measured memory_bytes: 24388
from itertools import combinations_with_replacement as comb_rplc
n, m, q = list(map(int, input().split()))
req = [list(map(int, input().split())) for _ in range(q)]

ans = 0

for seq in comb_rplc(range(1,m+1),n):
    now = 0
    for a, b, c, d in req:
        if seq[b-1] - seq[a-1] == c:
            now += d
    ans = max(ans, now)

print(ans)

Measured memory_bytes: 9108
import sys

def warshall_floyd(v_count, matrix):
    for i in range(v_count):
        for j, c2 in enumerate(matrix[j][i] for j in range(v_count)):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix


def has_negative_cycle(a) -> bool:
    return any(row[i] < 0 for i, row in enumerate(a))


V, E = map(int, input().split())
inf = float("inf")
matrix = [[inf]*V for _ in [0]*V]
for i in range(V):
    matrix[i][i] = 0
for s, t, d in (map(int, l.split()) for l in sys.stdin):
    matrix[s][t] = d
warshall_floyd(V, matrix)
if has_negative_cycle(matrix):
    print("NEGATIVE CYCLE")
else:
    for row in matrix:
        print(" ".join(map(lambda n: str(n) if n!=inf else "INF", row)))


Measured memory_bytes: 6232
#include <bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define TEST int inox,t;cin>>t; for(inox=1;inox<=t;inox++)
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define mp(x,y)  make_pair(x,y)
#define FAST    ios::sync_with_stdio(false); cin.tie(0);
#define modd 1000000007
using namespace std;
 
int main(){
ll n,i; cin>>n;
string s; cin>>s;
vector<ll> v(n);
rep(i,n){
if(s[i]=='W')v[i]=1;
else v[i]=0;
}

ll j=n-1,c=0;i=0;
while(i<j){
if(v[i]==0){
	if(v[j]==0)i++;
	else j--;
}
else{
	if(v[j]==1)j--;
	else {
		swap(v[i],v[j]);i++;j--;c++;
	}
}
}
cout<<c;
}

Measured memory_bytes: 5172
// Parasparopagraho Jīvānām

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std ;
using namespace  __gnu_pbds ;
using namespace __gnu_cxx ;

typedef long long ll ;
typedef long double ld ;

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

typedef vector<int> vi ;
typedef vector<ll> vll ;
typedef vector<pii> vpi ;
typedef vector<pll> vpl;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define per(i,b,a) for (int i = (b); i >= (a); i--)

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fi first
#define se second

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int mod1 = 1000000007 ;
const int mod2 = 998244353 ;
const ll  infl = 2e18 ;
const int infi = 2e9 ;
const int maxn = 200005 ;
const int block = 500 ;
const int logn = 30 ;
const int alpha = 27 ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ;

/* Careful when using long long
__builtin_clz(int x) {} //: the number of zeros at the beginning of the number
__builtin_ctz(int x) {} //: the number of zeros at the end of the number
__builtin_popcount(int x) {} //: the number of ones in the number
__builtin_parity(int x) {} //: the parity (even or odd) of the number of ones*/
ll modpow(ll a, ll b, int MOD) { ll res = 1 ; while(b) { if(b&1) { res = res*a ; res %= MOD ; } a *= a ; a %= MOD ; b >>= 1 ; } return res%MOD ; }
void upmin(int &a, int b) { if(a < b) { a = b ; } }
void relax(int &a, int b) { if(a > b) { a = b ; } }
ll add(ll a, ll b, int MOD) { a += b ; if(a >= MOD) { a -= MOD ; } return  a ; }
ll sub(ll a, ll b, int MOD) { a -= b ; if(a < 0) { a += MOD ; } return a ; }
ll mul(ll a, ll b, int MOD) { b %= MOD ; a *= b ; a %= MOD ; return a ; }
ll inverse(ll a, ll MOD) { a = modpow(a, MOD - 2, MOD) ; return a ; }
ll lcm(ll a, ll b) { ll ret ; ll g = __gcd(a, b) ; ret = a/g ; ret = ret*b ; return ret ; }

int n ;
int p[maxn] ;
int kaha[maxn] ;
int dp[maxn] ;
int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> n ;
    rep(i,0,n-1)
    {
        cin >> p[i] ;
        kaha[p[i]] = i + 1 ;
    }
    rep(i,1,n)
    {
        int abhi = kaha[i] ;
        int pehla = kaha[i-1] ;
        if(abhi > pehla)
        {
            dp[i] = dp[i-1] + 1 ;
        }
        else
        {
            dp[i] = 1 ;
        }
    }
    int res = 0 ;
    rep(i,1,n)
    {
        res = max(res, dp[i]) ;
    }
    res = n - res ;
    cout << res << endl ;
    return 0 ;
}


Measured memory_bytes: 2560
def lengthOfLIS(nums):
    tails = [0] * len(nums)
    size = 0
    for x in nums:
        i, j = 0, size
        while i != j:
            m = (i + j) // 2
            if tails[m] <= x:
                i = m + 1
            else:
                j = m
        tails[i] = x
        size = max(i + 1, size)
    return size
N=int(input())
A=[]
for i in range(N):
    A+=[-int(input())]
print(lengthOfLIS(A))

Measured memory_bytes: 52312
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)

#define vll    vector<ll>
#define vvll   vector<vector<ll>>
#define all(x) (x).begin(),(x).end()

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

	string S;
	cin >> S;

	map<char, ll> counts;

	rep(i, N) counts[S[i]]++;

	ll ans = 1;

	for (auto n : counts)
	{
		ans *= (n.second + 1);
		ans %= mod;
	}

	cout << ans - 1 << endl;

	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

//ICPC: Ideal Coin Payment and Change
public class Main{
	
	int[] p = {1,5,10,50,100,500};
	int[] c;
	
	int pay(int x){
		int r = 0;
		for(int k=5;k>=0;k--){
			int a = Math.min(x/p[k], c[k]);
			r+=a;
			x-=p[k]*a;
		}
		return r;
	}
	
	int get(int x){
		int r = 0;
		for(int k=5;k>=0;k--){
			int c = x/p[k];
			r+=c;
			x-=p[k]*c;
		}
		return r;
	}
	
	void run(){
		int[] r = new int[666001];
		for(int i=0;i<666001;i++)r[i]=get(i);
		Scanner sc = new Scanner(System.in);
		while(true){
			int P = sc.nextInt();
			if(P==0)break;
			c = new int[6];
			int sum = 0;
			for(int i=0;i<6;i++){
				c[i]=sc.nextInt();
				sum+=p[i]*c[i];
			}
			int min = 1<<28;
			for(int i=P;i<=sum;i++){
				min = Math.min(min, pay(i)+r[i-P]);
			}
			System.out.println(min);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    int tmp = 1;
    for(int i=0; i<10; i++){
        tmp *= 2;
        if(tmp > n) break;
    }

    cout << tmp / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
while 1:
    n = int(raw_input())
    if n == 0: break
    steps = raw_input().split()
    lr = [0,0]
    start = 0
    ans = 0
    for step in steps:
        if step[0] == "l":
            if step[1] == "u": lr[0] += 1
            else: lr[0] -= 1
        else:
            if step[1] == "u": lr[1] += 1
            else: lr[1] -= 1
        if (lr == [1,1] and start == 0) or (lr == [0,0] and start == 1):
            ans += 1
            start = lr[0]
    print ans

Measured memory_bytes: 4232
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      System.out.println(s(n,0));
    }
    public static int s(int n,int c){
      if(n < 6)return n+c;
      int a = 1;
      int b = 1;
      while(a*6<=n)a*=6;
      while(b*9<=n)b*=9;
      return Math.min(s(n-a,c+1),s(n-b,c+1));
    }
}

Measured memory_bytes: 23892
#include <stdio.h>
#define N 100001

typedef struct{
  int parent;
  int left;
  int right;
}Node;

Node T[N];

int main(){
  int n, i, j, buf;
  int ID, degree, depth[N];
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
   T[i].parent = -1;
   T[i].left = N;
   T[i].right = N;
   depth[i] = 0;
 }
  
 for(i = 0; i < n; i++){
   scanf("%d%d", &ID, &degree);
   
 if(degree == 1){
   scanf("%d",&T[ID].left);
   buf = T[ID].left;
   T[buf].parent = ID;
 }
 else if(degree > 1){
   scanf("%d",&T[ID].left);
   buf = T[ID].left;
   for(j = 1; j < degree; j++){
     scanf("%d", &T[buf].right);
     T[buf].parent = ID;
     buf = T[buf].right;
   }
   T[buf].parent = ID;
 }
 }
 
 for(i = 0; i < n; i++){
buf = T[i].parent;
 while(1){
   if(buf == -1) break;
else {
  buf = T[buf].parent;
  depth[i]++;
 }
 }
 printf("node %d: parent = %d, depth = %d,", i, T[i].parent, depth[i]);
 
 if(T[i].parent == -1){
   if(T[i].left == N) printf(" root, []\n");
   else{
     printf(" root, [%d", T[i].left);
     buf = T[i].left;
     while(T[buf].right != N){
       printf(", %d", T[buf].right);
       buf = T[buf].right;
     }
     printf("]\n");
   }
 }
 else if(T[i].left == N)
   printf(" leaf, []\n");
 else{
   printf(" internal node, [%d", T[i].left);
   buf = T[i].left;
   while(T[buf].right != N){
     printf(", %d", T[buf].right);
     buf = T[buf].right;
   }
   printf("]\n");
}
 }
 return 0;
}

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

#define endl '\n'

const int N = (int) 1e5 + 9;
const int inf = (int)2e9;

int A[N], B[N], C[N], BB[N];
long long S[N];

int main() {

    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf(" %d", &A[i]);
    }
    for(int i = 0; i < n; i++) {
        scanf(" %d", &B[i]);
    } 
    for(int i = 0; i < n; i++) {
        scanf(" %d", &C[i]);
    }
    sort(A, A + n);
    sort(B, B + n);
    sort(C, C + n);
    
    for(int i = 0; i < n; i++) {
        int l = 0;
        int r = n - 1;
        int mid;
        int sub = -inf;
        while(l <= r) {
            mid = (l + r) / 2;
            if(A[mid] < B[i]) {
                l = mid + 1;
                sub = max(sub, mid);
            }
            else {
                r = mid - 1;
            }
        }
        if(sub != -inf) {
            BB[i] = sub + 1;
        }
    }

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

    S[0] = BB[0];
    for(int i = 1; i < n; i++) {
        S[i] = S[i - 1] + BB[i];
    }

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

    long long res = 0;
    for(int i = 0; i < n; i++) {
        int l = 0;
        int r = n - 1;
        int mid;
        int sub = -inf;
        while(l <= r) {
            mid = (l + r) / 2;
            if(B[mid] < C[i]) {
                l = mid + 1;
                sub = max(sub, mid);
            }
            else {
                r = mid - 1;
            }
        }
        if(sub != -inf) {
            res += S[sub];
        }
        
    }
    printf("%lld", res);

    return 0;
}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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



int main(){
	int n;
	string str;
	while(getline(cin,str)){
		sscanf(str.c_str(),"%d",&n);
		if(n==0) break;

		int** stage = new int*[n];
		for(int i=0;i<n;i++) stage[i] = new int[n];


		for(int i=0;i<n;i++){
			getline(cin,str);
			for(int j=0;j<n;j++){
				if(str[j]=='*')	stage[i][j] = 1;
				else stage[i][j] = 0;
			}
		}

		int ub = 1000;
		int lb = 0;
		int md;

		for(int i=0;i<20;i++){
			md = (ub+lb) / 2;
			
			bool ok=false;
			for(int sy=0;sy+md-1<n;sy++){
				for(int sx=0;sx+md-1<n;sx++){
					ok = true;

					for(int y=0;y<md;y++){
						for(int x=0;x<md;x++){
							if(stage[y+sy][x+sx] == 1){
								ok=false;
								goto cant;
							}
						}
					}
cant:;
					if(ok) goto found;
				}
			}
found:;
			if(ok) lb = md;
			else ub = md;
		}

		cout << md << endl;

		for(int i=0;i<n;i++) delete[] stage[i];
		delete[] stage;
	}
}

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

int main(void)
{
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main() 
{
	char a[50],b[50];
	cin>>a>>b;
	int n=strlen(b);
	for(int i=0;i<n;i++)
	{
		cout<<a[i]<<b[i];
	}
	if(a[n])
	{
		cout<<a[n];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,s;
    cin >> k >> s;
    int count = 0;
    for(int x = 0;x <= k;x++)
    {
        for(int y = x;y <= k;y++)
        {
            for(int z = y;z <= k;z++)
            {
                if(x + y + z == s)
                {
                    if(x == y && x == z)
                    {
                        count += 1;
                    }
                    else if(x == y || x == z || y == z)
                    {
                        count += 3;
                    }
                    else
                    {
                        count += 6;
                    }
                }
            }
        }
    }
    cout << count << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 31

int N, M;
int adj_matrix[MAX][MAX] = {};
int main(){
    cin >> N >> M;
    for (int i = 1; i <= N; i++){
        int k;
        cin >> k;
        for (int j = 0; j < k; j++){
            int A;
            cin >> A;
            adj_matrix[i][A] = 1;
        }
    }
    int num = 0;
    for (int i = 1; i <= M; i++){
        int val = 0;
        for (int j = 1; j <= N; j++){
            val += adj_matrix[j][i];
        }
        if (val == N){
            num += 1;
        }
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int x,y,a,b,c,A[N],B[N],C[N];
priority_queue<int,vector<int>,greater<int>>q;
int main()
{
    scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
    for(int i=1;i<=a;i++) scanf("%d",&A[i]);
    for(int i=1;i<=b;i++) scanf("%d",&B[i]);
    for(int i=1;i<=c;i++) scanf("%d",&C[i]);
    sort(A+1,A+1+a,greater<int>());
    sort(B+1,B+1+b,greater<int>());
    sort(C+1,C+1+c,greater<int>());
    for(int i=1;i<=x;i++) q.push(A[i]);
    for(int i=1;i<=y;i++) q.push(B[i]);
    for(int i=1;i<=c;i++)
        if(q.top()<C[i])
    {
        q.pop();q.push(C[i]);
    }
    ll ans=0;
    while(!q.empty()) ans+=q.top(),q.pop();
    printf("%lld\n",ans);
}


Measured memory_bytes: 2552
#include <stdio.h>

int main()
{
	unsigned int N;
	char *S;
	char flag = 0b00000000;	//下位4bitをPWGYのフラグとする

	scanf("%d\n", &N);
	S = (char *)malloc(sizeof(char) * N);
	for(int i = 0; i < N; i++){
		scanf("%c ", &S[i]);
	}

	for(int i = 0; i < N; i++){
		if('P' == S[i]){flag = (flag|0b00001000);}
		else if('W' == S[i]){flag = (flag|0b00000100);}
		else if('G' == S[i]){flag = (flag|0b00000010);}
		else if('Y' == S[i]){flag = (flag|0b00000001);}

		if(0b00001111 == flag){break;}
	}

	if(0b00001111 == flag){printf("Four\n");}
	else{printf("Three\n");}
	
	return 0;
}

Measured memory_bytes: 128
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
       1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(arr[n-1])

Measured memory_bytes: 3060
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long
#define ld double
#define ull unsigned long long
#define PI pair < int, int > 

const int N = 512 * 512;
const int M = 123;
const ld Pi = acos(-1);
const ll Inf = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int Sz = 501;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) {
  return 1ll * a * b % mod;
}
int sum(int a, int b) {
  add(a, b);
  return a;
}

int n, a[N], x[N], cnt[N], id[N], num[N], C[N];
pair < int, int > arr[N];

void solve() { 
  cin >> n;
  for (int i = 1;i <= n;i++) {
    cin >> x[i];
    if (cnt[x[i]]) {
      cout << "No\n";
      return;
    }
    num[i] = n;
    cnt[x[i]] = i;
  }
  for (int i = 1, used = 0;i <= n * n;i++) {
    if (cnt[i]) {
      if (i - used < cnt[i]) {
        cout << "No\n";
        return;
      }
      used += cnt[i];
    }
  }
  queue < int > q;
  for (int i = 1;i <= n * n;i++) {
    if (cnt[i]) {
      int x = cnt[i];
      a[i] = x;
      num[x]--;
      for (int it = 1;it < x;it++) {
        a[q.front()] = x;
        q.pop();
        num[x]--;
      }
    } else {
      q.push(i);
    }
  }
  for (int i = 1;i <= n;i++) arr[i] = {x[i], i};
  sort(arr + 1, arr + n + 1);
  reverse(arr + 1, arr + n + 1);
  int ptr = 1;
  for (int i = n * n;i;i--) {
    if (!a[i]) {
      while(num[arr[ptr].s] == 0) ptr++;
      a[i] = arr[ptr].s;
      num[arr[ptr].s]--;
    }
  }
  for (int i = 1;i <= n * n;i++) {
    C[a[i]]++;
    if (cnt[i] > 0) {
      int x = cnt[i];
      if (C[x] != x) {
        cout << "No\n";
        return;
      }
    }
  }
  cout << "Yes\n";
  for (int i = 1, ptr = 0;i <= n * n;i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
  
int main() {
  #ifdef wws
   freopen("in", "r", stdin);
   // freopen("in", "w", stdout);
  #endif 
  ios_base::sync_with_stdio(0);
  int tt = 1; 
  while(tt--) solve();
  return 0;
}

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

int main(){
	string b;
	cin>>b;
	if(b[0]=='A'){
		cout<<"T";
	}else if(b[0]=='C'){
		cout<<"G";
	}else if(b[0]=='G'){
		cout<<"C";
	}else{
		cout<<"A";
	}
	cout<<endl;
	return 0;
}

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

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

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ull fun(ull n) {
	if (n < 2) {
		return 1;
	} else {
		return n * fun(n - 2);
	}
}

int main() {
	int w, h, n;
	cin >> w >> h >> n;
	vector<int> x(n), y(n), a(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> a[i];
	}
	vector<vector<int>> ans(w, vector<int>(h));
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			ans[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		switch(a[i]) {
			case 1:
				for (int j = 0; j < h; j++) {
					for (int k = 0; k < x[i]; k++) {
						ans[k][j] = 1;
					}
				}
				break;
			case 2:
				for (int j = 0; j < h; j++) {
					for (int k = x[i]; k < w; k++) {
						ans[k][j] = 1;
					}
				}
				break;
			case 3:
				for (int j = 0; j < w; j++) {
					for (int k = 0; k < y[i]; k++) {
						ans[j][k] = 1;
					}
				}
				break;
			case 4:
				for (int j = 0; j < w; j++) {
					for (int k = y[i]; k < h; k++) {
						ans[j][k] = 1;
					}
				}
				break;
		}
	}

	int count = 0;
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			if (ans[i][j] == 0) {
				count++;
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256