akhauriyash/Code-Regression huggingface dataset:
while True:
    m, f, r = [int(x) for x in input().split()]
    
    if m == f == r == -1:
        break
    
    sum_m_f = m + f
    score = ''
    
    if m == -1 or f == -1:
        score = 'F'
        print(score)
        continue
        
    if sum_m_f >= 80:
        score = 'A'
        print(score)
    elif sum_m_f >= 65:
        score = 'B'
        print(score)
    elif sum_m_f >= 50:
        score = 'C'
        print(score)
    elif sum_m_f >= 30:
        if r >= 50:
            score = 'C'
        else:
            score = 'D'
        print(score)
    else:
        score = 'F'
        print(score)


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N, vector<int>());
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph.at(a).emplace_back(b);
        graph.at(b).emplace_back(a);
    }

    int num_paths = 0;
    vector<int> perm;
    for (int i = 0; i < N; i++) {
        perm.emplace_back(i);
    }

    do {
        bool can_traverse = true;
        for (int i = 0; i < N - 1; i++) {
            int start = perm.at(i), end = perm.at(i + 1);
            if (find(graph.at(start).begin(), graph.at(start).end(), end) 
                == graph.at(start).end()) {
                    can_traverse = false;
                    break;
                }
            }
        if (can_traverse) num_paths += 1;
        } while (next_permutation(perm.begin() + 1, perm.end()));
    cout << num_paths << "\n";
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N;
    string S;
    cin >> N >> S;

    bool f = true;
    if(N % 2 == 1) f = false;
    else {
        REP(i,0,N/2) {
            if(S[i] != S[i+N/2]) {
                f = false;
                break;
            }
        }
    }
    _PR(f?"Yes":"No");

    return 0;
}

/*



*/

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

int main(){
  string s;
  cin >> s;
  
  uint64_t sum = 0;
  for( uint64_t i = 0; i < s.size(); ++i  ){
    sum += (uint64_t)( s.at(i) - '0');
  }

  if( sum % 9 == 0 ){
    cout <<  "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

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

int main() {
	ll n;
	cin >> n;
	ll ans = 1e15;
	for (ll i = 1; i * i <= n; ++i) {
		if (!(n % i)) {
			ans = min(ans, n / i + i - 2);
		}
	}
	cout << ans << endl;
}


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		HashMap<Integer, ArrayList<Integer>> m1 = new HashMap<>();
		HashMap<Integer, ArrayList<Integer>> m2 = new HashMap<>();
		for(int i = 0; i < N; i++) {
			int A = sc.nextInt();
			m1.put(i, new ArrayList<>());
			m2.put(i, new ArrayList<>());
			for(int j = 0; j < A; j++) {
				int x = sc.nextInt()-1;
				int y = sc.nextInt();
				if(y == 1)
					m1.get(i).add(x);
				else
					m2.get(i).add(x);
			}
		}
		int ans = 0;
		boolean[] x = new boolean[N];
		for(int i = 0; i < 1<<N; i++) {
			boolean ok = true;
			int num = 0;
			for(int j = 0; j < N; j++) {
				if ((1 & i >> j) == 1) { 
					x[j] = true;
					num++;
				}
				else
					x[j] = false;
			}
			LOOP:for(int j = 0; j < N; j++) {
				if(!x[j])
					continue;
				for(int k : m1.get(j)) {
					if(!x[k]) {
						ok = false;
						break LOOP;
					}
				}
				for(int k : m2.get(j)) {
					if(x[k]) {
						ok = false;
						break LOOP;
					}
				}

			}
			if(ok)
				ans = Math.max(ans, num);
		}
		
		System.out.println(ans);

	}

}

Measured memory_bytes: 37264
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    ll ave=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        a[i]=x-i-1;
    }
    sort(a.begin(),a.end());
    ll l=a[n/2];
    ll r=INF;
    if(n>1) r=a[n/2+1];
    ll ans=0;
    ll sub=0;
    for(int i=0;i<n;i++){
        ans+=abs(a[i]-l);
        sub+=abs(a[i]-r);
    }
    ans=min(ans,sub);
    cout<<ans<<endl;
}

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

int main(){

  string str;

  getline(cin,str);

  for(int i=0;i<str.size();i++){
    if(str[i]<123 && str[i]>96) printf("%c",str[i]-32);
    else cout << str[i];
  }
  cout << endl;
}

Measured memory_bytes: 1172
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[200000];
int b[200000];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	vector<H>vec;
	for (int i = 1; i < n - 1; i++) {
		if (a[i] < 0) {
			vec.push_back(H{ a[n - 1], a[i] });
			a[n - 1] -= a[i];
		}
		else {
			vec.push_back(H{ a[0],a[i] });
			a[0] -= a[i];
		}
	}
	vec.push_back(H{ a[n - 1], a[0] });
	cout << a[n - 1] - a[0] << endl;
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i].x << " " << vec[i].y << endl;
	}
}

Measured memory_bytes: 4336
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)

n = ip()                                     #入力整数1つ
#a,b,t= (int(i) for i in input().split())       #入力整数横2つ以上
v = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#v=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
c = [int(i) for i in input().split()]
s = 0
for i in range(n):
    if v[i] > c[i]:
        s +=(v[i]-c[i])
print(s)

Measured memory_bytes: 23240
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define debug(x) cout << #x << ":" << x << "\n";
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T>
std::istream& operator >> (std::istream& is, std::vector<T>& vec){
  T tmp;
  is >> tmp;
  vec.push_back(tmp);
  return is;
}
template <class T>
auto mkVec(unsigned int x){
  return std::vector<T>(x);
}

template <class T>
auto mkVec2(unsigned int x, unsigned int y){
  return std::vector<std::vector<T>>(x, std::vector<T>(y));
}

template <class T>
auto mkVec3(unsigned int x, unsigned int y, unsigned int z){
  return std::vector<std::vector<std::vector<T>>>(x, std::vector<std::vector<T>>(y, std::vector<T>(z)));
}

ll N;
vector<ll> v(N);

ll calc(ll b){
  ll res = 0;
  rep(i, N){
    res += abs(v[i] - b);
  }
  return res;
}

#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  cin >> N;
  v.resize(N);
  rep(i, N){
    ll x;
    cin >> x;
    v[i] = x - (i + 1);
  }
  sort(v.begin(), v.end());
  ll l = v[0], r = v[N - 1];
  while(l + 2 < r){

    ll m1 = (l * 2 + r)/3;
    ll m2 = (l + r * 2)/3;
    // debug(m1);
    // debug(calc(m1));
    // debug(m2);
    // debug(calc(m2));
    if(calc(m1) < calc(m2)){
      r = m2;
    }else{
      l = m1;
    }
  }
  // debug(l);
  // debug(r);
  cout << min(min(calc(l), calc((l + r)/2)), calc(r));
  
}
#endif


Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	char S[100001];
	scanf("%s", S);
	int N = strlen(S);
	int saigo = N;
	int kaisuu = (N - 2) / 2;
	int base = 2;
	if (S[0] == '0' || S[N - 1] == '1' || S[N - 2] == '0') {
		printf("-1");
	}
	else {
		putint(1);
		putint(2);

		rep1(i, kaisuu) {
			char c = S[i];
			if (c != S[N - i - 2]) {
				printf("-1");
				return 0;
			}
			if (c == '0') {
				putint(base);
				putint(saigo--);
			}
			else {
				putint(base++);
				putint(base);
			}
		}
		rep1(i, N - kaisuu - 2) {
			putint(base);
			putint(base + i);
		}
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

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

int main()
{
    // input
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];

    // solve
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    ll ans = 0;
    rep(i,n){
        ll a_num = lower_bound(ALL(a), b[i]) - a.begin();
        ll c_num = c.end() - upper_bound(ALL(c), b[i]);
        ans += a_num * c_num;
    }
    // output
    cout << ans << endl;
    return 0;
}

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

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main(){
    int x,y;
    cin>>x>>y;
    cout<<x+y/2<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int n;
int a[100000];

long long f(long long m) {
	rep(i,n) {
		m -= m%a[i];
	}
	return m;
}


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

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



	long long l, r;
	l = 0; r = 1LL << 60;
	while (r-l>1) {
		auto m = (l + r) / 2;
		if (f(m) > 2)r = m;
		else l = m;
	}
	auto ma = l;

	l = 0; r = 1LL << 60;
	while (r - l > 1) {
		auto m = (l + r) / 2;
		if (f(m) < 2)l = m;
		else r = m;
	}
	auto mi = r;


	if(mi<=ma && f(mi)==2 && f(ma)==2)cout << mi << ' ' << ma << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int answer[3] = { -1, -1, -1 };

int calc_yen(int a, int b, int c)
{
  return a * 10000 + b * 5000 + c * 1000;
}

void solve(int num_bill, int yen)
{
  for(int a = 0; a <= num_bill; a++) {
    for(int b = 0; b+a <= num_bill; b++) {
      int c = num_bill - a - b;
      if(yen == calc_yen(a, b, c)) {
        answer[0] = a;
        answer[1] = b;
        answer[2] = c;
        return;
      }
    }
  }
}

int main()
{
  int num_bill, yen;
  scanf("%d%d", &num_bill, &yen);
  solve(num_bill, yen);
  printf("%d %d %d\n", answer[0], answer[1], answer[2]);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int H, W; cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W, 0));
	int cnt = 0;
	vector<pair<int, int>> ans;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> a[i][j];
		}
	}
	//奇数枚のマスは下のマスはコインを一枚配布し、偶数となる
	//下端に都合の悪いコインを押し付ける
	for (int i = 0; i < H - 1; ++i) {
		for (int j = 0; j < W; ++j) {
			if (a[i][j] % 2 == 1) {
				cnt++;
				a[i][j]--;
				a[i + 1][j]++;
				ans.push_back({i + 1, j + 1});
				ans.push_back({i + 2, j + 1});
			}
		}
	}
	//奇数枚のマスは右のマスにコインを一枚配布し、偶数となる
	//一番右(全体で右下)のマスに都合の悪いコインを押し付ける
	//一番右(全体で右下)のマスの偶奇は全体枚数の偶奇に従うので、一番右下のマス以外をこれで全て偶数にすることが出来る
	for (int i = 0; i < (W - 1); ++i) {
		if (a[H - 1][i] % 2 == 1) {
			cnt++;
			a[H - 1][i]--;
			a[H - 1][i + 1]++;
			ans.push_back({H, i + 1});
			ans.push_back({H, i + 2});
		}
	}
	int loop = 0;
	cout << cnt << endl;
	for (auto& p : ans) {
		if (loop % 2 == 0) {
			cout << p.first << " " << p.second << " ";
		} else {
			cout << p.first << " " << p.second << endl;
		}
		loop++;
	}
	return;
}
int main() {
	solve();
	return 0;
}

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

int main()
{
  int N, X;
  cin >> N >> X;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  int D = 0;
  int ans = 1;
  for (int i = 0; i < N; i++) {
    D += L.at(i);
    if (D <= X) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    long long a, b;
    cin >> a >> b;
    a -= 1;
    vector<int>d(60,0);
    auto p = 2ll;
    for(int i = 0; i < 60; ++i){
        int a1 = (a + 1) / p * (p / 2);
        if((a + 1) % p > p / 2){
            a1 += (a + 1) % p - (p / 2);
        }
        int b1 = (b + 1) / p * (p / 2);
        if((b + 1) % p > p / 2){
            b1 += (b + 1) % p - (p / 2);
        }
        //cout << i << " " << a1 << " " << b1 << endl;
        d[i] = b1 - a1;
        p *= 2;
    }
    auto ans = 0ll;
    p = 1ll;
    for(int i = 0; i < 60; ++i){
        int f;
        if(d[i] % 2 == 0){
            f = 0;
        } else{
            f = 1;
        }
        ans += f * p;
        p *= 2;
    }
    
    cout << ans;
}




Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = [int(input()) for _ in range(N)]

maxA = max(A)
lenA = len(A)
cnt_maxA = A.count(maxA)

if cnt_maxA > 1:
    for _ in range(lenA):
        print(maxA)
    exit()

for i, a in enumerate(A):
    if a == maxA:
        if i == 0:
            print(max(A[1:]))
        elif i == lenA-1:
            print(max(A[:-1]))
        else:
            print(max(max(A[:i]), max(A[i+1:])))
    else:
        print(maxA)

Measured memory_bytes: 59716
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
	int cnt=0;
	string s;
	string s1="";
	string temp="";
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		s1+=s[i];
		if(s1==temp)
			continue;
		else{
			temp=s1;
			s1="";
			cnt++;
		}
	}
	cout<<cnt<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 640
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
	int N, K;
	cin >> N >> K;
	LL ans = 1;
	REP( i, N )
	{
		ans *= ( i == 0 ? K : K - 1 );
	}
	cout << ans << endl;
	return 0;
}


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

int T,P,R;

typedef struct{
	int tID;
	int score;
	int penalty;
	int wrong[10];
} team;

int comp(const void* c1, const void* c2){
	team* t1=(team*)c1;
	team* t2=(team*)c2;
	if(t1->score!=t2->score){
		return -(t1->score - t2->score);
	}else if(t1->penalty!=t2->penalty){
		return (t1->penalty - t2->penalty);
	}else{
		return (t1->tID - t2->tID);
	}
}

void solve(){
	team t[T];
	int i,j;
	for(i=0;i<T;i++){
		t[i].tID=i+1;
		t[i].score=0;
		t[i].penalty=0;
		for(j=0;j<10;j++){
			t[i].wrong[j]=0;
		}
	}
	int tID,pID,time;
	char str[10];
	for(i=0;i<R;i++){
		scanf("%d %d %d %s",&tID,&pID,&time,str);
		tID--;
		pID--;
		if(str[0]=='C'){
			t[tID].score++;
			t[tID].penalty+=t[tID].wrong[pID]*1200+time;
		}else{
			t[tID].wrong[pID]++;
		}
	}
	qsort(t,T,sizeof(team),comp);
	for(i=0;i<T;i++){
		printf("%d %d %d\n",t[i].tID,t[i].score,t[i].penalty);
	}
	return;
}


int main(void){
	while(scanf("%d %d %d",&T,&P,&R),T|P|R){
		solve();
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

vector<string> v;

void init() { rep(i, 0, 7) cin >> v[i]; }
string test(int i) { return v[i]; }

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

  int maxs = 19, mid = 0, head = 0, tail = n - 1;
  string old_input, input;

  cout << 0 << endl;
  cin >> input;
  old_input = input;
  // v.resize(n);
  // init();
  // old_input = input = test(0);
  if (input == "Vacant")
    return 0;

  while (maxs--) {
    mid = head + ((tail + 1) - head) / 2;
    cout << mid << endl;
    cin >> input;
    // input = test(mid);

    if (input == "Vacant")
      return 0;
    if ((mid - head) & 1) {
      if (old_input == input) {
        tail = mid;
      } else {
        head = mid;
        old_input = input;
      }
    } else {
      if (old_input == input) {
        head = mid;
        old_input = input;
      } else {
        tail = mid;
      }
    }
  }
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

const ll MOD = 1e9+7;


signed main(){
    string s;
    cin >> s;
    map<ll,ll> m;
    ll ans = 0;
    ll temp = 1;
    ll memo = 0;
    m[0] = 1;

    rep(i,0,s.size()){
        memo += temp * (ll)(s[s.size()-i-1] - '0');
        memo %= 2019;
        temp *= 10; temp %= 2019;

        if(m.count(memo) == 0){
            m[memo] = 1;
        }
        else{
            m[memo]++;
        }
    }

    rep(i,0,2019) if(m.count(i) != 0) ans += m[i]*(m[i]-1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3724
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	ll N, K; cin >> N >> K;
	cout << min(N%K, K - N % K) << endl;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
info = [list(map(int, input().split())) for _ in range(n)]
# print(info)
ans = float('inf')
for i in range(2**n):
    price = 0
    u = [0]*m
    for j in range(n):
        if (i>>j) & 1:
            price += info[j][0]
            for k in range(m):
                u[k] += info[j][k+1]
    ok = True
    # print(u)
    for l in range(m):
        if u[l] < x:
            ok = False
    if ok:
        ans = min(ans, price)

if ans == float('inf'):
    print('-1')
else:
    print(ans)

Measured memory_bytes: 9228
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)


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

const ll MOD = INF + 7;

int main(){
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int dp[1<<14][14];
bool oks[1001];
const int INF=1<<30;
int matrix[101][101];

int match(string s1,string s2){
  int res=0;
  for(int i=0;i<(int)min(s1.size(),s2.size());i++){
    //cout<<s2.substr(0,i+1)<<" "<<s1.substr((int)s1.size()-1-i,i+1)<<endl;
    if(s2.substr(0,i+1)==s1.substr((int)s1.size()-1-i,i+1)){
      res=max(res,i+1);
    }
  }
  return res;
}

int main(){
  int N;
  while(cin>>N&&N){
    vector<string> vs;
    for(int i=0;i<N;i++){
      string s;
      cin>>s;
      vs.push_back(s);
    }
    memset(oks,0,sizeof(oks));
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
	if(i==j)continue;
	if((int)vs[i].find(vs[j])!=-1){
	  oks[j]=true;
	}
      }
    }
    memset(matrix,0,sizeof(matrix));
    vector<string> ss;
    for(int i=0;i<N;i++)
      if(!oks[i])ss.push_back(vs[i]);
    N=ss.size();
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	if(i!=j)
	  matrix[i][j]=match(ss[i],ss[j]);
    // for(int i=0;i<N;i++){
    //   for(int j=0;j<N;j++)
    // 	cout<<matrix[i][j]<<" ";
    //   cout<<endl;
    // }
    for(int mask=(1<<N)-1;mask>=1;mask--){
      for(int j=0;j<N;j++){
	int res=INF;
	if(mask==(1<<N)-1)res=0;
	for(int k=0;k<N;k++){
	  if((mask>>k)&1)continue;
	  int nmask=mask|(1<<k);
	  res=min(res,dp[nmask][k]-matrix[j][k]+(int)ss[k].size());
	}
	dp[mask][j]=res;
      }	
    }
    int ans=INF;
    for(int i=0;i<N;i++){
      int mask=(1<<i);
      ans=min(ans,dp[mask][i]+(int)ss[i].size());
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1864
//Bismillahir Rahman-ir Rahim
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000002
#define PI acos(-1)
//#define m (pow(10, 9)+7)
typedef unsigned long long ull;
typedef long long ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    int ara[n], dif;
    for(int i = 0; i < n; i++){
        cin >> ara[i];
    }
    
    sort(ara, ara+n);

    dif = (ara[n-1] - ara[0]);

    cout << dif << endl;



    return 0;
}


Measured memory_bytes: 256
package main
import (
    "fmt"
    "bufio"
    "os"
    "strings"
    "strconv"
    )
func main() {
    input := bufio.NewScanner(os.Stdin)
    input.Scan()
    
    input.Scan()
    var ok bool = true
    for _, v := range strings.Split(input.Text(), " ") {
        n, _ := strconv.Atoi(v)
        if n % 2 == 0 {
            ok = map[bool]bool{true: true, false: false}[n % 3 == 0  || n % 5 == 0]
            if !ok {
                break
            }
        }
    }
    if ok {
        fmt.Println("APPROVED")
    } else {
        fmt.Println("DENIED")
    }
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
typedef long long int lli;

lli gcd(lli a, lli b){
  if(a<b)return gcd(b,a);
  if(b==0) return a;
  return gcd(b,a%b);
}

lli lcm(lli a, lli b){
  return a/gcd(a,b)*b;
}


int main(void){
  int n;
  lli res=1,t;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t;
    res=lcm(res,t);
  }
  cout<<res<<endl;
  return 0;
}

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

#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
  int n;
  cin >> n;
  int p[n];
  rep(i,n){
    cin >> p[i];
  }
  int ans =0;
  rep(j,n-2){
    if(p[j+1] != max(max(p[j],p[j+1]),p[j+2]) && p[j+1] != min(min(p[j],p[j+1]),p[j+2])){
      ans++;
    }
  }
  cout << ans;
 
 return 0;
}

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

int main(){
    int r,g,b;
    cin >> r >> g >> b;
    int a = 100 * r + 10 * g +b;
    if (a % 4 == 0)
        cout << "YES" << endl;
    else
        cout<< "NO" << endl;
    return 0;
}


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

int main()
{
  long long int N, M, sum=0;
  cin>>N>>M;
  int day[M];
  for(int i=0; i<M; i++)
  {
    cin>>day[M];
    sum+=day[M];
  }
  if(sum>N)
    cout<<"-1";
  else
    cout<<N-sum;
  return 0;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
"""
1 <= A, B <= 1659まで対応してるよ
"""
A, B = inpl()

L = [["."]*50 for i in range(100)]
R = [["#"]*50 for i in range(100)]

def plot(R):
    print("\n".join(["".join(r) for r in R]))

count = 0
for i in range(98):
    for j in range(16):
        if count == B-1:
            break
        L[i+1][j*3 + i%3 + 1] = "#"
        count += 1

count = 0
for i in range(98):
    for j in range(16):
        if count == A-1:
            break
        R[i+1][j*3 + i%3 + 1] = "."
        count += 1
        
ANS = [l+r for l, r in zip(L, R)]

print(100, 100)
plot(ANS)


Measured memory_bytes: 3188
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

int main(){
    int a,b,i;
    cin>>a>>b;
    if(a%2==0){
        if(25*a/2>10*b+9 || 25*a/2+12<10*b){
            cout<<-1;
        }else{
            cout<<max(10*b,25*a/2);
        }
    }else{
        if(25*a/2+1>10*b+9 || 25*a/2+12<10*b){
            cout<<-1;
        }else{
            cout<<max(10*b,25*a/2+1);
        }
    }
    return 0;
}

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

using namespace std;

#define MAX_R 50
#define MAX_C 50
#define INF (1<<29)
typedef pair<int, int> pii;

bool inField(int x, int y, int C, int R)
{
    return (0 <= x && x < C && 0 <= y && y < R);
}

int main()
{
    int R, C, M;
    char field[MAX_R][MAX_C];
    cin >> R >> C >> M;
    for (int i = 0; i < R; i++) {
        for (int j = 0; j < C; j++) {
            cin >> field[i][j];
        }
    }
    int cost[3][MAX_R][MAX_C];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < R; j++) {
            for (int k = 0; k < C; k++) {
                cin >> cost[i][j][k];
            }
        }
    }
    vector<int> X(M), Y(M);
    for (int i = 0; i < M; i++) {
        cin >> Y[i] >> X[i];
    }

    const int dx[] = {-1, 0, 1, 0};
    const int dy[] = {0, -1, 0, 1};
    
    map<pii, vector<int>> vis;
    int prev_d = 0;
    for (int i = 1; i < M; i++) {
        queue<pii> Q; Q.push(pii(X[i-1], Y[i-1]));
        vector<vector<int>> d(MAX_R, vector<int>(MAX_C, INF));
        vector<vector<int>> prev(MAX_R, vector<int>(MAX_C, INF));
        d[Y[i-1]][X[i-1]] = prev_d;
        while (!Q.empty()) {
            pii p = Q.front(); Q.pop();
            int x = p.first, y = p.second;
            if (x == X[i] && y == Y[i]) {
                prev_d = d[y][x];
                break;
            }
            for (int j = 0; j < 4; j++) {
                int nx = x + dx[j], ny = y + dy[j];
                if (!inField(nx, ny, C, R) ||
                    field[ny][nx] == '#') {
                    continue;
                }
                if (d[y][x] + 1 < d[ny][nx]) {
                    d[ny][nx] = d[y][x] + 1;
                    prev[ny][nx] = y*C + x;
                    Q.push(pii(nx, ny));
                }
            }
        }
        int x = X[i], y = Y[i];
        vis[pii(x, y)].push_back(d[y][x]);           
        while (x != X[i-1] || y != Y[i-1]) {           
            int nx = x, ny = y;
            nx = prev[y][x] % C;
            ny = prev[y][x] / C;
            x = nx; y = ny;
            vis[pii(x, y)].push_back(d[y][x]);           
        }
    }
    int sum = 0;
    for (auto &v : vis) {
        int x = v.first.first;
        int y = v.first.second;
        vector<int> p = v.second;
        sort(p.begin(), p.end());
        if (p.size() == 1) {
            sum += cost[1][y][x] + cost[2][y][x];
        } else {
            sum += cost[1][y][x];
            for (int i = 1; i < (int)p.size(); i++) {
                sum += min(cost[2][y][x] + cost[1][y][x], (p[i] - p[i-1]) * cost[0][y][x]);
            }
            sum += cost[2][y][x];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 8168
import java.util.*;

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

        final double n = (double)sc.nextInt();
        final double m = (double)sc.nextInt();
        final double d = (double)sc.nextInt();

        // n = 4, m = 2, d = 0
        // (1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,3),(2,4),(3,1),(3,2),(3,3),(3,4),(4,1),(4,2),(4,3),(4,4)
        // d = 0 (1,1),(2,2),(3,3),(4,4)
        // d = 1 (1,2),(2,1),(2,3),(3,2),(3,4),(4,3)
        // d = 2 (1,3),(2,4),(3,1),(4,2)
        // d = 3 (1,4),(4,1)

        double cn, cm, ret;
        if (d == 0) {
            cn = n;
        } else {
            cn = 2 * (n - d);
        }
        cm = m - 1;

        ret = cm * cn / (n * n);
        System.out.println(ret);
    }
}

Measured memory_bytes: 21716
/*
 * 17-08-26_AGC019_A.cpp
 *
 *  Created on: 2017/08/26
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>

using namespace std;

int Q,H,S,D;
long long N;
long long ans;
int main(){
	cin >> Q >> H >> S >> D;
	cin >> N;
	H = min(H,2*Q);
	S = min(S,2*H);
	D = min(D,2*S);
	N <<= 2;
	ans += D*(N / 8);
	N %= 8;
	ans += S*(N/ 4);
	N %= 4;
	ans += H*(N/2);
	N %= 2;
	ans += Q*(N);
	cout << ans << endl;
	return 0;
}




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

#define int long long
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(){
	int a, b;
	cin >> a >> b;
	cout << (a * b) << endl;

	return 0;
}


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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

inline ll calc(const int k, const int l) {
    return k > l ? (1LL * k * (k + 1) / 2 + 1LL * (l - 1) * l / 2) : (1LL * (k - 1) * k / 2 + 1LL * l * (l + 1) / 2);
}

int main() {
    str s;
    cin >> s;
    bool d_flg = false;
    int start = 0, mid = -1;
    ll ans = 0;
    REP(i, s.length()) {
        if(!d_flg && s[i] == '>') {
            d_flg = true;
            mid = i;
        }
        else if(d_flg && s[i] == '<') {
            d_flg = false;
            // DBG(start);
            // DBG(mid);
            // DBG(i);
            // DBG(calc(mid - start, i - mid));
            ans += calc(mid - start, i - mid);
            start = i;
        }
    }
    if(mid < start) mid = s.length();
    // DBG(start);
    // DBG(mid);
    // DBG(s.length());
    // DBG(calc(mid - start, s.length() - mid));
    ans += calc(mid - start, s.length() - mid);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

vector<P> G[100];
int po[100];
int get_log(int n){
	int ans = 0, m = 1;
	while(m <= n){m *= 2;ans++;}
	return ans;
}

void init(){
	int t = 1;
	rep(i,30){
		po[i] = t;
		t *= 2;
	}
}

signed main(){
	int L;
	init();
	scanf("%lld", &L);
	int n = get_log(L);
	rrep(i,n-1){
		G[i].pb(P(i+1, po[n-1-i]));
		G[i].pb(P(i+1, 0));
	}
	L -= po[n-1];
	int tmp = po[n-1];
	rrep(i,n){
		int m = n-i;
		if(((L>>m) & 1) == 0)continue;
		G[1].pb(P(i, tmp));tmp += po[m];
	}
	
	int m = 0;
	rrep(i,20)m += G[i].size();
	printf("%lld %lld\n", n, m);
	rrep(i,n){
		rep(j,G[i].size())printf("%lld %lld %lld\n", i, G[i][j].fi, G[i][j].se);
	}
	return 0;
}






Measured memory_bytes: 256
N, M, Q = map(int, input().split())
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1

# スコア計算
def score(A):
    tmp = 0
    for ai, bi, ci, di in zip(a, b, c, d):
        if A[bi] - A[ai] == ci:
            tmp += di
    return tmp

# DFS
def dfs(A):
    if len(A) == N:
        return score(A) # 数列 A のスコアを返す
    res = 0
    prev_last = A[-1] if len(A) > 0 else 0
    for v in range(prev_last, M):
        A.append(v)
        res = max(res, dfs(A)) # 再帰呼出しながら、スコア最大値も更新
        A.pop()
    return res

# 求める
print(dfs([]))

Measured memory_bytes: 9200
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string.h>
#include<string>
#include<map>
#include<utility>
#include<functional>
typedef long long ll;
using namespace std;
typedef pair<int,float> p;

vector<ll> a,b,c;
int n,m;
string s;

int main(){
  cin >> s ;
  bool flag = false;
  for(int i=0;i<s.size();i++){
    if(s[i]=='9'){
      flag = true;
    }
  }
  printf("%s\n",(flag)? "Yes" : "No");
  return 0;
}


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


int main() {
    int a,b;
    cin>>a>>b;
    
    for(int i=1;i<2000;i++){
        int za=i*8/100;
        int zb=i*10/100;
        if(za==a&&zb==b){
            dunk(i);
            return 0;
        }
    }
    
    dunk(-1);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  double a,b,c,d,e,f,x,y;
  while(cin >> a){
    cin >> b >> c >> d >> e >> f;
    if(b == 0){
      x = c / a;
    }else if(e == 0){
      x = f / d;
    }else if(b != 0 && e != 0){
      double g = a / b;
      double h = d / e;
      double i = c / b;
      double j = f / e;
      x = (i - j) / (g - h);
    }else{
      return -1;
    }
    if(b != 0){
      y = (c - a * x) / b;
    }else{
      y = (f - d * x) / e;
    }
    x = (int)(x * 1000) / (double)(1000);
    y = (int)(y * 1000) / (double)(1000);
    printf("%.3f %.3f\n", x, y);
  }
  return 0;
}

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

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

  int n; cin >> n;

  int r1, r2;
  r1 = n / 100;
  r2 = (n - 100*r1) / 10;
  int q = n - 100*r1 - 10*r2;

  if (q == 3)
  {
    cout << "bon" << endl;
    return 0;
  }
  if (q == 0 || q == 1 || q == 6 || q == 8)
  {
    cout << "pon" << endl;
    return 0;
  }
  
  cout << "hon" << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>

int	intcmp(const void *n1, const void *n2)
{
	return(*(int *)n1 - *(int *)n2);
}

int	main()
{
	int	N;
	int	i;
	int	*val;

	i = 0;
	scanf("%d\n", &N);
	val = (int *)malloc(sizeof(int) * (N + 1));
	while (i < N)
	{
		scanf("%d ", &val[i]);
		i++;
	}
	qsort(val, i, sizeof(int), intcmp);
	printf("%d\n", val[i / 2] - val[i / 2 - 1]);
	return (0);
}

Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;
using lint = long long;

struct RMQ{
  static const lint MAX_N = 3e5;
  lint n,dat[2 * MAX_N-1];
  RMQ(){}
  RMQ(lint n_){init(n_);}
  void init(lint n_){
    n = 1;
    while(n < n_) n *= 2;
    for(int i = 0; i < 2 * n-1; i++) dat[i] = 0;
  }
  void update(lint k, lint a){
    k += n-1;
    dat[k] = a;
    while(k > 0){
      k = (k - 1) / 2;
      dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  lint query(lint a, lint b, lint k, lint l, lint r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return dat[k];
    else{
      lint vl = query(a, b,k * 2 + 1, l, (l + r) / 2);
      lint vr=query(a, b, k * 2 + 2,(l + r) / 2, r);
      return max(vl, vr);
    }
  }
  lint query(lint a,lint b){
    return query(a, b, 0, 0, n);
  }
};

signed main(){
  int N; cin >> N;
	vector<lint> h(N), a(N);
	RMQ rmq(N + 10);
	for(int i = 0; i < N; i++) cin >> h[i], h[i]--;
	for(int i = 0; i < N; i++) cin >> a[i];
	lint ans = 0;
	for(int i = 0; i < N; i++){
		lint ans1 = a[i] + rmq.query(0, h[i]);
		ans = max(ans, ans1);
		rmq.update(h[i], ans1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1001001001;
const ll mod = 1000000007;
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

int main() {
    ll N,K; //ｎ以下のｋの倍数
    cin >> N >> K;
    if(K % 2 == 1){
        ll cnt = N / K;
        cout << cnt * cnt * cnt << endl;
    }
    else{
        ll zero = N / K;
        ll half = (N + K / 2) / K;
        /*cout << zero << half << endl;*/
        cout << zero * zero * zero + half * half * half << endl;
    }
}

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

int a, b, c, x, y;

int main() {
    while (cin >> a >> b >> c >> x >> y) {
        ll ans = 1e18;
        rep(i, 200001) {
            // ABピザをi枚買う
            ll t = a * max(0, x - i / 2) + b * max(0, y - i / 2) + c * i;
            ans = min(ans, t);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
x,y,a,b,c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

p = p[:x]
q = q[:y]
r = r[:x+y]

all = p + q + r
all.sort(reverse = True)
print(sum(all[:x+y]))

Measured memory_bytes: 113004
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

string solve(int x){
    if(x < 1200){
        return "ABC";
    }else{
        return "ARC";
    }
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x;
    cin >> x;

    cout << solve(x) << endl;

    return 0;
}


Measured memory_bytes: 256