akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;

int N;
vector<int> p, q;

int main() {
    cin >> N;
    vector<int> p(N), q(N);
    for (int i = 0; i < N; ++i) cin >> p[i], --p[i];
    for (int i = 0; i < N; ++i) cin >> q[i], --q[i];

    // 各順列が何番目かを求める
    map<vector<int>, int> ord;
    int iter = 0;

    // スタートとなる順列
    vector<int> v(N);
    for (int i = 0; i < N; ++i) v[i] = i;

    // 順番に
    do {
        ord[v] = iter++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(ord[p] - ord[q]) << endl;
}

Measured memory_bytes: 8652
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
using namespace std;
const int maxn = 200100;
ll moves[30], n, q;
string code;

char l[maxn], d[maxn];
bool checkleft(int x) {
    for(int i=0;i<q;i++) {
        if(x == 0) return true;
        if(l[i] == code[x-1]) {
            if(d[i] == 'R') x++;
            else x--;
        }
    }

    if(x == 0) return true;
    else return false;
}

bool checkright(int x) {
    for(int i=0;i<q;i++) {
        if(x == n+1) return true;
        if(l[i] == code[x-1]) {
            if(d[i] == 'R') x++;
            else x--;
        }
    }

    if(x == n+1) return true;
    else return false;
}

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

    for(int i=0;i<q;i++) {
        cin>>l[i]>>d[i];
    }

    int l_most = 0;
    for(int cekor=n/2;cekor>0;cekor/=2) {
        while(l_most + cekor <= n && checkleft(l_most+cekor)) l_most += cekor;
    }

    int r_most = n+1;
    for(int cekor=n/2;cekor>0;cekor/=2) {
        while(r_most - cekor >= 0 && checkright(r_most-cekor)) r_most -= cekor;
    }
    cout<<r_most-l_most-1<<"\n";
    return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
string s,w;
int h;
int main()
{
    cin>>s;
    w=s;
    reverse(w.begin(),w.end());
    if(s==w)cout<<h;
    else
    {
        for(int i=0;i<s.size();i++)
        {
            if(s[i]!=w[i])
            {
                h++;
            }
        }
         cout<<h/2;
    }

    return 0;
}


Measured memory_bytes: 256
n = input()
n = int(n)
b = input().split()
b = [int(i) for i in b]

a = []
a.append(b[0])
for i in range(n):
    if i+1 == n-1:
      a.append(b[i])
      break
    if b[i] < b[i+1]:
      a.append(b[i])
    else:
      a.append(b[i+1])
print(sum(a))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    string s[n];
    rep(i,n){
        cin>>s[i];
    }

    int g[n][n];
    rep(i,n){
        rep(j,n){
            if(s[i][j]=='1'){
                g[i][j]=1;
            }
            else{
                g[i][j]=INF;
            }
        }
    }

    rep(k,n){rep(i,n){rep(j,n){
        g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
    }}}
    int ans=-1;
    for(int st=0;st<n;st++){
        bool f=true;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++)if(s[i][j]=='1'){
                if(abs(g[st][i]-g[st][j])!=1){
                    f=false;
                }
            }
        }
        if(!f) continue;
        int gr=0;
        rep(i,n){
            if(i==st) continue;
            gr=max(gr,g[st][i]);
        }
        gr++;
        ans=max(ans,gr);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
import itertools

n = int(input())
A = list(map(int, input().split()))

p = list(itertools.permutations(A))
A2 = sorted(p)

index = A2.index(tuple(A))
if index - 1 >= 0:
    print(*A2[index - 1])

print(*A2[index])

if index + 1 < len(A2):
    print(*A2[index + 1])


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

int n, m;
typedef pair<int, int> P;
vector<P> v;
long long ans;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=0; i<n; ++i){
		int a, b;
		cin >> a >> b;
		v.push_back(P(a, b));
	}
	sort(v.begin(), v.end());
	for(int i=0; i<n; ++i){
		int t = min(m, v[i].second);
		ans += (long long)v[i].first * t;
		m -= t;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int a,b,c;
    cin >> a>>b>>c;
    if(a%c==0){
        cout<<b/c-a/c+1<<endl;
    }else{
        cout<<b/c-a/c<<endl;
    }
    
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N; cin>>N;
    vector<int> A(N),B(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        B[i]=A[i];
    }
    sort(B.begin(),B.end());
    int Amax=B[N-1];
    int Asecond=B[N-2];
    for(int i=0;i<N;i++){
        if(A[i]==Amax){
            cout<<Asecond<<endl;
        }
        else {
            cout<<Amax<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
import java.util.*;

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

    long a = s.nextLong();
    long b = s.nextLong();
    long c = s.nextLong();  // 0.5a + 0.5b
    long x = s.nextLong();
    long y = s.nextLong();

    long minCost = Long.MAX_VALUE;
    for (int i = 0; i <= Math.max(x, y); i++) {
      long cost = i * (2 * c) + Math.max(x - i, 0) * a + Math.max(y - i, 0) * b;
      minCost = Math.min(minCost, cost);
    }
    System.out.println(minCost);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define N 100001
#define ll long long
using namespace std;

ll abs(ll a, ll b){
    if (a>=b) return a-b;
    else return b-a;
}

int main(){
    ll n;
    cin>>n;
    
    ll data[n+1];
    vector<ll> num;
    for (ll i=1; i<=n; i++){
        cin>>data[i];
        num.push_back(data[i]-i);
    }
    
    sort(num.begin(),num.end());
    
    ll sum=0;
    ll v=num.size()/2;
    ll p=num[v];
    
    for (ll i=0; i<n; i++){
        sum+=abs(num[i]-p);
    }
    
    cout<<sum<<endl;
}

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

constexpr ll INF = 2000000000000000;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    ll sum = 0;
    rep(i,n) {
        sum += a[i];
    }
    ll counter = 0;
    ll ans = INF;
    rep(i,n-1) {
        counter += a[i];
        ll diff = sum - counter;
        ans = min(ans,abs(counter-diff));
    }
    cout << ans << "\n";
    return 0;
}

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



int main(){
    string a,b,c;
    cin>>a>>b>>c;

    if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;


    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

type Dice struct {
	T, S, E, W, N, B int
}

func (p *Dice) roll(direction rune) {

	if direction == 'S' {
		p.S, p.B, p.N, p.T = p.T, p.S, p.B, p.N
	} else if direction == 'N' {
		p.N, p.B, p.S, p.T = p.T, p.N, p.B, p.S
	} else if direction == 'W' {
		p.W, p.B, p.E, p.T = p.T, p.W, p.B, p.E
	} else if direction == 'E' {
		p.E, p.B, p.W, p.T = p.T, p.E, p.B, p.W
	}

}

func (p *Dice) matching(d Dice) bool {

	ret := false
	//6面がそれぞれ一度top
	for i := 0; i < 6; i++ {

		for j := 0; j < 4; j++ { //側面を一周
			if (p.T == d.T) && (p.S == d.S) && (p.E == d.E) && (p.W == d.W) && (p.N == d.N) && (p.B == d.B) {
				ret = true
				break
			} else {
				p.roll('N')
				p.roll('W')
				p.roll('S')
			}
		}

		if i%2 == 0 {
			p.roll('N')
		} else {
			p.roll('W')
		}
	}
	return ret
}

func main() {

	var t, s, e, w, n, b int

	fmt.Scanln(&t, &s, &e, &w, &n, &b)
	dice1 := Dice{t, s, e, w, n, b}

	fmt.Scanln(&t, &s, &e, &w, &n, &b)
	dice2 := Dice{t, s, e, w, n, b}

	if dice2.matching(dice1) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}



Measured memory_bytes: 1124
class BinarySearchTree:
    root = None
    def insert(self, k):
        y = None
        x = self.root
        z = Node(k)
        while x:
            y = x
            if z.k < x.k:
                x = x.l
            else:
                x = x.r
        z.p = y
         
        if y == None:
            self.root = z
        else:
            if z.k < y.k:
                y.l = z
            else:
                y.r = z
                
    def find(self, x, k):
        while x != None and k != x.k:
            if k < x.k:
                x = x.l
            else:
                x = x.r
        return x
         
    def preParse(self, u):
        if u == None:
            return
        print("", str(u.k), end = "")
        self.preParse(u.l)
        self.preParse(u.r)
 
    def inParse(self, u):
        if u == None:
            return
        self.inParse(u.l)
        print("", str(u.k), end = "")
        self.inParse(u.r)
 
class Node: 
    def __init__(self, k):
        self.k = k
        self.p = None
        self.l = None
        self.r = None
 
if __name__ == '__main__':
    n = int(input().rstrip())
    x = BinarySearchTree()
    for i in range(n):
        com = input().rstrip()
        if com.startswith("insert"):
            k = int(com.split(" ")[1])
            x.insert(k)
        elif com.startswith("find"):
            k = int(com.split(" ")[1])
            if x.find(x.root, k) != None:
                print("yes")
            else:
                print("no")
        else:
            x.inParse(x.root)
            print()
            x.preParse(x.root)
            print()

Measured memory_bytes: 124668
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        if (s == "A") Console.WriteLine("T");
        if (s == "T") Console.WriteLine("A");
        if (s == "G") Console.WriteLine("C");
        if (s == "C") Console.WriteLine("G");
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int main(void)
{
    int h,w,a[500][500],n=0,t[500][500],i,j;
    scanf("%d%d",&h,&w);
    for(i=0;i<h;++i){
        for(j=0;j<w;++j){
            scanf("%d",&a[i][j]);
            t[i][j]=a[i][j];
        }
    }
    for(i=0;i<h-1;++i){
        for(j=0;j<w;++j){
            if(t[i][j]%2){
                --t[i][j];
                ++t[i+1][j];
                ++n;
            }
        }
    }
    for(i=0;i<w-1;++i){
        if(t[h-1][i]%2){
            --t[h-1][i];
            ++t[h-1][i+1];
            ++n;
        }
    }
    printf("%d\n",n);
    for(i=0;i<h-1;++i){
        for(j=0;j<w;++j){
            if(a[i][j]%2){
                --a[i][j];
                ++a[i+1][j];
                printf("%d %d %d %d\n",i+1,j+1,i+2,j+1);
            }
        }
    }
    for(i=0;i<w-1;++i){
        if(a[h-1][i]%2){
            --a[h-1][i];
            ++a[h-1][i+1];
            printf("%d %d %d %d\n",h,i+1,h,i+2);
        }
    }
    return 0;
}

Measured memory_bytes: 3968
ars = "abcdefghijklmnopqrstuvwxyz"
S = input()
def iftasai(s):
  for i in s:
    if s.count(i) > 1:
      return False
  return True
if len(S) != 26:
  for i in ars:
    if not (i in S):
      print(S + i)
      quit()
elif S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  quit()
else:
  for i in range(1,len(S)+1):
    n = ars.index(S[-i])
    tmp = ars[n+1:]
    for j in tmp:
      ans = S[:-i] + j
      if iftasai(ans):
        print(ans)
        quit()
  n = ars.index(S[0])
  print(ars[n+1:])

Measured memory_bytes: 39152
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

from collections import defaultdict

class Node:
    def __init__(self, key):
        self.key = key
        self.par = -1
        self.left = -1
        self.right = -1

root = None
nodes = defaultdict(lambda: None)

def insert(z):
    global root
    # yはxの親
    y = None
    x = root
    # zの親となるべきノードを探す
    while x is not None:
        y = x
        if z.key < x.key:
            # 左の子に移動
            x = nodes[x.left]
        else:
            # 右の子に移動
            x = nodes[x.right]
    if y is None:
        z.par = -1
    else:
        z.par = y.key
    
    if y is None:
        # Tが空の場合
        root = z
    elif z.key < y.key:
        # zをyの左の子にする
        y.left = z.key
    else:
        # zをyの右の子にする
        y.right = z.key

def find(key):
    if nodes[key]:
        print('yes')
    else:
        print('no')

def tree_walk(node):
    preo.append(node.key)
    if node.left != -1:
        tree_walk(nodes[node.left])
    ino.append(node.key)
    if node.right != -1:
        tree_walk(nodes[node.right])
    return

N = INT()

for _ in range(N):
    instr = input()
    if instr == 'print':
        preo = []
        ino = []
        tree_walk(root)
        print('', *ino)
        print('', *preo)
    elif instr.startswith('insert'):
        _, key = instr.split()
        key = int(key)
        node = Node(key)
        nodes[key] = node
        insert(node)
    else:
        _, key = instr.split()
        find(int(key))



Measured memory_bytes: 121948
import sys

sys.setrecursionlimit(100000)
N = int(raw_input())
act = [map(int, raw_input().split()) for _ in range(N)]
memo = [[-1]*3 for _ in range(N)]

def happy(n, i):
  if memo[n][i] >= 0:
    return memo[n][i]
  if n == 0:
    h = act[n][i]
  else:
    h = -1
    for j in range(3):
      if j == i:
        continue
      c = happy(n-1,j)+act[n][i]
      h = h if h > c else c
  memo[n][i] = h
  return h
print max(happy(N-1,0),happy(N-1,1),happy(N-1,2))



Measured memory_bytes: 138268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int h = t / 3600;
		int m = (t - h * 3600) / 60;
		int s = t - h * 3600 - m * 60;
		System.out.printf("%d:%d:%d\n", h, m, s);
	}

}


Measured memory_bytes: 26204
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}
/*
ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}*/
int main() {
	cin >> n;
	vector<ll> a(n);
	map<ll, ll> mp;
	rep(i, n) {
		cin >> a[i];
		mp[a[i]]++;
	}
	ll q;
	cin >> q;
	vector<P> bc(q);
	rep(i, q) {
		cin >> bc[i].first >> bc[i].second;
	}
	ll sum = 0;
	rep(i, n) {
		sum += a[i];
	}
	rep(i, q) {
		sum -= bc[i].first * mp[bc[i].first];
		sum += bc[i].second * mp[bc[i].first];
		mp[bc[i].second] += mp[bc[i].first];
		mp[bc[i].first] = 0;
		cout << sum << endl;
	}
}


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

int main(){
  int n,i;
  ll s=0;
  cin >> n;
  vector<int> a(n),num(100001,0);
  for(i=0;i<n;i++){
    cin >> a.at(i);
    s += a.at(i);
    num.at(a.at(i))++;
  }
  int q;
  cin >> q;
  vector<int> b(q),c(q);
  for(i=0;i<q;i++){
    cin >> b.at(i) >> c.at(i);
    s += (c.at(i)-b.at(i))*num.at(b.at(i));
    cout << s << endl;
    num.at(c.at(i)) += num.at(b.at(i));
    num.at(b.at(i))=0;
  }
}
  

Measured memory_bytes: 4796
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
ll mo=1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t)
    {
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll red=0;
        ll white=0;
        for(ll i=0;i<s.length();i++){
            if(s[i]=='W')white++;
            else red++;
        }
        string s1="";
        while(red){
            s1+="R";
            red--;
        }
        while(white){
            s1+="W";
            white--;
        }
        ll count=0;
        for(ll i=0;i<s.length();i++){
            if(s1[i]=='W')break;
            else if(s[i]!=s1[i])count++;
        }
        cout<<count<<endl;
        t--;
    }
}

Measured memory_bytes: 3880
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 && W==0){
                break;
            }
            if(1 > H || W > 300){
                continue;
            }
             
            for(int i=0; i<H; i++){
                for(int j=0; j<W; j++){
                    System.out.print('#');
                }
                System.out.println("");
            }
            System.out.println("");
        }
 
    }
 
}



Measured memory_bytes: 34704
#include<stdio.h>

int main(void) {

	int n;
	char s[51];
	int ans = 0;
	scanf("%d", &n);
	scanf("%s", s);
	for (int i = 0; i < n-2; i++) {
		if (s[i] == 'A') {
			if (s[i + 1] == 'B') {
				if (s[i + 2] == 'C') {
					ans++;
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

struct UF{
    vi par;
    vi rank;

    UF( int n ){
        init(n);
    }

    void init( int n ){
        par.assign(n,0);
        for( int i = 0; i < n; i++ ) par[i] = i;
        rank.assign(n,0);
    }

    int find( int x ){
        if( par[x] == x ) return x;
        else return par[x] = find(par[x]);
    }

    int unite( int x, int y ){
        x = find(x);
        y = find(y);
        if( x == y ) return -1;
        if( rank[x] < rank[y] ){
            par[x] = y;
        }else{
            par[y] = x;
            if( rank[x] == rank[y] ) rank[x]++;
        }
        return 1;
    }

    bool same( int x, int y ) {
        return find(x) == find(y);
    }

};

int main() {

    int N,M,K;
    Scd3(N,M,K);

    UF u(N+M);
    Repe(i,N+M,N) u.rank[i] = INF;

    int q,a,b;
    Rep(i,K){
        Scd3(q,a,b);
        a--,b--;
        if( q == 1 ){
            int xa = u.find(a);
            int xb = u.find(b);
            if( xa >= N && xb >= N && xa != xb ) { 
                printf ("%lld\n", i+1);
                return 0;
            }
            u.unite(a,b);
        }else{
            int xa = u.find(a);
            int xb = b+N;
            if( xa >= N && xb >= N && xa != xb ) { 
                printf ("%lld\n", i+1);
                return 0;
            }
            u.unite(a,b+N);
        }
    }

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

    return 0;
}





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

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

    cout << t + s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int n,m,x;
const int maxn = 1e5+10;
long long a[maxn],b[maxn];
int main(){
    ll i,j,k;
    ll ans;
    ll now;
    ll comm;
    scanf("%d",&n);
        ans = 0;
        now = 0;
        for(i=1;i<=n;i++){
            scanf("%lld%lld",&a[i],&b[i]);
        }
        
        for(i=n;i>=1;i--){
            a[i] += ans;
            for(j=a[i]/b[i];;j++){
                if(j*b[i]>=a[i]){
                    break;
                }
            }
            comm = j*b[i] - a[i];
            ans += comm;
        }
        printf("%lld\n",ans);
    
    
}

Measured memory_bytes: 1792
from math import ceil
from itertools import accumulate
n = int(input())
import math
import decimal
import collections
import itertools
import sys
#Union-Find
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def unite(x, y):
    p = find(x)
    q = find(y)
    if p == q:
        return None
    if p > q:
        p,q = q,p
    par[p] += par[q]
    par[q] = p
def same(x, y):
    return find(x) == find(y)
def size(x):
    return -par[find(x)]
par = [-1 for i in range(n)]

#素数関連
def prime_numbers(x):
    if x < 2:
        return []
    prime_numbers = [i for i in range(x)]
    prime_numbers[1] = 0
    for prime_number in prime_numbers:
        if prime_number > math.sqrt(x):
            break
        if prime_number == 0:
            continue
        for composite_number in range(2 * prime_number, x, prime_number):
            prime_numbers[composite_number] = 0
    return [prime_number for prime_number in prime_numbers if prime_number != 0]
def is_prime(x):
    if x < 2:
        return False
    if x == 2 or x == 3 or x == 5:
        return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
        return False
    prime_number = 7
    difference = 4
    while prime_number <= math.sqrt(x):
        if x % prime_number == 0:
            return False
        prime_number += difference
        difference = 6 - difference
    return True
#nCr
mod = 10 ** 9 + 7
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
fa = [1] * (n + 1)
fi = [1] * (n + 1)
for i in range(1, n + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
def add(i, x):
    while i <= len(BIT):
        BIT[i] += x
        i += i & -i
def query(i):
    s = 0
    while i > 0:
        s += BIT[i]
        i -= i & -i
    return s
a = list(map(int, input().split()))
lis = sorted(list(set(a)))
l, r = 0, len(lis)
while r - l > 1:
    BIT = [0] * (2 * (n + 1) + 100)
    m = (l + r) // 2
    cum = [0]
    for i in range(n):
        cur = 1 if a[i] >= lis[m] else -1
        cum.append(cum[-1] + cur)
    cnt = 0
    for i in range(n + 1):
        cur = n + cum[i] + 5
        cnt += query(cur)
        add(cur, 1)
    if n * (n + 1) // 2 <= cnt * 2:
        l = m 
    else:
        r = m
print(lis[l])

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

int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    vector<char> ans(2 * N);
    rep(i, N){
        ans.at(2 * i) = S.at(i);
        ans.at(2 * i + 1) = T.at(i);
    }

    rep(i, 2 * N){
        cout << ans.at(i);
        if (i == 2 * N - 1){
            cout << endl;
            return 0;
        }
    }
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int H,W,x,y; cin >> H >> W >> x >> y;
    double ans = (double)H*W/2;
    cout << ans << " ";
    cout << (H-x==x && W-y==y ? 1 : 0) << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
int main()
{
	int N;
	std::cin >> N;
	std::vector<int64_t> A(N);
	for (int i = 0; i < N; ++i) {
		std::cin >> A[i];
		if (A[i] == 0) {
			std::cout << 0 << std::endl;
			return 0;
		}
	}

	int64_t ans = 1;
	for (int i = 0; i < N; ++i) {
		if (A[i] > (1000000000000000000LL + ans - 1) / ans) {
			std::cout << -1 << std::endl;
			return 0;
		}
		ans *= A[i];
		if (ans > 1000000000000000000LL) {
			std::cout << -1 << std::endl;
			return 0;
		}
	}
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 4052
l, r = [int(s) for s in input().split()]

mod_l = l % 2019
mod_r = r % 2019

if (r - l > 2018) or (mod_l > mod_r):
  print('0')
else:
  vmin = 2018
  for i in range(mod_l, mod_r):
    for j in range(i+1, mod_r+1):
      mod = (i * j) % 2019
      if mod < vmin:
        vmin = mod

  print(vmin)


Measured memory_bytes: 3060
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007
#define int long long

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

signed main()
{
    int n;
    cin >> n;
    int a[n];
    REP(i, n)
    {
        cin >> a[i];
    }
    int ansn = *max_element(a, a + n);
    cout << ansn << " ";
    int ansk = *min_element(a, a + n);
    REP(i, n)
    {
        if (abs(ansn / 2 - ansk) > abs(ansn / 2 - a[i]))
        {
            ansk = a[i];
        }
    }
    cout << ansk << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) {if (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int MOD = 1000000007;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main() {
    int N, W;
    cin >> N >> W;
    vi w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    vvll dp(N+1, vll(W+1, 0));
    
    reps(i, N) {
        reps(j, W) {
            chmax(dp[i][j], dp[i-1][j]);
            if (j-w[i-1] >= 0) {
                chmax(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1]);
            }
        }
    }
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAX=200004;
int cnt[MAX],fin,n;
main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int t;
        scanf("%d",&t);
        cnt[t]++;
    }
    for(int i=0;i<MAX-100;i++){
        fin=max(fin,cnt[i]+cnt[i+1]+cnt[i+2]);
    }
    printf("%d\n",fin);
}


Measured memory_bytes: 640
function parse(input) {
  const arr = input.split("\n")[0].split(" ")
  const n = parseInt(arr[0], 10)
  const k = parseInt(arr[1], 10)

  return [n, k]
}

function f(n, k) {
  return n % k ? 1 : 0
}

module.exports = {
  f,
  parse,
}

function Main(input) {
  const arr = parse(input)
  const n = arr[0]
  const k = arr[1]

  console.log(f(n, k))
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 7372
N= int(input())
blue_list = []
for i in range(N):
  blue_list.append(input())
M = int(input())
red_list = []
for j in range(M):
  red_list.append(input())
ans_list =[]
for i in range(len(blue_list)):
  bl = blue_list.count(blue_list[i])
  rl = red_list.count(blue_list[i])
  ans_list.append(bl-rl)
if max(ans_list) >= 0:
  print(max(ans_list))
else:
  print(0)


Measured memory_bytes: 3064
local k, n = io.read("*n", "*n")
local t = {}

if k % 2 == 0 then
  table.insert(t, k / 2)
  for i = 1, n - 1 do table.insert(t, k) end
else
  local hk = (k + 1) / 2
  for i = 1, n do t[i] = hk end
  local decnum = math.ceil((n - 1) / 2)
  local curpos = n
  for i = 1, decnum do
    for j = curpos, 1, -1 do
      if 0 < t[j] then
        t[j] = t[j] - 1
        if t[j] ~= 0 then
          for s = j + 1, n do
            t[s] = k
          end
          curpos = n
        else
          curpos = curpos - 1
        end
        break
      end
    end
  end
  for i = 1, n do
    if t[i] == 0 then
      for j = i, n do
        table.remove(t)
      end
      break
    end
  end
end

print(table.concat(t, " "))


Measured memory_bytes: 13048
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int targetPrice = sc.nextInt();

        int res = 0;// targetPriceになるパターン数
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= b; j++) {
                for (int k = 0; k <= c; k++) {
                    int sum = (500*i) + (100*j) + (50*k);
                    if (targetPrice == sum) res++;
                }
            }
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)
template<class F,class S>void add(map<F,S>&mp,F f,S s){if(mp.find(f)==mp.end())mp[f]=F();mp[f]+=s;}

bool sign(ll a){
    return a>=0;
}

int main(){
    dcl(x,y);
    rep(i,100){
        if(x*2>y){
            cout<<i+1<<endl;
            break;
        }
        x*=2;
    }
}


Measured memory_bytes: 256
import math

N, D = map(int, input().split())
x_list = [ [] for n in range(N)]
for n in range(N):
    x_list[n] = list(map(int, input().split()))

count = 0
for i in range(N):
    for j in range(i+1,N):
        if math.sqrt(sum([ (x_list[i][d] - x_list[j][d])**2  for d in range(D)]))%1==0:
            count += 1

print(count)

Measured memory_bytes: 3064
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 100002;

int n, c, k;

int t[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> c >> k;
    for(int i = 1; i <= n; i++)
        cin >> t[i];
    sort(t + 1, t + n + 1);
    int cnt = 1;
    int first = t[1];
    int ans = 1;
    for(int i = 2; i <= n; i++)
    {
        if(first + k < t[i] || cnt >= c)
        {
            ans++;
            first = t[i];
            cnt = 0;
        }
        cnt++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4048
#include <iostream>

using namespace std;

int main()
{
    int n, m;
    int masu[1001], sai[1001];
    int current = 1;

    cin >> n >> m;

    while (n != 0 && m != 0) {

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

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

        for (int i = 0; i < m; i++) {
            current += sai[i];

            current += masu[current];

            if (current >= n) {
                cout << i+1 << endl;
                break;
            }
        }

        current = 1;

        cin >> n >> m;
    }
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
  ll n;
  cin>>n;
  if(n==7||n==5||n==3)
    YES
  else
    NO

}
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;


#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
    if(ch == 'A') {
        return 1;
    } else if(ch == 'C'){
        return 2;
    } else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    } else {
        return 0;
    }
}

long long getKey(char str[]) {
    long long sum = 0,p = 1,i;
    for(i = 0; i< strlen(str);i++) {
        sum+= p*(getChar(str[i]));
        p*=5;
    }
    return sum;
}

int h1(int key) {
    return key % M;
}

int h2(int key) {
    return 1+ (key%(M-1));
}

int find(char str[]) {
    long long key,i,h;
    key = getKey(str);

    for(i = 0;;i++) {
        h = (h1(key) + i*h2(key)) % M;
        if(strcmp(H[h],str) == 0) {
            return 1;
        } else if(strlen(H[h]) == 0) {

            return 0;
        }
    }

    return 0;

}


int insert(char str[]) {
    long long key,i,h;
    key = getKey(str);

    for(i = 0;;i++) {
        h = (h1(key) + i*h2(key)) % M;
        if(strcmp(H[h],str) == 0) {
            return 1;
        } else if(strlen(H[h]) == 0) {
            strcpy(H[h],str);
            return 0;
        }
    }

    return 0;

}




int main(){
    int i,n,h;
    char str[L],com[9];

    for(i = 0; i < M; i++) {
        H[i][0] = '\0';
    }

    scanf("%d",&n);
    for(i = 0; i < n; i++) {
        scanf("%s %s",com,str);
        if(com[0] == 'i') {
            insert(str);
        } else {
            if(find(str)) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}

Measured memory_bytes: 17448
#include <stdio.h>

int main(void) {
	int a, b;
	
	scanf("%d", &a);
	scanf("%d", &b);
	if (a >= -1000 && a <= 1000 && b >= -1000 && b <= 1000) {
		if (a == b) printf("a == b\n");
		else if (a > b) printf("a > b\n");
		else if (a < b) printf("a < b\n");
	}

	return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	int n, q;
	cin >> n >> q;

	REP(i, n) {
		cin >> s;
		cout << s << endl;
		cout << s << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    long h1,m1,h2,m2,k,r=0;
    cin >> h1>>m1>>h2>>m2>>k;
    r=h2*60+m2-h1*60-m1;
    cout << r-k;

}

Measured memory_bytes: 3632
n = gets.chomp
n1 = n.gsub(/\./," ")
n2 = n1.gsub(/\,/," ")
str = n2.split(" ")
ans = []
str.each do |k|
    k1 = k.split("")
    length = k1.length
    if length <= 6 && length >= 3
        ans << k
    end
end

puts ans.join(" ")


Measured memory_bytes: 6952
// @problemURL url.com
package main

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

func nt(s *bufio.Scanner) string {
	s.Scan()
	return s.Text()
}

func ni(s *bufio.Scanner) int {
	return atoi(nt(s))
}

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var in = bufio.NewReader(os.Stdin)
	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	// Code
	n, m := ni(s), ni(s)
	var sum int
	for i := 0; i < m; i++ {
		sum += ni(s)
	}
	sum = n - sum
	if sum < 0 {
		sum = -1
	}
	fmt.Println(sum)
}


Measured memory_bytes: 1808
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#define fr first
#define sc second
#define MP make_pair
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
using namespace std;

lli gcd(lli a, lli b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
lli cg(lli n) {
	return n ^ (n >> 1);
}
lli SUM(lli a)
{
	return (a * (a + 1) / 2);
}
bool CAN(int x, int y, int n, int m)
{
	if (x >= 0 && y >= 0 && x < n && y < m)
	{
		return true;
	}
	return false;
}
double her(double x1, double y1, double x2, double y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
string strsum(string a, string b)
{
	int p = 0;
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (b.length() < a.length())
	{
		for (int i = b.length(); i < a.length(); i++)
		{
			b += "0";
		}
	}
	else
	{
		for (int i = a.length(); i < b.length(); i++)
		{
			a += "0";
		}
	}

	a += "0", b += "0";
	for (int i = 0; i < a.length(); i++)
	{
		c += (a[i] - '0' + b[i] - '0' + p) % 10 + '0';
		p = (a[i] + b[i] - '0' - '0' + p) / 10;
	}
	if (c[c.length() - 1] == '0') c.erase(c.length() - 1, 1);
	reverse(c.begin(), c.end());
	return c;
}
string strmin(string a, string b)
{
	if (a.length() > b.length()) return b;
	if (b.length() > a.length()) return a;
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] > b[i]) return b;
		if (b[i] > a[i]) return a;
	}
	return a;
}

char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };



const int N = 1e6 + 30;
const lli mod = 1000000007;

string s, t;
bool tar[26];
vector <int> a[26];
int i1 = -1;
lli pat, sm;
int main()
{
	fastio;
	cin >> s >> t;
	for (int i = 0; i < s.length(); i++)
	{
		a[s[i] - 'a'].PB(i);
		tar[s[i] - 'a'] = true;
	}
	for (int i = 0; i < t.length(); i++)
	{
		if (!tar[t[i] - 'a'])
		{
			cout << -1;
			return 0;
		}
		if (i1 >= a[t[i] - 'a'][a[t[i] - 'a'].size() - 1])
		{
			pat++;
			i1 = a[t[i] - 'a'][0];
		}
		else
		{
			i1 = *upper_bound(a[t[i] - 'a'].begin(), a[t[i] - 'a'].end(), i1);
		}
	}
	sm = s.length();
	pat *= sm;
	pat += i1;
	cout << pat + 1;
	return 0;
}

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

#define int long long

// Union Find
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);

        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
};

auto main() -> signed {
    UnionFind uf(12);
    uf.unionSet(1, 3);
    uf.unionSet(1, 5);
    uf.unionSet(1, 7);
    uf.unionSet(1, 8);
    uf.unionSet(1, 10);
    uf.unionSet(1, 12);
    uf.unionSet(4, 6);
    uf.unionSet(4, 9);
    uf.unionSet(4, 11);

    int x, y;
    cin >> x >> y;
    if(uf.findSet(x, y)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int A,B,C,k;
	int i=0;
	int sum1,sum2,sum3;
	scanf("%d %d %d",&A,&B,&C);
	scanf("%d",&k);
	int A1[k];
	int p=k;
	while(k--)
	{

		sum1=A*2+B+C;
		sum2=A+B*2+C;
		sum3=A+B+C*2;
		if(sum1>=sum2 && sum1>=sum3 )
		{
			A=A*2;
			A1[i]=sum1;
			//printf("%d",sum1);
		}
		else if(sum2>=sum1 && sum2>=sum3)
		{
			B=B*2;
			A1[i]=sum2;
			//printf("%d",sum1);
		}
		else if(sum3>=sum1 && sum3>=sum2)
		{
			C=C*2;
			A1[i]=sum3;
			//printf("%d",sum1);
		}
		else if(sum1==sum2 && sum2==sum3)
		{
			A=A*2;
			A1[i]=sum1;
		}
		i++;
	}
	i=0;
	int max=0;
	while(i<p)
	{
		if(A1[i]>max)
		{
			max=A1[i];
		}
		i++;
	}
	printf("%d\n",max);
}

Measured memory_bytes: 128
# include<bits/stdc++.h>
# include<unordered_map>
# include<unordered_set>
//# include<prettyprint.hpp>
using namespace std;
# define ll long long
int n, m, q, a[50], b[50], c[50], d[50], arr[10], ans;
void bkt(int pos, int val){
    arr[pos] = val;
    if (pos == n-1){
        int cost = 0;
        for(int i = 0; i < q; i++){
            if (arr[b[i]] - arr[a[i]] == c[i]) cost+=d[i];
        }
        ans = max(ans, cost);
        return;
    }
    for(int i = val; i <= m; i++){
        bkt(pos+1, i);
    }
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> n >> m >> q;
    for(int i  = 0; i < q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }
    bkt(0, 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608