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

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c;
    while(true)
    {
        cin >> a >> b >> c;
        if(a+b+c == 0) break;
        int n;
        cin >> n;
        vector<int> vec(a+b+c, 2), r(n);
        vector<vector<int>> a(n, vector<int>(3));
        REP(i, n)
        {
            cin >> a[i][0] >> a[i][1] >> a[i][2] >> r[i];
            if(r[i] == 1)
            {
                REP(j, 3) vec[a[i][j] - 1] = 1;

            }
        }

        REP(i, n)
        {
            if(r[i] == 0)
            {
                int ok = 0;
                REP(j, 3) ok += vec[a[i][j] - 1] == 1 ? 1 : 0;
                if (ok == 2)
                {
                    REP(j, 3)
                    {
                        if (vec[a[i][j] - 1] != 1) vec[a[i][j] - 1] = 0;
                    }
                }
            }
        }
        for(auto x : vec) cout << x << endl;
    }
}


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

fn main() {
    input! {
        A: i32,
        B: i32,
    }
    println!("{}", (A - 1) * (B - 1));
}


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

int main(){
    string s,t; cin >> s >> t;
    int a,b; cin >> a >> b;
    string u; cin >> u;
    if(u==s) cout << a-1 << ' ' << b << endl;
    else cout << a << ' ' << b-1 << endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        if((a+b)%2==0)
            cout<<(a+b)/2<<endl;
        else
            cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

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

using namespace std;

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    string x;

    cin >> n >> x;

    int counter = 0;

    for(int i=0;i<(int)x.size()-2;++i)
        if(x[i] == 'A' and x[i+1] == 'B' and x[i+2] == 'C')
            counter++;

    cout << counter << '\n';

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int h = sc.nextInt();
		int w = sc.nextInt();

		char[][] sq = new char[h][w];

		for (int i = 0; i < h; i++) {
			String s = sc.next();
			sq[i] = s.toCharArray();
		}
		
		String ans = isJoined(sq) ? "Yes" : "No";
		System.out.println(ans);

		sc.close();
	}

	static boolean isJoined(char[][] arr) {
		for (int i = 0; i < arr.length; i++) {
			for (int j = 0; j < arr[i].length; j++) {
				// 白マスはスキップ
				if (arr[i][j] == '.')
					continue;
				// 上
				if (i != 0)
					if (arr[i - 1][j] == '#')
						continue;
				// 下
				if (i != arr.length - 1)
					if (arr[i + 1][j] == '#')
						continue;
				// 左
				if (j != 0)
					if (arr[i][j - 1] == '#')
						continue;
				// 右
				if (j != arr[i].length - 1)
					if (arr[i][j + 1] == '#')
						continue;
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main() {

	int N, K;
	cin >> N >> K;
	vector<int> data(N);

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

	sort(data.begin(), data.end(), greater<int>());

	int ans = 0;
	for (int i = 0; i < K; i++) {
		ans += data[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// make pair, tuple
// __gcd(int, int);
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }
// 
// #Count leading & trailing zero of an integer bits
// __builtin_clz(n);
// __builtin_clzll(n);
//
// #Count 1s bits of an integer
// __builtin_popcount(n);
// __builtin_popcountll(n);
//
// #Error checking
// assert(n == 3);
// 
// #Error Printing
// cerr << "Some thing";

int main(){
    long long int l,r;cin >> l >> r;
    r = min(r, l + 2 * 2019);
    long long int ans = 2018;
    for(long long int i = l;i < r;i++){
        for(long long int j = i + 1;j <= r;j++){
            ans = min(ans, (i * j) % 2019);
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
N, M = [int(i) for i in input().split()]
L = 1
R = N

for _ in range(M):
    tL, tR = [int(i) for i in input().split()]
    if tL > L:
        L = tL
    if tR < R:
        R = tR

print(R - L + 1 if R >= L else 0)


Measured memory_bytes: 3060
/*input
4
aaaa
a
aaa
aa
*/

#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility> 
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ld = long double;

const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define all(c)      (c).begin(),(c).end()
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(auto x: v) {
    os << x << " ";
  }
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

/******************************** START *********************************/
const int N = 100005;

int main()
{
  ifalse;
  int n;
  cin >> n;
  map < string, int > mp;
  for(int i = 0; i < n;i ++) {
    string s;
    cin >> s;
    mp[s] ++;
  }
  cout << mp.size(), nl;
  return 0;
}

Measured memory_bytes: 19288
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

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

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    string s;
    cin >> s;
    int cnt = 0;
    rep(i, s.size()) cnt += s[i] - '0';
    cout << cnt << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){

    int N;
    cin >> N;
    
    double sq;
    double ans;
    int q;
    for(int i=N; i>=1; i--){
        sq = sqrt(i);
        ans = int(sq) * int(sq);
        if(i == ans){
            q = i;
            break;
        }
    }

    cout << q << endl;
    
    return 0;
}

Measured memory_bytes: 384
N,W=map(int,input().split())
dp=[[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1,N+1):
    w,v=map(int,input().split())
    for j in range(1,W+1):
        if j-w>=0:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
        else:
            dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

Measured memory_bytes: 171400
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, t: [i64; 3],
        l: [i64; n],
    }

    let ans = dfs(0, 0, 0, 0, &l, &t);
    println!("{}", ans);
}

fn dfs(rod: usize, a: i64, b: i64, c: i64, l: &[i64], t: &[i64]) -> i64 {
    if rod == l.len() {
        return if a*b*c == 0 {
            1<<60
        } else {
            (a - t[0]).abs() + (b - t[1]).abs() + (c - t[2]).abs() - 30
        };
    }
    let mut res = Vec::new();
    res.push(dfs(rod+1, a + l[rod], b, c, l, t) + 10);
    res.push(dfs(rod+1, a, b + l[rod], c, l, t) + 10);
    res.push(dfs(rod+1, a, b, c + l[rod], l, t) + 10);
    res.push(dfs(rod+1, a, b, c, l, t));
    res.iter().cloned().min().unwrap()    
}

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

typedef long long ll;

int n,k;
ll A[1000006];

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

	for(int i=0;i<n;i++)
		cin >> A[i];

	ll ans=INT_MAX;

	for(int i=0;i+k<=n;i++){
		ll l=A[i];
		ll r=A[i+k-1];

		if(l>=0)
			ans=min(ans,r);
		else if(r<=0)
			ans=min(ans,-l);
		else
			ans=min(ans,min(abs(l),abs(r))+r-l);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>

using namespace std;

int dp[100005];

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int m=dp[i-1]+1;
        for(int k=6;k<=i;)
        {m=min(m,1+dp[i-k]);
        k*=6;}                       //求6的几次方 
        for(int k=9;k<=i;)
        {m=min(m,1+dp[i-k]);
        k*=9;}                       //求9的几次方 
        dp[i]=m;                      
    }
    cout<<dp[n];
   // system("pause");
    return 0;
}  
    

Measured memory_bytes: 640
#include <iostream>

int main(void)
{
    int n;  // 1 <= n <= 999
    std::cin >> n;

    const int n_1 = n % 10;

    switch (n_1)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        std::cout << "hon" << std::endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        std::cout << "pon" << std::endl;
        break;
    case 3:
        std::cout << "bon" << std::endl;
        break;
    }

    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5;
int N, M;
vector<int> r;
vector<int> path[MAX_N];
int recursive(int v) {
    if(!r[v]) {
        for(auto x : path[v]) {
            r[v] = max(r[v], recursive(x) + 1);
        }
    }
    return r[v];
}
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        path[x].push_back(y);
    }
    r = vector<int>(N, 0);
    for(int i = 0; i < N; i++) {
        recursive(i);
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans = max(ans, r[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		try {
			int width = Integer.parseInt(scanner.nextLine());
			int height = 2;

			int[][] candyLines = new int[height][width];
			int[][] sum = new int[height][width];
			for (int x = 0; x < height; x++) {
				int sumTmp = 0;
				for (int y = 0; y < width; y++) {
					candyLines[x][y] = scanner.nextInt();
					sumTmp += candyLines[x][y];
					sum[x][y] = sumTmp;
				}
			}

			int maxCandy = 0;
			for (int i = 0; i < width; i++) {
				int candy = sum[0][i] + sum[1][width-1] - (i-1>=0?sum[1][i-1]:0);
				if (candy > maxCandy) {
					maxCandy = candy;
				}
			}
			System.out.print(maxCandy);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			scanner.close();
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, R;
    cin >> N >> R;
    if (N < 10) cout << R + 100 * (10 - N) << endl;
    else cout << R << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("in.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("out.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS 1

#include <cstdio>

using namespace std;

int main()
{
	int W, N, A[31], B[31], C[31];

	scanf("%d", &W);
	scanf("%d", &N);

	for (int i = 1; i <= N; i++)
	{
		scanf("%d,%d", &(A[i]), &(B[i]));
	}

	for (int i = 1; i <= W; i++)
	{
		int t = i;

		for (int j = 1; j <= N; j++)
		{
			if (A[j] == t)
			{
				t = B[j];
			}
			else if (B[j] == t)
			{
				t = A[j];
			}
		}

		C[t] = i;
	}

	for (int i = 1; i <= W; i++)
	{
		printf("%d\n", C[i]);
	}

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
  vector<int >v(n,0);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(),v.end());
  cout<<v[n/2]-v[n/2-1];
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int V[20];
int C[20];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>V[i];
	FOR(i,N) cin>>C[i];
	int ret=0;
	FOR(i,N) {
		if(V[i]>C[i]) ret+=V[i]-C[i];
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 100005  //check the limits, man
const ll INF = 1e12;
vvi ad(N);
int ans[N];
int main()
{
    int n,i,a,b,k,s,j,x;
    in(n);
    rep(i,n-1)
    {
        in2(a,b);
        ad[a].pb(b);
        ad[b].pb(a);
    }
    in(k);
    priority_queue<ii> pq;
    fill(ans,ans+N,-M);
    while(k--)
    {
        in2(a,b);
        ans[a]=b;
        pq.push({b,a});
    }
    while(!pq.empty())
    {
        b=pq.top().F,s=pq.top().S;
        pq.pop();
        x=ad[s].size();
        rep(i,x)
        {
            a=ad[s][i];
            if(ans[a]==-M)
                ans[a]=b-1,pq.push({ans[a],a});
        }
    }
    bool f=1;
    lp(i,1,n+1)
    {
        x=ad[i].size();
        rep(j,x)
        {
            a=ad[i][j];
            if(abs(ans[i]-ans[a])!=1)
                f=0;
        }
    }
    if(f)
    {
        printf("Yes\n");
        lp(i,1,n+1)
            out(ans[i]);
    }
    else
        printf("No\n");
}




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

signed
main(){
		int n,m;
		while(cin >> n >> m && !(n==0 && m==0))
		{
				vector<int> a(n);
				for(int i=0;i<n;i++)
						cin >> a[i];

				int ans = -1;

				for(int i=0;i<n;i++)
				{
						for(int j=i+1;j<n;j++)
						{
						int key = a[i] + a[j];
						if(key <= m)
						{
						if(ans<key)
						ans = key;
						}
						}
				}

				if(ans == -1) cout << "NONE" << endl;
				else cout << ans << endl;
		}
}


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

const int INF = 1e9;

const int MAXN = 15;
int N;
int W[MAXN][MAXN];

int V[1<<MAXN];
int dp[1<<MAXN][MAXN];

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int M;
	cin >> N >> M;
	int tot = 0;
	for (int i = 0; i < M; i++) {
		int a, b, c; cin >> a >> b >> c; a--, b--;
		W[a][b] = W[b][a] = c;
		tot += c;
	}

	for (int m = 0; m < (1<<N); m++) {
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {
				if ((m & (1 << i)) && (m & (1 << j))) {
					V[m] += W[i][j];
				}
			}
		}
	}

	for (int m = 0; m < (1<<N); m++) {
		for (int i = 0; i < N; i++) {
			dp[m][i] = -INF;
		}
	}
	dp[1][0] = 0;
	for (int m = 1; m < (1<<N); m++) {
		for (int i = 0; i < N; i++) {
			if (dp[m][i] == -INF) continue;

			for (int j = 0; j < N; j++) {
				if (m & (1 << j)) continue;
				if (W[i][j] == 0) continue;
				dp[m | (1 << j)][j] = max(dp[m | (1 << j)][j], dp[m][i] + W[i][j]);
			}

			int c = (1 << N) - 1 - m;
			for (int v = c; v; v = (v-1) & c) {
				dp[m|v][i] = max(dp[m|v][i], dp[m][i] + V[v | (1 << i)]);
			}
		}
	}
	cout << tot - dp[(1<<N)-1][N-1] << '\n';

	return 0;
}


Measured memory_bytes: 2304
program mirrored
  implicit none
  integer :: d, n, x(0:10), i, j, k
  integer(8) :: b(0:18) = 1_8, ans = 0_8, v(0:10)
  read(*,*) d
  if (mod(d,9) /= 0) then
    write(*,'(i0)') 0
    stop
  end if
  do i = 1, 18
    b(i) = 10_8*b(i-1)
  end do
  d = d/9
  do i = 1, 18
    n = (i+1)/2
    x = 0
    v = 0_8
    do j = 0, n-1
      do k = j, i-j-1
        v(j) = v(j)+b(k)
      end do
    end do
    ans = ans+num(int(d,8),i,0,n,x(0:n-1),v(0:n-1))
  end do
  write(*,'(i0)') ans
  stop
contains
  recursive function num(d,l,t,n,x,v) result(ret)
    implicit none
    integer, intent(in) :: l, t, n
    integer, intent(inout) :: x(0:n-1)
    integer(8), intent(in) :: d
    integer(8), intent(inout) :: v(0:n-1)
    integer :: i
    integer(8) :: ret
    ret = 0_8
    if (t == n) then
      if (d /= 0) return
      ret = 1_8
      ret = ret*int(9-abs(x(0)),8)
      do i = 1, n-1
        ret = ret*int(10-abs(x(i)),8)
      end do
      if (mod(l,2) == 0) ret = ret*10_8
      return
    end if
    do i = -9, 9
      if (-v(t) < d+v(t)*int(i,8) .and. d+v(t)*int(i,8) < v(t)) then
        x(t) = i
        ret = ret+num(d+v(t)*int(i,8),l,t+1,n,x,v)
      end if
    end do
    return
  end function num
end program mirrored

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<int>primes;
void hurui(const int amax) {
	static bool flag = false;
	if (flag)return;
	vector<int>sos;
	sos = vector<int>(amax + 1, true);
	sos[0] = false; sos[1] = false;
	for (int i = 2; i <= amax; ++i) {
		if (sos[i]) {
			for (int j = 2 * i; j <= amax; j += i)sos[j] = false;
		}
	}
	for (int i = 0; i <= amax; ++i) {
		if (sos[i]) {
			primes.push_back(i);
		}
	}
	flag = true;
}
map<long long int, int>soinnsuu(long long int a) {
	hurui(1e6);
	map<long long int, int>ans;
	for (auto i : primes) {
		if (i> a)break;
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;
	return ans;
}

int main() {
	int N,M;cin>>N>>M;
	auto n_mp(soinnsuu(N));
	map<int,bool>valid_mp;
	for (auto nm : n_mp) {
		valid_mp[nm.first]=false;
	}
	for (int i = 0; i < M; ++i) {
		int num;cin>>num;
		for (auto nm : n_mp) {
			if (num%nm.first) {
				valid_mp[nm.first]=true;
			}
		}
	}
	bool ok = all_of(valid_mp.begin(), valid_mp.end(), [](const pair<int, bool>&p) {
		return p.second;
	});
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 7420
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#define For(N) for (int i = 0; i < N; i++)

using namespace std;
using ll = long long int;

void say(string);

int main() {
	int A, B, C, D;
	int L, R;
	cin >> A >> B >> C >> D;
	L = A + B;
	R = C + D;
	if (L > R)say("Left");
	else if (L == R)say("Balanced");
	else say("Right");
}

void say(string s) {
	cout << s << endl;
}

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

const int MOD = (int) 1e9 + 7;

int A[100005];
long long fact[100005], mmi[100005];

long long power(long long N, long long expo)
{
    long long ans = 1;

    while(expo)
    {
        if(expo % 2)
            ans = ans * N % MOD;
        
        N = N * N % MOD;
        expo /= 2;
    }

    return ans;
}

long long nCr(int N, int r)
{
    if(N < r)
        return 0;
    
    return fact[N] * mmi[r] % MOD * mmi[N-r] % MOD;
}

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

    int N, K;
    cin >> N >> K;

    fact[0] = mmi[0] = 1;

    for(int i=1; i<=N; i++)
    {
        cin >> A[i];

        fact[i] = fact[i-1] * i % MOD;
        mmi[i] = power(fact[i], MOD-2);
    }

    sort(A+1, A+1+N);
    long long ans = 0;

    for(int i=1; i<=N; i++)
        ans += 1LL * (MOD + A[i]) % MOD * (nCr(i-1, K-1) + MOD - nCr(N-i, K-1)) % MOD;

    cout << ans % MOD << "\n";
    return 0;
}


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

using ll = long long;

#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())

ll dp_real[2][301][301];
ll dp_suff[2][301][301];
ll dp_diag[2][301][301];

const ll p = 998244353LL;

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	string s;
	int k;

	cin>>s>>k;

	k=min(k,300);

	int n = len(s);
	int zi=0;

	int initial_ones = 0;
	int ind=n-1;

	while(ind>=0 && s[ind]=='1')
	{
		ind--;
		initial_ones++;
	}

	// initialise the dp

	for(int i=0; i<=min(k,initial_ones); i++)
	{
		dp_real[0][i][i]=1;
		//cout << 0 << " " << i << " " << i << " " << 1 << endl;
	}

	// diag dudes is pretty easy to do

	for(int i=0; i<=k; i++)
	{
		for(int j=0; j<=k; j++)
		{
			dp_diag[0][i][j]=dp_real[0][i][j];

			if(i>0&&j>0)
			{
				dp_diag[0][i][j] += dp_diag[0][i-1][j-1];
				dp_diag[0][i][j] %= p;
			}
		}
	}
	// suff dudes ... not so bad either ???

	for(int i=0; i<=k; i++)
	{
		for(int j=k; j>=0; j--)
		{
			dp_suff[0][i][j]=dp_real[0][i][j];

			if(j<k)
			{
				dp_suff[0][i][j]+=dp_suff[0][i][j+1];
				dp_suff[0][i][j]%=p;
			}
		}
	}

	for(int ii=n-1; ii>=0; ii--)
	{
		if(s[ii]=='1') continue;
		
		// if(!skip_first)
		// {
		// 	skip_first=1;
		// 	continue;
		// }

		zi=1-zi;

		int a = 0;
		int copy_i = ii-1;

		while(copy_i>=0 && s[copy_i]=='1')
		{
			a++;
			copy_i--;
		}

		//cout << a << endl;

		for(int i=0; i<=k; i++)
		{
			for(int j=0; j<=k; j++)
			{
				// compute new real_dp[zi][i][j] value

				dp_real[zi][i][j] = dp_suff[1-zi][i][j];

				dp_real[zi][i][j] += dp_diag[1-zi][i][j];
				dp_real[zi][i][j] %= p;

				if(i-a > 0 && j-a > 0) // maybe add conditions on j < i or whatever
				{
					dp_real[zi][i][j] += p - dp_diag[1-zi][i-a-1][j-a-1];
					dp_real[zi][i][j] %= p;
				}

				dp_real[zi][i][j] += p-dp_real[1-zi][i][j];
				dp_real[zi][i][j] %= p;

				//cout << ii << " " << i << " " << j << " " << dp_real[zi][i][j] << endl;

				dp_diag[zi][i][j] = dp_real[zi][i][j];

				if(i>0&&j>0)
				{
					dp_diag[zi][i][j] += dp_diag[zi][i-1][j-1];
					dp_diag[zi][i][j] %= p;
				}
			}

			dp_suff[zi][i][k]=dp_real[zi][i][k];

			for(int j=k-1; j>=0; j--)
			{
				dp_suff[zi][i][j] = dp_real[zi][i][j];
				dp_suff[zi][i][j] += dp_suff[zi][i][j+1];
				dp_suff[zi][i][j] %= p;
			}
		}
	}

	ll ans=0LL;

	for(int i=0; i<=k; i++)
	{
		ans += dp_real[zi][i][0];
		ans %= p;
	}

	cout << ans << endl;
}

Measured memory_bytes: 7856
/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define Speedforce boost();
#define fop(s1, s2) freopen(s1, "r", stdin);freopen(s2, "w", stdout);

using namespace std;

void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 1e6;
const ll inf = 1e9 + 9;
const ld PI = acos(-1);

ll bin_pow(ll x, ll y){
    ll res = 1, base = x;
    while(y){
        if(y & 1){
            res *= base;
            res %= inf;
        }
        base *= base;
        base %= inf;
        y /= 2;
    }
    return res;
}

int n;
int a[1005][1005];
int used[1005];
int pos[1005];

int main(){
    Speedforce
    //fop("", "")
    cin >> n;
    for(int i = 1;i <= n;i ++){
        for(int j = 1;j < n;j ++){
            cin >> a[i][j];
        }
        pos[i] = 1;
    }
    int cnt = 0;
    while(1){
        cnt++;
        bool flag1 = 1, flag2 = 1;
        for(int i = 1;i <= n;i ++){
            if(pos[i] >= n){
                continue;
            }
            int c = a[i][pos[i]];
            if(i == a[c][pos[c]]){
                flag2 = 0;
                pos[i]++;
                pos[c]++;
                int mx = max(used[i], used[c]);
                used[i] = mx + 1;
                used[c] = mx + 1;
                i = 0;
            }
        }
        for(int i = 1;i <= n;i ++){
            //cout << pos[i] << " ";
            if(pos[i] < n){
                flag1 = 0;
            }
            cnt = max(cnt, used[i]);
        }
        //cout << endl;
        if(flag1){
            cout << cnt;
            return 0;
        }
        if(flag2){
            cout << -1;
            return 0;
        }
    }
}


Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
using namespace std;
#define INF 100000
int n,dp[5005][4],p[5005],ans=INF;
int main(void){
    scanf("%d",&n);
    for(int i=0;i<=n;i++)for(int j=0;j<5;j++)dp[i][j]=INF;
    for(int i=0;i<n;i++)scanf("%d",p+i);
    for(int i=0;i<=p[0];i++)dp[0][i]=p[0]-i;
    for(int i=0;i<n-1;i++){
        for(int j=0;j<4;j++){
            dp[i+1][max(p[i+1]-j,0)]=min(dp[i+1][max(p[i+1]-j,0)],dp[i][j]+j*2);
        }
    }
    for(int i=0;i<4;i++)ans=min(ans,dp[n-1][i]+i);
    printf("%d\n",ans);
}



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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	long long int A, B, C, K; cin >> A >> B >> C >> K;
	if(K % 2 == 0) cout << A - B << endl;
	else cout << B - A << endl;


	return 0;

}



Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
            for(int i = 0; n > i; i++)
            {
                double x1 = sc.nextDouble();
                double y1 = sc.nextDouble();
                double x2 = sc.nextDouble();
                double y2 = sc.nextDouble();
                double x3 = sc.nextDouble();
                double y3 = sc.nextDouble();
                    double A1 = (2 * (x2 - x1));
                    double B1 = (2 * (y2 - y1));
                    double C1 = (x1*x1 - x2*x2 + y1*y1 - y2*y2);
                    double A2 = (2 * (x3 - x1));
                    double B2 = (2 * (y3 - y1));
                    double C2 = (x1*x1 - x3*x3 + y1*y1 - y3*y3);
                        double px = ((B1*C2 - B2*C1)/(A1*B2 - A2*B1));
                        double py = ((C1*A2 - C2*A1)/(A1*B2 - A2*B1));
                        double r = (Math.sqrt((px-x1)*(px-x1)+(py-y1)*(py-y1)));
                    System.out.printf("%.3f %.3f %.3f\n", px, py, r);
            }
    }
}

Measured memory_bytes: 28868
(* O(3^k) *)
let a, b, c, k = Scanf.scanf " %d %d %d %d" @@ fun a b c d -> a, b, c, d
let rec f i a b c =
  if i > k then a + b + c
  else List.fold_left max 0 [f (i + 1) (a * 2) b c; f (i + 1) a (b * 2) c; f (i + 1) a b (c * 2)]
let _ = Printf.printf "%d\n" @@ f 1 a b c

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
  int n, a, b, c, tmp;
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> a >> b >> c;
    if (a < b && c < b) {tmp=a; a=b; b=tmp;}
    else if (a < c && b < c) {tmp=a; a=c; c=tmp;}
    if (c < b) {tmp=b; b=c; c=tmp;}
    if (a*a == (b*b) + (c*c)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  
  if (a%2 == 0 || b%2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int h, n;
    cin >> h >> n;
    vs32 a(n), b(n);
    rep (i, n) cin >> a[i] >> b[i];

    int dp[h + 1];
    rep (i, h + 1) dp[i] = 1e9;
    dp[0] = 0;

    rep (i, n)
    {
        for (int j = 1; j <= h; ++j)
        {
            dp[j] = MIN(dp[j], dp[max(0, j - a[i])] + b[i]);
        }
    }


    cout << dp[h] << "\n";
    return 0;
}



Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())

out = ""
def p(s):
    global out
    out += s
# 1回目 行き
for i in range(ty-sy):
    p("U")
for i in range(tx-sx):
    p("R")

# 1回目 帰り
for i in range(ty-sy):
    p("D")
for i in range(tx-sx):
    p("L")

# 2回目 行き
p("L")
for i in range(ty-sy+1):
    p("U")
for i in range(tx-sx+1):
    p("R")
p("D")
# 2回目 帰り
p("R")
for i in range(ty-sy+1):
    p("D")
for i in range(tx-sx+1):
    p("L")
p("U")
print(out)

Measured memory_bytes: 3064
a,b,c,d = gets.chomp.split('')
ops = %w[+ -].product( %w[+ -]).product(%w[+ -]).map { |e| e.flatten }
ops.each do |op|
  eq = (a + op[0] + b + op[1] + c + op[2] + d)
  if eval(eq) == 7
    puts "#{eq}=7"
    exit
  end
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#define fastio cin.tie(0); ios::sync_with_stdio(0)
#define multitc int _t; cin>>_t; while(_t--)
#define arrin(arr, n, type) arr.assign(n,type()); for(auto& i : arr) cin>>i;
#define all(x) (x).begin(), (x).end()
const int dir[9][2] = {{0,-1},{-1,0},{0,1},{1,0},{1,1},{-1,-1},{1,-1},{-1,1},{0,0}};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INF = 1e15+7;
const ll MOD = 998244353;
using namespace std;
using namespace __gnu_pbds;
int nextInt(){int x; cin>>x; return x;}
ll nextLong(){ll x; cin>>x; return x;}
template<typename T>
void arrin2d(vector<vector<T>>& arr, int y, int x)
{
    arr.assign(y,vector<T>(x));
    for(int i=0;i<y;++i)
    {
        for(int j=0;j<x;++j)
        {
            cin>>arr[i][j];
        }
    }
}
 
//using template
//code goes here
 
int n, x, y;
int main()
{
    fastio;
    cin>>n>>x>>y;
    vector<int> ret(n+1,0);
    for(int i=1;i<n;++i)
    {
        for(int j=i+1;j<=n;++j)
        {
            int dist = min(j-i,abs(i-x)+1+abs(j-y));
            ret[dist]++;
        }
    }
    for(int i=1;i<=n-1;++i)
    {
        cout<<ret[i]<<'\n';
    }
}

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

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

    string s;
    cin >> s;
    int N = s.size();
    int K;
    cin >> K;
    vector<int> A(N, 0);
    rep(i, N) { A[i] = 26 - (s[i] - 'a'); }
    rep(i, N) {
        if (s[i] == 'a' && i != N-1)
            continue;
        if (K - A[i] >= 0) {
            s[i] = 'a';
            K -= A[i];
            A[i] = 26;
            if (K == 0)
                break;
        }
    }

    if (K > 0) {
        if (K > A[N - 1]) {
            int n = K - A[N - 1];
            s[N - 1] = (char)((n % 26) + 'a');
        } else {
            int last = s[N - 1] - 'a';
            s[N - 1] = (char)(last + K + 'a');
        }
    }

    cout << s << endl;
}

Measured memory_bytes: 3872
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nk = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        WriteLine(Ceiling((double)(nk[0] - 1) / (nk[1] - 1)));
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 16864
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll h,w,k,ans=INF;cin>>h>>w>>k;

  V<string> v(h);
  rep(i,0,h)cin>>v[i];

  V<int> gind(h,0);
  V<int> num(h,0);
  rep(i,0,(1<<h)){
    int cnt=0;
    rep(j,0,h-1){
      if(i&(1<<j)){
        cnt++;
      }
      gind[j+1]=cnt;
    }

    ll res=cnt;

    num.assign(h,0);
    rep(j,0,w){
      bool ovf=false;
      rep(l,0,h){
        if(v[l][j]=='1'){
          num[gind[l]]++;
          if(k<num[gind[l]]){
            ovf=true;
          }
        }
      }
      
      if(ovf){
        res++;
        num.assign(h,0);
        rep(l,0,h){
          if(v[l][j]=='1')num[gind[l]]++;
        }

        rep(l,0,h){
          if(num[l]>k)res=LINF;
        }
      }
    }

    //if(chmin(ans,res))cerr<<i<<ENDL;
    chmin(ans,res);
  }
  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
n,m,p = map(int, input().split())
edge = []
e1 = [list() for _ in range(n+1)]
for _ in range(m):
  a,b,c = map(int, input().split())
  edge.append((a,b,p-c))
  e1[a].append(b)
dis = [float("inf")]*(n+1)
dis[1] = 0
t = []
for i in range(n):
  for a,b,c in edge:
    if dis[b] > dis[a] + c:
      dis[b] = dis[a] + c
      if i == n-1:
        t.append(b)
s = set(t)
while t:
  v = t.pop()
  for x in e1[v]:
    if x == n:
      print(-1)
      exit(0)
    if x in s:
      continue
    s.add(x)
    t.append(x)
print(max(0,-dis[n]))


Measured memory_bytes: 51692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000007
#define SEP " "

int     main()
{
	string s, t;
	cin >> s >> t;
	int c = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != t[i])
			c++;
	}
	cout << c << endl;
}


Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define pb              push_back
#define se              second
#define mp              make_pair
#define fi              first
#define del(a,vec)      vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f,l,v)   binary_search(f,l,v)
#define iter(a,b)       vector<int>::iterator a,b
#define lower(v,num)    lower_bound (v.begin(), v.end(), num);
#define upper(v,num)    upper_bound (v.begin(), v.end(), num); 
#define removecopy(a)   unique(a.begin(), a.end()); 
#define vi              vector<int> 
#define pi              pair<int,int>    
#define vpi             vector<pi>      
#define mlbb            ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)    
int mod =1000000007;
namespace Rahul{
    bool isPrime(int n) 
    {if (n <= 1)  return false; if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; }
    int pow (int x, int n,int mod) {//calculate x^n
    if (n == 0) return 1;

    int res = pow (x, n / 2,mod);

    res = (res * res) % mod;
    if (n % 2) res = (res * x ) % mod;

    return res;
    }
    int _gcd(int a,int b)
    {
        if(a==0)
            return b;
        else    
            return _gcd(b%a,a);
    }
    //s.erase(s.find(2)) where s={1,2,3,3,2}; 
};
using namespace Rahul;
int32_t main()
{
    mlbb;
    double a,b;
    cin>>a>>b;
    
    int ans = ceil(a/b);
    cout<<ans<<endl;
    
    
    
    
}


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

 using namespace std;
 typedef long long ll;

 int main() {
   string S;

   cin >> S;

   int k = S.length();
   int count = 0;

   for (int i = 0; i < k; i++) {
     if (S.at(i) == 'o') count++;
   }

   if (count + 15 - k >= 8) cout << "YES" << endl;
   else cout << "NO" << endl;
 }


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

int main(){
  int H, W;
  for (int i = 0; i < 100000; i++){
    cin >> H >> W;
    if (H == 0 && W == 0){
      break;
    }
    else{
      for (int j = 0; j < H; j++){
        for (int k = 0; k < W; k++){
          if (j > 0 && j < H - 1 && k > 0 && k < W - 1){
            cout << ".";
          }
          else {
            cout << "#";
          }
        }
        cout << endl;
      }
      cout << endl; 
    }
  }
} 



Measured memory_bytes: 3112
char N_[9],W_[20];
main()
{
	read(0,N_,9);
	int N=0;
	for(int i=0;N_[i]>='0';i++)N=N*10+N_[i]-'0';
	long ans=0;
	int i=1;
	while(i<=N)
	{
		long j=N/(N/i)+1;
		ans+=(j-i)*(i+j-1)*(N/i)*(N/i+1)/4;
		i=j;
	}
	i=20;
	do{W_[--i]=ans%10+'0';}while(ans/=10);
	write(1,W_+i,20-i);
}

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

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

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

int T;

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

void solve(ll a, ll b, ll c, ll d){
    if(d < b or a < b){
        cout << "No" << endl;
        return;
    }
    if(c >= b){
        cout << "Yes" << endl;
        return;
    }
    ll g = gcd(d, b);
    a -= (a - c - 1) / g * g;
    //cout << "!!! " << a << endl;
    if(a >= b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> T;
    while(T--){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        solve(a, b, c, d);
    }
    return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
//const int mod = 1000000007;
const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<P> d(n);
  rep(i, n) cin >> d[i].first >> d[i].second;
  rep(i, n-2) if(d[i].first == d[i].second && d[i+1].first == d[i+1].second && d[i+2].first == d[i+2].second) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3600
#include<iostream>

using namespace std;

int main(void){
    int A,B,C,T;
    T=0;
    
    cin>>A>>B>>C;
    
    if(A*C<=B){
        T=C;
    }else if(A>B){
        T=0;
    }else if(B/A<C){
        T=B/A;
    }
    
    cout<<T<<endl;    
       
    return 0;
}


Measured memory_bytes: 256
import math
n,d = map(int,input().split())
x = []
def dis(x1,x2):
    return (x1-x2)**2
for i in range(n):
    x_i = list(map(int,input().split()))
    x.append(x_i)
count = 0
for i in range(n):
    for j in range(i+1,n):
        sum = 0
        for k in range(d):
            sum += dis(x[i][k],x[j][k])
        if math.sqrt(sum).is_integer():
            count += 1
print(count)

Measured memory_bytes: 3064