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

typedef pair<int, int> P;

int main() {
	int n;
	
	while (cin >> n,n) {
		int m[101][101] = { 0 };
		vector<P> row;
		vector<P> ans;
		for (int x = 0; x < n; x++) {
			for (int y = 0; y < n; y++) {
				cin >> m[x][y];
			}
		}
		for (int x = 0; x < n; x++) {
			int u = m[x][0];
			for (int i = 0; i < n; i++) {
				u = min(u, m[x][i]);
			}
			for (int i = 0; i < n; i++) {
				if (u == m[x][i]) {
					P p(x, i);
					row.push_back(p);
				}
			}
		}
		for (int y = 0; y < n; y++) {
			int u = m[0][y], t = 0;
			for (int i = 0; i < n; i++) {
				u = max(u, m[i][y]);
			}
			for (int i = 0; i < n; i++) {
				if (u == m[i][y]) {
					P p(i, y);
						for(int j = 0; j < row.size(); j++) {
							if (row[j] == p)ans.push_back(p);
						}
				}
			}
		}
		int t = 0;
		for (int i = 0; i < ans.size(); i++) {
			if(!i) {
				int x = ans[i].first;
			int y = ans[i].second;
			t =  m[x][y];
		}
		else
		{
			int x = ans[i].first;
			int y = ans[i].second;
			t = max(t, m[x][y]);
		}
		}
		cout << t << endl;
	}
}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(b / a, c) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  float f,h=0,l=0;
  while((scanf("%f",&f)) != EOF){
    if(h<f) h = f;
    if(l==0 || l > f) l = f;
  }
  printf("%.1f\n",h-l);
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int main(){
	printf("%d\n",read()^1);
	return 0;
}



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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long ll;
using namespace std;

int main() {
  string a, b;
  cin >> a >> b;
  
  if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
    printf("YES\n");
  }
  else printf("NO\n");
  return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
l.sort()

from bisect import bisect_left

ans = 0
for i in range(n):
    a = l[i]
    for j in range(i+1,n):
        b = l[j]
        ans += bisect_left(l,a+b)-j-1
print(ans)


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

int main(){
    int N, T, A, i, ans;
    int H[1010],I[1010];
    cin >> N >> T >> A;

    for (i = 1; i <= N; i++)cin >> H[i];
    
    int ABS = abs(1000 * (A - (T - H[1] * 0.006)));
    for (i = 1; i <= N; i++){
      if(ABS >= abs(1000 * (A - (T - H[i] * 0.006)))){
        ABS = abs(1000 * (A - (T - H[i] * 0.006)));
        ans = i;
      }
    }
    cout << ans << endl;
}

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

int main() {
  ll h, w, n;
  cin >> h >> w >> n;
  vector<ll> subRect(10, 0);
  subRect[0] = (h - 2) * (w - 2);
  map<pair<ll, ll>, ll> m;
  for (int rect = 0; rect < n; rect++) {
    ll a, b;
    cin >> a >> b;
    for (int i = -2; i <= 0; i++) {
      for (int j = -2; j <= 0; j++) {
        int newI, newJ;
        newI = a + i;
        newJ = b + j;
        if (newI >= 1 and newI+2 <= h and newJ >= 1 and newJ+2 <= w) {
          subRect[m[{newI, newJ}]]--;
          m[{newI, newJ}]++;
          subRect[m[{newI, newJ}]]++;
        }
      }
    }
  }
  for (int i = 0; i <= 9; i++) {
    cout << subRect[i] << endl;
  }
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
ll a[maxn];


ll get(deque<ll> qq) {
    int n = qq.size();
    ll res = 0;
    for (int i=0; i+1<n; i++) {
	res += abs(qq[i]-qq[i+1]);
    }
    return res;
}

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

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

    if (n==1) out(0);
    
    ll ans = 0;
    {
	deque<ll> qq;
	int l=0; int r=n-1;
	bool flag=false;
	while (l<=r) {
	    if (flag) {
		qq.push_back(a[l++]);
	    } else {
		qq.push_back(a[r--]);
	    }
	    flag=!flag;
	}
	ll res = get(qq);
	ans = max(ans, res);

	for (int i=0; i<n; i++) {
	    res -= abs(qq[n-1]-qq[n-2]);
	    res += abs(qq[n-1]-qq[0]);
	    qq.push_front(qq[n-1]);
	    qq.pop_back();
	    ans = max(ans, res);
	}

	for (int i=0; i<n; i++) {
	    res -= abs(qq[0]-qq[1]);
	    res += abs(qq[0]-qq[n-1]);
	    qq.push_back(qq[0]);
	    qq.pop_front();
	    ans = max(ans, res);
	}
    }



    {
	deque<ll> qq;
	int l=0; int r=n-1;
	bool flag=true;
	while (l<=r) {
	    if (flag) {
		qq.push_back(a[l++]);
	    } else {
		qq.push_back(a[r--]);
	    }
	    flag=!flag;
	}
	ll res = get(qq);
	ans = max(ans, res);

	for (int i=0; i<n; i++) {
	    res -= abs(qq[n-1]-qq[n-2]);
	    res += abs(qq[n-1]-qq[0]);
	    qq.push_front(qq[n-1]);
	    qq.pop_back();
	    ans = max(ans, res);
	}
	for (int i=0; i<n; i++) {
	    res -= abs(qq[0]-qq[1]);
	    res += abs(qq[0]-qq[n-1]);
	    qq.push_back(qq[0]);
	    qq.pop_front();
	    ans = max(ans, res);
	}
    }




    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5648
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a[200005],cnt=1,ans;
int main(){
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(ll i=1;i<=n;i++){
		if(a[i]==cnt) cnt++;
		else ans++;
	}
	if(cnt==1) cout<<-1;
	else cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

func NextStringsLine() []string {
	strs := []string{}
	stringsStr := NextLine()
	tmp := strings.Split(stringsStr, " ")
	for _, s := range tmp {
		strs = append(strs, s)
	}
	return strs
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	fa := float64(a)
	fanswer := math.Abs(fa)
	return int(fanswer)
}

// DeleteElement returns a *NEW* slice, that have the same and minimum length and capacity.
// DeleteElement makes a new slice by using easy slice literal.
func DeleteElement(s []int, i int) []int {
	if i < 0 || len(s) <= i {
		panic(errors.New("[index error]"))
	}
	// appendのみの実装
	n := make([]int, 0, len(s)-1)
	n = append(n, s[:i]...)
	n = append(n, s[i+1:]...)
	return n
}

// Concat returns a *NEW* slice, that have the same and minimum length and capacity.
func Concat(s, t []rune) []rune {
	n := make([]rune, 0, len(s)+len(t))
	n = append(n, s...)
	n = append(n, t...)
	return n
}

// sort package (snippets)
//sort.Sort(sort.IntSlice(s))
//sort.Sort(sort.Reverse(sort.IntSlice(s)))
//sort.Sort(sort.Float64Slice(s))
//sort.Sort(sort.StringSlice(s))

// copy function
//a = []int{0, 1, 2}
//b = make([]int, len(a))
//copy(b, a)

/*******************************************************************/

func main() {
	tmp := NextLine()
	strs := strings.Split(tmp, " ")
	for _, str := range strs {
		for _, r := range []rune(str) {
			fmt.Printf("%s", strings.ToUpper(string(r)))
			break
		}
	}
	fmt.Println("")
}


Measured memory_bytes: 640
#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
typedef long double ld;

int solve(void);
ll count_shakehands(ll X, ll& ans);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

ll N, M;
vector<ll> A, B;

int solve(void)
{
	cin >> N >> M;
	A = vector<ll>(N);

	for (auto& a :A)
		cin >> a;

	sort(A.begin(), A.end(), std::greater<ll>());
	B = A;
	for (ll i = 0; i < A.size() - 1; i++)
		B[i+1] += B[i];

	ll ng = A[0] * 3;
	ll ok = 0;

	ll ans = 0;

	while (abs(ok - ng) > 1)
	{
		ll mid = (ng + ok) / 2;
		ll cnt = count_shakehands(mid, ans);
		( cnt >= M ? ok : ng ) = mid;
	}
	
	ll cnt = count_shakehands(ok, ans);
	cout << ans - ok * (cnt - M) << endl;
		
	return 0;
}

ll count_shakehands(ll X, ll& ans)
{
	ll cnt = 0;
	ans = 0;

	for (ll i = 0; i < A.size(); i++)
	{
		if (A[i] + A[0] < X) { continue; }

		ll ok = upper_bound(
			A.begin(),
			A.end(),
			X - A[i], greater<ll>()
		) - A.begin();

		cnt += (ok);

		{
			ll sa = A[i] * ( ok );
			ll sb = B[ok - 1];
			ans += sa + sb;
		}
	}

	return cnt;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    int w,h,x,y;
    scanf("%d %d %d %d",&w,&h,&x,&y);

    if(x*2 == w && y*2 == h){
        printf("%f 1\n",(double)w*(double)h/2);
    }else{
         printf("%f 0\n",(double)w*(double)h/2);
    }
    return  0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     
#include <iomanip> 

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
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()
{
  //input
  inputInt(N);
  
  //main
  int ans = 0;
  for(int i=1; i<=N; i++){
    int j = i;
    int d = 0;
    while(j > 0){
      d += 1;
      j /= 10;
    }
    if(d & 1) ans ++; 
  }
  
  // output
  output(ans);
    
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;cin >> n;
    for (int i = 0; i < n; ++i)
    {
        ll d;cin >> d;
        if(d&1)continue;
        if(d%3 and  d%5)
        {
            cout << "DENIED";return 0;
        }
    }
    cout << "APPROVED";
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)

const long long  int INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n"


void Main()
{
	ll H,W;
	ll result=0;
	cin>>H>>W;
	VVC s(H,VC(W,'.'));
	VVC t(H,VC(W,'x'));

	REP(j, H){
		REP(i,W){
			cin >> s[j][i];
			if(s[j][i]=='#') t[j][i]=s[j][i];
		};
	}

	REP(j, H){
		REP(i,W-1){
			if(s[j][i+1]==s[j][i]) t[j][i]='x',t[j][i+1]='x';
		};
	}

	REP(i, W){
		REP(j,H-1){
			if(s[j+1][i]==s[j][i]) t[j][i]='x',t[j+1][i]='x';
		};
	}

	REP(j, H){
		REP(i,W){
			if(t[j][i]=='#'){
				COUT("No");
				return;
			}
		};
	}
	COUT("Yes");
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include<stdio.h>
#define INF 1000000
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2


int n;
int M[100][100];

void cost(){
  int d[100];
  int color[100];
  int min,u;
  int i,j;

  for(i=0;i<n;i++){
    d[i] = INF;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;

  while(1){
    min = INF;
    u = NIL;
    for(i=0;i<n;i++){
      if(color[i] != BLACK && d[i] < min){
        min = d[i];
        u = i;
      }
    }

    if(u == NIL)break;
    color[u] = BLACK;

    for(j=0;j<n;j++){
      if(color[j] != BLACK && M[u][j] != INF){
        if(d[u] + M[u][j] < d[j]){
          d[j] = d[u] + M[u][j];
          color[j] = GRAY;
        }
      }
    }
  }

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

int main(){
  int k,l,x,y;
  int i,j;


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

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

  cost();

  return 0;
}



Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main(){
	int x=1, y=1,tmp;
	while (true){
		cin >> x >> y;
		if (x == 0 && y == 0){
			break;
		}
		if (x > y){
			tmp = x;
			x = y;
			y = tmp;
		}
		cout << x << " " << y << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
//#include "rainbow.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...)
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
//inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
 
 
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


int a[303][303],use[303],p[303];
vi q[303];
int main(){
    int T,i,j,k,m=0,K,n;
    scanf("%d%d",&n,&m);
    rep(i,0,n){
        rep(j,0,m)scanf("%d",&a[i][j]),a[i][j]--;
    }
    int l=1,r=n;
    while(l<=r){
        int x=(l+r)>>1;
        rep(i,0,n)p[i]=0;
        rep(i,0,m)use[i]=0;
        int ok=0;
        while(1){
            rep(i,0,m)q[i].clear();
            rep(i,0,n)q[a[i][p[i]]].pb(i);
            ok=1;
            rep(i,0,m)if(SZ(q[i])>x){ok=0;use[i]=1;}
            if(ok)break;
            rep(i,0,m)if(SZ(q[i])>x){
                for(auto o:q[i]){
                    while(p[o]<m&&use[a[o][p[o]]])p[o]++;
                    if(p[o]>=m){ok=0;goto t;}
                }
            }
        }
        t:;
        if(ok)r=x-1;
        else l=x+1;
    }
    printf("%d\n",r+1);
}

Measured memory_bytes: 1152
#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
	int N;
	int K;

	cin >> N >> K;
	if (K==1)
	{
		cout << 0 << endl;
	}
	else {
		N = N - K;
		if (N > 0)
		{
			cout << N << endl;

		}
		else

		{
			cout << 0 << endl;
		}
	}

	
}


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

#define MAX 100

int H, W;
char a[MAX][MAX];

int main()
{
	int H, W;

	cin >> H >> W;
	for( int i = 0; i < H; i++ ) {
		for( int j = 0; j < W; j++ ) {
			cin >> a[i][j];
		}
	}

	for( int j = 0; j < W + 2; j++ ) {
		cout << "#";
	}
	cout << endl;
	for( int i = 0; i < H; i++ ) {
		cout << "#";
		for( int j = 0; j < W; j++ ) {
			cout << a[i][j];
		}
		cout << "#" << endl;
	}
	for( int j = 0; j < W + 2; j++ ) {
		cout << "#";
	}
	cout << endl;

	return 0;
}


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

int main(void){
    int N;
    cin >> N;
    int A[N];

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

    int MAX = A[0];
    int MIN = A[0];

    for(int i = 0; i < N; i++){
        MAX = max(MAX, A[i]);
        MIN = min(MIN, A[i]);
    }

    int ans = abs(MAX-MIN);
    cout << ans << endl;

    return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF=1e18+1;
const int mod = 1000000007;

int T;
map<int64_t,int64_t>dp;
int64_t N,A,B,C,D;

int64_t f(int64_t x){
  if(x==0){return dp[0]=0;}
  if(x==1){return dp[1]=D;}
  if(dp[x]>0){return dp[x];}

  if(1e18/x<=D){dp[x]=1e18;}
  else{dp[x]=x*D;}
  chmin(dp[x],f(x/2)+A+(x%2)*D);
  chmin(dp[x],f((x+1)/2)+A+(2-x%2)*D);
  chmin(dp[x],f(x/3)+B+(x%3)*D);
  chmin(dp[x],f((x+2)/3)+B+(3-x%3)*D);
  chmin(dp[x],f(x/5)+C+(x%5)*D);
  chmin(dp[x],f((x+4)/5)+C+(5-x%5)*D);
  return dp[x];
}

int main(){
  cin>>T;
  for(int i=0;i<T;i++){
    cin>>N>>A>>B>>C>>D;
    dp.clear();
    cout<<f(N)<<endl;
  }
  return 0;                       
}

Measured memory_bytes: 4428
def bubble(A, N):
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if int(A[j][-1]) < int(A[j-1][-1]):
                A[j], A[j-1] = A[j-1], A[j]
                flag = True
    return A

def selection(A, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(A[j][-1]) < int(A[minj][-1]):
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
    return A

if __name__ == "__main__":
    N = int(input())
    A = input().split()

    A_bubble = bubble(A[:], N)
    print (*A_bubble)
    print ("Stable")

    A_selection = selection(A[:], N)
    print (*A_selection)
    if A_bubble == A_selection:
        print ("Stable")
    else:
        print ("Not stable")

Measured memory_bytes: 7780
fun main(args:Array<String>) {
	val (a,b,k) = readLine()!!.split(" ").map{ it.toLong() }
	(a..b).take(k.toInt())
			.plus( (a..b).reversed().take(k.toInt()) )
			.distinct()
			.sorted()
			.forEach { println(it) }
}

Measured memory_bytes: 37820
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
#define dump(x) cerr << #x " = " << x << endl
#define unittest_name_helper(counter) unittest_ ## counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__) ()
using ll = long long;
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> ostream & operator << (ostream & out, vector<T> const & xs) { REP (i, int(xs.size()) - 1) out << xs[i] << ' '; if (not xs.empty()) out << xs.back(); return out; }

int solve(int n, vector<int> const & a) {
    unordered_map<int, int> f;
    for (int a_i : a) {
        f[a_i] += 1;
    }

    unordered_map<int, vector<int> > g;
    unordered_map<int, int> degree;
    queue<int> que;
    for (int a_i : a) if (not g.count(a_i)) {
        REP (k, 31) {
            int a_j = (1 << k) - a_i;
            if (f.count(a_j)) {
                g[a_i].push_back(a_j);
            }
        }
        degree[a_i] = g[a_i].size();
        if (degree[a_i] == 1) {
            que.push(a_i);
        }
    }

    int ans = 0;
    while (not que.empty()) {
        int a_i = que.front();
        que.pop();
        for (int a_j : g[a_i]) {
            int delta = min(f[a_i], f[a_j]);
            if (a_i == a_j) {
                delta /= 2;
            } else {
                f[a_i] -= delta;
            }
            f[a_j] -= delta;
            ans += delta;
        }
        for (int a_j : g[a_i]) {
            degree[a_j] -= 1;
            if (degree[a_j] == 1) {
                que.push(a_j);
            }
        }
    }
    return ans;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP (i, n) cin >> a[i];
    cout << solve(n, a) << endl;
    return 0;
}


Measured memory_bytes: 34760
from bisect import *

N = int(input())
A = [-int(input()) for i in range(N)]

dp = [float("inf")]*N

for i in range(N) :
    ind = bisect_right(dp, A[i])
    dp[ind] = A[i]

ans = bisect_left(dp,float("inf"))
print(ans)


Measured memory_bytes: 7840
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int n,x[105],y[105];
int a[105],b[105];
int vis[105],link[105];
vector<int>way[105];
int find(int u){
	int v;
	for(int i=0;i<way[u].size();i++){
		v=way[u][i];
		if(vis[v]==0){
			vis[v]=1;
			if(link[v]==0||find(link[v])){
				link[v]=u;
				return 1;
			}
		}
	}
	return 0;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>x[i]>>y[i];
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(x[i]<a[j]&&y[i]<b[j]){
			   way[i].push_back(j);
			}
		}
	}
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		ans+=find(i);
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int count = 0;
  for (int i=1;i<=N;i+=2){
    int num = 0;
    for (int j=1;j<=i;j++){
      if((i%j) == 0) num++;
    }
    if (num == 8) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll A, B, K; cin >> A>> B >> K;
  ll c = max(ll(0), A-K);
  ll d = max(ll(0), B-max((ll)0, K-A));
  cout << c <<  " " << d << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		while (true) {
			int n = scan.nextInt();
			int p = scan.nextInt();
			int mem = 0;
			int b = 0;
			if (n == 0 && p == 0)
				break;

			int[] a = new int[n];

			for (int i = 0; i < n; i++) {
				a[i] = 0;
			}

			while (true) {
				if (p != 0) {
					a[b]++;
					p--;
					if (a[b] == 1)
						mem++;
					b++;
					if (b == n)
						b = 0;
				} else {
					p = a[b];
					a[b] = 0;
					if (p != 0)
						mem--;
					b++;
					if (b == n)
						b = 0;
				}
				if (p == 0 && mem == 1) {
					if (b == 0) {
						b = n - 1;
					} else {
						b = b - 1;
					}
					break;
				}

			}
			System.out.println(b);
		}
	}
}

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

int main() {

    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);
    vector<pair<LL, LL>> v;
    for(int i = 0; i < N; i++){
        LL a, b;
        scanf("%lld %lld", &a, &b);
        v.push_back(make_pair(b, a));
    }
    
    // 2. 〆切の時刻で, 昇順sort.
    sort(v.begin(), v.end());
    
    // 3. 区間をマージしていく.
    // [入力例]
    // ※〆切の時刻で, 昇順sort済.
    // 5
    // 2 4
    // 1 8
    // 1 9
    // 4 9
    // 3 12
    // -> 具体的には, 以下のような処理を想定.
    // 仕事1 => [2, 4]  … 開始時刻: 2, 終了時刻: 4
    // 仕事2 => [1, 4]  … 開始時刻: 1, 終了時刻: 4
    // 仕事3 => [0, 4]  … 開始時刻: 0, 終了時刻: 4
    // 仕事4 => [0, 8]  … 開始時刻: 0, 終了時刻: 8
    // 仕事5 => [0, 11] … 開始時刻: 0, 終了時刻: 11
    bool ans = true;
    LL l = v[0].first - v[0].second, r = v[0].first;
    // printf("[%lld, %lld]\n", l, r);
    // sub1_07.txt, sub1_09.txt, sub1_27.txt, sub1_28.txt で, 
    // WA版となった理由 と 推定し, ロジック追加.
    if(l < 0) ans = false; 

    for(int i = 1; i < N; i++){
        // 以下の条件で, 区間更新.
        LL a = v[i].second, b = v[i].first;
        
        // 3-1. 最小時刻が, ゼロの場合.
        if(l == 0) r += a;
        
        // 3-2. 最小時刻 が 0より大きく, かつ, 仕事にかかる時間が, 最小時刻 より 大きい場合.
        if(l > 0 && l < a) r += (a - l), l = 0;
        
        // 3-3. 最小時刻 が, 仕事にかかる時間以上に大きい場合.
        if(l >= a) l -= a;
        
        // 3-4. 仕事が〆切までに終了しているかチェック.
        // printf("[%lld, %lld]\n", l, r);
        if(r > b){
            ans = false;
            break;
        }
    }
    
    // 4. 後処理.
    if(ans) printf("%s\n", "Yes");
    else    printf("%s\n",  "No");
    return 0;

}

Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q,sum=0;
    cin>>n;
    vi a(n);
    map<int,int>m;
    rep(i,0,n){cin>>a[i];m[a[i]]++;sum+=a[i];}
    cin>>q;
    rep(i,0,q){
        int b,c;
        cin>>b>>c;
        if(m[b]){
            sum=sum-b*m[b]+c*m[b];
            m[c]+=m[b];
            m[b]=0;
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 9692
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;
vl c;
vl a;
vl b;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    c = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> c[i];
    }
    a = vl(N-1);
    b = vl(N-1);
    for(int i = 0; i < N-1; ++i){
        cin >> a[i];
        cin >> b[i];
    }
    solve();
}

// 1 <= N <= 2 × 10^5
// 1 <= c_i <= N
// 1 <= a_i,b_i <= N
// 与えられるグラフは木である。
// 入力はすべて整数である。

vvl g;
vl root,cnt;

// 個数を返す
ll dfs(ll x,ll p=-1){
    ll ret=1;
    ll tmp=root[c[x]];
    for(ll to:g[x]){
        if(to==p)continue;
        root[c[x]]=to;
        ret+=dfs(to,x);
    }
    root[c[x]]=tmp;
    cnt[x]+=ret;
    cnt[root[c[x]]]-=ret;
    return ret;
}

vl ans;
void dfs2(ll x,ll p=-1){
    for(ll to:g[x]){
        if(to==p)continue;
        ans[c[x]]-=cnt[to]*(cnt[to]+1)/2;
        dfs2(to,x);
    }
}

// ll N, vl c, vl a, vl b
// k=1,2,...,N に対する問題の答えを、順番に改行区切りで出力せよ。
void solve(){
    rep(i,N)--c[i];
    rep(i,N-1)--a[i],--b[i];

    g=vvl(N);
    root=vl(N);
    cnt=vl(2*N);
    rep(i,N){
        root[i]=i+N;
        cnt[i+N]=N;
    }
    rep(i,N-1){
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    dfs(0);
    ans=vl(N);
    rep(i,N)ans[i]=N*(N+1)/2-cnt[i+N]*(cnt[i+N]+1)/2;
    dfs2(0);
    rep(i,N)cout<<ans[i]<<endl;
}


Measured memory_bytes: 40684
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb(x) push_back(x)
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
#define vi vector<long long>
#define vs  vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
/*bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
*/
int main()
{
    ll a,b,t,n,k,p,q,r,sum,ct=0,flag=0;
    string s,s1,s2,s3;
    char ch;
    set<ll>st;
    map<ll,ll>mp;
    vector<ll>v;
    cin>>a>>ch>>b;
    if(ch=='+') cout<<a+b<<endl;
    else cout<<a-b<<endl;
}






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

int main() {
  int s;
  scanf("%d", &s);

  int ans = 1;
  while (1) {
    if (s == 4 || s == 2 || s == 1) break;
    
    if (s % 2 == 0) {
      s /= 2;
    } else {
      s = 3 * s + 1;
    }
    ans++;
  }

  printf("%d", ans + 3);
  return 0;
}


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

using namespace std;

int main()
{
  int n, k; cin >> n >> k;
  int len = 0;
  vector<int> iv;

  for (int i = 0; i < n; i++) {
    int l; cin >> l;
    iv.push_back(l);
  }

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

  for (int i = 0; i < k; i++) len += iv[i];

  cout << len << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def main():
    n=int(input())
    n_list=make_divisors(n)
    len_list=len(n_list)
    if len_list%2==1:print(2*n_list[len_list//2]-2)
    else:
        print(n_list[len_list//2-1]+n_list[len_list//2]-2)

if __name__=='__main__':
    main()

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

int main(){
  string s;
  cin >> s;
  
  int A=s.length(),Z=-1;
  for(int i=0; i<s.length(); i++){
    if(s[i]=='A' && i<A){
      A=i;
    }
    if(s[i]=='Z' && i>Z){
      Z=i;
    }
  }
  cout << Z-A+1 << endl;
  return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
// #define map unordered_map
// #define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

struct UnionFind {
  vector<ll> data;

  UnionFind(ll sz) { data.assign(sz, -1); }

  bool unite(ll x, ll y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  ll find(ll k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  ll size(ll k) { return (-data[find(k)]); }

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

ll N, M;

ll calc(UnionFind uf) {
  map<ll, ll> m;
  for (ll i = 1; i <= N; i++) {
    m[uf.find(i)]++;
  }

  ll r = 0;
  auto ite = m.begin();
  for (; ite != end(m); ite++) {
    ll count = (*ite).second;
    cout << (*ite).first << "," << count << endl;
  }

  return r;
}

int main() {
  scanf("%lld %lld", &N, &M);

  UnionFind uf = UnionFind(N + 1);

  vector<pair<ll, ll>> list(M);
  for (ll i = 0; i < M; i++) {
    ll a, b;
    scanf("%lld %lld", &a, &b);
    list[i] = make_pair(a, b);
  }

  reverse(list.begin(), list.end());

  vll ans;

  ll val = N * (N - 1) / 2;
  ans.emplace_back(val);
  for (ll i = 0; i < M; i++) {
    if (i == M - 1) {
      break;
    }
    ll a = list[i].first;
    ll b = list[i].second;

    bool same = uf.same(a, b);

    ll a_size = uf.size(a);
    ll b_size = uf.size(b);

    uf.unite(a, b);

    if (!same) {
      bool same2 = uf.same(a, b);
      if (same2) {
        val -= (a_size * b_size);
      }
    }
    ans.emplace_back(val);
  }

  reverse(ans.begin(), ans.end());

  for (ll i = 0; i < M; i++) {
    cout << ans[i] << endl;
  }
}

// 0
// 0
// 4
// 5
// 6


Measured memory_bytes: 4596
#include<stdio.h>

#define CNST_DAY 365
#define NUM_CONTEST 26

int main(void){

    int i,j,k,d,n;
    int D,c[NUM_CONTEST+1]={},s[CNST_DAY+1][NUM_CONTEST+1]={},last[NUM_CONTEST+1]={},t[CNST_DAY+1]={};
    long v[CNST_DAY+1]={};

    //入力
    scanf("%d",&D);
    for(d=1;d<=NUM_CONTEST;d++){
        scanf("%d",&c[d]);
    }
    for(d=1;d<=D;d++){
        for(i=1;i<=NUM_CONTEST;i++){
            scanf("%d",&s[d][i]);
        }
    }
    for(d=1;d<=D;d++){
        scanf("%d",&t[d]);
    }

    //スコア計算
    for(d=1;d<=D;d++){
        //開催するコンテストt[d]を決めた後
        last[t[d]]=d;
        v[d]=v[d-1]+s[d][t[d]];
        for(i=1;i<=NUM_CONTEST;i++){
            v[d]-=c[i]*(d-last[i]);
        }
    }

    //出力
    for(d=1;d<=D;d++){
        printf("%ld\n",v[d]);
    }

    return 0;
}

Measured memory_bytes: 1776
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////



int main(){fastio
    
    ll n,c;cin>>n>>c;
    ll d[c][c];rep(i,0,c-1)rep(j,0,c-1)cin>>d[i][j];
    
    /*
    ll dp[c][c];
    rep(goal,0,c-1){
        rep(i,0,c-1)dp[i][goal]=inf;
        dp[goal][goal]=0;
        priority_queue<l_l,vector<l_l>,greater<l_l>>q;q.push({0,goal});
        while(!q.empty()){
            l_l t=q.top();q.pop();
            rep(i,0,c-1){
                if(i==t.se)continue;
                if(dp[i][goal]>dp[t.se][goal]+d[i][t.se]){
                    dp[i][goal]=dp[t.se][goal]+d[i][t.se];
                    q.push({dp[i][goal],i});
                }
            }
        }
    }*/
    /*
    rep(i,0,c-1){
        rep(j,0,c-1)cout<<dp[i][j]<<" ";cout<<endl;
    }cout<<endl;*/
    
    ll a[n][n];rep(i,0,n-1)rep(j,0,n-1){cin>>a[i][j];a[i][j]--;}
    
    ll ep[3][c];memset(ep,0,sizeof(ep));
    rep(i,0,n-1)rep(j,0,n-1){
        ll k=(i+j)%3;
        rep(q,0,c-1){
            ep[k][q]+=d[a[i][j]][q];//dp[a[i][j]][q];
        }
    }
    /*
    rep(i,0,2){
        rep(j,0,c-1)cout<<ep[i][j]<<" ";cout<<endl;
    }*/
    
    ll ans=inf;
    rep(c1,0,c-1)rep(c2,0,c-1)rep(c3,0,c-1){
        if(c1==c2||c2==c3||c3==c1)continue;
        Min(ans,ep[0][c1]+ep[1][c2]+ep[2][c3]);
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>

int main(int argc, char *argv[]) {
	int m, n;
	for (m = 1; m <= 9; ++m) {
		for (n = 1; n <= 9; ++n) {
			std::cout << m << 'x' << n << '=' << (m * n) << std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
while True:
    try:
        sum = 0
        n = int(raw_input())
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        #print a , b, c, d
                        #print n
                        if (a+b+c+d == n):
                            sum += 1
        print sum
    except:
        break

Measured memory_bytes: 4640
import itertools

N, M, X = map(int, input().split())
a = [list(map(int, input().split())) for l in range(N)]

ans = 10**8

for i in range(2**N):
    score = [0] * M
    total = 0
    for j in range(N):
        if ((i >> j) & 1):
            total += a[j][0]
            for k in range(M):
                score[k] += a[j][k+1]
        
    if min(score) >= X:
        ans = min(ans, total)

if ans == 10**8:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9132
#include <iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)

using namespace std;

int main() {
    vector<int>demand(5);
    rep(i,5)cin>>demand[i];
    rep(i,4){
        if(demand[i]%10){
            if(demand[i+1]%10==0)swap(demand[i],demand[i+1]);
            else if(demand[i+1]%10>demand[i]%10)swap(demand[i],demand[i+1]);
        }
    }
    rep(i,4){
        if(demand[i]%10)demand[i]+=10-demand[i]%10;
    }
    int ans=0;
    rep(i,5)ans+=demand[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// Auhthor:: MOHAMMAD FAISAL
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH 
#include<bits/stdc++.h>
using namespace std;
bool solve(long long n)
{
  	long long temp = n;
   	long long sum=0;
  	while(n>0)
    {
      sum+=(n%10);
      n/=10;
    }
  	return (temp%sum==0) ?  true: false;
}
int main()
{
  
	long long n;
    cin >> n;
  	(solve(n)) ? cout<<"Yes": cout<<"No";
 	return 0;
}


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

namespace ABC146A
{
    class Program
    {
        static void Main(string[] args)
        {
            string a;
            int n;
            a = Console.ReadLine();
            n = 0;
            if (a == "SUN")
                n = 7;
            if (a == "MON")
                n = 6;
            if (a == "TUE")
                n = 5;
            if (a == "WED")
                n = 4;
            if (a == "THU")
                n = 3;
            if (a == "FRI")
                n = 2;
            if (a == "SAT")
                n = 1;

            Console.WriteLine(n);



        }
    }
}
   


Measured memory_bytes: 11092
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
vll B;
ll C;
ll N;
ll M;
vll ans;
bool is_prime[base10_6];

ll ltmp;
string stmp;
double dtmp;

/*
max 448,000,000
map<string,ll> count_map;
count_map['0']=0;
for(auto x : count_map) {
    string key = x.first;
    ll value = x.second;
}
*/



int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    map<ll,ll> count_map;
    map<ll,ll> pos_map;


    cin >> N;
    rep(ni,N){
        cin >> ltmp;
        A.push_back(ltmp);
        count_map[ltmp]++;
    }

    if(N==1){
        cout << 1 << endl;        
    }else if(count_map.count(1)>0){
        if(count_map[1]==1){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        sort(A.begin(),A.end());
        ll bef = -1;
        ll index = 0;
        ll cntA = A.size();
        rep(ai,cntA){
            ll target = A[ai];
            if(bef!=target){
                bef = target;

                B.push_back(target);
                pos_map[target]=index;
                is_prime[index]=true;
                index++;
            }
        }
        ll cntB = index;

        for( ll number = 0 ; number < cntB ; number++ ){
            if(is_prime[number]){
                ll target = B[number];
                for( ll ni = target*2 ; ni <=B[cntB-1] ; ni+=target ){
                    if(count_map.count(ni)>0){
                        //cout << ni << endl;
                        index = pos_map[ni];
                        is_prime[index]=false;
                    }
                }
            }
        }

        ll cntans=0;
        rep(bi,cntB){
            ll target = B[bi];
            if(is_prime[bi] && count_map[target]==1){
                cntans++;
                //cout << target << endl;

            }
        }
        cout << cntans << endl;


    }



}

Measured memory_bytes: 31552
import sys
 
input = sys.stdin.readline()
N = int(input)

result = False

if N > 0 and N < 82:
  for x in range(1,10):
    if (N%x)==0 and (N/x) < 10:
      result = True
if result:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940