akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

# define ll long long 
# define VI vector<int>
# define VLL vector<ll>
# define PII pair<int,int> 
# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ld long double
# define FOR(i,a,b) for(int i = a ; i < b ; ++i)
# define RFOR(i,a,b) for(int i = a ; i >= b ; --i)
# define all(a) a.begin(),a.end() 
const int MxN = 10000 ; 
const int MOD = 1e9 + 7 ; 

/* VARIABLES */
VI adj[MxN] ; 
vector<bool> vis(MxN) ; 
/* END OF VARIABLES */

void dfs(int u) {
	vis[u] = true ; 
	for(int x : adj[u]) {
		if(!vis[x])
			dfs(x) ; 
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;  
	int x1,x2,y1,y2 ; 
	cin >> x1 >> y1 >> x2 >> y2 ; 
	int xdis = x2 - x1 ; 
	int ydis = y2 - y1 ; 
	cout << x2 - ydis << " " << y2 + xdis << " " << x1 - ydis << " " << y1 + xdis ; 

	return 0 ; 
}



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

/*int change(char c) {
	if ('a' <= c && c <= 'z') {
		return (c - 'a');
	}
}*/
int mul(int x, int n) {
	long long y = 1;
	for (int i = 0; i < n; i++) {
		y = y * x;
	}
	return y;
}
int sum(long long x) {
	long long k = 1;
	int j = 0;
	while (k <= x) {
		j += (x % (10 * k)) / k;
		k = k * 10;
	}
	return j;
}

int main() {
	int a, n;
	long long m;
	cin >> a >> n >> m;
	int judge = 0;
	for (int i = 1; mul(i,n) <= m; i++) {
		if (mul(i, n) == mul(sum(mul(i, n)) + a, n)) {
			judge++;
		}
	}
	cout << judge << endl;

	/*int N;
	cin >> N;
	string s,t;
	cin >> s >> t;
	for (int j = 0; j < N; j++) {
		if (j == 0) {
			for (int i = 0; i < 26; i++) {
				if (change(s[0]) == i) {
					dp[0][i] = 1;
				}
				else {
					dp[0][i] = 0;
				}
			}
		}
		else {
			for (int i = 0; i < 26; i++) {
				dp[j][i] = dp[j - 1][i]%1000000007;
			}
			dp[j][change(s[j])] = (dp[j][change(s[j])]+dp[j - 1][change(t[j])])%1000000007;
		}
	}
	cout << dp[N-2][change(t[N-1])] << endl;*/
	return 0;
}


Measured memory_bytes: 3100
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	int n, c;
	cin >> n >> c;
	int d[30][30];
	int cnt[3][30] = {};
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			cin >> d[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int tmp;
			cin >> tmp;
			tmp--;
			cnt[(i + j) % 3][tmp]++;
		}
	}
	int ans = mod;
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			if (i == j) continue;
			for (int k = 0; k < c; k++) {
				if (i == k || j == k) continue;
				int res = 0;
				int now[3] = {i, j, k};
				for (int p = 0; p < 3; p++) {
					for (int q = 0; q < c; q++) {
						res += d[q][now[p]] * cnt[p][q];
					}
				}
				ans = min(ans, res);
			}
		}
	}
	cout << ans << endl;
}

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

typedef long long ll;

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

// chmax, chmin
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; }

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    map<int,int> m;
    REP(i,N) {
        cin >> A[i];
        m[A[i]] += 1;
    }
    
    vector<ll> v;
    for ( auto a: m){
        int num = a.second;
        int r = a.first;
        if ( num >= 4 ) {
            v.push_back(r);
            v.push_back(r);
        } else if ( num >= 2 ) {
            v.push_back(r);
        }
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    
    
    ll ans = 0;
    if ( v.size() >= 2 ){
        ans = v[0] * v[1];
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 8192
s=input()
word=list(s)
flaga=0
flagb=0
if (s[0]=='0' and 1<=int(s[1])<=9) or (s[0]=='1' and 0<=int(s[1])<=2):
  flaga+=1
if (s[2]=='0' and 1<=int(s[3])<=9) or (s[2]=='1' and 0<=int(s[3])<=2):
  flagb+=1

if flaga==1 and flagb==1:
  print('AMBIGUOUS')
elif flaga==0 and flagb==1:
  print('YYMM')
elif flaga==1 and flagb==0:
  print('MMYY')
elif flaga==0 and flagb==0:
  print('NA')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		int left = 0;
		int right = 0;
		int diffMin = 1000;

		for (int i = 1; i < n; i++) {
			for (int j = 0; j < i; j++) {
				left += a[j];
			}
			for (int j = i; j < n; j++) {
				right += a[j];
			}
			if (Math.abs(left - right) < diffMin) {
				diffMin = Math.abs(left - right);
			}

			left = 0;
			right = 0;
		}

		System.out.println(diffMin);

	}

}


Measured memory_bytes: 23124
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		int N = nextInt();
		int red = 0;
		ArrayList<String> list = nextCharArray();
		for(int i = 0; i < N; i++){
			if(list.get(i).equals("R")){
				red++;
			}
		}
		int blue = N - red;
		myout((red > blue) ? "Yes" : "No");
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33228
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    A,B = map(str,input().split())

    A = int(A)
    B100 = int(B[0]) * 100 + int(B[2:])

    res = A * B100 // 100

    print(res)



main()


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

int main() {
  vector<int> a(3);

  for(int i=0; i<3; i++){
    cin >> a.at(i);
  }

  sort(a.begin(), a.end());

  if(a.at(0)+a.at(1)==a.at(2)){
    cout << "Yes" << endl;
  }

  else{
    cout << "No" << endl;
  }

return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LIMIT 55555
bool primes[LIMIT];

vector<int> vals;
void build(){
	primes[0] = primes[1] = true;
	for(int i=2;i<LIMIT;i++){
		if(primes[i]) continue;
		for(int j=2*i;j<LIMIT;j+=i) primes[j] = true;
	}
	for(int i=0;i<LIMIT;i++) if(primes[i] == false && i%5 == 1) vals.push_back(i);
}

int main(){
	build();
	int N;cin>>N;
	for(int i=0;i<N;i++) cout<<vals[i]<<" ";
	cout<<endl;
	return 0;
}
	

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer[] A = new Integer[N];
		for (int i=0; i<N; i++){
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		int f = A[0];
		int l = A[A.length-1];
		System.out.println(l-f);
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,b) for(int i(a);i<b;i++)
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define pres(x) cout<<fixed; cout<<setprecision(x);
#define open freopen("input.txt","r",stdin) ; freopen("output.txt","w",stdout);
#define watch(x) cout<<(#x)<<" is "<<x<<"\n";
#define mod 1000000007
//#define v.all() v.begin(),v.end()

int32_t main(){
	
	fast;
	//open;

	int n,x;
	cin>>n;
	map<pair<string,int>, int> input; map<string, vector<int>> m; string array[n],s; pair<string,int> p; vector<int> v;
	
	rep(i,n){
		cin>>s>>x;
		p = make_pair(s,x);
		input[p] = i;
		array[i] = s;
		m[s].push_back(x);
	}
	sort(array,array+n);
	v = m[array[0]];
	sort(v.begin(), v.end(),greater<int>());
	// for(auto j:v)cout<<j<<" ";
	// 	cout<<"\n";
	
	rep(i,v.size()){		
		p = make_pair(array[0], v[i]);
		cout<<input[p]+1<<"\n";
	}
	
	int i=1; string prev=array[0];
	while(i<n){
		if(array[i]!=array[i-1]){
			v = m[array[i]];
			sort(v.begin(), v.end(),greater<int>());
			rep(j,v.size()){		
				p = make_pair(array[i], v[j]);
				cout<<input[p]+1<<"\n";
			}
			prev = array[i];
		}
		i++;
	}

	return 0;
}

Measured memory_bytes: 256
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)


def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True


s=input()
N=len(s)
l=int((N-1)/2 -1)
#r = int((N+3)/2 +1)
r=l+2
#print(s,l,r)
if is_kaibun(s) and is_kaibun(s[:(l+1)]) and is_kaibun(s[r:]):
    print("Yes")
else:
    print("No")


#999999999 999999999



Measured memory_bytes: 12476
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
    double n, m;
    cin >> n >> m;
    cout << (1900*m+100*(n-m))*pow(2,m) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    int ans = 0 , tmp = 0;
    REP(i,s.size()){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') tmp++;
        else tmp = 0;
        chmax(ans,tmp);
    }
    out(ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1.0)

#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld\n",a)

#define stll(a) stoll(a,nullptr,10)
#define all(a) a.begin(),a.end()
#define PII pair<ll,ll>
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define EL printf("\n")
#define ff first
#define ss second
#define rev(a) reverse(all(a))


#define mem(ar,val) memset(ar,val,sizeof(ar))
#define ssort(ar) sort(ar.begin(),ar.end())
#define csort(ar,comp) sort(ar.begin(),ar.end(),comp)

#define bug1(a) cerr<<"test "<<a<<endl;
#define bug2(a,b) cerr<<"test "<<a<<" "<<b<<endl;
#define bug3(a,b,c) cerr<<"test "<<a<<" "<<b<<" "<<c<<endl;
#define bug4(a,b,c,d) cerr<<"test "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

#define fout freopen("output.txt","w",stdout)
#define fin  freopen("input.txt","r",stdin)

/// unordered_map<int,int>mp;
/// mp.reserve(1024);
/// mp.max_load_factor(0.25);

/// pbds
/// *find_by_order(k) - return k th largest element.. 0 based
/// order_of_key(k) - number of items strictly smaller than k

///  priority_queue <ll, vector<ll>, greater<ll> >

/*
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
*/

typedef long long ll;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

ll ar[30];
int main()
{
    string st;
    cin>>st;
    ll n = st.length();
    for(int i=0;i<n;i++)
    {
        ar[ st[i]-'a' ]++;

    }
    for(int i=0;i<26;i++)
    {
        if(ar[i]&1)
        {
            cout<<"No\n";
            return 0;
        }

    }
    cout<<"Yes\n";
    return 0;


}













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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  map<char,int> c;
  string s;
  cin >> s;
  forn(i,4) {
    c[s[i]]++;
  }

  bool ok = true;
  ok &= c.size() == 2;
  for (auto p : c) {
    ok &= p.snd == 2;
  }

  if (ok)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

int main(){
	ll N;
	set<ll> d;
	cin >> N;
	rep(i, 0, N){
		ll temp;
		cin >> temp;
		d.insert(temp);
	}
	cout << d.size() << endl;
 	return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.cos
import kotlin.math.sqrt

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (a, b, h, m) = readIntegerList()
    val aRad = (PI / 6.0) * (h + m / 60.0) // ((2 * PI) / 12 * h) + (2 * PI) / 12 *  m / 60
    val bRad = PI * m / 30.0 // 2 * PI * m / 60
    val rad = aRad - bRad
    val ans = sqrt(a * a + b * b - 2 * a * b * cos(rad))
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 36612
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

//#define int long long

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

int main() {
    vector<P> v;
    int n, m;
    cin >> n >> m;
    int a, b;
    rep(i, m) {
        cin >> a >> b;
        v.pb(mp(a, b));
    }
    sor(v);
    int bmin = INF;
    int ret = 0;
    rep(i, m) {
        bmin = min(bmin, v[i].sc);
        if (v[i].fr >= bmin) {
            ret++;
            i--;
            bmin = INF;
            continue;
        }
    }
    ret++;

    cout << ret;

    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0){
		return 1;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1) * a % MOD;
	}
}

ll gcd(ll a, ll b){
	if(b==0){
		return a;
	}else{
		return gcd(b, a%b);
	}
}

int main(void){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max(0, c-(a-b))<<endl;
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    map<char,int> m;
    for(char c='a';c<='z';c++){
        m[c]++;
    }
    for(int i=0;i<n;i++){
        m[s[i]]++;
    }
    for(auto x:m){
        if(x.second == 1){
            cout << x.first << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
  char s[201],p[101];
  int i,j,f,l;

  scanf("%s",s);
  scanf("%s",p);
  for(i=0;s[i]!='\0';i++);
  l=i;
  for(i=0;i<l;i++)s[l+i]=s[i];
  s[i+l]='\0';
  for(f=0,i=0;s[i]!='\0';i++){
    if(s[i]==p[0]){
      for(j=0;;j++){
	if(p[j]=='\0'){
	  f=1;
	  break;
	}
	if(s[i+j]!=p[j]) break;
      }
    }
  }
  if(f==1) printf("Yes\n");
  else printf("No\n");

  return 0;
}

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

using namespace std;

const int ms = 2e5 + 17;
pair<int, int> arr[ms];
int answer[ms];

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

    int n;
    cin >> n;

    for(int i = 1; i <= n; ++i)
    {
        cin >> arr[i].first;

        arr[i].second = i;
    }

    sort(arr + 1, arr + n + 1);

    int val = n / 2;

    for(int i = 1; i <= n / 2; ++i)
        answer[arr[i].second] = arr[n / 2 + 1].first;

    for(int i = n / 2 + 1; i <= n; ++i)
        answer[arr[i].second] = arr[n / 2].first;

    for(int i = 1; i <= n; ++i)
        cout << answer[i] << '\n';

}


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

int main(){
	int H,W,h,w; cin>>H>>W>>h>>w;
	int mx=H*W;
	int mn=W*h+H*w-w*h;
	cout << mx-mn << endl;	
}

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

int main(void){
    int a, n, t, min = 1000000, max = -1000000;
    long int sum = 0;
    scanf("%d", &n);
    for(t = 0;t < n;t++){
        scanf("%d", &a);
        sum += a;
        if(min > a)
            min = a;
        if(max < a)
            max = a;
    }
    printf("%d %d %ld\n", min, max, sum);
    return 0;
}



Measured memory_bytes: 2100
from math import floor, sqrt
from itertools import count, takewhile

n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n)]

def mysqrt(n):
    x = floor(sqrt(n))
    for y in takewhile(lambda y: y**2 <= n, count(max(0, x-10))):
        x = y
    return x

for xy in xys:
    a, b = sorted(xy)
    if b - a < 2:
        print(2*a - 2)
    else:
        ab = a*b
        c = mysqrt(ab-1)
        if c*(c+1) >= ab:
            print(c*2 - 2)
        else:
            print(c*2 - 1)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
    float a,b,c,d,e,f,x,y;
    while(cin >> a){
        cin >> b;
        cin >> c;
        cin >> d;
        cin >> e;
        cin >> f;

        x = (-f+e*c/b)/(-d+a*e/b);
        y = (c-a*x)/b;
        x *= 10000.0f;
        y *= 10000.0f;
        x += 0.5f;
        y += 0.5f;
        x = (int)x;
        y = (int)y;
        x /= 10000.0f;
        y /= 10000.0f;
        printf("%.3f %.3f\n",x,y);

    }
    return 0;

}

Measured memory_bytes: 3144
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        if dp[i][j] != 0:
            dp[i+1][j] += dp[i][j] * 2
            dp[i+1][j] %= MOD
            if j + A[i] <= S:
                dp[i+1][j + A[i]] += dp[i][j]
                dp[i+1][j + A[i]] %= MOD

print(dp[N][S])

Measured memory_bytes: 132600
#include <iostream>
 
using namespace std;
 
int main(){
int N,M;
cin >> N;
long long T[N],sum=0;
for(int i=0;i<N;i++){
cin >>T[i];
sum+=T[i];
}
cin >> M;
int P;
long long X;
for(int i=0;i<M;i++){
cin >> P >> X;
cout << sum-T[P-1]+X << endl;
}
return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(3));
	vector<vector<int>> dp(n, vector<int>(3));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int j = 0; j < 3; ++j)
	{
		dp[0][j] = a[0][j];
	}
	for (int i = 1; i < n; i++)
	{
		
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 3; k++)
			{
				if (j != k)
				{
					dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
				}
				
			}
			
		}
	}
	cout << max({ dp[n - 1][0], dp[n - 1][1], dp[n - 1][2] });
	return 0;
}

Measured memory_bytes: 11264
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

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

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
	int n;
	long  long tk=0, ao=0;
	cin >> n;
	vector<int> a(n), b(n);
	priority_queue<pair<long long, int>> pq;
 	REP(i, n){
		cin >> a[i] >> b[i];
		pq.push(make_pair(a[i]+b[i], i));
	}

	pair<int, int> top;
	REP(i, n){
		top = pq.top();
		if(i % 2 == 0){
			tk += a[top.second];
		}
		else{
			ao += b[top.second];
		}
	pq.pop();
	}
	cout << tk - ao << endl;

}


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

int main() {
	// your code goes here
	int n;
	cin >> n;
	string s[n];
	map<string, int> k;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		if(k[s[i]] == 1){
			cout << "No" << endl;
			return 0;
		}
		k[s[i]]++;
	}
	for(int i = 1; i < n; i++){
		if(s[i - 1][s[i - 1].size() - 1] != s[i][0]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long

#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define U 1000000007
#define N 100005
#define ins insert
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  int h[n],ans[n];

  rep(i,0,n){ cin>>h[i]; ans[i]=INT_MAX;}
  ans[0]=0;
  rep(i,0,n)
  {
    rep(j,1,k+1)
    {
      if(i+j<n)
      ans[i+j]=min(ans[i+j],ans[i]+abs(h[i+j]-h[i]));
    }
  }
  cout<<ans[n-1];
 



}

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

int main(){
  int m,a,b,x,y,p[50000],n=0;
  for(int i=2;i<=50000;i++){
    bool f = true;
    for(int j=2;j*j<=i;j++){
      if(!(i%j)){
	f = false; break;
      }
    }
    if(f)p[n++] = i;
  }

  while(cin >> m >> a >> b,m+a+b){
    x = y = 0;
    for(int i=0;i<n;i++){
      if(2*p[i]>m)break;
      for(int j=i;j<n;j++){
	if(a*p[j]>b*p[i])break;
	if(p[i]*p[j]>m)break;
	if(x*y<p[i]*p[j]){
	  x = p[i]; y = p[j];
	}
      }
    }
    cout << x << " " << y << endl;
  }
}

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

#define mod 1000000007
#define LOCAL 0
#define pb push_back
#define ll long long

ll po(ll a,ll b){
	ll x = 1,y=a;
	while(b>0){
		if(b%2){
			x = x*y;
			x %= mod;
		}
		y=y*y;
		y%=mod;
		b/=2;
	}
	return x;
}

int main(){
	if(LOCAL){
    	freopen("C:/Users/gold/Desktop/sublime IO/input.txt","r",stdin);
    	freopen("C:/Users/gold/Desktop/sublime IO/output.txt","w",stdout);
	}
	int T = 1;
	//scanf("%d",&T);
	while(T--){
		string s;
		cin>>s;
		if(s.substr(0,4) == "YAKI"){
			puts("Yes");
		} else 
		puts("No");
	}
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  char S;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == 'Y') {
      cout << "Four" << endl; 
      break;
    }
  }
  if (S != 'Y')
  cout << "Three" << endl;
}

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;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	int N, M; cin >> N >> M;
	vector<long long int>ps,nums(N),as,bs,cs;
	for (int i = 0; i < M; ++i) {
		int p; cin >> p; p--;
		ps.push_back(p);
	}
	for (int i = 0; i < M - 1; ++i) {
		int a = ps[i];
		int b = ps[i + 1];
		if (a > b)swap(a, b);
		nums[a]++;
		nums[b]--;
	}
	for (int i = 1; i < N; ++i) {
		nums[i] += nums[i - 1];
	}
	long long int ans = 0;
	for (int i = 0; i < N - 1; ++i) {
		long long int a, b, c; cin >> a >> b >> c;
		long long int aa = min(a*nums[i], b*nums[i] + c);
		ans += aa;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4712
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int c = a+b;
    if(c >= 10){
        cout << "error" << endl;
    }else{
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
int N,K;
int *l;
scanf("%d %d",&N,&K);
l = (int *)malloc(N*sizeof(int));
int i,x;
for(i=0;i<N;i++){
scanf("%d",&l[i]);
}
int tmp;
for(i=0;i<N;i++){
	        for(x=N-1;x>i;--x){
	            if(l[x]<l[x-1]){
	                tmp=l[x-1];
	                l[x-1]=l[x];
	                l[x]=tmp;
}
}
}

int answer;
for(i=N-1;i>N-K-1;i--){
answer=answer+l[i];
}
printf("\n");
printf("%d\n",answer);
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <complex>
#include <iomanip>

using namespace std;

typedef complex<double> Point;

ostream& operator<<(ostream& os, const Point& p){
    return os <<  p.real() << " " << p.imag();
}

inline double dot(const Point& a, const Point& b){
    return real(conj(a) * b);
}

struct Line : vector<Point> {
    Line(const Point& a, const Point& b):vector<Point>{a, b}{}
};

inline Point proj(const Line& l, const Point& p){
    double t = dot(p - l[0], l[1] - l[0]) / norm(l[1] - l[0]);
    return l[0] + (l[1] - l[0]) * t;
}

int main(){
    int x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    Line l(Point(x0, y0), Point(x1, y1));
    int q;
    cin >> q;
    while(q--){
        int x2, y2;
        cin >> x2 >> y2;
        cout << fixed << setprecision(10) << proj(l, Point(x2, y2)) << '\n';
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
vector<int> parent;
vector<int> nodes;

int getParent(int x) {
  int y = x;
  while (y != parent[y]) y = parent[y];
  parent[x] = y;
  return y;
}

void unite(int x, int y) {
  x = getParent(x);
  y = getParent(y);
  if (x == y) return;
  if (nodes[x] < nodes[y]) swap(x, y);
  parent[y] = x;
  nodes[x] += nodes[y];
}

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;

  parent.resize(N);
  nodes.resize(N);
  rep(i, N) {
    parent[i] = i;
    nodes[i] = 1;
  }
  rep(i, M) {
    int x, y, z;
    cin >> x >> y >> z;
    --x, --y;
    unite(x, y);
  }

  int answer = 0;
  rep(i, N) {
    if (i == getParent(i)) ++answer;
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 1024
import std.stdio;
import std.conv;
import std.array;
import std.range;
import std.algorithm;

void main()
{
    auto buf = readln.split;
    int X = buf[0].to!int;
    int Y = buf[1].to!int;
    int Z = buf[2].to!int;
    int K = buf[3].to!int;

    long[] A = readln.split.to!(long[]);
    long[] B = readln.split.to!(long[]);
    long[] C = readln.split.to!(long[]);

    sort!("a > b")(A);
    sort!("a > b")(B);
    sort!("a > b")(C);

    long[] ans;

    int[] candidate = [0];

    ulong max_i, next_i;
    long max_v, v;
    int src;
    while (ans.length < K){
        max_v = 0;
        foreach (i; 0..candidate.length){
            v = A[candidate[i] / 1000000] + B[candidate[i] / 1000 % 1000] + C[candidate[i] % 1000];
            if (v > max_v){
                max_v = v;
                max_i = i;
            }
        }

        ans ~= max_v;
        src = candidate[max_i];
        int[] nexts;
        if (src / 1000000 + 1 < A.length) nexts ~= src + 1000000;
        if (src / 1000 % 1000 + 1 < B.length) nexts ~= src + 1000;
        if (src % 1000 + 1 < C.length) nexts ~= src + 1;
        foreach (next; nexts){
            next_i = candidate.assumeSorted().lowerBound(next).length;
            if (candidate.length <= next_i || candidate[next_i] != next) candidate.insertInPlace(next_i, next);
        }
        candidate = remove(candidate, max_i);
    }

    foreach (n; ans) writeln(n);
}



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

int main(){
    int a[30] = {};
    char c = getchar();
    while(isalpha(c)){
        a[c-'a']++;
        c = getchar();
    }
    for(int i = 0; i < 26; i++){
        if(!a[i]){
            printf("%c\n", 'a'+i);
            return 0;
        }
    }
    printf("None\n");
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
ll n;
Vi x;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n;
    x.resize(n);
    rep(i,n){
        cin>>x[i];
    }
    sort(all(x));
    ll ans = INF;
    rep(i,100){
        ll tmp = 0;
        rep(j,n){
            tmp += (x[j]-i-1)*(x[j]-i-1);
        }
        chmin(ans,tmp);
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,K;cin>>N>>K;
    int cnt = (N-1) * (N-2) / 2;
    if(K > cnt){
        cout << -1 << '\n'; return 0;
    }

    vector<pair<int,int> > v;
    for(int i=2;i<=N;++i){
        v.emplace_back(1,i);
    }
    cnt -= K;
    for(int i=2; i < N; ++i){
        for(int j=i+1; j <= N; ++j){
            if(cnt) {
                v.emplace_back(i,j);
                --cnt;
            }
        }
    }

    cout << v.size() << '\n';
    REP(i,v.size()) cout << v[i].first << " " << v[i].second << '\n';

    return 0;
}

Measured memory_bytes: 384
#include <iostream>

#define MAX 100
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int main(){
  int N, M, a[MAX][MAX], b[MAX], c[MAX];

  std::cin >> N >> M;
  rep(i,N){
    rep(j,M){
      std::cin >> a[i][j];
    }
    c[i] = 0;
  }
  rep(i,M){
    std::cin >> b[i];
  }

  rep(i,N){
    rep(j,M){
      c[i] += a[i][j]*b[j];
    }
  }
  rep(i,N){
    std::cout << c[i] << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1200
from sys import exit, setrecursionlimit
setrecursionlimit(10**6)

def array2D(row, col ,val=0):
    return [[val]*col for i in range(row)]

from itertools import product
import numpy as np

def c():
    INF = 10**9+1
    ans = INF
    for v in product(range(2), repeat=h-1):
        idx = 0
        K = []
        for i,j in enumerate(v):
            if j==1:
                K.append(S[idx:i+1, :].sum(axis=0).tolist())
                idx = i+1
        K.append(S[idx:, :].sum(axis=0).tolist())

        res = sum(list(v))
        s = [0]*(len(K))
        for i in range(w):
            f = False
            for j in range(len(K)):
                if s[j] + K[j][i] > k:
                    f = True
                    if K[j][i] > k:
                        res += INF
            if f:
                res += 1
                for j in range(len(K)):
                    s[j] = K[j][i]
            else:
                for j in range(len(K)):
                    s[j] += K[j][i]

        ans = min(res, ans)
    return ans




h,w,k = map(int, input().split())
S = []
for i in range(h):
    S.append(list(map(int, input())))

S = np.array(S)
print(c())

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

int main(){
    int A, B, sum=0;
    cin >> A >> B;
    for (int i=A; i<B+1; i++){
        bool flag = true;
        string s_num = to_string(i);
        int size_num = s_num.length();
        for (int j=0; j<(size_num + (size_num - 1))/2; j++){
            if (s_num[j] != s_num[size_num-1-j]) flag = false;
        }
        if (flag) sum++;
        flag = true;
    } 
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n,m,i,j,k;
  while(cin>>n>>m&&n&&m){
    int c[1000]={0};
    i=0;j=1;k=0;
    while(1){
      if(j==m&&c[i%n]==0){
	c[i%n]=1;
	++k;
	if(k==n){
	  int a=((i+1)%n)?(i+1)%n:n;
	  cout<<a<<endl;
	  break;
	}
	++i;j=1;
      }
      else if(c[i%n]==0){
	++j;++i;
      }
      else ++i;
    }
  }
  return 0;
}

Measured memory_bytes: 1164
def popcnt(n):
    return bin(n).count("1")

def f(n):
    cnt = 0
    while n>0:
        n = n%popcnt(n)
        cnt += 1
    return cnt

def solve(X):
    Y = int(X, 2)
    c = X.count("1")
    m, p = c-1, c+1
    Ym, Yp = Y%m if m else -1, Y%p
    for i in range(N):
        if X[i] == "1":
            Y = (Ym - pow(2,N-i-1,m))%m if Ym!=-1 else -1
        else:
            Y = (Yp + pow(2,N-i-1,p))%p
        print(f(Y) + 1 if Y!=-1 else 0)

N = int(input())
solve(input())



Measured memory_bytes: 83248
#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;

// O(√n) time
bool is_prime(int n) {
    if (n < 2) return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

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

    int a, d, n;
    while (cin >> a >> d >> n, a) {
        int cnt = 0;
        while (true) {
            if (is_prime(a)) {
                cnt++;
                if (cnt == n) break;
            }
            a += d;
        }
        cout << a << endl;
    }
}


Measured memory_bytes: 3140
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<set>
#include<queue>
#include<cstdlib>
#include<algorithm>

using namespace std;
#define pb push_back
#define mp make_pair
#define SZ(x) (int)(x).size()

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

const double eps = 1e-10;
const double PI = acos(-1.0);
//const double PI = 3.14159265358979323846264338327950288419716939937510
int dcmp(const double &x) { if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1; }
const int MOD = 1e9 + 7;
const int INF = (int)((1ll << 31) - 1);
const double INF_d = 1e64;

template<class T> 
T qmod(T a, T b){ T ret = 1; while (b){ if (b & 1) ret *= a; b >>= 1; a *= a; } return ret; }
template<class T>
T gcd(T a, T b){ return !b ? a : gcd(b, a % b); }
template<class T>
T ex_gcd(T a, T b, T &x, T &y){
    if (!b){ x = 1, y = 0; return a; }
    T t, ret;
    ret = ex_gcd(b, a % b, x, y);
    t = x, x = y, y = t - a / b * y;
    return ret;
}
template<class T>
T inv(T t, T p){ return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p; }
// head

namespace Union_Find{
    const int N = 1e4 + 7;
    int f[N], n, m;

    void init(int n){
        for (int i = 0; i <= n; i++) f[i] = i;
    }

    int find_fa(int x){ return x == f[x] ? x : f[x] = find_fa(f[x]); }

    void unite(int x, int y){
        int rx = find_fa(x), ry = find_fa(y);
        if (rx != ry) f[max(rx, ry)] = min(rx, ry);
    }
}

const int N = 1e5 + 7;
struct node{
    int l, r, val, mn;
};
node T[N << 2];
int n, m;

#define ls(x) (x << 1)
#define rs(x) (x<<1|1)

void build(int rt, int l, int r){
    T[rt].l = l, T[rt].r = r, T[rt].val = INF;
    if (r <= l) return;
    int mid = (l + r) >> 1;
    build(ls(rt), l, mid);
    build(rs(rt), mid + 1, r);
}

void pushup(int rt){ T[rt].val = min(T[ls(rt)].val, T[rs(rt)].val); }

void update(int rt, int l, int r, int val){
    if (T[rt].l > r || T[rt].r < l) return;
    if (l <= T[rt].l && T[rt].r <= r) { T[rt].val = val; return; }
    int mid = (T[rt].l + T[rt].r) >> 1;
    if (l <= mid) update(ls(rt), l, r, val);
    if (r > mid) update(rs(rt), l, r, val);
    pushup(rt);
}

int query(int rt, int l, int r){
    if (T[rt].l > r || T[rt].r < l) return INF;
    if (l <= T[rt].l && T[rt].r <= r) return T[rt].val;
    int mid = (T[rt].l + T[rt].r) >> 1;
    int ret = INF;
    if (l <= mid) ret = min(ret, query(ls(rt), l, r));
    if (r > mid) ret = min(ret, query(rs(rt), l, r));
    return ret;
}

int main(){
    scanf("%d%d", &n, &m);
    build(1, 1, n);
    for (int i = 0; i < m; i++){
        int op, x, y;
        scanf("%d%d%d", &op, &x, &y); x++;
        if (op) y++, printf("%d\n", query(1, x, y));
        else update(1, x, x, y);
    }
    return 0;
}


Measured memory_bytes: 7288
let reads f = stdin.ReadLine().Split(' ') |> Array.map f
let [| n; k |] = reads int64
let bs = reads int
let mutable na = 0L
let mutable nb = 0L
for i = 0 to int n-2 do
    for j = i+1 to int n-1 do
        if bs.[i] > bs.[j] then na <- na + 1L
        if bs.[i] < bs.[j] then nb <- nb + 1L

let m = int64 (10.**9.) + 7L
(k*(k-1L)/2L % m*(na+nb)%m + k*na%m) % m
|> printfn "%d"

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

using namespace std;

long long  dp[101][100001];
int n,k;
int we[101],val[101];
long long  go(int i,int k)
{
	if(i>=n || k<0)
	  return 0;
	else{
		if(dp[i][k]==-1){
	  if(we[i]>k)
	    dp[i][k]=go(i+1,k);
	  else  
	   dp[i][k]=max(val[i]+go(i+1,k-we[i]),go(i+1,k));
		}
	  return dp[i][k];	
	}
}

int main()
{   cin>>n>>k;
   memset(dp,-1,sizeof(dp));
   for(int i=0;i<n;i++)
     {
     	 cin>>we[i]>>val[i];
     }
    cout<<go(0,k); 
	return 0;
}

Measured memory_bytes: 79104