akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std; 
using lint  =                           long long int;
using pint  =                           pair<int, int>;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD                             1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){  
   int N;
   cin >> N;
   for(int i = 1;i*i <= N;++i){
       if(N%i == 0){
           if(N/i <= 9){
               cout<<"Yes"<<endl;
              return;
           }
       }
   }
   cout<<"No"<<endl;
   return;
}

int main(){   
  
 solve();

 return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>

#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip> //do setprecision
#include <ctime>
#include <complex>
using namespace std;

int main(void){
	long long int i,N;
	long long int sum=0,j=0,ans=0;
	long long int a[200001];
	cin >> N;
	for (i = 1; i <= N; ++i){
		cin >> a[i];
	}
	for (i = 1; i <= N-1; ++i){
		if(a[1]>=1 || (a[i+1]-a[i])>1){
			ans=-1;
		}
	}
	if(N==1){
		if(a[1]>=1){
			ans=-1;
		}
	}
	if(ans!=-1){
		for (i = 1; i <= N; ++i){
			sum=sum+a[i];
			if((a[i+1]-a[i])==1 && (i!=N)){
				j=j+a[i];
			}
		}
		ans=sum-j;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(){

	int hi[10],i,j,k;

	for(i=0;i<10;i++){
		scanf("%d",&hi[i]);
	}

	for(i=0;i<10;i++){
		for(j=i;j<10;j++){
			if(hi[i]<hi[j]){
				k=hi[i];
				hi[i]=hi[j];
				hi[j]=k;
			}
		}
	}

	printf("%d\n%d\n%d\n",hi[0],hi[1],hi[2]);

	return 0;
}

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

using namespace std;

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

    vector<vector<long>> S(8, vector<long>(N, 0));

    for(int i = 0; i < N; i++){
	long x, y, z;
	cin >> x >> y >> z;
	S.at(0).at(i) = x + y + z;
	S.at(1).at(i) = x + y - z;
	S.at(2).at(i) = x - y + z;
	S.at(3).at(i) = x - y - z;
	S.at(4).at(i) = - x + y + z;
	S.at(5).at(i) = - x + y - z;
	S.at(6).at(i) = - x - y + z;
	S.at(7).at(i) = - x - y - z;
    }
    for(int i = 0; i < 8; i++){
	sort(S.at(i).begin(), S.at(i).end());
	reverse(S.at(i).begin(), S.at(i).end());
    }

    vector<long> sum(8, 0);
    for(int i = 0; i < M; i++){
	for(int j = 0; j < 8; j++){
	    sum.at(j) += S.at(j).at(i);
	}
    }

    long ans = sum.at(0);
    for(int i = 1; i < 8; i++){
	ans = max(sum.at(i), ans);
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include "stdio.h"

int H,W;
int K;
char map[1001][1001] = {};
int width[3][1001][1001] = {};
int box[4];
int ans[3];

int main() {
	scanf("%d %d", &H, &W);
	scanf("%d", &K);
	for (int i = 0; i < H; i++) {
		scanf("%s", map[i]);
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			for (int k = 0; k < 3; k++) {
				width[k][i][j] = width[k][i][j - 1];
			}
			if (map[i-1][j-1] == 'J')width[0][i][j]++;
			else if (map[i-1][j-1] == 'O')width[1][i][j]++;
			else width[2][i][j]++;
		}
	}
	for (int i = 0; i < K; i++) {
		ans[0] = ans[1] = ans[2] = 0;
		scanf("%d %d %d %d", &box[0], &box[1], &box[2], &box[3]);
		for (int j = box[0]; j <= box[2]; j++) {
			for (int k = 0; k < 3; k++) {
				ans[k] += width[k][j][box[3]] - width[k][j][box[1]-1];
			}
		}
		printf("%d %d %d\n", ans[0], ans[1], ans[2]);
	}
	return 0;
}

Measured memory_bytes: 13744
/* AOJ 0045
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0045
 *
 */

#include <stdio.h>

int main(){
    int n;
    int sales;
    int items;
    int price;
    int volume;
    float ave;

    n = 0;
    sales = 0;
    items = 0;
    while(scanf("%d,%d", &price, &volume)==2){
        n += 1;
        sales += (price * volume);
        items += volume;
    }

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

    ave = 1.0*items/n;
    if((ave - (int)ave) < 0.5){
        printf("%d\n", (int)ave);
    }else{
        printf("%d\n", (int)ave+1);
    }
                

    return 0;
}

Measured memory_bytes: 0
N = int(input())
xyh = [tuple(map(int, input().split())) for _ in range(N)]

xi, yi, hi = None, None, None
for x, y, h in xyh:
    if h > 0:
        xi, yi, hi = x, y, h
        break

for cx in range(101):
    for cy in range(101):
        H = hi + abs(xi - cx) + abs(yi - cy)
        matched = True
        for x, y, h in xyh:
            if h != max(H - abs(x - cx) - abs(y - cy), 0):
                matched = False
                break
        if matched:
            print(cx, cy, H)
            exit(0)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
long double b,s=0.000000;
int c;
cin>>c;
while(c--){
    cin>>b>>a;
    if(a[0]=='J')
        s=s+b;
    else{
        s=s+(b*380000.0);
    }

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


Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    int w=0;
    int nn=n;
    while(n){
        w+=n%10;
        n/=10;
    }
    if(nn%w)cout<<"No"<<endl;else cout<<"Yes"<<endl;
    return 0;
}


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

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

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int a,b; cin >> a >> b;
    int ma = max(a,b);
    int mi = min(a,b);
    REP(i, ma) {
        cout << mi;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int d[100009];
int main()
{
	long long n,k,an=0;
	cin>>n>>k;
	pair<long long ,long long>a[n];
	for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
	sort(a,a+n);
	for(auto i: a)
	{
		an+=i.first*max(0ll,min(k,i.second));
		k
		-=i.second;
		
	}
	cout<<an<<endl;
}



Measured memory_bytes: 5156
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
----
)");
#define cin input
#endif

int main()
{
	string s;
	cin >> s;
	int count = 0;

	for (int i=0; i<4; i++)
	{
		if (s[i]=='+')
			count++;
		else
			count--;
	}
	cout << count << endl;
}

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

typedef long long ll;
ll n, A, B, s, g, l, r, md, num, ans, a[100005];
int main()
{
	ll i;
	cin >> n >> A >> B;
	for (i =0; i < n; i++) {
		scanf ("%lld", &a[i]);
		s += a[i];
	}
	l = 1;
	r = s / B + 2;
	while (l <= r) {
		md = (l + r) / 2;
		g = 0;
		for (i = 0; i < n; i++) {
			num = a[i] - B * md;
			if (num > 0) {
				g += num / (A - B);
				if (num % (A - B)) g++;
			}
		}
		if (g > md) l = md + 1;
		else {
			r = md - 1;
			ans = md;
		}
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#[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)*}
    };
}

#[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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        ss: [String; n],
    };
    let mut sum_ac = 0;
    let mut sum_tle = 0;
    let mut sum_wa = 0;
    let mut sum_re = 0;
    for s in ss {
        if s == "AC" {
            sum_ac += 1;
        } else if s == "TLE" {
            sum_tle += 1;
        } else if s == "WA" {
            sum_wa += 1;
        } else if s == "RE" {
            sum_re += 1;
        } else {
            panic!("")
        }
    }
    println!("AC x {}", sum_ac);
    println!("WA x {}", sum_wa);
    println!("TLE x {}", sum_tle);
    println!("RE x {}", sum_re);
}


Measured memory_bytes: 7548
import sys
import numpy as np
input = sys.stdin.readline

def main():
    n = int(input())
    v = np.array(list(map(int, input().split())))

    len1 = n//2 + n&1
    len2 = n//2

    d1 = {0:0}
    d2 = {0:0}
    for i in range(0,n,2):
        if v[i] in d1:
            d1[v[i]] += 1
        else:
            d1[v[i]] = 1
    for i in range(1,n,2):
        if v[i] in d2:
            d2[v[i]] += 1
        else:
            d2[v[i]] = 1

    a = sorted(d1.items(), key = lambda x: (x[1], x[0]) , reverse=True)
    b = sorted(d2.items(), key = lambda x: (x[1], -x[0]), reverse=True)
    a1_key, a1_val = a[0]
    a2_key, a2_val = a[1]
    b1_key, b1_val = b[0]
    b2_key, b2_val = b[1]
    if a1_key != b1_key:
        print(n - a1_val - b1_val)
    else:
        print(min(n - a1_val - b2_val, n - a2_val - b1_val))



if __name__ == "__main__":
    main()


Measured memory_bytes: 34280
n = int(input())
F = [list(map(int, input().split())) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
res = -(1 << 62)
for ss in range(1, 1 << 10):
    b = [0] * n
    s = ss
    for i in range(5):
        c0 = 1 if s & 1 else 0
        c1 = 1 if s & 2 else 0
        for j in range(n):
            b[j] += F[j][i * 2] * c0 + F[j][i * 2 + 1] * c1
        s >>= 2
    ts = 0
    for i in range(n):
        ts += P[i][b[i]]
    res = max(res, ts)
print(res)


Measured memory_bytes: 3064
void main() {
    int n = readln.chomp.to!int;
    writeln(n / 1000 ? "ABD" : "ABC");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.uni;

Measured memory_bytes: 256
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
  int n, i, j;
  int M[MAX][MAX];
  int  k, c, u, v;
  int minv;
  int d[MAX];
  int vis[MAX];

  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }

  for ( i = 0; i < n; i++ ) {
    d[i] = INFTY;
    vis[i] = 0;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for ( i = 0; i < n; i++ ){
      if ( minv > d[i] && !vis[i] ){
	u = i;
	minv = d[i];
      }
    }
    if ( u == -1 ) break;
    vis[u] = 1;
    for ( v = 0; v < n; v++ ){
      if ( !vis[v] && M[u][v] != INFTY ){
	if ( d[v] > d[u] + M[u][v] ){
	  d[v] = d[u] + M[u][v];
	}
      }
    }
  }

  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i, (d[i]==INFTY?-1:d[i]));
  }

  return 0;
}


Measured memory_bytes: 2060
# ENV[Z = 'RUBY_THREAD_VM_STACK_SIZE'] || exec( { Z => '50000000' },'ruby',$0)
# readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
# gets.split.map(&:to_i)
#

n = gets.to_i

ary = []
n.times do ||
  ary << gets.to_i
end
puts ary.uniq.length



Measured memory_bytes: 1788
from bisect import bisect_left

N = int(input())
S = input()

d = {"R": [], "G": [], "B": []}
for i in range(N):
    d[S[i]].append(i)


def find(x, y, z):
    total = len(z)
    res = 0
    for i in x:
        for j in y:
            if i > j:
                continue

            # Find k > j
            k = bisect_left(z, j)

            # Find k == 2 * j - i
            k0 = bisect_left(z, 2 * j - i)
            flag = int(k0 >= k and k0 < total and z[k0] == 2 * j - i)
            res += total - k - flag

    return res


ans = 0
ans += find(d["R"], d["G"], d["B"])
ans += find(d["R"], d["B"], d["G"])
ans += find(d["G"], d["R"], d["B"])
ans += find(d["G"], d["B"], d["R"])
ans += find(d["B"], d["R"], d["G"])
ans += find(d["B"], d["G"], d["R"])
print(ans)


Measured memory_bytes: 74752
n = int(input())
v = [int(item) for item in input().split()]
c = [int(item) for item in input().split()]

d = [[v[i], c[i]] for i in range(n)]
d.sort(key=lambda x: x[0] - x[1], reverse=True)

ans = 0
i = 0
while i < n and d[i][0] - d[i][1] > 0:
    ans += d[i][0] - d[i][1]
    i += 1

print(ans)


Measured memory_bytes: 3064
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0

for i in range(0,A+1):
    for j in range(0,B+1):
        for k in range(0,C+1):
            total = i * 500 + j * 100 + k * 50
            if total == X:
                counter += 1
print(counter) 

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a*b*c == 175) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <vector>
#include <utility>
#include <time.h>
#include <set>
#include <unordered_set>
#include <list>
#include <iterator>
#include <time.h>
#include <chrono>
#include <deque>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <climits>
using namespace std;

#define ll long long
#define ldb long double

ll mod(ll a, ll b)
{
	return (b + (a % b)) % b;
}

ll subMod(ll a, ll b, ll M)
{
	return mod((mod(a, M) - mod(b, M)), M);
}

void solve()
{
	string s;
	cin >> s;
	ll length = s.length();

	for (ll i = 0; i < length; i++)
	{
		cout << 'x';
	}
}

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

	solve();

	return 0;
}

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

using namespace std;

int main() {

	int table[4][13];

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			table[i][j] = 0;
		}
	}

	int n;

	cin >> n;

	char gara;
	int garacode;
	int rank;

	for (int k = 0; k < n; k++) {
		cin >> gara >> rank;

		switch (gara) {
		case 'S':
			garacode = 0;
			break;

		case 'H':
			garacode = 1;
			break;

		case 'C':
			garacode = 2;
			break;

		case 'D':
			garacode = 3;
			break;
		}

		table[garacode][rank - 1] = 1;

	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (table[i][j] == 0) {
				switch (i) {
				case 0:
					cout << 'S' << ' ' << j+1 << endl;
					break;

				case 1:
					cout << 'H' << ' ' << j+1 << endl;
					break;

				case 2:
					cout << 'C' << ' ' << j+1 << endl;
					break;

				case 3:
					cout << 'D' << ' ' << j+1 << endl;
					break;
				}


			}
			
		}
	}




	return 0;
}

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

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

  long long int result = 0;

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

  for(int i=0;i<n;i++) {
    for(int j=i+1;j<n;j++) {
      result += d[i] * d[j];
    }
  }

  cout << result << endl;
  return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> a(N - 1), b(N - 1), deg(N);
    vector<vector<int>> g(N);
    REP(i, N - 1) {
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
        ++deg[a[i]];
        ++deg[b[i]];
        g[a[i]].pb(i);
        g[b[i]].pb(i);
    }
    int K = *max_element(all(deg));
    cout << K << '\n';

    vector<int> used(N - 1, false);
    queue<pii> q;
    vector<int> result(N - 1, 0);

    q.push(pii(0, 0));
    while (!q.empty()) {
        int u;
        int parent_color;
        tie(u, parent_color) = q.front();
        q.pop();

        int color = 1;
        for (int e: g[u]) {
            if (!used[e]) {
                used[e] = true;
                if (color == parent_color) {
                    ++color;
                }
                int v;
                if (a[e] != u) {
                    v = a[e];
                } else {
                    v = b[e];
                }
                result[e] = color;
                q.push(pii(v, color));
                ++color;
            }
        }
    }

    REP(i, N - 1) {
        cout << result[i] << '\n';
    }

    cout << flush;
    return 0;
}


Measured memory_bytes: 8064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (1000000000000000000ll)
#define mod (1000000007)

int n;
int a[111];

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	cin>>n;
	int sum=0;
	FOR(i,0,n){
		cin>>a[i];
		a[i]*=n;
		sum+=a[i];
	}
	sum/=n;
	int pos=0;
	FOR(i,1,n){
		if(abs(a[i]-sum)<abs(a[pos]-sum))pos=i;
	}
	
	Tone(pos);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>

using namespace std;
int n,dp[100003][4],a[100003],b[100003],c[100003];

void DP()
{
    dp[1][1]=a[1],dp[1][2]=b[1],dp[1][3]=c[1];
    for(int i=2;i<=n;++i)
    {
        dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i];
        dp[i][3]=max(dp[i-1][1],dp[i-1][2])+c[i];
    }
    printf("%d",max(dp[n][1],max(dp[n][2],dp[n][3])));
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }
    DP();
    return 0;
}


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

// 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("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &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 (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n");
// }}} 2

// }}} 1

int main() {

    char s[3][13];

    Scs(s[0]);
    Scs(s[1]);
    Scs(s[2]);

    YESNO(s[0][strlen(s[0])-1] == s[1][0] && s[1][strlen(s[1])-1] == s[2][0]);

    return 0;
}


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

const int match[10] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
const int INF = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  int a[m];
  for ( int i = 0; i < m; i++ ) { cin >> a[i]; }
  sort(a, a+m, greater<int>());


  int dp[n+1];
  dp[0] = 0;
  for ( int i = 1; i <= n; i++ ) {
    dp[i] = -INF;
    for ( int j = 0; j < m; j++ ) {
      if ( i-match[a[j]] < 0 ) { continue; }
      if ( dp[i-match[a[j]]] < 0 ) { continue; }
      dp[i] = max(dp[i-match[a[j]]]+1, dp[i]);
    }
  }

  while ( n > 0 ) {
    for ( int i = 0; i < m; i++ ) {
      if ( n-match[a[i]] < 0 ) { continue; }
      if ( dp[n-match[a[i]]] == dp[n]-1 ) {
        cout << a[i];
        n -= match[a[i]];
        break;
      }
    }
  }
  cout << endl;
  return 0;
}


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

int main()
{
	int N, A, B, C, X, buf;
	while (cin >> N >> A >> B >> C >> X, N || A || B || C || X) {
		int cnt = 0;
		bool flag = true;
		for (int i = 0; i < N; i++) {
			cin >> buf;
			if (flag) {
				while (X != buf) {
					X = (A * X + B) % C;
					cnt++;
					if (cnt >= 10001) {
						flag = false;
						break;
					}
				}
			}
			X = (A * X + B) % C;
			cnt++;
		}
		if (flag)
			cout << cnt - 1 << endl;
		else
			cout << -1 << endl;
	}
	return 0;
}

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


void solve(long long N, long long K, std::vector<long long> p){
  sort(p.begin(), p.end());

  cout << accumulate(p.begin(), p.begin()+K, 0ll) << endl;

}

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


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a, b; cin >> n >> a >> b;
  string s; cin >> s;
  int cntJ=0, cntO=0;
  rep(i, n) {
    if(s[i]=='a' && cntJ+cntO<a+b) {
      cout << "Yes" << endk;
      cntJ++;
    } else if(s[i]=='b' && cntJ+cntO<a+b && cntO<b) {
      cout << "Yes" << endk;
      cntO++;
    } else {
      cout << "No" << endk;
    }
  }
  return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, X[200000], X_sorted[200000];
int main(int argc, char **argv) {
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> X[i];
        X_sorted[i] = X[i];
    }

    sort(X_sorted, X_sorted + N);

    int lb = X_sorted[N / 2 - 1];
    int ub = X_sorted[N / 2];

    for(int i = 0; i < N; ++i) {
        if(X[i] <= lb)
            cout << ub << endl;
        else
            cout << lb << endl;
    }
  
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>

using namespace std;

void func_A(){
    
    int x;
    for (int i = 1; i <= 5; ++i) {
        cin >> x;
        if (x == 0) {
            cout << i;
            return;
        }
    }

}

void func_B() {

    int x, y, turu, kame;
    cin >> x >> y;

    turu = (4 * x - y);
    if (turu % 2 == 1 || turu < 0) {
        cout << "No";
        return;
    }

    kame = (y - 2 * x);
    if (kame % 2 == 1 || kame < 0) {
        cout << "No";
        return;
    }
    cout << "Yes";
}

void func_C() {}

int main()
{

    //func_A();
    func_B();

    return 0;
}

Measured memory_bytes: 3636
// #include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define int long long

// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define all(v) v.begin(), v.end()
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
// union of two containers
template <typename T>
void container_union(T &c1, T &c2, T &c3) {
  std::vector<int> vec;
  std::set_union(c1.begin(), c1.end(),
                 c2.begin(), c2.end(),
                 std::back_inserter(vec));
  T tmp(vec.begin(), vec.end());
  c3 = tmp;
}

// chmax, chmin
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

// grid-search
std::vector<int> dx = {1, -1, 0,  0};
std::vector<int> dy = {0,  0, 1, -1};
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

// yes/no
std::string yes = "Yes";
std::string no = "No";
std::string YES = "YES";
std::string NO = "NO";

void solve();

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  solve();
  return 0;
}

void solve() {
  std::string s, t, u;
  int a, b;
  std::cin >> s >> t >> a >> b >> u;
  if (s == u) {
    a--;
  } else if (t == u) {
    b--;
  }
  std::cout << a << ' ' << b << '\n';
}


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

from collections import deque


S = list(input().rstrip())
Q = int(input())
Query = [list(map(str, input().split())) for _ in range(Q)]

q = deque()
gyaku = False
for s in S:
    q.append(s)

for A in Query:
    if A[0] == "1":
        gyaku =  not gyaku
    else:
        if (gyaku and A[1] == "1") or (not gyaku and A[1] == "2"):
            q.append(A[2])
        else:
            q.appendleft(A[2])


S = []
for p in q:
    S.append(p)

if gyaku:
    S = S[::-1]

print("".join(S))

Measured memory_bytes: 119176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


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

    string S; 
    cin >> S;

    int count = 0;
    for (int i = 0; i < 6; i++) {
        if (S[i] == '1') count++;
    }
    cout << count << endl;

    return 0;
}


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

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

	if (a == 1) {
		if (b == 2) {
			cout << 3 << endl;
		}
		else {
			cout << 2 << endl;
		}
	}
	else if (a == 2) {
		if (b == 1) {
			cout << 3 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	else {
		if (b == 1) {
			cout << 2 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long cc;
typedef pair <int, int> pii;
#define X first
#define Y second
#define pb push_back
int n, q;
set <int> lca;
int main() {
    //freopen("input.inp", "r", stdin);
    //freopen("output.out", "w", stdout);
    //freopen("VOI08LOCO.inp", "r", stdin);
    //freopen("VOI08LOCO.out", "w", stdout);
    ios_base  :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> q;
    while (q--) {
        int u, v; cin >> u >> v;
        if (n != 1) {
            lca.clear();
            while (u >= 1) {
                lca.insert(u);
                if (u % n > 1) u = u / n + 1; else u = u / n;
            }
            while (v >= 1) {
                if (lca.find(v) != lca.end()) {
                    cout << v << "\n";
                    break;
                }
                if (v % n > 1) v = v / n + 1; else v = v / n;
            }
        } else {
            cout << min(u, v) << "\n";
        }
    }
    return 0;
}


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

ll N, M, K;
const int MAX = 200010;
ll A[MAX], B[MAX];

ll binary_search(ll num, vector<ll> vec) {
    //ll ret = 0;
    int left = 0;
    int right = vec.size() - 1;
    while (left < right) {
        int mid = (left + right)/2;
        if (vec[mid] == num) {
            //ret = mid+1;
            right = mid;
            break;
        }
        else if (vec[mid] < num) {
            left = mid + 1;
            //ret = mid + 1;
        }
        else {
            right = mid;
            //ret = mid;
        }
    }
    return right;
}

int main() {
    cin >> N >> M >> K;
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < M; i++) cin >> B[i];
    
    vector<ll> sum_B(M);
    sum_B[0] = B[0];
    for (int i = 1; i < M; i++) {
        sum_B[i] = sum_B[i-1] + B[i];
    }

    int ans = 0;
    ll sum_A = 0;
    int tmp = upper_bound(sum_B.begin(), sum_B.end(), K-sum_A) - sum_B.begin();
    ans = max(ans, tmp);
    for (int i = 0; i < N; i++) {
        sum_A += A[i];
        if (sum_A <= K) {
            int tmp2 = upper_bound(sum_B.begin(), sum_B.end(), K-sum_A) - sum_B.begin();
            ans = max(ans, tmp2 +i+1);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7976
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 205;
const int MOD = 998244353;

int N;
int x[MAXN], y[MAXN];
int pot[MAXN];

void load() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%d%d", x + i, y + i);
}

inline int add(int x, int y) {
	x += y;
	if (x >= MOD)	
		x -= MOD;
	else if (x < 0)
		x += MOD;
	return x;
}

int ccw(int a, int b, int c) {
	return x[a] * (y[b] - y[c]) + x[b] * (y[c] - y[a]) + x[c] * (y[a] - y[b]);
}

bool in_range(int a, int b, int c) {
	return c >= min(a, b) && c <= max(a, b);
}

int solve() {
	pot[0] = 1;
	for (int i = 1; i <= N; i++)
		pot[i] = add(pot[i - 1], pot[i - 1]);	
	
	int sol = add(pot[N], -N - 1);
	for (int i = 0; i < N; i++)
		for (int j = 0; j < i; j++) {
			int cnt = 0;
			for (int k = 0; k < N; k++)
				cnt += k != i && k != j && !ccw(i, j, k) && in_range(x[i], x[j], x[k]) && in_range(y[i], y[j], y[k]);
			sol = add(sol, -pot[cnt]);
		}
	
	return sol;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 128
n,m,x = map(int, input().split())
C = []
A = []
ans = 10**9
for i in range(n):
  AC = list(map(int,input().split()))
  C.append(AC.pop(0))
  A.append(AC)

for i in range(2**n):
  cost = 0
  crit = [0]*m
  for j in range(n):
    if (i>>j)& 1:#use
      for k in range(m):
        crit[k] += A[j][k]
      cost += C[j]
  if min(crit) >= x:
    ans = min(ans, cost)
  #print(crit, cost)
if ans == 10**9:
  ans = -1
print(ans)

Measured memory_bytes: 9220
#include <iostream>
#include <vector>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
typedef vector<int> VI;
typedef vector<VI> VVI;

const int INF = 1e9;

int main() {
    int n, m;
    cin >> n >> m;
    VVI e(n,VI(n,INF));
    REP(i,n) e[i][i] = 0;
    while (m--){
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        e[a][b] = c;
        e[b][a] = c;
    }
    VVI d(e);    
    REP(i,n) REP(j,n) REP(k,n) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);

    int ans = 0;
    REP(i,n) REP(j,i) if (e[i][j] != INF && e[i][j] > d[i][j]) ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){

  int N;

  scanf("%d", &N);

  //あまりが 1 なら 1 - (N-1)/(2*N)
  if(N % 2 == 1){

    printf("%f", (1 - ((double)N-1)/(2*(double)N)));
  }

  //あまりが 0 なら 0.5
  if(N % 2 != 1){

    printf("%f", 0.5);
  }

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

    int n,k;
    cin>>n>>k;

    vi v(n);
    rep(i,0,n) cin>>v[i];

    vi dp(n+1,inf);

    dp[0] = 0;
    for(int i = 0;i<=n;i++){
        for(int j = i+1;j<=i+k;j++){
            if(j<n) dp[j] = min(dp[j],dp[i]+abs(v[i]-v[j]));
            else break;
        }
    }
    cout<<dp[n-1];
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 4824
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;
u64 over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int h, w, n;
  cin >> h >> w >> n;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  int c[h][w];
  int color = 0, cid = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      c[i][(i%2==0 ? j : w-1-j)] = cid+1;
      color++;
      if (color >= a[cid]) {
        color = 0;
        cid++;
      }
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cout << c[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 384
n = int(input())
L = [[]*n for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        x = x-1
        L[i].append((x,y))
#print(L)
ans = 0
for i in range(1<<n):
    bit = [(i>>j)&1 for j in range(n)]
    #print(bit)
    flag = True
    for j in range(n):
        if bit[j]:
            for x,y in L[j]:
                if bit[x] != y:
                    flag = False
                    break
            if not flag:
                break
    if flag:
        ans = max(ans,sum(bit)) 
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define uint unsigned int
using namespace std;

int main() {
	int a, b, t;
	cin >> a >> b >> t;

	t = t / a;

	cout << t * b << endl;
}

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

using namespace std;

int main(){
  long int X;
  cin >> X;

  long int ans = 0;
  ans += (X / 500) * 1000;
  X -= (X / 500) * 500;
  ans += (X / 5) * 5;

  cout << ans;
  return 0;
}


Measured memory_bytes: 256
N,K = map(int, input().split())
h = [0 for i in  range(N)]
for i in range(N):
    h[i] = int(input())
h.sort()
ans = h[K-1] - h[0]
for i in range(1,N-K+1):
    ans = min(ans,(h[K-1+i] - h[i]))
print(ans)

Measured memory_bytes: 7468
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      final int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 126928
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(10)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

class vec2d {
public:
	double x, y;
	vec2d(double x, double y) :x(x), y(y) {}
	double norm() const {
		return sqrt(x * x + y * y);
	}
	vec2d operator+(vec2d v) {
		return vec2d(x + v.x, y + v.y);
	}
	vec2d operator-(vec2d v) {
		return vec2d(x - v.x, y - v.y);
	}
	vec2d operator*(double k) const {
		return vec2d(x * k, y * k);
	}
	vec2d operator/(double k)const {
		return vec2d(x / k, y / k);
	}
	static double inner_product(const vec2d&a, const vec2d&b) {
		return a.x * b.x + a.y * b.y;
	}
	static double cros_product(const vec2d&a, const vec2d&b) {
		return a.x * b.y - a.y * b.x;
	}
	static double argument(const vec2d&a, const vec2d&b) {
		return atan2(cros_product(a, b), inner_product(a, b));
	}
	static vec2d projection(const vec2d&a, const vec2d&b) {
		double n = a.norm();
		return a * vec2d::inner_product(a, b) / n / n;
	}
};
signed main() {
	SETP;
	int q = in();
	REP(i, q) {
		double xp0 = in(), yp0 = in(), xp1 = in(), yp1 = in(), xp2 = in(), yp2 = in(), xp3 = in(), yp3 = in();
		vec2d s1(xp1 - xp0, yp1 - yp0), s2(xp3 - xp2, yp3 - yp2);
		double arg = vec2d::argument(s1, s2);
		if (abs(arg) < EPS || abs(abs(arg) - M_PI) < EPS) {
			cout << '2' << endl;
		} else if (abs(abs(arg) - M_PI_2) < EPS) {
			cout << '1' << endl;
		} else {
			cout << '0' << endl;
		}
	}
}


Measured memory_bytes: 3404
#include <bits/stdc++.h> 
using namespace std;
const int maxn = 1e5 + 5;
int f[30][maxn];
bool v[maxn];
int main() {
	string s , t;
	ios::sync_with_stdio(0);
	cin >> s >> t;
	int cnt = 0;
	for(int j = 0 ; j < 26 ; j++) {
		cnt = 0;
		for(int i = s.length() - 1 ; i >= 0 ; i--) { 
			f[j][i] = cnt;
			if(s[i] - 'a' == j) {
				cnt = i;
				if(!v[j])v[j] = 1;
			}
		}
	}
	cnt = 0;
	bool flag = 0;
	for(int i = 0 ; i < t.length() ; i++)if(!v[t[i] - 'a']) {
		flag = 1;
		break;
	}
	if(!flag) {
		while(s[cnt] != t[0])
			cnt = f[t[0] - 'a'][cnt];
		long long ans = 0;
		if(t.length() == 1)ans += cnt + 1;
		for(int i = 1 ; i < t.length() ; i++) {
			int tmp = cnt;
			cnt = f[t[i] - 'a'][cnt];
			while(s[cnt] != t[i])
				cnt = f[t[i] - 'a'][cnt];
			if(cnt <= tmp)ans += s.length();
			if(i == t.length() - 1)ans += cnt + 1;
		}
	 	cout << ans << "\n"; 
	}
	else cout << -1 << "\n"; 
	return 0;
}

Measured memory_bytes: 10704
from functools import lru_cache

T = int(input())


def gen_dp(a, b, c, d):
    @lru_cache(maxsize=None)
    def dp(n):

        if n == 0:
            return 0
        elif n == 1:
            return d
        else:
            return min(
                d * n,
                d * abs(n - (n // 5 * 5)) + c + dp(n // 5),
                d * abs(n - ((n + 4) // 5 * 5)) + c + dp((n + 4) // 5),
                d * abs(n - (n // 3 * 3)) + b + dp(n // 3),
                d * abs(n - ((n + 2) // 3 * 3)) + b + dp((n + 2) // 3),
                d * abs(n - (n // 2 * 2)) + a + dp(n // 2),
                d * abs(n - ((n + 1) // 2 * 2)) + a + dp((n + 1) // 2),
            )

    return dp


for _ in range(T):
    N, A, B, C, D = map(int, input().split(' '))
    dp = gen_dp(A, B, C, D)
    print(dp(N))


Measured memory_bytes: 20368
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace app02
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] p = Console.ReadLine().Split(' ');
            int[] ip = new int[N];
            for(int i = 0;i < N; i++)
            {
                ip[i] = int.Parse(p[i]);
            }
            int count = 0;

            for(int i = 1;i < N - 1; i++)
            {
                if (ip[i - 1] < ip[i] && ip[i] < ip[i + 1])
                {
                    count++;
                }
                if (ip[i - 1] > ip[i] && ip[i] > ip[i + 1])
                {
                    count++;
                }
            }
            Console.WriteLine($"{count}");
        }
    }
}


Measured memory_bytes: 13140